@distilled.cloud/core 1.0.0-rc.1 → 1.0.0-rc.10
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/api.d.ts.map +1 -1
- package/lib/api.js +16 -4
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts +4 -4
- package/lib/category.js +4 -4
- package/lib/codegen/boolean-string-enums.d.ts +36 -0
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -0
- package/lib/codegen/boolean-string-enums.js +94 -0
- package/lib/codegen/boolean-string-enums.js.map +1 -0
- package/lib/codegen/boolean-string-enums.test.d.ts +2 -0
- package/lib/codegen/boolean-string-enums.test.d.ts.map +1 -0
- package/lib/codegen/boolean-string-enums.test.js +147 -0
- package/lib/codegen/boolean-string-enums.test.js.map +1 -0
- package/lib/codegen/cli.d.ts +56 -6
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +59 -75
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/emit.d.ts +3 -7
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +6 -10
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +142 -20
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts +62 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -0
- package/lib/codegen/graphql-client.js +294 -0
- package/lib/codegen/graphql-client.js.map +1 -0
- package/lib/codegen/graphql-client.test.d.ts +2 -0
- package/lib/codegen/graphql-client.test.d.ts.map +1 -0
- package/lib/codegen/graphql-client.test.js +311 -0
- package/lib/codegen/graphql-client.test.js.map +1 -0
- package/lib/codegen/graphql.d.ts +207 -0
- package/lib/codegen/graphql.d.ts.map +1 -0
- package/lib/codegen/graphql.js +799 -0
- package/lib/codegen/graphql.js.map +1 -0
- package/lib/codegen/openapi-cli.d.ts +17 -3
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +50 -48
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +69 -6
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +173 -16
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/patches.d.ts +65 -0
- package/lib/codegen/patches.d.ts.map +1 -0
- package/lib/codegen/patches.js +236 -0
- package/lib/codegen/patches.js.map +1 -0
- package/lib/codegen/patches.test.d.ts +2 -0
- package/lib/codegen/patches.test.d.ts.map +1 -0
- package/lib/codegen/patches.test.js +105 -0
- package/lib/codegen/patches.test.js.map +1 -0
- package/lib/codegen/proto.d.ts +121 -0
- package/lib/codegen/proto.d.ts.map +1 -0
- package/lib/codegen/proto.js +962 -0
- package/lib/codegen/proto.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +131 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +1079 -0
- package/lib/codegen/rewrite-operation-ids.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.test.d.ts +2 -0
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +1 -0
- package/lib/codegen/rewrite-operation-ids.test.js +533 -0
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -0
- package/lib/codegen/spec-path.d.ts +16 -0
- package/lib/codegen/spec-path.d.ts.map +1 -0
- package/lib/codegen/spec-path.js +101 -0
- package/lib/codegen/spec-path.js.map +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +17 -13
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +284 -0
- package/lib/graphql.d.ts.map +1 -0
- package/lib/graphql.fixture.d.ts +249 -0
- package/lib/graphql.fixture.d.ts.map +1 -0
- package/lib/graphql.fixture.js +240 -0
- package/lib/graphql.fixture.js.map +1 -0
- package/lib/graphql.js +718 -0
- package/lib/graphql.js.map +1 -0
- package/lib/graphql.test.d.ts +2 -0
- package/lib/graphql.test.d.ts.map +1 -0
- package/lib/graphql.test.js +780 -0
- package/lib/graphql.test.js.map +1 -0
- package/lib/graphql.types.d.ts +2 -0
- package/lib/graphql.types.d.ts.map +1 -0
- package/lib/graphql.types.js +45 -0
- package/lib/graphql.types.js.map +1 -0
- package/lib/json-patch.d.ts +18 -11
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +63 -25
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.d.ts +43 -3
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +91 -5
- package/lib/pagination.js.map +1 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +62 -26
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.d.ts +2 -0
- package/lib/protocol-http.test.d.ts.map +1 -0
- package/lib/protocol-http.test.js +88 -0
- package/lib/protocol-http.test.js.map +1 -0
- package/lib/protocol-rest.d.ts +12 -2
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +17 -3
- package/lib/protocol-rest.js.map +1 -1
- package/lib/retry.js +1 -1
- package/lib/schema.d.ts +1 -1
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -1
- package/lib/schema.js.map +1 -1
- package/lib/trait.d.ts +27 -3
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +17 -1
- package/lib/trait.js.map +1 -1
- package/package.json +13 -10
- package/src/api.ts +18 -4
- package/src/category.ts +4 -4
- package/src/codegen/boolean-string-enums.test.ts +168 -0
- package/src/codegen/boolean-string-enums.ts +106 -0
- package/src/codegen/cli.ts +127 -110
- package/src/codegen/emit.ts +6 -10
- package/src/codegen/generator.ts +151 -21
- package/src/codegen/graphql-client.test.ts +386 -0
- package/src/codegen/graphql-client.ts +419 -0
- package/src/codegen/graphql.ts +1217 -0
- package/src/codegen/openapi-cli.ts +75 -59
- package/src/codegen/openapi.ts +255 -16
- package/src/codegen/patches.test.ts +130 -0
- package/src/codegen/patches.ts +291 -0
- package/src/codegen/proto.ts +1128 -0
- package/src/codegen/rewrite-operation-ids.test.ts +563 -0
- package/src/codegen/rewrite-operation-ids.ts +1206 -0
- package/src/codegen/spec-path.ts +115 -0
- package/src/errors.ts +20 -25
- package/src/graphql.fixture.ts +371 -0
- package/src/graphql.test.ts +974 -0
- package/src/graphql.ts +1321 -0
- package/src/graphql.types.ts +185 -0
- package/src/json-patch.ts +82 -25
- package/src/pagination.ts +134 -7
- package/src/protocol-http.test.ts +107 -0
- package/src/protocol-http.ts +67 -31
- package/src/protocol-rest.ts +28 -4
- package/src/retry.ts +1 -1
- package/src/schema.ts +2 -2
- package/src/trait.ts +39 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { booleanStringEnums, STRING_ENCODED_TRAIT, } from "./boolean-string-enums.js";
|
|
3
|
+
import { generateService } from "./generator.js";
|
|
4
|
+
const boolEnum = {
|
|
5
|
+
type: "enum",
|
|
6
|
+
members: {
|
|
7
|
+
TRUE: {
|
|
8
|
+
target: "smithy.api#Unit",
|
|
9
|
+
traits: { "smithy.api#enumValue": "true" },
|
|
10
|
+
},
|
|
11
|
+
FALSE: {
|
|
12
|
+
target: "smithy.api#Unit",
|
|
13
|
+
traits: { "smithy.api#enumValue": "false" },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const model = (shapes) => ({ smithy: "2.0", shapes });
|
|
18
|
+
describe("booleanStringEnums", () => {
|
|
19
|
+
test("retargets a request member and stamps the trait", () => {
|
|
20
|
+
const m = model({
|
|
21
|
+
"com.example.x#Flag": boolEnum,
|
|
22
|
+
"com.example.x#Request": {
|
|
23
|
+
type: "structure",
|
|
24
|
+
traits: { "smithy.api#input": {} },
|
|
25
|
+
members: { validation_enabled: { target: "com.example.x#Flag" } },
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 0 });
|
|
29
|
+
const member = m.shapes["com.example.x#Request"].members.validation_enabled;
|
|
30
|
+
expect(member.target).toBe("smithy.api#Boolean");
|
|
31
|
+
expect(member.traits[STRING_ENCODED_TRAIT]).toEqual({});
|
|
32
|
+
});
|
|
33
|
+
test("leaves response members alone", () => {
|
|
34
|
+
const m = model({
|
|
35
|
+
"com.example.x#Flag": boolEnum,
|
|
36
|
+
"com.example.x#Response": {
|
|
37
|
+
type: "structure",
|
|
38
|
+
members: { active: { target: "com.example.x#Flag" } },
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
42
|
+
expect(m.shapes["com.example.x#Response"].members.active.target).toBe("com.example.x#Flag");
|
|
43
|
+
});
|
|
44
|
+
test("retargets a request-only list's element type", () => {
|
|
45
|
+
const m = model({
|
|
46
|
+
"com.example.x#Flag": boolEnum,
|
|
47
|
+
"com.example.x#FlagList": {
|
|
48
|
+
type: "list",
|
|
49
|
+
member: { target: "com.example.x#Flag" },
|
|
50
|
+
},
|
|
51
|
+
"com.example.x#Request": {
|
|
52
|
+
type: "structure",
|
|
53
|
+
traits: { "smithy.api#input": {} },
|
|
54
|
+
members: { unique_entries: { target: "com.example.x#FlagList" } },
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
expect(booleanStringEnums(m)).toEqual({ members: 1, lists: 1 });
|
|
58
|
+
expect(m.shapes["com.example.x#FlagList"].member.target).toBe("smithy.api#Boolean");
|
|
59
|
+
});
|
|
60
|
+
test("leaves a list a response also uses", () => {
|
|
61
|
+
const m = model({
|
|
62
|
+
"com.example.x#Flag": boolEnum,
|
|
63
|
+
"com.example.x#FlagList": {
|
|
64
|
+
type: "list",
|
|
65
|
+
member: { target: "com.example.x#Flag" },
|
|
66
|
+
},
|
|
67
|
+
"com.example.x#Request": {
|
|
68
|
+
type: "structure",
|
|
69
|
+
traits: { "smithy.api#input": {} },
|
|
70
|
+
members: { unique_entries: { target: "com.example.x#FlagList" } },
|
|
71
|
+
},
|
|
72
|
+
"com.example.x#Response": {
|
|
73
|
+
type: "structure",
|
|
74
|
+
members: { seen: { target: "com.example.x#FlagList" } },
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
78
|
+
expect(m.shapes["com.example.x#FlagList"].member.target).toBe("com.example.x#Flag");
|
|
79
|
+
});
|
|
80
|
+
test("leaves an enum that is not exactly true/false", () => {
|
|
81
|
+
const m = model({
|
|
82
|
+
"com.example.x#Tri": {
|
|
83
|
+
type: "enum",
|
|
84
|
+
members: {
|
|
85
|
+
TRUE: {
|
|
86
|
+
target: "smithy.api#Unit",
|
|
87
|
+
traits: { "smithy.api#enumValue": "true" },
|
|
88
|
+
},
|
|
89
|
+
FALSE: {
|
|
90
|
+
target: "smithy.api#Unit",
|
|
91
|
+
traits: { "smithy.api#enumValue": "false" },
|
|
92
|
+
},
|
|
93
|
+
AUTO: {
|
|
94
|
+
target: "smithy.api#Unit",
|
|
95
|
+
traits: { "smithy.api#enumValue": "auto" },
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
"com.example.x#Request": {
|
|
100
|
+
type: "structure",
|
|
101
|
+
traits: { "smithy.api#input": {} },
|
|
102
|
+
members: { mode: { target: "com.example.x#Tri" } },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
expect(booleanStringEnums(m)).toEqual({ members: 0, lists: 0 });
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe("generateService", () => {
|
|
109
|
+
test("emits a boolean piped through T.StringEncoded()", () => {
|
|
110
|
+
const { code } = generateService(model({
|
|
111
|
+
"com.example.x#Example": {
|
|
112
|
+
type: "service",
|
|
113
|
+
version: "2024-01-01",
|
|
114
|
+
operations: [{ target: "com.example.x#GetThing" }],
|
|
115
|
+
},
|
|
116
|
+
"com.example.x#GetThing": {
|
|
117
|
+
type: "operation",
|
|
118
|
+
input: { target: "com.example.x#GetThingRequest" },
|
|
119
|
+
output: { target: "smithy.api#Unit" },
|
|
120
|
+
traits: { "smithy.api#http": { method: "GET", uri: "/things" } },
|
|
121
|
+
},
|
|
122
|
+
"com.example.x#GetThingRequest": {
|
|
123
|
+
type: "structure",
|
|
124
|
+
traits: { "smithy.api#input": {} },
|
|
125
|
+
members: {
|
|
126
|
+
verbose: {
|
|
127
|
+
target: "com.example.x#Flag",
|
|
128
|
+
traits: { "smithy.api#httpQuery": "verbose" },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
"com.example.x#Flag": boolEnum,
|
|
133
|
+
}), {
|
|
134
|
+
operationDecl: {
|
|
135
|
+
contextType: "ExampleOpContext",
|
|
136
|
+
commonErrorType: "ExampleOpError",
|
|
137
|
+
commonErrorClasses: [],
|
|
138
|
+
protocol: "ExampleProtocol",
|
|
139
|
+
retry: "Retry.Retry",
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
expect(code).toContain('"verbose": S.optional(S.Boolean.pipe(T.Query(), T.StringEncoded())),');
|
|
143
|
+
expect(code).toContain("verbose?: boolean;");
|
|
144
|
+
expect(code).not.toContain('"true" | "false"');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=boolean-string-enums.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boolean-string-enums.test.js","sourceRoot":"","sources":["../../src/codegen/boolean-string-enums.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE;QAC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BAAkB,EAAE,EAAE;gBACtB,QAAQ,EAAE,iBAAiB;gBAC3B,KAAK,EAAE,aAAa;aACrB;SACF,CACF,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CACpB,sEAAsE,CACvE,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/codegen/cli.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import * as FileSystem from "effect/FileSystem";
|
|
3
|
+
import * as Path from "effect/Path";
|
|
1
4
|
import { type SdkSpec } from "./generator.ts";
|
|
2
5
|
export interface GeneratorCliOptions {
|
|
3
6
|
/** Command description shown in --help. */
|
|
@@ -10,15 +13,62 @@ export interface GeneratorCliOptions {
|
|
|
10
13
|
readonly outDir?: string;
|
|
11
14
|
/** Model files to skip (e.g. a shared protocols model). */
|
|
12
15
|
readonly excludeModel?: (file: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Where the models are, when they aren't a flat directory of `<resource>.json`.
|
|
18
|
+
* AWS vendors Amazon's own repo, whose models sit at
|
|
19
|
+
* `models/<service>/service/<version>/<service>-<version>.json`.
|
|
20
|
+
*
|
|
21
|
+
* Returns the model files to compile; manual specs are merged in after,
|
|
22
|
+
* as usual.
|
|
23
|
+
*/
|
|
24
|
+
readonly discoverModels?: (ctx: {
|
|
25
|
+
readonly smithyDir: string;
|
|
26
|
+
}) => Effect.Effect<ReadonlyArray<{
|
|
27
|
+
readonly file: string;
|
|
28
|
+
readonly dir: string;
|
|
29
|
+
}>, never, FileSystem.FileSystem | Path.Path>;
|
|
30
|
+
/**
|
|
31
|
+
* Side effects to run before generating — e.g. AWS copies `partitions.json`
|
|
32
|
+
* out of the smithy submodule, runtime data its endpoint resolver reads.
|
|
33
|
+
*/
|
|
34
|
+
readonly prepare?: (ctx: {
|
|
35
|
+
readonly root: string;
|
|
36
|
+
readonly outDir: string;
|
|
37
|
+
}) => Effect.Effect<void, never, FileSystem.FileSystem | Path.Path>;
|
|
38
|
+
/**
|
|
39
|
+
* The output module's name, when it isn't the model's filename. AWS names
|
|
40
|
+
* modules after the service's `aws.api#service` sdkId (`amazon-s3.json` →
|
|
41
|
+
* `s3.ts`), so the public surface reads `AWS.S3.getObject`.
|
|
42
|
+
*/
|
|
43
|
+
readonly resourceName?: (ctx: {
|
|
44
|
+
readonly model: any;
|
|
45
|
+
readonly file: string;
|
|
46
|
+
}) => string;
|
|
47
|
+
/** Barrel export name for a resource. Default: the resource name itself. */
|
|
48
|
+
readonly barrelExportName?: (resource: string) => string;
|
|
49
|
+
/**
|
|
50
|
+
* The closing pass over the output directory. Defaults to formatting;
|
|
51
|
+
* AWS lint-fixes first (see `codegen/format.ts`).
|
|
52
|
+
*/
|
|
53
|
+
readonly finalize?: (dir: string) => Effect.Effect<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Keep generating after a model fails, instead of stopping at the first.
|
|
56
|
+
* AWS compiles 430 services in one run, and one broken model shouldn't
|
|
57
|
+
* hide the state of the other 429. The run still FAILS at the end — the
|
|
58
|
+
* failures are reported together rather than swallowed.
|
|
59
|
+
*/
|
|
60
|
+
readonly continueOnModelError?: boolean;
|
|
13
61
|
/** Directory of hand-authored models merged after the generated ones. */
|
|
14
62
|
readonly manualSpecsDir?: string;
|
|
15
|
-
/** RFC-6902 patch chain root. Default `patches`; `false` disables. */
|
|
16
|
-
readonly patchesDir?: string | false;
|
|
17
63
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
64
|
+
* RFC-6902 patches apply in convert, never here. Only `false` is accepted
|
|
65
|
+
* so a string is a type error rather than a silently ignored setting.
|
|
66
|
+
*/
|
|
67
|
+
readonly patchesDir?: false;
|
|
68
|
+
/**
|
|
69
|
+
* Model transform applied before generation (e.g. AWS dropping
|
|
70
|
+
* unreachable foreign-namespace shapes from a vendored model). Does not
|
|
71
|
+
* write back to `.generated-specs` — convert owns the committed model.
|
|
22
72
|
*/
|
|
23
73
|
readonly transformModel?: (model: any, resource: string) => string | void;
|
|
24
74
|
/** The provider spec — built per model (metadata may vary per model). */
|
package/lib/codegen/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/codegen/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/codegen/cli.ts"],"names":[],"mappings":"AAaA,OAAO,EAAW,MAAM,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AAKpC,OAAO,EAAmB,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAClD;;;;;;;OAOG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE;QAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;KAC5B,KAAK,MAAM,CAAC,MAAM,CACjB,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,M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AED,0EAA0E;AAC1E,eAAO,MAAM,eAAe,YAAa,mBAAmB,KAAG,IA2L9D,CAAC"}
|
package/lib/codegen/cli.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The generic generator CLI harness (dev-time only).
|
|
3
3
|
*
|
|
4
|
-
* Owns the smithy
|
|
5
|
-
* directory (plus optional hand-authored manual specs),
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* service modules and the namespaced barrel.
|
|
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. RFC-6902 patches apply in
|
|
8
|
+
* convert so `.generated-specs` is already the patched model.
|
|
10
9
|
*
|
|
11
10
|
* A provider's `scripts/generate.ts` is: trait consts + an SdkSpec + a
|
|
12
11
|
* `runGeneratorCli` call.
|
|
@@ -17,16 +16,15 @@ import * as FileSystem from "effect/FileSystem";
|
|
|
17
16
|
import * as Path from "effect/Path";
|
|
18
17
|
import { Flag } from "effect/unstable/cli";
|
|
19
18
|
import { Command } from "effect/unstable/cli";
|
|
20
|
-
import { applyOperation, isStaleTargetError, } from "../json-patch.js";
|
|
21
19
|
import { barrel } from "./emit.js";
|
|
22
20
|
import { formatGenerated } from "./format.js";
|
|
23
21
|
import { generateService } from "./generator.js";
|
|
24
22
|
/** Run the generator CLI (BunRuntime main — call at module top level). */
|
|
25
23
|
export const runGeneratorCli = (options) => {
|
|
26
24
|
const command = Command.make("generate", {
|
|
27
|
-
smithy: Flag.
|
|
28
|
-
out: Flag.
|
|
29
|
-
resource: Flag.
|
|
25
|
+
smithy: Flag.String("smithy").pipe(Flag.withDefault(options.smithyDir ?? ".generated-specs"), Flag.withDescription("Directory of Smithy JSON models")),
|
|
26
|
+
out: Flag.String("out").pipe(Flag.withDefault(options.outDir ?? "src/services"), Flag.withDescription("Output directory for generated service modules")),
|
|
27
|
+
resource: Flag.String("resource").pipe(Flag.withDefault(""), Flag.withDescription("Only generate this resource (e.g. ai)")),
|
|
30
28
|
}, (config) => Effect.gen(function* () {
|
|
31
29
|
const fs = yield* FileSystem.FileSystem;
|
|
32
30
|
const path = yield* Path.Path;
|
|
@@ -36,12 +34,15 @@ export const runGeneratorCli = (options) => {
|
|
|
36
34
|
yield* Console.log("⚙️ generate");
|
|
37
35
|
yield* Console.log(` Smithy: ${smithyDir}`);
|
|
38
36
|
yield* Console.log(` Output: ${outDir}`);
|
|
37
|
+
yield* options.prepare?.({ root, outDir }) ?? Effect.void;
|
|
39
38
|
// Generated models plus optional manual-specs (hand-authored models
|
|
40
39
|
// for APIs the provider's spec source doesn't cover). A manual model
|
|
41
40
|
// must not shadow a generated one.
|
|
42
|
-
const generated =
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const generated = options.discoverModels
|
|
42
|
+
? yield* options.discoverModels({ smithyDir })
|
|
43
|
+
: (yield* fs.readDirectory(smithyDir))
|
|
44
|
+
.filter((f) => f.endsWith(".json") && !(options.excludeModel?.(f) ?? false))
|
|
45
|
+
.map((f) => ({ file: f, dir: smithyDir }));
|
|
45
46
|
const manualDir = options.manualSpecsDir
|
|
46
47
|
? path.resolve(root, options.manualSpecsDir)
|
|
47
48
|
: undefined;
|
|
@@ -58,75 +59,43 @@ export const runGeneratorCli = (options) => {
|
|
|
58
59
|
const entries = [...generated, ...manual].sort((a, b) => a.file.localeCompare(b.file));
|
|
59
60
|
yield* fs.makeDirectory(outDir, { recursive: true });
|
|
60
61
|
const written = [];
|
|
62
|
+
const failedModels = [];
|
|
61
63
|
let totalOps = 0;
|
|
62
|
-
let totalPatches = 0;
|
|
63
|
-
let staleOps = 0;
|
|
64
|
-
const badPatches = [];
|
|
65
|
-
// Orphan check: a patch directory matching no smithy model would be
|
|
66
|
-
// silently dropped — flag it instead.
|
|
67
|
-
const patchRoot = options.patchesDir === false
|
|
68
|
-
? undefined
|
|
69
|
-
: path.join(root, options.patchesDir ?? "patches");
|
|
70
|
-
if (patchRoot && (yield* fs.exists(patchRoot))) {
|
|
71
|
-
const resources = new Set(entries.map((e) => e.file.replace(/\.json$/, "")));
|
|
72
|
-
for (const dir of yield* fs.readDirectory(patchRoot)) {
|
|
73
|
-
if (!resources.has(dir)) {
|
|
74
|
-
yield* Console.warn(`⚠️ patches/${dir}/ matches no smithy model — orphaned?`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
64
|
for (const { file, dir } of entries) {
|
|
79
|
-
const
|
|
65
|
+
const model = JSON.parse(yield* fs.readFileString(path.join(dir, file)));
|
|
66
|
+
// The module's name — the model's filename unless the provider
|
|
67
|
+
// derives it from the model itself (AWS: the service's sdkId).
|
|
68
|
+
const resource = options.resourceName?.({ model, file }) ??
|
|
69
|
+
file.replace(/\.json$/, "");
|
|
80
70
|
if (config.resource && resource !== config.resource)
|
|
81
71
|
continue;
|
|
82
|
-
const model = JSON.parse(yield* fs.readFileString(path.join(dir, file)));
|
|
83
|
-
// Apply the RFC-6902 patch chain before generating. Hand-written
|
|
84
|
-
// *.manual.json patches apply after the generated ones — they
|
|
85
|
-
// usually target post-rename shape names.
|
|
86
|
-
const patchDir = patchRoot && path.join(patchRoot, resource);
|
|
87
|
-
if (patchDir && (yield* fs.exists(patchDir))) {
|
|
88
|
-
const patchFiles = (yield* fs.readDirectory(patchDir))
|
|
89
|
-
.filter((f) => f.endsWith(".json"))
|
|
90
|
-
.sort((a, b) => Number(a.endsWith(".manual.json")) -
|
|
91
|
-
Number(b.endsWith(".manual.json")) || a.localeCompare(b));
|
|
92
|
-
for (const pf of patchFiles) {
|
|
93
|
-
const parsed = JSON.parse(yield* fs.readFileString(path.join(patchDir, pf)));
|
|
94
|
-
for (const patchOp of parsed.patches ?? []) {
|
|
95
|
-
try {
|
|
96
|
-
applyOperation(model, patchOp);
|
|
97
|
-
}
|
|
98
|
-
catch (e) {
|
|
99
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
100
|
-
if (isStaleTargetError(msg)) {
|
|
101
|
-
staleOps++;
|
|
102
|
-
yield* Console.warn(` ⚠️ stale: ${resource}/${pf} [${patchOp.op} ${patchOp.path}]`);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
badPatches.push(`${resource}/${pf} [${patchOp.op} ${patchOp.path}]: ${msg}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
totalPatches++;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
72
|
if (options.transformModel) {
|
|
113
73
|
const note = options.transformModel(model, resource);
|
|
114
74
|
if (note)
|
|
115
75
|
yield* Console.log(` ${note}`);
|
|
116
76
|
}
|
|
117
|
-
|
|
77
|
+
// `generateService` and the provider spec are synchronous and
|
|
78
|
+
// throw; with continueOnModelError the throw is recorded and the
|
|
79
|
+
// run moves on, so one broken model doesn't hide the state of
|
|
80
|
+
// every model after it. The run still fails at the end.
|
|
81
|
+
let generated;
|
|
82
|
+
try {
|
|
83
|
+
generated = generateService(model, options.spec(model));
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
if (!options.continueOnModelError)
|
|
87
|
+
throw e;
|
|
88
|
+
failedModels.push(`${resource}: ${e instanceof Error ? e.message : String(e)}`);
|
|
89
|
+
yield* Console.error(`❌ ${resource}`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const { code, operations } = generated;
|
|
118
93
|
if (operations === 0)
|
|
119
94
|
continue;
|
|
120
95
|
yield* fs.writeFileString(path.join(outDir, `${resource}.ts`), code);
|
|
121
96
|
written.push(resource);
|
|
122
97
|
totalOps += operations;
|
|
123
98
|
}
|
|
124
|
-
if (badPatches.length) {
|
|
125
|
-
for (const b of badPatches) {
|
|
126
|
-
yield* Console.error(`❌ bad patch: ${b}`);
|
|
127
|
-
}
|
|
128
|
-
return yield* Effect.die(new Error(`${badPatches.length} malformed patch operation(s) — fix or remove them`));
|
|
129
|
-
}
|
|
130
99
|
// Barrel — namespace per resource to avoid op-name collisions.
|
|
131
100
|
//
|
|
132
101
|
// A FULL run is authoritative: the barrel is exactly what was
|
|
@@ -140,11 +109,17 @@ export const runGeneratorCli = (options) => {
|
|
|
140
109
|
// resource without removing anything.
|
|
141
110
|
const barrelPath = path.join(outDir, "index.ts");
|
|
142
111
|
const filtered = config.resource !== "";
|
|
143
|
-
|
|
112
|
+
// Sorted, not in generation order: a provider that discovers models
|
|
113
|
+
// in some other order (AWS walks Amazon's directory tree) would
|
|
114
|
+
// otherwise reshuffle the barrel on every run.
|
|
115
|
+
let resources = [...written].sort((a, b) => `${a}.json`.localeCompare(`${b}.json`));
|
|
144
116
|
if (filtered && (yield* fs.exists(barrelPath))) {
|
|
117
|
+
// Recover the RESOURCE from each export line's path, not its name:
|
|
118
|
+
// the two differ when barrelExportName renames (AWS exports
|
|
119
|
+
// `S3` from `./s3.ts`).
|
|
145
120
|
const existing = (yield* fs.readFileString(barrelPath))
|
|
146
121
|
.split("\n")
|
|
147
|
-
.map((line) => /^export \* as
|
|
122
|
+
.map((line) => /^export \* as \S+ from "\.\/(.+)\.ts";/.exec(line)?.[1])
|
|
148
123
|
.filter((name) => name !== undefined);
|
|
149
124
|
// Ordered exactly as a full run orders it: by MODEL FILENAME, so
|
|
150
125
|
// the `.json` takes part in the collation (`ai_gateway.json` sorts
|
|
@@ -152,13 +127,22 @@ export const runGeneratorCli = (options) => {
|
|
|
152
127
|
// Otherwise a filtered run reshuffles the barrel into diff noise.
|
|
153
128
|
resources = [...new Set([...existing, ...written])].sort((a, b) => `${a}.json`.localeCompare(`${b}.json`));
|
|
154
129
|
}
|
|
155
|
-
yield* fs.writeFileString(barrelPath, barrel(`// AUTO-GENERATED by scripts/generate.ts. Do not edit.\n`, resources.map((r) => ({
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
130
|
+
yield* fs.writeFileString(barrelPath, barrel(`// AUTO-GENERATED by scripts/generate.ts. Do not edit.\n`, resources.map((r) => ({
|
|
131
|
+
name: options.barrelExportName?.(r) ?? r,
|
|
132
|
+
path: `./${r}.ts`,
|
|
133
|
+
}))));
|
|
134
|
+
yield* (options.finalize ?? formatGenerated)(outDir);
|
|
135
|
+
yield* Console.log(`\n✅ Generated ${totalOps} operations across ${written.length} resource modules.`);
|
|
161
136
|
yield* Console.log(` ${path.join(outDir, "index.ts")}`);
|
|
137
|
+
// Models that failed under continueOnModelError. Reported together,
|
|
138
|
+
// at the end, and the run FAILS — a generate that couldn't produce
|
|
139
|
+
// a module must not exit 0 with the failure buried in the log.
|
|
140
|
+
if (failedModels.length) {
|
|
141
|
+
yield* Console.error(`\n❌ ${failedModels.length} model(s) failed to generate:`);
|
|
142
|
+
for (const f of failedModels)
|
|
143
|
+
yield* Console.error(` ${f}`);
|
|
144
|
+
return yield* Effect.die(new Error(`${failedModels.length} model(s) failed to generate`));
|
|
145
|
+
}
|
|
162
146
|
})).pipe(Command.withDescription(options.description));
|
|
163
147
|
BunRuntime.runMain(Effect.provide(Command.run(command, { version: "1.0.0" }), BunServices.layer));
|
|
164
148
|
};
|
package/lib/codegen/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/codegen/cli.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/codegen/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,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C,CAAC,MAAM,CAAC,GAAG,CACtB,IAAI,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,8BAA8B,CAAC,CAChE,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CACL,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAErD,UAAU,CAAC,OAAO,CAChB,MAAM,CAAC,OAAO,CACZ,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAC1C,WAAW,CAAC,KAAK,CAClB,CACF,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/codegen/emit.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The PURE annotation emitted before generated schema consts. A single
|
|
3
|
-
* `/*@__PURE__*/` — Rolldown 1.1+ warns on the `/*#__PURE__*/` form
|
|
4
|
-
* (distilled #374).
|
|
5
|
-
*/
|
|
1
|
+
/** PURE annotates calls, never property reads. Both @ and # forms are supported. */
|
|
6
2
|
export declare const PURE = "/*@__PURE__*/ ";
|
|
7
3
|
/** `export interface X { … }` (or the empty-body form). */
|
|
8
4
|
export declare const interfaceDecl: (name: string, fields: string[]) => string;
|
|
@@ -68,7 +64,7 @@ export interface ErrorClassOptions {
|
|
|
68
64
|
readonly wrap?: (cls: string) => string;
|
|
69
65
|
}
|
|
70
66
|
/**
|
|
71
|
-
* `export class X extends /*@__PURE__*/ S.
|
|
67
|
+
* `export class X extends /*@__PURE__*/ S.TaggedError<X>()("X", { … }) {}`
|
|
72
68
|
*
|
|
73
69
|
* The PURE markers are what make an unused error class droppable. A class
|
|
74
70
|
* whose heritage clause is an unannotated call can never be tree-shaken —
|
|
@@ -78,7 +74,7 @@ export interface ErrorClassOptions {
|
|
|
78
74
|
*
|
|
79
75
|
* `wrap` needs its own marker as well as the inner one: a pure call's
|
|
80
76
|
* ARGUMENTS are still evaluated, so annotating only
|
|
81
|
-
* `T.applyErrorMatchers(S.
|
|
77
|
+
* `T.applyErrorMatchers(S.TaggedError…(…), […])` leaves the inner call
|
|
82
78
|
* holding the class alive. Verified against esbuild in both directions.
|
|
83
79
|
*/
|
|
84
80
|
export declare const errorClass: (o: ErrorClassOptions) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/codegen/emit.ts"],"names":[],"mappings":"AAoBA
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/codegen/emit.ts"],"names":[],"mappings":"AAoBA,oFAAoF;AACpF,eAAO,MAAM,IAAI,mBAAmB,CAAC;AAErC,2DAA2D;AAC3D,eAAO,MAAM,aAAa,SAAU,MAAM,UAAU,MAAM,EAAE,KAAG,MAG5B,CAAC;AAEpC,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,mFAAmF;IACnF,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,MAAO,mBAAmB,KAAG,MAYrD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,sBAAkB,MAGY,CAAC;AAEtE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EA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AAC;CACrC;AAED,sDAAsD;AACtD,eAAO,MAAM,cAAc,MAAO,qBAAqB,KAAG,MAGZ,CAAC;AAI/C,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,MAAO,qBAAqB,KAAG,MAAM,EAG/D,CAAC;AAEF,wDAAwD;AACxD,eAAO,MAAM,eAAe,WAClB,MAAM,cACF,SAAS,MAAM,EAAE,aAClB,MAAM,KAChB,MACwE,CAAC;AAE5E,yEAAyE;AACzE,eAAO,MAAM,MAAM,WACT,MAAM,WACL,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,KACrD,MAGG,CAAC"}
|
package/lib/codegen/emit.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* .annotate({ identifier: "X" })
|
|
10
10
|
* as any as S.Schema<X>; // no inference needed
|
|
11
11
|
*
|
|
12
|
-
* plus closed-alias string-union enums, `S.
|
|
12
|
+
* plus closed-alias string-union enums, `S.TaggedError` error classes, and
|
|
13
13
|
* `API.make(() => ({ … }))` operation consts. The helpers here own those
|
|
14
14
|
* shared skeletons; providers own the content strings (member pipes, trait
|
|
15
15
|
* calls, config fields). Emitted output is normalized by oxfmt afterwards,
|
|
@@ -17,11 +17,7 @@
|
|
|
17
17
|
* whitespace.
|
|
18
18
|
*/
|
|
19
19
|
import { q } from "./naming.js";
|
|
20
|
-
/**
|
|
21
|
-
* The PURE annotation emitted before generated schema consts. A single
|
|
22
|
-
* `/*@__PURE__*/` — Rolldown 1.1+ warns on the `/*#__PURE__*/` form
|
|
23
|
-
* (distilled #374).
|
|
24
|
-
*/
|
|
20
|
+
/** PURE annotates calls, never property reads. Both @ and # forms are supported. */
|
|
25
21
|
export const PURE = "/*@__PURE__*/ ";
|
|
26
22
|
/** `export interface X { … }` (or the empty-body form). */
|
|
27
23
|
export const interfaceDecl = (name, fields) => fields.length
|
|
@@ -65,11 +61,11 @@ export const enumDecl = (o) => {
|
|
|
65
61
|
const union = o.values.length ? o.values.map(q).join(" | ") : "string";
|
|
66
62
|
return [
|
|
67
63
|
`export type ${o.name} = ${union};`,
|
|
68
|
-
`export const ${o.name} = ${o.pure ?? ""}${o.schemaExpr
|
|
64
|
+
`export const ${o.name} = ${o.schemaExpr ? `${o.pure ?? ""}${o.schemaExpr}` : "S.String"};\n`,
|
|
69
65
|
];
|
|
70
66
|
};
|
|
71
67
|
/**
|
|
72
|
-
* `export class X extends /*@__PURE__*/ S.
|
|
68
|
+
* `export class X extends /*@__PURE__*/ S.TaggedError<X>()("X", { … }) {}`
|
|
73
69
|
*
|
|
74
70
|
* The PURE markers are what make an unused error class droppable. A class
|
|
75
71
|
* whose heritage clause is an unannotated call can never be tree-shaken —
|
|
@@ -79,12 +75,12 @@ export const enumDecl = (o) => {
|
|
|
79
75
|
*
|
|
80
76
|
* `wrap` needs its own marker as well as the inner one: a pure call's
|
|
81
77
|
* ARGUMENTS are still evaluated, so annotating only
|
|
82
|
-
* `T.applyErrorMatchers(S.
|
|
78
|
+
* `T.applyErrorMatchers(S.TaggedError…(…), […])` leaves the inner call
|
|
83
79
|
* holding the class alive. Verified against esbuild in both directions.
|
|
84
80
|
*/
|
|
85
81
|
export const errorClass = (o) => {
|
|
86
82
|
const annotations = o.annotations ? `,\n${o.annotations}` : "";
|
|
87
|
-
const cls = `${PURE}S.
|
|
83
|
+
const cls = `${PURE}S.TaggedError<${o.name}>()(${q(o.tag ?? o.name)}, {\n${o.fields.join("\n")}\n}${annotations})${o.pipes ?? ""}`;
|
|
88
84
|
const body = o.wrap ? `${PURE}${o.wrap(cls)}` : cls;
|
|
89
85
|
return `export class ${o.name} extends ${body} {}\n`;
|
|
90
86
|
};
|
package/lib/codegen/emit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/codegen/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/codegen/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAEhC,oFAAoF;AACpF,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAC;AAErC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,MAAgB,EAAU,EAAE,CACtE,MAAM,CAAC,MAAM;IACX,CAAC,CAAC,oBAAoB,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;IACvD,CAAC,CAAC,oBAAoB,IAAI,KAAK,CAAC;AAuBpC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAsB,EAAU,EAAE;IAC7D,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,IAAI,YAAY,CAAC,CAAC,IAAI,GAAG,CAAC;IAC/C,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;IAC9D,MAAM,OAAO,GAAG,CAAC,CAAC,SAAS;QACzB,CAAC,CAAC,aAAa,KAAK,KAAK,CAAC,CAAC,IAAI,MAAM;QACrC,CAAC,CAAC,aAAa,KAAK,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC;IACpC,MAAM,QAAQ,GAAG,CAAC,CAAC,UAAU;QAC3B,CAAC,CAAC,aAAa,CAAC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