@arkadia/data 0.1.7 → 0.1.9

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.
Files changed (54) hide show
  1. package/.prettierrc +8 -0
  2. package/README.md +159 -112
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js.map +1 -1
  5. package/dist/core/Decoder.d.ts.map +1 -1
  6. package/dist/core/Decoder.js +123 -97
  7. package/dist/core/Decoder.js.map +1 -1
  8. package/dist/core/Encoder.d.ts +1 -2
  9. package/dist/core/Encoder.d.ts.map +1 -1
  10. package/dist/core/Encoder.js +74 -76
  11. package/dist/core/Encoder.js.map +1 -1
  12. package/dist/core/Parser.d.ts +1 -1
  13. package/dist/core/Parser.d.ts.map +1 -1
  14. package/dist/core/Parser.js +11 -11
  15. package/dist/core/Parser.js.map +1 -1
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +7 -8
  19. package/dist/index.js.map +1 -1
  20. package/dist/models/Meta.d.ts +3 -2
  21. package/dist/models/Meta.d.ts.map +1 -1
  22. package/dist/models/Meta.js +3 -3
  23. package/dist/models/Meta.js.map +1 -1
  24. package/dist/models/Node.d.ts +4 -3
  25. package/dist/models/Node.d.ts.map +1 -1
  26. package/dist/models/Node.js +29 -23
  27. package/dist/models/Node.js.map +1 -1
  28. package/dist/models/Schema.d.ts.map +1 -1
  29. package/dist/models/Schema.js +27 -21
  30. package/dist/models/Schema.js.map +1 -1
  31. package/eslint.config.mjs +42 -0
  32. package/package.json +11 -1
  33. package/scripts/verify-build.js +95 -92
  34. package/src/config.ts +75 -75
  35. package/src/core/Decoder.ts +984 -922
  36. package/src/core/Encoder.ts +364 -371
  37. package/src/core/Parser.ts +112 -112
  38. package/src/index.ts +18 -20
  39. package/src/models/Meta.ts +107 -107
  40. package/src/models/Node.ts +190 -185
  41. package/src/models/Schema.ts +198 -193
  42. package/tests/00.meta.test.ts +19 -25
  43. package/tests/00.node.test.ts +40 -48
  44. package/tests/00.primitive.test.ts +121 -95
  45. package/tests/00.schema.test.ts +28 -35
  46. package/tests/01.schema.test.ts +42 -52
  47. package/tests/02.data.test.ts +69 -75
  48. package/tests/03.errors.test.ts +53 -55
  49. package/tests/04.list.test.ts +192 -193
  50. package/tests/05.record.test.ts +54 -56
  51. package/tests/06.meta.test.ts +393 -389
  52. package/tests/utils.ts +47 -44
  53. package/tsconfig.json +27 -29
  54. 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
- source: string | Node | any,
16
- expectedOutput: string,
17
- debug: boolean = false
16
+ source: string | Node | unknown,
17
+ expectedOutput: string,
18
+ debug: boolean = false,
18
19
  ): Node {
19
- let node: Node;
20
+ let node: Node;
20
21
 
21
- // 1. Prepare Node (if input is raw text)
22
- if (typeof source === 'string') {
23
- // Przekazujemy debug do decodera
24
- const res = decode(source, { debug });
25
-
26
- if (res.errors.length > 0) {
27
- console.error("Input decoding errors:", res.errors);
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
- // 2. First Encoding
36
- // Wymuszamy compact: true zgodnie z pythonowym oryginałem
37
- const encoded1 = encode(node, { compact: true });
38
+ // 2. First Encoding
39
+ // Wymuszamy compact: true zgodnie z pythonowym oryginałem
40
+ const encoded1 = encode(node, { compact: true });
38
41
 
39
- // Debug print to visualize differences in case of failure
40
- // (Vitest zrobi to automatycznie przy .toBe, ale zachowujemy logikę z Python)
41
- if (encoded1 !== expectedOutput) {
42
- console.log(`\n[ROUNDTRIP] Mismatch Pass 1:`);
43
- console.log(`EXPECTED: "${expectedOutput}"`);
44
- console.log(`ACTUAL: "${encoded1}"`);
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
- expect(encoded1).toBe(expectedOutput);
50
+ expect(encoded1).toBe(expectedOutput);
48
51
 
49
- // 3. Round Trip (Decode the result of the encoding)
50
- const res2 = decode(encoded1, { debug });
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
- // 4. Second Encoding (Idempotency Check)
58
- const encoded2 = encode(res2.node, { compact: true });
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
- if (encoded2 !== expectedOutput) {
61
- console.log(`\n[ROUNDTRIP] Mismatch Pass 2 (Consistency):`);
62
- console.log(`EXPECTED: "${expectedOutput}"`);
63
- console.log(`ACTUAL: "${encoded2}"`);
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
- expect(encoded2).toBe(expectedOutput);
69
+ expect(encoded2).toBe(expectedOutput);
67
70
 
68
- return node;
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", /* 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 */
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", /* 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) */
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, /* 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 */
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, /* 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
-
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, /* Report error for unused local variables */
32
- "noUnusedParameters": true, /* Report error for unused function parameters */
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 /* Skip type checking of declaration files (.d.ts) in external libs */
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", /* Do not include tests in the production build */
41
+ "**/*.test.ts" /* Do not include tests in the production build */,
44
42
  "**/*.spec.ts"
45
43
  ]
46
- }
44
+ }
package/vitest.config.ts CHANGED
@@ -6,4 +6,4 @@ export default defineConfig({
6
6
  globals: false,
7
7
  environment: 'node',
8
8
  },
9
- });
9
+ });