@power-plant/core 0.0.26 → 0.0.28
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/dist/config.cjs +9 -1
- package/dist/config.mjs +7 -1
- package/dist/context.cjs +189 -1
- package/dist/context.mjs +168 -1
- package/dist/define.cjs +97 -1
- package/dist/define.mjs +93 -1
- package/dist/execute-3oK9lgh3.cjs +501 -0
- package/dist/execute-C6kyFG8N.mjs +461 -0
- package/dist/execute-C6kyFG8N.mjs.map +1 -0
- package/dist/execute.cjs +6 -1
- package/dist/execute.mjs +4 -1
- package/dist/helpers/index.cjs +17 -1
- package/dist/helpers/index.mjs +4 -1
- package/dist/helpers/meta.cjs +142 -1
- package/dist/helpers/meta.mjs +133 -1
- package/dist/helpers/type-checks.cjs +46 -1
- package/dist/helpers/type-checks.mjs +42 -1
- package/dist/index.cjs +34 -1
- package/dist/index.mjs +6 -1
- package/package.json +4 -4
- package/dist/execute-4whFNgY3.cjs +0 -1
- package/dist/execute-ByonuMsd.mjs +0 -2
- package/dist/execute-ByonuMsd.mjs.map +0 -1
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
const require_context = require('./context.cjs');
|
|
29
|
+
const require_helpers_type_checks = require('./helpers/type-checks.cjs');
|
|
30
|
+
const require_helpers_meta = require('./helpers/meta.cjs');
|
|
31
|
+
let _stryke_unique_id_uuid = require("@stryke/unique-id/uuid");
|
|
32
|
+
let _stryke_env_get_env_paths = require("@stryke/env/get-env-paths");
|
|
33
|
+
let _stryke_fs_read_file = require("@stryke/fs/read-file");
|
|
34
|
+
let _stryke_fs_write_file = require("@stryke/fs/write-file");
|
|
35
|
+
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
36
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
37
|
+
let defu = require("defu");
|
|
38
|
+
defu = __toESM(defu, 1);
|
|
39
|
+
let node_os = require("node:os");
|
|
40
|
+
node_os = __toESM(node_os, 1);
|
|
41
|
+
let unstorage = require("unstorage");
|
|
42
|
+
let unstorage_drivers_fs_lite = require("unstorage/drivers/fs-lite");
|
|
43
|
+
unstorage_drivers_fs_lite = __toESM(unstorage_drivers_fs_lite, 1);
|
|
44
|
+
let _power_plant_schema_storage = require("@power-plant/schema/storage");
|
|
45
|
+
let _stryke_resolve_load = require("@stryke/resolve/load");
|
|
46
|
+
let _stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
47
|
+
let _power_plant_schema = require("@power-plant/schema");
|
|
48
|
+
let _stryke_resolve_type_checks = require("@stryke/resolve/type-checks");
|
|
49
|
+
|
|
50
|
+
//#region src/lib/context.ts
|
|
51
|
+
const logger = {
|
|
52
|
+
debug: console.debug,
|
|
53
|
+
info: console.info,
|
|
54
|
+
warn: console.warn,
|
|
55
|
+
error: console.error
|
|
56
|
+
};
|
|
57
|
+
const paths = (0, _stryke_env_get_env_paths.getEnvPaths)({
|
|
58
|
+
appId: "power-plant",
|
|
59
|
+
orgId: "storm-software"
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Create a session context for the engine.
|
|
63
|
+
*
|
|
64
|
+
* @param session - The session for the context.
|
|
65
|
+
* @param userConfig - The user configuration.
|
|
66
|
+
* @returns A session context.
|
|
67
|
+
*/
|
|
68
|
+
async function createSessionContext(userConfig = {}) {
|
|
69
|
+
const cwd = userConfig.cwd || process.cwd();
|
|
70
|
+
const now = /* @__PURE__ */ new Date();
|
|
71
|
+
const storage = (0, unstorage.createStorage)({ driver: (0, unstorage_drivers_fs_lite.default)({ base: cwd }) });
|
|
72
|
+
const store = JSON.parse(await (0, _stryke_fs_read_file.readFileIfExisting)((0, _stryke_path_join_paths.joinPaths)(paths.data, ".local-store.json")) || "{}");
|
|
73
|
+
const device = store.device || node_os.default.hostname() || (0, _stryke_unique_id_uuid.uuid)();
|
|
74
|
+
const user = store.user || node_os.default.userInfo().username || (0, _stryke_unique_id_uuid.uuid)();
|
|
75
|
+
if (!(0, _stryke_type_checks_is_set_string.isSetString)(store.device) || !(0, _stryke_type_checks_is_set_string.isSetString)(store.user)) await (0, _stryke_fs_write_file.writeFile)((0, _stryke_path_join_paths.joinPaths)(paths.data, ".local-store.json"), JSON.stringify({
|
|
76
|
+
device,
|
|
77
|
+
user
|
|
78
|
+
}, null, 2));
|
|
79
|
+
return (0, defu.default)({
|
|
80
|
+
cwd,
|
|
81
|
+
session: {
|
|
82
|
+
id: (0, _stryke_unique_id_uuid.uuid)(),
|
|
83
|
+
createdAt: now,
|
|
84
|
+
updatedAt: now,
|
|
85
|
+
device,
|
|
86
|
+
user,
|
|
87
|
+
executions: []
|
|
88
|
+
}
|
|
89
|
+
}, userConfig, {
|
|
90
|
+
storage,
|
|
91
|
+
settings: {},
|
|
92
|
+
logger
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create an execution context for the engine.
|
|
97
|
+
*
|
|
98
|
+
* @param executionId - The ID of the execution.
|
|
99
|
+
* @param sessionContext - The session context.
|
|
100
|
+
* @param options - The options.
|
|
101
|
+
* @param schema - The schema.
|
|
102
|
+
* @param input - The input.
|
|
103
|
+
* @param output - The output.
|
|
104
|
+
* @returns A promise that resolves to an execution context.
|
|
105
|
+
*/
|
|
106
|
+
async function createExecutionContext(executionId, sessionContext, options, schema, input, output) {
|
|
107
|
+
const documents = {};
|
|
108
|
+
const addDocument = (pathOrDocument, document) => {
|
|
109
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(pathOrDocument)) documents[pathOrDocument] = (0, defu.default)({ path: pathOrDocument }, document, {
|
|
110
|
+
chunks: [],
|
|
111
|
+
meta: {}
|
|
112
|
+
});
|
|
113
|
+
else documents[pathOrDocument.path] = (0, defu.default)(pathOrDocument, document);
|
|
114
|
+
};
|
|
115
|
+
let specValue;
|
|
116
|
+
const context = {
|
|
117
|
+
...sessionContext,
|
|
118
|
+
id: executionId,
|
|
119
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
120
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
121
|
+
options,
|
|
122
|
+
schema,
|
|
123
|
+
input,
|
|
124
|
+
output,
|
|
125
|
+
documents,
|
|
126
|
+
spec() {
|
|
127
|
+
if (!specValue) throw new Error("The specification was accessed prior to the input processing.");
|
|
128
|
+
return specValue;
|
|
129
|
+
},
|
|
130
|
+
addDocument,
|
|
131
|
+
meta: {
|
|
132
|
+
id: executionId,
|
|
133
|
+
executedAt: /* @__PURE__ */ new Date(),
|
|
134
|
+
executedBy: ""
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
Object.defineProperty(context, "~spec", {
|
|
138
|
+
get() {
|
|
139
|
+
return specValue;
|
|
140
|
+
},
|
|
141
|
+
set(value) {
|
|
142
|
+
specValue = value;
|
|
143
|
+
},
|
|
144
|
+
enumerable: false
|
|
145
|
+
});
|
|
146
|
+
return context;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/lib/extract.ts
|
|
151
|
+
async function extractExecution(execution, _spec, _options) {
|
|
152
|
+
return execution;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/lib/schema.ts
|
|
157
|
+
/**
|
|
158
|
+
* Extracts and normalizes {@link SchemaMetaConfig | schema metadata} from a given {@link SchemaMetaConfig}. This function ensures that the metadata is in a consistent format, converting version numbers to strings and filtering out any invalid or empty tags.
|
|
159
|
+
*
|
|
160
|
+
* @param schema - The schema from which to extract metadata.
|
|
161
|
+
* @param input - The schema metadata input to extract and normalize.
|
|
162
|
+
* @returns The normalized schema metadata.
|
|
163
|
+
*/
|
|
164
|
+
function extractSchemaMeta(schema, input) {
|
|
165
|
+
const jsonSchema = schema?.schema ?? {};
|
|
166
|
+
const meta = require_helpers_meta.resolveMeta(schema, input);
|
|
167
|
+
meta.description = require_helpers_meta.resolveMetaDescription(`Accepts a ${meta.title ?? ""} specification and processes it with a {title} sink.`, jsonSchema, meta, input?.description);
|
|
168
|
+
meta.examples = require_helpers_meta.resolveMetaExample(jsonSchema, meta, input?.examples);
|
|
169
|
+
return meta;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Normalizes any accepted schema input into a concrete schema descriptor.
|
|
173
|
+
*
|
|
174
|
+
* @param input - The schema input to normalize.
|
|
175
|
+
* @param options - Optional options for resolving the schema input.
|
|
176
|
+
* @returns A promise that resolves to a normalized schema descriptor.
|
|
177
|
+
*/
|
|
178
|
+
async function createSchema(input, options = {}) {
|
|
179
|
+
const { meta, schema } = require_helpers_type_checks.isSchemaConfigObject(input) ? input : {
|
|
180
|
+
schema: input,
|
|
181
|
+
meta: {}
|
|
182
|
+
};
|
|
183
|
+
const resolvedSchema = await (0, _power_plant_schema.extractSchemaWithSource)(schema, options);
|
|
184
|
+
return {
|
|
185
|
+
...resolvedSchema,
|
|
186
|
+
meta: extractSchemaMeta(resolvedSchema, meta)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Ensures resolved input/output schema overrides do not contradict the generator schema.
|
|
191
|
+
*
|
|
192
|
+
* @param baseSchema - The resolved generator schema.
|
|
193
|
+
* @param input - The resolved generator input descriptor.
|
|
194
|
+
* @param output - The resolved generator output descriptor.
|
|
195
|
+
*/
|
|
196
|
+
function assertGeneratorConfigSchemasDoNotContradict(baseSchema, input, output) {
|
|
197
|
+
if (input && input.schema !== baseSchema) (0, _power_plant_schema.assertSchemasDoNotContradict)(baseSchema.schema, input.schema.schema, "input");
|
|
198
|
+
if (output && output.schema !== baseSchema) (0, _power_plant_schema.assertSchemasDoNotContradict)(baseSchema.schema, output.schema.schema, "output");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/lib/input.ts
|
|
203
|
+
/**
|
|
204
|
+
* Extracts and normalizes input metadata from a given configuration. This function ensures that the metadata is in a consistent format, converting version numbers to strings and filtering out any invalid or empty tags.
|
|
205
|
+
*
|
|
206
|
+
* @param schema - The schema that the input input is expected to conform to.
|
|
207
|
+
* @param input - The input metadata input to extract and normalize.
|
|
208
|
+
* @returns The normalized input metadata.
|
|
209
|
+
*/
|
|
210
|
+
function extractInputMeta(schema, input) {
|
|
211
|
+
const jsonSchema = schema?.schema ?? {};
|
|
212
|
+
const meta = require_helpers_meta.resolveMeta(schema, input);
|
|
213
|
+
meta.description = require_helpers_meta.resolveMetaDescription(`Determines the ${meta.title ?? ""} specification from a {title} input.`, jsonSchema, meta, input?.description);
|
|
214
|
+
return meta;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Normalizes any accepted input configuration into a concrete input descriptor.
|
|
218
|
+
*
|
|
219
|
+
* @param schema - The schema that the specification is expected to conform to.
|
|
220
|
+
* @param config - The input configuration to normalize.
|
|
221
|
+
* @param options - Optional options for resolving the input configuration.
|
|
222
|
+
* @returns A promise that resolves to a normalized input descriptor.
|
|
223
|
+
*/
|
|
224
|
+
async function createInput(schema, config, options = {}) {
|
|
225
|
+
const { input, meta, schema: inputSchema } = require_helpers_type_checks.isInputConfigObject(config) ? config : {
|
|
226
|
+
input: config,
|
|
227
|
+
meta: {}
|
|
228
|
+
};
|
|
229
|
+
let resolvedSchema = schema;
|
|
230
|
+
if (inputSchema) {
|
|
231
|
+
let resolvedInputSchema;
|
|
232
|
+
if ((0, _stryke_resolve_type_checks.isLoadReference)(inputSchema)) try {
|
|
233
|
+
resolvedInputSchema = await (0, _stryke_resolve_load.load)(inputSchema, options);
|
|
234
|
+
} catch {}
|
|
235
|
+
else resolvedInputSchema = inputSchema;
|
|
236
|
+
if (resolvedInputSchema) {
|
|
237
|
+
resolvedSchema = await createSchema(resolvedInputSchema, options);
|
|
238
|
+
resolvedSchema.schema = (0, _power_plant_schema.mergeMetadata)(resolvedSchema.schema, schema.schema);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
let resolvedInput;
|
|
242
|
+
if ((0, _stryke_resolve_type_checks.isLoadReference)(input)) try {
|
|
243
|
+
const loaded = await (0, _stryke_resolve_load.load)(input, options);
|
|
244
|
+
if (require_helpers_type_checks.isInputConfigObject(loaded)) resolvedInput = await createInput(resolvedSchema, loaded.input, options).then((s) => s.input);
|
|
245
|
+
else resolvedInput = loaded;
|
|
246
|
+
} catch {}
|
|
247
|
+
if (!resolvedInput) resolvedInput = input;
|
|
248
|
+
return {
|
|
249
|
+
schema: resolvedSchema,
|
|
250
|
+
input: resolvedInput,
|
|
251
|
+
meta: extractInputMeta(resolvedSchema, meta)
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/lib/output.ts
|
|
257
|
+
/**
|
|
258
|
+
* Extracts and normalizes output metadata from a given configuration. This function ensures that the metadata is in a consistent format, converting version numbers to strings and filtering out any invalid or empty tags.
|
|
259
|
+
*
|
|
260
|
+
* @param schema - The schema that the specification is expected to conform to.
|
|
261
|
+
* @param config - The output metadata config to extract and normalize.
|
|
262
|
+
* @returns The normalized output metadata.
|
|
263
|
+
*/
|
|
264
|
+
function extractOutputMeta(schema, config) {
|
|
265
|
+
const jsonSchema = schema?.schema ?? {};
|
|
266
|
+
const meta = require_helpers_meta.resolveMeta(schema, config);
|
|
267
|
+
meta.description = require_helpers_meta.resolveMetaDescription(`Accepts a ${meta.title ?? ""} specification and processes it with a {title} output.`, jsonSchema, meta, config?.description);
|
|
268
|
+
return meta;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Normalizes any accepted output config into a concrete output descriptor.
|
|
272
|
+
*
|
|
273
|
+
* @param schema - The schema that the output config is expected to conform to.
|
|
274
|
+
* @param config - The output config to normalize.
|
|
275
|
+
* @param options - Optional options for resolving the output config.
|
|
276
|
+
* @returns A promise that resolves to a normalized output descriptor.
|
|
277
|
+
*/
|
|
278
|
+
async function createOutput(schema, config, options = {}) {
|
|
279
|
+
const { output, meta, schema: configSchema } = require_helpers_type_checks.isOutputConfigObject(config) ? config : {
|
|
280
|
+
output: config,
|
|
281
|
+
meta: {}
|
|
282
|
+
};
|
|
283
|
+
let resolvedSchema = schema;
|
|
284
|
+
if (configSchema) {
|
|
285
|
+
let resolvedConfigSchema;
|
|
286
|
+
if ((0, _stryke_resolve_type_checks.isLoadReference)(configSchema)) try {
|
|
287
|
+
resolvedConfigSchema = await (0, _stryke_resolve_load.load)(configSchema, options);
|
|
288
|
+
} catch {}
|
|
289
|
+
else resolvedConfigSchema = configSchema;
|
|
290
|
+
if (resolvedConfigSchema) {
|
|
291
|
+
resolvedSchema = await createSchema(resolvedConfigSchema, options);
|
|
292
|
+
resolvedSchema.schema = (0, _power_plant_schema.mergeMetadata)(resolvedSchema.schema, schema.schema);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
let resolvedOutput;
|
|
296
|
+
if ((0, _stryke_resolve_type_checks.isLoadReference)(output)) try {
|
|
297
|
+
const loaded = await (0, _stryke_resolve_load.load)(output, options);
|
|
298
|
+
if (require_helpers_type_checks.isOutputConfigObject(loaded)) resolvedOutput = await createOutput(resolvedSchema, loaded.output, options).then((s) => s.output);
|
|
299
|
+
else resolvedOutput = loaded;
|
|
300
|
+
} catch {}
|
|
301
|
+
if (!resolvedOutput) resolvedOutput = output;
|
|
302
|
+
return {
|
|
303
|
+
schema: resolvedSchema,
|
|
304
|
+
output: resolvedOutput,
|
|
305
|
+
meta: extractOutputMeta(resolvedSchema, meta)
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/lib/generator.ts
|
|
311
|
+
/**
|
|
312
|
+
* Creates a generator from raw schema/input/output configurations and resolves all descriptors.
|
|
313
|
+
*
|
|
314
|
+
* @remarks
|
|
315
|
+
* This function is used to create a generator from raw schema, input, and output configurations. It resolves all descriptors and returns a fully constructed generator that can be used to generate output based on the provided schema and options.
|
|
316
|
+
*
|
|
317
|
+
* @template TSpec - The type of the specification that the generator will produce.
|
|
318
|
+
* @template TOptions - The type of the options that will be passed to the generator during generation.
|
|
319
|
+
* @param config - The generator configuration containing schema, input, output, and optional meta information.
|
|
320
|
+
* @param options - Optional extraction options for schema, input, and output.
|
|
321
|
+
* @returns A promise that resolves to a fully constructed generator.
|
|
322
|
+
*/
|
|
323
|
+
async function createGenerator(executionId, sessionContext, config, options = {}) {
|
|
324
|
+
let configObject;
|
|
325
|
+
if (require_helpers_type_checks.isGeneratorConfigObject(config)) configObject = config;
|
|
326
|
+
else configObject = await (0, _stryke_resolve_load.load)(config, {
|
|
327
|
+
fs: (0, _power_plant_schema_storage.mapStorageToFileSystem)(sessionContext.storage),
|
|
328
|
+
...options
|
|
329
|
+
});
|
|
330
|
+
if (!configObject.schema) configObject.schema = { type: "any" };
|
|
331
|
+
const schema = await createSchema(configObject.schema, {
|
|
332
|
+
storage: sessionContext.storage,
|
|
333
|
+
tsconfig: options.tsconfig,
|
|
334
|
+
...options
|
|
335
|
+
});
|
|
336
|
+
let inputConfig = configObject.input;
|
|
337
|
+
if (!inputConfig) if (options.inputPath) inputConfig = "@power-plant/unstorage-input";
|
|
338
|
+
else throw new Error("No input configuration provided. Please provide an input configuration, a valid specification, or a `inputPath` option that points to a valid input file.");
|
|
339
|
+
let outputConfig = configObject.output;
|
|
340
|
+
if (!outputConfig) outputConfig = "@power-plant/unstorage-output";
|
|
341
|
+
const [input, output] = await Promise.all([createInput(schema, inputConfig, {
|
|
342
|
+
storage: sessionContext.storage,
|
|
343
|
+
...options
|
|
344
|
+
}), createOutput(schema, outputConfig, {
|
|
345
|
+
storage: sessionContext.storage,
|
|
346
|
+
...options
|
|
347
|
+
})]);
|
|
348
|
+
assertGeneratorConfigSchemasDoNotContradict(schema, input, output);
|
|
349
|
+
const generator = async (options) => {
|
|
350
|
+
const context = await createExecutionContext(executionId, sessionContext, options, schema, input, output);
|
|
351
|
+
return require_context.callAsyncExecutionContext(context, async () => {
|
|
352
|
+
const spec = (0, _stryke_type_checks_is_function.isFunction)(input.input) ? await input.input({
|
|
353
|
+
storage: context.storage,
|
|
354
|
+
...options
|
|
355
|
+
}) : input.input;
|
|
356
|
+
context["~spec"] = spec;
|
|
357
|
+
let generatorFn;
|
|
358
|
+
if ((0, _stryke_type_checks_is_function.isFunction)(configObject.generator)) generatorFn = configObject.generator;
|
|
359
|
+
else generatorFn = await (0, _stryke_resolve_load.load)(configObject.generator, {
|
|
360
|
+
storage: context.storage,
|
|
361
|
+
...options
|
|
362
|
+
});
|
|
363
|
+
const documents = await generatorFn(spec, options);
|
|
364
|
+
return {
|
|
365
|
+
spec,
|
|
366
|
+
options,
|
|
367
|
+
documents,
|
|
368
|
+
returns: await output.output(spec, options, documents)
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
return {
|
|
373
|
+
meta: configObject.meta,
|
|
374
|
+
schema,
|
|
375
|
+
input,
|
|
376
|
+
output,
|
|
377
|
+
generator
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/execute.ts
|
|
383
|
+
/**
|
|
384
|
+
* Creates an execution function that can be used to execute a generator.
|
|
385
|
+
*
|
|
386
|
+
* @remarks
|
|
387
|
+
* This function is used to create an execution function that can be used to execute a generator. It creates a new execution context and returns an execution function that can be used to execute the generator with the given configuration and options.
|
|
388
|
+
*
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```ts
|
|
392
|
+
* import { createExecute } from "@power-plant/core";
|
|
393
|
+
*
|
|
394
|
+
* // First, create an execution function with a custom configuration
|
|
395
|
+
* const execute = await createExecute({
|
|
396
|
+
* ...
|
|
397
|
+
* });
|
|
398
|
+
*
|
|
399
|
+
* // Then, execute the generator
|
|
400
|
+
* const result = await execute("my-generator", {
|
|
401
|
+
* ...
|
|
402
|
+
* });
|
|
403
|
+
* ```
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* import { createExecute } from "@power-plant/core";
|
|
408
|
+
*
|
|
409
|
+
* // First, create an execution function with a custom configuration
|
|
410
|
+
* const execute = await createExecute({
|
|
411
|
+
* ...
|
|
412
|
+
* });
|
|
413
|
+
*
|
|
414
|
+
* // Then, execute the generator
|
|
415
|
+
* const result = await execute({
|
|
416
|
+
* generator: (spec, options) => { ... },
|
|
417
|
+
* ...
|
|
418
|
+
* });
|
|
419
|
+
* ```
|
|
420
|
+
*
|
|
421
|
+
* @template TSpec - The type of the specification that the generator will produce.
|
|
422
|
+
* @template TOptions - The type of the options that will be passed to the generator during generation.
|
|
423
|
+
* @template TReturns - The type of the returns that the generator will produce.
|
|
424
|
+
* @param userConfig - The user configuration for the engine.
|
|
425
|
+
* @returns A promise that resolves to an execution function.
|
|
426
|
+
*/
|
|
427
|
+
async function createExecute(userConfig = {}) {
|
|
428
|
+
const context = await createSessionContext(userConfig);
|
|
429
|
+
const execute = async (config, options = {}) => require_context.callAsyncSessionContext(context, async () => {
|
|
430
|
+
const executionId = (0, _stryke_unique_id_uuid.uuid)();
|
|
431
|
+
const { generator } = await createGenerator(executionId, context, config, options);
|
|
432
|
+
const { documents, returns, spec, options: returnedOptions } = await generator(options);
|
|
433
|
+
const execution = await extractExecution({
|
|
434
|
+
documents: Object.fromEntries(Object.entries(documents).map(([path, document]) => [path, {
|
|
435
|
+
...document,
|
|
436
|
+
path,
|
|
437
|
+
meta: { executionId }
|
|
438
|
+
}])),
|
|
439
|
+
meta: {
|
|
440
|
+
executionId,
|
|
441
|
+
executedAt: /* @__PURE__ */ new Date(),
|
|
442
|
+
executedBy: context.session.user
|
|
443
|
+
}
|
|
444
|
+
}, spec, returnedOptions);
|
|
445
|
+
context.session.executions.push(execution);
|
|
446
|
+
return returns;
|
|
447
|
+
});
|
|
448
|
+
return execute;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Executes a generator with a given configuration and options.
|
|
452
|
+
*
|
|
453
|
+
* @remarks
|
|
454
|
+
* This function is used to execute a generator with a given configuration and options. It creates a new execution context and returns an execution function that can be used to execute the generator with the given configuration and options.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* import { execute } from "@power-plant/core";
|
|
459
|
+
*
|
|
460
|
+
* // Create and execute the generator
|
|
461
|
+
* const result = await execute("my-generator", {
|
|
462
|
+
* ...
|
|
463
|
+
* });
|
|
464
|
+
* ```
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* import { execute } from "@power-plant/core";
|
|
469
|
+
*
|
|
470
|
+
* // Create and execute the generator
|
|
471
|
+
* const result = await execute({
|
|
472
|
+
* generator: (spec, options) => { ... },
|
|
473
|
+
* }, {
|
|
474
|
+
* ...
|
|
475
|
+
* });
|
|
476
|
+
* ```
|
|
477
|
+
*
|
|
478
|
+
* @template TSpec - The type of the specification that the generator will produce.
|
|
479
|
+
* @template TOptions - The type of the options that will be passed to the generator during generation.
|
|
480
|
+
* @template TReturns - The type of the returns that the generator will produce.
|
|
481
|
+
* @param config - The configuration for the generator.
|
|
482
|
+
* @param options - The options for the generator.
|
|
483
|
+
* @returns A promise that resolves to the returns of the generator.
|
|
484
|
+
*/
|
|
485
|
+
async function execute(config, options = {}) {
|
|
486
|
+
return (await createExecute(options))(config, options);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
//#endregion
|
|
490
|
+
Object.defineProperty(exports, 'createExecute', {
|
|
491
|
+
enumerable: true,
|
|
492
|
+
get: function () {
|
|
493
|
+
return createExecute;
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
Object.defineProperty(exports, 'execute', {
|
|
497
|
+
enumerable: true,
|
|
498
|
+
get: function () {
|
|
499
|
+
return execute;
|
|
500
|
+
}
|
|
501
|
+
});
|