@lumibase/sdk 0.21.0 → 0.22.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/dist/index.cjs +12 -3
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +12 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -370,6 +370,7 @@ var RealtimeClient = class {
|
|
|
370
370
|
opts;
|
|
371
371
|
ws = null;
|
|
372
372
|
subscriptions = /* @__PURE__ */ new Map();
|
|
373
|
+
subscriptionFilters = /* @__PURE__ */ new Map();
|
|
373
374
|
presenceListeners = /* @__PURE__ */ new Set();
|
|
374
375
|
currentPresence = {};
|
|
375
376
|
sessionId = null;
|
|
@@ -402,14 +403,20 @@ var RealtimeClient = class {
|
|
|
402
403
|
* Subscribe to item mutation events for a specific collection.
|
|
403
404
|
* Multiple handlers per collection are supported.
|
|
404
405
|
*
|
|
406
|
+
* `opts.filter` is an optional Directus-style condition rule evaluated
|
|
407
|
+
* server-side over the event envelope (`collection`/`action`/`itemId`) —
|
|
408
|
+
* studio broadcasts are signal-only, so row data is never filterable. The
|
|
409
|
+
* filter is per-collection: the most recent subscribe call's filter wins.
|
|
410
|
+
*
|
|
405
411
|
* @returns Unsubscribe function.
|
|
406
412
|
*/
|
|
407
|
-
subscribe(collection, callback) {
|
|
413
|
+
subscribe(collection, callback, opts = {}) {
|
|
408
414
|
if (!this.subscriptions.has(collection)) {
|
|
409
415
|
this.subscriptions.set(collection, /* @__PURE__ */ new Set());
|
|
410
416
|
}
|
|
411
417
|
this.subscriptions.get(collection).add(callback);
|
|
412
|
-
this.
|
|
418
|
+
if (opts.filter) this.subscriptionFilters.set(collection, opts.filter);
|
|
419
|
+
this._send({ type: "subscribe", collection, ...opts.filter ? { filter: opts.filter } : {} });
|
|
413
420
|
return () => this.unsubscribe(collection, callback);
|
|
414
421
|
}
|
|
415
422
|
/** Remove a specific handler from a collection subscription. */
|
|
@@ -419,6 +426,7 @@ var RealtimeClient = class {
|
|
|
419
426
|
set.delete(callback);
|
|
420
427
|
if (set.size === 0) {
|
|
421
428
|
this.subscriptions.delete(collection);
|
|
429
|
+
this.subscriptionFilters.delete(collection);
|
|
422
430
|
this._send({ type: "unsubscribe", collection });
|
|
423
431
|
}
|
|
424
432
|
}
|
|
@@ -483,7 +491,8 @@ var RealtimeClient = class {
|
|
|
483
491
|
ws.addEventListener("open", () => {
|
|
484
492
|
this.backoffMs = this.opts.initialBackoffMs ?? 1e3;
|
|
485
493
|
for (const collection of this.subscriptions.keys()) {
|
|
486
|
-
this.
|
|
494
|
+
const filter = this.subscriptionFilters.get(collection);
|
|
495
|
+
this._sendRaw({ type: "subscribe", collection, ...filter ? { filter } : {} });
|
|
487
496
|
}
|
|
488
497
|
if (Object.keys(this.currentPresence).length > 0) {
|
|
489
498
|
this._sendRaw({ type: "presence", ...this.currentPresence });
|
package/dist/index.d.cts
CHANGED
|
@@ -1563,6 +1563,7 @@ declare class RealtimeClient {
|
|
|
1563
1563
|
private readonly opts;
|
|
1564
1564
|
private ws;
|
|
1565
1565
|
private readonly subscriptions;
|
|
1566
|
+
private readonly subscriptionFilters;
|
|
1566
1567
|
private presenceListeners;
|
|
1567
1568
|
private currentPresence;
|
|
1568
1569
|
private sessionId;
|
|
@@ -1578,9 +1579,16 @@ declare class RealtimeClient {
|
|
|
1578
1579
|
* Subscribe to item mutation events for a specific collection.
|
|
1579
1580
|
* Multiple handlers per collection are supported.
|
|
1580
1581
|
*
|
|
1582
|
+
* `opts.filter` is an optional Directus-style condition rule evaluated
|
|
1583
|
+
* server-side over the event envelope (`collection`/`action`/`itemId`) —
|
|
1584
|
+
* studio broadcasts are signal-only, so row data is never filterable. The
|
|
1585
|
+
* filter is per-collection: the most recent subscribe call's filter wins.
|
|
1586
|
+
*
|
|
1581
1587
|
* @returns Unsubscribe function.
|
|
1582
1588
|
*/
|
|
1583
|
-
subscribe(collection: string, callback: RealtimeEventCallback
|
|
1589
|
+
subscribe(collection: string, callback: RealtimeEventCallback, opts?: {
|
|
1590
|
+
filter?: Record<string, unknown>;
|
|
1591
|
+
}): () => void;
|
|
1584
1592
|
/** Remove a specific handler from a collection subscription. */
|
|
1585
1593
|
unsubscribe(collection: string, callback: RealtimeEventCallback): void;
|
|
1586
1594
|
/** Update the current user's presence. Sent immediately and on reconnect. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1563,6 +1563,7 @@ declare class RealtimeClient {
|
|
|
1563
1563
|
private readonly opts;
|
|
1564
1564
|
private ws;
|
|
1565
1565
|
private readonly subscriptions;
|
|
1566
|
+
private readonly subscriptionFilters;
|
|
1566
1567
|
private presenceListeners;
|
|
1567
1568
|
private currentPresence;
|
|
1568
1569
|
private sessionId;
|
|
@@ -1578,9 +1579,16 @@ declare class RealtimeClient {
|
|
|
1578
1579
|
* Subscribe to item mutation events for a specific collection.
|
|
1579
1580
|
* Multiple handlers per collection are supported.
|
|
1580
1581
|
*
|
|
1582
|
+
* `opts.filter` is an optional Directus-style condition rule evaluated
|
|
1583
|
+
* server-side over the event envelope (`collection`/`action`/`itemId`) —
|
|
1584
|
+
* studio broadcasts are signal-only, so row data is never filterable. The
|
|
1585
|
+
* filter is per-collection: the most recent subscribe call's filter wins.
|
|
1586
|
+
*
|
|
1581
1587
|
* @returns Unsubscribe function.
|
|
1582
1588
|
*/
|
|
1583
|
-
subscribe(collection: string, callback: RealtimeEventCallback
|
|
1589
|
+
subscribe(collection: string, callback: RealtimeEventCallback, opts?: {
|
|
1590
|
+
filter?: Record<string, unknown>;
|
|
1591
|
+
}): () => void;
|
|
1584
1592
|
/** Remove a specific handler from a collection subscription. */
|
|
1585
1593
|
unsubscribe(collection: string, callback: RealtimeEventCallback): void;
|
|
1586
1594
|
/** Update the current user's presence. Sent immediately and on reconnect. */
|
package/dist/index.js
CHANGED
|
@@ -293,6 +293,7 @@ var RealtimeClient = class {
|
|
|
293
293
|
opts;
|
|
294
294
|
ws = null;
|
|
295
295
|
subscriptions = /* @__PURE__ */ new Map();
|
|
296
|
+
subscriptionFilters = /* @__PURE__ */ new Map();
|
|
296
297
|
presenceListeners = /* @__PURE__ */ new Set();
|
|
297
298
|
currentPresence = {};
|
|
298
299
|
sessionId = null;
|
|
@@ -325,14 +326,20 @@ var RealtimeClient = class {
|
|
|
325
326
|
* Subscribe to item mutation events for a specific collection.
|
|
326
327
|
* Multiple handlers per collection are supported.
|
|
327
328
|
*
|
|
329
|
+
* `opts.filter` is an optional Directus-style condition rule evaluated
|
|
330
|
+
* server-side over the event envelope (`collection`/`action`/`itemId`) —
|
|
331
|
+
* studio broadcasts are signal-only, so row data is never filterable. The
|
|
332
|
+
* filter is per-collection: the most recent subscribe call's filter wins.
|
|
333
|
+
*
|
|
328
334
|
* @returns Unsubscribe function.
|
|
329
335
|
*/
|
|
330
|
-
subscribe(collection, callback) {
|
|
336
|
+
subscribe(collection, callback, opts = {}) {
|
|
331
337
|
if (!this.subscriptions.has(collection)) {
|
|
332
338
|
this.subscriptions.set(collection, /* @__PURE__ */ new Set());
|
|
333
339
|
}
|
|
334
340
|
this.subscriptions.get(collection).add(callback);
|
|
335
|
-
this.
|
|
341
|
+
if (opts.filter) this.subscriptionFilters.set(collection, opts.filter);
|
|
342
|
+
this._send({ type: "subscribe", collection, ...opts.filter ? { filter: opts.filter } : {} });
|
|
336
343
|
return () => this.unsubscribe(collection, callback);
|
|
337
344
|
}
|
|
338
345
|
/** Remove a specific handler from a collection subscription. */
|
|
@@ -342,6 +349,7 @@ var RealtimeClient = class {
|
|
|
342
349
|
set.delete(callback);
|
|
343
350
|
if (set.size === 0) {
|
|
344
351
|
this.subscriptions.delete(collection);
|
|
352
|
+
this.subscriptionFilters.delete(collection);
|
|
345
353
|
this._send({ type: "unsubscribe", collection });
|
|
346
354
|
}
|
|
347
355
|
}
|
|
@@ -406,7 +414,8 @@ var RealtimeClient = class {
|
|
|
406
414
|
ws.addEventListener("open", () => {
|
|
407
415
|
this.backoffMs = this.opts.initialBackoffMs ?? 1e3;
|
|
408
416
|
for (const collection of this.subscriptions.keys()) {
|
|
409
|
-
this.
|
|
417
|
+
const filter = this.subscriptionFilters.get(collection);
|
|
418
|
+
this._sendRaw({ type: "subscribe", collection, ...filter ? { filter } : {} });
|
|
410
419
|
}
|
|
411
420
|
if (Object.keys(this.currentPresence).length > 0) {
|
|
412
421
|
this._sendRaw({ type: "presence", ...this.currentPresence });
|