@powerhousedao/reactor-browser 6.2.3-dev.10 → 6.2.3-dev.100
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/{attachment-service-BW1v0OAT.d.ts → attachment-service-DXfpfp98.d.ts} +767 -108
- package/dist/attachment-service-DXfpfp98.d.ts.map +1 -0
- package/dist/auth-DzIYxeEJ.d.ts +32 -0
- package/dist/auth-DzIYxeEJ.d.ts.map +1 -0
- package/dist/client-1n_ZUXeu.js +135 -0
- package/dist/client-1n_ZUXeu.js.map +1 -0
- package/dist/{client-CxJD0Ck2.d.ts → client-BFk0MY6A.d.ts} +4 -3
- package/dist/client-BFk0MY6A.d.ts.map +1 -0
- package/dist/{client-DjK30EQ-.js → client-BFnMV-EO.js} +39 -22
- package/dist/client-BFnMV-EO.js.map +1 -0
- package/dist/dispatch-Cylwl2Dk.js +1173 -0
- package/dist/dispatch-Cylwl2Dk.js.map +1 -0
- package/dist/document-by-id-DdvqanGR.js +16 -0
- package/dist/document-by-id-DdvqanGR.js.map +1 -0
- package/dist/document-model-modules-BG-61uke.js +710 -0
- package/dist/document-model-modules-BG-61uke.js.map +1 -0
- package/dist/document-operations-D5QXcJbV.js +4609 -0
- package/dist/document-operations-D5QXcJbV.js.map +1 -0
- package/dist/global-DAAmZGCO.d.ts +612 -0
- package/dist/global-DAAmZGCO.d.ts.map +1 -0
- package/dist/{index-CBjFO54H.d.ts → index-Bj1poVfa.d.ts} +31 -100
- package/dist/index-Bj1poVfa.d.ts.map +1 -0
- package/dist/{index-BIVDXw3K.d.ts → index-rtDmzViP.d.ts} +3 -3
- package/dist/index-rtDmzViP.d.ts.map +1 -0
- package/dist/index.d.ts +907 -411
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +851 -306
- package/dist/index.js.map +1 -1
- package/dist/inspector-proxy-DODqs15F.d.ts +25 -0
- package/dist/inspector-proxy-DODqs15F.d.ts.map +1 -0
- package/dist/make-ph-event-functions-B5GU5xcR.js +180 -0
- package/dist/make-ph-event-functions-B5GU5xcR.js.map +1 -0
- package/dist/{pglite-CntadC_p-9NDG14dS.d.ts → pglite-CntadC_p-DTkdF8sr.d.ts} +11 -33
- package/dist/pglite-CntadC_p-DTkdF8sr.d.ts.map +1 -0
- package/dist/{relational-D1RB45sA.js → relational-DZuyKp2y.js} +66 -5
- package/dist/relational-DZuyKp2y.js.map +1 -0
- package/dist/{renown-rqK8sokh.js → renown-B3MUaiq7.js} +61 -31
- package/dist/renown-B3MUaiq7.js.map +1 -0
- package/dist/renown-CBoTdGrg.js +394 -0
- package/dist/renown-CBoTdGrg.js.map +1 -0
- package/dist/{types-N3Jy6Nry.d.ts → schema-Bn6L3QR1.d.ts} +255 -65
- package/dist/schema-Bn6L3QR1.d.ts.map +1 -0
- package/dist/{client-D4bkR4pH.js → schema-D0G1oAo9.js} +247 -152
- package/dist/schema-D0G1oAo9.js.map +1 -0
- package/dist/src/ai/index.d.ts +313 -79
- package/dist/src/ai/index.d.ts.map +1 -1
- package/dist/src/ai/index.js +1030 -173
- package/dist/src/ai/index.js.map +1 -1
- package/dist/src/analytics/index.d.ts +36 -44
- package/dist/src/analytics/index.d.ts.map +1 -1
- package/dist/src/analytics/index.js +4 -4
- package/dist/src/analytics/index.js.map +1 -1
- package/dist/src/document-model.d.ts +3 -4
- package/dist/src/document-model.d.ts.map +1 -1
- package/dist/src/document-model.js.map +1 -1
- package/dist/src/graphql/client.d.ts +4 -3
- package/dist/src/graphql/client.js +1 -1
- package/dist/src/graphql-client/entry.d.ts +7 -4
- package/dist/src/graphql-client/entry.js +4 -4
- package/dist/src/relational/index.d.ts +15 -9
- package/dist/src/relational/index.d.ts.map +1 -1
- package/dist/src/relational/index.js +1 -1
- package/dist/src/renown/index.d.ts +3 -2
- package/dist/src/renown/index.js +3 -3
- package/dist/src/rpc/index.d.ts +217 -140
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +600 -623
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/{store-BJYcr_FL.js → store-DInXcjal.js} +1 -1
- package/dist/{store-BJYcr_FL.js.map → store-DInXcjal.js.map} +1 -1
- package/dist/switchboard-directory-CWf5SRo7.js +435 -0
- package/dist/switchboard-directory-CWf5SRo7.js.map +1 -0
- package/dist/switchboards-D-_JBUbF.d.ts +75 -0
- package/dist/switchboards-D-_JBUbF.d.ts.map +1 -0
- package/dist/{types-6vDzbRRS.d.ts → types-520nWrB3.d.ts} +2 -2
- package/dist/types-520nWrB3.d.ts.map +1 -0
- package/dist/types-CyPDurGV.d.ts +63 -0
- package/dist/types-CyPDurGV.d.ts.map +1 -0
- package/package.json +24 -23
- package/dist/attachment-service-BW1v0OAT.d.ts.map +0 -1
- package/dist/client-CxJD0Ck2.d.ts.map +0 -1
- package/dist/client-D4bkR4pH.js.map +0 -1
- package/dist/client-DjK30EQ-.js.map +0 -1
- package/dist/document-by-id-B4FIzG1w.js +0 -519
- package/dist/document-by-id-B4FIzG1w.js.map +0 -1
- package/dist/document-model-modules-bTP87nyr.js +0 -419
- package/dist/document-model-modules-bTP87nyr.js.map +0 -1
- package/dist/document-operations-Cm4EtaZs.js +0 -2603
- package/dist/document-operations-Cm4EtaZs.js.map +0 -1
- package/dist/global-CgCouXuH.d.ts +0 -401
- package/dist/global-CgCouXuH.d.ts.map +0 -1
- package/dist/index-BIVDXw3K.d.ts.map +0 -1
- package/dist/index-CBjFO54H.d.ts.map +0 -1
- package/dist/inspector-proxy-6h5VKAwt.d.ts +0 -257
- package/dist/inspector-proxy-6h5VKAwt.d.ts.map +0 -1
- package/dist/make-ph-event-functions-DBq3iWYn.js +0 -53
- package/dist/make-ph-event-functions-DBq3iWYn.js.map +0 -1
- package/dist/pglite-CntadC_p-9NDG14dS.d.ts.map +0 -1
- package/dist/relational-D1RB45sA.js.map +0 -1
- package/dist/renown-BHxwP7xU.js +0 -97
- package/dist/renown-BHxwP7xU.js.map +0 -1
- package/dist/renown-rqK8sokh.js.map +0 -1
- package/dist/switchboard-CaXQ4-5Q.js +0 -271
- package/dist/switchboard-CaXQ4-5Q.js.map +0 -1
- package/dist/types-6vDzbRRS.d.ts.map +0 -1
- package/dist/types-N3Jy6Nry.d.ts.map +0 -1
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
//#region src/rpc/protocol.d.ts
|
|
2
|
-
type CorrelationId = string;
|
|
3
|
-
type ErrorInfo = {
|
|
4
|
-
name: string;
|
|
5
|
-
message: string;
|
|
6
|
-
stack?: string;
|
|
7
|
-
cause?: ErrorInfo;
|
|
8
|
-
};
|
|
9
|
-
type RpcRequest = {
|
|
10
|
-
k: "req";
|
|
11
|
-
id: CorrelationId;
|
|
12
|
-
method: string;
|
|
13
|
-
args: unknown[];
|
|
14
|
-
abortAt?: number;
|
|
15
|
-
};
|
|
16
|
-
type RpcResponse = {
|
|
17
|
-
k: "res";
|
|
18
|
-
id: CorrelationId;
|
|
19
|
-
value: unknown;
|
|
20
|
-
};
|
|
21
|
-
type RpcError = {
|
|
22
|
-
k: "err";
|
|
23
|
-
id: CorrelationId;
|
|
24
|
-
error: ErrorInfo;
|
|
25
|
-
};
|
|
26
|
-
/** Failed document subscribe; routed to the change-subscription registry. */
|
|
27
|
-
type RpcSubError = {
|
|
28
|
-
k: "sub-err";
|
|
29
|
-
id: CorrelationId;
|
|
30
|
-
error: ErrorInfo;
|
|
31
|
-
};
|
|
32
|
-
/** Failed live query; routed to the live-query registry. */
|
|
33
|
-
type RpcLiveError = {
|
|
34
|
-
k: "live-err";
|
|
35
|
-
id: CorrelationId;
|
|
36
|
-
error: ErrorInfo;
|
|
37
|
-
};
|
|
38
|
-
type RpcAbort = {
|
|
39
|
-
k: "abort";
|
|
40
|
-
targetId: CorrelationId;
|
|
41
|
-
};
|
|
42
|
-
type RpcSubscribe = {
|
|
43
|
-
k: "sub";
|
|
44
|
-
id: CorrelationId;
|
|
45
|
-
search: unknown;
|
|
46
|
-
view?: unknown;
|
|
47
|
-
};
|
|
48
|
-
type RpcEvent = {
|
|
49
|
-
k: "event";
|
|
50
|
-
id: CorrelationId;
|
|
51
|
-
change: unknown;
|
|
52
|
-
};
|
|
53
|
-
type RpcUnsub = {
|
|
54
|
-
k: "unsub";
|
|
55
|
-
id: CorrelationId;
|
|
56
|
-
};
|
|
57
|
-
type RpcNextPage = {
|
|
58
|
-
k: "page";
|
|
59
|
-
id: CorrelationId;
|
|
60
|
-
token: string;
|
|
61
|
-
};
|
|
62
|
-
declare const RPC_PROTOCOL_VERSION = 2;
|
|
63
|
-
type VersionFingerprint = {
|
|
64
|
-
appBuildId: string;
|
|
65
|
-
rpcProtocolVersion: number;
|
|
66
|
-
models: {
|
|
67
|
-
id: string;
|
|
68
|
-
version: number;
|
|
69
|
-
}[];
|
|
70
|
-
featureFlags?: string;
|
|
71
|
-
};
|
|
72
|
-
type RpcHello = {
|
|
73
|
-
k: "hello";
|
|
74
|
-
id: CorrelationId;
|
|
75
|
-
version: VersionFingerprint;
|
|
76
|
-
construct?: unknown;
|
|
77
|
-
packages?: string[];
|
|
78
|
-
};
|
|
79
|
-
type RpcRegisterPackages = {
|
|
80
|
-
k: "register-packages";
|
|
81
|
-
id: CorrelationId;
|
|
82
|
-
specs: string[];
|
|
83
|
-
};
|
|
84
|
-
type RpcUnregisterPackages = {
|
|
85
|
-
k: "unregister-packages";
|
|
86
|
-
id: CorrelationId;
|
|
87
|
-
names: string[];
|
|
88
|
-
};
|
|
89
|
-
type RpcReload = {
|
|
90
|
-
k: "reload";
|
|
91
|
-
reason: string;
|
|
92
|
-
workerGen?: string;
|
|
93
|
-
};
|
|
94
|
-
type RpcAdmin = {
|
|
95
|
-
k: "admin";
|
|
96
|
-
id: CorrelationId;
|
|
97
|
-
method: "info" | "restart" | "clearStorage" | "migrate";
|
|
98
|
-
};
|
|
99
|
-
type WorkerMigrationState = {
|
|
100
|
-
status: "idle" | "needed" | "migrating" | "failed";
|
|
101
|
-
legacyMajor?: number;
|
|
102
|
-
phase?: "clone" | "dump" | "restore";
|
|
103
|
-
error?: string;
|
|
104
|
-
};
|
|
105
|
-
type RpcMigration = {
|
|
106
|
-
k: "migration";
|
|
107
|
-
state: WorkerMigrationState;
|
|
108
|
-
};
|
|
109
|
-
type WorkerInspectorInfo = {
|
|
110
|
-
namespace: string;
|
|
111
|
-
ownerId: string;
|
|
112
|
-
bootedAtMs: number;
|
|
113
|
-
connectedClients: number;
|
|
114
|
-
appBuildId: string;
|
|
115
|
-
rpcProtocolVersion: number; /** Flags this worker is enforcing, from the fingerprint that built it. */
|
|
116
|
-
featureFlags?: string;
|
|
117
|
-
};
|
|
118
|
-
type ReactorIdentity = {
|
|
119
|
-
address: string;
|
|
120
|
-
chainId: number;
|
|
121
|
-
networkId: string;
|
|
122
|
-
};
|
|
123
|
-
type RpcIdentity = {
|
|
124
|
-
k: "identity";
|
|
125
|
-
user: ReactorIdentity | null;
|
|
126
|
-
};
|
|
127
|
-
type RpcBusEvent = {
|
|
128
|
-
k: "bus-event";
|
|
129
|
-
eventType: number;
|
|
130
|
-
event: unknown;
|
|
131
|
-
};
|
|
132
|
-
type OpKind = "sync-op" | "db-op" | "inspector-op";
|
|
133
|
-
type MethodCallMessage<K extends OpKind> = {
|
|
134
|
-
k: K;
|
|
135
|
-
id: CorrelationId;
|
|
136
|
-
method: string;
|
|
137
|
-
args: unknown[];
|
|
138
|
-
};
|
|
139
|
-
type RpcSyncOp = MethodCallMessage<"sync-op">;
|
|
140
|
-
type RpcDbOp = MethodCallMessage<"db-op">;
|
|
141
|
-
type RpcInspectorOp = MethodCallMessage<"inspector-op">;
|
|
142
|
-
type RpcLiveSubscribe = {
|
|
143
|
-
k: "sub-live";
|
|
144
|
-
id: CorrelationId;
|
|
145
|
-
sql: string;
|
|
146
|
-
params: unknown[];
|
|
147
|
-
};
|
|
148
|
-
type RpcLiveEvent = {
|
|
149
|
-
k: "event-live";
|
|
150
|
-
id: CorrelationId;
|
|
151
|
-
results: unknown;
|
|
152
|
-
};
|
|
153
|
-
type RpcLiveUnsub = {
|
|
154
|
-
k: "unsub-live";
|
|
155
|
-
id: CorrelationId;
|
|
156
|
-
};
|
|
157
|
-
type RpcPing = {
|
|
158
|
-
k: "ping";
|
|
159
|
-
id: CorrelationId;
|
|
160
|
-
};
|
|
161
|
-
type RpcPong = {
|
|
162
|
-
k: "pong";
|
|
163
|
-
id: CorrelationId;
|
|
164
|
-
ownerId: string;
|
|
165
|
-
bootedAtMs: number;
|
|
166
|
-
};
|
|
167
|
-
type ClientMessage = RpcRequest | RpcAbort | RpcSubscribe | RpcUnsub | RpcNextPage | RpcHello | RpcRegisterPackages | RpcUnregisterPackages | RpcIdentity | RpcAdmin | RpcSyncOp | RpcDbOp | RpcInspectorOp | RpcLiveSubscribe | RpcLiveUnsub | RpcPing;
|
|
168
|
-
type OwnerMessage = RpcResponse | RpcError | RpcSubError | RpcLiveError | RpcEvent | RpcReload | RpcBusEvent | RpcLiveEvent | RpcMigration | RpcPong;
|
|
169
|
-
type RpcMessage = ClientMessage | OwnerMessage;
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region src/rpc/rpc-correlator.d.ts
|
|
172
|
-
type RpcRequestOptions = {
|
|
173
|
-
/** Reject if no response arrives within this many ms; omit for no timeout. */timeoutMs?: number; /** Maps a successful response value (e.g. paged-result rehydration). */
|
|
174
|
-
transform?: (value: unknown) => unknown; /** Runs after the post; may return a cleanup invoked when the request settles. */
|
|
175
|
-
setup?: (id: CorrelationId) => (() => void) | void;
|
|
176
|
-
};
|
|
177
|
-
/** Anything that can send a client message (the router). */
|
|
178
|
-
type RpcPoster = {
|
|
179
|
-
post(message: ClientMessage): void;
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Request/response correlation shared by every RPC proxy: one pending map,
|
|
183
|
-
* res/err settlement, and per-request timeout/transform/cleanup.
|
|
184
|
-
*/
|
|
185
|
-
declare class RpcCorrelator {
|
|
186
|
-
private readonly poster;
|
|
187
|
-
private readonly prefix;
|
|
188
|
-
private counter;
|
|
189
|
-
private readonly pending;
|
|
190
|
-
constructor(poster: RpcPoster, prefix?: string);
|
|
191
|
-
nextId(): CorrelationId;
|
|
192
|
-
/** Settle the pending request a res/err refers to; a missing id is a no-op. */
|
|
193
|
-
handleMessage(message: OwnerMessage): void;
|
|
194
|
-
/** Send a request, resolving on its res/err. `build` stamps the generated id. */
|
|
195
|
-
request(build: (id: CorrelationId) => ClientMessage, options?: RpcRequestOptions): Promise<unknown>;
|
|
196
|
-
}
|
|
197
|
-
//#endregion
|
|
198
|
-
//#region src/rpc/transport.d.ts
|
|
199
|
-
interface IRpcTransport {
|
|
200
|
-
post(message: RpcMessage): void;
|
|
201
|
-
onMessage(listener: (message: RpcMessage) => void): () => void;
|
|
202
|
-
close(): void;
|
|
203
|
-
}
|
|
204
|
-
declare function createPortTransport(port: MessagePort): IRpcTransport;
|
|
205
|
-
//#endregion
|
|
206
|
-
//#region src/rpc/message-router.d.ts
|
|
207
|
-
type OwnerKind = OwnerMessage["k"];
|
|
208
|
-
/**
|
|
209
|
-
* Owns the single transport.onMessage and dispatches each message to the one
|
|
210
|
-
* consumer that owns its kind. Composes the shared RpcCorrelator (res/err) and
|
|
211
|
-
* exposes request/nextId; attach/detach swap the transport for reconnect.
|
|
212
|
-
*/
|
|
213
|
-
declare class MessageRouter {
|
|
214
|
-
private readonly handlers;
|
|
215
|
-
private readonly correlator;
|
|
216
|
-
private transport;
|
|
217
|
-
private detachTransport;
|
|
218
|
-
constructor(prefix?: string);
|
|
219
|
-
attach(transport: IRpcTransport): void;
|
|
220
|
-
detach(): void;
|
|
221
|
-
post(message: ClientMessage): void;
|
|
222
|
-
/** Register the sole owner of a message kind; throws on a duplicate. */
|
|
223
|
-
on<K extends OwnerKind>(kind: K, handler: (message: Extract<OwnerMessage, {
|
|
224
|
-
k: K;
|
|
225
|
-
}>) => void): () => void;
|
|
226
|
-
request(build: (id: CorrelationId) => ClientMessage, options?: RpcRequestOptions): Promise<unknown>;
|
|
227
|
-
nextId(): CorrelationId;
|
|
228
|
-
}
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/rpc/admin-client.d.ts
|
|
231
|
-
interface IWorkerAdminClient {
|
|
232
|
-
info(): Promise<WorkerInspectorInfo>;
|
|
233
|
-
restart(): Promise<void>;
|
|
234
|
-
clearStorage(): Promise<void>;
|
|
235
|
-
migrate(): Promise<void>;
|
|
236
|
-
getMigrationState(): WorkerMigrationState;
|
|
237
|
-
subscribeMigration(callback: () => void): () => void;
|
|
238
|
-
}
|
|
239
|
-
/** Worker lifecycle channel (info/restart/clearStorage/migrate) over the shared router. */
|
|
240
|
-
declare function createWorkerAdminClient(router: MessageRouter): IWorkerAdminClient;
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/rpc/inspector-proxy.d.ts
|
|
243
|
-
interface IInspectorProxy {
|
|
244
|
-
getQueueState(): Promise<unknown>;
|
|
245
|
-
pauseQueue(): Promise<void>;
|
|
246
|
-
resumeQueue(): Promise<void>;
|
|
247
|
-
getProcessors(): Promise<unknown>;
|
|
248
|
-
retryProcessor(processorId: string): Promise<void>;
|
|
249
|
-
validateDocument(documentId: string, branch?: string): Promise<unknown>;
|
|
250
|
-
rebuildKeyframes(documentId: string, branch?: string): Promise<unknown>;
|
|
251
|
-
rebuildSnapshots(documentId: string, branch?: string): Promise<unknown>;
|
|
252
|
-
queryReactorDb(sql: string, params?: unknown[]): Promise<unknown>;
|
|
253
|
-
}
|
|
254
|
-
declare function createInspectorProxy(router: MessageRouter): IInspectorProxy;
|
|
255
|
-
//#endregion
|
|
256
|
-
export { RpcMessage as C, WorkerMigrationState as E, RpcLiveUnsub as S, WorkerInspectorInfo as T, RPC_PROTOCOL_VERSION as _, MessageRouter as a, RpcLiveEvent as b, RpcCorrelator as c, ClientMessage as d, CorrelationId as f, OwnerMessage as g, OpKind as h, createWorkerAdminClient as i, RpcPoster as l, MethodCallMessage as m, createInspectorProxy as n, IRpcTransport as o, ErrorInfo as p, IWorkerAdminClient as r, createPortTransport as s, IInspectorProxy as t, RpcRequestOptions as u, ReactorIdentity as v, VersionFingerprint as w, RpcLiveSubscribe as x, RpcDbOp as y };
|
|
257
|
-
//# sourceMappingURL=inspector-proxy-6h5VKAwt.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inspector-proxy-6h5VKAwt.d.ts","names":[],"sources":["../src/rpc/protocol.ts","../src/rpc/rpc-correlator.ts","../src/rpc/transport.ts","../src/rpc/message-router.ts","../src/rpc/admin-client.ts","../src/rpc/inspector-proxy.ts"],"mappings":";KAAY,aAAA;AAAA,KAEA,SAAA;EACV,IAAA;EACA,OAAA;EACA,KAAA;EACA,KAAA,GAAQ,SAAA;AAAA;AAAA,KAGE,UAAA;EACV,CAAA;EACA,EAAA,EAAI,aAAA;EACJ,MAAA;EACA,IAAA;EACA,OAAA;AAAA;AAAA,KAGU,WAAA;EAAgB,CAAA;EAAU,EAAA,EAAI,aAAA;EAAe,KAAA;AAAA;AAAA,KAE7C,QAAA;EAAa,CAAA;EAAU,EAAA,EAAI,aAAA;EAAe,KAAA,EAAO,SAAA;AAAA;;KAGjD,WAAA;EAAgB,CAAA;EAAc,EAAA,EAAI,aAAA;EAAe,KAAA,EAAO,SAAA;AAAA;;KAGxD,YAAA;EACV,CAAA;EACA,EAAA,EAAI,aAAA;EACJ,KAAA,EAAO,SAAA;AAAA;AAAA,KAGG,QAAA;EAAa,CAAA;EAAY,QAAA,EAAU,aAAA;AAAA;AAAA,KAEnC,YAAA;EACV,CAAA;EACA,EAAA,EAAI,aAAA;EACJ,MAAA;EACA,IAAA;AAAA;AAAA,KAGU,QAAA;EAAa,CAAA;EAAY,EAAA,EAAI,aAAA;EAAe,MAAA;AAAA;AAAA,KAE5C,QAAA;EAAa,CAAA;EAAY,EAAA,EAAI,aAAA;AAAA;AAAA,KAE7B,WAAA;EAAgB,CAAA;EAAW,EAAA,EAAI,aAAA;EAAe,KAAA;AAAA;AAAA,cAI7C,oBAAA;AAAA,KAED,kBAAA;EACV,UAAA;EACA,kBA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alCase } from "change-case";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
//#region src/hooks/make-ph-event-functions.ts
|
|
4
|
-
const isServer = typeof window === "undefined";
|
|
5
|
-
function makePHEventFunctions(key) {
|
|
6
|
-
const setEventName = `ph:set${capitalCase(key)}`;
|
|
7
|
-
const updateEventName = `ph:${key}Updated`;
|
|
8
|
-
function setValue(value) {
|
|
9
|
-
if (isServer) return;
|
|
10
|
-
const event = new CustomEvent(setEventName, { detail: { [key]: value } });
|
|
11
|
-
window.dispatchEvent(event);
|
|
12
|
-
}
|
|
13
|
-
function dispatchUpdatedEvent() {
|
|
14
|
-
if (isServer) return;
|
|
15
|
-
const event = new CustomEvent(updateEventName);
|
|
16
|
-
window.dispatchEvent(event);
|
|
17
|
-
}
|
|
18
|
-
function handleSetValueEvent(event) {
|
|
19
|
-
if (isServer) return;
|
|
20
|
-
const value = event.detail[key];
|
|
21
|
-
if (!window.ph) window.ph = {};
|
|
22
|
-
window.ph[key] = value;
|
|
23
|
-
dispatchUpdatedEvent();
|
|
24
|
-
}
|
|
25
|
-
function addEventHandler() {
|
|
26
|
-
if (isServer) return;
|
|
27
|
-
window.addEventListener(setEventName, handleSetValueEvent);
|
|
28
|
-
}
|
|
29
|
-
function subscribeToValue(onStoreChange) {
|
|
30
|
-
if (isServer) return () => {};
|
|
31
|
-
window.addEventListener(updateEventName, onStoreChange);
|
|
32
|
-
return () => {
|
|
33
|
-
window.removeEventListener(updateEventName, onStoreChange);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function getSnapshot() {
|
|
37
|
-
if (isServer) return;
|
|
38
|
-
return window.ph?.[key];
|
|
39
|
-
}
|
|
40
|
-
function getServerSnapshot() {}
|
|
41
|
-
function useValue() {
|
|
42
|
-
return useSyncExternalStore(subscribeToValue, getSnapshot, getServerSnapshot);
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
useValue,
|
|
46
|
-
setValue,
|
|
47
|
-
addEventHandler
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
//#endregion
|
|
51
|
-
export { makePHEventFunctions as t };
|
|
52
|
-
|
|
53
|
-
//# sourceMappingURL=make-ph-event-functions-DBq3iWYn.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"make-ph-event-functions-DBq3iWYn.js","names":[],"sources":["../src/hooks/make-ph-event-functions.ts"],"sourcesContent":["import type {\n PHGlobal,\n PHGlobalKey,\n SetEvent,\n} from \"@powerhousedao/reactor-browser\";\nimport { capitalCase } from \"change-case\";\nimport { useSyncExternalStore } from \"react\";\n\n// guard condition for server side rendering\nconst isServer = typeof window === \"undefined\";\n\nexport function makePHEventFunctions<TKey extends PHGlobalKey>(key: TKey) {\n const setEventName = `ph:set${capitalCase(key)}` as const;\n const updateEventName = `ph:${key}Updated` as const;\n\n function setValue(value: PHGlobal[TKey] | undefined) {\n if (isServer) {\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 const value = event.detail[key];\n if (!window.ph) {\n window.ph = {};\n }\n window.ph[key] = value;\n dispatchUpdatedEvent();\n }\n\n function addEventHandler() {\n if (isServer) {\n return;\n }\n window.addEventListener(setEventName, handleSetValueEvent as EventListener);\n }\n\n function subscribeToValue(onStoreChange: () => void) {\n if (isServer) return () => {};\n window.addEventListener(updateEventName, onStoreChange);\n return () => {\n window.removeEventListener(updateEventName, onStoreChange);\n };\n }\n\n function getSnapshot() {\n if (isServer) {\n return undefined;\n }\n // The store is legitimately read before the first `setValue` (subscribers\n // mount before init runs), so an uninitialized store is expected, not an\n // error — return `undefined` quietly rather than warning on every render.\n return window.ph?.[key];\n }\n\n function getServerSnapshot() {\n return undefined;\n }\n\n function useValue() {\n return useSyncExternalStore(\n subscribeToValue,\n getSnapshot,\n getServerSnapshot,\n );\n }\n\n return {\n useValue,\n setValue,\n addEventHandler,\n };\n}\n"],"mappings":";;;AASA,MAAM,WAAW,OAAO,WAAW;AAEnC,SAAgB,qBAA+C,KAAW;CACxE,MAAM,eAAe,SAAS,YAAY,IAAI;CAC9C,MAAM,kBAAkB,MAAM,IAAI;CAElC,SAAS,SAAS,OAAmC;AACnD,MAAI,SACF;EAEF,MAAM,QAAQ,IAAI,YAAY,cAAc,EAC1C,QAAQ,GAAG,MAAM,OAAO,EACzB,CAAC;AACF,SAAO,cAAc,MAAM;;CAG7B,SAAS,uBAAuB;AAC9B,MAAI,SACF;EAEF,MAAM,QAAQ,IAAI,YAAY,gBAAgB;AAC9C,SAAO,cAAc,MAAM;;CAG7B,SAAS,oBAAoB,OAAuB;AAClD,MAAI,SACF;EAEF,MAAM,QAAQ,MAAM,OAAO;AAC3B,MAAI,CAAC,OAAO,GACV,QAAO,KAAK,EAAE;AAEhB,SAAO,GAAG,OAAO;AACjB,wBAAsB;;CAGxB,SAAS,kBAAkB;AACzB,MAAI,SACF;AAEF,SAAO,iBAAiB,cAAc,oBAAqC;;CAG7E,SAAS,iBAAiB,eAA2B;AACnD,MAAI,SAAU,cAAa;AAC3B,SAAO,iBAAiB,iBAAiB,cAAc;AACvD,eAAa;AACX,UAAO,oBAAoB,iBAAiB,cAAc;;;CAI9D,SAAS,cAAc;AACrB,MAAI,SACF;AAKF,SAAO,OAAO,KAAK;;CAGrB,SAAS,oBAAoB;CAI7B,SAAS,WAAW;AAClB,SAAO,qBACL,kBACA,aACA,kBACD;;AAGH,QAAO;EACL;EACA;EACA;EACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pglite-CntadC_p-9NDG14dS.d.ts","names":["Modes","text","binary","Mode","BufferParameter","ArrayBuffer","ArrayBufferView","MessageName","BackendMessage","name","length","parseComplete","bindComplete","closeComplete","noData","portalSuspended","replicationStart","emptyQuery","copyDone","AuthenticationOk","constructor","AuthenticationCleartextPassword","AuthenticationMD5Password","Uint8Array","salt","AuthenticationSASL","mechanisms","AuthenticationSASLContinue","data","AuthenticationSASLFinal","AuthenticationMessage","NoticeOrError","message","severity","code","detail","hint","position","internalPosition","internalQuery","where","schema","table","column","dataType","constraint","file","line","routine","DatabaseError","Error","CopyDataMessage","chunk","CopyResponse","columnTypes","columnCount","Field","tableID","columnID","dataTypeID","dataTypeSize","dataTypeModifier","format","RowDescriptionMessage","fieldCount","fields","ParameterDescriptionMessage","parameterCount","dataTypeIDs","ParameterStatusMessage","parameterName","parameterValue","BackendKeyDataMessage","processID","secretKey","NotificationResponseMessage","processId","channel","payload","ReadyForQueryMessage","status","CommandCompleteMessage","DataRowMessage","NoticeMessage","messages_AuthenticationCleartextPassword","messages_AuthenticationMD5Password","messages_AuthenticationMessage","messages_AuthenticationOk","messages_AuthenticationSASL","messages_AuthenticationSASLContinue","messages_AuthenticationSASLFinal","messages_BackendKeyDataMessage","messages_BackendMessage","messages_CommandCompleteMessage","messages_CopyDataMessage","messages_CopyResponse","messages_DataRowMessage","messages_DatabaseError","messages_Field","messages_MessageName","messages_NoticeMessage","messages_NotificationResponseMessage","messages_ParameterDescriptionMessage","messages_ParameterStatusMessage","messages_ReadyForQueryMessage","messages_RowDescriptionMessage","messages_bindComplete","messages_closeComplete","messages_copyDone","messages_emptyQuery","messages_noData","messages_parseComplete","messages_portalSuspended","messages_replicationStart","messages","IDBFS","Emscripten","FileSystemType","IDBDatabase","Record","quit","dbs","FS","filesystems","MEMFS","NODEFS","PostgresMod","EmscriptenModule","Array","Blob","Promise","Omit","preInit","mod","preRun","postRun","FD_BUFFER_MAX","WASM_PREFIX","INITIAL_MEMORY","pg_extensions","_pgl_initdb","_pgl_backend","_pgl_shutdown","_interactive_write","msgLength","_interactive_one","peek","_set_read_write_cbs","read_cb","write_cb","addFunction","ptr","cb","signature","removeFunction","f","PostgresFactory","T","Partial","moduleOverrides","_default","postgresMod_FS","postgresMod_PostgresMod","postgresMod","default","DumpTarCompressionOptions","PGDATA","FsType","Filesystem","PGlite","File","init","pg","emscriptenOptions","emscriptenOpts","syncToFs","relaxedDurability","initialSyncFs","dumpTar","dbname","compression","closeFs","EmscriptenBuiltinFilesystem","dataDir","_relaxedDurability","BaseFilesystem","debug","FsStats","chmod","path","mode","close","fd","fstat","lstat","mkdir","recursive","options","open","flags","readdir","read","buffer","offset","rename","oldPath","newPath","rmdir","truncate","len","unlink","utimes","atime","mtime","writeFile","encoding","flag","write","dev","ino","nlink","uid","gid","rdev","size","blksize","blocks","ctime","ERRNO_CODES","EBADF","EBADFD","EEXIST","EINVAL","EISDIR","ENODEV","ENOENT","ENOTDIR","ENOTEMPTY","FilesystemType","DebugLevel","RowMode","ParserOptions","pgType","value","SerializerOptions","QueryOptions","rowMode","parsers","serializers","blob","onNotice","notice","paramTypes","ExecProtocolOptions","throwOnError","ExtensionSetupResult","TNamespace","URL","namespaceObj","bundlePath","ExtensionSetup","PGliteInterface","clientOnly","Extension","setup","ExtensionNamespace","Extensions","namespace","InitializedExtensions","TExtensions","K","ExecProtocolResult","DumpDataDirResult","tarball","extension","filename","PGliteOptions","WebAssembly","Module","username","database","fs","extensions","loadDataDir","initialMemory","wasmModule","fsBundle","Results","TemplateStringsArray","DescribeQueryResult","Transaction","waitReady","ready","closed","query","params","sql","sqlStrings","exec","describeQuery","transaction","tx","callback","execProtocolRaw","execProtocol","runExclusive","fn","listen","unlisten","onNotification","offNotification","dumpDataDir","refreshArrayTypes","PGliteInterfaceExtensions","E","ReturnType","Awaited","N","Row","key","rows","affectedRows","rollback","Serializer","Parser","queryParams","serializer","resultFields","parser","BOOL","BYTEA","CHAR","INT8","INT2","INT4","REGPROC","TEXT","OID","TID","XID","CID","JSON","XML","PG_NODE_TREE","SMGR","PATH","POLYGON","CIDR","FLOAT4","FLOAT8","ABSTIME","RELTIME","TINTERVAL","CIRCLE","MACADDR8","MONEY","MACADDR","INET","ACLITEM","BPCHAR","VARCHAR","DATE","TIME","TIMESTAMP","TIMESTAMPTZ","INTERVAL","TIMETZ","BIT","VARBIT","NUMERIC","REFCURSOR","REGPROCEDURE","REGOPER","REGOPERATOR","REGCLASS","REGTYPE","UUID","TXID_SNAPSHOT","PG_LSN","PG_NDISTINCT","PG_DEPENDENCIES","TSVECTOR","TSQUERY","GTSVECTOR","REGCONFIG","REGDICTIONARY","JSONB","REGNAMESPACE","REGROLE","types","Date","string","to","from","serialize","x","parse","number","bigint","json","boolean","date","bytea","typeId","TypeHandler","TypeHandlers","parseType","type","arraySerializer","xs","typarray","arrayParser","types$1_ABSTIME","types$1_ACLITEM","types$1_BIT","types$1_BOOL","types$1_BPCHAR","types$1_BYTEA","types$1_CHAR","types$1_CID","types$1_CIDR","types$1_CIRCLE","types$1_DATE","types$1_FLOAT4","types$1_FLOAT8","types$1_GTSVECTOR","types$1_INET","types$1_INT2","types$1_INT4","types$1_INT8","types$1_INTERVAL","types$1_JSON","types$1_JSONB","types$1_MACADDR","types$1_MACADDR8","types$1_MONEY","types$1_NUMERIC","types$1_OID","types$1_PATH","types$1_PG_DEPENDENCIES","types$1_PG_LSN","types$1_PG_NDISTINCT","types$1_PG_NODE_TREE","types$1_POLYGON","types$1_Parser","types$1_REFCURSOR","types$1_REGCLASS","types$1_REGCONFIG","types$1_REGDICTIONARY","types$1_REGNAMESPACE","types$1_REGOPER","types$1_REGOPERATOR","types$1_REGPROC","types$1_REGPROCEDURE","types$1_REGROLE","types$1_REGTYPE","types$1_RELTIME","types$1_SMGR","types$1_Serializer","types$1_TEXT","types$1_TID","types$1_TIME","types$1_TIMESTAMP","types$1_TIMESTAMPTZ","types$1_TIMETZ","types$1_TINTERVAL","types$1_TSQUERY","types$1_TSVECTOR","types$1_TXID_SNAPSHOT","types$1_TypeHandler","types$1_TypeHandlers","types$1_UUID","types$1_VARBIT","types$1_VARCHAR","types$1_XID","types$1_XML","types$1_arrayParser","types$1_arraySerializer","types$1_parseType","types$1_parsers","types$1_serializers","types$1_types","types$1","BasePGlite","force","Pick","private","execProtocolStream","_handleBlob","_getWrittenBlob","_cleanupBlob","_checkReady","_runExclusiveQuery","_runExclusiveTransaction","_initArrayTypes","O","Symbol","asyncDispose","AsyncDisposable","DEFAULT_RECV_BUF_SIZE","MAX_BUFFER_SIZE","create","execProtocolRawSync","isInTransaction","clone","_runExclusiveListen","A","B","C","D","F","G","I","M","P","Q","R","S","W","a","b","c","d","e","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","y","z"],"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":";KAOKO,WAAAA;AAAAA,KACAC,cAAAA;EACDC,IAAAA,EAAMF,WAAAA;EACNG,MAAAA;AAAAA;AAAAA,UA6CMqB,aAAAA;EACNC,OAAAA;EACAC,QAAAA;EACAC,IAAAA;EACAC,MAAAA;EACAC,IAAAA;EACAC,QAAAA;EACAC,gBAAAA;EACAC,aAAAA;EACAC,KAAAA;EACAC,MAAAA;EACAC,KAAAA;EACAC,MAAAA;EACAC,QAAAA;EACAC,UAAAA;EACAC,IAAAA;EACAC,IAAAA;EACAC,OAAAA;AAAAA;AAAAA,cAqGUmC,aAAAA,YAAyB3E,cAAAA,EAAgBuB,aAAAA;EAAAA,SAC1CrB,MAAAA;EAAAA,SACAsB,OAAAA;EACTZ,WAAAA,CAAYV,MAAAA,UAAgBsB,OAAAA;EAAAA,SACnBvB,IAAAA;EACTwB,QAAAA;EACAC,IAAAA;EACAC,MAAAA;EACAC,IAAAA;EACAC,QAAAA;EACAC,gBAAAA;EACAC,aAAAA;EACAC,KAAAA;EACAC,MAAAA;EACAC,KAAAA;EACAC,MAAAA;EACAC,QAAAA;EACAC,UAAAA;EACAC,IAAAA;EACAC,IAAAA;EACAC,OAAAA;AAAAA;AAAAA,KAwDCmE,KAAAA,GAAQC,UAAAA,CAAWC,cAAAA;EACpBG,IAAAA;EAC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,CAA4B3L,EAAAA,QAAUhL,OAAAA,CAAQ2B,CAAAA,IAAK3B,OAAAA,CAAQ2B,CAAAA;EAC3D2V,KAAAA,CAAAA,GAAStX,OAAAA,CAAQmI,eAAAA;EACjBoP,mBAAAA,GAAAA,CAAuBvM,EAAAA,QAAUhL,OAAAA,CAAQ2B,CAAAA,IAAK3B,OAAAA,CAAQ2B,CAAAA;AAAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relational-D1RB45sA.js","names":[],"sources":["../src/pglite/usePGlite.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 type { LiveNamespace, PGliteWithLive } from \"@electric-sql/pglite/live\";\nimport { createRelationalDb } from \"@powerhousedao/reactor\";\nimport type { IRelationalDb as IRelationalDbCore } from \"@powerhousedao/shared/processors\";\nimport { Kysely } from \"kysely\";\nimport { PGliteDialect } from \"kysely-pglite-dialect\";\nimport { useMemo } from \"react\";\nimport { usePGliteDB } from \"../../pglite/usePGlite.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 = new Kysely<Schema>({\n dialect: new PGliteDialect(pgliteInstance as unknown as PGlite),\n });\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 const useRelationalDb = <Schema>(): IRelationalDbState<Schema> => {\n const pglite = usePGliteDB();\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 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;CACR;AAED,MAAa,oBAAoB;CAC/B,MAAM,CAAC,OAAO,YAAY,eAClB,OAAO,YAAY,UAAU,mBACpC;AAED,iBAAgB;EACd,MAAM,2BACJ,SAAS,OAAO,YAAY,UAAU,mBAAmB;AAE3D,SAAO,iBAAiB,qBAAqB,mBAAmB;AAEhE,eACE,OAAO,o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B,qBACd,gBACA;CAqCA,SAAS,SAOP,SACA,eACA,YACA,SAOA;EAKA,MAAM,eAAe,gBAAgB,WAAW;AAKhD,SAAO,mBACL,gBACA,SAJuB,YAAY,eAAe,CAAC,aAAa,CAAC,EAMjE,cACA,QACD;;AAOH,QAAO"}
|
package/dist/renown-BHxwP7xU.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { t as makePHEventFunctions } from "./make-ph-event-functions-DBq3iWYn.js";
|
|
2
|
-
import { createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
//#region src/hooks/loading.ts
|
|
5
|
-
const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
|
|
6
|
-
const loading = null;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/renown/initial-user.tsx
|
|
9
|
-
const RENOWN_INITIAL_UNKNOWN = { state: "unknown" };
|
|
10
|
-
const RENOWN_INITIAL_ANONYMOUS = { state: "anonymous" };
|
|
11
|
-
const RenownInitialUserContext = createContext(RENOWN_INITIAL_UNKNOWN);
|
|
12
|
-
function RenownInitialUserProvider({ initialAuth, initialUser, children }) {
|
|
13
|
-
const value = initialAuth ?? (initialUser ? {
|
|
14
|
-
state: "authenticated",
|
|
15
|
-
user: initialUser
|
|
16
|
-
} : RENOWN_INITIAL_UNKNOWN);
|
|
17
|
-
return /* @__PURE__ */ jsx(RenownInitialUserContext.Provider, {
|
|
18
|
-
value,
|
|
19
|
-
children
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/** First-render auth as a three-state value; use this to skip a spinner when anonymous. */
|
|
23
|
-
function useRenownInitialAuth() {
|
|
24
|
-
return useContext(RenownInitialUserContext);
|
|
25
|
-
}
|
|
26
|
-
function useRenownInitialUser() {
|
|
27
|
-
const initial = useRenownInitialAuth();
|
|
28
|
-
return initial.state === "authenticated" ? initial.user : void 0;
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/hooks/renown.ts
|
|
32
|
-
const renownEventFunctions = makePHEventFunctions("renown");
|
|
33
|
-
/** Adds an event handler for the renown instance */
|
|
34
|
-
const addRenownEventHandler = renownEventFunctions.addEventHandler;
|
|
35
|
-
/** Returns the renown instance */
|
|
36
|
-
const useRenown = renownEventFunctions.useValue;
|
|
37
|
-
/** Sets the renown instance */
|
|
38
|
-
const setRenown = renownEventFunctions.setValue;
|
|
39
|
-
/** Returns the DID from the renown instance */
|
|
40
|
-
function useDid() {
|
|
41
|
-
return useRenown()?.did;
|
|
42
|
-
}
|
|
43
|
-
function jsonEqual(a, b) {
|
|
44
|
-
if (a === b) return true;
|
|
45
|
-
if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
|
|
46
|
-
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
47
|
-
const ra = a;
|
|
48
|
-
const rb = b;
|
|
49
|
-
const keys = Object.keys(ra).filter((k) => ra[k] !== void 0);
|
|
50
|
-
if (keys.length !== Object.keys(rb).filter((k) => rb[k] !== void 0).length) return false;
|
|
51
|
-
return keys.every((k) => jsonEqual(ra[k], rb[k]));
|
|
52
|
-
}
|
|
53
|
-
function sameUser(a, b) {
|
|
54
|
-
return jsonEqual(a, b);
|
|
55
|
-
}
|
|
56
|
-
function resolveInstanceUser(instance, seed) {
|
|
57
|
-
const restored = instance.user;
|
|
58
|
-
if (restored) return sameUser(seed, restored) ? seed : restored;
|
|
59
|
-
return instance.status === "initial" ? void 0 : seed;
|
|
60
|
-
}
|
|
61
|
-
/** Returns the current user from the renown instance, subscribing to user events */
|
|
62
|
-
function useUser() {
|
|
63
|
-
const renown = useRenown();
|
|
64
|
-
const initialUser = useRenownInitialUser();
|
|
65
|
-
const instance = renown ? renown : void 0;
|
|
66
|
-
const [tracked, setTracked] = useState(() => ({
|
|
67
|
-
instance,
|
|
68
|
-
user: instance ? resolveInstanceUser(instance, initialUser) : initialUser
|
|
69
|
-
}));
|
|
70
|
-
const current = tracked.instance === instance ? tracked : {
|
|
71
|
-
instance,
|
|
72
|
-
user: instance ? resolveInstanceUser(instance, tracked.user ?? initialUser) : tracked.user
|
|
73
|
-
};
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
if (current !== tracked) setTracked(current);
|
|
76
|
-
}, [current, tracked]);
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!instance) return;
|
|
79
|
-
return instance.on("user", (user) => setTracked((prev) => ({
|
|
80
|
-
instance,
|
|
81
|
-
user: sameUser(prev.user, user) ? prev.user : user
|
|
82
|
-
})));
|
|
83
|
-
}, [instance]);
|
|
84
|
-
return instance ? current.user : initialUser ?? current.user;
|
|
85
|
-
}
|
|
86
|
-
/** Returns the login status, subscribing to renown status events */
|
|
87
|
-
function useLoginStatus() {
|
|
88
|
-
const renown = useRenown();
|
|
89
|
-
return useSyncExternalStore((cb) => {
|
|
90
|
-
if (!renown) return () => {};
|
|
91
|
-
return renown.on("status", cb);
|
|
92
|
-
}, () => renown === null ? "loading" : renown?.status, () => void 0);
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
95
|
-
export { useRenown as a, RENOWN_INITIAL_UNKNOWN as c, useRenownInitialUser as d, addLoadingEventHandler as f, useLoading as h, useLoginStatus as i, RenownInitialUserProvider as l, setLoading as m, setRenown as n, useUser as o, loading as p, useDid as r, RENOWN_INITIAL_ANONYMOUS as s, addRenownEventHandler as t, useRenownInitialAuth as u };
|
|
96
|
-
|
|
97
|
-
//# sourceMappingURL=renown-BHxwP7xU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"renown-BHxwP7xU.js","names":[],"sources":["../src/hooks/loading.ts","../src/renown/initial-user.tsx","../src/hooks/renown.ts"],"sourcesContent":["import type { LOADING } from \"../types/global.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nexport const {\n useValue: useLoading,\n setValue: setLoading,\n addEventHandler: addLoadingEventHandler,\n} = makePHEventFunctions(\"loading\");\n\nexport const loading: LOADING = null;\n","\"use client\";\n\nimport type { User } from \"@renown/sdk\";\nimport { createContext, useContext, type ReactNode } from \"react\";\n\n/** Whether the first render already knows who (if anyone) is signed in. */\n// \"anonymous\" is load-bearing: it separates a signed-out visitor from an\n// unresolved one, which otherwise both have to render a spinner.\nexport type RenownInitialAuth =\n | { state: \"authenticated\"; user: User }\n | { state: \"anonymous\" }\n | { state: \"unknown\" };\n\nexport const RENOWN_INITIAL_UNKNOWN: RenownInitialAuth = { state: \"unknown\" };\nexport const RENOWN_INITIAL_ANONYMOUS: RenownInitialAuth = {\n state: \"anonymous\",\n};\n\n// Seeds the auth store's first render (server + hydration) from a session\n// cookie or localStorage, enabling authenticated SSR without a flash.\nconst RenownInitialUserContext = createContext<RenownInitialAuth>(\n RENOWN_INITIAL_UNKNOWN,\n);\n\nexport interface RenownInitialUserProviderProps {\n /** Resolved first-render auth (see `RenownProvider`). Takes precedence over `initialUser`. */\n initialAuth?: RenownInitialAuth;\n /** User resolved from a verified session cookie (see `verifyRenownSession`). */\n initialUser?: User;\n children: ReactNode;\n}\n\nexport function RenownInitialUserProvider({\n initialAuth,\n initialUser,\n children,\n}: RenownInitialUserProviderProps) {\n // `initialUser` alone cannot express \"anonymous\" — absence stays \"unknown\".\n const value =\n initialAuth ??\n (initialUser\n ? { state: \"authenticated\" as const, user: initialUser }\n : RENOWN_INITIAL_UNKNOWN);\n return (\n <RenownInitialUserContext.Provider value={value}>\n {children}\n </RenownInitialUserContext.Provider>\n );\n}\n\n/** First-render auth as a three-state value; use this to skip a spinner when anonymous. */\nexport function useRenownInitialAuth(): RenownInitialAuth {\n return useContext(RenownInitialUserContext);\n}\n\nexport function useRenownInitialUser(): User | undefined {\n const initial = useRenownInitialAuth();\n return initial.state === \"authenticated\" ? initial.user : undefined;\n}\n","import type { IRenown, LoginStatus, User } from \"@renown/sdk\";\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\nimport { useRenownInitialUser } from \"../renown/initial-user.js\";\nimport type { LOADING } from \"../types/global.js\";\nimport { loading } from \"./loading.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nconst renownEventFunctions = makePHEventFunctions(\"renown\");\n\n/** Adds an event handler for the renown instance */\nexport const addRenownEventHandler: () => void =\n renownEventFunctions.addEventHandler;\n\n/** Returns the renown instance */\nexport const useRenown: () => IRenown | LOADING | undefined =\n renownEventFunctions.useValue;\n\n/** Sets the renown instance */\nexport const setRenown: (value: IRenown | LOADING | undefined) => void =\n renownEventFunctions.setValue;\n\n/** Returns the DID from the renown instance */\nexport function useDid() {\n const renown = useRenown();\n return renown?.did;\n}\n\n// Order-insensitive structural equality for plain JSON (what a persisted user\n// is): the cookie and localStorage paths build the same user with different key\n// order, and both must keep one object identity for did-keyed consumers.\nfunction jsonEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (typeof a !== \"object\" || typeof b !== \"object\" || !a || !b) return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n const ra = a as Record<string, unknown>;\n const rb = b as Record<string, unknown>;\n const keys = Object.keys(ra).filter((k) => ra[k] !== undefined);\n if (keys.length !== Object.keys(rb).filter((k) => rb[k] !== undefined).length)\n return false;\n return keys.every((k) => jsonEqual(ra[k], rb[k]));\n}\n\nfunction sameUser(a: User | undefined, b: User | undefined): boolean {\n return jsonEqual(a, b);\n}\n\n// What the SDK says once it exists. Its `user` is a synchronous storage read,\n// so undefined with status \"initial\" means nothing was restored and a stale seed\n// (e.g. a cookie outliving localStorage) must go; during \"checking\"/\"authorized\"\n// the SDK owns a session it has not published yet, so the seed stands.\nfunction resolveInstanceUser(\n instance: IRenown,\n seed: User | undefined,\n): User | undefined {\n const restored = instance.user;\n if (restored) return sameUser(seed, restored) ? seed : restored;\n return instance.status === \"initial\" ? undefined : seed;\n}\n\ninterface TrackedUser {\n instance: IRenown | undefined;\n user: User | undefined;\n}\n\n/** Returns the current user from the renown instance, subscribing to user events */\nexport function useUser(): User | undefined {\n const renown = useRenown();\n // Seed (cookie on the server, localStorage once mounted) covers the first\n // paint; the SDK is authoritative after, so a logout/revoke clears it.\n const initialUser = useRenownInitialUser();\n const instance = renown ? renown : undefined;\n // Tagged with the instance it came from. On a swap the value for this render\n // is derived here (state alone would be one frame stale) and persisted after\n // commit; the derivation is pure, so re-renders before that agree.\n const [tracked, setTracked] = useState<TrackedUser>(() => ({\n instance,\n user: instance ? resolveInstanceUser(instance, initialUser) : initialUser,\n }));\n const current: TrackedUser =\n tracked.instance === instance\n ? tracked\n : {\n instance,\n user: instance\n ? resolveInstanceUser(instance, tracked.user ?? initialUser)\n : tracked.user,\n };\n\n useEffect(() => {\n if (current !== tracked) setTracked(current);\n }, [current, tracked]);\n\n useEffect(() => {\n if (!instance) return;\n return instance.on(\"user\", (user) =>\n setTracked((prev) => ({\n instance,\n user: sameUser(prev.user, user) ? prev.user : user,\n })),\n );\n }, [instance]);\n\n // Until the SDK exists the seed wins, which is what lands the post-mount\n // localStorage read.\n return instance ? current.user : (initialUser ?? current.user);\n}\n\n/** Returns the login status, subscribing to renown status events */\nexport function useLoginStatus(): LoginStatus | \"loading\" | undefined {\n const renown = useRenown();\n return useSyncExternalStore(\n (cb) => {\n if (!renown) {\n return () => {};\n }\n return renown.on(\"status\", cb);\n },\n () => (renown === loading ? \"loading\" : renown?.status),\n () => undefined,\n );\n}\n"],"mappings":";;;;AAGA,MAAa,EACX,UAAU,YACV,UAAU,YACV,iBAAiB,2BACf,qBAAqB,UAAU;AAEnC,MAAa,UAAmB;;;ACIhC,MAAa,yBAA4C,EAAE,OAAO,WAAW;AAC7E,MAAa,2BAA8C,EACzD,OAAO,aACR;AAID,MAAM,2BAA2B,cAC/B,uBACD;AAUD,SAAgB,0BAA0B,EACxC,aACA,aACA,YACiC;CAEjC,MAAM,QACJ,gBACC,cACG;EAAE,OAAO;EAA0B,MAAM;EAAa,GACtD;AACN,QACE,oBAAC,yBAAyB,UAA1B;EAA0C;EACvC;EACiC,CAAA;;;AAKx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