effect 4.0.0-beta.97 → 4.0.0-beta.98

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 (166) hide show
  1. package/dist/LayerRef.d.ts +4 -6
  2. package/dist/LayerRef.d.ts.map +1 -1
  3. package/dist/LayerRef.js +4 -6
  4. package/dist/LayerRef.js.map +1 -1
  5. package/dist/Number.d.ts.map +1 -1
  6. package/dist/Number.js +28 -10
  7. package/dist/Number.js.map +1 -1
  8. package/dist/Schema.d.ts +22 -22
  9. package/dist/Schema.d.ts.map +1 -1
  10. package/dist/Schema.js +36 -33
  11. package/dist/Schema.js.map +1 -1
  12. package/dist/SchemaAST.d.ts.map +1 -1
  13. package/dist/SchemaAST.js +25 -10
  14. package/dist/SchemaAST.js.map +1 -1
  15. package/dist/SchemaError.d.ts +53 -0
  16. package/dist/SchemaError.d.ts.map +1 -0
  17. package/dist/SchemaError.js +61 -0
  18. package/dist/SchemaError.js.map +1 -0
  19. package/dist/SchemaGetter.d.ts.map +1 -1
  20. package/dist/SchemaGetter.js +17 -12
  21. package/dist/SchemaGetter.js.map +1 -1
  22. package/dist/SchemaRepresentation.d.ts.map +1 -1
  23. package/dist/SchemaRepresentation.js +186 -224
  24. package/dist/SchemaRepresentation.js.map +1 -1
  25. package/dist/index.d.ts +8 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +8 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/internal/effect.js +26 -8
  30. package/dist/internal/effect.js.map +1 -1
  31. package/dist/internal/schema/equivalence.js +1 -2
  32. package/dist/internal/schema/equivalence.js.map +1 -1
  33. package/dist/internal/schema/representation.js +1 -3
  34. package/dist/internal/schema/representation.js.map +1 -1
  35. package/dist/internal/schema/schema.d.ts +0 -13
  36. package/dist/internal/schema/schema.d.ts.map +1 -1
  37. package/dist/internal/schema/schema.js +4 -29
  38. package/dist/internal/schema/schema.js.map +1 -1
  39. package/dist/unstable/ai/McpSchema.d.ts +128 -128
  40. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  41. package/dist/unstable/cli/CliError.d.ts +8 -16
  42. package/dist/unstable/cli/CliError.d.ts.map +1 -1
  43. package/dist/unstable/cli/CliError.js +8 -16
  44. package/dist/unstable/cli/CliError.js.map +1 -1
  45. package/dist/unstable/cli/Command.d.ts +4 -3
  46. package/dist/unstable/cli/Command.d.ts.map +1 -1
  47. package/dist/unstable/cli/Command.js +3 -3
  48. package/dist/unstable/cli/Command.js.map +1 -1
  49. package/dist/unstable/cli/GlobalFlag.d.ts +6 -8
  50. package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
  51. package/dist/unstable/cli/GlobalFlag.js +6 -6
  52. package/dist/unstable/cli/GlobalFlag.js.map +1 -1
  53. package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
  54. package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
  55. package/dist/unstable/cluster/EntityProxyServer.js +2 -4
  56. package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
  57. package/dist/unstable/cluster/internal/entityManager.js +15 -12
  58. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  59. package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
  60. package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
  61. package/dist/unstable/httpapi/HttpApi.js +19 -20
  62. package/dist/unstable/httpapi/HttpApi.js.map +1 -1
  63. package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
  64. package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
  65. package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
  66. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  67. package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
  68. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  69. package/dist/unstable/httpapi/HttpApiClient.js +40 -30
  70. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  71. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
  72. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  73. package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
  74. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  75. package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
  76. package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
  77. package/dist/unstable/httpapi/HttpApiError.js +31 -0
  78. package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
  79. package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
  80. package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
  81. package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
  82. package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
  83. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
  84. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  85. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  86. package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
  87. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  88. package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
  89. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  90. package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
  91. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  92. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  93. package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
  94. package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
  95. package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
  96. package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
  97. package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
  98. package/dist/unstable/httpapi/HttpApiTest.js +9 -8
  99. package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
  100. package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
  101. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  102. package/dist/unstable/httpapi/OpenApi.js +77 -37
  103. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  104. package/dist/unstable/httpapi/internal/html.js +6 -2
  105. package/dist/unstable/httpapi/internal/html.js.map +1 -1
  106. package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
  107. package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
  108. package/dist/unstable/httpapi/internal/mediaType.js +7 -0
  109. package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
  110. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  111. package/dist/unstable/persistence/PersistedQueue.js +16 -12
  112. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  113. package/dist/unstable/reactivity/Atom.js +1 -1
  114. package/dist/unstable/reactivity/Atom.js.map +1 -1
  115. package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
  116. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  117. package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
  118. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  119. package/dist/unstable/rpc/RpcServer.d.ts +3 -1
  120. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  121. package/dist/unstable/rpc/RpcServer.js +6 -3
  122. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  123. package/dist/unstable/workflow/DurableDeferred.js +1 -1
  124. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  125. package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
  126. package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
  127. package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
  128. package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
  129. package/package.json +1 -1
  130. package/src/LayerRef.ts +4 -6
  131. package/src/Number.ts +29 -10
  132. package/src/Schema.ts +42 -34
  133. package/src/SchemaAST.ts +25 -13
  134. package/src/SchemaError.ts +64 -0
  135. package/src/SchemaGetter.ts +22 -16
  136. package/src/SchemaRepresentation.ts +165 -202
  137. package/src/index.ts +10 -0
  138. package/src/internal/effect.ts +39 -22
  139. package/src/internal/schema/equivalence.ts +1 -2
  140. package/src/internal/schema/representation.ts +4 -4
  141. package/src/internal/schema/schema.ts +4 -37
  142. package/src/unstable/cli/CliError.ts +24 -16
  143. package/src/unstable/cli/Command.ts +8 -8
  144. package/src/unstable/cli/GlobalFlag.ts +22 -33
  145. package/src/unstable/cluster/EntityProxyServer.ts +15 -17
  146. package/src/unstable/cluster/internal/entityManager.ts +48 -34
  147. package/src/unstable/httpapi/HttpApi.ts +72 -47
  148. package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
  149. package/src/unstable/httpapi/HttpApiClient.ts +196 -151
  150. package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
  151. package/src/unstable/httpapi/HttpApiError.ts +33 -0
  152. package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
  153. package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
  154. package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
  155. package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
  156. package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
  157. package/src/unstable/httpapi/HttpApiTest.ts +15 -14
  158. package/src/unstable/httpapi/OpenApi.ts +74 -36
  159. package/src/unstable/httpapi/internal/html.ts +9 -2
  160. package/src/unstable/httpapi/internal/mediaType.ts +6 -0
  161. package/src/unstable/persistence/PersistedQueue.ts +16 -14
  162. package/src/unstable/reactivity/Atom.ts +1 -1
  163. package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
  164. package/src/unstable/rpc/RpcServer.ts +10 -4
  165. package/src/unstable/workflow/DurableDeferred.ts +1 -1
  166. package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
@@ -17,6 +17,7 @@ import { format, formatPropertyKey } from "./Formatter.js";
17
17
  import { collectBrands } from "./internal/schema/annotations.js";
18
18
  import * as InternalRepresentation from "./internal/schema/representation.js";
19
19
  import { unescapeToken } from "./JsonPointer.js";
20
+ import { remainder } from "./Number.js";
20
21
  import * as Option from "./Option.js";
21
22
  import * as Predicate from "./Predicate.js";
22
23
  import * as Rec from "./Record.js";
@@ -2041,46 +2042,30 @@ export function fromJsonSchemaDocument(document, options) {
2041
2042
  * @since 4.0.0
2042
2043
  */
2043
2044
  export function fromJsonSchemaMultiDocument(document, options) {
2044
- let visited;
2045
+ let definitionIdentifier;
2045
2046
  const references = {};
2046
- const slots = new Map();
2047
- function getSlot(identifier) {
2048
- const existing = slots.get(identifier);
2049
- if (existing) return existing;
2050
- // Create the slot *before* resolving, so self-references can see it.
2051
- const slot = {
2052
- state: 0,
2053
- value: undefined
2054
- };
2055
- slots.set(identifier, slot);
2056
- return slot;
2057
- }
2047
+ const resolvedReferences = new Map();
2058
2048
  function resolveReference($ref) {
2059
2049
  const definition = document.definitions[$ref];
2060
2050
  if (definition === undefined) {
2061
2051
  throw new Error(`Reference ${$ref} not found`);
2062
2052
  }
2063
- const slot = getSlot($ref);
2064
- if (slot.state === 2) {
2065
- // Already built: return the built schema directly
2066
- return slot.value;
2067
- }
2068
- if (slot.state === 1) {
2069
- // Circular: we're currently building this identifier.
2053
+ const resolved = resolvedReferences.get($ref);
2054
+ if (resolved === null) {
2070
2055
  throw new Error(`Circular reference detected: ${$ref}`);
2071
2056
  }
2072
- // First time: build it.
2073
- slot.state = 1;
2057
+ if (resolved !== undefined) return resolved;
2058
+ resolvedReferences.set($ref, null);
2074
2059
  const value = recur(definition);
2075
- slot.value = value._tag === "Reference" ? resolveReference(value.$ref) : value;
2076
- slot.state = 2;
2077
- return slot.value;
2060
+ const out = value._tag === "Reference" ? resolveReference(value.$ref) : value;
2061
+ resolvedReferences.set($ref, out);
2062
+ return out;
2078
2063
  }
2079
- Object.entries(document.definitions).forEach(([identifier, definition]) => {
2080
- visited = new Set([identifier]);
2064
+ for (const [identifier, definition] of Object.entries(document.definitions)) {
2065
+ definitionIdentifier = identifier;
2081
2066
  references[identifier] = unknownToJson(recur(definition));
2082
- });
2083
- visited = new Set();
2067
+ }
2068
+ definitionIdentifier = undefined;
2084
2069
  const representations = Arr.map(document.schemas, schema => unknownToJson(recur(schema)));
2085
2070
  return {
2086
2071
  representations,
@@ -2141,7 +2126,7 @@ export function fromJsonSchemaMultiDocument(document, options) {
2141
2126
  _tag: "Reference",
2142
2127
  $ref: unescapeToken($ref)
2143
2128
  };
2144
- if (visited.has($ref)) {
2129
+ if (definitionIdentifier === $ref) {
2145
2130
  return {
2146
2131
  _tag: "Suspend",
2147
2132
  thunk: reference,
@@ -2293,129 +2278,104 @@ export function fromJsonSchemaMultiDocument(document, options) {
2293
2278
  case "Never":
2294
2279
  return a;
2295
2280
  case "Unknown":
2296
- switch (b._tag) {
2297
- case "Reference":
2298
- return combine(a, resolveReference(b.$ref));
2299
- default:
2300
- return {
2301
- ...b,
2302
- ...combineAnnotations(a.annotations, b.annotations)
2303
- };
2281
+ {
2282
+ const resolved = b._tag === "Reference" ? resolveReference(b.$ref) : b;
2283
+ return {
2284
+ ...resolved,
2285
+ ...combineAnnotations(a.annotations, resolved.annotations)
2286
+ };
2304
2287
  }
2305
2288
  case "Null":
2306
- switch (b._tag) {
2307
- case "Unknown":
2308
- case "Null":
2309
- return {
2310
- ...a,
2311
- ...combineAnnotations(a.annotations, b.annotations)
2312
- };
2313
- case "Union":
2314
- return combine(b, a);
2315
- case "Reference":
2316
- return combine(a, resolveReference(b.$ref));
2317
- default:
2318
- return never;
2319
- }
2320
2289
  case "String":
2321
- switch (b._tag) {
2322
- case "Unknown":
2323
- return {
2324
- ...a,
2325
- ...combineAnnotations(a.annotations, b.annotations)
2326
- };
2327
- case "String":
2328
- {
2329
- const checks = combineChecks(a.checks, b.checks, b.annotations);
2330
- return {
2331
- _tag: "String",
2332
- checks: checks ?? a.checks,
2333
- ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2334
- };
2335
- }
2336
- case "Literal":
2337
- return typeof b.literal === "string" ? {
2290
+ case "Number":
2291
+ case "Boolean":
2292
+ case "Literal":
2293
+ case "Arrays":
2294
+ case "Objects":
2295
+ case "Union":
2296
+ break;
2297
+ }
2298
+ if (b._tag === "Reference") {
2299
+ return combine(a, resolveReference(b.$ref));
2300
+ }
2301
+ if (b._tag === "Unknown") {
2302
+ return {
2303
+ ...a,
2304
+ ...combineAnnotations(a.annotations, b.annotations)
2305
+ };
2306
+ }
2307
+ if (a._tag === "Union") {
2308
+ const types = a.types.map(s => combine(s, b)).filter(s => s !== never);
2309
+ if (types.length === 0) return never;
2310
+ return {
2311
+ _tag: "Union",
2312
+ types,
2313
+ mode: a.mode,
2314
+ ...makeAnnotations(a.annotations)
2315
+ };
2316
+ }
2317
+ if (b._tag === "Union") {
2318
+ return combine(b, a);
2319
+ }
2320
+ switch (a._tag) {
2321
+ case "Null":
2322
+ return b._tag === "Null" ? {
2323
+ ...a,
2324
+ ...combineAnnotations(a.annotations, b.annotations)
2325
+ } : never;
2326
+ case "String":
2327
+ {
2328
+ if (b._tag === "Literal") {
2329
+ return satisfiesLiteral(a, b) ? {
2338
2330
  ...b,
2339
2331
  ...combineAnnotations(a.annotations, b.annotations)
2340
2332
  } : never;
2341
- case "Union":
2342
- return combine(b, a);
2343
- case "Reference":
2344
- return combine(a, resolveReference(b.$ref));
2345
- default:
2346
- return never;
2333
+ }
2334
+ if (b._tag !== "String") return never;
2335
+ const checks = combineChecks(a.checks, b.checks, b.annotations);
2336
+ return {
2337
+ _tag: "String",
2338
+ checks: checks ?? a.checks,
2339
+ ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2340
+ };
2347
2341
  }
2348
2342
  case "Number":
2349
- switch (b._tag) {
2350
- case "Unknown":
2351
- return {
2352
- ...a,
2353
- ...combineAnnotations(a.annotations, b.annotations)
2354
- };
2355
- case "Number":
2356
- {
2357
- const checks = combineNumberChecks(a.checks, b.checks, b.annotations);
2358
- return {
2359
- _tag: "Number",
2360
- checks: checks ?? a.checks,
2361
- ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2362
- };
2363
- }
2364
- case "Literal":
2365
- return typeof b.literal === "number" ? {
2343
+ {
2344
+ if (b._tag === "Literal") {
2345
+ return satisfiesLiteral(a, b) ? {
2366
2346
  ...b,
2367
2347
  ...combineAnnotations(a.annotations, b.annotations)
2368
2348
  } : never;
2369
- case "Union":
2370
- return combine(b, a);
2371
- case "Reference":
2372
- return combine(a, resolveReference(b.$ref));
2373
- default:
2374
- return never;
2349
+ }
2350
+ if (b._tag !== "Number") return never;
2351
+ const checks = combineNumberChecks(a.checks, b.checks, b.annotations);
2352
+ return {
2353
+ _tag: "Number",
2354
+ checks: checks ?? a.checks,
2355
+ ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2356
+ };
2375
2357
  }
2376
2358
  case "Boolean":
2377
- switch (b._tag) {
2378
- case "Unknown":
2379
- return {
2380
- ...a,
2381
- ...combineAnnotations(a.annotations, b.annotations)
2382
- };
2383
- case "Boolean":
2384
- return {
2385
- _tag: "Boolean",
2386
- ...combineAnnotations(a.annotations, b.annotations)
2387
- };
2388
- case "Literal":
2389
- return typeof b.literal === "boolean" ? {
2390
- ...b,
2391
- ...combineAnnotations(a.annotations, b.annotations)
2392
- } : never;
2393
- case "Union":
2394
- return combine(b, a);
2395
- case "Reference":
2396
- return combine(a, resolveReference(b.$ref));
2397
- default:
2398
- return never;
2359
+ if (b._tag === "Boolean") {
2360
+ return {
2361
+ _tag: "Boolean",
2362
+ ...combineAnnotations(a.annotations, b.annotations)
2363
+ };
2399
2364
  }
2365
+ return b._tag === "Literal" && typeof b.literal === "boolean" ? {
2366
+ ...b,
2367
+ ...combineAnnotations(a.annotations, b.annotations)
2368
+ } : never;
2400
2369
  case "Literal":
2401
2370
  switch (b._tag) {
2402
- case "Unknown":
2403
- return {
2404
- ...a,
2405
- ...combineAnnotations(a.annotations, b.annotations)
2406
- };
2407
2371
  case "Literal":
2408
2372
  return a.literal === b.literal ? {
2409
2373
  ...a,
2410
2374
  ...combineAnnotations(a.annotations, b.annotations)
2411
2375
  } : never;
2412
2376
  case "String":
2413
- return typeof a.literal === "string" ? {
2414
- ...a,
2415
- ...combineAnnotations(a.annotations, b.annotations)
2416
- } : never;
2417
2377
  case "Number":
2418
- return typeof a.literal === "number" ? {
2378
+ return satisfiesLiteral(b, a) ? {
2419
2379
  ...a,
2420
2380
  ...combineAnnotations(a.annotations, b.annotations)
2421
2381
  } : never;
@@ -2424,86 +2384,76 @@ export function fromJsonSchemaMultiDocument(document, options) {
2424
2384
  ...a,
2425
2385
  ...combineAnnotations(a.annotations, b.annotations)
2426
2386
  } : never;
2427
- case "Union":
2428
- return combine(b, a);
2429
- case "Reference":
2430
- return combine(a, resolveReference(b.$ref));
2431
2387
  default:
2432
2388
  return never;
2433
2389
  }
2434
2390
  case "Arrays":
2435
- switch (b._tag) {
2436
- case "Unknown":
2437
- return {
2438
- ...a,
2439
- ...combineAnnotations(a.annotations, b.annotations)
2440
- };
2441
- case "Arrays":
2442
- {
2443
- const checks = combineArraysChecks(a.checks, b.checks, b.annotations);
2444
- return {
2445
- _tag: "Arrays",
2446
- elements: combineElements(a.elements, b.elements),
2447
- rest: combineRest(a.rest, b.rest),
2448
- checks: checks ?? a.checks,
2449
- ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2450
- };
2451
- }
2452
- case "Union":
2453
- return combine(b, a);
2454
- case "Reference":
2455
- return combine(a, resolveReference(b.$ref));
2456
- default:
2457
- return never;
2391
+ {
2392
+ if (b._tag !== "Arrays") return never;
2393
+ const arrays = combineArrays(a, b);
2394
+ if (arrays === undefined) return never;
2395
+ const checks = combineArraysChecks(a.checks, b.checks, b.annotations);
2396
+ return {
2397
+ _tag: "Arrays",
2398
+ elements: arrays.elements,
2399
+ rest: arrays.rest,
2400
+ checks: checks ?? a.checks,
2401
+ ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2402
+ };
2458
2403
  }
2459
2404
  case "Objects":
2460
- switch (b._tag) {
2461
- case "Unknown":
2462
- return {
2463
- ...a,
2464
- ...combineAnnotations(a.annotations, b.annotations)
2465
- };
2466
- case "Objects":
2467
- {
2468
- const checks = combineChecks(a.checks, b.checks, b.annotations);
2469
- return {
2470
- _tag: "Objects",
2471
- propertySignatures: combinePropertySignatures(a.propertySignatures, b.propertySignatures),
2472
- indexSignatures: combineIndexSignatures(a.indexSignatures, b.indexSignatures),
2473
- checks: checks ?? a.checks,
2474
- ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2475
- };
2476
- }
2477
- case "Union":
2478
- return combine(b, a);
2479
- case "Reference":
2480
- return combine(a, resolveReference(b.$ref));
2481
- default:
2482
- return never;
2483
- }
2484
- case "Union":
2485
2405
  {
2486
- switch (b._tag) {
2487
- case "Unknown":
2488
- return {
2489
- ...a,
2490
- ...combineAnnotations(a.annotations, b.annotations)
2491
- };
2492
- default:
2493
- {
2494
- const types = a.types.map(s => combine(s, b)).filter(s => s !== never);
2495
- if (types.length === 0) return never;
2496
- return {
2497
- _tag: "Union",
2498
- types,
2499
- mode: a.mode,
2500
- ...makeAnnotations(a.annotations)
2501
- };
2502
- }
2503
- }
2406
+ if (b._tag !== "Objects") return never;
2407
+ const checks = combineChecks(a.checks, b.checks, b.annotations);
2408
+ return {
2409
+ _tag: "Objects",
2410
+ propertySignatures: combinePropertySignatures(a.propertySignatures, b.propertySignatures),
2411
+ indexSignatures: combineIndexSignatures(a.indexSignatures, b.indexSignatures),
2412
+ checks: checks ?? a.checks,
2413
+ ...combineAnnotations(a.annotations, checks ? undefined : b.annotations)
2414
+ };
2504
2415
  }
2416
+ default:
2417
+ return never;
2505
2418
  }
2506
2419
  }
2420
+ function satisfiesPrimitiveCheck(check, value) {
2421
+ if (check._tag === "FilterGroup") {
2422
+ return check.checks.every(check => satisfiesPrimitiveCheck(check, value));
2423
+ }
2424
+ const meta = check.meta;
2425
+ switch (meta._tag) {
2426
+ case "isMinLength":
2427
+ return typeof value === "string" && value.length >= meta.minLength;
2428
+ case "isMaxLength":
2429
+ return typeof value === "string" && value.length <= meta.maxLength;
2430
+ case "isPattern":
2431
+ return typeof value === "string" && meta.regExp.test(value);
2432
+ case "isFinite":
2433
+ return typeof value === "number" && globalThis.Number.isFinite(value);
2434
+ case "isInt":
2435
+ return typeof value === "number" && globalThis.Number.isSafeInteger(value);
2436
+ case "isMultipleOf":
2437
+ return typeof value === "number" && remainder(value, meta.divisor) === 0;
2438
+ case "isGreaterThan":
2439
+ return typeof value === "number" && value > meta.exclusiveMinimum;
2440
+ case "isGreaterThanOrEqualTo":
2441
+ return typeof value === "number" && value >= meta.minimum;
2442
+ case "isLessThan":
2443
+ return typeof value === "number" && value < meta.exclusiveMaximum;
2444
+ case "isLessThanOrEqualTo":
2445
+ return typeof value === "number" && value <= meta.maximum;
2446
+ default:
2447
+ return false;
2448
+ }
2449
+ }
2450
+ function satisfiesLiteral(type, literal) {
2451
+ const value = literal.literal;
2452
+ if (type._tag === "String" ? typeof value !== "string" : typeof value !== "number") {
2453
+ return false;
2454
+ }
2455
+ return type.checks.every(check => satisfiesPrimitiveCheck(check, value));
2456
+ }
2507
2457
  function collectProperties(js) {
2508
2458
  const properties = Predicate.isObject(js.properties) ? js.properties : {};
2509
2459
  const required = Array.isArray(js.required) ? js.required : [];
@@ -2544,34 +2494,46 @@ export function fromJsonSchemaMultiDocument(document, options) {
2544
2494
  }
2545
2495
  return out;
2546
2496
  }
2547
- function combineElements(a, b) {
2548
- const len = Math.max(a.length, b.length);
2549
- let out = [];
2497
+ function combineArrays(a, b) {
2498
+ const elements = [];
2499
+ const len = Math.max(a.elements.length, b.elements.length);
2550
2500
  for (let i = 0; i < len; i++) {
2551
- out.push({
2552
- isOptional: a[i].isOptional && b[i].isOptional,
2553
- type: combine(a[i].type, b[i].type)
2501
+ const ae = a.elements[i];
2502
+ const be = b.elements[i];
2503
+ const isOptional = ae?.isOptional !== false && be?.isOptional !== false;
2504
+ const at = ae?.type ?? a.rest[0];
2505
+ const bt = be?.type ?? b.rest[0];
2506
+ if (at === undefined || bt === undefined) {
2507
+ return isOptional ? {
2508
+ elements,
2509
+ rest: []
2510
+ } : undefined;
2511
+ }
2512
+ const type = combine(at, bt);
2513
+ if (type === never) {
2514
+ return isOptional ? {
2515
+ elements,
2516
+ rest: []
2517
+ } : undefined;
2518
+ }
2519
+ elements.push({
2520
+ isOptional,
2521
+ type
2554
2522
  });
2555
2523
  }
2556
- if (a.length > len) {
2557
- out = [...out, ...a.slice(len)];
2558
- } else if (b.length > len) {
2559
- out = [...out, ...b.slice(len)];
2560
- }
2561
- return out;
2562
- }
2563
- function combineRest(a, b) {
2564
- const len = Math.max(a.length, b.length);
2565
- let out = [];
2566
- for (let i = 0; i < len; i++) {
2567
- out.push(combine(a[i], b[i]));
2568
- }
2569
- if (a.length > len) {
2570
- out = [...out, ...a.slice(len)];
2571
- } else if (b.length > len) {
2572
- out = [...out, ...b.slice(len)];
2524
+ const ar = a.rest[0];
2525
+ const br = b.rest[0];
2526
+ if (ar === undefined || br === undefined) {
2527
+ return {
2528
+ elements,
2529
+ rest: []
2530
+ };
2573
2531
  }
2574
- return out;
2532
+ const rest = combine(ar, br);
2533
+ return {
2534
+ elements,
2535
+ rest: rest === never ? [] : [rest]
2536
+ };
2575
2537
  }
2576
2538
  function combinePropertySignatures(a, b) {
2577
2539
  const propertySignatures = [];