@nolag/collab 1.1.0 → 1.2.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/types.d.ts CHANGED
@@ -80,6 +80,24 @@ export interface SendOperationOptions {
80
80
  content?: string;
81
81
  /** Arbitrary operation payload for custom types */
82
82
  data?: Record<string, unknown>;
83
+ /**
84
+ * Route this operation to collaborators filtering on this value.
85
+ * Unfiltered (wildcard) collaborators still receive it.
86
+ */
87
+ filter?: string;
88
+ /**
89
+ * AND composite filter — reaches only collaborators filtering on all of
90
+ * these values together. Ignored when `filter` is also set.
91
+ */
92
+ filters?: string[];
93
+ }
94
+ /** Options for `NoLagCollab.joinDocument()`. */
95
+ export interface JoinDocumentOptions {
96
+ /**
97
+ * Only receive operations published with one of these filter values.
98
+ * Omit (or pass an empty array) to receive every operation.
99
+ */
100
+ filters?: FilterValue[];
83
101
  }
84
102
  export interface CursorPosition {
85
103
  /** User ID of the cursor owner */
@@ -178,3 +196,11 @@ export interface CollabDocumentEvents {
178
196
  replayed: number;
179
197
  }];
180
198
  }
199
+ /**
200
+ * A single subscription filter value.
201
+ *
202
+ * A plain string is an OR term: `['alice', 'bob']` matches either. A nested
203
+ * array is an AND group: `[['alice', 'admin']]` matches only what was
204
+ * published tagged with both.
205
+ */
206
+ export type FilterValue = string | string[];
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,54 @@
1
+ import type { FilterValue } from './types';
1
2
  export declare function generateId(): string;
2
3
  export declare function createLogger(prefix: string, enabled: boolean): (..._args: unknown[]) => void;
4
+ /**
5
+ * Build the filter fragment of an emit options object.
6
+ *
7
+ * `filter` wins over `filters`: a publish is routed to exactly one topic, so
8
+ * honouring both would silently drop one of them.
9
+ */
10
+ export declare function filterEmitOptions(opts?: {
11
+ filter?: string;
12
+ filters?: string[];
13
+ }): {
14
+ filter?: string;
15
+ filters?: string[];
16
+ };
17
+ /**
18
+ * Rebuild publish options from the filter a message arrived with, so a reply
19
+ * to it reaches the same audience the original did.
20
+ *
21
+ * The server joins AND groups into one composite value with '|', which is not
22
+ * a legal character in a plain filter, so split those back apart.
23
+ */
24
+ export declare function inheritFilter(filter?: string): {
25
+ filter?: string;
26
+ filters?: string[];
27
+ };
28
+ /**
29
+ * Merge OR terms into an existing filter set. AND groups (nested arrays) are
30
+ * preserved as-is — only plain string terms are deduplicated.
31
+ */
32
+ export declare function mergeFilters(existing: FilterValue[], add: string[]): FilterValue[];
33
+ /**
34
+ * Drop OR terms from a filter set. AND groups are left untouched — remove
35
+ * those by calling `setFilters` with the set you want.
36
+ */
37
+ export declare function withoutFilters(existing: FilterValue[], remove: string[]): FilterValue[];
38
+ /**
39
+ * The composite key the server derives from an AND filter group: values are
40
+ * lowercased, sorted, and joined with '|'. Mirrored here so an item created
41
+ * locally carries the same filter string as one arriving off the wire.
42
+ */
43
+ export declare function compositeFilterKey(values: string[]): string;
44
+ /**
45
+ * The single string form of whatever filter a publish used, for recording on
46
+ * the local copy of an item. Round-trips through `inheritFilter`.
47
+ */
48
+ export declare function recordedFilter(opts?: {
49
+ filter?: string;
50
+ filters?: string[];
51
+ }): string | undefined;
3
52
  /** Register a wrapper against a client + appName; warns on collision. */
4
53
  export declare function registerWrapper(client: object, appName: string, wrapperName: string): void;
5
54
  /** Release a wrapper's (client, appName) registration on detach. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nolag/collab",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"