@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,422 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Effect,
|
|
4
|
+
Match,
|
|
5
|
+
Option,
|
|
6
|
+
Predicate,
|
|
7
|
+
Record,
|
|
8
|
+
Result,
|
|
9
|
+
Schema,
|
|
10
|
+
String,
|
|
11
|
+
pipe,
|
|
12
|
+
} from "effect";
|
|
13
|
+
|
|
14
|
+
type JsonObject = typeof JsonObject.Type;
|
|
15
|
+
const JsonObject = Schema.Record(Schema.String, Schema.Unknown);
|
|
16
|
+
|
|
17
|
+
type MediaTypes = typeof MediaTypes.Type;
|
|
18
|
+
const MediaTypes = Schema.Array(Schema.String);
|
|
19
|
+
|
|
20
|
+
type Parameter = typeof Parameter.Type;
|
|
21
|
+
const Parameter = Schema.StructWithRest(
|
|
22
|
+
Schema.Struct({
|
|
23
|
+
collectionFormat: Schema.optionalKey(Schema.String),
|
|
24
|
+
description: Schema.optionalKey(Schema.String),
|
|
25
|
+
in: Schema.String,
|
|
26
|
+
name: Schema.String,
|
|
27
|
+
required: Schema.optionalKey(Schema.Boolean),
|
|
28
|
+
schema: Schema.optionalKey(Schema.Unknown),
|
|
29
|
+
type: Schema.optionalKey(Schema.String),
|
|
30
|
+
}),
|
|
31
|
+
[JsonObject],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
type Response = typeof Response.Type;
|
|
35
|
+
const Response = Schema.Struct({
|
|
36
|
+
description: Schema.optionalKey(Schema.String),
|
|
37
|
+
headers: Schema.optionalKey(Schema.Record(Schema.String, JsonObject)),
|
|
38
|
+
schema: Schema.optionalKey(Schema.Unknown),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
type Operation = typeof Operation.Type;
|
|
42
|
+
const Operation = Schema.StructWithRest(
|
|
43
|
+
Schema.Struct({
|
|
44
|
+
consumes: Schema.optionalKey(MediaTypes),
|
|
45
|
+
parameters: Schema.optionalKey(Schema.Array(JsonObject)),
|
|
46
|
+
produces: Schema.optionalKey(MediaTypes),
|
|
47
|
+
responses: Schema.Record(Schema.String, JsonObject),
|
|
48
|
+
}),
|
|
49
|
+
[JsonObject],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
type SecurityDefinition = typeof SecurityDefinition.Type;
|
|
53
|
+
const SecurityDefinition = Schema.Struct({
|
|
54
|
+
authorizationUrl: Schema.optionalKey(Schema.String),
|
|
55
|
+
description: Schema.optionalKey(Schema.String),
|
|
56
|
+
flow: Schema.optionalKey(Schema.String),
|
|
57
|
+
in: Schema.optionalKey(Schema.String),
|
|
58
|
+
name: Schema.optionalKey(Schema.String),
|
|
59
|
+
scopes: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
60
|
+
tokenUrl: Schema.optionalKey(Schema.String),
|
|
61
|
+
type: Schema.String,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
type ParameterizedHost = typeof ParameterizedHost.Type;
|
|
65
|
+
const ParameterizedHost = Schema.Struct({
|
|
66
|
+
hostTemplate: Schema.String,
|
|
67
|
+
parameters: Schema.optionalKey(
|
|
68
|
+
Schema.Array(
|
|
69
|
+
Schema.Struct({
|
|
70
|
+
default: Schema.optionalKey(Schema.String),
|
|
71
|
+
description: Schema.optionalKey(Schema.String),
|
|
72
|
+
enum: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
73
|
+
format: Schema.optionalKey(Schema.String),
|
|
74
|
+
name: Schema.String,
|
|
75
|
+
}),
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
useSchemePrefix: Schema.optionalKey(Schema.Boolean),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
type Swagger = typeof Swagger.Type;
|
|
82
|
+
const Swagger = Schema.StructWithRest(
|
|
83
|
+
Schema.Struct({
|
|
84
|
+
basePath: Schema.optionalKey(Schema.String),
|
|
85
|
+
consumes: Schema.optionalKey(MediaTypes),
|
|
86
|
+
definitions: Schema.optionalKey(JsonObject),
|
|
87
|
+
host: Schema.optionalKey(Schema.String),
|
|
88
|
+
parameters: Schema.optionalKey(Schema.Record(Schema.String, JsonObject)),
|
|
89
|
+
paths: Schema.Record(Schema.String, JsonObject),
|
|
90
|
+
produces: Schema.optionalKey(MediaTypes),
|
|
91
|
+
responses: Schema.optionalKey(Schema.Record(Schema.String, JsonObject)),
|
|
92
|
+
schemes: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
93
|
+
securityDefinitions: Schema.optionalKey(Schema.Record(Schema.String, SecurityDefinition)),
|
|
94
|
+
swagger: Schema.Literal("2.0"),
|
|
95
|
+
"x-ms-parameterized-host": Schema.optionalKey(ParameterizedHost),
|
|
96
|
+
}),
|
|
97
|
+
[JsonObject],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const methods = ["delete", "get", "head", "options", "patch", "post", "put"];
|
|
101
|
+
const formTypes = ["application/x-www-form-urlencoded", "multipart/form-data"];
|
|
102
|
+
const schemaKeys = [
|
|
103
|
+
"default",
|
|
104
|
+
"enum",
|
|
105
|
+
"exclusiveMaximum",
|
|
106
|
+
"exclusiveMinimum",
|
|
107
|
+
"format",
|
|
108
|
+
"items",
|
|
109
|
+
"maxItems",
|
|
110
|
+
"maxLength",
|
|
111
|
+
"maximum",
|
|
112
|
+
"minItems",
|
|
113
|
+
"minLength",
|
|
114
|
+
"minimum",
|
|
115
|
+
"multipleOf",
|
|
116
|
+
"pattern",
|
|
117
|
+
"type",
|
|
118
|
+
"uniqueItems",
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
function schema(value: unknown): unknown {
|
|
122
|
+
if (Array.isArray(value)) return Array.map(value, schema);
|
|
123
|
+
return Predicate.isObject(value) ? schemaObject(value) : value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function schemaObject(value: JsonObject): JsonObject {
|
|
127
|
+
const converted = Record.map(Record.remove(value, "x-nullable"), (entry, key) => {
|
|
128
|
+
if (!Predicate.isString(entry)) return schema(entry);
|
|
129
|
+
if (key === "$ref") return String.replace(/^#\/definitions\//u, "#/components/schemas/")(entry);
|
|
130
|
+
return key === "discriminator" ? { propertyName: entry } : entry;
|
|
131
|
+
});
|
|
132
|
+
const base: JsonObject = {
|
|
133
|
+
...converted,
|
|
134
|
+
...(value["x-nullable"] === true ? { nullable: true } : {}),
|
|
135
|
+
...(value["type"] === "file" ? { format: "binary", type: "string" } : {}),
|
|
136
|
+
};
|
|
137
|
+
if (!Array.isArray(converted["items"])) return base;
|
|
138
|
+
return value["type"] === "array"
|
|
139
|
+
? { ...base, items: { anyOf: converted["items"] } }
|
|
140
|
+
: { ...Record.remove(base, "items"), anyOf: converted["items"] };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function parameterSchema(parameter: Parameter) {
|
|
144
|
+
return schemaObject(Record.filter(parameter, (_, key) => Array.contains(schemaKeys, key)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function described(description?: string) {
|
|
148
|
+
return description === undefined ? {} : { description };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function mediaTypes(declared: MediaTypes, fallback: string) {
|
|
152
|
+
return Array.isReadonlyArrayNonEmpty(declared) ? declared : [fallback];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function requestBody(parameters: Parameter[], consumes: MediaTypes) {
|
|
156
|
+
const body = Option.getOrUndefined(
|
|
157
|
+
Array.findFirst(parameters, parameter => parameter.in === "body"),
|
|
158
|
+
);
|
|
159
|
+
if (body !== undefined) {
|
|
160
|
+
return {
|
|
161
|
+
content: Record.fromIterableWith(
|
|
162
|
+
mediaTypes(
|
|
163
|
+
Array.filter(consumes, type => !Array.contains(formTypes, type)),
|
|
164
|
+
"application/json",
|
|
165
|
+
),
|
|
166
|
+
type => [type, { schema: schema(body.schema) }],
|
|
167
|
+
),
|
|
168
|
+
...described(body.description),
|
|
169
|
+
required: body.required === true,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const fields = Array.filter(parameters, parameter => parameter.in === "formData");
|
|
174
|
+
if (Array.isReadonlyArrayEmpty(fields)) return undefined;
|
|
175
|
+
const fallback = Array.some(fields, field => field.type === "file")
|
|
176
|
+
? "multipart/form-data"
|
|
177
|
+
: "application/x-www-form-urlencoded";
|
|
178
|
+
const properties = Record.fromIterableWith(fields, field => [
|
|
179
|
+
field.name,
|
|
180
|
+
{ ...parameterSchema(field), ...described(field.description) },
|
|
181
|
+
]);
|
|
182
|
+
const encoding = Record.fromIterableWith(
|
|
183
|
+
Array.filter(fields, field => field.type === "array"),
|
|
184
|
+
field => [
|
|
185
|
+
field.name,
|
|
186
|
+
field.collectionFormat === "tsv"
|
|
187
|
+
? { "x-dual-delimiter": "\t" }
|
|
188
|
+
: collection(field.collectionFormat ?? "csv"),
|
|
189
|
+
],
|
|
190
|
+
);
|
|
191
|
+
return {
|
|
192
|
+
content: Record.fromIterableWith(
|
|
193
|
+
mediaTypes(
|
|
194
|
+
Array.filter(consumes, type => Array.contains(formTypes, type)),
|
|
195
|
+
fallback,
|
|
196
|
+
),
|
|
197
|
+
type => [
|
|
198
|
+
type,
|
|
199
|
+
{
|
|
200
|
+
encoding,
|
|
201
|
+
schema: {
|
|
202
|
+
properties,
|
|
203
|
+
required: Array.filterMap(fields, field =>
|
|
204
|
+
field.required === true ? Result.succeed(field.name) : Result.failVoid,
|
|
205
|
+
),
|
|
206
|
+
type: "object",
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
),
|
|
211
|
+
required: Array.some(fields, field => field.required === true),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function collection(format: string) {
|
|
216
|
+
if (format === "multi") return { explode: true, style: "form" };
|
|
217
|
+
if (format === "csv") return { explode: false, style: "form" };
|
|
218
|
+
if (format === "ssv") return { explode: false, style: "spaceDelimited" };
|
|
219
|
+
if (format === "pipes") return { explode: false, style: "pipeDelimited" };
|
|
220
|
+
return { explode: false, style: format };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function openApiParameter(value: Parameter) {
|
|
224
|
+
return {
|
|
225
|
+
...described(value.description),
|
|
226
|
+
...(value.type === "array" ? collection(value.collectionFormat ?? "csv") : {}),
|
|
227
|
+
in: value.in,
|
|
228
|
+
name: value.name,
|
|
229
|
+
required: value.in === "path" || value.required === true,
|
|
230
|
+
schema: parameterSchema(value),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function response(value: Response, produces: MediaTypes) {
|
|
235
|
+
return {
|
|
236
|
+
description: value.description ?? "",
|
|
237
|
+
...(value.headers === undefined
|
|
238
|
+
? {}
|
|
239
|
+
: {
|
|
240
|
+
headers: Record.map(value.headers, header => ({
|
|
241
|
+
...described(
|
|
242
|
+
Predicate.isString(header["description"]) ? header["description"] : undefined,
|
|
243
|
+
),
|
|
244
|
+
schema: schemaObject(Record.remove(header, "description")),
|
|
245
|
+
})),
|
|
246
|
+
}),
|
|
247
|
+
...(value.schema === undefined
|
|
248
|
+
? {}
|
|
249
|
+
: {
|
|
250
|
+
content: Record.fromIterableWith(mediaTypes(produces, "application/json"), type => [
|
|
251
|
+
type,
|
|
252
|
+
{ schema: schema(value.schema) },
|
|
253
|
+
]),
|
|
254
|
+
}),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function securityScheme(definition: SecurityDefinition) {
|
|
259
|
+
const scopes = definition.scopes ?? {};
|
|
260
|
+
return {
|
|
261
|
+
...described(definition.description),
|
|
262
|
+
...pipe(
|
|
263
|
+
Match.value(definition.type),
|
|
264
|
+
Match.when("basic", () => ({ scheme: "basic", type: "http" })),
|
|
265
|
+
Match.when("apiKey", () => ({ in: definition.in, name: definition.name, type: "apiKey" })),
|
|
266
|
+
Match.orElse(() => ({
|
|
267
|
+
flows: pipe(
|
|
268
|
+
Match.value(definition.flow),
|
|
269
|
+
Match.when("accessCode", () => ({
|
|
270
|
+
authorizationCode: {
|
|
271
|
+
authorizationUrl: definition.authorizationUrl,
|
|
272
|
+
scopes,
|
|
273
|
+
tokenUrl: definition.tokenUrl,
|
|
274
|
+
},
|
|
275
|
+
})),
|
|
276
|
+
Match.when("application", () => ({
|
|
277
|
+
clientCredentials: { scopes, tokenUrl: definition.tokenUrl },
|
|
278
|
+
})),
|
|
279
|
+
Match.when("password", () => ({ password: { scopes, tokenUrl: definition.tokenUrl } })),
|
|
280
|
+
Match.orElse(() => ({
|
|
281
|
+
implicit: { authorizationUrl: definition.authorizationUrl, scopes },
|
|
282
|
+
})),
|
|
283
|
+
),
|
|
284
|
+
type: definition.type,
|
|
285
|
+
})),
|
|
286
|
+
),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function server(document: Swagger) {
|
|
291
|
+
const scheme = pipe(
|
|
292
|
+
document.schemes ?? [],
|
|
293
|
+
Array.head,
|
|
294
|
+
Option.getOrElse(() => "https"),
|
|
295
|
+
);
|
|
296
|
+
const host = document["x-ms-parameterized-host"];
|
|
297
|
+
if (host === undefined) {
|
|
298
|
+
return {
|
|
299
|
+
url:
|
|
300
|
+
document.host === undefined
|
|
301
|
+
? (document.basePath ?? "/")
|
|
302
|
+
: `${scheme}://${document.host}${document.basePath ?? ""}`,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
url: `${host.useSchemePrefix === false ? "" : `${scheme}://`}${host.hostTemplate}${document.basePath ?? ""}`,
|
|
307
|
+
variables: Record.fromIterableWith(host.parameters ?? [], parameter => [
|
|
308
|
+
parameter.name,
|
|
309
|
+
{
|
|
310
|
+
default:
|
|
311
|
+
parameter.default ??
|
|
312
|
+
(parameter.format === "uri" ? `https://${parameter.name}.invalid` : parameter.name),
|
|
313
|
+
...described(parameter.description),
|
|
314
|
+
...(parameter.enum === undefined ? {} : { enum: parameter.enum }),
|
|
315
|
+
},
|
|
316
|
+
]),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const operation = Effect.fnUntraced(function* (
|
|
321
|
+
document: Swagger,
|
|
322
|
+
shared: JsonObject[],
|
|
323
|
+
value: unknown,
|
|
324
|
+
) {
|
|
325
|
+
const decoded = yield* Schema.decodeUnknownEffect(Operation)(value);
|
|
326
|
+
const declared = yield* Effect.forEach([...shared, ...(decoded.parameters ?? [])], entry =>
|
|
327
|
+
Schema.decodeUnknownEffect(Parameter)(
|
|
328
|
+
Predicate.isString(entry["$ref"])
|
|
329
|
+
? document.parameters?.[String.replace(/^#\/parameters\//u, "")(entry["$ref"])]
|
|
330
|
+
: entry,
|
|
331
|
+
),
|
|
332
|
+
);
|
|
333
|
+
const parameters = Array.filter(
|
|
334
|
+
declared,
|
|
335
|
+
(entry, index) =>
|
|
336
|
+
!Array.some(
|
|
337
|
+
Array.drop(declared, index + 1),
|
|
338
|
+
later => later.name === entry.name && later.in === entry.in,
|
|
339
|
+
),
|
|
340
|
+
);
|
|
341
|
+
const produces = decoded.produces ?? document.produces ?? [];
|
|
342
|
+
const body = requestBody(parameters, decoded.consumes ?? document.consumes ?? []);
|
|
343
|
+
function referenced(listed: JsonObject) {
|
|
344
|
+
if (!Predicate.isString(listed["$ref"])) return listed;
|
|
345
|
+
if (pipe(listed["$ref"], String.startsWith("#/responses/"))) {
|
|
346
|
+
return document.responses?.[String.replace(/^#\/responses\//u, "")(listed["$ref"])];
|
|
347
|
+
}
|
|
348
|
+
return { schema: { $ref: listed["$ref"] } };
|
|
349
|
+
}
|
|
350
|
+
const responses = yield* Effect.forEach(Record.toEntries(decoded.responses), entry =>
|
|
351
|
+
Effect.map(
|
|
352
|
+
Schema.decodeUnknownEffect(Response)(referenced(entry[1])),
|
|
353
|
+
decodedResponse => [entry[0], response(decodedResponse, produces)] as const,
|
|
354
|
+
),
|
|
355
|
+
);
|
|
356
|
+
return {
|
|
357
|
+
...Record.filter(
|
|
358
|
+
decoded,
|
|
359
|
+
(_, key) => !Array.contains(["consumes", "parameters", "produces", "responses"], key),
|
|
360
|
+
),
|
|
361
|
+
parameters: pipe(
|
|
362
|
+
parameters,
|
|
363
|
+
Array.filter(entry => entry.in !== "body" && entry.in !== "formData"),
|
|
364
|
+
Array.map(openApiParameter),
|
|
365
|
+
),
|
|
366
|
+
...(body === undefined ? {} : { requestBody: body }),
|
|
367
|
+
responses: Record.fromEntries(responses),
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
export const toOpenApi = Effect.fn("OpenApiSwagger.toOpenApi")(function* (input: unknown) {
|
|
372
|
+
const document = yield* Schema.decodeUnknownEffect(Swagger)(input);
|
|
373
|
+
const paths = yield* Effect.forEach(Record.toEntries(document.paths), entry => {
|
|
374
|
+
const shared = Array.filter(
|
|
375
|
+
Array.isArray(entry[1]["parameters"]) ? entry[1]["parameters"] : [],
|
|
376
|
+
Predicate.isObject,
|
|
377
|
+
);
|
|
378
|
+
return Effect.map(
|
|
379
|
+
Effect.forEach(
|
|
380
|
+
Array.filter(Record.toEntries(entry[1]), item => Array.contains(methods, item[0])),
|
|
381
|
+
item =>
|
|
382
|
+
Effect.map(
|
|
383
|
+
operation(document, shared, item[1]),
|
|
384
|
+
converted => [item[0], converted] as const,
|
|
385
|
+
),
|
|
386
|
+
),
|
|
387
|
+
operations => [entry[0], Record.fromEntries(operations)] as const,
|
|
388
|
+
);
|
|
389
|
+
});
|
|
390
|
+
return {
|
|
391
|
+
...Record.filter(
|
|
392
|
+
document,
|
|
393
|
+
(_, key) =>
|
|
394
|
+
!Array.contains(
|
|
395
|
+
[
|
|
396
|
+
"basePath",
|
|
397
|
+
"consumes",
|
|
398
|
+
"definitions",
|
|
399
|
+
"host",
|
|
400
|
+
"parameters",
|
|
401
|
+
"paths",
|
|
402
|
+
"produces",
|
|
403
|
+
"responses",
|
|
404
|
+
"schemes",
|
|
405
|
+
"securityDefinitions",
|
|
406
|
+
"swagger",
|
|
407
|
+
"x-ms-parameterized-host",
|
|
408
|
+
],
|
|
409
|
+
key,
|
|
410
|
+
),
|
|
411
|
+
),
|
|
412
|
+
components: {
|
|
413
|
+
schemas: Record.map(document.definitions ?? {}, schema),
|
|
414
|
+
securitySchemes: Record.map(document.securityDefinitions ?? {}, securityScheme),
|
|
415
|
+
},
|
|
416
|
+
openapi: "3.0.3",
|
|
417
|
+
paths: Record.fromEntries(paths),
|
|
418
|
+
servers: [server(document)],
|
|
419
|
+
};
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
export * as OpenApiSwagger from "./swagger.ts";
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Effect,
|
|
4
|
+
HashMap,
|
|
5
|
+
Match,
|
|
6
|
+
MutableList,
|
|
7
|
+
Option,
|
|
8
|
+
Order,
|
|
9
|
+
Record,
|
|
10
|
+
Result,
|
|
11
|
+
Schema,
|
|
12
|
+
Struct,
|
|
13
|
+
pipe,
|
|
14
|
+
} from "effect";
|
|
15
|
+
|
|
16
|
+
import { OpenApiIdentity } from "./identity.ts";
|
|
17
|
+
import { OpenApiSchema } from "./schema.ts";
|
|
18
|
+
|
|
19
|
+
export type LockFile = typeof LockFile.Type;
|
|
20
|
+
export const LockFile = Schema.fromJsonString(
|
|
21
|
+
Schema.Struct({
|
|
22
|
+
actions: Schema.Record(Schema.String, Schema.Struct({ hash: Schema.String })),
|
|
23
|
+
identities: OpenApiIdentity.Ledger,
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const StoredLockFile = Schema.fromJsonString(
|
|
28
|
+
Schema.Struct({
|
|
29
|
+
actions: Schema.Record(
|
|
30
|
+
Schema.String,
|
|
31
|
+
Schema.Union([
|
|
32
|
+
Schema.Struct({ hash: Schema.String }),
|
|
33
|
+
Schema.NonEmptyArray(
|
|
34
|
+
Schema.Union([
|
|
35
|
+
Schema.Struct({ hash: Schema.String, version: Schema.String }),
|
|
36
|
+
Schema.Struct({ removed: Schema.Literal(true), version: Schema.String }),
|
|
37
|
+
]),
|
|
38
|
+
),
|
|
39
|
+
]),
|
|
40
|
+
),
|
|
41
|
+
identities: OpenApiIdentity.Ledger,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/** Read the previous generator's ledger once, then write only current contract hashes. */
|
|
46
|
+
export const decodeLock = Effect.fn("OpenApiVersions.decodeLock")(function* (text: string) {
|
|
47
|
+
const stored = yield* Schema.decodeEffect(StoredLockFile)(text);
|
|
48
|
+
return {
|
|
49
|
+
actions: Record.filterMap(stored.actions, entry => {
|
|
50
|
+
const current = "hash" in entry ? entry : Array.lastNonEmpty(entry);
|
|
51
|
+
return "hash" in current ? Result.succeed({ hash: current.hash }) : Result.failVoid;
|
|
52
|
+
}),
|
|
53
|
+
identities: stored.identities,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** A JSON value for a node that ignores descriptions, field order and inlined spreads. */
|
|
58
|
+
function canonical(
|
|
59
|
+
node: OpenApiSchema.Node,
|
|
60
|
+
spreads: (name: string) => readonly OpenApiSchema.Field[],
|
|
61
|
+
ref: (target: string) => unknown,
|
|
62
|
+
): unknown {
|
|
63
|
+
const checks = node.checks === undefined ? {} : { checks: node.checks };
|
|
64
|
+
return pipe(
|
|
65
|
+
Match.value(node),
|
|
66
|
+
Match.tag("Ref", current => ref(current.target)),
|
|
67
|
+
Match.tag("Array", current => ({ array: canonical(current.item, spreads, ref), ...checks })),
|
|
68
|
+
Match.tag("Record", current => ({ record: canonical(current.value, spreads, ref), ...checks })),
|
|
69
|
+
Match.tag("NullOr", current => ({ nullOr: canonical(current.node, spreads, ref) })),
|
|
70
|
+
Match.tag("Literals", current => ({
|
|
71
|
+
literals: Array.sort(
|
|
72
|
+
Array.map(current.literals, value => JSON.stringify(value)),
|
|
73
|
+
Order.String,
|
|
74
|
+
),
|
|
75
|
+
})),
|
|
76
|
+
Match.tag("Union", current => ({
|
|
77
|
+
union: pipe(
|
|
78
|
+
Array.map(current.members, member => canonical(member, spreads, ref)),
|
|
79
|
+
Array.sort(Order.mapInput(Order.String, (member: unknown) => JSON.stringify(member))),
|
|
80
|
+
),
|
|
81
|
+
...(current.preserve === true ? { preserve: true } : {}),
|
|
82
|
+
...(current.exclusive === true ? { exclusive: true } : {}),
|
|
83
|
+
})),
|
|
84
|
+
Match.tag("Struct", current => {
|
|
85
|
+
const fields = Record.fromEntries(
|
|
86
|
+
Array.map(
|
|
87
|
+
[...Array.flatMap(current.spreads, spreads), ...current.fields],
|
|
88
|
+
field => [field.name, field] as const,
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
return {
|
|
92
|
+
fields: Array.map(Array.sort(Record.keys(fields), Order.String), name => {
|
|
93
|
+
const field = Option.getOrThrow(Record.get(fields, name));
|
|
94
|
+
return [name, field.optional, field.default ?? null, canonical(field.node, spreads, ref)];
|
|
95
|
+
}),
|
|
96
|
+
rest: current.rest,
|
|
97
|
+
...(current.excluded === undefined
|
|
98
|
+
? {}
|
|
99
|
+
: { excluded: Array.sort(current.excluded, Order.String) }),
|
|
100
|
+
...(current.additionalProperties === undefined
|
|
101
|
+
? {}
|
|
102
|
+
: { additional: canonical(current.additionalProperties, spreads, ref) }),
|
|
103
|
+
...checks,
|
|
104
|
+
};
|
|
105
|
+
}),
|
|
106
|
+
Match.tag("Bytes", current => ({ bytes: current.alphabet, direction: current.direction })),
|
|
107
|
+
Match.tag("Instant", current => ({ direction: current.direction, instant: current.clock })),
|
|
108
|
+
Match.orElse(current => ({
|
|
109
|
+
type: current._tag,
|
|
110
|
+
...checks,
|
|
111
|
+
...(current.format === undefined ? {} : { format: current.format }),
|
|
112
|
+
})),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Content hashes of each action's HTTP request and input/output schemas. Descriptions, key order
|
|
118
|
+
* and schema names do not count, so hashes describe only what is sent or accepted.
|
|
119
|
+
*/
|
|
120
|
+
export function hashes(catalogued: {
|
|
121
|
+
readonly contracts: readonly OpenApiSchema.Contract[];
|
|
122
|
+
readonly declarations: readonly OpenApiSchema.Declaration[];
|
|
123
|
+
}) {
|
|
124
|
+
const nodes = HashMap.fromIterable(
|
|
125
|
+
Array.map(
|
|
126
|
+
catalogued.declarations,
|
|
127
|
+
declaration => [declaration.name, declaration.node] as const,
|
|
128
|
+
),
|
|
129
|
+
);
|
|
130
|
+
function spreads(name: string): readonly OpenApiSchema.Field[] {
|
|
131
|
+
const node = HashMap.getUnsafe(nodes, name);
|
|
132
|
+
return node._tag === "Struct" ? [...Array.flatMap(node.spreads, spreads), ...node.fields] : [];
|
|
133
|
+
}
|
|
134
|
+
function hashable(declaration: OpenApiSchema.Declaration) {
|
|
135
|
+
const refs = MutableList.make<string>();
|
|
136
|
+
const content = JSON.stringify(
|
|
137
|
+
canonical(declaration.node, spreads, target => {
|
|
138
|
+
MutableList.append(refs, target);
|
|
139
|
+
return "#";
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
return { content, key: declaration.name, refs: MutableList.toArray(refs) };
|
|
143
|
+
}
|
|
144
|
+
const identity = OpenApiSchema.identities(Array.map(catalogued.declarations, hashable));
|
|
145
|
+
function ref(target: string) {
|
|
146
|
+
return { ref: HashMap.getUnsafe(identity, target) };
|
|
147
|
+
}
|
|
148
|
+
return Array.map(catalogued.contracts, contract =>
|
|
149
|
+
OpenApiSchema.hash(
|
|
150
|
+
JSON.stringify(
|
|
151
|
+
{
|
|
152
|
+
input: canonical(contract.input, spreads, ref),
|
|
153
|
+
output: canonical(contract.output, spreads, ref),
|
|
154
|
+
// Parameter order in the source is not a change.
|
|
155
|
+
request: {
|
|
156
|
+
...Struct.omit(contract, ["input", "output"]),
|
|
157
|
+
commaSeparated: Array.sort(contract.commaSeparated, Order.String),
|
|
158
|
+
...(contract.exploded === undefined
|
|
159
|
+
? {}
|
|
160
|
+
: { exploded: Array.sort(contract.exploded, Order.String) }),
|
|
161
|
+
...(contract.deepObject === undefined
|
|
162
|
+
? {}
|
|
163
|
+
: { deepObject: Array.sort(contract.deepObject, Order.String) }),
|
|
164
|
+
headers: Array.sort(contract.headers, Order.String),
|
|
165
|
+
query: Array.sort(contract.query, Order.String),
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
(key, value: unknown) => (key === "schema" ? undefined : value),
|
|
169
|
+
),
|
|
170
|
+
),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export * as OpenApiVersions from "./versions.ts";
|