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,35 @@
1
+ /**
2
+ * @file props.ts
3
+ * @brief Guard object shape helpers.
4
+ */
5
+ export function defineReadonlyProperty(target, key, value, enumerable) {
6
+ Object.defineProperty(target, key, {
7
+ configurable: false,
8
+ enumerable,
9
+ value,
10
+ writable: false
11
+ });
12
+ }
13
+ /**
14
+ * @brief is strict true.
15
+ */
16
+ export function isStrictTrue(value) {
17
+ return value === true;
18
+ }
19
+ /**
20
+ * @brief is record.
21
+ */
22
+ export function isRecord(value) {
23
+ return typeof value === "object" && value !== null && !Array.isArray(value);
24
+ }
25
+ /**
26
+ * @brief is plain reg exp.
27
+ */
28
+ export function isPlainRegExp(value) {
29
+ return value instanceof RegExp &&
30
+ Object.getPrototypeOf(value) === RegExp.prototype &&
31
+ !Object.prototype.hasOwnProperty.call(value, "exec") &&
32
+ !Object.prototype.hasOwnProperty.call(value, "test") &&
33
+ !Object.prototype.hasOwnProperty.call(value, "source") &&
34
+ !Object.prototype.hasOwnProperty.call(value, "flags");
35
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @file read.ts
3
+ * @brief Guard receiver and constructor validation.
4
+ */
5
+ import type { NumberSchema, Schema, StringSchema } from "../schema/index.js";
6
+ /**
7
+ * @brief read guard schema.
8
+ */
9
+ export declare function readGuardSchema(guard: unknown, label: string): Schema;
10
+ /**
11
+ * @brief read string method schema.
12
+ */
13
+ export declare function readStringMethodSchema(guard: unknown, label: string): StringSchema;
14
+ /**
15
+ * @brief read number method schema.
16
+ */
17
+ export declare function readNumberMethodSchema(guard: unknown, label: string): NumberSchema;
18
+ /**
19
+ * @brief read constructor schema.
20
+ */
21
+ export declare function readConstructorSchema(schema: unknown): Schema;
22
+ /**
23
+ * @brief read string constructor schema.
24
+ */
25
+ export declare function readStringConstructorSchema(schema: unknown): StringSchema;
26
+ /**
27
+ * @brief read number constructor schema.
28
+ */
29
+ export declare function readNumberConstructorSchema(schema: unknown): NumberSchema;
30
+ /**
31
+ * @brief check refinement input.
32
+ */
33
+ export declare function checkRefinementInput(predicate: unknown, name: unknown): asserts predicate is (value: unknown) => boolean;
34
+ /**
35
+ * @brief check string length bound.
36
+ */
37
+ export declare function checkStringLengthBound(value: number, label: string): number;
38
+ /**
39
+ * @brief check finite number bound.
40
+ */
41
+ export declare function checkFiniteNumberBound(value: number, label: string): number;
42
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/guard/read.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAK7E;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CAYR;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAalF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAalF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAK7D;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAKzE;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAKzE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAOlD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3E"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @file read.ts
3
+ * @brief Guard receiver and constructor validation.
4
+ */
5
+ import { SchemaTag } from "../kind/index.js";
6
+ import { freezeSchema, isSchemaValue } from "../schema/index.js";
7
+ import { isRecord } from "./props.js";
8
+ import { isConstructedGuard } from "./registry.js";
9
+ /**
10
+ * @brief read guard schema.
11
+ */
12
+ export function readGuardSchema(guard, label) {
13
+ if (isConstructedGuard(guard)) {
14
+ return guard.schema;
15
+ }
16
+ if (!isRecord(guard)) {
17
+ throw new TypeError(`${label} must be a TypeSea guard`);
18
+ }
19
+ const schema = guard["schema"];
20
+ if (!isSchemaValue(schema)) {
21
+ throw new TypeError(`${label} must contain a valid TypeSea schema`);
22
+ }
23
+ return schema;
24
+ }
25
+ /**
26
+ * @brief read string method schema.
27
+ */
28
+ export function readStringMethodSchema(guard, label) {
29
+ if (isConstructedGuard(guard)) {
30
+ const schema = guard.schema;
31
+ if (schema.tag !== SchemaTag.String) {
32
+ throw new TypeError(`${label} must be a string TypeSea guard`);
33
+ }
34
+ return schema;
35
+ }
36
+ const schema = readGuardSchema(guard, label);
37
+ if (schema.tag !== SchemaTag.String) {
38
+ throw new TypeError(`${label} must be a string TypeSea guard`);
39
+ }
40
+ return schema;
41
+ }
42
+ /**
43
+ * @brief read number method schema.
44
+ */
45
+ export function readNumberMethodSchema(guard, label) {
46
+ if (isConstructedGuard(guard)) {
47
+ const schema = guard.schema;
48
+ if (schema.tag !== SchemaTag.Number) {
49
+ throw new TypeError(`${label} must be a number TypeSea guard`);
50
+ }
51
+ return schema;
52
+ }
53
+ const schema = readGuardSchema(guard, label);
54
+ if (schema.tag !== SchemaTag.Number) {
55
+ throw new TypeError(`${label} must be a number TypeSea guard`);
56
+ }
57
+ return schema;
58
+ }
59
+ /**
60
+ * @brief read constructor schema.
61
+ */
62
+ export function readConstructorSchema(schema) {
63
+ if (!isSchemaValue(schema)) {
64
+ throw new TypeError("guard constructor requires a valid TypeSea schema");
65
+ }
66
+ return freezeSchema(schema);
67
+ }
68
+ /**
69
+ * @brief read string constructor schema.
70
+ */
71
+ export function readStringConstructorSchema(schema) {
72
+ if (!isSchemaValue(schema) || schema.tag !== SchemaTag.String) {
73
+ throw new TypeError("StringGuard constructor requires a string schema");
74
+ }
75
+ return schema;
76
+ }
77
+ /**
78
+ * @brief read number constructor schema.
79
+ */
80
+ export function readNumberConstructorSchema(schema) {
81
+ if (!isSchemaValue(schema) || schema.tag !== SchemaTag.Number) {
82
+ throw new TypeError("NumberGuard constructor requires a number schema");
83
+ }
84
+ return schema;
85
+ }
86
+ /**
87
+ * @brief check refinement input.
88
+ */
89
+ export function checkRefinementInput(predicate, name) {
90
+ if (typeof predicate !== "function") {
91
+ throw new TypeError("refinement predicate must be a function");
92
+ }
93
+ if (typeof name !== "string") {
94
+ throw new TypeError("refinement name must be a string");
95
+ }
96
+ }
97
+ /**
98
+ * @brief check string length bound.
99
+ */
100
+ export function checkStringLengthBound(value, label) {
101
+ if (!Number.isInteger(value) || value < 0) {
102
+ throw new RangeError(`${label} length bound must be a non-negative integer`);
103
+ }
104
+ return value;
105
+ }
106
+ /**
107
+ * @brief check finite number bound.
108
+ */
109
+ export function checkFiniteNumberBound(value, label) {
110
+ if (typeof value !== "number" || !Number.isFinite(value)) {
111
+ throw new RangeError(`${label} numeric bound must be finite`);
112
+ }
113
+ return value;
114
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file registry.ts
3
+ * @brief Constructed guard receiver registry.
4
+ */
5
+ import type { BaseGuard } from "./base.js";
6
+ import type { Presence } from "./types.js";
7
+ /**
8
+ * @brief register constructed guard.
9
+ */
10
+ export declare function registerConstructedGuard(value: object): void;
11
+ /**
12
+ * @brief is constructed guard.
13
+ */
14
+ export declare function isConstructedGuard(value: unknown): value is BaseGuard<unknown, Presence>;
15
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/guard/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQ3C;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,CAEvC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file registry.ts
3
+ * @brief Constructed guard receiver registry.
4
+ */
5
+ import { isRecord } from "./props.js";
6
+ /**
7
+ * @brief constructed guards.
8
+ */
9
+ const constructedGuards = new WeakSet();
10
+ /**
11
+ * @brief register constructed guard.
12
+ */
13
+ export function registerConstructedGuard(value) {
14
+ constructedGuards.add(value);
15
+ }
16
+ /**
17
+ * @brief is constructed guard.
18
+ */
19
+ export function isConstructedGuard(value) {
20
+ return isRecord(value) && constructedGuards.has(value);
21
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file string.ts
3
+ * @brief String guard implementation.
4
+ */
5
+ import type { StringSchema } from "../schema/index.js";
6
+ import { BaseGuard } from "./base.js";
7
+ import type { Presence } from "./types.js";
8
+ /**
9
+ * @brief string guard.
10
+ * @details Owns its state directly; methods expose receiver checks and explicit result flow.
11
+ * @invariant Construction leaves the instance in a fully usable state before it escapes.
12
+ */
13
+ export declare class StringGuard<TPresence extends Presence = "required"> extends BaseGuard<string, TPresence> {
14
+ /**
15
+ * @brief constructor.
16
+ * @post The receiver is initialized according to the class invariant before it can be observed.
17
+ */
18
+ constructor(schema: StringSchema);
19
+ /**
20
+ * @brief min.
21
+ */
22
+ min(value: number): StringGuard<TPresence>;
23
+ /**
24
+ * @brief max.
25
+ */
26
+ max(value: number): StringGuard<TPresence>;
27
+ /**
28
+ * @brief regex.
29
+ */
30
+ regex(pattern: RegExp, name: string): StringGuard<TPresence>;
31
+ /**
32
+ * @brief uuid.
33
+ */
34
+ uuid(): StringGuard<TPresence>;
35
+ }
36
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/guard/string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,WAAW,CACtB,SAAS,SAAS,QAAQ,GAAG,UAAU,CACvC,SAAQ,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC;IAEpC;;;OAGG;gBACgB,MAAM,EAAE,YAAY;IAKvC;;aAES;IACF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAejD;;aAES;IACF,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAejD;;eAEW;IACJ,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC;IAqBnE;;WAEO;IACA,IAAI,IAAI,WAAW,CAAC,SAAS,CAAC;CAYtC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @file string.ts
3
+ * @brief String guard implementation.
4
+ */
5
+ import { SchemaTag, StringCheckTag } from "../kind/index.js";
6
+ import { BaseGuard } from "./base.js";
7
+ import { isPlainRegExp } from "./props.js";
8
+ import { checkStringLengthBound, readStringConstructorSchema, readStringMethodSchema } from "./read.js";
9
+ /**
10
+ * @brief string guard.
11
+ * @details Owns its state directly; methods expose receiver checks and explicit result flow.
12
+ * @invariant Construction leaves the instance in a fully usable state before it escapes.
13
+ */
14
+ export class StringGuard extends BaseGuard {
15
+ /**
16
+ * @brief constructor.
17
+ * @post The receiver is initialized according to the class invariant before it can be observed.
18
+ */
19
+ constructor(schema) {
20
+ super(readStringConstructorSchema(schema));
21
+ Object.freeze(this);
22
+ }
23
+ /**
24
+ * @brief min.
25
+ */
26
+ min(value) {
27
+ const schema = readStringMethodSchema(this, "string min receiver");
28
+ const bound = checkStringLengthBound(value, "min");
29
+ return new StringGuard({
30
+ tag: SchemaTag.String,
31
+ checks: [
32
+ ...schema.checks,
33
+ {
34
+ tag: StringCheckTag.Min,
35
+ value: bound
36
+ }
37
+ ]
38
+ });
39
+ }
40
+ /**
41
+ * @brief max.
42
+ */
43
+ max(value) {
44
+ const schema = readStringMethodSchema(this, "string max receiver");
45
+ const bound = checkStringLengthBound(value, "max");
46
+ return new StringGuard({
47
+ tag: SchemaTag.String,
48
+ checks: [
49
+ ...schema.checks,
50
+ {
51
+ tag: StringCheckTag.Max,
52
+ value: bound
53
+ }
54
+ ]
55
+ });
56
+ }
57
+ /**
58
+ * @brief regex.
59
+ */
60
+ regex(pattern, name) {
61
+ if (!isPlainRegExp(pattern)) {
62
+ throw new TypeError("regex pattern must be a plain RegExp");
63
+ }
64
+ if (typeof name !== "string") {
65
+ throw new TypeError("regex name must be a string");
66
+ }
67
+ const schema = readStringMethodSchema(this, "string regex receiver");
68
+ return new StringGuard({
69
+ tag: SchemaTag.String,
70
+ checks: [
71
+ ...schema.checks,
72
+ {
73
+ tag: StringCheckTag.Regex,
74
+ regex: new RegExp(pattern.source, pattern.flags),
75
+ name
76
+ }
77
+ ]
78
+ });
79
+ }
80
+ /**
81
+ * @brief uuid.
82
+ */
83
+ uuid() {
84
+ const schema = readStringMethodSchema(this, "string uuid receiver");
85
+ return new StringGuard({
86
+ tag: SchemaTag.String,
87
+ checks: [
88
+ ...schema.checks,
89
+ {
90
+ tag: StringCheckTag.Uuid
91
+ }
92
+ ]
93
+ });
94
+ }
95
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @file types.ts
3
+ * @brief Public guard type contracts.
4
+ */
5
+ import type { CheckResult } from "../issue/index.js";
6
+ import type { Graph } from "../ir/index.js";
7
+ import type { Schema } from "../schema/index.js";
8
+ import type { BaseGuard } from "./base.js";
9
+ /**
10
+ * @brief type symbol.
11
+ */
12
+ export declare const TypeSymbol: unique symbol;
13
+ /**
14
+ * @brief presence symbol.
15
+ */
16
+ export declare const PresenceSymbol: unique symbol;
17
+ /**
18
+ * @brief brand symbol.
19
+ */
20
+ export declare const BrandSymbol: unique symbol;
21
+ /**
22
+ * @brief presence.
23
+ */
24
+ export type Presence = "required" | "optional";
25
+ /**
26
+ * @brief runtime value.
27
+ */
28
+ export type RuntimeValue<TValue, TPresence extends Presence> = TPresence extends "optional" ? TValue | undefined : TValue;
29
+ /**
30
+ * @brief infer.
31
+ */
32
+ export type Infer<TGuard> = TGuard extends Guard<infer TValue, infer TPresence> ? RuntimeValue<TValue, TPresence> : never;
33
+ /**
34
+ * @brief guard value.
35
+ */
36
+ export type GuardValue<TGuard> = TGuard extends Guard<infer TValue, Presence> ? TValue : never;
37
+ /**
38
+ * @brief guard presence.
39
+ */
40
+ export type GuardPresence<TGuard> = TGuard extends Guard<unknown, infer TPresence> ? TPresence : never;
41
+ /**
42
+ * @brief brand.
43
+ */
44
+ export type Brand<TValue, TBrand extends string> = TValue & {
45
+ readonly [BrandSymbol]: TBrand;
46
+ };
47
+ /**
48
+ * @brief guard.
49
+ */
50
+ export interface Guard<TValue, TPresence extends Presence = "required"> {
51
+ readonly [TypeSymbol]: TValue;
52
+ readonly [PresenceSymbol]: TPresence;
53
+ readonly schema: Schema;
54
+ /**
55
+ * @brief is.
56
+ */
57
+ is(value: unknown): value is RuntimeValue<TValue, TPresence>;
58
+ /**
59
+ * @brief check.
60
+ */
61
+ check(value: unknown): CheckResult<RuntimeValue<TValue, TPresence>>;
62
+ /**
63
+ * @brief assert.
64
+ */
65
+ assert(value: unknown): asserts value is RuntimeValue<TValue, TPresence>;
66
+ /**
67
+ * @brief graph.
68
+ */
69
+ graph(): Graph;
70
+ /**
71
+ * @brief optional.
72
+ */
73
+ optional(): BaseGuard<TValue, "optional">;
74
+ /**
75
+ * @brief undefinedable.
76
+ */
77
+ undefinedable(): BaseGuard<TValue | undefined, TPresence>;
78
+ /**
79
+ * @brief nullable.
80
+ */
81
+ nullable(): BaseGuard<TValue | null, TPresence>;
82
+ /**
83
+ * @brief array.
84
+ */
85
+ array(): BaseGuard<RuntimeValue<TValue, TPresence>[]>;
86
+ /**
87
+ * @brief brand.
88
+ */
89
+ brand<TBrand extends string>(): BaseGuard<Brand<TValue, TBrand>, TPresence>;
90
+ /**
91
+ * @brief refine.
92
+ */
93
+ refine(predicate: (value: RuntimeValue<TValue, TPresence>) => boolean, name: string): BaseGuard<TValue, TPresence>;
94
+ /**
95
+ * @brief or.
96
+ */
97
+ or<TOther extends Guard<unknown, Presence>>(other: TOther): BaseGuard<RuntimeValue<TValue, TPresence> | Infer<TOther>>;
98
+ /**
99
+ * @brief intersect.
100
+ */
101
+ intersect<TOther extends Guard<unknown, Presence>>(other: TOther): BaseGuard<RuntimeValue<TValue, TPresence> & Infer<TOther>>;
102
+ }
103
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/guard/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,OAAO,CAAC,MAAM,UAAU,EAAE,OAAO,MAAM,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,OAAO,CAAC,MAAM,WAAW,EAAE,OAAO,MAAM,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,MAAM,EAAE,SAAS,SAAS,QAAQ,IACzD,SAAS,SAAS,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,MAAM,IACtB,MAAM,SAAS,KAAK,CAAC,MAAM,MAAM,EAAE,MAAM,SAAS,CAAC,GAC/C,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAC/B,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,IAC3B,MAAM,SAAS,KAAK,CAAC,MAAM,MAAM,EAAE,QAAQ,CAAC,GAAG,MA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AC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAEtD;;WAEO;IACP,KAAK,CAAC,MAAM,SAAS,MAAM,KAAK,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC;IAE5E;;eAEW;IACX,MAAM,CACJ,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,OAAO,EAC9D,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEhC;;aAES;IACT,EAAE,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EACxC,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9D;;aAES;IACT,SAAS,CAAC,MAAM,SAAS,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC/C,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;CAC/D"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file types.ts
3
+ * @brief Public guard type contracts.
4
+ */
5
+ export {};
@@ -0,0 +1,14 @@
1
+ export { t, array, bigintGuard, discriminatedUnion, extend, intersect, lazy, literal, nullable, neverGuard, object, omit, optional, partial, pick, record, refine, strictObject, symbolGuard, tuple, union, unknownGuard, undefinedable, type InferObject, type InferTuple, type MergeObjectShapes, type ObjectGuardMode, type ObjectShape, type OmitObjectShape, ObjectGuard, type PartialObjectShape, type PickObjectShape, type TupleShape } from "./builders/index.js";
2
+ export { BaseGuard, NumberGuard, StringGuard, TypeSeaAssertionError, type Brand, type Guard, type GuardPresence, type GuardValue, type Infer, type Presence, type RuntimeValue } from "./guard/index.js";
3
+ export { CompiledBaseGuard, compile, type CompileOptions, type CompiledGuard } from "./compile/index.js";
4
+ export { emitAotModule, type AotCompileOptions, type AotIssue, type AotIssueCode, type AotModule } from "./aot/index.js";
5
+ export { toAsyncTrpcParser, toFastifyRouteSchema, toFastifyValidatorCompiler, toReactHookFormResolver, toTrpcParser, type AsyncTrpcParser, type FastifyHttpPart, type FastifyRouteSchema, type FastifyRouteSchemaOptions, type FastifyValidationResult, type FastifyValidator, type FastifyValidatorCompiler, type FastifyValidatorCompilerSource, type FastifyValidatorCompilerSourceMap, type FastifyValidatorRoute, type InferAdapter, type InferSyncAdapter, type ReactHookFormErrors, type ReactHookFormFieldError, type ReactHookFormResolver, type ReactHookFormResolverOptions, type ReactHookFormResolverResult, type SyncAdapterSource, type TrpcParser } from "./adapters/index.js";
6
+ export { BaseAsyncDecoder, asyncDecoder, asyncPipe, asyncRefine, asyncTransform, isAsyncDecoderValue, type AsyncDecodeSource, type AsyncDecoder, type InferAsyncDecoder } from "./async/index.js";
7
+ export { BaseDecoder, coerce, coerceBoolean, coerceNumber, coerceString, decoder, isDecoderValue, pipe, transform, type DecodeSource, type Decoder, type InferDecoder } from "./decoder/index.js";
8
+ export { schemaToJsonSchema, toJsonSchema, type JsonSchema, type JsonSchemaExportCode, type JsonSchemaExportIssue, type JsonSchemaObject, type JsonSchemaOptions, type JsonSchemaPrimitive, type JsonSchemaTypeName } from "./json-schema/index.js";
9
+ export { defineMessages, formatIssue, formatIssues, withMessages, type IssueMessageCatalog, type IssueMessageContext, type IssueMessageFormatter, type IssueMessageOptions, type IssueMessageTemplate, type MessageLocale } from "./message/index.js";
10
+ export type { CheckResult, Issue, IssueCode, PathSegment } from "./issue/index.js";
11
+ export type { Graph, GraphNode, NodeId } from "./ir/index.js";
12
+ export { optimizeGraph } from "./optimize/index.js";
13
+ export type { LiteralValue, Schema } from "./schema/index.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceR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MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { t, array, bigintGuard, discriminatedUnion, extend, intersect, lazy, literal, nullable, neverGuard, object, omit, optional, partial, pick, record, refine, strictObject, symbolGuard, tuple, union, unknownGuard, undefinedable, ObjectGuard } from "./builders/index.js";
2
+ export { BaseGuard, NumberGuard, StringGuard, TypeSeaAssertionError } from "./guard/index.js";
3
+ export { CompiledBaseGuard, compile } from "./compile/index.js";
4
+ export { emitAotModule } from "./aot/index.js";
5
+ export { toAsyncTrpcParser, toFastifyRouteSchema, toFastifyValidatorCompiler, toReactHookFormResolver, toTrpcParser } from "./adapters/index.js";
6
+ export { BaseAsyncDecoder, asyncDecoder, asyncPipe, asyncRefine, asyncTransform, isAsyncDecoderValue } from "./async/index.js";
7
+ export { BaseDecoder, coerce, coerceBoolean, coerceNumber, coerceString, decoder, isDecoderValue, pipe, transform } from "./decoder/index.js";
8
+ export { schemaToJsonSchema, toJsonSchema } from "./json-schema/index.js";
9
+ export { defineMessages, formatIssue, formatIssues, withMessages } from "./message/index.js";
10
+ export { optimizeGraph } from "./optimize/index.js";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @file internal.ts
3
+ * @brief Private helpers shared across TypeSea translation units.
4
+ *
5
+ * @invariant Values crossing a module boundary stay `unknown` until a local
6
+ * guard proves the shape needed by that module.
7
+ */
8
+ import type { Guard, Presence } from "../guard/index.js";
9
+ import { type Schema } from "../schema/index.js";
10
+ /**
11
+ * @brief read guard schema.
12
+ */
13
+ export declare function readGuardSchema(guard: unknown, label: string): Schema;
14
+ /**
15
+ * @brief is record.
16
+ */
17
+ export declare function isRecord(value: unknown): value is Readonly<Record<string, unknown>>;
18
+ /**
19
+ * @brief is unknown array.
20
+ */
21
+ export declare function isUnknownArray(value: unknown): value is readonly unknown[];
22
+ /**
23
+ * @brief includes string.
24
+ */
25
+ export declare function includesString(values: readonly string[], value: string): boolean;
26
+ /**
27
+ * @brief is strict true.
28
+ */
29
+ export declare function isStrictTrue(value: unknown): boolean;
30
+ /**
31
+ * @brief is guard value.
32
+ */
33
+ export declare function isGuardValue(value: unknown): value is Guard<unknown, Presence>;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAE5C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,OAAO,EAAE,CAE1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,KAAK,EAAE,MAAM,GACZ,OAAO,CAOT;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAEnC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @file internal.ts
3
+ * @brief Private helpers shared across TypeSea translation units.
4
+ *
5
+ * @invariant Values crossing a module boundary stay `unknown` until a local
6
+ * guard proves the shape needed by that module.
7
+ */
8
+ import { isSchemaValue } from "../schema/index.js";
9
+ /**
10
+ * @brief read guard schema.
11
+ */
12
+ export function readGuardSchema(guard, label) {
13
+ if (!isRecord(guard)) {
14
+ throw new TypeError(`${label} must be a TypeSea guard`);
15
+ }
16
+ const schema = guard["schema"];
17
+ if (!isSchemaValue(schema)) {
18
+ throw new TypeError(`${label} must contain a valid TypeSea schema`);
19
+ }
20
+ return schema;
21
+ }
22
+ /**
23
+ * @brief is record.
24
+ */
25
+ export function isRecord(value) {
26
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27
+ }
28
+ /**
29
+ * @brief is unknown array.
30
+ */
31
+ export function isUnknownArray(value) {
32
+ return Array.isArray(value);
33
+ }
34
+ /**
35
+ * @brief includes string.
36
+ */
37
+ export function includesString(values, value) {
38
+ for (let index = 0; index < values.length; index += 1) {
39
+ if (values[index] === value) {
40
+ return true;
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ /**
46
+ * @brief is strict true.
47
+ */
48
+ export function isStrictTrue(value) {
49
+ return value === true;
50
+ }
51
+ /**
52
+ * @brief is guard value.
53
+ */
54
+ export function isGuardValue(value) {
55
+ return isRecord(value) && isSchemaValue(value["schema"]);
56
+ }