@tiangong-lca/cli 0.0.1
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/README.md +368 -0
- package/bin/tiangong.d.ts +1 -0
- package/bin/tiangong.js +32 -0
- package/dist/scripts/assert-full-coverage.js +77 -0
- package/dist/scripts/assert-full-coverage.js.map +1 -0
- package/dist/src/cli.js +2740 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/lib/artifacts.js +86 -0
- package/dist/src/lib/artifacts.js.map +1 -0
- package/dist/src/lib/dotenv.js +36 -0
- package/dist/src/lib/dotenv.js.map +1 -0
- package/dist/src/lib/env.js +139 -0
- package/dist/src/lib/env.js.map +1 -0
- package/dist/src/lib/errors.js +38 -0
- package/dist/src/lib/errors.js.map +1 -0
- package/dist/src/lib/flow-build-alias-map.js +299 -0
- package/dist/src/lib/flow-build-alias-map.js.map +1 -0
- package/dist/src/lib/flow-get.js +81 -0
- package/dist/src/lib/flow-get.js.map +1 -0
- package/dist/src/lib/flow-governance.js +164 -0
- package/dist/src/lib/flow-governance.js.map +1 -0
- package/dist/src/lib/flow-list.js +187 -0
- package/dist/src/lib/flow-list.js.map +1 -0
- package/dist/src/lib/flow-publish-reviewed-data.js +808 -0
- package/dist/src/lib/flow-publish-reviewed-data.js.map +1 -0
- package/dist/src/lib/flow-publish-version.js +541 -0
- package/dist/src/lib/flow-publish-version.js.map +1 -0
- package/dist/src/lib/flow-read.js +310 -0
- package/dist/src/lib/flow-read.js.map +1 -0
- package/dist/src/lib/flow-regen-product.js +1396 -0
- package/dist/src/lib/flow-regen-product.js.map +1 -0
- package/dist/src/lib/flow-remediate.js +821 -0
- package/dist/src/lib/flow-remediate.js.map +1 -0
- package/dist/src/lib/http.js +45 -0
- package/dist/src/lib/http.js.map +1 -0
- package/dist/src/lib/io.js +30 -0
- package/dist/src/lib/io.js.map +1 -0
- package/dist/src/lib/kb-search.js +83 -0
- package/dist/src/lib/kb-search.js.map +1 -0
- package/dist/src/lib/lifecyclemodel-auto-build.js +1328 -0
- package/dist/src/lib/lifecyclemodel-auto-build.js.map +1 -0
- package/dist/src/lib/lifecyclemodel-orchestrate.js +1556 -0
- package/dist/src/lib/lifecyclemodel-orchestrate.js.map +1 -0
- package/dist/src/lib/lifecyclemodel-publish-build.js +296 -0
- package/dist/src/lib/lifecyclemodel-publish-build.js.map +1 -0
- package/dist/src/lib/lifecyclemodel-publish-resulting-process.js +101 -0
- package/dist/src/lib/lifecyclemodel-publish-resulting-process.js.map +1 -0
- package/dist/src/lib/lifecyclemodel-resulting-process.js +1152 -0
- package/dist/src/lib/lifecyclemodel-resulting-process.js.map +1 -0
- package/dist/src/lib/lifecyclemodel-validate-build.js +238 -0
- package/dist/src/lib/lifecyclemodel-validate-build.js.map +1 -0
- package/dist/src/lib/llm.js +383 -0
- package/dist/src/lib/llm.js.map +1 -0
- package/dist/src/lib/process-auto-build.js +717 -0
- package/dist/src/lib/process-auto-build.js.map +1 -0
- package/dist/src/lib/process-batch-build.js +409 -0
- package/dist/src/lib/process-batch-build.js.map +1 -0
- package/dist/src/lib/process-get.js +66 -0
- package/dist/src/lib/process-get.js.map +1 -0
- package/dist/src/lib/process-publish-build.js +451 -0
- package/dist/src/lib/process-publish-build.js.map +1 -0
- package/dist/src/lib/process-resume-build.js +364 -0
- package/dist/src/lib/process-resume-build.js.map +1 -0
- package/dist/src/lib/publish.js +562 -0
- package/dist/src/lib/publish.js.map +1 -0
- package/dist/src/lib/remote.js +88 -0
- package/dist/src/lib/remote.js.map +1 -0
- package/dist/src/lib/review-flow.js +1110 -0
- package/dist/src/lib/review-flow.js.map +1 -0
- package/dist/src/lib/review-lifecyclemodel.js +727 -0
- package/dist/src/lib/review-lifecyclemodel.js.map +1 -0
- package/dist/src/lib/review-process.js +702 -0
- package/dist/src/lib/review-process.js.map +1 -0
- package/dist/src/lib/run.js +106 -0
- package/dist/src/lib/run.js.map +1 -0
- package/dist/src/lib/state-lock.js +150 -0
- package/dist/src/lib/state-lock.js.map +1 -0
- package/dist/src/lib/supabase-client.js +269 -0
- package/dist/src/lib/supabase-client.js.map +1 -0
- package/dist/src/lib/supabase-json-ordered-write.js +186 -0
- package/dist/src/lib/supabase-json-ordered-write.js.map +1 -0
- package/dist/src/lib/supabase-rest.js +138 -0
- package/dist/src/lib/supabase-rest.js.map +1 -0
- package/dist/src/lib/supabase-session.js +424 -0
- package/dist/src/lib/supabase-session.js.map +1 -0
- package/dist/src/lib/tidas-sdk-package-validator.js +493 -0
- package/dist/src/lib/tidas-sdk-package-validator.js.map +1 -0
- package/dist/src/lib/unstructured.js +203 -0
- package/dist/src/lib/unstructured.js.map +1 -0
- package/dist/src/lib/user-api-key.js +75 -0
- package/dist/src/lib/user-api-key.js.map +1 -0
- package/dist/src/lib/validation.js +191 -0
- package/dist/src/lib/validation.js.map +1 -0
- package/dist/src/main.js +38 -0
- package/dist/src/main.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { CliError } from './errors.js';
|
|
3
|
+
import { writeJsonArtifact } from './artifacts.js';
|
|
4
|
+
import { readJsonInput } from './io.js';
|
|
5
|
+
import { buildRunId, resolveRunLayout } from './run.js';
|
|
6
|
+
import { hasSupabaseRestRuntime, syncSupabaseJsonOrderedRecord, } from './supabase-json-ordered-write.js';
|
|
7
|
+
const DEFAULT_MAX_ATTEMPTS = 5;
|
|
8
|
+
const DEFAULT_RETRY_DELAY_SECONDS = 2.0;
|
|
9
|
+
const DEFAULT_DATASET_VERSION = '01.01.000';
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function ensure_list(value) {
|
|
14
|
+
if (value === undefined || value === null) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return Array.isArray(value) ? value : [value];
|
|
18
|
+
}
|
|
19
|
+
function first_non_empty(...values) {
|
|
20
|
+
for (const value of values) {
|
|
21
|
+
if (typeof value === 'string' && value.trim()) {
|
|
22
|
+
return value.trim();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function to_positive_integer(value, defaultValue) {
|
|
28
|
+
if (value === undefined || value === null || value === '') {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
31
|
+
const parsed = typeof value === 'number'
|
|
32
|
+
? value
|
|
33
|
+
: typeof value === 'string'
|
|
34
|
+
? Number.parseInt(value, 10)
|
|
35
|
+
: Number.NaN;
|
|
36
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
37
|
+
throw new CliError('Publish request expected a positive integer value.', {
|
|
38
|
+
code: 'PUBLISH_INVALID_INTEGER',
|
|
39
|
+
exitCode: 2,
|
|
40
|
+
details: value,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
function to_non_negative_number(value, defaultValue) {
|
|
46
|
+
if (value === undefined || value === null || value === '') {
|
|
47
|
+
return defaultValue;
|
|
48
|
+
}
|
|
49
|
+
const parsed = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN;
|
|
50
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
51
|
+
throw new CliError('Publish request expected a non-negative number value.', {
|
|
52
|
+
code: 'PUBLISH_INVALID_NUMBER',
|
|
53
|
+
exitCode: 2,
|
|
54
|
+
details: value,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return parsed;
|
|
58
|
+
}
|
|
59
|
+
function to_boolean(value, defaultValue) {
|
|
60
|
+
return value === undefined ? defaultValue : Boolean(value);
|
|
61
|
+
}
|
|
62
|
+
function resolve_path(baseDir, value) {
|
|
63
|
+
return path.resolve(baseDir, value);
|
|
64
|
+
}
|
|
65
|
+
function load_json_object(filePath) {
|
|
66
|
+
const value = readJsonInput(filePath);
|
|
67
|
+
if (!isRecord(value)) {
|
|
68
|
+
throw new CliError(`Expected JSON object input: ${filePath}`, {
|
|
69
|
+
code: 'PUBLISH_INPUT_NOT_OBJECT',
|
|
70
|
+
exitCode: 2,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
function default_out_dir(baseDir, commit, now = new Date()) {
|
|
76
|
+
const runId = buildRunId({
|
|
77
|
+
namespace: 'publish',
|
|
78
|
+
operation: commit ? 'commit' : 'dry_run',
|
|
79
|
+
now,
|
|
80
|
+
});
|
|
81
|
+
return resolveRunLayout(path.join(baseDir, 'artifacts'), 'publish', runId).runRoot;
|
|
82
|
+
}
|
|
83
|
+
function serialize_error(error) {
|
|
84
|
+
if (error instanceof Error) {
|
|
85
|
+
return { message: error.message };
|
|
86
|
+
}
|
|
87
|
+
return { message: String(error) };
|
|
88
|
+
}
|
|
89
|
+
function extract_lifecyclemodel_identity(payload) {
|
|
90
|
+
const root = isRecord(payload.lifeCycleModelDataSet) ? payload.lifeCycleModelDataSet : payload;
|
|
91
|
+
const lifeCycleModelInformation = isRecord(root.lifeCycleModelInformation)
|
|
92
|
+
? root.lifeCycleModelInformation
|
|
93
|
+
: {};
|
|
94
|
+
const dataSetInformation = isRecord(lifeCycleModelInformation.dataSetInformation)
|
|
95
|
+
? lifeCycleModelInformation.dataSetInformation
|
|
96
|
+
: {};
|
|
97
|
+
const administrativeInformation = isRecord(root.administrativeInformation)
|
|
98
|
+
? root.administrativeInformation
|
|
99
|
+
: {};
|
|
100
|
+
const publicationAndOwnership = isRecord(administrativeInformation.publicationAndOwnership)
|
|
101
|
+
? administrativeInformation.publicationAndOwnership
|
|
102
|
+
: {};
|
|
103
|
+
const datasetId = first_non_empty(payload['@id'], payload.id, dataSetInformation['common:UUID']);
|
|
104
|
+
const version = first_non_empty(payload['@version'], payload.version, publicationAndOwnership['common:dataSetVersion'], DEFAULT_DATASET_VERSION);
|
|
105
|
+
if (!datasetId) {
|
|
106
|
+
throw new CliError('Lifecycle model payload missing @id/id.', {
|
|
107
|
+
code: 'PUBLISH_LIFECYCLEMODEL_ID_MISSING',
|
|
108
|
+
exitCode: 2,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return [datasetId, version];
|
|
112
|
+
}
|
|
113
|
+
function extract_process_identity(payload) {
|
|
114
|
+
const root = isRecord(payload.processDataSet) ? payload.processDataSet : payload;
|
|
115
|
+
const processInformation = isRecord(root.processInformation) ? root.processInformation : {};
|
|
116
|
+
const dataSetInformation = isRecord(processInformation.dataSetInformation)
|
|
117
|
+
? processInformation.dataSetInformation
|
|
118
|
+
: {};
|
|
119
|
+
const administrativeInformation = isRecord(root.administrativeInformation)
|
|
120
|
+
? root.administrativeInformation
|
|
121
|
+
: {};
|
|
122
|
+
const publicationAndOwnership = isRecord(administrativeInformation.publicationAndOwnership)
|
|
123
|
+
? administrativeInformation.publicationAndOwnership
|
|
124
|
+
: {};
|
|
125
|
+
const datasetId = first_non_empty(dataSetInformation['common:UUID']);
|
|
126
|
+
const version = first_non_empty(publicationAndOwnership['common:dataSetVersion'], DEFAULT_DATASET_VERSION);
|
|
127
|
+
if (!datasetId) {
|
|
128
|
+
throw new CliError('Process payload missing processInformation.dataSetInformation.common:UUID.', {
|
|
129
|
+
code: 'PUBLISH_PROCESS_ID_MISSING',
|
|
130
|
+
exitCode: 2,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return [datasetId, version];
|
|
134
|
+
}
|
|
135
|
+
function extract_source_identity(payload) {
|
|
136
|
+
const root = isRecord(payload.sourceDataSet) ? payload.sourceDataSet : payload;
|
|
137
|
+
const sourceInformation = isRecord(root.sourceInformation) ? root.sourceInformation : {};
|
|
138
|
+
const dataSetInformation = isRecord(sourceInformation.dataSetInformation)
|
|
139
|
+
? sourceInformation.dataSetInformation
|
|
140
|
+
: {};
|
|
141
|
+
const administrativeInformation = isRecord(root.administrativeInformation)
|
|
142
|
+
? root.administrativeInformation
|
|
143
|
+
: {};
|
|
144
|
+
const publicationAndOwnership = isRecord(administrativeInformation.publicationAndOwnership)
|
|
145
|
+
? administrativeInformation.publicationAndOwnership
|
|
146
|
+
: {};
|
|
147
|
+
const datasetId = first_non_empty(dataSetInformation['common:UUID']);
|
|
148
|
+
const version = first_non_empty(publicationAndOwnership['common:dataSetVersion'], DEFAULT_DATASET_VERSION);
|
|
149
|
+
if (!datasetId) {
|
|
150
|
+
throw new CliError('Source payload missing sourceInformation.dataSetInformation.common:UUID.', {
|
|
151
|
+
code: 'PUBLISH_SOURCE_ID_MISSING',
|
|
152
|
+
exitCode: 2,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return [datasetId, version];
|
|
156
|
+
}
|
|
157
|
+
function load_dataset_entry(entry, baseDir) {
|
|
158
|
+
if (isRecord(entry)) {
|
|
159
|
+
for (const key of ['json_ordered', 'jsonOrdered', 'payload']) {
|
|
160
|
+
const candidate = entry[key];
|
|
161
|
+
if (isRecord(candidate)) {
|
|
162
|
+
return candidate;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const fileValue = first_non_empty(entry.file, entry.path);
|
|
166
|
+
if (fileValue) {
|
|
167
|
+
return load_json_object(resolve_path(baseDir, fileValue));
|
|
168
|
+
}
|
|
169
|
+
return entry;
|
|
170
|
+
}
|
|
171
|
+
if (typeof entry === 'string' && entry.trim()) {
|
|
172
|
+
return load_json_object(resolve_path(baseDir, entry));
|
|
173
|
+
}
|
|
174
|
+
throw new CliError('Unsupported dataset entry in publish request.', {
|
|
175
|
+
code: 'PUBLISH_UNSUPPORTED_DATASET_ENTRY',
|
|
176
|
+
exitCode: 2,
|
|
177
|
+
details: entry,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function push_collected_entries(target, entries, origin) {
|
|
181
|
+
for (const entry of entries) {
|
|
182
|
+
target.push({ entry: entry, origin });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export function normalizePublishRequest(raw, options) {
|
|
186
|
+
if (!isRecord(raw)) {
|
|
187
|
+
throw new CliError('Publish request must be a JSON object.', {
|
|
188
|
+
code: 'PUBLISH_REQUEST_NOT_OBJECT',
|
|
189
|
+
exitCode: 2,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const requestDir = path.dirname(options.requestPath);
|
|
193
|
+
const inputs = isRecord(raw.inputs) ? raw.inputs : {};
|
|
194
|
+
const publish = isRecord(raw.publish) ? raw.publish : {};
|
|
195
|
+
const commit = options.commitOverride === undefined
|
|
196
|
+
? to_boolean(publish.commit, false)
|
|
197
|
+
: options.commitOverride;
|
|
198
|
+
const outDirValue = first_non_empty(options.outDirOverride, raw.out_dir, raw.output_dir);
|
|
199
|
+
const outDir = outDirValue
|
|
200
|
+
? resolve_path(requestDir, outDirValue)
|
|
201
|
+
: default_out_dir(requestDir, commit, options.now);
|
|
202
|
+
const relationMode = first_non_empty(publish.relation_mode, 'local_manifest_only');
|
|
203
|
+
if (relationMode !== 'local_manifest_only') {
|
|
204
|
+
throw new CliError("publish.relation_mode only supports 'local_manifest_only'.", {
|
|
205
|
+
code: 'PUBLISH_UNSUPPORTED_RELATION_MODE',
|
|
206
|
+
exitCode: 2,
|
|
207
|
+
details: relationMode,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
inputs: {
|
|
212
|
+
bundle_paths: ensure_list(inputs.bundle_paths)
|
|
213
|
+
.map((value) => String(value).trim())
|
|
214
|
+
.filter(Boolean)
|
|
215
|
+
.map((value) => resolve_path(requestDir, value)),
|
|
216
|
+
lifecyclemodels: ensure_list(inputs.lifecyclemodels),
|
|
217
|
+
processes: ensure_list(inputs.processes),
|
|
218
|
+
sources: ensure_list(inputs.sources),
|
|
219
|
+
relations: ensure_list(inputs.relations),
|
|
220
|
+
process_build_runs: ensure_list(inputs.process_build_runs),
|
|
221
|
+
},
|
|
222
|
+
publish: {
|
|
223
|
+
commit,
|
|
224
|
+
publish_lifecyclemodels: to_boolean(publish.publish_lifecyclemodels, true),
|
|
225
|
+
publish_processes: to_boolean(publish.publish_processes, true),
|
|
226
|
+
publish_sources: to_boolean(publish.publish_sources, true),
|
|
227
|
+
publish_relations: to_boolean(publish.publish_relations, true),
|
|
228
|
+
publish_process_build_runs: to_boolean(publish.publish_process_build_runs, true),
|
|
229
|
+
relation_mode: 'local_manifest_only',
|
|
230
|
+
max_attempts: to_positive_integer(publish.max_attempts, DEFAULT_MAX_ATTEMPTS),
|
|
231
|
+
retry_delay_seconds: to_non_negative_number(publish.retry_delay_seconds, DEFAULT_RETRY_DELAY_SECONDS),
|
|
232
|
+
process_build_forward_args: ensure_list(publish.process_build_forward_args)
|
|
233
|
+
.map((value) => String(value).trim())
|
|
234
|
+
.filter(Boolean),
|
|
235
|
+
},
|
|
236
|
+
out_dir: outDir,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
export function collectPublishInputs(normalized, requestBaseDir) {
|
|
240
|
+
const collected = {
|
|
241
|
+
bundle_paths: [...normalized.inputs.bundle_paths],
|
|
242
|
+
lifecyclemodels: [],
|
|
243
|
+
processes: [],
|
|
244
|
+
sources: [],
|
|
245
|
+
relations: [],
|
|
246
|
+
process_build_runs: [],
|
|
247
|
+
};
|
|
248
|
+
for (const bundlePath of normalized.inputs.bundle_paths) {
|
|
249
|
+
const bundle = load_json_object(bundlePath);
|
|
250
|
+
const origin = {
|
|
251
|
+
source: 'bundle',
|
|
252
|
+
base_dir: path.dirname(bundlePath),
|
|
253
|
+
bundle_path: bundlePath,
|
|
254
|
+
};
|
|
255
|
+
push_collected_entries(collected.lifecyclemodels, ensure_list(bundle.lifecyclemodels), origin);
|
|
256
|
+
push_collected_entries(collected.processes, [...ensure_list(bundle.projected_processes), ...ensure_list(bundle.processes)], origin);
|
|
257
|
+
push_collected_entries(collected.sources, ensure_list(bundle.sources), origin);
|
|
258
|
+
push_collected_entries(collected.relations, [...ensure_list(bundle.resulting_process_relations), ...ensure_list(bundle.relations)], origin);
|
|
259
|
+
push_collected_entries(collected.process_build_runs, ensure_list(bundle.process_build_runs), origin);
|
|
260
|
+
}
|
|
261
|
+
const directOrigin = {
|
|
262
|
+
source: 'input',
|
|
263
|
+
base_dir: requestBaseDir,
|
|
264
|
+
bundle_path: null,
|
|
265
|
+
};
|
|
266
|
+
push_collected_entries(collected.lifecyclemodels, normalized.inputs.lifecyclemodels, directOrigin);
|
|
267
|
+
push_collected_entries(collected.processes, normalized.inputs.processes, directOrigin);
|
|
268
|
+
push_collected_entries(collected.sources, normalized.inputs.sources, directOrigin);
|
|
269
|
+
push_collected_entries(collected.relations, normalized.inputs.relations, directOrigin);
|
|
270
|
+
push_collected_entries(collected.process_build_runs, normalized.inputs.process_build_runs, directOrigin);
|
|
271
|
+
return collected;
|
|
272
|
+
}
|
|
273
|
+
async function maybe_execute_dataset(report, payload, options) {
|
|
274
|
+
if (!options.commit) {
|
|
275
|
+
return report;
|
|
276
|
+
}
|
|
277
|
+
if (!options.executor) {
|
|
278
|
+
report.status = 'deferred_no_executor';
|
|
279
|
+
return report;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
report.execution = await options.executor({
|
|
283
|
+
table: options.table,
|
|
284
|
+
id: report.id,
|
|
285
|
+
version: report.version,
|
|
286
|
+
payload,
|
|
287
|
+
source: report.source,
|
|
288
|
+
bundle_path: report.bundle_path,
|
|
289
|
+
publish: options.publish,
|
|
290
|
+
});
|
|
291
|
+
report.status = 'executed';
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
report.status = 'failed';
|
|
295
|
+
report.error = serialize_error(error);
|
|
296
|
+
}
|
|
297
|
+
return report;
|
|
298
|
+
}
|
|
299
|
+
async function publish_lifecyclemodels(entries, options) {
|
|
300
|
+
const reports = [];
|
|
301
|
+
for (const item of entries) {
|
|
302
|
+
const payload = load_dataset_entry(item.entry, item.origin.base_dir);
|
|
303
|
+
const [datasetId, version] = extract_lifecyclemodel_identity(payload);
|
|
304
|
+
const report = {
|
|
305
|
+
table: 'lifecyclemodels',
|
|
306
|
+
id: datasetId,
|
|
307
|
+
version,
|
|
308
|
+
status: 'prepared',
|
|
309
|
+
source: item.origin.source,
|
|
310
|
+
bundle_path: item.origin.bundle_path,
|
|
311
|
+
};
|
|
312
|
+
reports.push(await maybe_execute_dataset(report, payload, {
|
|
313
|
+
...options,
|
|
314
|
+
table: 'lifecyclemodels',
|
|
315
|
+
executor: options.executor,
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
318
|
+
return reports;
|
|
319
|
+
}
|
|
320
|
+
async function publish_processes(entries, options) {
|
|
321
|
+
const reports = [];
|
|
322
|
+
for (const item of entries) {
|
|
323
|
+
const payload = load_dataset_entry(item.entry, item.origin.base_dir);
|
|
324
|
+
try {
|
|
325
|
+
const [datasetId, version] = extract_process_identity(payload);
|
|
326
|
+
const report = {
|
|
327
|
+
table: 'processes',
|
|
328
|
+
id: datasetId,
|
|
329
|
+
version,
|
|
330
|
+
status: 'prepared',
|
|
331
|
+
source: item.origin.source,
|
|
332
|
+
bundle_path: item.origin.bundle_path,
|
|
333
|
+
};
|
|
334
|
+
reports.push(await maybe_execute_dataset(report, payload, {
|
|
335
|
+
...options,
|
|
336
|
+
table: 'processes',
|
|
337
|
+
executor: options.executor,
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
const report = {
|
|
342
|
+
table: 'processes',
|
|
343
|
+
id: first_non_empty(payload['@id'], payload.id),
|
|
344
|
+
version: first_non_empty(payload['@version'], payload.version, DEFAULT_DATASET_VERSION),
|
|
345
|
+
status: 'deferred_projection_payload',
|
|
346
|
+
source: item.origin.source,
|
|
347
|
+
bundle_path: item.origin.bundle_path,
|
|
348
|
+
reason: error instanceof CliError && error.code === 'PUBLISH_PROCESS_ID_MISSING'
|
|
349
|
+
? 'Payload is not a canonical processDataSet wrapper; keep it in the publish bundle until a projection-to-process adapter exists.'
|
|
350
|
+
: serialize_error(error).message,
|
|
351
|
+
};
|
|
352
|
+
reports.push(report);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return reports;
|
|
356
|
+
}
|
|
357
|
+
async function publish_sources(entries, options) {
|
|
358
|
+
const reports = [];
|
|
359
|
+
for (const item of entries) {
|
|
360
|
+
const payload = load_dataset_entry(item.entry, item.origin.base_dir);
|
|
361
|
+
const [datasetId, version] = extract_source_identity(payload);
|
|
362
|
+
const report = {
|
|
363
|
+
table: 'sources',
|
|
364
|
+
id: datasetId,
|
|
365
|
+
version,
|
|
366
|
+
status: 'prepared',
|
|
367
|
+
source: item.origin.source,
|
|
368
|
+
bundle_path: item.origin.bundle_path,
|
|
369
|
+
};
|
|
370
|
+
reports.push(await maybe_execute_dataset(report, payload, {
|
|
371
|
+
...options,
|
|
372
|
+
table: 'sources',
|
|
373
|
+
executor: options.executor,
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
return reports;
|
|
377
|
+
}
|
|
378
|
+
async function publish_process_build_runs(entries, options) {
|
|
379
|
+
const reports = [];
|
|
380
|
+
for (const item of entries) {
|
|
381
|
+
const runId = typeof item.entry === 'string' ? item.entry.trim() : first_non_empty(item.entry.run_id);
|
|
382
|
+
if (!runId) {
|
|
383
|
+
throw new CliError('process_build_run entry missing run_id.', {
|
|
384
|
+
code: 'PUBLISH_PROCESS_BUILD_RUN_ID_MISSING',
|
|
385
|
+
exitCode: 2,
|
|
386
|
+
details: item.entry,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
const report = {
|
|
390
|
+
run_id: runId,
|
|
391
|
+
status: 'prepared',
|
|
392
|
+
source: item.origin.source,
|
|
393
|
+
bundle_path: item.origin.bundle_path,
|
|
394
|
+
forward_args: [...options.publish.process_build_forward_args],
|
|
395
|
+
};
|
|
396
|
+
if (!options.commit) {
|
|
397
|
+
reports.push(report);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (!options.executor) {
|
|
401
|
+
report.status = 'deferred_no_executor';
|
|
402
|
+
reports.push(report);
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
report.execution = await options.executor({
|
|
407
|
+
run_id: runId,
|
|
408
|
+
entry: item.entry,
|
|
409
|
+
source: item.origin.source,
|
|
410
|
+
bundle_path: item.origin.bundle_path,
|
|
411
|
+
forward_args: [...options.publish.process_build_forward_args],
|
|
412
|
+
publish: options.publish,
|
|
413
|
+
});
|
|
414
|
+
report.status = 'executed';
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
report.status = 'failed';
|
|
418
|
+
report.error = serialize_error(error);
|
|
419
|
+
}
|
|
420
|
+
reports.push(report);
|
|
421
|
+
}
|
|
422
|
+
return reports;
|
|
423
|
+
}
|
|
424
|
+
function build_relation_manifest(relations, publish, now) {
|
|
425
|
+
return {
|
|
426
|
+
generated_at_utc: now.toISOString(),
|
|
427
|
+
relation_mode: publish.relation_mode,
|
|
428
|
+
status: 'prepared_local_relation_manifest',
|
|
429
|
+
relations: publish.publish_relations ? relations.map((item) => item.entry) : [],
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function table_write_mode_for_publish() {
|
|
433
|
+
return 'upsert_current_version';
|
|
434
|
+
}
|
|
435
|
+
function build_default_dataset_executor(options) {
|
|
436
|
+
return async (args) => syncSupabaseJsonOrderedRecord({
|
|
437
|
+
table: options.table,
|
|
438
|
+
id: args.id,
|
|
439
|
+
version: args.version,
|
|
440
|
+
payload: args.payload,
|
|
441
|
+
writeMode: table_write_mode_for_publish(),
|
|
442
|
+
env: options.env,
|
|
443
|
+
fetchImpl: options.fetchImpl,
|
|
444
|
+
timeoutMs: options.timeoutMs,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function resolve_dataset_executors(options) {
|
|
448
|
+
const explicit = options.executors ?? {};
|
|
449
|
+
const env = options.env;
|
|
450
|
+
const fetchImpl = options.fetchImpl;
|
|
451
|
+
if (!env || !fetchImpl || !hasSupabaseRestRuntime(env)) {
|
|
452
|
+
return explicit;
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
lifecyclemodels: explicit.lifecyclemodels ??
|
|
456
|
+
build_default_dataset_executor({
|
|
457
|
+
table: 'lifecyclemodels',
|
|
458
|
+
env,
|
|
459
|
+
fetchImpl,
|
|
460
|
+
timeoutMs: options.timeoutMs,
|
|
461
|
+
}),
|
|
462
|
+
processes: explicit.processes ??
|
|
463
|
+
build_default_dataset_executor({
|
|
464
|
+
table: 'processes',
|
|
465
|
+
env,
|
|
466
|
+
fetchImpl,
|
|
467
|
+
timeoutMs: options.timeoutMs,
|
|
468
|
+
}),
|
|
469
|
+
sources: explicit.sources ??
|
|
470
|
+
build_default_dataset_executor({
|
|
471
|
+
table: 'sources',
|
|
472
|
+
env,
|
|
473
|
+
fetchImpl,
|
|
474
|
+
timeoutMs: options.timeoutMs,
|
|
475
|
+
}),
|
|
476
|
+
process_build_runs: explicit.process_build_runs,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
export async function runPublish(options) {
|
|
480
|
+
const requestPath = path.resolve(options.inputPath);
|
|
481
|
+
const requestDir = path.dirname(requestPath);
|
|
482
|
+
const raw = options.rawRequest ?? readJsonInput(requestPath);
|
|
483
|
+
const normalized = normalizePublishRequest(raw, {
|
|
484
|
+
requestPath,
|
|
485
|
+
outDirOverride: options.outDir ?? undefined,
|
|
486
|
+
commitOverride: options.commit ?? undefined,
|
|
487
|
+
now: options.now,
|
|
488
|
+
});
|
|
489
|
+
const collected = collectPublishInputs(normalized, requestDir);
|
|
490
|
+
const now = options.now ?? new Date();
|
|
491
|
+
const outDir = normalized.out_dir;
|
|
492
|
+
const executors = resolve_dataset_executors(options);
|
|
493
|
+
const files = {
|
|
494
|
+
normalized_request: path.join(outDir, 'normalized-request.json'),
|
|
495
|
+
collected_inputs: path.join(outDir, 'collected-inputs.json'),
|
|
496
|
+
relation_manifest: path.join(outDir, 'relation-manifest.json'),
|
|
497
|
+
publish_report: path.join(outDir, 'publish-report.json'),
|
|
498
|
+
};
|
|
499
|
+
writeJsonArtifact(files.normalized_request, normalized);
|
|
500
|
+
writeJsonArtifact(files.collected_inputs, collected);
|
|
501
|
+
const lifecyclemodels = normalized.publish.publish_lifecyclemodels
|
|
502
|
+
? await publish_lifecyclemodels(collected.lifecyclemodels, {
|
|
503
|
+
commit: normalized.publish.commit,
|
|
504
|
+
executor: executors.lifecyclemodels,
|
|
505
|
+
publish: normalized.publish,
|
|
506
|
+
})
|
|
507
|
+
: [];
|
|
508
|
+
const processes = normalized.publish.publish_processes
|
|
509
|
+
? await publish_processes(collected.processes, {
|
|
510
|
+
commit: normalized.publish.commit,
|
|
511
|
+
executor: executors.processes,
|
|
512
|
+
publish: normalized.publish,
|
|
513
|
+
})
|
|
514
|
+
: [];
|
|
515
|
+
const sources = normalized.publish.publish_sources
|
|
516
|
+
? await publish_sources(collected.sources, {
|
|
517
|
+
commit: normalized.publish.commit,
|
|
518
|
+
executor: executors.sources,
|
|
519
|
+
publish: normalized.publish,
|
|
520
|
+
})
|
|
521
|
+
: [];
|
|
522
|
+
const processBuildRuns = normalized.publish.publish_process_build_runs
|
|
523
|
+
? await publish_process_build_runs(collected.process_build_runs, {
|
|
524
|
+
commit: normalized.publish.commit,
|
|
525
|
+
executor: executors.process_build_runs,
|
|
526
|
+
publish: normalized.publish,
|
|
527
|
+
})
|
|
528
|
+
: [];
|
|
529
|
+
const relations = build_relation_manifest(collected.relations, normalized.publish, now);
|
|
530
|
+
writeJsonArtifact(files.relation_manifest, relations);
|
|
531
|
+
const publishEntries = [...lifecyclemodels, ...processes, ...sources, ...processBuildRuns];
|
|
532
|
+
const failed = publishEntries.filter((item) => item.status === 'failed').length;
|
|
533
|
+
const executed = publishEntries.filter((item) => item.status === 'executed').length;
|
|
534
|
+
const deferred = publishEntries.filter((item) => item.status.startsWith('deferred')).length;
|
|
535
|
+
const report = {
|
|
536
|
+
generated_at_utc: now.toISOString(),
|
|
537
|
+
request_path: requestPath,
|
|
538
|
+
out_dir: outDir,
|
|
539
|
+
commit: normalized.publish.commit,
|
|
540
|
+
status: failed > 0 ? 'completed_with_failures' : 'completed',
|
|
541
|
+
counts: {
|
|
542
|
+
bundle_paths: collected.bundle_paths.length,
|
|
543
|
+
lifecyclemodels: lifecyclemodels.length,
|
|
544
|
+
processes: processes.length,
|
|
545
|
+
sources: sources.length,
|
|
546
|
+
relations: relations.relations.length,
|
|
547
|
+
process_build_runs: processBuildRuns.length,
|
|
548
|
+
executed,
|
|
549
|
+
deferred,
|
|
550
|
+
failed,
|
|
551
|
+
},
|
|
552
|
+
files,
|
|
553
|
+
lifecyclemodels,
|
|
554
|
+
processes,
|
|
555
|
+
sources,
|
|
556
|
+
process_build_runs: processBuildRuns,
|
|
557
|
+
relations,
|
|
558
|
+
};
|
|
559
|
+
writeJsonArtifact(files.publish_report, report);
|
|
560
|
+
return report;
|
|
561
|
+
}
|
|
562
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/lib/publish.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,6BAA6B,GAG9B,MAAM,kCAAkC,CAAC;AAI1C,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,uBAAuB,GAAG,WAAW,CAAC;AAE5C,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,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;IACpF,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;IAE5F,MAAM,MAAM,GAAkB;QAC5B,gBAAgB,EAAE,GAAG,CAAC,WAAW,EAAE;QACnC,YAAY,EAAE,WAAW;QACzB,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM;QACjC,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,WAAW;QAC5D,MAAM,EAAE;YACN,YAAY,EAAE,SAAS,CAAC,YAAY,CAAC,MAAM;YAC3C,eAAe,EAAE,eAAe,CAAC,MAAM;YACvC,SAAS,EAAE,SAAS,CAAC,MAAM;YAC3B,OAAO,EAAE,OAAO,CAAC,MAAM;YACvB,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM;YACrC,kBAAkB,EAAE,gBAAgB,CAAC,MAAM;YAC3C,QAAQ;YACR,QAAQ;YACR,MAAM;SACP;QACD,KAAK;QACL,eAAe;QACf,SAAS;QACT,OAAO;QACP,kBAAkB,EAAE,gBAAgB;QACpC,SAAS;KACV,CAAC;IAEF,iBAAiB,CAAC,KAAK,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import path from 'node:path';\nimport { CliError } from './errors.js';\nimport { writeJsonArtifact } from './artifacts.js';\nimport type { FetchLike } from './http.js';\nimport { readJsonInput } from './io.js';\nimport { buildRunId, resolveRunLayout } from './run.js';\nimport {\n hasSupabaseRestRuntime,\n syncSupabaseJsonOrderedRecord,\n type SupabaseJsonOrderedTable,\n type SupabaseJsonOrderedWriteMode,\n} from './supabase-json-ordered-write.js';\n\ntype JsonObject = Record<string, unknown>;\n\nconst DEFAULT_MAX_ATTEMPTS = 5;\nconst DEFAULT_RETRY_DELAY_SECONDS = 2.0;\nconst DEFAULT_DATASET_VERSION = '01.01.000';\n\nfunction isRecord(value: unknown): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction ensure_list(value: unknown): unknown[] {\n if (value === undefined || value === null) {\n return [];\n }\n return Array.isArray(value) ? value : [value];\n}\n\nfunction first_non_empty(...values: unknown[]): string | null {\n for (const value of values) {\n if (typeof value === 'string' && value.trim()) {\n return value.trim();\n }\n }\n return null;\n}\n\nfunction to_positive_integer(value: unknown, defaultValue: number): number {\n if (value === undefined || value === null || value === '') {\n return defaultValue;\n }\n const parsed =\n typeof value === 'number'\n ? value\n : typeof value === 'string'\n ? Number.parseInt(value, 10)\n : Number.NaN;\n if (!Number.isInteger(parsed) || parsed <= 0) {\n throw new CliError('Publish request expected a positive integer value.', {\n code: 'PUBLISH_INVALID_INTEGER',\n exitCode: 2,\n details: value,\n });\n }\n return parsed;\n}\n\nfunction to_non_negative_number(value: unknown, defaultValue: number): number {\n if (value === undefined || value === null || value === '') {\n return defaultValue;\n }\n const parsed =\n typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN;\n if (!Number.isFinite(parsed) || parsed < 0) {\n throw new CliError('Publish request expected a non-negative number value.', {\n code: 'PUBLISH_INVALID_NUMBER',\n exitCode: 2,\n details: value,\n });\n }\n return parsed;\n}\n\nfunction to_boolean(value: unknown, defaultValue: boolean): boolean {\n return value === undefined ? defaultValue : Boolean(value);\n}\n\nfunction resolve_path(baseDir: string, value: string): string {\n return path.resolve(baseDir, value);\n}\n\nfunction load_json_object(filePath: string): JsonObject {\n const value = readJsonInput(filePath);\n if (!isRecord(value)) {\n throw new CliError(`Expected JSON object input: ${filePath}`, {\n code: 'PUBLISH_INPUT_NOT_OBJECT',\n exitCode: 2,\n });\n }\n return value;\n}\n\nfunction default_out_dir(baseDir: string, commit: boolean, now: Date = new Date()): string {\n const runId = buildRunId({\n namespace: 'publish',\n operation: commit ? 'commit' : 'dry_run',\n now,\n });\n return resolveRunLayout(path.join(baseDir, 'artifacts'), 'publish', runId).runRoot;\n}\n\nfunction serialize_error(error: unknown): { message: string } {\n if (error instanceof Error) {\n return { message: error.message };\n }\n return { message: String(error) };\n}\n\nexport type PublishDatasetEntry =\n | string\n | {\n file?: string;\n path?: string;\n json_ordered?: JsonObject;\n jsonOrdered?: JsonObject;\n payload?: JsonObject;\n [key: string]: unknown;\n };\n\nexport type PublishProcessBuildRunEntry =\n | string\n | {\n run_id?: string;\n run_root?: string;\n exports_dir?: string;\n [key: string]: unknown;\n };\n\nexport type PublishCollectedOrigin = {\n source: 'bundle' | 'input';\n base_dir: string;\n bundle_path: string | null;\n};\n\nexport type PublishCollectedDatasetEntry = {\n entry: PublishDatasetEntry;\n origin: PublishCollectedOrigin;\n};\n\nexport type PublishCollectedProcessBuildRunEntry = {\n entry: PublishProcessBuildRunEntry;\n origin: PublishCollectedOrigin;\n};\n\nexport type PublishCollectedRelationEntry = {\n entry: unknown;\n origin: PublishCollectedOrigin;\n};\n\nexport type PublishRequest = {\n inputs: {\n bundle_paths: string[];\n lifecyclemodels: PublishDatasetEntry[];\n processes: PublishDatasetEntry[];\n sources: PublishDatasetEntry[];\n relations: unknown[];\n process_build_runs: PublishProcessBuildRunEntry[];\n };\n publish: {\n commit: boolean;\n publish_lifecyclemodels: boolean;\n publish_processes: boolean;\n publish_sources: boolean;\n publish_relations: boolean;\n publish_process_build_runs: boolean;\n relation_mode: 'local_manifest_only';\n max_attempts: number;\n retry_delay_seconds: number;\n process_build_forward_args: string[];\n };\n out_dir: string;\n};\n\nexport type PublishCollectedInputs = {\n bundle_paths: string[];\n lifecyclemodels: PublishCollectedDatasetEntry[];\n processes: PublishCollectedDatasetEntry[];\n sources: PublishCollectedDatasetEntry[];\n relations: PublishCollectedRelationEntry[];\n process_build_runs: PublishCollectedProcessBuildRunEntry[];\n};\n\nexport type DatasetPublishExecutorArgs = {\n table: 'lifecyclemodels' | 'processes' | 'sources';\n id: string;\n version: string;\n payload: JsonObject;\n source: 'bundle' | 'input';\n bundle_path: string | null;\n publish: PublishRequest['publish'];\n};\n\nexport type ProcessBuildRunPublishExecutorArgs = {\n run_id: string;\n entry: PublishProcessBuildRunEntry;\n source: 'bundle' | 'input';\n bundle_path: string | null;\n forward_args: string[];\n publish: PublishRequest['publish'];\n};\n\nexport type PublishExecutors = {\n lifecyclemodels?: (args: DatasetPublishExecutorArgs) => Promise<unknown> | unknown;\n processes?: (args: DatasetPublishExecutorArgs) => Promise<unknown> | unknown;\n sources?: (args: DatasetPublishExecutorArgs) => Promise<unknown> | unknown;\n process_build_runs?: (args: ProcessBuildRunPublishExecutorArgs) => Promise<unknown> | unknown;\n};\n\nexport type PublishDatasetReport = {\n table: 'lifecyclemodels' | 'processes' | 'sources';\n id: string | null;\n version: string | null;\n status:\n | 'prepared'\n | 'executed'\n | 'deferred_no_executor'\n | 'deferred_projection_payload'\n | 'failed';\n source: 'bundle' | 'input';\n bundle_path: string | null;\n reason?: string;\n execution?: unknown;\n error?: { message: string };\n};\n\nexport type PublishProcessBuildRunReport = {\n run_id: string;\n status: 'prepared' | 'executed' | 'deferred_no_executor' | 'failed';\n source: 'bundle' | 'input';\n bundle_path: string | null;\n forward_args: string[];\n execution?: unknown;\n error?: { message: string };\n};\n\nexport type PublishRelationManifest = {\n generated_at_utc: string;\n relation_mode: 'local_manifest_only';\n status: 'prepared_local_relation_manifest';\n relations: unknown[];\n};\n\nexport type PublishReport = {\n generated_at_utc: string;\n request_path: string;\n out_dir: string;\n commit: boolean;\n status: 'completed' | 'completed_with_failures';\n counts: {\n bundle_paths: number;\n lifecyclemodels: number;\n processes: number;\n sources: number;\n relations: number;\n process_build_runs: number;\n executed: number;\n deferred: number;\n failed: number;\n };\n files: {\n normalized_request: string;\n collected_inputs: string;\n relation_manifest: string;\n publish_report: string;\n };\n lifecyclemodels: PublishDatasetReport[];\n processes: PublishDatasetReport[];\n sources: PublishDatasetReport[];\n process_build_runs: PublishProcessBuildRunReport[];\n relations: PublishRelationManifest;\n};\n\nexport type RunPublishOptions = {\n inputPath: string;\n rawRequest?: unknown;\n outDir?: string | null;\n commit?: boolean | null;\n executors?: PublishExecutors;\n env?: NodeJS.ProcessEnv;\n fetchImpl?: FetchLike;\n timeoutMs?: number;\n now?: Date;\n};\n\ntype PreparedPublishDatasetReport = PublishDatasetReport & {\n id: string;\n version: string;\n};\n\ntype NormalizePublishRequestOptions = {\n requestPath: string;\n outDirOverride?: string;\n commitOverride?: boolean;\n now?: Date;\n};\n\ntype PublishRequestOptions = {\n commit: boolean;\n executor:\n | PublishExecutors['lifecyclemodels']\n | PublishExecutors['processes']\n | PublishExecutors['sources']\n | undefined;\n publish: PublishRequest['publish'];\n};\n\nfunction extract_lifecyclemodel_identity(payload: JsonObject): [string, string] {\n const root = isRecord(payload.lifeCycleModelDataSet) ? payload.lifeCycleModelDataSet : payload;\n const lifeCycleModelInformation = isRecord(root.lifeCycleModelInformation)\n ? root.lifeCycleModelInformation\n : {};\n const dataSetInformation = isRecord(lifeCycleModelInformation.dataSetInformation)\n ? lifeCycleModelInformation.dataSetInformation\n : {};\n const administrativeInformation = isRecord(root.administrativeInformation)\n ? root.administrativeInformation\n : {};\n const publicationAndOwnership = isRecord(administrativeInformation.publicationAndOwnership)\n ? administrativeInformation.publicationAndOwnership\n : {};\n const datasetId = first_non_empty(payload['@id'], payload.id, dataSetInformation['common:UUID']);\n const version = first_non_empty(\n payload['@version'],\n payload.version,\n publicationAndOwnership['common:dataSetVersion'],\n DEFAULT_DATASET_VERSION,\n )!;\n if (!datasetId) {\n throw new CliError('Lifecycle model payload missing @id/id.', {\n code: 'PUBLISH_LIFECYCLEMODEL_ID_MISSING',\n exitCode: 2,\n });\n }\n return [datasetId, version];\n}\n\nfunction extract_process_identity(payload: JsonObject): [string, string] {\n const root = isRecord(payload.processDataSet) ? payload.processDataSet : payload;\n const processInformation = isRecord(root.processInformation) ? root.processInformation : {};\n const dataSetInformation = isRecord(processInformation.dataSetInformation)\n ? processInformation.dataSetInformation\n : {};\n const administrativeInformation = isRecord(root.administrativeInformation)\n ? root.administrativeInformation\n : {};\n const publicationAndOwnership = isRecord(administrativeInformation.publicationAndOwnership)\n ? administrativeInformation.publicationAndOwnership\n : {};\n const datasetId = first_non_empty(dataSetInformation['common:UUID']);\n const version = first_non_empty(\n publicationAndOwnership['common:dataSetVersion'],\n DEFAULT_DATASET_VERSION,\n )!;\n if (!datasetId) {\n throw new CliError(\n 'Process payload missing processInformation.dataSetInformation.common:UUID.',\n {\n code: 'PUBLISH_PROCESS_ID_MISSING',\n exitCode: 2,\n },\n );\n }\n return [datasetId, version];\n}\n\nfunction extract_source_identity(payload: JsonObject): [string, string] {\n const root = isRecord(payload.sourceDataSet) ? payload.sourceDataSet : payload;\n const sourceInformation = isRecord(root.sourceInformation) ? root.sourceInformation : {};\n const dataSetInformation = isRecord(sourceInformation.dataSetInformation)\n ? sourceInformation.dataSetInformation\n : {};\n const administrativeInformation = isRecord(root.administrativeInformation)\n ? root.administrativeInformation\n : {};\n const publicationAndOwnership = isRecord(administrativeInformation.publicationAndOwnership)\n ? administrativeInformation.publicationAndOwnership\n : {};\n const datasetId = first_non_empty(dataSetInformation['common:UUID']);\n const version = first_non_empty(\n publicationAndOwnership['common:dataSetVersion'],\n DEFAULT_DATASET_VERSION,\n )!;\n if (!datasetId) {\n throw new CliError('Source payload missing sourceInformation.dataSetInformation.common:UUID.', {\n code: 'PUBLISH_SOURCE_ID_MISSING',\n exitCode: 2,\n });\n }\n return [datasetId, version];\n}\n\nfunction load_dataset_entry(entry: PublishDatasetEntry, baseDir: string): JsonObject {\n if (isRecord(entry)) {\n for (const key of ['json_ordered', 'jsonOrdered', 'payload'] as const) {\n const candidate = entry[key];\n if (isRecord(candidate)) {\n return candidate;\n }\n }\n const fileValue = first_non_empty(entry.file, entry.path);\n if (fileValue) {\n return load_json_object(resolve_path(baseDir, fileValue));\n }\n return entry;\n }\n\n if (typeof entry === 'string' && entry.trim()) {\n return load_json_object(resolve_path(baseDir, entry));\n }\n\n throw new CliError('Unsupported dataset entry in publish request.', {\n code: 'PUBLISH_UNSUPPORTED_DATASET_ENTRY',\n exitCode: 2,\n details: entry,\n });\n}\n\nfunction push_collected_entries<T>(\n target: Array<{ entry: T; origin: PublishCollectedOrigin }>,\n entries: unknown[],\n origin: PublishCollectedOrigin,\n): void {\n for (const entry of entries) {\n target.push({ entry: entry as T, origin });\n }\n}\n\nexport function normalizePublishRequest(\n raw: unknown,\n options: NormalizePublishRequestOptions,\n): PublishRequest {\n if (!isRecord(raw)) {\n throw new CliError('Publish request must be a JSON object.', {\n code: 'PUBLISH_REQUEST_NOT_OBJECT',\n exitCode: 2,\n });\n }\n\n const requestDir = path.dirname(options.requestPath);\n const inputs = isRecord(raw.inputs) ? raw.inputs : {};\n const publish = isRecord(raw.publish) ? raw.publish : {};\n const commit =\n options.commitOverride === undefined\n ? to_boolean(publish.commit, false)\n : options.commitOverride;\n const outDirValue = first_non_empty(options.outDirOverride, raw.out_dir, raw.output_dir);\n const outDir = outDirValue\n ? resolve_path(requestDir, outDirValue)\n : default_out_dir(requestDir, commit, options.now);\n const relationMode = first_non_empty(publish.relation_mode, 'local_manifest_only');\n\n if (relationMode !== 'local_manifest_only') {\n throw new CliError(\"publish.relation_mode only supports 'local_manifest_only'.\", {\n code: 'PUBLISH_UNSUPPORTED_RELATION_MODE',\n exitCode: 2,\n details: relationMode,\n });\n }\n\n return {\n inputs: {\n bundle_paths: ensure_list(inputs.bundle_paths)\n .map((value) => String(value).trim())\n .filter(Boolean)\n .map((value) => resolve_path(requestDir, value)),\n lifecyclemodels: ensure_list(inputs.lifecyclemodels) as PublishDatasetEntry[],\n processes: ensure_list(inputs.processes) as PublishDatasetEntry[],\n sources: ensure_list(inputs.sources) as PublishDatasetEntry[],\n relations: ensure_list(inputs.relations),\n process_build_runs: ensure_list(inputs.process_build_runs) as PublishProcessBuildRunEntry[],\n },\n publish: {\n commit,\n publish_lifecyclemodels: to_boolean(publish.publish_lifecyclemodels, true),\n publish_processes: to_boolean(publish.publish_processes, true),\n publish_sources: to_boolean(publish.publish_sources, true),\n publish_relations: to_boolean(publish.publish_relations, true),\n publish_process_build_runs: to_boolean(publish.publish_process_build_runs, true),\n relation_mode: 'local_manifest_only',\n max_attempts: to_positive_integer(publish.max_attempts, DEFAULT_MAX_ATTEMPTS),\n retry_delay_seconds: to_non_negative_number(\n publish.retry_delay_seconds,\n DEFAULT_RETRY_DELAY_SECONDS,\n ),\n process_build_forward_args: ensure_list(publish.process_build_forward_args)\n .map((value) => String(value).trim())\n .filter(Boolean),\n },\n out_dir: outDir,\n };\n}\n\nexport function collectPublishInputs(\n normalized: PublishRequest,\n requestBaseDir: string,\n): PublishCollectedInputs {\n const collected: PublishCollectedInputs = {\n bundle_paths: [...normalized.inputs.bundle_paths],\n lifecyclemodels: [],\n processes: [],\n sources: [],\n relations: [],\n process_build_runs: [],\n };\n\n for (const bundlePath of normalized.inputs.bundle_paths) {\n const bundle = load_json_object(bundlePath);\n const origin: PublishCollectedOrigin = {\n source: 'bundle',\n base_dir: path.dirname(bundlePath),\n bundle_path: bundlePath,\n };\n push_collected_entries<PublishDatasetEntry>(\n collected.lifecyclemodels,\n ensure_list(bundle.lifecyclemodels),\n origin,\n );\n push_collected_entries<PublishDatasetEntry>(\n collected.processes,\n [...ensure_list(bundle.projected_processes), ...ensure_list(bundle.processes)],\n origin,\n );\n push_collected_entries<PublishDatasetEntry>(\n collected.sources,\n ensure_list(bundle.sources),\n origin,\n );\n push_collected_entries(\n collected.relations,\n [...ensure_list(bundle.resulting_process_relations), ...ensure_list(bundle.relations)],\n origin,\n );\n push_collected_entries<PublishProcessBuildRunEntry>(\n collected.process_build_runs,\n ensure_list(bundle.process_build_runs),\n origin,\n );\n }\n\n const directOrigin: PublishCollectedOrigin = {\n source: 'input',\n base_dir: requestBaseDir,\n bundle_path: null,\n };\n\n push_collected_entries<PublishDatasetEntry>(\n collected.lifecyclemodels,\n normalized.inputs.lifecyclemodels,\n directOrigin,\n );\n push_collected_entries<PublishDatasetEntry>(\n collected.processes,\n normalized.inputs.processes,\n directOrigin,\n );\n push_collected_entries<PublishDatasetEntry>(\n collected.sources,\n normalized.inputs.sources,\n directOrigin,\n );\n push_collected_entries(collected.relations, normalized.inputs.relations, directOrigin);\n push_collected_entries<PublishProcessBuildRunEntry>(\n collected.process_build_runs,\n normalized.inputs.process_build_runs,\n directOrigin,\n );\n\n return collected;\n}\n\nasync function maybe_execute_dataset(\n report: PreparedPublishDatasetReport,\n payload: JsonObject,\n options: PublishRequestOptions & {\n table: 'lifecyclemodels' | 'processes' | 'sources';\n },\n): Promise<PublishDatasetReport> {\n if (!options.commit) {\n return report;\n }\n\n if (!options.executor) {\n report.status = 'deferred_no_executor';\n return report;\n }\n\n try {\n report.execution = await options.executor({\n table: options.table,\n id: report.id,\n version: report.version,\n payload,\n source: report.source,\n bundle_path: report.bundle_path,\n publish: options.publish,\n });\n report.status = 'executed';\n } catch (error) {\n report.status = 'failed';\n report.error = serialize_error(error);\n }\n\n return report;\n}\n\nasync function publish_lifecyclemodels(\n entries: PublishCollectedDatasetEntry[],\n options: PublishRequestOptions,\n): Promise<PublishDatasetReport[]> {\n const reports: PublishDatasetReport[] = [];\n for (const item of entries) {\n const payload = load_dataset_entry(item.entry, item.origin.base_dir);\n const [datasetId, version] = extract_lifecyclemodel_identity(payload);\n const report: PreparedPublishDatasetReport = {\n table: 'lifecyclemodels',\n id: datasetId,\n version,\n status: 'prepared',\n source: item.origin.source,\n bundle_path: item.origin.bundle_path,\n };\n reports.push(\n await maybe_execute_dataset(report, payload, {\n ...options,\n table: 'lifecyclemodels',\n executor: options.executor,\n }),\n );\n }\n return reports;\n}\n\nasync function publish_processes(\n entries: PublishCollectedDatasetEntry[],\n options: PublishRequestOptions,\n): Promise<PublishDatasetReport[]> {\n const reports: PublishDatasetReport[] = [];\n for (const item of entries) {\n const payload = load_dataset_entry(item.entry, item.origin.base_dir);\n try {\n const [datasetId, version] = extract_process_identity(payload);\n const report: PreparedPublishDatasetReport = {\n table: 'processes',\n id: datasetId,\n version,\n status: 'prepared',\n source: item.origin.source,\n bundle_path: item.origin.bundle_path,\n };\n reports.push(\n await maybe_execute_dataset(report, payload, {\n ...options,\n table: 'processes',\n executor: options.executor,\n }),\n );\n } catch (error) {\n const report: PublishDatasetReport = {\n table: 'processes',\n id: first_non_empty(payload['@id'], payload.id),\n version: first_non_empty(payload['@version'], payload.version, DEFAULT_DATASET_VERSION),\n status: 'deferred_projection_payload',\n source: item.origin.source,\n bundle_path: item.origin.bundle_path,\n reason:\n error instanceof CliError && error.code === 'PUBLISH_PROCESS_ID_MISSING'\n ? 'Payload is not a canonical processDataSet wrapper; keep it in the publish bundle until a projection-to-process adapter exists.'\n : serialize_error(error).message,\n };\n reports.push(report);\n }\n }\n return reports;\n}\n\nasync function publish_sources(\n entries: PublishCollectedDatasetEntry[],\n options: PublishRequestOptions,\n): Promise<PublishDatasetReport[]> {\n const reports: PublishDatasetReport[] = [];\n for (const item of entries) {\n const payload = load_dataset_entry(item.entry, item.origin.base_dir);\n const [datasetId, version] = extract_source_identity(payload);\n const report: PreparedPublishDatasetReport = {\n table: 'sources',\n id: datasetId,\n version,\n status: 'prepared',\n source: item.origin.source,\n bundle_path: item.origin.bundle_path,\n };\n reports.push(\n await maybe_execute_dataset(report, payload, {\n ...options,\n table: 'sources',\n executor: options.executor,\n }),\n );\n }\n return reports;\n}\n\nasync function publish_process_build_runs(\n entries: PublishCollectedProcessBuildRunEntry[],\n options: {\n commit: boolean;\n executor: PublishExecutors['process_build_runs'];\n publish: PublishRequest['publish'];\n },\n): Promise<PublishProcessBuildRunReport[]> {\n const reports: PublishProcessBuildRunReport[] = [];\n for (const item of entries) {\n const runId =\n typeof item.entry === 'string' ? item.entry.trim() : first_non_empty(item.entry.run_id);\n\n if (!runId) {\n throw new CliError('process_build_run entry missing run_id.', {\n code: 'PUBLISH_PROCESS_BUILD_RUN_ID_MISSING',\n exitCode: 2,\n details: item.entry,\n });\n }\n\n const report: PublishProcessBuildRunReport = {\n run_id: runId,\n status: 'prepared',\n source: item.origin.source,\n bundle_path: item.origin.bundle_path,\n forward_args: [...options.publish.process_build_forward_args],\n };\n\n if (!options.commit) {\n reports.push(report);\n continue;\n }\n\n if (!options.executor) {\n report.status = 'deferred_no_executor';\n reports.push(report);\n continue;\n }\n\n try {\n report.execution = await options.executor({\n run_id: runId,\n entry: item.entry,\n source: item.origin.source,\n bundle_path: item.origin.bundle_path,\n forward_args: [...options.publish.process_build_forward_args],\n publish: options.publish,\n });\n report.status = 'executed';\n } catch (error) {\n report.status = 'failed';\n report.error = serialize_error(error);\n }\n\n reports.push(report);\n }\n return reports;\n}\n\nfunction build_relation_manifest(\n relations: PublishCollectedRelationEntry[],\n publish: PublishRequest['publish'],\n now: Date,\n): PublishRelationManifest {\n return {\n generated_at_utc: now.toISOString(),\n relation_mode: publish.relation_mode,\n status: 'prepared_local_relation_manifest',\n relations: publish.publish_relations ? relations.map((item) => item.entry) : [],\n };\n}\n\nfunction table_write_mode_for_publish(): SupabaseJsonOrderedWriteMode {\n return 'upsert_current_version';\n}\n\nfunction build_default_dataset_executor(options: {\n table: SupabaseJsonOrderedTable;\n env: NodeJS.ProcessEnv;\n fetchImpl: FetchLike;\n timeoutMs?: number;\n}) {\n return async (args: DatasetPublishExecutorArgs): Promise<unknown> =>\n syncSupabaseJsonOrderedRecord({\n table: options.table,\n id: args.id,\n version: args.version,\n payload: args.payload,\n writeMode: table_write_mode_for_publish(),\n env: options.env,\n fetchImpl: options.fetchImpl,\n timeoutMs: options.timeoutMs,\n });\n}\n\nfunction resolve_dataset_executors(options: RunPublishOptions): PublishExecutors {\n const explicit = options.executors ?? {};\n const env = options.env;\n const fetchImpl = options.fetchImpl;\n\n if (!env || !fetchImpl || !hasSupabaseRestRuntime(env)) {\n return explicit;\n }\n\n return {\n lifecyclemodels:\n explicit.lifecyclemodels ??\n build_default_dataset_executor({\n table: 'lifecyclemodels',\n env,\n fetchImpl,\n timeoutMs: options.timeoutMs,\n }),\n processes:\n explicit.processes ??\n build_default_dataset_executor({\n table: 'processes',\n env,\n fetchImpl,\n timeoutMs: options.timeoutMs,\n }),\n sources:\n explicit.sources ??\n build_default_dataset_executor({\n table: 'sources',\n env,\n fetchImpl,\n timeoutMs: options.timeoutMs,\n }),\n process_build_runs: explicit.process_build_runs,\n };\n}\n\nexport async function runPublish(options: RunPublishOptions): Promise<PublishReport> {\n const requestPath = path.resolve(options.inputPath);\n const requestDir = path.dirname(requestPath);\n const raw = options.rawRequest ?? readJsonInput(requestPath);\n const normalized = normalizePublishRequest(raw, {\n requestPath,\n outDirOverride: options.outDir ?? undefined,\n commitOverride: options.commit ?? undefined,\n now: options.now,\n });\n const collected = collectPublishInputs(normalized, requestDir);\n const now = options.now ?? new Date();\n const outDir = normalized.out_dir;\n const executors = resolve_dataset_executors(options);\n\n const files = {\n normalized_request: path.join(outDir, 'normalized-request.json'),\n collected_inputs: path.join(outDir, 'collected-inputs.json'),\n relation_manifest: path.join(outDir, 'relation-manifest.json'),\n publish_report: path.join(outDir, 'publish-report.json'),\n };\n\n writeJsonArtifact(files.normalized_request, normalized);\n writeJsonArtifact(files.collected_inputs, collected);\n\n const lifecyclemodels = normalized.publish.publish_lifecyclemodels\n ? await publish_lifecyclemodels(collected.lifecyclemodels, {\n commit: normalized.publish.commit,\n executor: executors.lifecyclemodels,\n publish: normalized.publish,\n })\n : [];\n const processes = normalized.publish.publish_processes\n ? await publish_processes(collected.processes, {\n commit: normalized.publish.commit,\n executor: executors.processes,\n publish: normalized.publish,\n })\n : [];\n const sources = normalized.publish.publish_sources\n ? await publish_sources(collected.sources, {\n commit: normalized.publish.commit,\n executor: executors.sources,\n publish: normalized.publish,\n })\n : [];\n const processBuildRuns = normalized.publish.publish_process_build_runs\n ? await publish_process_build_runs(collected.process_build_runs, {\n commit: normalized.publish.commit,\n executor: executors.process_build_runs,\n publish: normalized.publish,\n })\n : [];\n const relations = build_relation_manifest(collected.relations, normalized.publish, now);\n\n writeJsonArtifact(files.relation_manifest, relations);\n\n const publishEntries = [...lifecyclemodels, ...processes, ...sources, ...processBuildRuns];\n const failed = publishEntries.filter((item) => item.status === 'failed').length;\n const executed = publishEntries.filter((item) => item.status === 'executed').length;\n const deferred = publishEntries.filter((item) => item.status.startsWith('deferred')).length;\n\n const report: PublishReport = {\n generated_at_utc: now.toISOString(),\n request_path: requestPath,\n out_dir: outDir,\n commit: normalized.publish.commit,\n status: failed > 0 ? 'completed_with_failures' : 'completed',\n counts: {\n bundle_paths: collected.bundle_paths.length,\n lifecyclemodels: lifecyclemodels.length,\n processes: processes.length,\n sources: sources.length,\n relations: relations.relations.length,\n process_build_runs: processBuildRuns.length,\n executed,\n deferred,\n failed,\n },\n files,\n lifecyclemodels,\n processes,\n sources,\n process_build_runs: processBuildRuns,\n relations,\n };\n\n writeJsonArtifact(files.publish_report, report);\n return report;\n}\n"]}
|