clanka 0.8.2 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/Acp.d.ts.map +1 -1
  2. package/dist/Acp.js +3 -3
  3. package/dist/Acp.js.map +1 -1
  4. package/dist/Acp.test.js +6 -5
  5. package/dist/Acp.test.js.map +1 -1
  6. package/dist/AgentExecutor.d.ts.map +1 -1
  7. package/dist/AgentExecutor.js +1 -1
  8. package/dist/AgentExecutor.js.map +1 -1
  9. package/dist/AgentExecutor.test.d.ts +2 -0
  10. package/dist/AgentExecutor.test.d.ts.map +1 -0
  11. package/dist/AgentExecutor.test.js +87 -0
  12. package/dist/AgentExecutor.test.js.map +1 -0
  13. package/dist/bin/{Effect-BCeySOy1.mjs → Effect-BmOuzEIp.mjs} +243 -215
  14. package/dist/bin/Effect-BmOuzEIp.mjs.map +1 -0
  15. package/dist/bin/{McpClient-DP4jlaD1.mjs → McpClient-CLpFJSre.mjs} +3 -3
  16. package/dist/bin/{McpClient-DP4jlaD1.mjs.map → McpClient-CLpFJSre.mjs.map} +1 -1
  17. package/dist/bin/{OutputFormatter-Ch8yFytV.mjs → OutputFormatter-C_gdNUl1.mjs} +3 -3
  18. package/dist/bin/{OutputFormatter-Ch8yFytV.mjs.map → OutputFormatter-C_gdNUl1.mjs.map} +1 -1
  19. package/dist/bin/{Schema-C9JQ5hI0.mjs → Schema-C7W9nQug.mjs} +477 -382
  20. package/dist/bin/Schema-C7W9nQug.mjs.map +1 -0
  21. package/dist/bin/{SemanticSearch-BJGnYhFt.mjs → SemanticSearch-cqSnq90g.mjs} +269 -228
  22. package/dist/bin/SemanticSearch-cqSnq90g.mjs.map +1 -0
  23. package/dist/bin/{Stream-CgH3SuLu.mjs → Stream-BI6Fx9yq.mjs} +179 -171
  24. package/dist/bin/Stream-BI6Fx9yq.mjs.map +1 -0
  25. package/dist/bin/cli.mjs +172 -204
  26. package/dist/bin/cli.mjs.map +1 -1
  27. package/package.json +12 -12
  28. package/src/Acp.test.ts +6 -5
  29. package/src/Acp.ts +6 -3
  30. package/src/AgentExecutor.test.ts +133 -0
  31. package/src/AgentExecutor.ts +1 -2
  32. package/dist/bin/Effect-BCeySOy1.mjs.map +0 -1
  33. package/dist/bin/Schema-C9JQ5hI0.mjs.map +0 -1
  34. package/dist/bin/SemanticSearch-BJGnYhFt.mjs.map +0 -1
  35. package/dist/bin/Stream-CgH3SuLu.mjs.map +0 -1
@@ -1,8 +1,8 @@
1
- import { $a as map$4, $o as symbol, Ao as assignProperty$1, As as memoizeIdempotent, Bo as formatPath, Br as succeed$2, Co as args, Es as dual, Fo as NodeInspectSymbol, Fr as failCause, Ft as runSyncExit, Gn as isReason, Go as equals, Ha as fromNullOr, Hr as ClockRef, Ht as succeedNone, I as flatMap, J as fromResult, Jn as makeFailReason, Jo as combine, Ka as getOrNull, Ki as makeEquivalence$3, Ko as symbol$1, L as flatMapEager, Lo as format$1, Lr as isExit, M as fail$2, Mi as append, Mo as setStackTraceLimit, Ms as Class$2, No as BaseProto, Ns as Prototype, O as die, On as IllegalArgumentError, Os as identity, P as failCauseSync, Pi as empty$2, Pn as die$1, Pr as fail$3, Ps as pipeArguments, Qa as liftThrowable, Ra as filter, Ro as formatDate, Sa as toSeconds, So as TaggedError$2, Ui as isReadonlyArrayNonEmpty, Un as isCause, V as fnUntracedEager, Va as flatten, Vi as isArrayNonEmpty, Vo as formatPropertyKey, Vr as void_$1, Vt as succeed$3, Wn as isFailReason, Xa as isOption, Xn as map$5, Xo as number$1, Xr as effectIsExit, Xt as try_, Ya as isNone, Yn as makeInterruptReason, Yo as hash, Yr as currentTimeMillis$1, Yt as tryPromise, Za as isSome, Zo as string$1, _i as map$2, _o as strictEqual, _s as isTagged, ba as seconds, bi as resolveConcurrency, bo as Error$3, ca as succeed$1, co as Number$4, cs as isNotNullish, ct as mapEager, da as fromInputUnsafe, do as isGreaterThanOrEqualTo$1, ea as fail$1, eo as match, es as hasProperty, fa as infinity, fi as iterateConcurrent, fo as isLessThan$1, fs as isNumber, ga as millis, go as make$8, gs as isString, ho as Tuple$1, hs as isPropertyKey, io as some, is as isFunction, j as exit, jo as getStackTraceLimit, ko as assignProperties, ks as memoize, lo as String$4, ls as isNotUndefined, m as catchCause, ma as isFinite$2, mo as make$9, ms as isObjectKeyword, na as getOrThrow, ns as isBoolean, oo as BigInt$4, os as isNever$1, pa as isDuration, pi as iterateEager, po as isLessThanOrEqualTo$1, ps as isObject, qi as map$3, qn as makeDieReason, qo as array, rn as void_$2, rs as isError, sa as match$1, so as Date$3, st as mapBothEager, to as none, ts as isBigInt, uo as isGreaterThan$1, ut as mapErrorEager, va as nanos, xo as PipeInspectableProto, ya as negativeInfinity, ys as isUnknown, zi as fromIterable$1, zn as fromReasons, zo as formatJson, zr as isSuccess } from "./Effect-BCeySOy1.mjs";
2
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Tuple.js
1
+ import { $a as match, $i as fail$1, $o as hasProperty, Ao as getStackTraceLimit, Ba as flatten, Bi as isArrayNonEmpty, Bo as formatPropertyKey, Br as succeed$2, Ds as identity, Fr as failCause, Ft as runSyncExit, Ga as getOrNull, Gi as makeEquivalence$3, Gn as isReason, Go as symbol$1, Hi as isReadonlyArrayNonEmpty, Hr as ClockRef, Ht as succeedNone, I as flatMap, Io as format$1, J as fromResult, Ja as isNone, Jn as makeFailReason, Jo as hash, Ki as map$3, Ko as array, L as flatMapEager, La as filter, Lo as formatDate, Lr as isExit, M as fail$2, Mo as BaseProto, Ms as Prototype, Ni as empty$2, Ns as pipeArguments, O as die, On as IllegalArgumentError, Oo as assignProperties, Os as memoize, P as failCauseSync, Pn as die$1, Po as NodeInspectSymbol, Pr as fail$3, Qa as map$4, Qo as symbol, Ri as fromIterable$1, Ro as formatJson, So as args, Ts as dual, Un as isCause, Ut as suspend, V as fnUntracedEager, Va as fromNullOr, Vr as void_$1, Vt as succeed$3, Wn as isFailReason, Wo as equals, Xa as isSome, Xn as map$5, Xo as string$1, Xr as effectIsExit, Xt as try_, Ya as isOption, Yn as makeInterruptReason, Yo as number$1, Yr as currentTimeMillis$1, Yt as tryPromise, Za as liftThrowable, _a as nanos, _i as map$2, ao as BigInt$4, as as isNever$1, bi as resolveConcurrency, bo as PipeInspectableProto, co as String$4, cs as isNotUndefined, ct as mapEager, da as infinity, do as isLessThan$1, ds as isNumber, eo as none, es as isBigInt, fa as isDuration, fi as iterateConcurrent, fo as isLessThanOrEqualTo$1, fs as isObject, go as strictEqual, gs as isTagged, ha as millis, ho as make$8, hs as isString, j as exit, ji as append, jo as setStackTraceLimit, js as Class$2, ko as assignProperty$1, ks as memoizeIdempotent, lo as isGreaterThan$1, m as catchCause, mo as Tuple$1, ms as isPropertyKey, ns as isError, oa as match$1, oo as Date$3, pa as isFinite$2, pi as iterateEager, po as make$9, ps as isObjectKeyword, qn as makeDieReason, qo as combine, rn as void_$2, ro as some, rs as isFunction, sa as succeed$1, so as Number$4, ss as isNotNullish, st as mapBothEager, ta as getOrThrow, ts as isBoolean, ua as fromInputUnsafe, uo as isGreaterThanOrEqualTo$1, ut as mapErrorEager, va as negativeInfinity, vs as isUnknown, xa as toSeconds, xo as TaggedError$2, ya as seconds, yo as Error$3, zn as fromReasons, zo as formatPath, zr as isSuccess } from "./Effect-BmOuzEIp.mjs";
2
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Tuple.js
3
3
  const makeEquivalence$2 = Tuple$1;
4
4
  //#endregion
5
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Record.js
5
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Record.js
6
6
  const has = dual(2, (self, key) => Object.hasOwn(self, key));
7
7
  const map$1 = dual(2, (self, f) => {
8
8
  const out = { ...self };
@@ -20,7 +20,7 @@ const makeEquivalence$1 = (equivalence) => {
20
20
  return (self, that) => is(self, that) && is(that, self);
21
21
  };
22
22
  //#endregion
23
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Data.js
23
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Data.js
24
24
  const Class$1 = class extends Class$2 {
25
25
  constructor(props) {
26
26
  super();
@@ -51,17 +51,17 @@ function taggedMatch() {
51
51
  const Error$2 = Error$3;
52
52
  const TaggedError$1 = TaggedError$2;
53
53
  //#endregion
54
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/encoding/EncodingError.js
54
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/encoding/EncodingError.js
55
55
  const EncodingErrorTypeId = "~effect/encoding/EncodingError";
56
56
  var EncodingError = class extends TaggedError$1("EncodingError") {
57
57
  [EncodingErrorTypeId] = EncodingErrorTypeId;
58
58
  };
59
59
  //#endregion
60
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Clock.js
60
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Clock.js
61
61
  const Clock = ClockRef;
62
62
  const currentTimeMillis = currentTimeMillis$1;
63
63
  //#endregion
64
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/dateTime.js
64
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/dateTime.js
65
65
  const TypeId$9 = "~effect/DateTime";
66
66
  const TimeZoneTypeId = "~effect/DateTime/TimeZone";
67
67
  const Proto$3 = {
@@ -232,7 +232,7 @@ const formatIsoOffset = (self) => {
232
232
  };
233
233
  const formatIsoZoned = (self) => self.zone._tag === "Offset" ? formatIsoOffset(self) : `${formatIsoOffset(self)}[${self.zone.id}]`;
234
234
  //#endregion
235
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/redacted.js
235
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/redacted.js
236
236
  const redactedRegistry = new WeakMap();
237
237
  const value$1 = (self) => {
238
238
  if (redactedRegistry.has(self)) return redactedRegistry.get(self);
@@ -240,7 +240,7 @@ const value$1 = (self) => {
240
240
  };
241
241
  const stringOrRedacted = (val) => typeof val === "string" ? val : value$1(val);
242
242
  //#endregion
243
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Redacted.js
243
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Redacted.js
244
244
  const TypeId$8 = "~effect/Redacted";
245
245
  const isRedacted = (u) => hasProperty(u, TypeId$8);
246
246
  const make$6 = (value, options) => {
@@ -269,7 +269,7 @@ const Proto$2 = {
269
269
  const value = value$1;
270
270
  const makeEquivalence = (isEquivalent) => make$8((x, y) => isEquivalent(value(x), value(y)));
271
271
  //#endregion
272
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/BigDecimal.js
272
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/BigDecimal.js
273
273
  const TypeId$7 = "~effect/BigDecimal";
274
274
  const BigDecimalProto = {
275
275
  [TypeId$7]: TypeId$7,
@@ -373,7 +373,7 @@ const toExponential = (n) => {
373
373
  };
374
374
  const isZero = (n) => n.value === bigint0;
375
375
  //#endregion
376
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/DateTime.js
376
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/DateTime.js
377
377
  const isDateTime = isDateTime$1;
378
378
  const isUtc = isUtc$1;
379
379
  const fromDateUnsafe = fromDateUnsafe$1;
@@ -387,7 +387,7 @@ const removeTime = removeTime$1;
387
387
  const formatIso = formatIso$1;
388
388
  const formatIsoDate = formatIsoDate$1;
389
389
  //#endregion
390
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/encoding/Base64.js
390
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/encoding/Base64.js
391
391
  const encode = (input) => encodeBytes(typeof input === "string" ? encoder.encode(input) : input);
392
392
  const decode = (str) => {
393
393
  const stripped = stripCrlf(str);
@@ -458,7 +458,7 @@ const getCode = (charCode) => {
458
458
  return codes[charCode];
459
459
  };
460
460
  //#endregion
461
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/http/Cookies.js
461
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/http/Cookies.js
462
462
  const TypeId$6 = "~effect/http/Cookies";
463
463
  const isCookies = (u) => hasProperty(u, TypeId$6);
464
464
  const CookieTypeId = "~effect/http/Cookies/Cookie";
@@ -683,7 +683,7 @@ const tryDecodeURIComponent = (str) => {
683
683
  }
684
684
  };
685
685
  //#endregion
686
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/http/UrlParams.js
686
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/http/UrlParams.js
687
687
  const TypeId$5 = "~effect/http/UrlParams";
688
688
  const isUrlParams = (u) => hasProperty(u, TypeId$5);
689
689
  const Proto = {
@@ -757,7 +757,7 @@ const toRecord = (self) => {
757
757
  };
758
758
  const toReadonlyRecord = toRecord;
759
759
  //#endregion
760
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/annotations.js
760
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/annotations.js
761
761
  function resolve$1(ast) {
762
762
  return ast.checks ? ast.checks[ast.checks.length - 1].annotations : ast.annotations;
763
763
  }
@@ -783,7 +783,6 @@ const jsonSchemaAnnotationKeys = [
783
783
  const resolveIdentifier$1 = resolveAt$1("identifier");
784
784
  const resolveIdentifierFallback = resolveAt$1(IDENTIFIER_FALLBACK_KEY);
785
785
  const resolveDescription$1 = resolveAt$1("description");
786
- const resolveBrands = resolveAt$1("brands");
787
786
  const getExpected = memoize((ast) => {
788
787
  const identifier = resolve$1(ast)?.identifier;
789
788
  if (typeof identifier === "string") return identifier;
@@ -794,7 +793,6 @@ const annotationExcludedKeys = new Set([
794
793
  STRUCTURAL_ANNOTATION_KEY,
795
794
  "representation",
796
795
  "arbitraryConstraint",
797
- "brands",
798
796
  "toJsonSchema",
799
797
  "toCode",
800
798
  "toEquivalence",
@@ -806,7 +804,7 @@ const annotationExcludedKeys = new Set([
806
804
  "toCodecArbitrary"
807
805
  ]);
808
806
  //#endregion
809
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/parser.js
807
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/parser.js
810
808
  const missing = Symbol();
811
809
  const succeed = succeed$2;
812
810
  const missingExit = succeed(missing);
@@ -814,7 +812,7 @@ const sameExit = succeed(missing);
814
812
  const toOption = (value) => value === missing ? none() : some(value);
815
813
  const fromOptionExit = (option) => option._tag === "None" ? missingExit : succeed(option.value);
816
814
  //#endregion
817
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/SchemaIssue.js
815
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/SchemaIssue.js
818
816
  const TypeId$4 = "~effect/SchemaIssue/Issue";
819
817
  function isIssue(u) {
820
818
  return hasProperty(u, TypeId$4) && u[TypeId$4] === TypeId$4;
@@ -1027,7 +1025,7 @@ function findMessage(issue) {
1027
1025
  if (typeof message === "string") return message;
1028
1026
  }
1029
1027
  //#endregion
1030
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/cause.js
1028
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/cause.js
1031
1029
  function getSchemaIssue(cause) {
1032
1030
  let issue;
1033
1031
  for (const reason of cause.reasons) {
@@ -1042,7 +1040,7 @@ function getSchemaIssueOrThrow(cause, message) {
1042
1040
  return issue;
1043
1041
  }
1044
1042
  //#endregion
1045
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/SchemaGetter.js
1043
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/SchemaGetter.js
1046
1044
  const runGetter = (self, input, options) => {
1047
1045
  switch (self._tag) {
1048
1046
  case "Passthrough": return succeed$3(input);
@@ -1170,7 +1168,7 @@ function dateTimeUtcFromInput$1() {
1170
1168
  });
1171
1169
  }
1172
1170
  //#endregion
1173
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/SchemaTransformation.js
1171
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/SchemaTransformation.js
1174
1172
  const Middleware = class extends Class$2 {
1175
1173
  _tag = "Middleware";
1176
1174
  decode;
@@ -1286,7 +1284,7 @@ function fromJsonString$1(options) {
1286
1284
  return new Transformation(parseJson(options ?? {}), stringifyJson(options));
1287
1285
  }
1288
1286
  //#endregion
1289
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/SchemaAST.js
1287
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/SchemaAST.js
1290
1288
  function makeGuard(tag) {
1291
1289
  return (ast) => ast._tag === tag;
1292
1290
  }
@@ -1573,19 +1571,20 @@ const Arrays = class extends ASTNodeImpl {
1573
1571
  else if (index >= tailThreshold) return rest[index - tailThreshold + 1];
1574
1572
  return rest[0];
1575
1573
  }
1576
- return fnUntracedEager(function* (input, options) {
1577
- if (input === missing) return missing;
1578
- if (!Array.isArray(input)) return yield* fail$2(new InvalidType(ast, input, options));
1579
- if (!elements) {
1580
- elements = ast.elements.map((ast) => ({
1581
- ast,
1582
- parser: compileField(ast)
1583
- }));
1584
- rest = ast.rest.map((ast) => ({
1585
- ast,
1586
- parser: compileField(ast)
1587
- }));
1574
+ const finish = (state) => {
1575
+ const { input, len, options } = state;
1576
+ if (ast.rest.length === 0 && len > elementLen) for (let i = elementLen; i < len; i++) {
1577
+ const unexpected = new UnexpectedKey(ast, input[i], options);
1578
+ const issue = new Pointer([i], unexpected);
1579
+ if (options.errors === "all") {
1580
+ if (state.issues) state.issues.push(issue);
1581
+ else state.issues = [issue];
1582
+ } else return fail$2(new Composite(ast, [issue], input, options));
1588
1583
  }
1584
+ if (state.issues) return fail$2(new Composite(ast, state.issues, input, options));
1585
+ return succeed(state.output);
1586
+ };
1587
+ const parse = (input, options) => {
1589
1588
  const len = input.length;
1590
1589
  const state = {
1591
1590
  ast,
@@ -1603,18 +1602,34 @@ const Arrays = class extends ASTNodeImpl {
1603
1602
  concurrency,
1604
1603
  end
1605
1604
  });
1606
- if (eff) yield* eff;
1607
- if (ast.rest.length === 0 && len > elementLen) for (let i = elementLen; i <= len - 1; i++) {
1608
- const unexpected = new UnexpectedKey(ast, input[i], options);
1609
- const issue = new Pointer([i], unexpected);
1610
- if (options.errors === "all") {
1611
- if (state.issues) state.issues.push(issue);
1612
- else state.issues = [issue];
1613
- } else return yield* fail$2(new Composite(ast, [issue], input, options));
1605
+ if (!eff) return finish(state);
1606
+ if (effectIsExit(eff)) return flatMapEager(eff, () => finish(state));
1607
+ let first = true;
1608
+ return suspend(() => {
1609
+ if (!first) return parse(input, options);
1610
+ first = false;
1611
+ return flatMap(eff, () => finish(state));
1612
+ });
1613
+ };
1614
+ return (input, options) => {
1615
+ if (input === missing) return missingExit;
1616
+ try {
1617
+ if (!Array.isArray(input)) return fail$2(new InvalidType(ast, input, options));
1618
+ if (!elements) {
1619
+ elements = ast.elements.map((ast) => ({
1620
+ ast,
1621
+ parser: compileField(ast)
1622
+ }));
1623
+ rest = ast.rest.map((ast) => ({
1624
+ ast,
1625
+ parser: compileField(ast)
1626
+ }));
1627
+ }
1628
+ return parse(input, options);
1629
+ } catch (error) {
1630
+ return die(error);
1614
1631
  }
1615
- if (state.issues) return yield* fail$2(new Composite(ast, state.issues, input, options));
1616
- return state.output;
1617
- });
1632
+ };
1618
1633
  }
1619
1634
  _rebuild(recur, checks, encodingChecks) {
1620
1635
  const elements = mapOrSame(this.elements, recur);
@@ -1673,7 +1688,7 @@ function getIndexSignatureKeys(input, parameter, options = defaultParseOptions)
1673
1688
  case "String":
1674
1689
  case "TemplateLiteral": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchPart(k, options) !== void 0);
1675
1690
  case "Number": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
1676
- case "Symbol": return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
1691
+ case "Symbol": return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter((k) => Object.prototype.propertyIsEnumerable.call(input, k) && parameter.matchKey(k, options) !== void 0);
1677
1692
  case "Union": return [...new Set(parameter.types.flatMap(go))];
1678
1693
  default: return [];
1679
1694
  }
@@ -1732,55 +1747,14 @@ const Objects = class extends ASTNodeImpl {
1732
1747
  this.propertySignatures = propertySignatures;
1733
1748
  this.indexSignatures = indexSignatures;
1734
1749
  this.encodingChecks = encodingChecks;
1735
- const seen = new Set();
1736
- const duplicates = [];
1737
- for (const propertySignature of propertySignatures) {
1738
- const name = propertySignature.name;
1739
- if (seen.has(name)) duplicates.push(name);
1740
- else seen.add(name);
1741
- }
1742
- if (duplicates.length > 0) throw new Error(`Duplicate identifiers: ${JSON.stringify(duplicates)}. ts(2300)`);
1743
1750
  }
1744
1751
  getParser(compile, compileField = compile) {
1745
1752
  const ast = this;
1746
- const expectedKeys = [];
1747
- for (const ps of ast.propertySignatures) expectedKeys.push(typeof ps.name === "number" ? globalThis.String(ps.name) : ps.name);
1748
- const hasProperties = expectedKeys.length;
1753
+ const hasProperties = ast.propertySignatures.length;
1749
1754
  const indexCount = ast.indexSignatures.length;
1750
- let expectedKeysSet = hasProperties && indexCount ? new Set(expectedKeys) : void 0;
1751
1755
  if (!hasProperties && !indexCount) return fromRefinement(ast, isNotNullish);
1752
1756
  let properties;
1753
1757
  let indexes;
1754
- const finishIndex = (s, key, k2, inputValue, exitValue) => {
1755
- if (exitValue._tag === "Failure") return wrapPropertyKeyIssue(s, ast, key, exitValue) ?? void_$1;
1756
- const value = exitValue === sameExit ? inputValue : exitValue[args];
1757
- if (k2 !== missing && value !== missing) {
1758
- if (hasProperties && (expectedKeysSet.has(key) || expectedKeysSet.has(typeof k2 === "number" ? globalThis.String(k2) : k2))) return void_$1;
1759
- assignProperty$1(s.out, k2, value);
1760
- }
1761
- return void_$1;
1762
- };
1763
- const parseIndex = (s, key, index, exitKey) => {
1764
- if (!exitKey) {
1765
- const eff = index.parserKey(key, s.options);
1766
- if (!effectIsExit(eff)) return flatMap(exit(eff), (exit) => parseIndex(s, key, index, exit));
1767
- exitKey = eff;
1768
- }
1769
- if (exitKey._tag === "Failure") return wrapPropertyKeyIssue(s, ast, key, exitKey) ?? void_$1;
1770
- const k2 = exitKey === sameExit ? key : exitKey[args];
1771
- const inputValue = s.input[key];
1772
- const result = index.parserValue(inputValue, s.options);
1773
- return effectIsExit(result) ? finishIndex(s, key, k2, inputValue, result) : flatMap(exit(result), (exit) => finishIndex(s, key, k2, inputValue, exit));
1774
- };
1775
- const parseStringIndex = (s, key, index) => {
1776
- const inputValue = s.input[key];
1777
- const result = index.parserValue(inputValue, s.options);
1778
- return effectIsExit(result) ? finishIndex(s, key, key, inputValue, result) : flatMap(exit(result), (exit) => finishIndex(s, key, key, inputValue, exit));
1779
- };
1780
- const parseIndexes = indexCount ? iterateConcurrent()({
1781
- onItem: (s, [key, index]) => index.is.parameter === string ? parseStringIndex(s, key, index) : parseIndex(s, key, index),
1782
- step: (_s, _item, exit) => exit._tag === "Failure" ? exit : void 0
1783
- }) : void 0;
1784
1758
  const compileMembers = () => {
1785
1759
  if (!properties) {
1786
1760
  properties = ast.propertySignatures.map((ps) => ({
@@ -1796,69 +1770,102 @@ const Objects = class extends ASTNodeImpl {
1796
1770
  }
1797
1771
  return properties;
1798
1772
  };
1799
- const fallback = fnUntracedEager(function* (input, options) {
1800
- if (input === missing) return missing;
1801
- if (!(typeof input === "object" && input !== null && !Array.isArray(input))) return yield* fail$2(new InvalidType(ast, input, options));
1802
- compileMembers();
1803
- const record = input;
1804
- const out = {};
1805
- const state = {
1806
- ast,
1807
- input: record,
1808
- out,
1809
- issues: void 0,
1810
- options
1773
+ const makeFallback = () => {
1774
+ const expectedKeys = new Set(ast.propertySignatures.map((ps) => typeof ps.name === "number" ? globalThis.String(ps.name) : ps.name));
1775
+ const finishIndex = (s, key, k2, inputValue, exitValue) => {
1776
+ if (exitValue._tag === "Failure") return wrapPropertyKeyIssue(s, ast, key, exitValue) ?? void_$1;
1777
+ const value = exitValue === sameExit ? inputValue : exitValue[args];
1778
+ if (k2 !== missing && value !== missing) {
1779
+ if (hasProperties && (expectedKeys.has(key) || expectedKeys.has(typeof k2 === "number" ? globalThis.String(k2) : k2))) return void_$1;
1780
+ assignProperty$1(s.out, k2, value);
1781
+ }
1782
+ return void_$1;
1811
1783
  };
1812
- const errorsAllOption = options.errors === "all";
1813
- const onExcessPropertyError = options.onExcessProperty === "error";
1814
- const concurrency = options.concurrency === void 0 ? 1 : resolveConcurrency(options.concurrency);
1815
- const indexKeys = indexCount && onExcessPropertyError ? ast.indexSignatures.map((index) => getIndexSignatureKeys(record, index.parameter, options)) : void 0;
1816
- if (onExcessPropertyError) {
1817
- expectedKeysSet ??= new Set(expectedKeys);
1818
- const coveredKeys = indexKeys ? new Set(expectedKeysSet) : expectedKeysSet;
1819
- if (indexKeys) for (const keys of indexKeys) for (const key of keys) coveredKeys.add(key);
1820
- const inputKeys = Reflect.ownKeys(record);
1821
- for (let i = 0; i < inputKeys.length; i++) {
1822
- const key = inputKeys[i];
1823
- if (!coveredKeys.has(key)) {
1824
- const unexpected = new UnexpectedKey(ast, record[key], options);
1825
- const issue = new Pointer([key], unexpected);
1826
- if (errorsAllOption) {
1827
- if (state.issues) state.issues.push(issue);
1828
- else state.issues = [issue];
1829
- continue;
1830
- } else return yield* fail$2(new Composite(ast, [issue], input, options));
1784
+ const parseIndex = (s, key, index, exitKey) => {
1785
+ if (!exitKey) {
1786
+ const eff = index.parserKey(key, s.options);
1787
+ if (!effectIsExit(eff)) return flatMap(exit(eff), (exit) => parseIndex(s, key, index, exit));
1788
+ exitKey = eff;
1789
+ }
1790
+ if (exitKey._tag === "Failure") return wrapPropertyKeyIssue(s, ast, key, exitKey) ?? void_$1;
1791
+ const k2 = exitKey === sameExit ? key : exitKey[args];
1792
+ const inputValue = s.input[key];
1793
+ const result = index.parserValue(inputValue, s.options);
1794
+ return effectIsExit(result) ? finishIndex(s, key, k2, inputValue, result) : flatMap(exit(result), (exit) => finishIndex(s, key, k2, inputValue, exit));
1795
+ };
1796
+ const parseStringIndex = (s, key, index) => {
1797
+ const inputValue = s.input[key];
1798
+ const result = index.parserValue(inputValue, s.options);
1799
+ return effectIsExit(result) ? finishIndex(s, key, key, inputValue, result) : flatMap(exit(result), (exit) => finishIndex(s, key, key, inputValue, exit));
1800
+ };
1801
+ const parseIndexes = indexCount ? iterateConcurrent()({
1802
+ onItem: (s, [key, index]) => index.is.parameter === string ? parseStringIndex(s, key, index) : parseIndex(s, key, index),
1803
+ step: (_s, _item, exit) => exit._tag === "Failure" ? exit : void 0
1804
+ }) : void 0;
1805
+ return fnUntracedEager(function* (input, options) {
1806
+ if (input === missing) return missing;
1807
+ if (!(typeof input === "object" && input !== null && !Array.isArray(input))) return yield* fail$2(new InvalidType(ast, input, options));
1808
+ compileMembers();
1809
+ const record = input;
1810
+ const out = {};
1811
+ const state = {
1812
+ ast,
1813
+ input: record,
1814
+ out,
1815
+ issues: void 0,
1816
+ options
1817
+ };
1818
+ const errorsAllOption = options.errors === "all";
1819
+ const onExcessPropertyError = options.onExcessProperty === "error";
1820
+ const concurrency = options.concurrency === void 0 ? 1 : resolveConcurrency(options.concurrency);
1821
+ const indexKeys = indexCount && onExcessPropertyError ? ast.indexSignatures.map((index) => getIndexSignatureKeys(record, index.parameter, options)) : void 0;
1822
+ if (onExcessPropertyError) {
1823
+ const coveredKeys = indexKeys ? new Set(expectedKeys) : expectedKeys;
1824
+ if (indexKeys) for (const keys of indexKeys) for (const key of keys) coveredKeys.add(key);
1825
+ const inputKeys = Reflect.ownKeys(record);
1826
+ for (let i = 0; i < inputKeys.length; i++) {
1827
+ const key = inputKeys[i];
1828
+ if (!coveredKeys.has(key) && Object.prototype.propertyIsEnumerable.call(record, key)) {
1829
+ const unexpected = new UnexpectedKey(ast, record[key], options);
1830
+ const issue = new Pointer([key], unexpected);
1831
+ if (errorsAllOption) {
1832
+ if (state.issues) state.issues.push(issue);
1833
+ else state.issues = [issue];
1834
+ continue;
1835
+ } else return yield* fail$2(new Composite(ast, [issue], input, options));
1836
+ }
1831
1837
  }
1832
1838
  }
1833
- }
1834
- if (hasProperties) {
1835
- const eff = concurrency === 1 ? parseProperties(state, properties) : parsePropertiesConcurrent(state, properties, { concurrency });
1836
- if (eff) yield* eff;
1837
- }
1838
- if (indexCount && concurrency === 1) for (let i = 0; i < indexCount; i++) {
1839
- const index = indexes[i];
1840
- const parse = index.is.parameter === string ? parseStringIndex : parseIndex;
1841
- const keys = indexKeys?.[i] ?? (index.is.parameter === string ? Object.keys(record) : getIndexSignatureKeys(record, index.is.parameter, options));
1842
- for (let j = 0; j < keys.length; j++) {
1843
- const eff = parse(state, keys[j], index);
1844
- if (!effectIsExit(eff)) yield* eff;
1845
- else if (eff._tag === "Failure") return yield* eff;
1839
+ if (hasProperties) {
1840
+ const eff = concurrency === 1 ? parseProperties(state, properties) : parsePropertiesConcurrent(state, properties, { concurrency });
1841
+ if (eff) yield* eff;
1846
1842
  }
1847
- }
1848
- else if (parseIndexes) {
1849
- const keyPairs = empty$2();
1850
- for (let i = 0; i < indexCount; i++) {
1843
+ if (indexCount && concurrency === 1) for (let i = 0; i < indexCount; i++) {
1851
1844
  const index = indexes[i];
1845
+ const parse = index.is.parameter === string ? parseStringIndex : parseIndex;
1852
1846
  const keys = indexKeys?.[i] ?? (index.is.parameter === string ? Object.keys(record) : getIndexSignatureKeys(record, index.is.parameter, options));
1853
- for (let j = 0; j < keys.length; j++) keyPairs.push([keys[j], index]);
1847
+ for (let j = 0; j < keys.length; j++) {
1848
+ const eff = parse(state, keys[j], index);
1849
+ if (!effectIsExit(eff)) yield* eff;
1850
+ else if (eff._tag === "Failure") return yield* eff;
1851
+ }
1854
1852
  }
1855
- const eff = parseIndexes(state, keyPairs, { concurrency });
1856
- if (eff) yield* eff;
1857
- }
1858
- if (state.issues) return yield* fail$2(new Composite(ast, state.issues, input, options));
1859
- return out;
1860
- });
1861
- if (indexCount) return fallback;
1853
+ else if (parseIndexes) {
1854
+ const keyPairs = empty$2();
1855
+ for (let i = 0; i < indexCount; i++) {
1856
+ const index = indexes[i];
1857
+ const keys = indexKeys?.[i] ?? (index.is.parameter === string ? Object.keys(record) : getIndexSignatureKeys(record, index.is.parameter, options));
1858
+ for (let j = 0; j < keys.length; j++) keyPairs.push([keys[j], index]);
1859
+ }
1860
+ const eff = parseIndexes(state, keyPairs, { concurrency });
1861
+ if (eff) yield* eff;
1862
+ }
1863
+ if (state.issues) return yield* fail$2(new Composite(ast, state.issues, input, options));
1864
+ return out;
1865
+ });
1866
+ };
1867
+ if (indexCount) return makeFallback();
1868
+ let fallback;
1862
1869
  const resume = (state, index, pending) => {
1863
1870
  const property = properties[index];
1864
1871
  return flatMap(exit(pending), (exit) => {
@@ -1871,7 +1878,7 @@ const Objects = class extends ASTNodeImpl {
1871
1878
  };
1872
1879
  return (input, options) => {
1873
1880
  if (input === missing) return missingExit;
1874
- if (options.errors === "all" || options.onExcessProperty !== void 0 || options.concurrency !== void 0 && resolveConcurrency(options.concurrency) !== 1) return fallback(input, options);
1881
+ if (options.errors === "all" || options.onExcessProperty !== void 0 || options.concurrency !== void 0 && resolveConcurrency(options.concurrency) !== 1) return (fallback ??= makeFallback())(input, options);
1875
1882
  if (!(typeof input === "object" && input !== null && !Array.isArray(input))) return fail$2(new InvalidType(ast, input, options));
1876
1883
  const props = compileMembers();
1877
1884
  const record = input;
@@ -1981,6 +1988,7 @@ function structWithRest(ast, records) {
1981
1988
  let indexSignatures = ast.indexSignatures;
1982
1989
  let checks = ast.checks;
1983
1990
  for (const record of records) {
1991
+ for (const propertySignature of record.propertySignatures) if (propertySignatures.some((ps) => ps.name === propertySignature.name)) throw new Error(`Duplicate identifier: ${JSON.stringify(propertySignature.name)}. ts(2300)`);
1984
1992
  propertySignatures = propertySignatures.concat(record.propertySignatures);
1985
1993
  indexSignatures = indexSignatures.concat(record.indexSignatures);
1986
1994
  checks = combineChecks(checks, record.checks);
@@ -2088,8 +2096,9 @@ function collectSentinels(ast) {
2088
2096
  }
2089
2097
  const candidateIndexCache = new WeakMap();
2090
2098
  const emptyCandidates = Object.freeze([]);
2099
+ const getRuntimeType = (input) => input === null ? "null" : Array.isArray(input) ? "array" : typeof input;
2091
2100
  const hasPropertySignature = (input, key) => key === "__proto__" ? Object.hasOwn(input, key) : key in input;
2092
- function getIndex(types) {
2101
+ function getCandidateIndex(types) {
2093
2102
  let index = candidateIndexCache.get(types);
2094
2103
  if (index) return index;
2095
2104
  let bySentinel;
@@ -2097,19 +2106,19 @@ function getIndex(types) {
2097
2106
  let otherwise;
2098
2107
  let literalCandidates;
2099
2108
  let onlyLiterals = true;
2109
+ const literalOf = [];
2100
2110
  for (let i = 0; i < types.length; i++) {
2101
2111
  const a = types[i];
2102
2112
  const encoded = toCandidate(a);
2103
2113
  if (isNever(encoded)) continue;
2104
- if (onlyLiterals) {
2105
- if (isLiteral(encoded) || isUniqueSymbol(encoded)) {
2106
- literalCandidates ??= new Map();
2107
- const literal = isLiteral(encoded) ? encoded.literal : encoded.symbol;
2108
- let arr = literalCandidates.get(literal);
2109
- if (!arr) literalCandidates.set(literal, arr = []);
2110
- arr.push(a);
2111
- } else onlyLiterals = false;
2112
- }
2114
+ if (isLiteral(encoded) || isUniqueSymbol(encoded)) {
2115
+ literalCandidates ??= new Map();
2116
+ const literal = isLiteral(encoded) ? encoded.literal : encoded.symbol;
2117
+ literalOf[i] = literal;
2118
+ let arr = literalCandidates.get(literal);
2119
+ if (!arr) literalCandidates.set(literal, arr = []);
2120
+ arr.push(i);
2121
+ } else onlyLiterals = false;
2113
2122
  const sentinels = collectSentinels(encoded);
2114
2123
  if (sentinels.length) {
2115
2124
  bySentinel ??= new Map();
@@ -2128,18 +2137,21 @@ function getIndex(types) {
2128
2137
  for (const t of candidateTypes) (otherwise[t] ??= []).push(i);
2129
2138
  }
2130
2139
  }
2140
+ const fallbacks = {};
2141
+ const getFallback = (type) => fallbacks[type] ??= Object.freeze(otherwise?.[type] ?? emptyCandidates);
2131
2142
  if (onlyLiterals && literalCandidates) {
2132
2143
  literalCandidates.forEach(Object.freeze);
2133
2144
  index = (input) => literalCandidates.get(input) ?? emptyCandidates;
2134
2145
  } else if (bySentinel?.size === 1 && !otherwise) {
2135
2146
  const [key, [byValue]] = bySentinel.entries().next().value;
2136
- const candidates = byValue;
2137
- for (const [literal, indexes] of byValue) candidates.set(literal, Object.freeze(Array.from(indexes, (index) => types[index])));
2147
+ const candidates = new Map();
2148
+ for (const [literal, indexes] of byValue) candidates.set(literal, Object.freeze(Array.from(indexes)));
2149
+ const all = Object.freeze(types.map((_, i) => i));
2138
2150
  index = (input, isConstructor) => {
2139
2151
  if (isObjectKeyword(input)) {
2140
2152
  const value = hasPropertySignature(input, key) ? input[key] : void 0;
2141
2153
  if (value !== void 0) return candidates.get(value) ?? emptyCandidates;
2142
- if (isConstructor) return types;
2154
+ if (isConstructor) return all;
2143
2155
  }
2144
2156
  return emptyCandidates;
2145
2157
  };
@@ -2147,9 +2159,9 @@ function getIndex(types) {
2147
2159
  let commonSentinel;
2148
2160
  for (const entry of bySentinel) if ((!commonSentinel || entry[1][0].size > commonSentinel[1][0].size) && entry[1][1].size === sentinelCandidateCount) commonSentinel = entry;
2149
2161
  index = (input, isConstructor) => {
2150
- const base = otherwise?.[input === null ? "null" : Array.isArray(input) ? "array" : typeof input] ?? emptyCandidates;
2151
- if (!isObjectKeyword(input)) return base.map((i) => types[i]);
2152
- const selected = new Set(base);
2162
+ const runtimeType = getRuntimeType(input);
2163
+ if (!isObjectKeyword(input)) return getFallback(runtimeType);
2164
+ const selected = new Set(otherwise?.[runtimeType]);
2153
2165
  let directKey;
2154
2166
  if (commonSentinel) {
2155
2167
  const [key, [byValue]] = commonSentinel;
@@ -2157,7 +2169,7 @@ function getIndex(types) {
2157
2169
  const value = hasKey ? input[key] : void 0;
2158
2170
  if (hasKey && (!isConstructor || value !== void 0)) {
2159
2171
  const match = byValue.get(value);
2160
- if (!match) return base.map((i) => types[i]);
2172
+ if (!match) return getFallback(runtimeType);
2161
2173
  for (const i of match) selected.add(i);
2162
2174
  directKey = key;
2163
2175
  }
@@ -2179,23 +2191,15 @@ function getIndex(types) {
2179
2191
  for (const i of selected) if (all.has(i) && !match?.has(i)) selected.delete(i);
2180
2192
  }
2181
2193
  }
2182
- return Array.from(selected).sort((a, b) => a - b).map((i) => types[i]);
2194
+ return Array.from(selected).sort((a, b) => a - b);
2183
2195
  };
2184
2196
  } else index = (input) => {
2185
- return (otherwise?.[input === null ? "null" : Array.isArray(input) ? "array" : typeof input] ?? emptyCandidates).map((i) => types[i]).filter(filterLiterals(input));
2197
+ const fallback = getFallback(getRuntimeType(input));
2198
+ return literalCandidates ? fallback.filter((i) => literalOf[i] === void 0 || literalOf[i] === input) : fallback;
2186
2199
  };
2187
2200
  candidateIndexCache.set(types, index);
2188
2201
  return index;
2189
2202
  }
2190
- function filterLiterals(input) {
2191
- return (ast) => {
2192
- const encoded = toCandidate(ast);
2193
- return encoded._tag === "Literal" ? encoded.literal === input : encoded._tag === "UniqueSymbol" ? encoded.symbol === input : true;
2194
- };
2195
- }
2196
- function getCandidates(input, types, isConstructor = false) {
2197
- return getIndex(types)(input, isConstructor);
2198
- }
2199
2203
  const Union$1 = class extends ASTNodeImpl {
2200
2204
  _tag = "Union";
2201
2205
  types;
@@ -2209,34 +2213,20 @@ const Union$1 = class extends ASTNodeImpl {
2209
2213
  }
2210
2214
  getParser(compile, compileField) {
2211
2215
  const ast = this;
2216
+ const isConstructor = compileField !== void 0;
2217
+ const parsers = [];
2218
+ const parser = (i) => parsers[i] ??= compile(ast.types[i]);
2219
+ let index;
2212
2220
  return (input, options) => {
2213
2221
  if (input === missing) return missingExit;
2214
- const candidates = getCandidates(input, ast.types, compileField !== void 0);
2222
+ const candidates = (index ??= getCandidateIndex(ast.types))(input, isConstructor);
2215
2223
  if (candidates.length === 0) return fail$2(new AnyOf(ast, [], input, options));
2216
2224
  if (candidates.length === 1) {
2217
- const result = compile(candidates[0])(input, options);
2225
+ const result = parser(candidates[0])(input, options);
2218
2226
  if (result._tag === "Success") return result;
2219
- return effectIsExit(result) ? failSingleUnionCandidate(ast, result.cause, input, options) : catchCause(result, (cause) => failSingleUnionCandidate(ast, cause, input, options));
2227
+ return effectIsExit(result) ? failSingleUnionCandidate(ast, result.cause, input, options) : catchSingleUnionCandidate(ast, result, input, options);
2220
2228
  }
2221
- const state = {
2222
- ast,
2223
- compile,
2224
- input,
2225
- out: void 0,
2226
- successes: ast.options?.mode === "oneOf" ? [] : void 0,
2227
- issues: void 0,
2228
- options
2229
- };
2230
- const eff = parseUnion(state, candidates);
2231
- if (!eff) {
2232
- if (state.out) return state.out;
2233
- return fail$2(new AnyOf(ast, state.issues ?? [], input, options));
2234
- }
2235
- return flatMapEager(eff, (_) => {
2236
- if (state.out === sameExit) return succeed$3(input);
2237
- if (state.out) return state.out;
2238
- return fail$2(new AnyOf(ast, state.issues ?? [], input, options));
2239
- });
2229
+ return parseUnionCandidates(ast, parser, candidates, input, options);
2240
2230
  };
2241
2231
  }
2242
2232
  _rebuild(recur, checks, encodingChecks) {
@@ -2283,11 +2273,38 @@ function failSingleUnionCandidate(ast, cause, input, options) {
2283
2273
  if (!issue) return failCause(cause);
2284
2274
  return fail$3(new AnyOf(ast, [issue], input, options));
2285
2275
  }
2276
+ function catchSingleUnionCandidate(ast, result, input, options) {
2277
+ return catchCause(result, (cause) => failSingleUnionCandidate(ast, cause, input, options));
2278
+ }
2279
+ function parseUnionCandidates(ast, parser, candidates, input, options) {
2280
+ const state = {
2281
+ ast,
2282
+ parser,
2283
+ input,
2284
+ out: void 0,
2285
+ successes: ast.options?.mode === "oneOf" ? [] : void 0,
2286
+ issues: void 0,
2287
+ options
2288
+ };
2289
+ const eff = parseUnion(state, candidates);
2290
+ if (!eff) {
2291
+ if (state.out) return state.out;
2292
+ return fail$2(new AnyOf(ast, state.issues ?? [], input, options));
2293
+ }
2294
+ return resumeUnion(eff, state);
2295
+ }
2296
+ function resumeUnion(eff, state) {
2297
+ return flatMapEager(eff, (_) => {
2298
+ if (state.out === sameExit) return succeed$3(state.input);
2299
+ if (state.out) return state.out;
2300
+ return fail$2(new AnyOf(state.ast, state.issues ?? [], state.input, state.options));
2301
+ });
2302
+ }
2286
2303
  const parseUnion = iterateEager()({
2287
- onItem(s, ast) {
2288
- return s.compile(ast)(s.input, s.options);
2304
+ onItem(s, i) {
2305
+ return s.parser(i)(s.input, s.options);
2289
2306
  },
2290
- step(s, candidate, exit) {
2307
+ step(s, i, exit) {
2291
2308
  if (exit._tag === "Failure") {
2292
2309
  const issue = getSchemaIssue(exit.cause);
2293
2310
  if (issue === void 0) return exit;
@@ -2295,11 +2312,11 @@ const parseUnion = iterateEager()({
2295
2312
  else s.issues = [issue];
2296
2313
  } else {
2297
2314
  if (s.out && s.successes) {
2298
- s.successes.push(candidate);
2315
+ s.successes.push(s.ast.types[i]);
2299
2316
  return fail$3(new OneOf(s.ast, s.successes, s.input, s.options));
2300
2317
  }
2301
2318
  s.out = exit;
2302
- if (s.successes) s.successes.push(candidate);
2319
+ if (s.successes) s.successes.push(s.ast.types[i]);
2303
2320
  else return void_$1;
2304
2321
  }
2305
2322
  }
@@ -2397,52 +2414,47 @@ function isFinite$1(annotations) {
2397
2414
  const finite = appendChecks(number, [isFinite$1()]);
2398
2415
  const numberToJson = new Link(new Union$1([finite, nonFiniteLiterals]), new Transformation(Number$3(), transform$1((n) => globalThis.Number.isFinite(n) ? n : globalThis.String(n))));
2399
2416
  function isPattern$1(regExp, annotations) {
2400
- const source = regExp.source;
2401
- const pattern = new globalThis.RegExp(source, regExp.flags);
2417
+ const copy = new globalThis.RegExp(regExp);
2418
+ const payload = {
2419
+ source: copy.source,
2420
+ flags: copy.flags
2421
+ };
2402
2422
  return makeFilter$1((s) => {
2403
- pattern.lastIndex = 0;
2404
- return pattern.test(s);
2423
+ copy.lastIndex = 0;
2424
+ return copy.test(s);
2405
2425
  }, {
2406
- expected: `a string matching the RegExp ${source}`,
2426
+ expected: `a string matching the RegExp ${payload.source}`,
2407
2427
  representation: {
2408
2428
  id: "effect/schema/isPattern",
2409
- payload: {
2410
- source,
2411
- flags: regExp.flags
2412
- }
2429
+ payload
2413
2430
  },
2414
- toJsonSchema: () => ({ pattern: source }),
2415
- arbitraryConstraint: { patterns: [{
2416
- source: regExp.source,
2417
- flags: regExp.flags
2418
- }] },
2431
+ toJsonSchema: () => [{}, true],
2432
+ arbitraryConstraint: { patterns: [payload] },
2419
2433
  ...annotations
2420
2434
  });
2421
2435
  }
2422
- function modifyOwnPropertyDescriptors(ast, f) {
2423
- const d = Object.getOwnPropertyDescriptors(ast);
2424
- f(d);
2425
- return Object.create(Object.getPrototypeOf(ast), d);
2436
+ const bodyOwners = new WeakMap();
2437
+ function copy(ast, changes) {
2438
+ const out = Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, changes);
2439
+ if (Reflect.ownKeys(changes).every((key) => key === "context" || key === "encoding")) bodyOwners.set(out, getContextOwner(ast));
2440
+ return out;
2426
2441
  }
2427
- const contextOwners = new WeakMap();
2428
2442
  function getContextOwner(ast) {
2429
- return contextOwners.get(ast) ?? ast;
2443
+ const existing = bodyOwners.get(ast);
2444
+ if (existing !== void 0) return existing;
2445
+ if (ast.encoding === void 0) return ast;
2446
+ const owner = Object.assign(Object.create(Object.getPrototypeOf(ast)), ast, { encoding: void 0 });
2447
+ bodyOwners.set(ast, owner);
2448
+ return owner;
2430
2449
  }
2431
2450
  function replaceEncoding(ast, encoding) {
2432
- if (ast.encoding === encoding) return ast;
2433
- return modifyOwnPropertyDescriptors(ast, (d) => {
2434
- d.encoding.value = encoding;
2435
- });
2451
+ return ast.encoding === encoding ? ast : copy(ast, { encoding });
2436
2452
  }
2437
2453
  function replaceContext(ast, context) {
2438
2454
  if (ast.context === context) return ast;
2439
2455
  const owner = getContextOwner(ast);
2440
- if (owner.context === context) return owner;
2441
- const out = modifyOwnPropertyDescriptors(ast, (d) => {
2442
- d.context.value = context;
2443
- });
2444
- contextOwners.set(out, owner);
2445
- return out;
2456
+ if (owner.context === context && owner.encoding === ast.encoding) return owner;
2457
+ return copy(ast, { context });
2446
2458
  }
2447
2459
  function getLastEncoding(ast) {
2448
2460
  return ast.encoding ? getLastEncoding(ast.encoding[ast.encoding.length - 1].to) : ast;
@@ -2452,19 +2464,15 @@ function annotate(ast, annotations) {
2452
2464
  const last = ast.checks[ast.checks.length - 1];
2453
2465
  return replaceChecks(ast, append(ast.checks.slice(0, -1), last.annotate(annotations)));
2454
2466
  }
2455
- return modifyOwnPropertyDescriptors(ast, (d) => {
2456
- d.annotations.value = {
2457
- ...d.annotations.value,
2458
- ...annotations
2459
- };
2460
- });
2467
+ return copy(ast, { annotations: {
2468
+ ...ast.annotations,
2469
+ ...annotations
2470
+ } });
2461
2471
  }
2462
2472
  function replaceChecks(ast, checks) {
2463
2473
  if (ast._tag === "Suspend" && checks) throw new Error("Cannot add checks to Suspend");
2464
2474
  if (ast.checks === checks) return ast;
2465
- return modifyOwnPropertyDescriptors(ast, (d) => {
2466
- d.checks.value = checks;
2467
- });
2475
+ return copy(ast, { checks });
2468
2476
  }
2469
2477
  function appendChecks(ast, checks) {
2470
2478
  return replaceChecks(ast, combineChecks(ast.checks, checks));
@@ -2505,20 +2513,19 @@ function appendTransformation(from, transformation, to) {
2505
2513
  const link = new Link(from, transformation);
2506
2514
  return replaceEncoding(to, to.encoding ? [...to.encoding, link] : [link]);
2507
2515
  }
2508
- function brand$1(ast, brand) {
2509
- const existing = resolveBrands(ast);
2510
- return annotate(ast, { brands: existing ? [...existing, brand] : [brand] });
2511
- }
2512
2516
  function mapOrSame(as, f) {
2513
- let changed = false;
2514
- const out = new Array(as.length);
2517
+ let out;
2515
2518
  for (let i = 0; i < as.length; i++) {
2516
2519
  const a = as[i];
2517
2520
  const fa = f(a);
2518
- if (fa !== a) changed = true;
2519
- out[i] = fa;
2521
+ if (out) out[i] = fa;
2522
+ else if (fa !== a) {
2523
+ out = new Array(as.length);
2524
+ for (let j = 0; j < i; j++) out[j] = as[j];
2525
+ out[i] = fa;
2526
+ }
2520
2527
  }
2521
- return changed ? out : as;
2528
+ return out ?? as;
2522
2529
  }
2523
2530
  function annotateKey(ast, annotations) {
2524
2531
  return replaceContext(ast, ast.context ? new Context(ast.context.isOptional, ast.context.isMutable, ast.context.constructorDefault, {
@@ -2544,10 +2551,10 @@ function parseParameter(ast) {
2544
2551
  function go(ast) {
2545
2552
  switch (ast._tag) {
2546
2553
  case "Literal":
2547
- if (isPropertyKey(ast.literal)) literals.push(ast.literal);
2554
+ if (isPropertyKey(ast.literal) && !literals.includes(ast.literal)) literals.push(ast.literal);
2548
2555
  return;
2549
2556
  case "UniqueSymbol":
2550
- literals.push(ast.symbol);
2557
+ if (!literals.includes(ast.symbol)) literals.push(ast.symbol);
2551
2558
  return;
2552
2559
  case "Never": return;
2553
2560
  case "Union":
@@ -2583,16 +2590,28 @@ function extractStructuralChecks(checks) {
2583
2590
  const out = checks.flatMap(extract);
2584
2591
  return isArrayNonEmpty(out) ? out : void 0;
2585
2592
  }
2593
+ function canPreserveEncodingChecks(ast) {
2594
+ let preserve = true;
2595
+ function visit(child) {
2596
+ preserve = preserve && !child.encoding && !isSuspend(child);
2597
+ if (preserve && "recur" in child) child.recur(visit);
2598
+ return child;
2599
+ }
2600
+ if ("recur" in ast) ast.recur(visit);
2601
+ return preserve;
2602
+ }
2586
2603
  const toType$1 = memoizeIdempotent((ast) => {
2587
- if (ast.encoding) return toType$1(replaceEncoding(ast, void 0));
2588
- const out = ast;
2589
- const type = out.recur?.(toType$1) ?? out;
2590
- const encodingChecks = type.encodingChecks;
2591
- if (encodingChecks) {
2592
- const checks = type === ast ? encodingChecks : isArrays(type) || isObjects(type) || isDeclaration(type) && type.typeParameters.length > 0 ? extractStructuralChecks(encodingChecks) : void 0;
2593
- return modifyOwnPropertyDescriptors(type, (d) => {
2594
- d.encodingChecks.value = void 0;
2595
- d.checks.value = combineChecks(type.checks, checks);
2604
+ const owner = getContextOwner(ast);
2605
+ if (owner !== ast) {
2606
+ const type = toType$1(owner);
2607
+ return type === owner && ast.encoding === void 0 ? ast : replaceContext(type, ast.context);
2608
+ }
2609
+ const type = "recur" in ast ? ast.recur(toType$1) : ast;
2610
+ if ("encodingChecks" in type && type.encodingChecks) {
2611
+ const checks = canPreserveEncodingChecks(ast) ? type.encodingChecks : isArrays(type) || isObjects(type) || isDeclaration(type) && type.typeParameters.length > 0 ? extractStructuralChecks(type.encodingChecks) : void 0;
2612
+ return copy(type, {
2613
+ encodingChecks: void 0,
2614
+ checks: combineChecks(type.checks, checks)
2596
2615
  });
2597
2616
  }
2598
2617
  return type;
@@ -2612,8 +2631,12 @@ function flipEncoding(ast, encoding) {
2612
2631
  }
2613
2632
  const flip = memoize((ast) => {
2614
2633
  if (ast.encoding) return flipEncoding(ast, ast.encoding);
2615
- const out = ast;
2616
- return out.flip?.(flip) ?? out.recur?.(flip) ?? out;
2634
+ const owner = getContextOwner(ast);
2635
+ if (owner !== ast) {
2636
+ const flipped = flip(owner);
2637
+ return flipped === owner ? ast : replaceContext(flipped, ast.context);
2638
+ }
2639
+ return "flip" in ast ? ast.flip(flip) : "recur" in ast ? ast.recur(flip) : ast;
2617
2640
  });
2618
2641
  function containsUndefined(ast) {
2619
2642
  switch (ast._tag) {
@@ -2784,7 +2807,7 @@ const StringTree = new Declaration([], () => (input, ast, options) => isStringTr
2784
2807
  });
2785
2808
  const unknownToStringTree = new Link(StringTree, passthrough());
2786
2809
  //#endregion
2787
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/interpreter.js
2810
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/interpreter.js
2788
2811
  const flatMapTransformation = (result, current, f) => result === sameExit ? f(current) : flatMapEager(result, f);
2789
2812
  function compileTransformation(transformation) {
2790
2813
  if (transformation._tag === "Middleware") return (result, current, options) => {
@@ -2916,7 +2939,7 @@ function compile(ast, compile, compileField, base, specialize) {
2916
2939
  };
2917
2940
  }
2918
2941
  //#endregion
2919
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/compilerRegistry.js
2942
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/compilerRegistry.js
2920
2943
  const invalid = Symbol();
2921
2944
  const cache = new WeakMap();
2922
2945
  let compiler;
@@ -3004,7 +3027,7 @@ function resolve(ast) {
3004
3027
  return entry;
3005
3028
  }
3006
3029
  //#endregion
3007
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/SchemaParser.js
3030
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/SchemaParser.js
3008
3031
  function makeEffect(schema) {
3009
3032
  const ast = schema.ast;
3010
3033
  let parser;
@@ -3158,10 +3181,35 @@ function makeConstructorSync(ast) {
3158
3181
  const normalCompiler = (ast) => resolve(ast).parser;
3159
3182
  const constructorCompiler = (ast) => resolve(ast).makeEffect;
3160
3183
  //#endregion
3161
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/make.js
3184
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/make.js
3162
3185
  const TypeId$1 = "~effect/Schema/Schema";
3186
+ const RebuildOptions = Symbol();
3163
3187
  const SchemaProto = {
3164
3188
  [TypeId$1]: TypeId$1,
3189
+ get make() {
3190
+ const value = make$2(this);
3191
+ Object.defineProperty(this, "make", {
3192
+ value,
3193
+ enumerable: true
3194
+ });
3195
+ return value;
3196
+ },
3197
+ get makeEffect() {
3198
+ const value = makeEffect(this);
3199
+ Object.defineProperty(this, "makeEffect", {
3200
+ value,
3201
+ enumerable: true
3202
+ });
3203
+ return value;
3204
+ },
3205
+ get makeOption() {
3206
+ const value = makeOption(this);
3207
+ Object.defineProperty(this, "makeOption", {
3208
+ value,
3209
+ enumerable: true
3210
+ });
3211
+ return value;
3212
+ },
3165
3213
  pipe() {
3166
3214
  return pipeArguments(this, arguments);
3167
3215
  },
@@ -3173,6 +3221,9 @@ const SchemaProto = {
3173
3221
  },
3174
3222
  check(...checks) {
3175
3223
  return this.rebuild(appendChecks(this.ast, checks));
3224
+ },
3225
+ rebuild(ast) {
3226
+ return make$1(ast, this[RebuildOptions]);
3176
3227
  }
3177
3228
  };
3178
3229
  function make$1(ast, options) {
@@ -3180,15 +3231,12 @@ function make$1(ast, options) {
3180
3231
  const self = Object.setPrototypeOf(Schema, SchemaProto);
3181
3232
  if (options && (Object.hasOwn(options, "name") || Object.hasOwn(options, "length") || Object.hasOwn(options, "__proto__"))) Object.defineProperties(self, Object.getOwnPropertyDescriptors({ ...options }));
3182
3233
  else Object.assign(self, options);
3234
+ self[RebuildOptions] = options;
3183
3235
  self.ast = ast;
3184
- self.rebuild = (ast) => make$1(ast, options);
3185
- self.makeEffect = makeEffect(self);
3186
- self.make = make$2(self);
3187
- self.makeOption = makeOption(self);
3188
3236
  return self;
3189
3237
  }
3190
3238
  //#endregion
3191
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/JsonPointer.js
3239
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/JsonPointer.js
3192
3240
  function escapeToken(token) {
3193
3241
  return token.replace(/~/g, "~0").replace(/\//g, "~1");
3194
3242
  }
@@ -3215,7 +3263,7 @@ function parseUriFragment(fragment) {
3215
3263
  return pointer === void 0 ? void 0 : pointer.length === 0 ? [] : pointer.slice(1).split("/").map(unescapeToken);
3216
3264
  }
3217
3265
  //#endregion
3218
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/JsonSchema.js
3266
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/JsonSchema.js
3219
3267
  function getReferenceKey($ref) {
3220
3268
  const path = $ref.startsWith("#") ? parseUriFragment($ref) : void 0;
3221
3269
  return path !== void 0 && path.length === 2 && path[0] === "$defs" ? path[1] : void 0;
@@ -3311,7 +3359,7 @@ const OPEN_API_30_TO_2020_COLLISIONS = [
3311
3359
  "then"
3312
3360
  ];
3313
3361
  //#endregion
3314
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/toCodec.js
3362
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/toCodec.js
3315
3363
  function toCodecJson$1(schema) {
3316
3364
  return make$1(toCodecJsonAST(schema.ast), { schema });
3317
3365
  }
@@ -3329,16 +3377,7 @@ function validateCanonicalObjectPropertyNames(ast) {
3329
3377
  }
3330
3378
  function makeReorder(getPriority) {
3331
3379
  return (types) => {
3332
- const indexMap = new Map();
3333
- for (let i = 0; i < types.length; i++) indexMap.set(toEncoded$1(types[i]), i);
3334
- const sortedTypes = [...types].sort((a, b) => {
3335
- a = toEncoded$1(a);
3336
- b = toEncoded$1(b);
3337
- const pa = getPriority(a);
3338
- const pb = getPriority(b);
3339
- if (pa !== pb) return pa - pb;
3340
- return indexMap.get(a) - indexMap.get(b);
3341
- });
3380
+ const sortedTypes = [...types].sort((a, b) => getPriority(toEncoded$1(a)) - getPriority(toEncoded$1(b)));
3342
3381
  if (!sortedTypes.some((ast, index) => ast !== types[index])) return types;
3343
3382
  return sortedTypes;
3344
3383
  };
@@ -3446,17 +3485,17 @@ const toCodecStringTreeAST = applyToSelfOrLastLinkEncodingIdempotent((ast) => {
3446
3485
  return out;
3447
3486
  }, { stopAt: isCodecArrayFromSingleLink });
3448
3487
  //#endregion
3449
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/RegExp.js
3488
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/RegExp.js
3450
3489
  const RegExp$1 = globalThis.RegExp;
3451
3490
  const escape = (string) => string.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&");
3452
3491
  //#endregion
3453
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/errors.js
3492
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/errors.js
3454
3493
  function errorWithPath(message, path) {
3455
3494
  if (path.length > 0) message += `\n at ${formatPath(path)}`;
3456
3495
  return new Error(message);
3457
3496
  }
3458
3497
  //#endregion
3459
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/toJsonSchemaDocument.js
3498
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/toJsonSchemaDocument.js
3460
3499
  function formatDefinitionReference(key) {
3461
3500
  return `#/$defs/${formatUriFragmentToken(key)}`;
3462
3501
  }
@@ -3579,44 +3618,62 @@ function appendJsonSchema(left, right, inlineCheck) {
3579
3618
  allOf: members
3580
3619
  };
3581
3620
  }
3621
+ function isExact(exactness, seen = new Set()) {
3622
+ if (typeof exactness === "boolean") return exactness;
3623
+ if (seen.has(exactness)) return true;
3624
+ seen.add(exactness);
3625
+ return exactness.every((dependency) => isExact(dependency, seen));
3626
+ }
3627
+ function isApproximateCheckOutput(output) {
3628
+ return Array.isArray(output);
3629
+ }
3582
3630
  function compileJsonSchema(representations, rootPaths, references, options) {
3583
- const definitionStates = new Map();
3631
+ const compiledDefinitions = new Map();
3632
+ const definitionAliases = new Map();
3584
3633
  const compiledRepresentations = new WeakMap();
3634
+ const pendingOneOf = new Map();
3585
3635
  const fallbackDefinitions = new Map();
3586
3636
  const referenceKeys = Object.keys(references);
3587
3637
  for (const key of referenceKeys) compileDefinition(key, ["references", key]);
3588
- const schemas = map$3(representations, (representation, index) => finalizeJsonSchema(recur(representation, rootPaths[index])));
3589
- const definitions = {};
3590
- for (const key of referenceKeys) {
3591
- const compiled = definitionStates.get(key);
3592
- if (typeof compiled !== "string") assignProperty$1(definitions, key, finalizeJsonSchema(compiled));
3638
+ const compiledSchemas = map$3(representations, (representation, index) => recur(representation, rootPaths[index], []));
3639
+ for (const [branches, schemas] of pendingOneOf.values()) if (!isExact(branches)) {
3640
+ for (const schema of schemas) if (Array.isArray(schema.oneOf)) {
3641
+ schema.anyOf = schema.oneOf;
3642
+ delete schema.oneOf;
3643
+ }
3593
3644
  }
3645
+ for (const key of referenceKeys) {
3646
+ const representation = references[key];
3647
+ const fallback = getIdentifierFallback(representation);
3648
+ if (fallback === void 0) continue;
3649
+ const schema = compiledDefinitions.get(key)[0];
3650
+ const candidates = fallbackDefinitions.get(fallback);
3651
+ const match = candidates?.find((candidate) => equals(compiledDefinitions.get(candidate)[0], schema));
3652
+ if (match === void 0) {
3653
+ if (candidates === void 0) fallbackDefinitions.set(fallback, [key]);
3654
+ else candidates.push(key);
3655
+ } else definitionAliases.set(key, match);
3656
+ }
3657
+ const schemas = map$3(compiledSchemas, finalizeJsonSchema);
3658
+ const definitions = {};
3659
+ for (const key of referenceKeys) if (!definitionAliases.has(key)) assignProperty$1(definitions, key, finalizeJsonSchema(compiledDefinitions.get(key)[0]));
3594
3660
  return {
3595
3661
  dialect: "draft-2020-12",
3596
3662
  schemas,
3597
3663
  definitions
3598
3664
  };
3665
+ function registerPendingOneOf(schema) {
3666
+ if (Array.isArray(schema.oneOf)) pendingOneOf.get(schema.oneOf)?.[1].push(schema);
3667
+ return schema;
3668
+ }
3599
3669
  function compileDefinition(key, path) {
3600
- const compiled = definitionStates.get(key);
3601
- if (compiled !== void 0) return typeof compiled === "string" ? compiled : key;
3602
3670
  if (!Object.hasOwn(references, key)) throw errorWithPath(`Invalid reference ${key}`, [...path, "$ref"]);
3603
- definitionStates.set(key, null);
3604
- const representation = references[key];
3605
- const schema = recur(representation, ["references", key]);
3606
- const fallback = getIdentifierFallback(representation);
3607
- if (fallback !== void 0) {
3608
- const candidates = fallbackDefinitions.get(fallback);
3609
- const match = candidates?.find((candidate) => equals(definitionStates.get(candidate), schema));
3610
- if (match === void 0) {
3611
- if (candidates === void 0) fallbackDefinitions.set(fallback, [key]);
3612
- else candidates.push(key);
3613
- } else {
3614
- definitionStates.set(key, match);
3615
- return match;
3616
- }
3617
- }
3618
- definitionStates.set(key, schema);
3619
- return key;
3671
+ const cached = compiledDefinitions.get(key);
3672
+ if (cached !== void 0) return cached;
3673
+ const result = [{}, []];
3674
+ compiledDefinitions.set(key, result);
3675
+ result[0] = recur(references[key], ["references", key], result[1]);
3676
+ return result;
3620
3677
  }
3621
3678
  function finalizeJsonSchema(schema) {
3622
3679
  return rewriteRefs(schema, ($ref) => {
@@ -3627,8 +3684,8 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3627
3684
  }
3628
3685
  if (!pointer.startsWith("/$defs/")) return $ref;
3629
3686
  const separator = pointer.indexOf("/", 7);
3630
- const canonical = definitionStates.get(unescapeToken(pointer.slice(7, separator < 0 ? void 0 : separator)));
3631
- if (typeof canonical !== "string") return $ref;
3687
+ const canonical = definitionAliases.get(unescapeToken(pointer.slice(7, separator < 0 ? void 0 : separator)));
3688
+ if (canonical === void 0) return $ref;
3632
3689
  return $ref.replace(/^#(?:\/|%2f).*?(?:\/|%2f).*?(?=\/|%2f|$)/i, formatDefinitionReference(canonical));
3633
3690
  });
3634
3691
  }
@@ -3637,48 +3694,63 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3637
3694
  const annotations = representation.checks.length === 0 ? representation.annotations : representation.checks[representation.checks.length - 1].annotations;
3638
3695
  return typeof annotations?.identifier !== "string" && typeof annotations?.["~identifier"] === "string" ? annotations[IDENTIFIER_FALLBACK_KEY] : void 0;
3639
3696
  }
3640
- function annotationSchemas(representation, path) {
3641
- return representation?.schemas?.map((schema, index) => recur(schema, [
3642
- ...path,
3643
- "schemas",
3644
- index
3645
- ])) ?? [];
3646
- }
3647
- function compileCheck(check, type, path) {
3697
+ function compileCheck(check, type, path, dependencies) {
3648
3698
  const annotations = check.annotations;
3649
3699
  const callback = annotations?.toJsonSchema;
3650
3700
  if (callback !== void 0) {
3651
- const fragment = callback({
3701
+ const result = callback({
3652
3702
  type,
3653
- schemas: annotationSchemas(check.representation, [...path, "representation"])
3703
+ schemas: check.representation?.schemas?.map((schema, index) => recur(schema, [
3704
+ ...path,
3705
+ "representation",
3706
+ "schemas",
3707
+ index
3708
+ ], dependencies)) ?? []
3654
3709
  });
3710
+ const approximate = isApproximateCheckOutput(result);
3711
+ if (approximate) dependencies.push(false);
3712
+ const fragment = approximate ? result[0] : result;
3655
3713
  const ordinary = collectJsonSchemaAnnotations(annotations, options);
3656
3714
  const schema = ordinary === void 0 ? fragment : {
3657
3715
  ...fragment,
3658
3716
  ...ordinary
3659
3717
  };
3660
3718
  const allowed = ordinary === void 0 ? inlineableCheckKeywords : inlineableAnnotatedCheckKeywords;
3661
- return check._tag === "Filter" && hasOnlyKeywords(schema, allowed) && (ordinary === void 0 || hasOnlyKeywords(ordinary, promotableAnnotationKeywords)) ? [schema, true] : [schema];
3719
+ return [schema, check._tag === "Filter" && hasOnlyKeywords(schema, allowed) && (ordinary === void 0 || hasOnlyKeywords(ordinary, promotableAnnotationKeywords)) ? true : void 0];
3662
3720
  }
3663
- if (check._tag === "Filter") return void 0;
3664
- const children = check.checks.map((child, index) => compileCheck(child, type, [
3665
- ...path,
3666
- "checks",
3667
- index
3668
- ])).filter((child) => child !== void 0);
3669
- if (children.length === 0) return void 0;
3721
+ if (check._tag === "Filter") {
3722
+ dependencies.push(false);
3723
+ return;
3724
+ }
3725
+ const schemas = check.checks.flatMap((child, index) => {
3726
+ const result = compileCheck(child, type, [
3727
+ ...path,
3728
+ "checks",
3729
+ index
3730
+ ], dependencies);
3731
+ return result === void 0 ? [] : [result[0]];
3732
+ });
3733
+ if (schemas.length === 0) return void 0;
3670
3734
  const ordinary = collectJsonSchemaAnnotations(annotations, options);
3671
- const allOf = children.map(([schema]) => schema);
3672
- return [ordinary === void 0 ? { allOf } : {
3673
- allOf,
3735
+ const schema = { allOf: schemas };
3736
+ return [ordinary === void 0 ? schema : {
3737
+ ...schema,
3674
3738
  ...ordinary
3675
3739
  }];
3676
3740
  }
3677
- function recur(representation, path) {
3678
- if (representation._tag === "Reference") return { $ref: formatDefinitionReference(compileDefinition(representation.$ref, path)) };
3741
+ function recur(representation, path, dependencies) {
3742
+ if (representation._tag === "Reference") {
3743
+ dependencies.push(compileDefinition(representation.$ref, path)[1]);
3744
+ return { $ref: formatDefinitionReference(representation.$ref) };
3745
+ }
3679
3746
  const cached = compiledRepresentations.get(representation);
3680
- if (cached !== void 0) return cached;
3681
- let output = on(representation, path);
3747
+ if (cached !== void 0) {
3748
+ dependencies.push(cached[1]);
3749
+ return cached[0];
3750
+ }
3751
+ const local = [];
3752
+ dependencies.push(local);
3753
+ let output = on(representation, path, local);
3682
3754
  const ordinary = collectJsonSchemaAnnotations(representation.annotations, options);
3683
3755
  if (ordinary !== void 0) output = {
3684
3756
  ...output,
@@ -3690,13 +3762,13 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3690
3762
  ...path,
3691
3763
  "checks",
3692
3764
  index
3693
- ]);
3765
+ ], local);
3694
3766
  if (check !== void 0) output = appendJsonSchema(output, ...check);
3695
3767
  }
3696
- compiledRepresentations.set(representation, output);
3697
- return output;
3768
+ compiledRepresentations.set(representation, [output, local]);
3769
+ return registerPendingOneOf(output);
3698
3770
  }
3699
- function on(representation, path) {
3771
+ function on(representation, path, dependencies) {
3700
3772
  switch (representation._tag) {
3701
3773
  case "Any":
3702
3774
  case "Unknown": return {};
@@ -3716,8 +3788,10 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3716
3788
  type: "string",
3717
3789
  enum: [globalThis.String(representation.symbol)]
3718
3790
  };
3719
- case "Declaration": return {};
3720
- case "Suspend": return recur(representation.thunk, [...path, "thunk"]);
3791
+ case "Declaration":
3792
+ dependencies.push(false);
3793
+ return {};
3794
+ case "Suspend": return recur(representation.thunk, [...path, "thunk"], dependencies);
3721
3795
  case "Never": return { not: {} };
3722
3796
  case "String": return { type: "string" };
3723
3797
  case "Number": return { anyOf: [{ type: "number" }, {
@@ -3765,14 +3839,14 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3765
3839
  let minItems = representation.elements.length;
3766
3840
  const prefixItems = representation.elements.map((element, index) => {
3767
3841
  if (element.isOptional) minItems--;
3768
- const compiled = recur(element.type, [
3842
+ const schema = recur(element.type, [
3769
3843
  ...path,
3770
3844
  "elements",
3771
3845
  index,
3772
3846
  "type"
3773
- ]);
3847
+ ], dependencies);
3774
3848
  const annotations = collectJsonSchemaAnnotations(element.annotations, options);
3775
- return annotations === void 0 ? compiled : appendJsonSchema(compiled, annotations);
3849
+ return annotations === void 0 ? schema : registerPendingOneOf(appendJsonSchema(schema, annotations));
3776
3850
  });
3777
3851
  if (prefixItems.length > 0) {
3778
3852
  out.prefixItems = prefixItems;
@@ -3785,7 +3859,7 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3785
3859
  ...path,
3786
3860
  "rest",
3787
3861
  0
3788
- ]);
3862
+ ], dependencies);
3789
3863
  if (Object.keys(rest).length > 0) out.items = rest;
3790
3864
  else delete out.items;
3791
3865
  }
@@ -3805,14 +3879,14 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3805
3879
  "name"
3806
3880
  ]);
3807
3881
  const name = property.name;
3808
- const compiled = recur(property.type, [
3882
+ const schema = recur(property.type, [
3809
3883
  ...path,
3810
3884
  "propertySignatures",
3811
3885
  index,
3812
3886
  "type"
3813
- ]);
3887
+ ], dependencies);
3814
3888
  const annotations = collectJsonSchemaAnnotations(property.annotations, options);
3815
- assignProperty$1(properties, name, annotations === void 0 ? compiled : appendJsonSchema(compiled, annotations));
3889
+ assignProperty$1(properties, name, annotations === void 0 ? schema : registerPendingOneOf(appendJsonSchema(schema, annotations)));
3816
3890
  if (!property.isOptional) required.push(name);
3817
3891
  }
3818
3892
  if (representation.propertySignatures.length > 0) out.properties = properties;
@@ -3828,7 +3902,7 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3828
3902
  "indexSignatures",
3829
3903
  index,
3830
3904
  "type"
3831
- ]);
3905
+ ], dependencies);
3832
3906
  if (equals(type, { not: {} })) type = false;
3833
3907
  indexValueSchemas.push(type);
3834
3908
  const patterns = getParameterPatterns(signature.parameter, [
@@ -3839,12 +3913,13 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3839
3913
  ], new Set());
3840
3914
  if (patterns === void 0) {
3841
3915
  hasUnrepresentableIndexPattern = true;
3916
+ dependencies.push(false);
3842
3917
  continue;
3843
3918
  }
3844
3919
  if (patterns.length === 0) additionalPropertySchemas.push(type);
3845
3920
  else for (const pattern of patterns) {
3846
3921
  const previous = patternProperties[pattern];
3847
- assignProperty$1(patternProperties, pattern, previous === void 0 ? type : previous === false || type === false ? false : appendJsonSchema(previous, type));
3922
+ assignProperty$1(patternProperties, pattern, previous === void 0 ? type : previous === false || type === false ? false : registerPendingOneOf(appendJsonSchema(previous, type)));
3848
3923
  }
3849
3924
  }
3850
3925
  const hasPatternProperties = Object.keys(patternProperties).length > 0;
@@ -3857,7 +3932,7 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3857
3932
  "indexSignatures",
3858
3933
  index,
3859
3934
  "parameter"
3860
- ]));
3935
+ ], dependencies));
3861
3936
  out.propertyNames = propertyNames.length === 1 ? propertyNames[0] : { anyOf: propertyNames };
3862
3937
  out.additionalProperties = indexValueSchemas.length === 1 ? indexValueSchemas[0] : { anyOf: indexValueSchemas };
3863
3938
  if (additionalPropertySchemas.length > 0) out.allOf = additionalPropertySchemas.map((type) => ({
@@ -3874,18 +3949,21 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3874
3949
  return out;
3875
3950
  }
3876
3951
  case "Union": {
3952
+ const branches = [];
3877
3953
  const types = representation.types.map((type, index) => recur(type, [
3878
3954
  ...path,
3879
3955
  "types",
3880
3956
  index
3881
- ]));
3957
+ ], branches));
3958
+ dependencies.push(branches);
3882
3959
  if (types.length === 0) return { not: {} };
3883
3960
  const mode = representation.options?.mode ?? "anyOf";
3884
3961
  if (mode === "anyOf" && types.length > 1) {
3885
3962
  const compacted = compactEnums(types);
3886
3963
  if (compacted !== void 0) return compacted;
3887
3964
  }
3888
- return mode === "anyOf" ? { anyOf: types } : { oneOf: types };
3965
+ if (mode === "oneOf") pendingOneOf.set(types, [branches, []]);
3966
+ return { [mode]: types };
3889
3967
  }
3890
3968
  }
3891
3969
  }
@@ -3901,7 +3979,9 @@ function compileJsonSchema(representations, rootPaths, references, options) {
3901
3979
  case "String": {
3902
3980
  if (parameter.checks.length === 0) return [];
3903
3981
  if (parameter.checks.length !== 1 || parameter.checks[0]._tag !== "Filter" || parameter.checks[0].annotations?.toJsonSchema === void 0) return;
3904
- const schema = recur(parameter, path);
3982
+ const dependencies = [];
3983
+ const schema = recur(parameter, path, dependencies);
3984
+ if (!isExact(dependencies)) return void 0;
3905
3985
  return schema.type === "string" && typeof schema.pattern === "string" && hasOnlyKeywords(schema, "|type|pattern|title|description|default|examples|readOnly|writeOnly|") ? [schema.pattern] : void 0;
3906
3986
  }
3907
3987
  case "TemplateLiteral": return parameter.checks.length === 0 ? [`^${parameter.parts.map(getPartPattern).join("")}$`] : void 0;
@@ -3963,7 +4043,7 @@ function toJsonSchemaDocument$1(document, options) {
3963
4043
  };
3964
4044
  }
3965
4045
  //#endregion
3966
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schema/toRepresentation.js
4046
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schema/toRepresentation.js
3967
4047
  const defaultReferencePolicy = ({ identifier }) => identifier;
3968
4048
  function annotationsField(annotations) {
3969
4049
  return annotations === void 0 ? void 0 : { annotations };
@@ -4227,7 +4307,7 @@ function toRepresentations(asts, options) {
4227
4307
  }
4228
4308
  }
4229
4309
  //#endregion
4230
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Struct.js
4310
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Struct.js
4231
4311
  const omit = dual(2, (self, keys) => {
4232
4312
  return buildStruct(self, (k, v) => !hasPropertyKey(keys, k) ? [k, v] : void 0);
4233
4313
  });
@@ -4251,13 +4331,13 @@ function buildStruct(source, f) {
4251
4331
  return out;
4252
4332
  }
4253
4333
  //#endregion
4254
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/internal/schemaError.js
4334
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/internal/schemaError.js
4255
4335
  const SchemaErrorTypeId = "~effect/Schema/SchemaError";
4256
4336
  function isSchemaError$1(u) {
4257
4337
  return hasProperty(u, "~effect/Schema/SchemaError") && u["~effect/Schema/SchemaError"] === "~effect/Schema/SchemaError";
4258
4338
  }
4259
4339
  //#endregion
4260
- //#region node_modules/.pnpm/effect@https+++pkg.pr.new+Effect-TS+effect+effect@b3032f0_f95638f588f5b9b247401a051448b365/node_modules/effect/dist/Schema.js
4340
+ //#region node_modules/.pnpm/effect@4.0.0/node_modules/effect/dist/Schema.js
4261
4341
  const TypeId = TypeId$1;
4262
4342
  function declareConstructor() {
4263
4343
  return (typeParameters, run, annotations) => {
@@ -4438,7 +4518,7 @@ function check(...checks) {
4438
4518
  return (self) => self.check(...checks);
4439
4519
  }
4440
4520
  function brand(identifier) {
4441
- return (schema) => make(brand$1(schema.ast, identifier), {
4521
+ return (schema) => make(schema.ast, {
4442
4522
  schema,
4443
4523
  identifier
4444
4524
  });
@@ -4610,8 +4690,10 @@ function makeFilterGroup(checks, annotations = void 0) {
4610
4690
  function isPattern(regExp, annotations) {
4611
4691
  const source = regExp.source;
4612
4692
  const flags = regExp.flags;
4693
+ const canExport = /^[dg]*uy?$/.test(flags);
4613
4694
  const runtimeRegExp = flags === "" ? `new RegExp(${format$1(source)})` : `new RegExp(${format$1(source)}, ${format$1(flags)})`;
4614
4695
  return isPattern$1(regExp, {
4696
+ toJsonSchema: () => canExport ? { pattern: flags.endsWith("y") ? `^(?:${source})` : source } : [{}, true],
4615
4697
  toCode: () => ({ runtime: `Schema.isPattern(${runtimeRegExp})` }),
4616
4698
  ...annotations
4617
4699
  });
@@ -4794,7 +4876,7 @@ function isInt(annotations) {
4794
4876
  id: "effect/schema/isInt",
4795
4877
  payload: null
4796
4878
  },
4797
- toJsonSchema: () => ({ type: "integer" }),
4879
+ toJsonSchema: () => [{ type: "integer" }, true],
4798
4880
  toCode: () => ({ runtime: "Schema.isInt()" }),
4799
4881
  arbitraryConstraint: { number: "integer" },
4800
4882
  ...annotations
@@ -4817,7 +4899,7 @@ const isGreaterThanDate = makeIsGreaterThan({
4817
4899
  id: "effect/schema/isGreaterThanDate",
4818
4900
  payload: { exclusiveMinimum: encodeDatePayload(exclusiveMinimum) }
4819
4901
  },
4820
- toJsonSchema: () => ({}),
4902
+ toJsonSchema: () => [{}, true],
4821
4903
  toCode: () => ({ runtime: `Schema.isGreaterThanDate(${formatDateRuntime(exclusiveMinimum)})` })
4822
4904
  };
4823
4905
  }
@@ -4830,7 +4912,7 @@ const isGreaterThanOrEqualToDate = makeIsGreaterThanOrEqualTo({
4830
4912
  id: "effect/schema/isGreaterThanOrEqualToDate",
4831
4913
  payload: { minimum: encodeDatePayload(minimum) }
4832
4914
  },
4833
- toJsonSchema: () => ({}),
4915
+ toJsonSchema: () => [{}, true],
4834
4916
  toCode: () => ({ runtime: `Schema.isGreaterThanOrEqualToDate(${formatDateRuntime(minimum)})` })
4835
4917
  };
4836
4918
  }
@@ -4843,7 +4925,7 @@ const isLessThanDate = makeIsLessThan({
4843
4925
  id: "effect/schema/isLessThanDate",
4844
4926
  payload: { exclusiveMaximum: encodeDatePayload(exclusiveMaximum) }
4845
4927
  },
4846
- toJsonSchema: () => ({}),
4928
+ toJsonSchema: () => [{}, true],
4847
4929
  toCode: () => ({ runtime: `Schema.isLessThanDate(${formatDateRuntime(exclusiveMaximum)})` })
4848
4930
  };
4849
4931
  }
@@ -4856,7 +4938,7 @@ const isLessThanOrEqualToDate = makeIsLessThanOrEqualTo({
4856
4938
  id: "effect/schema/isLessThanOrEqualToDate",
4857
4939
  payload: { maximum: encodeDatePayload(maximum) }
4858
4940
  },
4859
- toJsonSchema: () => ({}),
4941
+ toJsonSchema: () => [{}, true],
4860
4942
  toCode: () => ({ runtime: `Schema.isLessThanOrEqualToDate(${formatDateRuntime(maximum)})` })
4861
4943
  };
4862
4944
  }
@@ -4876,7 +4958,7 @@ const isBetweenDate = makeIsBetween({
4876
4958
  ...exclusiveMaximum && { exclusiveMaximum }
4877
4959
  }
4878
4960
  },
4879
- toJsonSchema: () => ({}),
4961
+ toJsonSchema: () => [{}, true],
4880
4962
  toCode: () => ({ runtime: `Schema.isBetweenDate({ minimum: ${formatDateRuntime(options.minimum)}, maximum: ${formatDateRuntime(options.maximum)}, exclusiveMinimum: ${format$1(exclusiveMinimum)}, exclusiveMaximum: ${format$1(exclusiveMaximum)} })` })
4881
4963
  };
4882
4964
  }
@@ -4889,7 +4971,7 @@ const isGreaterThanBigInt = makeIsGreaterThan({
4889
4971
  id: "effect/schema/isGreaterThanBigInt",
4890
4972
  payload: { exclusiveMinimum: exclusiveMinimum.toString(10) }
4891
4973
  },
4892
- toJsonSchema: () => ({}),
4974
+ toJsonSchema: () => [{}, true],
4893
4975
  toCode: () => ({ runtime: `Schema.isGreaterThanBigInt(${format$1(exclusiveMinimum)})` })
4894
4976
  };
4895
4977
  }
@@ -4902,7 +4984,7 @@ const isGreaterThanOrEqualToBigInt = makeIsGreaterThanOrEqualTo({
4902
4984
  id: "effect/schema/isGreaterThanOrEqualToBigInt",
4903
4985
  payload: { minimum: minimum.toString(10) }
4904
4986
  },
4905
- toJsonSchema: () => ({}),
4987
+ toJsonSchema: () => [{}, true],
4906
4988
  toCode: () => ({ runtime: `Schema.isGreaterThanOrEqualToBigInt(${format$1(minimum)})` })
4907
4989
  };
4908
4990
  }
@@ -4915,7 +4997,7 @@ const isLessThanBigInt = makeIsLessThan({
4915
4997
  id: "effect/schema/isLessThanBigInt",
4916
4998
  payload: { exclusiveMaximum: exclusiveMaximum.toString(10) }
4917
4999
  },
4918
- toJsonSchema: () => ({}),
5000
+ toJsonSchema: () => [{}, true],
4919
5001
  toCode: () => ({ runtime: `Schema.isLessThanBigInt(${format$1(exclusiveMaximum)})` })
4920
5002
  };
4921
5003
  }
@@ -4928,7 +5010,7 @@ const isLessThanOrEqualToBigInt = makeIsLessThanOrEqualTo({
4928
5010
  id: "effect/schema/isLessThanOrEqualToBigInt",
4929
5011
  payload: { maximum: maximum.toString(10) }
4930
5012
  },
4931
- toJsonSchema: () => ({}),
5013
+ toJsonSchema: () => [{}, true],
4932
5014
  toCode: () => ({ runtime: `Schema.isLessThanOrEqualToBigInt(${format$1(maximum)})` })
4933
5015
  };
4934
5016
  }
@@ -4948,20 +5030,26 @@ const isBetweenBigInt = makeIsBetween({
4948
5030
  ...exclusiveMaximum && { exclusiveMaximum }
4949
5031
  }
4950
5032
  },
4951
- toJsonSchema: () => ({}),
5033
+ toJsonSchema: () => [{}, true],
4952
5034
  toCode: () => ({ runtime: `Schema.isBetweenBigInt({ minimum: ${format$1(options.minimum)}, maximum: ${format$1(options.maximum)}, exclusiveMinimum: ${format$1(exclusiveMinimum)}, exclusiveMaximum: ${format$1(exclusiveMaximum)} })` })
4953
5035
  };
4954
5036
  }
4955
5037
  });
4956
5038
  function isMinLength(minLength, annotations) {
4957
- minLength = Math.max(0, Math.floor(minLength));
5039
+ minLength = normalizeCardinality(minLength);
5040
+ return makeIsMinLength(minLength, Math.ceil(minLength / 2), annotations);
5041
+ }
5042
+ function makeIsMinLength(minLength, minCodePoints, annotations) {
4958
5043
  return makeFilter((input) => input.length >= minLength, {
4959
5044
  expected: `a value with a length of at least ${minLength}`,
4960
5045
  representation: {
4961
5046
  id: "effect/schema/isMinLength",
4962
5047
  payload: { minLength }
4963
5048
  },
4964
- toJsonSchema: ({ type }) => type === "array" ? { minItems: minLength } : { minLength },
5049
+ toJsonSchema: ({ type }) => type === "string" ? minLength <= 1 ? { minLength: minCodePoints } : [{ minLength: minCodePoints }, true] : type === "array" ? { minItems: minLength } : type === void 0 ? [{
5050
+ minLength: minCodePoints,
5051
+ minItems: minLength
5052
+ }, true] : [{}, true],
4965
5053
  toCode: () => ({ runtime: `Schema.isMinLength(${minLength})` }),
4966
5054
  [STRUCTURAL_ANNOTATION_KEY]: true,
4967
5055
  arbitraryConstraint: { minLength },
@@ -4969,32 +5057,39 @@ function isMinLength(minLength, annotations) {
4969
5057
  });
4970
5058
  }
4971
5059
  function isNonEmpty(annotations) {
4972
- return isMinLength(1, annotations);
5060
+ return makeIsMinLength(1, 1, annotations);
4973
5061
  }
4974
5062
  function isMaxLength(maxLength, annotations) {
4975
- maxLength = Math.max(0, Math.floor(maxLength));
5063
+ maxLength = normalizeCardinality(maxLength);
4976
5064
  return makeFilter((input) => input.length <= maxLength, {
4977
5065
  expected: `a value with a length of at most ${maxLength}`,
4978
5066
  representation: {
4979
5067
  id: "effect/schema/isMaxLength",
4980
5068
  payload: { maxLength }
4981
5069
  },
4982
- toJsonSchema: ({ type }) => type === "array" ? { maxItems: maxLength } : { maxLength },
5070
+ toJsonSchema: ({ type }) => type === "string" ? maxLength === 0 ? { maxLength } : [{ maxLength }, true] : type === "array" ? { maxItems: maxLength } : type === void 0 ? [{
5071
+ maxLength,
5072
+ maxItems: maxLength
5073
+ }, true] : [{}, true],
4983
5074
  toCode: () => ({ runtime: `Schema.isMaxLength(${maxLength})` }),
4984
5075
  [STRUCTURAL_ANNOTATION_KEY]: true,
4985
5076
  arbitraryConstraint: { maxLength },
4986
5077
  ...annotations
4987
5078
  });
4988
5079
  }
5080
+ function normalizeCardinality(value) {
5081
+ if (!globalThis.Number.isFinite(value)) throw new globalThis.RangeError(`Expected a finite number, got ${value}`);
5082
+ return Math.max(0, Math.floor(value));
5083
+ }
4989
5084
  function isMaxProperties(maxProperties, annotations) {
4990
- maxProperties = Math.max(0, Math.floor(maxProperties));
5085
+ maxProperties = normalizeCardinality(maxProperties);
4991
5086
  return makeFilter((input) => Reflect.ownKeys(input).length <= maxProperties, {
4992
5087
  expected: `a value with at most ${maxProperties === 1 ? "1 entry" : `${maxProperties} entries`}`,
4993
5088
  representation: {
4994
5089
  id: "effect/schema/isMaxProperties",
4995
5090
  payload: { maxProperties }
4996
5091
  },
4997
- toJsonSchema: () => ({ maxProperties }),
5092
+ toJsonSchema: ({ type }) => type === "object" ? { maxProperties } : [{ maxProperties }, true],
4998
5093
  toCode: () => ({ runtime: `Schema.isMaxProperties(${maxProperties})` }),
4999
5094
  [STRUCTURAL_ANNOTATION_KEY]: true,
5000
5095
  arbitraryConstraint: { maxProperties },
@@ -5023,7 +5118,7 @@ function isPropertyNames(keySchema, annotations) {
5023
5118
  payload: null,
5024
5119
  schemas: [propertyNames.ast]
5025
5120
  },
5026
- toJsonSchema: ({ schemas }) => ({ propertyNames: schemas[0] }),
5121
+ toJsonSchema: ({ schemas, type }) => type === "object" ? { propertyNames: schemas[0] } : [{ propertyNames: schemas[0] }, true],
5027
5122
  toCode: ({ schemas }) => ({ runtime: `Schema.isPropertyNames(${schemas[0].runtime})` }),
5028
5123
  [STRUCTURAL_ANNOTATION_KEY]: true,
5029
5124
  ...annotations
@@ -5785,4 +5880,4 @@ const MutableJson = make(annotate(MutableJson$1, { toCode: () => ({
5785
5880
  //#endregion
5786
5881
  export { declare as $, Union$1 as $t, OptionFromNullOr as A, toString as An, tag as At, TaggedUnion as B, isRedacted as Bn, omit as Bt, Never as C, transform$1 as Cn, isSchemaError as Ct, NullOr as D, empty as Dn, mutable as Dt, Null as E, Pointer as En, makeFilterGroup as Et, String$1 as F, formatIso as Fn, toType as Ft, Uint8Array$1 as G, EncodingError as Gn, encodeEffect$1 as Gt, Tuple as H, value as Hn, _is as Ht, Struct as I, formatIsoDate as In, withConstructorDefault as It, Union as J, TaggedError$1 as Jn, FilterGroup as Jt, Uint8ArrayFromBase64 as K, Error$2 as Kn, Arrays as Kt, StructWithRest as L, fromDateUnsafe as Ln, withDecodingDefault as Lt, Record as M, fromSetCookie as Mn, toCodecStringTree as Mt, Redacted as N, decode as Nn, toEncoded as Nt, Number$1 as O, fromInput as On, optional as Ot, SchemaError as P, encode as Pn, toJsonSchemaDocument as Pt, check as Q, map$1 as Qn, Suspend as Qt, TaggedClass as R, now as Rn, withDecodingDefaultKey as Rt, Natural as S, passthrough$1 as Sn, isSchema as St, NonEmptyString as T, InvalidValue as Tn, makeFilter as Tt, URL$1 as U, stringOrRedacted as Un, decodeEffect$1 as Ut, TrueLiterals as V, make$6 as Vn, getReferenceKey as Vt, URLFromString as W, Clock as Wn, decodeUnknownEffect$1 as Wt, Void as X, assignProperty as Xn, Objects as Xt, Unknown as Y, taggedEnum as Yn, Literal$1 as Yt, brand as Z, makeEquivalence$1 as Zn, PropertySignature as Zt, Int as _, transform as _n, isMaxLength as _t, BooleanLiterals as a, null_ as an, decodeUnknownSync as at, Literals as b, dateTimeUtcFromInput$1 as bn, isPattern as bt, DateTimeUtcFromDate as c, resolveAt as cn, encodeUnknownEffect as ct, Defect as d, string as dn, is as dt, applyToSelfOrLastLinkEncoding as en, decodeEffect as et, Duration as f, toEncoded$1 as fn, isFinite as ft, Finite as g, passthrough as gn, isLessThanOrEqualTo as gt, FalseLiterals as h, Transformation as hn, isInt as ht, BooleanFromBit as i, mapOrSame as in, decodeUnknownOption as it, OptionFromOptional as j, empty$1 as jn, toCodecJson as jt, Option as k, setAll as kn, optionalKey as kt, DateTimeUtcFromMillis as l, resolveDescription as ln, fromJsonString as lt, Exit as m, unknown as mn, isGreaterThanOrEqualTo as mt, ArraySchema as n, isNever as nn, decodeTo as nt, Class as o, optionalKey$1 as on, encodeEffect as ot, Error$1 as p, toType$1 as pn, isGreaterThan as pt, UndefinedOr as q, TaggedClass$1 as qn, Filter as qt, Boolean as r, isOptional as rn, decodeUnknownEffect as rt, DateTimeUtc as s, replaceChecks as sn, encodeTo as st, Any as t, decodeTo$1 as tn, decodeSync as tt, DateTimeUtcFromString as u, resolveIdentifier as un, instanceOf as ut, Json as v, transformEffect as vn, isMaxProperties as vt, NonEmptyArray as w, transformEffect$1 as wn, make as wt, MutableJson as x, map as xn, isPropertyNames as xt, Literal as y, transformOptional as yn, isMinLength as yt, TaggedError as z, removeTime as zn, evolve as zt };
5787
5882
 
5788
- //# sourceMappingURL=Schema-C9JQ5hI0.mjs.map
5883
+ //# sourceMappingURL=Schema-C7W9nQug.mjs.map