@fabricorg/fabric-gen 0.7.5 → 0.7.7
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/CHANGELOG.md +60 -0
- package/dist/cli.cjs +8 -631
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +8 -9
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +587 -611
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -65
- package/dist/index.d.ts +64 -65
- package/dist/index.js +599 -23
- package/dist/index.js.map +1 -1
- package/package.json +19 -18
- package/dist/chunk-LHZN67DB.js +0 -621
- package/dist/chunk-LHZN67DB.js.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,634 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
-
mod
|
|
24
|
-
));
|
|
25
|
-
|
|
26
|
-
// index.ts
|
|
27
|
-
var import_promises = require("fs/promises");
|
|
28
|
-
var import_node_crypto = require("crypto");
|
|
29
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
30
|
-
var import_node_url = require("url");
|
|
31
|
-
var import_compiler = require("@fabricorg/compiler");
|
|
32
|
-
var import_manifest = require("@fabricorg/platform/manifest");
|
|
33
|
-
var import_gen_capability = require("@fabricorg/gen-capability");
|
|
34
|
-
var import_gen_docs = require("@fabricorg/gen-docs");
|
|
35
|
-
var import_gen_events = require("@fabricorg/gen-events");
|
|
36
|
-
var import_gen_types = require("@fabricorg/gen-types");
|
|
37
|
-
var import_gen_prisma = require("@fabricorg/gen-prisma");
|
|
38
|
-
var import_gen_graphql = require("@fabricorg/gen-graphql");
|
|
39
|
-
var import_gen_sdui = require("@fabricorg/gen-sdui");
|
|
40
|
-
var import_sdui_composer = require("@fabricorg/sdui-composer");
|
|
41
|
-
var import_gen_conformance = require("@fabricorg/gen-conformance");
|
|
42
|
-
var import_assembly = require("@fabricorg/assembly");
|
|
43
|
-
var import_sdui_release = require("@fabricorg/sdui-release");
|
|
44
|
-
var GENERATOR_TARGETS = {
|
|
45
|
-
types: import_gen_types.typesGenerator,
|
|
46
|
-
events: import_gen_events.eventsGenerator,
|
|
47
|
-
capability: import_gen_capability.capabilityGenerator,
|
|
48
|
-
docs: import_gen_docs.docsGenerator,
|
|
49
|
-
prisma: import_gen_prisma.prismaGenerator,
|
|
50
|
-
graphql: import_gen_graphql.graphqlGenerator,
|
|
51
|
-
sdui: import_gen_sdui.sduiGenerator,
|
|
52
|
-
conformance: import_gen_conformance.conformanceGenerator
|
|
53
|
-
};
|
|
54
|
-
var compareCanonicalStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
|
|
55
|
-
var usage = [
|
|
56
|
-
"Usage:",
|
|
57
|
-
" fabric-gen init capability <namespace> [--directory <path>]",
|
|
58
|
-
" fabric-gen export --module <file> [--export <name>] --out <manifest.json>",
|
|
59
|
-
" fabric-gen init experience <application> [--directory <path>]",
|
|
60
|
-
" fabric-gen check-application [--config <path>]",
|
|
61
|
-
" fabric-gen promote-experience --config <path> --key <pem> [--out <path>]",
|
|
62
|
-
" fabric-gen --input <manifest.json> --out <directory> [--targets <list>] [--check]"
|
|
63
|
-
].join("\n");
|
|
64
|
-
var FabricGenUsageError = class extends Error {
|
|
65
|
-
name = "FabricGenUsageError";
|
|
66
|
-
};
|
|
67
|
-
function fabricGenCliExitCode(error) {
|
|
68
|
-
return error instanceof FabricGenUsageError ? 2 : 1;
|
|
69
|
-
}
|
|
70
|
-
function flagValue(args2, flag) {
|
|
71
|
-
const index = args2.indexOf(flag);
|
|
72
|
-
if (index < 0) return void 0;
|
|
73
|
-
const value = args2[index + 1];
|
|
74
|
-
if (!value || value.startsWith("--")) throw new FabricGenUsageError(usage);
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
async function runFabricGenCommand(args2) {
|
|
78
|
-
if (args2[0] === "export") {
|
|
79
|
-
const moduleFile = flagValue(args2, "--module");
|
|
80
|
-
const out = flagValue(args2, "--out");
|
|
81
|
-
if (!moduleFile || !out) throw new FabricGenUsageError(usage);
|
|
82
|
-
const result2 = await exportModuleManifestFile({ moduleFile, out, exportName: flagValue(args2, "--export") });
|
|
83
|
-
return `Exported "${result2.namespace}" from ${result2.exportName} to ${out}: ${result2.objectTypes} object types, ${result2.actions} actions, ${result2.eventTypes} event types.`;
|
|
84
|
-
}
|
|
85
|
-
if (args2[0] === "init") {
|
|
86
|
-
if (!args2[2] || args2[2].startsWith("--")) {
|
|
87
|
-
throw new FabricGenUsageError(usage);
|
|
88
|
-
}
|
|
89
|
-
const name = args2[2];
|
|
90
|
-
const directory = flagValue(args2, "--directory") ?? name;
|
|
91
|
-
if (args2[1] === "capability") {
|
|
92
|
-
const result2 = await initializeCapability({ directory, namespace: name });
|
|
93
|
-
return `Initialized capability "${name}" with ${result2.created.length} files.`;
|
|
94
|
-
}
|
|
95
|
-
if (args2[1] === "experience") {
|
|
96
|
-
const result2 = await initializeExperience({ directory, application: name });
|
|
97
|
-
return `Initialized experience integration "${name}" with ${result2.created.length} files.`;
|
|
98
|
-
}
|
|
99
|
-
throw new FabricGenUsageError(usage);
|
|
100
|
-
}
|
|
101
|
-
if (args2[0] === "promote-experience") {
|
|
102
|
-
const configPath = flagValue(args2, "--config");
|
|
103
|
-
const privateKeyPath = flagValue(args2, "--key");
|
|
104
|
-
if (!configPath) throw new FabricGenUsageError("promote-experience requires --config.");
|
|
105
|
-
if (!privateKeyPath) throw new FabricGenUsageError("promote-experience requires --key.");
|
|
106
|
-
const outputPath = flagValue(args2, "--out");
|
|
107
|
-
const result2 = await promoteExperience({
|
|
108
|
-
configPath,
|
|
109
|
-
privateKeyPath,
|
|
110
|
-
...outputPath ? { outputPath } : {}
|
|
111
|
-
});
|
|
112
|
-
return [
|
|
113
|
-
`Promoted ${result2.application} release ${result2.releaseDigest.slice(0, 12)} against assembly ${result2.assemblyDigest.slice(0, 12)}.`,
|
|
114
|
-
`Routes: ${result2.routes.views} views, ${result2.routes.intents} intents.`,
|
|
115
|
-
`Wrote ${result2.outputPath}`
|
|
116
|
-
].join("\n");
|
|
117
|
-
}
|
|
118
|
-
if (args2[0] === "check-application") {
|
|
119
|
-
const configPath = flagValue(args2, "--config") ?? "fabric.application.json";
|
|
120
|
-
const result2 = await checkApplication({ configPath });
|
|
121
|
-
return `Checked "${result2.application}": ${result2.capabilities} capabilities, ${result2.releases} releases.`;
|
|
122
|
-
}
|
|
123
|
-
const inputPath = flagValue(args2, "--input");
|
|
124
|
-
const outputDirectory = flagValue(args2, "--out");
|
|
125
|
-
if (!inputPath || !outputDirectory) throw new FabricGenUsageError(usage);
|
|
126
|
-
const result = await generateFromManifest({
|
|
127
|
-
inputPath,
|
|
128
|
-
outputDirectory,
|
|
129
|
-
targets: (flagValue(args2, "--targets") ?? "types,events,capability,docs").split(",").filter(Boolean),
|
|
130
|
-
check: args2.includes("--check")
|
|
131
|
-
});
|
|
132
|
-
return `${args2.includes("--check") ? "Checked" : "Generated"} ${result.files.length} files.`;
|
|
133
|
-
}
|
|
134
|
-
function experienceReadme(application) {
|
|
135
|
-
return [
|
|
136
|
-
`# ${application} experience integration`,
|
|
137
|
-
"",
|
|
138
|
-
"| File | What it is |",
|
|
139
|
-
"| --- | --- |",
|
|
140
|
-
"| `fabric.experience.ts` | The server runtime and gateway, wired to your host. |",
|
|
141
|
-
"| `fabric.component-pack.ts` | The components this application is allowed to render. |",
|
|
142
|
-
"| `fabric.application.json` | What the deployment gate reads. |",
|
|
143
|
-
"| `fabric.assembly.lock.json` | The resolved assembly. Empty until you add capabilities. |",
|
|
144
|
-
"| `fabric.runtime.json` | Capabilities the running host actually registers. |",
|
|
145
|
-
"",
|
|
146
|
-
"## Install",
|
|
147
|
-
"",
|
|
148
|
-
"The scaffolded files import three packages this generator does not install:",
|
|
149
|
-
"",
|
|
150
|
-
"```bash",
|
|
151
|
-
"pnpm add @fabricorg/experience-runtime @fabricorg/experience-gateway @fabricorg/component-pack",
|
|
152
|
-
"```",
|
|
153
|
-
"",
|
|
154
|
-
"## Check it",
|
|
155
|
-
"",
|
|
156
|
-
"```bash",
|
|
157
|
-
"fabric-gen check-application --config fabric.application.json",
|
|
158
|
-
"```",
|
|
159
|
-
"",
|
|
160
|
-
"It passes on the scaffold and keeps passing as you add capabilities, as long",
|
|
161
|
-
"as the lockfile, the runtime capabilities, and every promoted release agree.",
|
|
162
|
-
"Regenerate the lockfile from your composition root with `resolveAssembly`;",
|
|
163
|
-
"`fabric.runtime.json` must list what that same root registers with the host,",
|
|
164
|
-
"which is what stops a deployment from serving a plan its host cannot answer.",
|
|
165
|
-
""
|
|
166
|
-
].join("\n");
|
|
167
|
-
}
|
|
168
|
-
async function initializeExperience(options) {
|
|
169
|
-
if (!/^[a-z][a-z0-9-]*$/.test(options.application)) {
|
|
170
|
-
throw new Error("Application name must use lowercase letters, numbers, and hyphens.");
|
|
171
|
-
}
|
|
172
|
-
const functionName = options.application.split("-").map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
173
|
-
const files = [
|
|
174
|
-
[
|
|
175
|
-
import_node_path.default.join(options.directory, "fabric.experience.ts"),
|
|
176
|
-
[
|
|
177
|
-
'import { createExperienceServerRuntime } from "@fabricorg/experience-runtime/server";',
|
|
178
|
-
'import { createExperienceGateway } from "@fabricorg/experience-gateway";',
|
|
179
|
-
"",
|
|
180
|
-
`export const create${functionName}ExperienceRuntime = (`,
|
|
181
|
-
" options: Parameters<typeof createExperienceServerRuntime>[0],",
|
|
182
|
-
") => createExperienceServerRuntime(options);",
|
|
183
|
-
"",
|
|
184
|
-
`export const create${functionName}ExperienceGateway = (`,
|
|
185
|
-
" options: Parameters<typeof createExperienceGateway>[0],",
|
|
186
|
-
") => createExperienceGateway(options);",
|
|
187
|
-
""
|
|
188
|
-
].join("\n")
|
|
189
|
-
],
|
|
190
|
-
[
|
|
191
|
-
import_node_path.default.join(options.directory, "fabric.component-pack.ts"),
|
|
192
|
-
[
|
|
193
|
-
'import { defineComponentPack } from "@fabricorg/component-pack";',
|
|
194
|
-
"",
|
|
195
|
-
`export const define${functionName}ComponentPack = (artifactDigest: string) =>`,
|
|
196
|
-
" defineComponentPack({",
|
|
197
|
-
` name: "${options.application}",`,
|
|
198
|
-
` namespace: "${options.application}",`,
|
|
199
|
-
' version: "0.1.0",',
|
|
200
|
-
" artifactDigest,",
|
|
201
|
-
' tokenContract: { name: "fabric-family", version: "1.0.0" },',
|
|
202
|
-
" components: {",
|
|
203
|
-
' Text: { module: "./components/text.js", roles: ["content"], slots: [] },',
|
|
204
|
-
" },",
|
|
205
|
-
" });",
|
|
206
|
-
""
|
|
207
|
-
].join("\n")
|
|
208
|
-
],
|
|
209
|
-
[
|
|
210
|
-
import_node_path.default.join(options.directory, "fabric.application.json"),
|
|
211
|
-
`${JSON.stringify({
|
|
212
|
-
formatVersion: 1,
|
|
213
|
-
application: options.application,
|
|
214
|
-
assembly: "./fabric.assembly.lock.json",
|
|
215
|
-
runtimeCapabilities: "./fabric.runtime.json",
|
|
216
|
-
releases: []
|
|
217
|
-
}, null, 2)}
|
|
218
|
-
`
|
|
219
|
-
],
|
|
220
|
-
// The application config names these two files, so the scaffold has to
|
|
221
|
-
// produce them. Without them `fabric-gen check-application`, the very
|
|
222
|
-
// next step, failed on a missing file rather than on anything the
|
|
223
|
-
// author had done. The lockfile is resolved here, not hand-written, so
|
|
224
|
-
// it carries a real assembly digest from the first commit.
|
|
225
|
-
[
|
|
226
|
-
import_node_path.default.join(options.directory, "fabric.assembly.lock.json"),
|
|
227
|
-
`${JSON.stringify((0, import_assembly.resolveAssembly)({
|
|
228
|
-
manifest: {
|
|
229
|
-
formatVersion: 2,
|
|
230
|
-
application: options.application,
|
|
231
|
-
capabilities: [],
|
|
232
|
-
componentPacks: [],
|
|
233
|
-
bindings: [],
|
|
234
|
-
contracts: []
|
|
235
|
-
},
|
|
236
|
-
capabilities: [],
|
|
237
|
-
componentPacks: []
|
|
238
|
-
}).lockfile, null, 2)}
|
|
239
|
-
`
|
|
240
|
-
],
|
|
241
|
-
[
|
|
242
|
-
import_node_path.default.join(options.directory, "fabric.runtime.json"),
|
|
243
|
-
"[]\n"
|
|
244
|
-
],
|
|
245
|
-
[
|
|
246
|
-
import_node_path.default.join(options.directory, "README.md"),
|
|
247
|
-
experienceReadme(options.application)
|
|
248
|
-
]
|
|
249
|
-
];
|
|
250
|
-
await (0, import_promises.mkdir)(options.directory, { recursive: true });
|
|
251
|
-
const created = [];
|
|
252
|
-
try {
|
|
253
|
-
for (const [file, content] of files) {
|
|
254
|
-
await (0, import_promises.writeFile)(file, content, { encoding: "utf8", flag: "wx" });
|
|
255
|
-
created.push(file);
|
|
256
|
-
}
|
|
257
|
-
} catch (error) {
|
|
258
|
-
await Promise.all(created.map((file) => (0, import_promises.rm)(file, { force: true })));
|
|
259
|
-
if (error.code === "EEXIST") {
|
|
260
|
-
throw new Error("Refusing to overwrite an existing experience integration file.");
|
|
261
|
-
}
|
|
262
|
-
throw error;
|
|
263
|
-
}
|
|
264
|
-
return { created };
|
|
265
|
-
}
|
|
266
|
-
async function readJson(file) {
|
|
267
|
-
return JSON.parse(await (0, import_promises.readFile)(file, "utf8"));
|
|
268
|
-
}
|
|
269
|
-
function assertApplicationCheckConfig(value) {
|
|
270
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
271
|
-
throw new Error("Application check configuration must be a JSON object.");
|
|
272
|
-
}
|
|
273
|
-
const config = value;
|
|
274
|
-
if (config.formatVersion !== 1) throw new Error("Application check configuration formatVersion must be 1.");
|
|
275
|
-
if (typeof config.assembly !== "string" || !config.assembly) {
|
|
276
|
-
throw new Error("Application check configuration assembly must be a file path.");
|
|
277
|
-
}
|
|
278
|
-
if (typeof config.runtimeCapabilities !== "string" || !config.runtimeCapabilities) {
|
|
279
|
-
throw new Error("Application check configuration runtimeCapabilities must be a file path.");
|
|
280
|
-
}
|
|
281
|
-
if (!Array.isArray(config.releases) || !config.releases.every((entry) => typeof entry === "string" && entry)) {
|
|
282
|
-
throw new Error("Application check configuration releases must be an array of file paths.");
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async function checkApplication(options) {
|
|
286
|
-
const configValue = await readJson(options.configPath);
|
|
287
|
-
assertApplicationCheckConfig(configValue);
|
|
288
|
-
const base = import_node_path.default.dirname(options.configPath);
|
|
289
|
-
const resolve = (file) => import_node_path.default.resolve(base, file);
|
|
290
|
-
const assembly = await readJson(resolve(configValue.assembly));
|
|
291
|
-
(0, import_assembly.assertAssemblyLockfile)(assembly);
|
|
292
|
-
const runtimeCapabilities = await readJson(
|
|
293
|
-
resolve(configValue.runtimeCapabilities)
|
|
294
|
-
);
|
|
295
|
-
if (!Array.isArray(runtimeCapabilities)) {
|
|
296
|
-
throw new Error("Runtime capabilities must be a JSON array.");
|
|
297
|
-
}
|
|
298
|
-
(0, import_assembly.assertAssemblyRuntimeCompatible)(assembly, runtimeCapabilities);
|
|
299
|
-
for (const releasePath of configValue.releases) {
|
|
300
|
-
const release = await readJson(resolve(releasePath));
|
|
301
|
-
try {
|
|
302
|
-
(0, import_sdui_release.assertSduiReleaseIntegrity)(release);
|
|
303
|
-
} catch (error) {
|
|
304
|
-
throw new Error(
|
|
305
|
-
`Experience release "${releasePath}" is invalid: ${error instanceof Error ? error.message : String(error)}`
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
if (release.assemblyDigest !== assembly.assemblyDigest) {
|
|
309
|
-
throw new Error(
|
|
310
|
-
`Experience release "${release.document.name}@${release.document.version}" belongs to assembly "${release.assemblyDigest}", not "${assembly.assemblyDigest}".`
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
application: assembly.application,
|
|
316
|
-
capabilities: assembly.capabilities.length,
|
|
317
|
-
releases: configValue.releases.length,
|
|
318
|
-
assemblyDigest: assembly.assemblyDigest
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
async function exportModuleManifestFile(options) {
|
|
322
|
-
const absolute = import_node_path.default.resolve(options.moduleFile);
|
|
323
|
-
const loaded = await importAuthoredModule(absolute, options.moduleFile);
|
|
324
|
-
const candidates = Object.entries(loaded).filter(([, value]) => isFabricModuleLike(value));
|
|
325
|
-
let entry;
|
|
326
|
-
if (options.exportName) {
|
|
327
|
-
const named = loaded[options.exportName];
|
|
328
|
-
if (named === void 0) throw new Error(`"${options.moduleFile}" has no export named "${options.exportName}". It exports: ${Object.keys(loaded).join(", ") || "nothing"}.`);
|
|
329
|
-
if (!isFabricModuleLike(named)) throw new Error(`Export "${options.exportName}" of "${options.moduleFile}" is not a FabricModule: it has no string "namespace".`);
|
|
330
|
-
entry = [options.exportName, named];
|
|
331
|
-
} else if (candidates.length === 1) {
|
|
332
|
-
entry = candidates[0];
|
|
333
|
-
} else if (candidates.length === 0) {
|
|
334
|
-
throw new Error(`"${options.moduleFile}" exports no FabricModule. Export one, with a string "namespace", or name it with --export.`);
|
|
335
|
-
} else {
|
|
336
|
-
throw new Error(`"${options.moduleFile}" exports ${candidates.length} modules (${candidates.map(([name]) => name).join(", ")}). Choose one with --export.`);
|
|
337
|
-
}
|
|
338
|
-
const manifest = (0, import_manifest.exportModuleManifest)(entry[1]);
|
|
339
|
-
(0, import_compiler.compileManifestBundle)({ manifestVersion: 2, modules: [manifest] });
|
|
340
|
-
await (0, import_promises.mkdir)(import_node_path.default.dirname(import_node_path.default.resolve(options.out)), { recursive: true });
|
|
341
|
-
await (0, import_promises.writeFile)(import_node_path.default.resolve(options.out), `${JSON.stringify(manifest, null, 2)}
|
|
342
|
-
`, "utf8");
|
|
343
|
-
return {
|
|
344
|
-
namespace: manifest.namespace,
|
|
345
|
-
exportName: entry[0],
|
|
346
|
-
objectTypes: manifest.objectTypes.length,
|
|
347
|
-
actions: manifest.actions.length,
|
|
348
|
-
eventTypes: manifest.eventTypes.length
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
async function importAuthoredModule(absolute, display) {
|
|
352
|
-
try {
|
|
353
|
-
return await import((0, import_node_url.pathToFileURL)(absolute).href);
|
|
354
|
-
} catch (error) {
|
|
355
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
356
|
-
const readAsCommonJs = /Unexpected token '(export|import)'|Cannot use import statement outside a module/.test(reason);
|
|
357
|
-
if (readAsCommonJs && /\.[cm]?ts$/.test(absolute)) {
|
|
358
|
-
const sibling = import_node_path.default.join(import_node_path.default.dirname(absolute), `.fabric-gen-${process.pid}-${import_node_path.default.basename(absolute, import_node_path.default.extname(absolute))}.mts`);
|
|
359
|
-
try {
|
|
360
|
-
await (0, import_promises.writeFile)(sibling, await (0, import_promises.readFile)(absolute, "utf8"), "utf8");
|
|
361
|
-
return await import((0, import_node_url.pathToFileURL)(sibling).href);
|
|
362
|
-
} catch (retried) {
|
|
363
|
-
const retriedReason = retried instanceof Error ? retried.message : String(retried);
|
|
364
|
-
throw new Error(`Could not load module file "${display}": ${retriedReason}
|
|
365
|
-
A TypeScript file needs a runtime that strips types (Node 22.18 or newer); otherwise point --module at the built JavaScript.`);
|
|
366
|
-
} finally {
|
|
367
|
-
await (0, import_promises.rm)(sibling, { force: true });
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
throw new Error(`Could not load module file "${display}": ${reason}
|
|
371
|
-
A TypeScript file needs a runtime that strips types (Node 22.18 or newer); otherwise point --module at the built JavaScript.`);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function isFabricModuleLike(value) {
|
|
375
|
-
return typeof value === "object" && value !== null && typeof value.namespace === "string";
|
|
376
|
-
}
|
|
377
|
-
async function initializeCapability(options) {
|
|
378
|
-
if (!/^[a-z][a-z0-9-]*$/.test(options.namespace)) {
|
|
379
|
-
throw new Error("Capability namespace must use lowercase letters, numbers, and hyphens.");
|
|
380
|
-
}
|
|
381
|
-
const displayName = options.namespace.split("-").map((part, index) => index === 0 ? `${part.charAt(0).toUpperCase()}${part.slice(1)}` : part).join(" ");
|
|
382
|
-
const modulePath = import_node_path.default.join(options.directory, "module.ts");
|
|
383
|
-
const readmePath = import_node_path.default.join(options.directory, "README.md");
|
|
384
|
-
for (const file of [readmePath, modulePath]) {
|
|
385
|
-
try {
|
|
386
|
-
await (0, import_promises.access)(file);
|
|
387
|
-
throw new Error(`Refusing to overwrite existing file "${file}".`);
|
|
388
|
-
} catch (error) {
|
|
389
|
-
if (error instanceof Error && error.message.startsWith("Refusing to overwrite")) throw error;
|
|
390
|
-
if (error.code !== "ENOENT") throw error;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
const module2 = [
|
|
394
|
-
`import type { ActionDefinition } from "@fabricorg/platform/actions";`,
|
|
395
|
-
`import type { FabricModule } from "@fabricorg/platform/modules";`,
|
|
396
|
-
"",
|
|
397
|
-
`/** One governed action. Every field below is checked when the manifest is exported. */`,
|
|
398
|
-
`const recordExample: ActionDefinition = {`,
|
|
399
|
-
` actionId: "${options.namespace}.record_example",`,
|
|
400
|
-
` namespace: "${options.namespace}",`,
|
|
401
|
-
" version: 1,",
|
|
402
|
-
' kind: "atomic",',
|
|
403
|
-
" idempotent: true,",
|
|
404
|
-
" mutatesDomain: true,",
|
|
405
|
-
' emitsEvents: ["ExampleRecorded"],',
|
|
406
|
-
" // The six execution dimensions. A strict certification profile requires all of them.",
|
|
407
|
-
" execution: {",
|
|
408
|
-
' connectivity: "online-required",',
|
|
409
|
-
' authorityMoment: "execution",',
|
|
410
|
-
' idempotency: "required",',
|
|
411
|
-
' completion: "immediate",',
|
|
412
|
-
' consistency: "authoritative-now",',
|
|
413
|
-
' sensitivity: "internal",',
|
|
414
|
-
" },",
|
|
415
|
-
" schema: {",
|
|
416
|
-
" parse(value: unknown): { exampleId: string } {",
|
|
417
|
-
" const input = value as { exampleId?: unknown };",
|
|
418
|
-
' if (typeof input?.exampleId !== "string") throw new Error("exampleId is required");',
|
|
419
|
-
" return { exampleId: input.exampleId };",
|
|
420
|
-
" },",
|
|
421
|
-
" safeParse(value: unknown) {",
|
|
422
|
-
" try {",
|
|
423
|
-
" return { success: true as const, data: this.parse(value) };",
|
|
424
|
-
" } catch (error) {",
|
|
425
|
-
' return { success: false as const, error: { issues: [{ path: ["exampleId"], message: error instanceof Error ? error.message : String(error) }] } };',
|
|
426
|
-
" }",
|
|
427
|
-
" },",
|
|
428
|
-
" },",
|
|
429
|
-
" handler: async (_context, parameters) => ({",
|
|
430
|
-
" success: true,",
|
|
431
|
-
" data: {",
|
|
432
|
-
" ...(parameters as { exampleId: string }),",
|
|
433
|
-
" _events: [{",
|
|
434
|
-
' eventType: "ExampleRecorded",',
|
|
435
|
-
' entityType: "Example",',
|
|
436
|
-
" entityId: (parameters as { exampleId: string }).exampleId,",
|
|
437
|
-
" payload: parameters,",
|
|
438
|
-
" }],",
|
|
439
|
-
" },",
|
|
440
|
-
" }),",
|
|
441
|
-
"};",
|
|
442
|
-
"",
|
|
443
|
-
`export const ${camelCase(options.namespace)}Module: FabricModule = {`,
|
|
444
|
-
` namespace: "${options.namespace}",`,
|
|
445
|
-
' version: "0.1.0",',
|
|
446
|
-
" capability: {",
|
|
447
|
-
` displayName: "${displayName}",`,
|
|
448
|
-
` description: "Governed ${displayName.toLowerCase()} capability.",`,
|
|
449
|
-
' stability: "experimental",',
|
|
450
|
-
" },",
|
|
451
|
-
" objectTypes: [{",
|
|
452
|
-
' type: "Example",',
|
|
453
|
-
" schema: {",
|
|
454
|
-
' type: "object",',
|
|
455
|
-
' properties: { exampleId: { type: "string" } },',
|
|
456
|
-
' required: ["exampleId"],',
|
|
457
|
-
" },",
|
|
458
|
-
" }],",
|
|
459
|
-
` idPrefixes: [{ prefix: "exm", name: "Example", module: "${options.namespace}" }],`,
|
|
460
|
-
' eventTypes: [{ eventType: "ExampleRecorded", schemaVersion: 1 }],',
|
|
461
|
-
" actions: [recordExample],",
|
|
462
|
-
"};",
|
|
463
|
-
""
|
|
464
|
-
].join("\n");
|
|
465
|
-
const readme = [
|
|
466
|
-
`# ${displayName}`,
|
|
467
|
-
"",
|
|
468
|
-
"`module.ts` is the source of truth. It is TypeScript, so the shape of every",
|
|
469
|
-
"action, object type, and event is checked as you write it.",
|
|
470
|
-
"",
|
|
471
|
-
"## The loop",
|
|
472
|
-
"",
|
|
473
|
-
"```bash",
|
|
474
|
-
"# 1. Export the authored module to the normalized manifest the generators read.",
|
|
475
|
-
"fabric-gen export --module module.ts --out fabric.manifest.json",
|
|
476
|
-
"",
|
|
477
|
-
"# 2. Generate types, event contracts, the usage contract, and docs.",
|
|
478
|
-
"fabric-gen --input fabric.manifest.json --out generated",
|
|
479
|
-
"",
|
|
480
|
-
"# 3. In CI, prove the generated files match the manifest.",
|
|
481
|
-
"fabric-gen --input fabric.manifest.json --out generated --check",
|
|
482
|
-
"```",
|
|
483
|
-
"",
|
|
484
|
-
"Commit both `fabric.manifest.json` and `generated/`. The manifest is the",
|
|
485
|
-
"contract other capabilities and applications compile against; regenerating",
|
|
486
|
-
"is how a consumer learns what changed.",
|
|
487
|
-
"",
|
|
488
|
-
"## What to edit",
|
|
489
|
-
"",
|
|
490
|
-
"- **Object types** carry a portable JSON Schema. They become generated TypeScript types.",
|
|
491
|
-
"- **Actions** declare six execution dimensions. A host refuses an action whose",
|
|
492
|
-
" declaration does not match how it is invoked, so declare them honestly.",
|
|
493
|
-
"- **Events** are the capability's public vocabulary. Adding a field is compatible;",
|
|
494
|
-
" removing or retyping one is not.",
|
|
495
|
-
""
|
|
496
|
-
].join("\n");
|
|
497
|
-
await (0, import_promises.mkdir)(options.directory, { recursive: true });
|
|
498
|
-
const created = [];
|
|
499
|
-
try {
|
|
500
|
-
for (const [file, content] of [
|
|
501
|
-
[readmePath, readme],
|
|
502
|
-
[modulePath, module2]
|
|
503
|
-
]) {
|
|
504
|
-
await (0, import_promises.writeFile)(file, content, { encoding: "utf8", flag: "wx" });
|
|
505
|
-
created.push(file);
|
|
506
|
-
}
|
|
507
|
-
} catch (error) {
|
|
508
|
-
await Promise.all(created.map((file) => (0, import_promises.rm)(file, { force: true })));
|
|
509
|
-
if (error.code === "EEXIST") {
|
|
510
|
-
throw new Error("Refusing to overwrite a file created during capability initialization.");
|
|
511
|
-
}
|
|
512
|
-
throw error;
|
|
513
|
-
}
|
|
514
|
-
return { created };
|
|
515
|
-
}
|
|
516
|
-
function camelCase(namespace) {
|
|
517
|
-
return namespace.split("-").map((part, index) => index === 0 ? part : `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
518
|
-
}
|
|
519
|
-
async function generateFromManifest(options) {
|
|
520
|
-
const input = JSON.parse(await (0, import_promises.readFile)(options.inputPath, "utf8"));
|
|
521
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Manifest input must be a JSON object.");
|
|
522
|
-
const bundle = "modules" in input ? input : { manifestVersion: input.manifestVersion, modules: [input] };
|
|
523
|
-
const ir = (0, import_compiler.compileManifestBundle)(bundle);
|
|
524
|
-
const files = (await Promise.all(options.targets.map(async (name) => {
|
|
525
|
-
const target = GENERATOR_TARGETS[name];
|
|
526
|
-
if (!target) throw new Error(`Unknown generator target "${name}".`);
|
|
527
|
-
return (await (0, import_compiler.runGenerator)(target, ir)).map((file) => ({ ...file, path: `${name}/${file.path}` }));
|
|
528
|
-
}))).flat().sort((left, right) => compareCanonicalStrings(left.path, right.path));
|
|
529
|
-
const expected = new Set(files.map((file) => file.path));
|
|
530
|
-
const existing = await listFiles(options.outputDirectory);
|
|
531
|
-
const selectedPrefixes = options.targets.map((target) => `${target}/`);
|
|
532
|
-
const stale = existing.filter((file) => selectedPrefixes.some((prefix) => file.startsWith(prefix)) && !expected.has(file));
|
|
533
|
-
if (!options.check) await Promise.all(stale.map((file) => (0, import_promises.rm)(import_node_path.default.join(options.outputDirectory, file), { force: true })));
|
|
534
|
-
const changed = [];
|
|
535
|
-
for (const file of files) {
|
|
536
|
-
const target = import_node_path.default.join(options.outputDirectory, file.path);
|
|
537
|
-
let current;
|
|
538
|
-
try {
|
|
539
|
-
current = await (0, import_promises.readFile)(target, "utf8");
|
|
540
|
-
} catch {
|
|
541
|
-
current = void 0;
|
|
542
|
-
}
|
|
543
|
-
if (current !== file.content) {
|
|
544
|
-
changed.push(file.path);
|
|
545
|
-
if (!options.check) {
|
|
546
|
-
await (0, import_promises.mkdir)(import_node_path.default.dirname(target), { recursive: true });
|
|
547
|
-
await (0, import_promises.writeFile)(target, file.content, "utf8");
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
if (options.check && (changed.length || stale.length)) throw new Error(`Generated artifacts drifted: ${[...changed, ...stale.map((file) => `stale:${file}`)].join(", ")}`);
|
|
552
|
-
return { changed, stale, files };
|
|
553
|
-
}
|
|
554
|
-
async function listFiles(directory, prefix = "") {
|
|
555
|
-
let entries;
|
|
556
|
-
try {
|
|
557
|
-
entries = await (0, import_promises.readdir)(directory, { withFileTypes: true });
|
|
558
|
-
} catch {
|
|
559
|
-
return [];
|
|
560
|
-
}
|
|
561
|
-
const nested = await Promise.all(entries.map((entry) => entry.isDirectory() ? listFiles(import_node_path.default.join(directory, entry.name), `${prefix}${entry.name}/`) : [`${prefix}${entry.name}`]));
|
|
562
|
-
return nested.flat().sort();
|
|
563
|
-
}
|
|
564
|
-
function assertExperiencePromotionConfig(value) {
|
|
565
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
566
|
-
throw new Error("Experience promotion configuration must be a JSON object.");
|
|
567
|
-
}
|
|
568
|
-
const config = value;
|
|
569
|
-
if (config.formatVersion !== 1) throw new Error("Experience promotion configuration formatVersion must be 1.");
|
|
570
|
-
for (const field of ["application", "issuer", "keyId", "assembly", "release"]) {
|
|
571
|
-
if (typeof config[field] !== "string" || !config[field]) {
|
|
572
|
-
throw new Error(`Experience promotion configuration ${field} must be a non-empty string.`);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
if (!/^[a-z][a-z0-9-]*$/.test(config.application)) {
|
|
576
|
-
throw new Error("Experience promotion configuration application must be lowercase letters, numbers, and hyphens.");
|
|
577
|
-
}
|
|
578
|
-
if (!Array.isArray(config.contracts) || !config.contracts.every((entry) => typeof entry === "string" && entry)) {
|
|
579
|
-
throw new Error("Experience promotion configuration contracts must be an array of file paths.");
|
|
580
|
-
}
|
|
581
|
-
const known = /* @__PURE__ */ new Set(["formatVersion", "application", "issuer", "keyId", "assembly", "release", "contracts"]);
|
|
582
|
-
for (const field of Object.keys(config)) {
|
|
583
|
-
if (/key|secret|credential|token|pem|password/i.test(field) && field !== "keyId") {
|
|
584
|
-
throw new Error(`Experience promotion configuration must not carry "${field}"; pass the signing key with --key.`);
|
|
585
|
-
}
|
|
586
|
-
if (!known.has(field)) {
|
|
587
|
-
throw new Error(`Experience promotion configuration has an unknown field "${field}".`);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
async function promoteExperience(options) {
|
|
592
|
-
const configValue = await readJson(options.configPath);
|
|
593
|
-
assertExperiencePromotionConfig(configValue);
|
|
594
|
-
const base = import_node_path.default.dirname(options.configPath);
|
|
595
|
-
const resolve = (file) => import_node_path.default.resolve(base, file);
|
|
596
|
-
const assembly = await readJson(resolve(configValue.assembly));
|
|
597
|
-
(0, import_assembly.assertAssemblyLockfile)(assembly);
|
|
598
|
-
const release = await readJson(resolve(configValue.release));
|
|
599
|
-
(0, import_sdui_release.assertSduiReleaseIntegrity)(release);
|
|
600
|
-
const contracts = await Promise.all(
|
|
601
|
-
configValue.contracts.map(async (file) => await readJson(resolve(file)))
|
|
602
|
-
);
|
|
603
|
-
const privateKey = (0, import_node_crypto.createPrivateKey)(await (0, import_promises.readFile)(options.privateKeyPath, "utf8"));
|
|
604
|
-
const promoted = await (0, import_sdui_composer.promoteExperienceRelease)({
|
|
605
|
-
application: configValue.application,
|
|
606
|
-
release,
|
|
607
|
-
contracts,
|
|
608
|
-
assembly,
|
|
609
|
-
issuer: configValue.issuer,
|
|
610
|
-
signer: (0, import_sdui_composer.createEs256ReleaseSigner)({ keyId: configValue.keyId, privateKey })
|
|
611
|
-
});
|
|
612
|
-
const outputPath = options.outputPath ? import_node_path.default.resolve(options.outputPath) : resolve(`${configValue.application}.experience-release.jws`);
|
|
613
|
-
await (0, import_promises.mkdir)(import_node_path.default.dirname(outputPath), { recursive: true });
|
|
614
|
-
await (0, import_promises.writeFile)(outputPath, `${promoted.compactJws}
|
|
615
|
-
`, "utf8");
|
|
616
|
-
return {
|
|
617
|
-
application: configValue.application,
|
|
618
|
-
releaseDigest: release.releaseDigest,
|
|
619
|
-
assemblyDigest: assembly.assemblyDigest,
|
|
620
|
-
routes: {
|
|
621
|
-
views: promoted.release.routes.views.length,
|
|
622
|
-
intents: promoted.release.routes.intents.length
|
|
623
|
-
},
|
|
624
|
-
outputPath
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// cli.ts
|
|
629
|
-
var args = process.argv.slice(2);
|
|
630
|
-
runFabricGenCommand(args).then((message) => console.log(message)).catch((error) => {
|
|
631
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
632
|
-
process.exitCode = fabricGenCliExitCode(error);
|
|
2
|
+
const require_index = require("./index.cjs");
|
|
3
|
+
//#region cli.ts
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
require_index.runFabricGenCommand(args).then((message) => console.log(message)).catch((error) => {
|
|
6
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
7
|
+
process.exitCode = require_index.fabricGenCliExitCode(error);
|
|
633
8
|
});
|
|
9
|
+
//#endregion
|
|
10
|
+
|
|
634
11
|
//# sourceMappingURL=cli.cjs.map
|