@dual-os/cli 0.0.0-stage → 0.11.0-next.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.
Files changed (254) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +15 -2
  3. package/dist/_virtual/_rolldown/runtime.js +13 -0
  4. package/dist/auth/credentials.d.ts +17 -0
  5. package/dist/auth/credentials.d.ts.map +1 -0
  6. package/dist/auth/credentials.js +57 -0
  7. package/dist/auth/credentials.js.map +1 -0
  8. package/dist/auth/destination.d.ts +22 -0
  9. package/dist/auth/destination.d.ts.map +1 -0
  10. package/dist/auth/destination.js +49 -0
  11. package/dist/auth/destination.js.map +1 -0
  12. package/dist/auth/http.d.ts +12 -0
  13. package/dist/auth/http.d.ts.map +1 -0
  14. package/dist/auth/http.js +34 -0
  15. package/dist/auth/http.js.map +1 -0
  16. package/dist/auth/login.d.ts +22 -0
  17. package/dist/auth/login.d.ts.map +1 -0
  18. package/dist/auth/login.js +98 -0
  19. package/dist/auth/login.js.map +1 -0
  20. package/dist/auth/protocol.d.ts +26 -0
  21. package/dist/auth/protocol.d.ts.map +1 -0
  22. package/dist/auth/protocol.js +31 -0
  23. package/dist/auth/protocol.js.map +1 -0
  24. package/dist/baseline.d.ts +18 -0
  25. package/dist/baseline.d.ts.map +1 -0
  26. package/dist/baseline.js +22 -0
  27. package/dist/baseline.js.map +1 -0
  28. package/dist/bin.d.ts +1 -0
  29. package/dist/bin.js +7 -0
  30. package/dist/bin.js.map +1 -0
  31. package/dist/cli.d.ts +19 -0
  32. package/dist/cli.d.ts.map +1 -0
  33. package/dist/cli.js +492 -0
  34. package/dist/cli.js.map +1 -0
  35. package/dist/create/choices.d.ts +58 -0
  36. package/dist/create/choices.d.ts.map +1 -0
  37. package/dist/create/choices.js +121 -0
  38. package/dist/create/choices.js.map +1 -0
  39. package/dist/create/deployment.d.ts +48 -0
  40. package/dist/create/deployment.d.ts.map +1 -0
  41. package/dist/create/deployment.js +66 -0
  42. package/dist/create/deployment.js.map +1 -0
  43. package/dist/create/scaffold.d.ts +57 -0
  44. package/dist/create/scaffold.d.ts.map +1 -0
  45. package/dist/create/scaffold.js +198 -0
  46. package/dist/create/scaffold.js.map +1 -0
  47. package/dist/create/source-reference.d.ts +39 -0
  48. package/dist/create/source-reference.d.ts.map +1 -0
  49. package/dist/create/source-reference.js +185 -0
  50. package/dist/create/source-reference.js.map +1 -0
  51. package/dist/create/template.d.ts +116 -0
  52. package/dist/create/template.d.ts.map +1 -0
  53. package/dist/create/template.js +211 -0
  54. package/dist/create/template.js.map +1 -0
  55. package/dist/diagnostics.d.ts +6 -0
  56. package/dist/diagnostics.d.ts.map +1 -0
  57. package/dist/diagnostics.js +18 -0
  58. package/dist/diagnostics.js.map +1 -0
  59. package/dist/help.d.ts +16 -0
  60. package/dist/help.d.ts.map +1 -0
  61. package/dist/help.js +73 -0
  62. package/dist/help.js.map +1 -0
  63. package/dist/openapi/bundle.d.ts +18 -0
  64. package/dist/openapi/bundle.d.ts.map +1 -0
  65. package/dist/openapi/bundle.js +201 -0
  66. package/dist/openapi/bundle.js.map +1 -0
  67. package/dist/openapi/discovery.d.ts +30 -0
  68. package/dist/openapi/discovery.d.ts.map +1 -0
  69. package/dist/openapi/discovery.js +325 -0
  70. package/dist/openapi/discovery.js.map +1 -0
  71. package/dist/openapi/emit.d.ts +52 -0
  72. package/dist/openapi/emit.d.ts.map +1 -0
  73. package/dist/openapi/emit.js +596 -0
  74. package/dist/openapi/emit.js.map +1 -0
  75. package/dist/openapi/graphql.d.ts +102 -0
  76. package/dist/openapi/graphql.d.ts.map +1 -0
  77. package/dist/openapi/graphql.js +294 -0
  78. package/dist/openapi/graphql.js.map +1 -0
  79. package/dist/openapi/identity.d.ts +88 -0
  80. package/dist/openapi/identity.d.ts.map +1 -0
  81. package/dist/openapi/identity.js +98 -0
  82. package/dist/openapi/identity.js.map +1 -0
  83. package/dist/openapi/mcp.d.ts +21 -0
  84. package/dist/openapi/mcp.d.ts.map +1 -0
  85. package/dist/openapi/mcp.js +133 -0
  86. package/dist/openapi/mcp.js.map +1 -0
  87. package/dist/openapi/operations.d.ts +165 -0
  88. package/dist/openapi/operations.d.ts.map +1 -0
  89. package/dist/openapi/operations.js +361 -0
  90. package/dist/openapi/operations.js.map +1 -0
  91. package/dist/openapi/overlay.d.ts +23 -0
  92. package/dist/openapi/overlay.d.ts.map +1 -0
  93. package/dist/openapi/overlay.js +115 -0
  94. package/dist/openapi/overlay.js.map +1 -0
  95. package/dist/openapi/plugin.d.ts +83 -0
  96. package/dist/openapi/plugin.d.ts.map +1 -0
  97. package/dist/openapi/plugin.js +468 -0
  98. package/dist/openapi/plugin.js.map +1 -0
  99. package/dist/openapi/polymorphism.d.ts +21 -0
  100. package/dist/openapi/polymorphism.d.ts.map +1 -0
  101. package/dist/openapi/polymorphism.js +96 -0
  102. package/dist/openapi/polymorphism.js.map +1 -0
  103. package/dist/openapi/postman.d.ts +21 -0
  104. package/dist/openapi/postman.d.ts.map +1 -0
  105. package/dist/openapi/postman.js +286 -0
  106. package/dist/openapi/postman.js.map +1 -0
  107. package/dist/openapi/schema.d.ts +178 -0
  108. package/dist/openapi/schema.d.ts.map +1 -0
  109. package/dist/openapi/schema.js +1234 -0
  110. package/dist/openapi/schema.js.map +1 -0
  111. package/dist/openapi/select.d.ts +22 -0
  112. package/dist/openapi/select.d.ts.map +1 -0
  113. package/dist/openapi/select.js +79 -0
  114. package/dist/openapi/select.js.map +1 -0
  115. package/dist/openapi/spec.d.ts +147 -0
  116. package/dist/openapi/spec.d.ts.map +1 -0
  117. package/dist/openapi/spec.js +263 -0
  118. package/dist/openapi/spec.js.map +1 -0
  119. package/dist/openapi/swagger.d.ts +166 -0
  120. package/dist/openapi/swagger.d.ts.map +1 -0
  121. package/dist/openapi/swagger.js +298 -0
  122. package/dist/openapi/swagger.js.map +1 -0
  123. package/dist/openapi/versions.d.ts +52 -0
  124. package/dist/openapi/versions.d.ts.map +1 -0
  125. package/dist/openapi/versions.js +120 -0
  126. package/dist/openapi/versions.js.map +1 -0
  127. package/dist/plugin/archive.d.ts +27 -0
  128. package/dist/plugin/archive.d.ts.map +1 -0
  129. package/dist/plugin/archive.js +170 -0
  130. package/dist/plugin/archive.js.map +1 -0
  131. package/dist/plugin/bundle.d.ts +27 -0
  132. package/dist/plugin/bundle.d.ts.map +1 -0
  133. package/dist/plugin/bundle.js +328 -0
  134. package/dist/plugin/bundle.js.map +1 -0
  135. package/dist/plugin/init.d.ts +18 -0
  136. package/dist/plugin/init.d.ts.map +1 -0
  137. package/dist/plugin/init.js +121 -0
  138. package/dist/plugin/init.js.map +1 -0
  139. package/dist/plugin/inspection.d.ts +24 -0
  140. package/dist/plugin/inspection.d.ts.map +1 -0
  141. package/dist/plugin/inspection.js +24 -0
  142. package/dist/plugin/inspection.js.map +1 -0
  143. package/dist/plugin/package.d.ts +26 -0
  144. package/dist/plugin/package.d.ts.map +1 -0
  145. package/dist/plugin/package.js +73 -0
  146. package/dist/plugin/package.js.map +1 -0
  147. package/dist/plugin/publication.d.ts +29 -0
  148. package/dist/plugin/publication.d.ts.map +1 -0
  149. package/dist/plugin/publication.js +65 -0
  150. package/dist/plugin/publication.js.map +1 -0
  151. package/dist/plugin/validation.d.ts +15 -0
  152. package/dist/plugin/validation.d.ts.map +1 -0
  153. package/dist/plugin/validation.js +119 -0
  154. package/dist/plugin/validation.js.map +1 -0
  155. package/dist/release/archives.d.ts +33 -0
  156. package/dist/release/archives.d.ts.map +1 -0
  157. package/dist/release/archives.js +81 -0
  158. package/dist/release/archives.js.map +1 -0
  159. package/dist/release/release-manifest.d.ts +182 -0
  160. package/dist/release/release-manifest.d.ts.map +1 -0
  161. package/dist/release/release-manifest.js +79 -0
  162. package/dist/release/release-manifest.js.map +1 -0
  163. package/dist/release/releases.d.ts +36 -0
  164. package/dist/release/releases.d.ts.map +1 -0
  165. package/dist/release/releases.js +122 -0
  166. package/dist/release/releases.js.map +1 -0
  167. package/dist/skills.d.ts +35 -0
  168. package/dist/skills.d.ts.map +1 -0
  169. package/dist/skills.js +257 -0
  170. package/dist/skills.js.map +1 -0
  171. package/package.json +73 -4
  172. package/skills/dual-fde/SKILL.md +38 -0
  173. package/skills/dual-fde/references/access.md +62 -0
  174. package/skills/dual-fde/references/author-plugins.md +54 -0
  175. package/skills/dual-fde/references/cli.md +97 -0
  176. package/skills/dual-fde/references/manage-plugins.md +78 -0
  177. package/skills/dual-fde/references/migrations-deployment.md +84 -0
  178. package/skills/dual-fde/references/openapi-plugins.md +47 -0
  179. package/skills/dual-fde/references/sdk-docs.md +56 -0
  180. package/skills/dual-fde/references/upgrades.md +115 -0
  181. package/skills/dual-fde/references/working-context.md +69 -0
  182. package/src/auth/credentials.ts +84 -0
  183. package/src/auth/destination.ts +83 -0
  184. package/src/auth/http.ts +39 -0
  185. package/src/auth/login.ts +177 -0
  186. package/src/auth/protocol.ts +37 -0
  187. package/src/baseline.ts +15 -0
  188. package/src/bin.ts +4 -0
  189. package/src/cli.ts +969 -0
  190. package/src/create/choices.ts +177 -0
  191. package/src/create/deployment.ts +96 -0
  192. package/src/create/scaffold.ts +334 -0
  193. package/src/create/source-reference.ts +212 -0
  194. package/src/create/template.ts +300 -0
  195. package/src/diagnostics.ts +8 -0
  196. package/src/help.ts +142 -0
  197. package/src/openapi/bundle.ts +290 -0
  198. package/src/openapi/discovery.ts +438 -0
  199. package/src/openapi/emit.ts +1031 -0
  200. package/src/openapi/graphql.ts +375 -0
  201. package/src/openapi/identity.ts +153 -0
  202. package/src/openapi/mcp.ts +165 -0
  203. package/src/openapi/operations.ts +781 -0
  204. package/src/openapi/overlay.ts +195 -0
  205. package/src/openapi/plugin.ts +856 -0
  206. package/src/openapi/polymorphism.ts +207 -0
  207. package/src/openapi/postman.ts +403 -0
  208. package/src/openapi/schema.ts +2138 -0
  209. package/src/openapi/select.ts +113 -0
  210. package/src/openapi/spec.ts +401 -0
  211. package/src/openapi/swagger.ts +422 -0
  212. package/src/openapi/versions.ts +174 -0
  213. package/src/plugin/archive.ts +244 -0
  214. package/src/plugin/bundle.ts +572 -0
  215. package/src/plugin/init.ts +178 -0
  216. package/src/plugin/inspection.ts +19 -0
  217. package/src/plugin/package.ts +140 -0
  218. package/src/plugin/publication.ts +128 -0
  219. package/src/plugin/validation.ts +213 -0
  220. package/src/release/archives.ts +133 -0
  221. package/src/release/release-manifest.ts +79 -0
  222. package/src/release/releases.ts +210 -0
  223. package/src/skills.ts +434 -0
  224. package/templates/compose/.env.compose.example.hbs +3 -0
  225. package/templates/compose/.env.host.example.hbs +4 -0
  226. package/templates/compose/Dockerfile.hbs +12 -0
  227. package/templates/compose/OPERATIONS.md.hbs +159 -0
  228. package/templates/compose/_dockerignore +14 -0
  229. package/templates/compose/compose.external.yaml +7 -0
  230. package/templates/compose/compose.host-linux.yaml +5 -0
  231. package/templates/compose/compose.host.yaml.hbs +15 -0
  232. package/templates/compose/compose.yaml.hbs +85 -0
  233. package/templates/compose/release.env.hbs +2 -0
  234. package/templates/default/.env.example.hbs +79 -0
  235. package/templates/default/README.md.hbs +150 -0
  236. package/templates/default/_gitignore +11 -0
  237. package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
  238. package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
  239. package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
  240. package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
  241. package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
  242. package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
  243. package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
  244. package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
  245. package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
  246. package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
  247. package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
  248. package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
  249. package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
  250. package/templates/default/tsconfig.json +5 -0
  251. package/templates/default/vitest.config.ts +5 -0
  252. package/templates/default/vitest.host.config.ts +6 -0
  253. package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
  254. 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";