@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,438 @@
|
|
|
1
|
+
import { Array, Boolean, Effect, Option, Predicate, Record, Schema, String, pipe } from "effect";
|
|
2
|
+
|
|
3
|
+
type DiscoverySchema = {
|
|
4
|
+
readonly $ref?: string;
|
|
5
|
+
readonly default?: string;
|
|
6
|
+
readonly additionalProperties?: DiscoverySchema;
|
|
7
|
+
readonly description?: string;
|
|
8
|
+
readonly enum?: readonly string[];
|
|
9
|
+
readonly format?: string;
|
|
10
|
+
readonly items?: DiscoverySchema;
|
|
11
|
+
readonly location?: string;
|
|
12
|
+
readonly maximum?: string;
|
|
13
|
+
readonly minimum?: string;
|
|
14
|
+
readonly pattern?: string;
|
|
15
|
+
readonly properties?: Record.ReadonlyRecord<string, DiscoverySchema>;
|
|
16
|
+
readonly readOnly?: boolean;
|
|
17
|
+
readonly repeated?: boolean;
|
|
18
|
+
readonly required?: boolean;
|
|
19
|
+
readonly type?: string;
|
|
20
|
+
};
|
|
21
|
+
const DiscoverySchema = Schema.Struct({
|
|
22
|
+
$ref: Schema.optionalKey(Schema.String),
|
|
23
|
+
default: Schema.optionalKey(Schema.String),
|
|
24
|
+
additionalProperties: Schema.optionalKey(
|
|
25
|
+
Schema.suspend((): Schema.Codec<DiscoverySchema> => DiscoverySchema),
|
|
26
|
+
),
|
|
27
|
+
description: Schema.optionalKey(Schema.String),
|
|
28
|
+
enum: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
29
|
+
format: Schema.optionalKey(Schema.String),
|
|
30
|
+
items: Schema.optionalKey(Schema.suspend((): Schema.Codec<DiscoverySchema> => DiscoverySchema)),
|
|
31
|
+
location: Schema.optionalKey(Schema.String),
|
|
32
|
+
maximum: Schema.optionalKey(Schema.String),
|
|
33
|
+
minimum: Schema.optionalKey(Schema.String),
|
|
34
|
+
pattern: Schema.optionalKey(Schema.String),
|
|
35
|
+
properties: Schema.optionalKey(
|
|
36
|
+
Schema.Record(
|
|
37
|
+
Schema.String,
|
|
38
|
+
Schema.suspend((): Schema.Codec<DiscoverySchema> => DiscoverySchema),
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
readOnly: Schema.optionalKey(Schema.Boolean),
|
|
42
|
+
repeated: Schema.optionalKey(Schema.Boolean),
|
|
43
|
+
required: Schema.optionalKey(Schema.Boolean),
|
|
44
|
+
type: Schema.optionalKey(Schema.String),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const formats: Record.ReadonlyRecord<string, string> = {
|
|
48
|
+
byte: "base64url",
|
|
49
|
+
"google-datetime": "date-time",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type DiscoveryMethod = typeof DiscoveryMethod.Type;
|
|
53
|
+
const DiscoveryMethod = Schema.Struct({
|
|
54
|
+
deprecated: Schema.optionalKey(Schema.Boolean),
|
|
55
|
+
description: Schema.optionalKey(Schema.String),
|
|
56
|
+
flatPath: Schema.optionalKey(Schema.String),
|
|
57
|
+
httpMethod: Schema.String,
|
|
58
|
+
id: Schema.String,
|
|
59
|
+
mediaUpload: Schema.optionalKey(
|
|
60
|
+
Schema.Struct({
|
|
61
|
+
accept: Schema.Array(Schema.String),
|
|
62
|
+
maxSize: Schema.optionalKey(Schema.String),
|
|
63
|
+
protocols: Schema.Struct({
|
|
64
|
+
resumable: Schema.optionalKey(
|
|
65
|
+
Schema.Struct({ multipart: Schema.optionalKey(Schema.Boolean), path: Schema.String }),
|
|
66
|
+
),
|
|
67
|
+
simple: Schema.optionalKey(
|
|
68
|
+
Schema.Struct({ multipart: Schema.optionalKey(Schema.Boolean), path: Schema.String }),
|
|
69
|
+
),
|
|
70
|
+
}),
|
|
71
|
+
}),
|
|
72
|
+
),
|
|
73
|
+
parameters: Schema.optionalKey(Schema.Record(Schema.String, DiscoverySchema)),
|
|
74
|
+
path: Schema.String,
|
|
75
|
+
request: Schema.optionalKey(Schema.Struct({ $ref: Schema.String })),
|
|
76
|
+
response: Schema.optionalKey(Schema.Struct({ $ref: Schema.String })),
|
|
77
|
+
supportsMediaDownload: Schema.optionalKey(Schema.Boolean),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
type DiscoveryResource = {
|
|
81
|
+
readonly methods?: Record.ReadonlyRecord<string, DiscoveryMethod>;
|
|
82
|
+
readonly resources?: Record.ReadonlyRecord<string, DiscoveryResource>;
|
|
83
|
+
};
|
|
84
|
+
const DiscoveryResource = Schema.Struct({
|
|
85
|
+
methods: Schema.optionalKey(Schema.Record(Schema.String, DiscoveryMethod)),
|
|
86
|
+
resources: Schema.optionalKey(
|
|
87
|
+
Schema.Record(
|
|
88
|
+
Schema.String,
|
|
89
|
+
Schema.suspend((): Schema.Codec<DiscoveryResource> => DiscoveryResource),
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
type DiscoveryDocument = typeof DiscoveryDocument.Type;
|
|
95
|
+
const DiscoveryDocument = Schema.Struct({
|
|
96
|
+
...DiscoveryResource.fields,
|
|
97
|
+
auth: Schema.optionalKey(
|
|
98
|
+
Schema.Struct({
|
|
99
|
+
oauth2: Schema.Struct({
|
|
100
|
+
scopes: Schema.Record(Schema.String, Schema.Struct({ description: Schema.String })),
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
),
|
|
104
|
+
description: Schema.optionalKey(Schema.String),
|
|
105
|
+
documentationLink: Schema.optionalKey(Schema.String),
|
|
106
|
+
kind: Schema.Literal("discovery#restDescription"),
|
|
107
|
+
parameters: Schema.optionalKey(Schema.Record(Schema.String, DiscoverySchema)),
|
|
108
|
+
rootUrl: Schema.String,
|
|
109
|
+
schemas: Schema.optionalKey(Schema.Record(Schema.String, DiscoverySchema)),
|
|
110
|
+
servicePath: Schema.String,
|
|
111
|
+
title: Schema.String,
|
|
112
|
+
version: Schema.String,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
type Located = { method: DiscoveryMethod; tags: string[] };
|
|
116
|
+
|
|
117
|
+
function reference(name: string) {
|
|
118
|
+
return { $ref: `#/components/schemas/${name}` };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function openApiSchema(schema: DiscoverySchema): Record.ReadonlyRecord<string, unknown> {
|
|
122
|
+
if (schema.$ref !== undefined) return reference(schema.$ref);
|
|
123
|
+
return Record.filter(
|
|
124
|
+
{
|
|
125
|
+
additionalProperties:
|
|
126
|
+
schema.additionalProperties === undefined
|
|
127
|
+
? undefined
|
|
128
|
+
: openApiSchema(schema.additionalProperties),
|
|
129
|
+
description: schema.description,
|
|
130
|
+
enum: schema.enum,
|
|
131
|
+
format:
|
|
132
|
+
schema.format === undefined
|
|
133
|
+
? undefined
|
|
134
|
+
: Option.getOrElse(Record.get(formats, schema.format), () => schema.format),
|
|
135
|
+
items: schema.items === undefined ? undefined : openApiSchema(schema.items),
|
|
136
|
+
maximum:
|
|
137
|
+
schema.maximum === undefined
|
|
138
|
+
? undefined
|
|
139
|
+
: Schema.decodeSync(Schema.FiniteFromString)(schema.maximum),
|
|
140
|
+
minimum:
|
|
141
|
+
schema.minimum === undefined
|
|
142
|
+
? undefined
|
|
143
|
+
: Schema.decodeSync(Schema.FiniteFromString)(schema.minimum),
|
|
144
|
+
pattern: schema.pattern,
|
|
145
|
+
properties:
|
|
146
|
+
schema.properties === undefined ? undefined : Record.map(schema.properties, openApiSchema),
|
|
147
|
+
readOnly: schema.readOnly,
|
|
148
|
+
type: schema.type === "any" ? undefined : schema.type,
|
|
149
|
+
},
|
|
150
|
+
Predicate.isNotUndefined,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function methodsOf(resource: DiscoveryResource, tags: string[]): Located[] {
|
|
155
|
+
return [
|
|
156
|
+
...Array.map(Record.values(resource.methods ?? {}), method => ({ method, tags })),
|
|
157
|
+
...Array.flatten(
|
|
158
|
+
Record.collect(resource.resources ?? {}, (name, child) =>
|
|
159
|
+
methodsOf(child, [Array.join([...tags, name], ".")]),
|
|
160
|
+
),
|
|
161
|
+
),
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function operation(document: DiscoveryDocument, located: Located, path: string) {
|
|
166
|
+
const method = located.method;
|
|
167
|
+
const declared: Record.ReadonlyRecord<string, DiscoverySchema> = {
|
|
168
|
+
...Record.filter(document.parameters ?? {}, (_, name) => name === "fields"),
|
|
169
|
+
...method.parameters,
|
|
170
|
+
...(method.supportsMediaDownload === true && method.response !== undefined
|
|
171
|
+
? { alt: { enum: ["json", "media"], location: "query", type: "string" } }
|
|
172
|
+
: {}),
|
|
173
|
+
};
|
|
174
|
+
const pathParameters = pipe(
|
|
175
|
+
path,
|
|
176
|
+
String.matchAll(/\{([^}]+)\}/gu),
|
|
177
|
+
Array.fromIterable,
|
|
178
|
+
Array.map(match => Array.get(match, 1)),
|
|
179
|
+
Array.getSomes,
|
|
180
|
+
Array.map(name =>
|
|
181
|
+
Record.filter(
|
|
182
|
+
{
|
|
183
|
+
description: declared[name]?.description,
|
|
184
|
+
in: "path",
|
|
185
|
+
name,
|
|
186
|
+
required: true,
|
|
187
|
+
schema: {
|
|
188
|
+
...openApiSchema(declared[name] ?? { type: "string" }),
|
|
189
|
+
...(declared[name]?.default === undefined ? {} : { default: declared[name]?.default }),
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
Predicate.isNotUndefined,
|
|
193
|
+
),
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
const queryParameters = Record.collect(
|
|
197
|
+
Record.filter(declared, parameter => parameter.location === "query"),
|
|
198
|
+
(name, parameter) =>
|
|
199
|
+
Record.filter(
|
|
200
|
+
{
|
|
201
|
+
description: parameter.description,
|
|
202
|
+
in: "query",
|
|
203
|
+
name,
|
|
204
|
+
required: parameter.required,
|
|
205
|
+
schema:
|
|
206
|
+
parameter.repeated === true
|
|
207
|
+
? { items: openApiSchema(parameter), type: "array" }
|
|
208
|
+
: openApiSchema(parameter),
|
|
209
|
+
},
|
|
210
|
+
Predicate.isNotUndefined,
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
return {
|
|
214
|
+
deprecated: method.deprecated,
|
|
215
|
+
description: method.description,
|
|
216
|
+
operationId: pipe(method.id, String.split("."), Array.drop(1), Array.join(".")),
|
|
217
|
+
parameters: [...pathParameters, ...queryParameters],
|
|
218
|
+
requestBody:
|
|
219
|
+
method.request === undefined
|
|
220
|
+
? undefined
|
|
221
|
+
: {
|
|
222
|
+
content: { "application/json": { schema: reference(method.request.$ref) } },
|
|
223
|
+
required: true,
|
|
224
|
+
},
|
|
225
|
+
responses:
|
|
226
|
+
method.response === undefined
|
|
227
|
+
? Boolean.match(method.supportsMediaDownload === true, {
|
|
228
|
+
onFalse: () => ({ "204": { description: "No content" } }),
|
|
229
|
+
onTrue: () => ({
|
|
230
|
+
"200": {
|
|
231
|
+
content: { "*/*": { schema: { format: "binary", type: "string" } } },
|
|
232
|
+
description: "The media",
|
|
233
|
+
},
|
|
234
|
+
}),
|
|
235
|
+
})
|
|
236
|
+
: {
|
|
237
|
+
"200": {
|
|
238
|
+
content: {
|
|
239
|
+
"application/json": { schema: reference(method.response.$ref) },
|
|
240
|
+
...(method.supportsMediaDownload === true
|
|
241
|
+
? { "*/*": { schema: { format: "binary", type: "string" } } }
|
|
242
|
+
: {}),
|
|
243
|
+
},
|
|
244
|
+
description: "Successful response",
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
tags: located.tags,
|
|
248
|
+
...(method.supportsMediaDownload === true && method.response !== undefined
|
|
249
|
+
? { "x-dual-google-download": true }
|
|
250
|
+
: {}),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function endpoints(document: DiscoveryDocument, located: Located) {
|
|
255
|
+
const method = located.method;
|
|
256
|
+
const path = `/${String.replaceAll("{+", "{")(method.flatPath ?? method.path)}`;
|
|
257
|
+
const endpoint = {
|
|
258
|
+
httpMethod: String.toLowerCase(method.httpMethod),
|
|
259
|
+
operation: (canonicalPath: string) =>
|
|
260
|
+
Record.filter<string, unknown>(
|
|
261
|
+
operation(document, located, canonicalPath),
|
|
262
|
+
Predicate.isNotUndefined,
|
|
263
|
+
),
|
|
264
|
+
path,
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const upload = method.mediaUpload;
|
|
268
|
+
const simple = upload?.protocols.simple;
|
|
269
|
+
if (upload === undefined || simple === undefined) return [endpoint];
|
|
270
|
+
return [
|
|
271
|
+
endpoint,
|
|
272
|
+
{
|
|
273
|
+
httpMethod: endpoint.httpMethod,
|
|
274
|
+
operation: (canonicalPath: string) => {
|
|
275
|
+
const uploadOperation = operation(document, located, canonicalPath);
|
|
276
|
+
const file = { format: "binary", type: "string" };
|
|
277
|
+
const metadata =
|
|
278
|
+
method.request === undefined ? { type: "object" } : reference(method.request.$ref);
|
|
279
|
+
const pending = {
|
|
280
|
+
properties: {
|
|
281
|
+
nextOffset: { type: "integer" },
|
|
282
|
+
sessionUrl: { type: "string" },
|
|
283
|
+
state: { enum: ["pending"] },
|
|
284
|
+
},
|
|
285
|
+
required: ["state", "sessionUrl", "nextOffset"],
|
|
286
|
+
type: "object",
|
|
287
|
+
};
|
|
288
|
+
const session = { sessionUrl: { type: "string" }, totalBytes: { type: "integer" } };
|
|
289
|
+
const variants = [
|
|
290
|
+
{
|
|
291
|
+
properties: { media: file, mode: { enum: ["media"] } },
|
|
292
|
+
required: ["mode", "media"],
|
|
293
|
+
type: "object",
|
|
294
|
+
},
|
|
295
|
+
...(simple.multipart === true
|
|
296
|
+
? [
|
|
297
|
+
{
|
|
298
|
+
properties: { media: file, metadata, mode: { enum: ["multipart"] } },
|
|
299
|
+
required: ["mode", "metadata", "media"],
|
|
300
|
+
type: "object",
|
|
301
|
+
},
|
|
302
|
+
]
|
|
303
|
+
: []),
|
|
304
|
+
...(upload.protocols.resumable === undefined
|
|
305
|
+
? []
|
|
306
|
+
: [
|
|
307
|
+
{
|
|
308
|
+
properties: {
|
|
309
|
+
contentType: { type: "string" },
|
|
310
|
+
metadata,
|
|
311
|
+
mode: { enum: ["start"] },
|
|
312
|
+
totalBytes: { type: "integer" },
|
|
313
|
+
},
|
|
314
|
+
required: ["mode", "contentType", "totalBytes"],
|
|
315
|
+
type: "object",
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
properties: {
|
|
319
|
+
media: file,
|
|
320
|
+
mode: { enum: ["chunk"] },
|
|
321
|
+
...session,
|
|
322
|
+
offset: { type: "integer" },
|
|
323
|
+
},
|
|
324
|
+
required: ["mode", "sessionUrl", "offset", "totalBytes", "media"],
|
|
325
|
+
type: "object",
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
properties: { mode: { enum: ["status"] }, ...session },
|
|
329
|
+
required: ["mode", "sessionUrl", "totalBytes"],
|
|
330
|
+
type: "object",
|
|
331
|
+
},
|
|
332
|
+
]),
|
|
333
|
+
];
|
|
334
|
+
return Record.filter<string, unknown>(
|
|
335
|
+
{
|
|
336
|
+
...uploadOperation,
|
|
337
|
+
operationId: `${uploadOperation.operationId}.upload`,
|
|
338
|
+
parameters: uploadOperation.parameters,
|
|
339
|
+
requestBody: {
|
|
340
|
+
content: { "application/json": { schema: { oneOf: variants } } },
|
|
341
|
+
required: true,
|
|
342
|
+
},
|
|
343
|
+
responses: {
|
|
344
|
+
"200": {
|
|
345
|
+
content: {
|
|
346
|
+
"application/json": {
|
|
347
|
+
schema: {
|
|
348
|
+
oneOf: [
|
|
349
|
+
pending,
|
|
350
|
+
{
|
|
351
|
+
properties: {
|
|
352
|
+
resource:
|
|
353
|
+
method.response === undefined
|
|
354
|
+
? { type: "object" }
|
|
355
|
+
: reference(method.response.$ref),
|
|
356
|
+
state: { enum: ["complete"] },
|
|
357
|
+
},
|
|
358
|
+
required: ["state", "resource"],
|
|
359
|
+
type: "object",
|
|
360
|
+
},
|
|
361
|
+
],
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
description: "The completed resource or resumable session progress",
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
servers: [{ url: String.replace(/\/$/u, "")(document.rootUrl) }],
|
|
369
|
+
"x-dual-google-upload": {
|
|
370
|
+
...(upload.protocols.resumable === undefined
|
|
371
|
+
? {}
|
|
372
|
+
: {
|
|
373
|
+
resumableUrl: `${String.replace(/\/$/u, "")(document.rootUrl)}${String.replaceAll("{+", "{")(upload.protocols.resumable.path)}`,
|
|
374
|
+
}),
|
|
375
|
+
...(upload.maxSize === undefined ? {} : { maxSize: upload.maxSize }),
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
Predicate.isNotUndefined,
|
|
379
|
+
);
|
|
380
|
+
},
|
|
381
|
+
path: String.replaceAll("{+", "{")(simple.path),
|
|
382
|
+
},
|
|
383
|
+
];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export const toOpenApi = Effect.fn("OpenApiDiscovery.toOpenApi")(function* (input: unknown) {
|
|
387
|
+
const document = yield* Schema.decodeUnknownEffect(DiscoveryDocument)(input);
|
|
388
|
+
return {
|
|
389
|
+
components: Record.filter(
|
|
390
|
+
{
|
|
391
|
+
schemas: Record.map(document.schemas ?? {}, openApiSchema),
|
|
392
|
+
securitySchemes:
|
|
393
|
+
document.auth === undefined
|
|
394
|
+
? undefined
|
|
395
|
+
: {
|
|
396
|
+
oauth2: {
|
|
397
|
+
flows: {
|
|
398
|
+
authorizationCode: {
|
|
399
|
+
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
400
|
+
scopes: Record.map(document.auth.oauth2.scopes, scope => scope.description),
|
|
401
|
+
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
type: "oauth2",
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
Predicate.isNotUndefined,
|
|
409
|
+
),
|
|
410
|
+
...(document.documentationLink === undefined
|
|
411
|
+
? {}
|
|
412
|
+
: { externalDocs: { url: document.documentationLink } }),
|
|
413
|
+
info: Record.filter(
|
|
414
|
+
{ description: document.description, title: document.title, version: document.version },
|
|
415
|
+
Predicate.isNotUndefined,
|
|
416
|
+
),
|
|
417
|
+
openapi: "3.0.3",
|
|
418
|
+
paths: pipe(
|
|
419
|
+
methodsOf(document, []),
|
|
420
|
+
Array.flatMap(located => endpoints(document, located)),
|
|
421
|
+
Array.groupBy(endpoint => String.replaceAll(/\{[^}]+\}/gu, "{}")(endpoint.path)),
|
|
422
|
+
Record.values,
|
|
423
|
+
Record.fromIterableWith(group => {
|
|
424
|
+
const path = Array.headNonEmpty(group).path;
|
|
425
|
+
return [
|
|
426
|
+
path,
|
|
427
|
+
Record.fromIterableWith(group, endpoint => [
|
|
428
|
+
endpoint.httpMethod,
|
|
429
|
+
endpoint.operation(path),
|
|
430
|
+
]),
|
|
431
|
+
];
|
|
432
|
+
}),
|
|
433
|
+
),
|
|
434
|
+
servers: [{ url: String.replace(/\/$/u, "")(`${document.rootUrl}${document.servicePath}`) }],
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
export * as OpenApiDiscovery from "./discovery.ts";
|