@shivaedev/work-fleet 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +2 -2
- package/dist/admit.d.ts +54 -0
- package/dist/admit.d.ts.map +1 -1
- package/dist/engine/abandonStalled.d.ts +9807 -0
- package/dist/engine/abandonStalled.d.ts.map +1 -0
- package/dist/engine/abandonStalled.js +55 -0
- package/dist/engine/abandonStalled.js.map +1 -0
- package/dist/engine/applyResolution.d.ts +108 -0
- package/dist/engine/applyResolution.d.ts.map +1 -1
- package/dist/engine/applyResolution.js +3 -0
- package/dist/engine/applyResolution.js.map +1 -1
- package/dist/engine/approveBrief.d.ts +164 -2
- package/dist/engine/approveBrief.d.ts.map +1 -1
- package/dist/engine/approveBrief.js +7 -5
- package/dist/engine/approveBrief.js.map +1 -1
- package/dist/engine/authorizeResolution.d.ts +942 -24
- package/dist/engine/authorizeResolution.d.ts.map +1 -1
- package/dist/engine/boardBrief.d.ts +162 -0
- package/dist/engine/boardBrief.d.ts.map +1 -1
- package/dist/engine/capacityRetry.d.ts +2883 -75
- package/dist/engine/capacityRetry.d.ts.map +1 -1
- package/dist/engine/closeDecisions.d.ts +108 -0
- package/dist/engine/closeDecisions.d.ts.map +1 -1
- package/dist/engine/completeBoardWork.d.ts +108 -0
- package/dist/engine/completeBoardWork.d.ts.map +1 -1
- package/dist/engine/completeReport.d.ts +108 -0
- package/dist/engine/completeReport.d.ts.map +1 -1
- package/dist/engine/continueCommand.d.ts +54 -0
- package/dist/engine/continueCommand.d.ts.map +1 -1
- package/dist/engine/continueWorker.d.ts +108 -0
- package/dist/engine/continueWorker.d.ts.map +1 -1
- package/dist/engine/deliverPendingAnswers.d.ts +1104 -24
- package/dist/engine/deliverPendingAnswers.d.ts.map +1 -1
- package/dist/engine/dispatchCommand.d.ts +54 -0
- package/dist/engine/dispatchCommand.d.ts.map +1 -1
- package/dist/engine/ensureDecisionOwner.d.ts +108 -0
- package/dist/engine/ensureDecisionOwner.d.ts.map +1 -1
- package/dist/engine/ensurePublication.d.ts +108 -0
- package/dist/engine/ensurePublication.d.ts.map +1 -1
- package/dist/engine/inspectRenewal.d.ts +108 -0
- package/dist/engine/inspectRenewal.d.ts.map +1 -1
- package/dist/engine/launchInput.d.ts +54 -0
- package/dist/engine/launchInput.d.ts.map +1 -1
- package/dist/engine/launchReceipt.d.ts +54 -0
- package/dist/engine/launchReceipt.d.ts.map +1 -1
- package/dist/engine/makeAdopt.d.ts +108 -0
- package/dist/engine/makeAdopt.d.ts.map +1 -1
- package/dist/engine/makeAdvance.d.ts +54 -0
- package/dist/engine/makeAdvance.d.ts.map +1 -1
- package/dist/engine/makeDeliver.d.ts +108 -0
- package/dist/engine/makeDeliver.d.ts.map +1 -1
- package/dist/engine/makeHuman.d.ts +108 -0
- package/dist/engine/makeHuman.d.ts.map +1 -1
- package/dist/engine/makeLaunch.d.ts +108 -0
- package/dist/engine/makeLaunch.d.ts.map +1 -1
- package/dist/engine/makeObserve.d.ts +108 -0
- package/dist/engine/makeObserve.d.ts.map +1 -1
- package/dist/engine/makeReview.d.ts +108 -0
- package/dist/engine/makeReview.d.ts.map +1 -1
- package/dist/engine/makeState.d.ts +888 -24
- package/dist/engine/makeState.d.ts.map +1 -1
- package/dist/engine/makeValidate.d.ts +108 -0
- package/dist/engine/makeValidate.d.ts.map +1 -1
- package/dist/engine/mergeReadiness.d.ts +1212 -24
- package/dist/engine/mergeReadiness.d.ts.map +1 -1
- package/dist/engine/observeDeliveryFailure.d.ts +996 -24
- package/dist/engine/observeDeliveryFailure.d.ts.map +1 -1
- package/dist/engine/observeRenewal.d.ts +189 -0
- package/dist/engine/observeRenewal.d.ts.map +1 -1
- package/dist/engine/observedAttempt.d.ts.map +1 -1
- package/dist/engine/observedAttempt.js +3 -0
- package/dist/engine/observedAttempt.js.map +1 -1
- package/dist/engine/obtainReview.d.ts +54 -0
- package/dist/engine/obtainReview.d.ts.map +1 -1
- package/dist/engine/operationRecord.d.ts +726 -24
- package/dist/engine/operationRecord.d.ts.map +1 -1
- package/dist/engine/persistTerminalReceipts.d.ts +108 -0
- package/dist/engine/persistTerminalReceipts.d.ts.map +1 -1
- package/dist/engine/prepareCommand.d.ts +54 -0
- package/dist/engine/prepareCommand.d.ts.map +1 -1
- package/dist/engine/prepareCommand.js +19 -0
- package/dist/engine/prepareCommand.js.map +1 -1
- package/dist/engine/queueAnswerCommand.d.ts +54 -0
- package/dist/engine/queueAnswerCommand.d.ts.map +1 -1
- package/dist/engine/readOrContinueReview.d.ts +54 -0
- package/dist/engine/readOrContinueReview.d.ts.map +1 -1
- package/dist/engine/readRetry.d.ts +1995 -51
- package/dist/engine/readRetry.d.ts.map +1 -1
- package/dist/engine/reassignCommand.d.ts +54 -0
- package/dist/engine/reassignCommand.d.ts.map +1 -1
- package/dist/engine/reconcileAttempt.d.ts +81 -0
- package/dist/engine/reconcileAttempt.d.ts.map +1 -1
- package/dist/engine/reconcileCommand.d.ts +54 -0
- package/dist/engine/reconcileCommand.d.ts.map +1 -1
- package/dist/engine/recoverStall.d.ts +1023 -24
- package/dist/engine/recoverStall.d.ts.map +1 -1
- package/dist/engine/recoverStall.js +5 -1
- package/dist/engine/recoverStall.js.map +1 -1
- package/dist/engine/recoverUnobservable.d.ts +1023 -24
- package/dist/engine/recoverUnobservable.d.ts.map +1 -1
- package/dist/engine/refreshBrief.d.ts +1997 -53
- package/dist/engine/refreshBrief.d.ts.map +1 -1
- package/dist/engine/refreshReviewResult.d.ts +108 -0
- package/dist/engine/refreshReviewResult.d.ts.map +1 -1
- package/dist/engine/releaseClosedPreparation.d.ts +996 -24
- package/dist/engine/releaseClosedPreparation.d.ts.map +1 -1
- package/dist/engine/releaseExecution.d.ts +996 -24
- package/dist/engine/releaseExecution.d.ts.map +1 -1
- package/dist/engine/releaseFinishedWork.d.ts +54 -0
- package/dist/engine/releaseFinishedWork.d.ts.map +1 -1
- package/dist/engine/repository.d.ts +672 -24
- package/dist/engine/repository.d.ts.map +1 -1
- package/dist/engine/repository.js +1 -0
- package/dist/engine/repository.js.map +1 -1
- package/dist/engine/requestConflictRepair.d.ts +996 -24
- package/dist/engine/requestConflictRepair.d.ts.map +1 -1
- package/dist/engine/requestRework.d.ts +108 -0
- package/dist/engine/requestRework.d.ts.map +1 -1
- package/dist/engine/resolveCommand.d.ts +54 -0
- package/dist/engine/resolveCommand.d.ts.map +1 -1
- package/dist/engine/resolveExecution.d.ts +996 -24
- package/dist/engine/resolveExecution.d.ts.map +1 -1
- package/dist/engine/resolveExecution.js +3 -1
- package/dist/engine/resolveExecution.js.map +1 -1
- package/dist/engine/resumeAttempt.d.ts +1023 -24
- package/dist/engine/resumeAttempt.d.ts.map +1 -1
- package/dist/engine/retireUnacknowledged.d.ts +108 -0
- package/dist/engine/retireUnacknowledged.d.ts.map +1 -1
- package/dist/engine/retryTerminal.d.ts +942 -24
- package/dist/engine/retryTerminal.d.ts.map +1 -1
- package/dist/engine/scheduler.d.ts +108 -0
- package/dist/engine/scheduler.d.ts.map +1 -1
- package/dist/engine/sessionCleanup.d.ts +108 -0
- package/dist/engine/sessionCleanup.d.ts.map +1 -1
- package/dist/engine/sessionCleanup.js +3 -1
- package/dist/engine/sessionCleanup.js.map +1 -1
- package/dist/engine/sessionStatus.d.ts.map +1 -1
- package/dist/engine/sessionStatus.js +3 -0
- package/dist/engine/sessionStatus.js.map +1 -1
- package/dist/engine/settleMergedDelivery.d.ts +996 -24
- package/dist/engine/settleMergedDelivery.d.ts.map +1 -1
- package/dist/engine/steerBrief.d.ts +10340 -0
- package/dist/engine/steerBrief.d.ts.map +1 -0
- package/dist/engine/steerBrief.js +42 -0
- package/dist/engine/steerBrief.js.map +1 -0
- package/dist/engine/submissionFailure.d.ts +888 -24
- package/dist/engine/submissionFailure.d.ts.map +1 -1
- package/dist/engine/submitLaunch.d.ts +942 -24
- package/dist/engine/submitLaunch.d.ts.map +1 -1
- package/dist/engine/views.js +1 -0
- package/dist/engine/views.js.map +1 -1
- package/dist/engine/workerReport.d.ts +162 -0
- package/dist/engine/workerReport.d.ts.map +1 -1
- package/dist/fleet.d.ts +540 -0
- package/dist/fleet.d.ts.map +1 -1
- package/dist/host/admission.d.ts +108 -0
- package/dist/host/admission.d.ts.map +1 -1
- package/dist/host/admission.js +2 -1
- package/dist/host/admission.js.map +1 -1
- package/dist/host/answerWork.d.ts +54 -0
- package/dist/host/answerWork.d.ts.map +1 -1
- package/dist/host/commands.d.ts +108 -0
- package/dist/host/commands.d.ts.map +1 -1
- package/dist/host/daemon.d.ts +1465 -865
- package/dist/host/daemon.d.ts.map +1 -1
- package/dist/host/daemonClient.d.ts +691 -91
- package/dist/host/daemonClient.d.ts.map +1 -1
- package/dist/host/daemonContract.d.ts +984 -0
- package/dist/host/daemonContract.d.ts.map +1 -1
- package/dist/host/readWaitStates.d.ts.map +1 -1
- package/dist/host/readWaitStates.js +13 -4
- package/dist/host/readWaitStates.js.map +1 -1
- package/dist/host/reassignWork.d.ts +54 -0
- package/dist/host/reassignWork.d.ts.map +1 -1
- package/dist/host/recordPayloads.d.ts.map +1 -1
- package/dist/host/recordPayloads.js +8 -3
- package/dist/host/recordPayloads.js.map +1 -1
- package/dist/host/releaseWork.d.ts +108 -0
- package/dist/host/releaseWork.d.ts.map +1 -1
- package/dist/host/status.d.ts +30 -0
- package/dist/host/status.d.ts.map +1 -1
- package/dist/model.d.ts +144 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +14 -1
- package/dist/model.js.map +1 -1
- package/dist/operations.d.ts +1224 -0
- package/dist/operations.d.ts.map +1 -1
- package/dist/packageInfo.d.ts +1 -1
- package/dist/packageInfo.js +1 -1
- package/dist/prompt/briefEdit.d.ts +2 -0
- package/dist/prompt/briefEdit.d.ts.map +1 -0
- package/dist/prompt/briefEdit.js +41 -0
- package/dist/prompt/briefEdit.js.map +1 -0
- package/dist/prompt/worker.d.ts.map +1 -1
- package/dist/prompt/worker.js +11 -2
- package/dist/prompt/worker.js.map +1 -1
- package/dist/qualifyDependencies.d.ts +54 -0
- package/dist/qualifyDependencies.d.ts.map +1 -1
- package/dist/scheduling/areas.d.ts +162 -0
- package/dist/scheduling/areas.d.ts.map +1 -1
- package/dist/storage/attemptV12.d.ts +108 -0
- package/dist/storage/attemptV12.d.ts.map +1 -0
- package/dist/storage/attemptV12.js +94 -0
- package/dist/storage/attemptV12.js.map +1 -0
- package/dist/storage/createCollections.d.ts +5 -0
- package/dist/storage/createCollections.d.ts.map +1 -0
- package/dist/storage/createCollections.js +21 -0
- package/dist/storage/createCollections.js.map +1 -0
- package/dist/storage/cycleV12.d.ts +287 -0
- package/dist/storage/cycleV12.d.ts.map +1 -0
- package/dist/storage/cycleV12.js +124 -0
- package/dist/storage/cycleV12.js.map +1 -0
- package/dist/storage/fleetMigrations.d.ts +0 -39
- package/dist/storage/fleetMigrations.d.ts.map +1 -1
- package/dist/storage/fleetMigrations.js +3 -9
- package/dist/storage/fleetMigrations.js.map +1 -1
- package/dist/storage/legacyColumns.d.ts +40 -0
- package/dist/storage/legacyColumns.d.ts.map +1 -0
- package/dist/storage/legacyColumns.js +12 -0
- package/dist/storage/legacyColumns.js.map +1 -0
- package/dist/storage/makeForeignReservations.d.ts +15 -0
- package/dist/storage/makeForeignReservations.d.ts.map +1 -0
- package/dist/storage/makeForeignReservations.js +34 -0
- package/dist/storage/makeForeignReservations.js.map +1 -0
- package/dist/storage/makePostgresFleetStore.d.ts +36 -16
- package/dist/storage/makePostgresFleetStore.d.ts.map +1 -1
- package/dist/storage/makePostgresFleetStore.js +24 -32
- package/dist/storage/makePostgresFleetStore.js.map +1 -1
- package/dist/storage/model.d.ts +53 -59
- package/dist/storage/model.d.ts.map +1 -1
- package/dist/storage/model.js +18 -60
- package/dist/storage/model.js.map +1 -1
- package/dist/storage/operationEntries.d.ts +6 -5
- package/dist/storage/operationEntries.d.ts.map +1 -1
- package/dist/storage/operationEntries.js +12 -15
- package/dist/storage/operationEntries.js.map +1 -1
- package/dist/storage/preparationV12.d.ts +44 -0
- package/dist/storage/preparationV12.d.ts.map +1 -0
- package/dist/storage/preparationV12.js +30 -0
- package/dist/storage/preparationV12.js.map +1 -0
- package/dist/storage/readRecords.d.ts +4 -0
- package/dist/storage/readRecords.d.ts.map +1 -0
- package/dist/storage/readRecords.js +10 -0
- package/dist/storage/readRecords.js.map +1 -0
- package/dist/storage/recordChildren.d.ts +11 -0
- package/dist/storage/recordChildren.d.ts.map +1 -0
- package/dist/storage/recordChildren.js +105 -0
- package/dist/storage/recordChildren.js.map +1 -0
- package/dist/storage/recordShape.d.ts +23 -0
- package/dist/storage/recordShape.d.ts.map +1 -0
- package/dist/storage/recordShape.js +112 -0
- package/dist/storage/recordShape.js.map +1 -0
- package/dist/storage/recordValue.d.ts +9 -6
- package/dist/storage/recordValue.d.ts.map +1 -1
- package/dist/storage/recordValue.js +42 -32
- package/dist/storage/recordValue.js.map +1 -1
- package/dist/storage/shapeV12.d.ts +794 -0
- package/dist/storage/shapeV12.d.ts.map +1 -0
- package/dist/storage/shapeV12.js +10 -0
- package/dist/storage/shapeV12.js.map +1 -0
- package/dist/storage/textRecordValue.d.ts +3 -0
- package/dist/storage/textRecordValue.d.ts.map +1 -0
- package/dist/storage/textRecordValue.js +13 -0
- package/dist/storage/textRecordValue.js.map +1 -0
- package/dist/storage/typedDecisionsV12.d.ts +103 -0
- package/dist/storage/typedDecisionsV12.d.ts.map +1 -0
- package/dist/storage/typedDecisionsV12.js +97 -0
- package/dist/storage/typedDecisionsV12.js.map +1 -0
- package/dist/storage/typedTables.d.ts +4 -0
- package/dist/storage/typedTables.d.ts.map +1 -0
- package/dist/storage/typedTables.js +39 -0
- package/dist/storage/typedTables.js.map +1 -0
- package/package.json +8 -8
- package/src/engine/abandonStalled.ts +63 -0
- package/src/engine/applyResolution.ts +3 -0
- package/src/engine/approveBrief.ts +34 -32
- package/src/engine/observedAttempt.ts +3 -0
- package/src/engine/prepareCommand.ts +21 -0
- package/src/engine/recoverStall.ts +6 -2
- package/src/engine/repository.ts +1 -0
- package/src/engine/resolveExecution.ts +3 -1
- package/src/engine/sessionCleanup.ts +3 -1
- package/src/engine/sessionStatus.ts +5 -0
- package/src/engine/steerBrief.ts +54 -0
- package/src/engine/views.ts +1 -0
- package/src/host/admission.ts +2 -1
- package/src/host/readWaitStates.ts +12 -11
- package/src/host/recordPayloads.ts +11 -3
- package/src/model.ts +20 -1
- package/src/packageInfo.ts +1 -1
- package/src/prompt/briefEdit.ts +44 -0
- package/src/prompt/worker.ts +11 -2
- package/src/storage/attemptV12.ts +95 -0
- package/src/storage/createCollections.ts +21 -0
- package/src/storage/cycleV12.ts +125 -0
- package/src/storage/fleetMigrations.ts +3 -10
- package/src/storage/legacyColumns.ts +12 -0
- package/src/storage/makeForeignReservations.ts +41 -0
- package/src/storage/makePostgresFleetStore.ts +30 -43
- package/src/storage/model.ts +19 -69
- package/src/storage/operationEntries.ts +12 -22
- package/src/storage/preparationV12.ts +31 -0
- package/src/storage/readRecords.ts +12 -0
- package/src/storage/recordChildren.ts +131 -0
- package/src/storage/recordShape.ts +137 -0
- package/src/storage/recordValue.ts +47 -34
- package/src/storage/shapeV12.ts +11 -0
- package/src/storage/textRecordValue.ts +16 -0
- package/src/storage/typedDecisionsV12.ts +100 -0
- package/src/storage/typedTables.ts +39 -0
|
@@ -1,42 +1,55 @@
|
|
|
1
|
-
import { Effect
|
|
2
|
-
import
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { childTable, objectValue } from "#storage/recordChildren.ts";
|
|
4
|
+
import { collections, type Shape } from "#storage/recordShape.ts";
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type Row = Readonly<Record<string, unknown>>;
|
|
5
7
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export const recordValues = Effect.fn("FleetRow.recordValues")(function* (rows: readonly object[], shape: Shape, namespace: string) {
|
|
9
|
+
const sql = yield* SqlClient.SqlClient;
|
|
10
|
+
const roots = rows.map(objectValue);
|
|
11
|
+
const children = new Map<string, readonly Row[]>();
|
|
12
|
+
if (roots.length === 0) {
|
|
13
|
+
return [];
|
|
11
14
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
for (const collection of collections(shape)) {
|
|
16
|
+
const parent = collection.parents.at(-1);
|
|
17
|
+
const sources = parent === undefined ? roots : (children.get(parent) ?? []);
|
|
18
|
+
const offset = parent === undefined ? 0 : parent.split(".").length;
|
|
19
|
+
const marker = collection.path.slice(offset).join("__");
|
|
20
|
+
const workIds = [...new Set(sources.filter((row) => row[marker] !== null && row[marker] !== undefined).map((row) => row.work_id))];
|
|
21
|
+
if (workIds.length === 0) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const found =
|
|
25
|
+
yield* sql<Row>`select * from ${sql(childTable(namespace, collection.path))} where ${sql.in("work_id", workIds)} order by ${sql.csv(Array.from({ length: collection.parents.length + 1 }, (_unused, index) => sql`${sql(`position${index}`)}`))}`;
|
|
26
|
+
children.set(collection.path.join("."), found);
|
|
27
|
+
}
|
|
28
|
+
function read(node: Shape, row: Row, path: readonly string[], prefix: readonly string[], indices: readonly number[]): unknown {
|
|
29
|
+
const name = prefix.join("__");
|
|
30
|
+
if (typeof node === "string") {
|
|
31
|
+
return row[name] ?? undefined;
|
|
32
|
+
}
|
|
33
|
+
if (prefix.length > 0 && (row[name] === null || row[name] === undefined)) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
if ("fields" in node) {
|
|
37
|
+
return Object.fromEntries(
|
|
38
|
+
Object.entries(node.fields)
|
|
39
|
+
.map(([key, field]) => [key, read(field, row, [...path, key], [...prefix, key], indices)])
|
|
40
|
+
.filter(([_key, value]) => value !== undefined),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (typeof node.array === "string") {
|
|
44
|
+
return row[name];
|
|
34
45
|
}
|
|
35
|
-
|
|
46
|
+
return (children.get(path.join(".")) ?? [])
|
|
47
|
+
.filter((child) => child.work_id === row.work_id && indices.every((position, index) => child[`position${index}`] === position))
|
|
48
|
+
.map((child) => read(node.array, child, path, [], [...indices, Number(child[`position${indices.length}`])]));
|
|
36
49
|
}
|
|
37
|
-
return
|
|
50
|
+
return roots.map((row) => ({ ...objectValue(read(shape, row, [], [], [])), workId: row.work_id }));
|
|
38
51
|
});
|
|
39
52
|
|
|
40
|
-
export function recordValue(row: object,
|
|
41
|
-
return recordValues([row],
|
|
53
|
+
export function recordValue(row: object, shape: Shape, namespace: string) {
|
|
54
|
+
return recordValues([row], shape, namespace).pipe(Effect.map(([value]) => value));
|
|
42
55
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { attemptV12 } from "#storage/attemptV12.ts";
|
|
2
|
+
import { cycleV12 } from "#storage/cycleV12.ts";
|
|
3
|
+
import type { Shape } from "#storage/recordShape.ts";
|
|
4
|
+
|
|
5
|
+
const cycle = { ...cycleV12.fields, attempts: { array: attemptV12 } };
|
|
6
|
+
export const shapeV12 = {
|
|
7
|
+
fields: {
|
|
8
|
+
...cycle,
|
|
9
|
+
history: { array: { fields: { ...cycle, archivedAt: "number" } } },
|
|
10
|
+
},
|
|
11
|
+
} as const satisfies Shape;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { legacyColumns } from "#storage/legacyColumns.ts";
|
|
3
|
+
|
|
4
|
+
export const textRecordValue = Effect.fn("FleetStore.textRecordValue")(function* (
|
|
5
|
+
row: Readonly<Record<string, unknown>>,
|
|
6
|
+
structured: readonly string[],
|
|
7
|
+
) {
|
|
8
|
+
const value: Record<string, unknown> = {};
|
|
9
|
+
for (const name of Object.keys(legacyColumns)) {
|
|
10
|
+
const field = row[structured.includes(name) ? `legacy_${name}` : name];
|
|
11
|
+
if (field !== null) {
|
|
12
|
+
value[name] = structured.includes(name) ? yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(field) : field;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { Shape } from "#storage/recordShape.ts";
|
|
2
|
+
|
|
3
|
+
export const decisionV12 = {
|
|
4
|
+
fields: {
|
|
5
|
+
attentionOwner: "string",
|
|
6
|
+
boardAcknowledgementDisposition: "string",
|
|
7
|
+
code: "string",
|
|
8
|
+
id: "string",
|
|
9
|
+
links: { array: "string" },
|
|
10
|
+
publicationWork: {
|
|
11
|
+
fields: {
|
|
12
|
+
approved: "boolean",
|
|
13
|
+
areas: { array: "string" },
|
|
14
|
+
context: "string",
|
|
15
|
+
deliverable: "string",
|
|
16
|
+
dependsOn: { array: "string" },
|
|
17
|
+
revision: "string",
|
|
18
|
+
sourcePath: "string",
|
|
19
|
+
status: "string",
|
|
20
|
+
workId: "string",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
published: {
|
|
24
|
+
fields: {
|
|
25
|
+
itemId: "string",
|
|
26
|
+
questionId: "string",
|
|
27
|
+
request: "string",
|
|
28
|
+
revision: "string",
|
|
29
|
+
sourcePath: "string",
|
|
30
|
+
workId: "string",
|
|
31
|
+
workRevision: "string",
|
|
32
|
+
workSourcePath: "string",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
reason: "string",
|
|
36
|
+
recommendation: "string",
|
|
37
|
+
worker: {
|
|
38
|
+
fields: {
|
|
39
|
+
sessionId: "string",
|
|
40
|
+
turnId: "string",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
} as const satisfies Shape;
|
|
45
|
+
|
|
46
|
+
export const responsesV12 = {
|
|
47
|
+
array: {
|
|
48
|
+
fields: {
|
|
49
|
+
action: "string",
|
|
50
|
+
boardAcknowledged: "boolean",
|
|
51
|
+
boardAcknowledgementDisposition: "string",
|
|
52
|
+
decisionId: "string",
|
|
53
|
+
processedAt: "number",
|
|
54
|
+
published: {
|
|
55
|
+
fields: {
|
|
56
|
+
itemId: "string",
|
|
57
|
+
questionId: "string",
|
|
58
|
+
request: "string",
|
|
59
|
+
revision: "string",
|
|
60
|
+
sourcePath: "string",
|
|
61
|
+
workId: "string",
|
|
62
|
+
workRevision: "string",
|
|
63
|
+
workSourcePath: "string",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
questionId: "string",
|
|
67
|
+
questionRevision: "string",
|
|
68
|
+
responseId: "string",
|
|
69
|
+
type: "string",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
} as const satisfies Shape;
|
|
73
|
+
|
|
74
|
+
export const supersededDecisionsV12 = {
|
|
75
|
+
array: {
|
|
76
|
+
fields: {
|
|
77
|
+
boardAcknowledged: "boolean",
|
|
78
|
+
boardAcknowledgementDisposition: "string",
|
|
79
|
+
published: {
|
|
80
|
+
fields: {
|
|
81
|
+
itemId: "string",
|
|
82
|
+
questionId: "string",
|
|
83
|
+
request: "string",
|
|
84
|
+
revision: "string",
|
|
85
|
+
sourcePath: "string",
|
|
86
|
+
workId: "string",
|
|
87
|
+
workRevision: "string",
|
|
88
|
+
workSourcePath: "string",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
reassignedTo: {
|
|
92
|
+
fields: {
|
|
93
|
+
attentionOwner: "string",
|
|
94
|
+
decisionId: "string",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
supersededAt: "number",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
} as const satisfies Shape;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { createCollections } from "#storage/createCollections.ts";
|
|
4
|
+
import { legacyColumns } from "#storage/legacyColumns.ts";
|
|
5
|
+
import { modelFromColumns } from "#storage/model.ts";
|
|
6
|
+
import { inputColumns, makeRecordChildren } from "#storage/recordChildren.ts";
|
|
7
|
+
import { shapeColumns, sqlTypes } from "#storage/recordShape.ts";
|
|
8
|
+
import { shapeV12 } from "#storage/shapeV12.ts";
|
|
9
|
+
import { textRecordValue } from "#storage/textRecordValue.ts";
|
|
10
|
+
|
|
11
|
+
export const typedTables = Effect.fn("FleetStore.typedTables")(function* (namespace: string) {
|
|
12
|
+
const sql = yield* SqlClient.SqlClient;
|
|
13
|
+
const table = `${namespace}_records`;
|
|
14
|
+
const structured = Object.entries(legacyColumns)
|
|
15
|
+
.filter(([_name, kind]) => kind === "json")
|
|
16
|
+
.map(([name]) => name);
|
|
17
|
+
for (const name of structured) {
|
|
18
|
+
yield* sql`alter table ${sql(table)} rename column ${sql(name)} to ${sql(`legacy_${name}`)}`;
|
|
19
|
+
}
|
|
20
|
+
const columns = shapeColumns(shapeV12);
|
|
21
|
+
for (const [name, kind] of Object.entries(columns)) {
|
|
22
|
+
if (!(name in legacyColumns) || structured.includes(name)) {
|
|
23
|
+
yield* sql`alter table ${sql(table)} add column ${sql(name)} ${sql.literal(sqlTypes[kind])}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
yield* createCollections(namespace, shapeV12);
|
|
27
|
+
const rows = yield* sql`select * from ${sql(table)} order by admission_order`;
|
|
28
|
+
const model = modelFromColumns(columns);
|
|
29
|
+
const saveChildren = yield* makeRecordChildren(namespace, shapeV12);
|
|
30
|
+
for (const row of rows) {
|
|
31
|
+
const value = yield* textRecordValue(row, structured);
|
|
32
|
+
const input = yield* Schema.decodeUnknownEffect(model.insert)({ ...inputColumns(value, shapeV12), "work_id": row.work_id });
|
|
33
|
+
yield* sql`update ${sql(table)} set ${sql.update(yield* Schema.encodeEffect(model.insert)(input))} where work_id = ${row.work_id}`;
|
|
34
|
+
yield* saveChildren(String(row.work_id), value, false);
|
|
35
|
+
}
|
|
36
|
+
for (const name of structured) {
|
|
37
|
+
yield* sql`alter table ${sql(table)} drop column ${sql(`legacy_${name}`)}`;
|
|
38
|
+
}
|
|
39
|
+
});
|