@entifix/next-shell 0.13.0 → 0.15.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 +1 -25
- package/dist/lib/config/service-proxy-route.js.map +1 -1
- package/dist/lib/crud/entity-crud-form.d.ts +5 -3
- package/dist/lib/crud/entity-crud-form.d.ts.map +1 -1
- package/dist/lib/crud/entity-crud-form.js +2 -1
- package/dist/lib/crud/entity-crud-form.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 +154 -114
- package/dist/lib/crud/make-entity-crud.js.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts +13 -1
- package/dist/lib/crud/make-entity-crud.types.d.ts.map +1 -1
- package/dist/lib/crud/make-entity-crud.types.js.map +1 -1
- package/dist/lib/session/bearer.d.ts +1 -1
- package/dist/lib/session/bearer.js +1 -1
- package/dist/lib/session/bearer.js.map +1 -1
- package/dist/lib/workspace/index.d.ts +1 -2
- package/dist/lib/workspace/index.d.ts.map +1 -1
- package/dist/lib/workspace/index.js +1 -2
- package/dist/lib/workspace/index.js.map +1 -1
- package/dist/lib/workspace/pending-flows.d.ts +48 -0
- package/dist/lib/workspace/pending-flows.d.ts.map +1 -0
- package/dist/lib/workspace/pending-flows.js +60 -0
- package/dist/lib/workspace/pending-flows.js.map +1 -0
- package/package.json +11 -11
- 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,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":"AAAA;;;;AAGA,SAASA,MAAM,QAAQ,UAAU;AACjC,SAASC,iBAAiB,EAAEC,OAAO,QAAQ,qBAAqB;AAEhE,SAASC,yBAAyB,QAAQ,yBAAyB;AACnE,SAASC,YAAY,QAAQ,kBAAkB;AA6B/C;;;;;;CAMC,GACD,OAAO,SAASC,iBACdC,KAAmB;IAEnB,MAAMC,UAAwC,CAAC;IAC/C,KAAK,MAAM,QAAkDC,OAAOC,OAAO,CACzEH,MAAMC,OAAO,EACZ;cAFQ,CAACG,qBAA6C,SAA9B,EAAEC,QAAQC,QAAQ,EAAW,UAANC;;;QAGhDN,OAAO,CA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,iBAAiBc,MAAMjB,OAAO,AAAD,GAAI,OAAOiB;gBAC9C,MAAiDA,iBAAAA,MAAMjB,OAAO,EAAxD,EAAE,CAACG,cAAc,EAAEuC,UAAU,EAAW,GAAGzB,gBAATX,wCAASW;qCAAxCd;;gBACT,OAAO;oBAAEH,SAASM;gBAAK;YACzB;IACJ,CAAA,GACA;IACE,yEAAyE;IACzE,sEAAsE;IACtE,mEAAmE;IACnEqC,MAAM;IACNC,SAASnC;IACToC,SAASlC;IACTmC,OAAO5B;IACP6B,SAASrD,kBAAkB,IACzBE,0BAA0BC,cAAcU;IAE1CyC,YAAYlD;IACZmD,eAAe;AACjB,IAEF"}
|
|
@@ -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"}
|
|
@@ -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,Q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