effect 4.1.3 → 4.1.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.
- package/dist/SchemaRepresentation.d.ts +17 -3
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +4 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ai/Chat.d.ts +1 -1
- package/dist/ai/Chat.d.ts.map +1 -1
- package/dist/ai/Chat.js.map +1 -1
- package/dist/ai/LanguageModel.d.ts +23 -4
- package/dist/ai/LanguageModel.d.ts.map +1 -1
- package/dist/ai/LanguageModel.js +8 -4
- package/dist/ai/LanguageModel.js.map +1 -1
- package/dist/ai/McpClient.d.ts +0 -5
- package/dist/ai/McpClient.d.ts.map +1 -1
- package/dist/ai/McpClient.js +1 -11
- package/dist/ai/McpClient.js.map +1 -1
- package/dist/ai/McpSchema.d.ts +110 -110
- package/dist/ai/McpSchema.d.ts.map +1 -1
- package/dist/ai/McpServer.d.ts +1 -3
- package/dist/ai/McpServer.d.ts.map +1 -1
- package/dist/ai/McpServer.js +1 -3
- package/dist/ai/McpServer.js.map +1 -1
- package/dist/ai/WorkloadIdentity.d.ts +111 -0
- package/dist/ai/WorkloadIdentity.d.ts.map +1 -0
- package/dist/ai/WorkloadIdentity.js +227 -0
- package/dist/ai/WorkloadIdentity.js.map +1 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +5 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js +3 -1
- package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
- package/dist/ai/internal/mcpRuntime.js +2 -4
- package/dist/ai/internal/mcpRuntime.js.map +1 -1
- package/dist/ai/internal/mcpSkills.js +80 -2
- package/dist/ai/internal/mcpSkills.js.map +1 -1
- package/dist/ai/internal/structured-output.js +5 -1
- package/dist/ai/internal/structured-output.js.map +1 -1
- package/dist/cli/Command.d.ts.map +1 -1
- package/dist/cli/Command.js +3 -1
- package/dist/cli/Command.js.map +1 -1
- package/dist/cli/internal/lexer.js +13 -0
- package/dist/cli/internal/lexer.js.map +1 -1
- package/dist/cli/internal/parser.js +23 -16
- package/dist/cli/internal/parser.js.map +1 -1
- package/dist/cli/internal/wizard.d.ts.map +1 -1
- package/dist/cli/internal/wizard.js +4 -0
- package/dist/cli/internal/wizard.js.map +1 -1
- package/dist/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/http/HttpMiddleware.js +4 -2
- package/dist/http/HttpMiddleware.js.map +1 -1
- package/dist/http/internal/requestState.js +15 -0
- package/dist/http/internal/requestState.js.map +1 -1
- package/dist/http-api/HttpApi.d.ts +47 -0
- package/dist/http-api/HttpApi.d.ts.map +1 -1
- package/dist/http-api/HttpApi.js +66 -0
- package/dist/http-api/HttpApi.js.map +1 -1
- package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
- package/dist/http-api/HttpApiBuilder.js +9 -1
- package/dist/http-api/HttpApiBuilder.js.map +1 -1
- package/dist/http-api/HttpApiClient.d.ts +1 -1
- package/dist/http-api/HttpApiClient.d.ts.map +1 -1
- package/dist/http-api/HttpApiClient.js +5 -1
- package/dist/http-api/HttpApiClient.js.map +1 -1
- package/dist/http-api/HttpApiSchema.d.ts +66 -0
- package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
- package/dist/http-api/HttpApiSchema.js +66 -1
- package/dist/http-api/HttpApiSchema.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +141 -35
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toCodeDocument.js +3 -0
- package/dist/internal/schema/toCodeDocument.js.map +1 -1
- package/dist/internal/version.js +1 -1
- package/dist/testing/TestClock.js +3 -1
- package/dist/testing/TestClock.js.map +1 -1
- package/package.json +1 -1
- package/src/SchemaRepresentation.ts +18 -3
- package/src/ai/Chat.ts +9 -3
- package/src/ai/LanguageModel.ts +70 -14
- package/src/ai/McpClient.ts +1 -11
- package/src/ai/McpServer.ts +1 -3
- package/src/ai/WorkloadIdentity.ts +318 -0
- package/src/ai/index.ts +6 -0
- package/src/ai/internal/mcpProtocol/v2024_11_05.ts +3 -1
- package/src/ai/internal/mcpProtocol/v2025_03_26.ts +3 -1
- package/src/ai/internal/mcpProtocol/v2025_06_18.ts +3 -1
- package/src/ai/internal/mcpProtocol/v2025_11_25.ts +3 -1
- package/src/ai/internal/mcpRuntime.ts +2 -6
- package/src/ai/internal/mcpSkills.ts +70 -2
- package/src/ai/internal/structured-output.ts +6 -1
- package/src/cli/Command.ts +5 -1
- package/src/cli/internal/lexer.ts +14 -0
- package/src/cli/internal/parser.ts +28 -20
- package/src/cli/internal/wizard.ts +4 -0
- package/src/http/HttpMiddleware.ts +13 -2
- package/src/http/internal/requestState.ts +20 -0
- package/src/http-api/HttpApi.ts +80 -0
- package/src/http-api/HttpApiBuilder.ts +9 -1
- package/src/http-api/HttpApiClient.ts +13 -2
- package/src/http-api/HttpApiSchema.ts +68 -2
- package/src/internal/schema/fromJsonSchemaDocument.ts +154 -34
- package/src/internal/schema/toCodeDocument.ts +8 -0
- package/src/internal/version.ts +1 -1
- package/src/testing/TestClock.ts +1 -1
|
@@ -54,7 +54,7 @@ declare module "../Schema.ts" {
|
|
|
54
54
|
*/
|
|
55
55
|
export interface WithHeadersAnnotation {
|
|
56
56
|
readonly body: Schema.Top
|
|
57
|
-
readonly headers: Schema.
|
|
57
|
+
readonly headers: Schema.Struct<Schema.Struct.Fields>
|
|
58
58
|
/**
|
|
59
59
|
* Codecs from the body and headers types to their response representation.
|
|
60
60
|
* `HttpApiEndpoint` replaces them with the response encoding codecs.
|
|
@@ -1494,6 +1494,44 @@ const resolveHttpApiEncoding = SchemaAST.resolveAt<Encoding>("~httpApiEncoding")
|
|
|
1494
1494
|
*/
|
|
1495
1495
|
export const getWithHeadersAnnotation = SchemaAST.resolveAt<WithHeadersAnnotation>("~httpApiWithHeaders")
|
|
1496
1496
|
|
|
1497
|
+
/**
|
|
1498
|
+
* Returns the declared body and headers schemas of an `encodeToWithHeaders`
|
|
1499
|
+
* response, or `undefined` for any other schema.
|
|
1500
|
+
*
|
|
1501
|
+
* **When to use**
|
|
1502
|
+
*
|
|
1503
|
+
* Use to inspect response schemas for code generation before a response exists,
|
|
1504
|
+
* including schemas obtained through `HttpApi.reflect`.
|
|
1505
|
+
*
|
|
1506
|
+
* **Details**
|
|
1507
|
+
*
|
|
1508
|
+
* Both schemas keep their declared identity through endpoint construction and
|
|
1509
|
+
* reflection, with or without `disableCodecs`. The headers schema is a
|
|
1510
|
+
* `Schema.Struct`, so its fields can be inspected directly.
|
|
1511
|
+
*
|
|
1512
|
+
* **Gotchas**
|
|
1513
|
+
*
|
|
1514
|
+
* These are declared schemas, not the response codecs installed by an endpoint.
|
|
1515
|
+
* Plain schemas, `WithHeaders` wrappers, and ordinary transformations from an
|
|
1516
|
+
* identical `{ body, headers }` struct return `undefined`. So do schemas derived
|
|
1517
|
+
* from the result with operations such as `.check`, `Schema.Union`, or
|
|
1518
|
+
* `Schema.decodeTo` with a target that lacks this metadata, while `.annotate`,
|
|
1519
|
+
* `Schema.brand`, and `Schema.decode` keep the parts.
|
|
1520
|
+
*
|
|
1521
|
+
* @see encodeToWithHeaders
|
|
1522
|
+
* @see getResponseEncodingSchema
|
|
1523
|
+
* @stability unstable
|
|
1524
|
+
* @category getters
|
|
1525
|
+
* @since 4.1.4
|
|
1526
|
+
*/
|
|
1527
|
+
export function getEncodeToWithHeadersParts(schema: Schema.Constraint): {
|
|
1528
|
+
readonly body: Schema.Top
|
|
1529
|
+
readonly headers: Schema.Struct<Schema.Struct.Fields>
|
|
1530
|
+
} | undefined {
|
|
1531
|
+
const annotation = getWithHeadersAnnotation(schema.ast)
|
|
1532
|
+
return annotation === undefined ? undefined : { body: annotation.body, headers: annotation.headers }
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1497
1535
|
function findHttpApiStatusAnnotation(
|
|
1498
1536
|
ast: SchemaAST.AST | SchemaAST.FilterGroup<any>
|
|
1499
1537
|
): Schema.Annotations.Annotations | undefined {
|
|
@@ -1569,7 +1607,35 @@ export function getStatusSuccessSchema(schema: Schema.Constraint): number {
|
|
|
1569
1607
|
}
|
|
1570
1608
|
|
|
1571
1609
|
/**
|
|
1572
|
-
*
|
|
1610
|
+
* Returns the buffered response encoding resolved from a schema's annotations,
|
|
1611
|
+
* defaulting to `{ _tag: "Json", contentType: "application/json" }`.
|
|
1612
|
+
*
|
|
1613
|
+
* **When to use**
|
|
1614
|
+
*
|
|
1615
|
+
* Use to read response media types from declared schemas or schemas obtained
|
|
1616
|
+
* through `HttpApi.reflect` without encoding a response value.
|
|
1617
|
+
*
|
|
1618
|
+
* **Details**
|
|
1619
|
+
*
|
|
1620
|
+
* For `WithHeaders`, the wrapper's encoding takes precedence over the inner
|
|
1621
|
+
* schema's encoding. For `encodeToWithHeaders`, the body schema's encoding is
|
|
1622
|
+
* used. Re-annotating the result changes what this function returns, not what
|
|
1623
|
+
* the server sends.
|
|
1624
|
+
*
|
|
1625
|
+
* **Gotchas**
|
|
1626
|
+
*
|
|
1627
|
+
* - No-content schemas also receive the JSON default. Check `isNoContent` on
|
|
1628
|
+
* the body AST first: `schema.schema.ast` for `WithHeaders`, `parts.body.ast`
|
|
1629
|
+
* from `getEncodeToWithHeadersParts`, or `schema.ast` otherwise.
|
|
1630
|
+
* - Streaming and upgrade schemas are outside this buffered-response contract;
|
|
1631
|
+
* their JSON fallback does not describe their wire representation.
|
|
1632
|
+
* - Multipart encoding throws because multipart responses are not supported.
|
|
1633
|
+
*
|
|
1634
|
+
* @see getEncodeToWithHeadersParts
|
|
1635
|
+
* @see isNoContent
|
|
1636
|
+
* @stability unstable
|
|
1637
|
+
* @category getters
|
|
1638
|
+
* @since 4.1.4
|
|
1573
1639
|
*/
|
|
1574
1640
|
export function getResponseEncodingSchema(schema: Schema.Constraint): ResponseEncoding {
|
|
1575
1641
|
if (isWithHeaders(schema) && resolveHttpApiEncoding(schema.ast) === undefined) {
|
|
@@ -113,10 +113,15 @@ interface ImportedObjectProperty {
|
|
|
113
113
|
interface ImportedObjectScope {
|
|
114
114
|
readonly properties: ReadonlyMap<string, ImportedObjectProperty>
|
|
115
115
|
readonly hasProperties: boolean
|
|
116
|
+
readonly implicitAdditionalProperties: boolean
|
|
116
117
|
readonly patterns: ReadonlyArray<ImportedObjectPattern>
|
|
117
118
|
readonly additionalProperties: ImportedJsonSchemaRepresentation
|
|
118
119
|
}
|
|
119
120
|
|
|
121
|
+
type DefinitionState =
|
|
122
|
+
| { readonly _tag: "Translating"; aliasPath?: Path | undefined }
|
|
123
|
+
| { readonly _tag: "Ready"; readonly value: ImportedJsonSchemaRepresentation }
|
|
124
|
+
|
|
120
125
|
const never: ImportedJsonSchemaRepresentation = { _tag: "Never", checks: [] }
|
|
121
126
|
const unknown: ImportedJsonSchemaRepresentation = { _tag: "Unknown", checks: [] }
|
|
122
127
|
const string: ImportedJsonSchemaRepresentation = { _tag: "String", checks: [] }
|
|
@@ -285,7 +290,11 @@ export function fromJsonSchemaMultiDocument(
|
|
|
285
290
|
options?: SchemaRepresentation.FromJsonSchemaOptions,
|
|
286
291
|
singleRoot = false
|
|
287
292
|
): readonly [Schema.Top, ...Array<Schema.Top>] {
|
|
288
|
-
const definitionCache = new Map<string,
|
|
293
|
+
const definitionCache = new Map<string, DefinitionState>()
|
|
294
|
+
const activeIntersections = new Map<
|
|
295
|
+
string | ImportedJsonSchemaRepresentation,
|
|
296
|
+
Set<string | ImportedJsonSchemaRepresentation>
|
|
297
|
+
>()
|
|
289
298
|
const validatedAliases = new Set<string>()
|
|
290
299
|
const resolvingChoices = new Set<string>()
|
|
291
300
|
const references = new Map<string, ReferenceSlot>()
|
|
@@ -347,7 +356,10 @@ export function fromJsonSchemaMultiDocument(
|
|
|
347
356
|
const type = finalize(property.type)
|
|
348
357
|
InternalRecord.assignProperty(fields, property.name, property.isOptional ? Schema.optionalKey(type) : type)
|
|
349
358
|
}
|
|
350
|
-
const index = input.
|
|
359
|
+
const index = options?.closeObjects && input.scopes.some((scope) => scope.hasProperties) &&
|
|
360
|
+
input.scopes.every((scope) => scope.implicitAdditionalProperties)
|
|
361
|
+
? undefined
|
|
362
|
+
: input.indexSignatures[0]
|
|
351
363
|
const record = index === undefined
|
|
352
364
|
? undefined
|
|
353
365
|
: Schema.Record(finalize(index.parameter) as Schema.Record.Key, finalize(index.type))
|
|
@@ -390,6 +402,12 @@ export function fromJsonSchemaMultiDocument(
|
|
|
390
402
|
}
|
|
391
403
|
}
|
|
392
404
|
|
|
405
|
+
function withoutExamples(representation: ImportedJsonSchemaRepresentation): ImportedJsonSchemaRepresentation {
|
|
406
|
+
if (representation.annotations?.examples === undefined) return representation
|
|
407
|
+
const { examples: _, ...annotations } = representation.annotations
|
|
408
|
+
return { ...representation, annotations: Object.keys(annotations).length === 0 ? undefined : annotations }
|
|
409
|
+
}
|
|
410
|
+
|
|
393
411
|
function translateDefinition(
|
|
394
412
|
key: string,
|
|
395
413
|
path: Path,
|
|
@@ -397,28 +415,36 @@ export function fromJsonSchemaMultiDocument(
|
|
|
397
415
|
): ImportedJsonSchemaRepresentation {
|
|
398
416
|
const cached = definitionCache.get(key)
|
|
399
417
|
if (cached !== undefined) {
|
|
400
|
-
if (cached ===
|
|
418
|
+
if (cached._tag === "Translating") {
|
|
401
419
|
throw errorWithPath(
|
|
402
420
|
recursiveReferenceError ??
|
|
403
|
-
`
|
|
421
|
+
`Cannot resolve recursive definition ${JSON.stringify(key)} during normalization.`,
|
|
404
422
|
[...path, "$ref"]
|
|
405
423
|
)
|
|
406
424
|
}
|
|
407
|
-
return cached
|
|
425
|
+
return cached.value
|
|
408
426
|
}
|
|
409
|
-
|
|
427
|
+
const state: DefinitionState = { _tag: "Translating" }
|
|
428
|
+
definitionCache.set(key, state)
|
|
410
429
|
const pointer = pointers.get(key)
|
|
411
430
|
const wasInNestedResource = inNestedResource
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
431
|
+
try {
|
|
432
|
+
if (pointer !== undefined) inNestedResource = pointer.crossesResource
|
|
433
|
+
const representation = pointer === undefined
|
|
434
|
+
? translateSchema(document.definitions[key], ["definitions", key])
|
|
435
|
+
: translateSchema(pointer.target, ["definitions", ...pointer.tokens])
|
|
436
|
+
definitionCache.set(key, { _tag: "Ready", value: representation })
|
|
437
|
+
if (pointer !== undefined || state.aliasPath !== undefined) {
|
|
438
|
+
validatePointerAliases(representation, state.aliasPath ?? path, recursiveReferenceError)
|
|
439
|
+
}
|
|
440
|
+
return representation
|
|
441
|
+
} catch (error) {
|
|
442
|
+
definitionCache.delete(key)
|
|
443
|
+
validatedAliases.delete(key)
|
|
444
|
+
throw error
|
|
445
|
+
} finally {
|
|
446
|
+
inNestedResource = wasInNestedResource
|
|
420
447
|
}
|
|
421
|
-
return representation
|
|
422
448
|
}
|
|
423
449
|
|
|
424
450
|
function validatePointerAliases(
|
|
@@ -668,7 +694,10 @@ export function fromJsonSchemaMultiDocument(
|
|
|
668
694
|
for (const name of scope.properties.keys()) names.add(name)
|
|
669
695
|
hasFiniteKeyDomain ||= scope.additionalProperties._tag === "Never" && scope.patterns.length === 0
|
|
670
696
|
requiresFiniteKeyDomain ||= scope.additionalProperties._tag === "Never" ||
|
|
671
|
-
scope.additionalProperties._tag !== "Unknown" && (scope.
|
|
697
|
+
scope.additionalProperties._tag !== "Unknown" && (scope.patterns.length > 0 ||
|
|
698
|
+
Array.from(scope.properties.values()).some((property) =>
|
|
699
|
+
property.type !== undefined && !isCoveredBy(property.type, scope.additionalProperties)
|
|
700
|
+
))
|
|
672
701
|
}
|
|
673
702
|
const closedPattern = scopes.length === 1 && names.size === 0 &&
|
|
674
703
|
scopes[0].additionalProperties._tag === "Never" && scopes[0].patterns.length === 1
|
|
@@ -733,6 +762,23 @@ export function fromJsonSchemaMultiDocument(
|
|
|
733
762
|
const jsonRootTags = ["Null", "String", "Number", "Boolean", "Objects", "Arrays"] as const
|
|
734
763
|
const allMasks = (1 << jsonRootTags.length) - 1
|
|
735
764
|
|
|
765
|
+
// A catch-all can also validate declared properties when it cannot narrow them.
|
|
766
|
+
function isCoveredBy(type: ImportedJsonSchemaRepresentation, covering: ImportedJsonSchemaRepresentation): boolean {
|
|
767
|
+
if (covering._tag === "Unknown" || type._tag === "Never" || type === covering) return true
|
|
768
|
+
if (type._tag === "Union") return type.types.every((member) => isCoveredBy(member, covering))
|
|
769
|
+
if (covering._tag === "Reference") return type._tag === "Reference" && type.$ref === covering.$ref
|
|
770
|
+
if (covering._tag === "Union") {
|
|
771
|
+
return covering.options?.mode !== "oneOf" && covering.checks.length === 0 &&
|
|
772
|
+
covering.types.some((member) => isCoveredBy(type, member))
|
|
773
|
+
}
|
|
774
|
+
return (covering._tag === "Null" || covering._tag === "String" || covering._tag === "Number" ||
|
|
775
|
+
covering._tag === "Boolean") &&
|
|
776
|
+
covering.checks.every((check) =>
|
|
777
|
+
check._tag === "Filter" && check.filter.annotations?.representation?.id === "effect/schema/isFinite"
|
|
778
|
+
) &&
|
|
779
|
+
(type._tag === covering._tag || type._tag === "Literal" && (rootMask(type) & rootMask(covering)) !== 0)
|
|
780
|
+
}
|
|
781
|
+
|
|
736
782
|
function rootMask(representation: ImportedJsonSchemaRepresentation): number {
|
|
737
783
|
switch (representation._tag) {
|
|
738
784
|
case "Never":
|
|
@@ -768,11 +814,13 @@ export function fromJsonSchemaMultiDocument(
|
|
|
768
814
|
case "Reference": {
|
|
769
815
|
const key = representation.$ref
|
|
770
816
|
const cached = definitionCache.get(key)
|
|
771
|
-
if (cached ===
|
|
817
|
+
if (cached?._tag === "Translating" || resolvingChoices.has(key)) return true
|
|
772
818
|
resolvingChoices.add(key)
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
819
|
+
try {
|
|
820
|
+
return hasChoices(cached?.value ?? translateDefinition(key, representation.path))
|
|
821
|
+
} finally {
|
|
822
|
+
resolvingChoices.delete(key)
|
|
823
|
+
}
|
|
776
824
|
}
|
|
777
825
|
case "Union":
|
|
778
826
|
// Finite primitive literal sets intersect without expansion, so they can be duplicated across branches.
|
|
@@ -851,13 +899,12 @@ export function fromJsonSchemaMultiDocument(
|
|
|
851
899
|
path: Path,
|
|
852
900
|
unionOnLeft: boolean
|
|
853
901
|
): ImportedJsonSchemaRepresentation {
|
|
854
|
-
const mask = rootMask(type)
|
|
855
902
|
const members = union.types
|
|
856
903
|
.map((member, index) => ({
|
|
857
904
|
index,
|
|
858
905
|
type: member
|
|
859
906
|
}))
|
|
860
|
-
.filter((member) => (
|
|
907
|
+
.filter((member) => !areDisjoint(member.type, type))
|
|
861
908
|
if (members.length > 1 && hasChoices(type)) {
|
|
862
909
|
return unsupportedIntersection(path)
|
|
863
910
|
}
|
|
@@ -867,6 +914,13 @@ export function fromJsonSchemaMultiDocument(
|
|
|
867
914
|
? intersect(member, type, [...path, "types", members[0].index])
|
|
868
915
|
: intersect(type, member, [...path, "types", members[0].index])
|
|
869
916
|
}
|
|
917
|
+
// Resolve the reference without changing the union's matching mode.
|
|
918
|
+
if (members.length > 1 && type._tag === "Reference") {
|
|
919
|
+
const resolved = annotate(resolveReference(type, path), type)
|
|
920
|
+
const out = intersectUnionWithType(union, withoutExamples(resolved), path, unionOnLeft)
|
|
921
|
+
const examples = resolved.annotations?.examples
|
|
922
|
+
return examples === undefined ? out : annotate(out, { annotations: { examples } })
|
|
923
|
+
}
|
|
870
924
|
return makeUnion(
|
|
871
925
|
union,
|
|
872
926
|
members
|
|
@@ -879,12 +933,33 @@ export function fromJsonSchemaMultiDocument(
|
|
|
879
933
|
)
|
|
880
934
|
}
|
|
881
935
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
936
|
+
// Prove disjointness without intersecting (and potentially expanding) branches.
|
|
937
|
+
function areDisjoint(left: ImportedJsonSchemaRepresentation, right: ImportedJsonSchemaRepresentation): boolean {
|
|
938
|
+
if ((rootMask(left) & rootMask(right)) === 0) return true
|
|
939
|
+
if (left._tag === "Reference" && definitionCache.get(left.$ref)?._tag !== "Translating") {
|
|
940
|
+
left = resolveReference(left, left.path)
|
|
941
|
+
}
|
|
942
|
+
if (right._tag === "Reference" && definitionCache.get(right.$ref)?._tag !== "Translating") {
|
|
943
|
+
right = resolveReference(right, right.path)
|
|
944
|
+
}
|
|
945
|
+
if ((rootMask(left) & rootMask(right)) === 0) return true
|
|
946
|
+
if (left._tag !== "Objects" || right._tag !== "Objects") return false
|
|
947
|
+
const rightProperties = right.propertySignatures
|
|
948
|
+
return left.propertySignatures.some((property) => {
|
|
949
|
+
if (property.isOptional) return false
|
|
950
|
+
const value = literalValue(property.type)
|
|
951
|
+
if (value === undefined) return false
|
|
952
|
+
const other = rightProperties.find((other) => other.name === property.name && !other.isOptional)
|
|
953
|
+
const otherValue = other === undefined ? undefined : literalValue(other.type)
|
|
954
|
+
return otherValue !== undefined && value !== otherValue
|
|
955
|
+
})
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function isDisjointUnion(union: ImportedUnion): boolean {
|
|
959
|
+
for (let index = 0; index < union.types.length; index++) {
|
|
960
|
+
for (let other = 0; other < index; other++) {
|
|
961
|
+
if (!areDisjoint(union.types[index], union.types[other])) return false
|
|
962
|
+
}
|
|
888
963
|
}
|
|
889
964
|
return true
|
|
890
965
|
}
|
|
@@ -905,8 +980,8 @@ export function fromJsonSchemaMultiDocument(
|
|
|
905
980
|
const partitionTypes = partition.types
|
|
906
981
|
const otherTypes = other.types
|
|
907
982
|
for (const type of otherTypes) {
|
|
908
|
-
const
|
|
909
|
-
if (
|
|
983
|
+
const matches = partitionTypes.filter((member) => !areDisjoint(member, type)).length
|
|
984
|
+
if (matches > 1 && hasChoices(type)) {
|
|
910
985
|
return unsupportedIntersection(path)
|
|
911
986
|
}
|
|
912
987
|
}
|
|
@@ -926,8 +1001,8 @@ export function fromJsonSchemaMultiDocument(
|
|
|
926
1001
|
): ImportedJsonSchemaRepresentation {
|
|
927
1002
|
const literals = intersectLiteralUnions(left, right, path)
|
|
928
1003
|
if (literals !== undefined) return literals
|
|
929
|
-
if (
|
|
930
|
-
if (
|
|
1004
|
+
if (isDisjointUnion(left)) return intersectPartition(left, right, path, true)
|
|
1005
|
+
if (isDisjointUnion(right)) return intersectPartition(right, left, path, false)
|
|
931
1006
|
return unsupportedIntersection(path)
|
|
932
1007
|
}
|
|
933
1008
|
|
|
@@ -935,11 +1010,41 @@ export function fromJsonSchemaMultiDocument(
|
|
|
935
1010
|
left: ImportedJsonSchemaRepresentation,
|
|
936
1011
|
right: ImportedJsonSchemaRepresentation,
|
|
937
1012
|
path: Path
|
|
1013
|
+
): ImportedJsonSchemaRepresentation {
|
|
1014
|
+
// Annotation propagation can copy a reference without changing its definition.
|
|
1015
|
+
const leftKey = left._tag === "Reference" ? left.$ref : left
|
|
1016
|
+
const rightKey = right._tag === "Reference" ? right.$ref : right
|
|
1017
|
+
let active = activeIntersections.get(leftKey)
|
|
1018
|
+
if (active === undefined) {
|
|
1019
|
+
active = new Set()
|
|
1020
|
+
activeIntersections.set(leftKey, active)
|
|
1021
|
+
}
|
|
1022
|
+
if (active.has(rightKey)) throw errorWithPath("Cannot normalize this recursive intersection.", path)
|
|
1023
|
+
active.add(rightKey)
|
|
1024
|
+
try {
|
|
1025
|
+
return intersectNodes(left, right, path)
|
|
1026
|
+
} finally {
|
|
1027
|
+
active.delete(rightKey)
|
|
1028
|
+
if (active.size === 0) activeIntersections.delete(leftKey)
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function intersectNodes(
|
|
1033
|
+
left: ImportedJsonSchemaRepresentation,
|
|
1034
|
+
right: ImportedJsonSchemaRepresentation,
|
|
1035
|
+
path: Path
|
|
938
1036
|
): ImportedJsonSchemaRepresentation {
|
|
939
1037
|
if (left._tag === "Never") return left
|
|
940
1038
|
if (right._tag === "Never") return right
|
|
941
1039
|
if (left._tag === "Unknown") return annotateIntersection(right, left, right)
|
|
942
1040
|
if (right._tag === "Unknown") return annotateIntersection(left, left, right)
|
|
1041
|
+
if (left._tag === "Reference" && right._tag === "Reference" && left.$ref === right.$ref) {
|
|
1042
|
+
// Identity does not need the body, but its aliases must be checked once the body is ready.
|
|
1043
|
+
const state = definitionCache.get(left.$ref)
|
|
1044
|
+
if (state?._tag === "Translating") state.aliasPath ??= path
|
|
1045
|
+
else validatePointerAliases(left, path)
|
|
1046
|
+
return annotateIntersection(left, left, right)
|
|
1047
|
+
}
|
|
943
1048
|
if (left._tag === "Reference") {
|
|
944
1049
|
// Resolve an unannotated reference first. An annotated empty definition
|
|
945
1050
|
// could otherwise leave the other reference unresolved during union partitioning.
|
|
@@ -954,6 +1059,12 @@ export function fromJsonSchemaMultiDocument(
|
|
|
954
1059
|
if (right._tag === "Reference") {
|
|
955
1060
|
return annotate(intersect(left, resolveReference(right, path), path), right)
|
|
956
1061
|
}
|
|
1062
|
+
// Operand examples describe the whole intersection, not each distributed branch.
|
|
1063
|
+
const examples = right.annotations?.examples ?? left.annotations?.examples
|
|
1064
|
+
if (examples !== undefined && (left._tag === "Union" || right._tag === "Union")) {
|
|
1065
|
+
const out = intersectNodes(withoutExamples(left), withoutExamples(right), path)
|
|
1066
|
+
return annotate(out, { annotations: { examples } })
|
|
1067
|
+
}
|
|
957
1068
|
if (left._tag === "Union" && right._tag === "Union") return intersectUnions(left, right, path)
|
|
958
1069
|
if (left._tag === "Union") return intersectUnionWithType(left, right, path, true)
|
|
959
1070
|
if (right._tag === "Union") return intersectUnionWithType(right, left, path, false)
|
|
@@ -1292,13 +1403,22 @@ export function fromJsonSchemaMultiDocument(
|
|
|
1292
1403
|
isOptional: !required.has(name)
|
|
1293
1404
|
}]))
|
|
1294
1405
|
const hasProperties = propertyNames.length > 0
|
|
1406
|
+
const implicitAdditionalProperties = schema.additionalProperties === undefined
|
|
1295
1407
|
const patterns: Array<ImportedObjectPattern> = []
|
|
1296
1408
|
if (
|
|
1297
1409
|
isObject(schema.patternProperties)
|
|
1298
1410
|
) {
|
|
1299
1411
|
for (const [pattern, value] of Object.entries(schema.patternProperties)) {
|
|
1300
1412
|
const check = importPatternCheck(pattern, [...path, "patternProperties", pattern])
|
|
1301
|
-
if (check === undefined)
|
|
1413
|
+
if (check === undefined) {
|
|
1414
|
+
return {
|
|
1415
|
+
properties,
|
|
1416
|
+
hasProperties,
|
|
1417
|
+
implicitAdditionalProperties: false,
|
|
1418
|
+
patterns: [],
|
|
1419
|
+
additionalProperties: unknown
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1302
1422
|
patterns.push({
|
|
1303
1423
|
source: pattern,
|
|
1304
1424
|
parameter: {
|
|
@@ -1314,7 +1434,7 @@ export function fromJsonSchemaMultiDocument(
|
|
|
1314
1434
|
: isObject(schema.additionalProperties)
|
|
1315
1435
|
? translateSchema(schema.additionalProperties, [...path, "additionalProperties"])
|
|
1316
1436
|
: unknown
|
|
1317
|
-
return { properties, hasProperties, patterns, additionalProperties }
|
|
1437
|
+
return { properties, hasProperties, implicitAdditionalProperties, patterns, additionalProperties }
|
|
1318
1438
|
}
|
|
1319
1439
|
|
|
1320
1440
|
function collectObjectChecks(
|
|
@@ -43,6 +43,14 @@ function renderEmittableAnnotation(input: unknown): string | undefined {
|
|
|
43
43
|
return `[${values.join(", ")}]`
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const prototype = Object.getPrototypeOf(input)
|
|
47
|
+
// Plain objects from other realms also have a prototype whose prototype is null.
|
|
48
|
+
if (
|
|
49
|
+
prototype !== null &&
|
|
50
|
+
prototype !== Object.prototype &&
|
|
51
|
+
Object.getPrototypeOf(prototype) !== null
|
|
52
|
+
) return undefined
|
|
53
|
+
|
|
46
54
|
const entries: Array<string> = []
|
|
47
55
|
for (const [key, value] of Object.entries(input)) {
|
|
48
56
|
const rendered = renderEmittableAnnotation(value)
|
package/src/internal/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = "4.1.
|
|
2
|
+
export const version = "4.1.4"
|
package/src/testing/TestClock.ts
CHANGED
|
@@ -377,8 +377,8 @@ class TestClockImpl implements TestClock {
|
|
|
377
377
|
Effect.provideService(Console.Console, this.liveConsole),
|
|
378
378
|
Effect.delay(this.config.warningDelay),
|
|
379
379
|
this.withLive,
|
|
380
|
+
// Child fibers are interruptible by default; preserve the caller's mask.
|
|
380
381
|
Effect.forkChild,
|
|
381
|
-
Effect.interruptible,
|
|
382
382
|
Effect.flatMap((fiber) =>
|
|
383
383
|
Effect.sync(() => {
|
|
384
384
|
this.warningState = WarningState.Pending({ fiber })
|