@tiangong-lca/cli 0.1.0 → 0.1.2

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.
Files changed (159) hide show
  1. package/README.md +58 -6
  2. package/dist/src/batch.d.ts +6 -0
  3. package/dist/src/batch.js +6 -0
  4. package/dist/src/batch.js.map +1 -0
  5. package/dist/src/cli.d.ts +161 -0
  6. package/dist/src/cli.js +130 -0
  7. package/dist/src/cli.js.map +1 -1
  8. package/dist/src/command-spec.d.ts +90 -0
  9. package/dist/src/command-spec.js +400 -0
  10. package/dist/src/command-spec.js.map +1 -0
  11. package/dist/src/lib/artifacts.d.ts +9 -0
  12. package/dist/src/lib/auth-identity-receipt.d.ts +160 -0
  13. package/dist/src/lib/auth-identity-receipt.js +634 -0
  14. package/dist/src/lib/auth-identity-receipt.js.map +1 -0
  15. package/dist/src/lib/batch/attempt-recovery.d.ts +12 -0
  16. package/dist/src/lib/batch/attempt-recovery.js +183 -0
  17. package/dist/src/lib/batch/attempt-recovery.js.map +1 -0
  18. package/dist/src/lib/batch/canonical-contracts.d.ts +21 -0
  19. package/dist/src/lib/batch/canonical-contracts.js +180 -0
  20. package/dist/src/lib/batch/canonical-contracts.js.map +1 -0
  21. package/dist/src/lib/batch/engine.d.ts +2 -0
  22. package/dist/src/lib/batch/engine.js +294 -0
  23. package/dist/src/lib/batch/engine.js.map +1 -0
  24. package/dist/src/lib/batch/errors.d.ts +51 -0
  25. package/dist/src/lib/batch/errors.js +81 -0
  26. package/dist/src/lib/batch/errors.js.map +1 -0
  27. package/dist/src/lib/batch/item-projection.d.ts +10 -0
  28. package/dist/src/lib/batch/item-projection.js +118 -0
  29. package/dist/src/lib/batch/item-projection.js.map +1 -0
  30. package/dist/src/lib/batch/run-lock.d.ts +4 -0
  31. package/dist/src/lib/batch/run-lock.js +155 -0
  32. package/dist/src/lib/batch/run-lock.js.map +1 -0
  33. package/dist/src/lib/batch/scheduler-runtime.d.ts +29 -0
  34. package/dist/src/lib/batch/scheduler-runtime.js +114 -0
  35. package/dist/src/lib/batch/scheduler-runtime.js.map +1 -0
  36. package/dist/src/lib/batch/types.d.ts +183 -0
  37. package/dist/src/lib/batch/types.js +2 -0
  38. package/dist/src/lib/batch/types.js.map +1 -0
  39. package/dist/src/lib/dataset-author.d.ts +39 -0
  40. package/dist/src/lib/dataset-bilingual.d.ts +165 -0
  41. package/dist/src/lib/dataset-classification.d.ts +279 -0
  42. package/dist/src/lib/dataset-command.d.ts +53 -0
  43. package/dist/src/lib/dataset-contract.d.ts +82 -0
  44. package/dist/src/lib/dataset-curation-queue.d.ts +219 -0
  45. package/dist/src/lib/dataset-evidence-search.d.ts +134 -0
  46. package/dist/src/lib/dataset-import-lca.d.ts +136 -0
  47. package/dist/src/lib/dataset-local.d.ts +23 -0
  48. package/dist/src/lib/dataset-maintenance-alias-request.d.ts +12 -0
  49. package/dist/src/lib/dataset-maintenance-alias-rewrite.d.ts +111 -0
  50. package/dist/src/lib/dataset-maintenance-apply.d.ts +458 -0
  51. package/dist/src/lib/dataset-maintenance-clear-account.d.ts +161 -0
  52. package/dist/src/lib/dataset-maintenance-contract.d.ts +317 -0
  53. package/dist/src/lib/dataset-maintenance-derivatives.d.ts +48 -0
  54. package/dist/src/lib/dataset-maintenance-flow-identity-approval-claim.d.ts +50 -0
  55. package/dist/src/lib/dataset-maintenance-flow-identity-capture.d.ts +110 -0
  56. package/dist/src/lib/dataset-maintenance-flow-identity-command.d.ts +15 -0
  57. package/dist/src/lib/dataset-maintenance-flow-identity-contract.d.ts +387 -0
  58. package/dist/src/lib/dataset-maintenance-flow-identity-execution-contract.d.ts +456 -0
  59. package/dist/src/lib/dataset-maintenance-flow-identity-freeze.d.ts +99 -0
  60. package/dist/src/lib/dataset-maintenance-flow-identity-plan.d.ts +85 -0
  61. package/dist/src/lib/dataset-maintenance-flow-identity-recovery.d.ts +268 -0
  62. package/dist/src/lib/dataset-maintenance-flow-identity-run.d.ts +123 -0
  63. package/dist/src/lib/dataset-maintenance-flow-identity-seal.d.ts +50 -0
  64. package/dist/src/lib/dataset-maintenance-flow-identity-verify.d.ts +85 -0
  65. package/dist/src/lib/dataset-maintenance-flow-identity-wire.d.ts +32 -0
  66. package/dist/src/lib/dataset-maintenance-pagination.d.ts +58 -0
  67. package/dist/src/lib/dataset-maintenance-plan.d.ts +40 -0
  68. package/dist/src/lib/dataset-maintenance-protected-artifacts.d.ts +16 -0
  69. package/dist/src/lib/dataset-maintenance-protected-before.d.ts +71 -0
  70. package/dist/src/lib/dataset-maintenance-protected-contract.d.ts +385 -0
  71. package/dist/src/lib/dataset-maintenance-protected-freeze.d.ts +148 -0
  72. package/dist/src/lib/dataset-maintenance-protected-preparation.d.ts +76 -0
  73. package/dist/src/lib/dataset-maintenance-protected-run.d.ts +252 -0
  74. package/dist/src/lib/dataset-maintenance-protected-seal.d.ts +93 -0
  75. package/dist/src/lib/dataset-maintenance-protected-toolchain.d.ts +31 -0
  76. package/dist/src/lib/dataset-maintenance-protected-verify.d.ts +99 -0
  77. package/dist/src/lib/dataset-maintenance-remote.d.ts +212 -0
  78. package/dist/src/lib/dataset-maintenance-support-validation.d.ts +18 -0
  79. package/dist/src/lib/dataset-maintenance-verify.d.ts +102 -0
  80. package/dist/src/lib/dataset-patch.d.ts +193 -0
  81. package/dist/src/lib/dataset-references-rewrite.d.ts +77 -0
  82. package/dist/src/lib/dataset-remote-refresh.d.ts +64 -0
  83. package/dist/src/lib/dataset-remote-verify.d.ts +168 -0
  84. package/dist/src/lib/dataset-save-draft-run.d.ts +283 -0
  85. package/dist/src/lib/dataset-save-draft-run.js +54 -21
  86. package/dist/src/lib/dataset-save-draft-run.js.map +1 -1
  87. package/dist/src/lib/dataset-source-upload-attachments.d.ts +109 -0
  88. package/dist/src/lib/dataset-validate.d.ts +62 -0
  89. package/dist/src/lib/dotenv.d.ts +6 -0
  90. package/dist/src/lib/env.d.ts +59 -0
  91. package/dist/src/lib/errors.d.ts +18 -0
  92. package/dist/src/lib/flow-build-alias-map.d.ts +80 -0
  93. package/dist/src/lib/flow-fetch-rows.d.ts +70 -0
  94. package/dist/src/lib/flow-get.d.ts +35 -0
  95. package/dist/src/lib/flow-governance.d.ts +22 -0
  96. package/dist/src/lib/flow-list.d.ts +57 -0
  97. package/dist/src/lib/flow-materialize-decisions.d.ts +67 -0
  98. package/dist/src/lib/flow-payload-validation.d.ts +32 -0
  99. package/dist/src/lib/flow-publish-reviewed-data.d.ts +262 -0
  100. package/dist/src/lib/flow-publish-version.d.ts +193 -0
  101. package/dist/src/lib/flow-qa.d.ts +289 -0
  102. package/dist/src/lib/flow-read.d.ts +70 -0
  103. package/dist/src/lib/flow-regen-product.d.ts +431 -0
  104. package/dist/src/lib/flow-remediate.d.ts +133 -0
  105. package/dist/src/lib/http.d.ts +25 -0
  106. package/dist/src/lib/http.js.map +1 -1
  107. package/dist/src/lib/identity-preflight.d.ts +235 -0
  108. package/dist/src/lib/io.d.ts +2 -0
  109. package/dist/src/lib/kb-search.d.ts +23 -0
  110. package/dist/src/lib/lca-release.d.ts +105 -0
  111. package/dist/src/lib/lifecyclemodel-auto-build.d.ts +223 -0
  112. package/dist/src/lib/lifecyclemodel-bundle-save.d.ts +71 -0
  113. package/dist/src/lib/lifecyclemodel-graph.d.ts +91 -0
  114. package/dist/src/lib/lifecyclemodel-orchestrate.d.ts +349 -0
  115. package/dist/src/lib/lifecyclemodel-publish-build.d.ts +77 -0
  116. package/dist/src/lib/lifecyclemodel-publish-resulting-process.d.ts +27 -0
  117. package/dist/src/lib/lifecyclemodel-qa.d.ts +206 -0
  118. package/dist/src/lib/lifecyclemodel-resulting-process.d.ts +204 -0
  119. package/dist/src/lib/lifecyclemodel-save-draft-run.d.ts +96 -0
  120. package/dist/src/lib/lifecyclemodel-validate-build.d.ts +78 -0
  121. package/dist/src/lib/llm.d.ts +51 -0
  122. package/dist/src/lib/package-version.d.ts +3 -0
  123. package/dist/src/lib/process-auto-build.d.ts +168 -0
  124. package/dist/src/lib/process-batch-build.d.ts +97 -0
  125. package/dist/src/lib/process-dedup-review.d.ts +253 -0
  126. package/dist/src/lib/process-flow-build-plan.d.ts +108 -0
  127. package/dist/src/lib/process-get.d.ts +26 -0
  128. package/dist/src/lib/process-list.d.ts +87 -0
  129. package/dist/src/lib/process-payload-validation.d.ts +27 -0
  130. package/dist/src/lib/process-publish-build.d.ts +148 -0
  131. package/dist/src/lib/process-qa.d.ts +243 -0
  132. package/dist/src/lib/process-refresh-references.d.ts +179 -0
  133. package/dist/src/lib/process-required-fields.d.ts +142 -0
  134. package/dist/src/lib/process-resume-build.d.ts +77 -0
  135. package/dist/src/lib/process-save-draft-run.d.ts +72 -0
  136. package/dist/src/lib/process-save-draft.d.ts +53 -0
  137. package/dist/src/lib/process-scope-statistics.d.ts +210 -0
  138. package/dist/src/lib/process-verify-rows.d.ts +71 -0
  139. package/dist/src/lib/publish.d.ts +219 -0
  140. package/dist/src/lib/remote.d.ts +19 -0
  141. package/dist/src/lib/run.d.ts +60 -0
  142. package/dist/src/lib/runtime-rulesets.d.ts +29 -0
  143. package/dist/src/lib/state-lock.d.ts +25 -0
  144. package/dist/src/lib/state-lock.js +23 -1
  145. package/dist/src/lib/state-lock.js.map +1 -1
  146. package/dist/src/lib/supabase-client.d.ts +47 -0
  147. package/dist/src/lib/supabase-data-api-contract.d.ts +304 -0
  148. package/dist/src/lib/supabase-data-api-replay.d.ts +74 -0
  149. package/dist/src/lib/supabase-json-ordered-write.d.ts +65 -0
  150. package/dist/src/lib/supabase-rest.d.ts +26 -0
  151. package/dist/src/lib/supabase-session.d.ts +115 -0
  152. package/dist/src/lib/tidas-languages.d.ts +3 -0
  153. package/dist/src/lib/tidas-sdk-package-validator.d.ts +111 -0
  154. package/dist/src/lib/tidas-sdk-validation.d.ts +42 -0
  155. package/dist/src/lib/unstructured.d.ts +32 -0
  156. package/dist/src/lib/user-api-key.d.ts +16 -0
  157. package/dist/src/lib/validation.d.ts +82 -0
  158. package/dist/src/main.d.ts +4 -0
  159. package/package.json +17 -3
@@ -0,0 +1,142 @@
1
+ import { type DatasetRowInput, type JsonObject } from './dataset-local.js';
2
+ type AnnualSupplyStatus = 'existing' | 'completed' | 'blocked' | 'skipped';
3
+ export type ProcessRequiredFieldIssue = {
4
+ code: string;
5
+ message: string;
6
+ path: string;
7
+ };
8
+ export type ProcessRequiredFieldCompletion = {
9
+ field_path: string;
10
+ source: 'existing' | 'evidence' | 'missing_data_sentinel' | 'placeholder_repair' | 'required_structure_repair';
11
+ value: Array<{
12
+ '#text': string;
13
+ '@xml:lang': string;
14
+ }>;
15
+ amount: string | null;
16
+ unit: string | null;
17
+ reference_exchange_internal_id: string | null;
18
+ basis: string;
19
+ };
20
+ export type ProcessRequiredFieldsRowReport = {
21
+ index: number;
22
+ id: string | null;
23
+ version: string | null;
24
+ type: string | null;
25
+ status: AnnualSupplyStatus;
26
+ issues: ProcessRequiredFieldIssue[];
27
+ completions: ProcessRequiredFieldCompletion[];
28
+ };
29
+ export type ProcessRequiredFieldsReport = {
30
+ generated_at_utc: string;
31
+ input_path: string;
32
+ out_path: string;
33
+ out_dir: string | null;
34
+ status: 'completed' | 'completed_with_blockers';
35
+ default_unit: string;
36
+ counts: {
37
+ total: number;
38
+ processes: number;
39
+ completed: number;
40
+ existing: number;
41
+ blocked: number;
42
+ skipped: number;
43
+ };
44
+ files: {
45
+ output_rows: string;
46
+ report: string | null;
47
+ evidence: string | null;
48
+ };
49
+ rows: ProcessRequiredFieldsRowReport[];
50
+ };
51
+ export type RunProcessRequiredFieldsCompleteOptions = {
52
+ inputPath: string;
53
+ outPath: string;
54
+ outDir?: string | null;
55
+ defaultUnit?: string | null;
56
+ flowInputPath?: string | null;
57
+ rawInput?: unknown;
58
+ rawFlowInput?: unknown;
59
+ now?: Date;
60
+ };
61
+ type CompletionContext = {
62
+ defaultUnit: string;
63
+ flowUnitById?: Map<string, string>;
64
+ };
65
+ type AnnualSupplyEvidenceValue = {
66
+ value: Array<{
67
+ '#text': string;
68
+ '@xml:lang': string;
69
+ }>;
70
+ amount: string;
71
+ unit: string;
72
+ basis: string;
73
+ };
74
+ declare function textValue(value: unknown): string | null;
75
+ declare function valueAtPath(root: unknown, pathExpression: string): unknown;
76
+ declare function isValidAnnualSupplyVolume(value: unknown): boolean;
77
+ declare function hasDeferredAnnualSupplyTrace(root: JsonObject): boolean;
78
+ declare function isValidReview(value: unknown): boolean;
79
+ declare function isValidComplianceDeclaration(value: unknown): boolean;
80
+ export declare function collectProcessRequiredFieldIssues(payload: JsonObject): ProcessRequiredFieldIssue[];
81
+ declare function issuePath(pathSegments: Array<string | number>): string;
82
+ export declare function collectProcessPlaceholderIssues(payload: JsonObject): ProcessRequiredFieldIssue[];
83
+ declare function repairRequiredProcessStructures(root: JsonObject): ProcessRequiredFieldCompletion[];
84
+ declare function selectReferenceExchange(root: JsonObject): JsonObject | null;
85
+ declare function inferSpecificUnitFromFlowPayload(payload: JsonObject): string | null;
86
+ declare function buildFlowUnitIndex(flowRows: DatasetRowInput[], fallbackUnit: string): Map<string, string>;
87
+ declare function inferUnitFromReferenceExchange(exchange: JsonObject, fallbackOrContext: string | CompletionContext): string;
88
+ declare function annualSupplyTextParts(value: string): {
89
+ amount: string;
90
+ unit: string;
91
+ } | null;
92
+ declare function annualSupplyValueFromText(value: string): AnnualSupplyEvidenceValue | null;
93
+ declare function normalizeAnnualSupplyEvidenceValue(candidate: unknown, context: CompletionContext): AnnualSupplyEvidenceValue | null;
94
+ declare function isAnnualSupplyEvidencePath(pathExpression: string | null): boolean;
95
+ declare function fieldPathFromEvidenceEntry(entry: JsonObject): string | null;
96
+ declare function findAnnualSupplyEvidenceEntry(container: unknown, context: CompletionContext): AnnualSupplyEvidenceValue | null;
97
+ declare function findAnnualSupplyEvidenceValue(row: JsonObject, payload: JsonObject, context: CompletionContext): AnnualSupplyEvidenceValue | null;
98
+ declare function ensureDataSources(root: JsonObject): JsonObject;
99
+ declare function annualSupplyMissingDataSentinelValue(): Array<{
100
+ '#text': string;
101
+ '@xml:lang': string;
102
+ }>;
103
+ declare function cloneRowWithPayload(row: DatasetRowInput): {
104
+ row: JsonObject;
105
+ payload: JsonObject;
106
+ };
107
+ declare function completeProcessRow(row: DatasetRowInput, context: CompletionContext): {
108
+ row: JsonObject;
109
+ report: ProcessRequiredFieldsRowReport;
110
+ };
111
+ declare function requireOutputPath(value: string): string;
112
+ export declare function runProcessRequiredFieldsComplete(options: RunProcessRequiredFieldsCompleteOptions): Promise<ProcessRequiredFieldsReport>;
113
+ export declare const __testInternals: {
114
+ ANNUAL_SUPPLY_MISSING_DATA_SENTINEL_TEXT: string;
115
+ ANNUAL_SUPPLY_ROOT_FIELD: string;
116
+ annualSupplyMissingDataSentinelValue: typeof annualSupplyMissingDataSentinelValue;
117
+ annualSupplyTextParts: typeof annualSupplyTextParts;
118
+ annualSupplyValueFromText: typeof annualSupplyValueFromText;
119
+ cloneRowWithPayload: typeof cloneRowWithPayload;
120
+ collectProcessRequiredFieldIssues: typeof collectProcessRequiredFieldIssues;
121
+ completeProcessRow: typeof completeProcessRow;
122
+ ensureDataSources: typeof ensureDataSources;
123
+ fieldPathFromEvidenceEntry: typeof fieldPathFromEvidenceEntry;
124
+ hasDeferredAnnualSupplyTrace: typeof hasDeferredAnnualSupplyTrace;
125
+ findAnnualSupplyEvidenceValue: typeof findAnnualSupplyEvidenceValue;
126
+ findAnnualSupplyEvidenceEntry: typeof findAnnualSupplyEvidenceEntry;
127
+ buildFlowUnitIndex: typeof buildFlowUnitIndex;
128
+ inferUnitFromReferenceExchange: typeof inferUnitFromReferenceExchange;
129
+ inferSpecificUnitFromFlowPayload: typeof inferSpecificUnitFromFlowPayload;
130
+ issuePath: typeof issuePath;
131
+ isAnnualSupplyEvidencePath: typeof isAnnualSupplyEvidencePath;
132
+ isValidComplianceDeclaration: typeof isValidComplianceDeclaration;
133
+ isValidAnnualSupplyVolume: typeof isValidAnnualSupplyVolume;
134
+ isValidReview: typeof isValidReview;
135
+ normalizeAnnualSupplyEvidenceValue: typeof normalizeAnnualSupplyEvidenceValue;
136
+ repairRequiredProcessStructures: typeof repairRequiredProcessStructures;
137
+ requireOutputPath: typeof requireOutputPath;
138
+ selectReferenceExchange: typeof selectReferenceExchange;
139
+ textValue: typeof textValue;
140
+ valueAtPath: typeof valueAtPath;
141
+ };
142
+ export {};
@@ -0,0 +1,77 @@
1
+ type JsonRecord = Record<string, unknown>;
2
+ export type ProcessResumeBuildLayout = {
3
+ runId: string;
4
+ runRoot: string;
5
+ collectionDir: string;
6
+ cacheDir: string;
7
+ manifestsDir: string;
8
+ reportsDir: string;
9
+ latestRunIdPath: string;
10
+ statePath: string;
11
+ handoffSummaryPath: string;
12
+ runManifestPath: string;
13
+ invocationIndexPath: string;
14
+ resumeMetadataPath: string;
15
+ resumeHistoryPath: string;
16
+ reportPath: string;
17
+ };
18
+ export type ProcessResumeBuildReport = {
19
+ schema_version: 1;
20
+ generated_at_utc: string;
21
+ status: 'prepared_local_process_resume_run';
22
+ run_id: string;
23
+ run_root: string;
24
+ request_id: string | null;
25
+ resumed_from: string;
26
+ checkpoint: string | null;
27
+ attempt: number;
28
+ state_summary: {
29
+ build_status: string | null;
30
+ next_stage: string | null;
31
+ stop_after: string | null;
32
+ process_count: number;
33
+ matched_exchange_count: number;
34
+ process_dataset_count: number;
35
+ source_dataset_count: number;
36
+ };
37
+ files: {
38
+ state: string;
39
+ handoff_summary: string;
40
+ run_manifest: string;
41
+ invocation_index: string;
42
+ resume_metadata: string;
43
+ resume_history: string;
44
+ report: string;
45
+ };
46
+ next_actions: string[];
47
+ };
48
+ export type RunProcessResumeBuildOptions = {
49
+ runId?: string;
50
+ runDir?: string | null;
51
+ now?: Date;
52
+ cwd?: string;
53
+ };
54
+ declare function buildLayout(runRoot: string, runId: string): ProcessResumeBuildLayout;
55
+ declare function resolveLayout(options: RunProcessResumeBuildOptions): ProcessResumeBuildLayout;
56
+ declare function buildStateSummary(state: JsonRecord): ProcessResumeBuildReport['state_summary'];
57
+ declare function resolveResumedFrom(state: JsonRecord): string;
58
+ declare function nextAttempt(history: JsonRecord[]): number;
59
+ declare function updateStepMarkers(stepMarkers: unknown, completedAt: string): JsonRecord;
60
+ declare function buildUpdatedState(state: JsonRecord, resumeMetadata: JsonRecord, now: Date): JsonRecord;
61
+ declare function buildInvocationIndex(layout: ProcessResumeBuildLayout, invocationIndex: JsonRecord, options: RunProcessResumeBuildOptions, now: Date): JsonRecord;
62
+ declare function buildNextActions(layout: ProcessResumeBuildLayout, summary: ProcessResumeBuildReport['state_summary']): string[];
63
+ declare function buildReport(layout: ProcessResumeBuildLayout, state: JsonRecord, resumeMetadata: JsonRecord, summary: ProcessResumeBuildReport['state_summary'], now: Date): ProcessResumeBuildReport;
64
+ export declare function runProcessResumeBuild(options: RunProcessResumeBuildOptions): Promise<ProcessResumeBuildReport>;
65
+ export declare const __testInternals: {
66
+ buildLayout: typeof buildLayout;
67
+ resolveLayout: typeof resolveLayout;
68
+ buildStateSummary: typeof buildStateSummary;
69
+ resolveResumedFrom: typeof resolveResumedFrom;
70
+ nextAttempt: typeof nextAttempt;
71
+ updateStepMarkers: typeof updateStepMarkers;
72
+ buildUpdatedState: typeof buildUpdatedState;
73
+ buildInvocationIndex: typeof buildInvocationIndex;
74
+ buildNextActions: typeof buildNextActions;
75
+ buildReport: typeof buildReport;
76
+ };
77
+ export {};
@@ -0,0 +1,72 @@
1
+ import type { FetchLike } from './http.js';
2
+ import { type ProcessPayloadValidationResult } from './process-payload-validation.js';
3
+ import { type ProcessStateAwareWriteResult } from './process-save-draft.js';
4
+ type JsonObject = Record<string, unknown>;
5
+ export type ProcessSaveDraftSource = 'rows_file' | 'bundle' | 'input';
6
+ export type ProcessSaveDraftCandidate = {
7
+ id: string | null;
8
+ version: string | null;
9
+ source: ProcessSaveDraftSource;
10
+ bundle_path: string | null;
11
+ payload: JsonObject;
12
+ validation?: ProcessPayloadValidationResult;
13
+ error?: {
14
+ message: string;
15
+ };
16
+ };
17
+ export type ProcessSaveDraftProcessReport = {
18
+ id: string | null;
19
+ version: string | null;
20
+ source: ProcessSaveDraftSource;
21
+ bundle_path: string | null;
22
+ status: 'prepared' | 'executed' | 'failed';
23
+ validation?: ProcessPayloadValidationResult;
24
+ execution?: ProcessStateAwareWriteResult;
25
+ error?: {
26
+ message: string;
27
+ };
28
+ };
29
+ export type ProcessSaveDraftReport = {
30
+ generated_at_utc: string;
31
+ input_path: string;
32
+ input_kind: 'rows_file' | 'publish_request';
33
+ out_dir: string;
34
+ commit: boolean;
35
+ mode: 'dry_run' | 'commit';
36
+ target_user_id: string | null;
37
+ account_guard: {
38
+ target_user_id_required: boolean;
39
+ target_user_id: string | null;
40
+ commit_account_binding: 'current_cli_auth_session';
41
+ post_write_verify_required: boolean;
42
+ };
43
+ status: 'completed' | 'completed_with_failures';
44
+ counts: {
45
+ selected: number;
46
+ prepared: number;
47
+ executed: number;
48
+ failed: number;
49
+ };
50
+ files: {
51
+ normalized_input: string;
52
+ selected_processes: string;
53
+ progress_jsonl: string;
54
+ failures_jsonl: string;
55
+ summary_json: string;
56
+ };
57
+ processes: ProcessSaveDraftProcessReport[];
58
+ };
59
+ export type RunProcessSaveDraftOptions = {
60
+ inputPath: string;
61
+ outDir?: string | null;
62
+ commit?: boolean | null;
63
+ rawInput?: unknown;
64
+ env?: NodeJS.ProcessEnv;
65
+ fetchImpl?: FetchLike;
66
+ timeoutMs?: number;
67
+ now?: Date;
68
+ targetUserId?: string | null;
69
+ validateProcessPayloadImpl?: (payload: JsonObject) => ProcessPayloadValidationResult;
70
+ };
71
+ export declare function runProcessSaveDraft(options: RunProcessSaveDraftOptions): Promise<ProcessSaveDraftReport>;
72
+ export {};
@@ -0,0 +1,53 @@
1
+ import { CliError } from './errors.js';
2
+ import type { FetchLike } from './http.js';
3
+ import { type SupabaseJsonOrderedWriteResult } from './supabase-json-ordered-write.js';
4
+ type JsonObject = Record<string, unknown>;
5
+ export type VisibleProcessRow = {
6
+ id: string;
7
+ version: string;
8
+ user_id: string | null;
9
+ state_code: number | null;
10
+ };
11
+ export type ProcessSaveDraftRpcResult = {
12
+ ok: true;
13
+ [key: string]: unknown;
14
+ };
15
+ export type ProcessStateAwareWriteResult = SupabaseJsonOrderedWriteResult | {
16
+ status: 'success';
17
+ operation: 'save_draft';
18
+ write_path: 'cmd_dataset_save_draft';
19
+ rpc_result: ProcessSaveDraftRpcResult;
20
+ visible_row: VisibleProcessRow;
21
+ };
22
+ export type SyncStateAwareProcessRecordOptions = {
23
+ id: string;
24
+ version: string;
25
+ payload: JsonObject;
26
+ env: NodeJS.ProcessEnv;
27
+ fetchImpl: FetchLike;
28
+ timeoutMs?: number;
29
+ audit?: JsonObject;
30
+ modelId?: string | null;
31
+ targetUserId?: string | null;
32
+ };
33
+ declare function buildVisibleRowsUrl(restBaseUrl: string, id: string, version: string): string;
34
+ declare function parseVisibleRows(payload: unknown, url: string): VisibleProcessRow[];
35
+ declare function visibleDraftRow(rows: VisibleProcessRow[]): VisibleProcessRow | null;
36
+ declare function visibleDraftRowForTarget(rows: VisibleProcessRow[], targetUserId: string | null): VisibleProcessRow | null;
37
+ declare function buildCurrentUserUrl(restBaseUrl: string): string;
38
+ declare function assertTargetUserMatchesCurrent(options: {
39
+ targetUserId: string | null;
40
+ currentUserId: string;
41
+ }): void;
42
+ declare function buildUnsupportedVisibleRowError(id: string, version: string, rows: VisibleProcessRow[]): CliError;
43
+ export declare function syncStateAwareProcessRecord(options: SyncStateAwareProcessRecordOptions): Promise<ProcessStateAwareWriteResult>;
44
+ export declare const __testInternals: {
45
+ buildVisibleRowsUrl: typeof buildVisibleRowsUrl;
46
+ buildCurrentUserUrl: typeof buildCurrentUserUrl;
47
+ parseVisibleRows: typeof parseVisibleRows;
48
+ visibleDraftRow: typeof visibleDraftRow;
49
+ visibleDraftRowForTarget: typeof visibleDraftRowForTarget;
50
+ assertTargetUserMatchesCurrent: typeof assertTargetUserMatchesCurrent;
51
+ buildUnsupportedVisibleRowError: typeof buildUnsupportedVisibleRowError;
52
+ };
53
+ export {};
@@ -0,0 +1,210 @@
1
+ import type { FetchLike, ResponseLike } from './http.js';
2
+ type JsonRecord = Record<string, unknown>;
3
+ type ProcessScopeStatisticsScope = 'visible' | 'current-user';
4
+ type SnapshotRow = {
5
+ id: string;
6
+ version: string;
7
+ state_code: number | null;
8
+ user_id: string | null;
9
+ modified_at: string | null;
10
+ model_id: string | null;
11
+ json: JsonRecord;
12
+ };
13
+ type ClassificationEntry = {
14
+ level: number;
15
+ text: string;
16
+ };
17
+ type StatisticsMetadata = {
18
+ userId: string | null;
19
+ maskedUserEmail: string | null;
20
+ totalRowsReportedByRemote: number | null;
21
+ };
22
+ type StatisticsOptions = {
23
+ scope: ProcessScopeStatisticsScope;
24
+ stateCodes: number[];
25
+ };
26
+ export type RunProcessScopeStatisticsOptions = {
27
+ outDir: string;
28
+ scope?: ProcessScopeStatisticsScope;
29
+ stateCodes?: number[];
30
+ pageSize?: number | null;
31
+ reuseSnapshot?: boolean;
32
+ env?: NodeJS.ProcessEnv;
33
+ fetchImpl?: FetchLike;
34
+ timeoutMs?: number;
35
+ maxRetries?: number;
36
+ now?: Date;
37
+ };
38
+ export type ProcessScopeStatisticsReport = {
39
+ schema_version: 1;
40
+ generated_at_utc: string;
41
+ status: 'completed_process_scope_statistics';
42
+ out_dir: string;
43
+ scope: ProcessScopeStatisticsScope;
44
+ state_codes: number[];
45
+ total_process_rows: number;
46
+ domain_count_primary: number;
47
+ domain_count_leaf: number;
48
+ craft_count: number;
49
+ unit_process_rows: number;
50
+ product_count: number;
51
+ files: {
52
+ snapshot_manifest: string;
53
+ snapshot_rows: string;
54
+ process_scope_summary: string;
55
+ domain_summary: string;
56
+ craft_summary: string;
57
+ product_summary: string;
58
+ type_of_dataset_summary: string;
59
+ report: string;
60
+ report_zh: string;
61
+ };
62
+ };
63
+ type ProcessScopeStatisticsSummary = {
64
+ schema_version: 1;
65
+ generated_at_utc: string;
66
+ scope: ProcessScopeStatisticsScope;
67
+ state_codes: number[];
68
+ user_id: string | null;
69
+ masked_user_email: string | null;
70
+ total_process_rows: number;
71
+ total_rows_reported_by_remote: number | null;
72
+ rows_by_state_code: Record<string, number>;
73
+ distinct_visible_owner_user_ids: number;
74
+ domain_count_primary: number;
75
+ domain_count_leaf: number;
76
+ craft_count: number;
77
+ unit_process_rows: number;
78
+ unit_process_share: number;
79
+ product_count: number;
80
+ products_with_flow_id: number;
81
+ products_without_flow_id: number;
82
+ rows_missing_classification: number;
83
+ rows_missing_craft: number;
84
+ rows_missing_product: number;
85
+ rows_missing_reference_exchange: number;
86
+ metric_definitions: Record<string, string>;
87
+ };
88
+ type ProcessScopeStatisticsArtifacts = {
89
+ summary: ProcessScopeStatisticsSummary;
90
+ domainPrimarySummary: Array<{
91
+ domain: string;
92
+ count: number;
93
+ sample_path?: string;
94
+ }>;
95
+ domainLeafSummary: Array<{
96
+ domain: string;
97
+ count: number;
98
+ sample_path?: string;
99
+ }>;
100
+ craftSummary: Array<{
101
+ craft_signature: string;
102
+ label: string;
103
+ count: number;
104
+ source_kind: string;
105
+ }>;
106
+ productSummary: Array<{
107
+ product_key: string;
108
+ label: string;
109
+ count: number;
110
+ stable_flow_id: string;
111
+ stable_flow_version: string;
112
+ source_kind: string;
113
+ }>;
114
+ typeOfDataSetSummary: Array<{
115
+ type_of_dataset: string;
116
+ count: number;
117
+ }>;
118
+ craftSourceSummary: Array<{
119
+ source_kind: string;
120
+ count: number;
121
+ }>;
122
+ productSourceSummary: Array<{
123
+ source_kind: string;
124
+ count: number;
125
+ }>;
126
+ };
127
+ declare function toPositiveInteger(value: number | null | undefined, label: string, code: string): number;
128
+ declare function normalizeStateCodes(value: readonly number[] | undefined): number[];
129
+ declare function ensureScope(value: string | undefined): ProcessScopeStatisticsScope;
130
+ declare function parseJsonResponse(response: ResponseLike, label: string): Promise<unknown>;
131
+ declare function fetchJsonWithRetry(options: {
132
+ url: string;
133
+ init: RequestInit;
134
+ label: string;
135
+ fetchImpl: FetchLike;
136
+ timeoutMs: number;
137
+ maxRetries: number;
138
+ }): Promise<{
139
+ status: number;
140
+ headers: Headers;
141
+ body: unknown;
142
+ }>;
143
+ declare function resolveCurrentUserId(options: {
144
+ env: NodeJS.ProcessEnv;
145
+ fetchImpl: FetchLike;
146
+ timeoutMs: number;
147
+ now: Date;
148
+ maxRetries: number;
149
+ }): Promise<string>;
150
+ declare function fetchProcessRows(options: {
151
+ env: NodeJS.ProcessEnv;
152
+ fetchImpl: FetchLike;
153
+ timeoutMs: number;
154
+ maxRetries: number;
155
+ scope: ProcessScopeStatisticsScope;
156
+ stateCodes: number[];
157
+ pageSize: number;
158
+ userId: string | null;
159
+ }): Promise<{
160
+ rows: SnapshotRow[];
161
+ total: number | null;
162
+ }>;
163
+ declare function normalizeSnapshotRow(value: unknown): SnapshotRow | null;
164
+ declare function normalizePayload(value: unknown): JsonRecord | null;
165
+ declare function getLangList(value: unknown): JsonRecord[];
166
+ declare function getLangText(value: unknown, lang: string | null): string;
167
+ declare function getAnyLangText(value: unknown): string;
168
+ declare function extractClassificationEntries(dataSetInformation: JsonRecord): ClassificationEntry[];
169
+ declare function normalizeSignature(text: string): string;
170
+ declare function extractCraftCandidate(dataSetInformation: JsonRecord, technology: JsonRecord): {
171
+ source_kind: string;
172
+ label: string;
173
+ signature: string;
174
+ };
175
+ declare function extractReferenceProduct(processDataSet: JsonRecord, dataSetInformation: JsonRecord): {
176
+ key: string;
177
+ stable_flow_id: string;
178
+ stable_flow_version: string;
179
+ label: string;
180
+ source_kind: string;
181
+ missing_reference_exchange: boolean;
182
+ };
183
+ declare function calculateStatistics(rows: SnapshotRow[], options: StatisticsOptions, metadata: StatisticsMetadata, generatedAtUtc: string): ProcessScopeStatisticsArtifacts;
184
+ declare function escapePipe(value: unknown): string;
185
+ declare function renderMarkdownReport(statistics: ProcessScopeStatisticsArtifacts, reportLang: 'en' | 'zh'): string;
186
+ declare function readSnapshotManifest(filePath: string): JsonRecord | null;
187
+ export declare function runProcessScopeStatistics(options: RunProcessScopeStatisticsOptions): Promise<ProcessScopeStatisticsReport>;
188
+ export declare const __testInternals: {
189
+ calculateStatistics: typeof calculateStatistics;
190
+ ensureScope: typeof ensureScope;
191
+ escapePipe: typeof escapePipe;
192
+ extractClassificationEntries: typeof extractClassificationEntries;
193
+ extractCraftCandidate: typeof extractCraftCandidate;
194
+ extractReferenceProduct: typeof extractReferenceProduct;
195
+ fetchJsonWithRetry: typeof fetchJsonWithRetry;
196
+ fetchProcessRows: typeof fetchProcessRows;
197
+ getAnyLangText: typeof getAnyLangText;
198
+ getLangList: typeof getLangList;
199
+ getLangText: typeof getLangText;
200
+ normalizePayload: typeof normalizePayload;
201
+ normalizeSignature: typeof normalizeSignature;
202
+ normalizeSnapshotRow: typeof normalizeSnapshotRow;
203
+ normalizeStateCodes: typeof normalizeStateCodes;
204
+ parseJsonResponse: typeof parseJsonResponse;
205
+ readSnapshotManifest: typeof readSnapshotManifest;
206
+ resolveCurrentUserId: typeof resolveCurrentUserId;
207
+ renderMarkdownReport: typeof renderMarkdownReport;
208
+ toPositiveInteger: typeof toPositiveInteger;
209
+ };
210
+ export {};
@@ -0,0 +1,71 @@
1
+ import { type ProcessPayloadValidationResult } from './process-payload-validation.js';
2
+ type JsonObject = Record<string, unknown>;
3
+ type NameFieldKey = 'baseName' | 'treatmentStandardsRoutes' | 'mixAndLocationTypes' | 'functionalUnitFlowProperties';
4
+ export type ProcessVerifyNameFieldSummary = {
5
+ present: boolean;
6
+ en: string;
7
+ zh: string;
8
+ any: string;
9
+ };
10
+ export type ProcessVerifyRowRecord = {
11
+ row_index: number;
12
+ id: string | null;
13
+ version: string | null;
14
+ status: 'ok' | 'invalid';
15
+ validation: ProcessPayloadValidationResult;
16
+ name_summary: {
17
+ missing_required_fields: Array<'baseName' | 'treatmentStandardsRoutes' | 'mixAndLocationTypes'>;
18
+ fields: Record<NameFieldKey, ProcessVerifyNameFieldSummary>;
19
+ };
20
+ };
21
+ export type ProcessVerifyRowsReport = {
22
+ schema_version: 1;
23
+ generated_at_utc: string;
24
+ status: 'completed_process_row_verification' | 'completed_with_invalid_process_rows';
25
+ rows_file: string;
26
+ out_dir: string;
27
+ row_count: number;
28
+ invalid_count: number;
29
+ schema_invalid_count: number;
30
+ missing_required_name_field_count: number;
31
+ invalid_rows: Array<{
32
+ id: string | null;
33
+ version: string | null;
34
+ row_index: number;
35
+ missing_required_fields: Array<'baseName' | 'treatmentStandardsRoutes' | 'mixAndLocationTypes'>;
36
+ schema_issue_count: number;
37
+ }>;
38
+ files: {
39
+ summary_json: string;
40
+ verification_jsonl: string;
41
+ };
42
+ };
43
+ export type RunProcessVerifyRowsOptions = {
44
+ rowsFile: string;
45
+ outDir: string;
46
+ now?: Date;
47
+ validateProcessPayloadImpl?: (payload: JsonObject) => ProcessPayloadValidationResult;
48
+ };
49
+ declare function readRowsFile(filePath: string): unknown[];
50
+ declare function getPayload(row: unknown): JsonObject;
51
+ declare function getIdentity(row: unknown, payload: JsonObject, index: number): {
52
+ row_index: number;
53
+ id: string | null;
54
+ version: string | null;
55
+ };
56
+ declare function getLangList(value: unknown): JsonObject[];
57
+ declare function getLangText(value: unknown, lang: string | null): string;
58
+ declare function summarizeNameFields(payload: JsonObject): {
59
+ missing_required_fields: Array<'baseName' | 'treatmentStandardsRoutes' | 'mixAndLocationTypes'>;
60
+ fields: Record<NameFieldKey, ProcessVerifyNameFieldSummary>;
61
+ };
62
+ export declare function runProcessVerifyRows(options: RunProcessVerifyRowsOptions): Promise<ProcessVerifyRowsReport>;
63
+ export declare const __testInternals: {
64
+ getIdentity: typeof getIdentity;
65
+ getLangList: typeof getLangList;
66
+ getLangText: typeof getLangText;
67
+ getPayload: typeof getPayload;
68
+ readRowsFile: typeof readRowsFile;
69
+ summarizeNameFields: typeof summarizeNameFields;
70
+ };
71
+ export {};