effect 4.0.0-beta.83 → 4.0.0-beta.85

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 (235) hide show
  1. package/dist/Array.d.ts +64 -64
  2. package/dist/Array.js +26 -26
  3. package/dist/Cache.d.ts +1 -1
  4. package/dist/Cache.js +1 -1
  5. package/dist/Cause.d.ts +68 -68
  6. package/dist/Cause.js +47 -47
  7. package/dist/Channel.d.ts +5 -5
  8. package/dist/Channel.js +3 -3
  9. package/dist/Clock.d.ts +1 -1
  10. package/dist/Clock.js +1 -1
  11. package/dist/Combiner.d.ts +9 -9
  12. package/dist/Combiner.js +8 -8
  13. package/dist/Config.d.ts +15 -94
  14. package/dist/Config.d.ts.map +1 -1
  15. package/dist/Config.js +22 -70
  16. package/dist/Config.js.map +1 -1
  17. package/dist/ConfigProvider.d.ts +58 -74
  18. package/dist/ConfigProvider.d.ts.map +1 -1
  19. package/dist/ConfigProvider.js +66 -41
  20. package/dist/ConfigProvider.js.map +1 -1
  21. package/dist/Console.d.ts +1 -1
  22. package/dist/Console.js +1 -1
  23. package/dist/Context.d.ts.map +1 -1
  24. package/dist/Context.js +4 -3
  25. package/dist/Context.js.map +1 -1
  26. package/dist/Data.d.ts +15 -15
  27. package/dist/Data.js +3 -3
  28. package/dist/DateTime.d.ts +6 -6
  29. package/dist/DateTime.js +2 -2
  30. package/dist/Duration.d.ts +3 -3
  31. package/dist/Duration.js +3 -3
  32. package/dist/Effect.d.ts +84 -45
  33. package/dist/Effect.d.ts.map +1 -1
  34. package/dist/Effect.js +72 -33
  35. package/dist/Effect.js.map +1 -1
  36. package/dist/Equal.d.ts +7 -7
  37. package/dist/Equal.js +5 -5
  38. package/dist/Equivalence.d.ts +17 -17
  39. package/dist/Equivalence.js +13 -13
  40. package/dist/Exit.d.ts +3 -3
  41. package/dist/Exit.js +3 -3
  42. package/dist/Formatter.d.ts +5 -5
  43. package/dist/Formatter.js +4 -4
  44. package/dist/Function.d.ts +10 -10
  45. package/dist/Function.js +3 -3
  46. package/dist/HashMap.d.ts +3 -3
  47. package/dist/HashMap.js +1 -1
  48. package/dist/Iterable.d.ts +6 -6
  49. package/dist/Iterable.js +2 -2
  50. package/dist/JsonPatch.d.ts +2 -2
  51. package/dist/Layer.d.ts +1 -1
  52. package/dist/Layer.js +5 -4
  53. package/dist/Layer.js.map +1 -1
  54. package/dist/LayerMap.d.ts.map +1 -1
  55. package/dist/LayerMap.js +4 -3
  56. package/dist/LayerMap.js.map +1 -1
  57. package/dist/Logger.d.ts +1 -1
  58. package/dist/Logger.js +1 -1
  59. package/dist/Match.d.ts +8 -8
  60. package/dist/Match.js +8 -8
  61. package/dist/Metric.d.ts +3 -3
  62. package/dist/Metric.js +3 -3
  63. package/dist/Optic.d.ts +30 -30
  64. package/dist/Optic.js +12 -12
  65. package/dist/Option.d.ts +7 -7
  66. package/dist/Option.js +7 -7
  67. package/dist/Order.d.ts +23 -23
  68. package/dist/Order.js +20 -20
  69. package/dist/Pool.d.ts +1 -1
  70. package/dist/Pool.js +1 -1
  71. package/dist/Predicate.d.ts +88 -88
  72. package/dist/Predicate.js +47 -47
  73. package/dist/PubSub.d.ts +3 -3
  74. package/dist/PubSub.js +3 -3
  75. package/dist/Random.d.ts +31 -0
  76. package/dist/Random.d.ts.map +1 -1
  77. package/dist/Random.js +32 -0
  78. package/dist/Random.js.map +1 -1
  79. package/dist/Reducer.d.ts +1 -1
  80. package/dist/Reducer.js +1 -1
  81. package/dist/Result.d.ts +18 -18
  82. package/dist/Result.js +8 -8
  83. package/dist/Runtime.d.ts +1 -1
  84. package/dist/Runtime.js +1 -1
  85. package/dist/Schema.d.ts +313 -126
  86. package/dist/Schema.d.ts.map +1 -1
  87. package/dist/Schema.js +316 -127
  88. package/dist/Schema.js.map +1 -1
  89. package/dist/SchemaAST.d.ts +9 -8
  90. package/dist/SchemaAST.d.ts.map +1 -1
  91. package/dist/SchemaAST.js +203 -140
  92. package/dist/SchemaAST.js.map +1 -1
  93. package/dist/SchemaGetter.d.ts +48 -48
  94. package/dist/SchemaGetter.js +44 -44
  95. package/dist/SchemaIssue.d.ts +3 -3
  96. package/dist/SchemaIssue.js +3 -3
  97. package/dist/SchemaParser.d.ts +122 -22
  98. package/dist/SchemaParser.d.ts.map +1 -1
  99. package/dist/SchemaParser.js +186 -50
  100. package/dist/SchemaParser.js.map +1 -1
  101. package/dist/SchemaRepresentation.d.ts +1 -1
  102. package/dist/SchemaRepresentation.d.ts.map +1 -1
  103. package/dist/SchemaRepresentation.js +96 -2
  104. package/dist/SchemaRepresentation.js.map +1 -1
  105. package/dist/SchemaTransformation.d.ts +20 -20
  106. package/dist/SchemaTransformation.js +18 -18
  107. package/dist/Stream.d.ts +3 -3
  108. package/dist/Stream.js +2 -2
  109. package/dist/Stream.js.map +1 -1
  110. package/dist/String.d.ts +1 -1
  111. package/dist/String.js +1 -1
  112. package/dist/Struct.d.ts +1 -1
  113. package/dist/Struct.js +1 -1
  114. package/dist/Types.d.ts +13 -13
  115. package/dist/internal/effect.js +33 -20
  116. package/dist/internal/effect.js.map +1 -1
  117. package/dist/internal/schema/arbitrary.js +17 -1
  118. package/dist/internal/schema/arbitrary.js.map +1 -1
  119. package/dist/internal/schema/cause.d.ts +2 -0
  120. package/dist/internal/schema/cause.d.ts.map +1 -0
  121. package/dist/internal/schema/cause.js +24 -0
  122. package/dist/internal/schema/cause.js.map +1 -0
  123. package/dist/internal/schema/schema.d.ts +8 -4
  124. package/dist/internal/schema/schema.d.ts.map +1 -1
  125. package/dist/internal/schema/schema.js +21 -8
  126. package/dist/internal/schema/schema.js.map +1 -1
  127. package/dist/internal/stackTraceLimit.d.ts +2 -0
  128. package/dist/internal/stackTraceLimit.d.ts.map +1 -0
  129. package/dist/internal/stackTraceLimit.js +40 -0
  130. package/dist/internal/stackTraceLimit.js.map +1 -0
  131. package/dist/internal/tracer.d.ts.map +1 -1
  132. package/dist/internal/tracer.js +4 -3
  133. package/dist/internal/tracer.js.map +1 -1
  134. package/dist/testing/TestSchema.d.ts +3 -3
  135. package/dist/testing/TestSchema.js +1 -1
  136. package/dist/unstable/ai/AiError.d.ts +1 -1
  137. package/dist/unstable/ai/AiError.js +1 -1
  138. package/dist/unstable/ai/Chat.d.ts +1 -1
  139. package/dist/unstable/ai/Chat.js +1 -1
  140. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  141. package/dist/unstable/ai/Tool.js +4 -5
  142. package/dist/unstable/ai/Tool.js.map +1 -1
  143. package/dist/unstable/cli/Prompt.js +2 -2
  144. package/dist/unstable/cli/Prompt.js.map +1 -1
  145. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  146. package/dist/unstable/httpapi/HttpApiMiddleware.js +4 -3
  147. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  148. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  149. package/dist/unstable/persistence/PersistedQueue.js +1 -1
  150. package/dist/unstable/rpc/Rpc.d.ts +1 -1
  151. package/dist/unstable/rpc/Rpc.js +1 -1
  152. package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
  153. package/dist/unstable/rpc/RpcGroup.js +3 -4
  154. package/dist/unstable/rpc/RpcGroup.js.map +1 -1
  155. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  156. package/dist/unstable/rpc/RpcMiddleware.js +4 -3
  157. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  158. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  159. package/dist/unstable/sql/SqlResolver.js +15 -2
  160. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  161. package/dist/unstable/workflow/Activity.d.ts +1 -0
  162. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  163. package/dist/unstable/workflow/Activity.js +1 -0
  164. package/dist/unstable/workflow/Activity.js.map +1 -1
  165. package/dist/unstable/workflow/WorkflowEngine.js +1 -1
  166. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  167. package/package.json +1 -1
  168. package/src/Array.ts +65 -65
  169. package/src/Cache.ts +1 -1
  170. package/src/Cause.ts +68 -68
  171. package/src/Channel.ts +5 -5
  172. package/src/Clock.ts +1 -1
  173. package/src/Combiner.ts +9 -9
  174. package/src/Config.ts +40 -108
  175. package/src/ConfigProvider.ts +139 -100
  176. package/src/Console.ts +1 -1
  177. package/src/Context.ts +4 -5
  178. package/src/Data.ts +15 -15
  179. package/src/DateTime.ts +6 -6
  180. package/src/Duration.ts +3 -3
  181. package/src/Effect.ts +89 -45
  182. package/src/Equal.ts +7 -7
  183. package/src/Equivalence.ts +17 -17
  184. package/src/Exit.ts +3 -3
  185. package/src/Formatter.ts +5 -5
  186. package/src/Function.ts +10 -10
  187. package/src/HashMap.ts +3 -3
  188. package/src/Iterable.ts +6 -6
  189. package/src/JsonPatch.ts +2 -2
  190. package/src/Layer.ts +5 -5
  191. package/src/LayerMap.ts +4 -3
  192. package/src/Logger.ts +1 -1
  193. package/src/Match.ts +8 -8
  194. package/src/Metric.ts +3 -3
  195. package/src/Optic.ts +30 -30
  196. package/src/Option.ts +7 -7
  197. package/src/Order.ts +23 -23
  198. package/src/Pool.ts +1 -1
  199. package/src/Predicate.ts +88 -88
  200. package/src/PubSub.ts +3 -3
  201. package/src/Random.ts +42 -0
  202. package/src/Reducer.ts +1 -1
  203. package/src/Result.ts +20 -20
  204. package/src/Runtime.ts +1 -1
  205. package/src/Schema.ts +389 -153
  206. package/src/SchemaAST.ts +237 -148
  207. package/src/SchemaGetter.ts +48 -48
  208. package/src/SchemaIssue.ts +3 -3
  209. package/src/SchemaParser.ts +197 -58
  210. package/src/SchemaRepresentation.ts +73 -3
  211. package/src/SchemaTransformation.ts +20 -20
  212. package/src/Stream.ts +4 -4
  213. package/src/String.ts +1 -1
  214. package/src/Struct.ts +1 -1
  215. package/src/Types.ts +13 -13
  216. package/src/internal/effect.ts +40 -21
  217. package/src/internal/schema/arbitrary.ts +23 -2
  218. package/src/internal/schema/cause.ts +26 -0
  219. package/src/internal/schema/schema.ts +36 -10
  220. package/src/internal/stackTraceLimit.ts +63 -0
  221. package/src/internal/tracer.ts +4 -3
  222. package/src/testing/TestSchema.ts +3 -3
  223. package/src/unstable/ai/AiError.ts +1 -1
  224. package/src/unstable/ai/Chat.ts +1 -1
  225. package/src/unstable/ai/Tool.ts +4 -3
  226. package/src/unstable/cli/Prompt.ts +1 -1
  227. package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -3
  228. package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
  229. package/src/unstable/persistence/PersistedQueue.ts +1 -1
  230. package/src/unstable/rpc/Rpc.ts +1 -1
  231. package/src/unstable/rpc/RpcGroup.ts +3 -4
  232. package/src/unstable/rpc/RpcMiddleware.ts +4 -3
  233. package/src/unstable/sql/SqlResolver.ts +15 -2
  234. package/src/unstable/workflow/Activity.ts +2 -0
  235. package/src/unstable/workflow/WorkflowEngine.ts +1 -1
package/dist/SchemaAST.js CHANGED
@@ -19,10 +19,10 @@ import { memoize } from "./Function.js";
19
19
  import { effectIsExit, iterateEager } from "./internal/effect.js";
20
20
  import * as internalRecord from "./internal/record.js";
21
21
  import * as InternalAnnotations from "./internal/schema/annotations.js";
22
+ import * as InternalSchemaCause from "./internal/schema/cause.js";
22
23
  import * as Option from "./Option.js";
23
24
  import * as Pipeable from "./Pipeable.js";
24
25
  import * as Predicate from "./Predicate.js";
25
- import * as RegEx from "./RegExp.js";
26
26
  import * as Result from "./Result.js";
27
27
  import * as SchemaGetter from "./SchemaGetter.js";
28
28
  import * as SchemaIssue from "./SchemaIssue.js";
@@ -449,17 +449,17 @@ export class Declaration extends Base {
449
449
  return Effect.mapEager(run(oinput.value, this, options), Option.some);
450
450
  };
451
451
  }
452
- rebuild(recur, checks, encodingChecks) {
452
+ _rebuild(recur, checks, encodingChecks) {
453
453
  const tps = mapOrSame(this.typeParameters, recur);
454
454
  return tps === this.typeParameters ? this : new Declaration(tps, this.run, this.annotations, checks, undefined, this.context, encodingChecks);
455
455
  }
456
456
  /** @internal */
457
457
  recur(recur) {
458
- return this.rebuild(recur, this.checks, this.encodingChecks);
458
+ return this._rebuild(recur, this.checks, this.encodingChecks);
459
459
  }
460
460
  /** @internal */
461
461
  flip(recur) {
462
- return this.rebuild(recur, this.encodingChecks, this.checks);
462
+ return this._rebuild(recur, this.encodingChecks, this.checks);
463
463
  }
464
464
  /** @internal */
465
465
  getExpected() {
@@ -782,11 +782,12 @@ function isTemplateLiteralPart(ast) {
782
782
  case "String":
783
783
  case "Number":
784
784
  case "BigInt":
785
+ return true;
785
786
  case "Literal":
786
787
  case "TemplateLiteral":
787
- return true;
788
+ return ast.checks === undefined;
788
789
  case "Union":
789
- return ast.types.every(isTemplateLiteralPart);
790
+ return ast.checks === undefined && ast.types.every(isTemplateLiteralPart);
790
791
  default:
791
792
  return false;
792
793
  }
@@ -797,8 +798,7 @@ function isTemplateLiteralPart(ast) {
797
798
  *
798
799
  * **Details**
799
800
  *
800
- * `parts` is an array of AST nodes; each part contributes to the
801
- * template literal pattern. A regex is derived from the parts to validate
801
+ * `parts` is an array of AST nodes; each part contributes to matching
802
802
  * strings at runtime.
803
803
  *
804
804
  * @see {@link isTemplateLiteral}
@@ -837,14 +837,17 @@ export class TemplateLiteral extends Base {
837
837
  return "string";
838
838
  }
839
839
  /** @internal */
840
+ matchPart(s, options) {
841
+ return segmentTemplateLiteralParts(this.encodedParts, s, options) === undefined ? undefined : s;
842
+ }
843
+ /** @internal */
840
844
  asTemplateLiteralParser() {
841
- const tuple = new Arrays(false, this.parts.map(templateLiteralPartFromString), []);
842
- const regExp = getTemplateLiteralRegExp(this);
843
- return decodeTo(string, tuple, new SchemaTransformation.Transformation(SchemaGetter.transformOrFail(s => {
844
- const match = regExp.exec(s);
845
- if (match) return Effect.succeed(match.slice(1, this.parts.length + 1));
845
+ const tuple = new Arrays(false, this.parts.map(partFromString), []);
846
+ return decodeTo(string, tuple, new SchemaTransformation.Transformation(SchemaGetter.transformOrFail((s, options) => {
847
+ const segments = segmentTemplateLiteralParts(this.encodedParts, s, options);
848
+ if (segments !== undefined) return Effect.succeed(segments);
846
849
  return Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), {
847
- message: `Expected a value matching ${regExp.source}, got ${format(s)}`
850
+ message: `Expected a string matching template literal parts, got ${format(s)}`
848
851
  }));
849
852
  }), SchemaGetter.transform(parts => parts.join(""))));
850
853
  }
@@ -920,6 +923,10 @@ export class Literal extends Base {
920
923
  return fromConst(this, this.literal);
921
924
  }
922
925
  /** @internal */
926
+ matchPart(s, _options) {
927
+ return s === globalThis.String(this.literal) ? this.literal : undefined;
928
+ }
929
+ /** @internal */
923
930
  toCodecJson() {
924
931
  return typeof this.literal === "bigint" ? literalToString(this) : this;
925
932
  }
@@ -952,6 +959,10 @@ export class String extends Base {
952
959
  return fromRefinement(this, Predicate.isString);
953
960
  }
954
961
  /** @internal */
962
+ matchPart(s, options) {
963
+ return applyTemplateLiteralPartChecks(this, s, options);
964
+ }
965
+ /** @internal */
955
966
  getExpected() {
956
967
  return "string";
957
968
  }
@@ -996,6 +1007,17 @@ export class Number extends Base {
996
1007
  return fromRefinement(this, Predicate.isNumber);
997
1008
  }
998
1009
  /** @internal */
1010
+ matchKey(s, options) {
1011
+ return this._match(isStringNumberRegExp, s, options);
1012
+ }
1013
+ /** @internal */
1014
+ matchPart(s, options) {
1015
+ return this._match(isStringFiniteRegExp, s, options);
1016
+ }
1017
+ _match(regexp, s, options) {
1018
+ return regexp.test(s) ? applyTemplateLiteralPartChecks(this, globalThis.Number(s), options) : undefined;
1019
+ }
1020
+ /** @internal */
999
1021
  toCodecJson() {
1000
1022
  if (this.checks && (hasCheck(this.checks, "isFinite") || hasCheck(this.checks, "isInt"))) {
1001
1023
  return this;
@@ -1100,6 +1122,10 @@ export class Symbol extends Base {
1100
1122
  return fromRefinement(this, Predicate.isSymbol);
1101
1123
  }
1102
1124
  /** @internal */
1125
+ matchKey(s, options) {
1126
+ return applyTemplateLiteralPartChecks(this, s, options);
1127
+ }
1128
+ /** @internal */
1103
1129
  toCodecStringTree() {
1104
1130
  return replaceEncoding(this, [symbolToString]);
1105
1131
  }
@@ -1147,6 +1173,10 @@ export class BigInt extends Base {
1147
1173
  return fromRefinement(this, Predicate.isBigInt);
1148
1174
  }
1149
1175
  /** @internal */
1176
+ matchPart(s, options) {
1177
+ return isStringBigIntRegExp.test(s) ? applyTemplateLiteralPartChecks(this, globalThis.BigInt(s), options) : undefined;
1178
+ }
1179
+ /** @internal */
1150
1180
  toCodecStringTree() {
1151
1181
  return replaceEncoding(this, [bigIntToString]);
1152
1182
  }
@@ -1303,18 +1333,18 @@ export class Arrays extends Base {
1303
1333
  return Option.some(state.output);
1304
1334
  });
1305
1335
  }
1306
- rebuild(recur, checks, encodingChecks) {
1336
+ _rebuild(recur, checks, encodingChecks) {
1307
1337
  const elements = mapOrSame(this.elements, recur);
1308
1338
  const rest = mapOrSame(this.rest, recur);
1309
1339
  return elements === this.elements && rest === this.rest ? this : new Arrays(this.isMutable, elements, rest, this.annotations, checks, undefined, this.context, encodingChecks);
1310
1340
  }
1311
1341
  /** @internal */
1312
1342
  recur(recur) {
1313
- return this.rebuild(recur, this.checks, this.encodingChecks);
1343
+ return this._rebuild(recur, this.checks, this.encodingChecks);
1314
1344
  }
1315
1345
  /** @internal */
1316
1346
  flip(recur) {
1317
- return this.rebuild(recur, this.encodingChecks, this.checks);
1347
+ return this._rebuild(recur, this.encodingChecks, this.checks);
1318
1348
  }
1319
1349
  /** @internal */
1320
1350
  getExpected() {
@@ -1353,15 +1383,18 @@ const resolveConcurrency = value => {
1353
1383
  } : undefined;
1354
1384
  };
1355
1385
  const wrapPropertyKeyIssue = (s, ast, key, exit) => {
1356
- const issueResult = Cause.findError(exit.cause);
1357
- if (Result.isFailure(issueResult)) {
1386
+ if (exit.cause.reasons.length === 0) {
1358
1387
  return exit;
1359
1388
  }
1360
- const issue = new SchemaIssue.Pointer([key], issueResult.success);
1389
+ const issue = InternalSchemaCause.getSchemaIssue(exit.cause);
1390
+ if (issue === undefined) {
1391
+ return Exit.failCause(Cause.map(exit.cause, issue => new SchemaIssue.Composite(ast, s.oinput, [new SchemaIssue.Pointer([key], issue)])));
1392
+ }
1393
+ const pointer = new SchemaIssue.Pointer([key], issue);
1361
1394
  if (s.options.errors === "all") {
1362
- if (s.issues) s.issues.push(issue);else s.issues = [issue];
1395
+ if (s.issues) s.issues.push(pointer);else s.issues = [pointer];
1363
1396
  } else {
1364
- return Exit.fail(new SchemaIssue.Composite(ast, s.oinput, [issue]));
1397
+ return Exit.fail(new SchemaIssue.Composite(ast, s.oinput, [pointer]));
1365
1398
  }
1366
1399
  };
1367
1400
  /**
@@ -1369,30 +1402,29 @@ const wrapPropertyKeyIssue = (s, ast, key, exit) => {
1369
1402
  * @internal
1370
1403
  */
1371
1404
  export const FINITE_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
1372
- const isNumberStringRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
1373
1405
  /**
1374
1406
  * Returns the object keys that match the index signature parameter schema.
1375
1407
  * @internal
1376
1408
  */
1377
- export function getIndexSignatureKeys(input, parameter) {
1378
- const encoded = toEncoded(parameter);
1379
- switch (encoded._tag) {
1380
- case "String":
1381
- return Object.keys(input);
1382
- case "TemplateLiteral":
1383
- {
1384
- const regExp = getTemplateLiteralRegExp(encoded);
1385
- return Object.keys(input).filter(k => regExp.test(k));
1386
- }
1387
- case "Symbol":
1388
- return Object.getOwnPropertySymbols(input);
1389
- case "Number":
1390
- return Object.keys(input).filter(k => isNumberStringRegExp.test(k));
1391
- case "Union":
1392
- return [...new Set(encoded.types.flatMap(t => getIndexSignatureKeys(input, t)))];
1393
- default:
1394
- return [];
1409
+ export function getIndexSignatureKeys(input, parameter, options = defaultParseOptions) {
1410
+ let stringKeys;
1411
+ let symbolKeys;
1412
+ function go(parameter) {
1413
+ switch (parameter._tag) {
1414
+ case "String":
1415
+ case "TemplateLiteral":
1416
+ return (stringKeys ??= Object.keys(input)).filter(k => parameter.matchPart(k, options) !== undefined);
1417
+ case "Number":
1418
+ return (stringKeys ??= Object.keys(input)).filter(k => parameter.matchKey(k, options) !== undefined);
1419
+ case "Symbol":
1420
+ return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter(k => parameter.matchKey(k, options) !== undefined);
1421
+ case "Union":
1422
+ return [...new Set(parameter.types.flatMap(go))];
1423
+ default:
1424
+ return [];
1425
+ }
1395
1426
  }
1427
+ return go(parameterFromPropertyKey(toEncoded(parameter)));
1396
1428
  }
1397
1429
  /**
1398
1430
  * Represents a named property within an {@link Objects} node.
@@ -1441,6 +1473,22 @@ export class KeyValueCombiner {
1441
1473
  return new KeyValueCombiner(this.encode, this.decode);
1442
1474
  }
1443
1475
  }
1476
+ function isIndexSignatureParameterSide(ast) {
1477
+ switch (ast._tag) {
1478
+ case "String":
1479
+ case "Number":
1480
+ case "Symbol":
1481
+ case "TemplateLiteral":
1482
+ return true;
1483
+ case "Union":
1484
+ return ast.types.every(isIndexSignatureParameterSide);
1485
+ default:
1486
+ return false;
1487
+ }
1488
+ }
1489
+ function isIndexSignatureParameter(ast) {
1490
+ return isIndexSignatureParameterSide(ast) && isIndexSignatureParameterSide(toEncoded(ast));
1491
+ }
1444
1492
  /**
1445
1493
  * Represents an index signature entry within an {@link Objects} node.
1446
1494
  *
@@ -1471,6 +1519,9 @@ export class IndexSignature {
1471
1519
  type;
1472
1520
  merge;
1473
1521
  constructor(parameter, type, merge) {
1522
+ if (!isIndexSignatureParameter(parameter)) {
1523
+ throw new Error(`Invalid index signature parameter ${parameter._tag}`);
1524
+ }
1474
1525
  this.parameter = parameter;
1475
1526
  this.type = type;
1476
1527
  this.merge = merge;
@@ -1566,7 +1617,7 @@ export class Objects extends Base {
1566
1617
  }
1567
1618
  const parseIndexes = indexCount > 0 ? iterateEager()({
1568
1619
  onItem: Effect.fnUntracedEager(function* (s, [key, is]) {
1569
- const parserKey = recur(indexSignatureParameterFromString(is.parameter));
1620
+ const parserKey = recur(parameterFromPropertyKey(is.parameter));
1570
1621
  const effKey = parserKey(Option.some(key), s.options);
1571
1622
  const exitKey = effectIsExit(effKey) ? effKey : yield* Effect.exit(effKey);
1572
1623
  if (exitKey._tag === "Failure") {
@@ -1661,7 +1712,7 @@ export class Objects extends Base {
1661
1712
  const keyPairs = Arr.empty();
1662
1713
  for (let i = 0; i < indexCount; i++) {
1663
1714
  const is = ast.indexSignatures[i];
1664
- const keys = getIndexSignatureKeys(input, is.parameter);
1715
+ const keys = getIndexSignatureKeys(input, is.parameter, options);
1665
1716
  for (let j = 0; j < keys.length; j++) {
1666
1717
  const key = keys[j];
1667
1718
  keyPairs.push([key, is]);
@@ -1687,13 +1738,13 @@ export class Objects extends Base {
1687
1738
  return Option.some(out);
1688
1739
  });
1689
1740
  }
1690
- rebuild(recur, flipMerge, checks, encodingChecks) {
1741
+ _rebuild(recur, recurParameter, flipMerge, checks, encodingChecks) {
1691
1742
  const props = mapOrSame(this.propertySignatures, ps => {
1692
1743
  const t = recur(ps.type);
1693
1744
  return t === ps.type ? ps : new PropertySignature(ps.name, t);
1694
1745
  });
1695
1746
  const indexes = mapOrSame(this.indexSignatures, is => {
1696
- const p = recur(is.parameter);
1747
+ const p = recurParameter(is.parameter);
1697
1748
  const t = recur(is.type);
1698
1749
  const merge = flipMerge ? is.merge?.flip() : is.merge;
1699
1750
  return p === is.parameter && t === is.type && merge === is.merge ? is : new IndexSignature(p, t, merge);
@@ -1702,11 +1753,11 @@ export class Objects extends Base {
1702
1753
  }
1703
1754
  /** @internal */
1704
1755
  flip(recur) {
1705
- return this.rebuild(recur, true, this.encodingChecks, this.checks);
1756
+ return this._rebuild(recur, recur, true, this.encodingChecks, this.checks);
1706
1757
  }
1707
1758
  /** @internal */
1708
- recur(recur) {
1709
- return this.rebuild(recur, false, this.checks, this.encodingChecks);
1759
+ recur(recur, recurParameter = recur) {
1760
+ return this._rebuild(recur, recurParameter, false, this.checks, this.encodingChecks);
1710
1761
  }
1711
1762
  /** @internal */
1712
1763
  getExpected() {
@@ -1735,14 +1786,10 @@ const parseProperties = /*#__PURE__*/iterateEager()({
1735
1786
  }
1736
1787
  }
1737
1788
  });
1738
- function mergeChecks(checks, b) {
1739
- if (!checks) {
1740
- return b.checks;
1741
- }
1742
- if (!b.checks) {
1743
- return checks;
1744
- }
1745
- return [...checks, ...b.checks];
1789
+ function combineChecks(a, b) {
1790
+ if (!a) return b;
1791
+ if (!b) return a;
1792
+ return [...a, ...b];
1746
1793
  }
1747
1794
  /** @internal */
1748
1795
  export function struct(fields, checks, annotations) {
@@ -1770,10 +1817,10 @@ export function structWithRest(ast, records) {
1770
1817
  let propertySignatures = ast.propertySignatures;
1771
1818
  let indexSignatures = ast.indexSignatures;
1772
1819
  let checks = ast.checks;
1773
- for (const r of records) {
1774
- propertySignatures = propertySignatures.concat(r.propertySignatures);
1775
- indexSignatures = indexSignatures.concat(r.indexSignatures);
1776
- checks = mergeChecks(checks, r);
1820
+ for (const record of records) {
1821
+ propertySignatures = propertySignatures.concat(record.propertySignatures);
1822
+ indexSignatures = indexSignatures.concat(record.indexSignatures);
1823
+ checks = combineChecks(checks, record.checks);
1777
1824
  }
1778
1825
  return new Objects(propertySignatures, indexSignatures, undefined, checks);
1779
1826
  }
@@ -1997,17 +2044,25 @@ export class Union extends Base {
1997
2044
  });
1998
2045
  };
1999
2046
  }
2000
- rebuild(recur, checks, encodingChecks) {
2047
+ _rebuild(recur, checks, encodingChecks) {
2001
2048
  const types = mapOrSame(this.types, recur);
2002
2049
  return types === this.types ? this : new Union(types, this.mode, this.annotations, checks, undefined, this.context, encodingChecks);
2003
2050
  }
2004
2051
  /** @internal */
2005
2052
  recur(recur) {
2006
- return this.rebuild(recur, this.checks, this.encodingChecks);
2053
+ return this._rebuild(recur, this.checks, this.encodingChecks);
2007
2054
  }
2008
2055
  /** @internal */
2009
2056
  flip(recur) {
2010
- return this.rebuild(recur, this.encodingChecks, this.checks);
2057
+ return this._rebuild(recur, this.encodingChecks, this.checks);
2058
+ }
2059
+ /** @internal */
2060
+ matchPart(s, options) {
2061
+ for (const type of this.types) {
2062
+ const out = type.matchPart(s, options);
2063
+ if (out !== undefined) return out;
2064
+ }
2065
+ return undefined;
2011
2066
  }
2012
2067
  /** @internal */
2013
2068
  getExpected(getExpected) {
@@ -2046,11 +2101,11 @@ const parseUnion = /*#__PURE__*/iterateEager()({
2046
2101
  },
2047
2102
  step(s, candidate, exit) {
2048
2103
  if (exit._tag === "Failure") {
2049
- const issueResult = Cause.findError(exit.cause);
2050
- if (Result.isFailure(issueResult)) {
2104
+ const issue = InternalSchemaCause.getSchemaIssue(exit.cause);
2105
+ if (issue === undefined) {
2051
2106
  return exit;
2052
2107
  }
2053
- if (s.issues) s.issues.push(issueResult.success);else s.issues = [issueResult.success];
2108
+ if (s.issues) s.issues.push(issue);else s.issues = [issue];
2054
2109
  } else {
2055
2110
  if (s.out && s.ast.mode === "oneOf") {
2056
2111
  s.successes.push(candidate);
@@ -2094,7 +2149,7 @@ export function memoizeThunk(f) {
2094
2149
  * define recursive or mutually recursive schemas without infinite loops at
2095
2150
  * construction time.
2096
2151
  *
2097
- * **Example** (Recursive schema AST)
2152
+ * **Example** (Defining recursive schema ASTs)
2098
2153
  *
2099
2154
  * ```ts
2100
2155
  * import { Schema, SchemaAST } from "effect"
@@ -2350,7 +2405,7 @@ export function replaceChecks(ast, checks) {
2350
2405
  }
2351
2406
  /** @internal */
2352
2407
  export function appendChecks(ast, checks) {
2353
- return replaceChecks(ast, ast.checks ? [...ast.checks, ...checks] : checks);
2408
+ return replaceChecks(ast, combineChecks(ast.checks, checks));
2354
2409
  }
2355
2410
  function updateLastLink(encoding, f) {
2356
2411
  const links = encoding;
@@ -2461,42 +2516,33 @@ export function decodeTo(from, to, transformation) {
2461
2516
  return appendTransformation(from, transformation, to);
2462
2517
  }
2463
2518
  function parseParameter(ast) {
2464
- switch (ast._tag) {
2465
- case "Literal":
2466
- return {
2467
- literals: Predicate.isPropertyKey(ast.literal) ? [ast.literal] : [],
2468
- parameters: []
2469
- };
2470
- case "UniqueSymbol":
2471
- return {
2472
- literals: [ast.symbol],
2473
- parameters: []
2474
- };
2475
- case "String":
2476
- case "Number":
2477
- case "Symbol":
2478
- case "TemplateLiteral":
2479
- return {
2480
- literals: [],
2481
- parameters: [ast]
2482
- };
2483
- case "Union":
2484
- {
2485
- const out = {
2486
- literals: [],
2487
- parameters: []
2488
- };
2519
+ const literals = [];
2520
+ const parameters = [];
2521
+ function go(ast) {
2522
+ switch (ast._tag) {
2523
+ case "Literal":
2524
+ if (Predicate.isPropertyKey(ast.literal)) {
2525
+ literals.push(ast.literal);
2526
+ }
2527
+ return;
2528
+ case "UniqueSymbol":
2529
+ literals.push(ast.symbol);
2530
+ return;
2531
+ case "Never":
2532
+ return;
2533
+ case "Union":
2489
2534
  for (let i = 0; i < ast.types.length; i++) {
2490
- const parsed = parseParameter(ast.types[i]);
2491
- out.literals = out.literals.concat(parsed.literals);
2492
- out.parameters = out.parameters.concat(parsed.parameters);
2535
+ go(ast.types[i]);
2493
2536
  }
2494
- return out;
2495
- }
2537
+ return;
2538
+ default:
2539
+ parameters.push(ast);
2540
+ }
2496
2541
  }
2542
+ go(ast);
2497
2543
  return {
2498
- literals: [],
2499
- parameters: []
2544
+ literals,
2545
+ parameters
2500
2546
  };
2501
2547
  }
2502
2548
  /** @internal */
@@ -2647,39 +2693,6 @@ export function containsUndefined(ast) {
2647
2693
  return false;
2648
2694
  }
2649
2695
  }
2650
- function getTemplateLiteralSource(ast, top) {
2651
- return ast.encodedParts.map(part => handleTemplateLiteralASTPartParens(part, getTemplateLiteralASTPartPattern(part), top)).join("");
2652
- }
2653
- /** @internal */
2654
- export const getTemplateLiteralRegExp = /*#__PURE__*/memoize(ast => {
2655
- return new globalThis.RegExp(`^${getTemplateLiteralSource(ast, true)}$`);
2656
- });
2657
- function getTemplateLiteralASTPartPattern(part) {
2658
- switch (part._tag) {
2659
- case "Literal":
2660
- return RegEx.escape(globalThis.String(part.literal));
2661
- case "String":
2662
- return STRING_PATTERN;
2663
- case "Number":
2664
- return FINITE_PATTERN;
2665
- case "BigInt":
2666
- return BIGINT_PATTERN;
2667
- case "TemplateLiteral":
2668
- return getTemplateLiteralSource(part, false);
2669
- case "Union":
2670
- return part.types.map(getTemplateLiteralASTPartPattern).join("|");
2671
- }
2672
- }
2673
- function handleTemplateLiteralASTPartParens(part, s, top) {
2674
- if (isUnion(part)) {
2675
- if (!top) {
2676
- return `(?:${s})`;
2677
- }
2678
- } else if (!top) {
2679
- return s;
2680
- }
2681
- return `(${s})`;
2682
- }
2683
2696
  function fromConst(ast, value) {
2684
2697
  const succeed = Effect.succeedSome(value);
2685
2698
  return oinput => {
@@ -2697,6 +2710,46 @@ function fromRefinement(ast, refinement) {
2697
2710
  return refinement(oinput.value) ? Effect.succeed(oinput) : Effect.fail(new SchemaIssue.InvalidType(ast, oinput));
2698
2711
  };
2699
2712
  }
2713
+ function applyTemplateLiteralPartChecks(ast, value, options) {
2714
+ if (options?.disableChecks || ast.checks === undefined) return value;
2715
+ const issues = [];
2716
+ collectIssues(ast.checks, value, issues, ast, options);
2717
+ return issues.length === 0 ? value : undefined;
2718
+ }
2719
+ function segmentTemplateLiteralParts(parts, input, options) {
2720
+ const out = new Array(parts.length);
2721
+ const failures = new Set();
2722
+ function go(i, pos) {
2723
+ if (i === parts.length) return pos === input.length;
2724
+ const key = `${i}/${pos}`;
2725
+ if (failures.has(key)) return false;
2726
+ const part = parts[i];
2727
+ if (i === parts.length - 1) {
2728
+ const s = input.slice(pos);
2729
+ if (part.matchPart(s, options) !== undefined) {
2730
+ out[i] = s;
2731
+ return true;
2732
+ }
2733
+ } else if (part._tag === "Literal") {
2734
+ const s = globalThis.String(part.literal);
2735
+ if (input.startsWith(s, pos) && go(i + 1, pos + s.length)) {
2736
+ out[i] = s;
2737
+ return true;
2738
+ }
2739
+ } else {
2740
+ for (let end = input.length; end >= pos; end--) {
2741
+ const s = input.slice(pos, end);
2742
+ if (part.matchPart(s, options) !== undefined && go(i + 1, end)) {
2743
+ out[i] = s;
2744
+ return true;
2745
+ }
2746
+ }
2747
+ }
2748
+ failures.add(key);
2749
+ return false;
2750
+ }
2751
+ return go(0, 0) ? out : undefined;
2752
+ }
2700
2753
  /** @internal */
2701
2754
  export const enumsToLiterals = /*#__PURE__*/memoize(ast => {
2702
2755
  return new Union(ast.enums.map(e => new Literal(e[1], {
@@ -2710,29 +2763,38 @@ export function toCodec(f) {
2710
2763
  }
2711
2764
  return memoize(out);
2712
2765
  }
2713
- const indexSignatureParameterFromString = /*#__PURE__*/toCodec(ast => {
2766
+ const parameterFromPropertyKey = /*#__PURE__*/toCodec(ast => {
2714
2767
  switch (ast._tag) {
2715
2768
  default:
2716
2769
  return ast;
2717
2770
  case "Number":
2718
2771
  return ast.toCodecStringTree();
2719
2772
  case "Union":
2720
- return ast.recur(indexSignatureParameterFromString);
2773
+ return ast.recur(parameterFromPropertyKey);
2721
2774
  }
2722
2775
  });
2723
- const templateLiteralPartFromString = /*#__PURE__*/toCodec(ast => {
2776
+ /** @internal */
2777
+ export const parameterFromString = /*#__PURE__*/toCodec(ast => {
2724
2778
  switch (ast._tag) {
2725
2779
  default:
2726
2780
  return ast;
2727
- case "String":
2728
- case "TemplateLiteral":
2781
+ case "Symbol":
2782
+ case "UniqueSymbol":
2783
+ return ast.toCodecStringTree();
2784
+ case "Union":
2785
+ return ast.recur(parameterFromString);
2786
+ }
2787
+ });
2788
+ const partFromString = /*#__PURE__*/toCodec(ast => {
2789
+ switch (ast._tag) {
2790
+ default:
2729
2791
  return ast;
2730
- case "BigInt":
2731
2792
  case "Number":
2732
2793
  case "Literal":
2794
+ case "BigInt":
2733
2795
  return ast.toCodecStringTree();
2734
2796
  case "Union":
2735
- return ast.recur(templateLiteralPartFromString);
2797
+ return ast.recur(partFromString);
2736
2798
  }
2737
2799
  });
2738
2800
  /**
@@ -2741,6 +2803,7 @@ const templateLiteralPartFromString = /*#__PURE__*/toCodec(ast => {
2741
2803
  */
2742
2804
  export const STRING_PATTERN = "[\\s\\S]*?";
2743
2805
  const isStringFiniteRegExp = /*#__PURE__*/new globalThis.RegExp(`^${FINITE_PATTERN}$`);
2806
+ const isStringNumberRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
2744
2807
  /** @internal */
2745
2808
  export function isStringFinite(annotations) {
2746
2809
  return isPattern(isStringFiniteRegExp, {