@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,856 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ import {
4
+ Array,
5
+ Boolean,
6
+ Context,
7
+ Effect,
8
+ FileSystem,
9
+ HashMap,
10
+ HashSet,
11
+ Layer,
12
+ Option,
13
+ Order,
14
+ Path,
15
+ Predicate,
16
+ Record,
17
+ Result,
18
+ Schema,
19
+ String,
20
+ Struct,
21
+ pipe,
22
+ } from "effect";
23
+
24
+ import { HttpClient, HttpClientRequest } from "effect/http";
25
+ import * as Oxfmt from "vite-plus/fmt";
26
+
27
+ import { Mcp } from "@dual-os/sdk/Mcp";
28
+
29
+ import { OpenApiBundle } from "./bundle.ts";
30
+ import { OpenApiEmit } from "./emit.ts";
31
+ import { OpenApiGraphql } from "./graphql.ts";
32
+ import { OpenApiIdentity } from "./identity.ts";
33
+ import { OpenApiOperations } from "./operations.ts";
34
+ import { OpenApiOverlay } from "./overlay.ts";
35
+ import { OpenApiSchema } from "./schema.ts";
36
+ import { OpenApiSelect } from "./select.ts";
37
+ import { OpenApiSpec } from "./spec.ts";
38
+ import { OpenApiVersions } from "./versions.ts";
39
+
40
+ export class OpenApiPluginError extends Schema.TaggedError<OpenApiPluginError>()(
41
+ "OpenApiPluginError",
42
+ { cause: Schema.optional(Schema.Defect()), message: Schema.String },
43
+ ) {}
44
+
45
+ export type PackageScope = typeof PackageScope.Type;
46
+ export const PackageScope = Schema.String.check(
47
+ Schema.isPattern(/^@[a-z0-9-~][a-z0-9-._~]*$/u, {
48
+ message: "A package scope looks like @example",
49
+ }),
50
+ );
51
+
52
+ type PluginId = typeof PluginId.Type;
53
+ const PluginId = Schema.String.check(
54
+ Schema.isPattern(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u, {
55
+ message: "A plugin id is kebab-case and starts with a letter",
56
+ }),
57
+ );
58
+
59
+ type HttpUrl = typeof HttpUrl.Type;
60
+ const HttpUrl = Schema.String.check(
61
+ Schema.makeFilter(
62
+ value =>
63
+ Option.exists(
64
+ Schema.decodeOption(Schema.URLFromString)(value),
65
+ url =>
66
+ (url.protocol === "http:" || url.protocol === "https:") &&
67
+ String.isNonEmpty(url.hostname),
68
+ ),
69
+ { message: "A URL is an absolute http or https URL with a host" },
70
+ ),
71
+ );
72
+
73
+ /** How a spec's source is read: a description document, a GraphQL schema or endpoint, or an MCP server. */
74
+ export type SourceKind = typeof SourceKind.Type;
75
+ export const SourceKind = Schema.Literals(["document", "graphql", "mcp"]);
76
+
77
+ type OAuth = typeof OAuth.Type;
78
+ const OAuth = Schema.Struct({
79
+ authentication: Schema.optionalKey(Schema.Literals(["basic", "none", "post"])),
80
+ authorizationUrl: HttpUrl,
81
+ pkce: Schema.optionalKey(Schema.Boolean),
82
+ resource: Schema.optionalKey(HttpUrl),
83
+ scopes: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
84
+ tokenUrl: HttpUrl,
85
+ });
86
+
87
+ type Spec = typeof Spec.Type;
88
+ const Spec = Schema.Struct({
89
+ aliases: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
90
+ endpoint: Schema.optionalKey(HttpUrl),
91
+ exclude: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
92
+ include: Schema.optionalKey(
93
+ Schema.Union([
94
+ Schema.Array(Schema.NonEmptyString),
95
+ Schema.Record(PluginId, Schema.Array(Schema.NonEmptyString)),
96
+ ]),
97
+ ),
98
+ kind: SourceKind,
99
+ name: Schema.optionalKey(PluginId),
100
+ overlay: Schema.optionalKey(Schema.NonEmptyString),
101
+ source: Schema.NonEmptyString,
102
+ sourceUrl: Schema.optionalKey(HttpUrl),
103
+ });
104
+
105
+ type Inputs = typeof Inputs.Type;
106
+ const Inputs = Schema.Struct({
107
+ identityMappings: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
108
+ metadata: Schema.optionalKey(
109
+ Schema.Struct({
110
+ description: Schema.optionalKey(Schema.NonEmptyString),
111
+ name: Schema.optionalKey(Schema.NonEmptyString),
112
+ }),
113
+ ),
114
+ packageScope: Schema.optional(PackageScope),
115
+ provider: Schema.Struct({
116
+ metadata: Schema.optionalKey(
117
+ Schema.Struct({
118
+ categories: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
119
+ description: Schema.optionalKey(Schema.NonEmptyString),
120
+ docsUrl: Schema.optionalKey(Schema.NonEmptyString),
121
+ homepageUrl: Schema.optionalKey(Schema.NonEmptyString),
122
+ iconUrl: Schema.optionalKey(Schema.NonEmptyString),
123
+ }),
124
+ ),
125
+ name: Schema.NonEmptyString,
126
+ oauth: Schema.optionalKey(OAuth),
127
+ specs: Schema.NonEmptyArray(Spec),
128
+ }),
129
+ target: OpenApiEmit.Target,
130
+ });
131
+
132
+ export type PluginJson = typeof PluginJson.Type;
133
+ export const PluginJson = Schema.Struct({ openapi: Inputs });
134
+
135
+ export type Request = typeof Request.Type;
136
+ export const Request = Schema.Struct({
137
+ destination: Schema.NonEmptyString,
138
+ kind: SourceKind,
139
+ packageScope: Schema.optional(PackageScope),
140
+ spec: Schema.NonEmptyString,
141
+ target: OpenApiEmit.Target,
142
+ });
143
+
144
+ interface Summary {
145
+ added: string[];
146
+ changed: string[];
147
+ excluded: string[];
148
+ generated: number;
149
+ kept: string[];
150
+ vanished: string[];
151
+ widened: string[];
152
+ }
153
+
154
+ interface File {
155
+ readonly path: string;
156
+ readonly text: string;
157
+ }
158
+
159
+ interface Loaded {
160
+ readonly raw: OpenApiSpec.JsonObject;
161
+ readonly specUrl?: URL;
162
+ }
163
+
164
+ const inputsFile = "plugin.json";
165
+
166
+ function failure(message: string) {
167
+ return Effect.mapError(cause => OpenApiPluginError.make({ cause, message }));
168
+ }
169
+
170
+ function inSource(source: string) {
171
+ return Effect.mapError((message: string) =>
172
+ OpenApiPluginError.make({ message: `${source}: ${message}` }),
173
+ );
174
+ }
175
+
176
+ function specUrlOf(spec: string) {
177
+ if (!URL.canParse(spec)) {
178
+ return undefined;
179
+ }
180
+ const url = new URL(spec);
181
+ return /^https?:$/u.test(url.protocol) ? url : undefined;
182
+ }
183
+
184
+ function sourceName(entry: { name: Option.Option<string> }) {
185
+ return Option.getOrElse(entry.name, () => "api");
186
+ }
187
+
188
+ function keyOf(action: OpenApiSchema.Action) {
189
+ return Array.join([action.provider, action.operation.groupId, action.operation.actionId], "/");
190
+ }
191
+
192
+ function format(name: string, text: string, options: Oxfmt.FormatConfig) {
193
+ return Effect.map(
194
+ Effect.tryPromise({
195
+ catch: cause => OpenApiPluginError.make({ cause, message: `Could not format ${name}` }),
196
+ try: () => Oxfmt.format(name, text, options),
197
+ }),
198
+ formatted => formatted.code,
199
+ );
200
+ }
201
+
202
+ export interface Interface {
203
+ readonly create: (request: Request) => Effect.Effect<Summary, OpenApiPluginError>;
204
+ readonly generate: (directory: string) => Effect.Effect<Summary, OpenApiPluginError>;
205
+ }
206
+
207
+ export class Service extends Context.Service<Service, Interface>()(
208
+ "@dual-os/cli/openapi/plugin/Service",
209
+ ) {}
210
+
211
+ export const defaultLayer = Layer.effect(
212
+ Service,
213
+ Effect.gen(function* () {
214
+ const fileSystem = yield* FileSystem.FileSystem;
215
+ const path = yield* Path.Path;
216
+ const http = yield* HttpClient.HttpClient;
217
+ const client = HttpClient.filterStatusOk(http);
218
+
219
+ const read = Effect.fnUntraced(function* (location: string, base: string) {
220
+ const url = specUrlOf(location);
221
+ if (url === undefined) {
222
+ const source = path.resolve(base, location);
223
+ return {
224
+ source,
225
+ text: yield* pipe(fileSystem.readFileString(source), failure(`Could not read ${source}`)),
226
+ };
227
+ }
228
+ return {
229
+ source: url.href,
230
+ text: yield* pipe(
231
+ client.get(url.href),
232
+ Effect.flatMap(response => response.text),
233
+ Effect.timeout("60 seconds"),
234
+ failure(`Could not fetch ${url.href}`),
235
+ ),
236
+ };
237
+ });
238
+
239
+ const readText = Effect.fnUntraced(
240
+ function* (location: string) {
241
+ return (yield* read(location, "")).text;
242
+ },
243
+ Effect.mapError(error => error.message),
244
+ );
245
+
246
+ function parse(found: { source: string; text: string }) {
247
+ return OpenApiSpec.parse(found.text, document =>
248
+ OpenApiBundle.bundle(document, found.source, { path, read: readText }),
249
+ );
250
+ }
251
+
252
+ const load = Effect.fnUntraced(function* (spec: Spec, base: string) {
253
+ const endpoint = specUrlOf(spec.source);
254
+ const origin = specUrlOf(spec.sourceUrl ?? spec.source);
255
+ if (spec.kind === "document") {
256
+ const found = yield* read(spec.source, base);
257
+ const raw = yield* pipe(
258
+ parse(found),
259
+ failure(
260
+ `${found.source} is not an OpenAPI 3.0/3.1, Swagger 2.0, Google Discovery or Postman collection document`,
261
+ ),
262
+ );
263
+ return origin === undefined ? { raw } : { raw, specUrl: origin };
264
+ }
265
+ if (spec.kind === "graphql" && spec.endpoint !== undefined) {
266
+ const found = yield* read(spec.source, base);
267
+ return {
268
+ raw: yield* pipe(
269
+ OpenApiSpec.parseGraphql(found.text, spec.endpoint),
270
+ failure(`${found.source} is not a GraphQL introspection result or schema in SDL`),
271
+ ),
272
+ };
273
+ }
274
+ if (endpoint === undefined) {
275
+ return yield* OpenApiPluginError.make({
276
+ message: `${spec.source}: a ${spec.kind} source without an endpoint is the URL of a ${spec.kind === "graphql" ? "GraphQL endpoint" : "Model Context Protocol server"}`,
277
+ });
278
+ }
279
+ if (spec.kind === "graphql") {
280
+ return {
281
+ raw: yield* pipe(
282
+ client.execute(
283
+ pipe(
284
+ HttpClientRequest.post(endpoint.href),
285
+ HttpClientRequest.bodyJsonUnsafe({ query: OpenApiGraphql.introspectionQuery }),
286
+ ),
287
+ ),
288
+ Effect.flatMap(response => response.text),
289
+ Effect.flatMap(text => OpenApiSpec.parseGraphql(text, endpoint.href)),
290
+ failure(`${endpoint.href} did not answer a GraphQL introspection query`),
291
+ ),
292
+ };
293
+ }
294
+ return {
295
+ raw: yield* pipe(
296
+ Mcp.listTools(client, endpoint.href, {}),
297
+ Effect.map(found => OpenApiSpec.parseMcp(found.server, found.tools, endpoint.href)),
298
+ failure(`${endpoint.href} did not list Model Context Protocol tools`),
299
+ ),
300
+ };
301
+ });
302
+
303
+ const overlay = Effect.fnUntraced(function* (
304
+ entry: Spec,
305
+ raw: OpenApiSpec.JsonObject,
306
+ destination: string,
307
+ ) {
308
+ if (entry.overlay === undefined) {
309
+ return raw;
310
+ }
311
+ const found = yield* read(entry.overlay, destination);
312
+ const document = yield* pipe(
313
+ OpenApiSpec.parseYaml(found.text),
314
+ Effect.flatMap(Schema.decodeUnknownEffect(OpenApiOverlay.Overlay)),
315
+ failure(`${found.source} is not an OpenAPI Overlay 1.x document`),
316
+ );
317
+ return yield* pipe(
318
+ OpenApiOverlay.applyOverlay(raw, document),
319
+ Effect.fromResult,
320
+ Effect.flatMap(Schema.decodeUnknownEffect(OpenApiSpec.JsonObject)),
321
+ Effect.mapError(cause =>
322
+ OpenApiPluginError.make({
323
+ cause,
324
+ message: `${entry.overlay}: ${Predicate.isString(cause) ? cause : "the overlaid document is not an object"}`,
325
+ }),
326
+ ),
327
+ );
328
+ });
329
+
330
+ const prepare = Effect.fnUntraced(function* (entry: Spec, loaded: Loaded, destination: string) {
331
+ const expanded = yield* pipe(
332
+ OpenApiSpec.expand(yield* overlay(entry, loaded.raw, destination)),
333
+ Effect.fromResult,
334
+ inSource(entry.source),
335
+ );
336
+ const include = entry.include;
337
+ const sections =
338
+ include === undefined || Schema.is(Schema.Array(Schema.String))(include)
339
+ ? [{ include, name: Option.fromNullishOr(entry.name) }]
340
+ : Record.collect(include, (name, patterns) => ({
341
+ include: patterns,
342
+ name: Option.some(name),
343
+ }));
344
+ return yield* Effect.forEach(sections, section =>
345
+ Effect.gen(function* () {
346
+ const selected = yield* pipe(
347
+ OpenApiSelect.select(expanded, {
348
+ ...pipe(entry, Struct.pick(["aliases", "exclude"])),
349
+ ...(section.include === undefined ? {} : { include: section.include }),
350
+ }),
351
+ Effect.fromResult,
352
+ inSource(entry.source),
353
+ );
354
+ const spec = yield* pipe(
355
+ OpenApiSpec.document(selected),
356
+ failure(
357
+ `${entry.source} is not a valid OpenAPI 3.x document after its overlay and selection`,
358
+ ),
359
+ );
360
+ return {
361
+ name: section.name,
362
+ source: entry.source,
363
+ spec,
364
+ specUrl: loaded.specUrl,
365
+ walk: OpenApiOperations.walk(
366
+ loaded.specUrl === undefined ? { spec } : { spec, specUrl: loaded.specUrl },
367
+ ),
368
+ };
369
+ }),
370
+ );
371
+ });
372
+
373
+ const write = Effect.fnUntraced(function* (destination: string, files: File[]) {
374
+ const formatted = yield* Effect.forEach(
375
+ files,
376
+ file =>
377
+ Effect.map(
378
+ format(
379
+ file.path,
380
+ file.text,
381
+ Boolean.match(pipe(file.path, String.endsWith(".json")), {
382
+ onFalse: () => ({ arrowParens: "avoid", objectWrap: "preserve" }),
383
+ onTrue: () => ({
384
+ arrowParens: "avoid",
385
+ objectWrap: "collapse",
386
+ sortPackageJson: { sortScripts: true },
387
+ }),
388
+ }),
389
+ ),
390
+ text => ({ path: file.path, text }),
391
+ ),
392
+ { concurrency: 16 },
393
+ );
394
+ yield* pipe(
395
+ Effect.forEach(
396
+ Array.dedupe(Array.map(files, file => path.dirname(path.join(destination, file.path)))),
397
+ directory => fileSystem.makeDirectory(directory, { recursive: true }),
398
+ { discard: true },
399
+ ),
400
+ Effect.andThen(
401
+ Effect.forEach(
402
+ formatted,
403
+ file => fileSystem.writeFileString(path.join(destination, file.path), file.text),
404
+ { concurrency: 16, discard: true },
405
+ ),
406
+ ),
407
+ failure("Could not write the generated plugin package"),
408
+ );
409
+ });
410
+
411
+ const readPrevious = Effect.fnUntraced(function* (file: string) {
412
+ if (!(yield* fileSystem.exists(file))) {
413
+ return "";
414
+ }
415
+ return yield* fileSystem.readFileString(file);
416
+ }, failure("Could not read the generated plugin package"));
417
+
418
+ const readLock = Effect.fnUntraced(function* (file: string) {
419
+ if (!(yield* fileSystem.exists(file))) {
420
+ return { actions: {}, identities: {} };
421
+ }
422
+ return yield* OpenApiVersions.decodeLock(yield* fileSystem.readFileString(file));
423
+ }, failure("Could not read src/generated/lock.json"));
424
+
425
+ const generatePackage = Effect.fnUntraced(function* (
426
+ destination: string,
427
+ config: PluginJson,
428
+ loaded: HashMap.HashMap<string, Loaded>,
429
+ ) {
430
+ const inputs = config.openapi;
431
+ const pluginId = yield* pipe(
432
+ Schema.decodeEffect(PluginId)(path.basename(destination)),
433
+ failure(
434
+ `The package directory name ${path.basename(destination)} is the plugin id and must be kebab-case`,
435
+ ),
436
+ );
437
+ const naming = {
438
+ packageScope: inputs.packageScope ?? "@customer",
439
+ pluginId,
440
+ target: inputs.target,
441
+ };
442
+ const recorded = yield* readLock(path.join(destination, "src/generated/lock.json"));
443
+ if (
444
+ yield* pipe(
445
+ fileSystem.exists(path.join(destination, "src/adapters.ts")),
446
+ failure("Could not inspect legacy adapters"),
447
+ )
448
+ ) {
449
+ return yield* OpenApiPluginError.make({
450
+ message:
451
+ "Port auth.ts and triggers.ts to current SDK handlers, then remove src/adapters.ts before regenerating; keep historical code in its released artifact",
452
+ });
453
+ }
454
+ const documents = Array.flatten(
455
+ yield* Effect.forEach(inputs.provider.specs, entry =>
456
+ prepare(entry, HashMap.getUnsafe(loaded, entry.source), destination),
457
+ ),
458
+ );
459
+ const names = Array.map(documents, sourceName);
460
+ if (Array.dedupe(names).length !== names.length) {
461
+ return yield* OpenApiPluginError.make({
462
+ message: `Provider ${pluginId} must give its source documents and include sets distinct, stable names`,
463
+ });
464
+ }
465
+ const indexed = Array.map(documents, (entry, index) => ({ ...entry, index }));
466
+ // An operation selected by several entries of one source belongs to the first.
467
+ const owners = Array.reduce(indexed, HashMap.empty<string, number>(), (found, entry) =>
468
+ Array.reduce(entry.walk.operations, found, (owned, operation) => {
469
+ const claim = `${entry.source} ${operation.method} ${operation.path}`;
470
+ return HashMap.has(owned, claim) ? owned : HashMap.set(owned, claim, entry.index);
471
+ }),
472
+ );
473
+ const walked = Array.flatten(
474
+ Array.zipWith(
475
+ indexed,
476
+ OpenApiOperations.withReadableGroupIds(
477
+ Array.map(indexed, entry => ({
478
+ name: entry.name,
479
+ operations: Array.filter(entry.walk.operations, operation =>
480
+ Option.contains(
481
+ HashMap.get(owners, `${entry.source} ${operation.method} ${operation.path}`),
482
+ entry.index,
483
+ ),
484
+ ),
485
+ title: entry.spec.document.info.title,
486
+ })),
487
+ ),
488
+ (entry, operations) =>
489
+ Array.map(operations, operation => ({
490
+ document: entry.index,
491
+ operation,
492
+ source: sourceName(entry),
493
+ })),
494
+ ),
495
+ );
496
+ const candidates = Array.zipWith(
497
+ walked,
498
+ OpenApiOperations.withUniqueActionIds(Array.map(walked, entry => entry.operation)),
499
+ (entry, operation) => ({
500
+ ...entry,
501
+ operation: {
502
+ ...operation,
503
+ actionName:
504
+ documents.length > 1 && entry.source !== "api"
505
+ ? `${OpenApiSpec.titleCase(entry.source)} — ${operation.actionName}`
506
+ : operation.actionName,
507
+ },
508
+ provider: pluginId,
509
+ }),
510
+ );
511
+ const identified = yield* pipe(
512
+ OpenApiIdentity.resolve(candidates, recorded.identities, inputs.identityMappings ?? {}),
513
+ Effect.fromResult,
514
+ Effect.mapError(message => OpenApiPluginError.make({ message })),
515
+ );
516
+ const specs = Array.map(documents, entry => entry.spec);
517
+ const actions = Array.filter(
518
+ identified.actions,
519
+ action => !action.operation.deprecated || Record.has(recorded.actions, keyOf(action)),
520
+ );
521
+ const checked = OpenApiSchema.catalog(specs, actions);
522
+ const excluded = Array.flatMap(documents, entry =>
523
+ Array.map(
524
+ entry.walk.skipped,
525
+ skipped =>
526
+ `${sourceName(entry)} ${String.toUpperCase(skipped.operation?.method ?? "")} ${skipped.path}: ${skipped.reason}`,
527
+ ),
528
+ );
529
+ const widened = Array.filterMap(Array.zip(actions, checked.unsupported), pair =>
530
+ Array.isReadonlyArrayNonEmpty(pair[1])
531
+ ? Result.succeed(
532
+ `${keyOf(pair[0])} (${String.toUpperCase(pair[0].operation.method)} ${pair[0].operation.path}): ${Array.join(
533
+ Array.map(
534
+ Array.take(pair[1], 3),
535
+ unsupported => `${unsupported.pointer} ${unsupported.reason}`,
536
+ ),
537
+ "; ",
538
+ )}`,
539
+ )
540
+ : Result.failVoid,
541
+ );
542
+ if (Array.isReadonlyArrayEmpty(actions)) {
543
+ return yield* OpenApiPluginError.make({
544
+ message: `The documents contain no supported operations for this provider${Array.isReadonlyArrayEmpty(excluded) ? "" : `:\n${Array.join(excluded, "\n")}`}`,
545
+ });
546
+ }
547
+ const kept = HashSet.fromIterable(Array.map(actions, keyOf));
548
+ const ledger = Record.filter(
549
+ identified.ledger,
550
+ (_, id) => Record.has(recorded.identities, id) || HashSet.has(kept, id),
551
+ );
552
+ // A contract hash depends only on its own action, so the checked catalog serves every action.
553
+ const current = HashMap.fromIterable(
554
+ Array.zipWith(actions, OpenApiVersions.hashes(checked), (action, hash) => [
555
+ keyOf(action),
556
+ hash,
557
+ ]),
558
+ );
559
+ const unlisted = pipe(
560
+ Record.keys(recorded.actions),
561
+ Array.map(key => pipe(key, String.split("/"), Array.headNonEmpty)),
562
+ Array.dedupe,
563
+ Array.filter(id => id !== pluginId),
564
+ );
565
+ if (Array.isReadonlyArrayNonEmpty(unlisted)) {
566
+ return yield* OpenApiPluginError.make({
567
+ message: `lock.json records actions of ${Array.join(unlisted, ", ")}, but the package directory is ${pluginId}; restore its name to retain those actions`,
568
+ });
569
+ }
570
+ const added = Array.filter(
571
+ Array.fromIterable(HashMap.keys(current)),
572
+ key => !Record.has(recorded.actions, key),
573
+ );
574
+ const changed = Array.filter(
575
+ Array.fromIterable(HashMap.keys(current)),
576
+ key =>
577
+ Record.has(recorded.actions, key) &&
578
+ recorded.actions[key]?.hash !== HashMap.getUnsafe(current, key),
579
+ );
580
+ const vanished = Array.filter(
581
+ Record.keys(recorded.actions),
582
+ key => !HashMap.has(current, key),
583
+ );
584
+ const exported = Array.groupBy(
585
+ Array.fromIterable(HashMap.keys(current)),
586
+ OpenApiEmit.exportName,
587
+ );
588
+ for (const keys of Record.values(exported)) {
589
+ if (keys.length > 1)
590
+ return yield* OpenApiPluginError.make({
591
+ message: `Actions ${Array.join(keys, " and ")} share a module name; use identityMappings to give them distinct ids`,
592
+ });
593
+ }
594
+ const generatedDirectory = path.join(destination, "src/generated");
595
+ const named = OpenApiSchema.namedEnums(checked, actions);
596
+ const planned = Array.map(actions, action => ({
597
+ action,
598
+ group: action.operation.groupId,
599
+ id: action.operation.actionId,
600
+ key: keyOf(action),
601
+ }));
602
+
603
+ const spec = Array.getUnsafe(documents, 0).spec;
604
+ const provider = {
605
+ groups: Array.dedupe(Array.map(planned, entry => entry.group)),
606
+ metadata: {
607
+ ...Record.getSomes({
608
+ description: pipe(
609
+ Option.fromNullishOr(spec.document.info.description),
610
+ Option.map(description =>
611
+ pipe(description, String.replace(/\s+/gu, " "), String.trim),
612
+ ),
613
+ Option.filter(String.isNonEmpty),
614
+ ),
615
+ docsUrl: Option.map(
616
+ Schema.decodeUnknownOption(
617
+ Schema.Struct({ externalDocs: Schema.Struct({ url: Schema.NonEmptyString }) }),
618
+ )(spec.raw),
619
+ found => found.externalDocs.url,
620
+ ),
621
+ }),
622
+ ...inputs.provider.metadata,
623
+ },
624
+ name: inputs.provider.name,
625
+ };
626
+
627
+ const auth = yield* readPrevious(path.join(destination, "src/auth.ts"));
628
+ const generated = [
629
+ {
630
+ path: "src/generated/operations.ts",
631
+ text: OpenApiEmit.operationsSource(
632
+ named.declarations,
633
+ Array.zipWith(actions, named.contracts, (action, contract) => ({
634
+ contract,
635
+ name: OpenApiEmit.exportName(keyOf(action)),
636
+ })),
637
+ ),
638
+ },
639
+ {
640
+ path: "src/generated/plugin.ts",
641
+ text: OpenApiEmit.pluginSource({
642
+ actions: Array.map(planned, entry => ({
643
+ description: entry.action.operation.description,
644
+ group: entry.group,
645
+ id: entry.id,
646
+ key: entry.key,
647
+ name: entry.action.operation.actionName,
648
+ })),
649
+ metadata: inputs.metadata ?? {},
650
+ pluginId,
651
+ provider,
652
+ sandboxAccess: /\bexport\s+const\s+sandboxAccess\b/u.test(auth),
653
+ }),
654
+ },
655
+ { path: "src/generated/http.ts", text: OpenApiEmit.httpSource },
656
+ {
657
+ path: "src/generated/lock.json",
658
+ text: yield* pipe(
659
+ Schema.encodeEffect(OpenApiVersions.LockFile)({
660
+ actions: Record.fromEntries(
661
+ Array.map(
662
+ Array.sortWith(Array.fromIterable(current), ([key]) => key, Order.String),
663
+ ([key, hash]) => [key, { hash }] as const,
664
+ ),
665
+ ),
666
+ identities: ledger,
667
+ }),
668
+ failure("Could not encode the action identity ledger"),
669
+ ),
670
+ },
671
+ { path: inputsFile, text: OpenApiEmit.pluginJsonSource(naming, inputs) },
672
+ ];
673
+ const declared = pipe(
674
+ documents,
675
+ Array.flatMap(entry => OpenApiSpec.securitySchemes(entry.spec, entry.specUrl)),
676
+ Array.dedupeWith((left, right) => left.methodId === right.methodId),
677
+ );
678
+ const oauth = inputs.provider.oauth;
679
+ if (
680
+ oauth !== undefined &&
681
+ Array.some(documents, entry => OpenApiSpec.declaresOAuth(entry.spec))
682
+ ) {
683
+ return yield* OpenApiPluginError.make({
684
+ message:
685
+ "provider.oauth describes a source that declares no OAuth scheme; this source declares one, so remove provider.oauth or fix the scheme with an overlay",
686
+ });
687
+ }
688
+ const schemes =
689
+ oauth === undefined
690
+ ? declared
691
+ : [
692
+ ...declared,
693
+ {
694
+ description: undefined,
695
+ displayName: "OAuth",
696
+ kind: {
697
+ _tag: "OAuth2",
698
+ ...oauth,
699
+ scopes: Array.sort(oauth.scopes ?? [], Order.String),
700
+ },
701
+ methodId: "oauth",
702
+ name: "oauth",
703
+ } satisfies OpenApiSpec.SecurityScheme,
704
+ ];
705
+ const owned = [
706
+ { path: "src/auth.ts", text: Effect.succeed(OpenApiEmit.authSource(schemes)) },
707
+ { path: "src/triggers.ts", text: Effect.succeed(OpenApiEmit.triggersSource) },
708
+ {
709
+ path: "package.json",
710
+ text:
711
+ inputs.target === "internal"
712
+ ? pipe(
713
+ Effect.try(() =>
714
+ createRequire(path.join(destination, "package.json")).resolve(
715
+ "@dual-os/sdk/package.json",
716
+ ),
717
+ ),
718
+ Effect.flatMap(fileSystem.readFileString),
719
+ Effect.flatMap(
720
+ Schema.decodeEffect(
721
+ Schema.fromJsonString(Schema.Struct({ version: Schema.NonEmptyString })),
722
+ ),
723
+ ),
724
+ Effect.map(sdk => OpenApiEmit.packageJsonSource(naming, `^${sdk.version}`)),
725
+ failure("Could not read the @dual-os/sdk version the package builds on"),
726
+ )
727
+ : Effect.succeed(OpenApiEmit.packageJsonSource(naming, "*")),
728
+ },
729
+ { path: "tsconfig.json", text: Effect.succeed(OpenApiEmit.tsconfigSource()) },
730
+ {
731
+ path: "vite.config.ts",
732
+ text: Effect.succeed(OpenApiEmit.viteConfigSource(inputs.target)),
733
+ },
734
+ { path: "LICENSE", text: Effect.succeed(OpenApiEmit.licenseSource) },
735
+ ];
736
+ const existing = yield* pipe(
737
+ Effect.forEach(
738
+ owned,
739
+ file =>
740
+ Effect.map(fileSystem.exists(path.join(destination, file.path)), exists => ({
741
+ exists,
742
+ file,
743
+ })),
744
+ { concurrency: 16 },
745
+ ),
746
+ failure("Could not read the generated plugin package"),
747
+ );
748
+ const absent = Array.filter(existing, status => !status.exists);
749
+ yield* write(destination, [
750
+ ...generated,
751
+ ...(yield* Effect.forEach(absent, status =>
752
+ Effect.map(status.file.text, text => ({ path: status.file.path, text })),
753
+ )),
754
+ ]);
755
+ yield* pipe(
756
+ fileSystem.readDirectory(generatedDirectory),
757
+ Effect.flatMap(files =>
758
+ Effect.forEach(
759
+ Array.filter(
760
+ files,
761
+ file => !Array.contains(["plugin.ts", "operations.ts", "http.ts", "lock.json"], file),
762
+ ),
763
+ file => fileSystem.remove(path.join(generatedDirectory, file), { recursive: true }),
764
+ { discard: true },
765
+ ),
766
+ ),
767
+ failure("Could not delete superseded generated modules"),
768
+ );
769
+ return {
770
+ added,
771
+ changed,
772
+ excluded,
773
+ generated: actions.length,
774
+ kept: Array.filterMap(existing, status =>
775
+ status.exists ? Result.succeed(status.file.path) : Result.failVoid,
776
+ ),
777
+ vanished,
778
+ widened,
779
+ };
780
+ });
781
+
782
+ const create = Effect.fn("OpenApiPlugin.create")(function* (request: Request) {
783
+ const destination = path.resolve(request.destination);
784
+ const file = path.join(destination, inputsFile);
785
+ if (yield* pipe(fileSystem.exists(file), failure("Could not read the plugin package"))) {
786
+ return yield* OpenApiPluginError.make({
787
+ message: `${file} exists; edit it and run dual openapi-plugin ${request.destination} to regenerate the package`,
788
+ });
789
+ }
790
+ const url = specUrlOf(request.spec);
791
+ const spec =
792
+ url === undefined ? path.relative(destination, path.resolve(request.spec)) : url.href;
793
+ const loaded = yield* load({ kind: request.kind, source: spec }, destination);
794
+ const title = Schema.decodeUnknownOption(
795
+ Schema.Struct({ info: Schema.Struct({ title: Schema.NonEmptyString }) }),
796
+ )(loaded.raw);
797
+ return yield* generatePackage(
798
+ destination,
799
+ {
800
+ openapi: {
801
+ packageScope: request.packageScope,
802
+ provider: {
803
+ name: Option.match(title, {
804
+ onNone: () => OpenApiSpec.titleCase(path.basename(destination)),
805
+ onSome: found => found.info.title,
806
+ }),
807
+ specs: [{ kind: request.kind, source: spec }],
808
+ },
809
+ target: request.target,
810
+ },
811
+ },
812
+ HashMap.make([spec, loaded]),
813
+ );
814
+ });
815
+
816
+ const generate = Effect.fn("OpenApiPlugin.generate")(function* (directory: string) {
817
+ const destination = path.resolve(directory);
818
+ const file = path.join(destination, inputsFile);
819
+ const config = yield* pipe(
820
+ fileSystem.readFileString(file),
821
+ Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(PluginJson))),
822
+ Effect.mapError(cause =>
823
+ OpenApiPluginError.make({ cause, message: `${file}: ${cause.message}` }),
824
+ ),
825
+ );
826
+ const conflicting = Array.findFirst(config.openapi.provider.specs, spec =>
827
+ Array.some(
828
+ config.openapi.provider.specs,
829
+ other =>
830
+ other.source === spec.source &&
831
+ (other.kind !== spec.kind ||
832
+ other.endpoint !== spec.endpoint ||
833
+ other.sourceUrl !== spec.sourceUrl),
834
+ ),
835
+ );
836
+ const repeated = Option.getOrUndefined(conflicting);
837
+ if (repeated !== undefined) {
838
+ return yield* OpenApiPluginError.make({
839
+ message: `${file}: more than one spec loads the same source with different settings: ${repeated.source}`,
840
+ });
841
+ }
842
+ const loaded = yield* Effect.forEach(
843
+ Array.dedupeWith(
844
+ config.openapi.provider.specs,
845
+ (left, right) => left.source === right.source,
846
+ ),
847
+ spec => Effect.map(load(spec, destination), found => [spec.source, found] as const),
848
+ );
849
+ return yield* generatePackage(destination, config, HashMap.fromIterable(loaded));
850
+ });
851
+
852
+ return { create, generate } satisfies Interface;
853
+ }),
854
+ );
855
+
856
+ export * as OpenApiPlugin from "./plugin.ts";