@nolag/signal 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
@@ -72,3 +72,39 @@ export interface SignalPresenceData {
72
72
  peerId: string;
73
73
  metadata?: Record<string, unknown>;
74
74
  }
75
+ /** Publish-side filter options for a signaling message. */
76
+ export interface SignalOptions {
77
+ /**
78
+ * Route this signal to peers filtering on this value — normally the
79
+ * recipient's peerId, which turns the room broadcast into a direct send.
80
+ *
81
+ * Peers subscribed without filters still receive it, so this is safe to
82
+ * adopt one peer at a time.
83
+ */
84
+ filter?: string;
85
+ /**
86
+ * AND composite filter — reaches only peers filtering on all of these
87
+ * values together. Ignored when `filter` is also set.
88
+ */
89
+ filters?: string[];
90
+ }
91
+ /** Options for `NoLagSignal.joinRoom()`. */
92
+ export interface JoinRoomOptions {
93
+ /**
94
+ * Only receive signals published with one of these filter values. Join with
95
+ * your own peerId to receive only signals addressed to you.
96
+ *
97
+ * Note this is exclusive: a filtered peer no longer receives the room-wide
98
+ * broadcasts that unfiltered peers send. Adopt it on every peer at once, or
99
+ * not at all.
100
+ */
101
+ filters?: FilterValue[];
102
+ }
103
+ /**
104
+ * A single subscription filter value.
105
+ *
106
+ * A plain string is an OR term: `['alice', 'bob']` matches either. A nested
107
+ * array is an AND group: `[['alice', 'admin']]` matches only what was
108
+ * published tagged with both.
109
+ */
110
+ 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/signal",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"