@adhd/apigen-base-logical 0.1.1 → 0.1.3

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.mjs CHANGED
@@ -1,893 +1,863 @@
1
- const D = "$apigen";
2
- class C extends Error {
3
- constructor(r) {
4
- super(r), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
5
- }
1
+ //#region src/lib/contracts.ts
2
+ var e = "$apigen", t = class extends Error {
3
+ constructor(e) {
4
+ super(e), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
5
+ }
6
+ };
7
+ function n(e) {
8
+ e?.wellKnown;
9
+ let n = /* @__PURE__ */ new Map();
10
+ return {
11
+ register(e, r) {
12
+ if (n.has(e.id) && !r?.override) throw new t(`E_DUP_CODEC: a codec is already registered for id "${e.id}"`);
13
+ n.set(e.id, e);
14
+ },
15
+ resolve(e) {
16
+ for (let t of n.values()) if (t.matches(e)) return t;
17
+ },
18
+ get(e) {
19
+ return n.get(e);
20
+ },
21
+ ids() {
22
+ return [...n.keys()];
23
+ },
24
+ freeze() {
25
+ let e = new Map(n), r = {
26
+ register() {
27
+ throw new t("E_DUP_CODEC: registry is frozen and cannot accept new codecs");
28
+ },
29
+ resolve(t) {
30
+ for (let n of e.values()) if (n.matches(t)) return n;
31
+ },
32
+ get(t) {
33
+ return e.get(t);
34
+ },
35
+ ids() {
36
+ return [...e.keys()];
37
+ },
38
+ freeze() {
39
+ return r;
40
+ }
41
+ };
42
+ return r;
43
+ }
44
+ };
6
45
  }
7
- function x(e) {
8
- e == null || e.wellKnown;
9
- const r = /* @__PURE__ */ new Map();
10
- return {
11
- register(n, o) {
12
- if (r.has(n.id) && !(o != null && o.override))
13
- throw new C(
14
- `E_DUP_CODEC: a codec is already registered for id "${n.id}"`
15
- );
16
- r.set(n.id, n);
17
- },
18
- resolve(n) {
19
- for (const o of r.values())
20
- if (o.matches(n))
21
- return o;
22
- },
23
- get(n) {
24
- return r.get(n);
25
- },
26
- ids() {
27
- return [...r.keys()];
28
- },
29
- freeze() {
30
- const n = new Map(r), o = {
31
- register() {
32
- throw new C(
33
- "E_DUP_CODEC: registry is frozen and cannot accept new codecs"
34
- );
35
- },
36
- resolve(i) {
37
- for (const c of n.values())
38
- if (c.matches(i))
39
- return c;
40
- },
41
- get(i) {
42
- return n.get(i);
43
- },
44
- ids() {
45
- return [...n.keys()];
46
- },
47
- freeze() {
48
- return o;
49
- }
50
- };
51
- return o;
52
- }
53
- };
54
- }
55
- const R = "x-apigen-logical", P = "x-apigen-codec", ee = "x-apigen-ctor", te = "x-apigen-tojson", re = "0.1.0", M = [
56
- "scalar",
57
- "nominal",
58
- "union",
59
- "map",
60
- "set"
46
+ //#endregion
47
+ //#region src/lib/descriptor-ext.ts
48
+ var r = "x-apigen-logical", i = "x-apigen-codec", a = "x-apigen-ctor", o = "x-apigen-tojson", s = "0.1.0", c = [
49
+ "scalar",
50
+ "nominal",
51
+ "union",
52
+ "map",
53
+ "set"
61
54
  ];
62
- function ne(e) {
63
- const r = e[R];
64
- return typeof r == "string" && M.includes(r) ? r : void 0;
65
- }
66
- function oe(e) {
67
- const r = e[P];
68
- return typeof r == "string" ? r : void 0;
69
- }
70
- function h(e, r) {
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
- ...r
82
- };
83
- }
84
- function _(e, r, t) {
85
- const n = t.registry.resolve(r);
86
- if (n)
87
- return n.encode(e, r, t);
88
- const o = r.$ref;
89
- if (typeof o == "string") {
90
- const s = t.resolve(o);
91
- return _(e, s, t);
92
- }
93
- const i = r.oneOf;
94
- if (Array.isArray(i)) {
95
- const s = N(e, i, r);
96
- return _(e, s, t);
97
- }
98
- const c = r.type;
99
- if (c === "array") {
100
- if (!Array.isArray(e))
101
- return E(e, r, t);
102
- const s = r.items;
103
- if (!s)
104
- return e.map((a) => m(a));
105
- const u = t.path;
106
- return Array.isArray(s) ? e.map((a, f) => {
107
- const d = s[f];
108
- return d === void 0 ? m(a) : _(a, d, { ...t, path: `${u}/${f}` });
109
- }) : e.map(
110
- (a, f) => _(a, s, { ...t, path: `${u}/${f}` })
111
- );
112
- }
113
- if (c === "object") {
114
- if (e === null || typeof e != "object" || Array.isArray(e))
115
- return E(e, r, t);
116
- const s = r.properties;
117
- if (!s)
118
- return m(e);
119
- const u = t.path, a = {};
120
- for (const [f, d] of Object.entries(s)) {
121
- const p = e[f];
122
- p !== void 0 && (a[f] = _(p, d, {
123
- ...t,
124
- path: `${u}/${f}`
125
- }));
126
- }
127
- return a;
128
- }
129
- return c == null ? E(e, r, t) : m(e);
130
- }
131
- function l(e, r, t) {
132
- const n = t.registry.resolve(r);
133
- if (n)
134
- return n.decode(e, r, t);
135
- const o = r.$ref;
136
- if (typeof o == "string") {
137
- const s = t.resolve(o);
138
- return l(e, s, t);
139
- }
140
- const i = r.oneOf;
141
- if (Array.isArray(i)) {
142
- const s = N(e, i, r);
143
- return l(e, s, t);
144
- }
145
- const c = r.type;
146
- if (c === "array") {
147
- if (!Array.isArray(e))
148
- return e;
149
- const s = r.items;
150
- if (!s)
151
- return e;
152
- const u = t.path;
153
- return Array.isArray(s) ? e.map((a, f) => {
154
- const d = s[f];
155
- return d === void 0 ? a : l(a, d, { ...t, path: `${u}/${f}` });
156
- }) : e.map(
157
- (a, f) => l(a, s, { ...t, path: `${u}/${f}` })
158
- );
159
- }
160
- if (c === "object") {
161
- if (e === null || typeof e != "object" || Array.isArray(e))
162
- return e;
163
- const s = r.properties;
164
- if (!s)
165
- return e;
166
- const u = t.path, a = {};
167
- for (const [f, d] of Object.entries(s)) {
168
- const p = e[f];
169
- p !== void 0 && (a[f] = l(p, d, {
170
- ...t,
171
- path: `${u}/${f}`
172
- }));
173
- }
174
- return a;
175
- }
176
- return c == null ? k(e, t) : e;
177
- }
178
- function N(e, r, t, n) {
179
- const o = t.discriminator;
180
- if (o != null && o.propertyName) {
181
- const i = e !== null && typeof e == "object" ? e[o.propertyName] : void 0;
182
- if (typeof i == "string" && o.mapping) {
183
- const c = o.mapping[i];
184
- if (c) {
185
- const s = r.find((u) => u.$ref === c);
186
- if (s)
187
- return s;
188
- }
189
- }
190
- }
191
- return r[0] ?? {};
192
- }
193
- function E(e, r, t) {
194
- for (const n of t.registry.ids()) {
195
- const o = t.registry.get(n);
196
- if (o)
197
- try {
198
- const i = o.encode(e, o.schema, t);
199
- return { [D]: n, v: i };
200
- } catch {
201
- }
202
- }
203
- return m(e);
204
- }
205
- function k(e, r) {
206
- if (e !== null && typeof e == "object" && !Array.isArray(e) && D in e) {
207
- const t = e, n = t[D], o = r.registry.get(n);
208
- if (o)
209
- return o.decode(t.v, o.schema, r);
210
- }
211
- return e;
212
- }
213
- function m(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(m);
218
- if (typeof e == "object") {
219
- const r = {};
220
- for (const [t, n] of Object.entries(e))
221
- n !== void 0 && (r[t] = m(n));
222
- return r;
223
- }
224
- return null;
225
- }
226
- function ie(e, r) {
227
- const t = /* @__PURE__ */ new Set(), n = [e];
228
- for (; n.length > 0; ) {
229
- const o = n.pop();
230
- if (!o || t.has(o))
231
- continue;
232
- t.add(o);
233
- const i = o.$ref;
234
- if (typeof i == "string") {
235
- if (r) {
236
- const d = r[i];
237
- if (!d) {
238
- const p = Object.keys(r).join(", ") || "(none)";
239
- throw new Error(
240
- `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`
241
- );
242
- }
243
- n.push(d);
244
- }
245
- continue;
246
- }
247
- const c = o.oneOf;
248
- if (Array.isArray(c))
249
- for (const d of c)
250
- typeof d == "object" && d !== null && n.push(d);
251
- const s = o.properties;
252
- if (s)
253
- for (const d of Object.values(s))
254
- n.push(d);
255
- const u = o.items;
256
- if (Array.isArray(u))
257
- for (const d of u)
258
- typeof d == "object" && d !== null && n.push(d);
259
- else
260
- typeof u == "object" && u !== null && n.push(u);
261
- const a = o.additionalProperties;
262
- typeof a == "object" && a !== null && n.push(a);
263
- const f = o.propertyNames;
264
- typeof f == "object" && f !== null && n.push(f);
265
- }
266
- }
267
- function se(e) {
268
- return {
269
- encode(r, t, n) {
270
- const o = h(e, n);
271
- return _(r, t, o);
272
- },
273
- decode(r, t, n) {
274
- const o = h(e, n);
275
- return l(r, t, o);
276
- }
277
- };
278
- }
279
- function ce(e, r, t) {
280
- try {
281
- const n = t();
282
- e.register(n);
283
- } catch (n) {
284
- if (G(n))
285
- return;
286
- throw n;
287
- }
55
+ function l(e) {
56
+ let t = e[r];
57
+ return typeof t == "string" && c.includes(t) ? t : void 0;
288
58
  }
289
- function G(e) {
290
- return e === null || typeof e != "object" ? !1 : e.code === "MODULE_NOT_FOUND";
291
- }
292
- const v = {
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, r, t) {
300
- return e.toISOString();
301
- },
302
- decode(e, r, 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
- }, I = {
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, r, t) {
324
- return String(e);
325
- },
326
- decode(e, r, 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
- }
59
+ function u(e) {
60
+ let t = e[i];
61
+ return typeof t == "string" ? t : void 0;
62
+ }
63
+ //#endregion
64
+ //#region src/lib/runmode.ts
65
+ function d(e, t) {
66
+ return {
67
+ registry: e,
68
+ resolve: (e) => {
69
+ throw Error(`[apigen-logical] $ref "${e}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`);
70
+ },
71
+ seen: /* @__PURE__ */ new WeakSet(),
72
+ path: "",
73
+ mode: "strict",
74
+ ...t
75
+ };
76
+ }
77
+ function f(e, t, n) {
78
+ let r = n.registry.resolve(t);
79
+ if (r) return r.encode(e, t, n);
80
+ let i = t.$ref;
81
+ if (typeof i == "string") return f(e, n.resolve(i), n);
82
+ let a = t.oneOf;
83
+ if (Array.isArray(a)) return f(e, m(e, a, t, n), n);
84
+ let o = t.type;
85
+ if (o === "array") {
86
+ if (!Array.isArray(e)) return b(e, t, n);
87
+ let r = t.items;
88
+ if (!r) return e.map((e) => C(e));
89
+ let i = n.path;
90
+ return Array.isArray(r) ? e.map((e, t) => {
91
+ let a = r[t];
92
+ return a === void 0 ? C(e) : f(e, a, {
93
+ ...n,
94
+ path: `${i}/${t}`
95
+ });
96
+ }) : e.map((e, t) => f(e, r, {
97
+ ...n,
98
+ path: `${i}/${t}`
99
+ }));
100
+ }
101
+ if (o === "object") {
102
+ if (typeof e != "object" || !e || Array.isArray(e)) return b(e, t, n);
103
+ let r = t.properties;
104
+ if (!r) return C(e);
105
+ let i = n.path, a = {};
106
+ for (let [t, o] of Object.entries(r)) {
107
+ let r = e[t];
108
+ r !== void 0 && (a[t] = f(r, o, {
109
+ ...n,
110
+ path: `${i}/${t}`
111
+ }));
112
+ }
113
+ return a;
114
+ }
115
+ return o == null ? b(e, t, n) : C(e);
116
+ }
117
+ function p(e, t, n) {
118
+ let r = n.registry.resolve(t);
119
+ if (r) return r.decode(e, t, n);
120
+ let i = t.$ref;
121
+ if (typeof i == "string") return p(e, n.resolve(i), n);
122
+ let a = t.oneOf;
123
+ if (Array.isArray(a)) return p(e, m(e, a, t, n), n);
124
+ let o = t.type;
125
+ if (o === "array") {
126
+ if (!Array.isArray(e)) return e;
127
+ let r = t.items;
128
+ if (!r) return e;
129
+ let i = n.path;
130
+ return Array.isArray(r) ? e.map((e, t) => {
131
+ let a = r[t];
132
+ return a === void 0 ? e : p(e, a, {
133
+ ...n,
134
+ path: `${i}/${t}`
135
+ });
136
+ }) : e.map((e, t) => p(e, r, {
137
+ ...n,
138
+ path: `${i}/${t}`
139
+ }));
140
+ }
141
+ if (o === "object") {
142
+ if (typeof e != "object" || !e || Array.isArray(e)) return e;
143
+ let r = t.properties;
144
+ if (!r) return e;
145
+ let i = n.path, a = {};
146
+ for (let [t, o] of Object.entries(r)) {
147
+ let r = e[t];
148
+ r !== void 0 && (a[t] = p(r, o, {
149
+ ...n,
150
+ path: `${i}/${t}`
151
+ }));
152
+ }
153
+ for (let [t, n] of Object.entries(e)) !(t in r) && n !== void 0 && (a[t] = n);
154
+ return a;
155
+ }
156
+ return o == null ? S(e, n) : e;
157
+ }
158
+ function m(e, t, n, r) {
159
+ let i = n.discriminator;
160
+ if (i?.propertyName) {
161
+ let n = i.propertyName, a = typeof e == "object" && e ? e[n] : void 0;
162
+ if (typeof a == "string") {
163
+ if (i.mapping) {
164
+ let e = i.mapping[a];
165
+ if (e) {
166
+ let n = t.find((t) => t.$ref === e);
167
+ if (n) return n;
168
+ }
169
+ }
170
+ for (let e of t) {
171
+ let t = h(e, r).properties?.[n];
172
+ if (!t) continue;
173
+ let i = t.enum;
174
+ if (t.const === a || Array.isArray(i) && i.includes(a)) return e;
175
+ }
176
+ }
177
+ }
178
+ let a = _(e, t, r);
179
+ if (a) return a;
180
+ let o, s = -1;
181
+ for (let n of t) {
182
+ let t = y(e, h(n, r), r);
183
+ t !== null && t > s && (s = t, o = n);
184
+ }
185
+ return o === void 0 ? t[0] ?? {} : o;
186
+ }
187
+ function h(e, t) {
188
+ let n = e.$ref;
189
+ return typeof n == "string" ? t.resolve(n) : e;
190
+ }
191
+ function g(e) {
192
+ if ("const" in e) return e.const;
193
+ let t = e.enum;
194
+ if (Array.isArray(t) && t.length === 1) return t[0];
195
+ }
196
+ function _(e, t, n) {
197
+ if (typeof e != "object" || !e || Array.isArray(e)) return;
198
+ let r = e, i = t.map((e) => h(e, n)), a = /* @__PURE__ */ new Set();
199
+ for (let e of i) {
200
+ let t = e.properties;
201
+ if (t) for (let [e, n] of Object.entries(t)) g(n) !== void 0 && a.add(e);
202
+ }
203
+ for (let o of a) {
204
+ let a = i.map((e) => {
205
+ let t = e.properties?.[o];
206
+ return t ? g(t) : void 0;
207
+ }), s = a.filter((e) => e !== void 0), c = new Set(s);
208
+ if (s.length < 2 || c.size !== s.length) continue;
209
+ let l = r[o];
210
+ if (l === void 0) continue;
211
+ let u = a.findIndex((e) => e === l);
212
+ if (u !== -1 && y(e, i[u], n) !== null) return t[u];
213
+ }
214
+ }
215
+ function v(e) {
216
+ if (e === null) return "null";
217
+ if (Array.isArray(e)) return "array";
218
+ let t = typeof e;
219
+ return t === "number" ? Number.isInteger(e) ? "integer" : "number" : t;
220
+ }
221
+ function y(e, t, n) {
222
+ let r = t.oneOf;
223
+ if (Array.isArray(r)) {
224
+ let t = null;
225
+ for (let i of r) {
226
+ let r = y(e, h(i, n), n);
227
+ r !== null && (t === null || r > t) && (t = r);
228
+ }
229
+ return t;
230
+ }
231
+ let i = t.type, a = v(e);
232
+ if (typeof i == "string") {
233
+ if (!(i === a || i === "number" && a === "integer")) return null;
234
+ } else if (Array.isArray(i) && !i.some((e) => e === a || e === "number" && a === "integer")) return null;
235
+ if (typeof e != "object" || !e || Array.isArray(e)) return +(typeof i == "string");
236
+ let o = e, s = t.required, c = 0;
237
+ if (Array.isArray(s)) {
238
+ for (let e of s) if (typeof e == "string") {
239
+ if (o[e] === void 0) return null;
240
+ c += 2;
241
+ }
242
+ }
243
+ let l = t.properties;
244
+ if (l) {
245
+ for (let e of Object.keys(l)) o[e] !== void 0 && (c += 1);
246
+ for (let e of Object.keys(o)) l[e] === void 0 && --c;
247
+ }
248
+ return c;
249
+ }
250
+ function b(t, n, r) {
251
+ for (let n of r.registry.ids()) {
252
+ let i = r.registry.get(n);
253
+ if (i?.ownsValue?.(t)) return {
254
+ [e]: n,
255
+ v: i.encode(t, i.schema, r)
256
+ };
257
+ }
258
+ if (Array.isArray(t)) return t.map((e) => b(e, {}, r));
259
+ if (x(t)) {
260
+ let e = {};
261
+ for (let [n, i] of Object.entries(t)) i !== void 0 && (e[n] = b(i, {}, r));
262
+ return e;
263
+ }
264
+ return C(t);
265
+ }
266
+ function x(e) {
267
+ if (typeof e != "object" || !e || Array.isArray(e)) return !1;
268
+ let t = Object.getPrototypeOf(e);
269
+ return t === Object.prototype || t === null;
270
+ }
271
+ function S(t, n) {
272
+ if (typeof t == "object" && t && !Array.isArray(t) && "$apigen" in t) {
273
+ let r = t, i = r[e], a = n.registry.get(i);
274
+ if (a) return a.decode(r.v, a.schema, n);
275
+ }
276
+ if (Array.isArray(t)) return t.map((e) => S(e, n));
277
+ if (x(t)) {
278
+ let e = {};
279
+ for (let [r, i] of Object.entries(t)) e[r] = S(i, n);
280
+ return e;
281
+ }
282
+ return t;
283
+ }
284
+ function C(e) {
285
+ if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean") return e;
286
+ if (Array.isArray(e)) return e.map(C);
287
+ if (typeof e == "object") {
288
+ let t = {};
289
+ for (let [n, r] of Object.entries(e)) r !== void 0 && (t[n] = C(r));
290
+ return t;
291
+ }
292
+ return null;
293
+ }
294
+ function w(e, t) {
295
+ let n = /* @__PURE__ */ new Set(), r = [e];
296
+ for (; r.length > 0;) {
297
+ let e = r.pop();
298
+ if (!e || n.has(e)) continue;
299
+ n.add(e);
300
+ let i = e.$ref;
301
+ if (typeof i == "string") {
302
+ if (t) {
303
+ let e = t[i];
304
+ if (!e) {
305
+ let e = Object.keys(t).join(", ") || "(none)";
306
+ throw Error(`[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${e}`);
307
+ }
308
+ r.push(e);
309
+ }
310
+ continue;
311
+ }
312
+ let a = e.oneOf;
313
+ if (Array.isArray(a)) for (let e of a) typeof e == "object" && e && r.push(e);
314
+ let o = e.properties;
315
+ if (o) for (let e of Object.values(o)) r.push(e);
316
+ let s = e.items;
317
+ if (Array.isArray(s)) for (let e of s) typeof e == "object" && e && r.push(e);
318
+ else typeof s == "object" && s && r.push(s);
319
+ let c = e.additionalProperties;
320
+ typeof c == "object" && c && r.push(c);
321
+ let l = e.propertyNames;
322
+ typeof l == "object" && l && r.push(l);
323
+ }
324
+ }
325
+ function T(e) {
326
+ return {
327
+ encode(t, n, r) {
328
+ return f(t, n, d(e, r));
329
+ },
330
+ decode(t, n, r) {
331
+ return p(t, n, d(e, r));
332
+ }
333
+ };
334
+ }
335
+ function E(e, t, n) {
336
+ try {
337
+ let t = n();
338
+ e.register(t);
339
+ } catch (e) {
340
+ if (D(e)) return;
341
+ throw e;
342
+ }
343
+ }
344
+ function D(e) {
345
+ return typeof e != "object" || !e ? !1 : e.code === "MODULE_NOT_FOUND";
346
+ }
347
+ //#endregion
348
+ //#region src/lib/codecs/date-time.ts
349
+ var O = {
350
+ id: "date-time",
351
+ kind: "scalar",
352
+ schema: {
353
+ type: "string",
354
+ format: "date-time"
355
+ },
356
+ matches(e) {
357
+ return e.type === "string" && e.format === "date-time";
358
+ },
359
+ ownsValue(e) {
360
+ return e instanceof Date;
361
+ },
362
+ encode(e, t, n) {
363
+ return e.toISOString();
364
+ },
365
+ decode(e, t, n) {
366
+ if (typeof e != "string") {
367
+ if (n.mode === "strict") throw TypeError(`[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`);
368
+ return new Date(String(e));
369
+ }
370
+ if (n.mode === "strict" && Number.isNaN(new Date(e).getTime())) throw TypeError(`[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`);
371
+ return new Date(e);
372
+ }
373
+ }, k = {
374
+ id: "int64",
375
+ kind: "scalar",
376
+ schema: {
377
+ type: "string",
378
+ format: "int64"
379
+ },
380
+ matches(e) {
381
+ return e.type === "string" && e.format === "int64";
382
+ },
383
+ ownsValue(e) {
384
+ return typeof e == "bigint";
385
+ },
386
+ encode(e, t, n) {
387
+ return String(e);
388
+ },
389
+ decode(e, t, n) {
390
+ if (typeof e != "string") {
391
+ if (n.mode === "strict") throw TypeError(`[int64] expected a string on the wire at "${n.path}", got ${typeof e}`);
392
+ try {
393
+ return BigInt(Math.trunc(Number(e)));
394
+ } catch {
395
+ return BigInt(0);
396
+ }
397
+ }
398
+ if (n.mode === "strict") return BigInt(e);
399
+ if (/^-?\d+$/.test(e)) try {
400
+ return BigInt(e);
401
+ } catch {
402
+ return BigInt(0);
403
+ }
404
+ return BigInt(0);
405
+ }
348
406
  };
349
- function de(e) {
350
- return e;
351
- }
352
- const T = {
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, r, t) {
360
- return e;
361
- },
362
- decode(e, r, 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
- }, F = {
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, r, t) {
384
- return Buffer.from(e).toString("base64");
385
- },
386
- decode(e, r, 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
- }, w = /^[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, r, t) {
408
- return e.toLowerCase();
409
- },
410
- decode(e, r, 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" && !w.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", b = "Infinity", S = "-Infinity", z = /* @__PURE__ */ new Set([
425
- O,
426
- b,
427
- S
428
- ]), U = {
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, r, t) {
436
- return Number.isNaN(e) ? O : e === 1 / 0 ? b : e === -1 / 0 ? S : e;
437
- },
438
- decode(e, r, t) {
439
- if (typeof e == "number")
440
- return e;
441
- if (typeof e == "string") {
442
- if (e === O)
443
- return NaN;
444
- if (e === b)
445
- return 1 / 0;
446
- if (e === S)
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 ${[...z].join(", ")}.`
455
- );
456
- return NaN;
457
- }
407
+ //#endregion
408
+ //#region src/lib/codecs/decimal.ts
409
+ function A(e) {
410
+ return e;
411
+ }
412
+ var j = {
413
+ id: "decimal",
414
+ kind: "scalar",
415
+ schema: {
416
+ type: "string",
417
+ format: "decimal"
418
+ },
419
+ matches(e) {
420
+ return e.type === "string" && e.format === "decimal";
421
+ },
422
+ encode(e, t, n) {
423
+ return e;
424
+ },
425
+ decode(e, t, n) {
426
+ if (typeof e != "string") {
427
+ if (n.mode === "strict") throw TypeError(`[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`);
428
+ return A(String(e));
429
+ }
430
+ if (n.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e)) throw TypeError(`[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`);
431
+ return A(e);
432
+ }
433
+ }, M = {
434
+ id: "byte",
435
+ kind: "scalar",
436
+ schema: {
437
+ type: "string",
438
+ format: "byte"
439
+ },
440
+ matches(e) {
441
+ return e.type === "string" && e.format === "byte";
442
+ },
443
+ ownsValue(e) {
444
+ return e instanceof Uint8Array;
445
+ },
446
+ encode(e, t, n) {
447
+ return Buffer.from(e).toString("base64");
448
+ },
449
+ decode(e, t, n) {
450
+ if (typeof e != "string") {
451
+ if (n.mode === "strict") throw TypeError(`[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`);
452
+ return /* @__PURE__ */ new Uint8Array();
453
+ }
454
+ if (n.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e)) throw TypeError(`[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`);
455
+ return new Uint8Array(Buffer.from(e, "base64"));
456
+ }
457
+ }, N = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, P = {
458
+ id: "uuid",
459
+ kind: "scalar",
460
+ schema: {
461
+ type: "string",
462
+ format: "uuid"
463
+ },
464
+ matches(e) {
465
+ return e.type === "string" && e.format === "uuid";
466
+ },
467
+ encode(e, t, n) {
468
+ return e.toLowerCase();
469
+ },
470
+ decode(e, t, n) {
471
+ if (typeof e != "string") {
472
+ if (n.mode === "strict") throw TypeError(`[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`);
473
+ return String(e).toLowerCase();
474
+ }
475
+ if (n.mode === "strict" && !N.test(e)) throw TypeError(`[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`);
476
+ return e;
477
+ }
478
+ }, F = "NaN", I = "Infinity", L = "-Infinity", R = /* @__PURE__ */ new Set([
479
+ F,
480
+ I,
481
+ L
482
+ ]), z = {
483
+ id: "number-special",
484
+ kind: "scalar",
485
+ schema: { type: "number" },
486
+ matches(e) {
487
+ return e.type === "number" && e.format === void 0;
488
+ },
489
+ ownsValue(e) {
490
+ return typeof e == "number" && !Number.isFinite(e);
491
+ },
492
+ encode(e, t, n) {
493
+ return Number.isNaN(e) ? F : e === Infinity ? I : e === -Infinity ? L : e;
494
+ },
495
+ decode(e, t, n) {
496
+ if (typeof e == "number") return e;
497
+ if (typeof e == "string") {
498
+ if (e === F) return NaN;
499
+ if (e === I) return Infinity;
500
+ if (e === L) return -Infinity;
501
+ let t = Number(e);
502
+ if (!Number.isNaN(t)) return t;
503
+ }
504
+ if (n.mode === "strict") throw TypeError(`[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...R].join(", ")}.`);
505
+ return NaN;
506
+ }
458
507
  }, B = [
459
- v,
460
- I,
461
- T,
462
- F,
463
- L,
464
- U
508
+ O,
509
+ k,
510
+ j,
511
+ M,
512
+ P,
513
+ z
465
514
  ];
466
- function ae(e, r = {}) {
467
- for (const t of B)
468
- e.register(t, { override: r.override ?? !1 });
469
- }
470
- const J = 12;
471
- function Y(e, r) {
472
- const t = /^#\/(definitions|\$defs)\/(.+)$/.exec(e);
473
- if (!t)
474
- return;
475
- const [, n, o] = t, i = n === "$defs" ? r.$defs : r.definitions;
476
- return i == null ? void 0 : i[decodeURIComponent(o)];
515
+ function V(e, t = {}) {
516
+ for (let n of B) e.register(n, { override: t.override ?? !1 });
477
517
  }
478
- function A(e) {
479
- return Array.isArray(e) && e.length > 0 ? e[0] : void 0;
518
+ //#endregion
519
+ //#region src/lib/example.ts
520
+ var H = 12;
521
+ function U(e, t) {
522
+ let n = /^#\/(definitions|\$defs)\/(.+)$/.exec(e);
523
+ if (!n) return;
524
+ let [, r, i] = n;
525
+ return (r === "$defs" ? t.$defs : t.definitions)?.[decodeURIComponent(i)];
480
526
  }
481
527
  function W(e) {
482
- if (Array.isArray(e.type))
483
- return e.type.find((r) => r !== "null") ?? e.type[0];
484
- if (typeof e.type == "string")
485
- return e.type;
486
- if (e.properties)
487
- return "object";
528
+ return Array.isArray(e) && e.length > 0 ? e[0] : void 0;
529
+ }
530
+ function G(e) {
531
+ if (Array.isArray(e.type)) return e.type.find((e) => e !== "null") ?? e.type[0];
532
+ if (typeof e.type == "string") return e.type;
533
+ if (e.properties) return "object";
488
534
  }
489
535
  function K(e) {
490
- switch (e.format) {
491
- case "date-time":
492
- return "1970-01-01T00:00:00.000Z";
493
- case "date":
494
- return "1970-01-01";
495
- case "time":
496
- return "00:00:00Z";
497
- case "uuid":
498
- return "00000000-0000-0000-0000-000000000000";
499
- case "email":
500
- return "user@example.com";
501
- case "uri":
502
- case "url":
503
- case "uri-reference":
504
- return "https://example.com";
505
- case "hostname":
506
- return "example.com";
507
- case "ipv4":
508
- return "127.0.0.1";
509
- case "ipv6":
510
- return "::1";
511
- case "decimal":
512
- return "0";
513
- case "int64":
514
- return "0";
515
- case "byte":
516
- return "";
517
- default:
518
- return "<string>";
519
- }
520
- }
521
- function $(e, r, t) {
522
- const n = e.properties ?? {}, o = e.required ?? [], i = {};
523
- for (const c of o) {
524
- const s = n[c];
525
- i[c] = s !== void 0 ? y(s, r, t + 1) : `<${c}>`;
526
- }
527
- return i;
528
- }
529
- function q(e, r, t) {
530
- const n = Array.isArray(e.items) ? e.items[0] : e.items;
531
- return n ? [y(n, r, t + 1)] : [];
532
- }
533
- function y(e, r = e ?? {}, t = 0) {
534
- if (!e || t > J)
535
- return null;
536
- if (typeof e.$ref == "string") {
537
- const i = Y(e.$ref, r);
538
- return i !== void 0 ? y(i, r, t + 1) : null;
539
- }
540
- if (e.const !== void 0)
541
- return e.const;
542
- if (Array.isArray(e.enum) && e.enum.length > 0)
543
- return e.enum[0];
544
- if (Array.isArray(e.allOf) && e.allOf.length > 0) {
545
- const i = {}, c = [];
546
- for (const s of e.allOf) {
547
- Object.assign(i, s.properties ?? {});
548
- for (const u of s.required ?? [])
549
- c.includes(u) || c.push(u);
550
- }
551
- return $(
552
- { ...e, properties: i, required: c },
553
- r,
554
- t
555
- );
556
- }
557
- const n = A(e.oneOf) ?? A(e.anyOf);
558
- if (n)
559
- return y(n, r, t + 1);
560
- switch (W(e)) {
561
- case "object":
562
- return $(e, r, t);
563
- case "array":
564
- return q(e, r, t);
565
- case "string":
566
- return K(e);
567
- case "integer":
568
- case "number":
569
- return 0;
570
- case "boolean":
571
- return !1;
572
- case "null":
573
- return null;
574
- default:
575
- return null;
576
- }
577
- }
578
- function fe(e) {
579
- if (!e)
580
- return;
581
- const r = y(e);
582
- return `Example: ${JSON.stringify(r)}`;
583
- }
584
- const j = [
585
- v.id,
586
- // 'date-time'
587
- I.id,
588
- // 'int64'
589
- T.id,
590
- // 'decimal'
591
- F.id,
592
- // 'byte'
593
- L.id,
594
- // 'uuid'
595
- U.id
596
- // 'number-special'
597
- ], X = {
598
- "date-time": {
599
- encode: "$.toISOString()",
600
- decode: "new Date($)",
601
- mode: "native"
602
- },
603
- int64: {
604
- encode: "String($)",
605
- decode: "BigInt($)",
606
- mode: "native"
607
- },
608
- decimal: {
609
- // Default: branded string (zero-dep); opt-in to decimal.js for arithmetic.
610
- // DESIGN §13.2 branded row / §18 resolved: mode:'branded', dep declared so
611
- // generators can optionally inject it; consumers that never use Decimal
612
- // never install it (§14.2).
613
- encode: "$.toString()",
614
- decode: "new Decimal($)",
615
- imports: [],
616
- dep: { name: "decimal.js", version: "^10" },
617
- mode: "branded"
618
- },
619
- byte: {
620
- encode: "Buffer.from($).toString('base64')",
621
- decode: "new Uint8Array(Buffer.from($, 'base64'))",
622
- mode: "native"
623
- },
624
- uuid: {
625
- // UUID is a plain string in TS; encode normalises to lowercase.
626
- encode: "$.toLowerCase()",
627
- decode: "$",
628
- mode: "native"
629
- },
630
- "number-special": {
631
- // numToWire / wireToNum are stdlib helpers emitted inline by the engine.
632
- encode: "numToWire($)",
633
- decode: "wireToNum($)",
634
- mode: "native"
635
- }
636
- }, V = {
637
- "date-time": {
638
- encode: "$.isoformat()",
639
- decode: "datetime.fromisoformat($)",
640
- imports: ["from datetime import datetime"],
641
- mode: "native"
642
- },
643
- int64: {
644
- encode: "str($)",
645
- decode: "int($)",
646
- mode: "native"
647
- },
648
- decimal: {
649
- encode: "str($)",
650
- decode: "Decimal($)",
651
- imports: ["from decimal import Decimal"],
652
- mode: "native"
653
- },
654
- byte: {
655
- encode: "b64encode($).decode()",
656
- decode: "b64decode($)",
657
- imports: ["from base64 import b64encode, b64decode"],
658
- mode: "native"
659
- },
660
- uuid: {
661
- encode: "str($)",
662
- decode: "UUID($)",
663
- imports: ["from uuid import UUID"],
664
- mode: "native"
665
- },
666
- "number-special": {
667
- // Python json.dumps maps float('nan')/float('inf') to null by default;
668
- // the codec overrides with string sentinels (same as TS).
669
- encode: "num_to_wire($)",
670
- decode: "wire_to_num($)",
671
- mode: "native"
672
- }
673
- }, Z = {
674
- "date-time": {
675
- // chrono::DateTime<Utc> serialises as RFC3339 via serde.
676
- encode: "__SCAFFOLD_RUST_DATETIME_ENCODE__",
677
- decode: "__SCAFFOLD_RUST_DATETIME_DECODE__",
678
- imports: ["use chrono::{DateTime, Utc};"],
679
- dep: { name: "chrono", version: "^0.4" },
680
- mode: "lib"
681
- },
682
- int64: {
683
- // serde_with DisplayFromStr for i64/u64.
684
- encode: "__SCAFFOLD_RUST_INT64_ENCODE__",
685
- decode: "__SCAFFOLD_RUST_INT64_DECODE__",
686
- imports: ["use serde_with::DisplayFromStr;"],
687
- dep: { name: "serde_with", version: "^3" },
688
- mode: "lib"
689
- },
690
- decimal: {
691
- encode: "__SCAFFOLD_RUST_DECIMAL_ENCODE__",
692
- decode: "__SCAFFOLD_RUST_DECIMAL_DECODE__",
693
- imports: ["use rust_decimal::Decimal;"],
694
- dep: { name: "rust_decimal", version: "^1" },
695
- mode: "lib"
696
- },
697
- byte: {
698
- // serde_with Base64 attribute.
699
- encode: "__SCAFFOLD_RUST_BYTE_ENCODE__",
700
- decode: "__SCAFFOLD_RUST_BYTE_DECODE__",
701
- imports: ["use serde_with::base64::Base64;"],
702
- dep: { name: "serde_with", version: "^3" },
703
- mode: "lib"
704
- },
705
- uuid: {
706
- encode: "__SCAFFOLD_RUST_UUID_ENCODE__",
707
- decode: "__SCAFFOLD_RUST_UUID_DECODE__",
708
- imports: ["use uuid::Uuid;"],
709
- dep: { name: "uuid", version: "^1" },
710
- mode: "lib"
711
- },
712
- "number-special": {
713
- encode: "__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__",
714
- decode: "__SCAFFOLD_RUST_NUMSPECIAL_DECODE__",
715
- mode: "native"
716
- }
717
- }, H = {
718
- "date-time": {
719
- // time.Time serialises as RFC3339Nano via MarshalJSON.
720
- encode: "__SCAFFOLD_GO_DATETIME_ENCODE__",
721
- decode: "__SCAFFOLD_GO_DATETIME_DECODE__",
722
- imports: ['"time"'],
723
- mode: "native"
724
- },
725
- int64: {
726
- // struct tag `json:"x,string"` or math/big for arbitrary precision.
727
- encode: "__SCAFFOLD_GO_INT64_ENCODE__",
728
- decode: "__SCAFFOLD_GO_INT64_DECODE__",
729
- imports: ['"strconv"'],
730
- mode: "native"
731
- },
732
- decimal: {
733
- encode: "__SCAFFOLD_GO_DECIMAL_ENCODE__",
734
- decode: "__SCAFFOLD_GO_DECIMAL_DECODE__",
735
- imports: ['"github.com/shopspring/decimal"'],
736
- dep: { name: "github.com/shopspring/decimal", version: "v1" },
737
- mode: "lib"
738
- },
739
- byte: {
740
- // encoding/base64 — stdlib.
741
- encode: "__SCAFFOLD_GO_BYTE_ENCODE__",
742
- decode: "__SCAFFOLD_GO_BYTE_DECODE__",
743
- imports: ['"encoding/base64"'],
744
- mode: "native"
745
- },
746
- uuid: {
747
- encode: "__SCAFFOLD_GO_UUID_ENCODE__",
748
- decode: "__SCAFFOLD_GO_UUID_DECODE__",
749
- imports: ['"github.com/google/uuid"'],
750
- dep: { name: "github.com/google/uuid", version: "v1" },
751
- mode: "lib"
752
- },
753
- "number-special": {
754
- encode: "__SCAFFOLD_GO_NUMSPECIAL_ENCODE__",
755
- decode: "__SCAFFOLD_GO_NUMSPECIAL_DECODE__",
756
- mode: "native"
757
- }
758
- }, Q = {
759
- "date-time": {
760
- // Instant.toString() (RFC-3339/ISO-8601, UTC) / Instant.parse($) — the
761
- // jackson-datatype-jsr310 module is registered on the shared ObjectMapper
762
- // so java.time.Instant fields round-trip automatically, but the
763
- // dispatcher-woven glue (which builds/reads JsonNode by hand rather than
764
- // going through a field-annotated POJO) uses these expressions directly.
765
- encode: "$.toString()",
766
- decode: "Instant.parse($)",
767
- imports: ["import java.time.Instant;"],
768
- dep: { name: "jackson-datatype-jsr310", version: "2.x" },
769
- mode: "lib"
770
- },
771
- int64: {
772
- // Declarative, not expression-shaped: Jackson field annotation forces
773
- // Long/long to serialise as a JSON string (avoids precision loss in
774
- // JS/JSON-number consumers). mode:'native' — the "encode"/"decode"
775
- // values below ARE the annotation text (identical on both sides; Jackson
776
- // applies it symmetrically), not a `$`-substituted call expression.
777
- encode: "@JsonFormat(shape = JsonFormat.Shape.STRING)",
778
- decode: "@JsonFormat(shape = JsonFormat.Shape.STRING)",
779
- imports: ["import com.fasterxml.jackson.annotation.JsonFormat;"],
780
- mode: "native"
781
- },
782
- decimal: {
783
- // Encode is declarative (field annotation forces BigDecimal -> JSON
784
- // string via Jackson's stdlib ToStringSerializer, so scale/precision
785
- // survive the wire); decode is a plain expression since BigDecimal has
786
- // no matching stdlib deserializer-by-annotation for "parse from string".
787
- encode: "@JsonSerialize(using = ToStringSerializer.class)",
788
- decode: "new BigDecimal($)",
789
- imports: [
790
- "import java.math.BigDecimal;",
791
- "import com.fasterxml.jackson.databind.annotation.JsonSerialize;",
792
- "import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;"
793
- ],
794
- mode: "native"
795
- },
796
- byte: {
797
- // byte[] <-> base64 String is Jackson's built-in default codec — no
798
- // annotation, no wrapping expression. The dispatcher glue passes the
799
- // value through unchanged; Jackson's ObjectMapper performs the base64
800
- // transcoding when the JsonNode tree is built/read.
801
- encode: "$",
802
- decode: "$",
803
- mode: "native"
804
- },
805
- uuid: {
806
- // UUID.toString() / UUID.fromString($) — stdlib Java, no Jackson module.
807
- encode: "$.toString()",
808
- decode: "UUID.fromString($)",
809
- imports: ["import java.util.UUID;"],
810
- mode: "native"
811
- },
812
- "number-special": {
813
- // NaN/Infinity/-Infinity have no native JSON representation; mirrors the
814
- // TS numToWire/wireToNum inline helpers with a small custom Jackson
815
- // StdSerializer/StdDeserializer pair, generated inline by
816
- // renderDispatcherJava (class names below are the fixed contract the
817
- // generator emits — apigen-plugin-java-javalin/src/lib/dispatcher-template.ts).
818
- encode: "@JsonSerialize(using = NumberSpecialSerializer.class)",
819
- decode: "@JsonDeserialize(using = NumberSpecialDeserializer.class)",
820
- imports: [
821
- "import com.fasterxml.jackson.databind.annotation.JsonSerialize;",
822
- "import com.fasterxml.jackson.databind.annotation.JsonDeserialize;"
823
- ],
824
- mode: "native"
825
- }
826
- }, g = Object.freeze({
827
- typescript: X,
828
- python: V,
829
- rust: Z,
830
- go: H,
831
- java: Q
536
+ switch (e.format) {
537
+ case "date-time": return "1970-01-01T00:00:00.000Z";
538
+ case "date": return "1970-01-01";
539
+ case "time": return "00:00:00Z";
540
+ case "uuid": return "00000000-0000-0000-0000-000000000000";
541
+ case "email": return "user@example.com";
542
+ case "uri":
543
+ case "url":
544
+ case "uri-reference": return "https://example.com";
545
+ case "hostname": return "example.com";
546
+ case "ipv4": return "127.0.0.1";
547
+ case "ipv6": return "::1";
548
+ case "decimal": return "0";
549
+ case "int64": return "0";
550
+ case "byte": return "";
551
+ default: return "<string>";
552
+ }
553
+ }
554
+ function q(e, t, n) {
555
+ let r = e.properties ?? {}, i = e.required ?? [], a = {};
556
+ for (let e of i) {
557
+ let i = r[e];
558
+ a[e] = i === void 0 ? `<${e}>` : Y(i, t, n + 1);
559
+ }
560
+ return a;
561
+ }
562
+ function J(e, t, n) {
563
+ let r = Array.isArray(e.items) ? e.items[0] : e.items;
564
+ return r ? [Y(r, t, n + 1)] : [];
565
+ }
566
+ function Y(e, t = e ?? {}, n = 0) {
567
+ if (!e || n > H) return null;
568
+ if (typeof e.$ref == "string") {
569
+ let r = U(e.$ref, t);
570
+ return r === void 0 ? null : Y(r, t, n + 1);
571
+ }
572
+ if (e.const !== void 0) return e.const;
573
+ if (Array.isArray(e.enum) && e.enum.length > 0) return e.enum[0];
574
+ if (Array.isArray(e.allOf) && e.allOf.length > 0) {
575
+ let r = {}, i = [];
576
+ for (let t of e.allOf) {
577
+ Object.assign(r, t.properties ?? {});
578
+ for (let e of t.required ?? []) i.includes(e) || i.push(e);
579
+ }
580
+ return q({
581
+ ...e,
582
+ properties: r,
583
+ required: i
584
+ }, t, n);
585
+ }
586
+ let r = W(e.oneOf) ?? W(e.anyOf);
587
+ if (r) return Y(r, t, n + 1);
588
+ switch (G(e)) {
589
+ case "object": return q(e, t, n);
590
+ case "array": return J(e, t, n);
591
+ case "string": return K(e);
592
+ case "integer":
593
+ case "number": return 0;
594
+ case "boolean": return !1;
595
+ case "null": return null;
596
+ default: return null;
597
+ }
598
+ }
599
+ function X(e) {
600
+ if (!e) return;
601
+ let t = Y(e);
602
+ return `Example: ${JSON.stringify(t)}`;
603
+ }
604
+ //#endregion
605
+ //#region src/lib/hints.ts
606
+ var Z = [
607
+ O.id,
608
+ k.id,
609
+ j.id,
610
+ M.id,
611
+ P.id,
612
+ z.id
613
+ ], Q = Object.freeze({
614
+ typescript: {
615
+ "date-time": {
616
+ encode: "$.toISOString()",
617
+ decode: "new Date($)",
618
+ mode: "native"
619
+ },
620
+ int64: {
621
+ encode: "String($)",
622
+ decode: "BigInt($)",
623
+ mode: "native"
624
+ },
625
+ decimal: {
626
+ encode: "$.toString()",
627
+ decode: "new Decimal($)",
628
+ imports: [],
629
+ dep: {
630
+ name: "decimal.js",
631
+ version: "^10"
632
+ },
633
+ mode: "branded"
634
+ },
635
+ byte: {
636
+ encode: "Buffer.from($).toString('base64')",
637
+ decode: "new Uint8Array(Buffer.from($, 'base64'))",
638
+ mode: "native"
639
+ },
640
+ uuid: {
641
+ encode: "$.toLowerCase()",
642
+ decode: "$",
643
+ mode: "native"
644
+ },
645
+ "number-special": {
646
+ encode: "numToWire($)",
647
+ decode: "wireToNum($)",
648
+ mode: "native"
649
+ }
650
+ },
651
+ python: {
652
+ "date-time": {
653
+ encode: "$.isoformat()",
654
+ decode: "datetime.fromisoformat($)",
655
+ imports: ["from datetime import datetime"],
656
+ mode: "native"
657
+ },
658
+ int64: {
659
+ encode: "str($)",
660
+ decode: "int($)",
661
+ mode: "native"
662
+ },
663
+ decimal: {
664
+ encode: "str($)",
665
+ decode: "Decimal($)",
666
+ imports: ["from decimal import Decimal"],
667
+ mode: "native"
668
+ },
669
+ byte: {
670
+ encode: "b64encode($).decode()",
671
+ decode: "b64decode($)",
672
+ imports: ["from base64 import b64encode, b64decode"],
673
+ mode: "native"
674
+ },
675
+ uuid: {
676
+ encode: "str($)",
677
+ decode: "UUID($)",
678
+ imports: ["from uuid import UUID"],
679
+ mode: "native"
680
+ },
681
+ "number-special": {
682
+ encode: "num_to_wire($)",
683
+ decode: "wire_to_num($)",
684
+ mode: "native"
685
+ }
686
+ },
687
+ rust: {
688
+ "date-time": {
689
+ encode: "__SCAFFOLD_RUST_DATETIME_ENCODE__",
690
+ decode: "__SCAFFOLD_RUST_DATETIME_DECODE__",
691
+ imports: ["use chrono::{DateTime, Utc};"],
692
+ dep: {
693
+ name: "chrono",
694
+ version: "^0.4"
695
+ },
696
+ mode: "lib"
697
+ },
698
+ int64: {
699
+ encode: "__SCAFFOLD_RUST_INT64_ENCODE__",
700
+ decode: "__SCAFFOLD_RUST_INT64_DECODE__",
701
+ imports: ["use serde_with::DisplayFromStr;"],
702
+ dep: {
703
+ name: "serde_with",
704
+ version: "^3"
705
+ },
706
+ mode: "lib"
707
+ },
708
+ decimal: {
709
+ encode: "__SCAFFOLD_RUST_DECIMAL_ENCODE__",
710
+ decode: "__SCAFFOLD_RUST_DECIMAL_DECODE__",
711
+ imports: ["use rust_decimal::Decimal;"],
712
+ dep: {
713
+ name: "rust_decimal",
714
+ version: "^1"
715
+ },
716
+ mode: "lib"
717
+ },
718
+ byte: {
719
+ encode: "__SCAFFOLD_RUST_BYTE_ENCODE__",
720
+ decode: "__SCAFFOLD_RUST_BYTE_DECODE__",
721
+ imports: ["use serde_with::base64::Base64;"],
722
+ dep: {
723
+ name: "serde_with",
724
+ version: "^3"
725
+ },
726
+ mode: "lib"
727
+ },
728
+ uuid: {
729
+ encode: "__SCAFFOLD_RUST_UUID_ENCODE__",
730
+ decode: "__SCAFFOLD_RUST_UUID_DECODE__",
731
+ imports: ["use uuid::Uuid;"],
732
+ dep: {
733
+ name: "uuid",
734
+ version: "^1"
735
+ },
736
+ mode: "lib"
737
+ },
738
+ "number-special": {
739
+ encode: "__SCAFFOLD_RUST_NUMSPECIAL_ENCODE__",
740
+ decode: "__SCAFFOLD_RUST_NUMSPECIAL_DECODE__",
741
+ mode: "native"
742
+ }
743
+ },
744
+ go: {
745
+ "date-time": {
746
+ encode: "__SCAFFOLD_GO_DATETIME_ENCODE__",
747
+ decode: "__SCAFFOLD_GO_DATETIME_DECODE__",
748
+ imports: ["\"time\""],
749
+ mode: "native"
750
+ },
751
+ int64: {
752
+ encode: "__SCAFFOLD_GO_INT64_ENCODE__",
753
+ decode: "__SCAFFOLD_GO_INT64_DECODE__",
754
+ imports: ["\"strconv\""],
755
+ mode: "native"
756
+ },
757
+ decimal: {
758
+ encode: "__SCAFFOLD_GO_DECIMAL_ENCODE__",
759
+ decode: "__SCAFFOLD_GO_DECIMAL_DECODE__",
760
+ imports: ["\"github.com/shopspring/decimal\""],
761
+ dep: {
762
+ name: "github.com/shopspring/decimal",
763
+ version: "v1"
764
+ },
765
+ mode: "lib"
766
+ },
767
+ byte: {
768
+ encode: "__SCAFFOLD_GO_BYTE_ENCODE__",
769
+ decode: "__SCAFFOLD_GO_BYTE_DECODE__",
770
+ imports: ["\"encoding/base64\""],
771
+ mode: "native"
772
+ },
773
+ uuid: {
774
+ encode: "__SCAFFOLD_GO_UUID_ENCODE__",
775
+ decode: "__SCAFFOLD_GO_UUID_DECODE__",
776
+ imports: ["\"github.com/google/uuid\""],
777
+ dep: {
778
+ name: "github.com/google/uuid",
779
+ version: "v1"
780
+ },
781
+ mode: "lib"
782
+ },
783
+ "number-special": {
784
+ encode: "__SCAFFOLD_GO_NUMSPECIAL_ENCODE__",
785
+ decode: "__SCAFFOLD_GO_NUMSPECIAL_DECODE__",
786
+ mode: "native"
787
+ }
788
+ },
789
+ java: {
790
+ "date-time": {
791
+ encode: "$.toString()",
792
+ decode: "Instant.parse($)",
793
+ imports: ["import java.time.Instant;"],
794
+ dep: {
795
+ name: "jackson-datatype-jsr310",
796
+ version: "2.x"
797
+ },
798
+ mode: "lib"
799
+ },
800
+ int64: {
801
+ encode: "@JsonFormat(shape = JsonFormat.Shape.STRING)",
802
+ decode: "@JsonFormat(shape = JsonFormat.Shape.STRING)",
803
+ imports: ["import com.fasterxml.jackson.annotation.JsonFormat;"],
804
+ mode: "native"
805
+ },
806
+ decimal: {
807
+ encode: "@JsonSerialize(using = ToStringSerializer.class)",
808
+ decode: "new BigDecimal($)",
809
+ imports: [
810
+ "import java.math.BigDecimal;",
811
+ "import com.fasterxml.jackson.databind.annotation.JsonSerialize;",
812
+ "import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;"
813
+ ],
814
+ mode: "native"
815
+ },
816
+ byte: {
817
+ encode: "$",
818
+ decode: "$",
819
+ mode: "native"
820
+ },
821
+ uuid: {
822
+ encode: "$.toString()",
823
+ decode: "UUID.fromString($)",
824
+ imports: ["import java.util.UUID;"],
825
+ mode: "native"
826
+ },
827
+ "number-special": {
828
+ encode: "@JsonSerialize(using = NumberSpecialSerializer.class)",
829
+ decode: "@JsonDeserialize(using = NumberSpecialDeserializer.class)",
830
+ imports: ["import com.fasterxml.jackson.databind.annotation.JsonSerialize;", "import com.fasterxml.jackson.databind.annotation.JsonDeserialize;"],
831
+ mode: "native"
832
+ }
833
+ }
832
834
  });
833
- function ue(e) {
834
- return g[e];
835
- }
836
- function pe(e, r) {
837
- const t = g[r], n = [];
838
- for (const o of e) {
839
- const i = t[o];
840
- i != null && i.dep && n.push({ id: o, dep: i.dep });
841
- }
842
- return n;
843
- }
844
- function me() {
845
- const e = g.typescript, r = {};
846
- for (const t of j) {
847
- const n = e[t].dep;
848
- n && (r[t] = n);
849
- }
850
- return Object.freeze(r);
851
- }
852
- function _e(e, r) {
853
- const t = r ?? g[e], n = [];
854
- for (const o of j)
855
- t[o] || n.push(o);
856
- if (n.length > 0)
857
- throw new Error(
858
- `[hints] assertNoEmptyCells: language "${e}" is missing cells for: ${n.join(
859
- ", "
860
- )}`
861
- );
862
- }
863
- export {
864
- j as CANONICAL_LOGICAL_TYPE_IDS,
865
- C as CodecRegistryError,
866
- D as ENVELOPE_KEY,
867
- re as LOGICAL_TYPE_VERSION,
868
- g as TEMPLATE_CELLS,
869
- P as X_APIGEN_CODEC,
870
- ee as X_APIGEN_CTOR,
871
- R as X_APIGEN_LOGICAL,
872
- te as X_APIGEN_TOJSON,
873
- _e as assertNoEmptyCells,
874
- se as buildTranscoder,
875
- F as byteCodec,
876
- ue as cellsFor,
877
- oe as codecIdOf,
878
- x as createRegistry,
879
- v as dateTimeCodec,
880
- T as decimalCodec,
881
- pe as depsForLogicalTypes,
882
- I as int64Codec,
883
- ne as logicalKindOf,
884
- de as makeDecimal,
885
- U as numberSpecialCodec,
886
- ae as registerWellKnown,
887
- fe as renderExampleNote,
888
- y as synthesizeExample,
889
- ce as tryRegister,
890
- me as tsDepMap,
891
- L as uuidCodec,
892
- ie as validateSchemaRefs
893
- };
835
+ function $(e) {
836
+ return Q[e];
837
+ }
838
+ function ee(e, t) {
839
+ let n = Q[t], r = [];
840
+ for (let t of e) {
841
+ let e = n[t];
842
+ e?.dep && r.push({
843
+ id: t,
844
+ dep: e.dep
845
+ });
846
+ }
847
+ return r;
848
+ }
849
+ function te() {
850
+ let e = Q.typescript, t = {};
851
+ for (let n of Z) {
852
+ let r = e[n].dep;
853
+ r && (t[n] = r);
854
+ }
855
+ return Object.freeze(t);
856
+ }
857
+ function ne(e, t) {
858
+ let n = t ?? Q[e], r = [];
859
+ for (let e of Z) n[e] || r.push(e);
860
+ if (r.length > 0) throw Error(`[hints] assertNoEmptyCells: language "${e}" is missing cells for: ${r.join(", ")}`);
861
+ }
862
+ //#endregion
863
+ export { Z as CANONICAL_LOGICAL_TYPE_IDS, t as CodecRegistryError, e as ENVELOPE_KEY, s as LOGICAL_TYPE_VERSION, Q as TEMPLATE_CELLS, i as X_APIGEN_CODEC, a as X_APIGEN_CTOR, r as X_APIGEN_LOGICAL, o as X_APIGEN_TOJSON, ne as assertNoEmptyCells, T as buildTranscoder, M as byteCodec, $ as cellsFor, u as codecIdOf, n as createRegistry, O as dateTimeCodec, j as decimalCodec, ee as depsForLogicalTypes, k as int64Codec, l as logicalKindOf, A as makeDecimal, z as numberSpecialCodec, V as registerWellKnown, X as renderExampleNote, Y as synthesizeExample, E as tryRegister, te as tsDepMap, P as uuidCodec, w as validateSchemaRefs };