@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.
Files changed (311) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +2 -2
  3. package/dist/admit.d.ts +54 -0
  4. package/dist/admit.d.ts.map +1 -1
  5. package/dist/engine/abandonStalled.d.ts +9807 -0
  6. package/dist/engine/abandonStalled.d.ts.map +1 -0
  7. package/dist/engine/abandonStalled.js +55 -0
  8. package/dist/engine/abandonStalled.js.map +1 -0
  9. package/dist/engine/applyResolution.d.ts +108 -0
  10. package/dist/engine/applyResolution.d.ts.map +1 -1
  11. package/dist/engine/applyResolution.js +3 -0
  12. package/dist/engine/applyResolution.js.map +1 -1
  13. package/dist/engine/approveBrief.d.ts +164 -2
  14. package/dist/engine/approveBrief.d.ts.map +1 -1
  15. package/dist/engine/approveBrief.js +7 -5
  16. package/dist/engine/approveBrief.js.map +1 -1
  17. package/dist/engine/authorizeResolution.d.ts +942 -24
  18. package/dist/engine/authorizeResolution.d.ts.map +1 -1
  19. package/dist/engine/boardBrief.d.ts +162 -0
  20. package/dist/engine/boardBrief.d.ts.map +1 -1
  21. package/dist/engine/capacityRetry.d.ts +2883 -75
  22. package/dist/engine/capacityRetry.d.ts.map +1 -1
  23. package/dist/engine/closeDecisions.d.ts +108 -0
  24. package/dist/engine/closeDecisions.d.ts.map +1 -1
  25. package/dist/engine/completeBoardWork.d.ts +108 -0
  26. package/dist/engine/completeBoardWork.d.ts.map +1 -1
  27. package/dist/engine/completeReport.d.ts +108 -0
  28. package/dist/engine/completeReport.d.ts.map +1 -1
  29. package/dist/engine/continueCommand.d.ts +54 -0
  30. package/dist/engine/continueCommand.d.ts.map +1 -1
  31. package/dist/engine/continueWorker.d.ts +108 -0
  32. package/dist/engine/continueWorker.d.ts.map +1 -1
  33. package/dist/engine/deliverPendingAnswers.d.ts +1104 -24
  34. package/dist/engine/deliverPendingAnswers.d.ts.map +1 -1
  35. package/dist/engine/dispatchCommand.d.ts +54 -0
  36. package/dist/engine/dispatchCommand.d.ts.map +1 -1
  37. package/dist/engine/ensureDecisionOwner.d.ts +108 -0
  38. package/dist/engine/ensureDecisionOwner.d.ts.map +1 -1
  39. package/dist/engine/ensurePublication.d.ts +108 -0
  40. package/dist/engine/ensurePublication.d.ts.map +1 -1
  41. package/dist/engine/inspectRenewal.d.ts +108 -0
  42. package/dist/engine/inspectRenewal.d.ts.map +1 -1
  43. package/dist/engine/launchInput.d.ts +54 -0
  44. package/dist/engine/launchInput.d.ts.map +1 -1
  45. package/dist/engine/launchReceipt.d.ts +54 -0
  46. package/dist/engine/launchReceipt.d.ts.map +1 -1
  47. package/dist/engine/makeAdopt.d.ts +108 -0
  48. package/dist/engine/makeAdopt.d.ts.map +1 -1
  49. package/dist/engine/makeAdvance.d.ts +54 -0
  50. package/dist/engine/makeAdvance.d.ts.map +1 -1
  51. package/dist/engine/makeDeliver.d.ts +108 -0
  52. package/dist/engine/makeDeliver.d.ts.map +1 -1
  53. package/dist/engine/makeHuman.d.ts +108 -0
  54. package/dist/engine/makeHuman.d.ts.map +1 -1
  55. package/dist/engine/makeLaunch.d.ts +108 -0
  56. package/dist/engine/makeLaunch.d.ts.map +1 -1
  57. package/dist/engine/makeObserve.d.ts +108 -0
  58. package/dist/engine/makeObserve.d.ts.map +1 -1
  59. package/dist/engine/makeReview.d.ts +108 -0
  60. package/dist/engine/makeReview.d.ts.map +1 -1
  61. package/dist/engine/makeState.d.ts +888 -24
  62. package/dist/engine/makeState.d.ts.map +1 -1
  63. package/dist/engine/makeValidate.d.ts +108 -0
  64. package/dist/engine/makeValidate.d.ts.map +1 -1
  65. package/dist/engine/mergeReadiness.d.ts +1212 -24
  66. package/dist/engine/mergeReadiness.d.ts.map +1 -1
  67. package/dist/engine/observeDeliveryFailure.d.ts +996 -24
  68. package/dist/engine/observeDeliveryFailure.d.ts.map +1 -1
  69. package/dist/engine/observeRenewal.d.ts +189 -0
  70. package/dist/engine/observeRenewal.d.ts.map +1 -1
  71. package/dist/engine/observedAttempt.d.ts.map +1 -1
  72. package/dist/engine/observedAttempt.js +3 -0
  73. package/dist/engine/observedAttempt.js.map +1 -1
  74. package/dist/engine/obtainReview.d.ts +54 -0
  75. package/dist/engine/obtainReview.d.ts.map +1 -1
  76. package/dist/engine/operationRecord.d.ts +726 -24
  77. package/dist/engine/operationRecord.d.ts.map +1 -1
  78. package/dist/engine/persistTerminalReceipts.d.ts +108 -0
  79. package/dist/engine/persistTerminalReceipts.d.ts.map +1 -1
  80. package/dist/engine/prepareCommand.d.ts +54 -0
  81. package/dist/engine/prepareCommand.d.ts.map +1 -1
  82. package/dist/engine/prepareCommand.js +19 -0
  83. package/dist/engine/prepareCommand.js.map +1 -1
  84. package/dist/engine/queueAnswerCommand.d.ts +54 -0
  85. package/dist/engine/queueAnswerCommand.d.ts.map +1 -1
  86. package/dist/engine/readOrContinueReview.d.ts +54 -0
  87. package/dist/engine/readOrContinueReview.d.ts.map +1 -1
  88. package/dist/engine/readRetry.d.ts +1995 -51
  89. package/dist/engine/readRetry.d.ts.map +1 -1
  90. package/dist/engine/reassignCommand.d.ts +54 -0
  91. package/dist/engine/reassignCommand.d.ts.map +1 -1
  92. package/dist/engine/reconcileAttempt.d.ts +81 -0
  93. package/dist/engine/reconcileAttempt.d.ts.map +1 -1
  94. package/dist/engine/reconcileCommand.d.ts +54 -0
  95. package/dist/engine/reconcileCommand.d.ts.map +1 -1
  96. package/dist/engine/recoverStall.d.ts +1023 -24
  97. package/dist/engine/recoverStall.d.ts.map +1 -1
  98. package/dist/engine/recoverStall.js +5 -1
  99. package/dist/engine/recoverStall.js.map +1 -1
  100. package/dist/engine/recoverUnobservable.d.ts +1023 -24
  101. package/dist/engine/recoverUnobservable.d.ts.map +1 -1
  102. package/dist/engine/refreshBrief.d.ts +1997 -53
  103. package/dist/engine/refreshBrief.d.ts.map +1 -1
  104. package/dist/engine/refreshReviewResult.d.ts +108 -0
  105. package/dist/engine/refreshReviewResult.d.ts.map +1 -1
  106. package/dist/engine/releaseClosedPreparation.d.ts +996 -24
  107. package/dist/engine/releaseClosedPreparation.d.ts.map +1 -1
  108. package/dist/engine/releaseExecution.d.ts +996 -24
  109. package/dist/engine/releaseExecution.d.ts.map +1 -1
  110. package/dist/engine/releaseFinishedWork.d.ts +54 -0
  111. package/dist/engine/releaseFinishedWork.d.ts.map +1 -1
  112. package/dist/engine/repository.d.ts +672 -24
  113. package/dist/engine/repository.d.ts.map +1 -1
  114. package/dist/engine/repository.js +1 -0
  115. package/dist/engine/repository.js.map +1 -1
  116. package/dist/engine/requestConflictRepair.d.ts +996 -24
  117. package/dist/engine/requestConflictRepair.d.ts.map +1 -1
  118. package/dist/engine/requestRework.d.ts +108 -0
  119. package/dist/engine/requestRework.d.ts.map +1 -1
  120. package/dist/engine/resolveCommand.d.ts +54 -0
  121. package/dist/engine/resolveCommand.d.ts.map +1 -1
  122. package/dist/engine/resolveExecution.d.ts +996 -24
  123. package/dist/engine/resolveExecution.d.ts.map +1 -1
  124. package/dist/engine/resolveExecution.js +3 -1
  125. package/dist/engine/resolveExecution.js.map +1 -1
  126. package/dist/engine/resumeAttempt.d.ts +1023 -24
  127. package/dist/engine/resumeAttempt.d.ts.map +1 -1
  128. package/dist/engine/retireUnacknowledged.d.ts +108 -0
  129. package/dist/engine/retireUnacknowledged.d.ts.map +1 -1
  130. package/dist/engine/retryTerminal.d.ts +942 -24
  131. package/dist/engine/retryTerminal.d.ts.map +1 -1
  132. package/dist/engine/scheduler.d.ts +108 -0
  133. package/dist/engine/scheduler.d.ts.map +1 -1
  134. package/dist/engine/sessionCleanup.d.ts +108 -0
  135. package/dist/engine/sessionCleanup.d.ts.map +1 -1
  136. package/dist/engine/sessionCleanup.js +3 -1
  137. package/dist/engine/sessionCleanup.js.map +1 -1
  138. package/dist/engine/sessionStatus.d.ts.map +1 -1
  139. package/dist/engine/sessionStatus.js +3 -0
  140. package/dist/engine/sessionStatus.js.map +1 -1
  141. package/dist/engine/settleMergedDelivery.d.ts +996 -24
  142. package/dist/engine/settleMergedDelivery.d.ts.map +1 -1
  143. package/dist/engine/steerBrief.d.ts +10340 -0
  144. package/dist/engine/steerBrief.d.ts.map +1 -0
  145. package/dist/engine/steerBrief.js +42 -0
  146. package/dist/engine/steerBrief.js.map +1 -0
  147. package/dist/engine/submissionFailure.d.ts +888 -24
  148. package/dist/engine/submissionFailure.d.ts.map +1 -1
  149. package/dist/engine/submitLaunch.d.ts +942 -24
  150. package/dist/engine/submitLaunch.d.ts.map +1 -1
  151. package/dist/engine/views.js +1 -0
  152. package/dist/engine/views.js.map +1 -1
  153. package/dist/engine/workerReport.d.ts +162 -0
  154. package/dist/engine/workerReport.d.ts.map +1 -1
  155. package/dist/fleet.d.ts +540 -0
  156. package/dist/fleet.d.ts.map +1 -1
  157. package/dist/host/admission.d.ts +108 -0
  158. package/dist/host/admission.d.ts.map +1 -1
  159. package/dist/host/admission.js +2 -1
  160. package/dist/host/admission.js.map +1 -1
  161. package/dist/host/answerWork.d.ts +54 -0
  162. package/dist/host/answerWork.d.ts.map +1 -1
  163. package/dist/host/commands.d.ts +108 -0
  164. package/dist/host/commands.d.ts.map +1 -1
  165. package/dist/host/daemon.d.ts +1465 -865
  166. package/dist/host/daemon.d.ts.map +1 -1
  167. package/dist/host/daemonClient.d.ts +691 -91
  168. package/dist/host/daemonClient.d.ts.map +1 -1
  169. package/dist/host/daemonContract.d.ts +984 -0
  170. package/dist/host/daemonContract.d.ts.map +1 -1
  171. package/dist/host/readWaitStates.d.ts.map +1 -1
  172. package/dist/host/readWaitStates.js +13 -4
  173. package/dist/host/readWaitStates.js.map +1 -1
  174. package/dist/host/reassignWork.d.ts +54 -0
  175. package/dist/host/reassignWork.d.ts.map +1 -1
  176. package/dist/host/recordPayloads.d.ts.map +1 -1
  177. package/dist/host/recordPayloads.js +8 -3
  178. package/dist/host/recordPayloads.js.map +1 -1
  179. package/dist/host/releaseWork.d.ts +108 -0
  180. package/dist/host/releaseWork.d.ts.map +1 -1
  181. package/dist/host/status.d.ts +30 -0
  182. package/dist/host/status.d.ts.map +1 -1
  183. package/dist/model.d.ts +144 -0
  184. package/dist/model.d.ts.map +1 -1
  185. package/dist/model.js +14 -1
  186. package/dist/model.js.map +1 -1
  187. package/dist/operations.d.ts +1224 -0
  188. package/dist/operations.d.ts.map +1 -1
  189. package/dist/packageInfo.d.ts +1 -1
  190. package/dist/packageInfo.js +1 -1
  191. package/dist/prompt/briefEdit.d.ts +2 -0
  192. package/dist/prompt/briefEdit.d.ts.map +1 -0
  193. package/dist/prompt/briefEdit.js +41 -0
  194. package/dist/prompt/briefEdit.js.map +1 -0
  195. package/dist/prompt/worker.d.ts.map +1 -1
  196. package/dist/prompt/worker.js +11 -2
  197. package/dist/prompt/worker.js.map +1 -1
  198. package/dist/qualifyDependencies.d.ts +54 -0
  199. package/dist/qualifyDependencies.d.ts.map +1 -1
  200. package/dist/scheduling/areas.d.ts +162 -0
  201. package/dist/scheduling/areas.d.ts.map +1 -1
  202. package/dist/storage/attemptV12.d.ts +108 -0
  203. package/dist/storage/attemptV12.d.ts.map +1 -0
  204. package/dist/storage/attemptV12.js +94 -0
  205. package/dist/storage/attemptV12.js.map +1 -0
  206. package/dist/storage/createCollections.d.ts +5 -0
  207. package/dist/storage/createCollections.d.ts.map +1 -0
  208. package/dist/storage/createCollections.js +21 -0
  209. package/dist/storage/createCollections.js.map +1 -0
  210. package/dist/storage/cycleV12.d.ts +287 -0
  211. package/dist/storage/cycleV12.d.ts.map +1 -0
  212. package/dist/storage/cycleV12.js +124 -0
  213. package/dist/storage/cycleV12.js.map +1 -0
  214. package/dist/storage/fleetMigrations.d.ts +0 -39
  215. package/dist/storage/fleetMigrations.d.ts.map +1 -1
  216. package/dist/storage/fleetMigrations.js +3 -9
  217. package/dist/storage/fleetMigrations.js.map +1 -1
  218. package/dist/storage/legacyColumns.d.ts +40 -0
  219. package/dist/storage/legacyColumns.d.ts.map +1 -0
  220. package/dist/storage/legacyColumns.js +12 -0
  221. package/dist/storage/legacyColumns.js.map +1 -0
  222. package/dist/storage/makeForeignReservations.d.ts +15 -0
  223. package/dist/storage/makeForeignReservations.d.ts.map +1 -0
  224. package/dist/storage/makeForeignReservations.js +34 -0
  225. package/dist/storage/makeForeignReservations.js.map +1 -0
  226. package/dist/storage/makePostgresFleetStore.d.ts +36 -16
  227. package/dist/storage/makePostgresFleetStore.d.ts.map +1 -1
  228. package/dist/storage/makePostgresFleetStore.js +24 -32
  229. package/dist/storage/makePostgresFleetStore.js.map +1 -1
  230. package/dist/storage/model.d.ts +53 -59
  231. package/dist/storage/model.d.ts.map +1 -1
  232. package/dist/storage/model.js +18 -60
  233. package/dist/storage/model.js.map +1 -1
  234. package/dist/storage/operationEntries.d.ts +6 -5
  235. package/dist/storage/operationEntries.d.ts.map +1 -1
  236. package/dist/storage/operationEntries.js +12 -15
  237. package/dist/storage/operationEntries.js.map +1 -1
  238. package/dist/storage/preparationV12.d.ts +44 -0
  239. package/dist/storage/preparationV12.d.ts.map +1 -0
  240. package/dist/storage/preparationV12.js +30 -0
  241. package/dist/storage/preparationV12.js.map +1 -0
  242. package/dist/storage/readRecords.d.ts +4 -0
  243. package/dist/storage/readRecords.d.ts.map +1 -0
  244. package/dist/storage/readRecords.js +10 -0
  245. package/dist/storage/readRecords.js.map +1 -0
  246. package/dist/storage/recordChildren.d.ts +11 -0
  247. package/dist/storage/recordChildren.d.ts.map +1 -0
  248. package/dist/storage/recordChildren.js +105 -0
  249. package/dist/storage/recordChildren.js.map +1 -0
  250. package/dist/storage/recordShape.d.ts +23 -0
  251. package/dist/storage/recordShape.d.ts.map +1 -0
  252. package/dist/storage/recordShape.js +112 -0
  253. package/dist/storage/recordShape.js.map +1 -0
  254. package/dist/storage/recordValue.d.ts +9 -6
  255. package/dist/storage/recordValue.d.ts.map +1 -1
  256. package/dist/storage/recordValue.js +42 -32
  257. package/dist/storage/recordValue.js.map +1 -1
  258. package/dist/storage/shapeV12.d.ts +794 -0
  259. package/dist/storage/shapeV12.d.ts.map +1 -0
  260. package/dist/storage/shapeV12.js +10 -0
  261. package/dist/storage/shapeV12.js.map +1 -0
  262. package/dist/storage/textRecordValue.d.ts +3 -0
  263. package/dist/storage/textRecordValue.d.ts.map +1 -0
  264. package/dist/storage/textRecordValue.js +13 -0
  265. package/dist/storage/textRecordValue.js.map +1 -0
  266. package/dist/storage/typedDecisionsV12.d.ts +103 -0
  267. package/dist/storage/typedDecisionsV12.d.ts.map +1 -0
  268. package/dist/storage/typedDecisionsV12.js +97 -0
  269. package/dist/storage/typedDecisionsV12.js.map +1 -0
  270. package/dist/storage/typedTables.d.ts +4 -0
  271. package/dist/storage/typedTables.d.ts.map +1 -0
  272. package/dist/storage/typedTables.js +39 -0
  273. package/dist/storage/typedTables.js.map +1 -0
  274. package/package.json +8 -8
  275. package/src/engine/abandonStalled.ts +63 -0
  276. package/src/engine/applyResolution.ts +3 -0
  277. package/src/engine/approveBrief.ts +34 -32
  278. package/src/engine/observedAttempt.ts +3 -0
  279. package/src/engine/prepareCommand.ts +21 -0
  280. package/src/engine/recoverStall.ts +6 -2
  281. package/src/engine/repository.ts +1 -0
  282. package/src/engine/resolveExecution.ts +3 -1
  283. package/src/engine/sessionCleanup.ts +3 -1
  284. package/src/engine/sessionStatus.ts +5 -0
  285. package/src/engine/steerBrief.ts +54 -0
  286. package/src/engine/views.ts +1 -0
  287. package/src/host/admission.ts +2 -1
  288. package/src/host/readWaitStates.ts +12 -11
  289. package/src/host/recordPayloads.ts +11 -3
  290. package/src/model.ts +20 -1
  291. package/src/packageInfo.ts +1 -1
  292. package/src/prompt/briefEdit.ts +44 -0
  293. package/src/prompt/worker.ts +11 -2
  294. package/src/storage/attemptV12.ts +95 -0
  295. package/src/storage/createCollections.ts +21 -0
  296. package/src/storage/cycleV12.ts +125 -0
  297. package/src/storage/fleetMigrations.ts +3 -10
  298. package/src/storage/legacyColumns.ts +12 -0
  299. package/src/storage/makeForeignReservations.ts +41 -0
  300. package/src/storage/makePostgresFleetStore.ts +30 -43
  301. package/src/storage/model.ts +19 -69
  302. package/src/storage/operationEntries.ts +12 -22
  303. package/src/storage/preparationV12.ts +31 -0
  304. package/src/storage/readRecords.ts +12 -0
  305. package/src/storage/recordChildren.ts +131 -0
  306. package/src/storage/recordShape.ts +137 -0
  307. package/src/storage/recordValue.ts +47 -34
  308. package/src/storage/shapeV12.ts +11 -0
  309. package/src/storage/textRecordValue.ts +16 -0
  310. package/src/storage/typedDecisionsV12.ts +100 -0
  311. package/src/storage/typedTables.ts +39 -0
@@ -1,42 +1,55 @@
1
- import { Effect, Result, Schema } from "effect";
2
- import type { recordColumns } from "#storage/model.ts";
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
- const decodeJson = Schema.decodeUnknownResult(Schema.fromJsonString(Schema.Unknown));
6
+ type Row = Readonly<Record<string, unknown>>;
5
7
 
6
- function jsonValue(value: unknown) {
7
- try {
8
- return typeof value === "string" ? Result.succeed(JSON.parse(value)) : decodeJson(value);
9
- } catch {
10
- return decodeJson(value);
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
- export const recordValues = Effect.fn("FleetRow.recordValues")(function* (rows: readonly object[], columns: ReturnType<typeof recordColumns>) {
15
- const entries = Object.entries(columns);
16
- const records: Record<string, unknown>[] = [];
17
- for (const row of rows) {
18
- const values: Record<string, unknown> = { ...row };
19
- const fields: Record<string, unknown> = { workId: values.work_id };
20
- for (const [name, kind] of entries) {
21
- const value = values[name];
22
- if (value === null || value === undefined) {
23
- continue;
24
- }
25
- if (kind !== "json") {
26
- fields[name] = value;
27
- continue;
28
- }
29
- const decoded = jsonValue(value);
30
- if (decoded._tag === "Failure") {
31
- return yield* Effect.fail(decoded.failure);
32
- }
33
- fields[name] = decoded.success;
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
- records.push(fields);
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 records;
50
+ return roots.map((row) => ({ ...objectValue(read(shape, row, [], [], [])), workId: row.work_id }));
38
51
  });
39
52
 
40
- export function recordValue(row: object, columns: ReturnType<typeof recordColumns>) {
41
- return recordValues([row], columns).pipe(Effect.map(([value]) => value));
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
+ });