@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.
- package/.prettierrc +8 -0
- package/README.md +159 -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/05.record.test.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const expected = '<tests:string>(<number> 3)';
|
|
60
|
+
assertRoundtrip(akdText, expected, false);
|
|
61
|
+
});
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
77
|
+
const expected = '<tests:string>(<number> 3)';
|
|
78
|
+
assertRoundtrip(akdText, expected, false);
|
|
79
|
+
});
|
|
80
|
+
});
|