@latlng/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +343 -0
- package/dist/auth/token.d.ts +2 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/client.d.ts +385 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/errors/index.d.ts +66 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/http/routes.d.ts +41 -0
- package/dist/http/routes.d.ts.map +1 -0
- package/dist/http/transport.d.ts +26 -0
- package/dist/http/transport.d.ts.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1455 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/assert.d.ts +6 -0
- package/dist/internal/assert.d.ts.map +1 -0
- package/dist/internal/json.d.ts +3 -0
- package/dist/internal/json.d.ts.map +1 -0
- package/dist/internal/response-parsers.d.ts +26 -0
- package/dist/internal/response-parsers.d.ts.map +1 -0
- package/dist/routing/read-preference.d.ts +7 -0
- package/dist/routing/read-preference.d.ts.map +1 -0
- package/dist/routing/replicas.d.ts +22 -0
- package/dist/routing/replicas.d.ts.map +1 -0
- package/dist/types/events.d.ts +122 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/json.d.ts +7 -0
- package/dist/types/json.d.ts.map +1 -0
- package/dist/types/models.d.ts +408 -0
- package/dist/types/models.d.ts.map +1 -0
- package/dist/types/requests.d.ts +96 -0
- package/dist/types/requests.d.ts.map +1 -0
- package/dist/types/responses.d.ts +108 -0
- package/dist/types/responses.d.ts.map +1 -0
- package/dist/ws/socket.d.ts +66 -0
- package/dist/ws/socket.d.ts.map +1 -0
- package/dist/ws/subscriptions.d.ts +46 -0
- package/dist/ws/subscriptions.d.ts.map +1 -0
- package/package.json +49 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1455 @@
|
|
|
1
|
+
//#region src/errors/index.ts
|
|
2
|
+
var e = class extends Error {
|
|
3
|
+
cause;
|
|
4
|
+
constructor(e, t) {
|
|
5
|
+
super(e), this.name = new.target.name, this.cause = t?.cause;
|
|
6
|
+
}
|
|
7
|
+
}, t = class extends e {
|
|
8
|
+
timeoutMs;
|
|
9
|
+
constructor(e, t) {
|
|
10
|
+
super(`request timed out after ${e}ms`, t), this.timeoutMs = e;
|
|
11
|
+
}
|
|
12
|
+
}, n = class extends e {
|
|
13
|
+
status;
|
|
14
|
+
url;
|
|
15
|
+
body;
|
|
16
|
+
constructor(e, t) {
|
|
17
|
+
super(e, t), this.status = t.status, this.url = t.url, this.body = t.body;
|
|
18
|
+
}
|
|
19
|
+
}, r = class extends n {}, i = class extends n {};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/http/routes.ts
|
|
22
|
+
function a(e, t) {
|
|
23
|
+
return `${e.endsWith("/") ? e.slice(0, -1) : e}${t}`;
|
|
24
|
+
}
|
|
25
|
+
function o(e) {
|
|
26
|
+
let t = new URLSearchParams();
|
|
27
|
+
for (let [n, r] of Object.entries(e)) r != null && t.set(n, String(r));
|
|
28
|
+
let n = t.toString();
|
|
29
|
+
return n ? `?${n}` : "";
|
|
30
|
+
}
|
|
31
|
+
var s = {
|
|
32
|
+
ping: () => "/ping",
|
|
33
|
+
healthz: () => "/healthz",
|
|
34
|
+
server: () => "/server",
|
|
35
|
+
info: (e) => `/info${o({ section: e })}`,
|
|
36
|
+
metrics: () => "/metrics",
|
|
37
|
+
collections: (e) => `/collections${o({ match_pattern: e })}`,
|
|
38
|
+
collection: (e) => `/collections/${encodeURIComponent(e)}`,
|
|
39
|
+
renameCollection: (e) => `/collections/${encodeURIComponent(e)}/rename`,
|
|
40
|
+
bounds: (e) => `/collections/${encodeURIComponent(e)}/bounds`,
|
|
41
|
+
stats: (e) => `/collections/${encodeURIComponent(e)}/stats`,
|
|
42
|
+
object: (e, t) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}`,
|
|
43
|
+
objects: (e, t) => `/collections/${encodeURIComponent(e)}/objects${o({ match_pattern: t })}`,
|
|
44
|
+
fields: (e, t) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}/fields`,
|
|
45
|
+
field: (e, t, n) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}/fields/${encodeURIComponent(n)}`,
|
|
46
|
+
expire: (e, t) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}/expire`,
|
|
47
|
+
ttl: (e, t) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}/ttl`,
|
|
48
|
+
jsonRoot: (e, t) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}/json`,
|
|
49
|
+
jsonPath: (e, t, n) => `/collections/${encodeURIComponent(e)}/objects/${encodeURIComponent(t)}/json/${n}`,
|
|
50
|
+
nearby: (e) => `/collections/${encodeURIComponent(e)}/search/nearby`,
|
|
51
|
+
within: (e) => `/collections/${encodeURIComponent(e)}/search/within`,
|
|
52
|
+
intersects: (e) => `/collections/${encodeURIComponent(e)}/search/intersects`,
|
|
53
|
+
scan: (e) => `/collections/${encodeURIComponent(e)}/search/scan`,
|
|
54
|
+
search: (e) => `/collections/${encodeURIComponent(e)}/search/text`,
|
|
55
|
+
channels: (e) => `/channels${o({ match_pattern: e })}`,
|
|
56
|
+
channel: (e) => `/channels/${encodeURIComponent(e)}`,
|
|
57
|
+
hooks: (e) => `/hooks${o({ match_pattern: e })}`,
|
|
58
|
+
hook: (e) => `/hooks/${encodeURIComponent(e)}`,
|
|
59
|
+
config: (e) => `/config/${encodeURIComponent(e)}`,
|
|
60
|
+
flushdb: () => "/admin/flushdb",
|
|
61
|
+
gc: () => "/admin/gc",
|
|
62
|
+
aofshrink: () => "/admin/aofshrink",
|
|
63
|
+
webhookQueue: () => "/admin/webhook-queue",
|
|
64
|
+
configRewrite: () => "/admin/config/rewrite",
|
|
65
|
+
readonly: () => "/admin/readonly",
|
|
66
|
+
timeout: () => "/admin/timeout",
|
|
67
|
+
ws: () => "/ws"
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/auth/token.ts
|
|
71
|
+
function c(e, t) {
|
|
72
|
+
t && e.set("authorization", `Bearer ${t}`);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/internal/json.ts
|
|
76
|
+
async function l(e) {
|
|
77
|
+
if (e.status === 204) return;
|
|
78
|
+
let t = await e.text();
|
|
79
|
+
if (t) try {
|
|
80
|
+
return JSON.parse(t);
|
|
81
|
+
} catch {
|
|
82
|
+
return t;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/http/transport.ts
|
|
87
|
+
var u = class {
|
|
88
|
+
baseUrl;
|
|
89
|
+
token;
|
|
90
|
+
timeoutMs;
|
|
91
|
+
headers;
|
|
92
|
+
fetchImpl;
|
|
93
|
+
constructor(e) {
|
|
94
|
+
this.baseUrl = e.baseUrl, this.token = e.token, this.timeoutMs = e.timeoutMs ?? 5e3, this.headers = e.headers, this.fetchImpl = e.fetch ?? globalThis.fetch.bind(globalThis);
|
|
95
|
+
}
|
|
96
|
+
async request(e) {
|
|
97
|
+
let r = a(e.baseUrl ?? this.baseUrl, e.path), i = new AbortController(), o = setTimeout(() => i.abort(), this.timeoutMs), s = new Headers(this.headers);
|
|
98
|
+
e.body !== void 0 && s.set("content-type", "application/json"), c(s, this.token);
|
|
99
|
+
try {
|
|
100
|
+
let t = await this.fetchImpl(r, {
|
|
101
|
+
method: e.method ?? "GET",
|
|
102
|
+
headers: s,
|
|
103
|
+
body: e.body === void 0 ? void 0 : JSON.stringify(e.body),
|
|
104
|
+
signal: i.signal
|
|
105
|
+
}), n = await l(t);
|
|
106
|
+
if (!t.ok) throw this.toHttpError(r, t.status, n);
|
|
107
|
+
return e.parser ? e.parser(n) : n;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
throw e instanceof n ? e : e instanceof DOMException && e.name === "AbortError" ? new t(this.timeoutMs, { cause: e }) : e;
|
|
110
|
+
} finally {
|
|
111
|
+
clearTimeout(o);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async requestText(e) {
|
|
115
|
+
let r = a(e.baseUrl ?? this.baseUrl, e.path), i = new AbortController(), o = setTimeout(() => i.abort(), this.timeoutMs), s = new Headers(this.headers);
|
|
116
|
+
e.body !== void 0 && s.set("content-type", "application/json"), c(s, this.token);
|
|
117
|
+
try {
|
|
118
|
+
let t = await this.fetchImpl(r, {
|
|
119
|
+
method: e.method ?? "GET",
|
|
120
|
+
headers: s,
|
|
121
|
+
body: e.body === void 0 ? void 0 : JSON.stringify(e.body),
|
|
122
|
+
signal: i.signal
|
|
123
|
+
}), n = await t.text();
|
|
124
|
+
if (!t.ok) throw this.toHttpError(r, t.status, n);
|
|
125
|
+
return n;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
throw e instanceof n ? e : e instanceof DOMException && e.name === "AbortError" ? new t(this.timeoutMs, { cause: e }) : e;
|
|
128
|
+
} finally {
|
|
129
|
+
clearTimeout(o);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
toHttpError(e, t, a) {
|
|
133
|
+
let o = a && typeof a == "object" && "error" in a && typeof a.error == "string" ? a.error : typeof a == "string" && a.length > 0 ? a : `request failed with status ${t}`, s = {
|
|
134
|
+
status: t,
|
|
135
|
+
url: e,
|
|
136
|
+
body: a
|
|
137
|
+
};
|
|
138
|
+
return t === 401 ? new r(o, s) : t === 503 ? new i(o, s) : new n(o, s);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/internal/assert.ts
|
|
143
|
+
function d(e, t) {
|
|
144
|
+
if (!e) throw Error(t);
|
|
145
|
+
}
|
|
146
|
+
function f(e) {
|
|
147
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/types/models.ts
|
|
151
|
+
function p(e, t, n) {
|
|
152
|
+
return {
|
|
153
|
+
type: "point",
|
|
154
|
+
lat: e,
|
|
155
|
+
lon: t,
|
|
156
|
+
z: n
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function ee(e) {
|
|
160
|
+
return {
|
|
161
|
+
type: "bounds",
|
|
162
|
+
bounds: e
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function m(e) {
|
|
166
|
+
return {
|
|
167
|
+
type: "hash",
|
|
168
|
+
value: e
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function h(e) {
|
|
172
|
+
return {
|
|
173
|
+
type: "geojson",
|
|
174
|
+
value: e
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function g(e) {
|
|
178
|
+
return {
|
|
179
|
+
type: "string",
|
|
180
|
+
value: e
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function _(e) {
|
|
184
|
+
return {
|
|
185
|
+
type: "number",
|
|
186
|
+
value: e
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function te(e) {
|
|
190
|
+
return {
|
|
191
|
+
type: "text",
|
|
192
|
+
value: e
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function ne(e) {
|
|
196
|
+
return {
|
|
197
|
+
type: "json",
|
|
198
|
+
value: e
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function v(e) {
|
|
202
|
+
return Object.entries(e ?? {}).map(([e, t]) => ({
|
|
203
|
+
name: e,
|
|
204
|
+
value: t
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
function re(e) {
|
|
208
|
+
switch (e.type) {
|
|
209
|
+
case "number": return {
|
|
210
|
+
type: "number",
|
|
211
|
+
value: e.value
|
|
212
|
+
};
|
|
213
|
+
case "text": return {
|
|
214
|
+
type: "text",
|
|
215
|
+
value: e.value
|
|
216
|
+
};
|
|
217
|
+
case "json": return {
|
|
218
|
+
type: "json",
|
|
219
|
+
value: e.value
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function y(e) {
|
|
224
|
+
d(f(e), "field value must be an object");
|
|
225
|
+
let t = e.type, n = e.value;
|
|
226
|
+
if (d(typeof t == "string", "field value type must be a string"), t === "number") return d(typeof n == "number", "field number value must be a number"), {
|
|
227
|
+
type: t,
|
|
228
|
+
value: n
|
|
229
|
+
};
|
|
230
|
+
if (d(typeof n == "string", "field text/json value must be a string"), t === "text" || t === "json") return {
|
|
231
|
+
type: t,
|
|
232
|
+
value: n
|
|
233
|
+
};
|
|
234
|
+
throw Error(`unknown field value type: ${t}`);
|
|
235
|
+
}
|
|
236
|
+
function b(e) {
|
|
237
|
+
return e ? (Array.isArray(e) ? e : v(e)).map((e) => ({
|
|
238
|
+
name: e.name,
|
|
239
|
+
value: re(e.value)
|
|
240
|
+
})) : [];
|
|
241
|
+
}
|
|
242
|
+
function x(e) {
|
|
243
|
+
if (!f(e)) return {};
|
|
244
|
+
let t = e.values;
|
|
245
|
+
return f(t) ? Object.fromEntries(Object.entries(t).map(([e, t]) => [e, y(t)])) : {};
|
|
246
|
+
}
|
|
247
|
+
function S(e) {
|
|
248
|
+
switch (e.type) {
|
|
249
|
+
case "point": return { Point: {
|
|
250
|
+
lat: e.lat,
|
|
251
|
+
lon: e.lon,
|
|
252
|
+
z: e.z ?? null
|
|
253
|
+
} };
|
|
254
|
+
case "bounds": return { Bounds: e.bounds };
|
|
255
|
+
case "hash": return { Hash: e.value };
|
|
256
|
+
case "geojson": return { GeoJson: e.value };
|
|
257
|
+
case "string": return { String: e.value };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function C(e) {
|
|
261
|
+
if (d(f(e), "geo object must be an object"), "Point" in e) {
|
|
262
|
+
let t = e.Point;
|
|
263
|
+
return d(f(t), "Point payload must be an object"), d(typeof t.lat == "number", "point lat must be a number"), d(typeof t.lon == "number", "point lon must be a number"), {
|
|
264
|
+
type: "point",
|
|
265
|
+
lat: t.lat,
|
|
266
|
+
lon: t.lon,
|
|
267
|
+
z: typeof t.z == "number" || t.z === null ? t.z : void 0
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
if ("Bounds" in e) {
|
|
271
|
+
let t = e.Bounds;
|
|
272
|
+
return d(f(t), "Bounds payload must be an object"), {
|
|
273
|
+
type: "bounds",
|
|
274
|
+
bounds: {
|
|
275
|
+
min_lat: Number(t.min_lat),
|
|
276
|
+
min_lon: Number(t.min_lon),
|
|
277
|
+
max_lat: Number(t.max_lat),
|
|
278
|
+
max_lon: Number(t.max_lon)
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
if ("Hash" in e) return d(typeof e.Hash == "string", "Hash payload must be a string"), {
|
|
283
|
+
type: "hash",
|
|
284
|
+
value: e.Hash
|
|
285
|
+
};
|
|
286
|
+
if ("GeoJson" in e) return {
|
|
287
|
+
type: "geojson",
|
|
288
|
+
value: e.GeoJson
|
|
289
|
+
};
|
|
290
|
+
if ("String" in e) return d(typeof e.String == "string", "String payload must be a string"), {
|
|
291
|
+
type: "string",
|
|
292
|
+
value: e.String
|
|
293
|
+
};
|
|
294
|
+
throw Error("unknown geo object shape");
|
|
295
|
+
}
|
|
296
|
+
function w(e) {
|
|
297
|
+
switch (e.type) {
|
|
298
|
+
case "circle": return { Circle: {
|
|
299
|
+
lat: e.lat,
|
|
300
|
+
lon: e.lon,
|
|
301
|
+
meters: e.meters
|
|
302
|
+
} };
|
|
303
|
+
case "bounds": return { Bounds: e.bounds };
|
|
304
|
+
case "hash": return { Hash: e.value };
|
|
305
|
+
case "geojson": return { GeoJson: e.value };
|
|
306
|
+
case "tile": return { Tile: {
|
|
307
|
+
x: e.x,
|
|
308
|
+
y: e.y,
|
|
309
|
+
z: e.z
|
|
310
|
+
} };
|
|
311
|
+
case "quadkey": return { Quadkey: e.value };
|
|
312
|
+
case "sector": return { Sector: {
|
|
313
|
+
lat: e.lat,
|
|
314
|
+
lon: e.lon,
|
|
315
|
+
meters: e.meters,
|
|
316
|
+
bearing1: e.bearing1,
|
|
317
|
+
bearing2: e.bearing2
|
|
318
|
+
} };
|
|
319
|
+
case "reference": return { Reference: {
|
|
320
|
+
collection: e.collection,
|
|
321
|
+
id: e.id
|
|
322
|
+
} };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function T(e) {
|
|
326
|
+
if (d(f(e), "area must be an object"), "Circle" in e) {
|
|
327
|
+
let t = e.Circle;
|
|
328
|
+
return d(f(t), "Circle payload must be an object"), d(typeof t.lat == "number", "circle lat must be a number"), d(typeof t.lon == "number", "circle lon must be a number"), d(typeof t.meters == "number", "circle meters must be a number"), {
|
|
329
|
+
type: "circle",
|
|
330
|
+
lat: t.lat,
|
|
331
|
+
lon: t.lon,
|
|
332
|
+
meters: t.meters
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
if ("Bounds" in e) {
|
|
336
|
+
let t = e.Bounds;
|
|
337
|
+
return d(f(t), "Bounds payload must be an object"), {
|
|
338
|
+
type: "bounds",
|
|
339
|
+
bounds: {
|
|
340
|
+
min_lat: Number(t.min_lat),
|
|
341
|
+
min_lon: Number(t.min_lon),
|
|
342
|
+
max_lat: Number(t.max_lat),
|
|
343
|
+
max_lon: Number(t.max_lon)
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if ("Hash" in e) return d(typeof e.Hash == "string", "Hash payload must be a string"), {
|
|
348
|
+
type: "hash",
|
|
349
|
+
value: e.Hash
|
|
350
|
+
};
|
|
351
|
+
if ("GeoJson" in e) return {
|
|
352
|
+
type: "geojson",
|
|
353
|
+
value: e.GeoJson
|
|
354
|
+
};
|
|
355
|
+
if ("Tile" in e) {
|
|
356
|
+
let t = e.Tile;
|
|
357
|
+
return d(f(t), "Tile payload must be an object"), d(typeof t.x == "number", "tile x must be a number"), d(typeof t.y == "number", "tile y must be a number"), d(typeof t.z == "number", "tile z must be a number"), {
|
|
358
|
+
type: "tile",
|
|
359
|
+
x: t.x,
|
|
360
|
+
y: t.y,
|
|
361
|
+
z: t.z
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
if ("Quadkey" in e) return d(typeof e.Quadkey == "string", "Quadkey payload must be a string"), {
|
|
365
|
+
type: "quadkey",
|
|
366
|
+
value: e.Quadkey
|
|
367
|
+
};
|
|
368
|
+
if ("Sector" in e) {
|
|
369
|
+
let t = e.Sector;
|
|
370
|
+
return d(f(t), "Sector payload must be an object"), d(typeof t.lat == "number", "sector lat must be a number"), d(typeof t.lon == "number", "sector lon must be a number"), d(typeof t.meters == "number", "sector meters must be a number"), d(typeof t.bearing1 == "number", "sector bearing1 must be a number"), d(typeof t.bearing2 == "number", "sector bearing2 must be a number"), {
|
|
371
|
+
type: "sector",
|
|
372
|
+
lat: t.lat,
|
|
373
|
+
lon: t.lon,
|
|
374
|
+
meters: t.meters,
|
|
375
|
+
bearing1: t.bearing1,
|
|
376
|
+
bearing2: t.bearing2
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if ("Reference" in e) {
|
|
380
|
+
let t = e.Reference;
|
|
381
|
+
return d(f(t), "Reference payload must be an object"), d(typeof t.collection == "string", "reference collection must be a string"), d(typeof t.id == "string", "reference id must be a string"), {
|
|
382
|
+
type: "reference",
|
|
383
|
+
collection: t.collection,
|
|
384
|
+
id: t.id
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
throw Error("unknown area shape");
|
|
388
|
+
}
|
|
389
|
+
function E(e) {
|
|
390
|
+
return e === "desc" ? "Desc" : "Asc";
|
|
391
|
+
}
|
|
392
|
+
function ie(e) {
|
|
393
|
+
return !e || e === "objects" ? "Objects" : e === "points" ? "Points" : e === "bounds" ? "Bounds" : e === "ids" ? "Ids" : e === "count" ? "Count" : { Hashes: { precision: e.hashes.precision } };
|
|
394
|
+
}
|
|
395
|
+
function ae(e) {
|
|
396
|
+
switch (e.type) {
|
|
397
|
+
case "range": return { Range: {
|
|
398
|
+
min: e.min,
|
|
399
|
+
max: e.max
|
|
400
|
+
} };
|
|
401
|
+
case "equalsText": return { EqualsText: e.value };
|
|
402
|
+
case "regex": return { Regex: e.value };
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
function D(e) {
|
|
406
|
+
let t = e ?? {};
|
|
407
|
+
return {
|
|
408
|
+
cursor: t.cursor ?? 0,
|
|
409
|
+
limit: t.limit ?? 100,
|
|
410
|
+
nofields: t.nofields ?? !1,
|
|
411
|
+
match_pattern: t.matchPattern ?? null,
|
|
412
|
+
sort: E(t.sort),
|
|
413
|
+
where_filters: (t.whereFilters ?? []).map((e) => ({
|
|
414
|
+
field: e.field,
|
|
415
|
+
comparison: ae(e.comparison)
|
|
416
|
+
})),
|
|
417
|
+
where_in_filters: t.whereInFilters ?? [],
|
|
418
|
+
where_expr_filters: t.whereExprFilters ?? [],
|
|
419
|
+
clip: t.clip ?? !1,
|
|
420
|
+
output: ie(t.output)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
function oe(e) {
|
|
424
|
+
return e == null ? null : (d(f(e), "object response must be an object"), d(typeof e.id == "string", "object id must be a string"), {
|
|
425
|
+
id: e.id,
|
|
426
|
+
geo: C(e.geo),
|
|
427
|
+
fields: x(e.fields),
|
|
428
|
+
expires_at: typeof e.expires_at == "number" ? e.expires_at : null
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
function O(e) {
|
|
432
|
+
return d(f(e), "search results must be an object"), d(Array.isArray(e.results), "search results array is missing"), {
|
|
433
|
+
results: e.results.map((e) => (d(f(e), "search result item must be an object"), d(typeof e.id == "string", "search result id must be a string"), {
|
|
434
|
+
id: e.id,
|
|
435
|
+
object: e.object === null || e.object === void 0 ? void 0 : C(e.object),
|
|
436
|
+
fields: e.fields === null || e.fields === void 0 ? void 0 : x(e.fields),
|
|
437
|
+
distance_meters: typeof e.distance_meters == "number" ? e.distance_meters : null
|
|
438
|
+
})),
|
|
439
|
+
cursor: Number(e.cursor ?? 0),
|
|
440
|
+
count: Number(e.count ?? 0)
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function k(e) {
|
|
444
|
+
return d(f(e), "server info must be an object"), {
|
|
445
|
+
version: typeof e.version == "string" ? e.version : "",
|
|
446
|
+
api_version: typeof e.api_version == "string" ? e.api_version : "",
|
|
447
|
+
protocol_version: typeof e.protocol_version == "string" ? e.protocol_version : "",
|
|
448
|
+
storage_format_version: typeof e.storage_format_version == "string" ? e.storage_format_version : "",
|
|
449
|
+
num_collections: Number(e.num_collections ?? 0),
|
|
450
|
+
num_objects: Number(e.num_objects ?? 0),
|
|
451
|
+
num_points: Number(e.num_points ?? 0),
|
|
452
|
+
heap_bytes: Number(e.heap_bytes ?? 0),
|
|
453
|
+
read_only: !!e.read_only,
|
|
454
|
+
leader: !!e.leader,
|
|
455
|
+
server_id: typeof e.server_id == "string" ? e.server_id : "",
|
|
456
|
+
following: typeof e.following == "string" ? e.following : null,
|
|
457
|
+
caught_up: !!e.caught_up,
|
|
458
|
+
caught_up_once: !!e.caught_up_once,
|
|
459
|
+
last_sequence: Number(e.last_sequence ?? 0)
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/types/events.ts
|
|
464
|
+
function A(e) {
|
|
465
|
+
switch (e) {
|
|
466
|
+
case "set": return "Set";
|
|
467
|
+
case "del": return "Del";
|
|
468
|
+
case "drop": return "Drop";
|
|
469
|
+
case "fset": return "Fset";
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function j(e) {
|
|
473
|
+
switch (e) {
|
|
474
|
+
case "inside": return "Inside";
|
|
475
|
+
case "outside": return "Outside";
|
|
476
|
+
case "enter": return "Enter";
|
|
477
|
+
case "exit": return "Exit";
|
|
478
|
+
case "cross": return "Cross";
|
|
479
|
+
case "roam": return "Roam";
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function M(e) {
|
|
483
|
+
switch (e) {
|
|
484
|
+
case "Set":
|
|
485
|
+
case "set": return "set";
|
|
486
|
+
case "Del":
|
|
487
|
+
case "del": return "del";
|
|
488
|
+
case "Drop":
|
|
489
|
+
case "drop": return "drop";
|
|
490
|
+
case "Fset":
|
|
491
|
+
case "fset": return "fset";
|
|
492
|
+
default: throw Error(`unknown mutation command: ${String(e)}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function N(e) {
|
|
496
|
+
switch (e) {
|
|
497
|
+
case "Inside":
|
|
498
|
+
case "inside": return "inside";
|
|
499
|
+
case "Outside":
|
|
500
|
+
case "outside": return "outside";
|
|
501
|
+
case "Enter":
|
|
502
|
+
case "enter": return "enter";
|
|
503
|
+
case "Exit":
|
|
504
|
+
case "exit": return "exit";
|
|
505
|
+
case "Cross":
|
|
506
|
+
case "cross": return "cross";
|
|
507
|
+
case "Roam":
|
|
508
|
+
case "roam": return "roam";
|
|
509
|
+
default: throw Error(`unknown detect type: ${String(e)}`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function P(e) {
|
|
513
|
+
switch (e.type) {
|
|
514
|
+
case "nearby": return { Nearby: {
|
|
515
|
+
lat: e.lat,
|
|
516
|
+
lon: e.lon,
|
|
517
|
+
meters: e.meters,
|
|
518
|
+
options: D(e.options)
|
|
519
|
+
} };
|
|
520
|
+
case "within": return { Within: {
|
|
521
|
+
area: w(e.area),
|
|
522
|
+
options: D(e.options)
|
|
523
|
+
} };
|
|
524
|
+
case "intersects": return { Intersects: {
|
|
525
|
+
area: w(e.area),
|
|
526
|
+
options: D(e.options)
|
|
527
|
+
} };
|
|
528
|
+
case "roam": return { Roam: {
|
|
529
|
+
target_collection: e.targetCollection,
|
|
530
|
+
target_pattern: e.targetPattern,
|
|
531
|
+
meters: e.meters,
|
|
532
|
+
options: D(e.options),
|
|
533
|
+
nodwell: e.nodwell ?? !1
|
|
534
|
+
} };
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function F(e) {
|
|
538
|
+
return {
|
|
539
|
+
collection: e.collection,
|
|
540
|
+
query: P(e.query),
|
|
541
|
+
detect: e.detect.map(j),
|
|
542
|
+
commands: e.commands.map(A)
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function I(e) {
|
|
546
|
+
return d(Array.isArray(e), "hooks response must be an array"), e.map((e) => (d(f(e), "hook info must be an object"), d(typeof e.name == "string", "hook name must be a string"), d(typeof e.endpoint == "string", "hook endpoint must be a string"), d(typeof e.collection == "string", "hook collection must be a string"), {
|
|
547
|
+
name: e.name,
|
|
548
|
+
endpoint: e.endpoint,
|
|
549
|
+
collection: e.collection
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
function L(e) {
|
|
553
|
+
return d(f(e), "channel definition must be an object"), d(typeof e.name == "string", "channel name must be a string"), {
|
|
554
|
+
name: e.name,
|
|
555
|
+
def: B(e.def)
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function R(e) {
|
|
559
|
+
return d(f(e), "hook definition must be an object"), d(typeof e.name == "string", "hook name must be a string"), d(typeof e.endpoint == "string", "hook endpoint must be a string"), {
|
|
560
|
+
name: e.name,
|
|
561
|
+
endpoint: e.endpoint,
|
|
562
|
+
def: B(e.def)
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
function z(e) {
|
|
566
|
+
return d(f(e), "geofence event must be an object"), d(typeof e.collection == "string", "event collection missing"), d(typeof e.id == "string", "event id missing"), d(typeof e.timestamp_ns == "number", "timestamp missing"), {
|
|
567
|
+
command: M(e.command),
|
|
568
|
+
detect: N(e.detect),
|
|
569
|
+
collection: e.collection,
|
|
570
|
+
id: e.id,
|
|
571
|
+
object: C(e.object),
|
|
572
|
+
fields: x(e.fields),
|
|
573
|
+
timestamp_ns: e.timestamp_ns,
|
|
574
|
+
event_id: typeof e.event_id == "string" ? e.event_id : null,
|
|
575
|
+
job_id: typeof e.job_id == "string" ? e.job_id : null,
|
|
576
|
+
hook: typeof e.hook == "string" ? e.hook : null,
|
|
577
|
+
group: typeof e.group == "string" ? e.group : null,
|
|
578
|
+
nearby: f(e.nearby) && typeof e.nearby.collection == "string" && typeof e.nearby.id == "string" && typeof e.nearby.meters == "number" ? {
|
|
579
|
+
collection: e.nearby.collection,
|
|
580
|
+
id: e.nearby.id,
|
|
581
|
+
meters: e.nearby.meters
|
|
582
|
+
} : null
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function B(e) {
|
|
586
|
+
return d(f(e), "geofence definition must be an object"), d(typeof e.collection == "string", "geofence collection must be a string"), d(Array.isArray(e.detect), "geofence detect must be an array"), d(Array.isArray(e.commands), "geofence commands must be an array"), {
|
|
587
|
+
collection: e.collection,
|
|
588
|
+
query: V(e.query),
|
|
589
|
+
detect: e.detect.map(N),
|
|
590
|
+
commands: e.commands.map(M)
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function V(e) {
|
|
594
|
+
if (d(f(e), "geofence query must be an object"), "Nearby" in e) {
|
|
595
|
+
let t = e.Nearby;
|
|
596
|
+
return d(f(t), "Nearby payload must be an object"), d(typeof t.lat == "number", "nearby lat must be a number"), d(typeof t.lon == "number", "nearby lon must be a number"), d(typeof t.meters == "number", "nearby meters must be a number"), {
|
|
597
|
+
type: "nearby",
|
|
598
|
+
lat: t.lat,
|
|
599
|
+
lon: t.lon,
|
|
600
|
+
meters: t.meters,
|
|
601
|
+
options: H(t.options)
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
if ("Within" in e) {
|
|
605
|
+
let t = e.Within;
|
|
606
|
+
return d(f(t), "Within payload must be an object"), {
|
|
607
|
+
type: "within",
|
|
608
|
+
area: T(t.area),
|
|
609
|
+
options: H(t.options)
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
if ("Intersects" in e) {
|
|
613
|
+
let t = e.Intersects;
|
|
614
|
+
return d(f(t), "Intersects payload must be an object"), {
|
|
615
|
+
type: "intersects",
|
|
616
|
+
area: T(t.area),
|
|
617
|
+
options: H(t.options)
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
if ("Roam" in e) {
|
|
621
|
+
let t = e.Roam;
|
|
622
|
+
return d(f(t), "Roam payload must be an object"), d(typeof t.target_collection == "string", "roam target_collection must be a string"), d(typeof t.target_pattern == "string", "roam target_pattern must be a string"), d(typeof t.meters == "number", "roam meters must be a number"), {
|
|
623
|
+
type: "roam",
|
|
624
|
+
targetCollection: t.target_collection,
|
|
625
|
+
targetPattern: t.target_pattern,
|
|
626
|
+
meters: t.meters,
|
|
627
|
+
options: H(t.options),
|
|
628
|
+
nodwell: typeof t.nodwell == "boolean" ? t.nodwell : void 0
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
throw Error("unknown geofence query shape");
|
|
632
|
+
}
|
|
633
|
+
function H(e) {
|
|
634
|
+
if (!f(e)) return;
|
|
635
|
+
let t = typeof e.limit == "number" ? e.limit : void 0, n = typeof e.cursor == "number" ? e.cursor : void 0, r = typeof e.nofields == "boolean" ? e.nofields : void 0, i = typeof e.match_pattern == "string" ? e.match_pattern : void 0, a = typeof e.clip == "boolean" ? e.clip : void 0, o;
|
|
636
|
+
return e.sort === "Desc" ? o = "desc" : e.sort === "Asc" && (o = "asc"), {
|
|
637
|
+
cursor: n,
|
|
638
|
+
limit: t,
|
|
639
|
+
nofields: r,
|
|
640
|
+
matchPattern: i,
|
|
641
|
+
sort: o,
|
|
642
|
+
clip: a
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region src/internal/response-parsers.ts
|
|
647
|
+
function U(t) {
|
|
648
|
+
if (t && typeof t == "object" && "collections" in t && Array.isArray(t.collections)) return t.collections.filter((e) => typeof e == "string");
|
|
649
|
+
throw new e("invalid collections response");
|
|
650
|
+
}
|
|
651
|
+
function W(t) {
|
|
652
|
+
if (t && typeof t == "object" && "channels" in t && Array.isArray(t.channels)) return t.channels.filter((e) => typeof e == "string");
|
|
653
|
+
throw new e("invalid channels response");
|
|
654
|
+
}
|
|
655
|
+
function G(t) {
|
|
656
|
+
if (!Array.isArray(t)) throw new e("invalid stats response");
|
|
657
|
+
return t;
|
|
658
|
+
}
|
|
659
|
+
function K(t) {
|
|
660
|
+
if (!t || typeof t != "object" || !("server" in t)) throw new e("invalid info response");
|
|
661
|
+
let n = t;
|
|
662
|
+
return {
|
|
663
|
+
server: k(n.server),
|
|
664
|
+
metrics: n.metrics && typeof n.metrics == "object" ? n.metrics : void 0,
|
|
665
|
+
section: typeof n.section == "string" ? n.section : void 0
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function q(t) {
|
|
669
|
+
if (t && typeof t == "object" && "bounds" in t && t.bounds && typeof t.bounds == "object") return t.bounds;
|
|
670
|
+
throw new e("invalid bounds response");
|
|
671
|
+
}
|
|
672
|
+
function se(t) {
|
|
673
|
+
if (!t || typeof t != "object" || !("name" in t) || typeof t.name != "string" || !("stats" in t) || !t.stats || typeof t.stats != "object") throw new e("invalid collection info response");
|
|
674
|
+
return t;
|
|
675
|
+
}
|
|
676
|
+
function ce(t) {
|
|
677
|
+
if (!t || typeof t != "object") throw new e("invalid webhook queue response");
|
|
678
|
+
return t;
|
|
679
|
+
}
|
|
680
|
+
function le(t) {
|
|
681
|
+
if (!t || typeof t != "object") throw new e("invalid compaction response");
|
|
682
|
+
return t;
|
|
683
|
+
}
|
|
684
|
+
function J(t) {
|
|
685
|
+
if (!t || typeof t != "object" || !("deleted" in t)) throw new e("invalid delete response");
|
|
686
|
+
return !!t.deleted;
|
|
687
|
+
}
|
|
688
|
+
function ue(t) {
|
|
689
|
+
if (!t || typeof t != "object" || !("deleted" in t)) throw new e("invalid delete response");
|
|
690
|
+
return Number(t.deleted ?? 0);
|
|
691
|
+
}
|
|
692
|
+
function de(t) {
|
|
693
|
+
if (!t || typeof t != "object" || !("stored" in t)) throw new e("invalid set response");
|
|
694
|
+
return !!t.stored;
|
|
695
|
+
}
|
|
696
|
+
function fe(t) {
|
|
697
|
+
if (!t || typeof t != "object" || !("updated" in t)) throw new e("invalid update response");
|
|
698
|
+
return !!t.updated;
|
|
699
|
+
}
|
|
700
|
+
function pe(t) {
|
|
701
|
+
if (!t || typeof t != "object" || !("renamed" in t)) throw new e("invalid rename response");
|
|
702
|
+
return !!t.renamed;
|
|
703
|
+
}
|
|
704
|
+
function me(t) {
|
|
705
|
+
if (!t || typeof t != "object" || !("dropped" in t)) throw new e("invalid drop response");
|
|
706
|
+
return !!t.dropped;
|
|
707
|
+
}
|
|
708
|
+
function he(e) {
|
|
709
|
+
if (e === null) return null;
|
|
710
|
+
if (e && typeof e == "object" && "type" in e) return y(e);
|
|
711
|
+
if (e && typeof e == "object" && "value" in e) {
|
|
712
|
+
let t = e.value;
|
|
713
|
+
return t == null ? null : y(t);
|
|
714
|
+
}
|
|
715
|
+
return y(e);
|
|
716
|
+
}
|
|
717
|
+
function ge(t) {
|
|
718
|
+
if (!t || typeof t != "object" || !("ttl" in t)) throw new e("invalid ttl response");
|
|
719
|
+
let n = t.ttl;
|
|
720
|
+
return typeof n == "number" ? n : null;
|
|
721
|
+
}
|
|
722
|
+
function _e(e) {
|
|
723
|
+
if (e === null) return null;
|
|
724
|
+
let t = e && typeof e == "object" && "value" in e ? e.value : e;
|
|
725
|
+
if (t == null) return null;
|
|
726
|
+
if (typeof t != "string") return t;
|
|
727
|
+
try {
|
|
728
|
+
return JSON.parse(t);
|
|
729
|
+
} catch {
|
|
730
|
+
return t;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
function Y(t, n) {
|
|
734
|
+
if (!t || typeof t != "object" || !(n in t)) throw new e(`invalid ${n} response`);
|
|
735
|
+
return !!t[n];
|
|
736
|
+
}
|
|
737
|
+
function ve(t) {
|
|
738
|
+
if (!t || typeof t != "object" || !("seconds" in t)) throw new e("invalid timeout response");
|
|
739
|
+
let n = t.seconds;
|
|
740
|
+
return typeof n == "number" ? n : null;
|
|
741
|
+
}
|
|
742
|
+
function ye(e) {
|
|
743
|
+
return L(e);
|
|
744
|
+
}
|
|
745
|
+
function X(e) {
|
|
746
|
+
return R(e);
|
|
747
|
+
}
|
|
748
|
+
function be(e) {
|
|
749
|
+
return I(e);
|
|
750
|
+
}
|
|
751
|
+
//#endregion
|
|
752
|
+
//#region src/routing/read-preference.ts
|
|
753
|
+
function xe(e, t, n) {
|
|
754
|
+
let r = e.filter((e) => e.eligible).map((e) => e.url);
|
|
755
|
+
if (r.length === 0) return [];
|
|
756
|
+
if (t === "roundRobinFollowers") {
|
|
757
|
+
let e = n % r.length;
|
|
758
|
+
return [...r.slice(e), ...r.slice(0, e)];
|
|
759
|
+
}
|
|
760
|
+
return r;
|
|
761
|
+
}
|
|
762
|
+
//#endregion
|
|
763
|
+
//#region src/routing/replicas.ts
|
|
764
|
+
var Se = class {
|
|
765
|
+
leaderUrl;
|
|
766
|
+
readReplicas;
|
|
767
|
+
readPreference;
|
|
768
|
+
statusTtlMs;
|
|
769
|
+
statusCache = /* @__PURE__ */ new Map();
|
|
770
|
+
roundRobinCursor = 0;
|
|
771
|
+
constructor(e) {
|
|
772
|
+
this.leaderUrl = e.leaderUrl, this.readReplicas = e.readReplicas ?? [], this.readPreference = e.readPreference ?? "leader", this.statusTtlMs = e.statusTtlMs ?? 1e3;
|
|
773
|
+
}
|
|
774
|
+
getLeaderUrl() {
|
|
775
|
+
return this.leaderUrl;
|
|
776
|
+
}
|
|
777
|
+
async getReadCandidates(e) {
|
|
778
|
+
let t = xe(await Promise.all(this.readReplicas.map(async (t) => ({
|
|
779
|
+
url: t,
|
|
780
|
+
eligible: await this.isEligibleReplica(t, e)
|
|
781
|
+
}))), this.readPreference, this.roundRobinCursor);
|
|
782
|
+
return this.readPreference === "roundRobinFollowers" && t.length > 0 && (this.roundRobinCursor += 1), t;
|
|
783
|
+
}
|
|
784
|
+
getReadPreference() {
|
|
785
|
+
return this.readPreference;
|
|
786
|
+
}
|
|
787
|
+
async isEligibleReplica(e, t) {
|
|
788
|
+
let n = Date.now(), r = this.statusCache.get(e);
|
|
789
|
+
if (r && r.expiresAt > n) return !!(r.info && !r.info.leader && r.info.caught_up_once);
|
|
790
|
+
try {
|
|
791
|
+
let r = await t.request({
|
|
792
|
+
baseUrl: e,
|
|
793
|
+
path: s.server(),
|
|
794
|
+
parser: k
|
|
795
|
+
});
|
|
796
|
+
return this.statusCache.set(e, {
|
|
797
|
+
expiresAt: n + this.statusTtlMs,
|
|
798
|
+
info: r
|
|
799
|
+
}), !r.leader && r.caught_up_once;
|
|
800
|
+
} catch {
|
|
801
|
+
return this.statusCache.set(e, { expiresAt: n + this.statusTtlMs }), !1;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}, Ce = class {
|
|
805
|
+
values = [];
|
|
806
|
+
resolvers = [];
|
|
807
|
+
closed = !1;
|
|
808
|
+
push(e) {
|
|
809
|
+
if (this.closed) return;
|
|
810
|
+
let t = this.resolvers.shift();
|
|
811
|
+
if (t) {
|
|
812
|
+
t({
|
|
813
|
+
value: e,
|
|
814
|
+
done: !1
|
|
815
|
+
});
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
this.values.push(e);
|
|
819
|
+
}
|
|
820
|
+
close() {
|
|
821
|
+
for (this.closed = !0; this.resolvers.length > 0;) this.resolvers.shift()?.({
|
|
822
|
+
value: void 0,
|
|
823
|
+
done: !0
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
next() {
|
|
827
|
+
let e = this.values.shift();
|
|
828
|
+
return e === void 0 ? this.closed ? Promise.resolve({
|
|
829
|
+
value: void 0,
|
|
830
|
+
done: !0
|
|
831
|
+
}) : new Promise((e) => {
|
|
832
|
+
this.resolvers.push(e);
|
|
833
|
+
}) : Promise.resolve({
|
|
834
|
+
value: e,
|
|
835
|
+
done: !1
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
}, Z = class {
|
|
839
|
+
events = new Ce();
|
|
840
|
+
eventHandlers = /* @__PURE__ */ new Set();
|
|
841
|
+
closeHandlers = /* @__PURE__ */ new Set();
|
|
842
|
+
errorHandlers = /* @__PURE__ */ new Set();
|
|
843
|
+
closeFn;
|
|
844
|
+
closed = !1;
|
|
845
|
+
constructor(e) {
|
|
846
|
+
this.closeFn = e;
|
|
847
|
+
}
|
|
848
|
+
on(e, t) {
|
|
849
|
+
return e === "event" ? (this.eventHandlers.add(t), () => {
|
|
850
|
+
this.eventHandlers.delete(t);
|
|
851
|
+
}) : e === "close" ? (this.closeHandlers.add(t), () => {
|
|
852
|
+
this.closeHandlers.delete(t);
|
|
853
|
+
}) : (this.errorHandlers.add(t), () => {
|
|
854
|
+
this.errorHandlers.delete(t);
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
push(e) {
|
|
858
|
+
this.events.push(e);
|
|
859
|
+
for (let t of this.eventHandlers) t(e);
|
|
860
|
+
}
|
|
861
|
+
fail(e) {
|
|
862
|
+
for (let t of this.errorHandlers) t(e);
|
|
863
|
+
}
|
|
864
|
+
close() {
|
|
865
|
+
this.closed || (this.closed = !0, this.closeFn(), this.finish());
|
|
866
|
+
}
|
|
867
|
+
finish() {
|
|
868
|
+
this.closed ||= !0, this.events.close();
|
|
869
|
+
for (let e of this.closeHandlers) e();
|
|
870
|
+
}
|
|
871
|
+
[Symbol.asyncIterator]() {
|
|
872
|
+
return { next: () => this.events.next() };
|
|
873
|
+
}
|
|
874
|
+
}, Q = class t {
|
|
875
|
+
socket;
|
|
876
|
+
token;
|
|
877
|
+
pending = [];
|
|
878
|
+
activeSubscription;
|
|
879
|
+
constructor(t, n) {
|
|
880
|
+
this.socket = t, this.token = n, this.socket.addEventListener("message", (e) => {
|
|
881
|
+
this.handleMessage(e);
|
|
882
|
+
}), this.socket.addEventListener("close", () => {
|
|
883
|
+
for (this.activeSubscription?.finish(), this.activeSubscription = void 0; this.pending.length > 0;) this.pending.shift()?.reject(new e("websocket closed before command acknowledgement"));
|
|
884
|
+
}), this.socket.addEventListener("error", () => {
|
|
885
|
+
this.activeSubscription?.fail(new e("websocket transport error"));
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
static async connect(n) {
|
|
889
|
+
let r = (n.webSocketFactory ?? ((t) => {
|
|
890
|
+
if (typeof WebSocket != "function") throw new e("global WebSocket is not available");
|
|
891
|
+
return new WebSocket(t);
|
|
892
|
+
}))(n.url);
|
|
893
|
+
await new Promise((t, n) => {
|
|
894
|
+
r.addEventListener("open", () => t(), { once: !0 }), r.addEventListener("error", () => n(new e("failed to open websocket")), { once: !0 });
|
|
895
|
+
});
|
|
896
|
+
let i = new t(r, n.token);
|
|
897
|
+
if (n.token) {
|
|
898
|
+
let t = await i.command({
|
|
899
|
+
type: "auth",
|
|
900
|
+
token: n.token
|
|
901
|
+
});
|
|
902
|
+
if (!t || typeof t != "object" || t.authorized !== !0) throw new e("websocket authentication failed");
|
|
903
|
+
}
|
|
904
|
+
return i;
|
|
905
|
+
}
|
|
906
|
+
async ping() {
|
|
907
|
+
return this.command({ type: "ping" });
|
|
908
|
+
}
|
|
909
|
+
async subscribe(e) {
|
|
910
|
+
let t = this.replaceSubscription();
|
|
911
|
+
try {
|
|
912
|
+
return await this.command({
|
|
913
|
+
type: "subscribe",
|
|
914
|
+
channels: e
|
|
915
|
+
}), t;
|
|
916
|
+
} catch (e) {
|
|
917
|
+
throw t.close(), e;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
async psubscribe(e) {
|
|
921
|
+
let t = this.replaceSubscription();
|
|
922
|
+
try {
|
|
923
|
+
return await this.command({
|
|
924
|
+
type: "psubscribe",
|
|
925
|
+
patterns: e
|
|
926
|
+
}), t;
|
|
927
|
+
} catch (e) {
|
|
928
|
+
throw t.close(), e;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
async quit() {
|
|
932
|
+
try {
|
|
933
|
+
await this.command({ type: "quit" });
|
|
934
|
+
} catch {} finally {
|
|
935
|
+
this.close();
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
close() {
|
|
939
|
+
this.socket.close();
|
|
940
|
+
}
|
|
941
|
+
replaceSubscription() {
|
|
942
|
+
this.activeSubscription?.close();
|
|
943
|
+
let e = new Z(() => {
|
|
944
|
+
this.close();
|
|
945
|
+
});
|
|
946
|
+
return this.activeSubscription = e, e;
|
|
947
|
+
}
|
|
948
|
+
async command(t) {
|
|
949
|
+
if (this.socket.readyState !== WebSocket.OPEN) throw new e("websocket is not open");
|
|
950
|
+
let n = new Promise((e, t) => {
|
|
951
|
+
this.pending.push({
|
|
952
|
+
resolve: e,
|
|
953
|
+
reject: t
|
|
954
|
+
});
|
|
955
|
+
});
|
|
956
|
+
return this.socket.send(JSON.stringify(t)), n;
|
|
957
|
+
}
|
|
958
|
+
handleMessage(t) {
|
|
959
|
+
let n = JSON.parse(t.data), r = this.tryParseEvent(n);
|
|
960
|
+
if (r) {
|
|
961
|
+
this.activeSubscription?.push(r);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
let i = this.pending.shift();
|
|
965
|
+
if (i) {
|
|
966
|
+
if (n && typeof n == "object" && "error" in n && typeof n.error == "string") {
|
|
967
|
+
i.reject(new e(n.error));
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
i.resolve(n);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
tryParseEvent(e) {
|
|
974
|
+
try {
|
|
975
|
+
return z(e);
|
|
976
|
+
} catch {
|
|
977
|
+
return null;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
//#endregion
|
|
982
|
+
//#region src/client.ts
|
|
983
|
+
function we(e) {
|
|
984
|
+
switch (e) {
|
|
985
|
+
case "nx": return "Nx";
|
|
986
|
+
case "xx": return "Xx";
|
|
987
|
+
default: return "Always";
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
function Te(e) {
|
|
991
|
+
return !e || e === "objects" ? { format: "objects" } : e === "points" || e === "bounds" ? { format: e } : "hashes" in e ? {
|
|
992
|
+
format: "hashes",
|
|
993
|
+
hash_precision: e.hashes.precision
|
|
994
|
+
} : { format: "objects" };
|
|
995
|
+
}
|
|
996
|
+
var Ee = class {
|
|
997
|
+
transport;
|
|
998
|
+
replicaRouter;
|
|
999
|
+
token;
|
|
1000
|
+
webSocketFactory;
|
|
1001
|
+
constructor(e) {
|
|
1002
|
+
this.transport = new u({
|
|
1003
|
+
baseUrl: e.leaderUrl,
|
|
1004
|
+
token: e.token,
|
|
1005
|
+
timeoutMs: e.timeoutMs,
|
|
1006
|
+
headers: e.headers,
|
|
1007
|
+
fetch: e.fetch
|
|
1008
|
+
}), this.replicaRouter = new Se({
|
|
1009
|
+
leaderUrl: e.leaderUrl,
|
|
1010
|
+
readReplicas: e.readReplicas,
|
|
1011
|
+
readPreference: e.readPreference,
|
|
1012
|
+
statusTtlMs: e.replicaStatusTtlMs
|
|
1013
|
+
}), this.token = e.token, this.webSocketFactory = e.webSocketFactory;
|
|
1014
|
+
}
|
|
1015
|
+
async ping() {
|
|
1016
|
+
return this.requestLeader({
|
|
1017
|
+
path: s.ping(),
|
|
1018
|
+
parser: (e) => e
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
async healthz() {
|
|
1022
|
+
return this.requestLeader({
|
|
1023
|
+
path: s.healthz(),
|
|
1024
|
+
parser: (e) => e
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
async server() {
|
|
1028
|
+
return this.requestLeader({
|
|
1029
|
+
path: s.server(),
|
|
1030
|
+
parser: k
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
async info(e) {
|
|
1034
|
+
return this.requestLeader({
|
|
1035
|
+
path: s.info(e),
|
|
1036
|
+
parser: K
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
async metrics() {
|
|
1040
|
+
return this.transport.requestText({ path: s.metrics() });
|
|
1041
|
+
}
|
|
1042
|
+
async collections(e) {
|
|
1043
|
+
return this.requestRead({
|
|
1044
|
+
path: s.collections(e),
|
|
1045
|
+
parser: U
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
async createCollection(e) {
|
|
1049
|
+
return this.requestWrite({
|
|
1050
|
+
method: "POST",
|
|
1051
|
+
path: s.collection(e),
|
|
1052
|
+
parser: (e) => Y(e, "created")
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
async getCollection(e) {
|
|
1056
|
+
try {
|
|
1057
|
+
return await this.requestRead({
|
|
1058
|
+
path: s.collection(e),
|
|
1059
|
+
parser: se
|
|
1060
|
+
});
|
|
1061
|
+
} catch (e) {
|
|
1062
|
+
if (e instanceof n && e.status === 404) return null;
|
|
1063
|
+
throw e;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
async rename(e, t, n) {
|
|
1067
|
+
return this.requestWrite({
|
|
1068
|
+
method: "POST",
|
|
1069
|
+
path: s.renameCollection(e),
|
|
1070
|
+
body: {
|
|
1071
|
+
new_name: t,
|
|
1072
|
+
nx: n?.nx ?? !1
|
|
1073
|
+
},
|
|
1074
|
+
parser: pe
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
async bounds(e) {
|
|
1078
|
+
return this.requestRead({
|
|
1079
|
+
path: s.bounds(e),
|
|
1080
|
+
parser: q
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
async stats(e) {
|
|
1084
|
+
return this.requestRead({
|
|
1085
|
+
path: s.stats(e),
|
|
1086
|
+
parser: G
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
async setObject(e, t, n, r) {
|
|
1090
|
+
return this.requestWrite({
|
|
1091
|
+
method: "POST",
|
|
1092
|
+
path: s.object(e, t),
|
|
1093
|
+
body: {
|
|
1094
|
+
object: S(n),
|
|
1095
|
+
fields: b(r?.fields),
|
|
1096
|
+
expire_seconds: r?.expireSeconds,
|
|
1097
|
+
condition: we(r?.condition)
|
|
1098
|
+
},
|
|
1099
|
+
parser: de
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
async setPoint(e, t, n, r) {
|
|
1103
|
+
return this.setObject(e, t, p(n.lat, n.lon, n.z), r);
|
|
1104
|
+
}
|
|
1105
|
+
async get(e, t, n) {
|
|
1106
|
+
let r = Te(n?.format);
|
|
1107
|
+
return this.requestRead({
|
|
1108
|
+
path: `${s.object(e, t)}${De({
|
|
1109
|
+
with_fields: n?.withFields ?? !1,
|
|
1110
|
+
format: r.format,
|
|
1111
|
+
hash_precision: r.hash_precision
|
|
1112
|
+
})}`,
|
|
1113
|
+
parser: oe
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
async delete(e, t) {
|
|
1117
|
+
return this.requestWrite({
|
|
1118
|
+
method: "DELETE",
|
|
1119
|
+
path: s.object(e, t),
|
|
1120
|
+
parser: J
|
|
1121
|
+
});
|
|
1122
|
+
}
|
|
1123
|
+
async deleteMatching(e, t) {
|
|
1124
|
+
return this.requestWrite({
|
|
1125
|
+
method: "DELETE",
|
|
1126
|
+
path: s.objects(e, t?.matchPattern),
|
|
1127
|
+
parser: ue
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
async setFields(e, t, n, r) {
|
|
1131
|
+
return this.requestWrite({
|
|
1132
|
+
method: "POST",
|
|
1133
|
+
path: s.fields(e, t),
|
|
1134
|
+
body: {
|
|
1135
|
+
fields: b(n),
|
|
1136
|
+
xx: r?.xx ?? !1
|
|
1137
|
+
},
|
|
1138
|
+
parser: fe
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
async getField(e, t, n) {
|
|
1142
|
+
return this.requestRead({
|
|
1143
|
+
path: s.field(e, t, n),
|
|
1144
|
+
parser: he
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
async expire(e, t, n) {
|
|
1148
|
+
await this.requestWrite({
|
|
1149
|
+
method: "POST",
|
|
1150
|
+
path: s.expire(e, t),
|
|
1151
|
+
body: { seconds: n },
|
|
1152
|
+
parser: () => void 0
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
async persist(e, t) {
|
|
1156
|
+
await this.requestWrite({
|
|
1157
|
+
method: "DELETE",
|
|
1158
|
+
path: s.expire(e, t),
|
|
1159
|
+
parser: () => void 0
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
async ttl(e, t) {
|
|
1163
|
+
return this.requestRead({
|
|
1164
|
+
path: s.ttl(e, t),
|
|
1165
|
+
parser: ge
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
async setJson(e, t, n, r, i) {
|
|
1169
|
+
await this.requestWrite({
|
|
1170
|
+
method: "POST",
|
|
1171
|
+
path: s.jsonRoot(e, t),
|
|
1172
|
+
body: {
|
|
1173
|
+
path: n,
|
|
1174
|
+
value: r,
|
|
1175
|
+
raw: i?.raw ?? !1
|
|
1176
|
+
},
|
|
1177
|
+
parser: () => void 0
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
async getJson(e, t, n) {
|
|
1181
|
+
return this.requestRead({
|
|
1182
|
+
path: s.jsonPath(e, t, n),
|
|
1183
|
+
parser: _e
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
async deleteJson(e, t, n) {
|
|
1187
|
+
return this.requestWrite({
|
|
1188
|
+
method: "DELETE",
|
|
1189
|
+
path: s.jsonPath(e, t, n),
|
|
1190
|
+
parser: (e) => Y(e, "deleted")
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
async nearby(e, t) {
|
|
1194
|
+
return this.requestRead({
|
|
1195
|
+
method: "POST",
|
|
1196
|
+
path: s.nearby(e),
|
|
1197
|
+
body: {
|
|
1198
|
+
lat: t.lat,
|
|
1199
|
+
lon: t.lon,
|
|
1200
|
+
meters: t.meters,
|
|
1201
|
+
options: D(t.options)
|
|
1202
|
+
},
|
|
1203
|
+
parser: O
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
async within(e, t) {
|
|
1207
|
+
return this.requestRead({
|
|
1208
|
+
method: "POST",
|
|
1209
|
+
path: s.within(e),
|
|
1210
|
+
body: {
|
|
1211
|
+
area: w(t.area),
|
|
1212
|
+
options: D(t.options)
|
|
1213
|
+
},
|
|
1214
|
+
parser: O
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
async intersects(e, t) {
|
|
1218
|
+
return this.requestRead({
|
|
1219
|
+
method: "POST",
|
|
1220
|
+
path: s.intersects(e),
|
|
1221
|
+
body: {
|
|
1222
|
+
area: w(t.area),
|
|
1223
|
+
options: D(t.options)
|
|
1224
|
+
},
|
|
1225
|
+
parser: O
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
async scan(e, t) {
|
|
1229
|
+
return this.requestRead({
|
|
1230
|
+
method: "POST",
|
|
1231
|
+
path: s.scan(e),
|
|
1232
|
+
body: D(t),
|
|
1233
|
+
parser: O
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
async search(e, t) {
|
|
1237
|
+
return this.requestRead({
|
|
1238
|
+
method: "POST",
|
|
1239
|
+
path: s.search(e),
|
|
1240
|
+
body: D(t),
|
|
1241
|
+
parser: O
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
async setChannel(t) {
|
|
1245
|
+
return this.requestWrite({
|
|
1246
|
+
method: "POST",
|
|
1247
|
+
path: s.channels(),
|
|
1248
|
+
body: {
|
|
1249
|
+
name: t.name,
|
|
1250
|
+
def: F(t.def)
|
|
1251
|
+
},
|
|
1252
|
+
parser: (t) => {
|
|
1253
|
+
if (!t || typeof t != "object" || !("name" in t)) throw new e("invalid set channel response");
|
|
1254
|
+
return String(t.name ?? "");
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
async deleteChannel(e) {
|
|
1259
|
+
return this.requestWrite({
|
|
1260
|
+
method: "DELETE",
|
|
1261
|
+
path: s.channel(e),
|
|
1262
|
+
parser: J
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
async channels(e) {
|
|
1266
|
+
return this.requestRead({
|
|
1267
|
+
path: s.channels(e),
|
|
1268
|
+
parser: W
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
async getChannel(e) {
|
|
1272
|
+
try {
|
|
1273
|
+
return await this.requestRead({
|
|
1274
|
+
path: s.channel(e),
|
|
1275
|
+
parser: ye
|
|
1276
|
+
});
|
|
1277
|
+
} catch (e) {
|
|
1278
|
+
if (e instanceof n && e.status === 404) return null;
|
|
1279
|
+
throw e;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
async setHook(e) {
|
|
1283
|
+
await this.requestWrite({
|
|
1284
|
+
method: "POST",
|
|
1285
|
+
path: s.hooks(),
|
|
1286
|
+
body: {
|
|
1287
|
+
name: e.name,
|
|
1288
|
+
endpoint: e.endpoint,
|
|
1289
|
+
def: F(e.def)
|
|
1290
|
+
},
|
|
1291
|
+
parser: () => void 0
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
async deleteHook(e) {
|
|
1295
|
+
return this.requestWrite({
|
|
1296
|
+
method: "DELETE",
|
|
1297
|
+
path: s.hook(e),
|
|
1298
|
+
parser: J
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
async hooks(e) {
|
|
1302
|
+
return this.requestRead({
|
|
1303
|
+
path: s.hooks(e),
|
|
1304
|
+
parser: be
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
async getHook(e) {
|
|
1308
|
+
try {
|
|
1309
|
+
return await this.requestRead({
|
|
1310
|
+
path: s.hook(e),
|
|
1311
|
+
parser: X
|
|
1312
|
+
});
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
if (e instanceof n && e.status === 404) return null;
|
|
1315
|
+
throw e;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
async configGet(t) {
|
|
1319
|
+
return this.requestLeader({
|
|
1320
|
+
path: s.config(t),
|
|
1321
|
+
parser: (t) => {
|
|
1322
|
+
if (!t || typeof t != "object" || !("value" in t)) throw new e("invalid config response");
|
|
1323
|
+
return String(t.value ?? "");
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
async configSet(e, t) {
|
|
1328
|
+
await this.requestWrite({
|
|
1329
|
+
method: "POST",
|
|
1330
|
+
path: s.config(e),
|
|
1331
|
+
body: { value: t },
|
|
1332
|
+
parser: () => void 0
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
async configRewrite() {
|
|
1336
|
+
await this.requestWrite({
|
|
1337
|
+
method: "POST",
|
|
1338
|
+
path: s.configRewrite(),
|
|
1339
|
+
parser: () => void 0
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
async flushdb() {
|
|
1343
|
+
await this.requestWrite({
|
|
1344
|
+
method: "POST",
|
|
1345
|
+
path: s.flushdb(),
|
|
1346
|
+
parser: () => void 0
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
async gc() {
|
|
1350
|
+
await this.requestWrite({
|
|
1351
|
+
method: "POST",
|
|
1352
|
+
path: s.gc(),
|
|
1353
|
+
parser: () => void 0
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
async aofshrink() {
|
|
1357
|
+
return this.requestWrite({
|
|
1358
|
+
method: "POST",
|
|
1359
|
+
path: s.aofshrink(),
|
|
1360
|
+
parser: le
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
async webhookQueue() {
|
|
1364
|
+
return this.requestLeader({
|
|
1365
|
+
path: s.webhookQueue(),
|
|
1366
|
+
parser: ce
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
async readonly(t) {
|
|
1370
|
+
return this.requestWrite({
|
|
1371
|
+
method: "POST",
|
|
1372
|
+
path: s.readonly(),
|
|
1373
|
+
body: { enabled: t },
|
|
1374
|
+
parser: (t) => {
|
|
1375
|
+
if (!t || typeof t != "object" || !("read_only" in t)) throw new e("invalid readonly response");
|
|
1376
|
+
return !!t.read_only;
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
async timeout(e) {
|
|
1381
|
+
return this.requestWrite({
|
|
1382
|
+
method: "POST",
|
|
1383
|
+
path: s.timeout(),
|
|
1384
|
+
body: e,
|
|
1385
|
+
parser: ve
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
async dropCollection(e) {
|
|
1389
|
+
return this.requestWrite({
|
|
1390
|
+
method: "DELETE",
|
|
1391
|
+
path: s.collection(e),
|
|
1392
|
+
parser: me
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
async connectWebSocket(e) {
|
|
1396
|
+
return Q.connect({
|
|
1397
|
+
url: e?.url ?? Oe(this.replicaRouter.getLeaderUrl()),
|
|
1398
|
+
token: this.token,
|
|
1399
|
+
webSocketFactory: this.webSocketFactory
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
async requestWrite(e) {
|
|
1403
|
+
return this.transport.request(e);
|
|
1404
|
+
}
|
|
1405
|
+
async requestLeader(e) {
|
|
1406
|
+
return this.transport.request(e);
|
|
1407
|
+
}
|
|
1408
|
+
async requestRead(e) {
|
|
1409
|
+
let t = this.replicaRouter.getReadPreference();
|
|
1410
|
+
if (t === "leader") return this.transport.request(e);
|
|
1411
|
+
let n = await this.replicaRouter.getReadCandidates(this.transport);
|
|
1412
|
+
if (t === "leaderPreferred") {
|
|
1413
|
+
try {
|
|
1414
|
+
return await this.requestLeader(e);
|
|
1415
|
+
} catch (e) {
|
|
1416
|
+
if (!$(e)) throw e;
|
|
1417
|
+
}
|
|
1418
|
+
for (let t of n) try {
|
|
1419
|
+
return await this.transport.request({
|
|
1420
|
+
...e,
|
|
1421
|
+
baseUrl: t
|
|
1422
|
+
});
|
|
1423
|
+
} catch (e) {
|
|
1424
|
+
if (!$(e)) throw e;
|
|
1425
|
+
}
|
|
1426
|
+
return this.requestLeader(e);
|
|
1427
|
+
}
|
|
1428
|
+
for (let t of n) try {
|
|
1429
|
+
return await this.transport.request({
|
|
1430
|
+
...e,
|
|
1431
|
+
baseUrl: t
|
|
1432
|
+
});
|
|
1433
|
+
} catch (e) {
|
|
1434
|
+
if (!$(e)) throw e;
|
|
1435
|
+
}
|
|
1436
|
+
return this.requestLeader(e);
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
function $(e) {
|
|
1440
|
+
return e instanceof i || e instanceof t || !(e instanceof n);
|
|
1441
|
+
}
|
|
1442
|
+
function De(e) {
|
|
1443
|
+
let t = new URLSearchParams();
|
|
1444
|
+
for (let [n, r] of Object.entries(e)) r !== void 0 && t.set(n, String(r));
|
|
1445
|
+
let n = t.toString();
|
|
1446
|
+
return n ? `?${n}` : "";
|
|
1447
|
+
}
|
|
1448
|
+
function Oe(e) {
|
|
1449
|
+
let t = new URL(e);
|
|
1450
|
+
return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.pathname = s.ws(), t.search = "", t.hash = "", t.toString();
|
|
1451
|
+
}
|
|
1452
|
+
//#endregion
|
|
1453
|
+
export { r as AuthError, n as HttpError, Ee as LatLngClient, e as LatLngError, Z as LatLngSubscription, Q as LatLngWebSocketClient, i as ServerUnavailableError, t as TimeoutError, ee as bounds, v as fieldEntries, h as geojson, m as hash, ne as jsonField, _ as numberField, z as parseGeofenceEvent, p as point, g as stringObject, te as textField };
|
|
1454
|
+
|
|
1455
|
+
//# sourceMappingURL=index.js.map
|