@powerlines/schema 0.11.27 → 0.11.37

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 (82) hide show
  1. package/dist/bundle.cjs +34 -20
  2. package/dist/bundle.d.cts +3 -3
  3. package/dist/bundle.d.cts.map +1 -1
  4. package/dist/bundle.d.mts +3 -3
  5. package/dist/bundle.d.mts.map +1 -1
  6. package/dist/bundle.mjs +35 -21
  7. package/dist/bundle.mjs.map +1 -1
  8. package/dist/codegen.cjs +40 -36
  9. package/dist/codegen.d.cts +10 -22
  10. package/dist/codegen.d.cts.map +1 -1
  11. package/dist/codegen.d.mts +10 -22
  12. package/dist/codegen.d.mts.map +1 -1
  13. package/dist/codegen.mjs +39 -36
  14. package/dist/codegen.mjs.map +1 -1
  15. package/dist/constants.cjs +34 -11
  16. package/dist/constants.d.cts +9 -11
  17. package/dist/constants.d.cts.map +1 -1
  18. package/dist/constants.d.mts +9 -11
  19. package/dist/constants.d.mts.map +1 -1
  20. package/dist/constants.mjs +32 -11
  21. package/dist/constants.mjs.map +1 -1
  22. package/dist/extract.cjs +122 -92
  23. package/dist/extract.d.cts +34 -69
  24. package/dist/extract.d.cts.map +1 -1
  25. package/dist/extract.d.mts +34 -69
  26. package/dist/extract.d.mts.map +1 -1
  27. package/dist/extract.mjs +123 -93
  28. package/dist/extract.mjs.map +1 -1
  29. package/dist/helpers.cjs +45 -52
  30. package/dist/helpers.d.cts +28 -24
  31. package/dist/helpers.d.cts.map +1 -1
  32. package/dist/helpers.d.mts +28 -24
  33. package/dist/helpers.d.mts.map +1 -1
  34. package/dist/helpers.mjs +46 -52
  35. package/dist/helpers.mjs.map +1 -1
  36. package/dist/index.cjs +14 -7
  37. package/dist/index.d.cts +6 -6
  38. package/dist/index.d.mts +6 -6
  39. package/dist/index.mjs +5 -5
  40. package/dist/metadata.cjs +80 -0
  41. package/dist/metadata.d.cts +52 -0
  42. package/dist/metadata.d.cts.map +1 -0
  43. package/dist/metadata.d.mts +52 -0
  44. package/dist/metadata.d.mts.map +1 -0
  45. package/dist/metadata.mjs +76 -0
  46. package/dist/metadata.mjs.map +1 -0
  47. package/dist/persistence.cjs +1 -2
  48. package/dist/persistence.d.cts +5 -5
  49. package/dist/persistence.d.cts.map +1 -1
  50. package/dist/persistence.d.mts +5 -5
  51. package/dist/persistence.d.mts.map +1 -1
  52. package/dist/persistence.mjs +1 -1
  53. package/dist/persistence.mjs.map +1 -1
  54. package/dist/reflection.cjs +289 -303
  55. package/dist/reflection.d.cts +3 -16
  56. package/dist/reflection.d.cts.map +1 -1
  57. package/dist/reflection.d.mts +3 -16
  58. package/dist/reflection.d.mts.map +1 -1
  59. package/dist/reflection.mjs +290 -304
  60. package/dist/reflection.mjs.map +1 -1
  61. package/dist/resolve.cjs +7 -7
  62. package/dist/resolve.mjs +7 -7
  63. package/dist/resolve.mjs.map +1 -1
  64. package/dist/type-checks.cjs +122 -40
  65. package/dist/type-checks.d.cts +41 -33
  66. package/dist/type-checks.d.cts.map +1 -1
  67. package/dist/type-checks.d.mts +41 -33
  68. package/dist/type-checks.d.mts.map +1 -1
  69. package/dist/type-checks.mjs +120 -37
  70. package/dist/type-checks.mjs.map +1 -1
  71. package/dist/types.d.cts +225 -113
  72. package/dist/types.d.cts.map +1 -1
  73. package/dist/types.d.mts +225 -113
  74. package/dist/types.d.mts.map +1 -1
  75. package/package.json +11 -7
  76. package/dist/jtd.cjs +0 -385
  77. package/dist/jtd.d.cts +0 -15
  78. package/dist/jtd.d.cts.map +0 -1
  79. package/dist/jtd.d.mts +0 -15
  80. package/dist/jtd.d.mts.map +0 -1
  81. package/dist/jtd.mjs +0 -384
  82. package/dist/jtd.mjs.map +0 -1
package/dist/jtd.mjs DELETED
@@ -1,384 +0,0 @@
1
- import { isBoolean, isSetArray, isSetString, isUndefined } from "@stryke/type-checks";
2
- import { isSetObject as isSetObject$1 } from "@stryke/type-checks/is-set-object";
3
-
4
- //#region src/jtd.ts
5
- /**
6
- * Maps a JSON Schema `format` annotation for integers to the closest JTD numeric type.
7
- *
8
- * @param format - The JSON Schema format hint to map.
9
- * @returns The matching JTD numeric type, or `undefined` if no exact match exists.
10
- */
11
- function jsonSchemaIntegerFormatToJtd(format) {
12
- switch (format) {
13
- case "int8": return "int8";
14
- case "uint8": return "uint8";
15
- case "int16": return "int16";
16
- case "uint16": return "uint16";
17
- case "int32": return "int32";
18
- case "uint32": return "uint32";
19
- case void 0:
20
- default: return;
21
- }
22
- }
23
- /**
24
- * Maps a JSON Schema `format` annotation for floating point numbers to the closest JTD numeric type.
25
- *
26
- * @param format - The JSON Schema format hint to map.
27
- * @returns The matching JTD numeric type, or `undefined` if no exact match exists.
28
- */
29
- function jsonSchemaNumberFormatToJtd(format) {
30
- switch (format) {
31
- case "float":
32
- case "float32": return "float32";
33
- case "double":
34
- case "float64": return "float64";
35
- case void 0:
36
- default: return;
37
- }
38
- }
39
- /**
40
- * Picks the smallest unsigned JTD integer type that can hold the provided bounds.
41
- *
42
- * @param minimum - The inclusive lower bound, when known.
43
- * @param maximum - The inclusive upper bound, when known.
44
- * @returns The narrowest unsigned JTD integer type that can represent the range, or `undefined` if the range cannot be expressed as an unsigned integer.
45
- */
46
- function pickUnsignedIntegerType(minimum, maximum) {
47
- if (minimum === void 0 || minimum < 0) return;
48
- if (maximum === void 0) return;
49
- if (maximum <= 255) return "uint8";
50
- if (maximum <= 65535) return "uint16";
51
- if (maximum <= 4294967295) return "uint32";
52
- }
53
- /**
54
- * Picks the smallest signed JTD integer type that can hold the provided bounds.
55
- *
56
- * @param minimum - The inclusive lower bound, when known.
57
- * @param maximum - The inclusive upper bound, when known.
58
- * @returns The narrowest signed JTD integer type that can represent the range, or `undefined` if the range cannot be expressed as a signed integer.
59
- */
60
- function pickSignedIntegerType(minimum, maximum) {
61
- if (minimum !== void 0 && maximum !== void 0 && minimum >= -128 && maximum <= 127) return "int8";
62
- if (minimum !== void 0 && maximum !== void 0 && minimum >= -32768 && maximum <= 32767) return "int16";
63
- return "int32";
64
- }
65
- /**
66
- * Tests whether the provided value is a non-null object that can be inspected as a JSON Schema fragment.
67
- *
68
- * @param value - The value to test.
69
- * @returns `true` if the value is a plain object suitable for JSON-Schema conversion.
70
- */
71
- function isJsonSchemaLike(value) {
72
- return isSetObject$1(value);
73
- }
74
- /**
75
- * Reads the JSON Schema `type` field as an array, normalising the single-string form.
76
- *
77
- * @param schema - The JSON Schema fragment to inspect.
78
- * @returns The list of JSON Schema type names declared on the fragment.
79
- */
80
- function readTypes(schema) {
81
- if (Array.isArray(schema.type)) return schema.type;
82
- if (typeof schema.type === "string") return [schema.type];
83
- return [];
84
- }
85
- /**
86
- * Builds a JTD `metadata` object from the JSON Schema annotation keywords found on a fragment.
87
- *
88
- * @param schema - The source JSON Schema fragment.
89
- * @returns A metadata bag suitable for attaching to a JTD form, or `undefined` if no annotations are present.
90
- */
91
- function collectMetadata(schema) {
92
- const metadata = {};
93
- if (isSetString(schema.description)) metadata.description = schema.description;
94
- if (isSetArray(schema.examples)) metadata.examples = schema.examples;
95
- if (isSetArray(schema.alias) && schema.alias.every(isSetString)) metadata.alias = schema.alias;
96
- if (isSetString(schema.table)) metadata.default = schema.table;
97
- if (isSetString(schema.title)) metadata.title = schema.title;
98
- if (!isUndefined(schema.default)) metadata.default = schema.default;
99
- if (isBoolean(schema.isHidden)) metadata.isHidden = schema.isHidden;
100
- else if (isBoolean(schema.hidden)) metadata.isHidden = schema.hidden;
101
- if (isBoolean(schema.isIgnored)) metadata.isIgnored = schema.isIgnored;
102
- else if (isBoolean(schema.ignored)) metadata.isIgnored = schema.ignored;
103
- if (isBoolean(schema.isReadonly)) metadata.isReadonly = schema.isReadonly;
104
- else if (isBoolean(schema.readonly)) metadata.isReadonly = schema.readonly;
105
- if (isBoolean(schema.isPrimaryKey)) metadata.isPrimaryKey = schema.isPrimaryKey;
106
- else if (isBoolean(schema.primaryKey)) metadata.isPrimaryKey = schema.primaryKey;
107
- if (isBoolean(schema.isInternal)) metadata.isInternal = schema.isInternal;
108
- else if (isBoolean(schema.internal)) metadata.isInternal = schema.internal;
109
- if (isBoolean(schema.isRuntime)) metadata.isRuntime = schema.isRuntime;
110
- else if (isBoolean(schema.runtime)) metadata.isRuntime = schema.runtime;
111
- if (isSetArray(schema.union)) metadata.union = schema.union;
112
- return Object.keys(metadata).length > 0 ? metadata : void 0;
113
- }
114
- /**
115
- * Attaches metadata and nullability flags to a JTD form, mutating and returning the form.
116
- *
117
- * @param form - The base JTD form to decorate.
118
- * @param schema - The source JSON Schema fragment from which annotations are read.
119
- * @param nullable - Whether the schema is nullable in JTD semantics.
120
- * @returns The decorated JTD form.
121
- */
122
- function decorate(form, schema, nullable) {
123
- if (nullable) form.nullable = true;
124
- const metadata = collectMetadata(schema);
125
- if (metadata) form.metadata = metadata;
126
- return form;
127
- }
128
- /**
129
- * Determines whether the supplied list of JSON Schema types collapses to `null` only.
130
- *
131
- * @param types - The normalized list of JSON Schema type names.
132
- * @returns `true` if the only declared type is `null`.
133
- */
134
- function isNullOnly(types) {
135
- return types.length > 0 && types.every((t) => t === "null");
136
- }
137
- /**
138
- * Splits a `null` declaration away from a list of JSON Schema types.
139
- *
140
- * @param types - The normalized list of JSON Schema type names.
141
- * @returns A tuple of `[nonNullTypes, nullable]` describing the remaining types and whether `null` was present.
142
- */
143
- function stripNull(types) {
144
- const nullable = types.includes("null");
145
- return {
146
- types: types.filter((t) => t !== "null"),
147
- nullable
148
- };
149
- }
150
- /**
151
- * Converts a JSON Schema `enum` keyword to a JTD enum form, stringifying values when required.
152
- *
153
- * @param values - The raw enum values from the JSON Schema fragment.
154
- * @returns A JTD enum form, or `undefined` if the enum cannot be represented (e.g. empty list).
155
- */
156
- function enumToJtd(values) {
157
- const strings = values.filter((v) => v !== null && v !== void 0).map((v) => String(v));
158
- if (strings.length === 0) return;
159
- return { enum: Array.from(new Set(strings)) };
160
- }
161
- /**
162
- * Selects the most appropriate JTD numeric `type` value for a JSON Schema integer fragment.
163
- *
164
- * @param schema - The integer JSON Schema fragment.
165
- * @returns The chosen JTD integer type.
166
- */
167
- function pickIntegerJtdType(schema) {
168
- const mapped = jsonSchemaIntegerFormatToJtd(schema.format);
169
- if (mapped) return mapped;
170
- const unsigned = pickUnsignedIntegerType(schema.minimum, schema.maximum);
171
- if (unsigned) return unsigned;
172
- return pickSignedIntegerType(schema.minimum, schema.maximum) ?? "int32";
173
- }
174
- /**
175
- * Selects the most appropriate JTD numeric `type` value for a JSON Schema number fragment.
176
- *
177
- * @param schema - The number JSON Schema fragment.
178
- * @returns The chosen JTD floating point type.
179
- */
180
- function pickNumberJtdType(schema) {
181
- return jsonSchemaNumberFormatToJtd(schema.format) ?? "float64";
182
- }
183
- /**
184
- * Selects the JTD string `type` value for a JSON Schema string fragment, mapping `format: "date-time"` to `timestamp`.
185
- *
186
- * @param schema - The string JSON Schema fragment.
187
- * @returns The chosen JTD string type.
188
- */
189
- function pickStringJtdType(schema) {
190
- if (schema.format === "date-time") return "timestamp";
191
- return "string";
192
- }
193
- /**
194
- * Converts a JSON Schema object fragment into a JTD properties form.
195
- *
196
- * @param schema - The object JSON Schema fragment.
197
- * @param nullable - Whether the resulting JTD form should be nullable.
198
- * @returns The JTD properties form representing the object.
199
- */
200
- function objectToJtd(schema, nullable) {
201
- const required = new Set(schema.required ?? []);
202
- const properties = {};
203
- const optionalProperties = {};
204
- const metadata = { default: schema.default ?? {} };
205
- if (schema.properties) for (const [key, value] of Object.entries(schema.properties)) {
206
- if (!isUndefined(value.default)) metadata.default[key] = value.default;
207
- const converted = jsonSchemaToJtd(value);
208
- if (!converted) continue;
209
- if (required.has(key)) properties[key] = converted;
210
- else optionalProperties[key] = converted;
211
- }
212
- const hasProperties = Object.keys(properties).length > 0;
213
- const hasOptional = Object.keys(optionalProperties).length > 0;
214
- if (!hasProperties && !hasOptional && isJsonSchemaLike(schema.additionalProperties)) {
215
- const values = jsonSchemaToJtd(schema.additionalProperties);
216
- if (values) return decorate({
217
- metadata,
218
- values
219
- }, schema, nullable);
220
- }
221
- if (!hasProperties && !hasOptional && schema.patternProperties) {
222
- const first = Object.values(schema.patternProperties)[0];
223
- if (first) {
224
- const values = jsonSchemaToJtd(first);
225
- if (values) return decorate({
226
- metadata,
227
- values
228
- }, schema, nullable);
229
- }
230
- }
231
- const form = { metadata };
232
- if (hasProperties) form.properties = properties;
233
- else if (!hasOptional) form.properties = {};
234
- if (hasOptional) form.optionalProperties = optionalProperties;
235
- if (schema.additionalProperties === true || isJsonSchemaLike(schema.additionalProperties) || schema.patternProperties !== void 0) form.additionalProperties = true;
236
- return decorate(form, schema, nullable);
237
- }
238
- /**
239
- * Converts a JSON Schema array fragment into a JTD elements form.
240
- *
241
- * @param schema - The array JSON Schema fragment.
242
- * @param nullable - Whether the resulting JTD form should be nullable.
243
- * @returns The JTD elements form representing the array.
244
- */
245
- function arrayToJtd(schema, nullable) {
246
- let elementSchema;
247
- if (Array.isArray(schema.items)) elementSchema = schema.items[0];
248
- else if (schema.items) elementSchema = schema.items;
249
- return decorate({ elements: (elementSchema ? jsonSchemaToJtd(elementSchema) : {}) ?? {} }, schema, nullable);
250
- }
251
- /**
252
- * Attempts to detect and emit a JTD discriminator form from a JSON Schema `oneOf` or `anyOf` fragment.
253
- *
254
- * @param schemas - The list of candidate JSON Schema fragments.
255
- * @param nullable - Whether the resulting JTD form should be nullable.
256
- * @returns A discriminator form when every branch shares a single tag property, otherwise `undefined`.
257
- */
258
- function tryDiscriminator(schemas, nullable) {
259
- if (schemas.length < 2) return;
260
- let candidateKey;
261
- const mapping = {};
262
- for (const branch of schemas) {
263
- if (!isJsonSchemaLike(branch) || !branch.properties) return;
264
- const constantTags = Object.entries(branch.properties).filter(([, value]) => isJsonSchemaLike(value) && (typeof value.const === "string" || Array.isArray(value.enum) && value.enum.length === 1 && typeof value.enum[0] === "string"));
265
- if (constantTags.length === 0) return;
266
- const [tagKey, tagSchema] = constantTags[0];
267
- if (!candidateKey) candidateKey = tagKey;
268
- else if (candidateKey !== tagKey) return;
269
- const tag = typeof tagSchema.const === "string" ? tagSchema.const : tagSchema.enum?.[0];
270
- const { [tagKey]: _omit, ...restProperties } = branch.properties;
271
- const restRequired = (branch.required ?? []).filter((k) => k !== tagKey);
272
- const branchForm = jsonSchemaToJtd({
273
- ...branch,
274
- properties: restProperties,
275
- required: restRequired
276
- });
277
- if (!branchForm || !isSetObject$1(branchForm) || "ref" in branchForm) return;
278
- mapping[tag] = branchForm;
279
- }
280
- if (!candidateKey) return;
281
- const form = {
282
- discriminator: candidateKey,
283
- mapping
284
- };
285
- if (nullable) form.nullable = true;
286
- return form;
287
- }
288
- /**
289
- * Converts a JSON Schema fragment (draft-07 style, as produced by `zod-to-json-schema`, Standard Schema, etc.) into a valid JSON Type Definition (RFC 8927) schema.
290
- *
291
- * Unsupported JSON Schema keywords (`pattern`, `const`, `minItems`, `maxItems`, `uniqueItems`, etc.) are dropped — JTD intentionally omits these. Annotation keywords (`description`, `title`, `default`, `examples`) are preserved under the JTD `metadata` field.
292
- *
293
- * @param schema - The JSON Schema fragment to convert.
294
- * @returns A valid JTD form, or `undefined` if the input cannot be represented.
295
- */
296
- function jsonSchemaToJtd(schema) {
297
- if (!isJsonSchemaLike(schema)) return;
298
- if (isSetString(schema.$ref)) {
299
- const match = /^#\/(?:definitions|\$defs)\/(.+)$/.exec(schema.$ref);
300
- if (match) return { ref: match[1] };
301
- }
302
- if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {
303
- const merged = schema.allOf.reduce((acc, current) => mergeJsonSchema(acc, current), {});
304
- const { allOf: _allOf, ...rest } = schema;
305
- return jsonSchemaToJtd(mergeJsonSchema(merged, rest));
306
- }
307
- const rawTypes = readTypes(schema);
308
- const { types: nonNullTypes, nullable: typeIsNullable } = stripNull(rawTypes);
309
- const nullable = Boolean(schema.nullable) || typeIsNullable;
310
- if (isNullOnly(rawTypes)) return decorate({}, schema, true);
311
- if (Array.isArray(schema.enum)) {
312
- const enumForm = enumToJtd(schema.enum);
313
- if (enumForm) return decorate(enumForm, schema, nullable);
314
- }
315
- if (isSetString(schema.const)) return decorate({ enum: [schema.const] }, schema, nullable);
316
- const union = schema.oneOf ?? schema.anyOf;
317
- if (Array.isArray(union) && union.length > 0) {
318
- const branches = union.filter(isJsonSchemaLike);
319
- const onlyNullBranches = branches.filter((b) => readTypes(b).includes("null"));
320
- const nonNullBranches = branches.filter((b) => !isNullOnly(readTypes(b)) && readTypes(b).join() !== "null");
321
- const unionNullable = nullable || onlyNullBranches.length > 0;
322
- if (nonNullBranches.length === 1) {
323
- const collapsed = jsonSchemaToJtd(nonNullBranches[0]);
324
- if (collapsed) return decorate(collapsed, schema, unionNullable);
325
- }
326
- const discriminated = tryDiscriminator(nonNullBranches, unionNullable);
327
- if (discriminated) {
328
- const metadata = collectMetadata(schema);
329
- if (metadata) discriminated.metadata = metadata;
330
- return discriminated;
331
- }
332
- const fallback = decorate({}, schema, unionNullable);
333
- const metadata = fallback.metadata ?? {};
334
- metadata.union = union;
335
- fallback.metadata = metadata;
336
- return fallback;
337
- }
338
- if (nonNullTypes.includes("object") || schema.properties || schema.patternProperties || isJsonSchemaLike(schema.additionalProperties)) {
339
- const result = objectToJtd(schema, nullable);
340
- const definitions = schema.definitions ?? schema.$defs;
341
- if (definitions && Object.keys(definitions).length > 0) {
342
- const converted = {};
343
- for (const [key, value] of Object.entries(definitions)) {
344
- const def = jsonSchemaToJtd(value);
345
- if (def) converted[key] = def;
346
- }
347
- if (Object.keys(converted).length > 0) result.definitions = converted;
348
- }
349
- return result;
350
- }
351
- if (nonNullTypes.includes("array")) return arrayToJtd(schema, nullable);
352
- if (nonNullTypes.length === 1) {
353
- const t = nonNullTypes[0];
354
- if (t === "string") return decorate({ type: pickStringJtdType(schema) }, schema, nullable);
355
- if (t === "boolean") return decorate({ type: "boolean" }, schema, nullable);
356
- if (t === "integer") return decorate({ type: pickIntegerJtdType(schema) }, schema, nullable);
357
- if (t === "number") return decorate({ type: pickNumberJtdType(schema) }, schema, nullable);
358
- }
359
- if (nonNullTypes.length > 1) return decorate({}, schema, nullable);
360
- return decorate({}, schema, nullable);
361
- }
362
- /**
363
- * Shallow-merges two JSON Schema fragments, combining `required` arrays and `properties` maps.
364
- *
365
- * @param left - The base schema fragment.
366
- * @param right - The schema fragment to merge into the base.
367
- * @returns A merged schema fragment. Neither input is mutated.
368
- */
369
- function mergeJsonSchema(left, right) {
370
- const merged = {
371
- ...left,
372
- ...right
373
- };
374
- if (left.properties || right.properties) merged.properties = {
375
- ...left.properties ?? {},
376
- ...right.properties ?? {}
377
- };
378
- if (left.required || right.required) merged.required = Array.from(new Set([...left.required ?? [], ...right.required ?? []]));
379
- return merged;
380
- }
381
-
382
- //#endregion
383
- export { jsonSchemaToJtd };
384
- //# sourceMappingURL=jtd.mjs.map
package/dist/jtd.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"jtd.mjs","names":["isSetObject"],"sources":["../src/jtd.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n isBoolean,\n isSetArray,\n isSetString,\n isUndefined\n} from \"@stryke/type-checks\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport {\n JsonSchemaLike,\n JTDNumberType,\n JTDSchemaType,\n SchemaMetadata\n} from \"./types\";\n\n/**\n * Maps a JSON Schema `format` annotation for integers to the closest JTD numeric type.\n *\n * @param format - The JSON Schema format hint to map.\n * @returns The matching JTD numeric type, or `undefined` if no exact match exists.\n */\nfunction jsonSchemaIntegerFormatToJtd(\n format: string | undefined\n): JTDNumberType | undefined {\n switch (format) {\n case \"int8\":\n return \"int8\";\n case \"uint8\":\n return \"uint8\";\n case \"int16\":\n return \"int16\";\n case \"uint16\":\n return \"uint16\";\n case \"int32\":\n return \"int32\";\n case \"uint32\":\n return \"uint32\";\n case undefined:\n default:\n return undefined;\n }\n}\n\n/**\n * Maps a JSON Schema `format` annotation for floating point numbers to the closest JTD numeric type.\n *\n * @param format - The JSON Schema format hint to map.\n * @returns The matching JTD numeric type, or `undefined` if no exact match exists.\n */\nfunction jsonSchemaNumberFormatToJtd(\n format: string | undefined\n): JTDNumberType | undefined {\n switch (format) {\n case \"float\":\n case \"float32\":\n return \"float32\";\n case \"double\":\n case \"float64\":\n return \"float64\";\n case undefined:\n default:\n return undefined;\n }\n}\n\n/**\n * Picks the smallest unsigned JTD integer type that can hold the provided bounds.\n *\n * @param minimum - The inclusive lower bound, when known.\n * @param maximum - The inclusive upper bound, when known.\n * @returns The narrowest unsigned JTD integer type that can represent the range, or `undefined` if the range cannot be expressed as an unsigned integer.\n */\nfunction pickUnsignedIntegerType(\n minimum: number | undefined,\n maximum: number | undefined\n): JTDNumberType | undefined {\n if (minimum === undefined || minimum < 0) {\n return undefined;\n }\n if (maximum === undefined) {\n return undefined;\n }\n if (maximum <= 0xff) {\n return \"uint8\";\n }\n if (maximum <= 0xffff) {\n return \"uint16\";\n }\n if (maximum <= 0xffffffff) {\n return \"uint32\";\n }\n return undefined;\n}\n\n/**\n * Picks the smallest signed JTD integer type that can hold the provided bounds.\n *\n * @param minimum - The inclusive lower bound, when known.\n * @param maximum - The inclusive upper bound, when known.\n * @returns The narrowest signed JTD integer type that can represent the range, or `undefined` if the range cannot be expressed as a signed integer.\n */\nfunction pickSignedIntegerType(\n minimum: number | undefined,\n maximum: number | undefined\n): JTDNumberType | undefined {\n if (\n minimum !== undefined &&\n maximum !== undefined &&\n minimum >= -0x80 &&\n maximum <= 0x7f\n ) {\n return \"int8\";\n }\n if (\n minimum !== undefined &&\n maximum !== undefined &&\n minimum >= -0x8000 &&\n maximum <= 0x7fff\n ) {\n return \"int16\";\n }\n return \"int32\";\n}\n\n/**\n * Tests whether the provided value is a non-null object that can be inspected as a JSON Schema fragment.\n *\n * @param value - The value to test.\n * @returns `true` if the value is a plain object suitable for JSON-Schema conversion.\n */\nfunction isJsonSchemaLike(value: unknown): value is JsonSchemaLike {\n return isSetObject(value);\n}\n\n/**\n * Reads the JSON Schema `type` field as an array, normalising the single-string form.\n *\n * @param schema - The JSON Schema fragment to inspect.\n * @returns The list of JSON Schema type names declared on the fragment.\n */\nfunction readTypes(schema: JsonSchemaLike): string[] {\n if (Array.isArray(schema.type)) {\n return schema.type;\n }\n if (typeof schema.type === \"string\") {\n return [schema.type];\n }\n return [];\n}\n\n/**\n * Builds a JTD `metadata` object from the JSON Schema annotation keywords found on a fragment.\n *\n * @param schema - The source JSON Schema fragment.\n * @returns A metadata bag suitable for attaching to a JTD form, or `undefined` if no annotations are present.\n */\nfunction collectMetadata<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(schema: JsonSchemaLike): TMetadata | undefined {\n const metadata: TMetadata = {} as TMetadata;\n if (isSetString(schema.description)) {\n metadata.description = schema.description;\n }\n\n if (isSetArray(schema.examples)) {\n metadata.examples = schema.examples;\n }\n\n if (\n isSetArray(schema.alias) &&\n (schema.alias as unknown[]).every(isSetString)\n ) {\n metadata.alias = schema.alias as string[];\n }\n\n if (isSetString(schema.table)) {\n metadata.default = schema.table;\n }\n\n if (isSetString(schema.title)) {\n metadata.title = schema.title;\n }\n\n if (!isUndefined(schema.default)) {\n metadata.default = schema.default;\n }\n\n if (isBoolean(schema.isHidden)) {\n metadata.isHidden = schema.isHidden;\n } else if (isBoolean(schema.hidden)) {\n metadata.isHidden = schema.hidden;\n }\n\n if (isBoolean(schema.isIgnored)) {\n metadata.isIgnored = schema.isIgnored;\n } else if (isBoolean(schema.ignored)) {\n metadata.isIgnored = schema.ignored;\n }\n\n if (isBoolean(schema.isReadonly)) {\n metadata.isReadonly = schema.isReadonly;\n } else if (isBoolean(schema.readonly)) {\n metadata.isReadonly = schema.readonly;\n }\n\n if (isBoolean(schema.isPrimaryKey)) {\n metadata.isPrimaryKey = schema.isPrimaryKey;\n } else if (isBoolean(schema.primaryKey)) {\n metadata.isPrimaryKey = schema.primaryKey;\n }\n\n if (isBoolean(schema.isInternal)) {\n metadata.isInternal = schema.isInternal;\n } else if (isBoolean(schema.internal)) {\n metadata.isInternal = schema.internal;\n }\n\n if (isBoolean(schema.isRuntime)) {\n metadata.isRuntime = schema.isRuntime;\n } else if (isBoolean(schema.runtime)) {\n metadata.isRuntime = schema.runtime;\n }\n\n if (isSetArray(schema.union)) {\n metadata.union = schema.union as JsonSchemaLike[];\n }\n\n return Object.keys(metadata).length > 0 ? metadata : undefined;\n}\n\n/**\n * Attaches metadata and nullability flags to a JTD form, mutating and returning the form.\n *\n * @param form - The base JTD form to decorate.\n * @param schema - The source JSON Schema fragment from which annotations are read.\n * @param nullable - Whether the schema is nullable in JTD semantics.\n * @returns The decorated JTD form.\n */\nfunction decorate<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n form: JTDSchemaType<TMetadata>,\n schema: JsonSchemaLike,\n nullable: boolean\n): JTDSchemaType<TMetadata> {\n if (nullable) {\n (form as { nullable?: boolean }).nullable = true;\n }\n const metadata = collectMetadata<TMetadata>(schema);\n if (metadata) {\n (form as { metadata?: TMetadata }).metadata = metadata;\n }\n return form;\n}\n\n/**\n * Determines whether the supplied list of JSON Schema types collapses to `null` only.\n *\n * @param types - The normalized list of JSON Schema type names.\n * @returns `true` if the only declared type is `null`.\n */\nfunction isNullOnly(types: string[]): boolean {\n return types.length > 0 && types.every(t => t === \"null\");\n}\n\n/**\n * Splits a `null` declaration away from a list of JSON Schema types.\n *\n * @param types - The normalized list of JSON Schema type names.\n * @returns A tuple of `[nonNullTypes, nullable]` describing the remaining types and whether `null` was present.\n */\nfunction stripNull(types: string[]): { types: string[]; nullable: boolean } {\n const nullable = types.includes(\"null\");\n\n return { types: types.filter(t => t !== \"null\"), nullable };\n}\n\n/**\n * Converts a JSON Schema `enum` keyword to a JTD enum form, stringifying values when required.\n *\n * @param values - The raw enum values from the JSON Schema fragment.\n * @returns A JTD enum form, or `undefined` if the enum cannot be represented (e.g. empty list).\n */\nfunction enumToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(values: readonly unknown[]): JTDSchemaType<TMetadata> | undefined {\n const strings = values\n .filter(v => v !== null && v !== undefined)\n .map(v => String(v));\n if (strings.length === 0) {\n return undefined;\n }\n return { enum: Array.from(new Set(strings)) };\n}\n\n/**\n * Selects the most appropriate JTD numeric `type` value for a JSON Schema integer fragment.\n *\n * @param schema - The integer JSON Schema fragment.\n * @returns The chosen JTD integer type.\n */\nfunction pickIntegerJtdType(schema: JsonSchemaLike): JTDNumberType {\n const mapped = jsonSchemaIntegerFormatToJtd(schema.format);\n if (mapped) {\n return mapped;\n }\n const unsigned = pickUnsignedIntegerType(schema.minimum, schema.maximum);\n if (unsigned) {\n return unsigned;\n }\n return pickSignedIntegerType(schema.minimum, schema.maximum) ?? \"int32\";\n}\n\n/**\n * Selects the most appropriate JTD numeric `type` value for a JSON Schema number fragment.\n *\n * @param schema - The number JSON Schema fragment.\n * @returns The chosen JTD floating point type.\n */\nfunction pickNumberJtdType(schema: JsonSchemaLike): JTDNumberType {\n return jsonSchemaNumberFormatToJtd(schema.format) ?? \"float64\";\n}\n\n/**\n * Selects the JTD string `type` value for a JSON Schema string fragment, mapping `format: \"date-time\"` to `timestamp`.\n *\n * @param schema - The string JSON Schema fragment.\n * @returns The chosen JTD string type.\n */\nfunction pickStringJtdType(schema: JsonSchemaLike): \"string\" | \"timestamp\" {\n if (schema.format === \"date-time\") {\n return \"timestamp\";\n }\n return \"string\";\n}\n\n/**\n * Converts a JSON Schema object fragment into a JTD properties form.\n *\n * @param schema - The object JSON Schema fragment.\n * @param nullable - Whether the resulting JTD form should be nullable.\n * @returns The JTD properties form representing the object.\n */\nfunction objectToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(schema: JsonSchemaLike, nullable: boolean): JTDSchemaType<TMetadata> {\n const required = new Set(schema.required ?? []);\n const properties: Record<string, JTDSchemaType<TMetadata>> = {};\n const optionalProperties: Record<string, JTDSchemaType<TMetadata>> = {};\n\n const metadata = {\n default: schema.default ?? {}\n } as TMetadata & { default: Record<string, unknown> };\n\n if (schema.properties) {\n for (const [key, value] of Object.entries(schema.properties)) {\n if (!isUndefined(value.default)) {\n metadata.default[key] = value.default;\n }\n\n const converted = jsonSchemaToJtd<TMetadata>(value);\n if (!converted) {\n continue;\n }\n\n if (required.has(key)) {\n properties[key] = converted;\n } else {\n optionalProperties[key] = converted;\n }\n }\n }\n\n const hasProperties = Object.keys(properties).length > 0;\n const hasOptional = Object.keys(optionalProperties).length > 0;\n\n // JTD requires `values` form for open maps with a single value schema.\n // patternProperties / additionalProperties: object collapses to `values`\n // when there are no declared properties.\n if (\n !hasProperties &&\n !hasOptional &&\n isJsonSchemaLike(schema.additionalProperties)\n ) {\n const values = jsonSchemaToJtd<TMetadata>(schema.additionalProperties);\n if (values) {\n return decorate<TMetadata>({ metadata, values }, schema, nullable);\n }\n }\n if (!hasProperties && !hasOptional && schema.patternProperties) {\n const first = Object.values(schema.patternProperties)[0];\n if (first) {\n const values = jsonSchemaToJtd<TMetadata>(first);\n if (values) {\n return decorate<TMetadata>({ metadata, values }, schema, nullable);\n }\n }\n }\n\n const form: {\n metadata: TMetadata;\n properties?: Record<string, JTDSchemaType<TMetadata>>;\n optionalProperties?: Record<string, JTDSchemaType<TMetadata>>;\n additionalProperties?: boolean;\n } = { metadata };\n\n if (hasProperties) {\n form.properties = properties;\n } else if (!hasOptional) {\n // JTD object form must have at least one of properties / optionalProperties.\n form.properties = {};\n }\n if (hasOptional) {\n form.optionalProperties = optionalProperties;\n }\n if (\n schema.additionalProperties === true ||\n isJsonSchemaLike(schema.additionalProperties) ||\n schema.patternProperties !== undefined\n ) {\n form.additionalProperties = true;\n }\n\n return decorate<TMetadata>(form, schema, nullable);\n}\n\n/**\n * Converts a JSON Schema array fragment into a JTD elements form.\n *\n * @param schema - The array JSON Schema fragment.\n * @param nullable - Whether the resulting JTD form should be nullable.\n * @returns The JTD elements form representing the array.\n */\nfunction arrayToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(schema: JsonSchemaLike, nullable: boolean): JTDSchemaType<TMetadata> {\n let elementSchema: JsonSchemaLike | undefined;\n if (Array.isArray(schema.items)) {\n // Tuple form — JTD has no native tuple support. Best effort: collapse to\n // the union (anyOf) of the tuple member schemas; if there is only one\n // distinct shape, fall back to using it directly.\n elementSchema = schema.items[0];\n } else if (schema.items) {\n elementSchema = schema.items;\n }\n\n const elements = elementSchema\n ? jsonSchemaToJtd<TMetadata>(elementSchema)\n : {};\n\n return decorate<TMetadata>({ elements: elements ?? {} }, schema, nullable);\n}\n\n/**\n * Attempts to detect and emit a JTD discriminator form from a JSON Schema `oneOf` or `anyOf` fragment.\n *\n * @param schemas - The list of candidate JSON Schema fragments.\n * @param nullable - Whether the resulting JTD form should be nullable.\n * @returns A discriminator form when every branch shares a single tag property, otherwise `undefined`.\n */\nfunction tryDiscriminator<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n schemas: readonly JsonSchemaLike[],\n nullable: boolean\n): JTDSchemaType<TMetadata> | undefined {\n if (schemas.length < 2) {\n return undefined;\n }\n\n let candidateKey: string | undefined;\n const mapping: Record<string, JTDSchemaType<TMetadata>> = {};\n\n for (const branch of schemas) {\n if (!isJsonSchemaLike(branch) || !branch.properties) {\n return undefined;\n }\n\n const constantTags = Object.entries(branch.properties).filter(\n ([, value]) =>\n isJsonSchemaLike(value) &&\n (typeof value.const === \"string\" ||\n (Array.isArray(value.enum) &&\n value.enum.length === 1 &&\n typeof value.enum[0] === \"string\"))\n );\n if (constantTags.length === 0) {\n return undefined;\n }\n\n const [tagKey, tagSchema] = constantTags[0]!;\n if (!candidateKey) {\n candidateKey = tagKey;\n } else if (candidateKey !== tagKey) {\n return undefined;\n }\n\n const tag =\n typeof tagSchema.const === \"string\"\n ? tagSchema.const\n : (tagSchema.enum?.[0] as string);\n\n // Remove the discriminator property from the branch before converting,\n // as JTD's mapping schemas describe the remainder of the object.\n const { [tagKey]: _omit, ...restProperties } = branch.properties;\n const restRequired = (branch.required ?? []).filter(k => k !== tagKey);\n const branchSchema: JsonSchemaLike = {\n ...branch,\n properties: restProperties,\n required: restRequired\n };\n\n const branchForm = jsonSchemaToJtd<TMetadata>(branchSchema);\n if (!branchForm || !isSetObject(branchForm) || \"ref\" in branchForm) {\n return undefined;\n }\n\n mapping[tag] = branchForm;\n }\n\n if (!candidateKey) {\n return undefined;\n }\n\n const form: JTDSchemaType<TMetadata> = {\n discriminator: candidateKey,\n mapping\n };\n if (nullable) {\n (form as { nullable?: boolean }).nullable = true;\n }\n\n return form;\n}\n\n/**\n * Converts a JSON Schema fragment (draft-07 style, as produced by `zod-to-json-schema`, Standard Schema, etc.) into a valid JSON Type Definition (RFC 8927) schema.\n *\n * Unsupported JSON Schema keywords (`pattern`, `const`, `minItems`, `maxItems`, `uniqueItems`, etc.) are dropped — JTD intentionally omits these. Annotation keywords (`description`, `title`, `default`, `examples`) are preserved under the JTD `metadata` field.\n *\n * @param schema - The JSON Schema fragment to convert.\n * @returns A valid JTD form, or `undefined` if the input cannot be represented.\n */\nexport function jsonSchemaToJtd<\n TMetadata extends Partial<SchemaMetadata> = Partial<SchemaMetadata>\n>(\n schema: JsonSchemaLike | undefined | null\n): JTDSchemaType<TMetadata> | undefined {\n if (!isJsonSchemaLike(schema)) {\n return undefined;\n }\n\n // $ref → JTD ref form. The pointer must reference `#/definitions/<name>`.\n if (isSetString(schema.$ref)) {\n const match = /^#\\/(?:definitions|\\$defs)\\/(.+)$/.exec(schema.$ref);\n if (match) {\n return { ref: match[1]! };\n }\n }\n\n // allOf — fold member schemas together via shallow merge before converting.\n if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {\n const merged = schema.allOf.reduce<JsonSchemaLike>(\n (acc, current) => mergeJsonSchema(acc, current),\n {}\n );\n const { allOf: _allOf, ...rest } = schema;\n\n return jsonSchemaToJtd<TMetadata>(mergeJsonSchema(merged, rest));\n }\n\n const rawTypes = readTypes(schema);\n const { types: nonNullTypes, nullable: typeIsNullable } = stripNull(rawTypes);\n const nullable = Boolean(schema.nullable) || typeIsNullable;\n\n // Pure null type → JTD has no first-class null form, emit empty + nullable.\n if (isNullOnly(rawTypes)) {\n return decorate<TMetadata>({}, schema, true);\n }\n\n // Enum form.\n if (Array.isArray(schema.enum)) {\n const enumForm = enumToJtd<TMetadata>(schema.enum);\n if (enumForm) {\n return decorate<TMetadata>(enumForm, schema, nullable);\n }\n }\n\n // const → enum of one (only valid when value is a string in JTD).\n if (isSetString(schema.const)) {\n return decorate<TMetadata>({ enum: [schema.const] }, schema, nullable);\n }\n\n // anyOf / oneOf — try to detect a discriminated union, otherwise collapse.\n const union = schema.oneOf ?? schema.anyOf;\n if (Array.isArray(union) && union.length > 0) {\n const branches = union.filter(isJsonSchemaLike);\n const onlyNullBranches = branches.filter(b =>\n readTypes(b).includes(\"null\")\n );\n const nonNullBranches = branches.filter(\n b => !isNullOnly(readTypes(b)) && readTypes(b).join() !== \"null\"\n );\n const unionNullable = nullable || onlyNullBranches.length > 0;\n\n if (nonNullBranches.length === 1) {\n const collapsed = jsonSchemaToJtd<TMetadata>(nonNullBranches[0]);\n if (collapsed) {\n return decorate<TMetadata>(collapsed, schema, unionNullable);\n }\n }\n\n const discriminated = tryDiscriminator<TMetadata>(\n nonNullBranches,\n unionNullable\n );\n if (discriminated) {\n const metadata = collectMetadata<TMetadata>(schema);\n if (metadata) {\n (discriminated as { metadata?: TMetadata }).metadata = metadata;\n }\n return discriminated;\n }\n\n // No safe JTD equivalent: emit empty schema (matches any value) with\n // metadata to preserve provenance.\n const fallback = decorate<TMetadata>({}, schema, unionNullable);\n const metadata =\n (fallback as { metadata?: TMetadata }).metadata ?? ({} as TMetadata);\n metadata.union = union;\n (fallback as { metadata?: TMetadata }).metadata = metadata;\n return fallback;\n }\n\n // Object form — `type: \"object\"` or implicit via `properties`.\n if (\n nonNullTypes.includes(\"object\") ||\n schema.properties ||\n schema.patternProperties ||\n isJsonSchemaLike(schema.additionalProperties)\n ) {\n const result = objectToJtd<TMetadata>(schema, nullable);\n const definitions = schema.definitions ?? schema.$defs;\n if (definitions && Object.keys(definitions).length > 0) {\n const converted: Record<string, JTDSchemaType<TMetadata>> = {};\n for (const [key, value] of Object.entries(definitions)) {\n const def = jsonSchemaToJtd<TMetadata>(value);\n if (def) {\n converted[key] = def;\n }\n }\n if (Object.keys(converted).length > 0) {\n (\n result as { definitions?: Record<string, JTDSchemaType<TMetadata>> }\n ).definitions = converted;\n }\n }\n return result;\n }\n\n if (nonNullTypes.includes(\"array\")) {\n return arrayToJtd<TMetadata>(schema, nullable);\n }\n\n // Scalar types.\n if (nonNullTypes.length === 1) {\n const t = nonNullTypes[0]!;\n if (t === \"string\") {\n return decorate<TMetadata>(\n { type: pickStringJtdType(schema) },\n schema,\n nullable\n );\n }\n if (t === \"boolean\") {\n return decorate<TMetadata>({ type: \"boolean\" }, schema, nullable);\n }\n if (t === \"integer\") {\n return decorate<TMetadata>(\n { type: pickIntegerJtdType(schema) },\n schema,\n nullable\n );\n }\n if (t === \"number\") {\n return decorate<TMetadata>(\n { type: pickNumberJtdType(schema) },\n schema,\n nullable\n );\n }\n }\n\n // Mixed scalar types (e.g. [\"string\", \"number\"]) — emit empty schema since\n // JTD has no native union of primitives.\n if (nonNullTypes.length > 1) {\n return decorate<TMetadata>({}, schema, nullable);\n }\n\n // No type info — empty (any) schema, possibly nullable.\n return decorate<TMetadata>({}, schema, nullable);\n}\n\n/**\n * Shallow-merges two JSON Schema fragments, combining `required` arrays and `properties` maps.\n *\n * @param left - The base schema fragment.\n * @param right - The schema fragment to merge into the base.\n * @returns A merged schema fragment. Neither input is mutated.\n */\nfunction mergeJsonSchema(\n left: JsonSchemaLike,\n right: JsonSchemaLike\n): JsonSchemaLike {\n const merged: JsonSchemaLike = { ...left, ...right };\n if (left.properties || right.properties) {\n merged.properties = {\n ...(left.properties ?? {}),\n ...(right.properties ?? {})\n };\n }\n if (left.required || right.required) {\n merged.required = Array.from(\n new Set([...(left.required ?? []), ...(right.required ?? [])])\n );\n }\n return merged;\n}\n"],"mappings":";;;;;;;;;;AAsCA,SAAS,6BACP,QAC2B;CAC3B,QAAQ,QAAR;EACE,KAAK,QACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,KAAK,UACH,OAAO;EACT,KAAK;EACL,SACE;CACJ;AACF;;;;;;;AAQA,SAAS,4BACP,QAC2B;CAC3B,QAAQ,QAAR;EACE,KAAK;EACL,KAAK,WACH,OAAO;EACT,KAAK;EACL,KAAK,WACH,OAAO;EACT,KAAK;EACL,SACE;CACJ;AACF;;;;;;;;AASA,SAAS,wBACP,SACA,SAC2B;CAC3B,IAAI,YAAY,UAAa,UAAU,GACrC;CAEF,IAAI,YAAY,QACd;CAEF,IAAI,WAAW,KACb,OAAO;CAET,IAAI,WAAW,OACb,OAAO;CAET,IAAI,WAAW,YACb,OAAO;AAGX;;;;;;;;AASA,SAAS,sBACP,SACA,SAC2B;CAC3B,IACE,YAAY,UACZ,YAAY,UACZ,WAAW,QACX,WAAW,KAEX,OAAO;CAET,IACE,YAAY,UACZ,YAAY,UACZ,WAAW,UACX,WAAW,OAEX,OAAO;CAET,OAAO;AACT;;;;;;;AAQA,SAAS,iBAAiB,OAAyC;CACjE,OAAOA,cAAY,KAAK;AAC1B;;;;;;;AAQA,SAAS,UAAU,QAAkC;CACnD,IAAI,MAAM,QAAQ,OAAO,IAAI,GAC3B,OAAO,OAAO;CAEhB,IAAI,OAAO,OAAO,SAAS,UACzB,OAAO,CAAC,OAA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