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.
- package/dist/LayerRef.d.ts +4 -6
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +4 -6
- package/dist/LayerRef.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +28 -10
- package/dist/Number.js.map +1 -1
- package/dist/Schema.d.ts +22 -22
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +36 -33
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +25 -10
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +53 -0
- package/dist/SchemaError.d.ts.map +1 -0
- package/dist/SchemaError.js +61 -0
- package/dist/SchemaError.js.map +1 -0
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +17 -12
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +186 -224
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +26 -8
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/equivalence.js +1 -2
- package/dist/internal/schema/equivalence.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -3
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts +0 -13
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +4 -29
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +128 -128
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.d.ts +8 -16
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +8 -16
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +4 -3
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +3 -3
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +6 -8
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +6 -6
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.js +2 -4
- package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +15 -12
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +19 -20
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +40 -30
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +31 -0
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.js +9 -8
- package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +77 -37
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/httpapi/internal/html.js +6 -2
- package/dist/unstable/httpapi/internal/html.js.map +1 -1
- package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
- package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
- package/dist/unstable/httpapi/internal/mediaType.js +7 -0
- package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +16 -12
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +3 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +6 -3
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +1 -1
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +1 -1
- package/src/LayerRef.ts +4 -6
- package/src/Number.ts +29 -10
- package/src/Schema.ts +42 -34
- package/src/SchemaAST.ts +25 -13
- package/src/SchemaError.ts +64 -0
- package/src/SchemaGetter.ts +22 -16
- package/src/SchemaRepresentation.ts +165 -202
- package/src/index.ts +10 -0
- package/src/internal/effect.ts +39 -22
- package/src/internal/schema/equivalence.ts +1 -2
- package/src/internal/schema/representation.ts +4 -4
- package/src/internal/schema/schema.ts +4 -37
- package/src/unstable/cli/CliError.ts +24 -16
- package/src/unstable/cli/Command.ts +8 -8
- package/src/unstable/cli/GlobalFlag.ts +22 -33
- package/src/unstable/cluster/EntityProxyServer.ts +15 -17
- package/src/unstable/cluster/internal/entityManager.ts +48 -34
- package/src/unstable/httpapi/HttpApi.ts +72 -47
- package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
- package/src/unstable/httpapi/HttpApiClient.ts +196 -151
- package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
- package/src/unstable/httpapi/HttpApiError.ts +33 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
- package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
- package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
- package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
- package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
- package/src/unstable/httpapi/HttpApiTest.ts +15 -14
- package/src/unstable/httpapi/OpenApi.ts +74 -36
- package/src/unstable/httpapi/internal/html.ts +9 -2
- package/src/unstable/httpapi/internal/mediaType.ts +6 -0
- package/src/unstable/persistence/PersistedQueue.ts +16 -14
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
- package/src/unstable/rpc/RpcServer.ts +10 -4
- package/src/unstable/workflow/DurableDeferred.ts +1 -1
- 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
|
|
2045
|
+
let definitionIdentifier;
|
|
2045
2046
|
const references = {};
|
|
2046
|
-
const
|
|
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
|
|
2064
|
-
if (
|
|
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
|
-
|
|
2073
|
-
|
|
2057
|
+
if (resolved !== undefined) return resolved;
|
|
2058
|
+
resolvedReferences.set($ref, null);
|
|
2074
2059
|
const value = recur(definition);
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
return
|
|
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)
|
|
2080
|
-
|
|
2064
|
+
for (const [identifier, definition] of Object.entries(document.definitions)) {
|
|
2065
|
+
definitionIdentifier = identifier;
|
|
2081
2066
|
references[identifier] = unknownToJson(recur(definition));
|
|
2082
|
-
}
|
|
2083
|
-
|
|
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 (
|
|
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
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
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
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
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
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
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
|
-
|
|
2350
|
-
|
|
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
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
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
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
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
|
|
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
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
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
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
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
|
|
2548
|
-
const
|
|
2549
|
-
|
|
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
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
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
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
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
|
-
|
|
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 = [];
|