@entifix/next-shell 0.14.0 → 0.16.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 (35) hide show
  1. package/dist/lib/config/service-proxy-route.d.ts +4 -7
  2. package/dist/lib/config/service-proxy-route.d.ts.map +1 -1
  3. package/dist/lib/config/service-proxy-route.js +0 -24
  4. package/dist/lib/config/service-proxy-route.js.map +1 -1
  5. package/dist/lib/crud/index.d.ts +0 -1
  6. package/dist/lib/crud/index.d.ts.map +1 -1
  7. package/dist/lib/crud/index.js +0 -1
  8. package/dist/lib/crud/index.js.map +1 -1
  9. package/dist/lib/crud/make-entity-crud.d.ts +7 -12
  10. package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
  11. package/dist/lib/crud/make-entity-crud.js +33 -64
  12. package/dist/lib/crud/make-entity-crud.js.map +1 -1
  13. package/dist/lib/workspace/index.d.ts +0 -2
  14. package/dist/lib/workspace/index.d.ts.map +1 -1
  15. package/dist/lib/workspace/index.js +0 -2
  16. package/dist/lib/workspace/index.js.map +1 -1
  17. package/dist/lib/workspace/pending-flows.d.ts +2 -2
  18. package/dist/lib/workspace/pending-flows.js.map +1 -1
  19. package/package.json +9 -9
  20. package/dist/lib/crud/hand-off-write.d.ts +0 -35
  21. package/dist/lib/crud/hand-off-write.d.ts.map +0 -1
  22. package/dist/lib/crud/hand-off-write.js +0 -27
  23. package/dist/lib/crud/hand-off-write.js.map +0 -1
  24. package/dist/lib/crud/pending-notice.d.ts +0 -31
  25. package/dist/lib/crud/pending-notice.d.ts.map +0 -1
  26. package/dist/lib/crud/pending-notice.js +0 -72
  27. package/dist/lib/crud/pending-notice.js.map +0 -1
  28. package/dist/lib/workspace/pending-state.d.ts +0 -85
  29. package/dist/lib/workspace/pending-state.d.ts.map +0 -1
  30. package/dist/lib/workspace/pending-state.js +0 -155
  31. package/dist/lib/workspace/pending-state.js.map +0 -1
  32. package/dist/lib/workspace/pending-transactions.d.ts +0 -44
  33. package/dist/lib/workspace/pending-transactions.d.ts.map +0 -1
  34. package/dist/lib/workspace/pending-transactions.js +0 -114
  35. package/dist/lib/workspace/pending-transactions.js.map +0 -1
@@ -13,8 +13,8 @@ export interface PendingFlowsProviderProps {
13
13
  * organizationId })`, or `ANONYMOUS_WORKSPACE_SCOPE` for nobody in
14
14
  * particular, which keeps flow ids and their age only.
15
15
  *
16
- * Required for the reason `PendingTransactionsProviderProps.scope` is:
17
- * IndexedDB belongs to the browser profile, not to whoever signed in.
16
+ * Required because IndexedDB belongs to the browser profile, not to
17
+ * whoever signed in.
18
18
  */
19
19
  readonly scope: string;
20
20
  /** The tab's push channel, where each pending flow's outcome arrives. */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/workspace/pending-flows.tsx"],"sourcesContent":["'use client';\n\nimport { useToasts } from '@entifix/react-controls';\nimport {\n type FlowStatusRead,\n makePendingFlowStore,\n type PendingFlowStorage,\n PendingFlowStoreProvider,\n type PushChannel,\n usePendingFlowSettlement,\n} from '@entifix/react-integration';\nimport { type ReactNode, useMemo } from 'react';\n\nimport { makeIndexedDbStateStorage } from './idb-state-storage.js';\nimport { ANONYMOUS_WORKSPACE_SCOPE } from './workspace-scope.js';\n\n/**\n * How long a pending flow nobody can account for is kept before it is\n * dropped: no push arrived, and its status read answers nothing. Long enough\n * for a flow that waits on a person, short enough that a lost one does not\n * hold a form open across a working day.\n */\nexport const PENDING_FLOW_MAX_AGE_MS = 30 * 60 * 1000;\n\n// Module scope: a storage per render would reopen the database each time.\nconst pendingFlowStorage = makeIndexedDbStateStorage(\n 'entifix-pending-flows',\n 'flows',\n);\n\nexport interface PendingFlowsProviderProps {\n /**\n * Whose pending flows these are — `workspaceScopeKey({ userId,\n * organizationId })`, or `ANONYMOUS_WORKSPACE_SCOPE` for nobody in\n * particular, which keeps flow ids and their age only.\n *\n * Required for the reason `PendingTransactionsProviderProps.scope` is:\n * IndexedDB belongs to the browser profile, not to whoever signed in.\n */\n readonly scope: string;\n /** The tab's push channel, where each pending flow's outcome arrives. */\n readonly channel: PushChannel;\n /**\n * Reads a flow's status link when its push may have been missed —\n * `buildFlowStatusReader()` over REST. Omitted, a flow settles by push\n * alone, and one whose push was missed is dropped at the age bound.\n */\n readonly readStatus?: FlowStatusRead;\n readonly maxAgeMs?: number;\n /** Defaults to IndexedDB, so a pending write survives a reload. */\n readonly storage?: PendingFlowStorage;\n readonly children: ReactNode;\n}\n\n/**\n * Waits on every write this browser handed to a flow, and tells the operator\n * once when one fails\n * ([ADR 0022](../../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).\n *\n * It holds the pending-flow store the generated CRUD records into, persisted\n * per principal, and settles each flow from its push or from a status read\n * after a reconnect. A failed flow is shown through the host's\n * `ToastRegion`, translated, exactly once — however many tabs or\n * redeliveries report it.\n *\n * ⚠️ **Mount it inside a `ToastProvider`, and above the plain routes**, not\n * only the workspace: a create is `/<basePath>/new` on the route host.\n */\nexport function PendingFlowsProvider({\n scope,\n channel,\n readStatus,\n maxAgeMs = PENDING_FLOW_MAX_AGE_MS,\n storage = pendingFlowStorage,\n children,\n}: PendingFlowsProviderProps) {\n const toasts = useToasts();\n\n // A store per principal: a sign-in under another scope must never read the\n // previous one's pending writes.\n const store = useMemo(\n () =>\n makePendingFlowStore({\n storage,\n key: `pending-flows:${scope}`,\n anonymous: scope === ANONYMOUS_WORKSPACE_SCOPE,\n }),\n [scope, storage],\n );\n\n usePendingFlowSettlement({\n channel,\n store,\n maxAgeMs,\n ...(readStatus === undefined ? {} : { readStatus }),\n onFailure: failure => {\n toasts?.showFailure(failure);\n },\n });\n\n if (toasts === undefined)\n throw new Error(\n 'PendingFlowsProvider must sit inside a ToastProvider: a failed flow has nowhere else to be shown',\n );\n\n return (\n <PendingFlowStoreProvider store={store}>\n {children}\n </PendingFlowStoreProvider>\n );\n}\n"],"names":["useToasts","makePendingFlowStore","PendingFlowStoreProvider","usePendingFlowSettlement","useMemo","makeIndexedDbStateStorage","ANONYMOUS_WORKSPACE_SCOPE","PENDING_FLOW_MAX_AGE_MS","pendingFlowStorage","PendingFlowsProvider","scope","channel","readStatus","maxAgeMs","storage","children","toasts","store","key","anonymous","undefined","onFailure","failure","showFailure","Error"],"mappings":"AAAA;;;AAEA,SAASA,SAAS,QAAQ,0BAA0B;AACpD,SAEEC,oBAAoB,EAEpBC,wBAAwB,EAExBC,wBAAwB,QACnB,6BAA6B;AACpC,SAAyBC,OAAO,QAAQ,QAAQ;AAEhD,SAASC,yBAAyB,QAAQ,yBAAyB;AACnE,SAASC,yBAAyB,QAAQ,uBAAuB;AAEjE;;;;;CAKC,GACD,OAAO,MAAMC,0BAA0B,KAAK,KAAK,KAAK;AAEtD,0EAA0E;AAC1E,MAAMC,qBAAqBH,0BACzB,yBACA;AA2BF;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASI,qBAAqB,EACnCC,KAAK,EACLC,OAAO,EACPC,UAAU,EACVC,WAAWN,uBAAuB,EAClCO,UAAUN,kBAAkB,EAC5BO,QAAQ,EACkB;IAC1B,MAAMC,SAAShB;IAEf,2EAA2E;IAC3E,iCAAiC;IACjC,MAAMiB,QAAQb,QACZ,IACEH,qBAAqB;YACnBa;YACAI,KAAK,CAAC,cAAc,EAAER,OAAO;YAC7BS,WAAWT,UAAUJ;QACvB,IACF;QAACI;QAAOI;KAAQ;IAGlBX,yBAAyB;QACvBQ;QACAM;QACAJ;OACID,eAAeQ,YAAY,CAAC,IAAI;QAAER;IAAW;QACjDS,WAAWC,CAAAA;YACTN,0BAAAA,OAAQO,WAAW,CAACD;QACtB;;IAGF,IAAIN,WAAWI,WACb,MAAM,IAAII,MACR;IAGJ,qBACE,KAACtB;QAAyBe,OAAOA;kBAC9BF;;AAGP"}
1
+ {"version":3,"sources":["../../../src/lib/workspace/pending-flows.tsx"],"sourcesContent":["'use client';\n\nimport { useToasts } from '@entifix/react-controls';\nimport {\n type FlowStatusRead,\n makePendingFlowStore,\n type PendingFlowStorage,\n PendingFlowStoreProvider,\n type PushChannel,\n usePendingFlowSettlement,\n} from '@entifix/react-integration';\nimport { type ReactNode, useMemo } from 'react';\n\nimport { makeIndexedDbStateStorage } from './idb-state-storage.js';\nimport { ANONYMOUS_WORKSPACE_SCOPE } from './workspace-scope.js';\n\n/**\n * How long a pending flow nobody can account for is kept before it is\n * dropped: no push arrived, and its status read answers nothing. Long enough\n * for a flow that waits on a person, short enough that a lost one does not\n * hold a form open across a working day.\n */\nexport const PENDING_FLOW_MAX_AGE_MS = 30 * 60 * 1000;\n\n// Module scope: a storage per render would reopen the database each time.\nconst pendingFlowStorage = makeIndexedDbStateStorage(\n 'entifix-pending-flows',\n 'flows',\n);\n\nexport interface PendingFlowsProviderProps {\n /**\n * Whose pending flows these are — `workspaceScopeKey({ userId,\n * organizationId })`, or `ANONYMOUS_WORKSPACE_SCOPE` for nobody in\n * particular, which keeps flow ids and their age only.\n *\n * Required because IndexedDB belongs to the browser profile, not to\n * whoever signed in.\n */\n readonly scope: string;\n /** The tab's push channel, where each pending flow's outcome arrives. */\n readonly channel: PushChannel;\n /**\n * Reads a flow's status link when its push may have been missed —\n * `buildFlowStatusReader()` over REST. Omitted, a flow settles by push\n * alone, and one whose push was missed is dropped at the age bound.\n */\n readonly readStatus?: FlowStatusRead;\n readonly maxAgeMs?: number;\n /** Defaults to IndexedDB, so a pending write survives a reload. */\n readonly storage?: PendingFlowStorage;\n readonly children: ReactNode;\n}\n\n/**\n * Waits on every write this browser handed to a flow, and tells the operator\n * once when one fails\n * ([ADR 0022](../../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).\n *\n * It holds the pending-flow store the generated CRUD records into, persisted\n * per principal, and settles each flow from its push or from a status read\n * after a reconnect. A failed flow is shown through the host's\n * `ToastRegion`, translated, exactly once — however many tabs or\n * redeliveries report it.\n *\n * ⚠️ **Mount it inside a `ToastProvider`, and above the plain routes**, not\n * only the workspace: a create is `/<basePath>/new` on the route host.\n */\nexport function PendingFlowsProvider({\n scope,\n channel,\n readStatus,\n maxAgeMs = PENDING_FLOW_MAX_AGE_MS,\n storage = pendingFlowStorage,\n children,\n}: PendingFlowsProviderProps) {\n const toasts = useToasts();\n\n // A store per principal: a sign-in under another scope must never read the\n // previous one's pending writes.\n const store = useMemo(\n () =>\n makePendingFlowStore({\n storage,\n key: `pending-flows:${scope}`,\n anonymous: scope === ANONYMOUS_WORKSPACE_SCOPE,\n }),\n [scope, storage],\n );\n\n usePendingFlowSettlement({\n channel,\n store,\n maxAgeMs,\n ...(readStatus === undefined ? {} : { readStatus }),\n onFailure: failure => {\n toasts?.showFailure(failure);\n },\n });\n\n if (toasts === undefined)\n throw new Error(\n 'PendingFlowsProvider must sit inside a ToastProvider: a failed flow has nowhere else to be shown',\n );\n\n return (\n <PendingFlowStoreProvider store={store}>\n {children}\n </PendingFlowStoreProvider>\n );\n}\n"],"names":["useToasts","makePendingFlowStore","PendingFlowStoreProvider","usePendingFlowSettlement","useMemo","makeIndexedDbStateStorage","ANONYMOUS_WORKSPACE_SCOPE","PENDING_FLOW_MAX_AGE_MS","pendingFlowStorage","PendingFlowsProvider","scope","channel","readStatus","maxAgeMs","storage","children","toasts","store","key","anonymous","undefined","onFailure","failure","showFailure","Error"],"mappings":"AAAA;;;AAEA,SAASA,SAAS,QAAQ,0BAA0B;AACpD,SAEEC,oBAAoB,EAEpBC,wBAAwB,EAExBC,wBAAwB,QACnB,6BAA6B;AACpC,SAAyBC,OAAO,QAAQ,QAAQ;AAEhD,SAASC,yBAAyB,QAAQ,yBAAyB;AACnE,SAASC,yBAAyB,QAAQ,uBAAuB;AAEjE;;;;;CAKC,GACD,OAAO,MAAMC,0BAA0B,KAAK,KAAK,KAAK;AAEtD,0EAA0E;AAC1E,MAAMC,qBAAqBH,0BACzB,yBACA;AA2BF;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASI,qBAAqB,EACnCC,KAAK,EACLC,OAAO,EACPC,UAAU,EACVC,WAAWN,uBAAuB,EAClCO,UAAUN,kBAAkB,EAC5BO,QAAQ,EACkB;IAC1B,MAAMC,SAAShB;IAEf,2EAA2E;IAC3E,iCAAiC;IACjC,MAAMiB,QAAQb,QACZ,IACEH,qBAAqB;YACnBa;YACAI,KAAK,CAAC,cAAc,EAAER,OAAO;YAC7BS,WAAWT,UAAUJ;QACvB,IACF;QAACI;QAAOI;KAAQ;IAGlBX,yBAAyB;QACvBQ;QACAM;QACAJ;OACID,eAAeQ,YAAY,CAAC,IAAI;QAAER;IAAW;QACjDS,WAAWC,CAAAA;YACTN,0BAAAA,OAAQO,WAAW,CAACD;QACtB;;IAGF,IAAIN,WAAWI,WACb,MAAM,IAAII,MACR;IAGJ,qBACE,KAACtB;QAAyBe,OAAOA;kBAC9BF;;AAGP"}
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  }
22
22
  }
23
23
  },
24
- "version": "0.14.0",
24
+ "version": "0.16.0",
25
25
  "description": "Next.js application shell: back-office chrome, workspace tabs, CRUD screens derived from entity metadata, and session and proxy routes.",
26
26
  "license": "MIT",
27
27
  "repository": {
@@ -57,17 +57,17 @@
57
57
  "react": "19.3.1",
58
58
  "react-dom": "19.3.1",
59
59
  "zustand": "^5.0.16",
60
- "@entifix/testing-unit": "0.14.0"
60
+ "@entifix/testing-unit": "0.16.0"
61
61
  },
62
62
  "dependencies": {
63
63
  "idb": "^8.0.4",
64
- "@entifix/authz": "0.14.0",
65
- "@entifix/business": "0.14.0",
66
- "@entifix/i18n": "0.14.0",
67
- "@entifix/react-controls": "0.14.0",
68
- "@entifix/core": "0.14.0",
69
- "@entifix/react-integration": "0.14.0",
70
- "@entifix/transactions": "0.14.0"
64
+ "@entifix/authz": "0.16.0",
65
+ "@entifix/business": "0.16.0",
66
+ "@entifix/i18n": "0.16.0",
67
+ "@entifix/react-controls": "0.16.0",
68
+ "@entifix/core": "0.16.0",
69
+ "@entifix/react-integration": "0.16.0",
70
+ "@entifix/transactions": "0.16.0"
71
71
  },
72
72
  "files": [
73
73
  "dist",
@@ -1,35 +0,0 @@
1
- import type { PendingTransactionStore } from '@entifix/transactions';
2
- export interface HandOffWriteOptions {
3
- /** The saved record's id — the transaction id, for a tracked create. */
4
- readonly id: string;
5
- /** The record as the browser built it, shown until the service confirms. */
6
- readonly record: unknown;
7
- readonly pending: PendingTransactionStore;
8
- /** The draft the write was composed in, if it had one. */
9
- readonly draft?: {
10
- clear(): void;
11
- };
12
- }
13
- /**
14
- * What happens to a draft once its write has been handed over.
15
- *
16
- * A transactional create resolves at the `202`, **before** the write is
17
- * durable, so the save adapter has already announced it and the id is in the
18
- * pending set.
19
- * Handing the record over *is* the question: the returned entity is otherwise
20
- * indistinguishable from a plain REST create, and asking `entries.some(...)`
21
- * beforehand would read a set captured before the `await` that announced it.
22
- *
23
- * ⚠️ A **still-pending write keeps its draft**. The write has not committed, and
24
- * a failure minutes from now would otherwise have destroyed the operator's only
25
- * copy of what they typed. Only a plain, committed write spends it.
26
- *
27
- * It lives here rather than inside `makeEntityCrud` because it is not the
28
- * generator's rule — it is the rule for every screen that writes. A wizard's
29
- * Finalizar performs the same three steps, and a second copy of them is where
30
- * one of the two would eventually stop keeping the draft.
31
- *
32
- * @returns whether the write is still in flight.
33
- */
34
- export declare function handOffWrite({ id, record, pending, draft, }: HandOffWriteOptions): boolean;
35
- //# sourceMappingURL=hand-off-write.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hand-off-write.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/hand-off-write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAClC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;IAC1C,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,KAAK,IAAI,IAAI,CAAA;KAAE,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,EAAE,EACF,MAAM,EACN,OAAO,EACP,KAAK,GACN,EAAE,mBAAmB,GAAG,OAAO,CAK/B"}
@@ -1,27 +0,0 @@
1
- /**
2
- * What happens to a draft once its write has been handed over.
3
- *
4
- * A transactional create resolves at the `202`, **before** the write is
5
- * durable, so the save adapter has already announced it and the id is in the
6
- * pending set.
7
- * Handing the record over *is* the question: the returned entity is otherwise
8
- * indistinguishable from a plain REST create, and asking `entries.some(...)`
9
- * beforehand would read a set captured before the `await` that announced it.
10
- *
11
- * ⚠️ A **still-pending write keeps its draft**. The write has not committed, and
12
- * a failure minutes from now would otherwise have destroyed the operator's only
13
- * copy of what they typed. Only a plain, committed write spends it.
14
- *
15
- * It lives here rather than inside `makeEntityCrud` because it is not the
16
- * generator's rule — it is the rule for every screen that writes. A wizard's
17
- * Finalizar performs the same three steps, and a second copy of them is where
18
- * one of the two would eventually stop keeping the draft.
19
- *
20
- * @returns whether the write is still in flight.
21
- */ export function handOffWrite({ id, record, pending, draft }) {
22
- if (pending.attach(id, record)) return true;
23
- draft == null ? void 0 : draft.clear();
24
- return false;
25
- }
26
-
27
- //# sourceMappingURL=hand-off-write.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/crud/hand-off-write.ts"],"sourcesContent":["import type { PendingTransactionStore } from '@entifix/transactions';\n\nexport interface HandOffWriteOptions {\n /** The saved record's id — the transaction id, for a tracked create. */\n readonly id: string;\n /** The record as the browser built it, shown until the service confirms. */\n readonly record: unknown;\n readonly pending: PendingTransactionStore;\n /** The draft the write was composed in, if it had one. */\n readonly draft?: { clear(): void };\n}\n\n/**\n * What happens to a draft once its write has been handed over.\n *\n * A transactional create resolves at the `202`, **before** the write is\n * durable, so the save adapter has already announced it and the id is in the\n * pending set.\n * Handing the record over *is* the question: the returned entity is otherwise\n * indistinguishable from a plain REST create, and asking `entries.some(...)`\n * beforehand would read a set captured before the `await` that announced it.\n *\n * ⚠️ A **still-pending write keeps its draft**. The write has not committed, and\n * a failure minutes from now would otherwise have destroyed the operator's only\n * copy of what they typed. Only a plain, committed write spends it.\n *\n * It lives here rather than inside `makeEntityCrud` because it is not the\n * generator's rule — it is the rule for every screen that writes. A wizard's\n * Finalizar performs the same three steps, and a second copy of them is where\n * one of the two would eventually stop keeping the draft.\n *\n * @returns whether the write is still in flight.\n */\nexport function handOffWrite({\n id,\n record,\n pending,\n draft,\n}: HandOffWriteOptions): boolean {\n if (pending.attach(id, record)) return true;\n\n draft?.clear();\n return false;\n}\n"],"names":["handOffWrite","id","record","pending","draft","attach","clear"],"mappings":"AAYA;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASA,aAAa,EAC3BC,EAAE,EACFC,MAAM,EACNC,OAAO,EACPC,KAAK,EACe;IACpB,IAAID,QAAQE,MAAM,CAACJ,IAAIC,SAAS,OAAO;IAEvCE,yBAAAA,MAAOE,KAAK;IACZ,OAAO;AACT"}
@@ -1,31 +0,0 @@
1
- import type { PendingEntry } from '@entifix/transactions';
2
- export interface PendingNoticeProps {
3
- /** This entity's in-flight and failed writes, newest last. */
4
- entries: readonly PendingEntry[];
5
- /** Retires a failure the operator has read. */
6
- onDismiss: (transactionId: string) => void;
7
- className?: string;
8
- }
9
- /**
10
- * What became of the writes this browser started but the server has not
11
- * finished.
12
- *
13
- * ⚠️ **This is the list's surface because the tab strip cannot be.** Only
14
- * creates are transactional (`create: 'command'` fires on `isCreate` alone), and
15
- * a create has no workspace tab — `EntityEditorTab` takes a required id, so
16
- * `master:<key>` is the list and there is no address for a record that does not
17
- * exist yet. A badge keyed on a pending record id would therefore be unreachable
18
- * by construction, which is exactly the "declared, styled, never produced"
19
- * defect the optimistic mutation contract exists to prevent. It renders here instead, where
20
- * `afterSave()` actually puts the operator.
21
- *
22
- * `role="status"`, not `role="alert"` — the `BulkResult` reasoning: an outcome
23
- * to read, not an interruption.
24
- *
25
- * The failure headline is a catalog key and never `entry.reason`, which is free
26
- * text from whatever threw, in whatever language that code was written in. The
27
- * reason is kept as secondary, explicitly-unlocalized detail; a translatable
28
- * failure needs an error *code* on the event, which the event does not carry yet.
29
- */
30
- export declare function PendingNotice({ entries, onDismiss, className, }: PendingNoticeProps): import("react").JSX.Element | null;
31
- //# sourceMappingURL=pending-notice.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pending-notice.d.ts","sourceRoot":"","sources":["../../../src/lib/crud/pending-notice.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,8DAA8D;IAC9D,OAAO,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,+CAA+C;IAC/C,SAAS,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,SAAS,EACT,SAAS,GACV,EAAE,kBAAkB,sCA0DpB"}
@@ -1,72 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Button, cn, useT } from '@entifix/react-controls/primitives';
4
- /**
5
- * What became of the writes this browser started but the server has not
6
- * finished.
7
- *
8
- * ⚠️ **This is the list's surface because the tab strip cannot be.** Only
9
- * creates are transactional (`create: 'command'` fires on `isCreate` alone), and
10
- * a create has no workspace tab — `EntityEditorTab` takes a required id, so
11
- * `master:<key>` is the list and there is no address for a record that does not
12
- * exist yet. A badge keyed on a pending record id would therefore be unreachable
13
- * by construction, which is exactly the "declared, styled, never produced"
14
- * defect the optimistic mutation contract exists to prevent. It renders here instead, where
15
- * `afterSave()` actually puts the operator.
16
- *
17
- * `role="status"`, not `role="alert"` — the `BulkResult` reasoning: an outcome
18
- * to read, not an interruption.
19
- *
20
- * The failure headline is a catalog key and never `entry.reason`, which is free
21
- * text from whatever threw, in whatever language that code was written in. The
22
- * reason is kept as secondary, explicitly-unlocalized detail; a translatable
23
- * failure needs an error *code* on the event, which the event does not carry yet.
24
- */ export function PendingNotice({ entries, onDismiss, className }) {
25
- // The `shell` namespace: this copy lives in `shell.ts`, and `useT()` with no
26
- // argument reads `controls` — which resolves nothing and renders the key.
27
- const t = useT('shell');
28
- const saving = entries.filter((entry)=>entry.state === 'pending');
29
- const failed = entries.filter((entry)=>entry.state === 'failed');
30
- if (saving.length === 0 && failed.length === 0) return null;
31
- return /*#__PURE__*/ _jsxs("div", {
32
- role: "status",
33
- "aria-label": t('workspace.pendingLabel'),
34
- "data-testid": "pending-notice",
35
- className: cn('flex flex-col gap-2xs rounded-lg border border-border bg-surface-elevated px-s py-2xs', className),
36
- children: [
37
- saving.length > 0 && /*#__PURE__*/ _jsx("span", {
38
- className: "text-step-sm text-content-muted",
39
- children: t('workspace.savePending', {
40
- count: saving.length
41
- })
42
- }),
43
- failed.map((entry)=>/*#__PURE__*/ _jsxs("div", {
44
- className: "flex flex-wrap items-center gap-2xs",
45
- children: [
46
- /*#__PURE__*/ _jsx("span", {
47
- className: "text-step-sm text-danger",
48
- children: t('workspace.saveFailed')
49
- }),
50
- entry.reason !== undefined && // Untranslated on purpose, and marked as such: it is a server
51
- // exception string, shown because a reason nobody can read is worse
52
- // than one in the wrong language.
53
- /*#__PURE__*/ _jsx("span", {
54
- lang: "und",
55
- className: "text-step-sm text-content-muted",
56
- "data-testid": "pending-notice-reason",
57
- children: entry.reason
58
- }),
59
- /*#__PURE__*/ _jsx(Button, {
60
- type: "button",
61
- variant: "ghost",
62
- size: "sm",
63
- onClick: ()=>onDismiss(entry.transactionId),
64
- children: t('workspace.saveFailedDismiss')
65
- })
66
- ]
67
- }, entry.transactionId))
68
- ]
69
- });
70
- }
71
-
72
- //# sourceMappingURL=pending-notice.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/crud/pending-notice.tsx"],"sourcesContent":["'use client';\n\nimport { Button, cn, useT } from '@entifix/react-controls/primitives';\nimport type { PendingEntry } from '@entifix/transactions';\n\nexport interface PendingNoticeProps {\n /** This entity's in-flight and failed writes, newest last. */\n entries: readonly PendingEntry[];\n /** Retires a failure the operator has read. */\n onDismiss: (transactionId: string) => void;\n className?: string;\n}\n\n/**\n * What became of the writes this browser started but the server has not\n * finished.\n *\n * ⚠️ **This is the list's surface because the tab strip cannot be.** Only\n * creates are transactional (`create: 'command'` fires on `isCreate` alone), and\n * a create has no workspace tab — `EntityEditorTab` takes a required id, so\n * `master:<key>` is the list and there is no address for a record that does not\n * exist yet. A badge keyed on a pending record id would therefore be unreachable\n * by construction, which is exactly the \"declared, styled, never produced\"\n * defect the optimistic mutation contract exists to prevent. It renders here instead, where\n * `afterSave()` actually puts the operator.\n *\n * `role=\"status\"`, not `role=\"alert\"` — the `BulkResult` reasoning: an outcome\n * to read, not an interruption.\n *\n * The failure headline is a catalog key and never `entry.reason`, which is free\n * text from whatever threw, in whatever language that code was written in. The\n * reason is kept as secondary, explicitly-unlocalized detail; a translatable\n * failure needs an error *code* on the event, which the event does not carry yet.\n */\nexport function PendingNotice({\n entries,\n onDismiss,\n className,\n}: PendingNoticeProps) {\n // The `shell` namespace: this copy lives in `shell.ts`, and `useT()` with no\n // argument reads `controls` — which resolves nothing and renders the key.\n const t = useT('shell');\n\n const saving = entries.filter(entry => entry.state === 'pending');\n const failed = entries.filter(entry => entry.state === 'failed');\n\n if (saving.length === 0 && failed.length === 0) return null;\n\n return (\n <div\n role=\"status\"\n aria-label={t('workspace.pendingLabel')}\n data-testid=\"pending-notice\"\n className={cn(\n 'flex flex-col gap-2xs rounded-lg border border-border bg-surface-elevated px-s py-2xs',\n className,\n )}\n >\n {saving.length > 0 && (\n <span className=\"text-step-sm text-content-muted\">\n {t('workspace.savePending', { count: saving.length })}\n </span>\n )}\n\n {failed.map(entry => (\n <div\n key={entry.transactionId}\n className=\"flex flex-wrap items-center gap-2xs\"\n >\n <span className=\"text-step-sm text-danger\">\n {t('workspace.saveFailed')}\n </span>\n {entry.reason !== undefined && (\n // Untranslated on purpose, and marked as such: it is a server\n // exception string, shown because a reason nobody can read is worse\n // than one in the wrong language.\n <span\n lang=\"und\"\n className=\"text-step-sm text-content-muted\"\n data-testid=\"pending-notice-reason\"\n >\n {entry.reason}\n </span>\n )}\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => onDismiss(entry.transactionId)}\n >\n {t('workspace.saveFailedDismiss')}\n </Button>\n </div>\n ))}\n </div>\n );\n}\n"],"names":["Button","cn","useT","PendingNotice","entries","onDismiss","className","t","saving","filter","entry","state","failed","length","div","role","aria-label","data-testid","span","count","map","reason","undefined","lang","type","variant","size","onClick","transactionId"],"mappings":"AAAA;;AAEA,SAASA,MAAM,EAAEC,EAAE,EAAEC,IAAI,QAAQ,qCAAqC;AAWtE;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASC,cAAc,EAC5BC,OAAO,EACPC,SAAS,EACTC,SAAS,EACU;IACnB,6EAA6E;IAC7E,0EAA0E;IAC1E,MAAMC,IAAIL,KAAK;IAEf,MAAMM,SAASJ,QAAQK,MAAM,CAACC,CAAAA,QAASA,MAAMC,KAAK,KAAK;IACvD,MAAMC,SAASR,QAAQK,MAAM,CAACC,CAAAA,QAASA,MAAMC,KAAK,KAAK;IAEvD,IAAIH,OAAOK,MAAM,KAAK,KAAKD,OAAOC,MAAM,KAAK,GAAG,OAAO;IAEvD,qBACE,MAACC;QACCC,MAAK;QACLC,cAAYT,EAAE;QACdU,eAAY;QACZX,WAAWL,GACT,yFACAK;;YAGDE,OAAOK,MAAM,GAAG,mBACf,KAACK;gBAAKZ,WAAU;0BACbC,EAAE,yBAAyB;oBAAEY,OAAOX,OAAOK,MAAM;gBAAC;;YAItDD,OAAOQ,GAAG,CAACV,CAAAA,sBACV,MAACI;oBAECR,WAAU;;sCAEV,KAACY;4BAAKZ,WAAU;sCACbC,EAAE;;wBAEJG,MAAMW,MAAM,KAAKC,aAChB,8DAA8D;wBAC9D,oEAAoE;wBACpE,kCAAkC;sCAClC,KAACJ;4BACCK,MAAK;4BACLjB,WAAU;4BACVW,eAAY;sCAEXP,MAAMW,MAAM;;sCAGjB,KAACrB;4BACCwB,MAAK;4BACLC,SAAQ;4BACRC,MAAK;4BACLC,SAAS,IAAMtB,UAAUK,MAAMkB,aAAa;sCAE3CrB,EAAE;;;mBAxBAG,MAAMkB,aAAa;;;AA8BlC"}
@@ -1,85 +0,0 @@
1
- import type { PendingEntry, PendingTransaction } from '@entifix/transactions';
2
- /**
3
- * Writes the browser started and the server has not finished, keyed by
4
- * transaction id.
5
- *
6
- * ⚠️ **This is not workspace state, and the distinction is load-bearing.** Tabs
7
- * and drafts belong to the workspace and are scoped by `WorkspaceShell`; a
8
- * pending write is not, because a create happens at `/<basePath>/new` on the
9
- * plain route, outside any `WorkspaceShell` (a generated list still uses plain
10
- * `href`s — a known residual of the address grammar). A store mounted inside
11
- * the workspace would
12
- * be written to by nothing, or — worse — written to *before* `persist.setOptions`
13
- * had scoped it, which is the unscoped cross-account restore that keying a
14
- * draft per principal exists to prevent. So `PendingTransactionsProvider` sits at the authenticated layout
15
- * instead, above both.
16
- *
17
- * It shares the workspace's IndexedDB database because it is the same browser
18
- * profile and the same scope key, not because it is the same concern.
19
- */
20
- export interface PendingState {
21
- pending: Record<string, PendingEntry>;
22
- began(transaction: PendingTransaction): void;
23
- attach(transactionId: string, record: unknown): boolean;
24
- settle(transactionId: string): void;
25
- fail(transactionId: string, reason?: string): void;
26
- dismiss(transactionId: string): void;
27
- }
28
- /**
29
- * ⚠️ **`record` is stripped before persisting.** It is a class instance, and a
30
- * draft-style JSON round trip does not preserve one — it returns as something
31
- * else, silently. So a refresh keeps the *watch* and loses the row,
32
- * which is the documented behaviour: past a refresh, server truth plus an honest
33
- * notice beats a record rebuilt from a blob.
34
- */
35
- export declare function persistedPending(store: PendingState): Pick<PendingState, 'pending'>;
36
- /**
37
- * How many pending writes are watched at once, oldest evicted first.
38
- *
39
- * The same reasoning as {@link MAX_TABS}: an unbounded set persisted to
40
- * IndexedDB grows without anything ever pruning it, and reconciliation asks the
41
- * tracker once per entry on every reconnect — so the cap is also what keeps that
42
- * fan-out a handful of requests rather than an unbounded one.
43
- *
44
- * An evicted entry is dropped silently. The record is still on the server and
45
- * the list's own query is the fallback; what is lost is only the watching.
46
- */
47
- export declare const MAX_PENDING = 12;
48
- /**
49
- * Bump when the *shape* of an entry changes, and every persisted pending write
50
- * is discarded on the next load.
51
- *
52
- * Discarding is right here for a reason the other two stores do not share: an
53
- * entry is a claim that something is still in flight, and it stops being true on
54
- * its own. A stale one restored from a previous build watches a transaction that
55
- * settled hours ago, and the reconcile that would correct it is keyed on a shape
56
- * this build may no longer understand.
57
- */
58
- export declare const PENDING_VERSION = 1;
59
- /**
60
- * Discard, never guess — written out rather than left to zustand's default,
61
- * which discards too but logs an error for a decision that was made on purpose.
62
- * Same call as `migrateDrafts` and `migrateTabs`.
63
- */
64
- export declare function migratePending(): Pick<PendingState, 'pending'>;
65
- /**
66
- * Restores only the entries that are actually entries — per entry, so one bad
67
- * record does not take the rest with it. The `mergeDrafts` rule, for the same
68
- * reason: this is what happens when something else was written by a build that
69
- * predates the shape.
70
- */
71
- export declare function mergePending(persistedState: unknown, currentState: PendingState): PendingState;
72
- export declare const usePendingState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<PendingState>, "setState" | "persist"> & {
73
- setState(partial: PendingState | Partial<PendingState> | ((state: PendingState) => PendingState | Partial<PendingState>), replace?: false | undefined): unknown;
74
- setState(state: PendingState | ((state: PendingState) => PendingState), replace: true): unknown;
75
- persist: {
76
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<PendingState, unknown, unknown>>) => void;
77
- clearStorage: () => void;
78
- rehydrate: () => Promise<void> | void;
79
- hasHydrated: () => boolean;
80
- onHydrate: (fn: (state: PendingState) => void) => () => void;
81
- onFinishHydration: (fn: (state: PendingState) => void) => () => void;
82
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<PendingState, unknown, unknown>>;
83
- };
84
- }>;
85
- //# sourceMappingURL=pending-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pending-state.d.ts","sourceRoot":"","sources":["../../../src/lib/workspace/pending-state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAO9E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtC,KAAK,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IACxD,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,IAAI,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnD,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,YAAY,GAClB,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAQ/B;AAID;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,KAAK,CAAC;AAE9B;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AAIjC;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAE9D;AAcD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,YAAY,GACzB,YAAY,CAUd;AAgBD,eAAO,MAAM,eAAe;;;;;;;;;;;;EAgE3B,CAAC"}
@@ -1,155 +0,0 @@
1
- 'use client';
2
- import { _ as _extends } from "@swc/helpers/_/_extends";
3
- import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
4
- import { _ as _to_property_key } from "@swc/helpers/_/_to_property_key";
5
- import { create } from 'zustand';
6
- import { createJSONStorage, persist } from 'zustand/middleware';
7
- import { makeIndexedDbStateStorage } from './idb-state-storage.js';
8
- import { WORKSPACE_DB } from './tabs-state.js';
9
- /**
10
- * ⚠️ **`record` is stripped before persisting.** It is a class instance, and a
11
- * draft-style JSON round trip does not preserve one — it returns as something
12
- * else, silently. So a refresh keeps the *watch* and loses the row,
13
- * which is the documented behaviour: past a refresh, server truth plus an honest
14
- * notice beats a record rebuilt from a blob.
15
- */ export function persistedPending(store) {
16
- const pending = {};
17
- for (const _ref of Object.entries(store.pending)){
18
- const [transactionId, _ref1] = _ref, { record: _dropped } = _ref1, rest = _object_without_properties_loose(_ref1, [
19
- "record"
20
- ]);
21
- pending[transactionId] = rest;
22
- }
23
- return {
24
- pending
25
- };
26
- }
27
- const PENDING_STORE = 'stores';
28
- /**
29
- * How many pending writes are watched at once, oldest evicted first.
30
- *
31
- * The same reasoning as {@link MAX_TABS}: an unbounded set persisted to
32
- * IndexedDB grows without anything ever pruning it, and reconciliation asks the
33
- * tracker once per entry on every reconnect — so the cap is also what keeps that
34
- * fan-out a handful of requests rather than an unbounded one.
35
- *
36
- * An evicted entry is dropped silently. The record is still on the server and
37
- * the list's own query is the fallback; what is lost is only the watching.
38
- */ export const MAX_PENDING = 12;
39
- /**
40
- * Bump when the *shape* of an entry changes, and every persisted pending write
41
- * is discarded on the next load.
42
- *
43
- * Discarding is right here for a reason the other two stores do not share: an
44
- * entry is a claim that something is still in flight, and it stops being true on
45
- * its own. A stale one restored from a previous build watches a transaction that
46
- * settled hours ago, and the reconcile that would correct it is keyed on a shape
47
- * this build may no longer understand.
48
- */ export const PENDING_VERSION = 1;
49
- const emptyPending = {
50
- pending: {}
51
- };
52
- /**
53
- * Discard, never guess — written out rather than left to zustand's default,
54
- * which discards too but logs an error for a decision that was made on purpose.
55
- * Same call as `migrateDrafts` and `migrateTabs`.
56
- */ export function migratePending() {
57
- return emptyPending;
58
- }
59
- /** Whether a restored value is an entry this build can act on. */ function isPendingEntry(value) {
60
- if (value === null || typeof value !== 'object') return false;
61
- const entry = value;
62
- return typeof entry.transactionId === 'string' && typeof entry.entity === 'string' && typeof entry.at === 'string' && (entry.state === 'pending' || entry.state === 'failed');
63
- }
64
- /**
65
- * Restores only the entries that are actually entries — per entry, so one bad
66
- * record does not take the rest with it. The `mergeDrafts` rule, for the same
67
- * reason: this is what happens when something else was written by a build that
68
- * predates the shape.
69
- */ export function mergePending(persistedState, currentState) {
70
- const restored = persistedState == null ? void 0 : persistedState.pending;
71
- if (restored === null || typeof restored !== 'object') return currentState;
72
- const pending = {};
73
- for (const [transactionId, value] of Object.entries(restored)){
74
- if (isPendingEntry(value)) pending[transactionId] = value;
75
- }
76
- return _extends({}, currentState, {
77
- pending
78
- });
79
- }
80
- /** Drops the oldest entries until the set fits, by announcement time. */ function capPending(pending) {
81
- const entries = Object.entries(pending);
82
- if (entries.length <= MAX_PENDING) return pending;
83
- return Object.fromEntries(entries.sort(([, a], [, b])=>a.at.localeCompare(b.at)).slice(entries.length - MAX_PENDING));
84
- }
85
- export const usePendingState = create()(persist((set, get)=>({
86
- pending: {},
87
- began: (transaction)=>set((state)=>({
88
- pending: capPending(_extends({}, state.pending, {
89
- [transaction.transactionId]: _extends({}, transaction, {
90
- state: 'pending'
91
- })
92
- }))
93
- })),
94
- // Reads current state rather than taking it from the caller, so a save
95
- // handler cannot ask about a store snapshot older than its own `await`.
96
- attach: (transactionId, record)=>{
97
- const entry = get().pending[transactionId];
98
- if (entry === undefined) return false;
99
- set((state)=>({
100
- pending: _extends({}, state.pending, {
101
- [transactionId]: _extends({}, entry, {
102
- record
103
- })
104
- })
105
- }));
106
- return true;
107
- },
108
- // Settling drops the entry rather than marking it done: the server's copy
109
- // is the truth now, and the list query that just refetched is showing it.
110
- settle: (transactionId)=>set((state)=>{
111
- if (!(transactionId in state.pending)) return state;
112
- const _state_pending = state.pending, { [transactionId]: _settled } = _state_pending, rest = _object_without_properties_loose(_state_pending, [
113
- _to_property_key(transactionId)
114
- ]);
115
- return {
116
- pending: rest
117
- };
118
- }),
119
- // A failure is *kept*, marked, until someone reads it. Dropping it here
120
- // would un-render the optimistic row and say nothing about why.
121
- fail: (transactionId, reason)=>set((state)=>{
122
- const entry = state.pending[transactionId];
123
- if (entry === undefined) return state;
124
- return {
125
- pending: _extends({}, state.pending, {
126
- [transactionId]: _extends({}, entry, {
127
- state: 'failed',
128
- reason
129
- })
130
- })
131
- };
132
- }),
133
- dismiss: (transactionId)=>set((state)=>{
134
- if (!(transactionId in state.pending)) return state;
135
- const _state_pending = state.pending, { [transactionId]: _dismissed } = _state_pending, rest = _object_without_properties_loose(_state_pending, [
136
- _to_property_key(transactionId)
137
- ]);
138
- return {
139
- pending: rest
140
- };
141
- })
142
- }), {
143
- // Replaced with a scoped name before rehydrating, exactly as the tab and
144
- // draft stores are. This literal is only what an unscoped store would
145
- // write, and nothing rehydrates without passing through that call.
146
- name: 'pending',
147
- version: PENDING_VERSION,
148
- migrate: migratePending,
149
- merge: mergePending,
150
- storage: createJSONStorage(()=>makeIndexedDbStateStorage(WORKSPACE_DB, PENDING_STORE)),
151
- partialize: persistedPending,
152
- skipHydration: true
153
- }));
154
-
155
- //# sourceMappingURL=pending-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/lib/workspace/pending-state.ts"],"sourcesContent":["'use client';\n\nimport type { PendingEntry, PendingTransaction } from '@entifix/transactions';\nimport { create } from 'zustand';\nimport { createJSONStorage, persist } from 'zustand/middleware';\n\nimport { makeIndexedDbStateStorage } from './idb-state-storage.js';\nimport { WORKSPACE_DB } from './tabs-state.js';\n\n/**\n * Writes the browser started and the server has not finished, keyed by\n * transaction id.\n *\n * ⚠️ **This is not workspace state, and the distinction is load-bearing.** Tabs\n * and drafts belong to the workspace and are scoped by `WorkspaceShell`; a\n * pending write is not, because a create happens at `/<basePath>/new` on the\n * plain route, outside any `WorkspaceShell` (a generated list still uses plain\n * `href`s — a known residual of the address grammar). A store mounted inside\n * the workspace would\n * be written to by nothing, or — worse — written to *before* `persist.setOptions`\n * had scoped it, which is the unscoped cross-account restore that keying a\n * draft per principal exists to prevent. So `PendingTransactionsProvider` sits at the authenticated layout\n * instead, above both.\n *\n * It shares the workspace's IndexedDB database because it is the same browser\n * profile and the same scope key, not because it is the same concern.\n */\nexport interface PendingState {\n pending: Record<string, PendingEntry>;\n began(transaction: PendingTransaction): void;\n attach(transactionId: string, record: unknown): boolean;\n settle(transactionId: string): void;\n fail(transactionId: string, reason?: string): void;\n dismiss(transactionId: string): void;\n}\n\n/**\n * ⚠️ **`record` is stripped before persisting.** It is a class instance, and a\n * draft-style JSON round trip does not preserve one — it returns as something\n * else, silently. So a refresh keeps the *watch* and loses the row,\n * which is the documented behaviour: past a refresh, server truth plus an honest\n * notice beats a record rebuilt from a blob.\n */\nexport function persistedPending(\n store: PendingState,\n): Pick<PendingState, 'pending'> {\n const pending: Record<string, PendingEntry> = {};\n for (const [transactionId, { record: _dropped, ...rest }] of Object.entries(\n store.pending,\n )) {\n pending[transactionId] = rest;\n }\n return { pending };\n}\n\nconst PENDING_STORE = 'stores';\n\n/**\n * How many pending writes are watched at once, oldest evicted first.\n *\n * The same reasoning as {@link MAX_TABS}: an unbounded set persisted to\n * IndexedDB grows without anything ever pruning it, and reconciliation asks the\n * tracker once per entry on every reconnect — so the cap is also what keeps that\n * fan-out a handful of requests rather than an unbounded one.\n *\n * An evicted entry is dropped silently. The record is still on the server and\n * the list's own query is the fallback; what is lost is only the watching.\n */\nexport const MAX_PENDING = 12;\n\n/**\n * Bump when the *shape* of an entry changes, and every persisted pending write\n * is discarded on the next load.\n *\n * Discarding is right here for a reason the other two stores do not share: an\n * entry is a claim that something is still in flight, and it stops being true on\n * its own. A stale one restored from a previous build watches a transaction that\n * settled hours ago, and the reconcile that would correct it is keyed on a shape\n * this build may no longer understand.\n */\nexport const PENDING_VERSION = 1;\n\nconst emptyPending: Pick<PendingState, 'pending'> = { pending: {} };\n\n/**\n * Discard, never guess — written out rather than left to zustand's default,\n * which discards too but logs an error for a decision that was made on purpose.\n * Same call as `migrateDrafts` and `migrateTabs`.\n */\nexport function migratePending(): Pick<PendingState, 'pending'> {\n return emptyPending;\n}\n\n/** Whether a restored value is an entry this build can act on. */\nfunction isPendingEntry(value: unknown): value is PendingEntry {\n if (value === null || typeof value !== 'object') return false;\n const entry = value as Partial<PendingEntry>;\n return (\n typeof entry.transactionId === 'string' &&\n typeof entry.entity === 'string' &&\n typeof entry.at === 'string' &&\n (entry.state === 'pending' || entry.state === 'failed')\n );\n}\n\n/**\n * Restores only the entries that are actually entries — per entry, so one bad\n * record does not take the rest with it. The `mergeDrafts` rule, for the same\n * reason: this is what happens when something else was written by a build that\n * predates the shape.\n */\nexport function mergePending(\n persistedState: unknown,\n currentState: PendingState,\n): PendingState {\n const restored = (persistedState as Partial<PendingState> | undefined)\n ?.pending;\n if (restored === null || typeof restored !== 'object') return currentState;\n\n const pending: Record<string, PendingEntry> = {};\n for (const [transactionId, value] of Object.entries(restored)) {\n if (isPendingEntry(value)) pending[transactionId] = value;\n }\n return { ...currentState, pending };\n}\n\n/** Drops the oldest entries until the set fits, by announcement time. */\nfunction capPending(\n pending: Record<string, PendingEntry>,\n): Record<string, PendingEntry> {\n const entries = Object.entries(pending);\n if (entries.length <= MAX_PENDING) return pending;\n\n return Object.fromEntries(\n entries\n .sort(([, a], [, b]) => a.at.localeCompare(b.at))\n .slice(entries.length - MAX_PENDING),\n );\n}\n\nexport const usePendingState = create<PendingState>()(\n persist(\n (set, get) => ({\n pending: {},\n began: transaction =>\n set(state => ({\n pending: capPending({\n ...state.pending,\n [transaction.transactionId]: { ...transaction, state: 'pending' },\n }),\n })),\n // Reads current state rather than taking it from the caller, so a save\n // handler cannot ask about a store snapshot older than its own `await`.\n attach: (transactionId, record) => {\n const entry = get().pending[transactionId];\n if (entry === undefined) return false;\n set(state => ({\n pending: { ...state.pending, [transactionId]: { ...entry, record } },\n }));\n return true;\n },\n // Settling drops the entry rather than marking it done: the server's copy\n // is the truth now, and the list query that just refetched is showing it.\n settle: transactionId =>\n set(state => {\n if (!(transactionId in state.pending)) return state;\n const { [transactionId]: _settled, ...rest } = state.pending;\n return { pending: rest };\n }),\n // A failure is *kept*, marked, until someone reads it. Dropping it here\n // would un-render the optimistic row and say nothing about why.\n fail: (transactionId, reason) =>\n set(state => {\n const entry = state.pending[transactionId];\n if (entry === undefined) return state;\n return {\n pending: {\n ...state.pending,\n [transactionId]: { ...entry, state: 'failed', reason },\n },\n };\n }),\n dismiss: transactionId =>\n set(state => {\n if (!(transactionId in state.pending)) return state;\n const { [transactionId]: _dismissed, ...rest } = state.pending;\n return { pending: rest };\n }),\n }),\n {\n // Replaced with a scoped name before rehydrating, exactly as the tab and\n // draft stores are. This literal is only what an unscoped store would\n // write, and nothing rehydrates without passing through that call.\n name: 'pending',\n version: PENDING_VERSION,\n migrate: migratePending,\n merge: mergePending,\n storage: createJSONStorage(() =>\n makeIndexedDbStateStorage(WORKSPACE_DB, PENDING_STORE),\n ),\n partialize: persistedPending,\n skipHydration: true,\n },\n ),\n);\n"],"names":["create","createJSONStorage","persist","makeIndexedDbStateStorage","WORKSPACE_DB","persistedPending","store","pending","Object","entries","transactionId","record","_dropped","rest","PENDING_STORE","MAX_PENDING","PENDING_VERSION","emptyPending","migratePending","isPendingEntry","value","entry","entity","at","state","mergePending","persistedState","currentState","restored","capPending","length","fromEntries","sort","a","b","localeCompare","slice","usePendingState","set","get","began","transaction","attach","undefined","settle","_settled","fail","reason","dismiss","_dismissed","name","version","migrate","merge","storage","partialize","skipHydration"],"mappings":"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"}
@@ -1,44 +0,0 @@
1
- import type { PendingEntry, PendingTransactionStore } from '@entifix/transactions';
2
- import { type ReactNode } from 'react';
3
- /** Test seam: forget that any scope was hydrated. */
4
- export declare function resetPendingHydration(): void;
5
- export interface PendingTransactionsProviderProps {
6
- /**
7
- * Who these pending writes belong to — the same `workspaceScopeKey({ userId,
8
- * organizationId })` the workspace is scoped with.
9
- *
10
- * Required for the reason `WorkspaceShellProps.scope` is: IndexedDB is a
11
- * property of the browser profile, so a host that forgets one hands the next
12
- * account to sign in on that machine the previous account's in-flight writes.
13
- */
14
- scope: string;
15
- children: ReactNode;
16
- }
17
- /**
18
- * Makes the pending set available to everything below it.
19
- *
20
- * ⚠️ **Mount this above the plain routes, not only the workspace.** A create is
21
- * `/<basePath>/new` on the route host, so a provider inside `WorkspaceShell`
22
- * would never see the only kind of write that is transactional today.
23
- */
24
- export declare function PendingTransactionsProvider({ scope, children, }: PendingTransactionsProviderProps): import("react").JSX.Element;
25
- /** The pending set, or a store that watches nothing outside a provider. */
26
- export declare function usePendingTransactions(): PendingTransactionStore;
27
- /** The entries for one entity, which is what a list renders a notice from. */
28
- export declare function pendingFor(store: PendingTransactionStore, entity: string): readonly PendingEntry[];
29
- /**
30
- * The records a list should show that its own query cannot yet return.
31
- *
32
- * ⚠️ **Why this is not a cache patch.** Writing the row into the TanStack cache
33
- * looks simpler and does not survive: the list refetches on mount — which is
34
- * exactly when the operator arrives, having just been navigated here — and the
35
- * server legitimately does not have the record yet, so the refetch replaces the
36
- * patched page and the row disappears. The pending set outlives every refetch,
37
- * so merging at render time is the only version that holds until the write
38
- * actually settles.
39
- *
40
- * A failed entry contributes no row: the write did not happen, and the notice
41
- * beside the table is what says so.
42
- */
43
- export declare function pendingRecordsFor<TRecord>(store: PendingTransactionStore, entity: string): TRecord[];
44
- //# sourceMappingURL=pending-transactions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pending-transactions.d.ts","sourceRoot":"","sources":["../../../src/lib/workspace/pending-transactions.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAEL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AAiCf,qDAAqD;AACrD,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED,MAAM,WAAW,gCAAgC;IAC/C;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,QAAQ,GACT,EAAE,gCAAgC,+BAgDlC;AAED,2EAA2E;AAC3E,wBAAgB,sBAAsB,IAAI,uBAAuB,CAEhE;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,CACxB,KAAK,EAAE,uBAAuB,EAC9B,MAAM,EAAE,MAAM,GACb,SAAS,YAAY,EAAE,CAEzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EACvC,KAAK,EAAE,uBAAuB,EAC9B,MAAM,EAAE,MAAM,GACb,OAAO,EAAE,CAKX"}