typesea 0.1.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.
Files changed (271) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +320 -0
  4. package/dist/adapters/index.d.ts +152 -0
  5. package/dist/adapters/index.d.ts.map +1 -0
  6. package/dist/adapters/index.js +396 -0
  7. package/dist/aot/index.d.ts +33 -0
  8. package/dist/aot/index.d.ts.map +1 -0
  9. package/dist/aot/index.js +295 -0
  10. package/dist/async/index.d.ts +111 -0
  11. package/dist/async/index.d.ts.map +1 -0
  12. package/dist/async/index.js +221 -0
  13. package/dist/builders/composite.d.ts +31 -0
  14. package/dist/builders/composite.d.ts.map +1 -0
  15. package/dist/builders/composite.js +165 -0
  16. package/dist/builders/index.d.ts +11 -0
  17. package/dist/builders/index.d.ts.map +1 -0
  18. package/dist/builders/index.js +9 -0
  19. package/dist/builders/modifier.d.ts +26 -0
  20. package/dist/builders/modifier.d.ts.map +1 -0
  21. package/dist/builders/modifier.js +67 -0
  22. package/dist/builders/object/guard.d.ts +62 -0
  23. package/dist/builders/object/guard.d.ts.map +1 -0
  24. package/dist/builders/object/guard.js +113 -0
  25. package/dist/builders/object/index.d.ts +7 -0
  26. package/dist/builders/object/index.d.ts.map +1 -0
  27. package/dist/builders/object/index.js +5 -0
  28. package/dist/builders/object/schema.d.ts +44 -0
  29. package/dist/builders/object/schema.d.ts.map +1 -0
  30. package/dist/builders/object/schema.js +257 -0
  31. package/dist/builders/object/types.d.ts +63 -0
  32. package/dist/builders/object/types.d.ts.map +1 -0
  33. package/dist/builders/object/types.js +5 -0
  34. package/dist/builders/scalar.d.ts +39 -0
  35. package/dist/builders/scalar.d.ts.map +1 -0
  36. package/dist/builders/scalar.js +63 -0
  37. package/dist/builders/table.d.ts +53 -0
  38. package/dist/builders/table.d.ts.map +1 -0
  39. package/dist/builders/table.js +48 -0
  40. package/dist/builders/types.d.ts +26 -0
  41. package/dist/builders/types.d.ts.map +1 -0
  42. package/dist/builders/types.js +5 -0
  43. package/dist/compile/check-composite.d.ts +34 -0
  44. package/dist/compile/check-composite.d.ts.map +1 -0
  45. package/dist/compile/check-composite.js +117 -0
  46. package/dist/compile/check-scalar.d.ts +24 -0
  47. package/dist/compile/check-scalar.d.ts.map +1 -0
  48. package/dist/compile/check-scalar.js +73 -0
  49. package/dist/compile/check.d.ts +15 -0
  50. package/dist/compile/check.d.ts.map +1 -0
  51. package/dist/compile/check.js +98 -0
  52. package/dist/compile/context.d.ts +35 -0
  53. package/dist/compile/context.d.ts.map +1 -0
  54. package/dist/compile/context.js +72 -0
  55. package/dist/compile/graph-predicate.d.ts +19 -0
  56. package/dist/compile/graph-predicate.d.ts.map +1 -0
  57. package/dist/compile/graph-predicate.js +460 -0
  58. package/dist/compile/guard.d.ts +41 -0
  59. package/dist/compile/guard.d.ts.map +1 -0
  60. package/dist/compile/guard.js +180 -0
  61. package/dist/compile/index.d.ts +8 -0
  62. package/dist/compile/index.d.ts.map +1 -0
  63. package/dist/compile/index.js +6 -0
  64. package/dist/compile/issue.d.ts +18 -0
  65. package/dist/compile/issue.d.ts.map +1 -0
  66. package/dist/compile/issue.js +28 -0
  67. package/dist/compile/names.d.ts +16 -0
  68. package/dist/compile/names.d.ts.map +1 -0
  69. package/dist/compile/names.js +82 -0
  70. package/dist/compile/predicate.d.ts +23 -0
  71. package/dist/compile/predicate.d.ts.map +1 -0
  72. package/dist/compile/predicate.js +317 -0
  73. package/dist/compile/runtime.d.ts +55 -0
  74. package/dist/compile/runtime.d.ts.map +1 -0
  75. package/dist/compile/runtime.js +63 -0
  76. package/dist/compile/source.d.ts +11 -0
  77. package/dist/compile/source.d.ts.map +1 -0
  78. package/dist/compile/source.js +51 -0
  79. package/dist/compile/types.d.ts +52 -0
  80. package/dist/compile/types.d.ts.map +1 -0
  81. package/dist/compile/types.js +5 -0
  82. package/dist/decoder/index.d.ts +106 -0
  83. package/dist/decoder/index.d.ts.map +1 -0
  84. package/dist/decoder/index.js +262 -0
  85. package/dist/evaluate/check-composite.d.ts +39 -0
  86. package/dist/evaluate/check-composite.d.ts.map +1 -0
  87. package/dist/evaluate/check-composite.js +184 -0
  88. package/dist/evaluate/check-scalar.d.ts +20 -0
  89. package/dist/evaluate/check-scalar.d.ts.map +1 -0
  90. package/dist/evaluate/check-scalar.js +81 -0
  91. package/dist/evaluate/check.d.ts +11 -0
  92. package/dist/evaluate/check.d.ts.map +1 -0
  93. package/dist/evaluate/check.js +126 -0
  94. package/dist/evaluate/index.d.ts +7 -0
  95. package/dist/evaluate/index.d.ts.map +1 -0
  96. package/dist/evaluate/index.js +6 -0
  97. package/dist/evaluate/issue.d.ts +10 -0
  98. package/dist/evaluate/issue.d.ts.map +1 -0
  99. package/dist/evaluate/issue.js +11 -0
  100. package/dist/evaluate/predicate.d.ts +26 -0
  101. package/dist/evaluate/predicate.d.ts.map +1 -0
  102. package/dist/evaluate/predicate.js +37 -0
  103. package/dist/evaluate/shared.d.ts +59 -0
  104. package/dist/evaluate/shared.d.ts.map +1 -0
  105. package/dist/evaluate/shared.js +96 -0
  106. package/dist/evaluate/state.d.ts +65 -0
  107. package/dist/evaluate/state.d.ts.map +1 -0
  108. package/dist/evaluate/state.js +66 -0
  109. package/dist/guard/base.d.ts +72 -0
  110. package/dist/guard/base.d.ts.map +1 -0
  111. package/dist/guard/base.js +136 -0
  112. package/dist/guard/error.d.ts +19 -0
  113. package/dist/guard/error.d.ts.map +1 -0
  114. package/dist/guard/error.js +22 -0
  115. package/dist/guard/index.d.ts +10 -0
  116. package/dist/guard/index.d.ts.map +1 -0
  117. package/dist/guard/index.js +8 -0
  118. package/dist/guard/number.d.ts +32 -0
  119. package/dist/guard/number.d.ts.map +1 -0
  120. package/dist/guard/number.js +71 -0
  121. package/dist/guard/props.d.ts +18 -0
  122. package/dist/guard/props.d.ts.map +1 -0
  123. package/dist/guard/props.js +35 -0
  124. package/dist/guard/read.d.ts +42 -0
  125. package/dist/guard/read.d.ts.map +1 -0
  126. package/dist/guard/read.js +114 -0
  127. package/dist/guard/registry.d.ts +15 -0
  128. package/dist/guard/registry.d.ts.map +1 -0
  129. package/dist/guard/registry.js +21 -0
  130. package/dist/guard/string.d.ts +36 -0
  131. package/dist/guard/string.d.ts.map +1 -0
  132. package/dist/guard/string.js +95 -0
  133. package/dist/guard/types.d.ts +103 -0
  134. package/dist/guard/types.d.ts.map +1 -0
  135. package/dist/guard/types.js +5 -0
  136. package/dist/index.d.ts +14 -0
  137. package/dist/index.d.ts.map +1 -0
  138. package/dist/index.js +10 -0
  139. package/dist/internal/index.d.ts +34 -0
  140. package/dist/internal/index.d.ts.map +1 -0
  141. package/dist/internal/index.js +56 -0
  142. package/dist/ir/builder.d.ts +173 -0
  143. package/dist/ir/builder.d.ts.map +1 -0
  144. package/dist/ir/builder.js +481 -0
  145. package/dist/ir/freeze.d.ts +10 -0
  146. package/dist/ir/freeze.d.ts.map +1 -0
  147. package/dist/ir/freeze.js +102 -0
  148. package/dist/ir/index.d.ts +9 -0
  149. package/dist/ir/index.d.ts.map +1 -0
  150. package/dist/ir/index.js +7 -0
  151. package/dist/ir/regexp.d.ts +6 -0
  152. package/dist/ir/regexp.d.ts.map +1 -0
  153. package/dist/ir/regexp.js +12 -0
  154. package/dist/ir/types.d.ts +215 -0
  155. package/dist/ir/types.d.ts.map +1 -0
  156. package/dist/ir/types.js +5 -0
  157. package/dist/ir/validate.d.ts +10 -0
  158. package/dist/ir/validate.d.ts.map +1 -0
  159. package/dist/ir/validate.js +271 -0
  160. package/dist/issue/index.d.ts +44 -0
  161. package/dist/issue/index.d.ts.map +1 -0
  162. package/dist/issue/index.js +152 -0
  163. package/dist/json-schema/emit-combinator.d.ts +28 -0
  164. package/dist/json-schema/emit-combinator.d.ts.map +1 -0
  165. package/dist/json-schema/emit-combinator.js +96 -0
  166. package/dist/json-schema/emit-composite.d.ts +28 -0
  167. package/dist/json-schema/emit-composite.d.ts.map +1 -0
  168. package/dist/json-schema/emit-composite.js +127 -0
  169. package/dist/json-schema/emit-scalar.d.ts +25 -0
  170. package/dist/json-schema/emit-scalar.d.ts.map +1 -0
  171. package/dist/json-schema/emit-scalar.js +104 -0
  172. package/dist/json-schema/emit-types.d.ts +12 -0
  173. package/dist/json-schema/emit-types.d.ts.map +1 -0
  174. package/dist/json-schema/emit-types.js +5 -0
  175. package/dist/json-schema/emit.d.ts +12 -0
  176. package/dist/json-schema/emit.d.ts.map +1 -0
  177. package/dist/json-schema/emit.js +62 -0
  178. package/dist/json-schema/freeze.d.ts +14 -0
  179. package/dist/json-schema/freeze.d.ts.map +1 -0
  180. package/dist/json-schema/freeze.js +114 -0
  181. package/dist/json-schema/index.d.ts +20 -0
  182. package/dist/json-schema/index.d.ts.map +1 -0
  183. package/dist/json-schema/index.js +76 -0
  184. package/dist/json-schema/issue.d.ts +11 -0
  185. package/dist/json-schema/issue.d.ts.map +1 -0
  186. package/dist/json-schema/issue.js +14 -0
  187. package/dist/json-schema/read.d.ts +29 -0
  188. package/dist/json-schema/read.d.ts.map +1 -0
  189. package/dist/json-schema/read.js +87 -0
  190. package/dist/json-schema/types.d.ts +106 -0
  191. package/dist/json-schema/types.d.ts.map +1 -0
  192. package/dist/json-schema/types.js +5 -0
  193. package/dist/kind/index.d.ts +119 -0
  194. package/dist/kind/index.d.ts.map +1 -0
  195. package/dist/kind/index.js +94 -0
  196. package/dist/lower/index.d.ts +7 -0
  197. package/dist/lower/index.d.ts.map +1 -0
  198. package/dist/lower/index.js +199 -0
  199. package/dist/message/index.d.ts +51 -0
  200. package/dist/message/index.d.ts.map +1 -0
  201. package/dist/message/index.js +269 -0
  202. package/dist/optimize/compact.d.ts +10 -0
  203. package/dist/optimize/compact.d.ts.map +1 -0
  204. package/dist/optimize/compact.js +60 -0
  205. package/dist/optimize/fold-boolean.d.ts +15 -0
  206. package/dist/optimize/fold-boolean.d.ts.map +1 -0
  207. package/dist/optimize/fold-boolean.js +75 -0
  208. package/dist/optimize/fold-common.d.ts +45 -0
  209. package/dist/optimize/fold-common.d.ts.map +1 -0
  210. package/dist/optimize/fold-common.js +71 -0
  211. package/dist/optimize/fold-scalar.d.ts +59 -0
  212. package/dist/optimize/fold-scalar.d.ts.map +1 -0
  213. package/dist/optimize/fold-scalar.js +174 -0
  214. package/dist/optimize/fold.d.ts +10 -0
  215. package/dist/optimize/fold.d.ts.map +1 -0
  216. package/dist/optimize/fold.js +103 -0
  217. package/dist/optimize/index.d.ts +10 -0
  218. package/dist/optimize/index.d.ts.map +1 -0
  219. package/dist/optimize/index.js +23 -0
  220. package/dist/optimize/map-node.d.ts +21 -0
  221. package/dist/optimize/map-node.d.ts.map +1 -0
  222. package/dist/optimize/map-node.js +222 -0
  223. package/dist/optimize/remap.d.ts +30 -0
  224. package/dist/optimize/remap.d.ts.map +1 -0
  225. package/dist/optimize/remap.js +46 -0
  226. package/dist/optimize/rewrite.d.ts +22 -0
  227. package/dist/optimize/rewrite.d.ts.map +1 -0
  228. package/dist/optimize/rewrite.js +34 -0
  229. package/dist/plan/cache.d.ts +20 -0
  230. package/dist/plan/cache.d.ts.map +1 -0
  231. package/dist/plan/cache.js +122 -0
  232. package/dist/plan/index.d.ts +8 -0
  233. package/dist/plan/index.d.ts.map +1 -0
  234. package/dist/plan/index.js +6 -0
  235. package/dist/plan/predicate.d.ts +27 -0
  236. package/dist/plan/predicate.d.ts.map +1 -0
  237. package/dist/plan/predicate.js +415 -0
  238. package/dist/plan/schema-predicate.d.ts +15 -0
  239. package/dist/plan/schema-predicate.d.ts.map +1 -0
  240. package/dist/plan/schema-predicate.js +277 -0
  241. package/dist/plan/types.d.ts +18 -0
  242. package/dist/plan/types.d.ts.map +1 -0
  243. package/dist/plan/types.js +5 -0
  244. package/dist/result/index.d.ts +27 -0
  245. package/dist/result/index.d.ts.map +1 -0
  246. package/dist/result/index.js +20 -0
  247. package/dist/schema/common.d.ts +30 -0
  248. package/dist/schema/common.d.ts.map +1 -0
  249. package/dist/schema/common.js +102 -0
  250. package/dist/schema/freeze.d.ts +10 -0
  251. package/dist/schema/freeze.d.ts.map +1 -0
  252. package/dist/schema/freeze.js +163 -0
  253. package/dist/schema/index.d.ts +11 -0
  254. package/dist/schema/index.d.ts.map +1 -0
  255. package/dist/schema/index.js +9 -0
  256. package/dist/schema/lazy.d.ts +10 -0
  257. package/dist/schema/lazy.d.ts.map +1 -0
  258. package/dist/schema/lazy.js +25 -0
  259. package/dist/schema/literal.d.ts +10 -0
  260. package/dist/schema/literal.d.ts.map +1 -0
  261. package/dist/schema/literal.js +17 -0
  262. package/dist/schema/types.d.ts +243 -0
  263. package/dist/schema/types.d.ts.map +1 -0
  264. package/dist/schema/types.js +9 -0
  265. package/dist/schema/validate.d.ts +10 -0
  266. package/dist/schema/validate.d.ts.map +1 -0
  267. package/dist/schema/validate.js +268 -0
  268. package/docs/api.md +301 -0
  269. package/docs/engine-notes.md +153 -0
  270. package/docs/index.html +1242 -0
  271. package/package.json +68 -0
@@ -0,0 +1,295 @@
1
+ import { emitCompiledSourceBundle } from "../compile/index.js";
2
+ import { SchemaTag } from "../kind/index.js";
3
+ import { err, ok } from "../result/index.js";
4
+ import { freezeSchema, isSchemaValue } from "../schema/index.js";
5
+ /**
6
+ * @brief emit aot module.
7
+ */
8
+ export function emitAotModule(guard, options) {
9
+ const schema = readAotSchema(guard);
10
+ const config = readOptions(options);
11
+ const issues = [];
12
+ scanAotSchema(schema, [], issues, new WeakSet());
13
+ if (issues.length !== 0) {
14
+ return err(freezeAotIssues(issues));
15
+ }
16
+ const bundle = emitCompiledSourceBundle(schema, config.name);
17
+ if (bundle.dynamicSchemas.length !== 0) {
18
+ return err(freezeAotIssues([
19
+ {
20
+ path: Object.freeze([]),
21
+ code: "unsupported_aot_refine",
22
+ message: "AOT modules cannot preserve dynamic schema fallback"
23
+ }
24
+ ]));
25
+ }
26
+ return ok(Object.freeze({
27
+ source: emitModuleSource(bundle),
28
+ declarationSource: emitDeclarationSource()
29
+ }));
30
+ }
31
+ /**
32
+ * @brief read aot schema.
33
+ */
34
+ function readAotSchema(guard) {
35
+ if (!isRecord(guard)) {
36
+ throw new TypeError("AOT guard must be a TypeSea guard");
37
+ }
38
+ const schema = guard["schema"];
39
+ if (!isSchemaValue(schema)) {
40
+ throw new TypeError("AOT guard must contain a valid TypeSea schema");
41
+ }
42
+ return freezeSchema(schema);
43
+ }
44
+ /**
45
+ * @brief read options.
46
+ */
47
+ function readOptions(options) {
48
+ if (options === undefined) {
49
+ return {
50
+ name: "typesea_aot"
51
+ };
52
+ }
53
+ if (!isRecord(options)) {
54
+ throw new TypeError("AOT options must be an object");
55
+ }
56
+ const name = options.name;
57
+ if (name === undefined) {
58
+ return {
59
+ name: "typesea_aot"
60
+ };
61
+ }
62
+ if (typeof name !== "string") {
63
+ throw new TypeError("AOT name must be a string");
64
+ }
65
+ return {
66
+ name
67
+ };
68
+ }
69
+ /**
70
+ * @brief scan aot schema.
71
+ */
72
+ function scanAotSchema(schema, path, issues, seen) {
73
+ if (seen.has(schema)) {
74
+ return;
75
+ }
76
+ seen.add(schema);
77
+ switch (schema.tag) {
78
+ case SchemaTag.Literal:
79
+ if (typeof schema.value === "symbol") {
80
+ pushIssue(path, issues, "unsupported_aot_symbol_literal", "AOT modules cannot preserve symbol literal identity");
81
+ }
82
+ return;
83
+ case SchemaTag.Array:
84
+ scanAotSchema(schema.item, path.concat("items"), issues, seen);
85
+ return;
86
+ case SchemaTag.Tuple:
87
+ scanSchemaArray(schema.items, path, issues, seen);
88
+ return;
89
+ case SchemaTag.Record:
90
+ scanAotSchema(schema.value, path.concat("additionalProperties"), issues, seen);
91
+ return;
92
+ case SchemaTag.Object:
93
+ scanObjectEntries(schema.entries, path, issues, seen);
94
+ return;
95
+ case SchemaTag.Union:
96
+ scanSchemaArray(schema.options, path, issues, seen);
97
+ return;
98
+ case SchemaTag.Intersection:
99
+ scanAotSchema(schema.left, path.concat("left"), issues, seen);
100
+ scanAotSchema(schema.right, path.concat("right"), issues, seen);
101
+ return;
102
+ case SchemaTag.Optional:
103
+ case SchemaTag.Undefinedable:
104
+ case SchemaTag.Nullable:
105
+ case SchemaTag.Brand:
106
+ scanAotSchema(schema.inner, path.concat("inner"), issues, seen);
107
+ return;
108
+ case SchemaTag.DiscriminatedUnion:
109
+ for (let index = 0; index < schema.cases.length; index += 1) {
110
+ const unionCase = schema.cases[index];
111
+ if (unionCase !== undefined) {
112
+ scanAotSchema(unionCase.schema, path.concat(index), issues, seen);
113
+ }
114
+ }
115
+ return;
116
+ case SchemaTag.Lazy:
117
+ pushIssue(path, issues, "unsupported_aot_lazy", "AOT modules cannot preserve lazy resolvers");
118
+ return;
119
+ case SchemaTag.Refine:
120
+ pushIssue(path, issues, "unsupported_aot_refine", "AOT modules cannot preserve refinement predicates");
121
+ return;
122
+ case SchemaTag.Unknown:
123
+ case SchemaTag.Never:
124
+ case SchemaTag.String:
125
+ case SchemaTag.Number:
126
+ case SchemaTag.BigInt:
127
+ case SchemaTag.Symbol:
128
+ case SchemaTag.Boolean:
129
+ return;
130
+ }
131
+ }
132
+ /**
133
+ * @brief scan schema array.
134
+ */
135
+ function scanSchemaArray(schemas, path, issues, seen) {
136
+ for (let index = 0; index < schemas.length; index += 1) {
137
+ const schema = schemas[index];
138
+ if (schema !== undefined) {
139
+ scanAotSchema(schema, path.concat(index), issues, seen);
140
+ }
141
+ }
142
+ }
143
+ /**
144
+ * @brief scan object entries.
145
+ */
146
+ function scanObjectEntries(entries, path, issues, seen) {
147
+ for (let index = 0; index < entries.length; index += 1) {
148
+ const entry = entries[index];
149
+ if (entry !== undefined) {
150
+ scanAotSchema(entry.schema, path.concat(entry.key), issues, seen);
151
+ }
152
+ }
153
+ }
154
+ /**
155
+ * @brief emit module source.
156
+ */
157
+ function emitModuleSource(bundle) {
158
+ return [
159
+ "const l=",
160
+ serializeLiteralArray(bundle.literals),
161
+ ";const r=",
162
+ serializeRegExpArray(bundle.regexps),
163
+ ";const k=",
164
+ JSON.stringify(bundle.keysets),
165
+ ";const u=",
166
+ JSON.stringify(bundle.strings),
167
+ ";const d=function(){return false;};",
168
+ "const m=function(){return;};",
169
+ "const sk=function(v,ks){if(typeof v!==\"object\"||v===null||Array.isArray(v))return false;const ps=Reflect.ownKeys(v);for(let i=0;i<ps.length;i+=1){const key=ps[i];if(typeof key!==\"string\"||!ks.includes(key))return false;}return true;};",
170
+ "const __typesea=(function(l,r,k,u,d,m,sk){",
171
+ bundle.source,
172
+ "})(l,r,k,u,d,m,sk);",
173
+ "const freezeIssues=function(xs){if(xs.length===0)return Object.freeze([]);const out=new Array(xs.length);for(let i=0;i<xs.length;i+=1){const x=xs[i];const p=x.path.slice();Object.freeze(p);const y={path:p,code:x.code,expected:x.expected,actual:x.actual,message:x.message};Object.freeze(y);out[i]=y;}return Object.freeze(out);};",
174
+ "export function is(value){return __typesea.is(value);}",
175
+ "export function check(value){const issues=freezeIssues(__typesea.check(value));if(issues.length===0)return Object.freeze({ok:true,value});return Object.freeze({ok:false,error:issues});}",
176
+ "export function assert(value){const result=check(value);if(!result.ok){const error=new Error(\"TypeSea assertion failed\");Object.defineProperty(error,\"issues\",{configurable:false,enumerable:true,value:result.error,writable:false});throw error;}}",
177
+ "export default Object.freeze({is,check,assert});",
178
+ ""
179
+ ].join("");
180
+ }
181
+ /**
182
+ * @brief emit declaration source.
183
+ */
184
+ function emitDeclarationSource() {
185
+ return [
186
+ "export interface AotIssue {",
187
+ " readonly path: readonly (string | number)[];",
188
+ " readonly code: string;",
189
+ " readonly expected: string | undefined;",
190
+ " readonly actual: string | undefined;",
191
+ " readonly message: string | undefined;",
192
+ "}",
193
+ "export type AotCheckResult<TValue = unknown> =",
194
+ " | { readonly ok: true; readonly value: TValue }",
195
+ " | { readonly ok: false; readonly error: readonly AotIssue[] };",
196
+ "export declare function is(value: unknown): boolean;",
197
+ "export declare function check<TValue = unknown>(value: TValue): AotCheckResult<TValue>;",
198
+ "export declare function assert(value: unknown): void;",
199
+ "declare const guard: {",
200
+ " readonly is: typeof is;",
201
+ " readonly check: typeof check;",
202
+ " readonly assert: typeof assert;",
203
+ "};",
204
+ "export default guard;",
205
+ ""
206
+ ].join("\n");
207
+ }
208
+ /**
209
+ * @brief serialize literal array.
210
+ */
211
+ function serializeLiteralArray(values) {
212
+ const parts = new Array(values.length);
213
+ for (let index = 0; index < values.length; index += 1) {
214
+ const value = values[index];
215
+ if (value !== undefined || Object.prototype.hasOwnProperty.call(values, index)) {
216
+ parts[index] = serializeLiteral(value);
217
+ }
218
+ }
219
+ return `[${parts.join(",")}]`;
220
+ }
221
+ /**
222
+ * @brief serialize literal.
223
+ */
224
+ function serializeLiteral(value) {
225
+ switch (typeof value) {
226
+ case "string":
227
+ return JSON.stringify(value);
228
+ case "number":
229
+ if (Number.isNaN(value)) {
230
+ return "Number.NaN";
231
+ }
232
+ if (Object.is(value, -0)) {
233
+ return "-0";
234
+ }
235
+ if (value === Number.POSITIVE_INFINITY) {
236
+ return "Number.POSITIVE_INFINITY";
237
+ }
238
+ if (value === Number.NEGATIVE_INFINITY) {
239
+ return "Number.NEGATIVE_INFINITY";
240
+ }
241
+ return String(value);
242
+ case "bigint":
243
+ return `${String(value)}n`;
244
+ case "boolean":
245
+ return value ? "true" : "false";
246
+ case "undefined":
247
+ return "undefined";
248
+ case "symbol":
249
+ throw new TypeError("symbol literals must be rejected before AOT serialization");
250
+ default:
251
+ return "null";
252
+ }
253
+ }
254
+ /**
255
+ * @brief serialize reg exp array.
256
+ */
257
+ function serializeRegExpArray(values) {
258
+ const parts = new Array(values.length);
259
+ for (let index = 0; index < values.length; index += 1) {
260
+ const value = values[index];
261
+ if (value !== undefined) {
262
+ parts[index] = `new RegExp(${JSON.stringify(value.source)},${JSON.stringify(value.flags)})`;
263
+ }
264
+ }
265
+ return `[${parts.join(",")}]`;
266
+ }
267
+ /**
268
+ * @brief push issue.
269
+ */
270
+ function pushIssue(path, issues, code, message) {
271
+ issues.push({
272
+ path: path.slice(),
273
+ code,
274
+ message
275
+ });
276
+ }
277
+ /**
278
+ * @brief freeze aot issues.
279
+ */
280
+ function freezeAotIssues(issues) {
281
+ for (let index = 0; index < issues.length; index += 1) {
282
+ const issue = issues[index];
283
+ if (issue !== undefined) {
284
+ Object.freeze(issue.path);
285
+ Object.freeze(issue);
286
+ }
287
+ }
288
+ return Object.freeze(issues);
289
+ }
290
+ /**
291
+ * @brief is record.
292
+ */
293
+ function isRecord(value) {
294
+ return typeof value === "object" && value !== null && !Array.isArray(value);
295
+ }
@@ -0,0 +1,111 @@
1
+ import { type DecodeSource, type Decoder, type InferDecoder } from "../decoder/index.js";
2
+ import type { Guard, Presence, RuntimeValue } from "../guard/index.js";
3
+ import { type CheckResult } from "../issue/index.js";
4
+ /**
5
+ * @brief async decode runner.
6
+ */
7
+ type AsyncDecodeRunner<TValue> = (value: unknown) => Promise<CheckResult<TValue>>;
8
+ /**
9
+ * @brief async predicate.
10
+ */
11
+ type AsyncPredicate<TValue> = (value: TValue) => boolean | Promise<boolean>;
12
+ /**
13
+ * @brief async mapper.
14
+ */
15
+ type AsyncMapper<TValue, TNext> = (value: TValue) => TNext | Promise<TNext>;
16
+ /**
17
+ * @brief async decoder run symbol.
18
+ */
19
+ declare const AsyncDecoderRunSymbol: unique symbol;
20
+ /**
21
+ * @brief async decode source.
22
+ */
23
+ export type AsyncDecodeSource = DecodeSource | AsyncDecoder<unknown>;
24
+ /**
25
+ * @brief infer async decoder.
26
+ */
27
+ export type InferAsyncDecoder<TSource> = TSource extends AsyncDecoder<infer TValue> ? TValue : InferDecoder<TSource>;
28
+ /**
29
+ * @brief async decoder.
30
+ */
31
+ export interface AsyncDecoder<TValue> {
32
+ /**
33
+ * @brief decode async.
34
+ */
35
+ decodeAsync(value: unknown): Promise<CheckResult<TValue>>;
36
+ /**
37
+ * @brief refine async.
38
+ */
39
+ refineAsync(predicate: AsyncPredicate<TValue>, name: string): BaseAsyncDecoder<TValue>;
40
+ /**
41
+ * @brief transform async.
42
+ */
43
+ transformAsync<TNext>(mapper: AsyncMapper<TValue, TNext>): BaseAsyncDecoder<TNext>;
44
+ /**
45
+ * @brief pipe async.
46
+ */
47
+ pipeAsync<TNext extends AsyncDecodeSource>(next: TNext): BaseAsyncDecoder<InferAsyncDecoder<TNext>>;
48
+ }
49
+ /**
50
+ * @brief base async decoder.
51
+ * @details Owns its state directly; methods expose receiver checks and explicit result flow.
52
+ * @invariant Construction leaves the instance in a fully usable state before it escapes.
53
+ */
54
+ export declare class BaseAsyncDecoder<TValue> implements AsyncDecoder<TValue> {
55
+ private readonly [AsyncDecoderRunSymbol];
56
+ /**
57
+ * @brief constructor.
58
+ * @post The receiver is initialized according to the class invariant before it can be observed.
59
+ */
60
+ constructor(run: AsyncDecodeRunner<TValue>);
61
+ /**
62
+ * @brief decode async.
63
+ */
64
+ decodeAsync(this: unknown, value: unknown): Promise<CheckResult<TValue>>;
65
+ /**
66
+ * @brief refine async.
67
+ */
68
+ refineAsync(predicate: AsyncPredicate<TValue>, name: string): BaseAsyncDecoder<TValue>;
69
+ /**
70
+ * @brief transform async.
71
+ */
72
+ transformAsync<TNext>(mapper: AsyncMapper<TValue, TNext>): BaseAsyncDecoder<TNext>;
73
+ /**
74
+ * @brief pipe async.
75
+ */
76
+ pipeAsync<TNext extends AsyncDecodeSource>(next: TNext): BaseAsyncDecoder<InferAsyncDecoder<TNext>>;
77
+ }
78
+ /**
79
+ * @brief async decoder.
80
+ */
81
+ export declare function asyncDecoder<TValue, TPresence extends Presence>(source: Guard<TValue, TPresence>): BaseAsyncDecoder<RuntimeValue<TValue, TPresence>>;
82
+ /**
83
+ * @brief async decoder.
84
+ */
85
+ export declare function asyncDecoder<TValue>(source: Decoder<TValue> | AsyncDecoder<TValue>): BaseAsyncDecoder<TValue>;
86
+ /**
87
+ * @brief async refine.
88
+ */
89
+ export declare function asyncRefine<TValue, TPresence extends Presence>(source: Guard<TValue, TPresence>, predicate: AsyncPredicate<RuntimeValue<TValue, TPresence>>, name: string): BaseAsyncDecoder<RuntimeValue<TValue, TPresence>>;
90
+ /**
91
+ * @brief async refine.
92
+ */
93
+ export declare function asyncRefine<TValue>(source: Decoder<TValue> | AsyncDecoder<TValue>, predicate: AsyncPredicate<TValue>, name: string): BaseAsyncDecoder<TValue>;
94
+ /**
95
+ * @brief async transform.
96
+ */
97
+ export declare function asyncTransform<TValue, TPresence extends Presence, TNext>(source: Guard<TValue, TPresence>, mapper: AsyncMapper<RuntimeValue<TValue, TPresence>, TNext>): BaseAsyncDecoder<TNext>;
98
+ /**
99
+ * @brief async transform.
100
+ */
101
+ export declare function asyncTransform<TValue, TNext>(source: Decoder<TValue> | AsyncDecoder<TValue>, mapper: AsyncMapper<TValue, TNext>): BaseAsyncDecoder<TNext>;
102
+ /**
103
+ * @brief async pipe.
104
+ */
105
+ export declare function asyncPipe<TNext extends AsyncDecodeSource>(source: AsyncDecodeSource, next: TNext): BaseAsyncDecoder<InferAsyncDecoder<TNext>>;
106
+ /**
107
+ * @brief is async decoder value.
108
+ */
109
+ export declare function isAsyncDecoderValue(value: unknown): value is AsyncDecoder<unknown>;
110
+ export {};
111
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,OAAO,EACZ,KAAK,YAAY,EAElB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAA+B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIlF;;GAEG;AACH,KAAK,iBAAiB,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAElF;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,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AC,EACjC,IAAI,EAAE,MAAM,GACX,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAa5B;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,SAAS,QAAQ,EAAE,KAAK,EACtE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAChC,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,GAC1D,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAE3B;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,EAC1C,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,EAC9C,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GACjC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAY3B;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,SAAS,iBAAiB,EACvD,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,KAAK,GACV,gBAAgB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAE5C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,YAAY,CAAC,OAAO,CAAC,CAEhC"}
@@ -0,0 +1,221 @@
1
+ import { isDecoderValue } from "../decoder/index.js";
2
+ import { checkSchema } from "../evaluate/index.js";
3
+ import { freezeIssueArray, makeIssue } from "../issue/index.js";
4
+ import { err, ok } from "../result/index.js";
5
+ import { freezeSchema, isSchemaValue } from "../schema/index.js";
6
+ /**
7
+ * @brief async decoder run symbol.
8
+ */
9
+ const AsyncDecoderRunSymbol = Symbol("TypeSea.asyncDecoder.run");
10
+ /**
11
+ * @brief constructed async decoders.
12
+ */
13
+ const constructedAsyncDecoders = new WeakSet();
14
+ /**
15
+ * @brief base async decoder.
16
+ * @details Owns its state directly; methods expose receiver checks and explicit result flow.
17
+ * @invariant Construction leaves the instance in a fully usable state before it escapes.
18
+ */
19
+ export class BaseAsyncDecoder {
20
+ /**
21
+ * @brief constructor.
22
+ * @post The receiver is initialized according to the class invariant before it can be observed.
23
+ */
24
+ constructor(run) {
25
+ if (typeof run !== "function") {
26
+ throw new TypeError("async decoder run must be a function");
27
+ }
28
+ defineReadonlyProperty(this, AsyncDecoderRunSymbol, run, false);
29
+ constructedAsyncDecoders.add(this);
30
+ Object.freeze(this);
31
+ }
32
+ /**
33
+ * @brief decode async.
34
+ */
35
+ decodeAsync(value) {
36
+ return readAsyncDecoderRunner(this, "async decoder receiver")(value);
37
+ }
38
+ /**
39
+ * @brief refine async.
40
+ */
41
+ refineAsync(predicate, name) {
42
+ if (typeof predicate !== "function") {
43
+ throw new TypeError("async refinement predicate must be a function");
44
+ }
45
+ if (typeof name !== "string") {
46
+ throw new TypeError("async refinement name must be a string");
47
+ }
48
+ const run = readAsyncDecoderRunner(this, "async refine receiver");
49
+ return new BaseAsyncDecoder(async (value) => {
50
+ const decoded = await run(value);
51
+ if (!decoded.ok) {
52
+ return decoded;
53
+ }
54
+ const passed = await predicate(decoded.value);
55
+ if (isStrictTrue(passed)) {
56
+ return decoded;
57
+ }
58
+ return failRefinement(name, decoded.value);
59
+ });
60
+ }
61
+ /**
62
+ * @brief transform async.
63
+ */
64
+ transformAsync(mapper) {
65
+ if (typeof mapper !== "function") {
66
+ throw new TypeError("async transform mapper must be a function");
67
+ }
68
+ const run = readAsyncDecoderRunner(this, "async transform receiver");
69
+ return new BaseAsyncDecoder(async (value) => {
70
+ const decoded = await run(value);
71
+ if (!decoded.ok) {
72
+ return decoded;
73
+ }
74
+ return ok(await mapper(decoded.value));
75
+ });
76
+ }
77
+ /**
78
+ * @brief pipe async.
79
+ */
80
+ pipeAsync(next) {
81
+ const run = readAsyncDecoderRunner(this, "async pipe receiver");
82
+ const nextRun = readAsyncDecodeSourceRunner(next, "async pipe target");
83
+ return new BaseAsyncDecoder(async (value) => {
84
+ const decoded = await run(value);
85
+ if (!decoded.ok) {
86
+ return decoded;
87
+ }
88
+ return nextRun(decoded.value);
89
+ });
90
+ }
91
+ }
92
+ /**
93
+ * @brief async decoder.
94
+ */
95
+ export function asyncDecoder(source) {
96
+ return makeAsyncDecoder(source);
97
+ }
98
+ /**
99
+ * @brief async refine.
100
+ */
101
+ export function asyncRefine(source, predicate, name) {
102
+ return makeAsyncDecoder(source).refineAsync(predicate, name);
103
+ }
104
+ /**
105
+ * @brief async transform.
106
+ */
107
+ export function asyncTransform(source, mapper) {
108
+ return makeAsyncDecoder(source).transformAsync(mapper);
109
+ }
110
+ /**
111
+ * @brief async pipe.
112
+ */
113
+ export function asyncPipe(source, next) {
114
+ return makeAsyncDecoder(source).pipeAsync(next);
115
+ }
116
+ /**
117
+ * @brief is async decoder value.
118
+ */
119
+ export function isAsyncDecoderValue(value) {
120
+ return isConstructedAsyncDecoder(value);
121
+ }
122
+ /**
123
+ * @brief make async decoder.
124
+ */
125
+ function makeAsyncDecoder(source) {
126
+ const run = readAsyncDecodeSourceRunner(source, "async decoder source");
127
+ return new BaseAsyncDecoder(run);
128
+ }
129
+ /**
130
+ * @brief read async decode source runner.
131
+ */
132
+ function readAsyncDecodeSourceRunner(source, label) {
133
+ if (isConstructedAsyncDecoder(source)) {
134
+ return readAsyncDecoderRunner(source, label);
135
+ }
136
+ if (isDecoderValue(source)) {
137
+ return (value) => Promise.resolve(source.decode(value));
138
+ }
139
+ const schema = readGuardSchema(source, label);
140
+ return (value) => Promise.resolve(checkSchema(schema, value));
141
+ }
142
+ /**
143
+ * @brief read async decoder runner.
144
+ */
145
+ function readAsyncDecoderRunner(value, label) {
146
+ if (!isConstructedAsyncDecoder(value)) {
147
+ throw new TypeError(`${label} must be a TypeSea async decoder`);
148
+ }
149
+ return value[AsyncDecoderRunSymbol];
150
+ }
151
+ /**
152
+ * @brief is constructed async decoder.
153
+ */
154
+ function isConstructedAsyncDecoder(value) {
155
+ return isRecord(value) && constructedAsyncDecoders.has(value);
156
+ }
157
+ /**
158
+ * @brief read guard schema.
159
+ */
160
+ function readGuardSchema(value, label) {
161
+ if (!isRecord(value)) {
162
+ throw new TypeError(`${label} must be a TypeSea guard or decoder`);
163
+ }
164
+ const schema = value["schema"];
165
+ if (!isSchemaValue(schema)) {
166
+ throw new TypeError(`${label} must contain a valid TypeSea schema`);
167
+ }
168
+ return freezeSchema(schema);
169
+ }
170
+ /**
171
+ * @brief fail refinement.
172
+ */
173
+ function failRefinement(name, value) {
174
+ return err(freezeIssueArray([
175
+ makeIssue([], "expected_refinement", name, actualType(value), undefined)
176
+ ]));
177
+ }
178
+ /**
179
+ * @brief actual type.
180
+ */
181
+ function actualType(value) {
182
+ if (value === null) {
183
+ return "null";
184
+ }
185
+ if (Array.isArray(value)) {
186
+ return "array";
187
+ }
188
+ if (typeof value === "bigint") {
189
+ return "bigint";
190
+ }
191
+ if (typeof value === "symbol") {
192
+ return "symbol";
193
+ }
194
+ if (typeof value === "number" && Number.isNaN(value)) {
195
+ return "nan";
196
+ }
197
+ return typeof value;
198
+ }
199
+ /**
200
+ * @brief is strict true.
201
+ */
202
+ function isStrictTrue(value) {
203
+ return value === true;
204
+ }
205
+ /**
206
+ * @brief define readonly property.
207
+ */
208
+ function defineReadonlyProperty(target, key, value, enumerable) {
209
+ Object.defineProperty(target, key, {
210
+ configurable: false,
211
+ enumerable,
212
+ value,
213
+ writable: false
214
+ });
215
+ }
216
+ /**
217
+ * @brief is record.
218
+ */
219
+ function isRecord(value) {
220
+ return typeof value === "object" && value !== null && !Array.isArray(value);
221
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @file composite.ts
3
+ * @brief Composite guard builders.
4
+ */
5
+ import { BaseGuard, type Guard, type Infer, type Presence } from "../guard/index.js";
6
+ import type { DiscriminatedUnionCases, InferTuple, TupleShape, UnionInput } from "./types.js";
7
+ /**
8
+ * @brief array.
9
+ */
10
+ export declare function array<TGuard extends Guard<unknown, Presence>>(item: TGuard): BaseGuard<Infer<TGuard>[]>;
11
+ /**
12
+ * @brief tuple.
13
+ */
14
+ export declare function tuple<const TShape extends TupleShape>(shape: TShape): BaseGuard<InferTuple<TShape>>;
15
+ /**
16
+ * @brief record.
17
+ */
18
+ export declare function record<TGuard extends Guard<unknown, Presence>>(value: TGuard): BaseGuard<Readonly<Record<string, Infer<TGuard>>>>;
19
+ /**
20
+ * @brief union.
21
+ */
22
+ export declare function union<const TGuards extends UnionInput>(...guards: TGuards): BaseGuard<Infer<TGuards[number]>>;
23
+ /**
24
+ * @brief intersect.
25
+ */
26
+ export declare function intersect<TLeft extends Guard<unknown, Presence>, TRight extends Guard<unknown, Presence>>(left: TLeft, right: TRight): BaseGuard<Infer<TLeft> & Infer<TRight>>;
27
+ /**
28
+ * @brief discriminated union.
29
+ */
30
+ export declare function discriminatedUnion<const TKey extends string, const TCases extends Readonly<Record<string, Guard<unknown, Presence>>>>(key: TKey, cases: TCases & DiscriminatedUnionCases<TKey, TCases>): BaseGuard<Infer<TCases[keyof TCases]>>;
31
+ //# sourceMappingURL=composite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../src/builders/composite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EACL,SAAS,EACT,KAAK,KAAK,EACV,KAAK,KAAK,EACV,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAM3B,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,KAAK,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC3D,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAK5B;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,CAAC,MAAM,SAAS,UAAU,EACnD,KAAK,EAAE,MAAM,GACZ,SAAS,C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