@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.17
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/lib/_bundle/aws.js +2 -0
- package/lib/_bundle/aws.js.map +1 -0
- package/lib/_bundle/base.js +5 -0
- package/lib/_bundle/base.js.map +1 -0
- package/lib/_bundle/graphql.js +3 -0
- package/lib/_bundle/graphql.js.map +1 -0
- package/lib/_bundle/rest.js +2 -0
- package/lib/_bundle/rest.js.map +1 -0
- package/lib/_bundle/xml.js +4 -0
- package/lib/_bundle/xml.js.map +1 -0
- package/lib/api.d.ts +118 -13
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -188
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -278
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +1 -0
- package/lib/codegen/boolean-string-enums.js +36 -36
- package/lib/codegen/chunk.d.ts +7 -0
- package/lib/codegen/chunk.d.ts.map +1 -0
- package/lib/codegen/chunk.js +139 -0
- package/lib/codegen/chunk.js.map +1 -0
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +28 -14
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/datafy.d.ts +14 -0
- package/lib/codegen/datafy.d.ts.map +1 -0
- package/lib/codegen/datafy.js +853 -0
- package/lib/codegen/datafy.js.map +1 -0
- package/lib/codegen/dedupe.d.ts +5 -0
- package/lib/codegen/dedupe.d.ts.map +1 -0
- package/lib/codegen/dedupe.js +153 -0
- package/lib/codegen/dedupe.js.map +1 -0
- package/lib/codegen/emit.js +56 -56
- package/lib/codegen/format.js +18 -18
- package/lib/codegen/generated-at.js +29 -29
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +92 -84
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graph.js +36 -36
- package/lib/codegen/graphql-client.d.ts +2 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +55 -26
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql.js +113 -113
- package/lib/codegen/latin1.d.ts +3 -0
- package/lib/codegen/latin1.d.ts.map +1 -0
- package/lib/codegen/latin1.js +126 -0
- package/lib/codegen/latin1.js.map +1 -0
- package/lib/codegen/members.d.ts +7 -0
- package/lib/codegen/members.d.ts.map +1 -1
- package/lib/codegen/members.js +26 -19
- package/lib/codegen/members.js.map +1 -1
- package/lib/codegen/model-diff.js +6 -6
- package/lib/codegen/naming.js +19 -19
- package/lib/codegen/openapi-cli.js +15 -15
- package/lib/codegen/openapi.d.ts +17 -0
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +323 -169
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.js +14 -14
- package/lib/codegen/pagination.js +11 -11
- package/lib/codegen/patch-audit.js +57 -57
- package/lib/codegen/patches.js +79 -79
- package/lib/codegen/prelude.js +19 -19
- package/lib/codegen/privatize.d.ts +21 -0
- package/lib/codegen/privatize.d.ts.map +1 -0
- package/lib/codegen/privatize.js +176 -0
- package/lib/codegen/privatize.js.map +1 -0
- package/lib/codegen/proto.js +25 -25
- package/lib/codegen/pure.d.ts +6 -0
- package/lib/codegen/pure.d.ts.map +1 -0
- package/lib/codegen/pure.js +91 -0
- package/lib/codegen/pure.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +108 -108
- package/lib/codegen/spec-path.js +57 -57
- package/lib/codegen/table.d.ts +5 -0
- package/lib/codegen/table.d.ts.map +1 -0
- package/lib/codegen/table.js +249 -0
- package/lib/codegen/table.js.map +1 -0
- package/lib/config.d.ts +27 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +1 -0
- package/lib/crypto.d.ts +76 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +1 -0
- package/lib/debug.d.ts +2 -0
- package/lib/debug.d.ts.map +1 -0
- package/lib/debug.js +1 -0
- package/lib/error-category.d.ts +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -46
- package/lib/errors.d.ts +62 -62
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -195
- package/lib/graphql.d.ts +31 -20
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +1 -1027
- package/lib/graphql.types.js +1 -5
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -15
- package/lib/json-patch.d.ts +2 -2
- package/lib/json-patch.js +1 -226
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.d.ts +9 -25
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -266
- package/lib/plain-values.d.ts +10 -0
- package/lib/plain-values.d.ts.map +1 -0
- package/lib/plain-values.js +2 -0
- package/lib/plain-values.js.map +1 -0
- package/lib/protocol-http.d.ts +50 -14
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -639
- package/lib/protocol-rest.d.ts +38 -25
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -267
- package/lib/query.js +1 -27
- package/lib/response-validation-strict.d.ts +48 -0
- package/lib/response-validation-strict.d.ts.map +1 -0
- package/lib/response-validation-strict.js +1 -0
- package/lib/response-validation.d.ts +43 -25
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +1 -76
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.js +1 -112
- package/lib/retry.d.ts +48 -29
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -209
- package/lib/schema-lite-impl.d.ts +158 -0
- package/lib/schema-lite-impl.d.ts.map +1 -0
- package/lib/schema-lite-impl.js +1 -0
- package/lib/schema-lite-typed.d.ts +41 -0
- package/lib/schema-lite-typed.d.ts.map +1 -0
- package/lib/schema-lite-typed.js +2 -0
- package/lib/schema-lite-typed.js.map +1 -0
- package/lib/schema-lite.d.ts +40 -0
- package/lib/schema-lite.d.ts.map +1 -0
- package/lib/schema-lite.js +1 -0
- package/lib/schema.d.ts +20 -6
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/testing.d.ts +3 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -40
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts +13 -13
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -131
- package/lib/xml.d.ts +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +1 -311
- package/package.json +9 -7
- package/src/api.ts +1080 -180
- package/src/category.ts +33 -33
- package/src/chunks.ts +30 -0
- package/src/codegen/chunk.ts +147 -0
- package/src/codegen/cli.ts +27 -1
- package/src/codegen/datafy.ts +874 -0
- package/src/codegen/dedupe.ts +173 -0
- package/src/codegen/generator.ts +10 -3
- package/src/codegen/graphql-client.ts +49 -15
- package/src/codegen/latin1.ts +131 -0
- package/src/codegen/members.ts +8 -0
- package/src/codegen/openapi.ts +194 -3
- package/src/codegen/privatize.ts +200 -0
- package/src/codegen/pure.ts +94 -0
- package/src/codegen/table.ts +254 -0
- package/src/config.ts +216 -0
- package/src/crypto.ts +202 -0
- package/src/debug.ts +8 -0
- package/src/error-category.ts +2 -1
- package/src/errors.ts +65 -56
- package/src/graphql.ts +109 -62
- package/src/graphql.types.ts +9 -7
- package/src/index.ts +3 -2
- package/src/json-patch.ts +2 -2
- package/src/pagination.ts +37 -18
- package/src/plain-values.ts +41 -0
- package/src/protocol-http.ts +378 -145
- package/src/protocol-rest.ts +337 -169
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +101 -50
- package/src/retry-after.ts +3 -3
- package/src/retry.ts +94 -93
- package/src/schema-lite-impl.ts +550 -0
- package/src/schema-lite-typed.ts +44 -0
- package/src/schema-lite.ts +44 -0
- package/src/schema.ts +258 -14
- package/src/testing.ts +4 -2
- package/src/trait.ts +36 -28
- package/src/xml.ts +31 -17
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
- package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.test.js +0 -275
- package/lib/codegen/boolean-string-enums.test.js.map +0 -1
- package/lib/codegen/defer-naming.test.d.ts +0 -2
- package/lib/codegen/defer-naming.test.d.ts.map +0 -1
- package/lib/codegen/defer-naming.test.js +0 -105
- package/lib/codegen/defer-naming.test.js.map +0 -1
- package/lib/codegen/generated-at.test.d.ts +0 -2
- package/lib/codegen/generated-at.test.d.ts.map +0 -1
- package/lib/codegen/generated-at.test.js +0 -81
- package/lib/codegen/generated-at.test.js.map +0 -1
- package/lib/codegen/generator.test.d.ts +0 -2
- package/lib/codegen/generator.test.d.ts.map +0 -1
- package/lib/codegen/generator.test.js +0 -121
- package/lib/codegen/generator.test.js.map +0 -1
- package/lib/codegen/graphql-client.test.d.ts +0 -2
- package/lib/codegen/graphql-client.test.d.ts.map +0 -1
- package/lib/codegen/graphql-client.test.js +0 -171
- package/lib/codegen/graphql-client.test.js.map +0 -1
- package/lib/codegen/openapi-binary.test.d.ts +0 -2
- package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
- package/lib/codegen/openapi-binary.test.js +0 -67
- package/lib/codegen/openapi-binary.test.js.map +0 -1
- package/lib/codegen/patch-audit.test.d.ts +0 -2
- package/lib/codegen/patch-audit.test.d.ts.map +0 -1
- package/lib/codegen/patch-audit.test.js +0 -141
- package/lib/codegen/patch-audit.test.js.map +0 -1
- package/lib/codegen/patches.test.d.ts +0 -2
- package/lib/codegen/patches.test.d.ts.map +0 -1
- package/lib/codegen/patches.test.js +0 -155
- package/lib/codegen/patches.test.js.map +0 -1
- package/lib/codegen/protocol-imports.test.d.ts +0 -2
- package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
- package/lib/codegen/protocol-imports.test.js +0 -36
- package/lib/codegen/protocol-imports.test.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.test.js +0 -451
- package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
- package/lib/codegen/untagged-unions.test.d.ts +0 -2
- package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
- package/lib/codegen/untagged-unions.test.js +0 -80
- package/lib/codegen/untagged-unions.test.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/fixtures/xml/upstream-validator.json +0 -397
- package/lib/graphql.js.map +0 -1
- package/lib/graphql.test.d.ts +0 -2
- package/lib/graphql.test.d.ts.map +0 -1
- package/lib/graphql.test.js +0 -151
- package/lib/graphql.test.js.map +0 -1
- package/lib/graphql.types.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/json-patch.test.d.ts +0 -2
- package/lib/json-patch.test.d.ts.map +0 -1
- package/lib/json-patch.test.js +0 -65
- package/lib/json-patch.test.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/pagination.test.d.ts +0 -2
- package/lib/pagination.test.d.ts.map +0 -1
- package/lib/pagination.test.js +0 -131
- package/lib/pagination.test.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-http.test.d.ts +0 -2
- package/lib/protocol-http.test.d.ts.map +0 -1
- package/lib/protocol-http.test.js +0 -228
- package/lib/protocol-http.test.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/protocol-rest.test.d.ts +0 -2
- package/lib/protocol-rest.test.d.ts.map +0 -1
- package/lib/protocol-rest.test.js +0 -498
- package/lib/protocol-rest.test.js.map +0 -1
- package/lib/query.js.map +0 -1
- package/lib/response-validation.js.map +0 -1
- package/lib/response-validation.test.d.ts +0 -2
- package/lib/response-validation.test.d.ts.map +0 -1
- package/lib/response-validation.test.js +0 -72
- package/lib/response-validation.test.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry-after.test.d.ts +0 -2
- package/lib/retry-after.test.d.ts.map +0 -1
- package/lib/retry-after.test.js +0 -204
- package/lib/retry-after.test.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/retry.test.d.ts +0 -2
- package/lib/retry.test.d.ts.map +0 -1
- package/lib/retry.test.js +0 -407
- package/lib/retry.test.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/sdks.test.d.ts +0 -2
- package/lib/sdks.test.d.ts.map +0 -1
- package/lib/sdks.test.js +0 -76
- package/lib/sdks.test.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/lib/xml.js.map +0 -1
- package/lib/xml.test.d.ts +0 -2
- package/lib/xml.test.d.ts.map +0 -1
- package/lib/xml.test.js +0 -210
- package/lib/xml.test.js.map +0 -1
- package/src/codegen/boolean-string-enums.test.ts +0 -299
- package/src/codegen/defer-naming.test.ts +0 -113
- package/src/codegen/generated-at.test.ts +0 -89
- package/src/codegen/generator.test.ts +0 -137
- package/src/codegen/graphql-client.test.ts +0 -189
- package/src/codegen/openapi-binary.test.ts +0 -91
- package/src/codegen/patch-audit.test.ts +0 -160
- package/src/codegen/patches.test.ts +0 -188
- package/src/codegen/protocol-imports.test.ts +0 -39
- package/src/codegen/rewrite-operation-ids.test.ts +0 -472
- package/src/codegen/untagged-unions.test.ts +0 -85
- package/src/fixtures/xml/upstream-validator.json +0 -397
- package/src/graphql.test.ts +0 -198
- package/src/json-patch.test.ts +0 -77
- package/src/pagination.test.ts +0 -169
- package/src/protocol-http.test.ts +0 -276
- package/src/protocol-rest.test.ts +0 -703
- package/src/response-validation.test.ts +0 -89
- package/src/retry-after.test.ts +0 -267
- package/src/retry.test.ts +0 -566
- package/src/sdks.test.ts +0 -87
- package/src/xml.test.ts +0 -251
package/src/schema.ts
CHANGED
|
@@ -5,32 +5,39 @@
|
|
|
5
5
|
* provider package via `@distilled.cloud/core/schema`. Do not copy it into
|
|
6
6
|
* individual packages.
|
|
7
7
|
*
|
|
8
|
-
* Every real TYPE (`Schema`, `Codec`, `Top`,
|
|
8
|
+
* Every real TYPE (`Schema`, `Codec`, `Top`, ...) is re-exported untouched, so
|
|
9
9
|
* the `Schema.Schema<Foo>` annotations on generated consts (and the public
|
|
10
10
|
* `.d.ts`) stay precise. The schema *construction surface* (`Struct`,
|
|
11
|
-
* `optional`, `suspend`,
|
|
11
|
+
* `optional`, `suspend`, ...) and the leaf scalar schemas are retyped to `any`,
|
|
12
12
|
* so the compiler instantiates none of the heavy Schema generics while
|
|
13
|
-
* building a service file
|
|
13
|
+
* building a service file -- the explicit annotations carry the real types.
|
|
14
14
|
*
|
|
15
15
|
* Overriding a *value* export never affects the same-named *type* export (they
|
|
16
16
|
* live in separate namespaces and continue to flow through `export *`), so
|
|
17
17
|
* `Schema.Literal<"x">`-style type usages remain precise.
|
|
18
18
|
*
|
|
19
|
-
* Runtime behaviour is identical
|
|
20
|
-
* runtime value from `effect/Schema
|
|
19
|
+
* Runtime behaviour is identical. Every override aliases the exact same
|
|
20
|
+
* runtime value from `effect/Schema`, except `suspend`, `Array` and
|
|
21
|
+
* `Record`, which build the same schema lazily (see "Lazy schemas").
|
|
21
22
|
*/
|
|
22
|
-
export
|
|
23
|
+
// Types only: a value `export *` costs one binding per Effect Schema export
|
|
24
|
+
// (345 of them, ~70 KB) in every process that imports an SDK. The values
|
|
25
|
+
// generated and hand-written code use are re-exported explicitly below.
|
|
26
|
+
export type * from "effect/Schema";
|
|
27
|
+
export { declare, Duration, instanceOf, Redacted } from "effect/Schema";
|
|
23
28
|
|
|
29
|
+
import { pipeArguments } from "effect/Pipeable";
|
|
24
30
|
import * as S from "effect/Schema";
|
|
25
31
|
|
|
26
32
|
export type AnyFn = (...args: any[]) => any;
|
|
27
33
|
|
|
28
|
-
// Construction surface
|
|
34
|
+
// Construction surface -- collapse to `any` so generics are never instantiated.
|
|
29
35
|
export const optional: AnyFn = S.optional as AnyFn;
|
|
30
36
|
export const Struct: AnyFn = S.Struct as AnyFn;
|
|
31
|
-
export const
|
|
32
|
-
export const
|
|
33
|
-
export const
|
|
37
|
+
export const StructWithRest: AnyFn = S.StructWithRest as AnyFn;
|
|
38
|
+
export const suspend: AnyFn = (f: () => S.Top) => lazySuspend(f);
|
|
39
|
+
export const Array: AnyFn = (item: S.Top) => lazyArray(item);
|
|
40
|
+
export const Record: AnyFn = (key: S.Top, value: S.Top) => lazyRecord(key, value);
|
|
34
41
|
export const Union: AnyFn = S.Union as AnyFn;
|
|
35
42
|
export const Literal: AnyFn = S.Literal as AnyFn;
|
|
36
43
|
export const Literals: AnyFn = S.Literals as AnyFn;
|
|
@@ -38,7 +45,7 @@ export const NullOr: AnyFn = S.NullOr as AnyFn;
|
|
|
38
45
|
export const Tuple: AnyFn = S.Tuple as AnyFn;
|
|
39
46
|
export const encodeKeys: AnyFn = S.encodeKeys as AnyFn;
|
|
40
47
|
|
|
41
|
-
// Leaf schemas
|
|
48
|
+
// Leaf schemas -- collapse to `any` so `.pipe(...)` on them is free.
|
|
42
49
|
export const String: any = S.String;
|
|
43
50
|
export const Number: any = S.Number;
|
|
44
51
|
export const Boolean: any = S.Boolean;
|
|
@@ -48,6 +55,243 @@ export const Null: any = S.Null;
|
|
|
48
55
|
export const Void: any = S.Void;
|
|
49
56
|
export const Any: any = S.Any;
|
|
50
57
|
|
|
51
|
-
// NOTE: `Schema` / `Codec` (types)
|
|
52
|
-
//
|
|
53
|
-
//
|
|
58
|
+
// NOTE: `Schema` / `Codec` (types) are intentionally NOT overridden -- they
|
|
59
|
+
// flow through `export *` with real types so cast targets stay precise.
|
|
60
|
+
// `TaggedError` is overridden with the same type (see "Lazy error classes").
|
|
61
|
+
|
|
62
|
+
//#region Lazy schemas
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Schemas whose real Effect schema is built on first use instead of at
|
|
66
|
+
* import.
|
|
67
|
+
*
|
|
68
|
+
* A service module declares every schema as a top-level const, and
|
|
69
|
+
* importing it constructs all of them: EC2 has 2,575 `S.suspend(...)` and
|
|
70
|
+
* 784 `S.Array(...)` consts, Elasticsearch 3,272 and 2,265. An Effect schema
|
|
71
|
+
* is a function object plus an AST node (a `suspend` also a wrapper
|
|
72
|
+
* closure), and `.annotate` copies both: about 550 bytes per suspend, more
|
|
73
|
+
* for an array whose item it forces. A lazy schema is one small object
|
|
74
|
+
* holding how to build the real one and any annotations added before then:
|
|
75
|
+
* about 180 bytes.
|
|
76
|
+
*
|
|
77
|
+
* It inherits Effect's own schema prototype, so `pipe`, `annotate`, `make`,
|
|
78
|
+
* `isSchema` and every combinator see a schema. On first use of `.ast` (or
|
|
79
|
+
* of an own member such as an array's `value`) it builds the real schema --
|
|
80
|
+
* `build().annotate(annotations)`, exactly what eager code would have made --
|
|
81
|
+
* and copies the real schema's own properties onto itself, so from then on
|
|
82
|
+
* it IS that schema: same AST (memoized, stable identity), same rebuild
|
|
83
|
+
* options for later `.annotate` / `.check` calls.
|
|
84
|
+
*/
|
|
85
|
+
const SchemaProto: object = /*@__PURE__*/ Object.getPrototypeOf(S.String);
|
|
86
|
+
const buildKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/build");
|
|
87
|
+
const annotationsKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/annotations");
|
|
88
|
+
|
|
89
|
+
type Annotations = Record<string, unknown>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* How a lazy schema builds itself: a closure, or a shared builder plus data
|
|
93
|
+
* stored on the schema object (no closure per schema; see packed.ts).
|
|
94
|
+
*/
|
|
95
|
+
export interface LazyBuilder {
|
|
96
|
+
readonly build: (data: unknown) => S.Top;
|
|
97
|
+
}
|
|
98
|
+
const dataKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/data");
|
|
99
|
+
|
|
100
|
+
interface LazySchema {
|
|
101
|
+
[buildKey]?: (() => S.Top) | LazyBuilder;
|
|
102
|
+
[dataKey]?: unknown;
|
|
103
|
+
[annotationsKey]?: Annotations;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Build the real schema and become it. */
|
|
107
|
+
const force = (self: LazySchema): void => {
|
|
108
|
+
const build = self[buildKey];
|
|
109
|
+
if (!build) return;
|
|
110
|
+
const annotations = self[annotationsKey];
|
|
111
|
+
const built = typeof build === "function" ? build() : build.build(self[dataKey]);
|
|
112
|
+
const real = annotations ? built.annotate(annotations) : built;
|
|
113
|
+
delete self[buildKey];
|
|
114
|
+
delete self[dataKey];
|
|
115
|
+
delete self[annotationsKey];
|
|
116
|
+
Object.defineProperties(self, Object.getOwnPropertyDescriptors(real));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Members a built schema carries as own properties (array item, record key/value). */
|
|
120
|
+
const forwarded = (name: string): PropertyDescriptor => ({
|
|
121
|
+
configurable: true,
|
|
122
|
+
get(this: LazySchema & Record<string, unknown>) {
|
|
123
|
+
if (!this[buildKey]) return undefined;
|
|
124
|
+
force(this);
|
|
125
|
+
return this[name];
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const LazyProto: object = /*@__PURE__*/ Object.create(SchemaProto, {
|
|
130
|
+
ast: /*@__PURE__*/ forwarded("ast"),
|
|
131
|
+
value: /*@__PURE__*/ forwarded("value"),
|
|
132
|
+
key: /*@__PURE__*/ forwarded("key"),
|
|
133
|
+
annotate: {
|
|
134
|
+
configurable: true,
|
|
135
|
+
writable: true,
|
|
136
|
+
value(this: LazySchema, annotations: Annotations) {
|
|
137
|
+
const build = this[buildKey];
|
|
138
|
+
// Once built, annotate like any schema (a rebuilt copy).
|
|
139
|
+
if (!build) return (SchemaProto as { annotate: Function }).annotate.call(this, annotations);
|
|
140
|
+
const previous = this[annotationsKey];
|
|
141
|
+
return lazy(build, previous ? { ...previous, ...annotations } : annotations, this[dataKey]);
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Effect detects schemas by this key on the prototype; if a future Effect
|
|
147
|
+
// moves it, build eagerly.
|
|
148
|
+
const supported = (SchemaProto as Record<string, unknown>)["~effect/Schema/Schema"] !== undefined;
|
|
149
|
+
|
|
150
|
+
const lazy = (
|
|
151
|
+
build: (() => S.Top) | LazyBuilder,
|
|
152
|
+
annotations?: Annotations,
|
|
153
|
+
data?: unknown,
|
|
154
|
+
): S.Top => {
|
|
155
|
+
if (!supported) {
|
|
156
|
+
const built = typeof build === "function" ? build() : build.build(data);
|
|
157
|
+
return annotations ? built.annotate(annotations) : built;
|
|
158
|
+
}
|
|
159
|
+
const self = Object.create(LazyProto);
|
|
160
|
+
self[buildKey] = build;
|
|
161
|
+
if (data !== undefined) self[dataKey] = data;
|
|
162
|
+
if (annotations) self[annotationsKey] = annotations;
|
|
163
|
+
return self;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** A schema built on first use by `builder.build(data)`. */
|
|
167
|
+
export const lazyFrom = (builder: LazyBuilder, data: unknown): S.Top =>
|
|
168
|
+
lazy(builder, undefined, data);
|
|
169
|
+
|
|
170
|
+
const lazySuspend = (f: () => S.Top): S.Top => lazy(() => S.suspend(f));
|
|
171
|
+
const lazyArray = (item: S.Top): S.Top => lazy(() => S.Array(item));
|
|
172
|
+
const lazyRecord = (key: S.Top, value: S.Top): S.Top => lazy(() => S.Record(key as any, value));
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
|
|
176
|
+
//#region Lazy error classes
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* `S.TaggedError` whose Effect class is built on first use instead of at
|
|
180
|
+
* import.
|
|
181
|
+
*
|
|
182
|
+
* Every error class Effect builds carries its own copies of about fifteen
|
|
183
|
+
* static methods plus a tagged struct schema: about 4.6 KB per class, and
|
|
184
|
+
* AWS EC2 alone declares 248 of them. This returns a small constructor that
|
|
185
|
+
* stands in for the class until something needs it -- constructing an
|
|
186
|
+
* instance, or a schema static such as `ast` / `fields` / `make`. Then it
|
|
187
|
+
* builds the real class with `S.TaggedError` and puts it underneath: the
|
|
188
|
+
* lazy class's prototype starts inheriting from the real prototype, and
|
|
189
|
+
* statics forward to the real class with `this` bound to the lazy class, so
|
|
190
|
+
* decoding produces instances of the lazy class (and of its subclasses).
|
|
191
|
+
*
|
|
192
|
+
* `pipe` (used to attach error categories), `identifier` and the schema
|
|
193
|
+
* marker answer without building. Instances behave as before: same
|
|
194
|
+
* `_tag`, fields, validation, `instanceof`, stack and `Effect.catchTag`.
|
|
195
|
+
*/
|
|
196
|
+
const lazyErrorKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/lazyError");
|
|
197
|
+
|
|
198
|
+
interface LazyErrorState {
|
|
199
|
+
readonly identifier: string | undefined;
|
|
200
|
+
readonly args: ReadonlyArray<unknown>;
|
|
201
|
+
readonly lazy: Function;
|
|
202
|
+
real?: Function;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const SchemaTypeId = "~effect/Schema/Schema";
|
|
206
|
+
|
|
207
|
+
// The base every Effect error class extends (`core.Error`, a yieldable
|
|
208
|
+
// Error). Found on first use, so bundles without error classes do not keep
|
|
209
|
+
// Effect's class machinery.
|
|
210
|
+
let errorBase: Function | undefined;
|
|
211
|
+
const ErrorBase = (): Function =>
|
|
212
|
+
(errorBase ??= Object.getPrototypeOf(S.TaggedError()("Probe", {})) as Function);
|
|
213
|
+
|
|
214
|
+
const realErrorClass = (cls: Function): Function => {
|
|
215
|
+
const state = (cls as unknown as Record<symbol, LazyErrorState>)[lazyErrorKey];
|
|
216
|
+
if (!state.real) {
|
|
217
|
+
const real = (S.TaggedError as Function)(state.identifier)(...state.args) as Function;
|
|
218
|
+
state.real = real;
|
|
219
|
+
Object.setPrototypeOf(state.lazy.prototype, real.prototype);
|
|
220
|
+
}
|
|
221
|
+
return state.real;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** Effect's class statics that need the real class. */
|
|
225
|
+
const FORWARDED_STATICS = [
|
|
226
|
+
"ast",
|
|
227
|
+
"fields",
|
|
228
|
+
"make",
|
|
229
|
+
"makeOption",
|
|
230
|
+
"makeEffect",
|
|
231
|
+
"annotate",
|
|
232
|
+
"annotateKey",
|
|
233
|
+
"check",
|
|
234
|
+
"rebuild",
|
|
235
|
+
"extend",
|
|
236
|
+
"mapFields",
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
let lazyErrorStatics: object | undefined;
|
|
240
|
+
const LazyErrorStatics = (): object =>
|
|
241
|
+
(lazyErrorStatics ??= Object.create(ErrorBase(), {
|
|
242
|
+
[SchemaTypeId]: { value: SchemaTypeId, configurable: true },
|
|
243
|
+
identifier: {
|
|
244
|
+
configurable: true,
|
|
245
|
+
get(this: Record<symbol, LazyErrorState>) {
|
|
246
|
+
const state = this[lazyErrorKey];
|
|
247
|
+
return state.identifier ?? state.args[0];
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
pipe: {
|
|
251
|
+
configurable: true,
|
|
252
|
+
writable: true,
|
|
253
|
+
value(this: unknown) {
|
|
254
|
+
return pipeArguments(this, arguments);
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
...Object.fromEntries(
|
|
258
|
+
FORWARDED_STATICS.map((name) => [
|
|
259
|
+
name,
|
|
260
|
+
{
|
|
261
|
+
configurable: true,
|
|
262
|
+
get(this: Function) {
|
|
263
|
+
let owner: object | null = realErrorClass(this);
|
|
264
|
+
let descriptor: PropertyDescriptor | undefined;
|
|
265
|
+
while (owner && !(descriptor = Object.getOwnPropertyDescriptor(owner, name))) {
|
|
266
|
+
owner = Object.getPrototypeOf(owner);
|
|
267
|
+
}
|
|
268
|
+
if (!descriptor) return undefined;
|
|
269
|
+
if (descriptor.get) return descriptor.get.call(this);
|
|
270
|
+
return typeof descriptor.value === "function"
|
|
271
|
+
? descriptor.value.bind(this)
|
|
272
|
+
: descriptor.value;
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
]),
|
|
276
|
+
),
|
|
277
|
+
}));
|
|
278
|
+
|
|
279
|
+
const lazyTaggedError =
|
|
280
|
+
(identifier?: string) =>
|
|
281
|
+
(...args: ReadonlyArray<unknown>): Function => {
|
|
282
|
+
function LazyTaggedError(this: unknown, input?: unknown, options?: unknown) {
|
|
283
|
+
if (!new.target) throw new TypeError("Class constructor cannot be invoked without 'new'");
|
|
284
|
+
return Reflect.construct(realErrorClass(new.target), [input, options], new.target);
|
|
285
|
+
}
|
|
286
|
+
Object.setPrototypeOf(LazyTaggedError, LazyErrorStatics());
|
|
287
|
+
LazyTaggedError.prototype = Object.create(ErrorBase().prototype, {
|
|
288
|
+
constructor: { value: LazyTaggedError, writable: true, configurable: true },
|
|
289
|
+
});
|
|
290
|
+
const state: LazyErrorState = { identifier, args, lazy: LazyTaggedError };
|
|
291
|
+
Object.defineProperty(LazyTaggedError, lazyErrorKey, { value: state });
|
|
292
|
+
return LazyTaggedError;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
export const TaggedError: typeof S.TaggedError = lazyTaggedError as typeof S.TaggedError;
|
|
296
|
+
|
|
297
|
+
//#endregion
|
package/src/testing.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Test helpers for SDK packages: a canned-response `HttpClient` and a runner
|
|
3
|
-
* that executes one operation under
|
|
3
|
+
* that executes one operation under every response-validation mode.
|
|
4
4
|
*
|
|
5
5
|
* ```ts
|
|
6
6
|
* const { lenient, strict } = await runValidationModes(
|
|
@@ -52,13 +52,14 @@ export const mockHttpClient = (
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Run `effect` against `mockHttpClient(response)` once in lenient mode and
|
|
55
|
-
* once in
|
|
55
|
+
* once in each validating mode (`additionalProperties`, `strict`).
|
|
56
56
|
*/
|
|
57
57
|
export const runValidationModes = <A, E>(
|
|
58
58
|
effect: Effect.Effect<A, E, HttpClient.HttpClient>,
|
|
59
59
|
response: Parameters<typeof mockHttpClient>[0],
|
|
60
60
|
): Promise<{
|
|
61
61
|
readonly lenient: Result.Result<A, E>;
|
|
62
|
+
readonly additionalProperties: Result.Result<A, E>;
|
|
62
63
|
readonly strict: Result.Result<A, E>;
|
|
63
64
|
}> => {
|
|
64
65
|
const run = (mode: Layer.Layer<never>) =>
|
|
@@ -66,6 +67,7 @@ export const runValidationModes = <A, E>(
|
|
|
66
67
|
return Effect.runPromise(
|
|
67
68
|
Effect.all({
|
|
68
69
|
lenient: run(ResponseValidation.lenient),
|
|
70
|
+
additionalProperties: run(ResponseValidation.additionalProperties),
|
|
69
71
|
strict: run(ResponseValidation.strict),
|
|
70
72
|
}),
|
|
71
73
|
);
|
package/src/trait.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export const annotationMetaSymbol = Symbol.for(
|
|
1
|
+
export const annotationMetaSymbol = /*@__PURE__*/ Symbol.for(
|
|
2
|
+
"@distilled.cloud/core/annotation-meta",
|
|
3
|
+
);
|
|
2
4
|
|
|
3
5
|
export type Annotatable = {
|
|
4
6
|
annotate(annotations: any): Annotatable;
|
|
@@ -18,7 +20,7 @@ export interface Annotation {
|
|
|
18
20
|
* Build a pipeable schema annotation carrying `value` under `sym`. Exported
|
|
19
21
|
* so SDK packages can define their own protocol traits (e.g. cloudflare's
|
|
20
22
|
* envelope traits, aws's smithy traits) with the same mechanics as the
|
|
21
|
-
* generic ones here. Keys may be symbols or plain strings
|
|
23
|
+
* generic ones here. Keys may be symbols or plain strings -- effect Schema
|
|
22
24
|
* annotation dictionaries accept both.
|
|
23
25
|
*/
|
|
24
26
|
export function makeAnnotation<T>(sym: symbol | string, value: T): Annotation {
|
|
@@ -29,7 +31,7 @@ export function makeAnnotation<T>(sym: symbol | string, value: T): Annotation {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
|
-
* Combine several annotations into one
|
|
34
|
+
* Combine several annotations into one -- needed where only a single
|
|
33
35
|
* annotations object can be supplied (e.g. the second argument of
|
|
34
36
|
* `S.Class`).
|
|
35
37
|
*/
|
|
@@ -63,7 +65,7 @@ export interface HttpTrait {
|
|
|
63
65
|
readonly code?: number;
|
|
64
66
|
/**
|
|
65
67
|
* Request body encoding. Default is JSON; `"multipart"` sends
|
|
66
|
-
* multipart/form-data
|
|
68
|
+
* multipart/form-data -- body members become form parts (objects
|
|
67
69
|
* JSON-encoded) and members marked `FormDataFile()` append their files.
|
|
68
70
|
* `"form-urlencoded"` sends application/x-www-form-urlencoded with
|
|
69
71
|
* Stripe-style bracket notation for nested objects and arrays (see
|
|
@@ -80,13 +82,13 @@ export interface HttpTrait {
|
|
|
80
82
|
/**
|
|
81
83
|
* Explicit `Accept` for the operation, when the API serves more than one
|
|
82
84
|
* response media type. Atlas pins an API version this way (e.g.
|
|
83
|
-
* `application/vnd.atlas.2024-05-30+json`
|
|
85
|
+
* `application/vnd.atlas.2024-05-30+json` -- `application/json` alone is a
|
|
84
86
|
* 406). Protocols that don't read it fall back to their own default.
|
|
85
87
|
*/
|
|
86
88
|
readonly accept?: string;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
export const httpSymbol = Symbol.for("@distilled.cloud/core/http");
|
|
91
|
+
export const httpSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http");
|
|
90
92
|
/**
|
|
91
93
|
* Operation-level HTTP binding: the request method + URI template. Stamped on
|
|
92
94
|
* the input schema so the protocol can build the request line. URI `{labels}`
|
|
@@ -94,11 +96,13 @@ export const httpSymbol = Symbol.for("@distilled.cloud/core/http");
|
|
|
94
96
|
*/
|
|
95
97
|
export const Http = (trait: HttpTrait) => makeAnnotation(httpSymbol, trait);
|
|
96
98
|
|
|
97
|
-
export const labelSymbol = Symbol.for("@distilled.cloud/core/http/label");
|
|
99
|
+
export const labelSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/label");
|
|
98
100
|
/** Bind a member to a `{name}` placeholder in the operation's URI template. */
|
|
99
101
|
export const Label = (name?: string) => makeAnnotation(labelSymbol, name ?? true);
|
|
100
102
|
|
|
101
|
-
export const labelEncodingSymbol = Symbol.for(
|
|
103
|
+
export const labelEncodingSymbol = /*@__PURE__*/ Symbol.for(
|
|
104
|
+
"@distilled.cloud/core/http/label-encoding",
|
|
105
|
+
);
|
|
102
106
|
/** Preserve selected RFC 3986 pchar delimiters inside a single URI label. */
|
|
103
107
|
export const LabelEncoding = (options: { readonly preserve: string }) => {
|
|
104
108
|
if (!/^[!$&'()*+,;=:@]*$/.test(options.preserve)) {
|
|
@@ -107,41 +111,45 @@ export const LabelEncoding = (options: { readonly preserve: string }) => {
|
|
|
107
111
|
return makeAnnotation(labelEncodingSymbol, options.preserve);
|
|
108
112
|
};
|
|
109
113
|
|
|
110
|
-
export const responseCodeSymbol = Symbol.for(
|
|
114
|
+
export const responseCodeSymbol = /*@__PURE__*/ Symbol.for(
|
|
115
|
+
"@distilled.cloud/core/http/response-code",
|
|
116
|
+
);
|
|
111
117
|
export const ResponseCode = () => makeAnnotation(responseCodeSymbol, true);
|
|
112
118
|
|
|
113
|
-
export const headerSymbol = Symbol.for("@distilled.cloud/core/http/header");
|
|
119
|
+
export const headerSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/header");
|
|
114
120
|
export const Header = (name?: string) => makeAnnotation(headerSymbol, name ?? true);
|
|
115
121
|
|
|
116
|
-
export const bodySymbol = Symbol.for("@distilled.cloud/core/http/body");
|
|
122
|
+
export const bodySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/body");
|
|
117
123
|
export const Body = (name?: string) => makeAnnotation(bodySymbol, name ?? true);
|
|
118
124
|
|
|
119
|
-
export const querySymbol = Symbol.for("@distilled.cloud/core/http/query");
|
|
125
|
+
export const querySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/query");
|
|
120
126
|
export const Query = (name?: string) => makeAnnotation(querySymbol, name ?? true);
|
|
121
127
|
|
|
122
|
-
export const deepQuerySymbol = Symbol.for("@distilled.cloud/core/http/deep-query");
|
|
128
|
+
export const deepQuerySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/deep-query");
|
|
123
129
|
/**
|
|
124
130
|
* Binds a struct-valued input member to a family of DOTTED query parameters:
|
|
125
131
|
* `{ account: { id, name } }` with `DeepQuery("account")` serializes as
|
|
126
|
-
* `?account.id
|
|
132
|
+
* `?account.id=...&account.name=...` (null/undefined entries skipped). This is
|
|
127
133
|
* how several list endpoints model their filters on the wire (e.g.
|
|
128
134
|
* Cloudflare zones list `account.id` / `account.name`) while the TS surface
|
|
129
135
|
* keeps the nested-object shape (v0 parity).
|
|
130
136
|
*/
|
|
131
137
|
export const DeepQuery = (name?: string) => makeAnnotation(deepQuerySymbol, name ?? true);
|
|
132
138
|
|
|
133
|
-
export const httpBodySymbol = Symbol.for("@distilled.cloud/core/http-body");
|
|
139
|
+
export const httpBodySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http-body");
|
|
134
140
|
/**
|
|
135
141
|
* Marks the input member whose value IS the entire request body (raw arrays/
|
|
136
|
-
* scalars
|
|
142
|
+
* scalars -- e.g. endpoints that POST a bare JSON array). Mirrors
|
|
137
143
|
* `smithy.api#httpPayload`.
|
|
138
144
|
*/
|
|
139
145
|
export const HttpBody = () => makeAnnotation(httpBodySymbol, true);
|
|
140
146
|
|
|
141
|
-
export const stringEncodedSymbol = Symbol.for(
|
|
147
|
+
export const stringEncodedSymbol = /*@__PURE__*/ Symbol.for(
|
|
148
|
+
"@distilled.cloud/core/http/string-encoded",
|
|
149
|
+
);
|
|
142
150
|
/**
|
|
143
|
-
* Marks a member the API only accepts as the STRING spelling of its value
|
|
144
|
-
* `true` travels as `"true"`, `3` as `"3"`
|
|
151
|
+
* Marks a member the API only accepts as the STRING spelling of its value --
|
|
152
|
+
* `true` travels as `"true"`, `3` as `"3"` -- while the TS surface keeps the
|
|
145
153
|
* natural type (e.g. Cloudflare's multipart `validation_enabled`, which the
|
|
146
154
|
* docs model as the enum `"true" | "false"`). The protocol stringifies body
|
|
147
155
|
* members on encode, element-wise for lists; `null` is left alone. Query and
|
|
@@ -150,7 +158,7 @@ export const stringEncodedSymbol = Symbol.for("@distilled.cloud/core/http/string
|
|
|
150
158
|
*/
|
|
151
159
|
export const StringEncoded = () => makeAnnotation(stringEncodedSymbol, true);
|
|
152
160
|
|
|
153
|
-
export const formDataFileSymbol = Symbol.for("@distilled.cloud/core/form-data-file");
|
|
161
|
+
export const formDataFileSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/form-data-file");
|
|
154
162
|
/**
|
|
155
163
|
* Marks an input member holding `File`/`Blob` parts for a multipart upload
|
|
156
164
|
* (`Http({ contentType: "multipart" })`). Each file is appended to the form
|
|
@@ -161,9 +169,9 @@ export const FormDataFile = () => makeAnnotation(formDataFileSymbol, true);
|
|
|
161
169
|
|
|
162
170
|
//#region Generic JSON traits
|
|
163
171
|
|
|
164
|
-
export const keyDictionarySymbol = Symbol.for("@distilled.cloud/core/key-dictionary");
|
|
172
|
+
export const keyDictionarySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/key-dictionary");
|
|
165
173
|
/**
|
|
166
|
-
* Deep TS-name
|
|
174
|
+
* Deep TS-name->wire-name key dictionary for members whose full structure is
|
|
167
175
|
* not modeled (opaque `Document` content). The protocol renames any matching
|
|
168
176
|
* key at any depth on encode (and the reverse on decode); keys not in the
|
|
169
177
|
* dictionary pass through verbatim.
|
|
@@ -179,10 +187,10 @@ export type KeyDictionaryEntries = Record<string, string | ReadonlyArray<string>
|
|
|
179
187
|
export const KeyDictionary = (dict: KeyDictionaryEntries) =>
|
|
180
188
|
makeAnnotation(keyDictionarySymbol, dict);
|
|
181
189
|
|
|
182
|
-
export const unionCasesSymbol = Symbol.for("@distilled.cloud/core/union-cases");
|
|
190
|
+
export const unionCasesSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/union-cases");
|
|
183
191
|
|
|
184
192
|
/**
|
|
185
|
-
* The literal member every case of a union fixes to its own value
|
|
193
|
+
* The literal member every case of a union fixes to its own value -- what the
|
|
186
194
|
* docs call the resource `type` or the action `id`. `values[i]` is the value
|
|
187
195
|
* case `i` carries.
|
|
188
196
|
*/
|
|
@@ -198,8 +206,8 @@ export interface UnionDiscriminator {
|
|
|
198
206
|
* sets to pick the active case and drop the others, so consumers' `"key" in
|
|
199
207
|
* value` discrimination works.
|
|
200
208
|
*
|
|
201
|
-
* Key sets alone cannot tell apart cases that share them
|
|
202
|
-
* kinds of `resource_tagging`, the 34 page-rule actions
|
|
209
|
+
* Key sets alone cannot tell apart cases that share them -- the 41 resource
|
|
210
|
+
* kinds of `resource_tagging`, the 34 page-rule actions -- so when the union
|
|
203
211
|
* has a discriminator the protocol reads the case off it and only falls back
|
|
204
212
|
* to key-set scoring for a value whose tag is missing or unknown.
|
|
205
213
|
*/
|
|
@@ -211,7 +219,7 @@ export const UnionCases = (
|
|
|
211
219
|
|
|
212
220
|
//#region Error matcher traits
|
|
213
221
|
|
|
214
|
-
export const errorMatchersSymbol = Symbol.for("@distilled.cloud/core/error-matchers");
|
|
222
|
+
export const errorMatchersSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/error-matchers");
|
|
215
223
|
|
|
216
224
|
/** Exact text, or the conjunction of substring and regular-expression constraints. */
|
|
217
225
|
export type ErrorTextMatcher = string | { readonly includes?: string; readonly matches?: string };
|
|
@@ -246,7 +254,7 @@ export interface ErrorMatcher {
|
|
|
246
254
|
* Stamp wire-matching rules onto a generated error class. Protocols consult
|
|
247
255
|
* these to decide which of an operation's declared error classes a failed
|
|
248
256
|
* response should surface as (most specific matcher wins; ties break by
|
|
249
|
-
* declaration order
|
|
257
|
+
* declaration order -- see `matchTypedError` in `core/protocol-http`).
|
|
250
258
|
*/
|
|
251
259
|
export const applyErrorMatchers = <C>(cls: C, matchers: ReadonlyArray<ErrorMatcher>): C => {
|
|
252
260
|
(cls as any)[errorMatchersSymbol] = matchers;
|
package/src/xml.ts
CHANGED
|
@@ -6,13 +6,14 @@ export interface XmlObject {
|
|
|
6
6
|
[name: string]: XmlValue;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export class XmlParseError
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export class XmlParseError
|
|
10
|
+
extends /*@__PURE__*/ Data.TaggedError("XmlParseError")<{
|
|
11
|
+
readonly message: string;
|
|
12
|
+
/** UTF-16 offset in the original input; line and column are one-based. */
|
|
13
|
+
readonly offset: number;
|
|
14
|
+
readonly line: number;
|
|
15
|
+
readonly column: number;
|
|
16
|
+
}> {}
|
|
16
17
|
|
|
17
18
|
export interface XmlParseOptions {
|
|
18
19
|
/** Maximum open elements, including the root. Defaults to 256. */
|
|
@@ -34,10 +35,21 @@ const xmlSpace = /^[\t\n\r ]*$/;
|
|
|
34
35
|
const declarationPattern =
|
|
35
36
|
/^xml[\t\n\r ]+version[\t\n\r ]*=[\t\n\r ]*(?:"1\.0"|'1\.0')(?:[\t\n\r ]+encoding[\t\n\r ]*=[\t\n\r ]*(?:"[A-Za-z][A-Za-z0-9._-]*"|'[A-Za-z][A-Za-z0-9._-]*'))?(?:[\t\n\r ]+standalone[\t\n\r ]*=[\t\n\r ]*(?:"(?:yes|no)"|'(?:yes|no)'))?[\t\n\r ]*$/;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The prototype of every object the parser returns. It has no prototype
|
|
40
|
+
* itself, so element names such as `__proto__` or `constructor` are plain
|
|
41
|
+
* own keys, as with a null prototype -- but V8 keeps objects with a
|
|
42
|
+
* non-null prototype in fast mode, which makes parsing several times faster.
|
|
43
|
+
*/
|
|
44
|
+
const nodeProto: object = /*@__PURE__*/ Object.create(null);
|
|
45
|
+
|
|
46
|
+
/** An ASCII XML name not followed by a non-ASCII (possibly name) character. */
|
|
47
|
+
const asciiName = /[A-Za-z_:][\w:.-]*(?![^\0-\x7f])/y;
|
|
48
|
+
|
|
37
49
|
interface Element {
|
|
38
50
|
name: string;
|
|
39
51
|
object: XmlObject;
|
|
40
|
-
text: string
|
|
52
|
+
text: string;
|
|
41
53
|
hasChildren: boolean;
|
|
42
54
|
hasAttributes: boolean;
|
|
43
55
|
hasCdata: boolean;
|
|
@@ -58,7 +70,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
|
|
|
58
70
|
const maxDepth = options.maxDepth ?? 256;
|
|
59
71
|
const maxLength = options.maxLength ?? 64 * 1024 * 1024;
|
|
60
72
|
const stack: Element[] = [];
|
|
61
|
-
const document: XmlObject = Object.create(
|
|
73
|
+
const document: XmlObject = Object.create(nodeProto);
|
|
62
74
|
let hasRoot = false;
|
|
63
75
|
|
|
64
76
|
function fail(message: string, offset = pos): never {
|
|
@@ -92,14 +104,16 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
|
|
|
92
104
|
}
|
|
93
105
|
|
|
94
106
|
function readName(): string {
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
// ASCII names (most documents) match a cheaper, non-Unicode pattern first.
|
|
108
|
+
asciiName.lastIndex = namePattern.lastIndex = pos;
|
|
109
|
+
const match = asciiName.exec(xml) ?? namePattern.exec(xml);
|
|
97
110
|
if (!match) fail("Expected XML name");
|
|
98
|
-
pos
|
|
111
|
+
pos += match[0].length;
|
|
99
112
|
return match[0];
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
function decode(raw: string, offset: number, attribute = false): string {
|
|
116
|
+
if (raw.indexOf("&") < 0 && !(attribute ? /[\t\r\n]/ : /\r/).test(raw)) return raw;
|
|
103
117
|
const parts: string[] = [];
|
|
104
118
|
let from = 0;
|
|
105
119
|
while (from < raw.length) {
|
|
@@ -158,7 +172,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
|
|
|
158
172
|
}
|
|
159
173
|
|
|
160
174
|
function finish(element: Element): void {
|
|
161
|
-
const text = element.text
|
|
175
|
+
const text = element.text;
|
|
162
176
|
let value: XmlValue;
|
|
163
177
|
if (!element.hasChildren && !element.hasAttributes) {
|
|
164
178
|
value = text;
|
|
@@ -191,7 +205,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
|
|
|
191
205
|
} else {
|
|
192
206
|
const cdataEnd = raw.indexOf("]]>");
|
|
193
207
|
if (cdataEnd >= 0) fail("Unexpected CDATA terminator", offset + cdataEnd);
|
|
194
|
-
element.text
|
|
208
|
+
element.text += decode(raw, offset);
|
|
195
209
|
}
|
|
196
210
|
continue;
|
|
197
211
|
}
|
|
@@ -207,7 +221,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
|
|
|
207
221
|
if (!element) fail("CDATA outside root element");
|
|
208
222
|
const end = xml.indexOf("]]>", pos + 9);
|
|
209
223
|
if (end < 0) fail("Unterminated CDATA");
|
|
210
|
-
element.text
|
|
224
|
+
element.text += xml.slice(pos + 9, end).replace(/\r\n?/g, "\n");
|
|
211
225
|
element.hasCdata = true;
|
|
212
226
|
pos = end + 3;
|
|
213
227
|
} else if (xml.startsWith("<?", pos)) {
|
|
@@ -243,8 +257,8 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
|
|
|
243
257
|
pos++;
|
|
244
258
|
const element: Element = {
|
|
245
259
|
name: readName(),
|
|
246
|
-
object: Object.create(
|
|
247
|
-
text:
|
|
260
|
+
object: Object.create(nodeProto),
|
|
261
|
+
text: "",
|
|
248
262
|
hasChildren: false,
|
|
249
263
|
hasAttributes: false,
|
|
250
264
|
hasCdata: false,
|
package/lib/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAIrD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa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