@dual-os/cli 0.0.0-stage → 0.11.0
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 +4 -0
- package/README.md +15 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/auth/credentials.d.ts +17 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +57 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/destination.d.ts +22 -0
- package/dist/auth/destination.d.ts.map +1 -0
- package/dist/auth/destination.js +49 -0
- package/dist/auth/destination.js.map +1 -0
- package/dist/auth/http.d.ts +12 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +34 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/login.d.ts +22 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +98 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/protocol.d.ts +26 -0
- package/dist/auth/protocol.d.ts.map +1 -0
- package/dist/auth/protocol.js +31 -0
- package/dist/auth/protocol.js.map +1 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +22 -0
- package/dist/baseline.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +492 -0
- package/dist/cli.js.map +1 -0
- package/dist/create/choices.d.ts +58 -0
- package/dist/create/choices.d.ts.map +1 -0
- package/dist/create/choices.js +121 -0
- package/dist/create/choices.js.map +1 -0
- package/dist/create/deployment.d.ts +48 -0
- package/dist/create/deployment.d.ts.map +1 -0
- package/dist/create/deployment.js +66 -0
- package/dist/create/deployment.js.map +1 -0
- package/dist/create/scaffold.d.ts +57 -0
- package/dist/create/scaffold.d.ts.map +1 -0
- package/dist/create/scaffold.js +198 -0
- package/dist/create/scaffold.js.map +1 -0
- package/dist/create/source-reference.d.ts +39 -0
- package/dist/create/source-reference.d.ts.map +1 -0
- package/dist/create/source-reference.js +185 -0
- package/dist/create/source-reference.js.map +1 -0
- package/dist/create/template.d.ts +116 -0
- package/dist/create/template.d.ts.map +1 -0
- package/dist/create/template.js +211 -0
- package/dist/create/template.js.map +1 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/help.d.ts +16 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +73 -0
- package/dist/help.js.map +1 -0
- package/dist/openapi/bundle.d.ts +18 -0
- package/dist/openapi/bundle.d.ts.map +1 -0
- package/dist/openapi/bundle.js +201 -0
- package/dist/openapi/bundle.js.map +1 -0
- package/dist/openapi/discovery.d.ts +30 -0
- package/dist/openapi/discovery.d.ts.map +1 -0
- package/dist/openapi/discovery.js +325 -0
- package/dist/openapi/discovery.js.map +1 -0
- package/dist/openapi/emit.d.ts +52 -0
- package/dist/openapi/emit.d.ts.map +1 -0
- package/dist/openapi/emit.js +596 -0
- package/dist/openapi/emit.js.map +1 -0
- package/dist/openapi/graphql.d.ts +102 -0
- package/dist/openapi/graphql.d.ts.map +1 -0
- package/dist/openapi/graphql.js +294 -0
- package/dist/openapi/graphql.js.map +1 -0
- package/dist/openapi/identity.d.ts +88 -0
- package/dist/openapi/identity.d.ts.map +1 -0
- package/dist/openapi/identity.js +98 -0
- package/dist/openapi/identity.js.map +1 -0
- package/dist/openapi/mcp.d.ts +21 -0
- package/dist/openapi/mcp.d.ts.map +1 -0
- package/dist/openapi/mcp.js +133 -0
- package/dist/openapi/mcp.js.map +1 -0
- package/dist/openapi/operations.d.ts +165 -0
- package/dist/openapi/operations.d.ts.map +1 -0
- package/dist/openapi/operations.js +361 -0
- package/dist/openapi/operations.js.map +1 -0
- package/dist/openapi/overlay.d.ts +23 -0
- package/dist/openapi/overlay.d.ts.map +1 -0
- package/dist/openapi/overlay.js +115 -0
- package/dist/openapi/overlay.js.map +1 -0
- package/dist/openapi/plugin.d.ts +83 -0
- package/dist/openapi/plugin.d.ts.map +1 -0
- package/dist/openapi/plugin.js +468 -0
- package/dist/openapi/plugin.js.map +1 -0
- package/dist/openapi/polymorphism.d.ts +21 -0
- package/dist/openapi/polymorphism.d.ts.map +1 -0
- package/dist/openapi/polymorphism.js +96 -0
- package/dist/openapi/polymorphism.js.map +1 -0
- package/dist/openapi/postman.d.ts +21 -0
- package/dist/openapi/postman.d.ts.map +1 -0
- package/dist/openapi/postman.js +286 -0
- package/dist/openapi/postman.js.map +1 -0
- package/dist/openapi/schema.d.ts +178 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +1234 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/select.d.ts +22 -0
- package/dist/openapi/select.d.ts.map +1 -0
- package/dist/openapi/select.js +79 -0
- package/dist/openapi/select.js.map +1 -0
- package/dist/openapi/spec.d.ts +147 -0
- package/dist/openapi/spec.d.ts.map +1 -0
- package/dist/openapi/spec.js +263 -0
- package/dist/openapi/spec.js.map +1 -0
- package/dist/openapi/swagger.d.ts +166 -0
- package/dist/openapi/swagger.d.ts.map +1 -0
- package/dist/openapi/swagger.js +298 -0
- package/dist/openapi/swagger.js.map +1 -0
- package/dist/openapi/versions.d.ts +52 -0
- package/dist/openapi/versions.d.ts.map +1 -0
- package/dist/openapi/versions.js +120 -0
- package/dist/openapi/versions.js.map +1 -0
- package/dist/plugin/archive.d.ts +27 -0
- package/dist/plugin/archive.d.ts.map +1 -0
- package/dist/plugin/archive.js +170 -0
- package/dist/plugin/archive.js.map +1 -0
- package/dist/plugin/bundle.d.ts +27 -0
- package/dist/plugin/bundle.d.ts.map +1 -0
- package/dist/plugin/bundle.js +328 -0
- package/dist/plugin/bundle.js.map +1 -0
- package/dist/plugin/init.d.ts +18 -0
- package/dist/plugin/init.d.ts.map +1 -0
- package/dist/plugin/init.js +121 -0
- package/dist/plugin/init.js.map +1 -0
- package/dist/plugin/inspection.d.ts +24 -0
- package/dist/plugin/inspection.d.ts.map +1 -0
- package/dist/plugin/inspection.js +24 -0
- package/dist/plugin/inspection.js.map +1 -0
- package/dist/plugin/package.d.ts +26 -0
- package/dist/plugin/package.d.ts.map +1 -0
- package/dist/plugin/package.js +73 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/publication.d.ts +29 -0
- package/dist/plugin/publication.d.ts.map +1 -0
- package/dist/plugin/publication.js +65 -0
- package/dist/plugin/publication.js.map +1 -0
- package/dist/plugin/validation.d.ts +15 -0
- package/dist/plugin/validation.d.ts.map +1 -0
- package/dist/plugin/validation.js +119 -0
- package/dist/plugin/validation.js.map +1 -0
- package/dist/release/archives.d.ts +33 -0
- package/dist/release/archives.d.ts.map +1 -0
- package/dist/release/archives.js +81 -0
- package/dist/release/archives.js.map +1 -0
- package/dist/release/release-manifest.d.ts +182 -0
- package/dist/release/release-manifest.d.ts.map +1 -0
- package/dist/release/release-manifest.js +79 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/releases.d.ts +36 -0
- package/dist/release/releases.d.ts.map +1 -0
- package/dist/release/releases.js +122 -0
- package/dist/release/releases.js.map +1 -0
- package/dist/skills.d.ts +35 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +257 -0
- package/dist/skills.js.map +1 -0
- package/package.json +73 -4
- package/skills/dual-fde/SKILL.md +38 -0
- package/skills/dual-fde/references/access.md +62 -0
- package/skills/dual-fde/references/author-plugins.md +54 -0
- package/skills/dual-fde/references/cli.md +97 -0
- package/skills/dual-fde/references/manage-plugins.md +78 -0
- package/skills/dual-fde/references/migrations-deployment.md +84 -0
- package/skills/dual-fde/references/openapi-plugins.md +47 -0
- package/skills/dual-fde/references/sdk-docs.md +56 -0
- package/skills/dual-fde/references/upgrades.md +115 -0
- package/skills/dual-fde/references/working-context.md +69 -0
- package/src/auth/credentials.ts +84 -0
- package/src/auth/destination.ts +83 -0
- package/src/auth/http.ts +39 -0
- package/src/auth/login.ts +177 -0
- package/src/auth/protocol.ts +37 -0
- package/src/baseline.ts +15 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +969 -0
- package/src/create/choices.ts +177 -0
- package/src/create/deployment.ts +96 -0
- package/src/create/scaffold.ts +334 -0
- package/src/create/source-reference.ts +212 -0
- package/src/create/template.ts +300 -0
- package/src/diagnostics.ts +8 -0
- package/src/help.ts +142 -0
- package/src/openapi/bundle.ts +290 -0
- package/src/openapi/discovery.ts +438 -0
- package/src/openapi/emit.ts +1031 -0
- package/src/openapi/graphql.ts +375 -0
- package/src/openapi/identity.ts +153 -0
- package/src/openapi/mcp.ts +165 -0
- package/src/openapi/operations.ts +781 -0
- package/src/openapi/overlay.ts +195 -0
- package/src/openapi/plugin.ts +856 -0
- package/src/openapi/polymorphism.ts +207 -0
- package/src/openapi/postman.ts +403 -0
- package/src/openapi/schema.ts +2138 -0
- package/src/openapi/select.ts +113 -0
- package/src/openapi/spec.ts +401 -0
- package/src/openapi/swagger.ts +422 -0
- package/src/openapi/versions.ts +174 -0
- package/src/plugin/archive.ts +244 -0
- package/src/plugin/bundle.ts +572 -0
- package/src/plugin/init.ts +178 -0
- package/src/plugin/inspection.ts +19 -0
- package/src/plugin/package.ts +140 -0
- package/src/plugin/publication.ts +128 -0
- package/src/plugin/validation.ts +213 -0
- package/src/release/archives.ts +133 -0
- package/src/release/release-manifest.ts +79 -0
- package/src/release/releases.ts +210 -0
- package/src/skills.ts +434 -0
- package/templates/compose/.env.compose.example.hbs +3 -0
- package/templates/compose/.env.host.example.hbs +4 -0
- package/templates/compose/Dockerfile.hbs +12 -0
- package/templates/compose/OPERATIONS.md.hbs +159 -0
- package/templates/compose/_dockerignore +14 -0
- package/templates/compose/compose.external.yaml +7 -0
- package/templates/compose/compose.host-linux.yaml +5 -0
- package/templates/compose/compose.host.yaml.hbs +15 -0
- package/templates/compose/compose.yaml.hbs +85 -0
- package/templates/compose/release.env.hbs +2 -0
- package/templates/default/.env.example.hbs +79 -0
- package/templates/default/README.md.hbs +150 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
- package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
- package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
- package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
- package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
- package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
- package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
- package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
- package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
- package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
- package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
- package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
- package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/vitest.config.ts +5 -0
- package/templates/default/vitest.host.config.ts +6 -0
- package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
- package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
|
@@ -0,0 +1,1031 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Graph,
|
|
4
|
+
HashMap,
|
|
5
|
+
HashSet,
|
|
6
|
+
Match,
|
|
7
|
+
Option,
|
|
8
|
+
Order,
|
|
9
|
+
Predicate,
|
|
10
|
+
Record,
|
|
11
|
+
Result,
|
|
12
|
+
Schema,
|
|
13
|
+
String,
|
|
14
|
+
pipe,
|
|
15
|
+
} from "effect";
|
|
16
|
+
|
|
17
|
+
import { Baseline } from "../baseline.ts";
|
|
18
|
+
|
|
19
|
+
import type { OpenApiOperations } from "./operations.ts";
|
|
20
|
+
import { OpenApiSchema } from "./schema.ts";
|
|
21
|
+
import { OpenApiSpec } from "./spec.ts";
|
|
22
|
+
|
|
23
|
+
export type Target = typeof Target.Type;
|
|
24
|
+
export const Target = Schema.Literals(["internal", "customer"]);
|
|
25
|
+
|
|
26
|
+
interface Naming {
|
|
27
|
+
readonly target: Target;
|
|
28
|
+
readonly pluginId: string;
|
|
29
|
+
readonly packageScope: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ownedHeader =
|
|
33
|
+
"// Written once by dual openapi-plugin; edit freely. Delete it to regenerate.\n";
|
|
34
|
+
|
|
35
|
+
function key(value: string) {
|
|
36
|
+
return /^[A-Za-z_$][\w$]*$/u.test(value) ? value : JSON.stringify(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function importLine(names: readonly string[], from: string) {
|
|
40
|
+
return `import { ${Array.join(names, ", ")} } from "${from}";`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const primitives = {
|
|
44
|
+
Boolean: "Schema.Boolean",
|
|
45
|
+
File: "Http.File",
|
|
46
|
+
Int: "Schema.Int",
|
|
47
|
+
Never: "Schema.Never",
|
|
48
|
+
Null: "Schema.Null",
|
|
49
|
+
Number: "Schema.Number",
|
|
50
|
+
String: "Schema.String",
|
|
51
|
+
ToolFile: "ToolFile.Schema",
|
|
52
|
+
Unknown: "Schema.Unknown",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function literals(values: readonly (string | number | boolean)[], separator: string) {
|
|
56
|
+
return Array.join(
|
|
57
|
+
Array.map(values, value => JSON.stringify(value)),
|
|
58
|
+
separator,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function annotation(method: "annotate" | "annotateKey", description?: string, format?: string) {
|
|
63
|
+
const entries = [
|
|
64
|
+
...(description === undefined ? [] : [`description: ${JSON.stringify(description)}`]),
|
|
65
|
+
...(format === undefined ? [] : [`format: ${JSON.stringify(format)}`]),
|
|
66
|
+
];
|
|
67
|
+
return Array.isReadonlyArrayEmpty(entries) ? "" : `.${method}({ ${Array.join(entries, ", ")} })`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const carriers = { base64: "Base64", base64url: "Base64Url", "data-uri": "DataUri" };
|
|
71
|
+
|
|
72
|
+
const clocks = { "rfc-2822": "Rfc2822", "unix-seconds": "UnixSeconds" };
|
|
73
|
+
|
|
74
|
+
function instantCodec(instant: {
|
|
75
|
+
clock: OpenApiSchema.Clock;
|
|
76
|
+
direction?: OpenApiSchema.Direction;
|
|
77
|
+
}) {
|
|
78
|
+
const clock = clocks[instant.clock];
|
|
79
|
+
return instant.direction === "input" ? `Http.${clock}FromDateTime` : `Http.DateTimeFrom${clock}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function bytesCodec(bytes: {
|
|
83
|
+
alphabet: OpenApiSchema.Alphabet;
|
|
84
|
+
direction?: OpenApiSchema.Direction;
|
|
85
|
+
}) {
|
|
86
|
+
const carrier = carriers[bytes.alphabet];
|
|
87
|
+
return bytes.direction === "input" ? `Http.${carrier}FromFile` : `Http.FileFrom${carrier}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function field(entry: OpenApiSchema.Field, encoded: HashSet.HashSet<string>) {
|
|
91
|
+
const schema = expression(entry.node, encoded);
|
|
92
|
+
const value =
|
|
93
|
+
entry.node._tag === "Ref" && !entry.node.lazy ? `Schema.suspend(() => ${schema})` : schema;
|
|
94
|
+
const described =
|
|
95
|
+
entry.node._tag === "Ref" ? annotation("annotateKey", entry.node.description) : "";
|
|
96
|
+
if (!entry.optional && entry.default !== undefined) {
|
|
97
|
+
return `${key(entry.name)}: ${value}.pipe(Schema.withDecodingDefaultKey(Effect.succeed(${JSON.stringify(entry.default)})))${described}`;
|
|
98
|
+
}
|
|
99
|
+
return `${key(entry.name)}: ${entry.optional ? `Schema.optionalKey(${value})` : value}${described}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function codec(name: string, type: string, encoded: HashSet.HashSet<string>) {
|
|
103
|
+
return `Schema.Codec<${HashSet.has(encoded, name) ? `${name}, ${type}` : name}>`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function expression(
|
|
107
|
+
node: OpenApiSchema.Node,
|
|
108
|
+
encoded: HashSet.HashSet<string>,
|
|
109
|
+
preserve = false,
|
|
110
|
+
): string {
|
|
111
|
+
const shape = pipe(
|
|
112
|
+
Match.value(node),
|
|
113
|
+
Match.tags({
|
|
114
|
+
Array: array => `Schema.Array(${expression(array.item, encoded)})`,
|
|
115
|
+
Bytes: bytesCodec,
|
|
116
|
+
Instant: instantCodec,
|
|
117
|
+
Literals: literal =>
|
|
118
|
+
literal.literals.length === 1
|
|
119
|
+
? `Schema.Literal(${literals(literal.literals, "")})`
|
|
120
|
+
: `Schema.Literals([${literals(literal.literals, ", ")}])`,
|
|
121
|
+
NullOr: nullable => `Schema.NullOr(${expression(nullable.node, encoded)})`,
|
|
122
|
+
Record: record => `Schema.Record(Schema.String, ${expression(record.value, encoded)})`,
|
|
123
|
+
Ref: ref =>
|
|
124
|
+
ref.lazy
|
|
125
|
+
? `Schema.suspend((): ${codec(ref.target, `typeof ${ref.target}.Encoded`, encoded)} => ${ref.target})`
|
|
126
|
+
: ref.target,
|
|
127
|
+
Struct: struct => {
|
|
128
|
+
const keys = Array.isReadonlyArrayEmpty(struct.excluded ?? [])
|
|
129
|
+
? "Schema.String"
|
|
130
|
+
: `Schema.String.check(Schema.isPattern(new RegExp(${JSON.stringify(
|
|
131
|
+
`^(?!(?:${Array.join(
|
|
132
|
+
Array.map(struct.excluded ?? [], name =>
|
|
133
|
+
String.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")(name),
|
|
134
|
+
),
|
|
135
|
+
"|",
|
|
136
|
+
)})$)`,
|
|
137
|
+
)} , "u")))`;
|
|
138
|
+
const fields = `Schema.Struct({\n${Array.join(
|
|
139
|
+
[
|
|
140
|
+
...Array.map(struct.spreads, spread => `...${spread}.fields`),
|
|
141
|
+
...Array.map(struct.fields, entry => field(entry, encoded)),
|
|
142
|
+
],
|
|
143
|
+
", ",
|
|
144
|
+
)}\n})`;
|
|
145
|
+
if (struct.additionalProperties !== undefined) {
|
|
146
|
+
const additional = expression(struct.additionalProperties, encoded);
|
|
147
|
+
const members = Array.dedupe([
|
|
148
|
+
additional,
|
|
149
|
+
...Array.map(struct.fields, entry => expression(entry.node, encoded)),
|
|
150
|
+
...Array.map(struct.spreads, spread => `Schema.Union(Record.values(${spread}.fields))`),
|
|
151
|
+
]);
|
|
152
|
+
const names = `[${Array.join(
|
|
153
|
+
[
|
|
154
|
+
...Array.map(struct.fields, entry => JSON.stringify(entry.name)),
|
|
155
|
+
...Array.map(struct.spreads, spread => `...Record.keys(${spread}.fields)`),
|
|
156
|
+
],
|
|
157
|
+
", ",
|
|
158
|
+
)}]`;
|
|
159
|
+
return `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Union([${Array.join(members, ", ")}]))]).check(Schema.makeFilter(input => Array.every(Record.toEntries(input), entry => Array.contains(${names}, entry[0]) || Schema.is(${additional})(entry[1])), { representation: { id: "dual/openapi/additionalProperties", payload: null, schemas: [${additional}.ast] }, toJsonSchema: context => ({ properties: Record.fromEntries(Array.map(${names}, name => [name, {}])), additionalProperties: Array.getUnsafe(context.schemas, 0) }) }))`;
|
|
160
|
+
}
|
|
161
|
+
return struct.rest || preserve
|
|
162
|
+
? `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Unknown)])`
|
|
163
|
+
: fields;
|
|
164
|
+
},
|
|
165
|
+
Union: union =>
|
|
166
|
+
`Schema.Union([${Array.join(
|
|
167
|
+
Array.map(union.members, member => expression(member, encoded, union.preserve)),
|
|
168
|
+
", ",
|
|
169
|
+
)}]${union.exclusive === true ? ', { mode: "oneOf" }' : ""})`,
|
|
170
|
+
}),
|
|
171
|
+
Match.orElse(primitive => primitives[primitive._tag]),
|
|
172
|
+
);
|
|
173
|
+
const checked =
|
|
174
|
+
node.checks === undefined ? shape : `${shape}.check(${Array.join(node.checks, ", ")})`;
|
|
175
|
+
return node._tag === "Ref"
|
|
176
|
+
? checked
|
|
177
|
+
: `${checked}${annotation("annotate", node.description, node.format)}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const typeKeywords = {
|
|
181
|
+
Boolean: "boolean",
|
|
182
|
+
File: "unknown",
|
|
183
|
+
Int: "number",
|
|
184
|
+
Never: "never",
|
|
185
|
+
Null: "null",
|
|
186
|
+
Number: "number",
|
|
187
|
+
String: "string",
|
|
188
|
+
ToolFile: "ToolFile.File",
|
|
189
|
+
Unknown: "unknown",
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
function typeOf(node: OpenApiSchema.Node, encoded?: HashSet.HashSet<string>): string {
|
|
193
|
+
function element(item: OpenApiSchema.Node) {
|
|
194
|
+
return item._tag === "Array" ||
|
|
195
|
+
item._tag === "Union" ||
|
|
196
|
+
item._tag === "NullOr" ||
|
|
197
|
+
item._tag === "Literals"
|
|
198
|
+
? `(${typeOf(item, encoded)})`
|
|
199
|
+
: typeOf(item, encoded);
|
|
200
|
+
}
|
|
201
|
+
return pipe(
|
|
202
|
+
Match.value(node),
|
|
203
|
+
Match.tags({
|
|
204
|
+
Array: array => `readonly ${element(array.item)}[]`,
|
|
205
|
+
Bytes: bytes => {
|
|
206
|
+
if (bytes.direction === "input") {
|
|
207
|
+
return encoded === undefined ? "string" : "typeof Http.File.Encoded";
|
|
208
|
+
}
|
|
209
|
+
return encoded === undefined ? "ToolFile.File" : "string";
|
|
210
|
+
},
|
|
211
|
+
Instant: instant => {
|
|
212
|
+
const wire = instant.clock === "unix-seconds" ? "number" : "string";
|
|
213
|
+
if (instant.direction === "input") {
|
|
214
|
+
return encoded === undefined ? wire : "string";
|
|
215
|
+
}
|
|
216
|
+
return encoded === undefined ? "string" : wire;
|
|
217
|
+
},
|
|
218
|
+
Literals: literal => literals(literal.literals, " | "),
|
|
219
|
+
NullOr: nullable => `${typeOf(nullable.node, encoded)} | null`,
|
|
220
|
+
Record: record => `{ readonly [key: string]: ${typeOf(record.value, encoded)} }`,
|
|
221
|
+
Ref: ref =>
|
|
222
|
+
encoded !== undefined && HashSet.has(encoded, ref.target)
|
|
223
|
+
? `typeof ${ref.target}.Encoded`
|
|
224
|
+
: ref.target,
|
|
225
|
+
Struct: struct =>
|
|
226
|
+
Array.join(
|
|
227
|
+
[
|
|
228
|
+
...Array.map(struct.spreads, target =>
|
|
229
|
+
typeOf({ _tag: "Ref", lazy: false, target }, encoded),
|
|
230
|
+
),
|
|
231
|
+
`{\n${Array.join(
|
|
232
|
+
[
|
|
233
|
+
...Array.map(
|
|
234
|
+
struct.fields,
|
|
235
|
+
entry =>
|
|
236
|
+
`readonly ${key(entry.name)}${entry.optional || (encoded !== undefined && entry.default !== undefined) ? "?" : ""}: ${typeOf(entry.node, encoded)}`,
|
|
237
|
+
),
|
|
238
|
+
...(struct.additionalProperties === undefined
|
|
239
|
+
? struct.rest
|
|
240
|
+
? ["readonly [key: string]: unknown"]
|
|
241
|
+
: []
|
|
242
|
+
: [
|
|
243
|
+
`readonly [key: string]: ${Array.join(
|
|
244
|
+
Array.dedupe([
|
|
245
|
+
typeOf(struct.additionalProperties, encoded),
|
|
246
|
+
...Array.map(struct.fields, entry => typeOf(entry.node, encoded)),
|
|
247
|
+
...(Array.some(struct.fields, entry => entry.optional)
|
|
248
|
+
? ["undefined"]
|
|
249
|
+
: []),
|
|
250
|
+
...Array.map(struct.spreads, spread => `${spread}[keyof ${spread}]`),
|
|
251
|
+
]),
|
|
252
|
+
" | ",
|
|
253
|
+
)}`,
|
|
254
|
+
]),
|
|
255
|
+
],
|
|
256
|
+
"; ",
|
|
257
|
+
)}\n}`,
|
|
258
|
+
],
|
|
259
|
+
" & ",
|
|
260
|
+
),
|
|
261
|
+
Union: union =>
|
|
262
|
+
Array.join(
|
|
263
|
+
Array.map(union.members, member => typeOf(member, encoded)),
|
|
264
|
+
" | ",
|
|
265
|
+
),
|
|
266
|
+
}),
|
|
267
|
+
Match.orElse(primitive => typeKeywords[primitive._tag]),
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function holds(node: OpenApiSchema.Node, found: (node: OpenApiSchema.Node) => boolean): boolean {
|
|
272
|
+
return (
|
|
273
|
+
found(node) ||
|
|
274
|
+
pipe(
|
|
275
|
+
Match.value(node),
|
|
276
|
+
Match.tags({
|
|
277
|
+
Array: array => holds(array.item, found),
|
|
278
|
+
NullOr: nullable => holds(nullable.node, found),
|
|
279
|
+
Record: record => holds(record.value, found),
|
|
280
|
+
Struct: struct =>
|
|
281
|
+
Array.some(struct.fields, entry => holds(entry.node, found)) ||
|
|
282
|
+
(struct.additionalProperties !== undefined && holds(struct.additionalProperties, found)),
|
|
283
|
+
Union: union => Array.some(union.members, member => holds(member, found)),
|
|
284
|
+
}),
|
|
285
|
+
Match.orElse(() => false),
|
|
286
|
+
)
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function referrers(
|
|
291
|
+
declarations: readonly OpenApiSchema.Declaration[],
|
|
292
|
+
found: (node: OpenApiSchema.Node) => boolean,
|
|
293
|
+
) {
|
|
294
|
+
const graph = Graph.directed<OpenApiSchema.Declaration, null>(mutable => {
|
|
295
|
+
const indices = HashMap.fromIterable(
|
|
296
|
+
Array.map(
|
|
297
|
+
declarations,
|
|
298
|
+
declaration => [declaration.name, Graph.addNode(mutable, declaration)] as const,
|
|
299
|
+
),
|
|
300
|
+
);
|
|
301
|
+
for (const declaration of declarations) {
|
|
302
|
+
for (const target of OpenApiSchema.targets(declaration.node)) {
|
|
303
|
+
Graph.addEdge(
|
|
304
|
+
mutable,
|
|
305
|
+
HashMap.getUnsafe(indices, declaration.name),
|
|
306
|
+
HashMap.getUnsafe(indices, target),
|
|
307
|
+
null,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
const start = Graph.findNodes(graph, declaration => holds(declaration.node, found));
|
|
313
|
+
return HashSet.fromIterable(
|
|
314
|
+
Array.map(
|
|
315
|
+
Array.fromIterable(Graph.dfs(graph, { direction: "incoming", start })),
|
|
316
|
+
entry => entry[1].name,
|
|
317
|
+
),
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Composite schemas carry a written type: an inferred schema type is spelled out structurally at
|
|
323
|
+
* every reference, which exceeds TypeScript's declaration size limit on large APIs.
|
|
324
|
+
*/
|
|
325
|
+
function declarationSource(
|
|
326
|
+
declaration: OpenApiSchema.Declaration,
|
|
327
|
+
encoded: HashSet.HashSet<string>,
|
|
328
|
+
) {
|
|
329
|
+
const name = declaration.name;
|
|
330
|
+
const value = `${expression(declaration.node, encoded)}${declaration.node._tag === "Ref" ? annotation("annotate", declaration.node.description) : ""}.annotate({ identifier: ${JSON.stringify(name)} })`;
|
|
331
|
+
return declaration.spread ||
|
|
332
|
+
declaration.node._tag === "Literals" ||
|
|
333
|
+
holds(declaration.node, node => node._tag === "File")
|
|
334
|
+
? `export type ${name} = typeof ${name}.Type;\nexport const ${name} = ${value};`
|
|
335
|
+
: `export type ${name} = ${typeOf(declaration.node)};\n${HashSet.has(encoded, name) ? `export type ${name}$Encoded = ${typeOf(declaration.node, encoded)};\n` : ""}export const ${name}: ${codec(name, `${name}$Encoded`, encoded)} = ${value};`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function uses(texts: readonly string[], namespace: string) {
|
|
339
|
+
const call = new RegExp(`(?<![\\w$.])${namespace}\\.[A-Za-z]`, "u");
|
|
340
|
+
return Array.some(texts, text => call.test(text));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function effectImport(texts: readonly string[]) {
|
|
344
|
+
const names = [
|
|
345
|
+
...(uses(texts, "Array") ? ["Array"] : []),
|
|
346
|
+
...(Array.some(texts, String.includes("Effect.succeed(")) ? ["Effect"] : []),
|
|
347
|
+
...(uses(texts, "Record") ? ["Record"] : []),
|
|
348
|
+
...(uses(texts, "Schema") ? ["Schema"] : []),
|
|
349
|
+
...(Array.some(texts, text => /(?<![\w$.])pipe\(/u.test(text)) ? ["pipe"] : []),
|
|
350
|
+
];
|
|
351
|
+
return Array.isReadonlyArrayNonEmpty(names) ? [importLine(names, "effect")] : [];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The module export of an action's contract and call, `group_action`, in each version file. */
|
|
355
|
+
export function exportName(id: string) {
|
|
356
|
+
const parts = pipe(id, String.split("/"));
|
|
357
|
+
return `${OpenApiSpec.camelize(Array.getUnsafe(parts, 1))}_${OpenApiSpec.camelize(Array.getUnsafe(parts, 2))}`;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function access(name: string) {
|
|
361
|
+
return key(name) === name ? `input.${name}` : `input[${key(name)}]`;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function urlParts(url: string, segments: readonly string[]) {
|
|
365
|
+
return Array.join(
|
|
366
|
+
Array.map(
|
|
367
|
+
pipe(url, String.split(/('\{[^}]*\}'|\{[^}]*\})/u), Array.filter(String.isNonEmpty)),
|
|
368
|
+
part => {
|
|
369
|
+
if (pipe(part, String.startsWith("'{"))) {
|
|
370
|
+
return `'\${Http.literal(${access(pipe(part, String.slice(2, -2)))})}'`;
|
|
371
|
+
}
|
|
372
|
+
if (!pipe(part, String.startsWith("{"))) {
|
|
373
|
+
return pipe(part, String.replaceAll("\\", "\\\\"), String.replaceAll("`", "\\`"));
|
|
374
|
+
}
|
|
375
|
+
const name = pipe(part, String.slice(1, -1));
|
|
376
|
+
return `\${Http.${Array.contains(segments, name) ? "segments" : "path"}(${access(name)})}`;
|
|
377
|
+
},
|
|
378
|
+
),
|
|
379
|
+
"",
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function urlTemplate(
|
|
384
|
+
url: string,
|
|
385
|
+
segments: readonly string[] = [],
|
|
386
|
+
alias?: OpenApiOperations.Alias,
|
|
387
|
+
) {
|
|
388
|
+
// An alias prefix is the start of the operation's path, so it splits the URL once.
|
|
389
|
+
const parts = pipe(url, String.split(alias?.prefix ?? "\u0000"));
|
|
390
|
+
const text =
|
|
391
|
+
alias === undefined
|
|
392
|
+
? urlParts(url, segments)
|
|
393
|
+
: `${urlParts(Array.headNonEmpty(parts), segments)}\${${access(alias.parameter)} === undefined ? ${JSON.stringify(alias.replacement)} : \`${urlParts(alias.prefix, segments)}\`}${urlParts(Array.join(Array.tailNonEmpty(parts), alias.prefix), segments)}`;
|
|
394
|
+
return pipe(text, String.includes("${")) ? `\`${text}\`` : JSON.stringify(url);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
type Joined = string | [string, string];
|
|
398
|
+
|
|
399
|
+
function encodings(
|
|
400
|
+
joined: readonly Joined[],
|
|
401
|
+
deep: readonly string[],
|
|
402
|
+
exploded: readonly string[] = [],
|
|
403
|
+
) {
|
|
404
|
+
if (Array.isReadonlyArrayNonEmpty(exploded)) {
|
|
405
|
+
return `, ${JSON.stringify(joined)}, ${JSON.stringify(deep)}, ${JSON.stringify(exploded)}`;
|
|
406
|
+
}
|
|
407
|
+
if (Array.isReadonlyArrayNonEmpty(deep)) {
|
|
408
|
+
return `, ${JSON.stringify(joined)}, ${JSON.stringify(deep)}`;
|
|
409
|
+
}
|
|
410
|
+
return Array.isReadonlyArrayEmpty(joined) ? "" : `, ${JSON.stringify(joined)}`;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function params(
|
|
414
|
+
names: readonly string[],
|
|
415
|
+
joined: readonly Joined[],
|
|
416
|
+
deep: readonly string[],
|
|
417
|
+
exploded: readonly string[] = [],
|
|
418
|
+
) {
|
|
419
|
+
const fields = Array.join(
|
|
420
|
+
Array.map(names, name => `${key(name)}: ${access(name)}`),
|
|
421
|
+
", ",
|
|
422
|
+
);
|
|
423
|
+
const sent = Array.filter(joined, entry =>
|
|
424
|
+
Array.contains(names, Predicate.isString(entry) ? entry : entry[0]),
|
|
425
|
+
);
|
|
426
|
+
return `Http.params({ ${fields} }${encodings(sent, Array.intersection(deep, names), Array.intersection(exploded, names))})`;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function bodyStep(contract: OpenApiSchema.Contract, body: OpenApiOperations.Body) {
|
|
430
|
+
const content = JSON.stringify(body.contentType);
|
|
431
|
+
const joinedFields = Array.map(body.joined ?? [], entry => {
|
|
432
|
+
const name = Predicate.isString(entry) ? entry : entry[0];
|
|
433
|
+
const delimiter = Predicate.isString(entry) ? "," : entry[1];
|
|
434
|
+
const payloadAccess = `input.payload[${JSON.stringify(name)}]`;
|
|
435
|
+
return `${key(name)}: Array.isArray(${payloadAccess}) ? ${payloadAccess}.join(${JSON.stringify(delimiter)}) : ${payloadAccess}`;
|
|
436
|
+
});
|
|
437
|
+
const multipartPayload = Array.isReadonlyArrayEmpty(joinedFields)
|
|
438
|
+
? "input.payload"
|
|
439
|
+
: `{ ...input.payload, ${Array.join(joinedFields, ", ")} }`;
|
|
440
|
+
const value = pipe(
|
|
441
|
+
Match.value(body.encoding),
|
|
442
|
+
Match.when("json", () =>
|
|
443
|
+
body.contentType === "application/json"
|
|
444
|
+
? "HttpClientRequest.bodyJsonUnsafe(input.payload)"
|
|
445
|
+
: `HttpClientRequest.bodyText(JSON.stringify(input.payload), ${content})`,
|
|
446
|
+
),
|
|
447
|
+
Match.when("text", () => `HttpClientRequest.bodyText(input.payload, ${content})`),
|
|
448
|
+
Match.when(
|
|
449
|
+
"binary",
|
|
450
|
+
() =>
|
|
451
|
+
`HttpClientRequest.bodyUint8Array(input.payload.contentBase64, input.payload.contentType ?? ${content})`,
|
|
452
|
+
),
|
|
453
|
+
Match.when(
|
|
454
|
+
"form",
|
|
455
|
+
() =>
|
|
456
|
+
`HttpClientRequest.bodyUrlParams(Http.params(input.payload${encodings(body.joined ?? [], body.deepObject ?? [])}))`,
|
|
457
|
+
),
|
|
458
|
+
Match.orElse(() => `HttpClientRequest.bodyFormDataRecord(Http.form(${multipartPayload}))`),
|
|
459
|
+
);
|
|
460
|
+
const conditions = [
|
|
461
|
+
...(contract.bodies.length > 1
|
|
462
|
+
? [
|
|
463
|
+
OpenApiSchema.defaultContentType(contract.bodies) === body.contentType
|
|
464
|
+
? `(input.contentType ?? ${content}) === ${content}`
|
|
465
|
+
: `input.contentType === ${content}`,
|
|
466
|
+
]
|
|
467
|
+
: []),
|
|
468
|
+
...(body.required ? [] : ["input.payload !== undefined"]),
|
|
469
|
+
];
|
|
470
|
+
return Array.isReadonlyArrayEmpty(conditions)
|
|
471
|
+
? value
|
|
472
|
+
: `(request: HttpClientRequest.HttpClientRequest) => ${Array.join(conditions, " && ")} ? ${value}(request) : request`;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function sentBy(contract: OpenApiSchema.Contract, payload: string, call: string) {
|
|
476
|
+
const graphql = contract.graphql;
|
|
477
|
+
if (graphql !== undefined) {
|
|
478
|
+
return `Http.graphql(context, output, pipe(HttpClientRequest.post(${JSON.stringify(graphql.endpoint)}), HttpClientRequest.bodyJsonUnsafe({ query: ${JSON.stringify(graphql.document)}, variables: ${payload} })), ${JSON.stringify(graphql.field)})`;
|
|
479
|
+
}
|
|
480
|
+
const mcp = contract.mcp;
|
|
481
|
+
if (mcp === undefined) {
|
|
482
|
+
return call;
|
|
483
|
+
}
|
|
484
|
+
return `Http.mcp(context, output, ${JSON.stringify(mcp.endpoint)}, ${JSON.stringify(mcp.tool)}, ${payload === "{}" ? payload : `${payload} ?? {}`}, ${mcp.structured})`;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function operationSource(
|
|
488
|
+
name: string,
|
|
489
|
+
contract: OpenApiSchema.Contract,
|
|
490
|
+
encoded: HashSet.HashSet<string>,
|
|
491
|
+
decoded: HashSet.HashSet<string>,
|
|
492
|
+
) {
|
|
493
|
+
const method = String.toLowerCase(contract.method);
|
|
494
|
+
const declared = `HttpClientRequest.${method}(${urlTemplate(contract.url, contract.pathSegments, contract.alias)})`;
|
|
495
|
+
const steps = [
|
|
496
|
+
...(Array.isReadonlyArrayEmpty(contract.query)
|
|
497
|
+
? []
|
|
498
|
+
: [
|
|
499
|
+
`HttpClientRequest.setUrlParams(${params(contract.query, [...contract.commaSeparated, ...(contract.delimited ?? [])], contract.deepObject ?? [], contract.exploded ?? [])})`,
|
|
500
|
+
]),
|
|
501
|
+
...(Array.isReadonlyArrayEmpty(contract.headers)
|
|
502
|
+
? []
|
|
503
|
+
: [`HttpClientRequest.setHeaders(${params(contract.headers, contract.commaSeparated, [])})`]),
|
|
504
|
+
...(contract.googleUpload === undefined
|
|
505
|
+
? Array.map(contract.bodies, body => bodyStep(contract, body))
|
|
506
|
+
: []),
|
|
507
|
+
];
|
|
508
|
+
const built = Array.isReadonlyArrayEmpty(steps)
|
|
509
|
+
? declared
|
|
510
|
+
: `pipe(${declared}, ${Array.join(steps, ", ")})`;
|
|
511
|
+
const preauthenticated = `Http.preauthenticated(HttpClientRequest.${method}, input.uploadUrl${Array.isReadonlyArrayEmpty(steps) ? "" : `, ${Array.join(steps, ", ")}`})`;
|
|
512
|
+
const continued =
|
|
513
|
+
contract.nextLink === true ? `Http.continuation(${built}, input.nextLink)` : built;
|
|
514
|
+
const request = contract.preauthenticatedUpload === true ? preauthenticated : continued;
|
|
515
|
+
const context = contract.preauthenticatedUpload === true ? "undefined" : "context";
|
|
516
|
+
const single = Array.getUnsafe(contract.responses, 0);
|
|
517
|
+
const upload = contract.googleUpload;
|
|
518
|
+
const variants = `Http.variants(${context}, output, ${request}, ${JSON.stringify(
|
|
519
|
+
Array.map(contract.responses, response => ({
|
|
520
|
+
body: response.kind,
|
|
521
|
+
contentType: response.contentType,
|
|
522
|
+
...(response.headers === undefined ? {} : { headers: response.headers }),
|
|
523
|
+
...(/^2\d\d$/u.test(response.status) ? { status: Number(response.status) } : {}),
|
|
524
|
+
})),
|
|
525
|
+
)}${contract.googleDownload === true ? ', input.alt === "media"' : ""})`;
|
|
526
|
+
const plain =
|
|
527
|
+
contract.responses.length === 1 && single.headers === undefined
|
|
528
|
+
? `Http.execute(${context}, output, ${request}, ${JSON.stringify(single.kind)})`
|
|
529
|
+
: variants;
|
|
530
|
+
const call =
|
|
531
|
+
upload === undefined
|
|
532
|
+
? plain
|
|
533
|
+
: `Http.googleUpload(context, output, ${request}, input.payload, { ${Array.join(
|
|
534
|
+
[
|
|
535
|
+
...(upload.maxSize === undefined ? [] : [`maxSize: ${Number(upload.maxSize)}`]),
|
|
536
|
+
...(upload.resumableUrl === undefined
|
|
537
|
+
? []
|
|
538
|
+
: [`resumable: ${urlTemplate(upload.resumableUrl)}`]),
|
|
539
|
+
],
|
|
540
|
+
", ",
|
|
541
|
+
)} })`;
|
|
542
|
+
const payload = Array.isReadonlyArrayEmpty(contract.bodies) ? "{}" : "input.payload";
|
|
543
|
+
const sent = sentBy(contract, payload, call);
|
|
544
|
+
const reads = /\binput[.[]/u.test(sent);
|
|
545
|
+
const output = expression(contract.output, encoded);
|
|
546
|
+
return `export const ${name} = Http.endpoint({ input: ${expression(contract.input, encoded)}, output: ${holds(contract.output, node => OpenApiSchema.converts(node) || (node._tag === "Ref" && HashSet.has(decoded, node.target))) ? `Http.decoded(${output})` : output} }, (${reads ? "input" : "_input"}, ${context === "context" || contract.graphql !== undefined || contract.mcp !== undefined ? "context" : "_context"}, output) => ${sent});`;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/** A version file: the schemas and calls of the actions that changed in that version, never edited afterwards. */
|
|
550
|
+
export function operationsSource(
|
|
551
|
+
declarations: readonly OpenApiSchema.Declaration[],
|
|
552
|
+
actions: readonly { readonly name: string; readonly contract: OpenApiSchema.Contract }[],
|
|
553
|
+
) {
|
|
554
|
+
const encoded = referrers(
|
|
555
|
+
declarations,
|
|
556
|
+
node =>
|
|
557
|
+
OpenApiSchema.converts(node) ||
|
|
558
|
+
(node._tag === "Struct" &&
|
|
559
|
+
Array.some(node.fields, entry => !entry.optional && entry.default !== undefined)),
|
|
560
|
+
);
|
|
561
|
+
const decoded = referrers(declarations, OpenApiSchema.converts);
|
|
562
|
+
const texts = [
|
|
563
|
+
...Array.map(declarations, declaration => declarationSource(declaration, encoded)),
|
|
564
|
+
...Array.map(actions, action =>
|
|
565
|
+
operationSource(action.name, action.contract, encoded, decoded),
|
|
566
|
+
),
|
|
567
|
+
];
|
|
568
|
+
return `// Generated by dual openapi-plugin; current contracts and handlers.\n${Array.join(
|
|
569
|
+
[
|
|
570
|
+
Array.join(
|
|
571
|
+
[
|
|
572
|
+
...effectImport(texts),
|
|
573
|
+
...(Array.some(texts, String.includes("HttpClientRequest."))
|
|
574
|
+
? ['import { HttpClientRequest } from "effect/http";']
|
|
575
|
+
: []),
|
|
576
|
+
...(uses(texts, "ToolFile") ? [importLine(["ToolFile"], "@dual-os/sdk")] : []),
|
|
577
|
+
'import * as Http from "./http.ts";',
|
|
578
|
+
],
|
|
579
|
+
"\n",
|
|
580
|
+
),
|
|
581
|
+
...texts,
|
|
582
|
+
],
|
|
583
|
+
"\n\n",
|
|
584
|
+
)}\n`;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
interface Provider {
|
|
588
|
+
readonly name: string;
|
|
589
|
+
readonly metadata: Record.ReadonlyRecord<string, unknown>;
|
|
590
|
+
readonly groups: readonly string[];
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
interface PluginAction {
|
|
594
|
+
readonly key: string;
|
|
595
|
+
readonly group: string;
|
|
596
|
+
readonly id: string;
|
|
597
|
+
readonly name: string;
|
|
598
|
+
readonly description: Option.Option<string>;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function pluginConstant(pluginId: string) {
|
|
602
|
+
return `${OpenApiSpec.camelize(pluginId)}Plugin`;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function pluginBaseConstant(pluginId: string) {
|
|
606
|
+
return `${OpenApiSpec.camelize(pluginId)}PluginBase`;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function groupConstant(group: string) {
|
|
610
|
+
return `${OpenApiSpec.camelize(group)}Group`;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** Current contracts and fluent implementations for one plugin. */
|
|
614
|
+
export function pluginSource(options: {
|
|
615
|
+
readonly pluginId: string;
|
|
616
|
+
readonly metadata: Record.ReadonlyRecord<string, unknown>;
|
|
617
|
+
readonly provider: Provider;
|
|
618
|
+
readonly actions: readonly PluginAction[];
|
|
619
|
+
readonly sandboxAccess: boolean;
|
|
620
|
+
}) {
|
|
621
|
+
const base = pluginBaseConstant(options.pluginId);
|
|
622
|
+
const definitions = Array.map(options.actions, action => {
|
|
623
|
+
const metadata = {
|
|
624
|
+
name: action.name,
|
|
625
|
+
...Option.match(action.description, {
|
|
626
|
+
onNone: () => ({}),
|
|
627
|
+
onSome: description => ({ description }),
|
|
628
|
+
}),
|
|
629
|
+
};
|
|
630
|
+
return `const ${exportName(action.key)} = Action.make(${JSON.stringify(action.id)}, { ...Operations.${exportName(action.key)}, ...${JSON.stringify(metadata)} });`;
|
|
631
|
+
});
|
|
632
|
+
const groups = Array.map(
|
|
633
|
+
options.provider.groups,
|
|
634
|
+
group =>
|
|
635
|
+
`const ${groupConstant(group)} = Group.make(${JSON.stringify(group)}).pipe(Group.withName(${JSON.stringify(OpenApiSpec.titleCase(group))}), Group.withActions([${Array.join(
|
|
636
|
+
Array.map(
|
|
637
|
+
Array.filter(options.actions, action => action.group === group),
|
|
638
|
+
action => exportName(action.key),
|
|
639
|
+
),
|
|
640
|
+
", ",
|
|
641
|
+
)}]));`,
|
|
642
|
+
);
|
|
643
|
+
const handlers = Array.join(
|
|
644
|
+
Array.map(
|
|
645
|
+
options.provider.groups,
|
|
646
|
+
group =>
|
|
647
|
+
`.group(${JSON.stringify(group)}, handlers => handlers${Array.join(
|
|
648
|
+
Array.map(
|
|
649
|
+
Array.filter(options.actions, action => action.group === group),
|
|
650
|
+
action =>
|
|
651
|
+
`.action(${JSON.stringify(action.id)}, Operations.${exportName(action.key)}.run)`,
|
|
652
|
+
),
|
|
653
|
+
"",
|
|
654
|
+
)})`,
|
|
655
|
+
),
|
|
656
|
+
"",
|
|
657
|
+
);
|
|
658
|
+
return `${Array.join(
|
|
659
|
+
[
|
|
660
|
+
"// Generated by dual openapi-plugin; rerun it instead of editing.",
|
|
661
|
+
'import { Action, Group, Plugin } from "@dual-os/sdk";',
|
|
662
|
+
'import { FetchHttpClient, HttpClient } from "effect/http";',
|
|
663
|
+
'import * as Auth from "../auth.ts";',
|
|
664
|
+
'import * as Triggers from "../triggers.ts";',
|
|
665
|
+
'import * as Operations from "./operations.ts";',
|
|
666
|
+
...definitions,
|
|
667
|
+
...groups,
|
|
668
|
+
`export const ${base}: Plugin.Definition<${JSON.stringify(options.pluginId)}, typeof Auth.authMethods, readonly [${Array.join(
|
|
669
|
+
Array.map(options.provider.groups, group => `typeof ${groupConstant(group)}`),
|
|
670
|
+
", ",
|
|
671
|
+
)}], readonly [], typeof Triggers.triggers> = Plugin.make(${JSON.stringify(options.pluginId)}).pipe(${Array.join(
|
|
672
|
+
[
|
|
673
|
+
`Plugin.withName(${JSON.stringify(options.metadata["name"] ?? options.provider.name)})`,
|
|
674
|
+
...Array.map(
|
|
675
|
+
Record.toEntries({
|
|
676
|
+
...options.provider.metadata,
|
|
677
|
+
...Record.remove(options.metadata, "name"),
|
|
678
|
+
}),
|
|
679
|
+
([key, value]) => `Plugin.with${String.capitalize(key)}(${JSON.stringify(value)})`,
|
|
680
|
+
),
|
|
681
|
+
"Plugin.withAuthMethods(Auth.authMethods)",
|
|
682
|
+
...(options.sandboxAccess ? ["Plugin.withSandboxAccess(Auth.sandboxAccess)"] : []),
|
|
683
|
+
`Plugin.withGroups([${Array.join(Array.map(options.provider.groups, groupConstant), ", ")}])`,
|
|
684
|
+
"Plugin.withTriggers(Triggers.triggers)",
|
|
685
|
+
],
|
|
686
|
+
", ",
|
|
687
|
+
)});`,
|
|
688
|
+
`const live = Plugin.toLayer(${base}, handlers => handlers${handlers}.withTriggers(Triggers.handlers));`,
|
|
689
|
+
`export const ${pluginConstant(options.pluginId)}: Plugin.Provided<typeof ${base}, Plugin.HandlerServices<typeof ${base}> | HttpClient.HttpClient> = ${base}.pipe(Plugin.provide(live), Plugin.provide(FetchHttpClient.layer));`,
|
|
690
|
+
],
|
|
691
|
+
"\n\n",
|
|
692
|
+
)}\n`;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/** The package's binding of the SDK's HTTP runtime to its auth methods. */
|
|
696
|
+
export const httpSource = `// Generated by dual openapi-plugin; rerun it instead of editing.
|
|
697
|
+
import { Http } from "@dual-os/sdk";
|
|
698
|
+
import type { Action } from "@dual-os/sdk";
|
|
699
|
+
|
|
700
|
+
import * as Auth from "../auth.ts";
|
|
701
|
+
|
|
702
|
+
export {
|
|
703
|
+
Base64FromFile,
|
|
704
|
+
Base64UrlFromFile,
|
|
705
|
+
DataUriFromFile,
|
|
706
|
+
DateTimeFromRfc2822,
|
|
707
|
+
DateTimeFromUnixSeconds,
|
|
708
|
+
File,
|
|
709
|
+
FileFromBase64,
|
|
710
|
+
FileFromBase64Url,
|
|
711
|
+
FileFromDataUri,
|
|
712
|
+
Rfc2822FromDateTime,
|
|
713
|
+
UnixSecondsFromDateTime,
|
|
714
|
+
continuation,
|
|
715
|
+
decoded,
|
|
716
|
+
form,
|
|
717
|
+
literal,
|
|
718
|
+
params,
|
|
719
|
+
path,
|
|
720
|
+
preauthenticated,
|
|
721
|
+
segments,
|
|
722
|
+
} from "@dual-os/sdk/Http";
|
|
723
|
+
|
|
724
|
+
export type Handler<Input, Output> = Http.Handler<typeof Auth.authMethods, Input, Output>;
|
|
725
|
+
|
|
726
|
+
export interface Context extends Action.HandlerContext<typeof Auth.authMethods> {}
|
|
727
|
+
|
|
728
|
+
export const { endpoint, execute, googleUpload, graphql, mcp, variants } = Http.make<
|
|
729
|
+
typeof Auth.authMethods,
|
|
730
|
+
Context
|
|
731
|
+
>(Auth);
|
|
732
|
+
|
|
733
|
+
export * as Http from "./http.ts";
|
|
734
|
+
`;
|
|
735
|
+
|
|
736
|
+
export const triggersSource = `${ownedHeader}
|
|
737
|
+
export const triggers = [] as const;
|
|
738
|
+
export const handlers = {};
|
|
739
|
+
`;
|
|
740
|
+
|
|
741
|
+
function authMethodConstant(scheme: OpenApiSpec.SecurityScheme) {
|
|
742
|
+
return `${OpenApiSpec.camelize(scheme.methodId)}Method`;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function derived(scheme: OpenApiSpec.SecurityScheme) {
|
|
746
|
+
function declaration(constructor: string, entries: readonly string[]) {
|
|
747
|
+
return `const ${authMethodConstant(scheme)} = ${constructor}(${JSON.stringify(scheme.methodId)}, { ${Array.join(entries, ",\n")} });`;
|
|
748
|
+
}
|
|
749
|
+
const description =
|
|
750
|
+
scheme.description === undefined ? [] : [`description: ${JSON.stringify(scheme.description)}`];
|
|
751
|
+
const name = `name: ${JSON.stringify(scheme.displayName)}`;
|
|
752
|
+
function credential(schema: string, request: string) {
|
|
753
|
+
return Option.some({
|
|
754
|
+
method: declaration("AuthMethod.make", [
|
|
755
|
+
...description,
|
|
756
|
+
name,
|
|
757
|
+
`schema: Schema.Struct({ ${schema} })`,
|
|
758
|
+
]),
|
|
759
|
+
request,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
return pipe(
|
|
763
|
+
Match.value(scheme.kind),
|
|
764
|
+
Match.tag("HttpBearer", () =>
|
|
765
|
+
credential("token: Schema.String", "HttpClientRequest.bearerToken(binding.value.token)"),
|
|
766
|
+
),
|
|
767
|
+
Match.tag("HttpBasic", () =>
|
|
768
|
+
credential(
|
|
769
|
+
"password: Schema.String, username: Schema.String",
|
|
770
|
+
"HttpClientRequest.basicAuth(binding.value.username, binding.value.password)",
|
|
771
|
+
),
|
|
772
|
+
),
|
|
773
|
+
Match.tag("ApiKey", kind =>
|
|
774
|
+
credential(
|
|
775
|
+
"apiKey: Schema.String",
|
|
776
|
+
`HttpClientRequest.${kind.in === "header" ? "setHeader" : "setUrlParam"}(${JSON.stringify(kind.key)}, binding.value.apiKey)`,
|
|
777
|
+
),
|
|
778
|
+
),
|
|
779
|
+
Match.tag("OAuth2", kind =>
|
|
780
|
+
Option.some({
|
|
781
|
+
method: Array.join(
|
|
782
|
+
[
|
|
783
|
+
...(kind.authorizationUrl === undefined
|
|
784
|
+
? ["// TODO: the document declares no authorization URL; add `authorizationUrl`."]
|
|
785
|
+
: []),
|
|
786
|
+
...(kind.tokenUrl === undefined
|
|
787
|
+
? ["// TODO: the document declares no token URL; add `tokenUrl`."]
|
|
788
|
+
: []),
|
|
789
|
+
declaration("AuthMethod.oauth2", [
|
|
790
|
+
...(kind.authorizationUrl === undefined
|
|
791
|
+
? []
|
|
792
|
+
: [`authorizationUrl: ${JSON.stringify(kind.authorizationUrl)}`]),
|
|
793
|
+
...(kind.resource === undefined
|
|
794
|
+
? []
|
|
795
|
+
: [`authorizationParams: { resource: ${JSON.stringify(kind.resource)} }`]),
|
|
796
|
+
kind.authentication === undefined
|
|
797
|
+
? '// TODO: confirm the token endpoint authentication style; "post" is the default.\nclient: options => ({ authentication: "post", clientId: options.setup.clientId, clientSecret: options.setup.clientSecret })'
|
|
798
|
+
: `client: options => ({ authentication: ${JSON.stringify(kind.authentication)}, clientId: options.setup.clientId, clientSecret: options.setup.clientSecret })`,
|
|
799
|
+
...description,
|
|
800
|
+
kind.pkce === undefined
|
|
801
|
+
? "// TODO: add `pkce: true` when this provider requires PKCE.\nmaterial: AuthMethod.OAuth2TokenMaterial"
|
|
802
|
+
: "material: AuthMethod.OAuth2TokenMaterial",
|
|
803
|
+
name,
|
|
804
|
+
...(kind.pkce === true ? ["pkce: true"] : []),
|
|
805
|
+
`scopes: ${JSON.stringify(kind.scopes)}`,
|
|
806
|
+
"setup: Schema.Struct({ clientId: Schema.String, clientSecret: Schema.String })",
|
|
807
|
+
...(kind.tokenUrl === undefined
|
|
808
|
+
? []
|
|
809
|
+
: [`tokenUrl: ${JSON.stringify(kind.tokenUrl)}`]),
|
|
810
|
+
...(kind.resource === undefined
|
|
811
|
+
? []
|
|
812
|
+
: [`tokenParams: { resource: ${JSON.stringify(kind.resource)} }`]),
|
|
813
|
+
]),
|
|
814
|
+
],
|
|
815
|
+
"\n",
|
|
816
|
+
),
|
|
817
|
+
request: "HttpClientRequest.bearerToken(binding.value.accessToken)",
|
|
818
|
+
}),
|
|
819
|
+
),
|
|
820
|
+
Match.tag("Unsupported", () => Option.none()),
|
|
821
|
+
Match.exhaustive,
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export function authSource(schemes: readonly OpenApiSpec.SecurityScheme[]) {
|
|
826
|
+
const supported = pipe(
|
|
827
|
+
schemes,
|
|
828
|
+
Array.filterMap(scheme =>
|
|
829
|
+
Option.match(derived(scheme), {
|
|
830
|
+
onNone: () => Result.failVoid,
|
|
831
|
+
onSome: parts => Result.succeed({ ...parts, scheme }),
|
|
832
|
+
}),
|
|
833
|
+
),
|
|
834
|
+
Array.sort(
|
|
835
|
+
Order.mapInput(
|
|
836
|
+
Order.String,
|
|
837
|
+
(entry: { readonly scheme: OpenApiSpec.SecurityScheme }) => entry.scheme.methodId,
|
|
838
|
+
),
|
|
839
|
+
),
|
|
840
|
+
);
|
|
841
|
+
const notes = Array.flatMap(schemes, scheme =>
|
|
842
|
+
scheme.kind._tag === "Unsupported"
|
|
843
|
+
? [`// ${scheme.name} (${scheme.methodId}): ${scheme.kind.reason}`]
|
|
844
|
+
: [],
|
|
845
|
+
);
|
|
846
|
+
const todo = Array.isReadonlyArrayNonEmpty(notes)
|
|
847
|
+
? [
|
|
848
|
+
Array.join(
|
|
849
|
+
[
|
|
850
|
+
"// TODO: dual openapi-plugin derives no AuthMethod for these security schemes:",
|
|
851
|
+
...notes,
|
|
852
|
+
"// Add an AuthMethod for each one this plugin needs, list it in `authMethods`,",
|
|
853
|
+
"// and give it a case in `authorize`.",
|
|
854
|
+
],
|
|
855
|
+
"\n",
|
|
856
|
+
),
|
|
857
|
+
]
|
|
858
|
+
: [];
|
|
859
|
+
if (!Array.isReadonlyArrayNonEmpty(supported)) {
|
|
860
|
+
return `${ownedHeader}
|
|
861
|
+
import type { HttpClient } from "effect/http";
|
|
862
|
+
|
|
863
|
+
import type { Action } from "@dual-os/sdk";
|
|
864
|
+
|
|
865
|
+
${Array.join(
|
|
866
|
+
Array.isReadonlyArrayNonEmpty(todo)
|
|
867
|
+
? todo
|
|
868
|
+
: [
|
|
869
|
+
"// TODO: this OpenAPI document declares no security schemes. Add an AuthMethod here\n// and use it below when the API needs credentials.",
|
|
870
|
+
],
|
|
871
|
+
"\n\n",
|
|
872
|
+
)}
|
|
873
|
+
|
|
874
|
+
export const authMethods = [] as const;
|
|
875
|
+
|
|
876
|
+
export function authorize(
|
|
877
|
+
client: HttpClient.HttpClient,
|
|
878
|
+
_context: Action.HandlerContext<typeof authMethods>,
|
|
879
|
+
): HttpClient.HttpClient {
|
|
880
|
+
return client;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export * as Auth from "./auth.ts";
|
|
884
|
+
`;
|
|
885
|
+
}
|
|
886
|
+
const cases = Array.join(
|
|
887
|
+
Array.map(
|
|
888
|
+
supported,
|
|
889
|
+
entry =>
|
|
890
|
+
`${key(entry.scheme.methodId)}: binding => HttpClient.mapRequest(client, ${entry.request})`,
|
|
891
|
+
),
|
|
892
|
+
", ",
|
|
893
|
+
);
|
|
894
|
+
return `${ownedHeader}
|
|
895
|
+
import { Match, Schema, pipe } from "effect";
|
|
896
|
+
|
|
897
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
898
|
+
|
|
899
|
+
import { AuthMethod } from "@dual-os/sdk";
|
|
900
|
+
import type { Action } from "@dual-os/sdk";
|
|
901
|
+
|
|
902
|
+
${Array.join([...todo, ...Array.map(supported, entry => entry.method)], "\n\n")}
|
|
903
|
+
|
|
904
|
+
export const authMethods = [${Array.join(
|
|
905
|
+
Array.map(supported, entry => authMethodConstant(entry.scheme)),
|
|
906
|
+
", ",
|
|
907
|
+
)}] as const;
|
|
908
|
+
|
|
909
|
+
export function authorize(
|
|
910
|
+
client: HttpClient.HttpClient,
|
|
911
|
+
context: Action.HandlerContext<typeof authMethods>,
|
|
912
|
+
): HttpClient.HttpClient {
|
|
913
|
+
return pipe(
|
|
914
|
+
Match.value(context.auth.current),
|
|
915
|
+
Match.discriminatorsExhaustive("methodId")({ ${cases} }),
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export * as Auth from "./auth.ts";
|
|
920
|
+
`;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function packageName(naming: Naming) {
|
|
924
|
+
return naming.target === "internal"
|
|
925
|
+
? `@dual-os/${naming.pluginId}`
|
|
926
|
+
: `${naming.packageScope}/${naming.pluginId}`;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
export function packageJsonSource(naming: Naming, sdkRange: string) {
|
|
930
|
+
// Consumers load the build: ~90 plugin sources in one program exceed TypeScript's instantiation depth.
|
|
931
|
+
const entry = "./dist/generated/plugin.js";
|
|
932
|
+
return JSON.stringify({
|
|
933
|
+
name: packageName(naming),
|
|
934
|
+
...(naming.target === "customer" ? { private: true } : {}),
|
|
935
|
+
version: "0.0.0",
|
|
936
|
+
type: "module",
|
|
937
|
+
license: "UNLICENSED",
|
|
938
|
+
exports: {
|
|
939
|
+
".": entry,
|
|
940
|
+
"./definition": entry,
|
|
941
|
+
"./executable": entry,
|
|
942
|
+
"./package.json": "./package.json",
|
|
943
|
+
"./plugin.json": "./plugin.json",
|
|
944
|
+
},
|
|
945
|
+
files: ["dist/**", "src/**/*.ts", "!src/**/*.test.ts", "LICENSE", "plugin.json"],
|
|
946
|
+
scripts:
|
|
947
|
+
naming.target === "internal"
|
|
948
|
+
? { prepack: "vp run build" }
|
|
949
|
+
: { build: "vp pack", "check-types": "tsc --noEmit", prepack: "vp pack" },
|
|
950
|
+
dual: {
|
|
951
|
+
plugin: {
|
|
952
|
+
assets: ["dist/**"],
|
|
953
|
+
entrypoint: "dist/generated/plugin.js",
|
|
954
|
+
export: pluginConstant(naming.pluginId),
|
|
955
|
+
},
|
|
956
|
+
},
|
|
957
|
+
dependencies: {
|
|
958
|
+
"@dual-os/sdk": naming.target === "internal" ? "workspace:*" : sdkRange,
|
|
959
|
+
effect: Baseline.versions.effect,
|
|
960
|
+
},
|
|
961
|
+
devDependencies: {
|
|
962
|
+
typescript: Baseline.versions.typescript,
|
|
963
|
+
// The repository's root install owns Vite+ for internal plugins.
|
|
964
|
+
...(naming.target === "customer" ? { "vite-plus": "1.3.0" } : {}),
|
|
965
|
+
},
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
export function pluginJsonSource(naming: Naming, openapi: Record.ReadonlyRecord<string, unknown>) {
|
|
970
|
+
return JSON.stringify({
|
|
971
|
+
exports: {
|
|
972
|
+
definition: { export: pluginBaseConstant(naming.pluginId), subpath: "./definition" },
|
|
973
|
+
executable: { export: pluginConstant(naming.pluginId), subpath: "./executable" },
|
|
974
|
+
},
|
|
975
|
+
identity: { package: packageName(naming), plugin: naming.pluginId },
|
|
976
|
+
openapi,
|
|
977
|
+
schemaVersion: 1,
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
export function tsconfigSource() {
|
|
982
|
+
return JSON.stringify({
|
|
983
|
+
compilerOptions: {
|
|
984
|
+
target: "ESNext",
|
|
985
|
+
module: "ESNext",
|
|
986
|
+
moduleResolution: "Bundler",
|
|
987
|
+
strict: true,
|
|
988
|
+
skipLibCheck: true,
|
|
989
|
+
noEmit: true,
|
|
990
|
+
allowImportingTsExtensions: true,
|
|
991
|
+
exactOptionalPropertyTypes: true,
|
|
992
|
+
types: [],
|
|
993
|
+
},
|
|
994
|
+
include: ["src", "test"],
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export function viteConfigSource(target: Target) {
|
|
999
|
+
const pack = {
|
|
1000
|
+
entry: ["src/**/*.ts", "!src/**/*.test.ts", "!src/**/*.spec.ts"],
|
|
1001
|
+
root: "src",
|
|
1002
|
+
unbundle: true,
|
|
1003
|
+
fixedExtension: false,
|
|
1004
|
+
sourcemap: true,
|
|
1005
|
+
// The repository emits declarations with its pinned tsrs; customer packages use their TypeScript.
|
|
1006
|
+
dts: target === "internal" ? { sourcemap: true, tsgo: { path: "tsrs" } } : { sourcemap: true },
|
|
1007
|
+
};
|
|
1008
|
+
const run = {
|
|
1009
|
+
tasks: {
|
|
1010
|
+
build: {
|
|
1011
|
+
command: "vp pack -l error",
|
|
1012
|
+
dependsOn: [{ task: "build", from: ["dependencies", "devDependencies"] }],
|
|
1013
|
+
},
|
|
1014
|
+
"check:generated": {
|
|
1015
|
+
command: "tsrs -p tsconfig.json --checkerAssignment go",
|
|
1016
|
+
dependsOn: [{ task: "build", from: "devDependencies" }],
|
|
1017
|
+
cache: { output: [] },
|
|
1018
|
+
},
|
|
1019
|
+
},
|
|
1020
|
+
};
|
|
1021
|
+
const config = target === "internal" ? { pack, run } : { pack };
|
|
1022
|
+
return `import { defineConfig } from "vite-plus";\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
export const licenseSource = `All rights reserved.
|
|
1026
|
+
|
|
1027
|
+
This package is proprietary and is not licensed for public use or redistribution.
|
|
1028
|
+
Use and distribution require permission from the rights holder under a separate agreement.
|
|
1029
|
+
`;
|
|
1030
|
+
|
|
1031
|
+
export * as OpenApiEmit from "./emit.ts";
|