@frontman-ai/nextjs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2400 @@
1
+ import * as Nextjs from '@sentry/nextjs';
2
+
3
+ // src/FrontmanNextjs__Sentry.res.mjs
4
+
5
+ // ../../node_modules/@rescript/runtime/lib/es6/Primitive_option.js
6
+ function some(x) {
7
+ if (x === void 0) {
8
+ return {
9
+ BS_PRIVATE_NESTED_SOME_NONE: 0
10
+ };
11
+ } else if (x !== null && x.BS_PRIVATE_NESTED_SOME_NONE !== void 0) {
12
+ return {
13
+ BS_PRIVATE_NESTED_SOME_NONE: x.BS_PRIVATE_NESTED_SOME_NONE + 1 | 0
14
+ };
15
+ } else {
16
+ return x;
17
+ }
18
+ }
19
+ function fromNullable(x) {
20
+ if (x == null) {
21
+ return;
22
+ } else {
23
+ return some(x);
24
+ }
25
+ }
26
+ function valFromOption(x) {
27
+ if (x === null || x.BS_PRIVATE_NESTED_SOME_NONE === void 0) {
28
+ return x;
29
+ }
30
+ let depth = x.BS_PRIVATE_NESTED_SOME_NONE;
31
+ if (depth === 0) {
32
+ return;
33
+ } else {
34
+ return {
35
+ BS_PRIVATE_NESTED_SOME_NONE: depth - 1 | 0
36
+ };
37
+ }
38
+ }
39
+
40
+ // src/FrontmanNextjs__Sentry.res.mjs
41
+ var dsn = "https://442ae992e5a5ccfc42e6910220aeb2a9@o4510512511320064.ingest.de.sentry.io/4510512546185296";
42
+ var initialized = {
43
+ contents: false
44
+ };
45
+ function initialize(transport) {
46
+ if (initialized.contents) {
47
+ return;
48
+ }
49
+ let options_environment = process.env.NODE_ENV || "development";
50
+ let options_release = process.env.npm_package_version || "unknown";
51
+ let options_sampleRate = 1;
52
+ let options_initialScope = {
53
+ tags: Object.fromEntries([[
54
+ "frontman.library",
55
+ "frontman-nextjs"
56
+ ]])
57
+ };
58
+ let options = {
59
+ dsn,
60
+ environment: options_environment,
61
+ release: options_release,
62
+ sampleRate: options_sampleRate,
63
+ initialScope: options_initialScope
64
+ };
65
+ Nextjs.init(options);
66
+ initialized.contents = true;
67
+ }
68
+
69
+ // ../../node_modules/@rescript/runtime/lib/es6/Primitive_int.js
70
+ function min(x, y) {
71
+ if (x < y) {
72
+ return x;
73
+ } else {
74
+ return y;
75
+ }
76
+ }
77
+ function mod_(x, y) {
78
+ if (y === 0) {
79
+ throw {
80
+ RE_EXN_ID: "Division_by_zero",
81
+ Error: new Error()
82
+ };
83
+ }
84
+ return x % y;
85
+ }
86
+
87
+ // ../../node_modules/@rescript/runtime/lib/es6/Primitive_exceptions.js
88
+ var idMap = {};
89
+ function create(str) {
90
+ let v = idMap[str];
91
+ if (v !== void 0) {
92
+ let id = v + 1 | 0;
93
+ idMap[str] = id;
94
+ return str + ("/" + id);
95
+ }
96
+ idMap[str] = 1;
97
+ return str;
98
+ }
99
+
100
+ // ../../node_modules/sury/src/Sury.res.mjs
101
+ var immutableEmpty = {};
102
+ var immutableEmpty$1 = [];
103
+ function capitalize(string4) {
104
+ return string4.slice(0, 1).toUpperCase() + string4.slice(1);
105
+ }
106
+ var copy = ((d2) => ({ ...d2 }));
107
+ function fromString(string4) {
108
+ let _idx = 0;
109
+ while (true) {
110
+ let idx = _idx;
111
+ let match = string4[idx];
112
+ if (match === void 0) {
113
+ return `"` + string4 + `"`;
114
+ }
115
+ switch (match) {
116
+ case '"':
117
+ case "\n":
118
+ return JSON.stringify(string4);
119
+ default:
120
+ _idx = idx + 1 | 0;
121
+ continue;
122
+ }
123
+ }
124
+ }
125
+ function toArray2(path) {
126
+ if (path === "") {
127
+ return [];
128
+ } else {
129
+ return JSON.parse(path.split(`"]["`).join(`","`));
130
+ }
131
+ }
132
+ var vendor = "sury";
133
+ var s = Symbol(vendor);
134
+ var $$Error = /* @__PURE__ */ create("Sury.Error");
135
+ var constField = "const";
136
+ function has(acc, flag) {
137
+ return (acc & flag) !== 0;
138
+ }
139
+ var flags = {
140
+ unknown: 1,
141
+ string: 2,
142
+ number: 4,
143
+ boolean: 8,
144
+ undefined: 16,
145
+ null: 32,
146
+ object: 64,
147
+ array: 128,
148
+ union: 256,
149
+ ref: 512,
150
+ bigint: 1024,
151
+ nan: 2048,
152
+ "function": 4096,
153
+ instance: 8192,
154
+ never: 16384,
155
+ symbol: 32768
156
+ };
157
+ function stringify(unknown2) {
158
+ let tagFlag = flags[typeof unknown2];
159
+ if (tagFlag & 16) {
160
+ return "undefined";
161
+ }
162
+ if (!(tagFlag & 64)) {
163
+ if (tagFlag & 2) {
164
+ return `"` + unknown2 + `"`;
165
+ } else if (tagFlag & 1024) {
166
+ return unknown2 + `n`;
167
+ } else {
168
+ return unknown2.toString();
169
+ }
170
+ }
171
+ if (unknown2 === null) {
172
+ return "null";
173
+ }
174
+ if (Array.isArray(unknown2)) {
175
+ let string4 = "[";
176
+ for (let i = 0, i_finish = unknown2.length; i < i_finish; ++i) {
177
+ if (i !== 0) {
178
+ string4 = string4 + ", ";
179
+ }
180
+ string4 = string4 + stringify(unknown2[i]);
181
+ }
182
+ return string4 + "]";
183
+ }
184
+ if (unknown2.constructor !== Object) {
185
+ return Object.prototype.toString.call(unknown2);
186
+ }
187
+ let keys = Object.keys(unknown2);
188
+ let string$1 = "{ ";
189
+ for (let i$1 = 0, i_finish$1 = keys.length; i$1 < i_finish$1; ++i$1) {
190
+ let key = keys[i$1];
191
+ let value = unknown2[key];
192
+ string$1 = string$1 + key + `: ` + stringify(value) + `; `;
193
+ }
194
+ return string$1 + "}";
195
+ }
196
+ function toExpression(schema3) {
197
+ let tag = schema3.type;
198
+ let $$const = schema3.const;
199
+ let name = schema3.name;
200
+ if (name !== void 0) {
201
+ return name;
202
+ }
203
+ if ($$const !== void 0) {
204
+ return stringify($$const);
205
+ }
206
+ let format = schema3.format;
207
+ let anyOf = schema3.anyOf;
208
+ if (anyOf !== void 0) {
209
+ return anyOf.map(toExpression).join(" | ");
210
+ }
211
+ if (format !== void 0) {
212
+ return format;
213
+ }
214
+ switch (tag) {
215
+ case "nan":
216
+ return "NaN";
217
+ case "object":
218
+ let additionalItems = schema3.additionalItems;
219
+ let properties = schema3.properties;
220
+ let locations = Object.keys(properties);
221
+ if (locations.length === 0) {
222
+ if (typeof additionalItems === "object") {
223
+ return `{ [key: string]: ` + toExpression(additionalItems) + `; }`;
224
+ } else {
225
+ return `{}`;
226
+ }
227
+ } else {
228
+ return `{ ` + locations.map((location) => location + `: ` + toExpression(properties[location]) + `;`).join(" ") + ` }`;
229
+ }
230
+ default:
231
+ if (schema3.b) {
232
+ return tag;
233
+ }
234
+ switch (tag) {
235
+ case "instance":
236
+ return schema3.class.name;
237
+ case "array":
238
+ let additionalItems$1 = schema3.additionalItems;
239
+ let items = schema3.items;
240
+ if (typeof additionalItems$1 !== "object") {
241
+ return `[` + items.map((item) => toExpression(item.schema)).join(", ") + `]`;
242
+ }
243
+ let itemName = toExpression(additionalItems$1);
244
+ return (additionalItems$1.type === "union" ? `(` + itemName + `)` : itemName) + "[]";
245
+ default:
246
+ return tag;
247
+ }
248
+ }
249
+ }
250
+ var SuryError = class extends Error {
251
+ constructor(code, flag, path) {
252
+ super();
253
+ this.flag = flag;
254
+ this.code = code;
255
+ this.path = path;
256
+ }
257
+ };
258
+ var d = Object.defineProperty;
259
+ var p = SuryError.prototype;
260
+ d(p, "message", {
261
+ get() {
262
+ return message(this);
263
+ }
264
+ });
265
+ d(p, "reason", {
266
+ get() {
267
+ return reason(this);
268
+ }
269
+ });
270
+ d(p, "name", { value: "SuryError" });
271
+ d(p, "s", { value: s });
272
+ d(p, "_1", {
273
+ get() {
274
+ return this;
275
+ }
276
+ });
277
+ d(p, "RE_EXN_ID", {
278
+ value: $$Error
279
+ });
280
+ var Schema = function(type) {
281
+ this.type = type;
282
+ };
283
+ var sp = /* @__PURE__ */ Object.create(null);
284
+ d(sp, "with", {
285
+ get() {
286
+ return (fn, ...args) => fn(this, ...args);
287
+ }
288
+ });
289
+ Schema.prototype = sp;
290
+ function getOrRethrow(exn) {
291
+ if (exn && exn.s === s) {
292
+ return exn;
293
+ }
294
+ throw exn;
295
+ }
296
+ function reason(error, nestedLevelOpt) {
297
+ let nestedLevel = nestedLevelOpt !== void 0 ? nestedLevelOpt : 0;
298
+ let reason$1 = error.code;
299
+ if (typeof reason$1 !== "object") {
300
+ return "Encountered unexpected async transform or refine. Use parseAsyncOrThrow operation instead";
301
+ }
302
+ switch (reason$1.TAG) {
303
+ case "OperationFailed":
304
+ return reason$1._0;
305
+ case "InvalidOperation":
306
+ return reason$1.description;
307
+ case "InvalidType":
308
+ let unionErrors = reason$1.unionErrors;
309
+ let m = `Expected ` + toExpression(reason$1.expected) + `, received ` + stringify(reason$1.received);
310
+ if (unionErrors !== void 0) {
311
+ let lineBreak = `
312
+ ` + " ".repeat(nestedLevel << 1);
313
+ let reasonsDict = {};
314
+ for (let idx = 0, idx_finish = unionErrors.length; idx < idx_finish; ++idx) {
315
+ let error$1 = unionErrors[idx];
316
+ let reason$2 = reason(error$1, nestedLevel + 1);
317
+ let nonEmptyPath = error$1.path;
318
+ let location = nonEmptyPath === "" ? "" : `At ` + nonEmptyPath + `: `;
319
+ let line = `- ` + location + reason$2;
320
+ if (!reasonsDict[line]) {
321
+ reasonsDict[line] = 1;
322
+ m = m + lineBreak + line;
323
+ }
324
+ }
325
+ }
326
+ return m;
327
+ case "UnsupportedTransformation":
328
+ return `Unsupported transformation from ` + toExpression(reason$1.from) + ` to ` + toExpression(reason$1.to);
329
+ case "ExcessField":
330
+ return `Unrecognized key "` + reason$1._0 + `"`;
331
+ case "InvalidJsonSchema":
332
+ return toExpression(reason$1._0) + ` is not valid JSON`;
333
+ }
334
+ }
335
+ function message(error) {
336
+ let op = error.flag;
337
+ let text = "Failed ";
338
+ if (op & 2) {
339
+ text = text + "async ";
340
+ }
341
+ text = text + (op & 1 ? op & 4 ? "asserting" : "parsing" : "converting");
342
+ if (op & 8) {
343
+ text = text + " to JSON" + (op & 16 ? " string" : "");
344
+ }
345
+ let nonEmptyPath = error.path;
346
+ let tmp = nonEmptyPath === "" ? "" : ` at ` + nonEmptyPath;
347
+ return text + tmp + `: ` + reason(error, void 0);
348
+ }
349
+ var globalConfig = {
350
+ a: "strip"};
351
+ var shakenRef = "as";
352
+ var shakenTraps = {
353
+ get: (target, prop) => {
354
+ let l = target[shakenRef];
355
+ if (l === void 0) {
356
+ return target[prop];
357
+ }
358
+ if (prop === shakenRef) {
359
+ return target[prop];
360
+ }
361
+ let l$1 = valFromOption(l);
362
+ let message2 = `Schema S.` + l$1 + ` is not enabled. To start using it, add S.enable` + capitalize(l$1) + `() at the project root.`;
363
+ throw new Error(`[Sury] ` + message2);
364
+ }
365
+ };
366
+ function shaken(apiName) {
367
+ let mut = new Schema("never");
368
+ mut[shakenRef] = apiName;
369
+ return new Proxy(mut, shakenTraps);
370
+ }
371
+ var unknown = new Schema("unknown");
372
+ var bool = new Schema("boolean");
373
+ var string = new Schema("string");
374
+ var int = new Schema("number");
375
+ int.format = "int32";
376
+ var float = new Schema("number");
377
+ var unit = new Schema("undefined");
378
+ unit.const = void 0;
379
+ var copyWithoutCache = ((schema3) => {
380
+ let c = new Schema(schema3.type);
381
+ for (let k in schema3) {
382
+ if (k > "a" || k === "$ref" || k === "$defs") {
383
+ c[k] = schema3[k];
384
+ }
385
+ }
386
+ return c;
387
+ });
388
+ function updateOutput(schema3, fn) {
389
+ let root = copyWithoutCache(schema3);
390
+ let mut = root;
391
+ while (mut.to) {
392
+ let next = copyWithoutCache(mut.to);
393
+ mut.to = next;
394
+ mut = next;
395
+ }
396
+ fn(mut);
397
+ return root;
398
+ }
399
+ function embed(b, value) {
400
+ let e = b.g.e;
401
+ let l = e.length;
402
+ e[l] = value;
403
+ return `e[` + l + `]`;
404
+ }
405
+ function inlineConst(b, schema3) {
406
+ let tagFlag = flags[schema3.type];
407
+ let $$const = schema3.const;
408
+ if (tagFlag & 16) {
409
+ return "void 0";
410
+ } else if (tagFlag & 2) {
411
+ return fromString($$const);
412
+ } else if (tagFlag & 1024) {
413
+ return $$const + "n";
414
+ } else if (tagFlag & 45056) {
415
+ return embed(b, schema3.const);
416
+ } else {
417
+ return $$const;
418
+ }
419
+ }
420
+ function inlineLocation(b, location) {
421
+ let key = `"` + location + `"`;
422
+ let i = b.g[key];
423
+ if (i !== void 0) {
424
+ return i;
425
+ }
426
+ let inlinedLocation = fromString(location);
427
+ b.g[key] = inlinedLocation;
428
+ return inlinedLocation;
429
+ }
430
+ function secondAllocate(v) {
431
+ let b = this;
432
+ b.l = b.l + "," + v;
433
+ }
434
+ function initialAllocate(v) {
435
+ let b = this;
436
+ b.l = v;
437
+ b.a = secondAllocate;
438
+ }
439
+ function rootScope(flag, defs) {
440
+ let global2 = {
441
+ c: "",
442
+ l: "",
443
+ a: initialAllocate,
444
+ v: -1,
445
+ o: flag,
446
+ f: "",
447
+ e: [],
448
+ d: defs
449
+ };
450
+ global2.g = global2;
451
+ return global2;
452
+ }
453
+ function allocateScope(b) {
454
+ delete b.a;
455
+ let varsAllocation = b.l;
456
+ if (varsAllocation === "") {
457
+ return b.f + b.c;
458
+ } else {
459
+ return b.f + `let ` + varsAllocation + `;` + b.c;
460
+ }
461
+ }
462
+ function varWithoutAllocation(global2) {
463
+ let newCounter = global2.v + 1;
464
+ global2.v = newCounter;
465
+ return `v` + newCounter;
466
+ }
467
+ function _var(_b) {
468
+ return this.i;
469
+ }
470
+ function _notVar(b) {
471
+ let val2 = this;
472
+ let v = varWithoutAllocation(b.g);
473
+ let i = val2.i;
474
+ if (i === "") {
475
+ val2.b.a(v);
476
+ } else if (b.a !== void 0) {
477
+ b.a(v + `=` + i);
478
+ } else {
479
+ b.c = b.c + (v + `=` + i + `;`);
480
+ b.g.a(v);
481
+ }
482
+ val2.v = _var;
483
+ val2.i = v;
484
+ return v;
485
+ }
486
+ function allocateVal(b, schema3) {
487
+ let v = varWithoutAllocation(b.g);
488
+ b.a(v);
489
+ return {
490
+ b,
491
+ v: _var,
492
+ i: v,
493
+ f: 0,
494
+ type: schema3.type
495
+ };
496
+ }
497
+ function val(b, initial, schema3) {
498
+ return {
499
+ b,
500
+ v: _notVar,
501
+ i: initial,
502
+ f: 0,
503
+ type: schema3.type
504
+ };
505
+ }
506
+ function constVal(b, schema3) {
507
+ return {
508
+ b,
509
+ v: _notVar,
510
+ i: inlineConst(b, schema3),
511
+ f: 0,
512
+ type: schema3.type,
513
+ const: schema3.const
514
+ };
515
+ }
516
+ function asyncVal(b, initial) {
517
+ return {
518
+ b,
519
+ v: _notVar,
520
+ i: initial,
521
+ f: 2,
522
+ type: "unknown"
523
+ };
524
+ }
525
+ function objectJoin(inlinedLocation, value) {
526
+ return inlinedLocation + `:` + value + `,`;
527
+ }
528
+ function arrayJoin(_inlinedLocation, value) {
529
+ return value + ",";
530
+ }
531
+ function make(b, isArray) {
532
+ return {
533
+ b,
534
+ v: _notVar,
535
+ i: "",
536
+ f: 0,
537
+ type: isArray ? "array" : "object",
538
+ properties: {},
539
+ additionalItems: "strict",
540
+ j: isArray ? arrayJoin : objectJoin,
541
+ c: 0,
542
+ r: ""
543
+ };
544
+ }
545
+ function add(objectVal, location, val2) {
546
+ let inlinedLocation = inlineLocation(objectVal.b, location);
547
+ objectVal.properties[location] = val2;
548
+ if (val2.f & 2) {
549
+ objectVal.r = objectVal.r + val2.i + ",";
550
+ objectVal.i = objectVal.i + objectVal.j(inlinedLocation, `a[` + objectVal.c++ + `]`);
551
+ } else {
552
+ objectVal.i = objectVal.i + objectVal.j(inlinedLocation, val2.i);
553
+ }
554
+ }
555
+ function complete(objectVal, isArray) {
556
+ objectVal.i = isArray ? "[" + objectVal.i + "]" : "{" + objectVal.i + "}";
557
+ if (objectVal.c) {
558
+ objectVal.f = objectVal.f | 2;
559
+ objectVal.i = `Promise.all([` + objectVal.r + `]).then(a=>(` + objectVal.i + `))`;
560
+ }
561
+ objectVal.additionalItems = "strict";
562
+ return objectVal;
563
+ }
564
+ function addKey(b, input, key, val2) {
565
+ return input.v(b) + `[` + key + `]=` + val2.i;
566
+ }
567
+ function set(b, input, val2) {
568
+ if (input === val2) {
569
+ return "";
570
+ }
571
+ let inputVar = input.v(b);
572
+ let match = input.f & 2;
573
+ let match$1 = val2.f & 2;
574
+ if (match) {
575
+ if (!match$1) {
576
+ return inputVar + `=Promise.resolve(` + val2.i + `)`;
577
+ }
578
+ } else if (match$1) {
579
+ input.f = input.f | 2;
580
+ return inputVar + `=` + val2.i;
581
+ }
582
+ return inputVar + `=` + val2.i;
583
+ }
584
+ function get(b, targetVal, location) {
585
+ let properties = targetVal.properties;
586
+ let val2 = properties[location];
587
+ if (val2 !== void 0) {
588
+ return val2;
589
+ }
590
+ let schema3 = targetVal.additionalItems;
591
+ let schema$1;
592
+ if (schema3 === "strip" || schema3 === "strict") {
593
+ if (schema3 === "strip") {
594
+ throw new Error(`[Sury] The schema doesn't have additional items`);
595
+ }
596
+ throw new Error(`[Sury] The schema doesn't have additional items`);
597
+ } else {
598
+ schema$1 = schema3;
599
+ }
600
+ let val$1 = {
601
+ b,
602
+ v: _notVar,
603
+ i: targetVal.v(b) + (`[` + fromString(location) + `]`),
604
+ f: 0,
605
+ type: schema$1.type
606
+ };
607
+ properties[location] = val$1;
608
+ return val$1;
609
+ }
610
+ function setInlined(b, input, inlined) {
611
+ return input.v(b) + `=` + inlined;
612
+ }
613
+ function map(inlinedFn, input) {
614
+ return {
615
+ b: input.b,
616
+ v: _notVar,
617
+ i: inlinedFn + `(` + input.i + `)`,
618
+ f: 0,
619
+ type: "unknown"
620
+ };
621
+ }
622
+ function $$throw(b, code, path) {
623
+ throw new SuryError(code, b.g.o, path);
624
+ }
625
+ function failWithArg(b, path, fn, arg) {
626
+ return embed(b, (arg2) => $$throw(b, fn(arg2), path)) + `(` + arg + `)`;
627
+ }
628
+ function withPathPrepend(b, input, path, maybeDynamicLocationVar, appendSafe, fn) {
629
+ if (path === "" && maybeDynamicLocationVar === void 0) {
630
+ return fn(b, input, path);
631
+ }
632
+ try {
633
+ let $$catch = (b2, errorVar2) => {
634
+ b2.c = errorVar2 + `.path=` + fromString(path) + `+` + (maybeDynamicLocationVar !== void 0 ? `'["'+` + maybeDynamicLocationVar + `+'"]'+` : "") + errorVar2 + `.path`;
635
+ };
636
+ let fn$1 = (b2) => fn(b2, input, "");
637
+ let prevCode = b.c;
638
+ b.c = "";
639
+ let errorVar = varWithoutAllocation(b.g);
640
+ let maybeResolveVal = $$catch(b, errorVar);
641
+ let catchCode = `if(` + (errorVar + `&&` + errorVar + `.s===s`) + `){` + b.c;
642
+ b.c = "";
643
+ let bb = {
644
+ c: "",
645
+ l: "",
646
+ a: initialAllocate,
647
+ f: "",
648
+ g: b.g
649
+ };
650
+ let fnOutput = fn$1(bb);
651
+ b.c = b.c + allocateScope(bb);
652
+ let isNoop = fnOutput.i === input.i && b.c === "";
653
+ if (appendSafe !== void 0) ;
654
+ if (isNoop) {
655
+ return fnOutput;
656
+ }
657
+ let isAsync2 = fnOutput.f & 2;
658
+ let output = input === fnOutput ? input : appendSafe !== void 0 ? fnOutput : {
659
+ b,
660
+ v: _notVar,
661
+ i: "",
662
+ f: isAsync2 ? 2 : 0,
663
+ type: "unknown"
664
+ };
665
+ let catchCode$1 = maybeResolveVal !== void 0 ? (catchLocation) => catchCode + (catchLocation === 1 ? `return ` + maybeResolveVal.i : set(b, output, maybeResolveVal)) + (`}else{throw ` + errorVar + `}`) : (param) => catchCode + `}throw ` + errorVar;
666
+ b.c = prevCode + (`try{` + b.c + (isAsync2 ? setInlined(b, output, fnOutput.i + `.catch(` + errorVar + `=>{` + catchCode$1(1) + `})`) : set(b, output, fnOutput)) + `}catch(` + errorVar + `){` + catchCode$1(0) + `}`);
667
+ return output;
668
+ } catch (exn) {
669
+ let error = getOrRethrow(exn);
670
+ throw new SuryError(error.code, error.flag, path + "[]" + error.path);
671
+ }
672
+ }
673
+ function validation(b, inputVar, schema3, negative) {
674
+ let eq = negative ? "!==" : "===";
675
+ let and_ = negative ? "||" : "&&";
676
+ let exp = negative ? "!" : "";
677
+ let tag = schema3.type;
678
+ let tagFlag = flags[tag];
679
+ if (tagFlag & 2048) {
680
+ return exp + (`Number.isNaN(` + inputVar + `)`);
681
+ }
682
+ if (constField in schema3) {
683
+ return inputVar + eq + inlineConst(b, schema3);
684
+ }
685
+ if (tagFlag & 4) {
686
+ return `typeof ` + inputVar + eq + `"` + tag + `"`;
687
+ }
688
+ if (tagFlag & 64) {
689
+ return `typeof ` + inputVar + eq + `"` + tag + `"` + and_ + exp + inputVar;
690
+ }
691
+ if (tagFlag & 128) {
692
+ return exp + `Array.isArray(` + inputVar + `)`;
693
+ }
694
+ if (!(tagFlag & 8192)) {
695
+ return `typeof ` + inputVar + eq + `"` + tag + `"`;
696
+ }
697
+ let c = inputVar + ` instanceof ` + embed(b, schema3.class);
698
+ if (negative) {
699
+ return `!(` + c + `)`;
700
+ } else {
701
+ return c;
702
+ }
703
+ }
704
+ function refinement(b, inputVar, schema3, negative) {
705
+ let eq = negative ? "!==" : "===";
706
+ let and_ = negative ? "||" : "&&";
707
+ let not_ = negative ? "" : "!";
708
+ let lt = negative ? ">" : "<";
709
+ let gt = negative ? "<" : ">";
710
+ let match = schema3.type;
711
+ let tag;
712
+ let exit = 0;
713
+ let match$1 = schema3.const;
714
+ if (match$1 !== void 0) {
715
+ return "";
716
+ }
717
+ let match$2 = schema3.format;
718
+ if (match$2 !== void 0) {
719
+ switch (match$2) {
720
+ case "int32":
721
+ return and_ + inputVar + lt + `2147483647` + and_ + inputVar + gt + `-2147483648` + and_ + inputVar + `%1` + eq + `0`;
722
+ case "port":
723
+ case "json":
724
+ exit = 2;
725
+ break;
726
+ }
727
+ } else {
728
+ exit = 2;
729
+ }
730
+ if (exit === 2) {
731
+ switch (match) {
732
+ case "number":
733
+ {
734
+ return and_ + not_ + `Number.isNaN(` + inputVar + `)`;
735
+ }
736
+ case "array":
737
+ case "object":
738
+ tag = match;
739
+ break;
740
+ default:
741
+ return "";
742
+ }
743
+ }
744
+ let additionalItems = schema3.additionalItems;
745
+ let items = schema3.items;
746
+ let length2 = items.length;
747
+ let code = tag === "array" ? additionalItems === "strip" || additionalItems === "strict" ? additionalItems === "strip" ? and_ + inputVar + `.length` + gt + length2 : and_ + inputVar + `.length` + eq + length2 : "" : additionalItems === "strip" ? "" : and_ + not_ + `Array.isArray(` + inputVar + `)`;
748
+ for (let idx = 0, idx_finish = items.length; idx < idx_finish; ++idx) {
749
+ let match$3 = items[idx];
750
+ let location = match$3.location;
751
+ let item = match$3.schema;
752
+ let itemCode;
753
+ if (constField in item || schema3.unnest) {
754
+ let inlinedLocation = inlineLocation(b, location);
755
+ itemCode = validation(b, inputVar + (`[` + inlinedLocation + `]`), item, negative);
756
+ } else if (item.items) {
757
+ let inlinedLocation$1 = inlineLocation(b, location);
758
+ let inputVar$1 = inputVar + (`[` + inlinedLocation$1 + `]`);
759
+ itemCode = validation(b, inputVar$1, item, negative) + refinement(b, inputVar$1, item, negative);
760
+ } else {
761
+ itemCode = "";
762
+ }
763
+ if (itemCode !== "") {
764
+ code = code + and_ + itemCode;
765
+ }
766
+ }
767
+ return code;
768
+ }
769
+ function makeRefinedOf(b, input, schema3) {
770
+ let mut = {
771
+ b,
772
+ v: input.v,
773
+ i: input.i,
774
+ f: input.f,
775
+ type: schema3.type
776
+ };
777
+ let loop = (mut2, schema4) => {
778
+ if (constField in schema4) {
779
+ mut2.const = schema4.const;
780
+ }
781
+ let items = schema4.items;
782
+ if (items === void 0) {
783
+ return;
784
+ }
785
+ let properties = {};
786
+ items.forEach((item) => {
787
+ let schema5 = item.schema;
788
+ let isConst = constField in schema5;
789
+ if (!(isConst || schema5.items)) {
790
+ return;
791
+ }
792
+ let tmp;
793
+ if (isConst) {
794
+ tmp = inlineConst(b, schema5);
795
+ } else {
796
+ let inlinedLocation = inlineLocation(b, item.location);
797
+ tmp = mut2.v(b) + (`[` + inlinedLocation + `]`);
798
+ }
799
+ let mut$1 = {
800
+ b: mut2.b,
801
+ v: _notVar,
802
+ i: tmp,
803
+ f: 0,
804
+ type: schema5.type
805
+ };
806
+ loop(mut$1, schema5);
807
+ properties[item.location] = mut$1;
808
+ });
809
+ mut2.properties = properties;
810
+ mut2.additionalItems = unknown;
811
+ };
812
+ loop(mut, schema3);
813
+ return mut;
814
+ }
815
+ function typeFilterCode(b, schema3, input, path) {
816
+ if (schema3.noValidation || flags[schema3.type] & 17153) {
817
+ return "";
818
+ }
819
+ let inputVar = input.v(b);
820
+ return `if(` + validation(b, inputVar, schema3, true) + refinement(b, inputVar, schema3, true) + `){` + failWithArg(b, path, (input2) => ({
821
+ TAG: "InvalidType",
822
+ expected: schema3,
823
+ received: input2
824
+ }), inputVar) + `}`;
825
+ }
826
+ function unsupportedTransform(b, from, target, path) {
827
+ return $$throw(b, {
828
+ TAG: "UnsupportedTransformation",
829
+ from,
830
+ to: target
831
+ }, path);
832
+ }
833
+ function noopOperation(i) {
834
+ return i;
835
+ }
836
+ function setHas(has2, tag) {
837
+ has2[tag === "union" || tag === "ref" ? "unknown" : tag] = true;
838
+ }
839
+ var jsonName = `JSON`;
840
+ var jsonString = shaken("jsonString");
841
+ function inputToString(b, input) {
842
+ return val(b, `""+` + input.i, string);
843
+ }
844
+ function parse(prevB, schema3, inputArg, path) {
845
+ let b = {
846
+ c: "",
847
+ l: "",
848
+ a: initialAllocate,
849
+ f: "",
850
+ g: prevB.g
851
+ };
852
+ if (schema3.$defs) {
853
+ b.g.d = schema3.$defs;
854
+ }
855
+ let input = inputArg;
856
+ let isFromLiteral = constField in input;
857
+ let isSchemaLiteral = constField in schema3;
858
+ let isSameTag = input.type === schema3.type;
859
+ let schemaTagFlag = flags[schema3.type];
860
+ let inputTagFlag = flags[input.type];
861
+ let isUnsupported = false;
862
+ if (!(schemaTagFlag & 257 || schema3.format === "json")) {
863
+ if (schema3.name === jsonName && !(inputTagFlag & 1)) {
864
+ if (!(inputTagFlag & 14)) {
865
+ if (inputTagFlag & 1024) {
866
+ input = inputToString(b, input);
867
+ } else {
868
+ isUnsupported = true;
869
+ }
870
+ }
871
+ } else if (isSchemaLiteral) {
872
+ if (isFromLiteral) {
873
+ if (input.const !== schema3.const) {
874
+ input = constVal(b, schema3);
875
+ }
876
+ } else if (inputTagFlag & 2 && schemaTagFlag & 3132) {
877
+ let inputVar = input.v(b);
878
+ b.f = schema3.noValidation ? "" : input.i + `==="` + schema3.const + `"||` + failWithArg(b, path, (input2) => ({
879
+ TAG: "InvalidType",
880
+ expected: schema3,
881
+ received: input2
882
+ }), inputVar) + `;`;
883
+ input = constVal(b, schema3);
884
+ } else if (schema3.noValidation) {
885
+ input = constVal(b, schema3);
886
+ } else {
887
+ b.f = typeFilterCode(prevB, schema3, input, path);
888
+ input.type = schema3.type;
889
+ input.const = schema3.const;
890
+ }
891
+ } else if (isFromLiteral && !isSchemaLiteral) {
892
+ if (!isSameTag) {
893
+ if (schemaTagFlag & 2 && inputTagFlag & 3132) {
894
+ let $$const = "" + input.const;
895
+ input = {
896
+ b,
897
+ v: _notVar,
898
+ i: `"` + $$const + `"`,
899
+ f: 0,
900
+ type: "string",
901
+ const: $$const
902
+ };
903
+ } else {
904
+ isUnsupported = true;
905
+ }
906
+ }
907
+ } else if (inputTagFlag & 1) {
908
+ let ref = schema3.$ref;
909
+ if (ref !== void 0) {
910
+ let defs = b.g.d;
911
+ let identifier = ref.slice(8);
912
+ let def = defs[identifier];
913
+ let flag = schema3.noValidation ? (b.g.o | 1) ^ 1 : b.g.o;
914
+ let fn = def[flag];
915
+ let recOperation;
916
+ if (fn !== void 0) {
917
+ let fn$1 = valFromOption(fn);
918
+ recOperation = fn$1 === 0 ? embed(b, def) + (`[` + flag + `]`) : embed(b, fn$1);
919
+ } else {
920
+ def[flag] = 0;
921
+ let fn$2 = internalCompile(def, flag, b.g.d);
922
+ def[flag] = fn$2;
923
+ recOperation = embed(b, fn$2);
924
+ }
925
+ input = withPathPrepend(b, input, path, void 0, void 0, (param, input2, param$1) => {
926
+ let output = map(recOperation, input2);
927
+ if (def.isAsync === void 0) {
928
+ let defsMut = copy(defs);
929
+ defsMut[identifier] = unknown;
930
+ isAsyncInternal(def, defsMut);
931
+ }
932
+ if (def.isAsync) {
933
+ output.f = output.f | 2;
934
+ }
935
+ return output;
936
+ });
937
+ input.v(b);
938
+ } else {
939
+ if (b.g.o & 1) {
940
+ b.f = typeFilterCode(prevB, schema3, input, path);
941
+ }
942
+ let refined = makeRefinedOf(b, input, schema3);
943
+ input.type = refined.type;
944
+ input.i = refined.i;
945
+ input.v = refined.v;
946
+ input.additionalItems = refined.additionalItems;
947
+ input.properties = refined.properties;
948
+ if (constField in refined) {
949
+ input.const = refined.const;
950
+ }
951
+ }
952
+ } else if (schemaTagFlag & 2 && inputTagFlag & 1036) {
953
+ input = inputToString(b, input);
954
+ } else if (!isSameTag) {
955
+ if (inputTagFlag & 2) {
956
+ let inputVar$1 = input.v(b);
957
+ if (schemaTagFlag & 8) {
958
+ let output = allocateVal(b, schema3);
959
+ b.c = b.c + (`(` + output.i + `=` + inputVar$1 + `==="true")||` + inputVar$1 + `==="false"||` + failWithArg(b, path, (input2) => ({
960
+ TAG: "InvalidType",
961
+ expected: schema3,
962
+ received: input2
963
+ }), inputVar$1) + `;`);
964
+ input = output;
965
+ } else if (schemaTagFlag & 4) {
966
+ let output$1 = val(b, `+` + inputVar$1, schema3);
967
+ let outputVar = output$1.v(b);
968
+ let match = schema3.format;
969
+ b.c = b.c + (match !== void 0 ? `(` + refinement(b, outputVar, schema3, true).slice(2) + `)` : `Number.isNaN(` + outputVar + `)`) + (`&&` + failWithArg(b, path, (input2) => ({
970
+ TAG: "InvalidType",
971
+ expected: schema3,
972
+ received: input2
973
+ }), inputVar$1) + `;`);
974
+ input = output$1;
975
+ } else if (schemaTagFlag & 1024) {
976
+ let output$2 = allocateVal(b, schema3);
977
+ b.c = b.c + (`try{` + output$2.i + `=BigInt(` + inputVar$1 + `)}catch(_){` + failWithArg(b, path, (input2) => ({
978
+ TAG: "InvalidType",
979
+ expected: schema3,
980
+ received: input2
981
+ }), inputVar$1) + `}`);
982
+ input = output$2;
983
+ } else {
984
+ isUnsupported = true;
985
+ }
986
+ } else if (inputTagFlag & 4 && schemaTagFlag & 1024) {
987
+ input = val(b, `BigInt(` + input.i + `)`, schema3);
988
+ } else {
989
+ isUnsupported = true;
990
+ }
991
+ }
992
+ }
993
+ if (isUnsupported) {
994
+ unsupportedTransform(b, input, schema3, path);
995
+ }
996
+ let compiler2 = schema3.compiler;
997
+ if (compiler2 !== void 0) {
998
+ input = compiler2(b, input, schema3, path);
999
+ }
1000
+ if (input.t !== true) {
1001
+ let refiner = schema3.refiner;
1002
+ if (refiner !== void 0) {
1003
+ b.c = b.c + refiner(b, input.v(b), schema3, path);
1004
+ }
1005
+ }
1006
+ let to2 = schema3.to;
1007
+ if (to2 !== void 0) {
1008
+ let parser2 = schema3.parser;
1009
+ if (parser2 !== void 0) {
1010
+ input = parser2(b, input, schema3, path);
1011
+ }
1012
+ if (input.t !== true) {
1013
+ input = parse(b, to2, input, path);
1014
+ }
1015
+ }
1016
+ prevB.c = prevB.c + allocateScope(b);
1017
+ return input;
1018
+ }
1019
+ function isAsyncInternal(schema3, defs) {
1020
+ try {
1021
+ let b = rootScope(2, defs);
1022
+ let input = {
1023
+ b,
1024
+ v: _var,
1025
+ i: "i",
1026
+ f: 0,
1027
+ type: "unknown"
1028
+ };
1029
+ let output = parse(b, schema3, input, "");
1030
+ let isAsync2 = has(output.f, 2);
1031
+ schema3.isAsync = isAsync2;
1032
+ return isAsync2;
1033
+ } catch (exn) {
1034
+ getOrRethrow(exn);
1035
+ return false;
1036
+ }
1037
+ }
1038
+ function internalCompile(schema3, flag, defs) {
1039
+ let b = rootScope(flag, defs);
1040
+ if (flag & 8) {
1041
+ let output = reverse(schema3);
1042
+ jsonableValidation(output, output, "", flag);
1043
+ }
1044
+ let input = {
1045
+ b,
1046
+ v: _var,
1047
+ i: "i",
1048
+ f: 0,
1049
+ type: "unknown"
1050
+ };
1051
+ let schema$1 = flag & 4 ? updateOutput(schema3, (mut) => {
1052
+ let t = new Schema(unit.type);
1053
+ t.const = unit.const;
1054
+ t.noValidation = true;
1055
+ mut.to = t;
1056
+ }) : flag & 16 ? updateOutput(schema3, (mut) => {
1057
+ mut.to = jsonString;
1058
+ }) : schema3;
1059
+ let output$1 = parse(b, schema$1, input, "");
1060
+ let code = allocateScope(b);
1061
+ let isAsync2 = has(output$1.f, 2);
1062
+ schema$1.isAsync = isAsync2;
1063
+ if (code === "" && output$1 === input && !(flag & 2)) {
1064
+ return noopOperation;
1065
+ }
1066
+ let inlinedOutput = output$1.i;
1067
+ if (flag & 2 && !isAsync2 && !defs) {
1068
+ inlinedOutput = `Promise.resolve(` + inlinedOutput + `)`;
1069
+ }
1070
+ let inlinedFunction = `i=>{` + code + `return ` + inlinedOutput + `}`;
1071
+ let ctxVarValue1 = b.g.e;
1072
+ return new Function("e", "s", `return ` + inlinedFunction)(ctxVarValue1, s);
1073
+ }
1074
+ function reverse(schema3) {
1075
+ let reversedHead;
1076
+ let current = schema3;
1077
+ while (current) {
1078
+ let mut = copyWithoutCache(current);
1079
+ let next = mut.to;
1080
+ let to2 = reversedHead;
1081
+ if (to2 !== void 0) {
1082
+ mut.to = to2;
1083
+ } else {
1084
+ delete mut.to;
1085
+ }
1086
+ let parser2 = mut.parser;
1087
+ let serializer = mut.serializer;
1088
+ if (serializer !== void 0) {
1089
+ mut.parser = serializer;
1090
+ } else {
1091
+ delete mut.parser;
1092
+ }
1093
+ if (parser2 !== void 0) {
1094
+ mut.serializer = parser2;
1095
+ } else {
1096
+ delete mut.serializer;
1097
+ }
1098
+ let fromDefault = mut.fromDefault;
1099
+ let $$default = mut.default;
1100
+ if ($$default !== void 0) {
1101
+ mut.fromDefault = $$default;
1102
+ } else {
1103
+ delete mut.fromDefault;
1104
+ }
1105
+ if (fromDefault !== void 0) {
1106
+ mut.default = fromDefault;
1107
+ } else {
1108
+ delete mut.default;
1109
+ }
1110
+ let items = mut.items;
1111
+ if (items !== void 0) {
1112
+ let properties = {};
1113
+ let newItems = new Array(items.length);
1114
+ for (let idx = 0, idx_finish = items.length; idx < idx_finish; ++idx) {
1115
+ let item = items[idx];
1116
+ let reversed_schema = reverse(item.schema);
1117
+ let reversed_location = item.location;
1118
+ let reversed = {
1119
+ schema: reversed_schema,
1120
+ location: reversed_location
1121
+ };
1122
+ if (item.r) {
1123
+ reversed.r = item.r;
1124
+ }
1125
+ properties[item.location] = reversed_schema;
1126
+ newItems[idx] = reversed;
1127
+ }
1128
+ mut.items = newItems;
1129
+ let match = mut.properties;
1130
+ if (match !== void 0) {
1131
+ mut.properties = properties;
1132
+ }
1133
+ }
1134
+ if (typeof mut.additionalItems === "object") {
1135
+ mut.additionalItems = reverse(mut.additionalItems);
1136
+ }
1137
+ let anyOf = mut.anyOf;
1138
+ if (anyOf !== void 0) {
1139
+ let has2 = {};
1140
+ let newAnyOf = [];
1141
+ for (let idx$1 = 0, idx_finish$1 = anyOf.length; idx$1 < idx_finish$1; ++idx$1) {
1142
+ let s2 = anyOf[idx$1];
1143
+ let reversed$1 = reverse(s2);
1144
+ newAnyOf.push(reversed$1);
1145
+ setHas(has2, reversed$1.type);
1146
+ }
1147
+ mut.has = has2;
1148
+ mut.anyOf = newAnyOf;
1149
+ }
1150
+ let defs = mut.$defs;
1151
+ if (defs !== void 0) {
1152
+ let reversedDefs = {};
1153
+ for (let idx$2 = 0, idx_finish$2 = Object.keys(defs).length; idx$2 < idx_finish$2; ++idx$2) {
1154
+ let key = Object.keys(defs)[idx$2];
1155
+ reversedDefs[key] = reverse(defs[key]);
1156
+ }
1157
+ mut.$defs = reversedDefs;
1158
+ }
1159
+ reversedHead = mut;
1160
+ current = next;
1161
+ }
1162
+ return reversedHead;
1163
+ }
1164
+ function jsonableValidation(output, parent, path, flag) {
1165
+ let tagFlag = flags[output.type];
1166
+ if (tagFlag & 48129 || tagFlag & 16 && parent.type !== "object") {
1167
+ throw new SuryError({
1168
+ TAG: "InvalidJsonSchema",
1169
+ _0: parent
1170
+ }, flag, path);
1171
+ }
1172
+ if (tagFlag & 256) {
1173
+ output.anyOf.forEach((s2) => jsonableValidation(s2, parent, path, flag));
1174
+ return;
1175
+ }
1176
+ if (!(tagFlag & 192)) {
1177
+ return;
1178
+ }
1179
+ let additionalItems = output.additionalItems;
1180
+ if (additionalItems === "strip" || additionalItems === "strict") ; else {
1181
+ jsonableValidation(additionalItems, parent, path, flag);
1182
+ }
1183
+ let p2 = output.properties;
1184
+ if (p2 !== void 0) {
1185
+ let keys = Object.keys(p2);
1186
+ for (let idx = 0, idx_finish = keys.length; idx < idx_finish; ++idx) {
1187
+ let key = keys[idx];
1188
+ jsonableValidation(p2[key], parent, path, flag);
1189
+ }
1190
+ return;
1191
+ }
1192
+ output.items.forEach((item) => jsonableValidation(item.schema, output, path + (`[` + fromString(item.location) + `]`), flag));
1193
+ }
1194
+ function getOutputSchema(_schema) {
1195
+ while (true) {
1196
+ let schema3 = _schema;
1197
+ let to2 = schema3.to;
1198
+ if (to2 === void 0) {
1199
+ return schema3;
1200
+ }
1201
+ _schema = to2;
1202
+ continue;
1203
+ }
1204
+ }
1205
+ function operationFn(s2, o) {
1206
+ if (o in s2) {
1207
+ return s2[o];
1208
+ }
1209
+ let f = internalCompile(s2, o, 0);
1210
+ s2[o] = f;
1211
+ return f;
1212
+ }
1213
+ d(sp, "~standard", {
1214
+ get: function() {
1215
+ let schema3 = this;
1216
+ return {
1217
+ version: 1,
1218
+ vendor,
1219
+ validate: (input) => {
1220
+ try {
1221
+ return {
1222
+ value: operationFn(schema3, 1)(input)
1223
+ };
1224
+ } catch (exn) {
1225
+ let error = getOrRethrow(exn);
1226
+ return {
1227
+ issues: [{
1228
+ message: reason(error, void 0),
1229
+ path: error.path === "" ? void 0 : toArray2(error.path)
1230
+ }]
1231
+ };
1232
+ }
1233
+ }
1234
+ };
1235
+ }
1236
+ });
1237
+ var $$null = new Schema("null");
1238
+ $$null.const = null;
1239
+ function parse$1(value) {
1240
+ if (value === null) {
1241
+ return $$null;
1242
+ }
1243
+ let $$typeof = typeof value;
1244
+ let schema3;
1245
+ if ($$typeof === "object") {
1246
+ let i = new Schema("instance");
1247
+ i.class = value.constructor;
1248
+ schema3 = i;
1249
+ } else {
1250
+ schema3 = $$typeof === "undefined" ? unit : $$typeof === "number" ? Number.isNaN(value) ? new Schema("nan") : new Schema($$typeof) : new Schema($$typeof);
1251
+ }
1252
+ schema3.const = value;
1253
+ return schema3;
1254
+ }
1255
+ var defsPath = `#/$defs/`;
1256
+ function appendRefiner(maybeExistingRefiner, refiner) {
1257
+ if (maybeExistingRefiner !== void 0) {
1258
+ return (b, inputVar, selfSchema, path) => maybeExistingRefiner(b, inputVar, selfSchema, path) + refiner(b, inputVar, selfSchema, path);
1259
+ } else {
1260
+ return refiner;
1261
+ }
1262
+ }
1263
+ var nullAsUnit = new Schema("null");
1264
+ nullAsUnit.const = null;
1265
+ nullAsUnit.to = unit;
1266
+ function neverBuilder(b, input, selfSchema, path) {
1267
+ b.c = b.c + failWithArg(b, path, (input2) => ({
1268
+ TAG: "InvalidType",
1269
+ expected: selfSchema,
1270
+ received: input2
1271
+ }), input.i) + ";";
1272
+ return input;
1273
+ }
1274
+ var never = new Schema("never");
1275
+ never.compiler = neverBuilder;
1276
+ var nestedLoc = "BS_PRIVATE_NESTED_SOME_NONE";
1277
+ function getItemCode(b, schema3, input, output, deopt, path) {
1278
+ try {
1279
+ let globalFlag = b.g.o;
1280
+ if (deopt) {
1281
+ b.g.o = globalFlag | 1;
1282
+ }
1283
+ let bb = {
1284
+ c: "",
1285
+ l: "",
1286
+ a: initialAllocate,
1287
+ f: "",
1288
+ g: b.g
1289
+ };
1290
+ let input$1 = deopt ? copy(input) : makeRefinedOf(bb, input, schema3);
1291
+ let itemOutput = parse(bb, schema3, input$1, path);
1292
+ if (itemOutput !== input$1) {
1293
+ itemOutput.b = bb;
1294
+ if (itemOutput.f & 2) {
1295
+ output.f = output.f | 2;
1296
+ }
1297
+ bb.c = bb.c + (output.v(b) + `=` + itemOutput.i);
1298
+ }
1299
+ b.g.o = globalFlag;
1300
+ return allocateScope(bb);
1301
+ } catch (exn) {
1302
+ return "throw " + embed(b, getOrRethrow(exn));
1303
+ }
1304
+ }
1305
+ function isPriority(tagFlag, byKey) {
1306
+ if (tagFlag & 8320 && "object" in byKey) {
1307
+ return true;
1308
+ } else if (tagFlag & 2048) {
1309
+ return "number" in byKey;
1310
+ } else {
1311
+ return false;
1312
+ }
1313
+ }
1314
+ function isWiderUnionSchema(schemaAnyOf, inputAnyOf) {
1315
+ return inputAnyOf.every((inputSchema, idx) => {
1316
+ let schema3 = schemaAnyOf[idx];
1317
+ if (schema3 !== void 0 && !(flags[inputSchema.type] & 9152) && inputSchema.type === schema3.type) {
1318
+ return inputSchema.const === schema3.const;
1319
+ } else {
1320
+ return false;
1321
+ }
1322
+ });
1323
+ }
1324
+ function compiler(b, input, selfSchema, path) {
1325
+ let schemas = selfSchema.anyOf;
1326
+ let inputAnyOf = input.anyOf;
1327
+ if (inputAnyOf !== void 0) {
1328
+ if (isWiderUnionSchema(schemas, inputAnyOf)) {
1329
+ return input;
1330
+ } else {
1331
+ return unsupportedTransform(b, input, selfSchema, path);
1332
+ }
1333
+ }
1334
+ let fail = (caught2) => embed(b, function() {
1335
+ let args = arguments;
1336
+ return $$throw(b, {
1337
+ TAG: "InvalidType",
1338
+ expected: selfSchema,
1339
+ received: args[0],
1340
+ unionErrors: args.length > 1 ? Array.from(args).slice(1) : void 0
1341
+ }, path);
1342
+ }) + `(` + input.v(b) + caught2 + `)`;
1343
+ let typeValidation = b.g.o & 1;
1344
+ let initialInline = input.i;
1345
+ let deoptIdx = -1;
1346
+ let lastIdx = schemas.length - 1 | 0;
1347
+ let byKey = {};
1348
+ let keys = [];
1349
+ for (let idx = 0; idx <= lastIdx; ++idx) {
1350
+ let target = selfSchema.to;
1351
+ let schema3 = target !== void 0 && !selfSchema.parser && target.type !== "union" ? updateOutput(schemas[idx], (mut) => {
1352
+ let refiner = selfSchema.refiner;
1353
+ if (refiner !== void 0) {
1354
+ mut.refiner = appendRefiner(mut.refiner, refiner);
1355
+ }
1356
+ mut.to = target;
1357
+ }) : schemas[idx];
1358
+ let tag = schema3.type;
1359
+ let tagFlag = flags[tag];
1360
+ if (!(tagFlag & 16 && "fromDefault" in selfSchema)) {
1361
+ if (tagFlag & 17153 || !(flags[input.type] & 1) && input.type !== tag) {
1362
+ deoptIdx = idx;
1363
+ byKey = {};
1364
+ keys = [];
1365
+ } else {
1366
+ let key = tagFlag & 8192 ? schema3.class.name : tag;
1367
+ let arr = byKey[key];
1368
+ if (arr !== void 0) {
1369
+ if (tagFlag & 64 && nestedLoc in schema3.properties) {
1370
+ arr.unshift(schema3);
1371
+ } else if (!(tagFlag & 2096)) {
1372
+ arr.push(schema3);
1373
+ }
1374
+ } else {
1375
+ if (isPriority(tagFlag, byKey)) {
1376
+ keys.unshift(key);
1377
+ } else {
1378
+ keys.push(key);
1379
+ }
1380
+ byKey[key] = [schema3];
1381
+ }
1382
+ }
1383
+ }
1384
+ }
1385
+ let deoptIdx$1 = deoptIdx;
1386
+ let byKey$1 = byKey;
1387
+ let keys$1 = keys;
1388
+ let start = "";
1389
+ let end = "";
1390
+ let caught = "";
1391
+ let exit = false;
1392
+ if (deoptIdx$1 !== -1) {
1393
+ for (let idx$1 = 0; idx$1 <= deoptIdx$1; ++idx$1) {
1394
+ if (!exit) {
1395
+ let schema$1 = schemas[idx$1];
1396
+ let itemCode = getItemCode(b, schema$1, input, input, true, path);
1397
+ if (itemCode) {
1398
+ let errorVar = `e` + idx$1;
1399
+ start = start + (`try{` + itemCode + `}catch(` + errorVar + `){`);
1400
+ end = "}" + end;
1401
+ caught = caught + `,` + errorVar;
1402
+ } else {
1403
+ exit = true;
1404
+ }
1405
+ }
1406
+ }
1407
+ }
1408
+ if (!exit) {
1409
+ let nextElse = false;
1410
+ let noop = "";
1411
+ for (let idx$2 = 0, idx_finish = keys$1.length; idx$2 < idx_finish; ++idx$2) {
1412
+ let schemas$1 = byKey$1[keys$1[idx$2]];
1413
+ let isMultiple = schemas$1.length > 1;
1414
+ let firstSchema = schemas$1[0];
1415
+ let cond = 0;
1416
+ let body;
1417
+ if (isMultiple) {
1418
+ let inputVar = input.v(b);
1419
+ let itemStart = "";
1420
+ let itemEnd = "";
1421
+ let itemNextElse = false;
1422
+ let itemNoop = {
1423
+ contents: ""
1424
+ };
1425
+ let caught$1 = "";
1426
+ let byDiscriminant = {};
1427
+ let itemIdx = 0;
1428
+ let lastIdx$1 = schemas$1.length - 1 | 0;
1429
+ while (itemIdx <= lastIdx$1) {
1430
+ let schema$2 = schemas$1[itemIdx];
1431
+ let itemCond = (constField in schema$2 ? validation(b, inputVar, schema$2, false) : "") + refinement(b, inputVar, schema$2, false).slice(2);
1432
+ let itemCode$1 = getItemCode(b, schema$2, input, input, false, path);
1433
+ if (itemCond) {
1434
+ if (itemCode$1) {
1435
+ let match = byDiscriminant[itemCond];
1436
+ if (match !== void 0) {
1437
+ if (typeof match === "string") {
1438
+ byDiscriminant[itemCond] = [
1439
+ match,
1440
+ itemCode$1
1441
+ ];
1442
+ } else {
1443
+ match.push(itemCode$1);
1444
+ }
1445
+ } else {
1446
+ byDiscriminant[itemCond] = itemCode$1;
1447
+ }
1448
+ } else {
1449
+ itemNoop.contents = itemNoop.contents ? itemNoop.contents + `||` + itemCond : itemCond;
1450
+ }
1451
+ }
1452
+ if (!itemCond || itemIdx === lastIdx$1) {
1453
+ let accedDiscriminants = Object.keys(byDiscriminant);
1454
+ for (let idx$3 = 0, idx_finish$1 = accedDiscriminants.length; idx$3 < idx_finish$1; ++idx$3) {
1455
+ let discrim = accedDiscriminants[idx$3];
1456
+ let if_ = itemNextElse ? "else if" : "if";
1457
+ itemStart = itemStart + if_ + (`(` + discrim + `){`);
1458
+ let code = byDiscriminant[discrim];
1459
+ if (typeof code === "string") {
1460
+ itemStart = itemStart + code + "}";
1461
+ } else {
1462
+ let caught$2 = "";
1463
+ for (let idx$4 = 0, idx_finish$2 = code.length; idx$4 < idx_finish$2; ++idx$4) {
1464
+ let code$1 = code[idx$4];
1465
+ let errorVar$1 = `e` + idx$4;
1466
+ itemStart = itemStart + (`try{` + code$1 + `}catch(` + errorVar$1 + `){`);
1467
+ caught$2 = caught$2 + `,` + errorVar$1;
1468
+ }
1469
+ itemStart = itemStart + fail(caught$2) + "}".repeat(code.length) + "}";
1470
+ }
1471
+ itemNextElse = true;
1472
+ }
1473
+ byDiscriminant = {};
1474
+ }
1475
+ if (!itemCond) {
1476
+ if (itemCode$1) {
1477
+ if (itemNoop.contents) {
1478
+ let if_$1 = itemNextElse ? "else if" : "if";
1479
+ itemStart = itemStart + if_$1 + (`(!(` + itemNoop.contents + `)){`);
1480
+ itemEnd = "}" + itemEnd;
1481
+ itemNoop.contents = "";
1482
+ itemNextElse = false;
1483
+ }
1484
+ let errorVar$2 = `e` + itemIdx;
1485
+ itemStart = itemStart + ((itemNextElse ? "else{" : "") + `try{` + itemCode$1 + `}catch(` + errorVar$2 + `){`);
1486
+ itemEnd = (itemNextElse ? "}" : "") + "}" + itemEnd;
1487
+ caught$1 = caught$1 + `,` + errorVar$2;
1488
+ itemNextElse = false;
1489
+ } else {
1490
+ itemNoop.contents = "";
1491
+ itemIdx = lastIdx$1;
1492
+ }
1493
+ }
1494
+ itemIdx = itemIdx + 1;
1495
+ }
1496
+ cond = (inputVar2) => validation(b, inputVar2, {
1497
+ type: firstSchema.type,
1498
+ parser: 0
1499
+ }, false);
1500
+ if (itemNoop.contents) {
1501
+ if (itemStart) {
1502
+ if (typeValidation) {
1503
+ let if_$2 = itemNextElse ? "else if" : "if";
1504
+ itemStart = itemStart + if_$2 + (`(!(` + itemNoop.contents + `)){` + fail(caught$1) + `}`);
1505
+ }
1506
+ } else {
1507
+ let condBefore = cond;
1508
+ cond = (inputVar2) => condBefore(inputVar2) + (`&&(` + itemNoop.contents + `)`);
1509
+ }
1510
+ } else if (typeValidation && itemStart) {
1511
+ let errorCode = fail(caught$1);
1512
+ itemStart = itemStart + (itemNextElse ? `else{` + errorCode + `}` : errorCode);
1513
+ }
1514
+ body = itemStart + itemEnd;
1515
+ } else {
1516
+ cond = (inputVar) => validation(b, inputVar, firstSchema, false) + refinement(b, inputVar, firstSchema, false);
1517
+ body = getItemCode(b, firstSchema, input, input, false, path);
1518
+ }
1519
+ if (body || isPriority(flags[firstSchema.type], byKey$1)) {
1520
+ let if_$3 = nextElse ? "else if" : "if";
1521
+ start = start + if_$3 + (`(` + cond(input.v(b)) + `){` + body + `}`);
1522
+ nextElse = true;
1523
+ } else if (typeValidation) {
1524
+ let cond$1 = cond(input.v(b));
1525
+ noop = noop ? noop + `||` + cond$1 : cond$1;
1526
+ }
1527
+ }
1528
+ if (typeValidation || deoptIdx$1 === lastIdx) {
1529
+ let errorCode$1 = fail(caught);
1530
+ let tmp;
1531
+ if (noop) {
1532
+ let if_$4 = nextElse ? "else if" : "if";
1533
+ tmp = if_$4 + (`(!(` + noop + `)){` + errorCode$1 + `}`);
1534
+ } else {
1535
+ tmp = nextElse ? `else{` + errorCode$1 + `}` : errorCode$1;
1536
+ }
1537
+ start = start + tmp;
1538
+ }
1539
+ }
1540
+ b.c = b.c + start + end;
1541
+ let o = input.f & 2 ? asyncVal(b, `Promise.resolve(` + input.i + `)`) : input.v === _var ? b.c === "" && input.b.c === "" && (input.b.l === input.i + `=` + initialInline || initialInline === "i") ? (input.b.l = "", input.b.a = initialAllocate, input.v = _notVar, input.i = initialInline, input) : copy(input) : input;
1542
+ o.anyOf = selfSchema.anyOf;
1543
+ let to2 = selfSchema.to;
1544
+ o.type = to2 !== void 0 && to2.type !== "union" ? (o.t = true, getOutputSchema(to2).type) : "union";
1545
+ return o;
1546
+ }
1547
+ function factory(schemas) {
1548
+ let len = schemas.length;
1549
+ if (len === 1) {
1550
+ return schemas[0];
1551
+ }
1552
+ if (len !== 0) {
1553
+ let has2 = {};
1554
+ let anyOf = /* @__PURE__ */ new Set();
1555
+ for (let idx = 0, idx_finish = schemas.length; idx < idx_finish; ++idx) {
1556
+ let schema3 = schemas[idx];
1557
+ if (schema3.type === "union" && schema3.to === void 0) {
1558
+ schema3.anyOf.forEach((item) => {
1559
+ anyOf.add(item);
1560
+ });
1561
+ Object.assign(has2, schema3.has);
1562
+ } else {
1563
+ anyOf.add(schema3);
1564
+ setHas(has2, schema3.type);
1565
+ }
1566
+ }
1567
+ let mut = new Schema("union");
1568
+ mut.anyOf = Array.from(anyOf);
1569
+ mut.compiler = compiler;
1570
+ mut.has = has2;
1571
+ return mut;
1572
+ }
1573
+ throw new Error(`[Sury] S.union requires at least one item`);
1574
+ }
1575
+ function nestedNone() {
1576
+ let itemSchema = parse$1(0);
1577
+ let item = {
1578
+ schema: itemSchema,
1579
+ location: nestedLoc
1580
+ };
1581
+ let properties = {};
1582
+ properties[nestedLoc] = itemSchema;
1583
+ return {
1584
+ type: "object",
1585
+ serializer: (b, param, selfSchema, param$1) => constVal(b, selfSchema.to),
1586
+ additionalItems: "strip",
1587
+ items: [item],
1588
+ properties
1589
+ };
1590
+ }
1591
+ function parser(b, param, selfSchema, param$1) {
1592
+ return val(b, `{` + nestedLoc + `:` + getOutputSchema(selfSchema).items[0].schema.const + `}`, selfSchema.to);
1593
+ }
1594
+ function nestedOption(item) {
1595
+ return updateOutput(item, (mut) => {
1596
+ mut.to = nestedNone();
1597
+ mut.parser = parser;
1598
+ });
1599
+ }
1600
+ function factory$1(item, unitOpt) {
1601
+ let unit$1 = unitOpt !== void 0 ? unitOpt : unit;
1602
+ let match = getOutputSchema(item);
1603
+ let match$1 = match.type;
1604
+ switch (match$1) {
1605
+ case "undefined":
1606
+ return factory([
1607
+ unit$1,
1608
+ nestedOption(item)
1609
+ ]);
1610
+ case "union":
1611
+ let has2 = match.has;
1612
+ let anyOf = match.anyOf;
1613
+ return updateOutput(item, (mut) => {
1614
+ let mutHas = copy(has2);
1615
+ let newAnyOf = [];
1616
+ for (let idx = 0, idx_finish = anyOf.length; idx < idx_finish; ++idx) {
1617
+ let schema3 = anyOf[idx];
1618
+ let match2 = getOutputSchema(schema3);
1619
+ let match$12 = match2.type;
1620
+ let tmp;
1621
+ if (match$12 === "undefined") {
1622
+ mutHas[unit$1.type] = true;
1623
+ newAnyOf.push(unit$1);
1624
+ tmp = nestedOption(schema3);
1625
+ } else {
1626
+ let properties = match2.properties;
1627
+ if (properties !== void 0) {
1628
+ let nestedSchema = properties[nestedLoc];
1629
+ tmp = nestedSchema !== void 0 ? updateOutput(schema3, (mut2) => {
1630
+ let newItem_schema = {
1631
+ type: nestedSchema.type,
1632
+ parser: nestedSchema.parser,
1633
+ const: nestedSchema.const + 1
1634
+ };
1635
+ let newItem = {
1636
+ schema: newItem_schema,
1637
+ location: nestedLoc
1638
+ };
1639
+ let properties2 = {};
1640
+ properties2[nestedLoc] = newItem_schema;
1641
+ mut2.items = [newItem];
1642
+ mut2.properties = properties2;
1643
+ }) : schema3;
1644
+ } else {
1645
+ tmp = schema3;
1646
+ }
1647
+ }
1648
+ newAnyOf.push(tmp);
1649
+ }
1650
+ if (newAnyOf.length === anyOf.length) {
1651
+ mutHas[unit$1.type] = true;
1652
+ newAnyOf.push(unit$1);
1653
+ }
1654
+ mut.anyOf = newAnyOf;
1655
+ mut.has = mutHas;
1656
+ });
1657
+ default:
1658
+ return factory([
1659
+ item,
1660
+ unit$1
1661
+ ]);
1662
+ }
1663
+ }
1664
+ function arrayCompiler(b, input, selfSchema, path) {
1665
+ let item = selfSchema.additionalItems;
1666
+ let inputVar = input.v(b);
1667
+ let iteratorVar = varWithoutAllocation(b.g);
1668
+ let bb = {
1669
+ c: "",
1670
+ l: "",
1671
+ a: initialAllocate,
1672
+ f: "",
1673
+ g: b.g
1674
+ };
1675
+ let itemInput = val(bb, inputVar + `[` + iteratorVar + `]`, unknown);
1676
+ let itemOutput = withPathPrepend(bb, itemInput, path, iteratorVar, void 0, (b2, input2, path2) => parse(b2, item, input2, path2));
1677
+ let itemCode = allocateScope(bb);
1678
+ let isTransformed = itemInput !== itemOutput;
1679
+ let output = isTransformed ? val(b, `new Array(` + inputVar + `.length)`, selfSchema) : input;
1680
+ output.type = selfSchema.type;
1681
+ output.additionalItems = selfSchema.additionalItems;
1682
+ if (isTransformed || itemCode !== "") {
1683
+ b.c = b.c + (`for(let ` + iteratorVar + `=0;` + iteratorVar + `<` + inputVar + `.length;++` + iteratorVar + `){` + itemCode + (isTransformed ? addKey(b, output, iteratorVar, itemOutput) : "") + `}`);
1684
+ }
1685
+ if (itemOutput.f & 2) {
1686
+ return asyncVal(output.b, `Promise.all(` + output.i + `)`);
1687
+ } else {
1688
+ return output;
1689
+ }
1690
+ }
1691
+ function factory$2(item) {
1692
+ let mut = new Schema("array");
1693
+ mut.additionalItems = item;
1694
+ mut.items = immutableEmpty$1;
1695
+ mut.compiler = arrayCompiler;
1696
+ return mut;
1697
+ }
1698
+ function dictCompiler(b, input, selfSchema, path) {
1699
+ let item = selfSchema.additionalItems;
1700
+ let inputVar = input.v(b);
1701
+ let keyVar = varWithoutAllocation(b.g);
1702
+ let bb = {
1703
+ c: "",
1704
+ l: "",
1705
+ a: initialAllocate,
1706
+ f: "",
1707
+ g: b.g
1708
+ };
1709
+ let itemInput = val(bb, inputVar + `[` + keyVar + `]`, unknown);
1710
+ let itemOutput = withPathPrepend(bb, itemInput, path, keyVar, void 0, (b2, input2, path2) => parse(b2, item, input2, path2));
1711
+ let itemCode = allocateScope(bb);
1712
+ let isTransformed = itemInput !== itemOutput;
1713
+ let output = isTransformed ? val(b, "{}", selfSchema) : input;
1714
+ output.type = selfSchema.type;
1715
+ output.additionalItems = selfSchema.additionalItems;
1716
+ if (isTransformed || itemCode !== "") {
1717
+ b.c = b.c + (`for(let ` + keyVar + ` in ` + inputVar + `){` + itemCode + (isTransformed ? addKey(b, output, keyVar, itemOutput) : "") + `}`);
1718
+ }
1719
+ if (!(itemOutput.f & 2)) {
1720
+ return output;
1721
+ }
1722
+ let resolveVar = varWithoutAllocation(b.g);
1723
+ let rejectVar = varWithoutAllocation(b.g);
1724
+ let asyncParseResultVar = varWithoutAllocation(b.g);
1725
+ let counterVar = varWithoutAllocation(b.g);
1726
+ let outputVar = output.v(b);
1727
+ return asyncVal(b, `new Promise((` + resolveVar + `,` + rejectVar + `)=>{let ` + counterVar + `=Object.keys(` + outputVar + `).length;for(let ` + keyVar + ` in ` + outputVar + `){` + outputVar + `[` + keyVar + `].then(` + asyncParseResultVar + `=>{` + outputVar + `[` + keyVar + `]=` + asyncParseResultVar + `;if(` + counterVar + `--===1){` + resolveVar + `(` + outputVar + `)}},` + rejectVar + `)}})`);
1728
+ }
1729
+ function factory$3(item) {
1730
+ let mut = new Schema("object");
1731
+ mut.properties = immutableEmpty;
1732
+ mut.items = immutableEmpty$1;
1733
+ mut.additionalItems = item;
1734
+ mut.compiler = dictCompiler;
1735
+ return mut;
1736
+ }
1737
+ var json = shaken("json");
1738
+ function enableJson() {
1739
+ if (!json[shakenRef]) {
1740
+ return;
1741
+ }
1742
+ delete json.as;
1743
+ let jsonRef = new Schema("ref");
1744
+ jsonRef.$ref = defsPath + jsonName;
1745
+ jsonRef.name = jsonName;
1746
+ json.type = jsonRef.type;
1747
+ json.$ref = jsonRef.$ref;
1748
+ json.name = jsonName;
1749
+ let defs = {};
1750
+ defs[jsonName] = {
1751
+ type: "union",
1752
+ compiler,
1753
+ name: jsonName,
1754
+ has: {
1755
+ string: true,
1756
+ boolean: true,
1757
+ number: true,
1758
+ null: true,
1759
+ object: true,
1760
+ array: true
1761
+ },
1762
+ anyOf: [
1763
+ string,
1764
+ bool,
1765
+ float,
1766
+ $$null,
1767
+ factory$3(jsonRef),
1768
+ factory$2(jsonRef)
1769
+ ]
1770
+ };
1771
+ json.$defs = defs;
1772
+ }
1773
+ function objectStrictModeCheck(b, input, items, selfSchema, path) {
1774
+ if (!(selfSchema.type === "object" && selfSchema.additionalItems === "strict" && b.g.o & 1)) {
1775
+ return;
1776
+ }
1777
+ let key = allocateVal(b, unknown);
1778
+ let keyVar = key.i;
1779
+ b.c = b.c + (`for(` + keyVar + ` in ` + input.v(b) + `){if(`);
1780
+ if (items.length !== 0) {
1781
+ for (let idx = 0, idx_finish = items.length; idx < idx_finish; ++idx) {
1782
+ let match = items[idx];
1783
+ if (idx !== 0) {
1784
+ b.c = b.c + "&&";
1785
+ }
1786
+ b.c = b.c + (keyVar + `!==` + inlineLocation(b, match.location));
1787
+ }
1788
+ } else {
1789
+ b.c = b.c + "true";
1790
+ }
1791
+ b.c = b.c + (`){` + failWithArg(b, path, (exccessFieldName) => ({
1792
+ TAG: "ExcessField",
1793
+ _0: exccessFieldName
1794
+ }), keyVar) + `}}`);
1795
+ }
1796
+ function schemaCompiler(b, input, selfSchema, path) {
1797
+ let additionalItems = selfSchema.additionalItems;
1798
+ let items = selfSchema.items;
1799
+ let isArray = flags[selfSchema.type] & 128;
1800
+ if (b.g.o & 64) {
1801
+ let objectVal = make(b, isArray);
1802
+ for (let idx = 0, idx_finish = items.length; idx < idx_finish; ++idx) {
1803
+ let match = items[idx];
1804
+ let location = match.location;
1805
+ add(objectVal, location, input.properties[location]);
1806
+ }
1807
+ return complete(objectVal, isArray);
1808
+ }
1809
+ let objectVal$1 = make(b, isArray);
1810
+ for (let idx$1 = 0, idx_finish$1 = items.length; idx$1 < idx_finish$1; ++idx$1) {
1811
+ let match$1 = items[idx$1];
1812
+ let location$1 = match$1.location;
1813
+ let itemInput = get(b, input, location$1);
1814
+ let inlinedLocation = inlineLocation(b, location$1);
1815
+ let path$1 = path + (`[` + inlinedLocation + `]`);
1816
+ add(objectVal$1, location$1, parse(b, match$1.schema, itemInput, path$1));
1817
+ }
1818
+ objectStrictModeCheck(b, input, items, selfSchema, path);
1819
+ if ((additionalItems !== "strip" || b.g.o & 32) && items.every((item) => objectVal$1.properties[item.location] === input.properties[item.location])) {
1820
+ input.additionalItems = "strip";
1821
+ return input;
1822
+ } else {
1823
+ return complete(objectVal$1, isArray);
1824
+ }
1825
+ }
1826
+ function definitionToSchema(definition) {
1827
+ if (typeof definition !== "object" || definition === null) {
1828
+ return parse$1(definition);
1829
+ }
1830
+ if (definition["~standard"]) {
1831
+ return definition;
1832
+ }
1833
+ if (Array.isArray(definition)) {
1834
+ for (let idx = 0, idx_finish = definition.length; idx < idx_finish; ++idx) {
1835
+ let schema3 = definitionToSchema(definition[idx]);
1836
+ let location = idx.toString();
1837
+ definition[idx] = {
1838
+ schema: schema3,
1839
+ location
1840
+ };
1841
+ }
1842
+ let mut = new Schema("array");
1843
+ mut.items = definition;
1844
+ mut.additionalItems = "strict";
1845
+ mut.compiler = schemaCompiler;
1846
+ return mut;
1847
+ }
1848
+ let cnstr = definition.constructor;
1849
+ if (cnstr && cnstr !== Object) {
1850
+ return {
1851
+ type: "instance",
1852
+ const: definition,
1853
+ class: cnstr
1854
+ };
1855
+ }
1856
+ let fieldNames = Object.keys(definition);
1857
+ let length2 = fieldNames.length;
1858
+ let items = [];
1859
+ for (let idx$1 = 0; idx$1 < length2; ++idx$1) {
1860
+ let location$1 = fieldNames[idx$1];
1861
+ let schema$1 = definitionToSchema(definition[location$1]);
1862
+ let item = {
1863
+ schema: schema$1,
1864
+ location: location$1
1865
+ };
1866
+ definition[location$1] = schema$1;
1867
+ items[idx$1] = item;
1868
+ }
1869
+ let mut$1 = new Schema("object");
1870
+ mut$1.items = items;
1871
+ mut$1.properties = definition;
1872
+ mut$1.additionalItems = globalConfig.a;
1873
+ mut$1.compiler = schemaCompiler;
1874
+ return mut$1;
1875
+ }
1876
+ function matches(schema3) {
1877
+ return schema3;
1878
+ }
1879
+ var ctx = {
1880
+ m: matches
1881
+ };
1882
+ function factory$4(definer) {
1883
+ return definitionToSchema(definer(ctx));
1884
+ }
1885
+ var js_schema = definitionToSchema;
1886
+ function option(item) {
1887
+ return factory$1(item, unit);
1888
+ }
1889
+ var literal = js_schema;
1890
+ var union = factory;
1891
+ var schema = factory$4;
1892
+
1893
+ // ../../node_modules/sury/src/S.res.mjs
1894
+ var string2 = string;
1895
+ var json2 = json;
1896
+ var enableJson2 = enableJson;
1897
+ var literal2 = literal;
1898
+ var option2 = option;
1899
+ var union2 = union;
1900
+ var schema2 = schema;
1901
+
1902
+ // ../../node_modules/@rescript/runtime/lib/es6/Stdlib_Option.js
1903
+ function mapOr(opt, $$default, f) {
1904
+ if (opt !== void 0) {
1905
+ return f(valFromOption(opt));
1906
+ } else {
1907
+ return $$default;
1908
+ }
1909
+ }
1910
+ function map2(opt, f) {
1911
+ if (opt !== void 0) {
1912
+ return some(f(valFromOption(opt)));
1913
+ }
1914
+ }
1915
+ function flatMap(opt, f) {
1916
+ if (opt !== void 0) {
1917
+ return f(valFromOption(opt));
1918
+ }
1919
+ }
1920
+ function getOr(opt, $$default) {
1921
+ if (opt !== void 0) {
1922
+ return valFromOption(opt);
1923
+ } else {
1924
+ return $$default;
1925
+ }
1926
+ }
1927
+
1928
+ // ../../node_modules/@rescript/runtime/lib/es6/Stdlib_Array.js
1929
+ function make2(length2, x) {
1930
+ if (length2 <= 0) {
1931
+ return [];
1932
+ }
1933
+ let arr = new Array(length2);
1934
+ arr.fill(x);
1935
+ return arr;
1936
+ }
1937
+
1938
+ // src/FrontmanNextjs__CircularBuffer.res.mjs
1939
+ function make3(capacity) {
1940
+ return {
1941
+ data: make2(capacity, void 0),
1942
+ writeIndex: 0,
1943
+ count: 0,
1944
+ maxSize: capacity
1945
+ };
1946
+ }
1947
+ function push(buffer, entry) {
1948
+ buffer.data[buffer.writeIndex] = some(entry);
1949
+ return {
1950
+ data: buffer.data,
1951
+ writeIndex: mod_(buffer.writeIndex + 1 | 0, buffer.maxSize),
1952
+ count: min(buffer.count + 1 | 0, buffer.maxSize),
1953
+ maxSize: buffer.maxSize
1954
+ };
1955
+ }
1956
+
1957
+ // src/FrontmanNextjs__LogCapture.res.mjs
1958
+ enableJson2();
1959
+ function isBrowser() {
1960
+ return typeof window !== "undefined";
1961
+ }
1962
+ function getPatchedFlag() {
1963
+ return globalThis.__FRONTMAN_CONSOLE_PATCHED__;
1964
+ }
1965
+ function setPatchedFlag(_value) {
1966
+ globalThis.__FRONTMAN_CONSOLE_PATCHED__ = _value;
1967
+ }
1968
+ var logLevelSchema = union2([
1969
+ literal2("console"),
1970
+ literal2("build"),
1971
+ literal2("error")
1972
+ ]);
1973
+ var consoleMethodSchema = union2([
1974
+ literal2("log"),
1975
+ literal2("info"),
1976
+ literal2("warn"),
1977
+ literal2("error"),
1978
+ literal2("debug")
1979
+ ]);
1980
+ schema2((s2) => ({
1981
+ timestamp: s2.m(string2),
1982
+ level: s2.m(logLevelSchema),
1983
+ message: s2.m(string2),
1984
+ attributes: s2.m(option2(json2)),
1985
+ resource: s2.m(option2(json2)),
1986
+ consoleMethod: s2.m(option2(consoleMethodSchema))
1987
+ }));
1988
+ var defaultConfig_stdoutPatterns = [
1989
+ "webpack",
1990
+ "turbopack",
1991
+ "Compiled",
1992
+ "Failed"
1993
+ ];
1994
+ var defaultConfig = {
1995
+ bufferCapacity: 1024,
1996
+ stdoutPatterns: defaultConfig_stdoutPatterns
1997
+ };
1998
+ function getGlobalInstanceOpt() {
1999
+ return globalThis.__FRONTMAN_INSTANCE__;
2000
+ }
2001
+ function setGlobalInstance(_state) {
2002
+ globalThis.__FRONTMAN_INSTANCE__ = _state;
2003
+ }
2004
+ function getOrCreateInstance(config) {
2005
+ let state = getGlobalInstanceOpt();
2006
+ if (state !== void 0) {
2007
+ return state;
2008
+ }
2009
+ let state_buffer = {
2010
+ contents: make3(config.bufferCapacity)
2011
+ };
2012
+ let state$1 = {
2013
+ buffer: state_buffer,
2014
+ config
2015
+ };
2016
+ setGlobalInstance(state$1);
2017
+ return state$1;
2018
+ }
2019
+ function getInstance() {
2020
+ let state = getGlobalInstanceOpt();
2021
+ if (state !== void 0) {
2022
+ return state;
2023
+ } else {
2024
+ return getOrCreateInstance(defaultConfig);
2025
+ }
2026
+ }
2027
+ function argsToString(args) {
2028
+ return args.map((arg) => {
2029
+ let match = typeof arg;
2030
+ if (match === "string") {
2031
+ return arg;
2032
+ } else if (match === "object") {
2033
+ if (arg instanceof Error) {
2034
+ return getOr(arg.stack, arg.message);
2035
+ } else {
2036
+ return getOr(JSON.stringify(arg), "null");
2037
+ }
2038
+ } else {
2039
+ return String(arg);
2040
+ }
2041
+ }).join(" ");
2042
+ }
2043
+ function stripAnsi(str) {
2044
+ return str.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
2045
+ }
2046
+ function addLog(state, level, message2, attributes, consoleMethod) {
2047
+ let cleanMessage = stripAnsi(message2).trim();
2048
+ if (cleanMessage === "") {
2049
+ return;
2050
+ }
2051
+ let entry_timestamp = new Date(Date.now()).toISOString();
2052
+ let entry = {
2053
+ timestamp: entry_timestamp,
2054
+ level,
2055
+ message: cleanMessage,
2056
+ attributes,
2057
+ resource: void 0,
2058
+ consoleMethod
2059
+ };
2060
+ state.buffer.contents = push(state.buffer.contents, entry);
2061
+ }
2062
+ function handleConsoleLog(state, args) {
2063
+ try {
2064
+ return addLog(state, "console", argsToString(args), void 0, "log");
2065
+ } catch (exn) {
2066
+ return;
2067
+ }
2068
+ }
2069
+ function handleConsoleWarn(state, args) {
2070
+ try {
2071
+ return addLog(state, "console", argsToString(args), void 0, "warn");
2072
+ } catch (exn) {
2073
+ return;
2074
+ }
2075
+ }
2076
+ function handleConsoleError(state, args) {
2077
+ try {
2078
+ return addLog(state, "console", argsToString(args), void 0, "error");
2079
+ } catch (exn) {
2080
+ return;
2081
+ }
2082
+ }
2083
+ function handleConsoleInfo(state, args) {
2084
+ try {
2085
+ return addLog(state, "console", argsToString(args), void 0, "info");
2086
+ } catch (exn) {
2087
+ return;
2088
+ }
2089
+ }
2090
+ function handleConsoleDebug(state, args) {
2091
+ try {
2092
+ return addLog(state, "console", argsToString(args), void 0, "debug");
2093
+ } catch (exn) {
2094
+ return;
2095
+ }
2096
+ }
2097
+ var interceptConsole = (function(state) {
2098
+ const originalLog = console.log.bind(console);
2099
+ const originalWarn = console.warn.bind(console);
2100
+ const originalError = console.error.bind(console);
2101
+ const originalInfo = console.info.bind(console);
2102
+ const originalDebug = console.debug.bind(console);
2103
+ console.log = (...args) => {
2104
+ handleConsoleLog(state, args);
2105
+ originalLog(...args);
2106
+ };
2107
+ console.warn = (...args) => {
2108
+ handleConsoleWarn(state, args);
2109
+ originalWarn(...args);
2110
+ };
2111
+ console.error = (...args) => {
2112
+ handleConsoleError(state, args);
2113
+ originalError(...args);
2114
+ };
2115
+ console.info = (...args) => {
2116
+ handleConsoleInfo(state, args);
2117
+ originalInfo(...args);
2118
+ };
2119
+ console.debug = (...args) => {
2120
+ handleConsoleDebug(state, args);
2121
+ originalDebug(...args);
2122
+ };
2123
+ });
2124
+ function handleStdoutWrite(state, message2) {
2125
+ try {
2126
+ let matchesPattern = state.config.stdoutPatterns.some((pattern2) => message2.includes(pattern2));
2127
+ if (matchesPattern) {
2128
+ return addLog(state, "build", message2, void 0, void 0);
2129
+ } else {
2130
+ return;
2131
+ }
2132
+ } catch (exn) {
2133
+ return;
2134
+ }
2135
+ }
2136
+ function interceptStdout(_state) {
2137
+ (function(_state2) {
2138
+ const originalWrite = process.stdout.write.bind(process.stdout);
2139
+ process.stdout.write = (chunk, ...args) => {
2140
+ const message2 = typeof chunk === "string" ? chunk : chunk.toString();
2141
+ handleStdoutWrite(_state2, message2);
2142
+ return originalWrite(chunk, ...args);
2143
+ };
2144
+ })(_state);
2145
+ }
2146
+ function interceptUncaughtErrors(state) {
2147
+ process.on("uncaughtException", (error) => {
2148
+ try {
2149
+ let errorMessage = getOr(error.message, "Unknown error");
2150
+ let attributes = Object.fromEntries([
2151
+ [
2152
+ "stack",
2153
+ getOr(map2(error.stack, (prim) => prim), null)
2154
+ ],
2155
+ [
2156
+ "name",
2157
+ error.name
2158
+ ]
2159
+ ]);
2160
+ return addLog(state, "error", errorMessage, attributes, void 0);
2161
+ } catch (exn) {
2162
+ return;
2163
+ }
2164
+ });
2165
+ process.on("unhandledRejection", (reason2) => {
2166
+ try {
2167
+ let reasonMessage = getOr(reason2.message, String.toString(reason2));
2168
+ let attributes = Object.fromEntries([[
2169
+ "stack",
2170
+ getOr(map2(reason2.stack, (prim) => prim), null)
2171
+ ]]);
2172
+ return addLog(state, "error", reasonMessage, attributes, void 0);
2173
+ } catch (exn) {
2174
+ return;
2175
+ }
2176
+ });
2177
+ }
2178
+ function initialize2(configOpt, param) {
2179
+ let config = defaultConfig;
2180
+ if (isBrowser()) {
2181
+ return;
2182
+ }
2183
+ let match = getPatchedFlag();
2184
+ if (match !== void 0 && match) {
2185
+ return;
2186
+ }
2187
+ setPatchedFlag(true);
2188
+ let state = getOrCreateInstance(config);
2189
+ interceptConsole(state);
2190
+ interceptStdout(state);
2191
+ interceptUncaughtErrors(state);
2192
+ }
2193
+ if (typeof window === "undefined") {
2194
+ initialize2();
2195
+ }
2196
+ function string3(json3) {
2197
+ if (typeof json3 === "string") {
2198
+ return json3;
2199
+ }
2200
+ }
2201
+ function float2(json3) {
2202
+ if (typeof json3 === "number") {
2203
+ return json3;
2204
+ }
2205
+ }
2206
+ var Decode = {
2207
+ string: string3,
2208
+ float: float2};
2209
+
2210
+ // src/FrontmanNextjs__SpanProcessor.res.mjs
2211
+ function hrTimeToISO(param) {
2212
+ let ms = param[0] * 1e3 + param[1] / 1e6;
2213
+ return new Date(ms).toISOString();
2214
+ }
2215
+ function calculateDuration(span) {
2216
+ let match = span.startTime;
2217
+ let match$1 = span.endTime;
2218
+ let startMs = match[0] * 1e3 + match[1] / 1e6;
2219
+ let endMs = match$1[0] * 1e3 + match$1[1] / 1e6;
2220
+ return endMs - startMs;
2221
+ }
2222
+ function getStr(attrs, key) {
2223
+ return flatMap(attrs[key], Decode.string);
2224
+ }
2225
+ function getNum(attrs, key) {
2226
+ return flatMap(attrs[key], Decode.float);
2227
+ }
2228
+ function make4() {
2229
+ let onStart = (_span, _ctx) => {
2230
+ };
2231
+ let onEnd = (span) => {
2232
+ try {
2233
+ let attrs = span.attributes;
2234
+ let spanType = getStr(attrs, "next.span_type");
2235
+ let relevantTypes = [
2236
+ "BaseServer.handleRequest",
2237
+ "AppRender.getBodyResult",
2238
+ "AppRouteRouteHandlers.runHandler"
2239
+ ];
2240
+ let isRelevant = mapOr(spanType, false, (st) => relevantTypes.includes(st));
2241
+ if (!isRelevant) {
2242
+ return;
2243
+ }
2244
+ let httpMethod = getStr(attrs, "http.method");
2245
+ let r = getStr(attrs, "next.route");
2246
+ let route = r !== void 0 ? r : getStr(attrs, "http.route");
2247
+ let statusCode = getNum(attrs, "http.status_code");
2248
+ let path = getOr(route, "unknown");
2249
+ if (path.startsWith("/frontman")) {
2250
+ return;
2251
+ }
2252
+ let durationMs = calculateDuration(span);
2253
+ let match;
2254
+ if (spanType !== void 0) {
2255
+ switch (spanType) {
2256
+ case "AppRender.getBodyResult":
2257
+ let msg = `Rendered route: ` + path + ` (` + durationMs.toFixed(2) + `ms)`;
2258
+ match = [
2259
+ msg,
2260
+ "console"
2261
+ ];
2262
+ break;
2263
+ case "AppRouteRouteHandlers.runHandler":
2264
+ let msg$1 = `API route: ` + path + ` (` + durationMs.toFixed(2) + `ms)`;
2265
+ match = [
2266
+ msg$1,
2267
+ "console"
2268
+ ];
2269
+ break;
2270
+ case "BaseServer.handleRequest":
2271
+ let method = getOr(httpMethod, "UNKNOWN");
2272
+ let status = getOr(map2(statusCode, (code) => code.toString()), "unknown");
2273
+ let msg$2 = method + ` ` + path + ` ` + status + ` ` + durationMs.toFixed(2) + `ms`;
2274
+ let lvl = mapOr(statusCode, "console", (code) => {
2275
+ if (code >= 500) {
2276
+ return "error";
2277
+ } else {
2278
+ return "console";
2279
+ }
2280
+ });
2281
+ match = [
2282
+ msg$2,
2283
+ lvl
2284
+ ];
2285
+ break;
2286
+ default:
2287
+ match = [
2288
+ "",
2289
+ "console"
2290
+ ];
2291
+ }
2292
+ } else {
2293
+ match = [
2294
+ "",
2295
+ "console"
2296
+ ];
2297
+ }
2298
+ let message2 = match[0];
2299
+ if (message2 === "") {
2300
+ return;
2301
+ }
2302
+ let logAttrs = Object.fromEntries([
2303
+ [
2304
+ "log.origin",
2305
+ "opentelemetry-span"
2306
+ ],
2307
+ [
2308
+ "span.name",
2309
+ span.name
2310
+ ],
2311
+ [
2312
+ "span.type",
2313
+ getOr(spanType, "")
2314
+ ],
2315
+ [
2316
+ "http.method",
2317
+ getOr(httpMethod, "")
2318
+ ],
2319
+ [
2320
+ "http.route",
2321
+ getOr(route, "")
2322
+ ],
2323
+ [
2324
+ "http.status_code",
2325
+ getOr(map2(statusCode, (prim) => prim), null)
2326
+ ],
2327
+ [
2328
+ "duration.ms",
2329
+ durationMs
2330
+ ]
2331
+ ]);
2332
+ let match$1 = span.endTime;
2333
+ hrTimeToISO([
2334
+ match$1[0],
2335
+ match$1[1]
2336
+ ]);
2337
+ let state = getInstance();
2338
+ return addLog(state, match[1], message2, logAttrs, void 0);
2339
+ } catch (exn) {
2340
+ return;
2341
+ }
2342
+ };
2343
+ let forceFlush = () => Promise.resolve();
2344
+ let shutdown = () => Promise.resolve();
2345
+ return new Object({
2346
+ onStart,
2347
+ onEnd,
2348
+ forceFlush,
2349
+ shutdown
2350
+ });
2351
+ }
2352
+
2353
+ // src/FrontmanNextjs__LogRecordProcessor.res.mjs
2354
+ function mapSeverity(severityText) {
2355
+ if (severityText === void 0) {
2356
+ return "console";
2357
+ }
2358
+ switch (severityText) {
2359
+ case "CRITICAL":
2360
+ case "ERROR":
2361
+ case "FATAL":
2362
+ return "error";
2363
+ default:
2364
+ return "console";
2365
+ }
2366
+ }
2367
+ function make5() {
2368
+ let onEmit = (logRecord, _context) => {
2369
+ try {
2370
+ let body = getOr(fromNullable(logRecord.body), "");
2371
+ let level = mapSeverity(fromNullable(logRecord.severityText));
2372
+ let attributes = map2(fromNullable(logRecord.attributes), (attrs) => attrs);
2373
+ let state = getInstance();
2374
+ return addLog(state, level, body, attributes, void 0);
2375
+ } catch (exn) {
2376
+ return;
2377
+ }
2378
+ };
2379
+ let forceFlush = () => Promise.resolve();
2380
+ let shutdown = () => Promise.resolve();
2381
+ return new Object({
2382
+ onEmit,
2383
+ forceFlush,
2384
+ shutdown
2385
+ });
2386
+ }
2387
+
2388
+ // src/FrontmanNextjs__Instrumentation.res.mjs
2389
+ function setup() {
2390
+ initialize2();
2391
+ initialize();
2392
+ return [
2393
+ make5(),
2394
+ make4()
2395
+ ];
2396
+ }
2397
+ var LogCapture;
2398
+ var Sentry;
2399
+
2400
+ export { LogCapture, Sentry, setup };