@distilled.cloud/core 1.0.0-rc.2 → 1.0.0-rc.20
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/LICENSE +201 -0
- 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/grpc.js +2 -0
- package/lib/_bundle/grpc.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/annotations.d.ts +17 -0
- package/lib/annotations.d.ts.map +1 -0
- package/lib/annotations.js +2 -0
- package/lib/annotations.js.map +1 -0
- package/lib/api.d.ts +174 -18
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -178
- package/lib/category.d.ts +4 -4
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -280
- package/lib/chunks.d.ts +3 -0
- package/lib/chunks.d.ts.map +1 -0
- package/lib/chunks.js +1 -0
- package/lib/config.d.ts +68 -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/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 +64 -72
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -186
- package/lib/graphql.d.ts +403 -0
- package/lib/graphql.d.ts.map +1 -0
- package/lib/graphql.js +1 -0
- package/lib/graphql.types.d.ts +12 -0
- package/lib/graphql.types.d.ts.map +1 -0
- package/lib/graphql.types.js +1 -0
- package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-http2.js +6 -0
- package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
- package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
- package/lib/grpc-transport-cloudflare-sockets.js +5 -0
- package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
- package/lib/grpc-transport-node-http2.d.ts +19 -0
- package/lib/grpc-transport-node-http2.d.ts.map +1 -0
- package/lib/grpc-transport-node-http2.js +2 -0
- package/lib/grpc-transport-node-http2.js.map +1 -0
- package/lib/grpc-transport.d.ts +76 -0
- package/lib/grpc-transport.d.ts.map +1 -0
- package/lib/grpc-transport.js +1 -0
- package/lib/hpack.d.ts +34 -0
- package/lib/hpack.d.ts.map +1 -0
- package/lib/hpack.js +2 -0
- package/lib/hpack.js.map +1 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -0
- package/lib/pagination.d.ts +101 -24
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -182
- 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/protobuf.d.ts +92 -0
- package/lib/protobuf.d.ts.map +1 -0
- package/lib/protobuf.js +1 -0
- package/lib/protocol-grpc.d.ts +86 -0
- package/lib/protocol-grpc.d.ts.map +1 -0
- package/lib/protocol-grpc.js +1 -0
- package/lib/protocol-http.d.ts +102 -23
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -554
- package/lib/protocol-rest.d.ts +120 -50
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -242
- package/lib/query.d.ts +29 -0
- package/lib/query.d.ts.map +1 -0
- package/lib/query.js +1 -0
- 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 +86 -0
- package/lib/response-validation.d.ts.map +1 -0
- package/lib/response-validation.js +1 -0
- package/lib/retry-after.d.ts +3 -3
- package/lib/retry-after.d.ts.map +1 -1
- 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 -210
- 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 +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 +21 -7
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -48
- package/lib/sdk-error.d.ts +27 -0
- package/lib/sdk-error.d.ts.map +1 -0
- package/lib/sdk-error.js +1 -0
- package/lib/sensitive.d.ts +28 -0
- package/lib/sensitive.d.ts.map +1 -0
- package/lib/sensitive.js +2 -0
- package/lib/sensitive.js.map +1 -0
- package/lib/telemetry-debug.d.ts +6 -0
- package/lib/telemetry-debug.d.ts.map +1 -0
- package/lib/telemetry-debug.js +2 -0
- package/lib/telemetry-debug.js.map +1 -0
- package/lib/telemetry-hooks.d.ts +32 -0
- package/lib/telemetry-hooks.d.ts.map +1 -0
- package/lib/telemetry-hooks.js +2 -0
- package/lib/telemetry-hooks.js.map +1 -0
- package/lib/telemetry-host-rules.d.ts +23 -0
- package/lib/telemetry-host-rules.d.ts.map +1 -0
- package/lib/telemetry-host-rules.js +2 -0
- package/lib/telemetry-host-rules.js.map +1 -0
- package/lib/telemetry-lambda-context.d.ts +17 -0
- package/lib/telemetry-lambda-context.d.ts.map +1 -0
- package/lib/telemetry-lambda-context.js +2 -0
- package/lib/telemetry-lambda-context.js.map +1 -0
- package/lib/telemetry-message-context.d.ts +52 -0
- package/lib/telemetry-message-context.d.ts.map +1 -0
- package/lib/telemetry-message-context.js +2 -0
- package/lib/telemetry-message-context.js.map +1 -0
- package/lib/telemetry-metrics.d.ts +6 -0
- package/lib/telemetry-metrics.d.ts.map +1 -0
- package/lib/telemetry-metrics.js +2 -0
- package/lib/telemetry-metrics.js.map +1 -0
- package/lib/telemetry-name-template.d.ts +13 -0
- package/lib/telemetry-name-template.d.ts.map +1 -0
- package/lib/telemetry-name-template.js +2 -0
- package/lib/telemetry-name-template.js.map +1 -0
- package/lib/telemetry-stream.d.ts +11 -0
- package/lib/telemetry-stream.d.ts.map +1 -0
- package/lib/telemetry-stream.js +2 -0
- package/lib/telemetry-stream.js.map +1 -0
- package/lib/telemetry-xray.d.ts +28 -0
- package/lib/telemetry-xray.d.ts.map +1 -0
- package/lib/telemetry-xray.js +2 -0
- package/lib/telemetry-xray.js.map +1 -0
- package/lib/telemetry.d.ts +288 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/lib/trait.d.ts +71 -20
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -107
- package/lib/unknown-error.d.ts +18 -0
- package/lib/unknown-error.d.ts.map +1 -0
- package/lib/unknown-error.js +1 -0
- package/lib/xml.d.ts +44 -0
- package/lib/xml.d.ts.map +1 -0
- package/lib/xml.js +1 -0
- package/package.json +13 -13
- package/src/annotations.ts +53 -0
- package/src/api.ts +1370 -200
- package/src/category.ts +76 -106
- package/src/chunks.ts +30 -0
- package/src/config.ts +245 -0
- package/src/crypto.ts +202 -0
- package/src/error-category.ts +16 -29
- package/src/errors.ts +75 -75
- package/src/graphql.ts +1778 -0
- package/src/graphql.types.ts +105 -0
- package/src/grpc-transport-cloudflare-http2.ts +494 -0
- package/src/grpc-transport-cloudflare-sockets.ts +299 -0
- package/src/grpc-transport-node-http2.ts +234 -0
- package/src/grpc-transport.ts +118 -0
- package/src/hpack.ts +331 -0
- package/src/index.ts +31 -0
- package/src/pagination.ts +368 -94
- package/src/plain-values.ts +41 -0
- package/src/protobuf.ts +1332 -0
- package/src/protocol-grpc.ts +641 -0
- package/src/protocol-http.ts +622 -322
- package/src/protocol-rest.ts +440 -227
- package/src/query.ts +39 -0
- package/src/response-validation-strict.ts +327 -0
- package/src/response-validation.ts +161 -0
- package/src/retry-after.ts +7 -13
- package/src/retry.ts +96 -110
- 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 +259 -15
- package/src/sdk-error.ts +33 -0
- package/src/sensitive.ts +154 -0
- package/src/telemetry-debug.ts +179 -0
- package/src/telemetry-hooks.ts +33 -0
- package/src/telemetry-host-rules.ts +39 -0
- package/src/telemetry-lambda-context.ts +46 -0
- package/src/telemetry-message-context.ts +170 -0
- package/src/telemetry-metrics.ts +69 -0
- package/src/telemetry-name-template.ts +26 -0
- package/src/telemetry-stream.ts +100 -0
- package/src/telemetry-xray.ts +66 -0
- package/src/telemetry.ts +832 -0
- package/src/trait.ts +106 -67
- package/src/unknown-error.ts +38 -0
- package/src/xml.ts +346 -0
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -29
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -165
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -129
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -105
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -23
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -28
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -334
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -691
- package/lib/codegen/generator.js.map +0 -1
- package/lib/codegen/graph.d.ts +0 -36
- package/lib/codegen/graph.d.ts.map +0 -1
- package/lib/codegen/graph.js +0 -136
- package/lib/codegen/graph.js.map +0 -1
- package/lib/codegen/members.d.ts +0 -25
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -55
- package/lib/codegen/members.js.map +0 -1
- package/lib/codegen/naming.d.ts +0 -29
- package/lib/codegen/naming.d.ts.map +0 -1
- package/lib/codegen/naming.js +0 -74
- package/lib/codegen/naming.js.map +0 -1
- package/lib/codegen/openapi-cli.d.ts +0 -38
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -107
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -115
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1220
- package/lib/codegen/openapi.js.map +0 -1
- package/lib/codegen/operations.d.ts +0 -24
- package/lib/codegen/operations.d.ts.map +0 -1
- package/lib/codegen/operations.js +0 -56
- package/lib/codegen/operations.js.map +0 -1
- package/lib/codegen/pagination.d.ts +0 -39
- package/lib/codegen/pagination.d.ts.map +0 -1
- package/lib/codegen/pagination.js +0 -33
- package/lib/codegen/pagination.js.map +0 -1
- package/lib/codegen/prelude.d.ts +0 -15
- package/lib/codegen/prelude.d.ts.map +0 -1
- package/lib/codegen/prelude.js +0 -60
- package/lib/codegen/prelude.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/json-patch.d.ts +0 -44
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -174
- package/lib/json-patch.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/src/codegen/cli.ts +0 -268
- package/src/codegen/emit.ts +0 -207
- package/src/codegen/format.ts +0 -47
- package/src/codegen/generator.ts +0 -1153
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/members.ts +0 -71
- package/src/codegen/naming.ts +0 -86
- package/src/codegen/openapi-cli.ts +0 -166
- package/src/codegen/openapi.ts +0 -1450
- package/src/codegen/operations.ts +0 -76
- package/src/codegen/pagination.ts +0 -71
- package/src/codegen/prelude.ts +0 -70
- package/src/json-patch.ts +0 -222
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Operation-level smithy helpers for the SDK generators (dev-time only).
|
|
3
|
-
*/
|
|
4
|
-
import { local } from "./naming.ts";
|
|
5
|
-
import type { ShapeMap } from "./graph.ts";
|
|
6
|
-
|
|
7
|
-
export interface OpEntry {
|
|
8
|
-
id: string;
|
|
9
|
-
def: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** All operation shapes, sorted by local name. */
|
|
13
|
-
export const collectOperations = (shapes: ShapeMap): OpEntry[] => {
|
|
14
|
-
const operations: OpEntry[] = [];
|
|
15
|
-
for (const [id, def] of Object.entries(shapes)) {
|
|
16
|
-
if (def.type === "operation") operations.push({ id, def });
|
|
17
|
-
}
|
|
18
|
-
operations.sort((a, b) => local(a.id).localeCompare(local(b.id)));
|
|
19
|
-
return operations;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/** The model's shape namespace (from the first operation, else any shape). */
|
|
23
|
-
export const modelNamespace = (
|
|
24
|
-
operations: readonly OpEntry[],
|
|
25
|
-
shapes: ShapeMap,
|
|
26
|
-
fallback: string,
|
|
27
|
-
): string =>
|
|
28
|
-
operations.length
|
|
29
|
-
? operations[0].id.split("#")[0]
|
|
30
|
-
: (Object.keys(shapes)[0]?.split("#")[0] ?? fallback);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolve an operation's input/output targets, synthesizing an empty named
|
|
34
|
-
* structure for `smithy.api#Unit` so every operation has a shape that can
|
|
35
|
-
* carry operation-level traits (mutates `shapes`).
|
|
36
|
-
*/
|
|
37
|
-
export const ensureNamedIo = (
|
|
38
|
-
shapes: ShapeMap,
|
|
39
|
-
op: OpEntry,
|
|
40
|
-
ns: string,
|
|
41
|
-
): { input: string; output: string } => {
|
|
42
|
-
const opName = local(op.id);
|
|
43
|
-
let input = op.def.input?.target ?? "smithy.api#Unit";
|
|
44
|
-
let output = op.def.output?.target ?? "smithy.api#Unit";
|
|
45
|
-
if (input === "smithy.api#Unit") {
|
|
46
|
-
input = `${ns}#${opName}Request`;
|
|
47
|
-
shapes[input] = { type: "structure", members: {} };
|
|
48
|
-
}
|
|
49
|
-
if (output === "smithy.api#Unit") {
|
|
50
|
-
output = `${ns}#${opName}Response`;
|
|
51
|
-
shapes[output] = { type: "structure", members: {} };
|
|
52
|
-
}
|
|
53
|
-
return { input, output };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Every error shape id referenced by the operations' `errors` lists —
|
|
58
|
-
* deduplicated, existing in the model, sorted by local name.
|
|
59
|
-
*/
|
|
60
|
-
export const collectOpErrorIds = (
|
|
61
|
-
operations: readonly OpEntry[],
|
|
62
|
-
shapes: ShapeMap,
|
|
63
|
-
): string[] => {
|
|
64
|
-
const errorIds: string[] = [];
|
|
65
|
-
const seen = new Set<string>();
|
|
66
|
-
for (const op of operations) {
|
|
67
|
-
for (const e of op.def.errors ?? []) {
|
|
68
|
-
if (!seen.has(e.target) && shapes[e.target]) {
|
|
69
|
-
seen.add(e.target);
|
|
70
|
-
errorIds.push(e.target);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
errorIds.sort((a, b) => local(a).localeCompare(local(b)));
|
|
75
|
-
return errorIds;
|
|
76
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared pagination-trait handling for the SDK generators (dev-time only).
|
|
3
|
-
*
|
|
4
|
-
* Both SDKs source `smithy.api#paginated`; AWS merges operation-level
|
|
5
|
-
* config over service-level defaults, cloudflare validates the trait
|
|
6
|
-
* against the operation's actual members (degrading to a plain op when it
|
|
7
|
-
* can't work). Both behaviors live here.
|
|
8
|
-
*/
|
|
9
|
-
import type { PaginatedTrait } from "../pagination.ts";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Merge an operation-level paginated trait over service-level defaults
|
|
13
|
-
* (Smithy semantics: operations may specify partial pagination and inherit
|
|
14
|
-
* the rest from the service).
|
|
15
|
-
*/
|
|
16
|
-
export const mergePaginated = (
|
|
17
|
-
op: Partial<PaginatedTrait> | undefined,
|
|
18
|
-
service: Partial<PaginatedTrait> | undefined,
|
|
19
|
-
): PaginatedTrait | undefined => {
|
|
20
|
-
if (!op) return undefined;
|
|
21
|
-
const merged = {
|
|
22
|
-
mode: op.mode ?? service?.mode,
|
|
23
|
-
inputToken: op.inputToken ?? service?.inputToken,
|
|
24
|
-
outputToken: op.outputToken ?? service?.outputToken,
|
|
25
|
-
items: op.items ?? service?.items,
|
|
26
|
-
pageSize: op.pageSize ?? service?.pageSize,
|
|
27
|
-
};
|
|
28
|
-
return Object.fromEntries(
|
|
29
|
-
Object.entries(merged).filter(([, v]) => v !== undefined),
|
|
30
|
-
) as PaginatedTrait;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export interface ValidatePaginatedOptions {
|
|
34
|
-
readonly trait: Partial<PaginatedTrait>;
|
|
35
|
-
/** TS-facing member names of the operation input shape. */
|
|
36
|
-
readonly inputNames: ReadonlySet<string>;
|
|
37
|
-
/** TS-facing member names of the operation output shape. */
|
|
38
|
-
readonly outputNames: ReadonlySet<string>;
|
|
39
|
-
/** Items path fallback when the trait omits `items` (e.g. `"result"`). */
|
|
40
|
-
readonly itemsFallback?: string;
|
|
41
|
-
/** Output names accepted even when not modeled (e.g. `"resultInfo"`). */
|
|
42
|
-
readonly syntheticOutputs?: ReadonlySet<string>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface ValidatedPagination {
|
|
46
|
-
readonly ok: boolean;
|
|
47
|
-
/** Root member of the items path (`"result.items"` → `"result"`). */
|
|
48
|
-
readonly itemsRoot: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* A paginated op must actually carry its page/cursor token on the input
|
|
53
|
-
* and its items member on the output — otherwise `.pages()` would loop or
|
|
54
|
-
* yield nothing. Returns the items-path root for emitters that promote it
|
|
55
|
-
* to required.
|
|
56
|
-
*/
|
|
57
|
-
export const validatePaginated = (
|
|
58
|
-
o: ValidatePaginatedOptions,
|
|
59
|
-
): ValidatedPagination => {
|
|
60
|
-
const itemsRoot = String(o.trait.items ?? o.itemsFallback ?? "").split(
|
|
61
|
-
".",
|
|
62
|
-
)[0];
|
|
63
|
-
const tokenOk =
|
|
64
|
-
o.trait.mode === "single" ||
|
|
65
|
-
(typeof o.trait.inputToken === "string" &&
|
|
66
|
-
o.inputNames.has(o.trait.inputToken));
|
|
67
|
-
const itemsOk =
|
|
68
|
-
o.outputNames.has(itemsRoot) ||
|
|
69
|
-
(o.syntheticOutputs?.has(itemsRoot) ?? false);
|
|
70
|
-
return { ok: tokenOk && itemsOk, itemsRoot };
|
|
71
|
-
};
|
package/src/codegen/prelude.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Smithy prelude scalar baselines + reference resolvers for the SDK
|
|
3
|
-
* generators (dev-time only).
|
|
4
|
-
*
|
|
5
|
-
* The JSON flavor maps timestamps/blobs to plain strings — the baseline for
|
|
6
|
-
* SDKs whose wire format is JSON-over-docs (cloudflare). Generators with
|
|
7
|
-
* richer models (AWS) emit real timestamp/blob schemas themselves and only
|
|
8
|
-
* fall back here for untyped scalars.
|
|
9
|
-
*/
|
|
10
|
-
import { isPrelude, local } from "./naming.ts";
|
|
11
|
-
import { isForwardRef } from "./graph.ts";
|
|
12
|
-
|
|
13
|
-
/** Prelude shape → schema expression (JSON-wire flavor). */
|
|
14
|
-
export const JSON_PRELUDE: Record<string, string> = {
|
|
15
|
-
String: "S.String",
|
|
16
|
-
Boolean: "S.Boolean",
|
|
17
|
-
Double: "S.Number",
|
|
18
|
-
Float: "S.Number",
|
|
19
|
-
Integer: "S.Number",
|
|
20
|
-
Long: "S.Number",
|
|
21
|
-
BigInteger: "S.Number",
|
|
22
|
-
BigDecimal: "S.Number",
|
|
23
|
-
Timestamp: "S.String",
|
|
24
|
-
Blob: "S.String",
|
|
25
|
-
Document: "S.Unknown",
|
|
26
|
-
Unit: "S.Struct({})",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/** TypeScript type for each prelude shape, mirroring {@link JSON_PRELUDE}. */
|
|
30
|
-
export const TS_JSON_PRELUDE: Record<string, string> = {
|
|
31
|
-
String: "string",
|
|
32
|
-
Boolean: "boolean",
|
|
33
|
-
Double: "number",
|
|
34
|
-
Float: "number",
|
|
35
|
-
Integer: "number",
|
|
36
|
-
Long: "number",
|
|
37
|
-
BigInteger: "number",
|
|
38
|
-
BigDecimal: "number",
|
|
39
|
-
Timestamp: "string",
|
|
40
|
-
Blob: "string",
|
|
41
|
-
Document: "unknown",
|
|
42
|
-
Unit: "{}",
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Schema reference resolver: prelude shapes map through the prelude table,
|
|
47
|
-
* forward references (including into cycles) wrap in `S.suspend`.
|
|
48
|
-
*/
|
|
49
|
-
export const makeSchemaRef =
|
|
50
|
-
(
|
|
51
|
-
prelude: Record<string, string>,
|
|
52
|
-
indexOf: ReadonlyMap<string, number>,
|
|
53
|
-
): ((target: string, selfIdx: number) => string) =>
|
|
54
|
-
(target, selfIdx) => {
|
|
55
|
-
if (isPrelude(target)) return prelude[local(target)] ?? "S.Unknown";
|
|
56
|
-
const name = local(target);
|
|
57
|
-
if (isForwardRef(indexOf, target, selfIdx)) {
|
|
58
|
-
return `S.suspend(() => ${name})`;
|
|
59
|
-
}
|
|
60
|
-
return name;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* TypeScript type reference resolver. Named shapes all get an emitted
|
|
65
|
-
* interface / type alias, so forward references are always fine.
|
|
66
|
-
*/
|
|
67
|
-
export const makeTsRef =
|
|
68
|
-
(tsPrelude: Record<string, string>): ((target: string) => string) =>
|
|
69
|
-
(target) =>
|
|
70
|
-
isPrelude(target) ? (tsPrelude[local(target)] ?? "unknown") : local(target);
|
package/src/json-patch.ts
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JSON Patch (RFC 6902) Implementation
|
|
3
|
-
*
|
|
4
|
-
* Provides a unified spec patching system for all SDKs. Patches are applied to
|
|
5
|
-
* generated intermediary specs (Smithy models, OpenAPI docs, …) before code
|
|
6
|
-
* generation to add typed error shapes, rename operations, mark nullable
|
|
7
|
-
* fields, etc. Ported from the distilled repo's `core/json-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
|
-
// ============================================================================
|
|
14
|
-
// Types
|
|
15
|
-
// ============================================================================
|
|
16
|
-
|
|
17
|
-
export interface JsonPatchOperation {
|
|
18
|
-
op: "add" | "remove" | "replace" | "move" | "copy" | "test";
|
|
19
|
-
path: string;
|
|
20
|
-
value?: unknown;
|
|
21
|
-
from?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type JsonPatch = JsonPatchOperation[];
|
|
25
|
-
|
|
26
|
-
export interface PatchFile {
|
|
27
|
-
description?: string;
|
|
28
|
-
patches: JsonPatch;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// JSON Pointer (RFC 6901)
|
|
33
|
-
// ============================================================================
|
|
34
|
-
|
|
35
|
-
/** Parse a JSON Pointer (RFC 6901) path into segments. */
|
|
36
|
-
export function parseJsonPointer(pointer: string): string[] {
|
|
37
|
-
if (pointer === "") return [];
|
|
38
|
-
if (!pointer.startsWith("/")) {
|
|
39
|
-
throw new Error(`Invalid JSON Pointer: ${pointer}`);
|
|
40
|
-
}
|
|
41
|
-
return pointer
|
|
42
|
-
.slice(1)
|
|
43
|
-
.split("/")
|
|
44
|
-
.map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Get a value at a JSON Pointer path. */
|
|
48
|
-
export function getValueAtPath(obj: unknown, pointer: string): unknown {
|
|
49
|
-
const segments = parseJsonPointer(pointer);
|
|
50
|
-
let current: unknown = obj;
|
|
51
|
-
|
|
52
|
-
for (const segment of segments) {
|
|
53
|
-
if (current === null || typeof current !== "object") {
|
|
54
|
-
throw new Error(`Cannot traverse path ${pointer}: not an object`);
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(current)) {
|
|
57
|
-
const index = segment === "-" ? current.length : parseInt(segment, 10);
|
|
58
|
-
current = current[index];
|
|
59
|
-
} else {
|
|
60
|
-
current = (current as Record<string, unknown>)[segment];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return current;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Set a value at a JSON Pointer path. */
|
|
68
|
-
export function setValueAtPath(
|
|
69
|
-
obj: unknown,
|
|
70
|
-
pointer: string,
|
|
71
|
-
value: unknown,
|
|
72
|
-
): void {
|
|
73
|
-
const segments = parseJsonPointer(pointer);
|
|
74
|
-
if (segments.length === 0) {
|
|
75
|
-
throw new Error("Cannot set value at root path");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let current: unknown = obj;
|
|
79
|
-
|
|
80
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
81
|
-
const segment = segments[i]!;
|
|
82
|
-
if (current === null || typeof current !== "object") {
|
|
83
|
-
throw new Error(`Cannot traverse path ${pointer}: not an object`);
|
|
84
|
-
}
|
|
85
|
-
if (Array.isArray(current)) {
|
|
86
|
-
current = current[parseInt(segment, 10)];
|
|
87
|
-
} else {
|
|
88
|
-
current = (current as Record<string, unknown>)[segment];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const lastSegment = segments[segments.length - 1]!;
|
|
93
|
-
if (current === null || typeof current !== "object") {
|
|
94
|
-
throw new Error(
|
|
95
|
-
`Cannot set value at path ${pointer}: parent is not an object`,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (Array.isArray(current)) {
|
|
100
|
-
if (lastSegment === "-") {
|
|
101
|
-
current.push(value);
|
|
102
|
-
} else {
|
|
103
|
-
current[parseInt(lastSegment, 10)] = value;
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
(current as Record<string, unknown>)[lastSegment] = value;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Remove a value at a JSON Pointer path. */
|
|
111
|
-
export function removeValueAtPath(obj: unknown, pointer: string): void {
|
|
112
|
-
const segments = parseJsonPointer(pointer);
|
|
113
|
-
if (segments.length === 0) {
|
|
114
|
-
throw new Error("Cannot remove root");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let current: unknown = obj;
|
|
118
|
-
|
|
119
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
120
|
-
const segment = segments[i]!;
|
|
121
|
-
if (current === null || typeof current !== "object") {
|
|
122
|
-
throw new Error(`Cannot traverse path ${pointer}: not an object`);
|
|
123
|
-
}
|
|
124
|
-
if (Array.isArray(current)) {
|
|
125
|
-
current = current[parseInt(segment, 10)];
|
|
126
|
-
} else {
|
|
127
|
-
current = (current as Record<string, unknown>)[segment];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const lastSegment = segments[segments.length - 1]!;
|
|
132
|
-
if (current === null || typeof current !== "object") {
|
|
133
|
-
throw new Error(
|
|
134
|
-
`Cannot remove at path ${pointer}: parent is not an object`,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (Array.isArray(current)) {
|
|
139
|
-
current.splice(parseInt(lastSegment, 10), 1);
|
|
140
|
-
} else {
|
|
141
|
-
delete (current as Record<string, unknown>)[lastSegment];
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ============================================================================
|
|
146
|
-
// Patch Operations
|
|
147
|
-
// ============================================================================
|
|
148
|
-
|
|
149
|
-
/** Apply a single JSON Patch operation (mutates `obj` in place). */
|
|
150
|
-
export function applyOperation(
|
|
151
|
-
obj: unknown,
|
|
152
|
-
operation: JsonPatchOperation,
|
|
153
|
-
): void {
|
|
154
|
-
switch (operation.op) {
|
|
155
|
-
case "add":
|
|
156
|
-
setValueAtPath(obj, operation.path, operation.value);
|
|
157
|
-
break;
|
|
158
|
-
case "remove":
|
|
159
|
-
removeValueAtPath(obj, operation.path);
|
|
160
|
-
break;
|
|
161
|
-
case "replace":
|
|
162
|
-
// For replace, the path must exist
|
|
163
|
-
getValueAtPath(obj, operation.path); // throws if doesn't exist
|
|
164
|
-
setValueAtPath(obj, operation.path, operation.value);
|
|
165
|
-
break;
|
|
166
|
-
case "move": {
|
|
167
|
-
if (!operation.from) throw new Error("move operation requires 'from'");
|
|
168
|
-
const moveValue = getValueAtPath(obj, operation.from);
|
|
169
|
-
if (moveValue === undefined) {
|
|
170
|
-
throw new Error(
|
|
171
|
-
`Cannot move from path ${operation.from}: not an object`,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
removeValueAtPath(obj, operation.from);
|
|
175
|
-
setValueAtPath(obj, operation.path, moveValue);
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
case "copy": {
|
|
179
|
-
if (!operation.from) throw new Error("copy operation requires 'from'");
|
|
180
|
-
const copyValue = getValueAtPath(obj, operation.from);
|
|
181
|
-
setValueAtPath(
|
|
182
|
-
obj,
|
|
183
|
-
operation.path,
|
|
184
|
-
JSON.parse(JSON.stringify(copyValue)),
|
|
185
|
-
);
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
case "test": {
|
|
189
|
-
const testValue = getValueAtPath(obj, operation.path);
|
|
190
|
-
if (JSON.stringify(testValue) !== JSON.stringify(operation.value)) {
|
|
191
|
-
throw new Error(
|
|
192
|
-
`Test operation failed at ${operation.path}: expected ${JSON.stringify(operation.value)}, got ${JSON.stringify(testValue)}`,
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
default:
|
|
198
|
-
throw new Error(`Unknown operation: ${(operation as { op: string }).op}`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** Apply a JSON Patch to an object (mutates in place). */
|
|
203
|
-
export function applyPatch(obj: unknown, patch: JsonPatch): void {
|
|
204
|
-
for (const operation of patch) {
|
|
205
|
-
applyOperation(obj, operation);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Whether a per-operation failure is caused by the target location being
|
|
211
|
-
* absent from the spec (i.e. spec drift — the operation/shape the patch
|
|
212
|
-
* targets was renamed or removed upstream) as opposed to a malformed patch.
|
|
213
|
-
* Stale targets should be skipped with a warning rather than aborting the
|
|
214
|
-
* whole generate; a patch that only adds an error to an operation that no
|
|
215
|
-
* longer exists is harmless to drop.
|
|
216
|
-
*/
|
|
217
|
-
export function isStaleTargetError(message: string): boolean {
|
|
218
|
-
return (
|
|
219
|
-
message.includes("not an object") ||
|
|
220
|
-
message.includes("parent is not an object")
|
|
221
|
-
);
|
|
222
|
-
}
|