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,269 @@
1
+ import { copyIssueArray, freezeIssueArray, isIssueCodeValue, makeIssue } from "../issue/index.js";
2
+ import { err } from "../result/index.js";
3
+ /**
4
+ * @brief define messages.
5
+ */
6
+ export function defineMessages(catalog) {
7
+ return Object.freeze(copyCatalog(catalog));
8
+ }
9
+ /**
10
+ * @brief format issue.
11
+ */
12
+ export function formatIssue(issue, options) {
13
+ const copied = copyIssueArray([issue]);
14
+ const first = copied[0];
15
+ if (first === undefined) {
16
+ throw new TypeError("issue must be present");
17
+ }
18
+ return renderIssue(first, readOptions(options));
19
+ }
20
+ /**
21
+ * @brief format issues.
22
+ */
23
+ export function formatIssues(issues, options) {
24
+ const copied = copyIssueArray(issues);
25
+ const config = readOptions(options);
26
+ const messages = new Array(copied.length);
27
+ for (let index = 0; index < copied.length; index += 1) {
28
+ const issue = copied[index];
29
+ if (issue !== undefined) {
30
+ messages[index] = renderIssue(issue, config);
31
+ }
32
+ }
33
+ return Object.freeze(messages);
34
+ }
35
+ /**
36
+ * @brief with messages.
37
+ */
38
+ export function withMessages(result, options) {
39
+ if (result.ok) {
40
+ return result;
41
+ }
42
+ const copied = copyIssueArray(result.error);
43
+ const config = readOptions(options);
44
+ const issues = new Array(copied.length);
45
+ for (let index = 0; index < copied.length; index += 1) {
46
+ const issue = copied[index];
47
+ if (issue !== undefined) {
48
+ issues[index] = makeIssue(issue.path, issue.code, issue.expected, issue.actual, renderIssue(issue, config));
49
+ }
50
+ }
51
+ return err(freezeIssueArray(issues));
52
+ }
53
+ /**
54
+ * @brief render issue.
55
+ */
56
+ function renderIssue(issue, options) {
57
+ const context = makeContext(issue, options.pathFormatter);
58
+ const customTemplate = options.catalog?.[issue.code];
59
+ if (customTemplate !== undefined) {
60
+ return renderTemplate(customTemplate, issue, context);
61
+ }
62
+ if (issue.message !== undefined) {
63
+ return issue.message;
64
+ }
65
+ return renderTemplate(defaultCatalogs[options.locale][issue.code], issue, context);
66
+ }
67
+ /**
68
+ * @brief make context.
69
+ */
70
+ function makeContext(issue, pathFormatter) {
71
+ return {
72
+ path: pathFormatter(issue.path),
73
+ code: issue.code,
74
+ expected: issue.expected ?? "unknown",
75
+ actual: issue.actual ?? "unknown"
76
+ };
77
+ }
78
+ /**
79
+ * @brief render template.
80
+ */
81
+ function renderTemplate(template, issue, context) {
82
+ if (typeof template === "function") {
83
+ const rendered = template(issue, context);
84
+ if (typeof rendered !== "string") {
85
+ throw new TypeError("issue message formatter must return a string");
86
+ }
87
+ return rendered;
88
+ }
89
+ return template
90
+ .split("{path}").join(context.path)
91
+ .split("{code}").join(context.code)
92
+ .split("{expected}").join(context.expected)
93
+ .split("{actual}").join(context.actual);
94
+ }
95
+ /**
96
+ * @brief read options.
97
+ */
98
+ function readOptions(options) {
99
+ if (options === undefined) {
100
+ return {
101
+ locale: "en",
102
+ catalog: undefined,
103
+ pathFormatter: defaultPathFormatter
104
+ };
105
+ }
106
+ if (!isRecord(options)) {
107
+ throw new TypeError("message options must be an object");
108
+ }
109
+ const locale = readLocale(options.locale);
110
+ const pathFormatter = readPathFormatter(options.pathFormatter);
111
+ const catalog = options.catalog;
112
+ return {
113
+ locale,
114
+ catalog: catalog === undefined ? undefined : copyCatalog(catalog),
115
+ pathFormatter
116
+ };
117
+ }
118
+ /**
119
+ * @brief read locale.
120
+ */
121
+ function readLocale(value) {
122
+ if (value === undefined || value === "en") {
123
+ return "en";
124
+ }
125
+ if (value === "ko") {
126
+ return "ko";
127
+ }
128
+ throw new TypeError("message locale must be en or ko");
129
+ }
130
+ /**
131
+ * @brief read path formatter.
132
+ */
133
+ function readPathFormatter(value) {
134
+ if (value === undefined) {
135
+ return defaultPathFormatter;
136
+ }
137
+ if (typeof value !== "function") {
138
+ throw new TypeError("message path formatter must be a function");
139
+ }
140
+ const formatter = value;
141
+ return (path) => {
142
+ const formatted = formatter(path);
143
+ if (typeof formatted !== "string") {
144
+ throw new TypeError("message path formatter must return a string");
145
+ }
146
+ return formatted;
147
+ };
148
+ }
149
+ /**
150
+ * @brief copy catalog.
151
+ */
152
+ function copyCatalog(value) {
153
+ if (!isRecord(value)) {
154
+ throw new TypeError("message catalog must be an object");
155
+ }
156
+ const copied = {};
157
+ const keys = Object.keys(value);
158
+ for (let index = 0; index < keys.length; index += 1) {
159
+ const key = keys[index];
160
+ if (key === undefined) {
161
+ continue;
162
+ }
163
+ if (!isIssueCodeValue(key)) {
164
+ throw new TypeError("message catalog key must be an issue code");
165
+ }
166
+ const template = value[key];
167
+ if (!isIssueMessageTemplate(template)) {
168
+ throw new TypeError("message template must be a string or function");
169
+ }
170
+ copied[key] = template;
171
+ }
172
+ return copied;
173
+ }
174
+ /**
175
+ * @brief is issue message template.
176
+ */
177
+ function isIssueMessageTemplate(value) {
178
+ return typeof value === "string" || typeof value === "function";
179
+ }
180
+ /**
181
+ * @brief default path formatter.
182
+ */
183
+ function defaultPathFormatter(path) {
184
+ if (path.length === 0) {
185
+ return "$";
186
+ }
187
+ let result = "$";
188
+ for (let index = 0; index < path.length; index += 1) {
189
+ const segment = path[index];
190
+ if (typeof segment === "number") {
191
+ result += `[${String(segment)}]`;
192
+ }
193
+ else if (typeof segment === "string") {
194
+ result += `[${JSON.stringify(segment)}]`;
195
+ }
196
+ }
197
+ return result;
198
+ }
199
+ /**
200
+ * @brief is record.
201
+ */
202
+ function isRecord(value) {
203
+ return typeof value === "object" && value !== null && !Array.isArray(value);
204
+ }
205
+ /**
206
+ * @brief en catalog.
207
+ */
208
+ const enCatalog = Object.freeze({
209
+ expected_string: "Expected string at {path}; received {actual}.",
210
+ expected_number: "Expected number at {path}; received {actual}.",
211
+ expected_bigint: "Expected bigint at {path}; received {actual}.",
212
+ expected_symbol: "Expected symbol at {path}; received {actual}.",
213
+ expected_boolean: "Expected boolean at {path}; received {actual}.",
214
+ expected_never: "Expected never at {path}; received {actual}.",
215
+ expected_literal: "Expected literal {expected} at {path}; received {actual}.",
216
+ expected_array: "Expected array at {path}; received {actual}.",
217
+ expected_tuple: "Expected tuple at {path}; received {actual}.",
218
+ expected_tuple_length: "Expected tuple {expected} at {path}; received {actual}.",
219
+ expected_object: "Expected object at {path}; received {actual}.",
220
+ expected_record: "Expected record at {path}; received {actual}.",
221
+ expected_integer: "Expected integer at {path}; received {actual}.",
222
+ expected_min_length: "Expected {expected} at {path}; received {actual}.",
223
+ expected_max_length: "Expected {expected} at {path}; received {actual}.",
224
+ expected_pattern: "Expected pattern {expected} at {path}; received {actual}.",
225
+ expected_gte: "Expected value {expected} at {path}; received {actual}.",
226
+ expected_lte: "Expected value {expected} at {path}; received {actual}.",
227
+ expected_required_key: "Expected required key at {path}; received {actual}.",
228
+ expected_union: "Expected union at {path}; received {actual}.",
229
+ expected_discriminant: "Expected discriminant {expected} at {path}; received {actual}.",
230
+ expected_refinement: "Expected refinement {expected} at {path}; received {actual}.",
231
+ expected_depth_limit: "Expected validation depth within {expected} at {path}; received {actual}.",
232
+ unrecognized_key: "Unrecognized key at {path}; expected {expected}."
233
+ });
234
+ /**
235
+ * @brief ko catalog.
236
+ */
237
+ const koCatalog = Object.freeze({
238
+ expected_string: "{path}에서 문자열이 필요하지만 {actual}을 받았습니다.",
239
+ expected_number: "{path}에서 숫자가 필요하지만 {actual}을 받았습니다.",
240
+ expected_bigint: "{path}에서 bigint가 필요하지만 {actual}을 받았습니다.",
241
+ expected_symbol: "{path}에서 symbol이 필요하지만 {actual}을 받았습니다.",
242
+ expected_boolean: "{path}에서 boolean이 필요하지만 {actual}을 받았습니다.",
243
+ expected_never: "{path}에서 never가 필요하지만 {actual}을 받았습니다.",
244
+ expected_literal: "{path}에서 literal {expected}이 필요하지만 {actual}을 받았습니다.",
245
+ expected_array: "{path}에서 배열이 필요하지만 {actual}을 받았습니다.",
246
+ expected_tuple: "{path}에서 튜플이 필요하지만 {actual}을 받았습니다.",
247
+ expected_tuple_length: "{path}에서 튜플 {expected}이 필요하지만 {actual}을 받았습니다.",
248
+ expected_object: "{path}에서 객체가 필요하지만 {actual}을 받았습니다.",
249
+ expected_record: "{path}에서 record가 필요하지만 {actual}을 받았습니다.",
250
+ expected_integer: "{path}에서 정수가 필요하지만 {actual}을 받았습니다.",
251
+ expected_min_length: "{path}에서 {expected}이 필요하지만 {actual}을 받았습니다.",
252
+ expected_max_length: "{path}에서 {expected}이 필요하지만 {actual}을 받았습니다.",
253
+ expected_pattern: "{path}에서 패턴 {expected}이 필요하지만 {actual}을 받았습니다.",
254
+ expected_gte: "{path}에서 값 {expected}이 필요하지만 {actual}을 받았습니다.",
255
+ expected_lte: "{path}에서 값 {expected}이 필요하지만 {actual}을 받았습니다.",
256
+ expected_required_key: "{path}에 필수 키가 필요하지만 {actual}입니다.",
257
+ expected_union: "{path}에서 유니온 값이 필요하지만 {actual}을 받았습니다.",
258
+ expected_discriminant: "{path}에서 discriminant {expected}이 필요하지만 {actual}을 받았습니다.",
259
+ expected_refinement: "{path}에서 refinement {expected}을 통과해야 하지만 {actual}을 받았습니다.",
260
+ expected_depth_limit: "{path}에서 검증 깊이 {expected} 이내가 필요하지만 {actual}입니다.",
261
+ unrecognized_key: "{path}에서 알 수 없는 키입니다. 기대값은 {expected}입니다."
262
+ });
263
+ /**
264
+ * @brief default catalogs.
265
+ */
266
+ const defaultCatalogs = Object.freeze({
267
+ en: enCatalog,
268
+ ko: koCatalog
269
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file compact.ts
3
+ * @brief Reachability compaction for optimized graphs.
4
+ */
5
+ import type { Graph } from "../ir/index.js";
6
+ /**
7
+ * @brief compact reachable.
8
+ */
9
+ export declare function compactReachable(graph: Graph): Graph;
10
+ //# sourceMappingURL=compact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../src/optimize/compact.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAqB,MAAM,gBAAgB,CAAC;AAG/D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAyBpD"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @file compact.ts
3
+ * @brief Reachability compaction for optimized graphs.
4
+ */
5
+ import { remapId, remapNode } from "./remap.js";
6
+ /**
7
+ * @brief compact reachable.
8
+ */
9
+ export function compactReachable(graph) {
10
+ const reachable = markReachable(graph);
11
+ const remap = new Array(graph.nodes.length);
12
+ const nodes = [];
13
+ for (let index = 0; index < graph.nodes.length; index += 1) {
14
+ if (reachable[index] === true) {
15
+ remap[index] = nodes.length;
16
+ const node = graph.nodes[index];
17
+ if (node !== undefined) {
18
+ nodes.push(node);
19
+ }
20
+ }
21
+ }
22
+ const compacted = new Array(nodes.length);
23
+ for (let index = 0; index < nodes.length; index += 1) {
24
+ const node = nodes[index];
25
+ if (node !== undefined) {
26
+ compacted[index] = remapNode(node, remap);
27
+ }
28
+ }
29
+ return {
30
+ nodes: compacted,
31
+ entry: remapId(graph.entry, remap),
32
+ result: remapId(graph.result, remap)
33
+ };
34
+ }
35
+ /**
36
+ * @brief mark reachable.
37
+ */
38
+ function markReachable(graph) {
39
+ const reachable = new Array(graph.nodes.length).fill(false);
40
+ const stack = [graph.result, graph.entry];
41
+ while (stack.length !== 0) {
42
+ const id = stack.pop();
43
+ if (id === undefined || reachable[id] === true) {
44
+ continue;
45
+ }
46
+ reachable[id] = true;
47
+ const node = graph.nodes[id];
48
+ if (node === undefined) {
49
+ continue;
50
+ }
51
+ const deps = node.deps;
52
+ for (let index = 0; index < deps.length; index += 1) {
53
+ const dep = deps[index];
54
+ if (dep !== undefined) {
55
+ stack.push(dep);
56
+ }
57
+ }
58
+ }
59
+ return reachable;
60
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file fold-boolean.ts
3
+ * @brief Constant folding for boolean fold nodes.
4
+ */
5
+ import type { BooleanFoldNode, GraphNode, NodeId } from "../ir/index.js";
6
+ import { type FoldResult } from "./fold-common.js";
7
+ /**
8
+ * @brief fold and.
9
+ */
10
+ export declare function foldAnd(node: BooleanFoldNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
11
+ /**
12
+ * @brief fold or.
13
+ */
14
+ export declare function foldOr(node: BooleanFoldNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
15
+ //# sourceMappingURL=fold-boolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold-boolean.d.ts","sourceRoot":"","sources":["../../src/optimize/fold-boolean.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,MAAM,EACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CA+BZ;AAED;;GAEG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CA+BZ"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @file fold-boolean.ts
3
+ * @brief Constant folding for boolean fold nodes.
4
+ */
5
+ import { ensureConst, keep, readConst, replace } from "./fold-common.js";
6
+ /**
7
+ * @brief fold and.
8
+ */
9
+ export function foldAnd(node, nodes, aliases) {
10
+ const values = [];
11
+ for (let index = 0; index < node.values.length; index += 1) {
12
+ const value = node.values[index];
13
+ if (value === undefined) {
14
+ continue;
15
+ }
16
+ const constant = readConst(nodes, value);
17
+ if (constant.found) {
18
+ if (constant.value !== true) {
19
+ return replace(node, ensureConst(nodes, aliases, false));
20
+ }
21
+ continue;
22
+ }
23
+ values.push(value);
24
+ }
25
+ if (values.length === 0) {
26
+ return replace(node, ensureConst(nodes, aliases, true));
27
+ }
28
+ if (values.length === 1) {
29
+ const only = values[0];
30
+ if (only !== undefined) {
31
+ return replace(node, only);
32
+ }
33
+ }
34
+ return keep({
35
+ id: node.id,
36
+ tag: node.tag,
37
+ deps: values,
38
+ values
39
+ });
40
+ }
41
+ /**
42
+ * @brief fold or.
43
+ */
44
+ export function foldOr(node, nodes, aliases) {
45
+ const values = [];
46
+ for (let index = 0; index < node.values.length; index += 1) {
47
+ const value = node.values[index];
48
+ if (value === undefined) {
49
+ continue;
50
+ }
51
+ const constant = readConst(nodes, value);
52
+ if (constant.found) {
53
+ if (constant.value === true) {
54
+ return replace(node, ensureConst(nodes, aliases, true));
55
+ }
56
+ continue;
57
+ }
58
+ values.push(value);
59
+ }
60
+ if (values.length === 0) {
61
+ return replace(node, ensureConst(nodes, aliases, false));
62
+ }
63
+ if (values.length === 1) {
64
+ const only = values[0];
65
+ if (only !== undefined) {
66
+ return replace(node, only);
67
+ }
68
+ }
69
+ return keep({
70
+ id: node.id,
71
+ tag: node.tag,
72
+ deps: values,
73
+ values
74
+ });
75
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file fold-common.ts
3
+ * @brief Shared constant-folding helpers.
4
+ */
5
+ import type { GraphNode, NodeId } from "../ir/index.js";
6
+ import type { LiteralValue } from "../schema/index.js";
7
+ /**
8
+ * @brief const read.
9
+ */
10
+ export interface ConstRead {
11
+ readonly found: boolean;
12
+ readonly value: LiteralValue | undefined;
13
+ }
14
+ /**
15
+ * @brief fold result.
16
+ */
17
+ export interface FoldResult {
18
+ readonly node: GraphNode;
19
+ readonly replacement: NodeId | undefined;
20
+ }
21
+ /**
22
+ * @brief ensure const.
23
+ */
24
+ export declare function ensureConst(nodes: GraphNode[], aliases: NodeId[], value: LiteralValue): NodeId;
25
+ /**
26
+ * @brief read const.
27
+ */
28
+ export declare function readConst(nodes: readonly GraphNode[], id: NodeId): ConstRead;
29
+ /**
30
+ * @brief keep.
31
+ */
32
+ export declare function keep(node: GraphNode): FoldResult;
33
+ /**
34
+ * @brief replace.
35
+ */
36
+ export declare function replace(node: GraphNode, replacement: NodeId): FoldResult;
37
+ /**
38
+ * @brief is finite number.
39
+ */
40
+ export declare function isFiniteNumber(value: unknown): boolean;
41
+ /**
42
+ * @brief is plain record.
43
+ */
44
+ export declare function isPlainRecord(value: unknown): boolean;
45
+ //# sourceMappingURL=fold-common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold-common.d.ts","sourceRoot":"","sources":["../../src/optimize/fold-common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,KAAK,EAAE,YAAY,GAClB,MAAM,CAgBR;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAY5E;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAKhD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CAKxE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @file fold-common.ts
3
+ * @brief Shared constant-folding helpers.
4
+ */
5
+ import { NodeTag } from "../kind/index.js";
6
+ /**
7
+ * @brief ensure const.
8
+ */
9
+ export function ensureConst(nodes, aliases, value) {
10
+ for (let index = 0; index < nodes.length; index += 1) {
11
+ const node = nodes[index];
12
+ if (node?.tag === NodeTag.Const && Object.is(node.value, value)) {
13
+ return index;
14
+ }
15
+ }
16
+ const id = nodes.length;
17
+ nodes.push({
18
+ id,
19
+ tag: NodeTag.Const,
20
+ deps: [],
21
+ value
22
+ });
23
+ aliases[id] = id;
24
+ return id;
25
+ }
26
+ /**
27
+ * @brief read const.
28
+ */
29
+ export function readConst(nodes, id) {
30
+ const node = nodes[id];
31
+ if (node?.tag === NodeTag.Const) {
32
+ return {
33
+ found: true,
34
+ value: node.value
35
+ };
36
+ }
37
+ return {
38
+ found: false,
39
+ value: undefined
40
+ };
41
+ }
42
+ /**
43
+ * @brief keep.
44
+ */
45
+ export function keep(node) {
46
+ return {
47
+ node,
48
+ replacement: undefined
49
+ };
50
+ }
51
+ /**
52
+ * @brief replace.
53
+ */
54
+ export function replace(node, replacement) {
55
+ return {
56
+ node,
57
+ replacement
58
+ };
59
+ }
60
+ /**
61
+ * @brief is finite number.
62
+ */
63
+ export function isFiniteNumber(value) {
64
+ return typeof value === "number" && Number.isFinite(value);
65
+ }
66
+ /**
67
+ * @brief is plain record.
68
+ */
69
+ export function isPlainRecord(value) {
70
+ return typeof value === "object" && value !== null && !Array.isArray(value);
71
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @file fold-scalar.ts
3
+ * @brief Constant folding for scalar graph nodes.
4
+ */
5
+ import type { ArrayEveryNode, DiscriminantDispatchNode, EqualsNode, GetPropNode, GraphNode, HasOwnDataNode, HasOwnNode, NodeId, NumericCompareNode, RecordEveryNode, RegexNode, StrictKeysNode, StringBoundNode, TupleItemsNode, UnaryPredicateNode } from "../ir/index.js";
6
+ import { type FoldResult } from "./fold-common.js";
7
+ /**
8
+ * @brief fold get prop.
9
+ */
10
+ export declare function foldGetProp(node: GetPropNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
11
+ /**
12
+ * @brief fold unary.
13
+ */
14
+ export declare function foldUnary(node: UnaryPredicateNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
15
+ /**
16
+ * @brief fold equals.
17
+ */
18
+ export declare function foldEquals(node: EqualsNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
19
+ /**
20
+ * @brief fold numeric.
21
+ */
22
+ export declare function foldNumeric(node: NumericCompareNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
23
+ /**
24
+ * @brief fold string bound.
25
+ */
26
+ export declare function foldStringBound(node: StringBoundNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
27
+ /**
28
+ * @brief fold regex.
29
+ */
30
+ export declare function foldRegex(node: RegexNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
31
+ /**
32
+ * @brief fold has own.
33
+ */
34
+ export declare function foldHasOwn(node: HasOwnNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
35
+ /**
36
+ * @brief fold has own data.
37
+ */
38
+ export declare function foldHasOwnData(node: HasOwnDataNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
39
+ /**
40
+ * @brief fold strict keys.
41
+ */
42
+ export declare function foldStrictKeys(node: StrictKeysNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
43
+ /**
44
+ * @brief fold array every.
45
+ */
46
+ export declare function foldArrayEvery(node: ArrayEveryNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
47
+ /**
48
+ * @brief fold tuple items.
49
+ */
50
+ export declare function foldTupleItems(node: TupleItemsNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
51
+ /**
52
+ * @brief fold record every.
53
+ */
54
+ export declare function foldRecordEvery(node: RecordEveryNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
55
+ /**
56
+ * @brief fold discriminant dispatch.
57
+ */
58
+ export declare function foldDiscriminantDispatch(node: DiscriminantDispatchNode, nodes: GraphNode[], aliases: NodeId[]): FoldResult;
59
+ //# sourceMappingURL=fold-scalar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold-scalar.d.ts","sourceRoot":"","sources":["../../src/optimize/fold-scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,wBAAwB,EACxB,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACd,UAAU,EACV,MAAM,EACN,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,cAAc,EACd,eAAe,EACf,cAAc,EACd,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,kBAAkB,EACxB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CA6BZ;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAOZ;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,EACxB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAWZ;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CASZ;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAYZ;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,wBAAwB,EAC9B,KAAK,EAAE,SAAS,EAAE,EAClB,OAAO,EAAE,MAAM,EAAE,GAChB,UAAU,CAMZ"}