@adhd/apigen-base-logical 0.1.0 → 0.1.2

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,333 +1,465 @@
1
- const l = "$apigen";
2
- class g extends Error {
3
- constructor(o) {
4
- super(o), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
1
+ const D = "$apigen";
2
+ class N extends Error {
3
+ constructor(t) {
4
+ super(t), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
5
5
  }
6
6
  }
7
- function z(e) {
7
+ function de(e) {
8
8
  e == null || e.wellKnown;
9
- const o = /* @__PURE__ */ new Map();
9
+ const t = /* @__PURE__ */ new Map();
10
10
  return {
11
- register(n, r) {
12
- if (o.has(n.id) && !(r != null && r.override))
13
- throw new g(
11
+ register(n, o) {
12
+ if (t.has(n.id) && !(o != null && o.override))
13
+ throw new N(
14
14
  `E_DUP_CODEC: a codec is already registered for id "${n.id}"`
15
15
  );
16
- o.set(n.id, n);
16
+ t.set(n.id, n);
17
17
  },
18
18
  resolve(n) {
19
- for (const r of o.values())
20
- if (r.matches(n))
21
- return r;
19
+ for (const o of t.values())
20
+ if (o.matches(n))
21
+ return o;
22
22
  },
23
23
  get(n) {
24
- return o.get(n);
24
+ return t.get(n);
25
25
  },
26
26
  ids() {
27
- return [...o.keys()];
27
+ return [...t.keys()];
28
28
  },
29
29
  freeze() {
30
- const n = new Map(o), r = {
30
+ const n = new Map(t), o = {
31
31
  register() {
32
- throw new g(
32
+ throw new N(
33
33
  "E_DUP_CODEC: registry is frozen and cannot accept new codecs"
34
34
  );
35
35
  },
36
- resolve(d) {
36
+ resolve(i) {
37
37
  for (const a of n.values())
38
- if (a.matches(d))
38
+ if (a.matches(i))
39
39
  return a;
40
40
  },
41
- get(d) {
42
- return n.get(d);
41
+ get(i) {
42
+ return n.get(i);
43
43
  },
44
44
  ids() {
45
45
  return [...n.keys()];
46
46
  },
47
47
  freeze() {
48
- return r;
48
+ return o;
49
49
  }
50
50
  };
51
- return r;
51
+ return o;
52
52
  }
53
53
  };
54
54
  }
55
- const v = "x-apigen-logical", U = "x-apigen-codec", W = "x-apigen-ctor", K = "x-apigen-tojson", X = "0.1.0", j = [
55
+ const z = "x-apigen-logical", J = "x-apigen-codec", ae = "x-apigen-ctor", fe = "x-apigen-tojson", ue = "0.1.0", V = [
56
56
  "scalar",
57
57
  "nominal",
58
58
  "union",
59
59
  "map",
60
60
  "set"
61
61
  ];
62
- function H(e) {
63
- const o = e[v];
64
- return typeof o == "string" && j.includes(o) ? o : void 0;
62
+ function pe(e) {
63
+ const t = e[z];
64
+ return typeof t == "string" && V.includes(t) ? t : void 0;
65
65
  }
66
- function Z(e) {
67
- const o = e[U];
68
- return typeof o == "string" ? o : void 0;
66
+ function me(e) {
67
+ const t = e[J];
68
+ return typeof t == "string" ? t : void 0;
69
69
  }
70
- function h(e, o) {
70
+ function v(e, t) {
71
71
  return {
72
72
  registry: e,
73
- resolve: (t) => {
73
+ resolve: (r) => {
74
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.`
75
+ `[apigen-logical] $ref "${r}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`
76
76
  );
77
77
  },
78
78
  seen: /* @__PURE__ */ new WeakSet(),
79
79
  path: "",
80
80
  mode: "strict",
81
- ...o
81
+ ...t
82
82
  };
83
83
  }
84
- function p(e, o, t) {
85
- const n = t.registry.resolve(o);
84
+ function l(e, t, r) {
85
+ const n = r.registry.resolve(t);
86
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;
87
+ return n.encode(e, t, r);
88
+ const o = t.$ref;
89
+ if (typeof o == "string") {
90
+ const c = r.resolve(o);
91
+ return l(e, c, r);
92
+ }
93
+ const i = t.oneOf;
94
+ if (Array.isArray(i)) {
95
+ const c = L(e, i, t, r);
96
+ return l(e, c, r);
97
+ }
98
+ const a = t.type;
99
99
  if (a === "array") {
100
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}/${_}` });
101
+ return b(e, t, r);
102
+ const c = t.items;
103
+ if (!c)
104
+ return e.map((f) => _(f));
105
+ const u = r.path;
106
+ return Array.isArray(c) ? e.map((f, s) => {
107
+ const d = c[s];
108
+ return d === void 0 ? _(f) : l(f, d, { ...r, path: `${u}/${s}` });
109
109
  }) : e.map(
110
- (c, _) => p(c, i, { ...t, path: `${f}/${_}` })
110
+ (f, s) => l(f, c, { ...r, path: `${u}/${s}` })
111
111
  );
112
112
  }
113
113
  if (a === "object") {
114
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}/${_}`
115
+ return b(e, t, r);
116
+ const c = t.properties;
117
+ if (!c)
118
+ return _(e);
119
+ const u = r.path, f = {};
120
+ for (const [s, d] of Object.entries(c)) {
121
+ const p = e[s];
122
+ p !== void 0 && (f[s] = l(p, d, {
123
+ ...r,
124
+ path: `${u}/${s}`
125
125
  }));
126
126
  }
127
- return c;
127
+ return f;
128
128
  }
129
- return a == null ? D(e, o, t) : u(e);
129
+ return a == null ? b(e, t, r) : _(e);
130
130
  }
131
- function E(e, o, t) {
132
- const n = t.registry.resolve(o);
131
+ function y(e, t, r) {
132
+ const n = r.registry.resolve(t);
133
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;
134
+ return n.decode(e, t, r);
135
+ const o = t.$ref;
136
+ if (typeof o == "string") {
137
+ const c = r.resolve(o);
138
+ return y(e, c, r);
139
+ }
140
+ const i = t.oneOf;
141
+ if (Array.isArray(i)) {
142
+ const c = L(e, i, t, r);
143
+ return y(e, c, r);
144
+ }
145
+ const a = t.type;
146
146
  if (a === "array") {
147
147
  if (!Array.isArray(e))
148
148
  return e;
149
- const i = o.items;
150
- if (!i)
149
+ const c = t.items;
150
+ if (!c)
151
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}/${_}` });
152
+ const u = r.path;
153
+ return Array.isArray(c) ? e.map((f, s) => {
154
+ const d = c[s];
155
+ return d === void 0 ? f : y(f, d, { ...r, path: `${u}/${s}` });
156
156
  }) : e.map(
157
- (c, _) => E(c, i, { ...t, path: `${f}/${_}` })
157
+ (f, s) => y(f, c, { ...r, path: `${u}/${s}` })
158
158
  );
159
159
  }
160
160
  if (a === "object") {
161
161
  if (e === null || typeof e != "object" || Array.isArray(e))
162
162
  return e;
163
- const i = o.properties;
164
- if (!i)
163
+ const c = t.properties;
164
+ if (!c)
165
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}/${_}`
166
+ const u = r.path, f = {};
167
+ for (const [s, d] of Object.entries(c)) {
168
+ const p = e[s];
169
+ p !== void 0 && (f[s] = y(p, d, {
170
+ ...r,
171
+ path: `${u}/${s}`
172
172
  }));
173
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;
174
+ for (const [s, d] of Object.entries(e))
175
+ !(s in c) && d !== void 0 && (f[s] = d);
176
+ return f;
177
+ }
178
+ return a == null ? S(e, r) : e;
179
+ }
180
+ function L(e, t, r, n) {
181
+ var u;
182
+ const o = r.discriminator;
183
+ if (o != null && o.propertyName) {
184
+ const f = o.propertyName, s = e !== null && typeof e == "object" ? e[f] : void 0;
185
+ if (typeof s == "string") {
186
+ if (o.mapping) {
187
+ const d = o.mapping[s];
188
+ if (d) {
189
+ const p = t.find((m) => m.$ref === d);
190
+ if (p)
191
+ return p;
192
+ }
193
+ }
194
+ for (const d of t) {
195
+ const m = (u = O(d, n).properties) == null ? void 0 : u[f];
196
+ if (!m)
197
+ continue;
198
+ const g = m.enum;
199
+ if (m.const === s || Array.isArray(g) && g.includes(s))
200
+ return d;
188
201
  }
189
202
  }
190
203
  }
191
- return o[0] ?? {};
204
+ const i = Y(e, t, n);
205
+ if (i)
206
+ return i;
207
+ let a, c = -1;
208
+ for (const f of t) {
209
+ const s = O(f, n), d = U(e, s, n);
210
+ d !== null && d > c && (c = d, a = f);
211
+ }
212
+ return a !== void 0 ? a : t[0] ?? {};
192
213
  }
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 {
214
+ function O(e, t) {
215
+ const r = e.$ref;
216
+ return typeof r == "string" ? t.resolve(r) : e;
217
+ }
218
+ function I(e) {
219
+ if ("const" in e)
220
+ return e.const;
221
+ const t = e.enum;
222
+ if (Array.isArray(t) && t.length === 1)
223
+ return t[0];
224
+ }
225
+ function Y(e, t, r) {
226
+ if (e === null || typeof e != "object" || Array.isArray(e))
227
+ return;
228
+ const n = e, o = t.map((a) => O(a, r)), i = /* @__PURE__ */ new Set();
229
+ for (const a of o) {
230
+ const c = a.properties;
231
+ if (c)
232
+ for (const [u, f] of Object.entries(c))
233
+ I(f) !== void 0 && i.add(u);
234
+ }
235
+ for (const a of i) {
236
+ const c = o.map((p) => {
237
+ const m = p.properties, g = m == null ? void 0 : m[a];
238
+ return g ? I(g) : void 0;
239
+ }), u = c.filter((p) => p !== void 0), f = new Set(u);
240
+ if (u.length < 2 || f.size !== u.length)
241
+ continue;
242
+ const s = n[a];
243
+ if (s === void 0)
244
+ continue;
245
+ const d = c.findIndex((p) => p === s);
246
+ if (d !== -1)
247
+ return t[d];
248
+ }
249
+ }
250
+ function W(e) {
251
+ if (e === null)
252
+ return "null";
253
+ if (Array.isArray(e))
254
+ return "array";
255
+ const t = typeof e;
256
+ return t === "number" ? Number.isInteger(e) ? "integer" : "number" : t;
257
+ }
258
+ function U(e, t, r) {
259
+ const n = t.oneOf;
260
+ if (Array.isArray(n)) {
261
+ let s = null;
262
+ for (const d of n) {
263
+ const p = U(e, O(d, r), r);
264
+ p !== null && (s === null || p > s) && (s = p);
265
+ }
266
+ return s;
267
+ }
268
+ const o = t.type, i = W(e);
269
+ if (typeof o == "string") {
270
+ if (!(o === i || o === "number" && i === "integer"))
271
+ return null;
272
+ } else if (Array.isArray(o) && !o.some(
273
+ (d) => d === i || d === "number" && i === "integer"
274
+ ))
275
+ return null;
276
+ if (e === null || typeof e != "object" || Array.isArray(e))
277
+ return typeof o == "string" ? 1 : 0;
278
+ const a = e, c = t.required;
279
+ let u = 0;
280
+ if (Array.isArray(c)) {
281
+ for (const s of c)
282
+ if (typeof s == "string") {
283
+ if (a[s] === void 0)
284
+ return null;
285
+ u += 2;
201
286
  }
202
287
  }
203
- return u(e);
288
+ const f = t.properties;
289
+ if (f) {
290
+ for (const s of Object.keys(f))
291
+ a[s] !== void 0 && (u += 1);
292
+ for (const s of Object.keys(a))
293
+ f[s] === void 0 && (u -= 1);
294
+ }
295
+ return u;
296
+ }
297
+ function b(e, t, r) {
298
+ var n;
299
+ for (const o of r.registry.ids()) {
300
+ const i = r.registry.get(o);
301
+ if ((n = i == null ? void 0 : i.ownsValue) != null && n.call(i, e))
302
+ return {
303
+ [D]: o,
304
+ v: i.encode(e, i.schema, r)
305
+ };
306
+ }
307
+ if (Array.isArray(e))
308
+ return e.map((o) => b(o, {}, r));
309
+ if (j(e)) {
310
+ const o = {};
311
+ for (const [i, a] of Object.entries(e))
312
+ a !== void 0 && (o[i] = b(a, {}, r));
313
+ return o;
314
+ }
315
+ return _(e);
204
316
  }
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);
317
+ function j(e) {
318
+ if (e === null || typeof e != "object" || Array.isArray(e))
319
+ return !1;
320
+ const t = Object.getPrototypeOf(e);
321
+ return t === Object.prototype || t === null;
322
+ }
323
+ function S(e, t) {
324
+ if (e !== null && typeof e == "object" && !Array.isArray(e) && D in e) {
325
+ const r = e, n = r[D], o = t.registry.get(n);
326
+ if (o)
327
+ return o.decode(r.v, o.schema, t);
328
+ }
329
+ if (Array.isArray(e))
330
+ return e.map((r) => S(r, t));
331
+ if (j(e)) {
332
+ const r = {};
333
+ for (const [n, o] of Object.entries(e))
334
+ r[n] = S(o, t);
335
+ return r;
210
336
  }
211
337
  return e;
212
338
  }
213
- function u(e) {
339
+ function _(e) {
214
340
  if (e === null || typeof e == "string" || typeof e == "number" || typeof e == "boolean")
215
341
  return e;
216
342
  if (Array.isArray(e))
217
- return e.map(u);
343
+ return e.map(_);
218
344
  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;
345
+ const t = {};
346
+ for (const [r, n] of Object.entries(e))
347
+ n !== void 0 && (t[r] = _(n));
348
+ return t;
223
349
  }
224
350
  return null;
225
351
  }
226
- function q(e, o) {
227
- const t = /* @__PURE__ */ new Set(), n = [e];
352
+ function _e(e, t) {
353
+ const r = /* @__PURE__ */ new Set(), n = [e];
228
354
  for (; n.length > 0; ) {
229
- const r = n.pop();
230
- if (!r || t.has(r))
355
+ const o = n.pop();
356
+ if (!o || r.has(o))
231
357
  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)";
358
+ r.add(o);
359
+ const i = o.$ref;
360
+ if (typeof i == "string") {
361
+ if (t) {
362
+ const d = t[i];
363
+ if (!d) {
364
+ const p = Object.keys(t).join(", ") || "(none)";
239
365
  throw new Error(
240
- `[apigen-logical] $ref "${d}" cannot be resolved. Available $defs: ${m}`
366
+ `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`
241
367
  );
242
368
  }
243
- n.push(s);
369
+ n.push(d);
244
370
  }
245
371
  continue;
246
372
  }
247
- const a = r.oneOf;
373
+ const a = o.oneOf;
248
374
  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);
375
+ for (const d of a)
376
+ typeof d == "object" && d !== null && n.push(d);
377
+ const c = o.properties;
378
+ if (c)
379
+ for (const d of Object.values(c))
380
+ n.push(d);
381
+ const u = o.items;
382
+ if (Array.isArray(u))
383
+ for (const d of u)
384
+ typeof d == "object" && d !== null && n.push(d);
259
385
  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(_);
386
+ typeof u == "object" && u !== null && n.push(u);
387
+ const f = o.additionalProperties;
388
+ typeof f == "object" && f !== null && n.push(f);
389
+ const s = o.propertyNames;
390
+ typeof s == "object" && s !== null && n.push(s);
265
391
  }
266
392
  }
267
- function Q(e) {
393
+ function le(e) {
268
394
  return {
269
- encode(o, t, n) {
270
- const r = h(e, n);
271
- return p(o, t, r);
395
+ encode(t, r, n) {
396
+ const o = v(e, n);
397
+ return l(t, r, o);
272
398
  },
273
- decode(o, t, n) {
274
- const r = h(e, n);
275
- return E(o, t, r);
399
+ decode(t, r, n) {
400
+ const o = v(e, n);
401
+ return y(t, r, o);
276
402
  }
277
403
  };
278
404
  }
279
- function x(e, o, t) {
405
+ function ye(e, t, r) {
280
406
  try {
281
- const n = t();
407
+ const n = r();
282
408
  e.register(n);
283
409
  } catch (n) {
284
- if (P(n))
410
+ if (q(n))
285
411
  return;
286
412
  throw n;
287
413
  }
288
414
  }
289
- function P(e) {
415
+ function q(e) {
290
416
  return e === null || typeof e != "object" ? !1 : e.code === "MODULE_NOT_FOUND";
291
417
  }
292
- const b = {
418
+ const k = {
293
419
  id: "date-time",
294
420
  kind: "scalar",
295
421
  schema: { type: "string", format: "date-time" },
296
422
  matches(e) {
297
423
  return e.type === "string" && e.format === "date-time";
298
424
  },
299
- encode(e, o, t) {
425
+ ownsValue(e) {
426
+ return e instanceof Date;
427
+ },
428
+ encode(e, t, r) {
300
429
  return e.toISOString();
301
430
  },
302
- decode(e, o, t) {
431
+ decode(e, t, r) {
303
432
  if (typeof e != "string") {
304
- if (t.mode === "strict")
433
+ if (r.mode === "strict")
305
434
  throw new TypeError(
306
- `[date-time] expected a string on the wire at "${t.path}", got ${typeof e}`
435
+ `[date-time] expected a string on the wire at "${r.path}", got ${typeof e}`
307
436
  );
308
437
  return new Date(String(e));
309
438
  }
310
- if (t.mode === "strict" && Number.isNaN(new Date(e).getTime()))
439
+ if (r.mode === "strict" && Number.isNaN(new Date(e).getTime()))
311
440
  throw new TypeError(
312
- `[date-time] invalid date-time string at "${t.path}": ${JSON.stringify(e)}`
441
+ `[date-time] invalid date-time string at "${r.path}": ${JSON.stringify(e)}`
313
442
  );
314
443
  return new Date(e);
315
444
  }
316
- }, N = {
445
+ }, R = {
317
446
  id: "int64",
318
447
  kind: "scalar",
319
448
  schema: { type: "string", format: "int64" },
320
449
  matches(e) {
321
450
  return e.type === "string" && e.format === "int64";
322
451
  },
323
- encode(e, o, t) {
452
+ ownsValue(e) {
453
+ return typeof e == "bigint";
454
+ },
455
+ encode(e, t, r) {
324
456
  return String(e);
325
457
  },
326
- decode(e, o, t) {
458
+ decode(e, t, r) {
327
459
  if (typeof e != "string") {
328
- if (t.mode === "strict")
460
+ if (r.mode === "strict")
329
461
  throw new TypeError(
330
- `[int64] expected a string on the wire at "${t.path}", got ${typeof e}`
462
+ `[int64] expected a string on the wire at "${r.path}", got ${typeof e}`
331
463
  );
332
464
  try {
333
465
  return BigInt(Math.trunc(Number(e)));
@@ -335,7 +467,7 @@ const b = {
335
467
  return BigInt(0);
336
468
  }
337
469
  }
338
- if (t.mode === "strict")
470
+ if (r.mode === "strict")
339
471
  return BigInt(e);
340
472
  if (/^-?\d+$/.test(e))
341
473
  try {
@@ -346,141 +478,261 @@ const b = {
346
478
  return BigInt(0);
347
479
  }
348
480
  };
349
- function ee(e) {
481
+ function ge(e) {
350
482
  return e;
351
483
  }
352
- const F = {
484
+ const P = {
353
485
  id: "decimal",
354
486
  kind: "scalar",
355
487
  schema: { type: "string", format: "decimal" },
356
488
  matches(e) {
357
489
  return e.type === "string" && e.format === "decimal";
358
490
  },
359
- encode(e, o, t) {
491
+ encode(e, t, r) {
360
492
  return e;
361
493
  },
362
- decode(e, o, t) {
494
+ decode(e, t, r) {
363
495
  if (typeof e != "string") {
364
- if (t.mode === "strict")
496
+ if (r.mode === "strict")
365
497
  throw new TypeError(
366
- `[decimal] expected a string on the wire at "${t.path}", got ${typeof e}`
498
+ `[decimal] expected a string on the wire at "${r.path}", got ${typeof e}`
367
499
  );
368
500
  return String(e);
369
501
  }
370
- if (t.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e))
502
+ if (r.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e))
371
503
  throw new TypeError(
372
- `[decimal] wire value "${e}" at "${t.path}" is not a valid decimal string`
504
+ `[decimal] wire value "${e}" at "${r.path}" is not a valid decimal string`
373
505
  );
374
506
  return e;
375
507
  }
376
- }, $ = {
508
+ }, B = {
377
509
  id: "byte",
378
510
  kind: "scalar",
379
511
  schema: { type: "string", format: "byte" },
380
512
  matches(e) {
381
513
  return e.type === "string" && e.format === "byte";
382
514
  },
383
- encode(e, o, t) {
515
+ ownsValue(e) {
516
+ return e instanceof Uint8Array;
517
+ },
518
+ encode(e, t, r) {
384
519
  return Buffer.from(e).toString("base64");
385
520
  },
386
- decode(e, o, t) {
521
+ decode(e, t, r) {
387
522
  if (typeof e != "string") {
388
- if (t.mode === "strict")
523
+ if (r.mode === "strict")
389
524
  throw new TypeError(
390
- `[byte] expected a base64 string on the wire at "${t.path}", got ${typeof e}`
525
+ `[byte] expected a base64 string on the wire at "${r.path}", got ${typeof e}`
391
526
  );
392
527
  return new Uint8Array(0);
393
528
  }
394
- if (t.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e))
529
+ if (r.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e))
395
530
  throw new TypeError(
396
- `[byte] wire value at "${t.path}" is not standard base64 (format:byte): "${e}"`
531
+ `[byte] wire value at "${r.path}" is not standard base64 (format:byte): "${e}"`
397
532
  );
398
533
  return new Uint8Array(Buffer.from(e, "base64"));
399
534
  }
400
- }, R = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, L = {
535
+ }, K = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, w = {
401
536
  id: "uuid",
402
537
  kind: "scalar",
403
538
  schema: { type: "string", format: "uuid" },
404
539
  matches(e) {
405
540
  return e.type === "string" && e.format === "uuid";
406
541
  },
407
- encode(e, o, t) {
542
+ encode(e, t, r) {
408
543
  return e.toLowerCase();
409
544
  },
410
- decode(e, o, t) {
545
+ decode(e, t, r) {
411
546
  if (typeof e != "string") {
412
- if (t.mode === "strict")
547
+ if (r.mode === "strict")
413
548
  throw new TypeError(
414
- `[uuid] expected a string on the wire at "${t.path}", got ${typeof e}`
549
+ `[uuid] expected a string on the wire at "${r.path}", got ${typeof e}`
415
550
  );
416
551
  return String(e).toLowerCase();
417
552
  }
418
- if (t.mode === "strict" && !R.test(e))
553
+ if (r.mode === "strict" && !K.test(e))
419
554
  throw new TypeError(
420
- `[uuid] wire value "${e}" at "${t.path}" is not a lowercase-hyphenated RFC 4122 UUID`
555
+ `[uuid] wire value "${e}" at "${r.path}" is not a lowercase-hyphenated RFC 4122 UUID`
421
556
  );
422
557
  return e;
423
558
  }
424
- }, O = "NaN", C = "Infinity", A = "-Infinity", G = /* @__PURE__ */ new Set([
425
- O,
559
+ }, h = "NaN", C = "Infinity", $ = "-Infinity", X = /* @__PURE__ */ new Set([
560
+ h,
426
561
  C,
427
- A
428
- ]), I = {
562
+ $
563
+ ]), M = {
429
564
  id: "number-special",
430
565
  kind: "scalar",
431
566
  schema: { type: "number" },
432
567
  matches(e) {
433
568
  return e.type === "number" && e.format === void 0;
434
569
  },
435
- encode(e, o, t) {
436
- return Number.isNaN(e) ? O : e === 1 / 0 ? C : e === -1 / 0 ? A : e;
570
+ ownsValue(e) {
571
+ return typeof e == "number" && !Number.isFinite(e);
572
+ },
573
+ encode(e, t, r) {
574
+ return Number.isNaN(e) ? h : e === 1 / 0 ? C : e === -1 / 0 ? $ : e;
437
575
  },
438
- decode(e, o, t) {
576
+ decode(e, t, r) {
439
577
  if (typeof e == "number")
440
578
  return e;
441
579
  if (typeof e == "string") {
442
- if (e === O)
580
+ if (e === h)
443
581
  return NaN;
444
582
  if (e === C)
445
583
  return 1 / 0;
446
- if (e === A)
584
+ if (e === $)
447
585
  return -1 / 0;
448
586
  const n = Number(e);
449
587
  if (!Number.isNaN(n))
450
588
  return n;
451
589
  }
452
- if (t.mode === "strict")
590
+ if (r.mode === "strict")
453
591
  throw new TypeError(
454
- `[number-special] unrecognized wire value at "${t.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...G].join(", ")}.`
592
+ `[number-special] unrecognized wire value at "${r.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...X].join(", ")}.`
455
593
  );
456
594
  return NaN;
457
595
  }
458
- }, w = [
459
- b,
460
- N,
461
- F,
462
- $,
463
- L,
464
- I
596
+ }, Z = [
597
+ k,
598
+ R,
599
+ P,
600
+ B,
601
+ w,
602
+ M
465
603
  ];
466
- function te(e, o = {}) {
467
- for (const t of w)
468
- e.register(t, { override: o.override ?? !1 });
604
+ function be(e, t = {}) {
605
+ for (const r of Z)
606
+ e.register(r, { override: t.override ?? !1 });
607
+ }
608
+ const H = 12;
609
+ function Q(e, t) {
610
+ const r = /^#\/(definitions|\$defs)\/(.+)$/.exec(e);
611
+ if (!r)
612
+ return;
613
+ const [, n, o] = r, i = n === "$defs" ? t.$defs : t.definitions;
614
+ return i == null ? void 0 : i[decodeURIComponent(o)];
615
+ }
616
+ function T(e) {
617
+ return Array.isArray(e) && e.length > 0 ? e[0] : void 0;
618
+ }
619
+ function x(e) {
620
+ if (Array.isArray(e.type))
621
+ return e.type.find((t) => t !== "null") ?? e.type[0];
622
+ if (typeof e.type == "string")
623
+ return e.type;
624
+ if (e.properties)
625
+ return "object";
626
+ }
627
+ function ee(e) {
628
+ switch (e.format) {
629
+ case "date-time":
630
+ return "1970-01-01T00:00:00.000Z";
631
+ case "date":
632
+ return "1970-01-01";
633
+ case "time":
634
+ return "00:00:00Z";
635
+ case "uuid":
636
+ return "00000000-0000-0000-0000-000000000000";
637
+ case "email":
638
+ return "user@example.com";
639
+ case "uri":
640
+ case "url":
641
+ case "uri-reference":
642
+ return "https://example.com";
643
+ case "hostname":
644
+ return "example.com";
645
+ case "ipv4":
646
+ return "127.0.0.1";
647
+ case "ipv6":
648
+ return "::1";
649
+ case "decimal":
650
+ return "0";
651
+ case "int64":
652
+ return "0";
653
+ case "byte":
654
+ return "";
655
+ default:
656
+ return "<string>";
657
+ }
658
+ }
659
+ function F(e, t, r) {
660
+ const n = e.properties ?? {}, o = e.required ?? [], i = {};
661
+ for (const a of o) {
662
+ const c = n[a];
663
+ i[a] = c !== void 0 ? E(c, t, r + 1) : `<${a}>`;
664
+ }
665
+ return i;
666
+ }
667
+ function te(e, t, r) {
668
+ const n = Array.isArray(e.items) ? e.items[0] : e.items;
669
+ return n ? [E(n, t, r + 1)] : [];
469
670
  }
470
- const T = [
471
- b.id,
671
+ function E(e, t = e ?? {}, r = 0) {
672
+ if (!e || r > H)
673
+ return null;
674
+ if (typeof e.$ref == "string") {
675
+ const i = Q(e.$ref, t);
676
+ return i !== void 0 ? E(i, t, r + 1) : null;
677
+ }
678
+ if (e.const !== void 0)
679
+ return e.const;
680
+ if (Array.isArray(e.enum) && e.enum.length > 0)
681
+ return e.enum[0];
682
+ if (Array.isArray(e.allOf) && e.allOf.length > 0) {
683
+ const i = {}, a = [];
684
+ for (const c of e.allOf) {
685
+ Object.assign(i, c.properties ?? {});
686
+ for (const u of c.required ?? [])
687
+ a.includes(u) || a.push(u);
688
+ }
689
+ return F(
690
+ { ...e, properties: i, required: a },
691
+ t,
692
+ r
693
+ );
694
+ }
695
+ const n = T(e.oneOf) ?? T(e.anyOf);
696
+ if (n)
697
+ return E(n, t, r + 1);
698
+ switch (x(e)) {
699
+ case "object":
700
+ return F(e, t, r);
701
+ case "array":
702
+ return te(e, t, r);
703
+ case "string":
704
+ return ee(e);
705
+ case "integer":
706
+ case "number":
707
+ return 0;
708
+ case "boolean":
709
+ return !1;
710
+ case "null":
711
+ return null;
712
+ default:
713
+ return null;
714
+ }
715
+ }
716
+ function Ee(e) {
717
+ if (!e)
718
+ return;
719
+ const t = E(e);
720
+ return `Example: ${JSON.stringify(t)}`;
721
+ }
722
+ const G = [
723
+ k.id,
472
724
  // 'date-time'
473
- N.id,
725
+ R.id,
474
726
  // 'int64'
475
- F.id,
727
+ P.id,
476
728
  // 'decimal'
477
- $.id,
729
+ B.id,
478
730
  // 'byte'
479
- L.id,
731
+ w.id,
480
732
  // 'uuid'
481
- I.id
733
+ M.id
482
734
  // 'number-special'
483
- ], B = {
735
+ ], re = {
484
736
  "date-time": {
485
737
  encode: "$.toISOString()",
486
738
  decode: "new Date($)",
@@ -519,7 +771,7 @@ const T = [
519
771
  decode: "wireToNum($)",
520
772
  mode: "native"
521
773
  }
522
- }, k = {
774
+ }, ne = {
523
775
  "date-time": {
524
776
  encode: "$.isoformat()",
525
777
  decode: "datetime.fromisoformat($)",
@@ -556,7 +808,7 @@ const T = [
556
808
  decode: "wire_to_num($)",
557
809
  mode: "native"
558
810
  }
559
- }, J = {
811
+ }, oe = {
560
812
  "date-time": {
561
813
  // chrono::DateTime<Utc> serialises as RFC3339 via serde.
562
814
  encode: "__SCAFFOLD_RUST_DATETIME_ENCODE__",
@@ -600,7 +852,7 @@ const T = [
600
852
  decode: "__SCAFFOLD_RUST_NUMSPECIAL_DECODE__",
601
853
  mode: "native"
602
854
  }
603
- }, V = {
855
+ }, ie = {
604
856
  "date-time": {
605
857
  // time.Time serialises as RFC3339Nano via MarshalJSON.
606
858
  encode: "__SCAFFOLD_GO_DATETIME_ENCODE__",
@@ -641,78 +893,104 @@ const T = [
641
893
  decode: "__SCAFFOLD_GO_NUMSPECIAL_DECODE__",
642
894
  mode: "native"
643
895
  }
644
- }, Y = {
896
+ }, se = {
645
897
  "date-time": {
646
- // Instant.toString() / Instant.parse() via jackson-datatype-jsr310.
647
- encode: "__SCAFFOLD_JAVA_DATETIME_ENCODE__",
648
- decode: "__SCAFFOLD_JAVA_DATETIME_DECODE__",
898
+ // Instant.toString() (RFC-3339/ISO-8601, UTC) / Instant.parse($) — the
899
+ // jackson-datatype-jsr310 module is registered on the shared ObjectMapper
900
+ // so java.time.Instant fields round-trip automatically, but the
901
+ // dispatcher-woven glue (which builds/reads JsonNode by hand rather than
902
+ // going through a field-annotated POJO) uses these expressions directly.
903
+ encode: "$.toString()",
904
+ decode: "Instant.parse($)",
649
905
  imports: ["import java.time.Instant;"],
650
906
  dep: { name: "jackson-datatype-jsr310", version: "2.x" },
651
907
  mode: "lib"
652
908
  },
653
909
  int64: {
654
- // @JsonFormat(shape=STRING) on Long / BigInteger — stdlib Jackson.
655
- encode: "__SCAFFOLD_JAVA_INT64_ENCODE__",
656
- decode: "__SCAFFOLD_JAVA_INT64_DECODE__",
910
+ // Declarative, not expression-shaped: Jackson field annotation forces
911
+ // Long/long to serialise as a JSON string (avoids precision loss in
912
+ // JS/JSON-number consumers). mode:'native' — the "encode"/"decode"
913
+ // values below ARE the annotation text (identical on both sides; Jackson
914
+ // applies it symmetrically), not a `$`-substituted call expression.
915
+ encode: "@JsonFormat(shape = JsonFormat.Shape.STRING)",
916
+ decode: "@JsonFormat(shape = JsonFormat.Shape.STRING)",
657
917
  imports: ["import com.fasterxml.jackson.annotation.JsonFormat;"],
658
918
  mode: "native"
659
919
  },
660
920
  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;"],
921
+ // Encode is declarative (field annotation forces BigDecimal -> JSON
922
+ // string via Jackson's stdlib ToStringSerializer, so scale/precision
923
+ // survive the wire); decode is a plain expression since BigDecimal has
924
+ // no matching stdlib deserializer-by-annotation for "parse from string".
925
+ encode: "@JsonSerialize(using = ToStringSerializer.class)",
926
+ decode: "new BigDecimal($)",
927
+ imports: [
928
+ "import java.math.BigDecimal;",
929
+ "import com.fasterxml.jackson.databind.annotation.JsonSerialize;",
930
+ "import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;"
931
+ ],
665
932
  mode: "native"
666
933
  },
667
934
  byte: {
668
- // byte[] serialises as base64 by default in Jackson.
669
- encode: "__SCAFFOLD_JAVA_BYTE_ENCODE__",
670
- decode: "__SCAFFOLD_JAVA_BYTE_DECODE__",
935
+ // byte[] <-> base64 String is Jackson's built-in default codec — no
936
+ // annotation, no wrapping expression. The dispatcher glue passes the
937
+ // value through unchanged; Jackson's ObjectMapper performs the base64
938
+ // transcoding when the JsonNode tree is built/read.
939
+ encode: "$",
940
+ decode: "$",
671
941
  mode: "native"
672
942
  },
673
943
  uuid: {
674
- // UUID.toString() / UUID.fromString() — stdlib Java.
675
- encode: "__SCAFFOLD_JAVA_UUID_ENCODE__",
676
- decode: "__SCAFFOLD_JAVA_UUID_DECODE__",
944
+ // UUID.toString() / UUID.fromString($) — stdlib Java, no Jackson module.
945
+ encode: "$.toString()",
946
+ decode: "UUID.fromString($)",
677
947
  imports: ["import java.util.UUID;"],
678
948
  mode: "native"
679
949
  },
680
950
  "number-special": {
681
- // Custom StdSerializer — stdlib Jackson.
682
- encode: "__SCAFFOLD_JAVA_NUMSPECIAL_ENCODE__",
683
- decode: "__SCAFFOLD_JAVA_NUMSPECIAL_DECODE__",
951
+ // NaN/Infinity/-Infinity have no native JSON representation; mirrors the
952
+ // TS numToWire/wireToNum inline helpers with a small custom Jackson
953
+ // StdSerializer/StdDeserializer pair, generated inline by
954
+ // renderDispatcherJava (class names below are the fixed contract the
955
+ // generator emits — apigen-plugin-java-javalin/src/lib/dispatcher-template.ts).
956
+ encode: "@JsonSerialize(using = NumberSpecialSerializer.class)",
957
+ decode: "@JsonDeserialize(using = NumberSpecialDeserializer.class)",
958
+ imports: [
959
+ "import com.fasterxml.jackson.databind.annotation.JsonSerialize;",
960
+ "import com.fasterxml.jackson.databind.annotation.JsonDeserialize;"
961
+ ],
684
962
  mode: "native"
685
963
  }
686
- }, y = Object.freeze({
687
- typescript: B,
688
- python: k,
689
- rust: J,
690
- go: V,
691
- java: Y
964
+ }, A = Object.freeze({
965
+ typescript: re,
966
+ python: ne,
967
+ rust: oe,
968
+ go: ie,
969
+ java: se
692
970
  });
693
- function oe(e) {
694
- return y[e];
971
+ function Oe(e) {
972
+ return A[e];
695
973
  }
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 });
974
+ function Ae(e, t) {
975
+ const r = A[t], n = [];
976
+ for (const o of e) {
977
+ const i = r[o];
978
+ i != null && i.dep && n.push({ id: o, dep: i.dep });
701
979
  }
702
980
  return n;
703
981
  }
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);
982
+ function De() {
983
+ const e = A.typescript, t = {};
984
+ for (const r of G) {
985
+ const n = e[r].dep;
986
+ n && (t[r] = n);
709
987
  }
710
- return Object.freeze(o);
988
+ return Object.freeze(t);
711
989
  }
712
- function ie(e, o) {
713
- const t = o ?? y[e], n = [];
714
- for (const r of T)
715
- t[r] || n.push(r);
990
+ function Se(e, t) {
991
+ const r = t ?? A[e], n = [];
992
+ for (const o of G)
993
+ r[o] || n.push(o);
716
994
  if (n.length > 0)
717
995
  throw new Error(
718
996
  `[hints] assertNoEmptyCells: language "${e}" is missing cells for: ${n.join(
@@ -721,31 +999,33 @@ function ie(e, o) {
721
999
  );
722
1000
  }
723
1001
  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
1002
+ G as CANONICAL_LOGICAL_TYPE_IDS,
1003
+ N as CodecRegistryError,
1004
+ D as ENVELOPE_KEY,
1005
+ ue as LOGICAL_TYPE_VERSION,
1006
+ A as TEMPLATE_CELLS,
1007
+ J as X_APIGEN_CODEC,
1008
+ ae as X_APIGEN_CTOR,
1009
+ z as X_APIGEN_LOGICAL,
1010
+ fe as X_APIGEN_TOJSON,
1011
+ Se as assertNoEmptyCells,
1012
+ le as buildTranscoder,
1013
+ B as byteCodec,
1014
+ Oe as cellsFor,
1015
+ me as codecIdOf,
1016
+ de as createRegistry,
1017
+ k as dateTimeCodec,
1018
+ P as decimalCodec,
1019
+ Ae as depsForLogicalTypes,
1020
+ R as int64Codec,
1021
+ pe as logicalKindOf,
1022
+ ge as makeDecimal,
1023
+ M as numberSpecialCodec,
1024
+ be as registerWellKnown,
1025
+ Ee as renderExampleNote,
1026
+ E as synthesizeExample,
1027
+ ye as tryRegister,
1028
+ De as tsDepMap,
1029
+ w as uuidCodec,
1030
+ _e as validateSchemaRefs
751
1031
  };