functionalscript 0.45.0 → 0.46.0
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/README.md +5 -3
- package/fjs/asn.1/module.f.mjs +8 -1
- package/fjs/asn.1/proof.f.d.mts +10 -0
- package/fjs/asn.1/proof.f.mjs +16 -0
- package/fjs/basen/base128/module.f.mjs +22 -5
- package/fjs/bnf/data/module.f.d.mts +32 -6
- package/fjs/bnf/data/module.f.mjs +112 -7
- package/fjs/bnf/data/proof.f.d.mts +2 -0
- package/fjs/bnf/data/proof.f.mjs +74 -3
- package/fjs/bnf/data/types.d.ts +20 -2
- package/fjs/bnf/descent/module.f.d.mts +28 -14
- package/fjs/bnf/descent/module.f.mjs +122 -77
- package/fjs/bnf/descent/proof.f.d.mts +2 -0
- package/fjs/bnf/descent/proof.f.mjs +117 -31
- package/fjs/bnf/descent/types.d.ts +12 -14
- package/fjs/bnf/ll1/module.f.d.mts +64 -22
- package/fjs/bnf/ll1/module.f.mjs +214 -154
- package/fjs/bnf/ll1/proof.f.d.mts +15 -2
- package/fjs/bnf/ll1/proof.f.mjs +323 -149
- package/fjs/bnf/ll1/types.d.ts +16 -24
- package/fjs/bnf/matcher/module.f.d.mts +66 -0
- package/fjs/bnf/matcher/module.f.mjs +81 -0
- package/fjs/bnf/matcher/proof.f.d.mts +10 -0
- package/fjs/bnf/matcher/proof.f.mjs +79 -0
- package/fjs/bnf/matcher/types.d.ts +54 -0
- package/fjs/bnf/testlib.f.d.mts +31 -0
- package/fjs/bnf/testlib.f.mjs +80 -0
- package/fjs/cas/cli/module.f.d.mts +1 -1
- package/fjs/cas/cli/module.f.mjs +14 -20
- package/fjs/cas/cli/proof.f.d.mts +1 -3
- package/fjs/cas/cli/proof.f.mjs +44 -33
- package/fjs/cas/evo/module.f.d.mts +64 -18
- package/fjs/cas/evo/module.f.mjs +148 -70
- package/fjs/cas/evo/proof.f.d.mts +10 -1
- package/fjs/cas/evo/proof.f.mjs +305 -223
- package/fjs/cas/evo/types.d.ts +45 -9
- package/fjs/cas/module.f.d.mts +18 -32
- package/fjs/cas/module.f.mjs +129 -128
- package/fjs/cas/proof.f.d.mts +11 -8
- package/fjs/cas/proof.f.mjs +259 -147
- package/fjs/cas/types.d.ts +24 -10
- package/fjs/ci/config/module.f.d.mts +2 -2
- package/fjs/ci/config/module.f.mjs +2 -2
- package/fjs/ci/module.f.d.mts +5 -5
- package/fjs/ci/module.f.mjs +8 -7
- package/fjs/ci/nix/module.f.d.mts +7 -5
- package/fjs/ci/nix/module.f.mjs +13 -12
- package/fjs/ci/nix/proof.f.mjs +2 -2
- package/fjs/ci/proof.f.mjs +9 -5
- package/fjs/cli/module.f.d.mts +4 -6
- package/fjs/cli/module.f.mjs +4 -8
- package/fjs/cli/proof.f.mjs +17 -16
- package/fjs/cli/types.d.ts +2 -3
- package/fjs/common/monoid/types.d.ts +1 -1
- package/fjs/crypto/hmac/module.f.mjs +2 -2
- package/fjs/crypto/sha2/module.f.mjs +3 -1
- package/fjs/crypto/sha2/proof.f.d.mts +1 -0
- package/fjs/crypto/sha2/proof.f.mjs +24 -0
- package/fjs/crypto/sha2/types.d.ts +11 -0
- package/fjs/crypto/sign/module.f.mjs +2 -2
- package/fjs/dev/module.f.d.mts +13 -4
- package/fjs/dev/module.f.mjs +56 -27
- package/fjs/dev/update/module.f.d.mts +9 -4
- package/fjs/dev/update/module.f.mjs +14 -10
- package/fjs/dev/update/proof.f.d.mts +1 -3
- package/fjs/dev/update/proof.f.mjs +10 -5
- package/fjs/djs/module.f.d.mts +13 -5
- package/fjs/djs/module.f.mjs +31 -16
- package/fjs/djs/parser/module.f.d.mts +13 -3
- package/fjs/djs/parser/module.f.mjs +117 -16
- package/fjs/djs/parser/proof.f.d.mts +5 -1
- package/fjs/djs/parser/proof.f.mjs +274 -12
- package/fjs/djs/parser/types.d.ts +7 -1
- package/fjs/djs/proof.f.d.mts +18 -2
- package/fjs/djs/proof.f.mjs +187 -12
- package/fjs/djs/serializer/module.f.d.mts +25 -8
- package/fjs/djs/serializer/module.f.mjs +61 -15
- package/fjs/djs/serializer/proof.f.d.mts +5 -0
- package/fjs/djs/serializer/proof.f.mjs +23 -1
- package/fjs/djs/tokenizer/module.f.d.mts +17 -5
- package/fjs/djs/tokenizer/module.f.mjs +99 -60
- package/fjs/djs/tokenizer/proof.f.d.mts +1 -1
- package/fjs/djs/tokenizer/proof.f.mjs +74 -67
- package/fjs/djs/transpiler/module.f.d.mts +12 -7
- package/fjs/djs/transpiler/module.f.mjs +82 -56
- package/fjs/djs/transpiler/types.d.ts +7 -3
- package/fjs/djs/types.d.ts +7 -1
- package/fjs/effects/list/module.f.d.mts +14 -11
- package/fjs/effects/list/module.f.mjs +13 -11
- package/fjs/effects/list/types.d.ts +27 -7
- package/fjs/effects/memory/module.f.d.mts +2 -1
- package/fjs/effects/memory/module.f.mjs +3 -4
- package/fjs/effects/memory/proof.f.mjs +13 -7
- package/fjs/effects/memory/types.d.ts +4 -3
- package/fjs/effects/mock/module.f.d.mts +20 -4
- package/fjs/effects/mock/module.f.mjs +37 -5
- package/fjs/effects/mock/types.d.ts +10 -1
- package/fjs/effects/module.d.mts +4 -2
- package/fjs/effects/module.f.d.mts +466 -280
- package/fjs/effects/module.f.mjs +537 -299
- package/fjs/effects/module.mjs +2 -1
- package/fjs/effects/node/memory/module.d.mts +4 -2
- package/fjs/effects/node/memory/module.mjs +6 -3
- package/fjs/effects/node/memory/proof.mjs +10 -4
- package/fjs/effects/node/module.d.mts +4 -3
- package/fjs/effects/node/module.f.d.mts +168 -33
- package/fjs/effects/node/module.f.mjs +256 -52
- package/fjs/effects/node/module.mjs +57 -34
- package/fjs/effects/node/proof.f.d.mts +28 -2
- package/fjs/effects/node/proof.f.mjs +161 -42
- package/fjs/effects/node/types.d.ts +106 -18
- package/fjs/effects/node/virtual/module.f.d.mts +18 -4
- package/fjs/effects/node/virtual/module.f.mjs +110 -68
- package/fjs/effects/node/virtual/proof.f.d.mts +28 -2
- package/fjs/effects/node/virtual/proof.f.mjs +190 -9
- package/fjs/effects/proof.f.d.mts +69 -37
- package/fjs/effects/proof.f.mjs +410 -130
- package/fjs/effects/types.d.ts +161 -33
- package/fjs/emergent_testing/module.f.d.mts +19 -12
- package/fjs/emergent_testing/module.f.mjs +93 -33
- package/fjs/emergent_testing/proof.f.d.mts +21 -7
- package/fjs/emergent_testing/proof.f.mjs +166 -32
- package/fjs/emergent_testing/types.d.ts +22 -4
- package/fjs/fsm/module.f.d.mts +14 -4
- package/fjs/fsm/module.f.mjs +54 -37
- package/fjs/fsm/proof.f.d.mts +2 -0
- package/fjs/fsm/proof.f.mjs +83 -114
- package/fjs/js/keywords/module.f.d.mts +52 -0
- package/fjs/js/keywords/module.f.mjs +72 -0
- package/fjs/js/keywords/proof.f.d.mts +3 -0
- package/fjs/js/keywords/proof.f.mjs +13 -0
- package/fjs/js/tokenizer/module.f.d.mts +26 -6
- package/fjs/js/tokenizer/module.f.mjs +145 -159
- package/fjs/js/tokenizer/proof.f.d.mts +1 -0
- package/fjs/js/tokenizer/proof.f.mjs +54 -24
- package/fjs/js/tokenizer/types.d.ts +33 -24
- package/fjs/mcp/cas/module.f.d.mts +1 -6
- package/fjs/mcp/cas/module.f.mjs +55 -51
- package/fjs/mcp/cas/proof.f.d.mts +15 -0
- package/fjs/mcp/cas/proof.f.mjs +174 -0
- package/fjs/mcp/evo/module.f.d.mts +19 -10
- package/fjs/mcp/evo/module.f.mjs +48 -27
- package/fjs/mcp/evo/proof.f.d.mts +6 -1
- package/fjs/mcp/evo/proof.f.mjs +115 -31
- package/fjs/mcp/module.f.d.mts +4 -4
- package/fjs/mcp/module.f.mjs +6 -6
- package/fjs/mcp/proof.f.d.mts +5 -3
- package/fjs/mcp/proof.f.mjs +112 -46
- package/fjs/media/html/module.f.mjs +1 -1
- package/fjs/media/json/extended/module.f.d.mts +82 -0
- package/fjs/media/json/extended/module.f.mjs +153 -0
- package/fjs/media/json/extended/proof.f.d.mts +42 -0
- package/fjs/media/json/extended/proof.f.mjs +127 -0
- package/fjs/media/json/extended/types.d.ts +23 -0
- package/fjs/media/json/module.f.d.mts +8 -2
- package/fjs/media/json/module.f.mjs +43 -41
- package/fjs/media/json/number/module.f.d.mts +59 -0
- package/fjs/media/json/number/module.f.mjs +136 -0
- package/fjs/media/json/number/proof.f.d.mts +24 -0
- package/fjs/media/json/number/proof.f.mjs +86 -0
- package/fjs/media/json/number/types.d.ts +28 -0
- package/fjs/media/json/parser/module.f.d.mts +25 -13
- package/fjs/media/json/parser/module.f.mjs +114 -70
- package/fjs/media/json/parser/proof.f.d.mts +5 -0
- package/fjs/media/json/parser/proof.f.mjs +31 -1
- package/fjs/media/json/parser/types.d.ts +33 -14
- package/fjs/media/json/rtti/module.f.d.mts +1 -1
- package/fjs/media/json/rtti/module.f.mjs +1 -1
- package/fjs/media/json/rtti/proof.f.mjs +9 -9
- package/fjs/media/json/schema/module.f.mjs +3 -13
- package/fjs/media/json/schema/proof.f.d.mts +0 -1
- package/fjs/media/json/schema/proof.f.mjs +1 -2
- package/fjs/media/json/serializer/module.f.d.mts +32 -1
- package/fjs/media/json/serializer/module.f.mjs +64 -2
- package/fjs/media/json/tokenizer/module.f.mjs +7 -3
- package/fjs/media/json/tokenizer/proof.f.d.mts +6 -0
- package/fjs/media/json/tokenizer/proof.f.mjs +62 -21
- package/fjs/media/json/types.d.ts +36 -10
- package/fjs/media/lock/module.f.d.mts +100 -0
- package/fjs/media/lock/module.f.mjs +125 -0
- package/fjs/media/lock/proof.f.d.mts +33 -0
- package/fjs/media/lock/proof.f.mjs +196 -0
- package/fjs/media/lock/types.d.ts +15 -0
- package/fjs/media/module.f.d.mts +6 -5
- package/fjs/media/module.f.mjs +8 -7
- package/fjs/media/note/module.f.d.mts +121 -0
- package/fjs/media/note/module.f.mjs +131 -0
- package/fjs/media/note/proof.f.d.mts +29 -0
- package/fjs/media/note/proof.f.mjs +150 -0
- package/fjs/media/note/types.d.ts +10 -0
- package/fjs/media/proof.f.d.mts +4 -1
- package/fjs/media/proof.f.mjs +40 -21
- package/fjs/media/revision/module.f.d.mts +78 -7
- package/fjs/media/revision/module.f.mjs +119 -12
- package/fjs/media/revision/proof.f.d.mts +10 -0
- package/fjs/media/revision/proof.f.mjs +88 -0
- package/fjs/media/revision/types.d.ts +34 -5
- package/fjs/media/type/module.f.d.mts +33 -15
- package/fjs/media/type/module.f.mjs +35 -29
- package/fjs/media/type/proof.f.d.mts +2 -1
- package/fjs/media/type/proof.f.mjs +30 -10
- package/fjs/module.f.mjs +29 -8
- package/fjs/nanvm/proof.f.mjs +3 -3
- package/fjs/nanvm/rust/module.f.mjs +1 -1
- package/fjs/nanvm/update/module.f.d.mts +4 -4
- package/fjs/nanvm/update/module.f.mjs +8 -9
- package/fjs/nanvm/update/proof.f.mjs +4 -3
- package/fjs/proof.f.d.mts +3 -3
- package/fjs/proof.f.mjs +36 -10
- package/fjs/protocol/json_rpc/module.f.d.mts +2 -2
- package/fjs/protocol/json_rpc/module.f.mjs +3 -3
- package/fjs/protocol/json_rpc/proof.f.mjs +4 -4
- package/fjs/protocol/mcp/module.f.d.mts +10 -13
- package/fjs/protocol/mcp/module.f.mjs +74 -58
- package/fjs/protocol/mcp/proof.f.d.mts +13 -4
- package/fjs/protocol/mcp/proof.f.mjs +193 -61
- package/fjs/protocol/mcp/stdio/module.f.d.mts +15 -7
- package/fjs/protocol/mcp/stdio/module.f.mjs +38 -25
- package/fjs/protocol/mcp/stdio/proof.f.d.mts +4 -2
- package/fjs/protocol/mcp/stdio/proof.f.mjs +45 -12
- package/fjs/protocol/mcp/stdio/types.d.ts +1 -1
- package/fjs/protocol/mcp/types.d.ts +17 -6
- package/fjs/sul/id/module.f.d.mts +0 -1
- package/fjs/sul/id/module.f.mjs +2 -3
- package/fjs/sul/level/hash/module.f.mjs +2 -1
- package/fjs/sul/level/hash/proof.f.mjs +2 -2
- package/fjs/sul/module.f.mjs +18 -13
- package/fjs/text/code_point/module.f.d.mts +8 -0
- package/fjs/text/code_point/module.f.mjs +8 -1
- package/fjs/text/code_point/proof.f.d.mts +1 -0
- package/fjs/text/code_point/proof.f.mjs +11 -0
- package/fjs/text/sgr/module.f.d.mts +4 -6
- package/fjs/text/sgr/module.f.mjs +6 -7
- package/fjs/text/utf16/module.f.mjs +7 -2
- package/fjs/text/utf16/proof.f.mjs +3 -3
- package/fjs/text/utf8/module.f.mjs +4 -2
- package/fjs/types/array/module.f.mjs +14 -2
- package/fjs/types/bit_vec/module.f.d.mts +0 -2
- package/fjs/types/bit_vec/module.f.mjs +46 -32
- package/fjs/types/bit_vec/proof.f.mjs +2 -2
- package/fjs/types/btree/remove/module.f.mjs +1 -1
- package/fjs/types/btree/set/module.f.mjs +9 -11
- package/fjs/types/btree/set/proof.f.mjs +12 -0
- package/fjs/types/byte_set/module.f.d.mts +11 -4
- package/fjs/types/byte_set/module.f.mjs +14 -6
- package/fjs/types/byte_set/proof.f.mjs +7 -7
- package/fjs/types/function/compare/module.f.mjs +10 -3
- package/fjs/types/list/module.f.d.mts +1 -1
- package/fjs/types/list/module.f.mjs +1 -1
- package/fjs/types/nullable/module.f.d.mts +18 -4
- package/fjs/types/nullable/module.f.mjs +21 -4
- package/fjs/types/nullable/proof.f.d.mts +4 -0
- package/fjs/types/nullable/proof.f.mjs +15 -0
- package/fjs/types/object/module.f.d.mts +12 -2
- package/fjs/types/object/module.f.mjs +11 -1
- package/fjs/types/patricia_trie/module.f.mjs +26 -11
- package/fjs/types/result/module.f.d.mts +3 -3
- package/fjs/types/result/module.f.mjs +3 -3
- package/fjs/types/rtti/common/module.f.d.mts +25 -28
- package/fjs/types/rtti/common/module.f.mjs +36 -32
- package/fjs/types/rtti/common/proof.f.mjs +5 -5
- package/fjs/types/rtti/data/module.f.d.mts +14 -0
- package/fjs/types/rtti/data/module.f.mjs +25 -2
- package/fjs/types/rtti/data/proof.f.d.mts +1 -0
- package/fjs/types/rtti/data/proof.f.mjs +25 -2
- package/fjs/types/rtti/parse/module.f.d.mts +24 -14
- package/fjs/types/rtti/parse/module.f.mjs +37 -28
- package/fjs/types/rtti/parse/proof.f.d.mts +3 -2
- package/fjs/types/rtti/parse/proof.f.mjs +33 -14
- package/fjs/types/rtti/proof.f.mjs +3 -1
- package/fjs/types/rtti/ts/module.f.mjs +13 -17
- package/fjs/types/rtti/ts/types.d.ts +14 -1
- package/fjs/types/sorted_set/module.f.d.mts +18 -0
- package/fjs/types/sorted_set/module.f.mjs +22 -0
- package/fjs/types/sorted_set/proof.f.d.mts +1 -0
- package/fjs/types/sorted_set/proof.f.mjs +16 -1
- package/fjs/types/uint8array/module.f.d.mts +1 -1
- package/fjs/types/uint8array/module.f.mjs +1 -1
- package/fjs/website/module.f.d.mts +3 -3
- package/fjs/website/module.f.mjs +4 -7
- package/fjs/website/proof.f.mjs +2 -1
- package/package.json +2 -2
- package/fjs/dev/package_json/module.f.d.mts +0 -39
- package/fjs/dev/package_json/module.f.mjs +0 -40
- package/fjs/dev/package_json/proof.f.d.mts +0 -6
- package/fjs/dev/package_json/proof.f.mjs +0 -32
- package/fjs/effects/eff/module.f.d.mts +0 -20
- package/fjs/effects/eff/module.f.mjs +0 -70
- package/fjs/effects/eff/proof.f.d.mts +0 -15
- package/fjs/effects/eff/proof.f.mjs +0 -69
- package/fjs/effects/eff/types.d.ts +0 -71
- package/fjs/types/rtti/validate/module.f.d.mts +0 -41
- package/fjs/types/rtti/validate/module.f.mjs +0 -171
- package/fjs/types/rtti/validate/proof.f.d.mts +0 -125
- package/fjs/types/rtti/validate/proof.f.mjs +0 -437
- package/fjs/types/rtti/validate/types.d.ts +0 -6
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TypeScript counterparts of the JSON data model: `Primitive`, `Unknown`,
|
|
3
|
-
* `Object`, and `Array
|
|
3
|
+
* `Object`, and `Array`, plus the leaf-parameterized `Tree` they instantiate.
|
|
4
4
|
*
|
|
5
5
|
* `Unknown` is written by hand rather than derived, so that the recursion
|
|
6
6
|
* reads directly, and is then pinned against the rtti schemas in the sibling
|
|
7
7
|
* [`./rtti/module.f.mjs`](./rtti/module.f.mjs) with
|
|
8
8
|
* `Assert<Equal<Unknown, Ts<typeof unknown>>>`. The pin is what keeps the two
|
|
9
|
-
* descriptions of the same data model from drifting apart
|
|
9
|
+
* descriptions of the same data model from drifting apart — and it holds the
|
|
10
|
+
* `Tree<Primitive>` spelling to the same data model the schemas describe.
|
|
10
11
|
*
|
|
11
12
|
* @module
|
|
12
13
|
*/
|
|
@@ -14,12 +15,37 @@ import type { Entry as ObjectEntry } from '../../types/object/types.ts';
|
|
|
14
15
|
import type { Ts } from '../../types/rtti/ts/types.ts';
|
|
15
16
|
import type { primitive } from './rtti/module.f.mjs';
|
|
16
17
|
import type { List } from '../../types/list/types.ts';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A recursive JSON-shaped tree over a leaf type `P`: JSON's container
|
|
20
|
+
* structure with its primitive set left open.
|
|
21
|
+
*
|
|
22
|
+
* The parser and the serializer are written once against this shape and are
|
|
23
|
+
* instantiated per numeric policy — `Tree<Primitive>` is ordinary JSON,
|
|
24
|
+
* `Tree<ExtendedPrimitive>` (see
|
|
25
|
+
* [`./extended/types.ts`](./extended/types.ts)) adds `bigint` to the leaves.
|
|
26
|
+
*
|
|
27
|
+
* `TreeObject`'s index signature is **optional** on purpose: reading an
|
|
28
|
+
* arbitrary key off a JSON-shaped object yields `undefined` when the property
|
|
29
|
+
* is absent, and `undefined` is not a leaf of any of these trees. A required
|
|
30
|
+
* index signature would type every missing property as a value.
|
|
31
|
+
*/
|
|
32
|
+
export type Tree<P> = P | TreeObject<P> | TreeArray<P>;
|
|
33
|
+
export type TreeObject<P> = {
|
|
34
|
+
readonly [k in string]?: Tree<P>;
|
|
21
35
|
};
|
|
22
|
-
export type
|
|
23
|
-
export type
|
|
24
|
-
export type
|
|
25
|
-
export type
|
|
36
|
+
export type TreeArray<P> = readonly Tree<P>[];
|
|
37
|
+
export type Primitive = Ts<typeof primitive>;
|
|
38
|
+
export type Unknown = Tree<Primitive>;
|
|
39
|
+
export type Object = TreeObject<Primitive>;
|
|
40
|
+
export type Array = TreeArray<Primitive>;
|
|
41
|
+
export type TreeEntry<P> = ObjectEntry<Tree<P>>;
|
|
42
|
+
export type TreeEntries<P> = List<TreeEntry<P>>;
|
|
43
|
+
/**
|
|
44
|
+
* How a serializer orders an object's entries — `sort` for canonical output,
|
|
45
|
+
* `identity` to keep insertion order. It is a per-leaf-type alias only because
|
|
46
|
+
* the entries it reorders carry the tree's own leaves.
|
|
47
|
+
*/
|
|
48
|
+
export type TreeMapEntries<P> = (entries: TreeEntries<P>) => TreeEntries<P>;
|
|
49
|
+
export type Entry = TreeEntry<Primitive>;
|
|
50
|
+
export type _Entries = TreeEntries<Primitive>;
|
|
51
|
+
export type _MapEntries = TreeMapEntries<Primitive>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vnd.fjs.lock` — a lock map as a BLOB of its own, so several revisions can
|
|
3
|
+
* point at one agreed resolution instead of each carrying a copy.
|
|
4
|
+
*
|
|
5
|
+
* `vnd.fjs.revision`'s `lock` is an inline map, which keeps a revision
|
|
6
|
+
* interpretable in isolation but re-serializes the whole map into a new blob
|
|
7
|
+
* every time anything else about the revision changes — CAS deduplicates whole
|
|
8
|
+
* blobs, not fragments. This dialect is that map, alone: no `subject`,
|
|
9
|
+
* `parents`, `generation`, or `archived`, because it is a **value**, not a
|
|
10
|
+
* step. History for lock content, when someone wants it, is an ordinary
|
|
11
|
+
* revision whose `snapshot` is one of these blobs, so no second history
|
|
12
|
+
* mechanism appears and `revision` stays the only one.
|
|
13
|
+
*
|
|
14
|
+
* The `lock` schema and its semantic check are **imported** from
|
|
15
|
+
* `fjs/media/revision`, not restated: one recursive schema, one hash check,
|
|
16
|
+
* one canonical serialization, so a map means the same thing inline and shared
|
|
17
|
+
* and the two forms cannot drift (`proof.f.mjs` pins the bytes).
|
|
18
|
+
*
|
|
19
|
+
* Like its sibling, this module is the pure format only: the rtti schema, the
|
|
20
|
+
* `dialect` tag, and decode/validate. Whether a referenced blob exists, and
|
|
21
|
+
* what its bindings mean once fetched, stay a resolver's business.
|
|
22
|
+
*
|
|
23
|
+
* See `README.md` for the full spec.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*
|
|
27
|
+
* @import { Unknown } from '../json/types.ts'
|
|
28
|
+
* @import { Result } from '../../types/result/types.ts'
|
|
29
|
+
* @import { DialectEntry } from '../types.ts'
|
|
30
|
+
* @import { Lock, LockError } from './types.ts'
|
|
31
|
+
*/
|
|
32
|
+
import type { Unknown } from '../json/types.ts';
|
|
33
|
+
import type { Result } from '../../types/result/types.ts';
|
|
34
|
+
import type { DialectEntry } from '../types.ts';
|
|
35
|
+
import type { Lock, LockError } from './types.ts';
|
|
36
|
+
/**
|
|
37
|
+
* Format tag: names the dialect of this BLOB. The media type it is served
|
|
38
|
+
* with is derived mechanically: `application/` + `dialect` + `+json`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const dialect: 'vnd.fjs.lock';
|
|
41
|
+
/** The media type derived from {@link dialect}: `application/vnd.fjs.lock+json`. */
|
|
42
|
+
export declare const mediaType: "application/vnd.fjs.lock+json";
|
|
43
|
+
/**
|
|
44
|
+
* rtti schema for a `lock` BLOB: the dialect tag and the map, nothing else.
|
|
45
|
+
*
|
|
46
|
+
* `lock` is `fjs/media/revision`'s own schema, so the shared form admits
|
|
47
|
+
* exactly the maps the inline form does, to the same depth, with the same
|
|
48
|
+
* value domain.
|
|
49
|
+
*
|
|
50
|
+
* The field is **required** and may be `{}`: an absent map and an empty one
|
|
51
|
+
* would otherwise be two spellings of one blob, and a blob whose only purpose
|
|
52
|
+
* is to hold a map has nothing to say when it does not. It is also never a
|
|
53
|
+
* hash — a lock blob does not reference further lock blobs (see the README's
|
|
54
|
+
* [Composition](./README.md#composition)), so following a reference always
|
|
55
|
+
* terminates in one step.
|
|
56
|
+
*/
|
|
57
|
+
export declare const lockSchema: {
|
|
58
|
+
readonly dialect: "vnd.fjs.lock";
|
|
59
|
+
readonly lock: import("../revision/types.ts").LockSchema;
|
|
60
|
+
};
|
|
61
|
+
/** Serializes a lock blob canonically, recursively sorting every object's property names.
|
|
62
|
+
* @type {(lock: Lock) => string}
|
|
63
|
+
*/
|
|
64
|
+
export declare const encodeText: (lock: Lock) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Checks the semantic refinement the structural schema can't express on an
|
|
67
|
+
* already shape-valid lock blob: every direct value at every depth of the map
|
|
68
|
+
* must decode as a cbase32 hash. This is `fjs/media/revision`'s own
|
|
69
|
+
* `lockMapError`, so a map rejected inline is rejected here and vice versa.
|
|
70
|
+
*
|
|
71
|
+
* Exported separately from {@link validate} for callers holding an
|
|
72
|
+
* already-typed `Lock` — the same split, for the same reason, as the revision
|
|
73
|
+
* dialect's `checkReferences`.
|
|
74
|
+
*
|
|
75
|
+
* @type {(l: Lock) => Result<Lock, string>}
|
|
76
|
+
*/
|
|
77
|
+
export declare const checkReferences: (l: Lock) => Result<Lock, string>;
|
|
78
|
+
/**
|
|
79
|
+
* Validates an already-parsed JSON value as a `lock` BLOB: structural (rtti)
|
|
80
|
+
* validation followed by the hash semantic check.
|
|
81
|
+
*
|
|
82
|
+
* @type {(value: Unknown) => Result<Lock, LockError>}
|
|
83
|
+
*/
|
|
84
|
+
export declare const validate: (value: Unknown) => Result<Lock, LockError>;
|
|
85
|
+
/**
|
|
86
|
+
* Decodes `text` as a `lock` BLOB: JSON-parses it, then validates it per
|
|
87
|
+
* {@link validate}. Detection is semantic, not syntactic — any JSON that
|
|
88
|
+
* satisfies the schema is a lock blob, regardless of key order or whitespace.
|
|
89
|
+
*
|
|
90
|
+
* @type {(text: string) => Result<Lock, LockError>}
|
|
91
|
+
*/
|
|
92
|
+
export declare const decodeText: (text: string) => Result<Lock, LockError>;
|
|
93
|
+
/**
|
|
94
|
+
* This dialect as a registry entry for `fjs/media`'s `detect`. It carries the
|
|
95
|
+
* semantic check too, so a blob is detected as `vnd.fjs.lock` exactly when
|
|
96
|
+
* {@link decodeText} would accept it.
|
|
97
|
+
*
|
|
98
|
+
* @type {DialectEntry}
|
|
99
|
+
*/
|
|
100
|
+
export declare const lockDialect: DialectEntry;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `vnd.fjs.lock` — a lock map as a BLOB of its own, so several revisions can
|
|
3
|
+
* point at one agreed resolution instead of each carrying a copy.
|
|
4
|
+
*
|
|
5
|
+
* `vnd.fjs.revision`'s `lock` is an inline map, which keeps a revision
|
|
6
|
+
* interpretable in isolation but re-serializes the whole map into a new blob
|
|
7
|
+
* every time anything else about the revision changes — CAS deduplicates whole
|
|
8
|
+
* blobs, not fragments. This dialect is that map, alone: no `subject`,
|
|
9
|
+
* `parents`, `generation`, or `archived`, because it is a **value**, not a
|
|
10
|
+
* step. History for lock content, when someone wants it, is an ordinary
|
|
11
|
+
* revision whose `snapshot` is one of these blobs, so no second history
|
|
12
|
+
* mechanism appears and `revision` stays the only one.
|
|
13
|
+
*
|
|
14
|
+
* The `lock` schema and its semantic check are **imported** from
|
|
15
|
+
* `fjs/media/revision`, not restated: one recursive schema, one hash check,
|
|
16
|
+
* one canonical serialization, so a map means the same thing inline and shared
|
|
17
|
+
* and the two forms cannot drift (`proof.f.mjs` pins the bytes).
|
|
18
|
+
*
|
|
19
|
+
* Like its sibling, this module is the pure format only: the rtti schema, the
|
|
20
|
+
* `dialect` tag, and decode/validate. Whether a referenced blob exists, and
|
|
21
|
+
* what its bindings mean once fetched, stay a resolver's business.
|
|
22
|
+
*
|
|
23
|
+
* See `README.md` for the full spec.
|
|
24
|
+
*
|
|
25
|
+
* @module
|
|
26
|
+
*
|
|
27
|
+
* @import { Unknown } from '../json/types.ts'
|
|
28
|
+
* @import { Result } from '../../types/result/types.ts'
|
|
29
|
+
* @import { DialectEntry } from '../types.ts'
|
|
30
|
+
* @import { Lock, LockError } from './types.ts'
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { parse as rttiParse } from '../../types/rtti/parse/module.f.mjs'
|
|
34
|
+
import { parse as parseJson, stringify } from '../json/module.f.mjs'
|
|
35
|
+
import { error, ok, okThen } from '../../types/result/module.f.mjs'
|
|
36
|
+
import { dialectEntry } from '../module.f.mjs'
|
|
37
|
+
import { sort } from '../../types/object/module.f.mjs'
|
|
38
|
+
import { lock, lockMapError } from '../revision/module.f.mjs'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Format tag: names the dialect of this BLOB. The media type it is served
|
|
42
|
+
* with is derived mechanically: `application/` + `dialect` + `+json`.
|
|
43
|
+
*/
|
|
44
|
+
export const dialect = /** @type {const} */ ('vnd.fjs.lock')
|
|
45
|
+
|
|
46
|
+
/** The media type derived from {@link dialect}: `application/vnd.fjs.lock+json`. */
|
|
47
|
+
export const mediaType = /** @type {const} */ (`application/${dialect}+json`)
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* rtti schema for a `lock` BLOB: the dialect tag and the map, nothing else.
|
|
51
|
+
*
|
|
52
|
+
* `lock` is `fjs/media/revision`'s own schema, so the shared form admits
|
|
53
|
+
* exactly the maps the inline form does, to the same depth, with the same
|
|
54
|
+
* value domain.
|
|
55
|
+
*
|
|
56
|
+
* The field is **required** and may be `{}`: an absent map and an empty one
|
|
57
|
+
* would otherwise be two spellings of one blob, and a blob whose only purpose
|
|
58
|
+
* is to hold a map has nothing to say when it does not. It is also never a
|
|
59
|
+
* hash — a lock blob does not reference further lock blobs (see the README's
|
|
60
|
+
* [Composition](./README.md#composition)), so following a reference always
|
|
61
|
+
* terminates in one step.
|
|
62
|
+
*/
|
|
63
|
+
export const lockSchema = /** @type {const} */ ({
|
|
64
|
+
dialect,
|
|
65
|
+
lock,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
/** Serializes a lock blob canonically, recursively sorting every object's property names.
|
|
69
|
+
* @type {(lock: Lock) => string}
|
|
70
|
+
*/
|
|
71
|
+
export const encodeText = stringify(sort)
|
|
72
|
+
|
|
73
|
+
/** Structural-only validator: checks the shape, not the hash semantics. */
|
|
74
|
+
const validateShape = rttiParse(lockSchema)
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Checks the semantic refinement the structural schema can't express on an
|
|
78
|
+
* already shape-valid lock blob: every direct value at every depth of the map
|
|
79
|
+
* must decode as a cbase32 hash. This is `fjs/media/revision`'s own
|
|
80
|
+
* `lockMapError`, so a map rejected inline is rejected here and vice versa.
|
|
81
|
+
*
|
|
82
|
+
* Exported separately from {@link validate} for callers holding an
|
|
83
|
+
* already-typed `Lock` — the same split, for the same reason, as the revision
|
|
84
|
+
* dialect's `checkReferences`.
|
|
85
|
+
*
|
|
86
|
+
* @type {(l: Lock) => Result<Lock, string>}
|
|
87
|
+
*/
|
|
88
|
+
export const checkReferences = l => {
|
|
89
|
+
const message = lockMapError(l.lock)
|
|
90
|
+
return message === null ? ok(l) : error(message)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Validates an already-parsed JSON value as a `lock` BLOB: structural (rtti)
|
|
95
|
+
* validation followed by the hash semantic check.
|
|
96
|
+
*
|
|
97
|
+
* @type {(value: Unknown) => Result<Lock, LockError>}
|
|
98
|
+
*/
|
|
99
|
+
export const validate = value => okThen(checkReferences)(validateShape(value))
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Decodes `text` as a `lock` BLOB: JSON-parses it, then validates it per
|
|
103
|
+
* {@link validate}. Detection is semantic, not syntactic — any JSON that
|
|
104
|
+
* satisfies the schema is a lock blob, regardless of key order or whitespace.
|
|
105
|
+
*
|
|
106
|
+
* @type {(text: string) => Result<Lock, LockError>}
|
|
107
|
+
*/
|
|
108
|
+
export const decodeText = text => okThen(validate)(parseJson(text))
|
|
109
|
+
|
|
110
|
+
/** {@link checkReferences} as the `boolean` refinement a {@link DialectEntry} takes.
|
|
111
|
+
* @type {(l: Lock) => boolean}
|
|
112
|
+
*/
|
|
113
|
+
const isValidLock = l => {
|
|
114
|
+
const [tag] = checkReferences(l)
|
|
115
|
+
return tag === 'ok'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* This dialect as a registry entry for `fjs/media`'s `detect`. It carries the
|
|
120
|
+
* semantic check too, so a blob is detected as `vnd.fjs.lock` exactly when
|
|
121
|
+
* {@link decodeText} would accept it.
|
|
122
|
+
*
|
|
123
|
+
* @type {DialectEntry}
|
|
124
|
+
*/
|
|
125
|
+
export const lockDialect = dialectEntry(lockSchema, isValidLock)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Object as JsonObject } from '../json/types.ts'
|
|
3
|
+
* @import { LockMap } from './types.ts'
|
|
4
|
+
*/
|
|
5
|
+
export declare const proof: {
|
|
6
|
+
dialectAndMediaType: () => void;
|
|
7
|
+
validate: {
|
|
8
|
+
flatMapAccepted: () => void;
|
|
9
|
+
emptyMapAccepted: () => void;
|
|
10
|
+
nestedMapAccepted: () => void;
|
|
11
|
+
missingLockRejected: () => void;
|
|
12
|
+
referenceLockRejected: () => void;
|
|
13
|
+
malformedMapRejected: () => void;
|
|
14
|
+
invalidHashRejected: () => void;
|
|
15
|
+
revisionFieldsIgnored: () => void;
|
|
16
|
+
revisionBlobRejected: () => void;
|
|
17
|
+
};
|
|
18
|
+
checkReferences: {
|
|
19
|
+
valid: () => void;
|
|
20
|
+
invalid: () => void;
|
|
21
|
+
};
|
|
22
|
+
decodeText: {
|
|
23
|
+
validJson: () => void;
|
|
24
|
+
keyOrderIndependent: () => void;
|
|
25
|
+
malformedJsonRejected: () => void;
|
|
26
|
+
ordinaryJsonRejected: () => void;
|
|
27
|
+
};
|
|
28
|
+
encodeText: {
|
|
29
|
+
recursivelySortsObjectsLexicographically: () => void;
|
|
30
|
+
equivalentOrdersConverge: () => void;
|
|
31
|
+
};
|
|
32
|
+
inlineAndSharedSerializeIdentically: () => void;
|
|
33
|
+
};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Object as JsonObject } from '../json/types.ts'
|
|
3
|
+
* @import { LockMap } from './types.ts'
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { assert, assertEq } from '../../asserts/module.f.mjs'
|
|
7
|
+
import { dialect, mediaType, checkReferences, validate, decodeText, encodeText } from './module.f.mjs'
|
|
8
|
+
import {
|
|
9
|
+
dialect as revisionDialect,
|
|
10
|
+
encodeText as revisionEncodeText,
|
|
11
|
+
validate as revisionValidate,
|
|
12
|
+
} from '../revision/module.f.mjs'
|
|
13
|
+
import { stringify } from '../json/module.f.mjs'
|
|
14
|
+
import { sort } from '../../types/object/module.f.mjs'
|
|
15
|
+
|
|
16
|
+
// Valid cbase32 hashes (round-tripped in fjs/basen/cbase32/proof.f.mjs): single
|
|
17
|
+
// cbase32 symbols, cheap to write inline here.
|
|
18
|
+
const h1 = '8'
|
|
19
|
+
const h2 = 'r'
|
|
20
|
+
|
|
21
|
+
/** A shape-valid lock blob holding `lock`.
|
|
22
|
+
* @type {(lock: JsonObject) => JsonObject}
|
|
23
|
+
*/
|
|
24
|
+
const lockOf = lock => ({ dialect, lock })
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The one map both forms are asked to carry — nested, so the claim covers
|
|
28
|
+
* every depth rather than just the top level.
|
|
29
|
+
* @type {LockMap}
|
|
30
|
+
*/
|
|
31
|
+
const sharedMap = { C: { D: h2, C: h1 }, B: { D: h1 } }
|
|
32
|
+
|
|
33
|
+
/** The canonical rendering of a lock map on its own, independent of either blob. */
|
|
34
|
+
const canonicalMap = stringify(sort)
|
|
35
|
+
|
|
36
|
+
export const proof = {
|
|
37
|
+
dialectAndMediaType: () => {
|
|
38
|
+
assertEq(dialect, 'vnd.fjs.lock')
|
|
39
|
+
assertEq(mediaType, 'application/vnd.fjs.lock+json')
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
validate: {
|
|
43
|
+
// The ordinary case: a flat map of subject-to-content bindings.
|
|
44
|
+
flatMapAccepted: () => {
|
|
45
|
+
const r = validate(lockOf({ dependency: h1 }))
|
|
46
|
+
assert(r[0] === 'ok', ['expected ok', r])
|
|
47
|
+
assertEq(r[1].lock.dependency, h1)
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
// An empty map is a lock blob that records no bindings — distinct from
|
|
51
|
+
// a revision omitting `lock`, and the reason the field is required.
|
|
52
|
+
emptyMapAccepted: () => {
|
|
53
|
+
const r = validate(lockOf({}))
|
|
54
|
+
assert(r[0] === 'ok', ['expected ok', r])
|
|
55
|
+
assertEq(Object.keys(r[1].lock).length, 0)
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// Nesting is the revision dialect's, unchanged: scopes to any depth.
|
|
59
|
+
nestedMapAccepted: () => {
|
|
60
|
+
const [t] = validate(lockOf({ B: { C: { D: { E: h1 } } }, empty: {} }))
|
|
61
|
+
assertEq(t, 'ok')
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// `lock` is required: a blob carrying only the tag is not one.
|
|
65
|
+
missingLockRejected: () => {
|
|
66
|
+
const [t] = validate({ dialect })
|
|
67
|
+
assertEq(t, 'error')
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// The field is a map, never a hash — a lock blob does not reference
|
|
71
|
+
// further lock blobs, so following a reference terminates in one step.
|
|
72
|
+
referenceLockRejected: () => {
|
|
73
|
+
const [t] = validate({ dialect, lock: h1 })
|
|
74
|
+
assertEq(t, 'error')
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
// A value must be a string or a map: a number fails structurally.
|
|
78
|
+
malformedMapRejected: () => {
|
|
79
|
+
const [t] = validate(lockOf({ dependency: 1 }))
|
|
80
|
+
assertEq(t, 'error')
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
// The semantic check is the revision dialect's own, so a non-hash
|
|
84
|
+
// string is rejected here with the same path-naming message.
|
|
85
|
+
invalidHashRejected: () => {
|
|
86
|
+
const r = validate(lockOf({ B: { D: 'https://example.com/x' } }))
|
|
87
|
+
assert(r[0] === 'error', ['expected error', r])
|
|
88
|
+
assertEq(r[1], 'lock value for B/D is not a valid hash: https://example.com/x')
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
// No `subject`, `parents`, `generation` or `archived`: this dialect is
|
|
92
|
+
// a value, not a step. rtti structs are open, so such fields are
|
|
93
|
+
// ignored rather than rejected — the additive forward-compatibility
|
|
94
|
+
// path, the same one the revision dialect relies on.
|
|
95
|
+
revisionFieldsIgnored: () => {
|
|
96
|
+
const [t] = validate({ dialect, lock: {}, subject: h1, parents: [], generation: 0 })
|
|
97
|
+
assertEq(t, 'ok')
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// A revision blob is not a lock blob: the tag is matched as an exact
|
|
101
|
+
// literal, so the two dialects never validate each other's content.
|
|
102
|
+
revisionBlobRejected: () => {
|
|
103
|
+
const [t] = validate({
|
|
104
|
+
dialect: revisionDialect,
|
|
105
|
+
subject: h1,
|
|
106
|
+
parents: [],
|
|
107
|
+
snapshot: h2,
|
|
108
|
+
generation: 0,
|
|
109
|
+
lock: {},
|
|
110
|
+
})
|
|
111
|
+
assertEq(t, 'error')
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
// The already-typed entry point, for callers that assembled a `Lock`
|
|
116
|
+
// themselves and need only the semantic half.
|
|
117
|
+
checkReferences: {
|
|
118
|
+
valid: () => {
|
|
119
|
+
const [t] = checkReferences({ dialect, lock: { dependency: h1 } })
|
|
120
|
+
assertEq(t, 'ok')
|
|
121
|
+
},
|
|
122
|
+
invalid: () => {
|
|
123
|
+
const [t] = checkReferences({ dialect, lock: { dependency: 'not a hash!' } })
|
|
124
|
+
assertEq(t, 'error')
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
decodeText: {
|
|
129
|
+
validJson: () => {
|
|
130
|
+
const r = decodeText(JSON.stringify(lockOf({ dependency: h1 })))
|
|
131
|
+
assert(r[0] === 'ok', ['expected ok', r])
|
|
132
|
+
assertEq(r[1].lock.dependency, h1)
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// Key order carries no meaning: the JSON is parsed and the parsed
|
|
136
|
+
// value validated, so `dialect` need not come first.
|
|
137
|
+
keyOrderIndependent: () => {
|
|
138
|
+
const [t] = decodeText(`{"lock":{"dependency":"${h1}"},"dialect":"${dialect}"}`)
|
|
139
|
+
assertEq(t, 'ok')
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
malformedJsonRejected: () => {
|
|
143
|
+
const [t] = decodeText('{not json')
|
|
144
|
+
assertEq(t, 'error')
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
ordinaryJsonRejected: () => {
|
|
148
|
+
const [t] = decodeText('{"hello":"world"}')
|
|
149
|
+
assertEq(t, 'error')
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
encodeText: {
|
|
154
|
+
recursivelySortsObjectsLexicographically: () => {
|
|
155
|
+
const decoded = validate(lockOf({ scope: { '2': h2, '10': h1 }, '2': h2, '10': h1 }))
|
|
156
|
+
assert(decoded[0] === 'ok', ['expected ok', decoded])
|
|
157
|
+
assertEq(
|
|
158
|
+
encodeText(decoded[1]),
|
|
159
|
+
`{"dialect":"${dialect}","lock":{"10":"${h1}","2":"${h2}","scope":{"10":"${h1}","2":"${h2}"}}}`,
|
|
160
|
+
)
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
// Two blobs differing only in property order converge on one byte
|
|
164
|
+
// sequence, so they address the same CAS blob — which is the whole
|
|
165
|
+
// point of sharing one.
|
|
166
|
+
equivalentOrdersConverge: () => {
|
|
167
|
+
const a = validate(lockOf({ B: { B: h1, D: h2 }, C: { D: h1 } }))
|
|
168
|
+
const b = validate(lockOf({ C: { D: h1 }, B: { D: h2, B: h1 } }))
|
|
169
|
+
assert(a[0] === 'ok', ['expected ok', a])
|
|
170
|
+
assert(b[0] === 'ok', ['expected ok', b])
|
|
171
|
+
assertEq(encodeText(a[1]), encodeText(b[1]))
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
// The point of importing `lock` rather than restating it: one map, one
|
|
176
|
+
// canonical rendering, whether it is held inline by a revision or shared
|
|
177
|
+
// as a blob of its own. The two dialects have different field sets, so the
|
|
178
|
+
// surrounding bytes differ — the map's do not, and a resolver reading
|
|
179
|
+
// either form sees the identical bytes under `lock`.
|
|
180
|
+
inlineAndSharedSerializeIdentically: () => {
|
|
181
|
+
const fragment = `"lock":${canonicalMap(sharedMap)}`
|
|
182
|
+
const shared = validate(lockOf(sharedMap))
|
|
183
|
+
assert(shared[0] === 'ok', ['expected ok', shared])
|
|
184
|
+
const inline = revisionValidate({
|
|
185
|
+
dialect: revisionDialect,
|
|
186
|
+
subject: h1,
|
|
187
|
+
parents: [],
|
|
188
|
+
snapshot: h2,
|
|
189
|
+
generation: 0,
|
|
190
|
+
lock: sharedMap,
|
|
191
|
+
})
|
|
192
|
+
assert(inline[0] === 'ok', ['expected ok', inline])
|
|
193
|
+
assert(encodeText(shared[1]).includes(fragment), encodeText(shared[1]))
|
|
194
|
+
assert(revisionEncodeText(inline[1]).includes(fragment), revisionEncodeText(inline[1]))
|
|
195
|
+
},
|
|
196
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-level API for `fjs/media/lock/module.f.mjs`: `Lock` and `LockError`.
|
|
3
|
+
*
|
|
4
|
+
* The map type itself is not restated here — it is `fjs/media/revision`'s
|
|
5
|
+
* `LockMap`, re-exported so a consumer of the shared form needs only one
|
|
6
|
+
* import, and so nothing can define a second, drifting spelling of it.
|
|
7
|
+
*/
|
|
8
|
+
import type { ValidationError } from '../../types/rtti/common/types.ts';
|
|
9
|
+
import type { Ts } from '../../types/rtti/ts/types.ts';
|
|
10
|
+
import type { lockSchema } from './module.f.mjs';
|
|
11
|
+
export type { LockMap } from '../revision/types.ts';
|
|
12
|
+
/** The TypeScript type derived from `lockSchema` — the single source of truth. */
|
|
13
|
+
export type Lock = Ts<typeof lockSchema>;
|
|
14
|
+
/** Either a structural validation error or a semantic (hash) error message. */
|
|
15
|
+
export type LockError = ValidationError | string;
|
package/fjs/media/module.f.d.mts
CHANGED
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* `fjs/media/type` verdict unchanged.
|
|
13
13
|
*
|
|
14
14
|
* The dialect set is a **parameter**, not an import: `detect(dialects)(bytes)`.
|
|
15
|
-
* This module therefore knows no dialect of its own — `fjs/media/revision
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* This module therefore knows no dialect of its own — `fjs/media/revision`,
|
|
16
|
+
* `fjs/media/lock`, and `fjs/media/note` each export their own
|
|
17
|
+
* {@link DialectEntry} (`revisionDialect`, `lockDialect`, `noteDialect`), and
|
|
18
|
+
* a caller passes the list it wants recognized. Any format following the `vnd.fjs.<name>` convention (see
|
|
19
|
+
* `fjs/media/revision/README.md`), in this repo or downstream, is registerable
|
|
20
|
+
* the same way.
|
|
20
21
|
*
|
|
21
22
|
* Detection is semantic, not syntactic: any JSON that satisfies a dialect's
|
|
22
23
|
* schema is recognized regardless of key order, whitespace, or any other
|
package/fjs/media/module.f.mjs
CHANGED
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* `fjs/media/type` verdict unchanged.
|
|
13
13
|
*
|
|
14
14
|
* The dialect set is a **parameter**, not an import: `detect(dialects)(bytes)`.
|
|
15
|
-
* This module therefore knows no dialect of its own — `fjs/media/revision
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* This module therefore knows no dialect of its own — `fjs/media/revision`,
|
|
16
|
+
* `fjs/media/lock`, and `fjs/media/note` each export their own
|
|
17
|
+
* {@link DialectEntry} (`revisionDialect`, `lockDialect`, `noteDialect`), and
|
|
18
|
+
* a caller passes the list it wants recognized. Any format following the `vnd.fjs.<name>` convention (see
|
|
19
|
+
* `fjs/media/revision/README.md`), in this repo or downstream, is registerable
|
|
20
|
+
* the same way.
|
|
20
21
|
*
|
|
21
22
|
* Detection is semantic, not syntactic: any JSON that satisfies a dialect's
|
|
22
23
|
* schema is recognized regardless of key order, whitespace, or any other
|
|
@@ -53,7 +54,7 @@ import { fromVec } from '../text/utf8/module.f.mjs'
|
|
|
53
54
|
import { detectVec } from './type/module.f.mjs'
|
|
54
55
|
import { parse } from './json/module.f.mjs'
|
|
55
56
|
import { assert, assertNotNullish } from '../asserts/module.f.mjs'
|
|
56
|
-
import {
|
|
57
|
+
import { parse as rttiParse } from '../types/rtti/parse/module.f.mjs'
|
|
57
58
|
|
|
58
59
|
/** The default refinement: structural validation alone decides the match. */
|
|
59
60
|
const always = () => true
|
|
@@ -119,7 +120,7 @@ const matchWith = v => extraValidate => u => {
|
|
|
119
120
|
export const dialectEntry = (type, extraValidate = always) => {
|
|
120
121
|
const { dialect } = type
|
|
121
122
|
assert(typeof dialect === 'string', 'dialectEntry: schema has no direct string `dialect` member')
|
|
122
|
-
return { dialect, match: matchWith(
|
|
123
|
+
return { dialect, match: matchWith(rttiParse(type))(extraValidate) }
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
/**
|