@arkadia/data 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +8 -0
- package/README.md +166 -112
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/Decoder.d.ts.map +1 -1
- package/dist/core/Decoder.js +123 -97
- package/dist/core/Decoder.js.map +1 -1
- package/dist/core/Encoder.d.ts +1 -2
- package/dist/core/Encoder.d.ts.map +1 -1
- package/dist/core/Encoder.js +74 -76
- package/dist/core/Encoder.js.map +1 -1
- package/dist/core/Parser.d.ts +1 -1
- package/dist/core/Parser.d.ts.map +1 -1
- package/dist/core/Parser.js +11 -11
- package/dist/core/Parser.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/models/Meta.d.ts +3 -2
- package/dist/models/Meta.d.ts.map +1 -1
- package/dist/models/Meta.js +3 -3
- package/dist/models/Meta.js.map +1 -1
- package/dist/models/Node.d.ts +4 -3
- package/dist/models/Node.d.ts.map +1 -1
- package/dist/models/Node.js +29 -23
- package/dist/models/Node.js.map +1 -1
- package/dist/models/Schema.d.ts.map +1 -1
- package/dist/models/Schema.js +27 -21
- package/dist/models/Schema.js.map +1 -1
- package/eslint.config.mjs +42 -0
- package/package.json +11 -1
- package/scripts/verify-build.js +95 -92
- package/src/config.ts +75 -75
- package/src/core/Decoder.ts +984 -922
- package/src/core/Encoder.ts +364 -371
- package/src/core/Parser.ts +112 -112
- package/src/index.ts +18 -20
- package/src/models/Meta.ts +107 -107
- package/src/models/Node.ts +190 -185
- package/src/models/Schema.ts +198 -193
- package/tests/00.meta.test.ts +19 -25
- package/tests/00.node.test.ts +40 -48
- package/tests/00.primitive.test.ts +121 -95
- package/tests/00.schema.test.ts +28 -35
- package/tests/01.schema.test.ts +42 -52
- package/tests/02.data.test.ts +69 -75
- package/tests/03.errors.test.ts +53 -55
- package/tests/04.list.test.ts +192 -193
- package/tests/05.record.test.ts +54 -56
- package/tests/06.meta.test.ts +393 -389
- package/tests/utils.ts +47 -44
- package/tsconfig.json +27 -29
- package/vitest.config.ts +1 -1
package/tests/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect } from 'vitest';
|
|
2
2
|
import { Node } from '../src/models/Node';
|
|
3
3
|
// Zakładam, że masz te funkcje wyeksportowane z index.ts (szczegóły niżej)
|
|
4
|
+
import { parseDataToNode } from '../src/core/Parser';
|
|
4
5
|
import { decode, encode } from '../src/index';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -12,58 +13,60 @@ import { decode, encode } from '../src/index';
|
|
|
12
13
|
* * Returns the Node so that further logical assertions (field checking) can be performed.
|
|
13
14
|
*/
|
|
14
15
|
export function assertRoundtrip(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
source: string | Node | unknown,
|
|
17
|
+
expectedOutput: string,
|
|
18
|
+
debug: boolean = false,
|
|
18
19
|
): Node {
|
|
19
|
-
|
|
20
|
+
let node: Node;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
expect(res.errors, `Input decoding errors: ${res.errors.join(', ')}`).toHaveLength(0);
|
|
30
|
-
node = res.node;
|
|
31
|
-
} else {
|
|
32
|
-
node = source;
|
|
22
|
+
// 1. Prepare Node (if input is raw text)
|
|
23
|
+
if (typeof source === 'string') {
|
|
24
|
+
// Przekazujemy debug do decodera
|
|
25
|
+
const res = decode(source, { debug });
|
|
26
|
+
|
|
27
|
+
if (res.errors.length > 0) {
|
|
28
|
+
console.error('Input decoding errors:', res.errors);
|
|
33
29
|
}
|
|
30
|
+
expect(res.errors, `Input decoding errors: ${res.errors.join(', ')}`).toHaveLength(0);
|
|
31
|
+
node = res.node;
|
|
32
|
+
} else if (!(source instanceof Node)) {
|
|
33
|
+
node = parseDataToNode(source);
|
|
34
|
+
} else {
|
|
35
|
+
node = source;
|
|
36
|
+
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
// 2. First Encoding
|
|
39
|
+
// Wymuszamy compact: true zgodnie z pythonowym oryginałem
|
|
40
|
+
const encoded1 = encode(node, { compact: true });
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
// Debug print to visualize differences in case of failure
|
|
43
|
+
// (Vitest zrobi to automatycznie przy .toBe, ale zachowujemy logikę z Python)
|
|
44
|
+
if (encoded1 !== expectedOutput) {
|
|
45
|
+
console.log(`\n[ROUNDTRIP] Mismatch Pass 1:`);
|
|
46
|
+
console.log(`EXPECTED: "${expectedOutput}"`);
|
|
47
|
+
console.log(`ACTUAL: "${encoded1}"`);
|
|
48
|
+
}
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
expect(encoded1).toBe(expectedOutput);
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (res2.errors.length > 0) {
|
|
53
|
-
console.error("Re-decoding errors:", res2.errors);
|
|
54
|
-
}
|
|
55
|
-
expect(res2.errors, `Re-decoding errors: ${res2.errors.join(', ')}`).toHaveLength(0);
|
|
52
|
+
// 3. Round Trip (Decode the result of the encoding)
|
|
53
|
+
const res2 = decode(encoded1, { debug });
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
if (res2.errors.length > 0) {
|
|
56
|
+
console.error('Re-decoding errors:', res2.errors);
|
|
57
|
+
}
|
|
58
|
+
expect(res2.errors, `Re-decoding errors: ${res2.errors.join(', ')}`).toHaveLength(0);
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
// 4. Second Encoding (Idempotency Check)
|
|
61
|
+
const encoded2 = encode(res2.node, { compact: true });
|
|
62
|
+
|
|
63
|
+
if (encoded2 !== expectedOutput) {
|
|
64
|
+
console.log(`\n[ROUNDTRIP] Mismatch Pass 2 (Consistency):`);
|
|
65
|
+
console.log(`EXPECTED: "${expectedOutput}"`);
|
|
66
|
+
console.log(`ACTUAL: "${encoded2}"`);
|
|
67
|
+
}
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
expect(encoded2).toBe(expectedOutput);
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
}
|
|
71
|
+
return node;
|
|
72
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
/* --- Basic Language Configuration --- */
|
|
4
|
-
"target": "ES2020"
|
|
5
|
-
"module": "CommonJS"
|
|
6
|
-
"lib": ["ES2020"]
|
|
7
|
-
"moduleResolution": "node"
|
|
4
|
+
"target": "ES2020" /* JavaScript version to generate. ES2020 is safe for Node 14+ */,
|
|
5
|
+
"module": "CommonJS" /* Module standard (Node.js uses CommonJS by default) */,
|
|
6
|
+
"lib": ["ES2020"] /* Available libraries (e.g., Promise, Map, Set) */,
|
|
7
|
+
"moduleResolution": "node" /* Module resolution strategy */,
|
|
8
8
|
|
|
9
9
|
/* --- Output File Structure --- */
|
|
10
|
-
"outDir": "./dist"
|
|
11
|
-
"rootDir": "./src"
|
|
12
|
-
"declaration": true
|
|
13
|
-
"declarationMap": true
|
|
14
|
-
"sourceMap": true
|
|
15
|
-
"removeComments": false
|
|
10
|
+
"outDir": "./dist" /* Where compiled files should go */,
|
|
11
|
+
"rootDir": "./src" /* Source directory. Ensures strictly that only files inside src are compiled */,
|
|
12
|
+
"declaration": true /* Generate .d.ts files (required for npm libraries) */,
|
|
13
|
+
"declarationMap": true /* Allows editors (VS Code) to go to source definition */,
|
|
14
|
+
"sourceMap": true /* Generate source maps (.js.map) for debugging */,
|
|
15
|
+
"removeComments": false /* Do not remove comments (useful for JSDoc in IDEs) */,
|
|
16
16
|
|
|
17
17
|
/* --- Interoperability --- */
|
|
18
|
-
"esModuleInterop": true
|
|
19
|
-
"forceConsistentCasingInFileNames": true
|
|
20
|
-
"resolveJsonModule": true
|
|
18
|
+
"esModuleInterop": true /* Allows importing CommonJS modules as default imports */,
|
|
19
|
+
"forceConsistentCasingInFileNames": true /* Enforce consistent casing in file names */,
|
|
20
|
+
"resolveJsonModule": true /* Allows importing .json files in code */,
|
|
21
21
|
|
|
22
22
|
/* --- Strict Type-Checking --- */
|
|
23
|
-
"strict": true
|
|
24
|
-
"noImplicitAny": true
|
|
25
|
-
"strictNullChecks": true
|
|
26
|
-
"strictPropertyInitialization": true
|
|
27
|
-
"noImplicitReturns": true
|
|
28
|
-
"noFallthroughCasesInSwitch": true
|
|
29
|
-
|
|
23
|
+
"strict": true /* Enable all strict type-checking options */,
|
|
24
|
+
"noImplicitAny": true /* Error if type is not explicit and is 'any' */,
|
|
25
|
+
"strictNullChecks": true /* Error on unhandled null/undefined */,
|
|
26
|
+
"strictPropertyInitialization": true /* Check if class properties are initialized in the constructor */,
|
|
27
|
+
"noImplicitReturns": true /* Every code path in a function must return a value */,
|
|
28
|
+
"noFallthroughCasesInSwitch": true /* Prevent accidental fallthrough in switch cases */,
|
|
29
|
+
|
|
30
30
|
/* --- Code Cleanliness --- */
|
|
31
|
-
"noUnusedLocals": true
|
|
32
|
-
"noUnusedParameters": true
|
|
33
|
-
|
|
31
|
+
"noUnusedLocals": true /* Report error for unused local variables */,
|
|
32
|
+
"noUnusedParameters": true /* Report error for unused function parameters */,
|
|
33
|
+
|
|
34
34
|
/* --- Compilation Optimization --- */
|
|
35
|
-
"skipLibCheck": true
|
|
35
|
+
"skipLibCheck": true /* Skip type checking of declaration files (.d.ts) in external libs */
|
|
36
36
|
},
|
|
37
|
-
"include": [
|
|
38
|
-
"src/**/*" /* Compile everything in the src folder */
|
|
39
|
-
],
|
|
37
|
+
"include": ["src/**/*" /* Compile everything in the src folder */],
|
|
40
38
|
"exclude": [
|
|
41
39
|
"node_modules",
|
|
42
40
|
"dist",
|
|
43
|
-
"**/*.test.ts"
|
|
41
|
+
"**/*.test.ts" /* Do not include tests in the production build */,
|
|
44
42
|
"**/*.spec.ts"
|
|
45
43
|
]
|
|
46
|
-
}
|
|
44
|
+
}
|
package/vitest.config.ts
CHANGED