functionalscript 0.13.1 → 0.14.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/{types → fs}/asn.1/module.f.d.ts +1 -1
- package/{types → fs}/asn.1/module.f.js +3 -3
- package/{types → fs}/asn.1/test.f.js +2 -2
- package/{types → fs}/base128/module.f.d.ts +1 -1
- package/{types → fs}/base128/module.f.js +1 -1
- package/{types → fs}/base128/test.f.js +2 -2
- package/{bnf → fs/bnf}/data/module.f.d.ts +1 -1
- package/{cas → fs/cas}/module.f.d.ts +4 -4
- package/{cas → fs/cas}/module.f.js +1 -1
- package/{types → fs}/cbase32/module.f.d.ts +2 -2
- package/{types → fs}/cbase32/module.f.js +1 -1
- package/{types → fs}/cbase32/test.f.js +1 -1
- package/fs/ci/bun/module.f.d.ts +2 -0
- package/fs/ci/bun/module.f.js +20 -0
- package/fs/ci/common/module.f.d.ts +43 -0
- package/fs/ci/common/module.f.js +32 -0
- package/fs/ci/config/module.f.d.ts +25 -0
- package/fs/ci/config/module.f.js +34 -0
- package/fs/ci/deno/module.f.d.ts +2 -0
- package/fs/ci/deno/module.f.js +13 -0
- package/fs/ci/module.f.js +40 -0
- package/fs/ci/node/module.f.d.ts +6 -0
- package/fs/ci/node/module.f.js +36 -0
- package/fs/ci/playwright/module.f.d.ts +2 -0
- package/fs/ci/playwright/module.f.js +23 -0
- package/fs/ci/rust/module.f.d.ts +2 -0
- package/fs/ci/rust/module.f.js +49 -0
- package/{crypto → fs/crypto}/secp/module.f.d.ts +1 -2
- package/{dev → fs/dev}/module.f.d.ts +2 -0
- package/{dev → fs/dev}/module.f.js +5 -0
- package/{dev → fs/dev}/tf/all.test.js +7 -5
- package/{dev → fs/dev}/tf/module.f.d.ts +1 -1
- package/{dev → fs/dev}/tf/module.f.js +12 -9
- package/fs/dev/tf/test.f.d.ts +16 -0
- package/fs/dev/tf/test.f.js +22 -0
- package/fs/dev/version/module.f.d.ts +3 -0
- package/{djs → fs/djs}/tokenizer/module.f.js +3 -3
- package/{djs/parser-new → fs/djs/tokenizer-new}/test.f.d.ts +2 -1
- package/fs/djs/tokenizer-new/test.f.js +894 -0
- package/{js → fs/js}/tokenizer/module.f.js +34 -34
- package/{json → fs/json}/tokenizer/module.f.js +1 -1
- package/{path → fs/path}/module.f.d.ts +1 -1
- package/fs/sul/id/module.f.d.ts +33 -0
- package/fs/sul/id/module.f.js +94 -0
- package/fs/sul/id/test.f.d.ts +21 -0
- package/fs/sul/id/test.f.js +75 -0
- package/fs/sul/level/hash/module.f.d.ts +38 -0
- package/fs/sul/level/hash/module.f.js +43 -0
- package/fs/sul/level/hash/test.f.d.ts +14 -0
- package/fs/sul/level/hash/test.f.js +112 -0
- package/fs/sul/level/literal/module.f.d.ts +64 -0
- package/fs/sul/level/literal/module.f.js +88 -0
- package/fs/sul/level/literal/test.f.d.ts +12 -0
- package/fs/sul/level/literal/test.f.js +722 -0
- package/fs/sul/module.f.d.ts +23 -0
- package/fs/sul/module.f.js +46 -0
- package/fs/sul/test.f.d.ts +10 -0
- package/fs/sul/test.f.js +47 -0
- package/{text → fs/text}/module.f.d.ts +1 -1
- package/{text → fs/text}/utf16/module.f.js +8 -8
- package/{text → fs/text}/utf8/module.f.js +2 -2
- package/{types → fs/types}/bit_vec/module.f.d.ts +13 -1
- package/{types → fs/types}/bit_vec/module.f.js +33 -15
- package/{types → fs/types}/effects/module.f.d.ts +1 -0
- package/{types → fs/types}/effects/node/virtual/module.f.d.ts +3 -3
- package/{types → fs/types}/function/operator/module.f.d.ts +1 -1
- package/{types → fs/types}/function/operator/module.f.js +1 -1
- package/{types → fs/types}/list/module.f.js +1 -1
- package/fs/types/patricia_trie/module.f.d.ts +25 -0
- package/fs/types/patricia_trie/module.f.js +35 -0
- package/fs/types/patricia_trie/test.f.d.ts +8 -0
- package/fs/types/patricia_trie/test.f.js +121 -0
- package/fs/types/rtti/parse/module.f.d.ts +32 -0
- package/fs/types/rtti/parse/module.f.js +113 -0
- package/fs/types/rtti/parse/test.f.d.ts +104 -0
- package/fs/types/rtti/parse/test.f.js +316 -0
- package/fs/types/rtti/validate/module.f.d.ts +74 -0
- package/{types → fs/types}/rtti/validate/module.f.js +26 -24
- package/{types → fs/types}/rtti/validate/test.f.d.ts +11 -0
- package/{types → fs/types}/rtti/validate/test.f.js +38 -0
- package/{types → fs/types}/uint8array/module.f.d.ts +2 -2
- package/package.json +8 -8
- package/ci/module.f.js +0 -183
- package/dev/tf/test.f.d.ts +0 -4
- package/dev/tf/test.f.js +0 -5
- package/dev/version/module.f.d.ts +0 -3
- package/djs/parser-new/test.f.js +0 -202
- package/types/rtti/validate/module.f.d.ts +0 -50
- /package/{types → fs}/asn.1/test.f.d.ts +0 -0
- /package/{cas → fs/base128}/test.f.d.ts +0 -0
- /package/{bnf → fs/bnf}/data/module.f.js +0 -0
- /package/{bnf → fs/bnf}/data/test.f.d.ts +0 -0
- /package/{bnf → fs/bnf}/data/test.f.js +0 -0
- /package/{bnf → fs/bnf}/module.f.d.ts +0 -0
- /package/{bnf → fs/bnf}/module.f.js +0 -0
- /package/{bnf → fs/bnf}/test.f.d.ts +0 -0
- /package/{bnf → fs/bnf}/test.f.js +0 -0
- /package/{bnf → fs/bnf}/testlib.f.d.ts +0 -0
- /package/{bnf → fs/bnf}/testlib.f.js +0 -0
- /package/{types/base128 → fs/cas}/test.f.d.ts +0 -0
- /package/{cas → fs/cas}/test.f.js +0 -0
- /package/{types → fs}/cbase32/test.f.d.ts +0 -0
- /package/{ci → fs/ci}/module.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/hmac/module.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/hmac/module.f.js +0 -0
- /package/{crypto → fs/crypto}/hmac/test.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/hmac/test.f.js +0 -0
- /package/{crypto → fs/crypto}/secp/module.f.js +0 -0
- /package/{crypto → fs/crypto}/secp/test.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/secp/test.f.js +0 -0
- /package/{crypto → fs/crypto}/sha2/module.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/sha2/module.f.js +0 -0
- /package/{crypto → fs/crypto}/sha2/test.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/sha2/test.f.js +0 -0
- /package/{crypto → fs/crypto}/sign/module.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/sign/module.f.js +0 -0
- /package/{crypto → fs/crypto}/sign/test.f.d.ts +0 -0
- /package/{crypto → fs/crypto}/sign/test.f.js +0 -0
- /package/{dev → fs/dev}/index/module.f.d.ts +0 -0
- /package/{dev → fs/dev}/index/module.f.js +0 -0
- /package/{dev → fs/dev}/test.f.d.ts +0 -0
- /package/{dev → fs/dev}/test.f.js +0 -0
- /package/{dev → fs/dev}/tf/all.test.d.ts +0 -0
- /package/{dev → fs/dev}/version/module.f.js +0 -0
- /package/{dev → fs/dev}/version/test.f.d.ts +0 -0
- /package/{dev → fs/dev}/version/test.f.js +0 -0
- /package/{djs → fs/djs}/ast/module.f.d.ts +0 -0
- /package/{djs → fs/djs}/ast/module.f.js +0 -0
- /package/{djs → fs/djs}/ast/test.f.d.ts +0 -0
- /package/{djs → fs/djs}/ast/test.f.js +0 -0
- /package/{djs → fs/djs}/examples/input.f.d.ts +0 -0
- /package/{djs → fs/djs}/examples/input.f.js +0 -0
- /package/{djs → fs/djs}/examples/m.f.d.ts +0 -0
- /package/{djs → fs/djs}/examples/m.f.js +0 -0
- /package/{djs → fs/djs}/module.f.d.ts +0 -0
- /package/{djs → fs/djs}/module.f.js +0 -0
- /package/{djs → fs/djs}/parser/module.f.d.ts +0 -0
- /package/{djs → fs/djs}/parser/module.f.js +0 -0
- /package/{djs → fs/djs}/parser/test.f.d.ts +0 -0
- /package/{djs → fs/djs}/parser/test.f.js +0 -0
- /package/{djs → fs/djs}/serializer/module.f.d.ts +0 -0
- /package/{djs → fs/djs}/serializer/module.f.js +0 -0
- /package/{djs → fs/djs}/serializer/test.f.d.ts +0 -0
- /package/{djs → fs/djs}/serializer/test.f.js +0 -0
- /package/{djs → fs/djs}/tokenizer/module.f.d.ts +0 -0
- /package/{djs → fs/djs}/tokenizer/test.f.d.ts +0 -0
- /package/{djs → fs/djs}/tokenizer/test.f.js +0 -0
- /package/{djs/parser-new → fs/djs/tokenizer-new}/module.f.d.ts +0 -0
- /package/{djs/parser-new → fs/djs/tokenizer-new}/module.f.js +0 -0
- /package/{djs → fs/djs}/transpiler/module.f.d.ts +0 -0
- /package/{djs → fs/djs}/transpiler/module.f.js +0 -0
- /package/{djs → fs/djs}/transpiler/test.f.d.ts +0 -0
- /package/{djs → fs/djs}/transpiler/test.f.js +0 -0
- /package/{fjs → fs/fjs}/module.d.ts +0 -0
- /package/{fjs → fs/fjs}/module.f.d.ts +0 -0
- /package/{fjs → fs/fjs}/module.f.js +0 -0
- /package/{fjs → fs/fjs}/module.js +0 -0
- /package/{fsc → fs/fsc}/bnf.f.d.ts +0 -0
- /package/{fsc → fs/fsc}/bnf.f.js +0 -0
- /package/{fsc → fs/fsc}/json.f.d.ts +0 -0
- /package/{fsc → fs/fsc}/json.f.js +0 -0
- /package/{fsc → fs/fsc}/module.f.d.ts +0 -0
- /package/{fsc → fs/fsc}/module.f.js +0 -0
- /package/{fsc → fs/fsc}/test.f.d.ts +0 -0
- /package/{fsc → fs/fsc}/test.f.js +0 -0
- /package/{fsm → fs/fsm}/module.f.d.ts +0 -0
- /package/{fsm → fs/fsm}/module.f.js +0 -0
- /package/{fsm → fs/fsm}/test.f.d.ts +0 -0
- /package/{fsm → fs/fsm}/test.f.js +0 -0
- /package/{html → fs/html}/module.f.d.ts +0 -0
- /package/{html → fs/html}/module.f.js +0 -0
- /package/{html → fs/html}/test.f.d.ts +0 -0
- /package/{html → fs/html}/test.f.js +0 -0
- /package/{io → fs/io}/module.d.ts +0 -0
- /package/{io → fs/io}/module.f.d.ts +0 -0
- /package/{io → fs/io}/module.f.js +0 -0
- /package/{io → fs/io}/module.js +0 -0
- /package/{io → fs/io}/virtual/module.f.d.ts +0 -0
- /package/{io → fs/io}/virtual/module.f.js +0 -0
- /package/{js → fs/js}/tokenizer/module.f.d.ts +0 -0
- /package/{js → fs/js}/tokenizer/test.f.d.ts +0 -0
- /package/{js → fs/js}/tokenizer/test.f.js +0 -0
- /package/{json → fs/json}/module.f.d.ts +0 -0
- /package/{json → fs/json}/module.f.js +0 -0
- /package/{json → fs/json}/parser/module.f.d.ts +0 -0
- /package/{json → fs/json}/parser/module.f.js +0 -0
- /package/{json → fs/json}/parser/test.f.d.ts +0 -0
- /package/{json → fs/json}/parser/test.f.js +0 -0
- /package/{json → fs/json}/serializer/module.f.d.ts +0 -0
- /package/{json → fs/json}/serializer/module.f.js +0 -0
- /package/{json → fs/json}/serializer/test.f.d.ts +0 -0
- /package/{json → fs/json}/serializer/test.f.js +0 -0
- /package/{json → fs/json}/test.f.d.ts +0 -0
- /package/{json → fs/json}/test.f.js +0 -0
- /package/{json → fs/json}/tokenizer/module.f.d.ts +0 -0
- /package/{json → fs/json}/tokenizer/test.f.d.ts +0 -0
- /package/{json → fs/json}/tokenizer/test.f.js +0 -0
- /package/{path → fs/path}/module.f.js +0 -0
- /package/{path → fs/path}/test.f.d.ts +0 -0
- /package/{path → fs/path}/test.f.js +0 -0
- /package/{text → fs/text}/ascii/module.f.d.ts +0 -0
- /package/{text → fs/text}/ascii/module.f.js +0 -0
- /package/{text → fs/text}/ascii/test.f.d.ts +0 -0
- /package/{text → fs/text}/ascii/test.f.js +0 -0
- /package/{text → fs/text}/module.f.js +0 -0
- /package/{text → fs/text}/sgr/module.f.d.ts +0 -0
- /package/{text → fs/text}/sgr/module.f.js +0 -0
- /package/{text → fs/text}/sgr/test.f.d.ts +0 -0
- /package/{text → fs/text}/sgr/test.f.js +0 -0
- /package/{text → fs/text}/test.f.d.ts +0 -0
- /package/{text → fs/text}/test.f.js +0 -0
- /package/{text → fs/text}/utf16/module.f.d.ts +0 -0
- /package/{text → fs/text}/utf16/test.f.d.ts +0 -0
- /package/{text → fs/text}/utf16/test.f.js +0 -0
- /package/{text → fs/text}/utf8/module.f.d.ts +0 -0
- /package/{text → fs/text}/utf8/test.f.d.ts +0 -0
- /package/{text → fs/text}/utf8/test.f.js +0 -0
- /package/{types → fs/types}/array/module.f.d.ts +0 -0
- /package/{types → fs/types}/array/module.f.js +0 -0
- /package/{types → fs/types}/array/test.f.d.ts +0 -0
- /package/{types → fs/types}/array/test.f.js +0 -0
- /package/{types → fs/types}/bigfloat/module.f.d.ts +0 -0
- /package/{types → fs/types}/bigfloat/module.f.js +0 -0
- /package/{types → fs/types}/bigfloat/test.f.d.ts +0 -0
- /package/{types → fs/types}/bigfloat/test.f.js +0 -0
- /package/{types → fs/types}/bigint/module.f.d.ts +0 -0
- /package/{types → fs/types}/bigint/module.f.js +0 -0
- /package/{types → fs/types}/bigint/test.f.d.ts +0 -0
- /package/{types → fs/types}/bigint/test.f.js +0 -0
- /package/{types → fs/types}/bit_vec/test.f.d.ts +0 -0
- /package/{types → fs/types}/bit_vec/test.f.js +0 -0
- /package/{types → fs/types}/btree/find/module.f.d.ts +0 -0
- /package/{types → fs/types}/btree/find/module.f.js +0 -0
- /package/{types → fs/types}/btree/find/test.f.d.ts +0 -0
- /package/{types → fs/types}/btree/find/test.f.js +0 -0
- /package/{types → fs/types}/btree/module.f.d.ts +0 -0
- /package/{types → fs/types}/btree/module.f.js +0 -0
- /package/{types → fs/types}/btree/remove/module.f.d.ts +0 -0
- /package/{types → fs/types}/btree/remove/module.f.js +0 -0
- /package/{types → fs/types}/btree/remove/test.f.d.ts +0 -0
- /package/{types → fs/types}/btree/remove/test.f.js +0 -0
- /package/{types → fs/types}/btree/set/module.f.d.ts +0 -0
- /package/{types → fs/types}/btree/set/module.f.js +0 -0
- /package/{types → fs/types}/btree/set/test.f.d.ts +0 -0
- /package/{types → fs/types}/btree/set/test.f.js +0 -0
- /package/{types → fs/types}/btree/test.f.d.ts +0 -0
- /package/{types → fs/types}/btree/test.f.js +0 -0
- /package/{types → fs/types}/btree/types/module.f.d.ts +0 -0
- /package/{types → fs/types}/btree/types/module.f.js +0 -0
- /package/{types → fs/types}/byte_set/module.f.d.ts +0 -0
- /package/{types → fs/types}/byte_set/module.f.js +0 -0
- /package/{types → fs/types}/byte_set/test.f.d.ts +0 -0
- /package/{types → fs/types}/byte_set/test.f.js +0 -0
- /package/{types → fs/types}/effects/mock/module.f.d.ts +0 -0
- /package/{types → fs/types}/effects/mock/module.f.js +0 -0
- /package/{types → fs/types}/effects/module.d.ts +0 -0
- /package/{types → fs/types}/effects/module.f.js +0 -0
- /package/{types → fs/types}/effects/module.js +0 -0
- /package/{types → fs/types}/effects/node/module.f.d.ts +0 -0
- /package/{types → fs/types}/effects/node/module.f.js +0 -0
- /package/{types → fs/types}/effects/node/test.f.d.ts +0 -0
- /package/{types → fs/types}/effects/node/test.f.js +0 -0
- /package/{types → fs/types}/effects/node/virtual/module.f.js +0 -0
- /package/{types → fs/types}/function/compare/module.f.d.ts +0 -0
- /package/{types → fs/types}/function/compare/module.f.js +0 -0
- /package/{types → fs/types}/function/compare/test.f.d.ts +0 -0
- /package/{types → fs/types}/function/compare/test.f.js +0 -0
- /package/{types → fs/types}/function/module.f.d.ts +0 -0
- /package/{types → fs/types}/function/module.f.js +0 -0
- /package/{types → fs/types}/function/test.f.d.ts +0 -0
- /package/{types → fs/types}/function/test.f.js +0 -0
- /package/{types → fs/types}/list/module.f.d.ts +0 -0
- /package/{types → fs/types}/list/test.f.d.ts +0 -0
- /package/{types → fs/types}/list/test.f.js +0 -0
- /package/{types → fs/types}/map/module.f.d.ts +0 -0
- /package/{types → fs/types}/map/module.f.js +0 -0
- /package/{types → fs/types}/map/test.f.d.ts +0 -0
- /package/{types → fs/types}/map/test.f.js +0 -0
- /package/{types → fs/types}/monoid/module.f.d.ts +0 -0
- /package/{types → fs/types}/monoid/module.f.js +0 -0
- /package/{types → fs/types}/monoid/test.f.d.ts +0 -0
- /package/{types → fs/types}/monoid/test.f.js +0 -0
- /package/{types → fs/types}/nibble_set/module.f.d.ts +0 -0
- /package/{types → fs/types}/nibble_set/module.f.js +0 -0
- /package/{types → fs/types}/nibble_set/test.f.d.ts +0 -0
- /package/{types → fs/types}/nibble_set/test.f.js +0 -0
- /package/{types → fs/types}/nominal/module.f.d.ts +0 -0
- /package/{types → fs/types}/nominal/module.f.js +0 -0
- /package/{types → fs/types}/nominal/test.f.d.ts +0 -0
- /package/{types → fs/types}/nominal/test.f.js +0 -0
- /package/{types → fs/types}/nullable/module.f.d.ts +0 -0
- /package/{types → fs/types}/nullable/module.f.js +0 -0
- /package/{types → fs/types}/nullable/test.f.d.ts +0 -0
- /package/{types → fs/types}/nullable/test.f.js +0 -0
- /package/{types → fs/types}/number/module.f.d.ts +0 -0
- /package/{types → fs/types}/number/module.f.js +0 -0
- /package/{types → fs/types}/number/test.f.d.ts +0 -0
- /package/{types → fs/types}/number/test.f.js +0 -0
- /package/{types → fs/types}/object/module.f.d.ts +0 -0
- /package/{types → fs/types}/object/module.f.js +0 -0
- /package/{types → fs/types}/object/test.f.d.ts +0 -0
- /package/{types → fs/types}/object/test.f.js +0 -0
- /package/{types → fs/types}/option/module.f.d.ts +0 -0
- /package/{types → fs/types}/option/module.f.js +0 -0
- /package/{types → fs/types}/ordered_map/module.f.d.ts +0 -0
- /package/{types → fs/types}/ordered_map/module.f.js +0 -0
- /package/{types → fs/types}/ordered_map/test.f.d.ts +0 -0
- /package/{types → fs/types}/ordered_map/test.f.js +0 -0
- /package/{types → fs/types}/prime_field/module.f.d.ts +0 -0
- /package/{types → fs/types}/prime_field/module.f.js +0 -0
- /package/{types → fs/types}/prime_field/test.f.d.ts +0 -0
- /package/{types → fs/types}/prime_field/test.f.js +0 -0
- /package/{types → fs/types}/range/module.f.d.ts +0 -0
- /package/{types → fs/types}/range/module.f.js +0 -0
- /package/{types → fs/types}/range/test.f.d.ts +0 -0
- /package/{types → fs/types}/range/test.f.js +0 -0
- /package/{types → fs/types}/range_map/module.f.d.ts +0 -0
- /package/{types → fs/types}/range_map/module.f.js +0 -0
- /package/{types → fs/types}/range_map/test.f.d.ts +0 -0
- /package/{types → fs/types}/range_map/test.f.js +0 -0
- /package/{types → fs/types}/result/module.d.ts +0 -0
- /package/{types → fs/types}/result/module.f.d.ts +0 -0
- /package/{types → fs/types}/result/module.f.js +0 -0
- /package/{types → fs/types}/result/module.js +0 -0
- /package/{types → fs/types}/result/test.f.d.ts +0 -0
- /package/{types → fs/types}/result/test.f.js +0 -0
- /package/{types → fs/types}/rtti/module.f.d.ts +0 -0
- /package/{types → fs/types}/rtti/module.f.js +0 -0
- /package/{types → fs/types}/rtti/test.f.d.ts +0 -0
- /package/{types → fs/types}/rtti/test.f.js +0 -0
- /package/{types → fs/types}/rtti/ts/module.f.d.ts +0 -0
- /package/{types → fs/types}/rtti/ts/module.f.js +0 -0
- /package/{types → fs/types}/rtti/ts/test.f.d.ts +0 -0
- /package/{types → fs/types}/rtti/ts/test.f.js +0 -0
- /package/{types → fs/types}/sorted_list/module.f.d.ts +0 -0
- /package/{types → fs/types}/sorted_list/module.f.js +0 -0
- /package/{types → fs/types}/sorted_list/test.f.d.ts +0 -0
- /package/{types → fs/types}/sorted_list/test.f.js +0 -0
- /package/{types → fs/types}/sorted_set/module.f.d.ts +0 -0
- /package/{types → fs/types}/sorted_set/module.f.js +0 -0
- /package/{types → fs/types}/sorted_set/test.f.d.ts +0 -0
- /package/{types → fs/types}/sorted_set/test.f.js +0 -0
- /package/{types → fs/types}/string/module.f.d.ts +0 -0
- /package/{types → fs/types}/string/module.f.js +0 -0
- /package/{types → fs/types}/string/test.f.d.ts +0 -0
- /package/{types → fs/types}/string/test.f.js +0 -0
- /package/{types → fs/types}/string_set/module.f.d.ts +0 -0
- /package/{types → fs/types}/string_set/module.f.js +0 -0
- /package/{types → fs/types}/string_set/test.f.d.ts +0 -0
- /package/{types → fs/types}/string_set/test.f.js +0 -0
- /package/{types → fs/types}/ts/module.f.d.ts +0 -0
- /package/{types → fs/types}/ts/module.f.js +0 -0
- /package/{types → fs/types}/uint8array/module.f.js +0 -0
- /package/{types → fs/types}/uint8array/test.f.d.ts +0 -0
- /package/{types → fs/types}/uint8array/test.f.js +0 -0
- /package/{website → fs/website}/module.f.d.ts +0 -0
- /package/{website → fs/website}/module.f.js +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {} from "../module.f.js";
|
|
2
|
+
import { ok } from "../../result/module.f.js";
|
|
3
|
+
import { constPrimitiveValidate, prependPath, primitive0Validate, verror, } from "../validate/module.f.js";
|
|
4
|
+
import { isArray as commonIsArray } from "../../array/module.f.js";
|
|
5
|
+
import { isObject as commonIsObject } from "../../object/module.f.js";
|
|
6
|
+
import { find, map as listMap } from "../../list/module.f.js";
|
|
7
|
+
const indexedFirstError = (results) => {
|
|
8
|
+
// TODO: findIndex breaks type inference,
|
|
9
|
+
// we should replace it with something else.
|
|
10
|
+
const i = results.findIndex(r => r[0] === 'error');
|
|
11
|
+
return i < 0 ? null : [i, results[i]];
|
|
12
|
+
};
|
|
13
|
+
const keyedFirstError = (results) => {
|
|
14
|
+
const e = results.find(([, r]) => r[0] === 'error');
|
|
15
|
+
return e === undefined ? null : [e[0], e[1]];
|
|
16
|
+
};
|
|
17
|
+
const arrayParse = (item) => value => {
|
|
18
|
+
if (!commonIsArray(value)) {
|
|
19
|
+
return verror('unexpected value');
|
|
20
|
+
}
|
|
21
|
+
if (value.length === 0) {
|
|
22
|
+
return ok([]);
|
|
23
|
+
}
|
|
24
|
+
// Note: we shouldn't instantiate `itemParse` until we know the array is non-empty.
|
|
25
|
+
// Otherwise, we can get infinite recursion on empty arrays for recursive schemas.
|
|
26
|
+
const itemParse = parse(item);
|
|
27
|
+
const results = value.map(itemParse);
|
|
28
|
+
const err = indexedFirstError(results);
|
|
29
|
+
return (err === null
|
|
30
|
+
? ok(results.map(r => r[1]))
|
|
31
|
+
: prependPath(String(err[0]), err[1]));
|
|
32
|
+
};
|
|
33
|
+
const recordParse = (item) => value => {
|
|
34
|
+
if (!commonIsObject(value)) {
|
|
35
|
+
return verror('unexpected value');
|
|
36
|
+
}
|
|
37
|
+
const entries = Object.entries(value);
|
|
38
|
+
if (entries.length === 0) {
|
|
39
|
+
return ok({});
|
|
40
|
+
}
|
|
41
|
+
const itemParse = parse(item);
|
|
42
|
+
const results = entries.map(([k, v]) => [k, itemParse(v)]);
|
|
43
|
+
const err = keyedFirstError(results);
|
|
44
|
+
return (err === null
|
|
45
|
+
? ok(Object.fromEntries(results.map(([k, r]) => [k, r[1]])))
|
|
46
|
+
: prependPath(err[0], err[1]));
|
|
47
|
+
};
|
|
48
|
+
const tupleParse = (rtti) => value => {
|
|
49
|
+
if (!commonIsArray(value)) {
|
|
50
|
+
return verror('unexpected value');
|
|
51
|
+
}
|
|
52
|
+
const results = rtti.map((t, i) => parse(t)(value[i]));
|
|
53
|
+
const err = indexedFirstError(results);
|
|
54
|
+
return (err === null
|
|
55
|
+
? ok(results.map(r => r[1]))
|
|
56
|
+
: prependPath(String(err[0]), err[1]));
|
|
57
|
+
};
|
|
58
|
+
const structParse = (rtti) => value => {
|
|
59
|
+
if (!commonIsObject(value)) {
|
|
60
|
+
return verror('unexpected value');
|
|
61
|
+
}
|
|
62
|
+
const results = Object.entries(rtti).map(([k, t]) => [k, parse(t)(value[k])]);
|
|
63
|
+
const err = keyedFirstError(results);
|
|
64
|
+
return (err === null
|
|
65
|
+
? ok(Object.fromEntries(results.map(([k, r]) => [k, r[1]])))
|
|
66
|
+
: prependPath(err[0], err[1]));
|
|
67
|
+
};
|
|
68
|
+
const constObjectParse = (rtti) => commonIsArray(rtti)
|
|
69
|
+
? tupleParse(rtti)
|
|
70
|
+
: structParse(rtti);
|
|
71
|
+
const constParse = (rtti) => typeof rtti === 'object' && rtti !== null
|
|
72
|
+
? constObjectParse(rtti)
|
|
73
|
+
: constPrimitiveValidate(rtti);
|
|
74
|
+
const findFirst = find(verror('no match'))((k) => k[0] === 'ok');
|
|
75
|
+
const orParse = (rtti) => value => findFirst(listMap(t => parse(t)(value))(rtti));
|
|
76
|
+
/**
|
|
77
|
+
* Creates a parser function for the given RTTI schema.
|
|
78
|
+
*
|
|
79
|
+
* The returned function takes an unknown value and returns either
|
|
80
|
+
* `['ok', newValue]` containing a freshly constructed value matching the schema,
|
|
81
|
+
* or `['error', { path, message }]` describing the failure location.
|
|
82
|
+
*
|
|
83
|
+
* @param rtti - A schema `Type`: a `Thunk` for tag-based schemas, or a `Const`
|
|
84
|
+
* (primitive literal, tuple, or struct) for exact-value schemas.
|
|
85
|
+
* @returns A `Parse<T>` function.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const p = parse(array(number))
|
|
90
|
+
* p([1, 2, 3]) // ['ok', [1, 2, 3]] (a new array)
|
|
91
|
+
* p([1, 'two']) // ['error', { path: ['1'], message: 'unexpected value' }]
|
|
92
|
+
*
|
|
93
|
+
* // tuples are closed: extra elements are dropped
|
|
94
|
+
* parse([number, number] as const)([1, 2, 3]) // ['ok', [1, 2]]
|
|
95
|
+
*
|
|
96
|
+
* // structs drop undeclared keys
|
|
97
|
+
* parse({ a: number } as const)({ a: 1, b: 2 }) // ['ok', { a: 1 }]
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export const parse = (rtti) => {
|
|
101
|
+
if (typeof rtti === 'function') {
|
|
102
|
+
const [tag, ...value] = rtti();
|
|
103
|
+
switch (tag) {
|
|
104
|
+
case 'const': return constParse(value[0]);
|
|
105
|
+
case 'array': return arrayParse(value[0]);
|
|
106
|
+
case 'record': return recordParse(value[0]);
|
|
107
|
+
case 'unknown': return ok;
|
|
108
|
+
case 'or': return orParse(value);
|
|
109
|
+
}
|
|
110
|
+
return primitive0Validate(tag);
|
|
111
|
+
}
|
|
112
|
+
return constParse(rtti);
|
|
113
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
boolean: {
|
|
3
|
+
ok: () => void;
|
|
4
|
+
error: () => void;
|
|
5
|
+
};
|
|
6
|
+
number: {
|
|
7
|
+
ok: () => void;
|
|
8
|
+
error: () => void;
|
|
9
|
+
};
|
|
10
|
+
string: {
|
|
11
|
+
ok: () => void;
|
|
12
|
+
error: () => void;
|
|
13
|
+
};
|
|
14
|
+
bigint: {
|
|
15
|
+
ok: () => void;
|
|
16
|
+
error: () => void;
|
|
17
|
+
};
|
|
18
|
+
unknown: {
|
|
19
|
+
ok: () => void;
|
|
20
|
+
};
|
|
21
|
+
const: {
|
|
22
|
+
null: {
|
|
23
|
+
ok: () => void;
|
|
24
|
+
error: () => void;
|
|
25
|
+
};
|
|
26
|
+
undefined: {
|
|
27
|
+
ok: () => void;
|
|
28
|
+
error: () => void;
|
|
29
|
+
};
|
|
30
|
+
number: {
|
|
31
|
+
ok: () => void;
|
|
32
|
+
error: () => void;
|
|
33
|
+
};
|
|
34
|
+
string: {
|
|
35
|
+
ok: () => void;
|
|
36
|
+
error: () => void;
|
|
37
|
+
};
|
|
38
|
+
bigint: {
|
|
39
|
+
ok: () => void;
|
|
40
|
+
error: () => void;
|
|
41
|
+
};
|
|
42
|
+
boolean: {
|
|
43
|
+
ok: () => void;
|
|
44
|
+
error: () => void;
|
|
45
|
+
};
|
|
46
|
+
tuple: {
|
|
47
|
+
ok: () => void;
|
|
48
|
+
extraItemsDropped: () => void;
|
|
49
|
+
error: () => void;
|
|
50
|
+
};
|
|
51
|
+
struct: {
|
|
52
|
+
ok: () => void;
|
|
53
|
+
extraKeysDropped: () => void;
|
|
54
|
+
error: () => void;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
array: {
|
|
58
|
+
empty: () => void;
|
|
59
|
+
ok: () => void;
|
|
60
|
+
freshArray: () => void;
|
|
61
|
+
error: () => void;
|
|
62
|
+
nested: () => void;
|
|
63
|
+
};
|
|
64
|
+
record: {
|
|
65
|
+
empty: () => void;
|
|
66
|
+
ok: () => void;
|
|
67
|
+
freshRecord: () => void;
|
|
68
|
+
error: () => void;
|
|
69
|
+
};
|
|
70
|
+
constThunk: {
|
|
71
|
+
primitive: () => void;
|
|
72
|
+
};
|
|
73
|
+
or: {
|
|
74
|
+
consts: {
|
|
75
|
+
ok: () => void;
|
|
76
|
+
error: () => void;
|
|
77
|
+
};
|
|
78
|
+
thunks: {
|
|
79
|
+
ok: () => void;
|
|
80
|
+
error: () => void;
|
|
81
|
+
};
|
|
82
|
+
firstMatchWins: () => void;
|
|
83
|
+
};
|
|
84
|
+
option: {
|
|
85
|
+
ok: () => void;
|
|
86
|
+
error: () => void;
|
|
87
|
+
};
|
|
88
|
+
path: {
|
|
89
|
+
rootMismatch: () => void;
|
|
90
|
+
arrayIndex: () => void;
|
|
91
|
+
recordKey: () => void;
|
|
92
|
+
nestedArray: () => void;
|
|
93
|
+
tupleIndex: () => void;
|
|
94
|
+
structKey: () => void;
|
|
95
|
+
deepStruct: () => void;
|
|
96
|
+
recursiveSchema: () => void;
|
|
97
|
+
orRoot: () => void;
|
|
98
|
+
};
|
|
99
|
+
recursive: {
|
|
100
|
+
arrayOfArrays: () => void;
|
|
101
|
+
recordOfRecords: () => void;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export default _default;
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { parse } from "./module.f.js";
|
|
2
|
+
import { boolean, number, string, bigint, unknown, array, record, or, option } from "../module.f.js";
|
|
3
|
+
const assertOk = ([k]) => { if (k !== 'ok') {
|
|
4
|
+
throw 'expected ok';
|
|
5
|
+
} };
|
|
6
|
+
const assertError = ([k]) => { if (k !== 'error') {
|
|
7
|
+
throw 'expected error';
|
|
8
|
+
} };
|
|
9
|
+
const unwrap = (r) => {
|
|
10
|
+
if (r[0] !== 'ok') {
|
|
11
|
+
throw 'expected ok';
|
|
12
|
+
}
|
|
13
|
+
return r[1];
|
|
14
|
+
};
|
|
15
|
+
const assertErrorPath = (expected) => (r) => {
|
|
16
|
+
if (r[0] !== 'error') {
|
|
17
|
+
throw 'expected error';
|
|
18
|
+
}
|
|
19
|
+
const e = r[1];
|
|
20
|
+
if (e.path.length !== expected.length) {
|
|
21
|
+
throw `path length ${e.path.length} != ${expected.length}`;
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < expected.length; i++) {
|
|
24
|
+
if (e.path[i] !== expected[i]) {
|
|
25
|
+
throw `path[${i}] ${e.path[i]} != ${expected[i]}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const assertDeepEqual = (a, b) => {
|
|
30
|
+
if (a === b) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (a instanceof Array && b instanceof Array) {
|
|
34
|
+
if (a.length !== b.length) {
|
|
35
|
+
throw `array length ${a.length} != ${b.length}`;
|
|
36
|
+
}
|
|
37
|
+
for (let i = 0; i < a.length; i++) {
|
|
38
|
+
assertDeepEqual(a[i], b[i]);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (typeof a === 'object' && a !== null && typeof b === 'object' && b !== null) {
|
|
43
|
+
const ka = Object.keys(a).sort();
|
|
44
|
+
const kb = Object.keys(b).sort();
|
|
45
|
+
if (ka.length !== kb.length) {
|
|
46
|
+
throw `key count ${ka.length} != ${kb.length}`;
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < ka.length; i++) {
|
|
49
|
+
if (ka[i] !== kb[i]) {
|
|
50
|
+
throw `key ${ka[i]} != ${kb[i]}`;
|
|
51
|
+
}
|
|
52
|
+
assertDeepEqual(a[ka[i]], b[kb[i]]);
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
throw `not deep-equal: ${String(a)} vs ${String(b)}`;
|
|
57
|
+
};
|
|
58
|
+
export default {
|
|
59
|
+
boolean: {
|
|
60
|
+
ok: () => {
|
|
61
|
+
assertOk(parse(boolean)(true));
|
|
62
|
+
assertOk(parse(boolean)(false));
|
|
63
|
+
},
|
|
64
|
+
error: () => {
|
|
65
|
+
assertError(parse(boolean)(0));
|
|
66
|
+
assertError(parse(boolean)('true'));
|
|
67
|
+
assertError(parse(boolean)(null));
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
number: {
|
|
71
|
+
ok: () => {
|
|
72
|
+
assertOk(parse(number)(42));
|
|
73
|
+
},
|
|
74
|
+
error: () => {
|
|
75
|
+
assertError(parse(number)('42'));
|
|
76
|
+
assertError(parse(number)(42n));
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
string: {
|
|
80
|
+
ok: () => {
|
|
81
|
+
assertOk(parse(string)('hello'));
|
|
82
|
+
},
|
|
83
|
+
error: () => {
|
|
84
|
+
assertError(parse(string)(42));
|
|
85
|
+
assertError(parse(string)(null));
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
bigint: {
|
|
89
|
+
ok: () => {
|
|
90
|
+
assertOk(parse(bigint)(4n));
|
|
91
|
+
},
|
|
92
|
+
error: () => {
|
|
93
|
+
assertError(parse(bigint)(4));
|
|
94
|
+
assertError(parse(bigint)('4'));
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
unknown: {
|
|
98
|
+
ok: () => {
|
|
99
|
+
assertOk(parse(unknown)(null));
|
|
100
|
+
assertOk(parse(unknown)(42));
|
|
101
|
+
assertOk(parse(unknown)('hello'));
|
|
102
|
+
assertOk(parse(unknown)(true));
|
|
103
|
+
assertOk(parse(unknown)({}));
|
|
104
|
+
assertOk(parse(unknown)([]));
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
const: {
|
|
108
|
+
null: {
|
|
109
|
+
ok: () => assertOk(parse(null)(null)),
|
|
110
|
+
error: () => {
|
|
111
|
+
assertError(parse(null)(undefined));
|
|
112
|
+
assertError(parse(null)(0));
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
undefined: {
|
|
116
|
+
ok: () => assertOk(parse(undefined)(undefined)),
|
|
117
|
+
error: () => assertError(parse(undefined)(null)),
|
|
118
|
+
},
|
|
119
|
+
number: {
|
|
120
|
+
ok: () => assertOk(parse(42)(42)),
|
|
121
|
+
error: () => assertError(parse(42)(43)),
|
|
122
|
+
},
|
|
123
|
+
string: {
|
|
124
|
+
ok: () => assertOk(parse('hello')('hello')),
|
|
125
|
+
error: () => assertError(parse('hello')('world')),
|
|
126
|
+
},
|
|
127
|
+
bigint: {
|
|
128
|
+
ok: () => assertOk(parse(7n)(7n)),
|
|
129
|
+
error: () => assertError(parse(7n)(8n)),
|
|
130
|
+
},
|
|
131
|
+
boolean: {
|
|
132
|
+
ok: () => assertOk(parse(true)(true)),
|
|
133
|
+
error: () => assertError(parse(true)(false)),
|
|
134
|
+
},
|
|
135
|
+
tuple: {
|
|
136
|
+
ok: () => {
|
|
137
|
+
const t = [42, 'hello'];
|
|
138
|
+
const r = parse(t)([42, 'hello']);
|
|
139
|
+
assertDeepEqual(unwrap(r), [42, 'hello']);
|
|
140
|
+
},
|
|
141
|
+
// The key behavior change vs `validate`: extra tuple elements are dropped.
|
|
142
|
+
extraItemsDropped: () => {
|
|
143
|
+
const r = parse([42])([42, 'extra']);
|
|
144
|
+
assertDeepEqual(unwrap(r), [42]);
|
|
145
|
+
},
|
|
146
|
+
error: () => {
|
|
147
|
+
assertError(parse([42])([99]));
|
|
148
|
+
assertError(parse([42])({}));
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
struct: {
|
|
152
|
+
ok: () => {
|
|
153
|
+
const t = { a: 42, b: 'hello' };
|
|
154
|
+
const r = parse(t)({ a: 42, b: 'hello' });
|
|
155
|
+
assertDeepEqual(unwrap(r), { a: 42, b: 'hello' });
|
|
156
|
+
},
|
|
157
|
+
// Undeclared properties are dropped from the constructed value.
|
|
158
|
+
extraKeysDropped: () => {
|
|
159
|
+
const r = parse({ a: 42 })({ a: 42, b: 'extra' });
|
|
160
|
+
assertDeepEqual(unwrap(r), { a: 42 });
|
|
161
|
+
},
|
|
162
|
+
error: () => {
|
|
163
|
+
assertError(parse({ a: 42 })({ a: 99 }));
|
|
164
|
+
assertError(parse({ a: 42 })([]));
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
array: {
|
|
169
|
+
empty: () => {
|
|
170
|
+
const r = parse(array(number))([]);
|
|
171
|
+
assertDeepEqual(unwrap(r), []);
|
|
172
|
+
},
|
|
173
|
+
ok: () => {
|
|
174
|
+
const r = parse(array(number))([1, 2, 3]);
|
|
175
|
+
assertDeepEqual(unwrap(r), [1, 2, 3]);
|
|
176
|
+
},
|
|
177
|
+
// `parse` always constructs a new array, even when the inner type is a primitive.
|
|
178
|
+
freshArray: () => {
|
|
179
|
+
const input = [1, 2, 3];
|
|
180
|
+
const out = unwrap(parse(array(number))(input));
|
|
181
|
+
if (out === input) {
|
|
182
|
+
throw 'expected a fresh array';
|
|
183
|
+
}
|
|
184
|
+
assertDeepEqual(out, [1, 2, 3]);
|
|
185
|
+
},
|
|
186
|
+
error: () => {
|
|
187
|
+
assertError(parse(array(number))([1, 'two', 3]));
|
|
188
|
+
assertError(parse(array(number))({}));
|
|
189
|
+
assertError(parse(array(number))(null));
|
|
190
|
+
},
|
|
191
|
+
nested: () => {
|
|
192
|
+
const r = parse(array(array(boolean)))([[true, false], [false]]);
|
|
193
|
+
assertDeepEqual(unwrap(r), [[true, false], [false]]);
|
|
194
|
+
assertError(parse(array(array(boolean)))([[true, 42]]));
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
record: {
|
|
198
|
+
empty: () => {
|
|
199
|
+
const r = parse(record(number))({});
|
|
200
|
+
assertDeepEqual(unwrap(r), {});
|
|
201
|
+
},
|
|
202
|
+
ok: () => {
|
|
203
|
+
const r = parse(record(string))({ a: 'hello', b: 'world' });
|
|
204
|
+
assertDeepEqual(unwrap(r), { a: 'hello', b: 'world' });
|
|
205
|
+
},
|
|
206
|
+
// `parse` always constructs a new record.
|
|
207
|
+
freshRecord: () => {
|
|
208
|
+
const input = { a: 1, b: 2 };
|
|
209
|
+
const out = unwrap(parse(record(number))(input));
|
|
210
|
+
if (out === input) {
|
|
211
|
+
throw 'expected a fresh record';
|
|
212
|
+
}
|
|
213
|
+
assertDeepEqual(out, { a: 1, b: 2 });
|
|
214
|
+
},
|
|
215
|
+
error: () => {
|
|
216
|
+
assertError(parse(record(number))({ a: 1, b: 'two' }));
|
|
217
|
+
assertError(parse(record(number))(null));
|
|
218
|
+
assertError(parse(record(number))([]));
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
constThunk: {
|
|
222
|
+
primitive: () => {
|
|
223
|
+
const t = () => ['const', 7n];
|
|
224
|
+
assertOk(parse(t)(7n));
|
|
225
|
+
assertError(parse(t)(8n));
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
or: {
|
|
229
|
+
consts: {
|
|
230
|
+
ok: () => {
|
|
231
|
+
const t = or(...[false, 42, 'hello']);
|
|
232
|
+
assertOk(parse(t)(false));
|
|
233
|
+
assertOk(parse(t)(42));
|
|
234
|
+
assertOk(parse(t)('hello'));
|
|
235
|
+
},
|
|
236
|
+
error: () => {
|
|
237
|
+
const t = or(...[false, 42, 'hello']);
|
|
238
|
+
assertError(parse(t)(true));
|
|
239
|
+
assertError(parse(t)(43));
|
|
240
|
+
assertError(parse(t)('world'));
|
|
241
|
+
assertError(parse(t)(null));
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
thunks: {
|
|
245
|
+
ok: () => {
|
|
246
|
+
const t = or(number, string);
|
|
247
|
+
assertOk(parse(t)(42));
|
|
248
|
+
assertOk(parse(t)('hello'));
|
|
249
|
+
},
|
|
250
|
+
error: () => {
|
|
251
|
+
const t = or(number, string);
|
|
252
|
+
assertError(parse(t)(true));
|
|
253
|
+
assertError(parse(t)(null));
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
// First matching variant wins; the freshly-constructed value comes from that variant.
|
|
257
|
+
firstMatchWins: () => {
|
|
258
|
+
const t = or([number], array(number));
|
|
259
|
+
const out = unwrap(parse(t)([1, 2, 3]));
|
|
260
|
+
// The const tuple `[number]` matches first and returns a length-1 result.
|
|
261
|
+
assertDeepEqual(out, [1]);
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
option: {
|
|
265
|
+
ok: () => {
|
|
266
|
+
const t = option(number);
|
|
267
|
+
assertOk(parse(t)(42));
|
|
268
|
+
assertOk(parse(t)(undefined));
|
|
269
|
+
},
|
|
270
|
+
error: () => {
|
|
271
|
+
const t = option(number);
|
|
272
|
+
assertError(parse(t)(null));
|
|
273
|
+
assertError(parse(t)('42'));
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
path: {
|
|
277
|
+
rootMismatch: () => assertErrorPath([])(parse(number)('not a number')),
|
|
278
|
+
arrayIndex: () => assertErrorPath(['1'])(parse(array(number))([1, 'two', 3])),
|
|
279
|
+
recordKey: () => {
|
|
280
|
+
const r = parse(record(number))({ a: 1, b: 'two', c: 3 });
|
|
281
|
+
assertErrorPath(['b'])(r);
|
|
282
|
+
},
|
|
283
|
+
nestedArray: () => assertErrorPath(['0', '1'])(parse(array(array(number)))([[1, 'x'], [2, 3]])),
|
|
284
|
+
tupleIndex: () => assertErrorPath(['1'])(parse([number, number])([1, 'two'])),
|
|
285
|
+
structKey: () => assertErrorPath(['b'])(parse({ a: number, b: number })({ a: 1, b: 'two' })),
|
|
286
|
+
deepStruct: () => {
|
|
287
|
+
const schema = { user: { name: string, age: number } };
|
|
288
|
+
const r = parse(schema)({ user: { name: 'A', age: 'old' } });
|
|
289
|
+
assertErrorPath(['user', 'age'])(r);
|
|
290
|
+
},
|
|
291
|
+
recursiveSchema: () => {
|
|
292
|
+
const list = () => ['array', list];
|
|
293
|
+
const r = parse(list)([[[42]]]);
|
|
294
|
+
assertErrorPath(['0', '0', '0'])(r);
|
|
295
|
+
},
|
|
296
|
+
orRoot: () => assertErrorPath([])(parse(or(number, string))(true)),
|
|
297
|
+
},
|
|
298
|
+
recursive: {
|
|
299
|
+
arrayOfArrays: () => {
|
|
300
|
+
const list = () => ['array', list];
|
|
301
|
+
const v = parse(list);
|
|
302
|
+
assertOk(v([]));
|
|
303
|
+
assertOk(v([[], []]));
|
|
304
|
+
assertOk(v([[[], []], []]));
|
|
305
|
+
assertError(v([42]));
|
|
306
|
+
assertError(v(null));
|
|
307
|
+
},
|
|
308
|
+
recordOfRecords: () => {
|
|
309
|
+
const tree = () => ['record', tree];
|
|
310
|
+
const v = parse(tree);
|
|
311
|
+
assertOk(v({}));
|
|
312
|
+
assertOk(v({ a: {}, b: { c: {} } }));
|
|
313
|
+
assertError(v({ a: 42 }));
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime validation of unknown values against RTTI schemas.
|
|
3
|
+
*
|
|
4
|
+
* The main entry point is `validate(rtti)`, which takes a schema `Type` and returns
|
|
5
|
+
* a `Validate<T>` function. When called with an unknown value, it returns a `Result`
|
|
6
|
+
* that is either `['ok', typedValue]` or `['error', { path, message }]`.
|
|
7
|
+
*
|
|
8
|
+
* ## Error path
|
|
9
|
+
*
|
|
10
|
+
* On failure, the error carries a `path` pointing at the offending sub-value:
|
|
11
|
+
* each step is the string property name (for structs/records) or the stringified
|
|
12
|
+
* index (for tuples/arrays). The path is empty when the failure is at the root.
|
|
13
|
+
*
|
|
14
|
+
* ## Dispatch strategy
|
|
15
|
+
*
|
|
16
|
+
* - **`Thunk`** schemas are evaluated lazily: the thunk is called once to obtain an
|
|
17
|
+
* `Info` descriptor, then dispatched by tag:
|
|
18
|
+
* - `'const'` — delegates to `constValidate`
|
|
19
|
+
* - `'unknown'` — always succeeds (any DJS value is valid)
|
|
20
|
+
* - `Tag1` (`'array'`, `'record'`) — delegates to `containerValidate`
|
|
21
|
+
* - `Tag0` (`'boolean'`, `'number'`, `'string'`, `'bigint'`) — uses `typeof` check
|
|
22
|
+
* - `'or'` — tries each variant; reports `'no match'` at the current location if all fail
|
|
23
|
+
* - **`Const`** schemas (primitives, tuples, structs) validate by exact equality or
|
|
24
|
+
* recursive field/element checking.
|
|
25
|
+
*
|
|
26
|
+
* ## Recursion safety
|
|
27
|
+
*
|
|
28
|
+
* For `array` and `record` schemas, the inner item validator is instantiated lazily —
|
|
29
|
+
* only after confirming the container is non-empty. This prevents infinite recursion
|
|
30
|
+
* when validating recursive schemas like `const list = () => ['array', list]`.
|
|
31
|
+
*
|
|
32
|
+
* @module
|
|
33
|
+
*/
|
|
34
|
+
import type { Unknown } from '../../../djs/module.f.ts';
|
|
35
|
+
import { type Info0, type Primitive0, type Type } from '../module.f.ts';
|
|
36
|
+
import { type Error, type Result as CommonResult } from '../../result/module.f.ts';
|
|
37
|
+
import type { Ts } from '../ts/module.f.ts';
|
|
38
|
+
import type { Primitive } from '../../../djs/module.f.ts';
|
|
39
|
+
/** A path to a sub-value within the validated structure. Each step is an object key or stringified array index. */
|
|
40
|
+
export type Path = readonly string[];
|
|
41
|
+
/** Detailed validation failure: the offending `path` plus a short `message`. */
|
|
42
|
+
export type ValidationError = {
|
|
43
|
+
readonly path: Path;
|
|
44
|
+
readonly message: string;
|
|
45
|
+
};
|
|
46
|
+
/** Validation result: either the typed value or a `ValidationError`. */
|
|
47
|
+
export type Result<T extends Type> = CommonResult<Ts<T>, ValidationError>;
|
|
48
|
+
/** A function that validates an unknown value against schema `T`. */
|
|
49
|
+
export type Validate<T extends Type> = (value: Unknown) => Result<T>;
|
|
50
|
+
/** Builds an error result with empty path and the given message. */
|
|
51
|
+
export declare const verror: (message: string) => Error<ValidationError>;
|
|
52
|
+
/** Prepends `key` to the error's path, used to build the path bottom-up. */
|
|
53
|
+
export declare const prependPath: (key: string, r: Error<ValidationError>) => Error<ValidationError>;
|
|
54
|
+
/** Validates a `Tag0` primitive schema using `typeof`. */
|
|
55
|
+
export declare const primitive0Validate: <K extends Primitive0, T extends Info0<K>>(tag: K) => Validate<T>;
|
|
56
|
+
/** Validates a primitive `Const` schema using strict equality (`===`). */
|
|
57
|
+
export declare const constPrimitiveValidate: <T extends Primitive>(rtti: T) => Validate<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a validator function for the given RTTI schema.
|
|
60
|
+
*
|
|
61
|
+
* @param rtti - A schema `Type`: a `Thunk` for tag-based schemas, or a `Const`
|
|
62
|
+
* (primitive literal, tuple, or struct) for exact-value schemas.
|
|
63
|
+
* @returns A `Validate<T>` function that checks an unknown value and returns
|
|
64
|
+
* `['ok', value]` or `['error', { path, message }]`.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const v = validate(array(number))
|
|
69
|
+
* v([1, 2, 3]) // ['ok', [1, 2, 3]]
|
|
70
|
+
* v([1, 'two']) // ['error', { path: ['1'], message: 'unexpected value' }]
|
|
71
|
+
* v(['a']) // ['error', { path: ['0'], message: 'unexpected value' }]
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const validate: <T extends Type>(rtti: T) => Validate<T>;
|