@dual-os/cli 0.0.0-stage → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +15 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/auth/credentials.d.ts +17 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +57 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/destination.d.ts +22 -0
- package/dist/auth/destination.d.ts.map +1 -0
- package/dist/auth/destination.js +49 -0
- package/dist/auth/destination.js.map +1 -0
- package/dist/auth/http.d.ts +12 -0
- package/dist/auth/http.d.ts.map +1 -0
- package/dist/auth/http.js +34 -0
- package/dist/auth/http.js.map +1 -0
- package/dist/auth/login.d.ts +22 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +98 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/protocol.d.ts +26 -0
- package/dist/auth/protocol.d.ts.map +1 -0
- package/dist/auth/protocol.js +31 -0
- package/dist/auth/protocol.js.map +1 -0
- package/dist/baseline.d.ts +18 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +22 -0
- package/dist/baseline.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +7 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +19 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +492 -0
- package/dist/cli.js.map +1 -0
- package/dist/create/choices.d.ts +58 -0
- package/dist/create/choices.d.ts.map +1 -0
- package/dist/create/choices.js +121 -0
- package/dist/create/choices.js.map +1 -0
- package/dist/create/deployment.d.ts +48 -0
- package/dist/create/deployment.d.ts.map +1 -0
- package/dist/create/deployment.js +66 -0
- package/dist/create/deployment.js.map +1 -0
- package/dist/create/scaffold.d.ts +57 -0
- package/dist/create/scaffold.d.ts.map +1 -0
- package/dist/create/scaffold.js +198 -0
- package/dist/create/scaffold.js.map +1 -0
- package/dist/create/source-reference.d.ts +39 -0
- package/dist/create/source-reference.d.ts.map +1 -0
- package/dist/create/source-reference.js +185 -0
- package/dist/create/source-reference.js.map +1 -0
- package/dist/create/template.d.ts +116 -0
- package/dist/create/template.d.ts.map +1 -0
- package/dist/create/template.js +211 -0
- package/dist/create/template.js.map +1 -0
- package/dist/diagnostics.d.ts +6 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +18 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/help.d.ts +16 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +73 -0
- package/dist/help.js.map +1 -0
- package/dist/openapi/bundle.d.ts +18 -0
- package/dist/openapi/bundle.d.ts.map +1 -0
- package/dist/openapi/bundle.js +201 -0
- package/dist/openapi/bundle.js.map +1 -0
- package/dist/openapi/discovery.d.ts +30 -0
- package/dist/openapi/discovery.d.ts.map +1 -0
- package/dist/openapi/discovery.js +325 -0
- package/dist/openapi/discovery.js.map +1 -0
- package/dist/openapi/emit.d.ts +52 -0
- package/dist/openapi/emit.d.ts.map +1 -0
- package/dist/openapi/emit.js +596 -0
- package/dist/openapi/emit.js.map +1 -0
- package/dist/openapi/graphql.d.ts +102 -0
- package/dist/openapi/graphql.d.ts.map +1 -0
- package/dist/openapi/graphql.js +294 -0
- package/dist/openapi/graphql.js.map +1 -0
- package/dist/openapi/identity.d.ts +88 -0
- package/dist/openapi/identity.d.ts.map +1 -0
- package/dist/openapi/identity.js +98 -0
- package/dist/openapi/identity.js.map +1 -0
- package/dist/openapi/mcp.d.ts +21 -0
- package/dist/openapi/mcp.d.ts.map +1 -0
- package/dist/openapi/mcp.js +133 -0
- package/dist/openapi/mcp.js.map +1 -0
- package/dist/openapi/operations.d.ts +165 -0
- package/dist/openapi/operations.d.ts.map +1 -0
- package/dist/openapi/operations.js +361 -0
- package/dist/openapi/operations.js.map +1 -0
- package/dist/openapi/overlay.d.ts +23 -0
- package/dist/openapi/overlay.d.ts.map +1 -0
- package/dist/openapi/overlay.js +115 -0
- package/dist/openapi/overlay.js.map +1 -0
- package/dist/openapi/plugin.d.ts +83 -0
- package/dist/openapi/plugin.d.ts.map +1 -0
- package/dist/openapi/plugin.js +468 -0
- package/dist/openapi/plugin.js.map +1 -0
- package/dist/openapi/polymorphism.d.ts +21 -0
- package/dist/openapi/polymorphism.d.ts.map +1 -0
- package/dist/openapi/polymorphism.js +96 -0
- package/dist/openapi/polymorphism.js.map +1 -0
- package/dist/openapi/postman.d.ts +21 -0
- package/dist/openapi/postman.d.ts.map +1 -0
- package/dist/openapi/postman.js +286 -0
- package/dist/openapi/postman.js.map +1 -0
- package/dist/openapi/schema.d.ts +178 -0
- package/dist/openapi/schema.d.ts.map +1 -0
- package/dist/openapi/schema.js +1234 -0
- package/dist/openapi/schema.js.map +1 -0
- package/dist/openapi/select.d.ts +22 -0
- package/dist/openapi/select.d.ts.map +1 -0
- package/dist/openapi/select.js +79 -0
- package/dist/openapi/select.js.map +1 -0
- package/dist/openapi/spec.d.ts +147 -0
- package/dist/openapi/spec.d.ts.map +1 -0
- package/dist/openapi/spec.js +263 -0
- package/dist/openapi/spec.js.map +1 -0
- package/dist/openapi/swagger.d.ts +166 -0
- package/dist/openapi/swagger.d.ts.map +1 -0
- package/dist/openapi/swagger.js +298 -0
- package/dist/openapi/swagger.js.map +1 -0
- package/dist/openapi/versions.d.ts +52 -0
- package/dist/openapi/versions.d.ts.map +1 -0
- package/dist/openapi/versions.js +120 -0
- package/dist/openapi/versions.js.map +1 -0
- package/dist/plugin/archive.d.ts +27 -0
- package/dist/plugin/archive.d.ts.map +1 -0
- package/dist/plugin/archive.js +170 -0
- package/dist/plugin/archive.js.map +1 -0
- package/dist/plugin/bundle.d.ts +27 -0
- package/dist/plugin/bundle.d.ts.map +1 -0
- package/dist/plugin/bundle.js +328 -0
- package/dist/plugin/bundle.js.map +1 -0
- package/dist/plugin/init.d.ts +18 -0
- package/dist/plugin/init.d.ts.map +1 -0
- package/dist/plugin/init.js +121 -0
- package/dist/plugin/init.js.map +1 -0
- package/dist/plugin/inspection.d.ts +24 -0
- package/dist/plugin/inspection.d.ts.map +1 -0
- package/dist/plugin/inspection.js +24 -0
- package/dist/plugin/inspection.js.map +1 -0
- package/dist/plugin/package.d.ts +26 -0
- package/dist/plugin/package.d.ts.map +1 -0
- package/dist/plugin/package.js +73 -0
- package/dist/plugin/package.js.map +1 -0
- package/dist/plugin/publication.d.ts +29 -0
- package/dist/plugin/publication.d.ts.map +1 -0
- package/dist/plugin/publication.js +65 -0
- package/dist/plugin/publication.js.map +1 -0
- package/dist/plugin/validation.d.ts +15 -0
- package/dist/plugin/validation.d.ts.map +1 -0
- package/dist/plugin/validation.js +119 -0
- package/dist/plugin/validation.js.map +1 -0
- package/dist/release/archives.d.ts +33 -0
- package/dist/release/archives.d.ts.map +1 -0
- package/dist/release/archives.js +81 -0
- package/dist/release/archives.js.map +1 -0
- package/dist/release/release-manifest.d.ts +182 -0
- package/dist/release/release-manifest.d.ts.map +1 -0
- package/dist/release/release-manifest.js +79 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/releases.d.ts +36 -0
- package/dist/release/releases.d.ts.map +1 -0
- package/dist/release/releases.js +122 -0
- package/dist/release/releases.js.map +1 -0
- package/dist/skills.d.ts +35 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +257 -0
- package/dist/skills.js.map +1 -0
- package/package.json +73 -4
- package/skills/dual-fde/SKILL.md +38 -0
- package/skills/dual-fde/references/access.md +62 -0
- package/skills/dual-fde/references/author-plugins.md +54 -0
- package/skills/dual-fde/references/cli.md +97 -0
- package/skills/dual-fde/references/manage-plugins.md +78 -0
- package/skills/dual-fde/references/migrations-deployment.md +84 -0
- package/skills/dual-fde/references/openapi-plugins.md +47 -0
- package/skills/dual-fde/references/sdk-docs.md +56 -0
- package/skills/dual-fde/references/upgrades.md +115 -0
- package/skills/dual-fde/references/working-context.md +69 -0
- package/src/auth/credentials.ts +84 -0
- package/src/auth/destination.ts +83 -0
- package/src/auth/http.ts +39 -0
- package/src/auth/login.ts +177 -0
- package/src/auth/protocol.ts +37 -0
- package/src/baseline.ts +15 -0
- package/src/bin.ts +4 -0
- package/src/cli.ts +969 -0
- package/src/create/choices.ts +177 -0
- package/src/create/deployment.ts +96 -0
- package/src/create/scaffold.ts +334 -0
- package/src/create/source-reference.ts +212 -0
- package/src/create/template.ts +300 -0
- package/src/diagnostics.ts +8 -0
- package/src/help.ts +142 -0
- package/src/openapi/bundle.ts +290 -0
- package/src/openapi/discovery.ts +438 -0
- package/src/openapi/emit.ts +1031 -0
- package/src/openapi/graphql.ts +375 -0
- package/src/openapi/identity.ts +153 -0
- package/src/openapi/mcp.ts +165 -0
- package/src/openapi/operations.ts +781 -0
- package/src/openapi/overlay.ts +195 -0
- package/src/openapi/plugin.ts +856 -0
- package/src/openapi/polymorphism.ts +207 -0
- package/src/openapi/postman.ts +403 -0
- package/src/openapi/schema.ts +2138 -0
- package/src/openapi/select.ts +113 -0
- package/src/openapi/spec.ts +401 -0
- package/src/openapi/swagger.ts +422 -0
- package/src/openapi/versions.ts +174 -0
- package/src/plugin/archive.ts +244 -0
- package/src/plugin/bundle.ts +572 -0
- package/src/plugin/init.ts +178 -0
- package/src/plugin/inspection.ts +19 -0
- package/src/plugin/package.ts +140 -0
- package/src/plugin/publication.ts +128 -0
- package/src/plugin/validation.ts +213 -0
- package/src/release/archives.ts +133 -0
- package/src/release/release-manifest.ts +79 -0
- package/src/release/releases.ts +210 -0
- package/src/skills.ts +434 -0
- package/templates/compose/.env.compose.example.hbs +3 -0
- package/templates/compose/.env.host.example.hbs +4 -0
- package/templates/compose/Dockerfile.hbs +12 -0
- package/templates/compose/OPERATIONS.md.hbs +159 -0
- package/templates/compose/_dockerignore +14 -0
- package/templates/compose/compose.external.yaml +7 -0
- package/templates/compose/compose.host-linux.yaml +5 -0
- package/templates/compose/compose.host.yaml.hbs +15 -0
- package/templates/compose/compose.yaml.hbs +85 -0
- package/templates/compose/release.env.hbs +2 -0
- package/templates/default/.env.example.hbs +79 -0
- package/templates/default/README.md.hbs +150 -0
- package/templates/default/_gitignore +11 -0
- package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
- package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
- package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
- package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
- package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
- package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
- package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
- package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
- package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
- package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
- package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
- package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
- package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/vitest.config.ts +5 -0
- package/templates/default/vitest.host.config.ts +6 -0
- package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
- package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array,
|
|
3
|
+
Effect,
|
|
4
|
+
HashMap,
|
|
5
|
+
HashSet,
|
|
6
|
+
Option,
|
|
7
|
+
Predicate,
|
|
8
|
+
Record,
|
|
9
|
+
Ref,
|
|
10
|
+
Schema,
|
|
11
|
+
String,
|
|
12
|
+
pipe,
|
|
13
|
+
} from "effect";
|
|
14
|
+
import type { Path } from "effect";
|
|
15
|
+
|
|
16
|
+
import { OpenApiSpec } from "./spec.ts";
|
|
17
|
+
|
|
18
|
+
export class OpenApiBundleError extends Schema.TaggedError<OpenApiBundleError>()(
|
|
19
|
+
"OpenApiBundleError",
|
|
20
|
+
{ message: Schema.String },
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
export type Io = { path: Path.Path; read: (location: string) => Effect.Effect<string, string> };
|
|
24
|
+
|
|
25
|
+
type State = {
|
|
26
|
+
documents: HashMap.HashMap<string, OpenApiSpec.JsonObject>;
|
|
27
|
+
hoisted: OpenApiSpec.JsonObject;
|
|
28
|
+
names: HashMap.HashMap<string, string>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type Position = { base: string; inSchema: boolean; inlining: string[]; keysAreNames: boolean };
|
|
32
|
+
|
|
33
|
+
type Target = { location: string; pointer: string };
|
|
34
|
+
|
|
35
|
+
const dataKeywords = ["const", "default", "enum", "example", "examples"];
|
|
36
|
+
|
|
37
|
+
const schemaMaps = ["$defs", "definitions", "schemas"];
|
|
38
|
+
|
|
39
|
+
const nameMaps = [
|
|
40
|
+
...schemaMaps,
|
|
41
|
+
"callbacks",
|
|
42
|
+
"encoding",
|
|
43
|
+
"headers",
|
|
44
|
+
"links",
|
|
45
|
+
"parameters",
|
|
46
|
+
"patternProperties",
|
|
47
|
+
"properties",
|
|
48
|
+
"requestBodies",
|
|
49
|
+
"responses",
|
|
50
|
+
"securitySchemes",
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
function unique(name: string, taken: HashSet.HashSet<string>, attempt = 1): string {
|
|
54
|
+
const candidate = attempt === 1 ? name : `${name}${attempt}`;
|
|
55
|
+
return HashSet.has(taken, candidate) ? unique(name, taken, attempt + 1) : candidate;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const bundle = Effect.fn("OpenApiBundle.bundle")(function* (
|
|
59
|
+
root: OpenApiSpec.JsonObject,
|
|
60
|
+
location: string,
|
|
61
|
+
io: Io,
|
|
62
|
+
) {
|
|
63
|
+
const swagger = root["swagger"] !== undefined;
|
|
64
|
+
const schemaPointer = swagger ? "/definitions" : "/components/schemas";
|
|
65
|
+
const own = HashSet.fromIterable(
|
|
66
|
+
Record.keys(
|
|
67
|
+
OpenApiSpec.asObject(
|
|
68
|
+
swagger ? root["definitions"] : OpenApiSpec.asObject(root["components"])?.["schemas"],
|
|
69
|
+
) ?? {},
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
const state = yield* Ref.make<State>({
|
|
73
|
+
documents: HashMap.empty(),
|
|
74
|
+
hoisted: {},
|
|
75
|
+
names: HashMap.empty(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function local(name: string) {
|
|
79
|
+
return `#${schemaPointer}/${OpenApiSpec.pointerToken(name)}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function join(from: string, reference: string) {
|
|
83
|
+
if (URL.canParse(from)) return new URL(reference, from).href;
|
|
84
|
+
if (URL.canParse(reference)) return reference;
|
|
85
|
+
return io.path.resolve(io.path.dirname(from), reference);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function targetOf(reference: string, base: string): Target {
|
|
89
|
+
const parts = pipe(reference, String.split("#"));
|
|
90
|
+
const file = Array.headNonEmpty(parts);
|
|
91
|
+
return {
|
|
92
|
+
location: String.isEmpty(file) ? base : join(base, file),
|
|
93
|
+
pointer: pipe(
|
|
94
|
+
Array.get(parts, 1),
|
|
95
|
+
Option.getOrElse(() => ""),
|
|
96
|
+
),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function nameOf(target: Target) {
|
|
101
|
+
const token = pipe(target.pointer, String.split("/"), Array.lastNonEmpty);
|
|
102
|
+
if (String.isNonEmpty(token)) return OpenApiSpec.pointerKey(token);
|
|
103
|
+
return io.path.parse(
|
|
104
|
+
URL.canParse(target.location) ? new URL(target.location).pathname : target.location,
|
|
105
|
+
).name;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const failed = Effect.mapError((message: string) => OpenApiBundleError.make({ message }));
|
|
109
|
+
|
|
110
|
+
const load = Effect.fnUntraced(function* (at: string) {
|
|
111
|
+
return yield* Option.match(HashMap.get((yield* Ref.get(state)).documents, at), {
|
|
112
|
+
onNone: () =>
|
|
113
|
+
pipe(
|
|
114
|
+
failed(io.read(at)),
|
|
115
|
+
Effect.flatMap(text =>
|
|
116
|
+
failed(
|
|
117
|
+
Effect.mapError(OpenApiSpec.decode(text), () => `${at} is not a JSON or YAML object`),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
Effect.tap(document =>
|
|
121
|
+
Ref.update(state, current => ({
|
|
122
|
+
...current,
|
|
123
|
+
documents: HashMap.set(current.documents, at, document),
|
|
124
|
+
})),
|
|
125
|
+
),
|
|
126
|
+
),
|
|
127
|
+
onSome: Effect.succeed,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const read = Effect.fnUntraced(function* (target: Target) {
|
|
132
|
+
return yield* failed(
|
|
133
|
+
Effect.fromResult(OpenApiSpec.pointerTarget(yield* load(target.location), target.pointer)),
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const mapValues = Effect.fnUntraced(function* <A>(
|
|
138
|
+
record: OpenApiSpec.JsonObject,
|
|
139
|
+
transform: (value: unknown, key: string) => Effect.Effect<A, OpenApiBundleError>,
|
|
140
|
+
) {
|
|
141
|
+
return Record.fromEntries(
|
|
142
|
+
yield* Effect.forEach(Record.toEntries(record), entry =>
|
|
143
|
+
Effect.map(transform(entry[1], entry[0]), value => [entry[0], value] as const),
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const declare = Effect.fnUntraced(function* (
|
|
149
|
+
target: Target,
|
|
150
|
+
key: string,
|
|
151
|
+
taken: HashSet.HashSet<string>,
|
|
152
|
+
): Effect.fn.Return<string, OpenApiBundleError> {
|
|
153
|
+
const name = unique(nameOf(target), taken);
|
|
154
|
+
yield* Ref.update(state, found => ({ ...found, names: HashMap.set(found.names, key, name) }));
|
|
155
|
+
const bundled = yield* visit(yield* read(target), {
|
|
156
|
+
base: target.location,
|
|
157
|
+
inSchema: true,
|
|
158
|
+
inlining: [],
|
|
159
|
+
keysAreNames: false,
|
|
160
|
+
});
|
|
161
|
+
yield* Ref.update(state, found => ({
|
|
162
|
+
...found,
|
|
163
|
+
hoisted: { ...found.hoisted, [name]: bundled },
|
|
164
|
+
}));
|
|
165
|
+
return local(name);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const hoist = Effect.fnUntraced(function* (
|
|
169
|
+
target: Target,
|
|
170
|
+
): Effect.fn.Return<string, OpenApiBundleError> {
|
|
171
|
+
if (target.location === location) return `#${target.pointer}`;
|
|
172
|
+
const key = `${target.location}#${target.pointer}`;
|
|
173
|
+
const current = yield* Ref.get(state);
|
|
174
|
+
return yield* Option.match(HashMap.get(current.names, key), {
|
|
175
|
+
onNone: () =>
|
|
176
|
+
declare(
|
|
177
|
+
target,
|
|
178
|
+
key,
|
|
179
|
+
HashSet.union(own, HashSet.fromIterable(HashMap.values(current.names))),
|
|
180
|
+
),
|
|
181
|
+
onSome: name => Effect.succeed(local(name)),
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const inline = Effect.fnUntraced(function* (
|
|
186
|
+
node: OpenApiSpec.JsonObject,
|
|
187
|
+
target: Target,
|
|
188
|
+
position: Position,
|
|
189
|
+
): Effect.fn.Return<unknown, OpenApiBundleError> {
|
|
190
|
+
const key = `${target.location}#${target.pointer}`;
|
|
191
|
+
if (Array.contains(position.inlining, key)) {
|
|
192
|
+
return yield* OpenApiBundleError.make({ message: `reference cycle at ${key}` });
|
|
193
|
+
}
|
|
194
|
+
const inlined = yield* visit(yield* read(target), {
|
|
195
|
+
base: target.location,
|
|
196
|
+
inSchema: false,
|
|
197
|
+
inlining: [...position.inlining, key],
|
|
198
|
+
keysAreNames: false,
|
|
199
|
+
});
|
|
200
|
+
return Predicate.isObject(inlined) && !Array.isArray(inlined)
|
|
201
|
+
? { ...inlined, ...Record.remove(node, "$ref") }
|
|
202
|
+
: inlined;
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const mapped = Effect.fnUntraced(function* (value: unknown, position: Position) {
|
|
206
|
+
if (!Predicate.isString(value)) return value;
|
|
207
|
+
const reference = /[/#]|\.(?:ya?ml|json)$/iu.test(value);
|
|
208
|
+
if (position.base === location && (!reference || pipe(value, String.startsWith("#")))) {
|
|
209
|
+
return value;
|
|
210
|
+
}
|
|
211
|
+
return yield* hoist(
|
|
212
|
+
targetOf(
|
|
213
|
+
reference ? value : `#${schemaPointer}/${OpenApiSpec.pointerToken(value)}`,
|
|
214
|
+
position.base,
|
|
215
|
+
),
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const member = Effect.fnUntraced(function* (
|
|
220
|
+
key: string,
|
|
221
|
+
value: unknown,
|
|
222
|
+
position: Position,
|
|
223
|
+
): Effect.fn.Return<unknown, OpenApiBundleError> {
|
|
224
|
+
if (
|
|
225
|
+
!position.keysAreNames &&
|
|
226
|
+
(pipe(key, String.startsWith("x-")) || Array.contains(dataKeywords, key))
|
|
227
|
+
) {
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
const child: Position = {
|
|
231
|
+
...position,
|
|
232
|
+
inSchema:
|
|
233
|
+
position.inSchema ||
|
|
234
|
+
(!position.keysAreNames && (key === "schema" || Array.contains(schemaMaps, key))),
|
|
235
|
+
keysAreNames: !position.keysAreNames && Array.contains(nameMaps, key),
|
|
236
|
+
};
|
|
237
|
+
const declared = OpenApiSpec.asObject(value);
|
|
238
|
+
const mapping = OpenApiSpec.asObject(declared?.["mapping"]);
|
|
239
|
+
if (!position.keysAreNames && key === "discriminator" && mapping !== undefined) {
|
|
240
|
+
return { ...declared, mapping: yield* mapValues(mapping, entry => mapped(entry, child)) };
|
|
241
|
+
}
|
|
242
|
+
return yield* visit(value, child);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const visitObject = Effect.fnUntraced(function* (
|
|
246
|
+
node: OpenApiSpec.JsonObject,
|
|
247
|
+
position: Position,
|
|
248
|
+
) {
|
|
249
|
+
return yield* mapValues(node, (value, key) => member(key, value, position));
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const visit = Effect.fnUntraced(function* (
|
|
253
|
+
node: unknown,
|
|
254
|
+
position: Position,
|
|
255
|
+
): Effect.fn.Return<unknown, OpenApiBundleError> {
|
|
256
|
+
if (Array.isArray(node)) {
|
|
257
|
+
return yield* Effect.forEach(node, item => visit(item, { ...position, keysAreNames: false }));
|
|
258
|
+
}
|
|
259
|
+
if (!Predicate.isObject(node)) return node;
|
|
260
|
+
const reference = node["$ref"];
|
|
261
|
+
if (!Predicate.isString(reference)) return yield* visitObject(node, position);
|
|
262
|
+
const target = targetOf(reference, position.base);
|
|
263
|
+
if (target.location === location) return { ...node, $ref: `#${target.pointer}` };
|
|
264
|
+
if (position.inSchema) return { ...node, $ref: yield* hoist(target) };
|
|
265
|
+
return yield* inline(node, target, position);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const bundled = yield* visitObject(root, {
|
|
269
|
+
base: location,
|
|
270
|
+
inSchema: false,
|
|
271
|
+
inlining: [],
|
|
272
|
+
keysAreNames: false,
|
|
273
|
+
});
|
|
274
|
+
const hoisted = (yield* Ref.get(state)).hoisted;
|
|
275
|
+
if (Record.isEmptyRecord(hoisted)) return bundled;
|
|
276
|
+
return swagger
|
|
277
|
+
? { ...bundled, definitions: { ...OpenApiSpec.asObject(bundled["definitions"]), ...hoisted } }
|
|
278
|
+
: {
|
|
279
|
+
...bundled,
|
|
280
|
+
components: {
|
|
281
|
+
...OpenApiSpec.asObject(bundled["components"]),
|
|
282
|
+
schemas: {
|
|
283
|
+
...OpenApiSpec.asObject(OpenApiSpec.asObject(bundled["components"])?.["schemas"]),
|
|
284
|
+
...hoisted,
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
export * as OpenApiBundle from "./bundle.ts";
|