@nolag/iot 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
@@ -62,6 +62,31 @@ export interface TelemetryReading {
62
62
  export interface SendTelemetryOptions {
63
63
  unit?: string;
64
64
  tags?: Record<string, string>;
65
+ /**
66
+ * Route this reading to subscribers filtering on this value — a site, a
67
+ * sensor class, a criticality tier. Unfiltered subscribers still receive it.
68
+ */
69
+ filter?: string;
70
+ /**
71
+ * AND composite filter — reaches only subscribers filtering on all of these
72
+ * values together, e.g. `['site-a', 'critical']`. Ignored when `filter` is
73
+ * also set.
74
+ */
75
+ filters?: string[];
76
+ }
77
+ /** Options for `NoLagIoT.joinGroup()`. */
78
+ export interface JoinGroupOptions {
79
+ /**
80
+ * Only receive telemetry published with one of these filter values — the
81
+ * way to subscribe a dashboard to one site's sensors instead of every
82
+ * device in the group.
83
+ *
84
+ * Commands and command acks are not affected: those already route by
85
+ * deviceId internally, and overriding that would break command delivery.
86
+ *
87
+ * Omit (or pass an empty array) to receive all telemetry.
88
+ */
89
+ filters?: FilterValue[];
65
90
  }
66
91
  export interface DeviceCommand {
67
92
  /** Client-generated unique command ID */
@@ -131,3 +156,11 @@ export interface DeviceGroupEvents {
131
156
  replayStart: [];
132
157
  replayEnd: [];
133
158
  }
159
+ /**
160
+ * A single subscription filter value.
161
+ *
162
+ * A plain string is an OR term: `['alice', 'bob']` matches either. A nested
163
+ * array is an AND group: `[['alice', 'admin']]` matches only what was
164
+ * published tagged with both.
165
+ */
166
+ 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/iot",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"