@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.
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,596 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { versions } from "../baseline.js";
3
+ import { camelize, titleCase } from "./spec.js";
4
+ import { converts, defaultContentType, targets } from "./schema.js";
5
+ import "./emit.js";
6
+ import { Array, Graph, HashMap, HashSet, Match, Option, Order, Predicate, Record, Result, Schema, String, pipe } from "effect";
7
+ // src/openapi/emit.ts
8
+ var emit_exports = /* @__PURE__ */ __exportAll({
9
+ OpenApiEmit: () => emit_exports,
10
+ Target: () => Target,
11
+ authSource: () => authSource,
12
+ exportName: () => exportName,
13
+ httpSource: () => httpSource,
14
+ licenseSource: () => licenseSource,
15
+ operationsSource: () => operationsSource,
16
+ packageJsonSource: () => packageJsonSource,
17
+ pluginJsonSource: () => pluginJsonSource,
18
+ pluginSource: () => pluginSource,
19
+ triggersSource: () => triggersSource,
20
+ tsconfigSource: () => tsconfigSource,
21
+ viteConfigSource: () => viteConfigSource
22
+ });
23
+ const Target = Schema.Literals(["internal", "customer"]);
24
+ const ownedHeader = "// Written once by dual openapi-plugin; edit freely. Delete it to regenerate.\n";
25
+ function key(value) {
26
+ return /^[A-Za-z_$][\w$]*$/u.test(value) ? value : JSON.stringify(value);
27
+ }
28
+ function importLine(names, from) {
29
+ return `import { ${Array.join(names, ", ")} } from "${from}";`;
30
+ }
31
+ const primitives = {
32
+ Boolean: "Schema.Boolean",
33
+ File: "Http.File",
34
+ Int: "Schema.Int",
35
+ Never: "Schema.Never",
36
+ Null: "Schema.Null",
37
+ Number: "Schema.Number",
38
+ String: "Schema.String",
39
+ ToolFile: "ToolFile.Schema",
40
+ Unknown: "Schema.Unknown"
41
+ };
42
+ function literals(values, separator) {
43
+ return Array.join(Array.map(values, (value) => JSON.stringify(value)), separator);
44
+ }
45
+ function annotation(method, description, format) {
46
+ const entries = [...description === void 0 ? [] : [`description: ${JSON.stringify(description)}`], ...format === void 0 ? [] : [`format: ${JSON.stringify(format)}`]];
47
+ return Array.isReadonlyArrayEmpty(entries) ? "" : `.${method}({ ${Array.join(entries, ", ")} })`;
48
+ }
49
+ const carriers = {
50
+ base64: "Base64",
51
+ base64url: "Base64Url",
52
+ "data-uri": "DataUri"
53
+ };
54
+ const clocks = {
55
+ "rfc-2822": "Rfc2822",
56
+ "unix-seconds": "UnixSeconds"
57
+ };
58
+ function instantCodec(instant) {
59
+ const clock = clocks[instant.clock];
60
+ return instant.direction === "input" ? `Http.${clock}FromDateTime` : `Http.DateTimeFrom${clock}`;
61
+ }
62
+ function bytesCodec(bytes) {
63
+ const carrier = carriers[bytes.alphabet];
64
+ return bytes.direction === "input" ? `Http.${carrier}FromFile` : `Http.FileFrom${carrier}`;
65
+ }
66
+ function field(entry, encoded) {
67
+ const schema = expression(entry.node, encoded);
68
+ const value = entry.node._tag === "Ref" && !entry.node.lazy ? `Schema.suspend(() => ${schema})` : schema;
69
+ const described = entry.node._tag === "Ref" ? annotation("annotateKey", entry.node.description) : "";
70
+ if (!entry.optional && entry.default !== void 0) return `${key(entry.name)}: ${value}.pipe(Schema.withDecodingDefaultKey(Effect.succeed(${JSON.stringify(entry.default)})))${described}`;
71
+ return `${key(entry.name)}: ${entry.optional ? `Schema.optionalKey(${value})` : value}${described}`;
72
+ }
73
+ function codec(name, type, encoded) {
74
+ return `Schema.Codec<${HashSet.has(encoded, name) ? `${name}, ${type}` : name}>`;
75
+ }
76
+ function expression(node, encoded, preserve = false) {
77
+ const shape = pipe(Match.value(node), Match.tags({
78
+ Array: (array) => `Schema.Array(${expression(array.item, encoded)})`,
79
+ Bytes: bytesCodec,
80
+ Instant: instantCodec,
81
+ Literals: (literal) => literal.literals.length === 1 ? `Schema.Literal(${literals(literal.literals, "")})` : `Schema.Literals([${literals(literal.literals, ", ")}])`,
82
+ NullOr: (nullable) => `Schema.NullOr(${expression(nullable.node, encoded)})`,
83
+ Record: (record) => `Schema.Record(Schema.String, ${expression(record.value, encoded)})`,
84
+ Ref: (ref) => ref.lazy ? `Schema.suspend((): ${codec(ref.target, `typeof ${ref.target}.Encoded`, encoded)} => ${ref.target})` : ref.target,
85
+ Struct: (struct) => {
86
+ const keys = Array.isReadonlyArrayEmpty(struct.excluded ?? []) ? "Schema.String" : `Schema.String.check(Schema.isPattern(new RegExp(${JSON.stringify(`^(?!(?:${Array.join(Array.map(struct.excluded ?? [], (name) => String.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")(name)), "|")})$)`)} , "u")))`;
87
+ const fields = `Schema.Struct({\n${Array.join([...Array.map(struct.spreads, (spread) => `...${spread}.fields`), ...Array.map(struct.fields, (entry) => field(entry, encoded))], ", ")}\n})`;
88
+ if (struct.additionalProperties !== void 0) {
89
+ const additional = expression(struct.additionalProperties, encoded);
90
+ const members = Array.dedupe([
91
+ additional,
92
+ ...Array.map(struct.fields, (entry) => expression(entry.node, encoded)),
93
+ ...Array.map(struct.spreads, (spread) => `Schema.Union(Record.values(${spread}.fields))`)
94
+ ]);
95
+ const names = `[${Array.join([...Array.map(struct.fields, (entry) => JSON.stringify(entry.name)), ...Array.map(struct.spreads, (spread) => `...Record.keys(${spread}.fields)`)], ", ")}]`;
96
+ return `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Union([${Array.join(members, ", ")}]))]).check(Schema.makeFilter(input => Array.every(Record.toEntries(input), entry => Array.contains(${names}, entry[0]) || Schema.is(${additional})(entry[1])), { representation: { id: "dual/openapi/additionalProperties", payload: null, schemas: [${additional}.ast] }, toJsonSchema: context => ({ properties: Record.fromEntries(Array.map(${names}, name => [name, {}])), additionalProperties: Array.getUnsafe(context.schemas, 0) }) }))`;
97
+ }
98
+ return struct.rest || preserve ? `Schema.StructWithRest(${fields}, [Schema.Record(${keys}, Schema.Unknown)])` : fields;
99
+ },
100
+ Union: (union) => `Schema.Union([${Array.join(Array.map(union.members, (member) => expression(member, encoded, union.preserve)), ", ")}]${union.exclusive === true ? ", { mode: \"oneOf\" }" : ""})`
101
+ }), Match.orElse((primitive) => primitives[primitive._tag]));
102
+ const checked = node.checks === void 0 ? shape : `${shape}.check(${Array.join(node.checks, ", ")})`;
103
+ return node._tag === "Ref" ? checked : `${checked}${annotation("annotate", node.description, node.format)}`;
104
+ }
105
+ const typeKeywords = {
106
+ Boolean: "boolean",
107
+ File: "unknown",
108
+ Int: "number",
109
+ Never: "never",
110
+ Null: "null",
111
+ Number: "number",
112
+ String: "string",
113
+ ToolFile: "ToolFile.File",
114
+ Unknown: "unknown"
115
+ };
116
+ function typeOf(node, encoded) {
117
+ function element(item) {
118
+ return item._tag === "Array" || item._tag === "Union" || item._tag === "NullOr" || item._tag === "Literals" ? `(${typeOf(item, encoded)})` : typeOf(item, encoded);
119
+ }
120
+ return pipe(Match.value(node), Match.tags({
121
+ Array: (array) => `readonly ${element(array.item)}[]`,
122
+ Bytes: (bytes) => {
123
+ if (bytes.direction === "input") return encoded === void 0 ? "string" : "typeof Http.File.Encoded";
124
+ return encoded === void 0 ? "ToolFile.File" : "string";
125
+ },
126
+ Instant: (instant) => {
127
+ const wire = instant.clock === "unix-seconds" ? "number" : "string";
128
+ if (instant.direction === "input") return encoded === void 0 ? wire : "string";
129
+ return encoded === void 0 ? "string" : wire;
130
+ },
131
+ Literals: (literal) => literals(literal.literals, " | "),
132
+ NullOr: (nullable) => `${typeOf(nullable.node, encoded)} | null`,
133
+ Record: (record) => `{ readonly [key: string]: ${typeOf(record.value, encoded)} }`,
134
+ Ref: (ref) => encoded !== void 0 && HashSet.has(encoded, ref.target) ? `typeof ${ref.target}.Encoded` : ref.target,
135
+ Struct: (struct) => Array.join([...Array.map(struct.spreads, (target) => typeOf({
136
+ _tag: "Ref",
137
+ lazy: false,
138
+ target
139
+ }, encoded)), `{\n${Array.join([...Array.map(struct.fields, (entry) => `readonly ${key(entry.name)}${entry.optional || encoded !== void 0 && entry.default !== void 0 ? "?" : ""}: ${typeOf(entry.node, encoded)}`), ...struct.additionalProperties === void 0 ? struct.rest ? ["readonly [key: string]: unknown"] : [] : [`readonly [key: string]: ${Array.join(Array.dedupe([
140
+ typeOf(struct.additionalProperties, encoded),
141
+ ...Array.map(struct.fields, (entry) => typeOf(entry.node, encoded)),
142
+ ...Array.some(struct.fields, (entry) => entry.optional) ? ["undefined"] : [],
143
+ ...Array.map(struct.spreads, (spread) => `${spread}[keyof ${spread}]`)
144
+ ]), " | ")}`]], "; ")}\n}`], " & "),
145
+ Union: (union) => Array.join(Array.map(union.members, (member) => typeOf(member, encoded)), " | ")
146
+ }), Match.orElse((primitive) => typeKeywords[primitive._tag]));
147
+ }
148
+ function holds(node, found) {
149
+ return found(node) || pipe(Match.value(node), Match.tags({
150
+ Array: (array) => holds(array.item, found),
151
+ NullOr: (nullable) => holds(nullable.node, found),
152
+ Record: (record) => holds(record.value, found),
153
+ Struct: (struct) => Array.some(struct.fields, (entry) => holds(entry.node, found)) || struct.additionalProperties !== void 0 && holds(struct.additionalProperties, found),
154
+ Union: (union) => Array.some(union.members, (member) => holds(member, found))
155
+ }), Match.orElse(() => false));
156
+ }
157
+ function referrers(declarations, found) {
158
+ const graph = Graph.directed((mutable) => {
159
+ const indices = HashMap.fromIterable(Array.map(declarations, (declaration) => [declaration.name, Graph.addNode(mutable, declaration)]));
160
+ for (const declaration of declarations) for (const target of targets(declaration.node)) Graph.addEdge(mutable, HashMap.getUnsafe(indices, declaration.name), HashMap.getUnsafe(indices, target), null);
161
+ });
162
+ const start = Graph.findNodes(graph, (declaration) => holds(declaration.node, found));
163
+ return HashSet.fromIterable(Array.map(Array.fromIterable(Graph.dfs(graph, {
164
+ direction: "incoming",
165
+ start
166
+ })), (entry) => entry[1].name));
167
+ }
168
+ /**
169
+ * Composite schemas carry a written type: an inferred schema type is spelled out structurally at
170
+ * every reference, which exceeds TypeScript's declaration size limit on large APIs.
171
+ */
172
+ function declarationSource(declaration, encoded) {
173
+ const name = declaration.name;
174
+ const value = `${expression(declaration.node, encoded)}${declaration.node._tag === "Ref" ? annotation("annotate", declaration.node.description) : ""}.annotate({ identifier: ${JSON.stringify(name)} })`;
175
+ return declaration.spread || declaration.node._tag === "Literals" || holds(declaration.node, (node) => node._tag === "File") ? `export type ${name} = typeof ${name}.Type;\nexport const ${name} = ${value};` : `export type ${name} = ${typeOf(declaration.node)};\n${HashSet.has(encoded, name) ? `export type ${name}$Encoded = ${typeOf(declaration.node, encoded)};\n` : ""}export const ${name}: ${codec(name, `${name}$Encoded`, encoded)} = ${value};`;
176
+ }
177
+ function uses(texts, namespace) {
178
+ const call = new RegExp(`(?<![\\w$.])${namespace}\\.[A-Za-z]`, "u");
179
+ return Array.some(texts, (text) => call.test(text));
180
+ }
181
+ function effectImport(texts) {
182
+ const names = [
183
+ ...uses(texts, "Array") ? ["Array"] : [],
184
+ ...Array.some(texts, String.includes("Effect.succeed(")) ? ["Effect"] : [],
185
+ ...uses(texts, "Record") ? ["Record"] : [],
186
+ ...uses(texts, "Schema") ? ["Schema"] : [],
187
+ ...Array.some(texts, (text) => /(?<![\w$.])pipe\(/u.test(text)) ? ["pipe"] : []
188
+ ];
189
+ return Array.isReadonlyArrayNonEmpty(names) ? [importLine(names, "effect")] : [];
190
+ }
191
+ /** The module export of an action's contract and call, `group_action`, in each version file. */
192
+ function exportName(id) {
193
+ const parts = pipe(id, String.split("/"));
194
+ return `${camelize(Array.getUnsafe(parts, 1))}_${camelize(Array.getUnsafe(parts, 2))}`;
195
+ }
196
+ function access(name) {
197
+ return key(name) === name ? `input.${name}` : `input[${key(name)}]`;
198
+ }
199
+ function urlParts(url, segments) {
200
+ return Array.join(Array.map(pipe(url, String.split(/('\{[^}]*\}'|\{[^}]*\})/u), Array.filter(String.isNonEmpty)), (part) => {
201
+ if (pipe(part, String.startsWith("'{"))) return `'\${Http.literal(${access(pipe(part, String.slice(2, -2)))})}'`;
202
+ if (!pipe(part, String.startsWith("{"))) return pipe(part, String.replaceAll("\\", "\\\\"), String.replaceAll("`", "\\`"));
203
+ const name = pipe(part, String.slice(1, -1));
204
+ return `\${Http.${Array.contains(segments, name) ? "segments" : "path"}(${access(name)})}`;
205
+ }), "");
206
+ }
207
+ function urlTemplate(url, segments = [], alias) {
208
+ const parts = pipe(url, String.split(alias?.prefix ?? "\0"));
209
+ const text = alias === void 0 ? urlParts(url, segments) : `${urlParts(Array.headNonEmpty(parts), segments)}\${${access(alias.parameter)} === undefined ? ${JSON.stringify(alias.replacement)} : \`${urlParts(alias.prefix, segments)}\`}${urlParts(Array.join(Array.tailNonEmpty(parts), alias.prefix), segments)}`;
210
+ return pipe(text, String.includes("${")) ? `\`${text}\`` : JSON.stringify(url);
211
+ }
212
+ function encodings(joined, deep, exploded = []) {
213
+ if (Array.isReadonlyArrayNonEmpty(exploded)) return `, ${JSON.stringify(joined)}, ${JSON.stringify(deep)}, ${JSON.stringify(exploded)}`;
214
+ if (Array.isReadonlyArrayNonEmpty(deep)) return `, ${JSON.stringify(joined)}, ${JSON.stringify(deep)}`;
215
+ return Array.isReadonlyArrayEmpty(joined) ? "" : `, ${JSON.stringify(joined)}`;
216
+ }
217
+ function params(names, joined, deep, exploded = []) {
218
+ return `Http.params({ ${Array.join(Array.map(names, (name) => `${key(name)}: ${access(name)}`), ", ")} }${encodings(Array.filter(joined, (entry) => Array.contains(names, Predicate.isString(entry) ? entry : entry[0])), Array.intersection(deep, names), Array.intersection(exploded, names))})`;
219
+ }
220
+ function bodyStep(contract, body) {
221
+ const content = JSON.stringify(body.contentType);
222
+ const joinedFields = Array.map(body.joined ?? [], (entry) => {
223
+ const name = Predicate.isString(entry) ? entry : entry[0];
224
+ const delimiter = Predicate.isString(entry) ? "," : entry[1];
225
+ const payloadAccess = `input.payload[${JSON.stringify(name)}]`;
226
+ return `${key(name)}: Array.isArray(${payloadAccess}) ? ${payloadAccess}.join(${JSON.stringify(delimiter)}) : ${payloadAccess}`;
227
+ });
228
+ const multipartPayload = Array.isReadonlyArrayEmpty(joinedFields) ? "input.payload" : `{ ...input.payload, ${Array.join(joinedFields, ", ")} }`;
229
+ const value = pipe(Match.value(body.encoding), Match.when("json", () => body.contentType === "application/json" ? "HttpClientRequest.bodyJsonUnsafe(input.payload)" : `HttpClientRequest.bodyText(JSON.stringify(input.payload), ${content})`), Match.when("text", () => `HttpClientRequest.bodyText(input.payload, ${content})`), Match.when("binary", () => `HttpClientRequest.bodyUint8Array(input.payload.contentBase64, input.payload.contentType ?? ${content})`), Match.when("form", () => `HttpClientRequest.bodyUrlParams(Http.params(input.payload${encodings(body.joined ?? [], body.deepObject ?? [])}))`), Match.orElse(() => `HttpClientRequest.bodyFormDataRecord(Http.form(${multipartPayload}))`));
230
+ const conditions = [...contract.bodies.length > 1 ? [defaultContentType(contract.bodies) === body.contentType ? `(input.contentType ?? ${content}) === ${content}` : `input.contentType === ${content}`] : [], ...body.required ? [] : ["input.payload !== undefined"]];
231
+ return Array.isReadonlyArrayEmpty(conditions) ? value : `(request: HttpClientRequest.HttpClientRequest) => ${Array.join(conditions, " && ")} ? ${value}(request) : request`;
232
+ }
233
+ function sentBy(contract, payload, call) {
234
+ const graphql = contract.graphql;
235
+ if (graphql !== void 0) return `Http.graphql(context, output, pipe(HttpClientRequest.post(${JSON.stringify(graphql.endpoint)}), HttpClientRequest.bodyJsonUnsafe({ query: ${JSON.stringify(graphql.document)}, variables: ${payload} })), ${JSON.stringify(graphql.field)})`;
236
+ const mcp = contract.mcp;
237
+ if (mcp === void 0) return call;
238
+ return `Http.mcp(context, output, ${JSON.stringify(mcp.endpoint)}, ${JSON.stringify(mcp.tool)}, ${payload === "{}" ? payload : `${payload} ?? {}`}, ${mcp.structured})`;
239
+ }
240
+ function operationSource(name, contract, encoded, decoded) {
241
+ const method = String.toLowerCase(contract.method);
242
+ const declared = `HttpClientRequest.${method}(${urlTemplate(contract.url, contract.pathSegments, contract.alias)})`;
243
+ const steps = [
244
+ ...Array.isReadonlyArrayEmpty(contract.query) ? [] : [`HttpClientRequest.setUrlParams(${params(contract.query, [...contract.commaSeparated, ...contract.delimited ?? []], contract.deepObject ?? [], contract.exploded ?? [])})`],
245
+ ...Array.isReadonlyArrayEmpty(contract.headers) ? [] : [`HttpClientRequest.setHeaders(${params(contract.headers, contract.commaSeparated, [])})`],
246
+ ...contract.googleUpload === void 0 ? Array.map(contract.bodies, (body) => bodyStep(contract, body)) : []
247
+ ];
248
+ const built = Array.isReadonlyArrayEmpty(steps) ? declared : `pipe(${declared}, ${Array.join(steps, ", ")})`;
249
+ const preauthenticated = `Http.preauthenticated(HttpClientRequest.${method}, input.uploadUrl${Array.isReadonlyArrayEmpty(steps) ? "" : `, ${Array.join(steps, ", ")}`})`;
250
+ const continued = contract.nextLink === true ? `Http.continuation(${built}, input.nextLink)` : built;
251
+ const request = contract.preauthenticatedUpload === true ? preauthenticated : continued;
252
+ const context = contract.preauthenticatedUpload === true ? "undefined" : "context";
253
+ const single = Array.getUnsafe(contract.responses, 0);
254
+ const upload = contract.googleUpload;
255
+ const variants = `Http.variants(${context}, output, ${request}, ${JSON.stringify(Array.map(contract.responses, (response) => ({
256
+ body: response.kind,
257
+ contentType: response.contentType,
258
+ ...response.headers === void 0 ? {} : { headers: response.headers },
259
+ .../^2\d\d$/u.test(response.status) ? { status: Number(response.status) } : {}
260
+ })))}${contract.googleDownload === true ? ", input.alt === \"media\"" : ""})`;
261
+ const plain = contract.responses.length === 1 && single.headers === void 0 ? `Http.execute(${context}, output, ${request}, ${JSON.stringify(single.kind)})` : variants;
262
+ const call = upload === void 0 ? plain : `Http.googleUpload(context, output, ${request}, input.payload, { ${Array.join([...upload.maxSize === void 0 ? [] : [`maxSize: ${Number(upload.maxSize)}`], ...upload.resumableUrl === void 0 ? [] : [`resumable: ${urlTemplate(upload.resumableUrl)}`]], ", ")} })`;
263
+ const sent = sentBy(contract, Array.isReadonlyArrayEmpty(contract.bodies) ? "{}" : "input.payload", call);
264
+ const reads = /\binput[.[]/u.test(sent);
265
+ const output = expression(contract.output, encoded);
266
+ return `export const ${name} = Http.endpoint({ input: ${expression(contract.input, encoded)}, output: ${holds(contract.output, (node) => converts(node) || node._tag === "Ref" && HashSet.has(decoded, node.target)) ? `Http.decoded(${output})` : output} }, (${reads ? "input" : "_input"}, ${context === "context" || contract.graphql !== void 0 || contract.mcp !== void 0 ? "context" : "_context"}, output) => ${sent});`;
267
+ }
268
+ /** A version file: the schemas and calls of the actions that changed in that version, never edited afterwards. */
269
+ function operationsSource(declarations, actions) {
270
+ const encoded = referrers(declarations, (node) => converts(node) || node._tag === "Struct" && Array.some(node.fields, (entry) => !entry.optional && entry.default !== void 0));
271
+ const decoded = referrers(declarations, converts);
272
+ const texts = [...Array.map(declarations, (declaration) => declarationSource(declaration, encoded)), ...Array.map(actions, (action) => operationSource(action.name, action.contract, encoded, decoded))];
273
+ return `// Generated by dual openapi-plugin; current contracts and handlers.\n${Array.join([Array.join([
274
+ ...effectImport(texts),
275
+ ...Array.some(texts, String.includes("HttpClientRequest.")) ? ["import { HttpClientRequest } from \"effect/http\";"] : [],
276
+ ...uses(texts, "ToolFile") ? [importLine(["ToolFile"], "@dual-os/sdk")] : [],
277
+ "import * as Http from \"./http.ts\";"
278
+ ], "\n"), ...texts], "\n\n")}\n`;
279
+ }
280
+ function pluginConstant(pluginId) {
281
+ return `${camelize(pluginId)}Plugin`;
282
+ }
283
+ function pluginBaseConstant(pluginId) {
284
+ return `${camelize(pluginId)}PluginBase`;
285
+ }
286
+ function groupConstant(group) {
287
+ return `${camelize(group)}Group`;
288
+ }
289
+ /** Current contracts and fluent implementations for one plugin. */
290
+ function pluginSource(options) {
291
+ const base = pluginBaseConstant(options.pluginId);
292
+ const definitions = Array.map(options.actions, (action) => {
293
+ const metadata = {
294
+ name: action.name,
295
+ ...Option.match(action.description, {
296
+ onNone: () => ({}),
297
+ onSome: (description) => ({ description })
298
+ })
299
+ };
300
+ return `const ${exportName(action.key)} = Action.make(${JSON.stringify(action.id)}, { ...Operations.${exportName(action.key)}, ...${JSON.stringify(metadata)} });`;
301
+ });
302
+ const groups = Array.map(options.provider.groups, (group) => `const ${groupConstant(group)} = Group.make(${JSON.stringify(group)}).pipe(Group.withName(${JSON.stringify(titleCase(group))}), Group.withActions([${Array.join(Array.map(Array.filter(options.actions, (action) => action.group === group), (action) => exportName(action.key)), ", ")}]));`);
303
+ const handlers = Array.join(Array.map(options.provider.groups, (group) => `.group(${JSON.stringify(group)}, handlers => handlers${Array.join(Array.map(Array.filter(options.actions, (action) => action.group === group), (action) => `.action(${JSON.stringify(action.id)}, Operations.${exportName(action.key)}.run)`), "")})`), "");
304
+ return `${Array.join([
305
+ "// Generated by dual openapi-plugin; rerun it instead of editing.",
306
+ "import { Action, Group, Plugin } from \"@dual-os/sdk\";",
307
+ "import { FetchHttpClient, HttpClient } from \"effect/http\";",
308
+ "import * as Auth from \"../auth.ts\";",
309
+ "import * as Triggers from \"../triggers.ts\";",
310
+ "import * as Operations from \"./operations.ts\";",
311
+ ...definitions,
312
+ ...groups,
313
+ `export const ${base}: Plugin.Definition<${JSON.stringify(options.pluginId)}, typeof Auth.authMethods, readonly [${Array.join(Array.map(options.provider.groups, (group) => `typeof ${groupConstant(group)}`), ", ")}], readonly [], typeof Triggers.triggers> = Plugin.make(${JSON.stringify(options.pluginId)}).pipe(${Array.join([
314
+ `Plugin.withName(${JSON.stringify(options.metadata["name"] ?? options.provider.name)})`,
315
+ ...Array.map(Record.toEntries({
316
+ ...options.provider.metadata,
317
+ ...Record.remove(options.metadata, "name")
318
+ }), ([key, value]) => `Plugin.with${String.capitalize(key)}(${JSON.stringify(value)})`),
319
+ "Plugin.withAuthMethods(Auth.authMethods)",
320
+ ...options.sandboxAccess ? ["Plugin.withSandboxAccess(Auth.sandboxAccess)"] : [],
321
+ `Plugin.withGroups([${Array.join(Array.map(options.provider.groups, groupConstant), ", ")}])`,
322
+ "Plugin.withTriggers(Triggers.triggers)"
323
+ ], ", ")});`,
324
+ `const live = Plugin.toLayer(${base}, handlers => handlers${handlers}.withTriggers(Triggers.handlers));`,
325
+ `export const ${pluginConstant(options.pluginId)}: Plugin.Provided<typeof ${base}, Plugin.HandlerServices<typeof ${base}> | HttpClient.HttpClient> = ${base}.pipe(Plugin.provide(live), Plugin.provide(FetchHttpClient.layer));`
326
+ ], "\n\n")}\n`;
327
+ }
328
+ /** The package's binding of the SDK's HTTP runtime to its auth methods. */
329
+ const httpSource = `// Generated by dual openapi-plugin; rerun it instead of editing.
330
+ import { Http } from "@dual-os/sdk";
331
+ import type { Action } from "@dual-os/sdk";
332
+
333
+ import * as Auth from "../auth.ts";
334
+
335
+ export {
336
+ Base64FromFile,
337
+ Base64UrlFromFile,
338
+ DataUriFromFile,
339
+ DateTimeFromRfc2822,
340
+ DateTimeFromUnixSeconds,
341
+ File,
342
+ FileFromBase64,
343
+ FileFromBase64Url,
344
+ FileFromDataUri,
345
+ Rfc2822FromDateTime,
346
+ UnixSecondsFromDateTime,
347
+ continuation,
348
+ decoded,
349
+ form,
350
+ literal,
351
+ params,
352
+ path,
353
+ preauthenticated,
354
+ segments,
355
+ } from "@dual-os/sdk/Http";
356
+
357
+ export type Handler<Input, Output> = Http.Handler<typeof Auth.authMethods, Input, Output>;
358
+
359
+ export interface Context extends Action.HandlerContext<typeof Auth.authMethods> {}
360
+
361
+ export const { endpoint, execute, googleUpload, graphql, mcp, variants } = Http.make<
362
+ typeof Auth.authMethods,
363
+ Context
364
+ >(Auth);
365
+
366
+ export * as Http from "./http.ts";
367
+ `;
368
+ const triggersSource = `${ownedHeader}
369
+ export const triggers = [] as const;
370
+ export const handlers = {};
371
+ `;
372
+ function authMethodConstant(scheme) {
373
+ return `${camelize(scheme.methodId)}Method`;
374
+ }
375
+ function derived(scheme) {
376
+ function declaration(constructor, entries) {
377
+ return `const ${authMethodConstant(scheme)} = ${constructor}(${JSON.stringify(scheme.methodId)}, { ${Array.join(entries, ",\n")} });`;
378
+ }
379
+ const description = scheme.description === void 0 ? [] : [`description: ${JSON.stringify(scheme.description)}`];
380
+ const name = `name: ${JSON.stringify(scheme.displayName)}`;
381
+ function credential(schema, request) {
382
+ return Option.some({
383
+ method: declaration("AuthMethod.make", [
384
+ ...description,
385
+ name,
386
+ `schema: Schema.Struct({ ${schema} })`
387
+ ]),
388
+ request
389
+ });
390
+ }
391
+ return pipe(Match.value(scheme.kind), Match.tag("HttpBearer", () => credential("token: Schema.String", "HttpClientRequest.bearerToken(binding.value.token)")), Match.tag("HttpBasic", () => credential("password: Schema.String, username: Schema.String", "HttpClientRequest.basicAuth(binding.value.username, binding.value.password)")), Match.tag("ApiKey", (kind) => credential("apiKey: Schema.String", `HttpClientRequest.${kind.in === "header" ? "setHeader" : "setUrlParam"}(${JSON.stringify(kind.key)}, binding.value.apiKey)`)), Match.tag("OAuth2", (kind) => Option.some({
392
+ method: Array.join([
393
+ ...kind.authorizationUrl === void 0 ? ["// TODO: the document declares no authorization URL; add `authorizationUrl`."] : [],
394
+ ...kind.tokenUrl === void 0 ? ["// TODO: the document declares no token URL; add `tokenUrl`."] : [],
395
+ declaration("AuthMethod.oauth2", [
396
+ ...kind.authorizationUrl === void 0 ? [] : [`authorizationUrl: ${JSON.stringify(kind.authorizationUrl)}`],
397
+ ...kind.resource === void 0 ? [] : [`authorizationParams: { resource: ${JSON.stringify(kind.resource)} }`],
398
+ kind.authentication === void 0 ? "// TODO: confirm the token endpoint authentication style; \"post\" is the default.\nclient: options => ({ authentication: \"post\", clientId: options.setup.clientId, clientSecret: options.setup.clientSecret })" : `client: options => ({ authentication: ${JSON.stringify(kind.authentication)}, clientId: options.setup.clientId, clientSecret: options.setup.clientSecret })`,
399
+ ...description,
400
+ kind.pkce === void 0 ? "// TODO: add `pkce: true` when this provider requires PKCE.\nmaterial: AuthMethod.OAuth2TokenMaterial" : "material: AuthMethod.OAuth2TokenMaterial",
401
+ name,
402
+ ...kind.pkce === true ? ["pkce: true"] : [],
403
+ `scopes: ${JSON.stringify(kind.scopes)}`,
404
+ "setup: Schema.Struct({ clientId: Schema.String, clientSecret: Schema.String })",
405
+ ...kind.tokenUrl === void 0 ? [] : [`tokenUrl: ${JSON.stringify(kind.tokenUrl)}`],
406
+ ...kind.resource === void 0 ? [] : [`tokenParams: { resource: ${JSON.stringify(kind.resource)} }`]
407
+ ])
408
+ ], "\n"),
409
+ request: "HttpClientRequest.bearerToken(binding.value.accessToken)"
410
+ })), Match.tag("Unsupported", () => Option.none()), Match.exhaustive);
411
+ }
412
+ function authSource(schemes) {
413
+ const supported = pipe(schemes, Array.filterMap((scheme) => Option.match(derived(scheme), {
414
+ onNone: () => Result.failVoid,
415
+ onSome: (parts) => Result.succeed({
416
+ ...parts,
417
+ scheme
418
+ })
419
+ })), Array.sort(Order.mapInput(Order.String, (entry) => entry.scheme.methodId)));
420
+ const notes = Array.flatMap(schemes, (scheme) => scheme.kind._tag === "Unsupported" ? [`// ${scheme.name} (${scheme.methodId}): ${scheme.kind.reason}`] : []);
421
+ const todo = Array.isReadonlyArrayNonEmpty(notes) ? [Array.join([
422
+ "// TODO: dual openapi-plugin derives no AuthMethod for these security schemes:",
423
+ ...notes,
424
+ "// Add an AuthMethod for each one this plugin needs, list it in `authMethods`,",
425
+ "// and give it a case in `authorize`."
426
+ ], "\n")] : [];
427
+ if (!Array.isReadonlyArrayNonEmpty(supported)) return `${ownedHeader}
428
+ import type { HttpClient } from "effect/http";
429
+
430
+ import type { Action } from "@dual-os/sdk";
431
+
432
+ ${Array.join(Array.isReadonlyArrayNonEmpty(todo) ? todo : ["// TODO: this OpenAPI document declares no security schemes. Add an AuthMethod here\n// and use it below when the API needs credentials."], "\n\n")}
433
+
434
+ export const authMethods = [] as const;
435
+
436
+ export function authorize(
437
+ client: HttpClient.HttpClient,
438
+ _context: Action.HandlerContext<typeof authMethods>,
439
+ ): HttpClient.HttpClient {
440
+ return client;
441
+ }
442
+
443
+ export * as Auth from "./auth.ts";
444
+ `;
445
+ const cases = Array.join(Array.map(supported, (entry) => `${key(entry.scheme.methodId)}: binding => HttpClient.mapRequest(client, ${entry.request})`), ", ");
446
+ return `${ownedHeader}
447
+ import { Match, Schema, pipe } from "effect";
448
+
449
+ import { HttpClient, HttpClientRequest } from "effect/http";
450
+
451
+ import { AuthMethod } from "@dual-os/sdk";
452
+ import type { Action } from "@dual-os/sdk";
453
+
454
+ ${Array.join([...todo, ...Array.map(supported, (entry) => entry.method)], "\n\n")}
455
+
456
+ export const authMethods = [${Array.join(Array.map(supported, (entry) => authMethodConstant(entry.scheme)), ", ")}] as const;
457
+
458
+ export function authorize(
459
+ client: HttpClient.HttpClient,
460
+ context: Action.HandlerContext<typeof authMethods>,
461
+ ): HttpClient.HttpClient {
462
+ return pipe(
463
+ Match.value(context.auth.current),
464
+ Match.discriminatorsExhaustive("methodId")({ ${cases} }),
465
+ );
466
+ }
467
+
468
+ export * as Auth from "./auth.ts";
469
+ `;
470
+ }
471
+ function packageName(naming) {
472
+ return naming.target === "internal" ? `@dual-os/${naming.pluginId}` : `${naming.packageScope}/${naming.pluginId}`;
473
+ }
474
+ function packageJsonSource(naming, sdkRange) {
475
+ const entry = "./dist/generated/plugin.js";
476
+ return JSON.stringify({
477
+ name: packageName(naming),
478
+ ...naming.target === "customer" ? { private: true } : {},
479
+ version: "0.0.0",
480
+ type: "module",
481
+ license: "UNLICENSED",
482
+ exports: {
483
+ ".": entry,
484
+ "./definition": entry,
485
+ "./executable": entry,
486
+ "./package.json": "./package.json",
487
+ "./plugin.json": "./plugin.json"
488
+ },
489
+ files: [
490
+ "dist/**",
491
+ "src/**/*.ts",
492
+ "!src/**/*.test.ts",
493
+ "LICENSE",
494
+ "plugin.json"
495
+ ],
496
+ scripts: naming.target === "internal" ? { prepack: "vp run build" } : {
497
+ build: "vp pack",
498
+ "check-types": "tsc --noEmit",
499
+ prepack: "vp pack"
500
+ },
501
+ dual: { plugin: {
502
+ assets: ["dist/**"],
503
+ entrypoint: "dist/generated/plugin.js",
504
+ export: pluginConstant(naming.pluginId)
505
+ } },
506
+ dependencies: {
507
+ "@dual-os/sdk": naming.target === "internal" ? "workspace:*" : sdkRange,
508
+ effect: versions.effect
509
+ },
510
+ devDependencies: {
511
+ typescript: versions.typescript,
512
+ ...naming.target === "customer" ? { "vite-plus": "1.3.0" } : {}
513
+ }
514
+ });
515
+ }
516
+ function pluginJsonSource(naming, openapi) {
517
+ return JSON.stringify({
518
+ exports: {
519
+ definition: {
520
+ export: pluginBaseConstant(naming.pluginId),
521
+ subpath: "./definition"
522
+ },
523
+ executable: {
524
+ export: pluginConstant(naming.pluginId),
525
+ subpath: "./executable"
526
+ }
527
+ },
528
+ identity: {
529
+ package: packageName(naming),
530
+ plugin: naming.pluginId
531
+ },
532
+ openapi,
533
+ schemaVersion: 1
534
+ });
535
+ }
536
+ function tsconfigSource() {
537
+ return JSON.stringify({
538
+ compilerOptions: {
539
+ target: "ESNext",
540
+ module: "ESNext",
541
+ moduleResolution: "Bundler",
542
+ strict: true,
543
+ skipLibCheck: true,
544
+ noEmit: true,
545
+ allowImportingTsExtensions: true,
546
+ exactOptionalPropertyTypes: true,
547
+ types: []
548
+ },
549
+ include: ["src", "test"]
550
+ });
551
+ }
552
+ function viteConfigSource(target) {
553
+ const pack = {
554
+ entry: [
555
+ "src/**/*.ts",
556
+ "!src/**/*.test.ts",
557
+ "!src/**/*.spec.ts"
558
+ ],
559
+ root: "src",
560
+ unbundle: true,
561
+ fixedExtension: false,
562
+ sourcemap: true,
563
+ dts: target === "internal" ? {
564
+ sourcemap: true,
565
+ tsgo: { path: "tsrs" }
566
+ } : { sourcemap: true }
567
+ };
568
+ return `import { defineConfig } from "vite-plus";\nexport default defineConfig(${JSON.stringify(target === "internal" ? {
569
+ pack,
570
+ run: { tasks: {
571
+ build: {
572
+ command: "vp pack -l error",
573
+ dependsOn: [{
574
+ task: "build",
575
+ from: ["dependencies", "devDependencies"]
576
+ }]
577
+ },
578
+ "check:generated": {
579
+ command: "tsrs -p tsconfig.json --checkerAssignment go",
580
+ dependsOn: [{
581
+ task: "build",
582
+ from: "devDependencies"
583
+ }],
584
+ cache: { output: [] }
585
+ }
586
+ } }
587
+ } : { pack }, null, 2)});\n`;
588
+ }
589
+ const licenseSource = `All rights reserved.
590
+
591
+ This package is proprietary and is not licensed for public use or redistribution.
592
+ Use and distribution require permission from the rights holder under a separate agreement.
593
+ `;
594
+ export { emit_exports as OpenApiEmit, Target, authSource, exportName, httpSource, licenseSource, operationsSource, packageJsonSource, pluginJsonSource, pluginSource, triggersSource, tsconfigSource, viteConfigSource };
595
+
596
+ //# sourceMappingURL=emit.js.map