@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.
- package/LICENSE +4 -0
- package/README.md +15 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/auth/credentials.d.ts +17 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +57 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/destination.d.ts +22 -0
- package/dist/auth/destination.d.ts.map +1 -0
- package/dist/auth/destination.js +49 -0
- package/dist/auth/destination.js.map +1 -0
- package/dist/auth/http.d.ts +12 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +34 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/login.d.ts +22 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +98 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/protocol.d.ts +26 -0
- package/dist/auth/protocol.d.ts.map +1 -0
- package/dist/auth/protocol.js +31 -0
- package/dist/auth/protocol.js.map +1 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +22 -0
- package/dist/baseline.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +492 -0
- package/dist/cli.js.map +1 -0
- package/dist/create/choices.d.ts +58 -0
- package/dist/create/choices.d.ts.map +1 -0
- package/dist/create/choices.js +121 -0
- package/dist/create/choices.js.map +1 -0
- package/dist/create/deployment.d.ts +48 -0
- package/dist/create/deployment.d.ts.map +1 -0
- package/dist/create/deployment.js +66 -0
- package/dist/create/deployment.js.map +1 -0
- package/dist/create/scaffold.d.ts +57 -0
- package/dist/create/scaffold.d.ts.map +1 -0
- package/dist/create/scaffold.js +198 -0
- package/dist/create/scaffold.js.map +1 -0
- package/dist/create/source-reference.d.ts +39 -0
- package/dist/create/source-reference.d.ts.map +1 -0
- package/dist/create/source-reference.js +185 -0
- package/dist/create/source-reference.js.map +1 -0
- package/dist/create/template.d.ts +116 -0
- package/dist/create/template.d.ts.map +1 -0
- package/dist/create/template.js +211 -0
- package/dist/create/template.js.map +1 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/help.d.ts +16 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +73 -0
- package/dist/help.js.map +1 -0
- package/dist/openapi/bundle.d.ts +18 -0
- package/dist/openapi/bundle.d.ts.map +1 -0
- package/dist/openapi/bundle.js +201 -0
- package/dist/openapi/bundle.js.map +1 -0
- package/dist/openapi/discovery.d.ts +30 -0
- package/dist/openapi/discovery.d.ts.map +1 -0
- package/dist/openapi/discovery.js +325 -0
- package/dist/openapi/discovery.js.map +1 -0
- package/dist/openapi/emit.d.ts +52 -0
- package/dist/openapi/emit.d.ts.map +1 -0
- package/dist/openapi/emit.js +596 -0
- package/dist/openapi/emit.js.map +1 -0
- package/dist/openapi/graphql.d.ts +102 -0
- package/dist/openapi/graphql.d.ts.map +1 -0
- package/dist/openapi/graphql.js +294 -0
- package/dist/openapi/graphql.js.map +1 -0
- package/dist/openapi/identity.d.ts +88 -0
- package/dist/openapi/identity.d.ts.map +1 -0
- package/dist/openapi/identity.js +98 -0
- package/dist/openapi/identity.js.map +1 -0
- package/dist/openapi/mcp.d.ts +21 -0
- package/dist/openapi/mcp.d.ts.map +1 -0
- package/dist/openapi/mcp.js +133 -0
- package/dist/openapi/mcp.js.map +1 -0
- package/dist/openapi/operations.d.ts +165 -0
- package/dist/openapi/operations.d.ts.map +1 -0
- package/dist/openapi/operations.js +361 -0
- package/dist/openapi/operations.js.map +1 -0
- package/dist/openapi/overlay.d.ts +23 -0
- package/dist/openapi/overlay.d.ts.map +1 -0
- package/dist/openapi/overlay.js +115 -0
- package/dist/openapi/overlay.js.map +1 -0
- package/dist/openapi/plugin.d.ts +83 -0
- package/dist/openapi/plugin.d.ts.map +1 -0
- package/dist/openapi/plugin.js +468 -0
- package/dist/openapi/plugin.js.map +1 -0
- package/dist/openapi/polymorphism.d.ts +21 -0
- package/dist/openapi/polymorphism.d.ts.map +1 -0
- package/dist/openapi/polymorphism.js +96 -0
- package/dist/openapi/polymorphism.js.map +1 -0
- package/dist/openapi/postman.d.ts +21 -0
- package/dist/openapi/postman.d.ts.map +1 -0
- package/dist/openapi/postman.js +286 -0
- package/dist/openapi/postman.js.map +1 -0
- package/dist/openapi/schema.d.ts +178 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +1234 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/select.d.ts +22 -0
- package/dist/openapi/select.d.ts.map +1 -0
- package/dist/openapi/select.js +79 -0
- package/dist/openapi/select.js.map +1 -0
- package/dist/openapi/spec.d.ts +147 -0
- package/dist/openapi/spec.d.ts.map +1 -0
- package/dist/openapi/spec.js +263 -0
- package/dist/openapi/spec.js.map +1 -0
- package/dist/openapi/swagger.d.ts +166 -0
- package/dist/openapi/swagger.d.ts.map +1 -0
- package/dist/openapi/swagger.js +298 -0
- package/dist/openapi/swagger.js.map +1 -0
- package/dist/openapi/versions.d.ts +52 -0
- package/dist/openapi/versions.d.ts.map +1 -0
- package/dist/openapi/versions.js +120 -0
- package/dist/openapi/versions.js.map +1 -0
- package/dist/plugin/archive.d.ts +27 -0
- package/dist/plugin/archive.d.ts.map +1 -0
- package/dist/plugin/archive.js +170 -0
- package/dist/plugin/archive.js.map +1 -0
- package/dist/plugin/bundle.d.ts +27 -0
- package/dist/plugin/bundle.d.ts.map +1 -0
- package/dist/plugin/bundle.js +328 -0
- package/dist/plugin/bundle.js.map +1 -0
- package/dist/plugin/init.d.ts +18 -0
- package/dist/plugin/init.d.ts.map +1 -0
- package/dist/plugin/init.js +121 -0
- package/dist/plugin/init.js.map +1 -0
- package/dist/plugin/inspection.d.ts +24 -0
- package/dist/plugin/inspection.d.ts.map +1 -0
- package/dist/plugin/inspection.js +24 -0
- package/dist/plugin/inspection.js.map +1 -0
- package/dist/plugin/package.d.ts +26 -0
- package/dist/plugin/package.d.ts.map +1 -0
- package/dist/plugin/package.js +73 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/publication.d.ts +29 -0
- package/dist/plugin/publication.d.ts.map +1 -0
- package/dist/plugin/publication.js +65 -0
- package/dist/plugin/publication.js.map +1 -0
- package/dist/plugin/validation.d.ts +15 -0
- package/dist/plugin/validation.d.ts.map +1 -0
- package/dist/plugin/validation.js +119 -0
- package/dist/plugin/validation.js.map +1 -0
- package/dist/release/archives.d.ts +33 -0
- package/dist/release/archives.d.ts.map +1 -0
- package/dist/release/archives.js +81 -0
- package/dist/release/archives.js.map +1 -0
- package/dist/release/release-manifest.d.ts +182 -0
- package/dist/release/release-manifest.d.ts.map +1 -0
- package/dist/release/release-manifest.js +79 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/releases.d.ts +36 -0
- package/dist/release/releases.d.ts.map +1 -0
- package/dist/release/releases.js +122 -0
- package/dist/release/releases.js.map +1 -0
- package/dist/skills.d.ts +35 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +257 -0
- package/dist/skills.js.map +1 -0
- package/package.json +73 -4
- package/skills/dual-fde/SKILL.md +38 -0
- package/skills/dual-fde/references/access.md +62 -0
- package/skills/dual-fde/references/author-plugins.md +54 -0
- package/skills/dual-fde/references/cli.md +97 -0
- package/skills/dual-fde/references/manage-plugins.md +78 -0
- package/skills/dual-fde/references/migrations-deployment.md +84 -0
- package/skills/dual-fde/references/openapi-plugins.md +47 -0
- package/skills/dual-fde/references/sdk-docs.md +56 -0
- package/skills/dual-fde/references/upgrades.md +115 -0
- package/skills/dual-fde/references/working-context.md +69 -0
- package/src/auth/credentials.ts +84 -0
- package/src/auth/destination.ts +83 -0
- package/src/auth/http.ts +39 -0
- package/src/auth/login.ts +177 -0
- package/src/auth/protocol.ts +37 -0
- package/src/baseline.ts +15 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +969 -0
- package/src/create/choices.ts +177 -0
- package/src/create/deployment.ts +96 -0
- package/src/create/scaffold.ts +334 -0
- package/src/create/source-reference.ts +212 -0
- package/src/create/template.ts +300 -0
- package/src/diagnostics.ts +8 -0
- package/src/help.ts +142 -0
- package/src/openapi/bundle.ts +290 -0
- package/src/openapi/discovery.ts +438 -0
- package/src/openapi/emit.ts +1031 -0
- package/src/openapi/graphql.ts +375 -0
- package/src/openapi/identity.ts +153 -0
- package/src/openapi/mcp.ts +165 -0
- package/src/openapi/operations.ts +781 -0
- package/src/openapi/overlay.ts +195 -0
- package/src/openapi/plugin.ts +856 -0
- package/src/openapi/polymorphism.ts +207 -0
- package/src/openapi/postman.ts +403 -0
- package/src/openapi/schema.ts +2138 -0
- package/src/openapi/select.ts +113 -0
- package/src/openapi/spec.ts +401 -0
- package/src/openapi/swagger.ts +422 -0
- package/src/openapi/versions.ts +174 -0
- package/src/plugin/archive.ts +244 -0
- package/src/plugin/bundle.ts +572 -0
- package/src/plugin/init.ts +178 -0
- package/src/plugin/inspection.ts +19 -0
- package/src/plugin/package.ts +140 -0
- package/src/plugin/publication.ts +128 -0
- package/src/plugin/validation.ts +213 -0
- package/src/release/archives.ts +133 -0
- package/src/release/release-manifest.ts +79 -0
- package/src/release/releases.ts +210 -0
- package/src/skills.ts +434 -0
- package/templates/compose/.env.compose.example.hbs +3 -0
- package/templates/compose/.env.host.example.hbs +4 -0
- package/templates/compose/Dockerfile.hbs +12 -0
- package/templates/compose/OPERATIONS.md.hbs +159 -0
- package/templates/compose/_dockerignore +14 -0
- package/templates/compose/compose.external.yaml +7 -0
- package/templates/compose/compose.host-linux.yaml +5 -0
- package/templates/compose/compose.host.yaml.hbs +15 -0
- package/templates/compose/compose.yaml.hbs +85 -0
- package/templates/compose/release.env.hbs +2 -0
- package/templates/default/.env.example.hbs +79 -0
- package/templates/default/README.md.hbs +150 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
- package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
- package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
- package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
- package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
- package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
- package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
- package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
- package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
- package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
- package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
- package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
- package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/vitest.config.ts +5 -0
- package/templates/default/vitest.host.config.ts +6 -0
- package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
- package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import "./plugin.js";
|
|
2
|
+
import { Context, Effect, FileSystem, Layer, Path, Schema } from "effect";
|
|
3
|
+
import { HttpClient } from "effect/http";
|
|
4
|
+
declare namespace plugin_d_exports {
|
|
5
|
+
export { Interface, plugin_d_exports as OpenApiPlugin, OpenApiPluginError, PackageScope, PluginJson, Request, Service, SourceKind, defaultLayer };
|
|
6
|
+
}
|
|
7
|
+
declare const OpenApiPluginError_base: Schema.Class<OpenApiPluginError, Schema.TaggedStruct<"OpenApiPluginError", {
|
|
8
|
+
readonly cause: Schema.optional<Schema.Defect>;
|
|
9
|
+
readonly message: Schema.String;
|
|
10
|
+
}>, import("effect/Cause").YieldableError>;
|
|
11
|
+
export declare class OpenApiPluginError extends OpenApiPluginError_base {}
|
|
12
|
+
export type PackageScope = typeof PackageScope.Type;
|
|
13
|
+
export declare const PackageScope: Schema.String;
|
|
14
|
+
/** How a spec's source is read: a description document, a GraphQL schema or endpoint, or an MCP server. */
|
|
15
|
+
export type SourceKind = typeof SourceKind.Type;
|
|
16
|
+
export declare const SourceKind: Schema.Literals<readonly ["document", "graphql", "mcp"]>;
|
|
17
|
+
export type PluginJson = typeof PluginJson.Type;
|
|
18
|
+
export declare const PluginJson: Schema.Struct<{
|
|
19
|
+
readonly openapi: Schema.Struct<{
|
|
20
|
+
readonly identityMappings: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
21
|
+
readonly metadata: Schema.optionalKey<Schema.Struct<{
|
|
22
|
+
readonly description: Schema.optionalKey<Schema.NonEmptyString>;
|
|
23
|
+
readonly name: Schema.optionalKey<Schema.NonEmptyString>;
|
|
24
|
+
}>>;
|
|
25
|
+
readonly packageScope: Schema.optional<Schema.String>;
|
|
26
|
+
readonly provider: Schema.Struct<{
|
|
27
|
+
readonly metadata: Schema.optionalKey<Schema.Struct<{
|
|
28
|
+
readonly categories: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
|
|
29
|
+
readonly description: Schema.optionalKey<Schema.NonEmptyString>;
|
|
30
|
+
readonly docsUrl: Schema.optionalKey<Schema.NonEmptyString>;
|
|
31
|
+
readonly homepageUrl: Schema.optionalKey<Schema.NonEmptyString>;
|
|
32
|
+
readonly iconUrl: Schema.optionalKey<Schema.NonEmptyString>;
|
|
33
|
+
}>>;
|
|
34
|
+
readonly name: Schema.NonEmptyString;
|
|
35
|
+
readonly oauth: Schema.optionalKey<Schema.Struct<{
|
|
36
|
+
readonly authentication: Schema.optionalKey<Schema.Literals<readonly ["basic", "none", "post"]>>;
|
|
37
|
+
readonly authorizationUrl: Schema.String;
|
|
38
|
+
readonly pkce: Schema.optionalKey<Schema.Boolean>;
|
|
39
|
+
readonly resource: Schema.optionalKey<Schema.String>;
|
|
40
|
+
readonly scopes: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
|
|
41
|
+
readonly tokenUrl: Schema.String;
|
|
42
|
+
}>>;
|
|
43
|
+
readonly specs: Schema.NonEmptyArray<Schema.Struct<{
|
|
44
|
+
readonly aliases: Schema.optionalKey<Schema.$Record<Schema.String, Schema.String>>;
|
|
45
|
+
readonly endpoint: Schema.optionalKey<Schema.String>;
|
|
46
|
+
readonly exclude: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
|
|
47
|
+
readonly include: Schema.optionalKey<Schema.Union<readonly [Schema.$Array<Schema.NonEmptyString>, Schema.$Record<Schema.String, Schema.$Array<Schema.NonEmptyString>>]>>;
|
|
48
|
+
readonly kind: Schema.Literals<readonly ["document", "graphql", "mcp"]>;
|
|
49
|
+
readonly name: Schema.optionalKey<Schema.String>;
|
|
50
|
+
readonly overlay: Schema.optionalKey<Schema.NonEmptyString>;
|
|
51
|
+
readonly source: Schema.NonEmptyString;
|
|
52
|
+
readonly sourceUrl: Schema.optionalKey<Schema.String>;
|
|
53
|
+
}>>;
|
|
54
|
+
}>;
|
|
55
|
+
readonly target: Schema.Literals<readonly ["internal", "customer"]>;
|
|
56
|
+
}>;
|
|
57
|
+
}>;
|
|
58
|
+
export type Request = typeof Request.Type;
|
|
59
|
+
export declare const Request: Schema.Struct<{
|
|
60
|
+
readonly destination: Schema.NonEmptyString;
|
|
61
|
+
readonly kind: Schema.Literals<readonly ["document", "graphql", "mcp"]>;
|
|
62
|
+
readonly packageScope: Schema.optional<Schema.String>;
|
|
63
|
+
readonly spec: Schema.NonEmptyString;
|
|
64
|
+
readonly target: Schema.Literals<readonly ["internal", "customer"]>;
|
|
65
|
+
}>;
|
|
66
|
+
interface Summary {
|
|
67
|
+
added: string[];
|
|
68
|
+
changed: string[];
|
|
69
|
+
excluded: string[];
|
|
70
|
+
generated: number;
|
|
71
|
+
kept: string[];
|
|
72
|
+
vanished: string[];
|
|
73
|
+
widened: string[];
|
|
74
|
+
}
|
|
75
|
+
export interface Interface {
|
|
76
|
+
readonly create: (request: Request) => Effect.Effect<Summary, OpenApiPluginError>;
|
|
77
|
+
readonly generate: (directory: string) => Effect.Effect<Summary, OpenApiPluginError>;
|
|
78
|
+
}
|
|
79
|
+
declare const Service_base: Context.ServiceClass<Service, "@dual-os/cli/openapi/plugin/Service", Interface>;
|
|
80
|
+
export declare class Service extends Service_base {}
|
|
81
|
+
export declare const defaultLayer: Layer.Layer<Service, never, FileSystem.FileSystem | HttpClient.HttpClient | Path.Path>;
|
|
82
|
+
export { plugin_d_exports as OpenApiPlugin };
|
|
83
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","names":[],"sources":["../../src/openapi/plugin.ts"],"mappings":";;;;;;;;;;qBAuCa,2BAA2B;YAK5B,sBAAsB,aAAa;qBAClC,cAAY,OAAA;;YA4Bb,oBAAoB,WAAW;qBAC9B,YAAU,OAAA;YAyDX,oBAAoB,WAAW;qBAC9B,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAEX,iBAAiB,QAAQ;qBACxB,SAAO,OAAA;;;;;;;UAQV;EACR;EACA;EACA;EACA;EACA;EACA;EACA;;iBAmDe;WACN,SAAS,SAAS,YAAY,OAAO,OAAO,SAAS;WACrD,WAAW,sBAAsB,OAAO,OAAO,SAAS;;;qBAGtD,gBAAgB;qBAIhB,cAAY,MAAA,MAAA,gBAAA,WAAA,aAAA,WAAA,aAAA,KAAA"}
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { introspectionQuery } from "./graphql.js";
|
|
3
|
+
import { JsonObject, declaresOAuth, document, expand, parse, parseGraphql, parseMcp, parseYaml, securitySchemes, titleCase } from "./spec.js";
|
|
4
|
+
import { bundle } from "./bundle.js";
|
|
5
|
+
import { catalog, namedEnums } from "./schema.js";
|
|
6
|
+
import { Target, authSource, exportName, httpSource, licenseSource, operationsSource, packageJsonSource, pluginJsonSource, pluginSource, triggersSource, tsconfigSource, viteConfigSource } from "./emit.js";
|
|
7
|
+
import { resolve } from "./identity.js";
|
|
8
|
+
import { walk, withReadableGroupIds, withUniqueActionIds } from "./operations.js";
|
|
9
|
+
import { Overlay, applyOverlay } from "./overlay.js";
|
|
10
|
+
import { select } from "./select.js";
|
|
11
|
+
import { LockFile, decodeLock, hashes } from "./versions.js";
|
|
12
|
+
import "./plugin.js";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { Array, Boolean, Context, Effect, FileSystem, HashMap, HashSet, Layer, Option, Order, Path, Predicate, Record, Result, Schema, String, Struct, pipe } from "effect";
|
|
15
|
+
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
16
|
+
import * as Oxfmt from "vite-plus/fmt";
|
|
17
|
+
import { Mcp } from "@dual-os/sdk/Mcp";
|
|
18
|
+
// src/openapi/plugin.ts
|
|
19
|
+
var plugin_exports = /* @__PURE__ */ __exportAll({
|
|
20
|
+
OpenApiPlugin: () => plugin_exports,
|
|
21
|
+
OpenApiPluginError: () => OpenApiPluginError,
|
|
22
|
+
PackageScope: () => PackageScope,
|
|
23
|
+
PluginJson: () => PluginJson,
|
|
24
|
+
Request: () => Request,
|
|
25
|
+
Service: () => Service,
|
|
26
|
+
SourceKind: () => SourceKind,
|
|
27
|
+
defaultLayer: () => defaultLayer
|
|
28
|
+
});
|
|
29
|
+
var OpenApiPluginError = class extends Schema.TaggedError()("OpenApiPluginError", {
|
|
30
|
+
cause: Schema.optional(Schema.Defect()),
|
|
31
|
+
message: Schema.String
|
|
32
|
+
}) {};
|
|
33
|
+
const PackageScope = Schema.String.check(Schema.isPattern(/^@[a-z0-9-~][a-z0-9-._~]*$/u, { message: "A package scope looks like @example" }));
|
|
34
|
+
const PluginId = Schema.String.check(Schema.isPattern(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u, { message: "A plugin id is kebab-case and starts with a letter" }));
|
|
35
|
+
const HttpUrl = Schema.String.check(Schema.makeFilter((value) => Option.exists(Schema.decodeOption(Schema.URLFromString)(value), (url) => (url.protocol === "http:" || url.protocol === "https:") && String.isNonEmpty(url.hostname)), { message: "A URL is an absolute http or https URL with a host" }));
|
|
36
|
+
const SourceKind = Schema.Literals([
|
|
37
|
+
"document",
|
|
38
|
+
"graphql",
|
|
39
|
+
"mcp"
|
|
40
|
+
]);
|
|
41
|
+
const OAuth = Schema.Struct({
|
|
42
|
+
authentication: Schema.optionalKey(Schema.Literals([
|
|
43
|
+
"basic",
|
|
44
|
+
"none",
|
|
45
|
+
"post"
|
|
46
|
+
])),
|
|
47
|
+
authorizationUrl: HttpUrl,
|
|
48
|
+
pkce: Schema.optionalKey(Schema.Boolean),
|
|
49
|
+
resource: Schema.optionalKey(HttpUrl),
|
|
50
|
+
scopes: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
|
|
51
|
+
tokenUrl: HttpUrl
|
|
52
|
+
});
|
|
53
|
+
const Spec = Schema.Struct({
|
|
54
|
+
aliases: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
55
|
+
endpoint: Schema.optionalKey(HttpUrl),
|
|
56
|
+
exclude: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
|
|
57
|
+
include: Schema.optionalKey(Schema.Union([Schema.Array(Schema.NonEmptyString), Schema.Record(PluginId, Schema.Array(Schema.NonEmptyString))])),
|
|
58
|
+
kind: SourceKind,
|
|
59
|
+
name: Schema.optionalKey(PluginId),
|
|
60
|
+
overlay: Schema.optionalKey(Schema.NonEmptyString),
|
|
61
|
+
source: Schema.NonEmptyString,
|
|
62
|
+
sourceUrl: Schema.optionalKey(HttpUrl)
|
|
63
|
+
});
|
|
64
|
+
const Inputs = Schema.Struct({
|
|
65
|
+
identityMappings: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
66
|
+
metadata: Schema.optionalKey(Schema.Struct({
|
|
67
|
+
description: Schema.optionalKey(Schema.NonEmptyString),
|
|
68
|
+
name: Schema.optionalKey(Schema.NonEmptyString)
|
|
69
|
+
})),
|
|
70
|
+
packageScope: Schema.optional(PackageScope),
|
|
71
|
+
provider: Schema.Struct({
|
|
72
|
+
metadata: Schema.optionalKey(Schema.Struct({
|
|
73
|
+
categories: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
|
|
74
|
+
description: Schema.optionalKey(Schema.NonEmptyString),
|
|
75
|
+
docsUrl: Schema.optionalKey(Schema.NonEmptyString),
|
|
76
|
+
homepageUrl: Schema.optionalKey(Schema.NonEmptyString),
|
|
77
|
+
iconUrl: Schema.optionalKey(Schema.NonEmptyString)
|
|
78
|
+
})),
|
|
79
|
+
name: Schema.NonEmptyString,
|
|
80
|
+
oauth: Schema.optionalKey(OAuth),
|
|
81
|
+
specs: Schema.NonEmptyArray(Spec)
|
|
82
|
+
}),
|
|
83
|
+
target: Target
|
|
84
|
+
});
|
|
85
|
+
const PluginJson = Schema.Struct({ openapi: Inputs });
|
|
86
|
+
const Request = Schema.Struct({
|
|
87
|
+
destination: Schema.NonEmptyString,
|
|
88
|
+
kind: SourceKind,
|
|
89
|
+
packageScope: Schema.optional(PackageScope),
|
|
90
|
+
spec: Schema.NonEmptyString,
|
|
91
|
+
target: Target
|
|
92
|
+
});
|
|
93
|
+
const inputsFile = "plugin.json";
|
|
94
|
+
function failure(message) {
|
|
95
|
+
return Effect.mapError((cause) => OpenApiPluginError.make({
|
|
96
|
+
cause,
|
|
97
|
+
message
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
function inSource(source) {
|
|
101
|
+
return Effect.mapError((message) => OpenApiPluginError.make({ message: `${source}: ${message}` }));
|
|
102
|
+
}
|
|
103
|
+
function specUrlOf(spec) {
|
|
104
|
+
if (!URL.canParse(spec)) return;
|
|
105
|
+
const url = new URL(spec);
|
|
106
|
+
return /^https?:$/u.test(url.protocol) ? url : void 0;
|
|
107
|
+
}
|
|
108
|
+
function sourceName(entry) {
|
|
109
|
+
return Option.getOrElse(entry.name, () => "api");
|
|
110
|
+
}
|
|
111
|
+
function keyOf(action) {
|
|
112
|
+
return Array.join([
|
|
113
|
+
action.provider,
|
|
114
|
+
action.operation.groupId,
|
|
115
|
+
action.operation.actionId
|
|
116
|
+
], "/");
|
|
117
|
+
}
|
|
118
|
+
function format(name, text, options) {
|
|
119
|
+
return Effect.map(Effect.tryPromise({
|
|
120
|
+
catch: (cause) => OpenApiPluginError.make({
|
|
121
|
+
cause,
|
|
122
|
+
message: `Could not format ${name}`
|
|
123
|
+
}),
|
|
124
|
+
try: () => Oxfmt.format(name, text, options)
|
|
125
|
+
}), (formatted) => formatted.code);
|
|
126
|
+
}
|
|
127
|
+
var Service = class extends Context.Service()("@dual-os/cli/openapi/plugin/Service") {};
|
|
128
|
+
const defaultLayer = Layer.effect(Service, Effect.gen(function* () {
|
|
129
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
130
|
+
const path = yield* Path.Path;
|
|
131
|
+
const http = yield* HttpClient.HttpClient;
|
|
132
|
+
const client = HttpClient.filterStatusOk(http);
|
|
133
|
+
const read = Effect.fnUntraced(function* (location, base) {
|
|
134
|
+
const url = specUrlOf(location);
|
|
135
|
+
if (url === void 0) {
|
|
136
|
+
const source = path.resolve(base, location);
|
|
137
|
+
return {
|
|
138
|
+
source,
|
|
139
|
+
text: yield* pipe(fileSystem.readFileString(source), failure(`Could not read ${source}`))
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
source: url.href,
|
|
144
|
+
text: yield* pipe(client.get(url.href), Effect.flatMap((response) => response.text), Effect.timeout("60 seconds"), failure(`Could not fetch ${url.href}`))
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
const readText = Effect.fnUntraced(function* (location) {
|
|
148
|
+
return (yield* read(location, "")).text;
|
|
149
|
+
}, Effect.mapError((error) => error.message));
|
|
150
|
+
function parse$1(found) {
|
|
151
|
+
return parse(found.text, (document) => bundle(document, found.source, {
|
|
152
|
+
path,
|
|
153
|
+
read: readText
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
const load = Effect.fnUntraced(function* (spec, base) {
|
|
157
|
+
const endpoint = specUrlOf(spec.source);
|
|
158
|
+
const origin = specUrlOf(spec.sourceUrl ?? spec.source);
|
|
159
|
+
if (spec.kind === "document") {
|
|
160
|
+
const found = yield* read(spec.source, base);
|
|
161
|
+
const raw = yield* pipe(parse$1(found), failure(`${found.source} is not an OpenAPI 3.0/3.1, Swagger 2.0, Google Discovery or Postman collection document`));
|
|
162
|
+
return origin === void 0 ? { raw } : {
|
|
163
|
+
raw,
|
|
164
|
+
specUrl: origin
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (spec.kind === "graphql" && spec.endpoint !== void 0) {
|
|
168
|
+
const found = yield* read(spec.source, base);
|
|
169
|
+
return { raw: yield* pipe(parseGraphql(found.text, spec.endpoint), failure(`${found.source} is not a GraphQL introspection result or schema in SDL`)) };
|
|
170
|
+
}
|
|
171
|
+
if (endpoint === void 0) return yield* OpenApiPluginError.make({ message: `${spec.source}: a ${spec.kind} source without an endpoint is the URL of a ${spec.kind === "graphql" ? "GraphQL endpoint" : "Model Context Protocol server"}` });
|
|
172
|
+
if (spec.kind === "graphql") return { raw: yield* pipe(client.execute(pipe(HttpClientRequest.post(endpoint.href), HttpClientRequest.bodyJsonUnsafe({ query: introspectionQuery }))), Effect.flatMap((response) => response.text), Effect.flatMap((text) => parseGraphql(text, endpoint.href)), failure(`${endpoint.href} did not answer a GraphQL introspection query`)) };
|
|
173
|
+
return { raw: yield* pipe(Mcp.listTools(client, endpoint.href, {}), Effect.map((found) => parseMcp(found.server, found.tools, endpoint.href)), failure(`${endpoint.href} did not list Model Context Protocol tools`)) };
|
|
174
|
+
});
|
|
175
|
+
const overlay = Effect.fnUntraced(function* (entry, raw, destination) {
|
|
176
|
+
if (entry.overlay === void 0) return raw;
|
|
177
|
+
const found = yield* read(entry.overlay, destination);
|
|
178
|
+
const document = yield* pipe(parseYaml(found.text), Effect.flatMap(Schema.decodeUnknownEffect(Overlay)), failure(`${found.source} is not an OpenAPI Overlay 1.x document`));
|
|
179
|
+
return yield* pipe(applyOverlay(raw, document), Effect.fromResult, Effect.flatMap(Schema.decodeUnknownEffect(JsonObject)), Effect.mapError((cause) => OpenApiPluginError.make({
|
|
180
|
+
cause,
|
|
181
|
+
message: `${entry.overlay}: ${Predicate.isString(cause) ? cause : "the overlaid document is not an object"}`
|
|
182
|
+
})));
|
|
183
|
+
});
|
|
184
|
+
const prepare = Effect.fnUntraced(function* (entry, loaded, destination) {
|
|
185
|
+
const expanded = yield* pipe(expand(yield* overlay(entry, loaded.raw, destination)), Effect.fromResult, inSource(entry.source));
|
|
186
|
+
const include = entry.include;
|
|
187
|
+
const sections = include === void 0 || Schema.is(Schema.Array(Schema.String))(include) ? [{
|
|
188
|
+
include,
|
|
189
|
+
name: Option.fromNullishOr(entry.name)
|
|
190
|
+
}] : Record.collect(include, (name, patterns) => ({
|
|
191
|
+
include: patterns,
|
|
192
|
+
name: Option.some(name)
|
|
193
|
+
}));
|
|
194
|
+
return yield* Effect.forEach(sections, (section) => Effect.gen(function* () {
|
|
195
|
+
const selected = yield* pipe(select(expanded, {
|
|
196
|
+
...pipe(entry, Struct.pick(["aliases", "exclude"])),
|
|
197
|
+
...section.include === void 0 ? {} : { include: section.include }
|
|
198
|
+
}), Effect.fromResult, inSource(entry.source));
|
|
199
|
+
const spec = yield* pipe(document(selected), failure(`${entry.source} is not a valid OpenAPI 3.x document after its overlay and selection`));
|
|
200
|
+
return {
|
|
201
|
+
name: section.name,
|
|
202
|
+
source: entry.source,
|
|
203
|
+
spec,
|
|
204
|
+
specUrl: loaded.specUrl,
|
|
205
|
+
walk: walk(loaded.specUrl === void 0 ? { spec } : {
|
|
206
|
+
spec,
|
|
207
|
+
specUrl: loaded.specUrl
|
|
208
|
+
})
|
|
209
|
+
};
|
|
210
|
+
}));
|
|
211
|
+
});
|
|
212
|
+
const write = Effect.fnUntraced(function* (destination, files) {
|
|
213
|
+
const formatted = yield* Effect.forEach(files, (file) => Effect.map(format(file.path, file.text, Boolean.match(pipe(file.path, String.endsWith(".json")), {
|
|
214
|
+
onFalse: () => ({
|
|
215
|
+
arrowParens: "avoid",
|
|
216
|
+
objectWrap: "preserve"
|
|
217
|
+
}),
|
|
218
|
+
onTrue: () => ({
|
|
219
|
+
arrowParens: "avoid",
|
|
220
|
+
objectWrap: "collapse",
|
|
221
|
+
sortPackageJson: { sortScripts: true }
|
|
222
|
+
})
|
|
223
|
+
})), (text) => ({
|
|
224
|
+
path: file.path,
|
|
225
|
+
text
|
|
226
|
+
})), { concurrency: 16 });
|
|
227
|
+
yield* pipe(Effect.forEach(Array.dedupe(Array.map(files, (file) => path.dirname(path.join(destination, file.path)))), (directory) => fileSystem.makeDirectory(directory, { recursive: true }), { discard: true }), Effect.andThen(Effect.forEach(formatted, (file) => fileSystem.writeFileString(path.join(destination, file.path), file.text), {
|
|
228
|
+
concurrency: 16,
|
|
229
|
+
discard: true
|
|
230
|
+
})), failure("Could not write the generated plugin package"));
|
|
231
|
+
});
|
|
232
|
+
const readPrevious = Effect.fnUntraced(function* (file) {
|
|
233
|
+
if (!(yield* fileSystem.exists(file))) return "";
|
|
234
|
+
return yield* fileSystem.readFileString(file);
|
|
235
|
+
}, failure("Could not read the generated plugin package"));
|
|
236
|
+
const readLock = Effect.fnUntraced(function* (file) {
|
|
237
|
+
if (!(yield* fileSystem.exists(file))) return {
|
|
238
|
+
actions: {},
|
|
239
|
+
identities: {}
|
|
240
|
+
};
|
|
241
|
+
return yield* decodeLock(yield* fileSystem.readFileString(file));
|
|
242
|
+
}, failure("Could not read src/generated/lock.json"));
|
|
243
|
+
const generatePackage = Effect.fnUntraced(function* (destination, config, loaded) {
|
|
244
|
+
const inputs = config.openapi;
|
|
245
|
+
const pluginId = yield* pipe(Schema.decodeEffect(PluginId)(path.basename(destination)), failure(`The package directory name ${path.basename(destination)} is the plugin id and must be kebab-case`));
|
|
246
|
+
const naming = {
|
|
247
|
+
packageScope: inputs.packageScope ?? "@customer",
|
|
248
|
+
pluginId,
|
|
249
|
+
target: inputs.target
|
|
250
|
+
};
|
|
251
|
+
const recorded = yield* readLock(path.join(destination, "src/generated/lock.json"));
|
|
252
|
+
if (yield* pipe(fileSystem.exists(path.join(destination, "src/adapters.ts")), failure("Could not inspect legacy adapters"))) return yield* OpenApiPluginError.make({ message: "Port auth.ts and triggers.ts to current SDK handlers, then remove src/adapters.ts before regenerating; keep historical code in its released artifact" });
|
|
253
|
+
const documents = Array.flatten(yield* Effect.forEach(inputs.provider.specs, (entry) => prepare(entry, HashMap.getUnsafe(loaded, entry.source), destination)));
|
|
254
|
+
const names = Array.map(documents, sourceName);
|
|
255
|
+
if (Array.dedupe(names).length !== names.length) return yield* OpenApiPluginError.make({ message: `Provider ${pluginId} must give its source documents and include sets distinct, stable names` });
|
|
256
|
+
const indexed = Array.map(documents, (entry, index) => ({
|
|
257
|
+
...entry,
|
|
258
|
+
index
|
|
259
|
+
}));
|
|
260
|
+
const owners = Array.reduce(indexed, HashMap.empty(), (found, entry) => Array.reduce(entry.walk.operations, found, (owned, operation) => {
|
|
261
|
+
const claim = `${entry.source} ${operation.method} ${operation.path}`;
|
|
262
|
+
return HashMap.has(owned, claim) ? owned : HashMap.set(owned, claim, entry.index);
|
|
263
|
+
}));
|
|
264
|
+
const walked = Array.flatten(Array.zipWith(indexed, withReadableGroupIds(Array.map(indexed, (entry) => ({
|
|
265
|
+
name: entry.name,
|
|
266
|
+
operations: Array.filter(entry.walk.operations, (operation) => Option.contains(HashMap.get(owners, `${entry.source} ${operation.method} ${operation.path}`), entry.index)),
|
|
267
|
+
title: entry.spec.document.info.title
|
|
268
|
+
}))), (entry, operations) => Array.map(operations, (operation) => ({
|
|
269
|
+
document: entry.index,
|
|
270
|
+
operation,
|
|
271
|
+
source: sourceName(entry)
|
|
272
|
+
}))));
|
|
273
|
+
const candidates = Array.zipWith(walked, withUniqueActionIds(Array.map(walked, (entry) => entry.operation)), (entry, operation) => ({
|
|
274
|
+
...entry,
|
|
275
|
+
operation: {
|
|
276
|
+
...operation,
|
|
277
|
+
actionName: documents.length > 1 && entry.source !== "api" ? `${titleCase(entry.source)} — ${operation.actionName}` : operation.actionName
|
|
278
|
+
},
|
|
279
|
+
provider: pluginId
|
|
280
|
+
}));
|
|
281
|
+
const identified = yield* pipe(resolve(candidates, recorded.identities, inputs.identityMappings ?? {}), Effect.fromResult, Effect.mapError((message) => OpenApiPluginError.make({ message })));
|
|
282
|
+
const specs = Array.map(documents, (entry) => entry.spec);
|
|
283
|
+
const actions = Array.filter(identified.actions, (action) => !action.operation.deprecated || Record.has(recorded.actions, keyOf(action)));
|
|
284
|
+
const checked = catalog(specs, actions);
|
|
285
|
+
const excluded = Array.flatMap(documents, (entry) => Array.map(entry.walk.skipped, (skipped) => `${sourceName(entry)} ${String.toUpperCase(skipped.operation?.method ?? "")} ${skipped.path}: ${skipped.reason}`));
|
|
286
|
+
const widened = Array.filterMap(Array.zip(actions, checked.unsupported), (pair) => Array.isReadonlyArrayNonEmpty(pair[1]) ? Result.succeed(`${keyOf(pair[0])} (${String.toUpperCase(pair[0].operation.method)} ${pair[0].operation.path}): ${Array.join(Array.map(Array.take(pair[1], 3), (unsupported) => `${unsupported.pointer} ${unsupported.reason}`), "; ")}`) : Result.failVoid);
|
|
287
|
+
if (Array.isReadonlyArrayEmpty(actions)) return yield* OpenApiPluginError.make({ message: `The documents contain no supported operations for this provider${Array.isReadonlyArrayEmpty(excluded) ? "" : `:\n${Array.join(excluded, "\n")}`}` });
|
|
288
|
+
const kept = HashSet.fromIterable(Array.map(actions, keyOf));
|
|
289
|
+
const ledger = Record.filter(identified.ledger, (_, id) => Record.has(recorded.identities, id) || HashSet.has(kept, id));
|
|
290
|
+
const current = HashMap.fromIterable(Array.zipWith(actions, hashes(checked), (action, hash) => [keyOf(action), hash]));
|
|
291
|
+
const unlisted = pipe(Record.keys(recorded.actions), Array.map((key) => pipe(key, String.split("/"), Array.headNonEmpty)), Array.dedupe, Array.filter((id) => id !== pluginId));
|
|
292
|
+
if (Array.isReadonlyArrayNonEmpty(unlisted)) return yield* OpenApiPluginError.make({ message: `lock.json records actions of ${Array.join(unlisted, ", ")}, but the package directory is ${pluginId}; restore its name to retain those actions` });
|
|
293
|
+
const added = Array.filter(Array.fromIterable(HashMap.keys(current)), (key) => !Record.has(recorded.actions, key));
|
|
294
|
+
const changed = Array.filter(Array.fromIterable(HashMap.keys(current)), (key) => Record.has(recorded.actions, key) && recorded.actions[key]?.hash !== HashMap.getUnsafe(current, key));
|
|
295
|
+
const vanished = Array.filter(Record.keys(recorded.actions), (key) => !HashMap.has(current, key));
|
|
296
|
+
const exported = Array.groupBy(Array.fromIterable(HashMap.keys(current)), exportName);
|
|
297
|
+
for (const keys of Record.values(exported)) if (keys.length > 1) return yield* OpenApiPluginError.make({ message: `Actions ${Array.join(keys, " and ")} share a module name; use identityMappings to give them distinct ids` });
|
|
298
|
+
const generatedDirectory = path.join(destination, "src/generated");
|
|
299
|
+
const named = namedEnums(checked, actions);
|
|
300
|
+
const planned = Array.map(actions, (action) => ({
|
|
301
|
+
action,
|
|
302
|
+
group: action.operation.groupId,
|
|
303
|
+
id: action.operation.actionId,
|
|
304
|
+
key: keyOf(action)
|
|
305
|
+
}));
|
|
306
|
+
const spec = Array.getUnsafe(documents, 0).spec;
|
|
307
|
+
const provider = {
|
|
308
|
+
groups: Array.dedupe(Array.map(planned, (entry) => entry.group)),
|
|
309
|
+
metadata: {
|
|
310
|
+
...Record.getSomes({
|
|
311
|
+
description: pipe(Option.fromNullishOr(spec.document.info.description), Option.map((description) => pipe(description, String.replace(/\s+/gu, " "), String.trim)), Option.filter(String.isNonEmpty)),
|
|
312
|
+
docsUrl: Option.map(Schema.decodeUnknownOption(Schema.Struct({ externalDocs: Schema.Struct({ url: Schema.NonEmptyString }) }))(spec.raw), (found) => found.externalDocs.url)
|
|
313
|
+
}),
|
|
314
|
+
...inputs.provider.metadata
|
|
315
|
+
},
|
|
316
|
+
name: inputs.provider.name
|
|
317
|
+
};
|
|
318
|
+
const auth = yield* readPrevious(path.join(destination, "src/auth.ts"));
|
|
319
|
+
const generated = [
|
|
320
|
+
{
|
|
321
|
+
path: "src/generated/operations.ts",
|
|
322
|
+
text: operationsSource(named.declarations, Array.zipWith(actions, named.contracts, (action, contract) => ({
|
|
323
|
+
contract,
|
|
324
|
+
name: exportName(keyOf(action))
|
|
325
|
+
})))
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
path: "src/generated/plugin.ts",
|
|
329
|
+
text: pluginSource({
|
|
330
|
+
actions: Array.map(planned, (entry) => ({
|
|
331
|
+
description: entry.action.operation.description,
|
|
332
|
+
group: entry.group,
|
|
333
|
+
id: entry.id,
|
|
334
|
+
key: entry.key,
|
|
335
|
+
name: entry.action.operation.actionName
|
|
336
|
+
})),
|
|
337
|
+
metadata: inputs.metadata ?? {},
|
|
338
|
+
pluginId,
|
|
339
|
+
provider,
|
|
340
|
+
sandboxAccess: /\bexport\s+const\s+sandboxAccess\b/u.test(auth)
|
|
341
|
+
})
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
path: "src/generated/http.ts",
|
|
345
|
+
text: httpSource
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
path: "src/generated/lock.json",
|
|
349
|
+
text: yield* pipe(Schema.encodeEffect(LockFile)({
|
|
350
|
+
actions: Record.fromEntries(Array.map(Array.sortWith(Array.fromIterable(current), ([key]) => key, Order.String), ([key, hash]) => [key, { hash }])),
|
|
351
|
+
identities: ledger
|
|
352
|
+
}), failure("Could not encode the action identity ledger"))
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
path: inputsFile,
|
|
356
|
+
text: pluginJsonSource(naming, inputs)
|
|
357
|
+
}
|
|
358
|
+
];
|
|
359
|
+
const declared = pipe(documents, Array.flatMap((entry) => securitySchemes(entry.spec, entry.specUrl)), Array.dedupeWith((left, right) => left.methodId === right.methodId));
|
|
360
|
+
const oauth = inputs.provider.oauth;
|
|
361
|
+
if (oauth !== void 0 && Array.some(documents, (entry) => declaresOAuth(entry.spec))) return yield* OpenApiPluginError.make({ message: "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" });
|
|
362
|
+
const schemes = oauth === void 0 ? declared : [...declared, {
|
|
363
|
+
description: void 0,
|
|
364
|
+
displayName: "OAuth",
|
|
365
|
+
kind: {
|
|
366
|
+
_tag: "OAuth2",
|
|
367
|
+
...oauth,
|
|
368
|
+
scopes: Array.sort(oauth.scopes ?? [], Order.String)
|
|
369
|
+
},
|
|
370
|
+
methodId: "oauth",
|
|
371
|
+
name: "oauth"
|
|
372
|
+
}];
|
|
373
|
+
const owned = [
|
|
374
|
+
{
|
|
375
|
+
path: "src/auth.ts",
|
|
376
|
+
text: Effect.succeed(authSource(schemes))
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
path: "src/triggers.ts",
|
|
380
|
+
text: Effect.succeed(triggersSource)
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
path: "package.json",
|
|
384
|
+
text: inputs.target === "internal" ? pipe(Effect.try(() => createRequire(path.join(destination, "package.json")).resolve("@dual-os/sdk/package.json")), Effect.flatMap(fileSystem.readFileString), Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(Schema.Struct({ version: Schema.NonEmptyString })))), Effect.map((sdk) => packageJsonSource(naming, `^${sdk.version}`)), failure("Could not read the @dual-os/sdk version the package builds on")) : Effect.succeed(packageJsonSource(naming, "*"))
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
path: "tsconfig.json",
|
|
388
|
+
text: Effect.succeed(tsconfigSource())
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
path: "vite.config.ts",
|
|
392
|
+
text: Effect.succeed(viteConfigSource(inputs.target))
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
path: "LICENSE",
|
|
396
|
+
text: Effect.succeed(licenseSource)
|
|
397
|
+
}
|
|
398
|
+
];
|
|
399
|
+
const existing = yield* pipe(Effect.forEach(owned, (file) => Effect.map(fileSystem.exists(path.join(destination, file.path)), (exists) => ({
|
|
400
|
+
exists,
|
|
401
|
+
file
|
|
402
|
+
})), { concurrency: 16 }), failure("Could not read the generated plugin package"));
|
|
403
|
+
const absent = Array.filter(existing, (status) => !status.exists);
|
|
404
|
+
yield* write(destination, [...generated, ...yield* Effect.forEach(absent, (status) => Effect.map(status.file.text, (text) => ({
|
|
405
|
+
path: status.file.path,
|
|
406
|
+
text
|
|
407
|
+
})))]);
|
|
408
|
+
yield* pipe(fileSystem.readDirectory(generatedDirectory), Effect.flatMap((files) => Effect.forEach(Array.filter(files, (file) => !Array.contains([
|
|
409
|
+
"plugin.ts",
|
|
410
|
+
"operations.ts",
|
|
411
|
+
"http.ts",
|
|
412
|
+
"lock.json"
|
|
413
|
+
], file)), (file) => fileSystem.remove(path.join(generatedDirectory, file), { recursive: true }), { discard: true })), failure("Could not delete superseded generated modules"));
|
|
414
|
+
return {
|
|
415
|
+
added,
|
|
416
|
+
changed,
|
|
417
|
+
excluded,
|
|
418
|
+
generated: actions.length,
|
|
419
|
+
kept: Array.filterMap(existing, (status) => status.exists ? Result.succeed(status.file.path) : Result.failVoid),
|
|
420
|
+
vanished,
|
|
421
|
+
widened
|
|
422
|
+
};
|
|
423
|
+
});
|
|
424
|
+
return {
|
|
425
|
+
create: Effect.fn("OpenApiPlugin.create")(function* (request) {
|
|
426
|
+
const destination = path.resolve(request.destination);
|
|
427
|
+
const file = path.join(destination, inputsFile);
|
|
428
|
+
if (yield* pipe(fileSystem.exists(file), failure("Could not read the plugin package"))) return yield* OpenApiPluginError.make({ message: `${file} exists; edit it and run dual openapi-plugin ${request.destination} to regenerate the package` });
|
|
429
|
+
const url = specUrlOf(request.spec);
|
|
430
|
+
const spec = url === void 0 ? path.relative(destination, path.resolve(request.spec)) : url.href;
|
|
431
|
+
const loaded = yield* load({
|
|
432
|
+
kind: request.kind,
|
|
433
|
+
source: spec
|
|
434
|
+
}, destination);
|
|
435
|
+
const title = Schema.decodeUnknownOption(Schema.Struct({ info: Schema.Struct({ title: Schema.NonEmptyString }) }))(loaded.raw);
|
|
436
|
+
return yield* generatePackage(destination, { openapi: {
|
|
437
|
+
packageScope: request.packageScope,
|
|
438
|
+
provider: {
|
|
439
|
+
name: Option.match(title, {
|
|
440
|
+
onNone: () => titleCase(path.basename(destination)),
|
|
441
|
+
onSome: (found) => found.info.title
|
|
442
|
+
}),
|
|
443
|
+
specs: [{
|
|
444
|
+
kind: request.kind,
|
|
445
|
+
source: spec
|
|
446
|
+
}]
|
|
447
|
+
},
|
|
448
|
+
target: request.target
|
|
449
|
+
} }, HashMap.make([spec, loaded]));
|
|
450
|
+
}),
|
|
451
|
+
generate: Effect.fn("OpenApiPlugin.generate")(function* (directory) {
|
|
452
|
+
const destination = path.resolve(directory);
|
|
453
|
+
const file = path.join(destination, inputsFile);
|
|
454
|
+
const config = yield* pipe(fileSystem.readFileString(file), Effect.flatMap(Schema.decodeEffect(Schema.fromJsonString(PluginJson))), Effect.mapError((cause) => OpenApiPluginError.make({
|
|
455
|
+
cause,
|
|
456
|
+
message: `${file}: ${cause.message}`
|
|
457
|
+
})));
|
|
458
|
+
const conflicting = Array.findFirst(config.openapi.provider.specs, (spec) => Array.some(config.openapi.provider.specs, (other) => other.source === spec.source && (other.kind !== spec.kind || other.endpoint !== spec.endpoint || other.sourceUrl !== spec.sourceUrl)));
|
|
459
|
+
const repeated = Option.getOrUndefined(conflicting);
|
|
460
|
+
if (repeated !== void 0) return yield* OpenApiPluginError.make({ message: `${file}: more than one spec loads the same source with different settings: ${repeated.source}` });
|
|
461
|
+
const loaded = yield* Effect.forEach(Array.dedupeWith(config.openapi.provider.specs, (left, right) => left.source === right.source), (spec) => Effect.map(load(spec, destination), (found) => [spec.source, found]));
|
|
462
|
+
return yield* generatePackage(destination, config, HashMap.fromIterable(loaded));
|
|
463
|
+
})
|
|
464
|
+
};
|
|
465
|
+
}));
|
|
466
|
+
export { plugin_exports as OpenApiPlugin, OpenApiPluginError, PackageScope, PluginJson, Request, Service, SourceKind, defaultLayer };
|
|
467
|
+
|
|
468
|
+
//# sourceMappingURL=plugin.js.map
|