Chore/base configurations

This commit is contained in:
Kuldeep
2026-01-25 12:51:34 +00:00
parent 6d3c0b3188
commit e8252b2fa2
21 changed files with 18154 additions and 1728 deletions

5
.cspell.json Normal file
View File

@@ -0,0 +1,5 @@
{
"version": "0.1",
"import": ["@generalprotocols/cspell-dictionary/cspell.json"],
"words": ["nonfungible", "lockscript"]
}

View File

@@ -4,7 +4,7 @@ root = true
charset = utf-8 charset = utf-8
indent_style = space indent_style = space
indent_size = 4 indent_size = 4
max_line_length = 150
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true

View File

@@ -1,2 +0,0 @@
**/build/
**/node_modules/

View File

@@ -1,52 +0,0 @@
{
"extends": ["@generalprotocols/eslint-config/typescript", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 2020,
"project": "./tsconfig.json",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}
],
"import/extensions": [
"error",
{
"js": "always"
}
],
"import/no-internal-modules": [
"error",
{
"allow": ["**/*"]
}
],
"max-len": [
"error",
{
"code": 150,
"ignoreUrls": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreComments": true
}
],
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"destructuredArrayIgnorePattern": "^_"
}
],
"object-curly-newline": [
"error",
{
"multiline": true
}
]
}
}

11
.gitignore vendored
View File

@@ -1,11 +1,14 @@
.vscode/ .vscode/
build/ dist/
build/** dist/**
node_modules/ node_modules/
yarn.lock yarn.lock
yarn-error.log yarn-error.log
.DS_Store .DS_Store
public/
docs/
coverage/
*.js *.js
*.js.map *.js.map
@@ -14,8 +17,8 @@ yarn-error.log
*.tsbuildinfo *.tsbuildinfo
# Generated files # Generated files
src/parser/xo-template.schema.json source/parser/xo-template.schema.json
src/parser/ajv/validate-xo-template.js source/parser/ajv/validate-xo-template.js
# Exception: include generate-schema.js # Exception: include generate-schema.js
!scripts/generate-schema.js !scripts/generate-schema.js

View File

@@ -1,7 +0,0 @@
{
"printWidth": 150,
"useTabs": false,
"tabWidth": 4,
"singleQuote": true,
"semi": true
}

23
.prettierrc.mjs Normal file
View File

@@ -0,0 +1,23 @@
// Prettier configuration aligned with @xo-cash/eslint-config
export default {
// Matches @stylistic/max-len': [ 'warn', 150, ...]
printWidth: 150,
// Matches @stylistic/no-tabs': [ 'error' ]
useTabs: false,
// Matches @stylistic/indent': [ 'error', 4, ...]
tabWidth: 4,
// Matches @stylistic/array-bracket-spacing': [ 'error', 'always', ...]
bracketSpacing: true,
// Matches @stylistic/quotes: ['error', 'single', { avoidEscape: true }], from @chalp/eslint-airbnb/base/stylistic.js
singleQuote: true,
// Matches @stylistic/semi: ['error', 'always'], from @chalp/eslint-airbnb/base/stylistic.js
semi: true,
// Matches @stylistic/arrow-parens: ['error', 'always'], from @chalp/eslint-airbnb/base/stylistic.js
arrowParens: 'always',
};

8
eslint.config.mjs Normal file
View File

@@ -0,0 +1,8 @@
import baseConfig from '@xo-cash/eslint-config';
export default [
{
ignores: [ 'source/parser/ajv/validate-xo-template.js', 'docs/**' ],
},
...baseConfig,
];

19631
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,24 +3,26 @@
"version": "0.0.1", "version": "0.0.1",
"description": "XO Cash utilities", "description": "XO Cash utilities",
"type": "module", "type": "module",
"types": "./dist/index.d.mts",
"source": "./source/index.ts",
"module": "./dist/index.mjs",
"exports": { "exports": {
".": "./build/index.js" "types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}, },
"types": "./build/index.d.ts",
"sideEffects": false,
"scripts": { "scripts": {
"build": "npm run clean && tsc", "analyze": "tsdown --clean --no-fixed-extension --sourcemap source/index.ts && esbuild-analyzer dist/",
"clean": "del-cli ./build", "build": "tsdown --clean --sourcemap source/index.ts",
"docs": "typedoc --hideGenerator --categorizeByGroup", "docs": "typedoc --hideGenerator --categorizeByGroup",
"lint": "eslint . --ext .ts", "format": "prettier --write . && eslint --fix",
"lint:fix": "eslint . --ext .ts --fix",
"prettier": "prettier --write .",
"prebuild": "node scripts/generate-schema.js", "prebuild": "node scripts/generate-schema.js",
"prepublishOnly": "npm run build", "spellcheck": "cspell 'source/**' 'test/**' 'playground/**'",
"syntax": "tsc --noEmit" "style": "eslint",
"syntax": "tsc --noEmit",
"test": "vitest --dir test/ --test-timeout=15000 --passWithNoTests --run --coverage"
}, },
"files": [ "files": [
"build" "dist"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
@@ -41,18 +43,25 @@
"@xo-cash/types": "0.0.1" "@xo-cash/types": "0.0.1"
}, },
"devDependencies": { "devDependencies": {
"@generalprotocols/eslint-config": "^1.0.1", "@chalp/eslint-airbnb": "^1.3.0",
"@types/node": "^20.10.0", "@generalprotocols/cspell-dictionary": "^1.0.1",
"ajv-cli": "^5.0.0", "@stylistic/eslint-plugin": "^5.7.0",
"del-cli": "^7.0.0", "@typescript-eslint/eslint-plugin": "^8.53.1",
"eslint": "^8.57.1", "@typescript-eslint/parser": "^8.53.1",
"eslint-config-prettier": "^10.1.8", "@vitest/coverage-v8": "^4.0.17",
"eslint-plugin-prettier": "^5.5.4", "@viz-kit/esbuild-analyzer": "^1.0.0",
"@xo-cash/eslint-config": "1.0.1",
"cspell": "^9.6.0",
"eslint": "^9.39.2",
"prettier": "^3.6.2", "prettier": "^3.6.2",
"ts-json-schema-generator": "^2.4.0", "tsdown": "^0.20.0-beta.4",
"typedoc": "^0.28.15", "typedoc": "^0.28.16",
"typedoc-plugin-coverage": "^4.0.2", "typedoc-plugin-coverage": "^4.0.2",
"typescript": "^5.3.2" "typescript": "^5.3.2",
"typescript-eslint": "^8.53.1",
"vitest": "^4.0.17",
"ajv-cli": "^5.0.0",
"ts-json-schema-generator": "^2.4.0"
}, },
"engines": { "engines": {
"node": ">=18.0.0" "node": ">=18.0.0"

View File

@@ -10,22 +10,23 @@ const __dirname = dirname(__filename);
const rootDir = join(__dirname, '..'); const rootDir = join(__dirname, '..');
// exec helper // exec helper
function exec(command, options = {}) { const exec = (command, options = {}) => {
const defaultOptions = { const defaultOptions = {
stdio: 'inherit', stdio: 'inherit',
cwd: rootDir, cwd: rootDir,
shell: true, shell: true,
...options, ...options,
}; };
return execSync(command, defaultOptions); return execSync(command, defaultOptions);
} };
try { try {
const schemaPath = join(rootDir, 'src/parser/xo-template.schema.json'); const schemaPath = join(rootDir, 'source/parser/xo-template.schema.json');
const validatorPath = join(rootDir, 'src/parser/ajv/validate-xo-template.js'); const validatorPath = join(rootDir, 'source/parser/ajv/validate-xo-template.js');
const tsconfigPath = join(rootDir, 'tsconfig.json'); const tsconfigPath = join(rootDir, 'tsconfig.json');
// Point directly to the dist file - the type is exported at the end via barrel export // Point directly to the dist file - the type is exported at the end via barrel export
const templatePath = join(rootDir, 'node_modules/@xo-cash/types/dist/index.d.mts'); const templatePath = join(rootDir, 'node_modules/@xo-cash/types/dist/index.d.ts');
// Generate schema JSON (write to file directly instead of shell redirection) // Generate schema JSON (write to file directly instead of shell redirection)
// Using --no-type-check to skip type checking and --expose all to find types exported via barrel exports // Using --no-type-check to skip type checking and --expose all to find types exported via barrel exports

5
source/index.ts Normal file
View File

@@ -0,0 +1,5 @@
export * from './errors.ts';
export * from './parser/ajv/ajv-utils.ts';
export * from './parser/xo-template.ts';
export * from './script.ts';
export * from './templates.ts';

View File

@@ -24,9 +24,9 @@ export type AjvValidator<T = unknown> = {
data: unknown, data: unknown,
dataCxt?: { dataCxt?: {
instancePath?: string; instancePath?: string;
parentData: any; parentData: unknown;
parentDataProperty: any; parentDataProperty: unknown;
rootData?: any; rootData?: unknown;
}, },
): data is T; ): data is T;
errors?: XOAjvError[] | null; errors?: XOAjvError[] | null;

View File

@@ -3,8 +3,8 @@
*/ */
import { lossyNormalize } from '@bitauth/libauth'; import { lossyNormalize } from '@bitauth/libauth';
import type { AjvValidator, XOAjvError } from './ajv-types.js'; import type { AjvValidator, XOAjvError } from './ajv-types.ts';
import { FailedToParseTemplateError } from '../../errors.js'; import { FailedToParseTemplateError } from '../../errors.ts';
const errorsToDescription = (errors: XOAjvError[]): string => { const errorsToDescription = (errors: XOAjvError[]): string => {
// TODO: translate instancePath and make errors more descriptive. // TODO: translate instancePath and make errors more descriptive.

View File

@@ -4,9 +4,9 @@
*/ */
import type { XOTemplate } from '@xo-cash/types'; import type { XOTemplate } from '@xo-cash/types';
import type { AjvValidator } from './ajv/ajv-types.js'; import type { AjvValidator } from './ajv/ajv-types.ts';
import { parseJson, validateSchema } from './ajv/ajv-utils.js'; import { parseJson, validateSchema } from './ajv/ajv-utils.ts';
import { InvalidTemplateError } from '../errors.js'; import { InvalidTemplateError } from '../errors.ts';
import xoTemplateValidator from './ajv/validate-xo-template.js'; import xoTemplateValidator from './ajv/validate-xo-template.js';
/** /**

View File

@@ -1,9 +1,9 @@
import { binToHex, sha256 } from '@bitauth/libauth'; import { binToHex, sha256 } from '@bitauth/libauth';
/** /**
* Converts a script to a scripthash. * Converts a script to a scriptHash.
* @param {Uint8Array} script - The script to convert. * @param {Uint8Array} script - The script to convert.
* @returns {string} The scripthash as a hexadecimal string. * @returns {string} The scriptHash as a hexadecimal string.
*/ */
export const scriptToScriptHash = (script: Uint8Array): string => { export const scriptToScriptHash = (script: Uint8Array): string => {
const hash = sha256.hash(script); const hash = sha256.hash(script);

View File

@@ -8,7 +8,7 @@ import type { XOTemplate } from '@xo-cash/types';
* @returns The template identifier for the template. * @returns The template identifier for the template.
*/ */
export const generateTemplateIdentifier = (template: XOTemplate): string => { export const generateTemplateIdentifier = (template: XOTemplate): string => {
// TODO: Finalise on the stringify method and ensure unique identifier generation is sufficient. // TODO: Finalize on the stringify method and ensure unique identifier generation is sufficient.
return binToHex(sha256.hash(utf8ToBin(stringify(template)))); return binToHex(sha256.hash(utf8ToBin(stringify(template))));
}; };

View File

@@ -1,5 +0,0 @@
export * from './errors.js';
export * from './parser/ajv/ajv-utils.js';
export * from './parser/xo-template.js';
export * from './script.js';
export * from './templates.js';

View File

@@ -1,26 +1,14 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2022", "module": "es2022",
"module": "NodeNext", "target": "es2022",
"moduleResolution": "NodeNext",
"rootDir": "src",
"outDir": "build",
"incremental": true,
"tsBuildInfoFile": "./build/.tsbuildinfo",
"esModuleInterop": true,
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"skipLibCheck": true, "skipLibCheck": true,
"strict": true, "moduleResolution": "node",
"allowJs": true, "resolveJsonModule": true,
"strictPropertyInitialization": false, "allowImportingTsExtensions": true,
"traceResolution": false, "noEmit": true,
"listEmittedFiles": false, "declaration": true,
"listFiles": false, "declarationMap": true
"pretty": true
}, },
"exclude": ["node_modules", "build", "scripts"], "exclude": ["node_modules/**/*", "dist/**/*"]
"compileOnSave": false
} }

17
typedoc.json Normal file
View File

@@ -0,0 +1,17 @@
{
"entryPoints": ["source/index.ts"],
"out": "public/",
"plugin": ["typedoc-plugin-coverage"],
"maxTypeConversionDepth": 2,
"visibilityFilters": {
"protected": false,
"private": false,
"inherited": false,
"external": false
},
"groupOrder": ["Classes", "Interfaces", "Events", "*"],
"navigation": {
"includeCategories": false,
"includeGroups": true
}
}