@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,81 @@
|
|
|
1
|
+
import { CliError } from './errors.js';
|
|
2
|
+
import { fetchOneFlowRow, normalizeSupabaseFlowPayload, } from './flow-read.js';
|
|
3
|
+
import { requireSupabaseRestRuntime } from './supabase-rest.js';
|
|
4
|
+
import { createSupabaseDataRuntime } from './supabase-session.js';
|
|
5
|
+
const FLOW_GET_TIMEOUT_MS = 10_000;
|
|
6
|
+
function normalizeToken(value) {
|
|
7
|
+
if (typeof value !== 'string') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const trimmed = value.trim();
|
|
11
|
+
return trimmed ? trimmed : null;
|
|
12
|
+
}
|
|
13
|
+
function nowIso(now = new Date()) {
|
|
14
|
+
return now.toISOString();
|
|
15
|
+
}
|
|
16
|
+
export async function runFlowGet(options) {
|
|
17
|
+
const flowId = normalizeToken(options.flowId);
|
|
18
|
+
if (!flowId) {
|
|
19
|
+
throw new CliError('Missing required --id value.', {
|
|
20
|
+
code: 'FLOW_ID_REQUIRED',
|
|
21
|
+
exitCode: 2,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const requestedVersion = normalizeToken(options.version ?? null);
|
|
25
|
+
const requestedUserId = normalizeToken(options.userId ?? null);
|
|
26
|
+
const requestedStateCode = Number.isInteger(options.stateCode) && options.stateCode >= 0
|
|
27
|
+
? options.stateCode
|
|
28
|
+
: null;
|
|
29
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
30
|
+
const timeoutMs = options.timeoutMs ?? FLOW_GET_TIMEOUT_MS;
|
|
31
|
+
const runtime = createSupabaseDataRuntime({
|
|
32
|
+
runtime: requireSupabaseRestRuntime(options.env ?? process.env),
|
|
33
|
+
fetchImpl,
|
|
34
|
+
timeoutMs,
|
|
35
|
+
now: options.now,
|
|
36
|
+
});
|
|
37
|
+
const lookup = await fetchOneFlowRow({
|
|
38
|
+
runtime,
|
|
39
|
+
id: flowId,
|
|
40
|
+
version: requestedVersion,
|
|
41
|
+
userId: requestedUserId,
|
|
42
|
+
stateCode: requestedStateCode,
|
|
43
|
+
timeoutMs,
|
|
44
|
+
fetchImpl,
|
|
45
|
+
fallbackToLatest: requestedVersion !== null,
|
|
46
|
+
});
|
|
47
|
+
if (!lookup) {
|
|
48
|
+
throw new CliError(requestedVersion
|
|
49
|
+
? `Could not resolve flow dataset for ${flowId}@${requestedVersion}.`
|
|
50
|
+
: `Could not resolve flow dataset for ${flowId}.`, {
|
|
51
|
+
code: 'FLOW_GET_NOT_FOUND',
|
|
52
|
+
exitCode: 2,
|
|
53
|
+
details: {
|
|
54
|
+
flow_id: flowId,
|
|
55
|
+
version: requestedVersion,
|
|
56
|
+
user_id: requestedUserId,
|
|
57
|
+
state_code: requestedStateCode,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
schema_version: 1,
|
|
63
|
+
generated_at_utc: nowIso(options.now),
|
|
64
|
+
status: 'resolved_remote_flow',
|
|
65
|
+
flow_id: lookup.row.id || flowId,
|
|
66
|
+
requested_version: requestedVersion,
|
|
67
|
+
requested_user_id: requestedUserId,
|
|
68
|
+
requested_state_code: requestedStateCode,
|
|
69
|
+
resolved_version: lookup.row.version || requestedVersion || '',
|
|
70
|
+
resolution: lookup.resolution,
|
|
71
|
+
source_url: lookup.sourceUrl,
|
|
72
|
+
modified_at: lookup.row.modified_at,
|
|
73
|
+
user_id: lookup.row.user_id,
|
|
74
|
+
state_code: lookup.row.state_code,
|
|
75
|
+
flow: normalizeSupabaseFlowPayload(lookup.row.json, requestedVersion ? `${flowId}@${requestedVersion}` : flowId),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export const __testInternals = {
|
|
79
|
+
normalizeToken,
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=flow-get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-get.js","sourceRoot":"","sources":["../../../src/lib/flow-get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EACL,eAAe,EACf,4BAA4B,GAE7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAIlE,MAAM,mBAAmB,GAAG,MAAM,CAAC;AA8BnC,SAAS,cAAc,CAAC,KAAgC;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC;AAED,SAAS,MAAM,CAAC,MAAY,IAAI,IAAI,EAAE;IACpC,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CA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AAsC,MAAM,IAAI,gBAAgB,GAAG;YACrE,CAAC,CAAC,sCAAsC,MAAM,GAAG,EACnD;YACE,IAAI,EAAE,oBAAoB;YAC1B,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE;gBACP,OAAO,EAAE,MAAM;gBACf,OAAO,EAAE,gBAAgB;gBACzB,OAAO,EAAE,eAAe;gBACxB,UAAU,EAAE,kBAAkB;aAC/B;SACF,CACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,cAAc,EAAE,CAAC;QACjB,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QACrC,MAAM,EAAE,sBAAsB;QAC9B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,MAAM;QAChC,iBAAiB,EAAE,gBAAgB;QACnC,iBAAiB,EAAE,eAAe;QAClC,oBAAoB,EAAE,kBAAkB;QACxC,gBAAgB,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,gBAAgB,IAAI,EAAE;QAC9D,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,UAAU,EAAE,MAAM,CAAC,SAAS;QAC5B,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW;QACnC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO;QAC3B,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU;QACjC,IAAI,EAAE,4BAA4B,CAChC,MAAM,CAAC,GAAG,CAAC,IAAI,EACf,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,gBAAgB,EAAE,CAAC,CAAC,CAAC,MAAM,CAC5D;KACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc;CACf,CAAC","sourcesContent":["import { CliError } from './errors.js';\nimport type { FetchLike } from './http.js';\nimport {\n fetchOneFlowRow,\n normalizeSupabaseFlowPayload,\n type SupabaseFlowLookup,\n} from './flow-read.js';\nimport { requireSupabaseRestRuntime } from './supabase-rest.js';\nimport { createSupabaseDataRuntime } from './supabase-session.js';\n\ntype JsonObject = Record<string, unknown>;\n\nconst FLOW_GET_TIMEOUT_MS = 10_000;\n\nexport type RunFlowGetOptions = {\n flowId: string;\n version?: string | null;\n userId?: string | null;\n stateCode?: number | null;\n env?: NodeJS.ProcessEnv;\n fetchImpl?: FetchLike;\n timeoutMs?: number;\n now?: Date;\n};\n\nexport type FlowGetReport = {\n schema_version: 1;\n generated_at_utc: string;\n status: 'resolved_remote_flow';\n flow_id: string;\n requested_version: string | null;\n requested_user_id: string | null;\n requested_state_code: number | null;\n resolved_version: string;\n resolution: SupabaseFlowLookup['resolution'];\n source_url: string;\n modified_at: string | null;\n user_id: string | null;\n state_code: number | null;\n flow: JsonObject;\n};\n\nfunction normalizeToken(value: string | null | undefined): string | null {\n if (typeof value !== 'string') {\n return null;\n }\n\n const trimmed = value.trim();\n return trimmed ? trimmed : null;\n}\n\nfunction nowIso(now: Date = new Date()): string {\n return now.toISOString();\n}\n\nexport async function runFlowGet(options: RunFlowGetOptions): Promise<FlowGetReport> {\n const flowId = normalizeToken(options.flowId);\n if (!flowId) {\n throw new CliError('Missing required --id value.', {\n code: 'FLOW_ID_REQUIRED',\n exitCode: 2,\n });\n }\n\n const requestedVersion = normalizeToken(options.version ?? null);\n const requestedUserId = normalizeToken(options.userId ?? null);\n const requestedStateCode =\n Number.isInteger(options.stateCode) && (options.stateCode as number) >= 0\n ? (options.stateCode as number)\n : null;\n\n const fetchImpl = options.fetchImpl ?? (fetch as FetchLike);\n const timeoutMs = options.timeoutMs ?? FLOW_GET_TIMEOUT_MS;\n const runtime = createSupabaseDataRuntime({\n runtime: requireSupabaseRestRuntime(options.env ?? process.env),\n fetchImpl,\n timeoutMs,\n now: options.now,\n });\n const lookup = await fetchOneFlowRow({\n runtime,\n id: flowId,\n version: requestedVersion,\n userId: requestedUserId,\n stateCode: requestedStateCode,\n timeoutMs,\n fetchImpl,\n fallbackToLatest: requestedVersion !== null,\n });\n\n if (!lookup) {\n throw new CliError(\n requestedVersion\n ? `Could not resolve flow dataset for ${flowId}@${requestedVersion}.`\n : `Could not resolve flow dataset for ${flowId}.`,\n {\n code: 'FLOW_GET_NOT_FOUND',\n exitCode: 2,\n details: {\n flow_id: flowId,\n version: requestedVersion,\n user_id: requestedUserId,\n state_code: requestedStateCode,\n },\n },\n );\n }\n\n return {\n schema_version: 1,\n generated_at_utc: nowIso(options.now),\n status: 'resolved_remote_flow',\n flow_id: lookup.row.id || flowId,\n requested_version: requestedVersion,\n requested_user_id: requestedUserId,\n requested_state_code: requestedStateCode,\n resolved_version: lookup.row.version || requestedVersion || '',\n resolution: lookup.resolution,\n source_url: lookup.sourceUrl,\n modified_at: lookup.row.modified_at,\n user_id: lookup.row.user_id,\n state_code: lookup.row.state_code,\n flow: normalizeSupabaseFlowPayload(\n lookup.row.json,\n requestedVersion ? `${flowId}@${requestedVersion}` : flowId,\n ),\n };\n}\n\nexport const __testInternals = {\n normalizeToken,\n};\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CliError } from './errors.js';
|
|
4
|
+
export function isRecord(value) {
|
|
5
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
6
|
+
}
|
|
7
|
+
export function listify(value) {
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
return value === undefined || value === null ? [] : [value];
|
|
12
|
+
}
|
|
13
|
+
export function deepGet(value, pathParts, defaultValue = undefined) {
|
|
14
|
+
let current = value;
|
|
15
|
+
for (const part of pathParts) {
|
|
16
|
+
if (!isRecord(current)) {
|
|
17
|
+
return defaultValue;
|
|
18
|
+
}
|
|
19
|
+
current = current[part];
|
|
20
|
+
if (current === undefined || current === null) {
|
|
21
|
+
return defaultValue;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return current;
|
|
25
|
+
}
|
|
26
|
+
export function coerceText(value) {
|
|
27
|
+
if (typeof value === 'string') {
|
|
28
|
+
return value.trim();
|
|
29
|
+
}
|
|
30
|
+
if (isRecord(value)) {
|
|
31
|
+
if (typeof value['#text'] === 'string') {
|
|
32
|
+
return String(value['#text']).trim();
|
|
33
|
+
}
|
|
34
|
+
for (const nested of Object.values(value)) {
|
|
35
|
+
const candidate = coerceText(nested);
|
|
36
|
+
if (candidate) {
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
for (const item of value) {
|
|
44
|
+
const candidate = coerceText(item);
|
|
45
|
+
if (candidate) {
|
|
46
|
+
return candidate;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
return value === undefined || value === null ? '' : String(value).trim();
|
|
52
|
+
}
|
|
53
|
+
export function firstLangEntry(value, fallback = '') {
|
|
54
|
+
if (isRecord(value) && ('#text' in value || '@xml:lang' in value)) {
|
|
55
|
+
const text = coerceText(value);
|
|
56
|
+
if (text) {
|
|
57
|
+
return {
|
|
58
|
+
'@xml:lang': coerceText(value['@xml:lang']) || 'en',
|
|
59
|
+
'#text': text,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(value)) {
|
|
64
|
+
for (const item of value) {
|
|
65
|
+
const result = firstLangEntry(item);
|
|
66
|
+
if (result) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (isRecord(value)) {
|
|
72
|
+
for (const nested of Object.values(value)) {
|
|
73
|
+
const result = firstLangEntry(nested);
|
|
74
|
+
if (result) {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return fallback
|
|
80
|
+
? {
|
|
81
|
+
'@xml:lang': 'en',
|
|
82
|
+
'#text': fallback,
|
|
83
|
+
}
|
|
84
|
+
: null;
|
|
85
|
+
}
|
|
86
|
+
export function normalizeText(value) {
|
|
87
|
+
return value
|
|
88
|
+
.replace(/[^0-9a-zA-Z\u4e00-\u9fff]+/gu, ' ')
|
|
89
|
+
.replace(/\s+/gu, ' ')
|
|
90
|
+
.trim()
|
|
91
|
+
.toLowerCase();
|
|
92
|
+
}
|
|
93
|
+
export function datasetPayloadFromRow(row) {
|
|
94
|
+
if (isRecord(row.json_ordered)) {
|
|
95
|
+
return row.json_ordered;
|
|
96
|
+
}
|
|
97
|
+
if (isRecord(row.json)) {
|
|
98
|
+
return row.json;
|
|
99
|
+
}
|
|
100
|
+
return row;
|
|
101
|
+
}
|
|
102
|
+
export function flowDatasetFromRow(row) {
|
|
103
|
+
const payload = datasetPayloadFromRow(row);
|
|
104
|
+
return isRecord(payload.flowDataSet) ? payload.flowDataSet : payload;
|
|
105
|
+
}
|
|
106
|
+
export function extractFlowRecord(row) {
|
|
107
|
+
const dataset = flowDatasetFromRow(row);
|
|
108
|
+
const info = deepGet(dataset, ['flowInformation', 'dataSetInformation'], {});
|
|
109
|
+
const id = coerceText(row.id) || coerceText(info['common:UUID']);
|
|
110
|
+
const version = coerceText(row.version) ||
|
|
111
|
+
coerceText(deepGet(dataset, [
|
|
112
|
+
'administrativeInformation',
|
|
113
|
+
'publicationAndOwnership',
|
|
114
|
+
'common:dataSetVersion',
|
|
115
|
+
])) ||
|
|
116
|
+
'01.00.000';
|
|
117
|
+
const nameBlock = deepGet(info, ['name', 'baseName']) ??
|
|
118
|
+
deepGet(info, ['name']) ??
|
|
119
|
+
info['common:shortDescription'];
|
|
120
|
+
const name = coerceText(nameBlock) || id;
|
|
121
|
+
const flowType = coerceText(deepGet(dataset, ['modellingAndValidation', 'LCIMethodAndAllocation', 'typeOfDataSet'])) ||
|
|
122
|
+
coerceText(deepGet(dataset, ['modellingAndValidation', 'LCIMethod', 'typeOfDataSet'])) ||
|
|
123
|
+
coerceText(row.typeOfDataSet);
|
|
124
|
+
return {
|
|
125
|
+
id,
|
|
126
|
+
version,
|
|
127
|
+
name,
|
|
128
|
+
flowType,
|
|
129
|
+
shortDescription: firstLangEntry(info['common:shortDescription'], name),
|
|
130
|
+
row,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function loadRowsFromFile(filePath) {
|
|
134
|
+
const resolved = path.resolve(filePath);
|
|
135
|
+
const text = readFileSync(resolved, 'utf8');
|
|
136
|
+
if (resolved.endsWith('.jsonl')) {
|
|
137
|
+
return text
|
|
138
|
+
.split(/\r?\n/gu)
|
|
139
|
+
.map((line) => line.trim())
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.map((line) => {
|
|
142
|
+
const parsed = JSON.parse(line);
|
|
143
|
+
if (!isRecord(parsed)) {
|
|
144
|
+
throw new CliError(`Expected JSON object rows in JSONL file: ${resolved}`, {
|
|
145
|
+
code: 'FLOW_ROWS_INVALID_JSONL_ROW',
|
|
146
|
+
exitCode: 2,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return parsed;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const parsed = JSON.parse(text);
|
|
153
|
+
if (!Array.isArray(parsed) || !parsed.every(isRecord)) {
|
|
154
|
+
throw new CliError(`Expected JSON array of objects: ${resolved}`, {
|
|
155
|
+
code: 'FLOW_ROWS_INVALID_JSON',
|
|
156
|
+
exitCode: 2,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return parsed;
|
|
160
|
+
}
|
|
161
|
+
export const __testInternals = {
|
|
162
|
+
isRecord,
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=flow-governance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-governance.js","sourceRoot":"","sources":["../../../src/lib/flow-governance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,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;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE5C,IAAI,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI;aACR,KAAK,CAAC,SAAS,CAAC;aAChB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;aAC1B,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;YAC3C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBACtB,MAAM,IAAI,QAAQ,CAAC,4CAA4C,QAAQ,EAAE,EAAE;oBACzE,IAAI,EAAE,6BAA6B;oBACnC,QAAQ,EAAE,CAAC;iBACZ,CAAC,CAAC;YACL,CAAC;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;IAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,QAAQ,CAAC,mCAAmC,QAAQ,EAAE,EAAE;YAChE,IAAI,EAAE,wBAAwB;YAC9B,QAAQ,EAAE,CAAC;SACZ,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,QAAQ;CACT,CAAC","sourcesContent":["import { readFileSync } from 'node:fs';\nimport path from 'node:path';\nimport { CliError } from './errors.js';\n\nexport type JsonRecord = Record<string, unknown>;\n\nexport function isRecord(value: unknown): value is JsonRecord {\n return Boolean(value && typeof value === 'object' && !Array.isArray(value));\n}\n\nexport type FlowRecord = {\n id: string;\n version: string;\n name: string;\n flowType: string;\n shortDescription: JsonRecord | null;\n row: JsonRecord;\n};\n\nexport function listify<T>(value: T | T[] | null | undefined): T[] {\n if (Array.isArray(value)) {\n return value;\n }\n\n return value === undefined || value === null ? [] : [value];\n}\n\nexport function deepGet(\n value: unknown,\n pathParts: string[],\n defaultValue: unknown = undefined,\n): unknown {\n let current: unknown = value;\n\n for (const part of pathParts) {\n if (!isRecord(current)) {\n return defaultValue;\n }\n\n current = current[part];\n if (current === undefined || current === null) {\n return defaultValue;\n }\n }\n\n return current;\n}\n\nexport function coerceText(value: unknown): string {\n if (typeof value === 'string') {\n return value.trim();\n }\n\n if (isRecord(value)) {\n if (typeof value['#text'] === 'string') {\n return String(value['#text']).trim();\n }\n\n for (const nested of Object.values(value)) {\n const candidate = coerceText(nested);\n if (candidate) {\n return candidate;\n }\n }\n\n return '';\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const candidate = coerceText(item);\n if (candidate) {\n return candidate;\n }\n }\n\n return '';\n }\n\n return value === undefined || value === null ? '' : String(value).trim();\n}\n\nexport function firstLangEntry(value: unknown, fallback = ''): JsonRecord | null {\n if (isRecord(value) && ('#text' in value || '@xml:lang' in value)) {\n const text = coerceText(value);\n if (text) {\n return {\n '@xml:lang': coerceText(value['@xml:lang']) || 'en',\n '#text': text,\n };\n }\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const result = firstLangEntry(item);\n if (result) {\n return result;\n }\n }\n }\n\n if (isRecord(value)) {\n for (const nested of Object.values(value)) {\n const result = firstLangEntry(nested);\n if (result) {\n return result;\n }\n }\n }\n\n return fallback\n ? {\n '@xml:lang': 'en',\n '#text': fallback,\n }\n : null;\n}\n\nexport function normalizeText(value: string): string {\n return value\n .replace(/[^0-9a-zA-Z\\u4e00-\\u9fff]+/gu, ' ')\n .replace(/\\s+/gu, ' ')\n .trim()\n .toLowerCase();\n}\n\nexport function datasetPayloadFromRow(row: JsonRecord): JsonRecord {\n if (isRecord(row.json_ordered)) {\n return row.json_ordered;\n }\n\n if (isRecord(row.json)) {\n return row.json;\n }\n\n return row;\n}\n\nexport function flowDatasetFromRow(row: JsonRecord): JsonRecord {\n const payload = datasetPayloadFromRow(row);\n return isRecord(payload.flowDataSet) ? payload.flowDataSet : payload;\n}\n\nexport function extractFlowRecord(row: JsonRecord): FlowRecord {\n const dataset = flowDatasetFromRow(row);\n const info = deepGet(dataset, ['flowInformation', 'dataSetInformation'], {}) as JsonRecord;\n const id = coerceText(row.id) || coerceText(info['common:UUID']);\n const version =\n coerceText(row.version) ||\n coerceText(\n deepGet(dataset, [\n 'administrativeInformation',\n 'publicationAndOwnership',\n 'common:dataSetVersion',\n ]),\n ) ||\n '01.00.000';\n const nameBlock =\n deepGet(info, ['name', 'baseName']) ??\n deepGet(info, ['name']) ??\n info['common:shortDescription'];\n const name = coerceText(nameBlock) || id;\n const flowType =\n coerceText(\n deepGet(dataset, ['modellingAndValidation', 'LCIMethodAndAllocation', 'typeOfDataSet']),\n ) ||\n coerceText(deepGet(dataset, ['modellingAndValidation', 'LCIMethod', 'typeOfDataSet'])) ||\n coerceText(row.typeOfDataSet);\n\n return {\n id,\n version,\n name,\n flowType,\n shortDescription: firstLangEntry(info['common:shortDescription'], name),\n row,\n };\n}\n\nexport function loadRowsFromFile(filePath: string): JsonRecord[] {\n const resolved = path.resolve(filePath);\n const text = readFileSync(resolved, 'utf8');\n\n if (resolved.endsWith('.jsonl')) {\n return text\n .split(/\\r?\\n/gu)\n .map((line) => line.trim())\n .filter(Boolean)\n .map((line) => {\n const parsed = JSON.parse(line) as unknown;\n if (!isRecord(parsed)) {\n throw new CliError(`Expected JSON object rows in JSONL file: ${resolved}`, {\n code: 'FLOW_ROWS_INVALID_JSONL_ROW',\n exitCode: 2,\n });\n }\n return parsed;\n });\n }\n\n const parsed = JSON.parse(text) as unknown;\n if (!Array.isArray(parsed) || !parsed.every(isRecord)) {\n throw new CliError(`Expected JSON array of objects: ${resolved}`, {\n code: 'FLOW_ROWS_INVALID_JSON',\n exitCode: 2,\n });\n }\n\n return parsed;\n}\n\nexport const __testInternals = {\n isRecord,\n};\n"]}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { CliError } from './errors.js';
|
|
2
|
+
import { listFlowRows, normalizeStateCodeList, normalizeSupabaseFlowPayload, normalizeTokenList, } from './flow-read.js';
|
|
3
|
+
import { requireSupabaseRestRuntime } from './supabase-rest.js';
|
|
4
|
+
import { createSupabaseDataRuntime } from './supabase-session.js';
|
|
5
|
+
const FLOW_LIST_TIMEOUT_MS = 10_000;
|
|
6
|
+
const DEFAULT_FLOW_LIST_LIMIT = 100;
|
|
7
|
+
const DEFAULT_FLOW_LIST_PAGE_SIZE = 100;
|
|
8
|
+
const DEFAULT_FLOW_LIST_ORDER = 'id.asc,version.asc';
|
|
9
|
+
function normalizeToken(value) {
|
|
10
|
+
if (typeof value !== 'string') {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const trimmed = value.trim();
|
|
14
|
+
if (!trimmed) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return trimmed;
|
|
18
|
+
}
|
|
19
|
+
function nowIso(now = new Date()) {
|
|
20
|
+
return now.toISOString();
|
|
21
|
+
}
|
|
22
|
+
function toPositiveInteger(value, label, code) {
|
|
23
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
24
|
+
throw new CliError(`Expected ${label} to be a positive integer.`, {
|
|
25
|
+
code,
|
|
26
|
+
exitCode: 2,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function toNonNegativeInteger(value, label, code) {
|
|
32
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
33
|
+
throw new CliError(`Expected ${label} to be a non-negative integer.`, {
|
|
34
|
+
code,
|
|
35
|
+
exitCode: 2,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
export async function runFlowList(options) {
|
|
41
|
+
const ids = normalizeTokenList(options.ids);
|
|
42
|
+
const requestedVersion = normalizeToken(options.version ?? null);
|
|
43
|
+
const requestedUserId = normalizeToken(options.userId ?? null);
|
|
44
|
+
const requestedStateCodes = normalizeStateCodeList(options.stateCodes);
|
|
45
|
+
const requestedTypeOfDataset = normalizeTokenList(options.typeOfDataset);
|
|
46
|
+
const all = Boolean(options.all);
|
|
47
|
+
const order = normalizeToken(options.order ?? null) ?? DEFAULT_FLOW_LIST_ORDER;
|
|
48
|
+
if (all && options.limit !== null && options.limit !== undefined) {
|
|
49
|
+
throw new CliError('Cannot combine --all with --limit.', {
|
|
50
|
+
code: 'FLOW_LIST_ALL_LIMIT_CONFLICT',
|
|
51
|
+
exitCode: 2,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (all && options.offset !== null && options.offset !== undefined) {
|
|
55
|
+
throw new CliError('Cannot combine --all with --offset.', {
|
|
56
|
+
code: 'FLOW_LIST_ALL_OFFSET_CONFLICT',
|
|
57
|
+
exitCode: 2,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (all &&
|
|
61
|
+
ids.length === 0 &&
|
|
62
|
+
requestedVersion === null &&
|
|
63
|
+
requestedUserId === null &&
|
|
64
|
+
requestedStateCodes.length === 0 &&
|
|
65
|
+
requestedTypeOfDataset.length === 0) {
|
|
66
|
+
throw new CliError('Refusing to run --all without at least one narrowing filter.', {
|
|
67
|
+
code: 'FLOW_LIST_ALL_FILTER_REQUIRED',
|
|
68
|
+
exitCode: 2,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
72
|
+
const timeoutMs = options.timeoutMs ?? FLOW_LIST_TIMEOUT_MS;
|
|
73
|
+
const runtime = createSupabaseDataRuntime({
|
|
74
|
+
runtime: requireSupabaseRestRuntime(options.env ?? process.env),
|
|
75
|
+
fetchImpl,
|
|
76
|
+
timeoutMs,
|
|
77
|
+
now: options.now,
|
|
78
|
+
});
|
|
79
|
+
const sourceUrls = [];
|
|
80
|
+
const rows = [];
|
|
81
|
+
if (all) {
|
|
82
|
+
const pageSizeValue = options.pageSize ?? DEFAULT_FLOW_LIST_PAGE_SIZE;
|
|
83
|
+
const pageSize = toPositiveInteger(pageSizeValue, '--page-size', 'FLOW_LIST_PAGE_SIZE_INVALID');
|
|
84
|
+
let currentOffset = 0;
|
|
85
|
+
while (true) {
|
|
86
|
+
const page = await listFlowRows({
|
|
87
|
+
runtime,
|
|
88
|
+
filters: {
|
|
89
|
+
ids,
|
|
90
|
+
version: requestedVersion,
|
|
91
|
+
userId: requestedUserId,
|
|
92
|
+
stateCodes: requestedStateCodes,
|
|
93
|
+
typeOfDataset: requestedTypeOfDataset,
|
|
94
|
+
order,
|
|
95
|
+
limit: pageSize,
|
|
96
|
+
offset: currentOffset,
|
|
97
|
+
},
|
|
98
|
+
timeoutMs,
|
|
99
|
+
fetchImpl,
|
|
100
|
+
});
|
|
101
|
+
sourceUrls.push(page.sourceUrl);
|
|
102
|
+
rows.push(...page.rows.map((row) => ({
|
|
103
|
+
id: row.id,
|
|
104
|
+
version: row.version,
|
|
105
|
+
user_id: row.user_id,
|
|
106
|
+
state_code: row.state_code,
|
|
107
|
+
modified_at: row.modified_at,
|
|
108
|
+
flow: normalizeSupabaseFlowPayload(row.json, `${row.id}@${row.version}`),
|
|
109
|
+
})));
|
|
110
|
+
if (page.rows.length < pageSize) {
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
currentOffset += pageSize;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
schema_version: 1,
|
|
117
|
+
generated_at_utc: nowIso(options.now),
|
|
118
|
+
status: 'listed_remote_flows',
|
|
119
|
+
filters: {
|
|
120
|
+
ids,
|
|
121
|
+
requested_version: requestedVersion,
|
|
122
|
+
requested_user_id: requestedUserId,
|
|
123
|
+
requested_state_codes: requestedStateCodes,
|
|
124
|
+
requested_type_of_dataset: requestedTypeOfDataset,
|
|
125
|
+
order,
|
|
126
|
+
all: true,
|
|
127
|
+
limit: null,
|
|
128
|
+
offset: 0,
|
|
129
|
+
page_size: pageSize,
|
|
130
|
+
},
|
|
131
|
+
count: rows.length,
|
|
132
|
+
source_urls: sourceUrls,
|
|
133
|
+
rows,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const limit = toPositiveInteger(options.limit ?? DEFAULT_FLOW_LIST_LIMIT, '--limit', 'FLOW_LIST_LIMIT_INVALID');
|
|
137
|
+
const offset = toNonNegativeInteger(options.offset ?? 0, '--offset', 'FLOW_LIST_OFFSET_INVALID');
|
|
138
|
+
const page = await listFlowRows({
|
|
139
|
+
runtime,
|
|
140
|
+
filters: {
|
|
141
|
+
ids,
|
|
142
|
+
version: requestedVersion,
|
|
143
|
+
userId: requestedUserId,
|
|
144
|
+
stateCodes: requestedStateCodes,
|
|
145
|
+
typeOfDataset: requestedTypeOfDataset,
|
|
146
|
+
order,
|
|
147
|
+
limit,
|
|
148
|
+
offset,
|
|
149
|
+
},
|
|
150
|
+
timeoutMs,
|
|
151
|
+
fetchImpl,
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
schema_version: 1,
|
|
155
|
+
generated_at_utc: nowIso(options.now),
|
|
156
|
+
status: 'listed_remote_flows',
|
|
157
|
+
filters: {
|
|
158
|
+
ids,
|
|
159
|
+
requested_version: requestedVersion,
|
|
160
|
+
requested_user_id: requestedUserId,
|
|
161
|
+
requested_state_codes: requestedStateCodes,
|
|
162
|
+
requested_type_of_dataset: requestedTypeOfDataset,
|
|
163
|
+
order,
|
|
164
|
+
all: false,
|
|
165
|
+
limit,
|
|
166
|
+
offset,
|
|
167
|
+
page_size: null,
|
|
168
|
+
},
|
|
169
|
+
count: page.rows.length,
|
|
170
|
+
source_urls: [page.sourceUrl],
|
|
171
|
+
rows: page.rows.map((row) => ({
|
|
172
|
+
id: row.id,
|
|
173
|
+
version: row.version,
|
|
174
|
+
user_id: row.user_id,
|
|
175
|
+
state_code: row.state_code,
|
|
176
|
+
modified_at: row.modified_at,
|
|
177
|
+
flow: normalizeSupabaseFlowPayload(row.json, `${row.id}@${row.version}`),
|
|
178
|
+
})),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export const __testInternals = {
|
|
182
|
+
normalizeToken,
|
|
183
|
+
nowIso,
|
|
184
|
+
toPositiveInteger,
|
|
185
|
+
toNonNegativeInteger,
|
|
186
|
+
};
|
|
187
|
+
//# sourceMappingURL=flow-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-list.js","sourceRoot":"","sources":["../../../src/lib/flow-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAIlE,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AA+CrD,SAAS,cAAc,CAAC,KAAgC;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,MAAM,CAAC,MAAY,IAAI,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AE,IAAI,CAAC,IAAI,CAAC,MAAM;QACvB,WAAW,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;QAC7B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC5B,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,IAAI,EAAE,4BAA4B,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;SACzE,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,cAAc;IACd,MAAM;IACN,iBAAiB;IACjB,oBAAoB;CACrB,CAAC","sourcesContent":["import { CliError } from './errors.js';\nimport type { FetchLike } from './http.js';\nimport {\n listFlowRows,\n normalizeStateCodeList,\n normalizeSupabaseFlowPayload,\n normalizeTokenList,\n} from './flow-read.js';\nimport { requireSupabaseRestRuntime } from './supabase-rest.js';\nimport { createSupabaseDataRuntime } from './supabase-session.js';\n\ntype JsonObject = Record<string, unknown>;\n\nconst FLOW_LIST_TIMEOUT_MS = 10_000;\nconst DEFAULT_FLOW_LIST_LIMIT = 100;\nconst DEFAULT_FLOW_LIST_PAGE_SIZE = 100;\nconst DEFAULT_FLOW_LIST_ORDER = 'id.asc,version.asc';\n\nexport type RunFlowListOptions = {\n ids?: string[];\n version?: string | null;\n userId?: string | null;\n stateCodes?: number[];\n typeOfDataset?: string[];\n limit?: number | null;\n offset?: number | null;\n all?: boolean;\n pageSize?: number | null;\n order?: string | null;\n env?: NodeJS.ProcessEnv;\n fetchImpl?: FetchLike;\n timeoutMs?: number;\n now?: Date;\n};\n\nexport type FlowListReport = {\n schema_version: 1;\n generated_at_utc: string;\n status: 'listed_remote_flows';\n filters: {\n ids: string[];\n requested_version: string | null;\n requested_user_id: string | null;\n requested_state_codes: number[];\n requested_type_of_dataset: string[];\n order: string;\n all: boolean;\n limit: number | null;\n offset: number;\n page_size: number | null;\n };\n count: number;\n source_urls: string[];\n rows: Array<{\n id: string;\n version: string;\n user_id: string | null;\n state_code: number | null;\n modified_at: string | null;\n flow: JsonObject;\n }>;\n};\n\nfunction normalizeToken(value: string | null | undefined): string | null {\n if (typeof value !== 'string') {\n return null;\n }\n\n const trimmed = value.trim();\n if (!trimmed) {\n return null;\n }\n return trimmed;\n}\n\nfunction nowIso(now: Date = new Date()): string {\n return now.toISOString();\n}\n\nfunction toPositiveInteger(value: number | null | undefined, label: string, code: string): number {\n if (!Number.isInteger(value) || (value as number) <= 0) {\n throw new CliError(`Expected ${label} to be a positive integer.`, {\n code,\n exitCode: 2,\n });\n }\n return value as number;\n}\n\nfunction toNonNegativeInteger(\n value: number | null | undefined,\n label: string,\n code: string,\n): number {\n if (!Number.isInteger(value) || (value as number) < 0) {\n throw new CliError(`Expected ${label} to be a non-negative integer.`, {\n code,\n exitCode: 2,\n });\n }\n return value as number;\n}\n\nexport async function runFlowList(options: RunFlowListOptions): Promise<FlowListReport> {\n const ids = normalizeTokenList(options.ids);\n const requestedVersion = normalizeToken(options.version ?? null);\n const requestedUserId = normalizeToken(options.userId ?? null);\n const requestedStateCodes = normalizeStateCodeList(options.stateCodes);\n const requestedTypeOfDataset = normalizeTokenList(options.typeOfDataset);\n const all = Boolean(options.all);\n const order = normalizeToken(options.order ?? null) ?? DEFAULT_FLOW_LIST_ORDER;\n\n if (all && options.limit !== null && options.limit !== undefined) {\n throw new CliError('Cannot combine --all with --limit.', {\n code: 'FLOW_LIST_ALL_LIMIT_CONFLICT',\n exitCode: 2,\n });\n }\n\n if (all && options.offset !== null && options.offset !== undefined) {\n throw new CliError('Cannot combine --all with --offset.', {\n code: 'FLOW_LIST_ALL_OFFSET_CONFLICT',\n exitCode: 2,\n });\n }\n\n if (\n all &&\n ids.length === 0 &&\n requestedVersion === null &&\n requestedUserId === null &&\n requestedStateCodes.length === 0 &&\n requestedTypeOfDataset.length === 0\n ) {\n throw new CliError('Refusing to run --all without at least one narrowing filter.', {\n code: 'FLOW_LIST_ALL_FILTER_REQUIRED',\n exitCode: 2,\n });\n }\n\n const fetchImpl = options.fetchImpl ?? (fetch as FetchLike);\n const timeoutMs = options.timeoutMs ?? FLOW_LIST_TIMEOUT_MS;\n const runtime = createSupabaseDataRuntime({\n runtime: requireSupabaseRestRuntime(options.env ?? process.env),\n fetchImpl,\n timeoutMs,\n now: options.now,\n });\n const sourceUrls: string[] = [];\n\n const rows: FlowListReport['rows'] = [];\n if (all) {\n const pageSizeValue = options.pageSize ?? DEFAULT_FLOW_LIST_PAGE_SIZE;\n const pageSize = toPositiveInteger(pageSizeValue, '--page-size', 'FLOW_LIST_PAGE_SIZE_INVALID');\n let currentOffset = 0;\n while (true) {\n const page = await listFlowRows({\n runtime,\n filters: {\n ids,\n version: requestedVersion,\n userId: requestedUserId,\n stateCodes: requestedStateCodes,\n typeOfDataset: requestedTypeOfDataset,\n order,\n limit: pageSize,\n offset: currentOffset,\n },\n timeoutMs,\n fetchImpl,\n });\n sourceUrls.push(page.sourceUrl);\n rows.push(\n ...page.rows.map((row) => ({\n id: row.id,\n version: row.version,\n user_id: row.user_id,\n state_code: row.state_code,\n modified_at: row.modified_at,\n flow: normalizeSupabaseFlowPayload(row.json, `${row.id}@${row.version}`),\n })),\n );\n if (page.rows.length < pageSize) {\n break;\n }\n currentOffset += pageSize;\n }\n\n return {\n schema_version: 1,\n generated_at_utc: nowIso(options.now),\n status: 'listed_remote_flows',\n filters: {\n ids,\n requested_version: requestedVersion,\n requested_user_id: requestedUserId,\n requested_state_codes: requestedStateCodes,\n requested_type_of_dataset: requestedTypeOfDataset,\n order,\n all: true,\n limit: null,\n offset: 0,\n page_size: pageSize,\n },\n count: rows.length,\n source_urls: sourceUrls,\n rows,\n };\n }\n\n const limit = toPositiveInteger(\n options.limit ?? DEFAULT_FLOW_LIST_LIMIT,\n '--limit',\n 'FLOW_LIST_LIMIT_INVALID',\n );\n const offset = toNonNegativeInteger(options.offset ?? 0, '--offset', 'FLOW_LIST_OFFSET_INVALID');\n const page = await listFlowRows({\n runtime,\n filters: {\n ids,\n version: requestedVersion,\n userId: requestedUserId,\n stateCodes: requestedStateCodes,\n typeOfDataset: requestedTypeOfDataset,\n order,\n limit,\n offset,\n },\n timeoutMs,\n fetchImpl,\n });\n\n return {\n schema_version: 1,\n generated_at_utc: nowIso(options.now),\n status: 'listed_remote_flows',\n filters: {\n ids,\n requested_version: requestedVersion,\n requested_user_id: requestedUserId,\n requested_state_codes: requestedStateCodes,\n requested_type_of_dataset: requestedTypeOfDataset,\n order,\n all: false,\n limit,\n offset,\n page_size: null,\n },\n count: page.rows.length,\n source_urls: [page.sourceUrl],\n rows: page.rows.map((row) => ({\n id: row.id,\n version: row.version,\n user_id: row.user_id,\n state_code: row.state_code,\n modified_at: row.modified_at,\n flow: normalizeSupabaseFlowPayload(row.json, `${row.id}@${row.version}`),\n })),\n };\n}\n\nexport const __testInternals = {\n normalizeToken,\n nowIso,\n toPositiveInteger,\n toNonNegativeInteger,\n};\n"]}
|