@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/lib/graphql.types.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const deployment = service.latestDeployment.pipe(mapQuery((d) => ({ id: d.id, status: d.status })));
|
|
3
|
-
const popular = service.stars.pipe(mapQuery((stars) => stars > 5));
|
|
4
|
-
const labels = service.tags.pipe(mapQuery((tag) => tag.label));
|
|
5
|
-
//# sourceMappingURL=graphql.types.js.map
|
|
1
|
+
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@distilled.cloud/core`
|
|
2
|
+
* `@distilled.cloud/core` -- the runtime shared by every distilled SDK.
|
|
3
3
|
*
|
|
4
4
|
* ```ts
|
|
5
5
|
* import { ResponseValidation, Retry } from "@distilled.cloud/core";
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
10
|
* Each namespace is also importable on its own subpath
|
|
11
|
-
* (`@distilled.cloud/core/response-validation`,
|
|
11
|
+
* (`@distilled.cloud/core/response-validation`, ...); generated SDKs use the
|
|
12
12
|
* subpaths. Code generation (`codegen/*`) and test helpers (`testing`) stay
|
|
13
13
|
* subpath-only.
|
|
14
14
|
*/
|
|
@@ -20,6 +20,7 @@ export * as Pagination from "./pagination.ts";
|
|
|
20
20
|
export * as ProtocolHttp from "./protocol-http.ts";
|
|
21
21
|
export * as ProtocolRest from "./protocol-rest.ts";
|
|
22
22
|
export { Query } from "./query.ts";
|
|
23
|
+
export * as Crypto from "./crypto.ts";
|
|
23
24
|
export * as ResponseValidation from "./response-validation.ts";
|
|
24
25
|
export * as Retry from "./retry.ts";
|
|
25
26
|
export * as RetryAfter from "./retry-after.ts";
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,kBAAkB,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,kBAAkB,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@distilled.cloud/core` — the runtime shared by every distilled SDK.
|
|
3
|
-
*
|
|
4
|
-
* ```ts
|
|
5
|
-
* import { ResponseValidation, Retry } from "@distilled.cloud/core";
|
|
6
|
-
*
|
|
7
|
-
* program.pipe(Effect.provide(ResponseValidation.strict));
|
|
8
|
-
* ```
|
|
9
|
-
*
|
|
10
|
-
* Each namespace is also importable on its own subpath
|
|
11
|
-
* (`@distilled.cloud/core/response-validation`, …); generated SDKs use the
|
|
12
|
-
* subpaths. Code generation (`codegen/*`) and test helpers (`testing`) stay
|
|
13
|
-
* subpath-only.
|
|
14
|
-
*/
|
|
15
1
|
export * as API from "./api.js";
|
|
16
2
|
export * as Category from "./category.js";
|
|
17
3
|
export * as Errors from "./errors.js";
|
|
@@ -20,8 +6,8 @@ export * as Pagination from "./pagination.js";
|
|
|
20
6
|
export * as ProtocolHttp from "./protocol-http.js";
|
|
21
7
|
export * as ProtocolRest from "./protocol-rest.js";
|
|
22
8
|
export { Query } from "./query.js";
|
|
9
|
+
export * as Crypto from "./crypto.js";
|
|
23
10
|
export * as ResponseValidation from "./response-validation.js";
|
|
24
11
|
export * as Retry from "./retry.js";
|
|
25
12
|
export * as RetryAfter from "./retry-after.js";
|
|
26
13
|
export * as Trait from "./trait.js";
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
package/lib/json-patch.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* model; generate does not patch. Operation names are convert policy
|
|
7
7
|
* (`operationNames`), never a patch.
|
|
8
8
|
*
|
|
9
|
-
* Pure functions only
|
|
9
|
+
* Pure functions only -- callers load patch files themselves (the generators
|
|
10
10
|
* use Effect's FileSystem) and hand the parsed operations to `applyPatch`.
|
|
11
11
|
*/
|
|
12
12
|
export interface JsonPatchOperation {
|
|
@@ -32,7 +32,7 @@ export interface PatchFile {
|
|
|
32
32
|
export declare function parseJsonPointer(pointer: string): string[];
|
|
33
33
|
/** Get a value at a JSON Pointer path. */
|
|
34
34
|
/**
|
|
35
|
-
* The target location of a patch operation is absent from the document
|
|
35
|
+
* The target location of a patch operation is absent from the document --
|
|
36
36
|
* spec drift (renamed/removed upstream), not a malformed patch.
|
|
37
37
|
*/
|
|
38
38
|
export declare class StaleTargetError extends Error {
|
package/lib/json-patch.js
CHANGED
|
@@ -1,227 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* JSON Patch (RFC 6902) Implementation
|
|
3
|
-
*
|
|
4
|
-
* The patch engine for every SDK. Patches are Smithy ops applied in
|
|
5
|
-
* `convert` (`finalizeConvert`), so `.generated-specs` is the patched Smithy
|
|
6
|
-
* model; generate does not patch. Operation names are convert policy
|
|
7
|
-
* (`operationNames`), never a patch.
|
|
8
|
-
*
|
|
9
|
-
* Pure functions only — callers load patch files themselves (the generators
|
|
10
|
-
* use Effect's FileSystem) and hand the parsed operations to `applyPatch`.
|
|
11
|
-
*/
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// JSON Pointer (RFC 6901)
|
|
14
|
-
// ============================================================================
|
|
15
|
-
/** Parse a JSON Pointer (RFC 6901) path into segments. */
|
|
16
|
-
export function parseJsonPointer(pointer) {
|
|
17
|
-
if (pointer === "")
|
|
18
|
-
return [];
|
|
19
|
-
if (!pointer.startsWith("/")) {
|
|
20
|
-
throw new Error(`Invalid JSON Pointer: ${pointer}`);
|
|
21
|
-
}
|
|
22
|
-
return pointer
|
|
23
|
-
.slice(1)
|
|
24
|
-
.split("/")
|
|
25
|
-
.map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
26
|
-
}
|
|
27
|
-
/** Get a value at a JSON Pointer path. */
|
|
28
|
-
/**
|
|
29
|
-
* The target location of a patch operation is absent from the document —
|
|
30
|
-
* spec drift (renamed/removed upstream), not a malformed patch.
|
|
31
|
-
*/
|
|
32
|
-
export class StaleTargetError extends Error {
|
|
33
|
-
name = "StaleTargetError";
|
|
34
|
-
}
|
|
35
|
-
export function getValueAtPath(obj, pointer) {
|
|
36
|
-
const segments = parseJsonPointer(pointer);
|
|
37
|
-
let current = obj;
|
|
38
|
-
for (const segment of segments) {
|
|
39
|
-
if (current === null || current === undefined || typeof current !== "object") {
|
|
40
|
-
throw new StaleTargetError(`JSON pointer ${pointer} missing (at '${segment}'): not an object`);
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(current)) {
|
|
43
|
-
const index = segment === "-" ? current.length : parseInt(segment, 10);
|
|
44
|
-
if (index < 0 || index >= current.length) {
|
|
45
|
-
throw new StaleTargetError(`JSON pointer ${pointer} missing index '${segment}'`);
|
|
46
|
-
}
|
|
47
|
-
current = current[index];
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const record = current;
|
|
51
|
-
if (!Object.prototype.hasOwnProperty.call(record, segment)) {
|
|
52
|
-
throw new StaleTargetError(`JSON pointer ${pointer} missing key '${segment}'`);
|
|
53
|
-
}
|
|
54
|
-
current = record[segment];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return current;
|
|
58
|
-
}
|
|
59
|
-
/** Set a value at a JSON Pointer path. */
|
|
60
|
-
export function setValueAtPath(obj, pointer, value, mode = "add", before) {
|
|
61
|
-
const segments = parseJsonPointer(pointer);
|
|
62
|
-
if (segments.length === 0) {
|
|
63
|
-
throw new Error("Cannot set value at root path");
|
|
64
|
-
}
|
|
65
|
-
let current = obj;
|
|
66
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
67
|
-
const segment = segments[i];
|
|
68
|
-
if (current === null || typeof current !== "object") {
|
|
69
|
-
throw new StaleTargetError(`Cannot traverse path ${pointer}: not an object`);
|
|
70
|
-
}
|
|
71
|
-
if (Array.isArray(current)) {
|
|
72
|
-
current = current[parseInt(segment, 10)];
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
current = current[segment];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const lastSegment = segments[segments.length - 1];
|
|
79
|
-
if (current === null || typeof current !== "object") {
|
|
80
|
-
throw new StaleTargetError(`Cannot set value at path ${pointer}: parent is not an object`);
|
|
81
|
-
}
|
|
82
|
-
if (Array.isArray(current)) {
|
|
83
|
-
if (lastSegment === "-") {
|
|
84
|
-
current.push(value);
|
|
85
|
-
}
|
|
86
|
-
else if (mode === "replace") {
|
|
87
|
-
current[parseInt(lastSegment, 10)] = value;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// RFC 6902 §4.1: `add` at an array index inserts before it.
|
|
91
|
-
const index = parseInt(lastSegment, 10);
|
|
92
|
-
if (Number.isNaN(index) || index < 0 || index > current.length) {
|
|
93
|
-
throw new StaleTargetError(`JSON pointer ${pointer} index '${lastSegment}' is out of bounds`);
|
|
94
|
-
}
|
|
95
|
-
current.splice(index, 0, value);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const record = current;
|
|
100
|
-
if (before === undefined || lastSegment in record || !(before in record)) {
|
|
101
|
-
record[lastSegment] = value;
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
// Rebuild the keys in place: the parent object stays the same object,
|
|
105
|
-
// since callers and later ops may hold a reference to it.
|
|
106
|
-
const entries = Object.entries(record);
|
|
107
|
-
for (const [key] of entries)
|
|
108
|
-
delete record[key];
|
|
109
|
-
for (const [key, v] of entries) {
|
|
110
|
-
if (key === before)
|
|
111
|
-
record[lastSegment] = value;
|
|
112
|
-
record[key] = v;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/** Remove a value at a JSON Pointer path. */
|
|
117
|
-
export function removeValueAtPath(obj, pointer) {
|
|
118
|
-
const segments = parseJsonPointer(pointer);
|
|
119
|
-
if (segments.length === 0) {
|
|
120
|
-
throw new Error("Cannot remove root");
|
|
121
|
-
}
|
|
122
|
-
let current = obj;
|
|
123
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
124
|
-
const segment = segments[i];
|
|
125
|
-
if (current === null || typeof current !== "object") {
|
|
126
|
-
throw new StaleTargetError(`Cannot traverse path ${pointer}: not an object`);
|
|
127
|
-
}
|
|
128
|
-
if (Array.isArray(current)) {
|
|
129
|
-
current = current[parseInt(segment, 10)];
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
current = current[segment];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const lastSegment = segments[segments.length - 1];
|
|
136
|
-
if (current === null || typeof current !== "object") {
|
|
137
|
-
throw new StaleTargetError(`Cannot remove at path ${pointer}: parent is not an object`);
|
|
138
|
-
}
|
|
139
|
-
// RFC 6902 §4.2: the target location MUST exist.
|
|
140
|
-
if (Array.isArray(current)) {
|
|
141
|
-
const index = parseInt(lastSegment, 10);
|
|
142
|
-
if (Number.isNaN(index) || index < 0 || index >= current.length) {
|
|
143
|
-
throw new StaleTargetError(`JSON pointer ${pointer} missing index '${lastSegment}'`);
|
|
144
|
-
}
|
|
145
|
-
current.splice(index, 1);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
const record = current;
|
|
149
|
-
if (!Object.prototype.hasOwnProperty.call(record, lastSegment)) {
|
|
150
|
-
throw new StaleTargetError(`JSON pointer ${pointer} missing key '${lastSegment}'`);
|
|
151
|
-
}
|
|
152
|
-
delete record[lastSegment];
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// ============================================================================
|
|
156
|
-
// Patch Operations
|
|
157
|
-
// ============================================================================
|
|
158
|
-
/** Apply a single JSON Patch operation (mutates `obj` in place). */
|
|
159
|
-
export function applyOperation(obj, operation) {
|
|
160
|
-
switch (operation.op) {
|
|
161
|
-
case "add":
|
|
162
|
-
setValueAtPath(obj, operation.path, operation.value, "add", operation.before);
|
|
163
|
-
break;
|
|
164
|
-
case "remove":
|
|
165
|
-
removeValueAtPath(obj, operation.path);
|
|
166
|
-
break;
|
|
167
|
-
case "replace": {
|
|
168
|
-
const existing = getValueAtPath(obj, operation.path);
|
|
169
|
-
if (existing === undefined) {
|
|
170
|
-
throw new StaleTargetError(`JSON pointer ${operation.path} does not exist`);
|
|
171
|
-
}
|
|
172
|
-
setValueAtPath(obj, operation.path, operation.value, "replace");
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
case "move": {
|
|
176
|
-
if (!operation.from)
|
|
177
|
-
throw new Error("move operation requires 'from'");
|
|
178
|
-
const moveValue = getValueAtPath(obj, operation.from);
|
|
179
|
-
if (moveValue === undefined) {
|
|
180
|
-
throw new StaleTargetError(`Cannot move from path ${operation.from}: not an object`);
|
|
181
|
-
}
|
|
182
|
-
removeValueAtPath(obj, operation.from);
|
|
183
|
-
setValueAtPath(obj, operation.path, moveValue, "add", operation.before);
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
case "copy": {
|
|
187
|
-
if (!operation.from)
|
|
188
|
-
throw new Error("copy operation requires 'from'");
|
|
189
|
-
const copyValue = getValueAtPath(obj, operation.from);
|
|
190
|
-
setValueAtPath(obj, operation.path, JSON.parse(JSON.stringify(copyValue)));
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
case "test": {
|
|
194
|
-
const testValue = getValueAtPath(obj, operation.path);
|
|
195
|
-
if (JSON.stringify(testValue) !== JSON.stringify(operation.value)) {
|
|
196
|
-
throw new Error(`Test operation failed at ${operation.path}: expected ${JSON.stringify(operation.value)}, got ${JSON.stringify(testValue)}`);
|
|
197
|
-
}
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
default:
|
|
201
|
-
throw new Error(`Unknown operation: ${operation.op}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/** Apply a JSON Patch to an object (mutates in place). */
|
|
205
|
-
export function applyPatch(obj, patch) {
|
|
206
|
-
for (const operation of patch) {
|
|
207
|
-
applyOperation(obj, operation);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Whether a per-operation failure is a {@link StaleTargetError} (the
|
|
212
|
-
* operation/shape the patch targets was renamed or removed upstream) as
|
|
213
|
-
* opposed to a malformed patch. Accepts the thrown value or its message.
|
|
214
|
-
* Convert fails the run on these by default (`onStalePatch: "fail"`);
|
|
215
|
-
* `"warn"` restores skip-and-continue.
|
|
216
|
-
*/
|
|
217
|
-
export function isStaleTargetError(error) {
|
|
218
|
-
if (error instanceof StaleTargetError)
|
|
219
|
-
return true;
|
|
220
|
-
const message = typeof error === "string" ? error : error instanceof Error ? error.message : "";
|
|
221
|
-
return (message.includes("not an object") ||
|
|
222
|
-
message.includes("parent is not an object") ||
|
|
223
|
-
message.includes("missing key") ||
|
|
224
|
-
message.includes("missing index") ||
|
|
225
|
-
message.includes("does not exist"));
|
|
226
|
-
}
|
|
1
|
+
function parseJsonPointer(e){if(e===``)return[];if(!e.startsWith(`/`))throw new Error(`Invalid JSON Pointer: ${e}`);return e.slice(1).split(`/`).map(e=>e.replace(/~1/g,`/`).replace(/~0/g,`~`))}var StaleTargetError=class extends Error{name=`StaleTargetError`};function getValueAtPath(e,t){const n=parseJsonPointer(t);let r=e;for(const e of n){if(r===null||r===void 0||typeof r!==`object`)throw new StaleTargetError(`JSON pointer ${t} missing (at '${e}'): not an object`);if(Array.isArray(r)){const n=e===`-`?r.length:parseInt(e,10);if(n<0||n>=r.length)throw new StaleTargetError(`JSON pointer ${t} missing index '${e}'`);r=r[n]}else{const n=r;if(!Object.prototype.hasOwnProperty.call(n,e))throw new StaleTargetError(`JSON pointer ${t} missing key '${e}'`);r=n[e]}}return r}function setValueAtPath(e,t,n,r=`add`,i){const a=parseJsonPointer(t);if(a.length===0)throw new Error(`Cannot set value at root path`);let o=e;for(let e=0;e<a.length-1;e++){const n=a[e];if(o===null||typeof o!==`object`)throw new StaleTargetError(`Cannot traverse path ${t}: not an object`);if(Array.isArray(o))o=o[parseInt(n,10)];else o=o[n]}const s=a[a.length-1];if(o===null||typeof o!==`object`)throw new StaleTargetError(`Cannot set value at path ${t}: parent is not an object`);if(Array.isArray(o)){if(s===`-`)o.push(n);else if(r===`replace`)o[parseInt(s,10)]=n;else{const e=parseInt(s,10);if(Number.isNaN(e)||e<0||e>o.length)throw new StaleTargetError(`JSON pointer ${t} index '${s}' is out of bounds`);o.splice(e,0,n)}}else{const e=o;if(i===void 0||s in e||!(i in e)){e[s]=n;return}const t=Object.entries(e);for(const[n]of t)delete e[n];for(const[r,a]of t){if(r===i)e[s]=n;e[r]=a}}}function removeValueAtPath(e,t){const n=parseJsonPointer(t);if(n.length===0)throw new Error(`Cannot remove root`);let r=e;for(let e=0;e<n.length-1;e++){const i=n[e];if(r===null||typeof r!==`object`)throw new StaleTargetError(`Cannot traverse path ${t}: not an object`);if(Array.isArray(r))r=r[parseInt(i,10)];else r=r[i]}const i=n[n.length-1];if(r===null||typeof r!==`object`)throw new StaleTargetError(`Cannot remove at path ${t}: parent is not an object`);if(Array.isArray(r)){const e=parseInt(i,10);if(Number.isNaN(e)||e<0||e>=r.length)throw new StaleTargetError(`JSON pointer ${t} missing index '${i}'`);r.splice(e,1)}else{const e=r;if(!Object.prototype.hasOwnProperty.call(e,i))throw new StaleTargetError(`JSON pointer ${t} missing key '${i}'`);delete e[i]}}function applyOperation(e,t){switch(t.op){case`add`:setValueAtPath(e,t.path,t.value,`add`,t.before);break;case`remove`:removeValueAtPath(e,t.path);break;case`replace`:if(getValueAtPath(e,t.path)===void 0)throw new StaleTargetError(`JSON pointer ${t.path} does not exist`);setValueAtPath(e,t.path,t.value,`replace`);break;case`move`:{if(!t.from)throw new Error(`move operation requires 'from'`);const n=getValueAtPath(e,t.from);if(n===void 0)throw new StaleTargetError(`Cannot move from path ${t.from}: not an object`);removeValueAtPath(e,t.from);setValueAtPath(e,t.path,n,`add`,t.before);break}case`copy`:{if(!t.from)throw new Error(`copy operation requires 'from'`);const n=getValueAtPath(e,t.from);setValueAtPath(e,t.path,JSON.parse(JSON.stringify(n)));break}case`test`:{const n=getValueAtPath(e,t.path);if(JSON.stringify(n)!==JSON.stringify(t.value))throw new Error(`Test operation failed at ${t.path}: expected ${JSON.stringify(t.value)}, got ${JSON.stringify(n)}`);break}default:throw new Error(`Unknown operation: ${t.op}`)}}function applyPatch(e,t){for(const n of t)applyOperation(e,n)}function isStaleTargetError(e){if(e instanceof StaleTargetError)return true;const t=typeof e===`string`?e:e instanceof Error?e.message:``;return t.includes(`not an object`)||t.includes(`parent is not an object`)||t.includes(`missing key`)||t.includes(`missing index`)||t.includes(`does not exist`)}export{StaleTargetError,applyOperation,applyPatch,getValueAtPath,isStaleTargetError,parseJsonPointer,removeValueAtPath,setValueAtPath};
|
|
227
2
|
//# sourceMappingURL=json-patch.js.map
|
package/lib/json-patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-patch.js","
|
|
1
|
+
{"version":3,"file":"json-patch.js","names":["pointer","segment","segments","current","obj","index","record","i","lastSegment","value","mode","before","entries","key","v","operation","moveValue","copyValue","testValue","patch","error","message"],"sources":["../src/json-patch.ts"],"mappings":"AA2CA,SAAgB,iBAAiB,EAA2B,CAC1D,GAAIA,IAAY,GAAI,MAAO,CAAC,EAC5B,GAAI,CAACA,EAAQ,WAAW,GAAG,EACzB,MAAM,IAAI,MAAM,yBAAyBA,GAAS,EAEpD,OAAOA,EACJ,MAAM,CAAC,CAAC,CACR,MAAM,GAAG,CAAC,CACV,IAAK,GAAYC,EAAQ,QAAQ,MAAO,GAAG,CAAC,CAAC,QAAQ,MAAO,GAAG,CAAC,CACrE,CAOA,IAAa,iBAAb,cAAsC,KAAM,CAC1C,KAAyB,kBAC3B,EAEA,SAAgB,eAAe,EAAc,EAA0B,CACrE,MAAMC,EAAW,iBAAiBF,CAAO,EACzC,IAAIG,EAAmBC,EAEvB,IAAK,MAAMH,KAAWC,EAAU,CAC9B,GAAIC,IAAY,MAAQA,IAAY,IAAA,IAAa,OAAOA,IAAY,SAClE,MAAM,IAAI,iBACR,gBAAgBH,EAAQ,gBAAgBC,EAAQ,kBAClD,EAEF,GAAI,MAAM,QAAQE,CAAO,EAAG,CAC1B,MAAME,EAAQJ,IAAY,IAAME,EAAQ,OAAS,SAASF,EAAS,EAAE,EACrE,GAAII,EAAQ,GAAKA,GAASF,EAAQ,OAChC,MAAM,IAAI,iBAAiB,gBAAgBH,EAAQ,kBAAkBC,EAAQ,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IAAI,CAC5E,CACF,CAGA,SAAgB,WAAW,EAAc,EAAwB,CAC/D,IAAK,MAAMA,KAAaI,EACtB,eAAef,EAAKW,CAAS,CAEjC,CASA,SAAgB,mBAAmB,EAAyB,CAC1D,GAAIK,aAAiB,iBAAkB,MAAO,MAC9C,MAAMC,EAAU,OAAOD,IAAU,SAAWA,EAAQA,aAAiB,MAAQA,EAAM,QAAU,GAC7F,OACEC,EAAQ,SAAS,eAAe,GAChCA,EAAQ,SAAS,yBAAyB,GAC1CA,EAAQ,SAAS,aAAa,GAC9BA,EAAQ,SAAS,eAAe,GAChCA,EAAQ,SAAS,gBAAgB,CAErC"}
|
package/lib/pagination.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pagination utilities for streaming through paginated API responses.
|
|
3
|
-
*
|
|
4
|
-
* Supports multiple pagination styles:
|
|
5
|
-
* - Page-based: page/per_page with a page number that advances
|
|
6
|
-
* - Cursor-based: cursor/limit with an opaque next-cursor string
|
|
7
|
-
* - Token-based (AWS style): NextToken/MaxResults continuation tokens
|
|
8
|
-
* - Relay (GraphQL connections): after/first with a `pageInfo` block whose
|
|
9
|
-
* `hasNextPage` — not the cursor — marks the end
|
|
10
|
-
* - Single: one-shot list endpoints that still expose the paginated surface
|
|
11
|
-
*
|
|
12
|
-
* Each SDK stores a {@link PaginatedTrait} on its operations (sourced from the
|
|
13
|
-
* `smithy.api#paginated` trait in its models) and picks a
|
|
14
|
-
* {@link PaginationStrategy}; these shared utilities handle the streaming.
|
|
15
|
-
* Ported from the distilled repo's `core/pagination`.
|
|
16
|
-
*/
|
|
17
1
|
import * as Effect from "effect/Effect";
|
|
18
2
|
import * as Stream from "effect/Stream";
|
|
19
3
|
/**
|
|
@@ -27,8 +11,8 @@ export declare const getPath: (obj: unknown, path: string) => unknown;
|
|
|
27
11
|
* cursors/tokens), every segment here fans out over whatever the previous one
|
|
28
12
|
* produced, so a path may cross a list:
|
|
29
13
|
*
|
|
30
|
-
* - `"items"` on `{ items: [a, b] }`
|
|
31
|
-
* - `"edges.node"` on a Relay connection
|
|
14
|
+
* - `"items"` on `{ items: [a, b] }` -> `[a, b]` (the common flat case)
|
|
15
|
+
* - `"edges.node"` on a Relay connection -> every edge's `node`
|
|
32
16
|
*
|
|
33
17
|
* `null`/`undefined` links are dropped rather than propagated, so a partially
|
|
34
18
|
* null page yields the items it does have instead of nothing.
|
|
@@ -44,7 +28,7 @@ export interface PaginatedTrait {
|
|
|
44
28
|
readonly outputToken?: string;
|
|
45
29
|
/**
|
|
46
30
|
* The path to the output member containing the paginated items. Segments
|
|
47
|
-
* may cross arrays
|
|
31
|
+
* may cross arrays -- `"edges.node"` walks every edge and collects its
|
|
48
32
|
* `node` (see {@link getItems}).
|
|
49
33
|
*/
|
|
50
34
|
readonly items?: string;
|
|
@@ -54,7 +38,7 @@ export interface PaginatedTrait {
|
|
|
54
38
|
* Relay extension: the path to the boolean that says whether another page
|
|
55
39
|
* exists (`"pageInfo.hasNextPage"`). Relay connections keep returning the
|
|
56
40
|
* last page's `endCursor` after the end, so the cursor alone can't
|
|
57
|
-
* terminate traversal
|
|
41
|
+
* terminate traversal -- see {@link paginateRelay}.
|
|
58
42
|
*/
|
|
59
43
|
readonly hasNextPage?: string;
|
|
60
44
|
}
|
|
@@ -64,7 +48,7 @@ export type PaginationStrategy = <Input extends Record<string, unknown>, Output,
|
|
|
64
48
|
* means "no more pages".
|
|
65
49
|
*
|
|
66
50
|
* APIs mark the terminal page by omitting the output token, returning it
|
|
67
|
-
* as `null`, or
|
|
51
|
+
* as `null`, or -- for several services (e.g. SSM, CloudWatch Logs) -- as an
|
|
68
52
|
* empty string. Treating `""` as a live token re-requests the first page
|
|
69
53
|
* forever (or fails with a ValidationException). Object tokens (e.g.
|
|
70
54
|
* DynamoDB's `LastEvaluatedKey`) are always truthy and unaffected.
|
|
@@ -72,7 +56,7 @@ export type PaginationStrategy = <Input extends Record<string, unknown>, Output,
|
|
|
72
56
|
export declare const isTerminalToken: (token: unknown) => boolean;
|
|
73
57
|
/**
|
|
74
58
|
* Stream for single-shot list endpoints that still expose the paginated
|
|
75
|
-
* surface
|
|
59
|
+
* surface -- emits exactly one page.
|
|
76
60
|
*/
|
|
77
61
|
export declare const paginateSingle: PaginationStrategy;
|
|
78
62
|
/**
|
|
@@ -82,18 +66,18 @@ export declare const paginateSingle: PaginationStrategy;
|
|
|
82
66
|
*/
|
|
83
67
|
export declare const paginatePageNumber: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
|
|
84
68
|
/**
|
|
85
|
-
* Stream of pages using cursor-based pagination
|
|
69
|
+
* Stream of pages using cursor-based pagination -- follow `outputToken`
|
|
86
70
|
* cursors until one comes back absent or repeats a previously requested cursor.
|
|
87
71
|
* Empty pages still advance when they return a new cursor.
|
|
88
72
|
*/
|
|
89
73
|
export declare const paginateCursor: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
|
|
90
74
|
/**
|
|
91
|
-
* Stream of pages using token-based pagination
|
|
75
|
+
* Stream of pages using token-based pagination -- pass `outputToken` back as
|
|
92
76
|
* `inputToken` until it comes back absent.
|
|
93
77
|
*/
|
|
94
78
|
export declare const paginateToken: <Input extends Record<string, unknown>, Output, E, R>(operation: (input: Input) => Effect.Effect<Output, E, R>, input: Input, pagination: PaginatedTrait) => Stream.Stream<Output, E, R>;
|
|
95
79
|
/**
|
|
96
|
-
* Stream of pages over a Relay connection
|
|
80
|
+
* Stream of pages over a Relay connection -- pass `pageInfo.endCursor` back as
|
|
97
81
|
* `after` for as long as `pageInfo.hasNextPage` is true.
|
|
98
82
|
*
|
|
99
83
|
* Relay is cursor pagination with one twist that breaks
|
package/lib/pagination.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,OAAO,QAAS,OAAO,QAAQ,MAAM,KAAG,OAUpD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,QAAS,OAAO,QAAQ,MAAM,KAAG,SAAS,OAAO,EAcrE,CAAC;AAMF,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,0BAA0B;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;IACjE,oEAAoE;IACpE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EACnF,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,EACxD,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,cAAc,KACvB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAA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