@adhd/apigen-base-logical 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +10 -0
- package/index.js +1 -0
- package/index.mjs +751 -0
- package/lib/codecs/byte.d.ts +13 -0
- package/lib/codecs/date-time.d.ts +11 -0
- package/lib/codecs/decimal.d.ts +29 -0
- package/lib/codecs/index.d.ts +24 -0
- package/lib/codecs/int64.d.ts +12 -0
- package/lib/codecs/number-special.d.ts +22 -0
- package/lib/codecs/uuid.d.ts +10 -0
- package/lib/contracts.d.ts +60 -0
- package/lib/descriptor-ext.d.ts +25 -0
- package/lib/emit.d.ts +113 -0
- package/lib/hints.d.ts +86 -0
- package/lib/registry.d.ts +37 -0
- package/lib/runmode.d.ts +97 -0
- package/package.json +7 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
const l = "$apigen";
|
|
2
|
+
class g extends Error {
|
|
3
|
+
constructor(o) {
|
|
4
|
+
super(o), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function z(e) {
|
|
8
|
+
e == null || e.wellKnown;
|
|
9
|
+
const o = /* @__PURE__ */ new Map();
|
|
10
|
+
return {
|
|
11
|
+
register(n, r) {
|
|
12
|
+
if (o.has(n.id) && !(r != null && r.override))
|
|
13
|
+
throw new g(
|
|
14
|
+
`E_DUP_CODEC: a codec is already registered for id "${n.id}"`
|
|
15
|
+
);
|
|
16
|
+
o.set(n.id, n);
|
|
17
|
+
},
|
|
18
|
+
resolve(n) {
|
|
19
|
+
for (const r of o.values())
|
|
20
|
+
if (r.matches(n))
|
|
21
|
+
return r;
|
|
22
|
+
},
|
|
23
|
+
get(n) {
|
|
24
|
+
return o.get(n);
|
|
25
|
+
},
|
|
26
|
+
ids() {
|
|
27
|
+
return [...o.keys()];
|
|
28
|
+
},
|
|
29
|
+
freeze() {
|
|
30
|
+
const n = new Map(o), r = {
|
|
31
|
+
register() {
|
|
32
|
+
throw new g(
|
|
33
|
+
"E_DUP_CODEC: registry is frozen and cannot accept new codecs"
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
resolve(d) {
|
|
37
|
+
for (const a of n.values())
|
|
38
|
+
if (a.matches(d))
|
|
39
|
+
return a;
|
|
40
|
+
},
|
|
41
|
+
get(d) {
|
|
42
|
+
return n.get(d);
|
|
43
|
+
},
|
|
44
|
+
ids() {
|
|
45
|
+
return [...n.keys()];
|
|
46
|
+
},
|
|
47
|
+
freeze() {
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
return r;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const v = "x-apigen-logical", U = "x-apigen-codec", W = "x-apigen-ctor", K = "x-apigen-tojson", X = "0.1.0", j = [
|
|
56
|
+
"scalar",
|
|
57
|
+
"nominal",
|
|
58
|
+
"union",
|
|
59
|
+
"map",
|
|
60
|
+
"set"
|
|
61
|
+
];
|
|
62
|
+
function H(e) {
|
|
63
|
+
const o = e[v];
|
|
64
|
+
return typeof o == "string" && j.includes(o) ? o : void 0;
|
|
65
|
+
}
|
|
66
|
+
function Z(e) {
|
|
67
|
+
const o = e[U];
|
|
68
|
+
return typeof o == "string" ? o : void 0;
|
|
69
|
+
}
|
|
70
|
+
function h(e, o) {
|
|
71
|
+
return {
|
|
72
|
+
registry: e,
|
|
73
|
+
resolve: (t) => {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`[apigen-logical] $ref "${t}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
seen: /* @__PURE__ */ new WeakSet(),
|
|
79
|
+
path: "",
|
|
80
|
+
mode: "strict",
|
|
81
|
+
...o
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function p(e, o, t) {
|
|
85
|
+
const n = t.registry.resolve(o);
|
|
86
|
+
if (n)
|
|
87
|
+
return n.encode(e, o, t);
|
|
88
|
+
const r = o.$ref;
|
|
89
|
+
if (typeof r == "string") {
|
|
90
|
+
const i = t.resolve(r);
|
|
91
|
+
return p(e, i, t);
|
|
92
|
+
}
|
|
93
|
+
const d = o.oneOf;
|
|
94
|
+
if (Array.isArray(d)) {
|
|
95
|
+
const i = S(e, d, o);
|
|
96
|
+
return p(e, i, t);
|
|
97
|
+
}
|
|
98
|
+
const a = o.type;
|
|
99
|
+
if (a === "array") {
|
|
100
|
+
if (!Array.isArray(e))
|
|
101
|
+
return D(e, o, t);
|
|
102
|
+
const i = o.items;
|
|
103
|
+
if (!i)
|
|
104
|
+
return e.map((c) => u(c));
|
|
105
|
+
const f = t.path;
|
|
106
|
+
return Array.isArray(i) ? e.map((c, _) => {
|
|
107
|
+
const s = i[_];
|
|
108
|
+
return s === void 0 ? u(c) : p(c, s, { ...t, path: `${f}/${_}` });
|
|
109
|
+
}) : e.map(
|
|
110
|
+
(c, _) => p(c, i, { ...t, path: `${f}/${_}` })
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (a === "object") {
|
|
114
|
+
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
115
|
+
return D(e, o, t);
|
|
116
|
+
const i = o.properties;
|
|
117
|
+
if (!i)
|
|
118
|
+
return u(e);
|
|
119
|
+
const f = t.path, c = {};
|
|
120
|
+
for (const [_, s] of Object.entries(i)) {
|
|
121
|
+
const m = e[_];
|
|
122
|
+
m !== void 0 && (c[_] = p(m, s, {
|
|
123
|
+
...t,
|
|
124
|
+
path: `${f}/${_}`
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
return c;
|
|
128
|
+
}
|
|
129
|
+
return a == null ? D(e, o, t) : u(e);
|
|
130
|
+
}
|
|
131
|
+
function E(e, o, t) {
|
|
132
|
+
const n = t.registry.resolve(o);
|
|
133
|
+
if (n)
|
|
134
|
+
return n.decode(e, o, t);
|
|
135
|
+
const r = o.$ref;
|
|
136
|
+
if (typeof r == "string") {
|
|
137
|
+
const i = t.resolve(r);
|
|
138
|
+
return E(e, i, t);
|
|
139
|
+
}
|
|
140
|
+
const d = o.oneOf;
|
|
141
|
+
if (Array.isArray(d)) {
|
|
142
|
+
const i = S(e, d, o);
|
|
143
|
+
return E(e, i, t);
|
|
144
|
+
}
|
|
145
|
+
const a = o.type;
|
|
146
|
+
if (a === "array") {
|
|
147
|
+
if (!Array.isArray(e))
|
|
148
|
+
return e;
|
|
149
|
+
const i = o.items;
|
|
150
|
+
if (!i)
|
|
151
|
+
return e;
|
|
152
|
+
const f = t.path;
|
|
153
|
+
return Array.isArray(i) ? e.map((c, _) => {
|
|
154
|
+
const s = i[_];
|
|
155
|
+
return s === void 0 ? c : E(c, s, { ...t, path: `${f}/${_}` });
|
|
156
|
+
}) : e.map(
|
|
157
|
+
(c, _) => E(c, i, { ...t, path: `${f}/${_}` })
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (a === "object") {
|
|
161
|
+
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
162
|
+
return e;
|
|
163
|
+
const i = o.properties;
|
|
164
|
+
if (!i)
|
|
165
|
+
return e;
|
|
166
|
+
const f = t.path, c = {};
|
|
167
|
+
for (const [_, s] of Object.entries(i)) {
|
|
168
|
+
const m = e[_];
|
|
169
|
+
m !== void 0 && (c[_] = E(m, s, {
|
|
170
|
+
...t,
|
|
171
|
+
path: `${f}/${_}`
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
return c;
|
|
175
|
+
}
|
|
176
|
+
return a == null ? M(e, t) : e;
|
|
177
|
+
}
|
|
178
|
+
function S(e, o, t, n) {
|
|
179
|
+
const r = t.discriminator;
|
|
180
|
+
if (r != null && r.propertyName) {
|
|
181
|
+
const d = e !== null && typeof e == "object" ? e[r.propertyName] : void 0;
|
|
182
|
+
if (typeof d == "string" && r.mapping) {
|
|
183
|
+
const a = r.mapping[d];
|
|
184
|
+
if (a) {
|
|
185
|
+
const i = o.find((f) => f.$ref === a);
|
|
186
|
+
if (i)
|
|
187
|
+
return i;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return o[0] ?? {};
|
|
192
|
+
}
|
|
193
|
+
function D(e, o, t) {
|
|
194
|
+
for (const n of t.registry.ids()) {
|
|
195
|
+
const r = t.registry.get(n);
|
|
196
|
+
if (r)
|
|
197
|
+
try {
|
|
198
|
+
const d = r.encode(e, r.schema, t);
|
|
199
|
+
return { [l]: n, v: d };
|
|
200
|
+
} catch {
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return u(e);
|
|
204
|
+
}
|
|
205
|
+
function M(e, o) {
|
|
206
|
+
if (e !== null && typeof e == "object" && !Array.isArray(e) && l in e) {
|
|
207
|
+
const t = e, n = t[l], r = o.registry.get(n);
|
|
208
|
+
if (r)
|
|
209
|
+
return r.decode(t.v, r.schema, o);
|
|
210
|
+
}
|
|
211
|
+
return e;
|
|
212
|
+
}
|
|
213
|
+
function u(e) {
|
|
214
|
+
if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean")
|
|
215
|
+
return e;
|
|
216
|
+
if (Array.isArray(e))
|
|
217
|
+
return e.map(u);
|
|
218
|
+
if (typeof e == "object") {
|
|
219
|
+
const o = {};
|
|
220
|
+
for (const [t, n] of Object.entries(e))
|
|
221
|
+
n !== void 0 && (o[t] = u(n));
|
|
222
|
+
return o;
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
function q(e, o) {
|
|
227
|
+
const t = /* @__PURE__ */ new Set(), n = [e];
|
|
228
|
+
for (; n.length > 0; ) {
|
|
229
|
+
const r = n.pop();
|
|
230
|
+
if (!r || t.has(r))
|
|
231
|
+
continue;
|
|
232
|
+
t.add(r);
|
|
233
|
+
const d = r.$ref;
|
|
234
|
+
if (typeof d == "string") {
|
|
235
|
+
if (o) {
|
|
236
|
+
const s = o[d];
|
|
237
|
+
if (!s) {
|
|
238
|
+
const m = Object.keys(o).join(", ") || "(none)";
|
|
239
|
+
throw new Error(
|
|
240
|
+
`[apigen-logical] $ref "${d}" cannot be resolved. Available $defs: ${m}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
n.push(s);
|
|
244
|
+
}
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const a = r.oneOf;
|
|
248
|
+
if (Array.isArray(a))
|
|
249
|
+
for (const s of a)
|
|
250
|
+
typeof s == "object" && s !== null && n.push(s);
|
|
251
|
+
const i = r.properties;
|
|
252
|
+
if (i)
|
|
253
|
+
for (const s of Object.values(i))
|
|
254
|
+
n.push(s);
|
|
255
|
+
const f = r.items;
|
|
256
|
+
if (Array.isArray(f))
|
|
257
|
+
for (const s of f)
|
|
258
|
+
typeof s == "object" && s !== null && n.push(s);
|
|
259
|
+
else
|
|
260
|
+
typeof f == "object" && f !== null && n.push(f);
|
|
261
|
+
const c = r.additionalProperties;
|
|
262
|
+
typeof c == "object" && c !== null && n.push(c);
|
|
263
|
+
const _ = r.propertyNames;
|
|
264
|
+
typeof _ == "object" && _ !== null && n.push(_);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function Q(e) {
|
|
268
|
+
return {
|
|
269
|
+
encode(o, t, n) {
|
|
270
|
+
const r = h(e, n);
|
|
271
|
+
return p(o, t, r);
|
|
272
|
+
},
|
|
273
|
+
decode(o, t, n) {
|
|
274
|
+
const r = h(e, n);
|
|
275
|
+
return E(o, t, r);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function x(e, o, t) {
|
|
280
|
+
try {
|
|
281
|
+
const n = t();
|
|
282
|
+
e.register(n);
|
|
283
|
+
} catch (n) {
|
|
284
|
+
if (P(n))
|
|
285
|
+
return;
|
|
286
|
+
throw n;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function P(e) {
|
|
290
|
+
return e === null || typeof e != "object" ? !1 : e.code === "MODULE_NOT_FOUND";
|
|
291
|
+
}
|
|
292
|
+
const b = {
|
|
293
|
+
id: "date-time",
|
|
294
|
+
kind: "scalar",
|
|
295
|
+
schema: { type: "string", format: "date-time" },
|
|
296
|
+
matches(e) {
|
|
297
|
+
return e.type === "string" && e.format === "date-time";
|
|
298
|
+
},
|
|
299
|
+
encode(e, o, t) {
|
|
300
|
+
return e.toISOString();
|
|
301
|
+
},
|
|
302
|
+
decode(e, o, t) {
|
|
303
|
+
if (typeof e != "string") {
|
|
304
|
+
if (t.mode === "strict")
|
|
305
|
+
throw new TypeError(
|
|
306
|
+
`[date-time] expected a string on the wire at "${t.path}", got ${typeof e}`
|
|
307
|
+
);
|
|
308
|
+
return new Date(String(e));
|
|
309
|
+
}
|
|
310
|
+
if (t.mode === "strict" && Number.isNaN(new Date(e).getTime()))
|
|
311
|
+
throw new TypeError(
|
|
312
|
+
`[date-time] invalid date-time string at "${t.path}": ${JSON.stringify(e)}`
|
|
313
|
+
);
|
|
314
|
+
return new Date(e);
|
|
315
|
+
}
|
|
316
|
+
}, N = {
|
|
317
|
+
id: "int64",
|
|
318
|
+
kind: "scalar",
|
|
319
|
+
schema: { type: "string", format: "int64" },
|
|
320
|
+
matches(e) {
|
|
321
|
+
return e.type === "string" && e.format === "int64";
|
|
322
|
+
},
|
|
323
|
+
encode(e, o, t) {
|
|
324
|
+
return String(e);
|
|
325
|
+
},
|
|
326
|
+
decode(e, o, t) {
|
|
327
|
+
if (typeof e != "string") {
|
|
328
|
+
if (t.mode === "strict")
|
|
329
|
+
throw new TypeError(
|
|
330
|
+
`[int64] expected a string on the wire at "${t.path}", got ${typeof e}`
|
|
331
|
+
);
|
|
332
|
+
try {
|
|
333
|
+
return BigInt(Math.trunc(Number(e)));
|
|
334
|
+
} catch {
|
|
335
|
+
return BigInt(0);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (t.mode === "strict")
|
|
339
|
+
return BigInt(e);
|
|
340
|
+
if (/^-?\d+$/.test(e))
|
|
341
|
+
try {
|
|
342
|
+
return BigInt(e);
|
|
343
|
+
} catch {
|
|
344
|
+
return BigInt(0);
|
|
345
|
+
}
|
|
346
|
+
return BigInt(0);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
function ee(e) {
|
|
350
|
+
return e;
|
|
351
|
+
}
|
|
352
|
+
const F = {
|
|
353
|
+
id: "decimal",
|
|
354
|
+
kind: "scalar",
|
|
355
|
+
schema: { type: "string", format: "decimal" },
|
|
356
|
+
matches(e) {
|
|
357
|
+
return e.type === "string" && e.format === "decimal";
|
|
358
|
+
},
|
|
359
|
+
encode(e, o, t) {
|
|
360
|
+
return e;
|
|
361
|
+
},
|
|
362
|
+
decode(e, o, t) {
|
|
363
|
+
if (typeof e != "string") {
|
|
364
|
+
if (t.mode === "strict")
|
|
365
|
+
throw new TypeError(
|
|
366
|
+
`[decimal] expected a string on the wire at "${t.path}", got ${typeof e}`
|
|
367
|
+
);
|
|
368
|
+
return String(e);
|
|
369
|
+
}
|
|
370
|
+
if (t.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e))
|
|
371
|
+
throw new TypeError(
|
|
372
|
+
`[decimal] wire value "${e}" at "${t.path}" is not a valid decimal string`
|
|
373
|
+
);
|
|
374
|
+
return e;
|
|
375
|
+
}
|
|
376
|
+
}, $ = {
|
|
377
|
+
id: "byte",
|
|
378
|
+
kind: "scalar",
|
|
379
|
+
schema: { type: "string", format: "byte" },
|
|
380
|
+
matches(e) {
|
|
381
|
+
return e.type === "string" && e.format === "byte";
|
|
382
|
+
},
|
|
383
|
+
encode(e, o, t) {
|
|
384
|
+
return Buffer.from(e).toString("base64");
|
|
385
|
+
},
|
|
386
|
+
decode(e, o, t) {
|
|
387
|
+
if (typeof e != "string") {
|
|
388
|
+
if (t.mode === "strict")
|
|
389
|
+
throw new TypeError(
|
|
390
|
+
`[byte] expected a base64 string on the wire at "${t.path}", got ${typeof e}`
|
|
391
|
+
);
|
|
392
|
+
return new Uint8Array(0);
|
|
393
|
+
}
|
|
394
|
+
if (t.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e))
|
|
395
|
+
throw new TypeError(
|
|
396
|
+
`[byte] wire value at "${t.path}" is not standard base64 (format:byte): "${e}"`
|
|
397
|
+
);
|
|
398
|
+
return new Uint8Array(Buffer.from(e, "base64"));
|
|
399
|
+
}
|
|
400
|
+
}, R = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, L = {
|
|
401
|
+
id: "uuid",
|
|
402
|
+
kind: "scalar",
|
|
403
|
+
schema: { type: "string", format: "uuid" },
|
|
404
|
+
matches(e) {
|
|
405
|
+
return e.type === "string" && e.format === "uuid";
|
|
406
|
+
},
|
|
407
|
+
encode(e, o, t) {
|
|
408
|
+
return e.toLowerCase();
|
|
409
|
+
},
|
|
410
|
+
decode(e, o, t) {
|
|
411
|
+
if (typeof e != "string") {
|
|
412
|
+
if (t.mode === "strict")
|
|
413
|
+
throw new TypeError(
|
|
414
|
+
`[uuid] expected a string on the wire at "${t.path}", got ${typeof e}`
|
|
415
|
+
);
|
|
416
|
+
return String(e).toLowerCase();
|
|
417
|
+
}
|
|
418
|
+
if (t.mode === "strict" && !R.test(e))
|
|
419
|
+
throw new TypeError(
|
|
420
|
+
`[uuid] wire value "${e}" at "${t.path}" is not a lowercase-hyphenated RFC 4122 UUID`
|
|
421
|
+
);
|
|
422
|
+
return e;
|
|
423
|
+
}
|
|
424
|
+
}, O = "NaN", C = "Infinity", A = "-Infinity", G = /* @__PURE__ */ new Set([
|
|
425
|
+
O,
|
|
426
|
+
C,
|
|
427
|
+
A
|
|
428
|
+
]), I = {
|
|
429
|
+
id: "number-special",
|
|
430
|
+
kind: "scalar",
|
|
431
|
+
schema: { type: "number" },
|
|
432
|
+
matches(e) {
|
|
433
|
+
return e.type === "number" && e.format === void 0;
|
|
434
|
+
},
|
|
435
|
+
encode(e, o, t) {
|
|
436
|
+
return Number.isNaN(e) ? O : e === 1 / 0 ? C : e === -1 / 0 ? A : e;
|
|
437
|
+
},
|
|
438
|
+
decode(e, o, t) {
|
|
439
|
+
if (typeof e == "number")
|
|
440
|
+
return e;
|
|
441
|
+
if (typeof e == "string") {
|
|
442
|
+
if (e === O)
|
|
443
|
+
return NaN;
|
|
444
|
+
if (e === C)
|
|
445
|
+
return 1 / 0;
|
|
446
|
+
if (e === A)
|
|
447
|
+
return -1 / 0;
|
|
448
|
+
const n = Number(e);
|
|
449
|
+
if (!Number.isNaN(n))
|
|
450
|
+
return n;
|
|
451
|
+
}
|
|
452
|
+
if (t.mode === "strict")
|
|
453
|
+
throw new TypeError(
|
|
454
|
+
`[number-special] unrecognized wire value at "${t.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...G].join(", ")}.`
|
|
455
|
+
);
|
|
456
|
+
return NaN;
|
|
457
|
+
}
|
|
458
|
+
}, w = [
|
|
459
|
+
b,
|
|
460
|
+
N,
|
|
461
|
+
F,
|
|
462
|
+
$,
|
|
463
|
+
L,
|
|
464
|
+
I
|
|
465
|
+
];
|
|
466
|
+
function te(e, o = {}) {
|
|
467
|
+
for (const t of w)
|
|
468
|
+
e.register(t, { override: o.override ?? !1 });
|
|
469
|
+
}
|
|
470
|
+
const T = [
|
|
471
|
+
b.id,
|
|
472
|
+
// 'date-time'
|
|
473
|
+
N.id,
|
|
474
|
+
// 'int64'
|
|
475
|
+
F.id,
|
|
476
|
+
// 'decimal'
|
|
477
|
+
$.id,
|
|
478
|
+
// 'byte'
|
|
479
|
+
L.id,
|
|
480
|
+
// 'uuid'
|
|
481
|
+
I.id
|
|
482
|
+
// 'number-special'
|
|
483
|
+
], B = {
|
|
484
|
+
"date-time": {
|
|
485
|
+
encode: "$.toISOString()",
|
|
486
|
+
decode: "new Date($)",
|
|
487
|
+
mode: "native"
|
|
488
|
+
},
|
|
489
|
+
int64: {
|
|
490
|
+
encode: "String($)",
|
|
491
|
+
decode: "BigInt($)",
|
|
492
|
+
mode: "native"
|
|
493
|
+
},
|
|
494
|
+
decimal: {
|
|
495
|
+
// Default: branded string (zero-dep); opt-in to decimal.js for arithmetic.
|
|
496
|
+
// DESIGN §13.2 branded row / §18 resolved: mode:'branded', dep declared so
|
|
497
|
+
// generators can optionally inject it; consumers that never use Decimal
|
|
498
|
+
// never install it (§14.2).
|
|
499
|
+
encode: "$.toString()",
|
|
500
|
+
decode: "new Decimal($)",
|
|
501
|
+
imports: [],
|
|
502
|
+
dep: { name: "decimal.js", version: "^10" },
|
|
503
|
+
mode: "branded"
|
|
504
|
+
},
|
|
505
|
+
byte: {
|
|
506
|
+
encode: "Buffer.from($).toString('base64')",
|
|
507
|
+
decode: "new Uint8Array(Buffer.from($, 'base64'))",
|
|
508
|
+
mode: "native"
|
|
509
|
+
},
|
|
510
|
+
uuid: {
|
|
511
|
+
// UUID is a plain string in TS; encode normalises to lowercase.
|
|
512
|
+
encode: "$.toLowerCase()",
|
|
513
|
+
decode: "$",
|
|
514
|
+
mode: "native"
|
|
515
|
+
},
|
|
516
|
+
"number-special": {
|
|
517
|
+
// numToWire / wireToNum are stdlib helpers emitted inline by the engine.
|
|
518
|
+
encode: "numToWire($)",
|
|
519
|
+
decode: "wireToNum($)",
|
|
520
|
+
mode: "native"
|
|
521
|
+
}
|
|
522
|
+
}, k = {
|
|
523
|
+
"date-time": {
|
|
524
|
+
encode: "$.isoformat()",
|
|
525
|
+
decode: "datetime.fromisoformat($)",
|
|
526
|
+
imports: ["from datetime import datetime"],
|
|
527
|
+
mode: "native"
|
|
528
|
+
},
|
|
529
|
+
int64: {
|
|
530
|
+
encode: "str($)",
|
|
531
|
+
decode: "int($)",
|
|
532
|
+
mode: "native"
|
|
533
|
+
},
|
|
534
|
+
decimal: {
|
|
535
|
+
encode: "str($)",
|
|
536
|
+
decode: "Decimal($)",
|
|
537
|
+
imports: ["from decimal import Decimal"],
|
|
538
|
+
mode: "native"
|
|
539
|
+
},
|
|
540
|
+
byte: {
|
|
541
|
+
encode: "b64encode($).decode()",
|
|
542
|
+
decode: "b64decode($)",
|
|
543
|
+
imports: ["from base64 import b64encode, b64decode"],
|
|
544
|
+
mode: "native"
|
|
545
|
+
},
|
|
546
|
+
uuid: {
|
|
547
|
+
encode: "str($)",
|
|
548
|
+
decode: "UUID($)",
|
|
549
|
+
imports: ["from uuid import UUID"],
|
|
550
|
+
mode: "native"
|
|
551
|
+
},
|
|
552
|
+
"number-special": {
|
|
553
|
+
// Python json.dumps maps float('nan')/float('inf') to null by default;
|
|
554
|
+
// the codec overrides with string sentinels (same as TS).
|
|
555
|
+
encode: "num_to_wire($)",
|
|
556
|
+
decode: "wire_to_num($)",
|
|
557
|
+
mode: "native"
|
|
558
|
+
}
|
|
559
|
+
}, J = {
|
|
560
|
+
"date-time": {
|
|
561
|
+
// chrono::DateTime<Utc> serialises as RFC3339 via serde.
|
|
562
|
+
encode: "__SCAFFOLD_RUST_DATETIME_ENCODE__",
|
|
563
|
+
decode: "__SCAFFOLD_RUST_DATETIME_DECODE__",
|
|
564
|
+
imports: ["use chrono::{DateTime, Utc};"],
|
|
565
|
+
dep: { name: "chrono", version: "^0.4" },
|
|
566
|
+
mode: "lib"
|
|
567
|
+
},
|
|
568
|
+
int64: {
|
|
569
|
+
// serde_with DisplayFromStr for i64/u64.
|
|
570
|
+
encode: "__SCAFFOLD_RUST_INT64_ENCODE__",
|
|
571
|
+
decode: "__SCAFFOLD_RUST_INT64_DECODE__",
|
|
572
|
+
imports: ["use serde_with::DisplayFromStr;"],
|
|
573
|
+
dep: { name: "serde_with", version: "^3" },
|
|
574
|
+
mode: "lib"
|
|
575
|
+
},
|
|
576
|
+
decimal: {
|
|
577
|
+
encode: "__SCAFFOLD_RUST_DECIMAL_ENCODE__",
|
|
578
|
+
decode: "__SCAFFOLD_RUST_DECIMAL_DECODE__",
|
|
579
|
+
imports: ["use rust_decimal::Decimal;"],
|
|
580
|
+
dep: { name: "rust_decimal", version: "^1" },
|
|
581
|
+
mode: "lib"
|
|
582
|
+
},
|
|
583
|
+
byte: {
|
|
584
|
+
// serde_with Base64 attribute.
|
|
585
|
+
encode: "__SCAFFOLD_RUST_BYTE_ENCODE__",
|
|
586
|
+
decode: "__SCAFFOLD_RUST_BYTE_DECODE__",
|
|
587
|
+
imports: ["use serde_with::base64::Base64;"],
|
|
588
|
+
dep: { name: "serde_with", version: "^3" },
|
|
589
|
+
mode: "lib"
|
|
590
|
+
},
|
|
591
|
+
uuid: {
|
|
592
|
+
encode: "__SCAFFOLD_RUST_UUID_ENCODE__",
|
|
593
|
+
decode: "__SCAFFOLD_RUST_UUID_DECODE__",
|
|
594
|
+
imports: ["use uuid::Uuid;"],
|
|
595
|
+
dep: { name: "uuid", version: "^1" },
|
|
596
|
+
mode: "lib"
|
|
597
|
+
},
|
|
598
|
+
"number-special": {
|
|
599
|
+
encode: "__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__",
|
|
600
|
+
decode: "__SCAFFOLD_RUST_NUMSPECIAL_DECODE__",
|
|
601
|
+
mode: "native"
|
|
602
|
+
}
|
|
603
|
+
}, V = {
|
|
604
|
+
"date-time": {
|
|
605
|
+
// time.Time serialises as RFC3339Nano via MarshalJSON.
|
|
606
|
+
encode: "__SCAFFOLD_GO_DATETIME_ENCODE__",
|
|
607
|
+
decode: "__SCAFFOLD_GO_DATETIME_DECODE__",
|
|
608
|
+
imports: ['"time"'],
|
|
609
|
+
mode: "native"
|
|
610
|
+
},
|
|
611
|
+
int64: {
|
|
612
|
+
// struct tag `json:"x,string"` or math/big for arbitrary precision.
|
|
613
|
+
encode: "__SCAFFOLD_GO_INT64_ENCODE__",
|
|
614
|
+
decode: "__SCAFFOLD_GO_INT64_DECODE__",
|
|
615
|
+
imports: ['"strconv"'],
|
|
616
|
+
mode: "native"
|
|
617
|
+
},
|
|
618
|
+
decimal: {
|
|
619
|
+
encode: "__SCAFFOLD_GO_DECIMAL_ENCODE__",
|
|
620
|
+
decode: "__SCAFFOLD_GO_DECIMAL_DECODE__",
|
|
621
|
+
imports: ['"github.com/shopspring/decimal"'],
|
|
622
|
+
dep: { name: "github.com/shopspring/decimal", version: "v1" },
|
|
623
|
+
mode: "lib"
|
|
624
|
+
},
|
|
625
|
+
byte: {
|
|
626
|
+
// encoding/base64 — stdlib.
|
|
627
|
+
encode: "__SCAFFOLD_GO_BYTE_ENCODE__",
|
|
628
|
+
decode: "__SCAFFOLD_GO_BYTE_DECODE__",
|
|
629
|
+
imports: ['"encoding/base64"'],
|
|
630
|
+
mode: "native"
|
|
631
|
+
},
|
|
632
|
+
uuid: {
|
|
633
|
+
encode: "__SCAFFOLD_GO_UUID_ENCODE__",
|
|
634
|
+
decode: "__SCAFFOLD_GO_UUID_DECODE__",
|
|
635
|
+
imports: ['"github.com/google/uuid"'],
|
|
636
|
+
dep: { name: "github.com/google/uuid", version: "v1" },
|
|
637
|
+
mode: "lib"
|
|
638
|
+
},
|
|
639
|
+
"number-special": {
|
|
640
|
+
encode: "__SCAFFOLD_GO_NUMSPECIAL_ENCODE__",
|
|
641
|
+
decode: "__SCAFFOLD_GO_NUMSPECIAL_DECODE__",
|
|
642
|
+
mode: "native"
|
|
643
|
+
}
|
|
644
|
+
}, Y = {
|
|
645
|
+
"date-time": {
|
|
646
|
+
// Instant.toString() / Instant.parse() via jackson-datatype-jsr310.
|
|
647
|
+
encode: "__SCAFFOLD_JAVA_DATETIME_ENCODE__",
|
|
648
|
+
decode: "__SCAFFOLD_JAVA_DATETIME_DECODE__",
|
|
649
|
+
imports: ["import java.time.Instant;"],
|
|
650
|
+
dep: { name: "jackson-datatype-jsr310", version: "2.x" },
|
|
651
|
+
mode: "lib"
|
|
652
|
+
},
|
|
653
|
+
int64: {
|
|
654
|
+
// @JsonFormat(shape=STRING) on Long / BigInteger — stdlib Jackson.
|
|
655
|
+
encode: "__SCAFFOLD_JAVA_INT64_ENCODE__",
|
|
656
|
+
decode: "__SCAFFOLD_JAVA_INT64_DECODE__",
|
|
657
|
+
imports: ["import com.fasterxml.jackson.annotation.JsonFormat;"],
|
|
658
|
+
mode: "native"
|
|
659
|
+
},
|
|
660
|
+
decimal: {
|
|
661
|
+
// @JsonSerialize(using=ToStringSerializer) on BigDecimal — stdlib Jackson.
|
|
662
|
+
encode: "__SCAFFOLD_JAVA_DECIMAL_ENCODE__",
|
|
663
|
+
decode: "__SCAFFOLD_JAVA_DECIMAL_DECODE__",
|
|
664
|
+
imports: ["import java.math.BigDecimal;"],
|
|
665
|
+
mode: "native"
|
|
666
|
+
},
|
|
667
|
+
byte: {
|
|
668
|
+
// byte[] serialises as base64 by default in Jackson.
|
|
669
|
+
encode: "__SCAFFOLD_JAVA_BYTE_ENCODE__",
|
|
670
|
+
decode: "__SCAFFOLD_JAVA_BYTE_DECODE__",
|
|
671
|
+
mode: "native"
|
|
672
|
+
},
|
|
673
|
+
uuid: {
|
|
674
|
+
// UUID.toString() / UUID.fromString() — stdlib Java.
|
|
675
|
+
encode: "__SCAFFOLD_JAVA_UUID_ENCODE__",
|
|
676
|
+
decode: "__SCAFFOLD_JAVA_UUID_DECODE__",
|
|
677
|
+
imports: ["import java.util.UUID;"],
|
|
678
|
+
mode: "native"
|
|
679
|
+
},
|
|
680
|
+
"number-special": {
|
|
681
|
+
// Custom StdSerializer — stdlib Jackson.
|
|
682
|
+
encode: "__SCAFFOLD_JAVA_NUMSPECIAL_ENCODE__",
|
|
683
|
+
decode: "__SCAFFOLD_JAVA_NUMSPECIAL_DECODE__",
|
|
684
|
+
mode: "native"
|
|
685
|
+
}
|
|
686
|
+
}, y = Object.freeze({
|
|
687
|
+
typescript: B,
|
|
688
|
+
python: k,
|
|
689
|
+
rust: J,
|
|
690
|
+
go: V,
|
|
691
|
+
java: Y
|
|
692
|
+
});
|
|
693
|
+
function oe(e) {
|
|
694
|
+
return y[e];
|
|
695
|
+
}
|
|
696
|
+
function ne(e, o) {
|
|
697
|
+
const t = y[o], n = [];
|
|
698
|
+
for (const r of e) {
|
|
699
|
+
const d = t[r];
|
|
700
|
+
d != null && d.dep && n.push({ id: r, dep: d.dep });
|
|
701
|
+
}
|
|
702
|
+
return n;
|
|
703
|
+
}
|
|
704
|
+
function re() {
|
|
705
|
+
const e = y.typescript, o = {};
|
|
706
|
+
for (const t of T) {
|
|
707
|
+
const n = e[t].dep;
|
|
708
|
+
n && (o[t] = n);
|
|
709
|
+
}
|
|
710
|
+
return Object.freeze(o);
|
|
711
|
+
}
|
|
712
|
+
function ie(e, o) {
|
|
713
|
+
const t = o ?? y[e], n = [];
|
|
714
|
+
for (const r of T)
|
|
715
|
+
t[r] || n.push(r);
|
|
716
|
+
if (n.length > 0)
|
|
717
|
+
throw new Error(
|
|
718
|
+
`[hints] assertNoEmptyCells: language "${e}" is missing cells for: ${n.join(
|
|
719
|
+
", "
|
|
720
|
+
)}`
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
export {
|
|
724
|
+
T as CANONICAL_LOGICAL_TYPE_IDS,
|
|
725
|
+
g as CodecRegistryError,
|
|
726
|
+
l as ENVELOPE_KEY,
|
|
727
|
+
X as LOGICAL_TYPE_VERSION,
|
|
728
|
+
y as TEMPLATE_CELLS,
|
|
729
|
+
U as X_APIGEN_CODEC,
|
|
730
|
+
W as X_APIGEN_CTOR,
|
|
731
|
+
v as X_APIGEN_LOGICAL,
|
|
732
|
+
K as X_APIGEN_TOJSON,
|
|
733
|
+
ie as assertNoEmptyCells,
|
|
734
|
+
Q as buildTranscoder,
|
|
735
|
+
$ as byteCodec,
|
|
736
|
+
oe as cellsFor,
|
|
737
|
+
Z as codecIdOf,
|
|
738
|
+
z as createRegistry,
|
|
739
|
+
b as dateTimeCodec,
|
|
740
|
+
F as decimalCodec,
|
|
741
|
+
ne as depsForLogicalTypes,
|
|
742
|
+
N as int64Codec,
|
|
743
|
+
H as logicalKindOf,
|
|
744
|
+
ee as makeDecimal,
|
|
745
|
+
I as numberSpecialCodec,
|
|
746
|
+
te as registerWellKnown,
|
|
747
|
+
x as tryRegister,
|
|
748
|
+
re as tsDepMap,
|
|
749
|
+
L as uuidCodec,
|
|
750
|
+
q as validateSchemaRefs
|
|
751
|
+
};
|