Add lightweight correctness linting and resolve formatting conflicts
This commit is contained in:
Vendored
+22
-7
@@ -1,11 +1,21 @@
|
||||
import { createHash } from "node:crypto";
|
||||
export const migrationObjectId = (executionId, port, logicalKey) => `obj:migration:${createHash("sha256").update(JSON.stringify([executionId, port, logicalKey])).digest("hex")}`;
|
||||
export const migrationObjectId = (executionId, port, logicalKey) => `obj:migration:${createHash("sha256")
|
||||
.update(JSON.stringify([executionId, port, logicalKey]))
|
||||
.digest("hex")}`;
|
||||
/** No ordinary RuntimeContext or network/database clients are supplied here.
|
||||
* Process isolation belongs to the host, not this convenience API. */
|
||||
export const createMigrationContext = (input) => {
|
||||
if (input.schemaVersion !== 1 || !input.executionId || new Set(input.ports.map((entry) => entry.name)).size !== input.ports.length)
|
||||
if (input.schemaVersion !== 1 ||
|
||||
!input.executionId ||
|
||||
new Set(input.ports.map((entry) => entry.name)).size !== input.ports.length)
|
||||
throw new Error("Invalid migration input");
|
||||
const output = { schemaVersion: 1, executionId: input.executionId, writes: [], creates: [], edgeReplacements: [] };
|
||||
const output = {
|
||||
schemaVersion: 1,
|
||||
executionId: input.executionId,
|
||||
writes: [],
|
||||
creates: [],
|
||||
edgeReplacements: [],
|
||||
};
|
||||
const port = (name, access) => {
|
||||
const selected = input.ports.find((entry) => entry.name === name);
|
||||
if (!selected?.access.includes(access) || (selected.view === "old" && access !== "read"))
|
||||
@@ -17,7 +27,8 @@ export const createMigrationContext = (input) => {
|
||||
const selected = port(name, "read"), states = structuredClone(selected.states ?? []);
|
||||
if (selected.view === "new" && Object.hasOwn(selected, "defaultValue"))
|
||||
for (const helper of output.creates) {
|
||||
if (input.ports.find((entry) => entry.name === helper.port)?.atomId === selected.attachedAtomId && !states.some((entry) => entry.objectId === helper.objectId))
|
||||
if (input.ports.find((entry) => entry.name === helper.port)?.atomId === selected.attachedAtomId &&
|
||||
!states.some((entry) => entry.objectId === helper.objectId))
|
||||
states.push({ objectId: helper.objectId, value: structuredClone(selected.defaultValue) });
|
||||
}
|
||||
if (selected.view === "new")
|
||||
@@ -30,9 +41,11 @@ export const createMigrationContext = (input) => {
|
||||
else
|
||||
states[existing] = entry;
|
||||
}
|
||||
return states.sort((a, b) => a.objectId < b.objectId ? -1 : a.objectId > b.objectId ? 1 : 0);
|
||||
return states.sort((a, b) => (a.objectId < b.objectId ? -1 : a.objectId > b.objectId ? 1 : 0));
|
||||
},
|
||||
read(name, objectId) {
|
||||
return context.enumerate(name).find((entry) => entry.objectId === objectId)?.value;
|
||||
},
|
||||
read(name, objectId) { return context.enumerate(name).find((entry) => entry.objectId === objectId)?.value; },
|
||||
write(name, objectId, value) {
|
||||
port(name, "write");
|
||||
const previous = output.writes.findIndex((entry) => entry.port === name && entry.objectId === objectId);
|
||||
@@ -53,7 +66,9 @@ export const createMigrationContext = (input) => {
|
||||
},
|
||||
edges(name) {
|
||||
const selected = port(name, "read");
|
||||
const replacement = selected.view === "new" ? output.edgeReplacements.find((entry) => input.ports.find((candidate) => candidate.name === entry.port)?.binding === selected.binding) : undefined;
|
||||
const replacement = selected.view === "new"
|
||||
? output.edgeReplacements.find((entry) => input.ports.find((candidate) => candidate.name === entry.port)?.binding === selected.binding)
|
||||
: undefined;
|
||||
return structuredClone(replacement?.edges ?? selected.edges ?? []);
|
||||
},
|
||||
replaceEdges(name, edges) {
|
||||
|
||||
Reference in New Issue
Block a user