@powerhousedao/reactor-browser 6.2.3-dev.9 → 6.2.3-dev.90

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 (101) hide show
  1. package/dist/{attachment-service-D3EhiAJ7.d.ts → attachment-service-10Qn5nIw.d.ts} +766 -108
  2. package/dist/attachment-service-10Qn5nIw.d.ts.map +1 -0
  3. package/dist/auth-DzIYxeEJ.d.ts +32 -0
  4. package/dist/auth-DzIYxeEJ.d.ts.map +1 -0
  5. package/dist/{client-DjK30EQ-.js → client-BFnMV-EO.js} +39 -22
  6. package/dist/client-BFnMV-EO.js.map +1 -0
  7. package/dist/{client-D66jVnot.js → client-BNMyQ_Z2.js} +372 -33
  8. package/dist/client-BNMyQ_Z2.js.map +1 -0
  9. package/dist/{client-BIHN_UyR.d.ts → client-C-NgSjoc.d.ts} +4 -3
  10. package/dist/client-C-NgSjoc.d.ts.map +1 -0
  11. package/dist/dispatch-Cylwl2Dk.js +1173 -0
  12. package/dist/dispatch-Cylwl2Dk.js.map +1 -0
  13. package/dist/document-by-id-DdvqanGR.js +16 -0
  14. package/dist/document-by-id-DdvqanGR.js.map +1 -0
  15. package/dist/document-model-modules-ChmfyIxT.js +644 -0
  16. package/dist/document-model-modules-ChmfyIxT.js.map +1 -0
  17. package/dist/document-operations-o9cfLoeV.js +4662 -0
  18. package/dist/document-operations-o9cfLoeV.js.map +1 -0
  19. package/dist/global-bbfp3_1x.d.ts +649 -0
  20. package/dist/global-bbfp3_1x.d.ts.map +1 -0
  21. package/dist/{index-B33TKEqp.d.ts → index-Bfr_cWdi.d.ts} +31 -100
  22. package/dist/index-Bfr_cWdi.d.ts.map +1 -0
  23. package/dist/{index-BIVDXw3K.d.ts → index-rtDmzViP.d.ts} +3 -3
  24. package/dist/index-rtDmzViP.d.ts.map +1 -0
  25. package/dist/index.d.ts +837 -411
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +851 -129
  28. package/dist/index.js.map +1 -1
  29. package/dist/inspector-proxy-DODqs15F.d.ts +25 -0
  30. package/dist/inspector-proxy-DODqs15F.d.ts.map +1 -0
  31. package/dist/make-ph-event-functions-B5GU5xcR.js +180 -0
  32. package/dist/make-ph-event-functions-B5GU5xcR.js.map +1 -0
  33. package/dist/{pglite-CntadC_p-9NDG14dS.d.ts → pglite-CntadC_p-DTkdF8sr.d.ts} +11 -33
  34. package/dist/pglite-CntadC_p-DTkdF8sr.d.ts.map +1 -0
  35. package/dist/{relational-D1RB45sA.js → relational-DZuyKp2y.js} +66 -5
  36. package/dist/relational-DZuyKp2y.js.map +1 -0
  37. package/dist/{renown-rqK8sokh.js → renown-B3MUaiq7.js} +61 -31
  38. package/dist/renown-B3MUaiq7.js.map +1 -0
  39. package/dist/renown-CBoTdGrg.js +394 -0
  40. package/dist/renown-CBoTdGrg.js.map +1 -0
  41. package/dist/{types-Dcv1ZLoW.d.ts → schema-Bn6L3QR1.d.ts} +324 -64
  42. package/dist/schema-Bn6L3QR1.d.ts.map +1 -0
  43. package/dist/src/ai/index.d.ts +276 -75
  44. package/dist/src/ai/index.d.ts.map +1 -1
  45. package/dist/src/ai/index.js +733 -172
  46. package/dist/src/ai/index.js.map +1 -1
  47. package/dist/src/analytics/index.d.ts +36 -44
  48. package/dist/src/analytics/index.d.ts.map +1 -1
  49. package/dist/src/analytics/index.js +4 -4
  50. package/dist/src/analytics/index.js.map +1 -1
  51. package/dist/src/document-model.d.ts +3 -4
  52. package/dist/src/document-model.d.ts.map +1 -1
  53. package/dist/src/document-model.js.map +1 -1
  54. package/dist/src/graphql/client.d.ts +4 -3
  55. package/dist/src/graphql/client.js +1 -1
  56. package/dist/src/graphql-client/entry.d.ts +6 -4
  57. package/dist/src/graphql-client/entry.js +4 -4
  58. package/dist/src/relational/index.d.ts +15 -9
  59. package/dist/src/relational/index.d.ts.map +1 -1
  60. package/dist/src/relational/index.js +1 -1
  61. package/dist/src/renown/index.d.ts +3 -2
  62. package/dist/src/renown/index.js +3 -3
  63. package/dist/src/rpc/index.d.ts +217 -140
  64. package/dist/src/rpc/index.d.ts.map +1 -1
  65. package/dist/src/rpc/index.js +600 -623
  66. package/dist/src/rpc/index.js.map +1 -1
  67. package/dist/{store-BJYcr_FL.js → store-DInXcjal.js} +1 -1
  68. package/dist/{store-BJYcr_FL.js.map → store-DInXcjal.js.map} +1 -1
  69. package/dist/{switchboard-CaXQ4-5Q.js → switchboard-B640iT1L.js} +61 -11
  70. package/dist/switchboard-B640iT1L.js.map +1 -0
  71. package/dist/{types-6vDzbRRS.d.ts → types-520nWrB3.d.ts} +2 -2
  72. package/dist/types-520nWrB3.d.ts.map +1 -0
  73. package/dist/types-CT44EMmw.d.ts +59 -0
  74. package/dist/types-CT44EMmw.d.ts.map +1 -0
  75. package/package.json +24 -23
  76. package/dist/attachment-service-D3EhiAJ7.d.ts.map +0 -1
  77. package/dist/client-BIHN_UyR.d.ts.map +0 -1
  78. package/dist/client-D66jVnot.js.map +0 -1
  79. package/dist/client-DjK30EQ-.js.map +0 -1
  80. package/dist/document-by-id-B4FIzG1w.js +0 -519
  81. package/dist/document-by-id-B4FIzG1w.js.map +0 -1
  82. package/dist/document-model-modules-bTP87nyr.js +0 -419
  83. package/dist/document-model-modules-bTP87nyr.js.map +0 -1
  84. package/dist/document-operations-WeE6wIDt.js +0 -2603
  85. package/dist/document-operations-WeE6wIDt.js.map +0 -1
  86. package/dist/global-OuINvEGT.d.ts +0 -401
  87. package/dist/global-OuINvEGT.d.ts.map +0 -1
  88. package/dist/index-B33TKEqp.d.ts.map +0 -1
  89. package/dist/index-BIVDXw3K.d.ts.map +0 -1
  90. package/dist/inspector-proxy-6h5VKAwt.d.ts +0 -257
  91. package/dist/inspector-proxy-6h5VKAwt.d.ts.map +0 -1
  92. package/dist/make-ph-event-functions-DBq3iWYn.js +0 -53
  93. package/dist/make-ph-event-functions-DBq3iWYn.js.map +0 -1
  94. package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +0 -1
  95. package/dist/relational-D1RB45sA.js.map +0 -1
  96. package/dist/renown-BHxwP7xU.js +0 -97
  97. package/dist/renown-BHxwP7xU.js.map +0 -1
  98. package/dist/renown-rqK8sokh.js.map +0 -1
  99. package/dist/switchboard-CaXQ4-5Q.js.map +0 -1
  100. package/dist/types-6vDzbRRS.d.ts.map +0 -1
  101. package/dist/types-Dcv1ZLoW.d.ts.map +0 -1
@@ -0,0 +1,25 @@
1
+ import { IInspector, IInspectorAdmin, IReactorDbQuery } from "@powerhousedao/reactor";
2
+ import { MessageRouter, WorkerInspectorInfo, WorkerMigrationState } from "@powerhousedao/reactor/rpc";
3
+ //#region src/rpc/admin-client.d.ts
4
+ interface IWorkerAdminClient {
5
+ info(): Promise<WorkerInspectorInfo>;
6
+ restart(): Promise<void>;
7
+ clearStorage(): Promise<void>;
8
+ migrate(): Promise<void>;
9
+ getMigrationState(): WorkerMigrationState;
10
+ subscribeMigration(callback: () => void): () => void;
11
+ }
12
+ /** Worker lifecycle channel (info/restart/clearStorage/migrate) over the shared router. */
13
+ declare function createWorkerAdminClient(router: MessageRouter): IWorkerAdminClient;
14
+ //#endregion
15
+ //#region src/rpc/inspector-proxy.d.ts
16
+ /** `queryReactorDb` is the published name of `queryDb`. */
17
+ interface IInspectorProxy extends IInspector, IInspectorAdmin, IReactorDbQuery {
18
+ queryReactorDb(sql: string, params?: unknown[]): Promise<unknown[]>;
19
+ }
20
+ /** Every row of `INSPECTOR_OPS`; the host decides which tiers it serves. */
21
+ declare function createInspectorProxy(router: MessageRouter): IInspectorProxy;
22
+ //#endregion
23
+ export { createWorkerAdminClient as i, createInspectorProxy as n, IWorkerAdminClient as r, IInspectorProxy as t };
24
+ export {};
25
+ //# sourceMappingURL=inspector-proxy-DODqs15F.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspector-proxy-DODqs15F.d.ts","names":[],"sources":["../src/rpc/admin-client.ts","../src/rpc/inspector-proxy.ts"],"mappings":";;;UAQiB;EACf,QAAQ,QAAQ;EAChB,WAAW;EACX,gBAAgB;EAChB,WAAW;EACX,qBAAqB;EACrB,mBAAmB;;;iBAIL,wBACd,QAAQ,gBACP;;;;UCVc,wBACP,YAAY,iBAAiB;EACrC,eAAe,aAAa,qBAAqB;;;iBAInC,qBAAqB,QAAQ,gBAAgB"}
@@ -0,0 +1,180 @@
1
+ import { createContext, useContext, useSyncExternalStore } from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { capitalCase } from "change-case";
4
+ //#region src/hooks/ph-store.tsx
5
+ const ALL_KEYS = Symbol("all keys");
6
+ const listenersByStore = /* @__PURE__ */ new WeakMap();
7
+ const windowBound = /* @__PURE__ */ new WeakSet();
8
+ const subscribeCache = /* @__PURE__ */ new WeakMap();
9
+ function notifyKey(listeners, key) {
10
+ for (const set of [listeners.get(key), listeners.get(ALL_KEYS)]) for (const listener of set ?? []) listener();
11
+ if (windowBound.has(listeners) && typeof key === "string") window.dispatchEvent(new CustomEvent(`ph:${key}Updated`));
12
+ }
13
+ function createPHStore(initial = {}) {
14
+ const listeners = /* @__PURE__ */ new Map();
15
+ const store = new Proxy({ ...initial }, {
16
+ set: (target, key, value) => {
17
+ if (Reflect.get(target, key) === value) return true;
18
+ Reflect.set(target, key, value);
19
+ notifyKey(listeners, key);
20
+ return true;
21
+ },
22
+ deleteProperty: (target, key) => {
23
+ Reflect.deleteProperty(target, key);
24
+ notifyKey(listeners, key);
25
+ return true;
26
+ }
27
+ });
28
+ listenersByStore.set(store, listeners);
29
+ return store;
30
+ }
31
+ function listenersOf(store) {
32
+ const listeners = listenersByStore.get(store);
33
+ if (!listeners) throw new Error("Not a store made by createPHStore");
34
+ return listeners;
35
+ }
36
+ /** Subscribes to changes of `key`, or of every key when omitted. */
37
+ function subscribePHStore(store, listener, key = ALL_KEYS) {
38
+ return subscribeOwn(store, listener, key);
39
+ }
40
+ function subscribeOwn(store, listener, key) {
41
+ const listeners = listenersOf(store);
42
+ const set = listeners.get(key) ?? /* @__PURE__ */ new Set();
43
+ listeners.set(key, set);
44
+ set.add(listener);
45
+ return () => {
46
+ set.delete(listener);
47
+ };
48
+ }
49
+ /** Notifies `key`'s listeners without a change, as re-setting a value does. */
50
+ function notifyPHStore(store, key) {
51
+ notifyKey(listenersOf(store), key);
52
+ }
53
+ /** A subscribe for `key`, stable per store as useSyncExternalStore expects. */
54
+ function getPHStoreSubscribe(store, key) {
55
+ const cacheKey = key ?? ALL_KEYS;
56
+ const cache = subscribeCache.get(store) ?? /* @__PURE__ */ new Map();
57
+ subscribeCache.set(store, cache);
58
+ let subscribe = cache.get(cacheKey);
59
+ if (!subscribe) {
60
+ subscribe = (listener) => subscribePHStore(store, listener, cacheKey);
61
+ cache.set(cacheKey, subscribe);
62
+ }
63
+ return subscribe;
64
+ }
65
+ let activeStore;
66
+ /** The store bound with {@link bindPHStoreToWindow}, if any. */
67
+ function getActivePHStore() {
68
+ return activeStore;
69
+ }
70
+ /** The app's state outside React: the bound store, else `window.ph`. */
71
+ function getPHStore() {
72
+ if (activeStore) return activeStore;
73
+ return typeof window === "undefined" ? void 0 : window.ph;
74
+ }
75
+ /** The bound store; otherwise binds `window.ph` if it is a store, else a new
76
+ * store that takes over a plain `window.ph`'s values. */
77
+ function ensurePHStore() {
78
+ if (activeStore) return activeStore;
79
+ const current = typeof window === "undefined" ? void 0 : window.ph;
80
+ const store = current && listenersByStore.has(current) ? current : createPHStore();
81
+ bindPHStoreToWindow(store);
82
+ return store;
83
+ }
84
+ /** Makes `store` the app's state and `window.ph`; values set on a plain
85
+ * `window.ph` carry over where `store` has none. */
86
+ function bindPHStoreToWindow(store) {
87
+ activeStore = store;
88
+ if (typeof window === "undefined") return;
89
+ const previous = window.ph;
90
+ const previousListeners = previous && listenersByStore.get(previous);
91
+ if (previousListeners) windowBound.delete(previousListeners);
92
+ else if (previous) {
93
+ for (const [key, value] of Object.entries(previous)) if (!(key in store)) Reflect.set(store, key, value);
94
+ }
95
+ windowBound.add(listenersOf(store));
96
+ window.ph = store;
97
+ }
98
+ const PHStoreContext = createContext(void 0);
99
+ /** Hooks below read from `store`; without a provider they read `window.ph`. */
100
+ function PHStoreProvider(props) {
101
+ return /* @__PURE__ */ jsx(PHStoreContext.Provider, {
102
+ value: props.store,
103
+ children: props.children
104
+ });
105
+ }
106
+ function usePHStore() {
107
+ return useContext(PHStoreContext);
108
+ }
109
+ //#endregion
110
+ //#region src/hooks/make-ph-event-functions.ts
111
+ const isServer = typeof window === "undefined";
112
+ const updatedEventName = (key) => `ph:${key}Updated`;
113
+ /** Calls `onChange` whenever `key` is set: through the bound store, or the
114
+ * `ph:<key>Updated` event on pages that bound none. */
115
+ function subscribeToPHValue(key, onChange) {
116
+ if (isServer) return () => {};
117
+ const store = getActivePHStore();
118
+ if (store) return subscribePHStore(store, onChange, key);
119
+ const eventName = updatedEventName(key);
120
+ window.addEventListener(eventName, onChange);
121
+ return () => window.removeEventListener(eventName, onChange);
122
+ }
123
+ function makePHEventFunctions(key) {
124
+ const setEventName = `ph:set${capitalCase(key)}`;
125
+ const updateEventName = updatedEventName(key);
126
+ function setValue(value) {
127
+ if (isServer) return;
128
+ const store = getActivePHStore();
129
+ if (store) {
130
+ const unchanged = store[key] === value;
131
+ store[key] = value;
132
+ if (unchanged) notifyPHStore(store, key);
133
+ return;
134
+ }
135
+ const event = new CustomEvent(setEventName, { detail: { [key]: value } });
136
+ window.dispatchEvent(event);
137
+ }
138
+ function dispatchUpdatedEvent() {
139
+ if (isServer) return;
140
+ const event = new CustomEvent(updateEventName);
141
+ window.dispatchEvent(event);
142
+ }
143
+ function handleSetValueEvent(event) {
144
+ if (isServer) return;
145
+ if (getActivePHStore()) {
146
+ setValue(event.detail[key]);
147
+ return;
148
+ }
149
+ (window.ph ??= {})[key] = event.detail[key];
150
+ dispatchUpdatedEvent();
151
+ }
152
+ function addEventHandler() {
153
+ if (isServer) return;
154
+ window.addEventListener(setEventName, handleSetValueEvent);
155
+ }
156
+ function subscribeToValue(onStoreChange) {
157
+ return subscribeToPHValue(key, onStoreChange);
158
+ }
159
+ function getSnapshot() {
160
+ if (isServer) return;
161
+ return getPHStore()?.[key];
162
+ }
163
+ function getServerSnapshot() {}
164
+ function useValue() {
165
+ const store = usePHStore();
166
+ const readStore = () => store?.[key];
167
+ return useSyncExternalStore(store ? getPHStoreSubscribe(store, key) : subscribeToValue, store ? readStore : getSnapshot, store ? readStore : getServerSnapshot);
168
+ }
169
+ return {
170
+ useValue,
171
+ setValue,
172
+ addEventHandler,
173
+ subscribeToValue,
174
+ getSnapshot
175
+ };
176
+ }
177
+ //#endregion
178
+ export { createPHStore as a, getPHStore as c, subscribePHStore as d, usePHStore as f, bindPHStoreToWindow as i, getPHStoreSubscribe as l, subscribeToPHValue as n, ensurePHStore as o, PHStoreProvider as r, getActivePHStore as s, makePHEventFunctions as t, notifyPHStore as u };
179
+
180
+ //# sourceMappingURL=make-ph-event-functions-B5GU5xcR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-ph-event-functions-B5GU5xcR.js","names":[],"sources":["../src/hooks/ph-store.tsx","../src/hooks/make-ph-event-functions.ts"],"sourcesContent":["import type { PHGlobal, PHGlobalKey } from \"@powerhousedao/reactor-browser\";\nimport type { ReactNode } from \"react\";\nimport { createContext, useContext } from \"react\";\n\n/** PH state of one app (or one server request); assigning a key notifies. */\nexport type PHStore = PHGlobal;\n\ntype Listeners = Map<PropertyKey, Set<() => void>>;\n\n// Listeners per key; ALL_KEYS hears every change.\nconst ALL_KEYS = Symbol(\"all keys\");\nconst listenersByStore = new WeakMap<PHStore, Listeners>();\n// Stores bound to window.ph; their changes also fire `ph:<key>Updated`.\nconst windowBound = new WeakSet<Listeners>();\nconst subscribeCache = new WeakMap<\n PHStore,\n Map<PropertyKey, (listener: () => void) => () => void>\n>();\n\nfunction notifyKey(listeners: Listeners, key: PropertyKey) {\n for (const set of [listeners.get(key), listeners.get(ALL_KEYS)]) {\n for (const listener of set ?? []) listener();\n }\n // Another bundled copy of reactor-browser subscribes through window events.\n if (windowBound.has(listeners) && typeof key === \"string\") {\n window.dispatchEvent(new CustomEvent(`ph:${key}Updated`));\n }\n}\n\nexport function createPHStore(initial: PHGlobal = {}): PHStore {\n const listeners: Listeners = new Map();\n const store = new Proxy<PHGlobal>(\n { ...initial },\n {\n set: (target, key, value) => {\n if (Reflect.get(target, key) === value) return true;\n Reflect.set(target, key, value);\n notifyKey(listeners, key);\n return true;\n },\n deleteProperty: (target, key) => {\n Reflect.deleteProperty(target, key);\n notifyKey(listeners, key);\n return true;\n },\n },\n );\n listenersByStore.set(store, listeners);\n return store;\n}\n\nfunction listenersOf(store: PHStore) {\n const listeners = listenersByStore.get(store);\n if (!listeners) throw new Error(\"Not a store made by createPHStore\");\n return listeners;\n}\n\n/** Subscribes to changes of `key`, or of every key when omitted. */\nexport function subscribePHStore(\n store: PHStore,\n listener: () => void,\n key: PHGlobalKey | typeof ALL_KEYS = ALL_KEYS,\n): () => void {\n return subscribeOwn(store, listener, key);\n}\n\nfunction subscribeOwn(store: PHStore, listener: () => void, key: PropertyKey) {\n const listeners = listenersOf(store);\n const set = listeners.get(key) ?? new Set();\n listeners.set(key, set);\n set.add(listener);\n return () => {\n set.delete(listener);\n };\n}\n\n/** Notifies `key`'s listeners without a change, as re-setting a value does. */\nexport function notifyPHStore(store: PHStore, key: PHGlobalKey) {\n notifyKey(listenersOf(store), key);\n}\n\n/** A subscribe for `key`, stable per store as useSyncExternalStore expects. */\nexport function getPHStoreSubscribe(store: PHStore, key?: PHGlobalKey) {\n const cacheKey = key ?? ALL_KEYS;\n const cache =\n subscribeCache.get(store) ??\n new Map<PropertyKey, (listener: () => void) => () => void>();\n subscribeCache.set(store, cache);\n let subscribe = cache.get(cacheKey);\n if (!subscribe) {\n subscribe = (listener: () => void) =>\n subscribePHStore(store, listener, cacheKey);\n cache.set(cacheKey, subscribe);\n }\n return subscribe;\n}\n\nlet activeStore: PHStore | undefined;\n\n/** The store bound with {@link bindPHStoreToWindow}, if any. */\nexport function getActivePHStore() {\n return activeStore;\n}\n\n/** The app's state outside React: the bound store, else `window.ph`. */\nexport function getPHStore(): PHStore | undefined {\n if (activeStore) return activeStore;\n return typeof window === \"undefined\" ? undefined : window.ph;\n}\n\n/** The bound store; otherwise binds `window.ph` if it is a store, else a new\n * store that takes over a plain `window.ph`'s values. */\nexport function ensurePHStore(): PHStore {\n if (activeStore) return activeStore;\n const current = typeof window === \"undefined\" ? undefined : window.ph;\n const store =\n current && listenersByStore.has(current) ? current : createPHStore();\n bindPHStoreToWindow(store);\n return store;\n}\n\n/** Makes `store` the app's state and `window.ph`; values set on a plain\n * `window.ph` carry over where `store` has none. */\nexport function bindPHStoreToWindow(store: PHStore) {\n activeStore = store;\n if (typeof window === \"undefined\") return;\n const previous = window.ph;\n const previousListeners = previous && listenersByStore.get(previous);\n // A previously bound store is replaced, not merged.\n if (previousListeners) windowBound.delete(previousListeners);\n else if (previous) {\n for (const [key, value] of Object.entries(previous)) {\n if (!(key in store)) Reflect.set(store, key, value);\n }\n }\n windowBound.add(listenersOf(store));\n window.ph = store;\n}\n\nconst PHStoreContext = createContext<PHStore | undefined>(undefined);\n\n/** Hooks below read from `store`; without a provider they read `window.ph`. */\nexport function PHStoreProvider(props: {\n store: PHStore;\n children: ReactNode;\n}) {\n return (\n <PHStoreContext.Provider value={props.store}>\n {props.children}\n </PHStoreContext.Provider>\n );\n}\n\nexport function usePHStore() {\n return useContext(PHStoreContext);\n}\n","import type {\n PHGlobal,\n PHGlobalKey,\n SetEvent,\n} from \"@powerhousedao/reactor-browser\";\nimport { capitalCase } from \"change-case\";\nimport { useSyncExternalStore } from \"react\";\nimport {\n getActivePHStore,\n getPHStore,\n getPHStoreSubscribe,\n notifyPHStore,\n subscribePHStore,\n usePHStore,\n} from \"./ph-store.js\";\n\n// guard condition for server side rendering\nconst isServer = typeof window === \"undefined\";\n\nconst updatedEventName = (key: PHGlobalKey) => `ph:${key}Updated`;\n\n/** Calls `onChange` whenever `key` is set: through the bound store, or the\n * `ph:<key>Updated` event on pages that bound none. */\nexport function subscribeToPHValue(key: PHGlobalKey, onChange: () => void) {\n if (isServer) return () => {};\n const store = getActivePHStore();\n if (store) return subscribePHStore(store, onChange, key);\n const eventName = updatedEventName(key);\n window.addEventListener(eventName, onChange);\n return () => window.removeEventListener(eventName, onChange);\n}\n\nexport function makePHEventFunctions<TKey extends PHGlobalKey>(key: TKey) {\n const setEventName = `ph:set${capitalCase(key)}` as const;\n const updateEventName = updatedEventName(key);\n\n function setValue(value: PHGlobal[TKey] | undefined) {\n if (isServer) {\n return;\n }\n const store = getActivePHStore();\n if (store) {\n const unchanged = store[key] === value;\n store[key] = value;\n // Re-setting a value still notifies, as the event path always has.\n if (unchanged) notifyPHStore(store, key);\n return;\n }\n const event = new CustomEvent(setEventName, {\n detail: { [key]: value },\n });\n window.dispatchEvent(event);\n }\n\n function dispatchUpdatedEvent() {\n if (isServer) {\n return;\n }\n const event = new CustomEvent(updateEventName);\n window.dispatchEvent(event);\n }\n\n function handleSetValueEvent(event: SetEvent<TKey>) {\n if (isServer) {\n return;\n }\n if (getActivePHStore()) {\n setValue(event.detail[key]);\n return;\n }\n // No bound store: the page keeps a plain `window.ph`.\n (window.ph ??= {})[key] = event.detail[key];\n dispatchUpdatedEvent();\n }\n\n // Only pages without a bound store need it; `ph:set*` events still apply.\n function addEventHandler() {\n if (isServer) {\n return;\n }\n window.addEventListener(setEventName, handleSetValueEvent as EventListener);\n }\n\n function subscribeToValue(onStoreChange: () => void) {\n return subscribeToPHValue(key, onStoreChange);\n }\n\n function getSnapshot() {\n if (isServer) {\n return undefined;\n }\n // Read before the first setValue is expected: subscribers mount before init.\n return getPHStore()?.[key];\n }\n\n function getServerSnapshot() {\n return undefined;\n }\n\n function useValue() {\n const store = usePHStore();\n const readStore = () => store?.[key];\n return useSyncExternalStore(\n store ? getPHStoreSubscribe(store, key) : subscribeToValue,\n store ? readStore : getSnapshot,\n store ? readStore : getServerSnapshot,\n );\n }\n\n return {\n useValue,\n setValue,\n addEventHandler,\n // Non-React access,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O,CAAC,EAAA,CAAG,OAAO,MAAM,OAAO;EACvC,qBAAqB;CACvB;CAGA,SAAS,kBAAkB;EACzB,IAAI,UACF;EAEF,OAAO,iBAAiB,cAAc,mBAAoC;CAC5E;CAEA,SAAS,iBAAiB,eAA2B;EACnD,OAAO,mBAAmB,KAAK,aAAa;CAC9C;CAEA,SAAS,cAAc;EACrB,IAAI,UACF;EAGF,OAAO,WAAW,CAAC,GAAG;CACxB;CAEA,SAAS,oBAAoB,CAE7B;CAEA,SAAS,WAAW;EAClB,MAAM,QAAQ,WAAW;EACzB,MAAM,kBAAkB,QAAQ;EAChC,OAAO,qBACL,QAAQ,oBAAoB,OAAO,GAAG,IAAI,kBAC1C,QAAQ,YAAY,aACpB,QAAQ,YAAY,iBACtB;CACF;CAEA,OAAO;EACL;EACA;EACA;EAEA;EACA;CACF;AACF"}
@@ -111,9 +111,6 @@ interface Filesystem {
111
111
  */
112
112
  closeFs(): Promise<void>;
113
113
  }
114
- /**
115
- * Base class for all emscripten built-in filesystems.
116
- */
117
114
  type DebugLevel = 0 | 1 | 2 | 3 | 4 | 5;
118
115
  type RowMode = 'array' | 'object';
119
116
  interface ParserOptions {
@@ -151,7 +148,7 @@ type ExtensionNamespace<T> = T extends Extension<infer TNamespace> ? TNamespace
151
148
  type Extensions = {
152
149
  [namespace: string]: Extension | URL;
153
150
  };
154
- type InitializedExtensions<TExtensions extends Extensions = Extensions> = { [K in keyof TExtensions]: ExtensionNamespace<TExtensions[K]> };
151
+ type InitializedExtensions<TExtensions extends Extensions = Extensions> = { [K in keyof TExtensions]: ExtensionNamespace<TExtensions[K]>; };
155
152
  interface ExecProtocolResult {
156
153
  messages: BackendMessage[];
157
154
  data: Uint8Array;
@@ -192,7 +189,7 @@ type PGliteInterface<T extends Extensions = Extensions> = InitializedExtensions<
192
189
  dumpDataDir(compression?: DumpTarCompressionOptions): Promise<File | Blob>;
193
190
  refreshArrayTypes(): Promise<void>;
194
191
  };
195
- type PGliteInterfaceExtensions<E> = E extends Extensions ? { [K in keyof E]: E[K] extends Extension ? Awaited<ReturnType<E[K]['setup']>>['namespaceObj'] extends infer N ? N extends undefined | null | void ? never : N : never : never } : Record<string, never>;
192
+ type PGliteInterfaceExtensions<E> = E extends Extensions ? { [K in keyof E]: E[K] extends Extension ? Awaited<ReturnType<E[K]['setup']>>['namespaceObj'] extends (infer N) ? N extends undefined | null | void ? never : N : never : never; } : Record<string, never>;
196
193
  type Row<T = {
197
194
  [key: string]: any;
198
195
  }> = T;
@@ -238,19 +235,13 @@ declare abstract class BasePGlite implements Pick<PGliteInterface, 'query' | 'sq
238
235
  * @param message The postgres wire protocol message to execute
239
236
  * @returns The result of the query
240
237
  */
241
- abstract execProtocol(message: Uint8Array, {
242
- syncToFs,
243
- onNotice
244
- }: ExecProtocolOptions): Promise<ExecProtocolResult>;
238
+ abstract execProtocol(message: Uint8Array, { syncToFs, onNotice }: ExecProtocolOptions): Promise<ExecProtocolResult>;
245
239
  /**
246
240
  * Execute a postgres wire protocol message
247
241
  * @param message The postgres wire protocol message to execute
248
242
  * @returns The parsed results of the query
249
243
  */
250
- abstract execProtocolStream(message: Uint8Array, {
251
- syncToFs,
252
- onNotice
253
- }: ExecProtocolOptions): Promise<BackendMessage[]>;
244
+ abstract execProtocolStream(message: Uint8Array, { syncToFs, onNotice }: ExecProtocolOptions): Promise<BackendMessage[]>;
254
245
  /**
255
246
  * Execute a postgres wire protocol message directly without wrapping the response.
256
247
  * Only use if `execProtocol()` doesn't suite your needs.
@@ -262,9 +253,7 @@ declare abstract class BasePGlite implements Pick<PGliteInterface, 'query' | 'sq
262
253
  * @param message The postgres wire protocol message to execute
263
254
  * @returns The direct message data response produced by Postgres
264
255
  */
265
- abstract execProtocolRaw(message: Uint8Array, {
266
- syncToFs
267
- }: ExecProtocolOptions): Promise<Uint8Array>;
256
+ abstract execProtocolRaw(message: Uint8Array, { syncToFs }: ExecProtocolOptions): Promise<Uint8Array>;
268
257
  /**
269
258
  * Sync the database to the filesystem
270
259
  * @returns Promise that resolves when the database is synced to the filesystem
@@ -298,9 +287,7 @@ declare abstract class BasePGlite implements Pick<PGliteInterface, 'query' | 'sq
298
287
  * each type.
299
288
  * This should be called at the end of #init() in the implementing class.
300
289
  */
301
- _initArrayTypes({
302
- force
303
- }?: {
290
+ _initArrayTypes({ force }?: {
304
291
  force?: boolean | undefined;
305
292
  }): Promise<void>;
306
293
  /**
@@ -462,29 +449,19 @@ declare class PGlite extends BasePGlite implements PGliteInterface, AsyncDisposa
462
449
  * @param message The postgres wire protocol message to execute
463
450
  * @returns The direct message data response produced by Postgres
464
451
  */
465
- execProtocolRaw(message: Uint8Array, {
466
- syncToFs
467
- }?: ExecProtocolOptions): Promise<Uint8Array>;
452
+ execProtocolRaw(message: Uint8Array, { syncToFs }?: ExecProtocolOptions): Promise<Uint8Array>;
468
453
  /**
469
454
  * Execute a postgres wire protocol message
470
455
  * @param message The postgres wire protocol message to execute
471
456
  * @returns The result of the query
472
457
  */
473
- execProtocol(message: Uint8Array, {
474
- syncToFs,
475
- throwOnError,
476
- onNotice
477
- }?: ExecProtocolOptions): Promise<ExecProtocolResult>;
458
+ execProtocol(message: Uint8Array, { syncToFs, throwOnError, onNotice }?: ExecProtocolOptions): Promise<ExecProtocolResult>;
478
459
  /**
479
460
  * Execute a postgres wire protocol message
480
461
  * @param message The postgres wire protocol message to execute
481
462
  * @returns The parsed results of the query
482
463
  */
483
- execProtocolStream(message: Uint8Array, {
484
- syncToFs,
485
- throwOnError,
486
- onNotice
487
- }?: ExecProtocolOptions): Promise<BackendMessage[]>;
464
+ execProtocolStream(message: Uint8Array, { syncToFs, throwOnError, onNotice }?: ExecProtocolOptions): Promise<BackendMessage[]>;
488
465
  /**
489
466
  * Check if the database is in a transaction
490
467
  * @returns True if the database is in a transaction, false otherwise
@@ -540,4 +517,5 @@ declare class PGlite extends BasePGlite implements PGliteInterface, AsyncDisposa
540
517
  }
541
518
  //#endregion
542
519
  export { type PGliteInterface as n, type Results as r, PGlite as t };
543
- //# sourceMappingURL=pglite-CntadC_p-9NDG14dS.d.ts.map
520
+ export {};
521
+ //# sourceMappingURL=pglite-CntadC_p-DTkdF8sr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite-CntadC_p-DTkdF8sr.d.ts","names":[],"sources":["../../../node_modules/.pnpm/@electric-sql+pglite@0.3.15/node_modules/@electric-sql/pglite/dist/pglite-CntadC_p.d.ts"],"x_google_ignoreList":[0],"mappings":";KAOK;KACA;EACD,MAAM;EACN;;UA6CM;EACN;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;cAqGU,yBAAyB,gBAAgB;WAC1C;WACA;EACT,YAAY,gBAAgB;WACnB;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAwDC,QAAQ,WAAW;EACpB;EACA,KAAK,eAAe;;KAEnB,YAAY;EACb;IACI,OAAO,WAAW;IAClB,QAAQ,WAAW;IACnB,OAAO;;EAEX;;UAEM,oBAAoB,KAAK;EAC/B,SAAS;KACJ,KAAK;;EAEV,QAAQ;KACH,KAAK;;EAEV,SAAS;KACJ,KAAK;;EAEV,IAAI;EACJ;EACA;EACA;EACA,eAAe,eAAe,QAAQ;EACtC;EACA;EACA;EACA,qBAAqB;EACrB,mBAAmB,gBAAgB;EACnC,sBAAsB,iBAAiB;EACvC,cAAc,KAAK,UAAU,yBAAyB;EACtD,iBAAiB;;KAWhB;;;;;;UAUK;;;;EAIN,KAAK,IAAI,QAAQ,mBAAmB,QAAQ,eAAe;IACvD,gBAAgB,QAAQ;;;;;EAK5B,SAAS,8BAA8B;;;;EAIvC,iBAAiB;;;;EAIjB,QAAQ,gBAAgB,cAAc,4BAA4B,QAAQ,OAAO;;;;EAIjF,WAAW;;KA4FV;KACA;UACK;GACL,kBAAkB;;UAEb;GACL,kBAAkB;;UAEb;EACN,UAAU;EACV,UAAU;EACV,cA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iBAAiB;;;;;;EAM5C,YAAY,cAAc,4BAA4B,QAAQ,OAAO;;;;;;EAMrE,mBAAmB,GAAG,UAAU,QAAQ,KAAK,QAAQ;;;;;;EAMrD,yBAAyB,GAAG,UAAU,QAAQ,KAAK,QAAQ;EAC3D,SAAS,QAAQ;EACjB,oBAAoB,GAAG,UAAU,QAAQ,KAAK,QAAQ"}
@@ -1,5 +1,5 @@
1
- import { createRelationalDb } from "@powerhousedao/reactor";
2
1
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { HardenedPGliteDialect, createRelationalDb } from "@powerhousedao/reactor";
3
3
  import { Kysely } from "kysely";
4
4
  import { PGliteDialect } from "kysely-pglite-dialect";
5
5
  import deepEqual from "lodash.isequal";
@@ -32,15 +32,71 @@ function setPGliteDB(pglite) {
32
32
  window.dispatchEvent(new CustomEvent(PGLITE_UPDATE_EVENT));
33
33
  }
34
34
  //#endregion
35
+ //#region src/relational/utils/relational-dialect.ts
36
+ /** A query-only proxy (Connect's worker RPC) has no session here to harden; its worker does that. */
37
+ function relationalDialect(instance, options = {}) {
38
+ const session = instance;
39
+ if (typeof session.exec === "function" && typeof session.isInTransaction === "function") return new HardenedPGliteDialect(session, options);
40
+ return new PGliteDialect(instance);
41
+ }
42
+ const sharedByInstance = /* @__PURE__ */ new WeakMap();
43
+ function sharedFor(instance, options = {}) {
44
+ let shared = sharedByInstance.get(instance);
45
+ if (shared === void 0) {
46
+ const listeners = /* @__PURE__ */ new Set();
47
+ const created = {
48
+ listeners,
49
+ kysely: new Kysely({ dialect: relationalDialect(instance, {
50
+ ...options,
51
+ onPoisoned: (cause) => {
52
+ created.poisoned = cause;
53
+ for (const listener of [...listeners]) try {
54
+ listener(cause);
55
+ } catch (error) {
56
+ console.error("relational onPoisoned listener threw", error);
57
+ }
58
+ }
59
+ }) })
60
+ };
61
+ shared = created;
62
+ sharedByInstance.set(instance, shared);
63
+ }
64
+ return shared;
65
+ }
66
+ /** One Kysely, so one queue, per PGlite; `options` apply from the first caller, which creates it. */
67
+ function relationalKysely(instance, options = {}) {
68
+ return sharedFor(instance, options).kysely;
69
+ }
70
+ /**
71
+ * Tells `listener` once the shared session of `instance` is poisoned, however
72
+ * many consumers share it and whichever opened it first; a late subscriber is
73
+ * told at once. Returns the unsubscribe.
74
+ */
75
+ function subscribeRelationalPoisoned(instance, listener) {
76
+ const shared = sharedFor(instance);
77
+ if (shared.poisoned !== void 0) {
78
+ listener(shared.poisoned);
79
+ return () => void 0;
80
+ }
81
+ shared.listeners.add(listener);
82
+ return () => {
83
+ shared.listeners.delete(listener);
84
+ };
85
+ }
86
+ //#endregion
35
87
  //#region src/relational/hooks/useRelationalDb.ts
36
88
  function createRelationalDbWithLive(pgliteInstance) {
37
- const relationalDBWithLive = createRelationalDb(new Kysely({ dialect: new PGliteDialect(pgliteInstance) }));
89
+ const baseDb = relationalKysely(pgliteInstance);
90
+ const relationalDBWithLive = createRelationalDb(baseDb);
38
91
  relationalDBWithLive.live = pgliteInstance.live;
39
92
  return relationalDBWithLive;
40
93
  }
41
- const useRelationalDb = () => {
94
+ const useRelationalDb = (options = {}) => {
42
95
  const pglite = usePGliteDB();
43
- return useMemo(() => {
96
+ const onPoisoned = useRef(options.onPoisoned);
97
+ onPoisoned.current = options.onPoisoned;
98
+ const wantsPoisoned = options.onPoisoned !== void 0;
99
+ const relationalDb = useMemo(() => {
44
100
  if (!pglite.db || pglite.isLoading || pglite.error) return {
45
101
  db: null,
46
102
  isLoading: pglite.isLoading,
@@ -52,6 +108,11 @@ const useRelationalDb = () => {
52
108
  error: null
53
109
  };
54
110
  }, [pglite]);
111
+ useEffect(() => {
112
+ if (!pglite.db || !wantsPoisoned) return;
113
+ return subscribeRelationalPoisoned(pglite.db, (cause) => onPoisoned.current?.(cause));
114
+ }, [pglite.db, wantsPoisoned]);
115
+ return relationalDb;
55
116
  };
56
117
  //#endregion
57
118
  //#region src/relational/hooks/useRelationalQuery.ts
@@ -132,4 +193,4 @@ function createProcessorQuery(ProcessorClass) {
132
193
  //#endregion
133
194
  export { setPGliteDB as i, useRelationalQuery as n, useRelationalDb as r, createProcessorQuery as t };
134
195
 
135
- //# sourceMappingURL=relational-D1RB45sA.js.map
196
+ //# sourceMappingURL=relational-DZuyKp2y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relational-DZuyKp2y.js","names":[],"sources":["../src/pglite/usePGlite.ts","../src/relational/utils/relational-dialect.ts","../src/relational/hooks/useRelationalDb.ts","../src/relational/hooks/useRelationalQuery.ts","../src/relational/utils/createProcessorQuery.ts"],"sourcesContent":["import type { PGliteWithLive } from \"@electric-sql/pglite/live\";\nimport { useEffect, useState } from \"react\";\n\nexport const PGLITE_UPDATE_EVENT = \"ph:pglite-update\";\n\nexport interface PGliteState {\n db: PGliteWithLive | null;\n isLoading: boolean;\n error: Error | null;\n}\n\nconst defaultPGliteState: PGliteState = {\n db: null,\n isLoading: true,\n error: null,\n};\n\nexport const usePGliteDB = () => {\n const [state, setState] = useState<PGliteState>(\n () => window.powerhouse?.pglite ?? defaultPGliteState,\n );\n\n useEffect(() => {\n const handlePgliteUpdate = () =>\n setState(window.powerhouse?.pglite ?? defaultPGliteState);\n\n window.addEventListener(PGLITE_UPDATE_EVENT, handlePgliteUpdate);\n\n return () =>\n window.removeEventListener(PGLITE_UPDATE_EVENT, handlePgliteUpdate);\n }, []);\n\n return state;\n};\n\nexport function setPGliteDB(pglite: Partial<PGliteState>): void {\n const currentPowerhouse = window.powerhouse ?? {};\n const currentPGliteState = window.powerhouse?.pglite ?? defaultPGliteState;\n\n window.powerhouse = {\n ...currentPowerhouse,\n pglite: {\n ...currentPGliteState,\n ...pglite,\n },\n };\n window.dispatchEvent(new CustomEvent(PGLITE_UPDATE_EVENT));\n}\n\nexport const useSetPGliteDB = () => setPGliteDB;\n\nexport const usePGlite = () => {\n const pglite = usePGliteDB();\n const setPGlite = useSetPGliteDB();\n\n return [pglite, setPGlite];\n};\n","import type { PGlite } from \"@electric-sql/pglite\";\nimport {\n HardenedPGliteDialect,\n type HardenedPGliteDialectOptions,\n type PGliteSession,\n} from \"@powerhousedao/reactor\";\nimport { Kysely, type Dialect } from \"kysely\";\nimport { PGliteDialect } from \"kysely-pglite-dialect\";\n\n/** A query-only proxy (Connect's worker RPC) has no session here to harden; its worker does that. */\nexport function relationalDialect(\n instance: unknown,\n options: Partial<HardenedPGliteDialectOptions> = {},\n): Dialect {\n const session = instance as Partial<PGliteSession>;\n if (\n typeof session.exec === \"function\" &&\n typeof session.isInTransaction === \"function\"\n ) {\n return new HardenedPGliteDialect(session as PGliteSession, options);\n }\n return new PGliteDialect(instance as PGlite);\n}\n\ntype PoisonListener = (cause: Error) => void;\n\ntype SharedRelationalDb = {\n kysely: Kysely<unknown>;\n listeners: Set<PoisonListener>;\n poisoned?: Error;\n};\n\nconst sharedByInstance = new WeakMap<object, SharedRelationalDb>();\n\nfunction sharedFor(\n instance: object,\n options: Partial<Omit<HardenedPGliteDialectOptions, \"onPoisoned\">> = {},\n): SharedRelationalDb {\n let shared = sharedByInstance.get(instance);\n if (shared === undefined) {\n const listeners = new Set<PoisonListener>();\n const created: SharedRelationalDb = {\n listeners,\n kysely: new Kysely<unknown>({\n dialect: relationalDialect(instance, {\n ...options,\n onPoisoned: (cause) => {\n created.poisoned = cause;\n for (const listener of [...listeners]) {\n try {\n listener(cause);\n } catch (error) {\n console.error(\"relational onPoisoned listener threw\", error);\n }\n }\n },\n }),\n }),\n };\n shared = created;\n sharedByInstance.set(instance, shared);\n }\n return shared;\n}\n\n/** One Kysely, so one queue, per PGlite; `options` apply from the first caller, which creates it. */\nexport function relationalKysely<Schema>(\n instance: object,\n options: Partial<Omit<HardenedPGliteDialectOptions, \"onPoisoned\">> = {},\n): Kysely<Schema> {\n return sharedFor(instance, options).kysely as Kysely<Schema>;\n}\n\n/**\n * Tells `listener` once the shared session of `instance` is poisoned, however\n * many consumers share it and whichever opened it first; a late subscriber is\n * told at once. Returns the unsubscribe.\n */\nexport function subscribeRelationalPoisoned(\n instance: object,\n listener: PoisonListener,\n): () => void {\n const shared = sharedFor(instance);\n if (shared.poisoned !== undefined) {\n listener(shared.poisoned);\n return () => undefined;\n }\n shared.listeners.add(listener);\n return () => {\n shared.listeners.delete(listener);\n };\n}\n","import type { LiveNamespace, PGliteWithLive } from \"@electric-sql/pglite/live\";\nimport { createRelationalDb } from \"@powerhousedao/reactor\";\nimport type { IRelationalDb as IRelationalDbCore } from \"@powerhousedao/shared/processors\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { usePGliteDB } from \"../../pglite/usePGlite.js\";\nimport {\n relationalKysely,\n subscribeRelationalPoisoned,\n} from \"../utils/relational-dialect.js\";\n\n// Type for Relational DB instance enhanced with live capabilities\nexport type RelationalDbWithLive<Schema> = IRelationalDbCore<Schema> & {\n live: LiveNamespace;\n};\n\ninterface IRelationalDbState<Schema> {\n db: RelationalDbWithLive<Schema> | null;\n isLoading: boolean;\n error: Error | null;\n}\n\n// Custom initializer that creates enhanced Kysely instance with live capabilities\nfunction createRelationalDbWithLive<Schema>(\n pgliteInstance: PGliteWithLive,\n): RelationalDbWithLive<Schema> {\n const baseDb = relationalKysely<Schema>(pgliteInstance);\n const relationalDb = createRelationalDb(baseDb);\n\n // Inject the live namespace with proper typing\n const relationalDBWithLive =\n relationalDb as unknown as RelationalDbWithLive<Schema>;\n relationalDBWithLive.live = pgliteInstance.live;\n\n return relationalDBWithLive;\n}\n\nexport type RelationalDbOptions = {\n /**\n * Called once if the shared PGlite session becomes unusable; every hook that\n * passes one is told, and it unsubscribes on unmount. Recovery is the caller's.\n */\n onPoisoned?: (cause: Error) => void;\n};\n\nexport const useRelationalDb = <Schema>(\n options: RelationalDbOptions = {},\n): IRelationalDbState<Schema> => {\n const pglite = usePGliteDB();\n const onPoisoned = useRef(options.onPoisoned);\n onPoisoned.current = options.onPoisoned;\n const wantsPoisoned = options.onPoisoned !== undefined;\n\n const relationalDb = useMemo<IRelationalDbState<Schema>>(() => {\n if (!pglite.db || pglite.isLoading || pglite.error) {\n return {\n db: null,\n isLoading: pglite.isLoading,\n error: pglite.error,\n };\n }\n\n const db = createRelationalDbWithLive<Schema>(pglite.db);\n\n return {\n db,\n isLoading: false,\n error: null,\n };\n }, [pglite]);\n\n useEffect(() => {\n if (!pglite.db || !wantsPoisoned) return;\n return subscribeRelationalPoisoned(pglite.db, (cause) =>\n onPoisoned.current?.(cause),\n );\n }, [pglite.db, wantsPoisoned]);\n\n return relationalDb;\n};\n","import type { LiveQueryResults } from \"@electric-sql/pglite/live\";\nimport type {\n IRelationalQueryBuilder,\n RelationalDbProcessorClass,\n} from \"@powerhousedao/shared/processors\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { useRelationalDb } from \"./useRelationalDb.js\";\n\nexport type QueryCallbackReturnType = {\n sql: string;\n parameters?: readonly unknown[];\n};\n\nexport type useRelationalQueryOptions = {\n // Whether to hash the namespace to avoid namespace size limit. True by default\n hashNamespace?: boolean;\n};\n\nconst MAX_RETRIES = 5;\nconst RETRY_DELAY = 200;\n\nconst isRelationNotExistError = (error: unknown): boolean => {\n const errorMessage =\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : String(error);\n\n return (\n errorMessage.toLowerCase().includes(\"relation\") &&\n errorMessage.toLowerCase().includes(\"does not exist\")\n );\n};\n\ntype LiveQueryType = {\n unsubscribe: () => void;\n};\n\nexport function useRelationalQuery<Schema, T = unknown, TParams = undefined>(\n ProcessorClass: RelationalDbProcessorClass<Schema>,\n driveId: string,\n queryCallback: (\n db: IRelationalQueryBuilder<Schema>,\n parameters?: TParams,\n ) => QueryCallbackReturnType,\n parameters?: TParams,\n _options?: useRelationalQueryOptions,\n) {\n const [result, setResult] = useState<LiveQueryResults<T> | null>(null);\n const [queryLoading, setQueryLoading] = useState(true);\n const [error, setError] = useState<Error | undefined>(undefined);\n const retryCount = useRef(0);\n const retryTimeoutRef = useRef<NodeJS.Timeout>(null);\n\n const relationalDb = useRelationalDb<Schema>();\n\n const executeLiveQuery = async (\n sql: string,\n queryParameters: readonly unknown[] | undefined,\n retryAttempt = 0,\n ): Promise<LiveQueryType | null> => {\n if (!relationalDb.db) {\n return null;\n }\n\n try {\n const live = await relationalDb.db.live.query<T>(\n sql,\n queryParameters ? [...queryParameters] : [],\n (result) => {\n setResult(result);\n setQueryLoading(false);\n retryCount.current = 0; // Reset retry count on success\n },\n );\n\n return live as LiveQueryType;\n } catch (err: unknown) {\n if (isRelationNotExistError(err) && retryAttempt < MAX_RETRIES) {\n return new Promise((resolve) => {\n retryTimeoutRef.current = setTimeout(() => {\n resolve(executeLiveQuery(sql, queryParameters, retryAttempt + 1));\n }, RETRY_DELAY);\n });\n }\n\n setQueryLoading(false);\n setError(err instanceof Error ? err : new Error(String(err)));\n return null;\n }\n };\n\n useEffect(() => {\n setError(undefined);\n setQueryLoading(true);\n retryCount.current = 0;\n\n if (!relationalDb.db) {\n return;\n }\n\n // Use the processor helper to obtain a typed namespaced query builder\n const db = ProcessorClass.query(driveId, relationalDb.db);\n\n const compiledQuery = queryCallback(db, parameters);\n const { sql, parameters: queryParameters } = compiledQuery;\n\n const liveQueryPromise = executeLiveQuery(sql, queryParameters);\n\n return () => {\n if (retryTimeoutRef.current) {\n clearTimeout(retryTimeoutRef.current);\n }\n void liveQueryPromise.then((live) => {\n if (live?.unsubscribe) {\n live.unsubscribe();\n }\n });\n };\n }, [relationalDb.db, ProcessorClass, driveId, queryCallback, parameters]);\n\n return {\n isLoading: relationalDb.isLoading || queryLoading,\n error: error || relationalDb.error,\n result,\n } as const;\n}\n","import type { LiveQueryResults } from \"@electric-sql/pglite/live\";\nimport type {\n QueryCallbackReturnType,\n useRelationalQueryOptions,\n} from \"@powerhousedao/reactor-browser\";\nimport type {\n IRelationalQueryBuilder,\n RelationalDbProcessorClass,\n} from \"@powerhousedao/shared/processors\";\nimport type { CompiledQuery } from \"kysely\";\nimport deepEqual from \"lodash.isequal\";\nimport { useCallback, useMemo, useRef } from \"react\";\nimport { useRelationalQuery } from \"../hooks/useRelationalQuery.js\";\n\n// Custom hook for parameter memoization\nfunction useStableParams<T>(params: T): T {\n const prevParamsRef = useRef<T>(null);\n\n return useMemo(() => {\n if (!deepEqual(prevParamsRef.current, params)) {\n prevParamsRef.current = params;\n }\n return prevParamsRef.current as T;\n }, [params]);\n}\n\nexport function createProcessorQuery<TSchema>(\n ProcessorClass: RelationalDbProcessorClass<TSchema>,\n) {\n // Overload for queries without parameters\n function useQuery<\n TQueryBuilder extends (\n db: IRelationalQueryBuilder<TSchema>,\n ) => QueryCallbackReturnType,\n >(\n driveId: string,\n queryCallback: TQueryBuilder,\n ): {\n isLoading: boolean;\n error: Error | null;\n result: LiveQueryResults<\n ReturnType<TQueryBuilder> extends CompiledQuery<infer R> ? R : any\n > | null;\n };\n\n // Overload for queries with parameters\n function useQuery<\n TParams,\n TQueryBuilder extends (\n db: IRelationalQueryBuilder<TSchema>,\n parameters: TParams,\n ) => QueryCallbackReturnType,\n >(\n driveId: string,\n queryCallback: TQueryBuilder,\n parameters: TParams,\n options?: useRelationalQueryOptions,\n ): {\n isLoading: boolean;\n error: Error | null;\n result: LiveQueryResults<\n ReturnType<TQueryBuilder> extends CompiledQuery<infer R> ? R : any\n > | null;\n };\n\n function useQuery<\n TParams,\n TQueryBuilder extends (\n db: IRelationalQueryBuilder<TSchema>,\n parameters?: TParams,\n ) => QueryCallbackReturnType,\n >(\n driveId: string,\n queryCallback: TQueryBuilder,\n parameters?: TParams,\n options?: useRelationalQueryOptions,\n ): {\n isLoading: boolean;\n error: Error | null;\n result: LiveQueryResults<\n ReturnType<TQueryBuilder> extends CompiledQuery<infer R> ? R : any\n > | null;\n } {\n type InferredResult =\n ReturnType<TQueryBuilder> extends CompiledQuery<infer R> ? R : any;\n\n // Automatically memoize parameters using deep comparison\n const stableParams = useStableParams(parameters);\n\n // Memoize the callback to prevent infinite loops, updating when parameters change\n const memoizedCallback = useCallback(queryCallback, [stableParams]);\n\n return useRelationalQuery<TSchema, InferredResult, TParams>(\n ProcessorClass,\n driveId,\n memoizedCallback,\n stableParams,\n options,\n ) as {\n isLoading: boolean;\n error: Error | null;\n result: LiveQueryResults<InferredResult> | null;\n };\n }\n\n return useQuery;\n}\n"],"mappings":";;;;;;AAGA,MAAa,sBAAsB;AAQnC,MAAM,qBAAkC;CACtC,IAAI;CACJ,WAAW;CACX,OAAO;AACT;AAEA,MAAa,oBAAoB;CAC/B,MAAM,CAAC,OAAO,YAAY,eAClB,OAAO,YAAY,UAAU,kBACrC;CAEA,gBAAgB;EACd,MAAM,2BACJ,SAAS,OAAO,YAAY,UAAU,kBAAkB;EAE1D,OAAO,iBAAiB,qBAAqB,kBAAkB;EAE/D,aACE,OAAO,oBAAoB,qBAAqB,kBAAkB;CACtE,GAAG,CAAC,CAAC;CAEL,OAAO;AACT;AAEA,SAAgB,YAAY,QAAoC;CAC9D,MAAM,oBAAoB,OAAO,cAAc,CAAC;CAChD,MAAM,qBAAqB,OAAO,YAAY,UAAU;CAExD,OAAO,aAAa;EAClB,GAAG;EACH,QAAQ;GACN,GAAG;GACH,GAAG;EACL;CACF;CACA,OAAO,cAAc,IAAI,YAAY,mBAAmB,CAAC;AAC3D;;;;ACrCA,SAAgB,kBACd,UACA,UAAiD,CAAC,GACzC;CACT,MAAM,UAAU;CAChB,IACE,OAAO,QAAQ,SAAS,cACxB,OAAO,QAAQ,oBAAoB,YAEnC,OAAO,IAAI,sBAAsB,SAA0B,OAAO;CAEpE,OAAO,IAAI,cAAc,QAAkB;AAC7C;AAUA,MAAM,mCAAmB,IAAI,QAAoC;AAEjE,SAAS,UACP,UACA,UAAqE,CAAC,GAClD;CACpB,IAAI,SAAS,iBAAiB,IAAI,QAAQ;CAC1C,IAAI,WAAW,KAAA,GAAW;EACxB,MAAM,4BAAY,IAAI,IAAoB;EAC1C,MAAM,UAA8B;GAClC;GACA,QAAQ,IAAI,OAAgB,EAC1B,SAAS,kBAAkB,UAAU;IACnC,GAAG;IACH,aAAa,UAAU;KACrB,QAAQ,WAAW;KACnB,KAA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