cry-synced-db-client 0.1.99 → 0.1.101
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/index.js
CHANGED
|
@@ -6898,6 +6898,14 @@ var RestProxy = class {
|
|
|
6898
6898
|
this._totalRequestMs = 0;
|
|
6899
6899
|
this._requestCount = 0;
|
|
6900
6900
|
}
|
|
6901
|
+
/** Typed rdb2 operation call — exposes the full rdb2 API. */
|
|
6902
|
+
async call(operation, payload, options) {
|
|
6903
|
+
return this.restCall(
|
|
6904
|
+
operation,
|
|
6905
|
+
payload,
|
|
6906
|
+
options
|
|
6907
|
+
);
|
|
6908
|
+
}
|
|
6901
6909
|
async restCall(operation, payload = {}, options) {
|
|
6902
6910
|
var _a, _b, _c;
|
|
6903
6911
|
const timeout = (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : this.defaultTimeoutMs;
|
|
@@ -7211,7 +7219,7 @@ var Ebus2ProxyServerUpdateNotifier = class {
|
|
|
7211
7219
|
this.reconnectAttempt = 0;
|
|
7212
7220
|
this.forcedOffline = false;
|
|
7213
7221
|
this.subscribedChannels = /* @__PURE__ */ new Set();
|
|
7214
|
-
var _a, _b, _c, _d;
|
|
7222
|
+
var _a, _b, _c, _d, _e;
|
|
7215
7223
|
this.wsUrl = config.wsUrl;
|
|
7216
7224
|
this.dbName = config.dbName;
|
|
7217
7225
|
this.collections = config.collections;
|
|
@@ -7225,6 +7233,8 @@ var Ebus2ProxyServerUpdateNotifier = class {
|
|
|
7225
7233
|
if (config.onWsDisconnect) this.onWsDisconnectCallbacks.push(config.onWsDisconnect);
|
|
7226
7234
|
if (config.onWsReconnect) this.onWsReconnectCallbacks.push(config.onWsReconnect);
|
|
7227
7235
|
this.onWsNotification = config.onWsNotification;
|
|
7236
|
+
this.subscribeServices = (_e = config.subscribeServices) != null ? _e : false;
|
|
7237
|
+
this.onServicesChange = config.onServicesChange;
|
|
7228
7238
|
}
|
|
7229
7239
|
subscribe(callback) {
|
|
7230
7240
|
this.callbacks.add(callback);
|
|
@@ -7358,6 +7368,9 @@ var Ebus2ProxyServerUpdateNotifier = class {
|
|
|
7358
7368
|
this.reconnectAttempt = 0;
|
|
7359
7369
|
this.currentReconnectDelay = this.reconnectDelayMs;
|
|
7360
7370
|
this.sendSubscribe(`db/${this.dbName}`);
|
|
7371
|
+
if (this.subscribeServices) {
|
|
7372
|
+
this.sendSubscribe("ebus/services");
|
|
7373
|
+
}
|
|
7361
7374
|
this.startPingInterval();
|
|
7362
7375
|
for (const callback of this.onWsConnectCallbacks) {
|
|
7363
7376
|
try {
|
|
@@ -7417,6 +7430,14 @@ var Ebus2ProxyServerUpdateNotifier = class {
|
|
|
7417
7430
|
}
|
|
7418
7431
|
}
|
|
7419
7432
|
handleChannelMessage(message) {
|
|
7433
|
+
if (message.channel === "ebus/services" && this.onServicesChange) {
|
|
7434
|
+
try {
|
|
7435
|
+
this.onServicesChange(message.data);
|
|
7436
|
+
} catch (err) {
|
|
7437
|
+
console.error("onServicesChange callback failed:", err);
|
|
7438
|
+
}
|
|
7439
|
+
return;
|
|
7440
|
+
}
|
|
7420
7441
|
const prefix = `db/${this.dbName}/`;
|
|
7421
7442
|
if (!message.channel.startsWith(prefix)) {
|
|
7422
7443
|
return;
|
|
@@ -25,6 +25,15 @@ export interface Ebus2ProxyServerUpdateNotifierConfig {
|
|
|
25
25
|
onWsReconnect?: (attempt: number) => void;
|
|
26
26
|
/** Called when a notification is received */
|
|
27
27
|
onWsNotification?: (payload: PublishDataPayload) => void;
|
|
28
|
+
/** Subscribe to ebus/services channel for worker presence */
|
|
29
|
+
subscribeServices?: boolean;
|
|
30
|
+
/** Called when ebus/services data changes (worker presence) */
|
|
31
|
+
onServicesChange?: (services: EbusService[]) => void;
|
|
32
|
+
}
|
|
33
|
+
export interface EbusService {
|
|
34
|
+
name: string;
|
|
35
|
+
workers: number;
|
|
36
|
+
requests: number;
|
|
28
37
|
}
|
|
29
38
|
export declare class Ebus2ProxyServerUpdateNotifier implements I_ServerUpdateNotifier {
|
|
30
39
|
private wsUrl;
|
|
@@ -39,6 +48,8 @@ export declare class Ebus2ProxyServerUpdateNotifier implements I_ServerUpdateNot
|
|
|
39
48
|
private onWsDisconnectCallbacks;
|
|
40
49
|
private onWsReconnectCallbacks;
|
|
41
50
|
private onWsNotification?;
|
|
51
|
+
private subscribeServices;
|
|
52
|
+
private onServicesChange?;
|
|
42
53
|
private ws;
|
|
43
54
|
private callbacks;
|
|
44
55
|
private connected;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AggregateOptions, Timestamp } from "mongodb";
|
|
2
2
|
import type { I_RestInterface, QuerySpec, QueryOpts, GetNewerSpec, BatchSpec, CollectionUpdateRequest, CollectionUpdateResult } from "../types/I_RestInterface";
|
|
3
3
|
import type { Id } from "../types/DbEntity";
|
|
4
|
+
import type { Rdb2CallMap, Rdb2Operation } from "../types/Rdb2CallMap";
|
|
4
5
|
/** Progress callback for tracking upload progress */
|
|
5
6
|
export type ProgressCallback = (sentBytes: number, totalBytes: number) => void;
|
|
6
7
|
export interface RestProxyConfig {
|
|
@@ -93,6 +94,11 @@ export declare class RestProxy implements I_RestInterface {
|
|
|
93
94
|
getRequestCount(): number;
|
|
94
95
|
/** Reset timing stats */
|
|
95
96
|
resetTimingStats(): void;
|
|
97
|
+
/** Typed rdb2 operation call — exposes the full rdb2 API. */
|
|
98
|
+
call<K extends Rdb2Operation, T = unknown>(operation: K, payload?: Rdb2CallMap[K], options?: {
|
|
99
|
+
timeoutMs?: number;
|
|
100
|
+
signal?: AbortSignal;
|
|
101
|
+
}): Promise<T>;
|
|
96
102
|
private restCall;
|
|
97
103
|
/** Combine multiple abort signals into one */
|
|
98
104
|
private combineSignals;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export { DexieDb } from "./db/DexieDb";
|
|
|
6
6
|
export { RestProxy } from "./db/RestProxy";
|
|
7
7
|
export type { RestProxyConfig } from "./db/RestProxy";
|
|
8
8
|
export { Ebus2ProxyServerUpdateNotifier } from "./db/Ebus2ProxyServerUpdateNotifier";
|
|
9
|
-
export type { Ebus2ProxyServerUpdateNotifierConfig } from "./db/Ebus2ProxyServerUpdateNotifier";
|
|
9
|
+
export type { Ebus2ProxyServerUpdateNotifierConfig, EbusService } from "./db/Ebus2ProxyServerUpdateNotifier";
|
|
10
10
|
export { resolveConflict } from "./utils/conflictResolution";
|
|
11
11
|
export { filterByQuery, matchesQuery, sortItems, applySkipLimit, projectItem, applyQueryOpts } from "./utils/localQuery";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { AggregateOptions } from "mongodb";
|
|
2
|
+
import type { Id } from "./DbEntity";
|
|
3
|
+
import type { QuerySpec, QueryOpts, Projection, BatchSpec, UpsertOptions, GetNewerSpec, CollectionUpdateRequest } from "./I_RestInterface";
|
|
4
|
+
/**
|
|
5
|
+
* Maps each rdb2 API operation to its payload shape.
|
|
6
|
+
* Derived from rdb2-api-spec.json — excludes disallowed
|
|
7
|
+
* server-only operations (close, createCollection, transactions, etc.).
|
|
8
|
+
*/
|
|
9
|
+
export interface Rdb2CallMap {
|
|
10
|
+
ping: {};
|
|
11
|
+
isConnected: {};
|
|
12
|
+
isOnReplicaSet: {};
|
|
13
|
+
getDatabases: {};
|
|
14
|
+
getDatabaseInfos: {};
|
|
15
|
+
getDb: {};
|
|
16
|
+
getCollections: {};
|
|
17
|
+
find: {
|
|
18
|
+
collection: string;
|
|
19
|
+
query?: QuerySpec<any>;
|
|
20
|
+
opts?: QueryOpts;
|
|
21
|
+
};
|
|
22
|
+
findOne: {
|
|
23
|
+
collection: string;
|
|
24
|
+
query: QuerySpec<any>;
|
|
25
|
+
projection?: Projection;
|
|
26
|
+
opts?: QueryOpts;
|
|
27
|
+
};
|
|
28
|
+
findAll: {
|
|
29
|
+
collection: string;
|
|
30
|
+
query?: QuerySpec<any>;
|
|
31
|
+
opts?: QueryOpts;
|
|
32
|
+
};
|
|
33
|
+
findById: {
|
|
34
|
+
collection: string;
|
|
35
|
+
id: Id;
|
|
36
|
+
projection?: Projection;
|
|
37
|
+
opts?: QueryOpts;
|
|
38
|
+
};
|
|
39
|
+
findByIds: {
|
|
40
|
+
collection: string;
|
|
41
|
+
ids: Id[];
|
|
42
|
+
projection?: Projection;
|
|
43
|
+
opts?: QueryOpts;
|
|
44
|
+
};
|
|
45
|
+
findByIdsInManyCollections: {
|
|
46
|
+
request: {
|
|
47
|
+
collection: string;
|
|
48
|
+
ids: Id[];
|
|
49
|
+
}[];
|
|
50
|
+
opts?: QueryOpts;
|
|
51
|
+
};
|
|
52
|
+
findNewer: {
|
|
53
|
+
collection: string;
|
|
54
|
+
timestamp: any;
|
|
55
|
+
query?: QuerySpec<any>;
|
|
56
|
+
opts?: QueryOpts;
|
|
57
|
+
};
|
|
58
|
+
findNewerMany: {
|
|
59
|
+
spec?: GetNewerSpec<any>[];
|
|
60
|
+
};
|
|
61
|
+
count: {
|
|
62
|
+
collection: string;
|
|
63
|
+
query?: QuerySpec<any>;
|
|
64
|
+
opts?: QueryOpts;
|
|
65
|
+
};
|
|
66
|
+
distinct: {
|
|
67
|
+
collection: string;
|
|
68
|
+
field: string;
|
|
69
|
+
};
|
|
70
|
+
aggregate: {
|
|
71
|
+
collection: string;
|
|
72
|
+
pipeline: object[];
|
|
73
|
+
opts?: AggregateOptions;
|
|
74
|
+
};
|
|
75
|
+
isUnique: {
|
|
76
|
+
collection: string;
|
|
77
|
+
field: string;
|
|
78
|
+
value: any;
|
|
79
|
+
id?: Id;
|
|
80
|
+
};
|
|
81
|
+
testHash: {
|
|
82
|
+
collection: string;
|
|
83
|
+
query: QuerySpec<any>;
|
|
84
|
+
field: string;
|
|
85
|
+
unhashedValue: string;
|
|
86
|
+
};
|
|
87
|
+
insert: {
|
|
88
|
+
collection: string;
|
|
89
|
+
insert: any;
|
|
90
|
+
};
|
|
91
|
+
insertMany: {
|
|
92
|
+
collection: string;
|
|
93
|
+
insert: any[];
|
|
94
|
+
};
|
|
95
|
+
save: {
|
|
96
|
+
collection: string;
|
|
97
|
+
update: any;
|
|
98
|
+
id?: Id;
|
|
99
|
+
options?: any;
|
|
100
|
+
};
|
|
101
|
+
update: {
|
|
102
|
+
collection: string;
|
|
103
|
+
query: QuerySpec<any>;
|
|
104
|
+
update: any;
|
|
105
|
+
};
|
|
106
|
+
updateOne: {
|
|
107
|
+
collection: string;
|
|
108
|
+
query: QuerySpec<any>;
|
|
109
|
+
update: any;
|
|
110
|
+
options?: any;
|
|
111
|
+
};
|
|
112
|
+
upsert: {
|
|
113
|
+
collection: string;
|
|
114
|
+
query: QuerySpec<any>;
|
|
115
|
+
update: any;
|
|
116
|
+
options?: UpsertOptions;
|
|
117
|
+
};
|
|
118
|
+
upsertBatch: {
|
|
119
|
+
collection: string;
|
|
120
|
+
batch: BatchSpec<any>;
|
|
121
|
+
};
|
|
122
|
+
updateCollections: {
|
|
123
|
+
collectionsBatches: CollectionUpdateRequest<any>[];
|
|
124
|
+
};
|
|
125
|
+
delete: {
|
|
126
|
+
collection: string;
|
|
127
|
+
query: QuerySpec<any>;
|
|
128
|
+
};
|
|
129
|
+
deleteOne: {
|
|
130
|
+
collection: string;
|
|
131
|
+
query: QuerySpec<any>;
|
|
132
|
+
};
|
|
133
|
+
hardDelete: {
|
|
134
|
+
collection: string;
|
|
135
|
+
query: QuerySpec<any>;
|
|
136
|
+
};
|
|
137
|
+
hardDeleteOne: {
|
|
138
|
+
collection: string;
|
|
139
|
+
query: QuerySpec<any>;
|
|
140
|
+
};
|
|
141
|
+
blockOne: {
|
|
142
|
+
collection: string;
|
|
143
|
+
query: QuerySpec<any>;
|
|
144
|
+
};
|
|
145
|
+
unblockOne: {
|
|
146
|
+
collection: string;
|
|
147
|
+
query: QuerySpec<any>;
|
|
148
|
+
};
|
|
149
|
+
latestTimestamp: {
|
|
150
|
+
collection: string;
|
|
151
|
+
};
|
|
152
|
+
latestTimestamps: {
|
|
153
|
+
collections: string[];
|
|
154
|
+
};
|
|
155
|
+
resetCollectionSync: {
|
|
156
|
+
collection: string;
|
|
157
|
+
};
|
|
158
|
+
dbLogGet: {
|
|
159
|
+
collection: string;
|
|
160
|
+
id: Id;
|
|
161
|
+
};
|
|
162
|
+
dbLogPurge: {
|
|
163
|
+
collection: string;
|
|
164
|
+
id?: Id;
|
|
165
|
+
};
|
|
166
|
+
inTransaction: {};
|
|
167
|
+
newId: {};
|
|
168
|
+
}
|
|
169
|
+
/** Union of all allowed rdb2 operation names. */
|
|
170
|
+
export type Rdb2Operation = keyof Rdb2CallMap;
|
|
@@ -7,3 +7,4 @@ export type { I_ServerUpdateNotifier as ServerUpdateNotifier, ServerUpdateCallba
|
|
|
7
7
|
export type { I_SyncedDb as SyncedDb, SyncedDbConfig, CollectionConfig, CollectionSyncConfig, SyncInfo, ServerWriteRequestInfo, ServerWriteResultInfo, FindNewerManyCallInfo, FindNewerManyResultInfo, DexieWriteRequestInfo, DexieWriteResultInfo, LocalstorageWriteResultInfo, WsNotificationInfo, InfrastructureErrorType, InfrastructureErrorInfo, ConflictSource, ConflictResolutionReport, CrossTabSyncInfo, } from "./I_SyncedDb";
|
|
8
8
|
export type { NetworkStatusChangeInfo } from "../db/types/managers";
|
|
9
9
|
export type { CollectionConfig as CollectionConfigFull, CollectionSyncConfig as CollectionSyncConfigFull } from "./CollectionConfig";
|
|
10
|
+
export type { Rdb2CallMap, Rdb2Operation } from "./Rdb2CallMap";
|