@live-state/sync 0.0.6 → 0.0.7-canary-1

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.
@@ -1,520 +0,0 @@
1
- import { z } from 'zod';
2
- import { StandardSchemaV1 } from '@standard-schema/spec';
3
-
4
- type LiveTypeMeta = {};
5
- type MutationType = "set";
6
- type StorageFieldType = {
7
- type: string;
8
- nullable: boolean;
9
- default?: any;
10
- unique?: boolean;
11
- index?: boolean;
12
- primary?: boolean;
13
- references?: string;
14
- };
15
- declare abstract class LiveType<Value = any, Meta extends LiveTypeMeta = LiveTypeMeta, EncodeInput = Partial<Value> | Value, DecodeInput = {
16
- value: Value;
17
- _meta: keyof Meta extends never ? never : Meta;
18
- }> {
19
- readonly _value: Value;
20
- readonly _meta: Meta;
21
- readonly _encodeInput: EncodeInput;
22
- readonly _decodeInput: DecodeInput;
23
- abstract encodeMutation(mutationType: MutationType, input: EncodeInput, timestamp: string): DecodeInput;
24
- /**
25
- * Merges the materialized shape with the encoded mutation
26
- * @param mutationType The type of mutation
27
- * @param encodedMutation The encoded mutation
28
- * @param materializedShape The materialized shape
29
- * @returns A tuple of the new materialized shape and the accepted diff
30
- */
31
- abstract mergeMutation(mutationType: MutationType, encodedMutation: DecodeInput, materializedShape?: MaterializedLiveType<LiveType<Value, Meta>>): [MaterializedLiveType<LiveType<Value, Meta>>, DecodeInput | null];
32
- abstract getStorageFieldType(): StorageFieldType;
33
- }
34
- type LiveTypeAny = LiveType<any, LiveTypeMeta, any, any>;
35
- type InferLiveType<T extends LiveTypeAny> = T["_value"] extends Record<string, LiveTypeAny> ? {
36
- [K in keyof T["_value"]]: InferLiveType<T["_value"][K]>;
37
- } : T["_value"];
38
- type InferIndex<T extends LiveTypeAny> = string;
39
-
40
- declare class NullableLiveType<T extends LiveTypeAny> extends LiveType<T["_value"] | null, T["_meta"], T["_encodeInput"], T["_decodeInput"]> {
41
- readonly inner: T;
42
- constructor(inner: T);
43
- encodeMutation(mutationType: MutationType, input: T["_value"] | null, timestamp: string): T["_decodeInput"];
44
- mergeMutation(mutationType: MutationType, encodedMutation: T["_decodeInput"], materializedShape?: MaterializedLiveType<LiveType<T["_value"] | null, T["_meta"], T["_value"] | Partial<T["_value"] | null>, T["_decodeInput"]>> | undefined): [
45
- MaterializedLiveType<LiveType<T["_value"] | null, T["_meta"], T["_value"] | Partial<T["_value"] | null>, T["_decodeInput"]>>,
46
- T["_decodeInput"] | null
47
- ];
48
- getStorageFieldType(): StorageFieldType;
49
- }
50
- type LiveAtomicTypeMeta = {
51
- timestamp: string | null;
52
- } & LiveTypeMeta;
53
- declare class LiveAtomicType<Value, DefaultValue = undefined> extends LiveType<Value, LiveAtomicTypeMeta, Value, {
54
- value: Value;
55
- _meta: LiveAtomicTypeMeta;
56
- }> {
57
- readonly storageType: string;
58
- readonly convertFunc?: (value: any) => Value;
59
- readonly isIndex: boolean;
60
- readonly isUnique: boolean;
61
- readonly defaultValue: DefaultValue;
62
- readonly foreignReference?: string;
63
- readonly isPrimary: boolean;
64
- constructor(storageType: string, convertFunc?: (value: any) => Value, index?: boolean, unique?: boolean, defaultValue?: DefaultValue, references?: string, primary?: boolean);
65
- encodeMutation(mutationType: MutationType, input: Value, timestamp: string): {
66
- value: Value;
67
- _meta: LiveAtomicTypeMeta;
68
- };
69
- mergeMutation(mutationType: MutationType, encodedMutation: {
70
- value: Value;
71
- _meta: LiveAtomicTypeMeta;
72
- }, materializedShape?: MaterializedLiveType<LiveType<Value, LiveAtomicTypeMeta, Value | Partial<Value>, {
73
- value: Value;
74
- _meta: LiveAtomicTypeMeta;
75
- }>>): [
76
- MaterializedLiveType<LiveType<Value, LiveAtomicTypeMeta, Value | Partial<Value>, {
77
- value: Value;
78
- _meta: LiveAtomicTypeMeta;
79
- }>>,
80
- {
81
- value: Value;
82
- _meta: LiveAtomicTypeMeta;
83
- } | null
84
- ];
85
- getStorageFieldType(): StorageFieldType;
86
- unique(): LiveAtomicType<Value, undefined>;
87
- index(): LiveAtomicType<Value, undefined>;
88
- default(value: Value): LiveAtomicType<Value, Value>;
89
- primary(): LiveAtomicType<Value, undefined>;
90
- nullable(): NullableLiveType<this>;
91
- }
92
- declare class LiveString extends LiveAtomicType<string> {
93
- private constructor();
94
- static create(): LiveString;
95
- static createId(): LiveAtomicType<string, undefined>;
96
- static createReference(foreignField: `${string}.${string}`): LiveString;
97
- }
98
-
99
- /** biome-ignore-all lint/complexity/noBannedTypes: false positive */
100
-
101
- type InferLiveObjectWithoutRelations<T extends LiveObjectAny> = {
102
- [K in keyof T["fields"]]: InferLiveType<T["fields"][K]>;
103
- };
104
- type InferLiveObject<T extends LiveObjectAny, Include extends IncludeClause<T> | undefined = undefined> = InferLiveObjectWithoutRelations<T> & (Include extends IncludeClause<T> ? {
105
- [K in keyof T["relations"] as Include[K] extends true | IncludeClause<T["relations"][K]["entity"]> ? K : never]: Include[K] extends true ? T["relations"][K]["type"] extends "one" ? T["fields"][Exclude<T["relations"][K]["relationalColumn"], undefined>] extends NullableLiveType<any> ? InferLiveObject<T["relations"][K]["entity"]> | null : InferLiveObject<T["relations"][K]["entity"]> : InferLiveObject<T["relations"][K]["entity"]>[] : Include[K] extends IncludeClause<T["relations"][K]["entity"]> ? T["relations"][K]["type"] extends "one" ? T["fields"][Exclude<T["relations"][K]["relationalColumn"], undefined>] extends NullableLiveType<any> ? InferLiveObject<T["relations"][K]["entity"], Include[K]> | null : InferLiveObject<T["relations"][K]["entity"], Include[K]> : InferLiveObject<T["relations"][K]["entity"], Include[K]>[] : never;
106
- } : {});
107
- type InferRelationalColumns<T extends Record<string, RelationAny>> = {
108
- [K in keyof T as T[K]["type"] extends "many" ? never : T[K]["relationalColumn"]]: T[K]["required"] extends true ? InferIndex<T[K]["entity"]> : InferIndex<T[K]["entity"]> | null;
109
- };
110
- type InferLiveObjectWithRelationalIds<T extends LiveObjectAny> = keyof T["relations"] extends string ? InferLiveObjectWithoutRelations<T> & InferRelationalColumns<T["relations"]> : InferLiveObjectWithoutRelations<T>;
111
- type LiveObjectMutationInput<TSchema extends LiveObjectAny> = Partial<InferLiveObjectWithRelationalIds<TSchema>>;
112
- declare class LiveObject<TName extends string, TSchema extends Record<string, LiveTypeAny>, TRelations extends Record<string, RelationAny>> extends LiveType<TSchema, LiveTypeMeta, LiveObjectMutationInput<any>, Record<string, MaterializedLiveType<LiveTypeAny>>> {
113
- readonly name: TName;
114
- readonly fields: TSchema;
115
- readonly relations: TRelations;
116
- constructor(name: TName, fields: TSchema, relations?: TRelations);
117
- encodeMutation(_mutationType: MutationType, input: LiveObjectMutationInput<this>, timestamp: string): Record<string, any>;
118
- mergeMutation(mutationType: MutationType, encodedMutations: Record<string, MaterializedLiveType<LiveTypeAny>>, materializedShape?: MaterializedLiveType<this> | undefined): [MaterializedLiveType<this>, Record<string, any> | null];
119
- setRelations<TRelations extends Record<string, RelationAny>>(relations: TRelations): LiveObject<this["name"], this["fields"], TRelations>;
120
- getStorageFieldType(): StorageFieldType;
121
- static create<TName extends string, TSchema extends Record<string, LiveTypeAny>>(name: TName, schema: TSchema): LiveObject<TName, TSchema, never>;
122
- }
123
- type LiveObjectAny = LiveObject<string, Record<string, LiveTypeAny>, any>;
124
- declare class Relation<TEntity extends LiveObjectAny, TSourceEntity extends LiveObjectAny, TType extends "one" | "many", TRelationalColumn extends keyof TSourceEntity["fields"], TForeignColumn extends keyof TEntity["fields"], TRequired extends boolean> extends LiveType<InferIndex<TEntity>, {
125
- timestamp: string | null;
126
- } & LiveTypeMeta> {
127
- readonly entity: TEntity;
128
- readonly type: TType;
129
- readonly required: TRequired;
130
- readonly relationalColumn?: TRelationalColumn;
131
- readonly foreignColumn?: TForeignColumn;
132
- readonly sourceEntity: TSourceEntity;
133
- private constructor();
134
- encodeMutation(mutationType: MutationType, input: string, timestamp: string): {
135
- value: string;
136
- _meta: {
137
- timestamp: string;
138
- };
139
- };
140
- mergeMutation(mutationType: MutationType, encodedMutation: {
141
- value: string;
142
- _meta: {
143
- timestamp: string;
144
- };
145
- }, materializedShape?: MaterializedLiveType<LiveString> | undefined): [
146
- MaterializedLiveType<LiveString>,
147
- {
148
- value: string;
149
- _meta: {
150
- timestamp: string;
151
- };
152
- } | null
153
- ];
154
- getStorageFieldType(): StorageFieldType;
155
- toJSON(): {
156
- entityName: string;
157
- type: TType;
158
- required: TRequired;
159
- relationalColumn: TRelationalColumn | undefined;
160
- foreignColumn: TForeignColumn | undefined;
161
- };
162
- static createOneFactory<TOriginEntity extends LiveObjectAny>(): <TEntity extends LiveObjectAny, TColumn extends keyof TOriginEntity["fields"], TRequired extends boolean = false>(entity: TEntity, column: TColumn, required?: TRequired) => Relation<TEntity, TOriginEntity, "one", TColumn, never, TRequired>;
163
- static createManyFactory<TOriginEntity extends LiveObjectAny>(): <TEntity extends LiveObjectAny, TColumn extends keyof TEntity["fields"], TRequired extends boolean = false>(entity: TEntity, foreignColumn: TColumn, required?: TRequired) => Relation<TEntity, TOriginEntity, "many", never, TColumn, TRequired>;
164
- }
165
- type RelationAny = Relation<LiveObjectAny, LiveObjectAny, any, any, any, any>;
166
- type MaterializedLiveType<T extends LiveTypeAny> = {
167
- value: T["_value"] extends Record<string, LiveTypeAny> ? {
168
- [K in keyof T["_value"]]: MaterializedLiveType<T["_value"][K]>;
169
- } : T["_value"];
170
- _meta: T["_meta"];
171
- };
172
- type ExtractObjectValues<T> = T[keyof T];
173
- type RelationsDecl<TObjectName extends string = string, TRelations extends Record<string, RelationAny> = Record<string, RelationAny>> = {
174
- $type: "relations";
175
- objectName: TObjectName;
176
- relations: TRelations;
177
- };
178
- type ParseRelationsFromSchema<TRawSchema extends RawSchema, TObjectName extends string> = ExtractObjectValues<{
179
- [K in keyof TRawSchema]: TRawSchema[K] extends RelationsDecl<infer TObjectName_, any> ? TObjectName_ extends TObjectName ? {
180
- [K2 in keyof TRawSchema[K]["relations"]]: Relation<ParseObjectFromSchema<TRawSchema, TRawSchema[K]["relations"][K2]["entity"]["name"]>, TRawSchema[K]["relations"][K2]["sourceEntity"], TRawSchema[K]["relations"][K2]["type"], Exclude<TRawSchema[K]["relations"][K2]["relationalColumn"], undefined>, Exclude<TRawSchema[K]["relations"][K2]["foreignColumn"], undefined>, TRawSchema[K]["relations"][K2]["required"]>;
181
- } : never : never;
182
- }>;
183
- type ParseObjectFromSchema<TRawSchema extends RawSchema, TObjectName extends string> = ExtractObjectValues<{
184
- [K in keyof TRawSchema]: TRawSchema[K] extends LiveObjectAny ? TRawSchema[K]["name"] extends TObjectName ? LiveObject<TRawSchema[K]["name"], TRawSchema[K]["fields"], ParseRelationsFromSchema<TRawSchema, TRawSchema[K]["name"]>> : never : never;
185
- }>;
186
- type RawSchema = Record<string, LiveObjectAny | RelationsDecl>;
187
- type Schema<TRawSchema extends RawSchema> = {
188
- [K in keyof TRawSchema as TRawSchema[K] extends LiveObjectAny ? TRawSchema[K]["name"] : never]: TRawSchema[K] extends LiveObjectAny ? ParseObjectFromSchema<TRawSchema, TRawSchema[K]["name"]> : never;
189
- };
190
- type WhereClause<T extends LiveObjectAny> = ({
191
- [K in keyof T["fields"]]?: InferLiveType<T["fields"][K]> | ({
192
- $eq?: InferLiveType<T["fields"][K]>;
193
- $in?: InferLiveType<T["fields"][K]>[];
194
- $not?: InferLiveType<T["fields"][K]> | {
195
- $in?: InferLiveType<T["fields"][K]>[];
196
- $eq?: InferLiveType<T["fields"][K]>;
197
- };
198
- } & (Exclude<InferLiveType<T["fields"][K]>, null | undefined> extends number | Date ? {
199
- $gt?: InferLiveType<T["fields"][K]>;
200
- $gte?: InferLiveType<T["fields"][K]>;
201
- $lt?: InferLiveType<T["fields"][K]>;
202
- $lte?: InferLiveType<T["fields"][K]>;
203
- } : {}));
204
- } & {
205
- [K in keyof T["relations"]]?: WhereClause<T["relations"][K]["entity"]>;
206
- }) | {
207
- $and?: WhereClause<T>[];
208
- $or?: WhereClause<T>[];
209
- };
210
- type IncludeClause<T extends LiveObjectAny> = {
211
- [K in keyof T["relations"]]?: boolean | IncludeClause<T["relations"][K]["entity"]>;
212
- };
213
- type GetFieldType<T> = T extends NullableLiveType<any> ? T["inner"] : T;
214
- type HasDefaultValue<T> = T extends LiveAtomicType<any, undefined> ? false : true;
215
- type InferInsert<T extends LiveObjectAny> = {
216
- [K in keyof T["fields"] as HasDefaultValue<GetFieldType<T["fields"][K]>> extends true ? never : K]: InferLiveType<T["fields"][K]>;
217
- } & {
218
- [K in keyof T["fields"] as HasDefaultValue<GetFieldType<T["fields"][K]>> extends false ? never : K]?: InferLiveType<T["fields"][K]>;
219
- };
220
- type InferUpdate<T extends LiveObjectAny> = Omit<LiveObjectMutationInput<T>, "id">;
221
-
222
- type Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;
223
- type ConditionalPromise<T, P extends boolean> = P extends true ? Promise<T> : T;
224
- type PromiseOrSync<T> = T | Promise<T>;
225
- type Generatable<T, Arg = never> = T | ((arg: Arg) => T);
226
-
227
- type Simplify<T> = T extends Record<string, unknown> ? {
228
- [K in keyof T]: Simplify<T[K]>;
229
- } : T extends Array<infer U> ? Array<Simplify<U>> : T;
230
- declare const LogLevel: {
231
- readonly CRITICAL: 0;
232
- readonly ERROR: 1;
233
- readonly WARN: 2;
234
- readonly INFO: 3;
235
- readonly DEBUG: 4;
236
- };
237
- type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
238
-
239
- declare const querySchema: z.ZodObject<{
240
- resource: z.ZodString;
241
- where: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
242
- include: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
243
- lastSyncedAt: z.ZodOptional<z.ZodString>;
244
- limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
245
- sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
246
- key: z.ZodString;
247
- direction: z.ZodEnum<{
248
- asc: "asc";
249
- desc: "desc";
250
- }>;
251
- }, z.core.$strip>>>;
252
- }, z.core.$strip>;
253
- type RawQueryRequest = z.infer<typeof querySchema>;
254
-
255
- /** biome-ignore-all lint/complexity/noBannedTypes: <explanation> */
256
-
257
- type InferQueryResult<TCollection extends LiveObjectAny, TInclude extends IncludeClause<TCollection>, TSingle extends boolean = false> = TSingle extends true ? Simplify<InferLiveObject<TCollection, TInclude>> | undefined : Simplify<InferLiveObject<TCollection, TInclude>>[];
258
- declare class QueryBuilder<TCollection extends LiveObjectAny, TInclude extends IncludeClause<TCollection> = {}, TSingle extends boolean = false, TShouldAwait extends boolean = false> {
259
- private _collection;
260
- private _client;
261
- private _where;
262
- private _include;
263
- private _limit?;
264
- private _single?;
265
- private _sort?;
266
- private _shouldAwait?;
267
- private constructor();
268
- where(where: WhereClause<TCollection>): QueryBuilder<TCollection, TInclude, TSingle, TShouldAwait>;
269
- include<TNewInclude extends IncludeClause<TCollection>>(include: TNewInclude): QueryBuilder<TCollection, TInclude & TNewInclude, TSingle, TShouldAwait>;
270
- limit(limit: number): QueryBuilder<TCollection, TInclude, TSingle, TShouldAwait>;
271
- one(id: string): QueryBuilder<TCollection, TInclude, true, TShouldAwait>;
272
- first(where?: WhereClause<TCollection>): QueryBuilder<TCollection, TInclude, true, TShouldAwait>;
273
- orderBy(key: keyof TCollection["fields"], direction?: "asc" | "desc"): QueryBuilder<TCollection, TInclude, TSingle, TShouldAwait>;
274
- toJSON(): {
275
- resource: string;
276
- where: WhereClause<TCollection>;
277
- include: TInclude;
278
- limit: number | undefined;
279
- sort: {
280
- key: string;
281
- direction: "asc" | "desc";
282
- }[] | undefined;
283
- };
284
- buildQueryRequest(): RawQueryRequest;
285
- get(): ConditionalPromise<InferQueryResult<TCollection, TInclude, TSingle>, TShouldAwait>;
286
- subscribe(callback: (value: InferQueryResult<TCollection, TInclude, TSingle>) => void): () => void;
287
- }
288
-
289
- /**
290
- * Extracts the output type from a Standard Schema validator.
291
- * Supports Standard Schema (via ~standard property) and Zod schemas (via _output property for backward compatibility).
292
- */
293
- type InferSchema<T> = T extends {
294
- "~standard": {
295
- types?: {
296
- output: infer U;
297
- };
298
- };
299
- } ? U : T extends StandardSchemaV1<any, any> ? StandardSchemaV1.InferOutput<T> : T extends {
300
- _output: infer U;
301
- } ? U : never;
302
- /**
303
- * Helper type for custom mutation functions.
304
- * When the input type is `never` or `undefined`, the function has no parameters.
305
- */
306
- type CustomMutationFunction<TInput, TOutput> = [TInput] extends [never] | [undefined] ? () => Promisify<TOutput> : (input: TInput) => Promisify<TOutput>;
307
- /**
308
- * Simplified router constraint for client-side usage.
309
- * This avoids importing server-internal types like Storage and Hooks,
310
- * which can cause type incompatibilities when the package is bundled.
311
- */
312
- type ClientRouterConstraint = {
313
- routes: Record<string, {
314
- resourceSchema: LiveObjectAny;
315
- customMutations: Record<string, {
316
- inputValidator: StandardSchemaV1<any, any>;
317
- handler: (...args: any[]) => any;
318
- }>;
319
- }>;
320
- };
321
- type Client$1<TRouter extends ClientRouterConstraint, TShouldAwait extends boolean = false> = {
322
- query: {
323
- [K in keyof TRouter["routes"]]: QueryBuilder<TRouter["routes"][K]["resourceSchema"], {}, false, TShouldAwait>;
324
- };
325
- mutate: {
326
- [K in keyof TRouter["routes"]]: {
327
- insert: (input: Simplify<InferInsert<TRouter["routes"][K]["resourceSchema"]>>) => ConditionalPromise<void, TShouldAwait>;
328
- update: (id: string, value: Simplify<InferUpdate<TRouter["routes"][K]["resourceSchema"]>>) => ConditionalPromise<void, TShouldAwait>;
329
- } & {
330
- [K2 in keyof TRouter["routes"][K]["customMutations"]]: CustomMutationFunction<InferSchema<TRouter["routes"][K]["customMutations"][K2]["inputValidator"]>, ReturnType<TRouter["routes"][K]["customMutations"][K2]["handler"]>>;
331
- };
332
- };
333
- };
334
-
335
- declare const useLiveQuery: <T extends {
336
- get: () => U;
337
- subscribe: (cb: (v: U) => void) => () => void;
338
- }, U>(observable: T) => ReturnType<T["get"]>;
339
- declare const useLoadData: (client: Client<ClientRouterConstraint>["client"], query: QueryBuilder<any, any>) => void;
340
-
341
- declare const serverMessageSchema: z.ZodUnion<readonly [z.ZodObject<{
342
- id: z.ZodString;
343
- type: z.ZodLiteral<"REJECT">;
344
- resource: z.ZodString;
345
- message: z.ZodOptional<z.ZodString>;
346
- }, z.core.$strip>, z.ZodObject<{
347
- id: z.ZodString;
348
- type: z.ZodLiteral<"REPLY">;
349
- data: z.ZodAny;
350
- }, z.core.$strip>, z.ZodObject<{
351
- type: z.ZodLiteral<"MUTATE">;
352
- resource: z.ZodString;
353
- resourceId: z.ZodOptional<z.ZodString>;
354
- procedure: z.ZodEnum<{
355
- INSERT: "INSERT";
356
- UPDATE: "UPDATE";
357
- }>;
358
- payload: z.ZodRecord<z.ZodString, z.ZodObject<{
359
- value: z.ZodNullable<z.ZodAny>;
360
- _meta: z.ZodOptional<z.ZodObject<{
361
- timestamp: z.ZodNullable<z.ZodOptional<z.ZodString>>;
362
- }, z.core.$strip>>;
363
- }, z.core.$strip>>;
364
- id: z.ZodString;
365
- }, z.core.$strip>]>;
366
- type ServerMessage = z.infer<typeof serverMessageSchema>;
367
-
368
- type WebSocketClientEventMap = WebSocketEventMap & {
369
- connectionChange: {
370
- open: boolean;
371
- };
372
- };
373
- declare class WebSocketClient {
374
- private ws;
375
- private url;
376
- private autoConnect;
377
- private autoReconnect;
378
- private reconnectTimeout;
379
- private reconnectLimit?;
380
- private reconnectAttempts;
381
- private eventListeners;
382
- private reconnectTimer;
383
- private intentionallyDisconnected;
384
- private credentials?;
385
- constructor(options: {
386
- url: string;
387
- autoConnect?: boolean;
388
- autoReconnect?: boolean;
389
- reconnectTimeout?: number;
390
- reconnectLimit?: number;
391
- credentials?: ClientOptions["credentials"];
392
- });
393
- connected(): boolean;
394
- connect(): Promise<void>;
395
- disconnect(): void;
396
- addEventListener<K extends keyof WebSocketClientEventMap>(event: K, callback: (event: WebSocketClientEventMap[K]) => void): void;
397
- removeEventListener<K extends keyof WebSocketClientEventMap>(event: K, callback: (event: WebSocketClientEventMap[K]) => void): void;
398
- send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
399
- private handleOpen;
400
- private handleClose;
401
- private handleError;
402
- private handleMessage;
403
- private scheduleReconnect;
404
- private dispatchEvent;
405
- }
406
-
407
- interface WebSocketClientOptions extends ClientOptions {
408
- connection?: {
409
- autoConnect?: boolean;
410
- autoReconnect?: boolean;
411
- reconnectTimeout?: number;
412
- maxReconnectAttempts?: number;
413
- };
414
- }
415
- type ConnectionStateChangeEvent = {
416
- type: "CONNECTION_STATE_CHANGE";
417
- open: boolean;
418
- };
419
- type MessageReceivedEvent = {
420
- type: "MESSAGE_RECEIVED";
421
- message: ServerMessage;
422
- };
423
- type ClientStorageLoadedEvent = {
424
- type: "CLIENT_STORAGE_LOADED";
425
- resource: string;
426
- itemCount: number;
427
- };
428
- type DataLoadRequestedEvent = {
429
- type: "DATA_LOAD_REQUESTED";
430
- query: RawQueryRequest;
431
- subscriptionId: string;
432
- };
433
- type DataLoadReplyEvent = {
434
- type: "DATA_LOAD_REPLY";
435
- resource: string;
436
- itemCount: number;
437
- subscriptionId?: string;
438
- };
439
- type MutationSentEvent = {
440
- type: "MUTATION_SENT";
441
- mutationId: string;
442
- resource: string;
443
- resourceId: string;
444
- procedure: string;
445
- optimistic: boolean;
446
- };
447
- type MutationReceivedEvent = {
448
- type: "MUTATION_RECEIVED";
449
- mutationId: string;
450
- resource: string;
451
- resourceId: string;
452
- procedure: string;
453
- };
454
- type MutationRejectedEvent = {
455
- type: "MUTATION_REJECTED";
456
- mutationId: string;
457
- resource: string;
458
- };
459
- type SubscriptionCreatedEvent = {
460
- type: "SUBSCRIPTION_CREATED";
461
- query: RawQueryRequest;
462
- subscriptionKey: string;
463
- subscriberCount: number;
464
- };
465
- type SubscriptionRemovedEvent = {
466
- type: "SUBSCRIPTION_REMOVED";
467
- query: RawQueryRequest;
468
- subscriptionKey: string;
469
- };
470
- type QueryExecutedEvent = {
471
- type: "QUERY_EXECUTED";
472
- query: RawQueryRequest;
473
- resultCount: number;
474
- };
475
- type QuerySubscriptionTriggeredEvent = {
476
- type: "QUERY_SUBSCRIPTION_TRIGGERED";
477
- query: RawQueryRequest;
478
- };
479
- type StoreStateUpdatedEvent = {
480
- type: "STORE_STATE_UPDATED";
481
- resource: string;
482
- itemCount: number;
483
- };
484
- type OptimisticMutationAppliedEvent = {
485
- type: "OPTIMISTIC_MUTATION_APPLIED";
486
- mutationId: string;
487
- resource: string;
488
- resourceId: string;
489
- procedure: string;
490
- pendingMutations: number;
491
- };
492
- type OptimisticMutationUndoneEvent = {
493
- type: "OPTIMISTIC_MUTATION_UNDONE";
494
- mutationId: string;
495
- resource: string;
496
- resourceId: string;
497
- pendingMutations: number;
498
- };
499
- type ClientEvents = ConnectionStateChangeEvent | MessageReceivedEvent | ClientStorageLoadedEvent | DataLoadRequestedEvent | DataLoadReplyEvent | MutationSentEvent | MutationReceivedEvent | MutationRejectedEvent | SubscriptionCreatedEvent | SubscriptionRemovedEvent | QueryExecutedEvent | QuerySubscriptionTriggeredEvent | StoreStateUpdatedEvent | OptimisticMutationAppliedEvent | OptimisticMutationUndoneEvent;
500
- type Client<TRouter extends ClientRouterConstraint> = {
501
- client: {
502
- ws: WebSocketClient;
503
- addEventListener: (listener: (event: ClientEvents) => void) => () => void;
504
- load: (query: RawQueryRequest) => () => void;
505
- };
506
- store: Client$1<TRouter>;
507
- };
508
- declare const createClient: <TRouter extends ClientRouterConstraint>(opts: WebSocketClientOptions) => Client<TRouter>;
509
-
510
- type ClientOptions = {
511
- url: string;
512
- schema: Schema<any>;
513
- credentials?: Generatable<PromiseOrSync<Record<string, string>>>;
514
- storage: {
515
- name: string;
516
- } | false;
517
- logLevel?: LogLevel;
518
- };
519
-
520
- export { type ClientOptions as C, type DataLoadRequestedEvent as D, type MessageReceivedEvent as M, type OptimisticMutationAppliedEvent as O, type QueryExecutedEvent as Q, type SubscriptionCreatedEvent as S, type ClientRouterConstraint as a, type Client$1 as b, useLoadData as c, type ConnectionStateChangeEvent as d, type ClientStorageLoadedEvent as e, type DataLoadReplyEvent as f, type MutationSentEvent as g, type MutationReceivedEvent as h, type MutationRejectedEvent as i, type SubscriptionRemovedEvent as j, type QuerySubscriptionTriggeredEvent as k, type StoreStateUpdatedEvent as l, type OptimisticMutationUndoneEvent as m, type ClientEvents as n, type Client as o, createClient as p, useLiveQuery as u };