@distilled.cloud/core 1.0.0-rc.16 → 1.0.0-rc.18
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/annotations.d.ts +15 -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 +15 -0
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -796
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +1 -278
- package/lib/chunks.js +1 -11
- package/lib/config.d.ts +54 -13
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -161
- package/lib/crypto.js +1 -130
- package/lib/debug.d.ts.map +1 -1
- package/lib/debug.js +1 -8
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js +1 -47
- package/lib/errors.d.ts +2 -13
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -198
- package/lib/graphql.d.ts +14 -0
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +1 -1058
- package/lib/graphql.types.js +1 -6
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -15
- package/lib/pagination.d.ts +34 -2
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -271
- package/lib/plain-values.js +1 -39
- package/lib/plain-values.js.map +1 -1
- package/lib/protocol-http.d.ts +30 -6
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -812
- package/lib/protocol-rest.d.ts +53 -39
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -375
- package/lib/query.js +1 -27
- package/lib/response-validation-strict.js +1 -284
- package/lib/response-validation.d.ts +4 -3
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js +1 -118
- package/lib/retry-after.js +1 -112
- package/lib/retry.js +1 -197
- package/lib/schema-lite-impl.js +1 -341
- package/lib/schema-lite-typed.js +1 -27
- package/lib/schema-lite.js +1 -31
- package/lib/schema.js +1 -220
- package/lib/telemetry-debug.d.ts +14 -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 +9 -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 +269 -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.js +1 -131
- package/lib/xml.js +1 -323
- package/package.json +1 -3
- package/src/annotations.ts +37 -0
- package/src/api.ts +130 -30
- package/src/category.ts +21 -22
- package/src/config.ts +58 -29
- package/src/debug.ts +9 -6
- package/src/error-category.ts +12 -14
- package/src/errors.ts +7 -7
- package/src/graphql.ts +123 -18
- package/src/index.ts +3 -2
- package/src/pagination.ts +119 -6
- package/src/protocol-http.ts +63 -43
- package/src/protocol-rest.ts +201 -140
- package/src/response-validation.ts +4 -3
- package/src/telemetry-debug.ts +135 -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 +91 -0
- package/src/telemetry-xray.ts +66 -0
- package/src/telemetry.ts +768 -0
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/chunks.js.map +0 -1
- package/lib/codegen/boolean-string-enums.d.ts +0 -36
- package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.js +0 -147
- package/lib/codegen/boolean-string-enums.js.map +0 -1
- package/lib/codegen/chunk.d.ts +0 -7
- package/lib/codegen/chunk.d.ts.map +0 -1
- package/lib/codegen/chunk.js +0 -139
- package/lib/codegen/chunk.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -80
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -166
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/datafy.d.ts +0 -14
- package/lib/codegen/datafy.d.ts.map +0 -1
- package/lib/codegen/datafy.js +0 -853
- package/lib/codegen/datafy.js.map +0 -1
- package/lib/codegen/dedupe.d.ts +0 -5
- package/lib/codegen/dedupe.d.ts.map +0 -1
- package/lib/codegen/dedupe.js +0 -153
- package/lib/codegen/dedupe.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -125
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -99
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -11
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -32
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generated-at.d.ts +0 -29
- package/lib/codegen/generated-at.d.ts.map +0 -1
- package/lib/codegen/generated-at.js +0 -78
- package/lib/codegen/generated-at.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -353
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -810
- 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/graphql-client.d.ts +0 -70
- package/lib/codegen/graphql-client.d.ts.map +0 -1
- package/lib/codegen/graphql-client.js +0 -439
- package/lib/codegen/graphql-client.js.map +0 -1
- package/lib/codegen/graphql.d.ts +0 -207
- package/lib/codegen/graphql.d.ts.map +0 -1
- package/lib/codegen/graphql.js +0 -786
- package/lib/codegen/graphql.js.map +0 -1
- package/lib/codegen/latin1.d.ts +0 -3
- package/lib/codegen/latin1.d.ts.map +0 -1
- package/lib/codegen/latin1.js +0 -126
- package/lib/codegen/latin1.js.map +0 -1
- package/lib/codegen/members.d.ts +0 -32
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -62
- package/lib/codegen/members.js.map +0 -1
- package/lib/codegen/model-diff.d.ts +0 -10
- package/lib/codegen/model-diff.d.ts.map +0 -1
- package/lib/codegen/model-diff.js +0 -67
- package/lib/codegen/model-diff.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 -52
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -84
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -209
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1548
- 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 -31
- package/lib/codegen/pagination.js.map +0 -1
- package/lib/codegen/patch-audit.d.ts +0 -84
- package/lib/codegen/patch-audit.d.ts.map +0 -1
- package/lib/codegen/patch-audit.js +0 -366
- package/lib/codegen/patch-audit.js.map +0 -1
- package/lib/codegen/patches.d.ts +0 -129
- package/lib/codegen/patches.d.ts.map +0 -1
- package/lib/codegen/patches.js +0 -472
- package/lib/codegen/patches.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/codegen/privatize.d.ts +0 -21
- package/lib/codegen/privatize.d.ts.map +0 -1
- package/lib/codegen/privatize.js +0 -176
- package/lib/codegen/privatize.js.map +0 -1
- package/lib/codegen/proto.d.ts +0 -121
- package/lib/codegen/proto.d.ts.map +0 -1
- package/lib/codegen/proto.js +0 -960
- package/lib/codegen/proto.js.map +0 -1
- package/lib/codegen/pure.d.ts +0 -6
- package/lib/codegen/pure.d.ts.map +0 -1
- package/lib/codegen/pure.js +0 -91
- package/lib/codegen/pure.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
- package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.js +0 -1117
- package/lib/codegen/rewrite-operation-ids.js.map +0 -1
- package/lib/codegen/spec-path.d.ts +0 -16
- package/lib/codegen/spec-path.d.ts.map +0 -1
- package/lib/codegen/spec-path.js +0 -101
- package/lib/codegen/spec-path.js.map +0 -1
- package/lib/codegen/table.d.ts +0 -5
- package/lib/codegen/table.d.ts.map +0 -1
- package/lib/codegen/table.js +0 -249
- package/lib/codegen/table.js.map +0 -1
- package/lib/config.js.map +0 -1
- package/lib/crypto.js.map +0 -1
- package/lib/debug.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/graphql.js.map +0 -1
- package/lib/graphql.types.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/json-patch.d.ts +0 -58
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -227
- 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/query.js.map +0 -1
- package/lib/response-validation-strict.js.map +0 -1
- package/lib/response-validation.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/schema-lite-impl.js.map +0 -1
- package/lib/schema-lite-typed.js.map +0 -1
- package/lib/schema-lite.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/testing.d.ts +0 -40
- package/lib/testing.d.ts.map +0 -1
- package/lib/testing.js +0 -42
- package/lib/testing.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/lib/xml.js.map +0 -1
- package/src/codegen/boolean-string-enums.ts +0 -155
- package/src/codegen/chunk.ts +0 -147
- package/src/codegen/cli.ts +0 -293
- package/src/codegen/datafy.ts +0 -874
- package/src/codegen/dedupe.ts +0 -173
- package/src/codegen/emit.ts +0 -200
- package/src/codegen/format.ts +0 -49
- package/src/codegen/generated-at.ts +0 -88
- package/src/codegen/generator.ts +0 -1229
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/graphql-client.ts +0 -545
- package/src/codegen/graphql.ts +0 -1145
- package/src/codegen/latin1.ts +0 -131
- package/src/codegen/members.ts +0 -79
- package/src/codegen/model-diff.ts +0 -67
- package/src/codegen/naming.ts +0 -85
- package/src/codegen/openapi-cli.ts +0 -141
- package/src/codegen/openapi.ts +0 -1845
- package/src/codegen/operations.ts +0 -73
- package/src/codegen/pagination.ts +0 -64
- package/src/codegen/patch-audit.ts +0 -480
- package/src/codegen/patches.ts +0 -581
- package/src/codegen/prelude.ts +0 -70
- package/src/codegen/privatize.ts +0 -200
- package/src/codegen/proto.ts +0 -1092
- package/src/codegen/pure.ts +0 -94
- package/src/codegen/rewrite-operation-ids.ts +0 -1219
- package/src/codegen/spec-path.ts +0 -112
- package/src/codegen/table.ts +0 -254
- package/src/json-patch.ts +0 -273
- package/src/testing.ts +0 -74
package/src/codegen/cli.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The generic generator CLI harness (dev-time only).
|
|
3
|
-
*
|
|
4
|
-
* Owns the smithy→SDK pipeline every SDK package shares: scan the model
|
|
5
|
-
* directory (plus optional hand-authored manual specs), compile each model
|
|
6
|
-
* through {@link generateService} with the provider's {@link SdkSpec}, write
|
|
7
|
-
* the service modules and the namespaced barrel. Patches are already in
|
|
8
|
-
* `.generated-specs` (convert applies them, see `codegen/patches`).
|
|
9
|
-
*
|
|
10
|
-
* A provider's `scripts/generate.ts` is: trait consts + an SdkSpec + a
|
|
11
|
-
* `runGeneratorCli` call.
|
|
12
|
-
*/
|
|
13
|
-
import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
14
|
-
import { Console, Effect } from "effect";
|
|
15
|
-
import { Flag } from "effect/cli";
|
|
16
|
-
import { Command } from "effect/cli";
|
|
17
|
-
import * as FileSystem from "effect/FileSystem";
|
|
18
|
-
import * as Path from "effect/Path";
|
|
19
|
-
import { chunkSchemas } from "./chunk.ts";
|
|
20
|
-
import { dedupeSchemas } from "./dedupe.ts";
|
|
21
|
-
import { barrel } from "./emit.ts";
|
|
22
|
-
import { formatGenerated } from "./format.ts";
|
|
23
|
-
import { stampGeneratedAt } from "./generated-at.ts";
|
|
24
|
-
import { generateService, type SdkSpec } from "./generator.ts";
|
|
25
|
-
import { toLatin1 } from "./latin1.ts";
|
|
26
|
-
import { privatizeSchemas, typeOnlyNamespaceImports } from "./privatize.ts";
|
|
27
|
-
import { annotateNestedCalls } from "./pure.ts";
|
|
28
|
-
import { tableSchemas } from "./table.ts";
|
|
29
|
-
|
|
30
|
-
export interface GeneratorCliOptions {
|
|
31
|
-
/** Command description shown in --help. */
|
|
32
|
-
readonly description: string;
|
|
33
|
-
/** Absolute package root (usually `path.resolve(import.meta.dirname, "..")`). */
|
|
34
|
-
readonly root: string;
|
|
35
|
-
/** Model directory default (relative to root). Default `.generated-specs`. */
|
|
36
|
-
readonly smithyDir?: string;
|
|
37
|
-
/** Output directory default (relative to root). Default `src/services`. */
|
|
38
|
-
readonly outDir?: string;
|
|
39
|
-
/** Model files to skip (e.g. a shared protocols model). */
|
|
40
|
-
readonly excludeModel?: (file: string) => boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Where the models are, when they aren't a flat directory of `<resource>.json`.
|
|
43
|
-
* AWS vendors Amazon's own repo, whose models sit at
|
|
44
|
-
* `models/<service>/service/<version>/<service>-<version>.json`.
|
|
45
|
-
*
|
|
46
|
-
* Returns the model files to compile; manual specs are merged in after,
|
|
47
|
-
* as usual.
|
|
48
|
-
*/
|
|
49
|
-
readonly discoverModels?: (ctx: {
|
|
50
|
-
readonly smithyDir: string;
|
|
51
|
-
}) => Effect.Effect<
|
|
52
|
-
ReadonlyArray<{ readonly file: string; readonly dir: string }>,
|
|
53
|
-
never,
|
|
54
|
-
FileSystem.FileSystem | Path.Path
|
|
55
|
-
>;
|
|
56
|
-
/**
|
|
57
|
-
* Side effects to run before generating — e.g. AWS copies `partitions.json`
|
|
58
|
-
* out of the smithy submodule, runtime data its endpoint resolver reads.
|
|
59
|
-
*/
|
|
60
|
-
readonly prepare?: (ctx: {
|
|
61
|
-
readonly root: string;
|
|
62
|
-
readonly outDir: string;
|
|
63
|
-
}) => Effect.Effect<void, never, FileSystem.FileSystem | Path.Path>;
|
|
64
|
-
/**
|
|
65
|
-
* The output module's name, when it isn't the model's filename. AWS names
|
|
66
|
-
* modules after the service's `aws.api#service` sdkId (`amazon-s3.json` →
|
|
67
|
-
* `s3.ts`), so the public surface reads `AWS.S3.getObject`.
|
|
68
|
-
*/
|
|
69
|
-
readonly resourceName?: (ctx: { readonly model: any; readonly file: string }) => string;
|
|
70
|
-
/** Barrel export name for a resource. Default: the resource name itself. */
|
|
71
|
-
readonly barrelExportName?: (resource: string) => string;
|
|
72
|
-
/**
|
|
73
|
-
* The closing pass over the output directory. Defaults to formatting;
|
|
74
|
-
* AWS lint-fixes first (see `codegen/format.ts`).
|
|
75
|
-
*/
|
|
76
|
-
readonly finalize?: (dir: string) => Effect.Effect<void>;
|
|
77
|
-
/**
|
|
78
|
-
* Keep generating after a model fails, instead of stopping at the first.
|
|
79
|
-
* AWS compiles 430 services in one run, and one broken model shouldn't
|
|
80
|
-
* hide the state of the other 429. The run still FAILS at the end — the
|
|
81
|
-
* failures are reported together rather than swallowed.
|
|
82
|
-
*/
|
|
83
|
-
readonly continueOnModelError?: boolean;
|
|
84
|
-
/** Directory of hand-authored models merged after the generated ones. */
|
|
85
|
-
readonly manualSpecsDir?: string;
|
|
86
|
-
/**
|
|
87
|
-
* Generate never applies patches: convert does, so `.generated-specs` is
|
|
88
|
-
* the patched model. Only `false` is accepted so a path is a type error
|
|
89
|
-
* rather than a silently ignored setting.
|
|
90
|
-
*/
|
|
91
|
-
readonly patchesDir?: false;
|
|
92
|
-
/**
|
|
93
|
-
* Model transform applied before generation (e.g. AWS dropping
|
|
94
|
-
* unreachable foreign-namespace shapes from a vendored model). Does not
|
|
95
|
-
* write back to `.generated-specs` — convert owns the committed model.
|
|
96
|
-
*/
|
|
97
|
-
readonly transformModel?: (model: any, resource: string) => string | void;
|
|
98
|
-
/** The provider spec — built per model (metadata may vary per model). */
|
|
99
|
-
readonly spec: (model: any) => SdkSpec;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Run the generator CLI (NodeRuntime main — call at module top level). */
|
|
103
|
-
export const runGeneratorCli = (options: GeneratorCliOptions): void => {
|
|
104
|
-
const command = Command.make(
|
|
105
|
-
"generate",
|
|
106
|
-
{
|
|
107
|
-
smithy: Flag.String("smithy").pipe(
|
|
108
|
-
Flag.withDefault(options.smithyDir ?? ".generated-specs"),
|
|
109
|
-
Flag.withDescription("Directory of Smithy JSON models"),
|
|
110
|
-
),
|
|
111
|
-
out: Flag.String("out").pipe(
|
|
112
|
-
Flag.withDefault(options.outDir ?? "src/services"),
|
|
113
|
-
Flag.withDescription("Output directory for generated service modules"),
|
|
114
|
-
),
|
|
115
|
-
resource: Flag.String("resource").pipe(
|
|
116
|
-
Flag.withDefault(""),
|
|
117
|
-
Flag.withDescription("Only generate this resource (e.g. ai)"),
|
|
118
|
-
),
|
|
119
|
-
},
|
|
120
|
-
(config) =>
|
|
121
|
-
Effect.gen(function* () {
|
|
122
|
-
const fs = yield* FileSystem.FileSystem;
|
|
123
|
-
const path = yield* Path.Path;
|
|
124
|
-
const root = options.root;
|
|
125
|
-
const smithyDir = path.resolve(root, config.smithy);
|
|
126
|
-
const outDir = path.resolve(root, config.out);
|
|
127
|
-
|
|
128
|
-
yield* Console.log("⚙️ generate");
|
|
129
|
-
yield* Console.log(` Smithy: ${smithyDir}`);
|
|
130
|
-
yield* Console.log(` Output: ${outDir}`);
|
|
131
|
-
|
|
132
|
-
yield* options.prepare?.({ root, outDir }) ?? Effect.void;
|
|
133
|
-
|
|
134
|
-
// Generated models plus optional manual-specs (hand-authored models
|
|
135
|
-
// for APIs the provider's spec source doesn't cover). A manual model
|
|
136
|
-
// must not shadow a generated one.
|
|
137
|
-
const generated = options.discoverModels
|
|
138
|
-
? yield* options.discoverModels({ smithyDir })
|
|
139
|
-
: (yield* fs.readDirectory(smithyDir))
|
|
140
|
-
.filter((f) => f.endsWith(".json") && !(options.excludeModel?.(f) ?? false))
|
|
141
|
-
.map((f) => ({ file: f, dir: smithyDir }));
|
|
142
|
-
const manualDir = options.manualSpecsDir
|
|
143
|
-
? path.resolve(root, options.manualSpecsDir)
|
|
144
|
-
: undefined;
|
|
145
|
-
const manual =
|
|
146
|
-
manualDir && (yield* fs.exists(manualDir))
|
|
147
|
-
? (yield* fs.readDirectory(manualDir))
|
|
148
|
-
.filter((f) => f.endsWith(".json"))
|
|
149
|
-
.map((f) => ({ file: f, dir: manualDir }))
|
|
150
|
-
: [];
|
|
151
|
-
for (const m of manual) {
|
|
152
|
-
if (generated.some((g) => g.file === m.file)) {
|
|
153
|
-
return yield* Effect.die(
|
|
154
|
-
new Error(
|
|
155
|
-
`${options.manualSpecsDir}/${m.file} shadows a generated model — rename or delete it`,
|
|
156
|
-
),
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
const entries = [...generated, ...manual].sort((a, b) => a.file.localeCompare(b.file));
|
|
161
|
-
|
|
162
|
-
yield* fs.makeDirectory(outDir, { recursive: true });
|
|
163
|
-
|
|
164
|
-
const written: string[] = [];
|
|
165
|
-
const failedModels: string[] = [];
|
|
166
|
-
let totalOps = 0;
|
|
167
|
-
|
|
168
|
-
for (const { file, dir } of entries) {
|
|
169
|
-
const model = JSON.parse(yield* fs.readFileString(path.join(dir, file)));
|
|
170
|
-
// The module's name — the model's filename unless the provider
|
|
171
|
-
// derives it from the model itself (AWS: the service's sdkId).
|
|
172
|
-
const resource = options.resourceName?.({ model, file }) ?? file.replace(/\.json$/, "");
|
|
173
|
-
if (config.resource && resource !== config.resource) continue;
|
|
174
|
-
|
|
175
|
-
if (options.transformModel) {
|
|
176
|
-
const note = options.transformModel(model, resource);
|
|
177
|
-
if (note) yield* Console.log(` ${note}`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// `generateService` and the provider spec are synchronous and
|
|
181
|
-
// throw; with continueOnModelError the throw is recorded and the
|
|
182
|
-
// run moves on, so one broken model doesn't hide the state of
|
|
183
|
-
// every model after it. The run still fails at the end.
|
|
184
|
-
let generated;
|
|
185
|
-
try {
|
|
186
|
-
generated = generateService(model, options.spec(model));
|
|
187
|
-
} catch (e) {
|
|
188
|
-
if (!options.continueOnModelError) throw e;
|
|
189
|
-
failedModels.push(`${resource}: ${e instanceof Error ? e.message : String(e)}`);
|
|
190
|
-
yield* Console.error(`❌ ${resource}`);
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
const { operations } = generated;
|
|
194
|
-
if (operations === 0) continue;
|
|
195
|
-
// Every nested call in a top-level initializer gets a PURE marker,
|
|
196
|
-
// so one unused schema cannot pin others in a consumer's bundle.
|
|
197
|
-
// Latin-1-only source halves the heap V8 keeps for the module text.
|
|
198
|
-
// Structurally identical schemas become aliases of one schema, and
|
|
199
|
-
// schema consts become module-private (types stay exported).
|
|
200
|
-
const resourceFile = `${resource}.ts`;
|
|
201
|
-
const marked = annotateNestedCalls(generated.code, resourceFile);
|
|
202
|
-
const code = toLatin1(
|
|
203
|
-
typeOnlyNamespaceImports(
|
|
204
|
-
tableSchemas(
|
|
205
|
-
chunkSchemas(
|
|
206
|
-
privatizeSchemas(dedupeSchemas(marked, resourceFile).code, resourceFile).code,
|
|
207
|
-
resourceFile,
|
|
208
|
-
).code,
|
|
209
|
-
resourceFile,
|
|
210
|
-
).code,
|
|
211
|
-
resourceFile,
|
|
212
|
-
),
|
|
213
|
-
resourceFile,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
yield* fs.writeFileString(path.join(outDir, `${resource}.ts`), code);
|
|
217
|
-
written.push(resource);
|
|
218
|
-
totalOps += operations;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Barrel — namespace per resource to avoid op-name collisions.
|
|
222
|
-
//
|
|
223
|
-
// A FULL run is authoritative: the barrel is exactly what was
|
|
224
|
-
// generated, so a resource whose model went away drops out of it.
|
|
225
|
-
//
|
|
226
|
-
// A `--resource` run only knows about the resource it generated, so
|
|
227
|
-
// rewriting the barrel from that would delete every other export —
|
|
228
|
-
// which is how #397 shipped a cloudflare barrel exporting `workers`
|
|
229
|
-
// and nothing else, silently dropping 119 services. Merge into the
|
|
230
|
-
// existing barrel instead, so `--resource` can still ADD a brand-new
|
|
231
|
-
// resource without removing anything.
|
|
232
|
-
const barrelPath = path.join(outDir, "index.ts");
|
|
233
|
-
const filtered = config.resource !== "";
|
|
234
|
-
// Sorted, not in generation order: a provider that discovers models
|
|
235
|
-
// in some other order (AWS walks Amazon's directory tree) would
|
|
236
|
-
// otherwise reshuffle the barrel on every run.
|
|
237
|
-
let resources = [...written].sort((a, b) => `${a}.json`.localeCompare(`${b}.json`));
|
|
238
|
-
if (filtered && (yield* fs.exists(barrelPath))) {
|
|
239
|
-
// Recover the RESOURCE from each export line's path, not its name:
|
|
240
|
-
// the two differ when barrelExportName renames (AWS exports
|
|
241
|
-
// `S3` from `./s3.ts`).
|
|
242
|
-
const existing = (yield* fs.readFileString(barrelPath))
|
|
243
|
-
.split("\n")
|
|
244
|
-
.map((line) => /^export \* as \S+ from "\.\/(.+)\.ts";/.exec(line)?.[1])
|
|
245
|
-
.filter((name): name is string => name !== undefined);
|
|
246
|
-
// Ordered exactly as a full run orders it: by MODEL FILENAME, so
|
|
247
|
-
// the `.json` takes part in the collation (`ai_gateway.json` sorts
|
|
248
|
-
// before `ai.json`, where the bare names sort the other way).
|
|
249
|
-
// Otherwise a filtered run reshuffles the barrel into diff noise.
|
|
250
|
-
resources = [...new Set([...existing, ...written])].sort((a, b) =>
|
|
251
|
-
`${a}.json`.localeCompare(`${b}.json`),
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
yield* fs.writeFileString(
|
|
256
|
-
barrelPath,
|
|
257
|
-
barrel(
|
|
258
|
-
`// AUTO-GENERATED by scripts/generate.ts. Do not edit.\n`,
|
|
259
|
-
resources.map((r) => ({
|
|
260
|
-
name: options.barrelExportName?.(r) ?? r,
|
|
261
|
-
path: `./${r}.ts`,
|
|
262
|
-
})),
|
|
263
|
-
),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
yield* (options.finalize ?? formatGenerated)(outDir);
|
|
267
|
-
|
|
268
|
-
yield* Console.log(
|
|
269
|
-
`\n✅ Generated ${totalOps} operations across ${written.length} resource modules.`,
|
|
270
|
-
);
|
|
271
|
-
yield* Console.log(` ${path.join(outDir, "index.ts")}`);
|
|
272
|
-
|
|
273
|
-
// Models that failed under continueOnModelError. Reported together,
|
|
274
|
-
// at the end, and the run FAILS — a generate that couldn't produce
|
|
275
|
-
// a module must not exit 0 with the failure buried in the log.
|
|
276
|
-
if (failedModels.length) {
|
|
277
|
-
yield* Console.error(`\n❌ ${failedModels.length} model(s) failed to generate:`);
|
|
278
|
-
for (const f of failedModels) yield* Console.error(` ${f}`);
|
|
279
|
-
return yield* Effect.die(new Error(`${failedModels.length} model(s) failed to generate`));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const stamp = yield* Effect.sync(() => stampGeneratedAt(root));
|
|
283
|
-
yield* Console.log(` package.json distilled.generatedAt = ${stamp.generatedAt}`);
|
|
284
|
-
yield* Console.log(
|
|
285
|
-
` package.json distilled.specUpdatedAt = ${stamp.specUpdatedAt ?? "(unknown, unchanged)"}`,
|
|
286
|
-
);
|
|
287
|
-
}),
|
|
288
|
-
).pipe(Command.withDescription(options.description));
|
|
289
|
-
|
|
290
|
-
NodeRuntime.runMain(
|
|
291
|
-
Effect.provide(Command.run(command, { version: "1.0.0" }), NodeServices.layer),
|
|
292
|
-
);
|
|
293
|
-
};
|