@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
@@ -3,80 +3,78 @@ import { decode } from '../src/index';
3
3
  import { assertRoundtrip } from './utils';
4
4
 
5
5
  describe('AK Data Record Handling', () => {
6
+ // ==============================================================================
7
+ // 1. SCHEMA DEFINITION META (Types defined in < ... >)
8
+ // ==============================================================================
6
9
 
7
- // ==============================================================================
8
- // 1. SCHEMA DEFINITION META (Types defined in < ... >)
9
- // ==============================================================================
10
-
11
- it('should handle different type in record', () => {
12
- const akdText = `
10
+ it('should handle different type in record', () => {
11
+ const akdText = `
13
12
  <
14
13
  id: number
15
14
  >
16
15
  ( ["text"] )
17
16
  `;
18
17
 
19
- const result = decode(akdText, { debug: false });
20
- const node = result.node;
21
- expect(result.errors).toHaveLength(0);
22
-
23
- // 1. Check Record Meta (Outer)
24
- expect(node.isRecord).toBe(true);
18
+ const result = decode(akdText, { debug: false });
19
+ const node = result.node;
20
+ expect(result.errors).toHaveLength(0);
21
+
22
+ // 1. Check Record Meta (Outer)
23
+ expect(node.isRecord).toBe(true);
24
+
25
+ const expected = '<id:number>(<[string]> ["text"])';
26
+ assertRoundtrip(node, expected, false);
27
+ });
25
28
 
26
- const expected = '<id:number>(<[string]> ["text"])';
27
- assertRoundtrip(node, expected, false);
28
- });
29
+ it('should handle simple types', () => {
30
+ // Input is a raw AKD format string representing a dictionary
31
+ const akdText = '{ a:"a", b:"b", c:"c", d: 3 }';
29
32
 
30
- it('should handle simple types', () => {
31
- // Input is a raw AKD format string representing a dictionary
32
- const akdText = '{ a:"a", b:"b", c:"c", d: 3 }';
33
-
34
- // The parser infers the schema from the keys/values.
35
- // The encoder then outputs the inferred schema and converts the named record
36
- // to a positional one because a schema exists.
37
- const expected = '<a:string,b:string,c:string,d:number>("a","b","c",3)';
38
-
39
- assertRoundtrip(akdText, expected, false);
40
- });
33
+ // The parser infers the schema from the keys/values.
34
+ // The encoder then outputs the inferred schema and converts the named record
35
+ // to a positional one because a schema exists.
36
+ const expected = '<a:string,b:string,c:string,d:number>("a","b","c",3)';
41
37
 
42
- it('should handle record named type mismatch', () => {
43
- /**
44
- * Tests a scenario where a record field has a defined type (e.g., string),
45
- * but the actual value inside is of a different type (e.g., int).
46
- *
47
- * This ensures that the encodeRecord method uses applyTypeTag correctly.
48
- *
49
- * Schema: <tests: string>
50
- * Data: { tests: 3 }
51
- * Expected Output: ... (<number> 3)
52
- */
53
- const akdText = `
38
+ assertRoundtrip(akdText, expected, false);
39
+ });
40
+
41
+ it('should handle record named type mismatch', () => {
42
+ /**
43
+ * Tests a scenario where a record field has a defined type (e.g., string),
44
+ * but the actual value inside is of a different type (e.g., int).
45
+ *
46
+ * This ensures that the encodeRecord method uses applyTypeTag correctly.
47
+ *
48
+ * Schema: <tests: string>
49
+ * Data: { tests: 3 }
50
+ * Expected Output: ... (<number> 3)
51
+ */
52
+ const akdText = `
54
53
  <tests: string>
55
54
  {
56
55
  tests: 3
57
56
  }
58
57
  `;
59
58
 
60
- const expected = '<tests:string>(<number> 3)';
61
- assertRoundtrip(akdText, expected, false);
62
- });
59
+ const expected = '<tests:string>(<number> 3)';
60
+ assertRoundtrip(akdText, expected, false);
61
+ });
63
62
 
64
- it('should handle record positional type mismatch', () => {
65
- /**
66
- * Tests a scenario where a positional record field has a defined type (e.g., string),
67
- * but the actual value inside is of a different type (e.g., int).
68
- *
69
- * Schema: <tests: string>
70
- * Data: (3)
71
- * Expected Output: ... (<number> 3)
72
- */
73
- const akdText = `
63
+ it('should handle record positional type mismatch', () => {
64
+ /**
65
+ * Tests a scenario where a positional record field has a defined type (e.g., string),
66
+ * but the actual value inside is of a different type (e.g., int).
67
+ *
68
+ * Schema: <tests: string>
69
+ * Data: (3)
70
+ * Expected Output: ... (<number> 3)
71
+ */
72
+ const akdText = `
74
73
  <tests: string>
75
74
  (3)
76
75
  `;
77
76
 
78
- const expected = '<tests:string>(<number> 3)';
79
- assertRoundtrip(akdText, expected, false);
80
- });
81
-
82
- });
77
+ const expected = '<tests:string>(<number> 3)';
78
+ assertRoundtrip(akdText, expected, false);
79
+ });
80
+ });