effect 4.0.0-beta.105 → 4.0.0-beta.106
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/Config.js +3 -3
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +35 -3
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +41 -8
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Fiber.d.ts +1 -1
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Function.d.ts +26 -0
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +36 -0
- package/dist/Function.js.map +1 -1
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +34 -17
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Schema.d.ts +32 -84
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +58 -54
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -17
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +39 -28
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +15 -3
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +8 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ScopedRef.d.ts.map +1 -1
- package/dist/ScopedRef.js +1 -1
- package/dist/ScopedRef.js.map +1 -1
- package/dist/TxQueue.js +1 -1
- package/dist/TxQueue.js.map +1 -1
- package/dist/internal/effect.js +2 -4
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/executionPlan.js +3 -2
- package/dist/internal/executionPlan.js.map +1 -1
- package/dist/internal/rcRef.js +18 -13
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +10 -6
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toArbitrary.d.ts +1 -4
- package/dist/internal/schema/toArbitrary.d.ts.map +1 -1
- package/dist/internal/schema/toArbitrary.js +0 -74
- package/dist/internal/schema/toArbitrary.js.map +1 -1
- package/dist/internal/schema/toJsonSchemaDocument.js +18 -4
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toRepresentation.js +45 -43
- package/dist/internal/schema/toRepresentation.js.map +1 -1
- package/dist/testing/TestSchema.js +2 -2
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +110 -110
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +23 -11
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +4 -3
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +38 -13
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +2 -2
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/EntityProxy.d.ts +3 -3
- package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxy.js +4 -3
- package/dist/unstable/cluster/EntityProxy.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +14 -5
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +6 -5
- package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +14 -12
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +3 -3
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +2 -3
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.js +4 -4
- package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerEncrypted.js +3 -2
- package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +7 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
- package/dist/unstable/http/MultipartParser/internal/multipart.js +18 -6
- package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +5 -0
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +20 -16
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workers/Worker.d.ts.map +1 -1
- package/dist/unstable/workers/Worker.js +11 -12
- package/dist/unstable/workers/Worker.js.map +1 -1
- package/package.json +1 -1
- package/src/Config.ts +3 -3
- package/src/ConfigProvider.ts +43 -8
- package/src/Fiber.ts +1 -1
- package/src/Function.ts +37 -0
- package/src/JsonSchema.ts +43 -42
- package/src/Schema.ts +68 -146
- package/src/SchemaAST.ts +50 -30
- package/src/SchemaRepresentation.ts +15 -3
- package/src/ScopedRef.ts +3 -1
- package/src/TxQueue.ts +1 -1
- package/src/internal/effect.ts +3 -6
- package/src/internal/executionPlan.ts +3 -2
- package/src/internal/rcRef.ts +24 -16
- package/src/internal/schema/fromJsonSchemaDocument.ts +19 -14
- package/src/internal/schema/toArbitrary.ts +0 -72
- package/src/internal/schema/toJsonSchemaDocument.ts +24 -4
- package/src/internal/schema/toRepresentation.ts +66 -48
- package/src/testing/TestSchema.ts +2 -2
- package/src/unstable/ai/McpServer.ts +23 -11
- package/src/unstable/ai/Prompt.ts +37 -15
- package/src/unstable/cluster/Entity.ts +7 -2
- package/src/unstable/cluster/EntityProxy.ts +12 -5
- package/src/unstable/cluster/Sharding.ts +29 -17
- package/src/unstable/eventlog/EventLogEncryption.ts +15 -16
- package/src/unstable/eventlog/EventLogMessage.ts +2 -3
- package/src/unstable/eventlog/EventLogRemote.ts +4 -4
- package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -2
- package/src/unstable/http/HttpServerRequest.ts +8 -3
- package/src/unstable/http/MultipartParser/internal/multipart.ts +19 -6
- package/src/unstable/httpapi/OpenApi.ts +4 -1
- package/src/unstable/rpc/RpcClient.ts +5 -0
- package/src/unstable/sql/SqlResolver.ts +28 -20
- package/src/unstable/workers/Worker.ts +13 -14
package/src/JsonSchema.ts
CHANGED
|
@@ -256,19 +256,6 @@ const DRAFT_07_SINGLE_SUBSCHEMA_KEYWORDS = new Set(["not", "additionalProperties
|
|
|
256
256
|
|
|
257
257
|
const MAP_SUBSCHEMA_KEYWORDS = new Set(["properties", "patternProperties"])
|
|
258
258
|
const ARRAY_SUBSCHEMA_KEYWORDS = new Set(["allOf", "anyOf", "oneOf"])
|
|
259
|
-
const DRAFT_2020_12_MAP_SUBSCHEMA_KEYWORDS = new Set(["$defs", ...MAP_SUBSCHEMA_KEYWORDS, "dependentSchemas"])
|
|
260
|
-
const DRAFT_2020_12_ARRAY_SUBSCHEMA_KEYWORDS = new Set([...ARRAY_SUBSCHEMA_KEYWORDS, "prefixItems"])
|
|
261
|
-
const DRAFT_2020_12_SINGLE_SUBSCHEMA_KEYWORDS = new Set([
|
|
262
|
-
...DRAFT_07_SINGLE_SUBSCHEMA_KEYWORDS,
|
|
263
|
-
"unevaluatedProperties",
|
|
264
|
-
"items",
|
|
265
|
-
"contains",
|
|
266
|
-
"unevaluatedItems",
|
|
267
|
-
"if",
|
|
268
|
-
"then",
|
|
269
|
-
"else",
|
|
270
|
-
"contentSchema"
|
|
271
|
-
])
|
|
272
259
|
|
|
273
260
|
/**
|
|
274
261
|
* Parses a raw Draft-07 JSON Schema into a `Document<"draft-2020-12">`.
|
|
@@ -465,10 +452,7 @@ export function fromSchemaDraft2020_12(js: JsonSchema): Document<"draft-2020-12"
|
|
|
465
452
|
* @since 4.0.0
|
|
466
453
|
*/
|
|
467
454
|
export function fromSchemaOpenApi3_1(js: JsonSchema): Document<"draft-2020-12"> {
|
|
468
|
-
const schema =
|
|
469
|
-
js,
|
|
470
|
-
(schema) => rewriteSchemaRef(schema, (ref) => ref.replace(RE_COMPONENTS_SCHEMAS, "#/$defs"))
|
|
471
|
-
) as JsonSchema
|
|
455
|
+
const schema = rewriteRefs(js, (ref) => ref.replace(RE_COMPONENTS_SCHEMAS, "#/$defs"))
|
|
472
456
|
return fromSchemaDraft2020_12(schema)
|
|
473
457
|
}
|
|
474
458
|
|
|
@@ -828,20 +812,16 @@ export function toMultiDocumentOpenApi3_1(multiDocument: MultiDocument<"draft-20
|
|
|
828
812
|
}
|
|
829
813
|
|
|
830
814
|
function rewrite(schema: JsonSchema): JsonSchema {
|
|
831
|
-
return
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
const key = keyMap.get(unescapeToken(token)) ?? token
|
|
842
|
-
return `#/components/schemas/${key}${rest}`
|
|
843
|
-
})
|
|
844
|
-
) as JsonSchema
|
|
815
|
+
return rewriteRefs(schema, ($ref) => {
|
|
816
|
+
if (!$ref.startsWith("#/$defs/")) return $ref
|
|
817
|
+
|
|
818
|
+
const path = $ref.slice("#/$defs/".length)
|
|
819
|
+
const separatorIndex = path.indexOf("/")
|
|
820
|
+
const token = separatorIndex === -1 ? path : path.slice(0, separatorIndex)
|
|
821
|
+
const rest = separatorIndex === -1 ? "" : path.slice(separatorIndex)
|
|
822
|
+
const key = keyMap.get(unescapeToken(token)) ?? token
|
|
823
|
+
return `#/components/schemas/${key}${rest}`
|
|
824
|
+
})
|
|
845
825
|
}
|
|
846
826
|
|
|
847
827
|
return {
|
|
@@ -874,18 +854,37 @@ function transformSchema(
|
|
|
874
854
|
return walk(node)
|
|
875
855
|
|
|
876
856
|
function walk(node: unknown): unknown {
|
|
877
|
-
if (!Predicate.isObject(node)
|
|
857
|
+
if (!Predicate.isObject(node)) return node
|
|
878
858
|
|
|
879
859
|
const out: Record<string, unknown> = {}
|
|
880
860
|
for (const key of Object.keys(node)) {
|
|
881
861
|
const value = node[key]
|
|
882
862
|
let transformed = value
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
863
|
+
switch (key) {
|
|
864
|
+
case "$defs":
|
|
865
|
+
case "properties":
|
|
866
|
+
case "patternProperties":
|
|
867
|
+
case "dependentSchemas":
|
|
868
|
+
transformed = mapObject(value, walk) ?? value
|
|
869
|
+
break
|
|
870
|
+
case "allOf":
|
|
871
|
+
case "anyOf":
|
|
872
|
+
case "oneOf":
|
|
873
|
+
case "prefixItems":
|
|
874
|
+
transformed = Array.isArray(value) ? value.map(walk) : value
|
|
875
|
+
break
|
|
876
|
+
case "not":
|
|
877
|
+
case "additionalProperties":
|
|
878
|
+
case "propertyNames":
|
|
879
|
+
case "unevaluatedProperties":
|
|
880
|
+
case "items":
|
|
881
|
+
case "contains":
|
|
882
|
+
case "unevaluatedItems":
|
|
883
|
+
case "if":
|
|
884
|
+
case "then":
|
|
885
|
+
case "else":
|
|
886
|
+
case "contentSchema":
|
|
887
|
+
transformed = walk(value)
|
|
889
888
|
}
|
|
890
889
|
InternalRecord.assignProperty(out, key, transformed)
|
|
891
890
|
}
|
|
@@ -893,6 +892,11 @@ function transformSchema(
|
|
|
893
892
|
}
|
|
894
893
|
}
|
|
895
894
|
|
|
895
|
+
/** @internal */
|
|
896
|
+
export function rewriteRefs(schema: JsonSchema, rewrite: ($ref: string) => string): JsonSchema {
|
|
897
|
+
return transformSchema(schema, (schema) => rewriteSchemaRef(schema, rewrite)) as JsonSchema
|
|
898
|
+
}
|
|
899
|
+
|
|
896
900
|
function rewriteSchemaRef(
|
|
897
901
|
schema: Record<string, unknown>,
|
|
898
902
|
rewrite: ($ref: string) => string
|
|
@@ -904,10 +908,7 @@ function rewriteSchemaRef(
|
|
|
904
908
|
}
|
|
905
909
|
|
|
906
910
|
function mapObject(value: unknown, f: (node: unknown) => unknown): Record<string, unknown> | undefined {
|
|
907
|
-
|
|
908
|
-
const out: Record<string, unknown> = {}
|
|
909
|
-
for (const k of Object.keys(value)) InternalRecord.assignProperty(out, k, f(value[k]))
|
|
910
|
-
return out
|
|
911
|
+
return Predicate.isObject(value) ? Rec.map(value, f) : undefined
|
|
911
912
|
}
|
|
912
913
|
|
|
913
914
|
function rewriteSubschemaKeyword(
|
package/src/Schema.ts
CHANGED
|
@@ -63,7 +63,7 @@ import type * as SchemaRepresentation from "./SchemaRepresentation.ts"
|
|
|
63
63
|
import * as SchemaTransformation from "./SchemaTransformation.ts"
|
|
64
64
|
import type { Assign, Lambda, Mutable, Simplify } from "./Struct.ts"
|
|
65
65
|
import * as Struct_ from "./Struct.ts"
|
|
66
|
-
import * as FastCheck from "./testing/FastCheck.ts"
|
|
66
|
+
import type * as FastCheck from "./testing/FastCheck.ts"
|
|
67
67
|
import type { RequiredKeys, UnionToIntersection } from "./Types.ts"
|
|
68
68
|
import type { Unify } from "./Unify.ts"
|
|
69
69
|
|
|
@@ -2476,7 +2476,10 @@ interface optionalLambda extends Lambda {
|
|
|
2476
2476
|
* @category combinators
|
|
2477
2477
|
* @since 3.10.0
|
|
2478
2478
|
*/
|
|
2479
|
-
export const optional = Struct_.lambda<optionalLambda>((self) =>
|
|
2479
|
+
export const optional = Struct_.lambda<optionalLambda>((self) => {
|
|
2480
|
+
const schema = UndefinedOr(self)
|
|
2481
|
+
return make(SchemaAST.optional(self.ast), { schema })
|
|
2482
|
+
})
|
|
2480
2483
|
|
|
2481
2484
|
interface requiredLambda extends Lambda {
|
|
2482
2485
|
<S extends Constraint>(self: optional<S>): S
|
|
@@ -5617,7 +5620,7 @@ export function decodeTo<To extends Constraint, From extends Constraint, RD = ne
|
|
|
5617
5620
|
* ```
|
|
5618
5621
|
*
|
|
5619
5622
|
* @category transforming
|
|
5620
|
-
* @since
|
|
5623
|
+
* @since 4.0.0
|
|
5621
5624
|
*/
|
|
5622
5625
|
export function decode<S extends Constraint, RD = never, RE = never>(transformation: {
|
|
5623
5626
|
readonly decode: SchemaGetter.Getter<S["Type"], S["Type"], RD>
|
|
@@ -5706,7 +5709,7 @@ export function encodeTo<To extends Constraint, From extends Constraint, RD = ne
|
|
|
5706
5709
|
* ```
|
|
5707
5710
|
*
|
|
5708
5711
|
* @category transforming
|
|
5709
|
-
* @since
|
|
5712
|
+
* @since 4.0.0
|
|
5710
5713
|
*/
|
|
5711
5714
|
export function encode<S extends Constraint, RD = never, RE = never>(transformation: {
|
|
5712
5715
|
readonly decode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RD>
|
|
@@ -14957,44 +14960,32 @@ export const TaggedError: {
|
|
|
14957
14960
|
// -----------------------------------------------------------------------------
|
|
14958
14961
|
|
|
14959
14962
|
/**
|
|
14960
|
-
*
|
|
14961
|
-
*
|
|
14962
|
-
*
|
|
14963
|
+
* Represents a function that builds a fast-check `Arbitrary<T>` from the
|
|
14964
|
+
* `fast-check` module.
|
|
14965
|
+
*
|
|
14966
|
+
* **When to use**
|
|
14967
|
+
*
|
|
14968
|
+
* Use as the result type of schema arbitrary derivation.
|
|
14963
14969
|
*
|
|
14964
14970
|
* @category utility types
|
|
14965
14971
|
* @since 4.0.0
|
|
14966
14972
|
*/
|
|
14967
|
-
export type
|
|
14973
|
+
export type Arbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>
|
|
14968
14974
|
|
|
14969
14975
|
/**
|
|
14970
|
-
*
|
|
14971
|
-
*
|
|
14972
|
-
*
|
|
14973
|
-
* **Details**
|
|
14976
|
+
* Returns an {@link Arbitrary} factory derived from a schema. The generated
|
|
14977
|
+
* values satisfy the schema and use its decoded `Type`.
|
|
14974
14978
|
*
|
|
14975
|
-
*
|
|
14976
|
-
* want derivation diagnostics via `{ report: true }`. Unsupported schema
|
|
14977
|
-
* nodes, impossible constraints, invalid candidates, and recursive schemas
|
|
14978
|
-
* without a finite terminal path fail immediately.
|
|
14979
|
+
* **When to use**
|
|
14979
14980
|
*
|
|
14980
|
-
*
|
|
14981
|
-
* @since 4.0.0
|
|
14982
|
-
*/
|
|
14983
|
-
export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<S["Type"]> {
|
|
14984
|
-
const lawc = InternalArbitrary.memoized(schema.ast)
|
|
14985
|
-
return (fc) => lawc(fc, {})
|
|
14986
|
-
}
|
|
14987
|
-
|
|
14988
|
-
/**
|
|
14989
|
-
* Derives a `fast-check` `Arbitrary` from a schema for property-based
|
|
14990
|
-
* testing. The derived arbitrary generates values that satisfy the schema.
|
|
14981
|
+
* Use when you need a fast-check generator for values accepted by a schema.
|
|
14991
14982
|
*
|
|
14992
14983
|
* **Details**
|
|
14993
14984
|
*
|
|
14994
14985
|
* Constraints refine base generators; candidates add weighted sources while
|
|
14995
|
-
* filters still validate every value.
|
|
14996
|
-
*
|
|
14997
|
-
*
|
|
14986
|
+
* filters still validate every value. Recursive schemas use terminal branches
|
|
14987
|
+
* and fail when no finite terminal path exists. The result is memoized so
|
|
14988
|
+
* repeated calls with the same schema are cheap.
|
|
14998
14989
|
*
|
|
14999
14990
|
* **Example** (Generating arbitrary values)
|
|
15000
14991
|
*
|
|
@@ -15002,36 +14993,20 @@ export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<
|
|
|
15002
14993
|
* import { Schema } from "effect"
|
|
15003
14994
|
* import * as FastCheck from "fast-check"
|
|
15004
14995
|
*
|
|
15005
|
-
* const
|
|
14996
|
+
* const makePersonArbitrary = Schema.toArbitrary(
|
|
15006
14997
|
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
15007
14998
|
* )
|
|
15008
14999
|
*
|
|
15009
|
-
*
|
|
15010
|
-
* FastCheck.sample(
|
|
15000
|
+
* const PersonArbitrary = makePersonArbitrary(FastCheck)
|
|
15001
|
+
* FastCheck.sample(PersonArbitrary, 1)
|
|
15011
15002
|
* ```
|
|
15012
15003
|
*
|
|
15013
15004
|
* @category generators
|
|
15014
15005
|
* @since 4.0.0
|
|
15015
15006
|
*/
|
|
15016
|
-
export function toArbitrary<S extends Constraint>(schema: S):
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
options: { readonly report: true }
|
|
15020
|
-
): Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>>
|
|
15021
|
-
export function toArbitrary<S extends Constraint>(
|
|
15022
|
-
schema: S,
|
|
15023
|
-
options?: { readonly report?: boolean }
|
|
15024
|
-
): FastCheck.Arbitrary<S["Type"]> | Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>> {
|
|
15025
|
-
if (options?.report === true) {
|
|
15026
|
-
const lawc = InternalArbitrary.memoized(schema.ast)
|
|
15027
|
-
const report = InternalArbitrary.makeReport()
|
|
15028
|
-
InternalArbitrary.collectReport(schema.ast, report)
|
|
15029
|
-
return {
|
|
15030
|
-
value: lawc(FastCheck, {}),
|
|
15031
|
-
report: InternalArbitrary.toReport(report)
|
|
15032
|
-
}
|
|
15033
|
-
}
|
|
15034
|
-
return toArbitraryLazy(schema)(FastCheck)
|
|
15007
|
+
export function toArbitrary<S extends Constraint>(schema: S): Arbitrary<S["Type"]> {
|
|
15008
|
+
const lawc = InternalArbitrary.memoized(schema.ast)
|
|
15009
|
+
return (fc) => lawc(fc, {})
|
|
15035
15010
|
}
|
|
15036
15011
|
|
|
15037
15012
|
// -----------------------------------------------------------------------------
|
|
@@ -15367,7 +15342,10 @@ export function toJsonSchemaDocument(
|
|
|
15367
15342
|
schema: Constraint,
|
|
15368
15343
|
options?: ToJsonSchemaOptions
|
|
15369
15344
|
): JsonSchema.Document<"draft-2020-12"> {
|
|
15370
|
-
const document = InternalToRepresentation.toRepresentation(
|
|
15345
|
+
const document = InternalToRepresentation.toRepresentation(
|
|
15346
|
+
toCodecJsonAST(schema.ast),
|
|
15347
|
+
InternalToJsonSchemaDocument.toRepresentationOptions
|
|
15348
|
+
)
|
|
15371
15349
|
return InternalToJsonSchemaDocument.toJsonSchemaDocument(document, options)
|
|
15372
15350
|
}
|
|
15373
15351
|
|
|
@@ -15422,16 +15400,14 @@ export function toCodecJson<S extends Constraint>(schema: S): toCodecJson<S> {
|
|
|
15422
15400
|
return make(toCodecJsonAST(schema.ast), { schema })
|
|
15423
15401
|
}
|
|
15424
15402
|
|
|
15425
|
-
|
|
15426
|
-
|
|
15403
|
+
/** @internal */
|
|
15404
|
+
export const toCodecJsonAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
15405
|
+
const out = toCodecJsonASTStep(ast, toCodecJsonAST)
|
|
15427
15406
|
const context = ast.context
|
|
15428
15407
|
if (out === ast || context === undefined) return out
|
|
15429
15408
|
return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(context))
|
|
15430
15409
|
})
|
|
15431
15410
|
|
|
15432
|
-
/** @internal */
|
|
15433
|
-
export const toCodecJsonAST = memoize(toCodecJsonASTBase)
|
|
15434
|
-
|
|
15435
15411
|
function withoutConstructorDefault(context: SchemaAST.Context): SchemaAST.Context {
|
|
15436
15412
|
return context.constructorDefault === undefined ?
|
|
15437
15413
|
context :
|
|
@@ -15482,7 +15458,7 @@ const toCodecJsonReorder = makeReorder((ast: SchemaAST.AST) => {
|
|
|
15482
15458
|
}
|
|
15483
15459
|
})
|
|
15484
15460
|
|
|
15485
|
-
function
|
|
15461
|
+
function toCodecJsonASTStep(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
15486
15462
|
switch (ast._tag) {
|
|
15487
15463
|
case "Declaration": {
|
|
15488
15464
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
@@ -15541,17 +15517,17 @@ function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Sche
|
|
|
15541
15517
|
* @since 4.0.0
|
|
15542
15518
|
*/
|
|
15543
15519
|
export function toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]> {
|
|
15544
|
-
return make(
|
|
15520
|
+
return make(toCodecIsoAST(SchemaAST.toType(schema.ast)))
|
|
15545
15521
|
}
|
|
15546
15522
|
|
|
15547
|
-
const
|
|
15548
|
-
const out =
|
|
15523
|
+
const toCodecIsoAST = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
|
|
15524
|
+
const out = toCodecIsoASTStep(ast, toCodecIsoAST)
|
|
15549
15525
|
return out !== ast && ast.context !== undefined ?
|
|
15550
15526
|
SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context)) :
|
|
15551
15527
|
out
|
|
15552
15528
|
})
|
|
15553
15529
|
|
|
15554
|
-
function
|
|
15530
|
+
function toCodecIsoASTStep(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
15555
15531
|
switch (ast._tag) {
|
|
15556
15532
|
case "Declaration": {
|
|
15557
15533
|
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
|
|
@@ -15621,7 +15597,7 @@ export interface toCodecStringTree<S extends Constraint> extends
|
|
|
15621
15597
|
* @since 4.0.0
|
|
15622
15598
|
*/
|
|
15623
15599
|
export function toCodecStringTree<S extends Constraint>(schema: S): toCodecStringTree<S> {
|
|
15624
|
-
return make(
|
|
15600
|
+
return make(toCodecStringTreeAST(schema.ast), { schema })
|
|
15625
15601
|
}
|
|
15626
15602
|
|
|
15627
15603
|
/**
|
|
@@ -15670,7 +15646,7 @@ export interface toCodecArrayFromSingle<S extends Constraint> extends
|
|
|
15670
15646
|
* @since 4.0.0
|
|
15671
15647
|
*/
|
|
15672
15648
|
export function toCodecArrayFromSingle<S extends Constraint>(schema: S): toCodecArrayFromSingle<S> {
|
|
15673
|
-
return make(
|
|
15649
|
+
return make(toCodecArrayFromSingleAST(schema.ast))
|
|
15674
15650
|
}
|
|
15675
15651
|
|
|
15676
15652
|
type XmlEncoderOptions = {
|
|
@@ -15807,7 +15783,7 @@ const toStringTreeReorder = makeReorder((ast: SchemaAST.AST) => {
|
|
|
15807
15783
|
}
|
|
15808
15784
|
})
|
|
15809
15785
|
|
|
15810
|
-
function
|
|
15786
|
+
function toCodecStringTreeASTStep(
|
|
15811
15787
|
ast: SchemaAST.AST,
|
|
15812
15788
|
recur: (ast: SchemaAST.AST) => SchemaAST.AST,
|
|
15813
15789
|
onMissingAnnotation: (ast: SchemaAST.AST) => SchemaAST.AST
|
|
@@ -15886,37 +15862,29 @@ const booleanToString = new SchemaAST.Link(
|
|
|
15886
15862
|
)
|
|
15887
15863
|
)
|
|
15888
15864
|
|
|
15889
|
-
const
|
|
15865
|
+
const arrayFromSingleTransformation = new SchemaTransformation.Transformation(
|
|
15866
|
+
SchemaGetter.transform((input: ReadonlyArray<unknown> | string) => typeof input === "string" ? [input] : input),
|
|
15867
|
+
SchemaGetter.passthrough()
|
|
15868
|
+
)
|
|
15890
15869
|
|
|
15891
|
-
const
|
|
15892
|
-
|
|
15870
|
+
const isCodecArrayFromSingleLink = (link: SchemaAST.Link): boolean =>
|
|
15871
|
+
link.transformation === arrayFromSingleTransformation
|
|
15893
15872
|
|
|
15894
|
-
const
|
|
15895
|
-
|
|
15896
|
-
return ast
|
|
15897
|
-
}
|
|
15898
|
-
const out = serializerTree(ast, serializerStringTree, (ast) => {
|
|
15873
|
+
const toCodecStringTreeAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
15874
|
+
const out = toCodecStringTreeASTStep(ast, toCodecStringTreeAST, (ast) => {
|
|
15899
15875
|
throw new globalThis.Error("Missing structural codec for StringTree", { cause: ast })
|
|
15900
15876
|
})
|
|
15901
15877
|
if (out !== ast && ast.context !== undefined) {
|
|
15902
15878
|
return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context))
|
|
15903
15879
|
}
|
|
15904
15880
|
return out
|
|
15905
|
-
})
|
|
15881
|
+
}, { stopAt: isCodecArrayFromSingleLink })
|
|
15906
15882
|
|
|
15907
15883
|
const toArrayFromSingleInputElement = (ast: SchemaAST.AST): SchemaAST.AST =>
|
|
15908
15884
|
SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown
|
|
15909
15885
|
|
|
15910
|
-
const
|
|
15911
|
-
|
|
15912
|
-
SchemaGetter.passthrough()
|
|
15913
|
-
)
|
|
15914
|
-
|
|
15915
|
-
const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
|
|
15916
|
-
if (isSerializerArrayFromSingle(ast)) {
|
|
15917
|
-
return ast
|
|
15918
|
-
}
|
|
15919
|
-
const out = onSerializerArrayFromSingle(ast)
|
|
15886
|
+
const toCodecArrayFromSingleAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
15887
|
+
const out = toCodecArrayFromSingleASTStep(ast)
|
|
15920
15888
|
if (SchemaAST.isArrays(out)) {
|
|
15921
15889
|
const ensure = SchemaAST.decodeTo(
|
|
15922
15890
|
new SchemaAST.Union(
|
|
@@ -15928,8 +15896,7 @@ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast)
|
|
|
15928
15896
|
),
|
|
15929
15897
|
SchemaAST.string
|
|
15930
15898
|
],
|
|
15931
|
-
"anyOf"
|
|
15932
|
-
{ [SERIALIZER_ENSURE_ARRAY]: true }
|
|
15899
|
+
"anyOf"
|
|
15933
15900
|
),
|
|
15934
15901
|
out,
|
|
15935
15902
|
arrayFromSingleTransformation
|
|
@@ -15937,12 +15904,12 @@ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast)
|
|
|
15937
15904
|
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure
|
|
15938
15905
|
}
|
|
15939
15906
|
return out
|
|
15940
|
-
})
|
|
15907
|
+
}, { stopAt: isCodecArrayFromSingleLink })
|
|
15941
15908
|
|
|
15942
|
-
function
|
|
15909
|
+
function toCodecArrayFromSingleASTStep(ast: SchemaAST.AST): SchemaAST.AST {
|
|
15943
15910
|
return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" ||
|
|
15944
15911
|
ast._tag === "Suspend"
|
|
15945
|
-
? ast.recur(
|
|
15912
|
+
? ast.recur(toCodecArrayFromSingleAST)
|
|
15946
15913
|
: ast
|
|
15947
15914
|
}
|
|
15948
15915
|
|
|
@@ -16768,6 +16735,15 @@ export declare namespace Annotations {
|
|
|
16768
16735
|
readonly representation?:
|
|
16769
16736
|
| SchemaRepresentation.CheckRepresentationAnnotation<SchemaAST.AST>
|
|
16770
16737
|
| undefined
|
|
16738
|
+
/**
|
|
16739
|
+
* Compiles this filter to a JSON Schema fragment.
|
|
16740
|
+
*
|
|
16741
|
+
* **Gotchas**
|
|
16742
|
+
*
|
|
16743
|
+
* Treat the input schemas as immutable. The returned value must be a valid JSON Schema object graph and must not be
|
|
16744
|
+
* mutated after this function returns. Return a new object graph to produce different output during a later
|
|
16745
|
+
* compilation.
|
|
16746
|
+
*/
|
|
16771
16747
|
readonly toJsonSchema?: SchemaRepresentation.ToJsonSchema.Check | undefined
|
|
16772
16748
|
readonly toCode?: SchemaRepresentation.Generation.Check | undefined
|
|
16773
16749
|
/**
|
|
@@ -16818,8 +16794,7 @@ export declare namespace Annotations {
|
|
|
16818
16794
|
|
|
16819
16795
|
/**
|
|
16820
16796
|
* Types used by arbitrary-derivation annotations to configure `toArbitrary`
|
|
16821
|
-
* hooks, filter hints, candidate sources,
|
|
16822
|
-
* constraints.
|
|
16797
|
+
* hooks, filter hints, candidate sources, and merged generation constraints.
|
|
16823
16798
|
*
|
|
16824
16799
|
* @since 4.0.0
|
|
16825
16800
|
*/
|
|
@@ -16832,8 +16807,7 @@ export declare namespace Annotations {
|
|
|
16832
16807
|
* `constraint` refines the schema node's base generator. `candidate` adds a
|
|
16833
16808
|
* weighted source before all filters run. If neither hint is provided, the
|
|
16834
16809
|
* filter does not guide generation; generated values are still checked by
|
|
16835
|
-
* the filter predicate.
|
|
16836
|
-
* `OpaqueFilter`.
|
|
16810
|
+
* the filter predicate.
|
|
16837
16811
|
*
|
|
16838
16812
|
* @category models
|
|
16839
16813
|
* @since 4.0.0
|
|
@@ -17021,58 +16995,6 @@ export declare namespace Annotations {
|
|
|
17021
16995
|
typeParameters: { readonly [K in keyof TypeParameters]: TypeParameter<TypeParameters[K]["Type"]> }
|
|
17022
16996
|
): (fc: typeof FastCheck, context: Context) => Output<T>
|
|
17023
16997
|
}
|
|
17024
|
-
|
|
17025
|
-
/**
|
|
17026
|
-
* Wraps a derived value together with arbitrary-derivation diagnostics.
|
|
17027
|
-
*
|
|
17028
|
-
* @category models
|
|
17029
|
-
* @since 4.0.0
|
|
17030
|
-
*/
|
|
17031
|
-
export interface WithReport<A> {
|
|
17032
|
-
readonly value: A
|
|
17033
|
-
readonly report: Report
|
|
17034
|
-
}
|
|
17035
|
-
|
|
17036
|
-
/**
|
|
17037
|
-
* Diagnostics collected while deriving an arbitrary.
|
|
17038
|
-
*
|
|
17039
|
-
* **Details**
|
|
17040
|
-
*
|
|
17041
|
-
* Reports contain warnings only. Unsupported schema nodes, impossible
|
|
17042
|
-
* constraints, invalid candidate weights, and throwing candidate factories
|
|
17043
|
-
* fail immediately.
|
|
17044
|
-
*
|
|
17045
|
-
* @category models
|
|
17046
|
-
* @since 4.0.0
|
|
17047
|
-
*/
|
|
17048
|
-
export interface Report {
|
|
17049
|
-
readonly warnings: ReadonlyArray<Warning>
|
|
17050
|
-
}
|
|
17051
|
-
|
|
17052
|
-
/**
|
|
17053
|
-
* Non-fatal arbitrary-derivation warning.
|
|
17054
|
-
*
|
|
17055
|
-
* @category models
|
|
17056
|
-
* @since 4.0.0
|
|
17057
|
-
*/
|
|
17058
|
-
export type Warning = OpaqueFilterWarning
|
|
17059
|
-
|
|
17060
|
-
/**
|
|
17061
|
-
* Warning emitted when a filter is handled only by the final `.filter`.
|
|
17062
|
-
*
|
|
17063
|
-
* **Details**
|
|
17064
|
-
*
|
|
17065
|
-
* The filter is still enforced. The warning means it did not contribute
|
|
17066
|
-
* a constraint or candidate, so generation may rely on fast-check discards.
|
|
17067
|
-
*
|
|
17068
|
-
* @category models
|
|
17069
|
-
* @since 4.0.0
|
|
17070
|
-
*/
|
|
17071
|
-
export interface OpaqueFilterWarning {
|
|
17072
|
-
readonly _tag: "OpaqueFilter"
|
|
17073
|
-
readonly path: ReadonlyArray<PropertyKey>
|
|
17074
|
-
readonly description?: string | undefined
|
|
17075
|
-
}
|
|
17076
16998
|
}
|
|
17077
16999
|
|
|
17078
17000
|
/**
|