@things-factory/fact-change 10.1.147 → 10.1.149
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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.factChangeRows = factChangeRows;
|
|
4
4
|
exports.assertFactChangeInTransaction = assertFactChangeInTransaction;
|
|
5
|
-
const
|
|
5
|
+
const refusal_1 = require("@things-factory/shell/refusal");
|
|
6
6
|
const writing_transaction_1 = require("@things-factory/webhook/writing-transaction");
|
|
7
7
|
const blank = (value) => typeof value !== 'string' || !value.trim();
|
|
8
8
|
/**
|
|
@@ -16,7 +16,7 @@ function factChangeRows(what, by, now) {
|
|
|
16
16
|
if (!what.changes?.length)
|
|
17
17
|
return [];
|
|
18
18
|
if (blank(what.factKind) || blank(what.factName) || what.changes.some(one => blank(one.field))) {
|
|
19
|
-
throw new
|
|
19
|
+
throw new refusal_1.Refusal('change-names-no-fact', { kind: what.factKind ?? '', name: what.factName ?? '' }, 'a change record has to say which fact and which field moved');
|
|
20
20
|
}
|
|
21
21
|
const at = what.at ?? now;
|
|
22
22
|
return what.changes.map(one => ({
|
|
@@ -39,6 +39,6 @@ function factChangeRows(what, by, now) {
|
|
|
39
39
|
function assertFactChangeInTransaction(manager) {
|
|
40
40
|
if ((0, writing_transaction_1.isWritingTransaction)(manager))
|
|
41
41
|
return;
|
|
42
|
-
throw new
|
|
42
|
+
throw new refusal_1.Refusal('change-record-outside-transaction', {}, 'a change record is written in the transaction that makes the change - on its own it can outlive a change that failed');
|
|
43
43
|
}
|
|
44
44
|
//# sourceMappingURL=fact-change-rows.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fact-change-rows.js","sourceRoot":"","sources":["../../server/service/fact-change-rows.ts"],"names":[],"mappings":";;AA+CA,wCAyBC;AAMD,sEAQC;AAtFD,
|
|
1
|
+
{"version":3,"file":"fact-change-rows.js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,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,EAAE;QACF,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,GAAG,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3C,CAAC,CAAC,CAAA;AACL,CAAC;AAED;;;GAGG;AACH,SAAgB,6BAA6B,CAAC,OAA8C;IAC1F,IAAI,IAAA,0CAAoB,EAAC,OAAO,CAAC;QAAE,OAAM;IAEzC,MAAM,IAAI,iBAAO,CACf,mCAAmC,EACnC,EAAE,EACF,sHAAsH,CACvH,CAAA;AACH,CAAC","sourcesContent":["import { Refusal } from '@things-factory/shell/refusal'\nimport { isWritingTransaction, type MaybeTransactional } from '@things-factory/webhook/writing-transaction'\n\nimport type { FieldChange } from './fact-change-text.js'\n\n/**\n * Which rows a change becomes, and when it may be written — judgement only, no storage, so tests run\n * without a database.\n */\nexport interface FactChangeWhat {\n /** Which kind of fact — the product's vocabulary (`job-order`, `station-screen-spec`, …). */\n factKind: string\n /** The fact, by name. */\n factName: string\n changes: FieldChange[]\n at?: Date\n}\n\nexport interface FactChangeBy {\n user?: unknown\n /** Where the change came from, in the product's own words (plant: `manual` · `twin-command` · `intake`). */\n source?: string\n /** Why. May be empty: empty means nobody wrote one, not that there was no reason. */\n reason?: string\n /** The approval it came through. Who approved is kept by worklist; this points there. */\n activityInstanceId?: string\n}\n\nexport interface FactChangeRow extends FieldChange {\n factKind: string\n factName: string\n at: Date\n source?: string\n reason?: string\n activityInstanceId?: string\n changedBy?: unknown\n}\n\nconst blank = (value: unknown) => typeof value !== 'string' || !value.trim()\n\n/**\n * The rows to write. No moved field, no row — a history filled with \"nothing happened\" is a history\n * nobody reads.\n *\n * A change that does not say which fact and which field moved is refused: a row about nothing can never\n * be found again and only inflates the count.\n */\nexport function factChangeRows(what: FactChangeWhat, by: FactChangeBy, now: Date): FactChangeRow[] {\n if (!what.changes?.length) return []\n\n if (blank(what.factKind) || blank(what.factName) || what.changes.some(one => blank(one.field))) {\n throw new Refusal(\n 'change-names-no-fact',\n { kind: what.factKind ?? '', name: what.factName ?? '' },\n 'a change record has to say which fact and which field moved'\n )\n }\n\n const at = what.at ?? now\n\n return what.changes.map(one => ({\n factKind: what.factKind,\n factName: what.factName,\n field: one.field,\n ...(one.fromValue !== undefined ? { fromValue: one.fromValue } : {}),\n ...(one.toValue !== undefined ? { toValue: one.toValue } : {}),\n at,\n ...(by.source ? { source: by.source } : {}),\n ...(by.reason ? { reason: by.reason } : {}),\n ...(by.activityInstanceId ? { activityInstanceId: by.activityInstanceId } : {}),\n ...(by.user ? { changedBy: by.user } : {})\n }))\n}\n\n/**\n * A change row is written in the transaction that makes the change. Committed on its own, it outlives a\n * change that then fails, and the history says something happened that did not.\n */\nexport function assertFactChangeInTransaction(manager: MaybeTransactional | undefined | null): void {\n if (isWritingTransaction(manager)) return\n\n throw new Refusal(\n 'change-record-outside-transaction',\n {},\n 'a change record is written in the transaction that makes the change - on its own it can outlive a change that failed'\n )\n}\n"]}
|