@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.
- package/dist/lib/config/service-proxy-route.d.ts +4 -7
- package/dist/lib/config/service-proxy-route.d.ts.map +1 -1
- package/dist/lib/config/service-proxy-route.js +0 -24
- package/dist/lib/config/service-proxy-route.js.map +1 -1
- package/dist/lib/crud/index.d.ts +0 -1
- package/dist/lib/crud/index.d.ts.map +1 -1
- package/dist/lib/crud/index.js +0 -1
- package/dist/lib/crud/index.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.d.ts +7 -12
- package/dist/lib/crud/make-entity-crud.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.js +33 -64
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/workspace/index.d.ts +0 -2
- package/dist/lib/workspace/index.d.ts.map +1 -1
- package/dist/lib/workspace/index.js +0 -2
- package/dist/lib/workspace/index.js.map +1 -1
- package/dist/lib/workspace/pending-flows.d.ts +2 -2
- package/dist/lib/workspace/pending-flows.js.map +1 -1
- package/package.json +9 -9
- package/dist/lib/crud/hand-off-write.d.ts +0 -35
- package/dist/lib/crud/hand-off-write.d.ts.map +0 -1
- package/dist/lib/crud/hand-off-write.js +0 -27
- package/dist/lib/crud/hand-off-write.js.map +0 -1
- package/dist/lib/crud/pending-notice.d.ts +0 -31
- package/dist/lib/crud/pending-notice.d.ts.map +0 -1
- package/dist/lib/crud/pending-notice.js +0 -72
- package/dist/lib/crud/pending-notice.js.map +0 -1
- package/dist/lib/workspace/pending-state.d.ts +0 -85
- package/dist/lib/workspace/pending-state.d.ts.map +0 -1
- package/dist/lib/workspace/pending-state.js +0 -155
- package/dist/lib/workspace/pending-state.js.map +0 -1
- package/dist/lib/workspace/pending-transactions.d.ts +0 -44
- package/dist/lib/workspace/pending-transactions.d.ts.map +0 -1
- package/dist/lib/workspace/pending-transactions.js +0 -114
- package/dist/lib/workspace/pending-transactions.js.map +0 -1
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
3
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
-
import { NoopTransactionSink } from '@entifix/transactions';
|
|
5
|
-
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
6
|
-
import { usePendingState } from './pending-state.js';
|
|
7
|
-
/**
|
|
8
|
-
* What a caller outside a mounted provider gets: a store that watches nothing.
|
|
9
|
-
*
|
|
10
|
-
* A create on a page with no provider still works exactly as it does today — it
|
|
11
|
-
* simply gets no optimistic treatment. That is the honest boundary, and it is
|
|
12
|
-
* what keeps `began` from ever writing into an unscoped store.
|
|
13
|
-
*/ const noopStore = _extends({}, NoopTransactionSink, {
|
|
14
|
-
entries: [],
|
|
15
|
-
attach: ()=>false,
|
|
16
|
-
settle: ()=>undefined,
|
|
17
|
-
fail: ()=>undefined,
|
|
18
|
-
dismiss: ()=>undefined
|
|
19
|
-
});
|
|
20
|
-
const PendingTransactionsContext = /*#__PURE__*/ createContext(noopStore);
|
|
21
|
-
/**
|
|
22
|
-
* Which scope the module-level store has already been read for.
|
|
23
|
-
*
|
|
24
|
-
* Module-level because the store it guards is: `usePendingState` is a singleton,
|
|
25
|
-
* so "has this been hydrated" is a fact about the module and not about any one
|
|
26
|
-
* component instance. A ref would reset on remount, which is the case this
|
|
27
|
-
* exists to survive.
|
|
28
|
-
*/ let hydratedScope;
|
|
29
|
-
/** Test seam: forget that any scope was hydrated. */ export function resetPendingHydration() {
|
|
30
|
-
hydratedScope = undefined;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Makes the pending set available to everything below it.
|
|
34
|
-
*
|
|
35
|
-
* ⚠️ **Mount this above the plain routes, not only the workspace.** A create is
|
|
36
|
-
* `/<basePath>/new` on the route host, so a provider inside `WorkspaceShell`
|
|
37
|
-
* would never see the only kind of write that is transactional today.
|
|
38
|
-
*/ export function PendingTransactionsProvider({ scope, children }) {
|
|
39
|
-
const pending = usePendingState((state)=>state.pending);
|
|
40
|
-
const began = usePendingState((state)=>state.began);
|
|
41
|
-
const attach = usePendingState((state)=>state.attach);
|
|
42
|
-
const settle = usePendingState((state)=>state.settle);
|
|
43
|
-
const fail = usePendingState((state)=>state.fail);
|
|
44
|
-
const dismiss = usePendingState((state)=>state.dismiss);
|
|
45
|
-
// ⚠️ The scope is applied *before* the read, never after: the storage key is
|
|
46
|
-
// what decides whose in-flight writes come back, so setting it late would
|
|
47
|
-
// restore the unscoped set first and only then start writing to the right key.
|
|
48
|
-
//
|
|
49
|
-
// ⚠️ **And the read happens once per scope, not once per mount.** Measured on
|
|
50
|
-
// the live fleet: `rehydrate()` *replaces* in-memory state with what is on
|
|
51
|
-
// disk, and the disk write that follows a `began` is asynchronous — so a
|
|
52
|
-
// second call (a remount, or React's development double-invoke) lands between
|
|
53
|
-
// the two and wipes the very entry that was just recorded. The symptom is a
|
|
54
|
-
// notice that appears and vanishes, with the write still in flight.
|
|
55
|
-
//
|
|
56
|
-
// Unlike `WorkspaceShell` there is no hydration *gate*, deliberately: this
|
|
57
|
-
// provider wraps every authenticated page, so holding render back on an
|
|
58
|
-
// IndexedDB read would blank the whole app on each load. A tab set has to
|
|
59
|
-
// gate; a pending set has nothing to be wrong about while it is still empty.
|
|
60
|
-
useEffect(()=>{
|
|
61
|
-
if (hydratedScope === scope) return;
|
|
62
|
-
hydratedScope = scope;
|
|
63
|
-
usePendingState.persist.setOptions({
|
|
64
|
-
name: `pending:${scope}`
|
|
65
|
-
});
|
|
66
|
-
// `rehydrate()` is typed `void | Promise<void>`, hence the wrap.
|
|
67
|
-
void Promise.resolve(usePendingState.persist.rehydrate());
|
|
68
|
-
}, [
|
|
69
|
-
scope
|
|
70
|
-
]);
|
|
71
|
-
const store = useMemo(()=>({
|
|
72
|
-
entries: Object.values(pending),
|
|
73
|
-
began,
|
|
74
|
-
attach,
|
|
75
|
-
settle,
|
|
76
|
-
fail,
|
|
77
|
-
dismiss
|
|
78
|
-
}), [
|
|
79
|
-
pending,
|
|
80
|
-
began,
|
|
81
|
-
attach,
|
|
82
|
-
settle,
|
|
83
|
-
fail,
|
|
84
|
-
dismiss
|
|
85
|
-
]);
|
|
86
|
-
return /*#__PURE__*/ _jsx(PendingTransactionsContext, {
|
|
87
|
-
value: store,
|
|
88
|
-
children: children
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/** The pending set, or a store that watches nothing outside a provider. */ export function usePendingTransactions() {
|
|
92
|
-
return useContext(PendingTransactionsContext);
|
|
93
|
-
}
|
|
94
|
-
/** The entries for one entity, which is what a list renders a notice from. */ export function pendingFor(store, entity) {
|
|
95
|
-
return store.entries.filter((entry)=>entry.entity === entity);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The records a list should show that its own query cannot yet return.
|
|
99
|
-
*
|
|
100
|
-
* ⚠️ **Why this is not a cache patch.** Writing the row into the TanStack cache
|
|
101
|
-
* looks simpler and does not survive: the list refetches on mount — which is
|
|
102
|
-
* exactly when the operator arrives, having just been navigated here — and the
|
|
103
|
-
* server legitimately does not have the record yet, so the refetch replaces the
|
|
104
|
-
* patched page and the row disappears. The pending set outlives every refetch,
|
|
105
|
-
* so merging at render time is the only version that holds until the write
|
|
106
|
-
* actually settles.
|
|
107
|
-
*
|
|
108
|
-
* A failed entry contributes no row: the write did not happen, and the notice
|
|
109
|
-
* beside the table is what says so.
|
|
110
|
-
*/ export function pendingRecordsFor(store, entity) {
|
|
111
|
-
return store.entries.filter((entry)=>entry.entity === entity && entry.state === 'pending').map((entry)=>entry.record).filter((record)=>record !== undefined);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=pending-transactions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/workspace/pending-transactions.tsx"],"sourcesContent":["'use client';\n\nimport type {\n PendingEntry,\n PendingTransactionStore,\n} from '@entifix/transactions';\nimport { NoopTransactionSink } from '@entifix/transactions';\nimport {\n createContext,\n type ReactNode,\n useContext,\n useEffect,\n useMemo,\n} from 'react';\n\nimport { usePendingState } from './pending-state.js';\n\n/**\n * What a caller outside a mounted provider gets: a store that watches nothing.\n *\n * A create on a page with no provider still works exactly as it does today — it\n * simply gets no optimistic treatment. That is the honest boundary, and it is\n * what keeps `began` from ever writing into an unscoped store.\n */\nconst noopStore: PendingTransactionStore = {\n ...NoopTransactionSink,\n entries: [],\n attach: () => false,\n settle: () => undefined,\n fail: () => undefined,\n dismiss: () => undefined,\n};\n\nconst PendingTransactionsContext =\n createContext<PendingTransactionStore>(noopStore);\n\n/**\n * Which scope the module-level store has already been read for.\n *\n * Module-level because the store it guards is: `usePendingState` is a singleton,\n * so \"has this been hydrated\" is a fact about the module and not about any one\n * component instance. A ref would reset on remount, which is the case this\n * exists to survive.\n */\nlet hydratedScope: string | undefined;\n\n/** Test seam: forget that any scope was hydrated. */\nexport function resetPendingHydration(): void {\n hydratedScope = undefined;\n}\n\nexport interface PendingTransactionsProviderProps {\n /**\n * Who these pending writes belong to — the same `workspaceScopeKey({ userId,\n * organizationId })` the workspace is scoped with.\n *\n * Required for the reason `WorkspaceShellProps.scope` is: IndexedDB is a\n * property of the browser profile, so a host that forgets one hands the next\n * account to sign in on that machine the previous account's in-flight writes.\n */\n scope: string;\n children: ReactNode;\n}\n\n/**\n * Makes the pending set available to everything below it.\n *\n * ⚠️ **Mount this above the plain routes, not only the workspace.** A create is\n * `/<basePath>/new` on the route host, so a provider inside `WorkspaceShell`\n * would never see the only kind of write that is transactional today.\n */\nexport function PendingTransactionsProvider({\n scope,\n children,\n}: PendingTransactionsProviderProps) {\n const pending = usePendingState(state => state.pending);\n const began = usePendingState(state => state.began);\n const attach = usePendingState(state => state.attach);\n const settle = usePendingState(state => state.settle);\n const fail = usePendingState(state => state.fail);\n const dismiss = usePendingState(state => state.dismiss);\n\n // ⚠️ The scope is applied *before* the read, never after: the storage key is\n // what decides whose in-flight writes come back, so setting it late would\n // restore the unscoped set first and only then start writing to the right key.\n //\n // ⚠️ **And the read happens once per scope, not once per mount.** Measured on\n // the live fleet: `rehydrate()` *replaces* in-memory state with what is on\n // disk, and the disk write that follows a `began` is asynchronous — so a\n // second call (a remount, or React's development double-invoke) lands between\n // the two and wipes the very entry that was just recorded. The symptom is a\n // notice that appears and vanishes, with the write still in flight.\n //\n // Unlike `WorkspaceShell` there is no hydration *gate*, deliberately: this\n // provider wraps every authenticated page, so holding render back on an\n // IndexedDB read would blank the whole app on each load. A tab set has to\n // gate; a pending set has nothing to be wrong about while it is still empty.\n useEffect(() => {\n if (hydratedScope === scope) return;\n hydratedScope = scope;\n usePendingState.persist.setOptions({ name: `pending:${scope}` });\n // `rehydrate()` is typed `void | Promise<void>`, hence the wrap.\n void Promise.resolve(usePendingState.persist.rehydrate());\n }, [scope]);\n\n const store = useMemo<PendingTransactionStore>(\n () => ({\n entries: Object.values(pending),\n began,\n attach,\n settle,\n fail,\n dismiss,\n }),\n [pending, began, attach, settle, fail, dismiss],\n );\n\n return (\n <PendingTransactionsContext value={store}>\n {children}\n </PendingTransactionsContext>\n );\n}\n\n/** The pending set, or a store that watches nothing outside a provider. */\nexport function usePendingTransactions(): PendingTransactionStore {\n return useContext(PendingTransactionsContext);\n}\n\n/** The entries for one entity, which is what a list renders a notice from. */\nexport function pendingFor(\n store: PendingTransactionStore,\n entity: string,\n): readonly PendingEntry[] {\n return store.entries.filter(entry => entry.entity === entity);\n}\n\n/**\n * The records a list should show that its own query cannot yet return.\n *\n * ⚠️ **Why this is not a cache patch.** Writing the row into the TanStack cache\n * looks simpler and does not survive: the list refetches on mount — which is\n * exactly when the operator arrives, having just been navigated here — and the\n * server legitimately does not have the record yet, so the refetch replaces the\n * patched page and the row disappears. The pending set outlives every refetch,\n * so merging at render time is the only version that holds until the write\n * actually settles.\n *\n * A failed entry contributes no row: the write did not happen, and the notice\n * beside the table is what says so.\n */\nexport function pendingRecordsFor<TRecord>(\n store: PendingTransactionStore,\n entity: string,\n): TRecord[] {\n return store.entries\n .filter(entry => entry.entity === entity && entry.state === 'pending')\n .map(entry => entry.record)\n .filter((record): record is TRecord => record !== undefined);\n}\n"],"names":["NoopTransactionSink","createContext","useContext","useEffect","useMemo","usePendingState","noopStore","entries","attach","settle","undefined","fail","dismiss","PendingTransactionsContext","hydratedScope","resetPendingHydration","PendingTransactionsProvider","scope","children","pending","state","began","persist","setOptions","name","Promise","resolve","rehydrate","store","Object","values","value","usePendingTransactions","pendingFor","entity","filter","entry","pendingRecordsFor","map","record"],"mappings":"AAAA;;;AAMA,SAASA,mBAAmB,QAAQ,wBAAwB;AAC5D,SACEC,aAAa,EAEbC,UAAU,EACVC,SAAS,EACTC,OAAO,QACF,QAAQ;AAEf,SAASC,eAAe,QAAQ,qBAAqB;AAErD;;;;;;CAMC,GACD,MAAMC,YAAqC,aACtCN;IACHO,SAAS,EAAE;IACXC,QAAQ,IAAM;IACdC,QAAQ,IAAMC;IACdC,MAAM,IAAMD;IACZE,SAAS,IAAMF;;AAGjB,MAAMG,2CACJZ,cAAuCK;AAEzC;;;;;;;CAOC,GACD,IAAIQ;AAEJ,mDAAmD,GACnD,OAAO,SAASC;IACdD,gBAAgBJ;AAClB;AAeA;;;;;;CAMC,GACD,OAAO,SAASM,4BAA4B,EAC1CC,KAAK,EACLC,QAAQ,EACyB;IACjC,MAAMC,UAAUd,gBAAgBe,CAAAA,QAASA,MAAMD,OAAO;IACtD,MAAME,QAAQhB,gBAAgBe,CAAAA,QAASA,MAAMC,KAAK;IAClD,MAAMb,SAASH,gBAAgBe,CAAAA,QAASA,MAAMZ,MAAM;IACpD,MAAMC,SAASJ,gBAAgBe,CAAAA,QAASA,MAAMX,MAAM;IACpD,MAAME,OAAON,gBAAgBe,CAAAA,QAASA,MAAMT,IAAI;IAChD,MAAMC,UAAUP,gBAAgBe,CAAAA,QAASA,MAAMR,OAAO;IAEtD,6EAA6E;IAC7E,0EAA0E;IAC1E,+EAA+E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