ironflock 1.3.3 → 1.5.2

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.d.ts CHANGED
@@ -2,6 +2,7 @@ import { default as default_2 } from 'autobahn';
2
2
  import { default as default_3 } from 'typia';
3
3
  import { EventEmitter } from 'eventemitter3';
4
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
5
+ import { Subscription } from 'autobahn';
5
6
  import { tags } from 'typia';
6
7
 
7
8
  export declare type AuthPayload = {
@@ -27,12 +28,113 @@ export declare interface CallParams {
27
28
  kwargs?: Record<string, unknown>;
28
29
  }
29
30
 
31
+ export declare interface ConnectToAllAppsOptions {
32
+ /** Provider stage to connect to. Defaults to this app's own stage (ENV). */
33
+ stage?: "dev" | "prod";
34
+ /**
35
+ * Invoked with the failure of each provider that could not be opened (only
36
+ * when continueOnError is true — otherwise the first failure rejects), and
37
+ * with a {@link CrossAppAccessError} if an already-opened provider connection
38
+ * is later fatally denied (grant revoked → refused reconnect).
39
+ */
40
+ onError?: (error: unknown) => void;
41
+ /**
42
+ * When true (the default) a provider that fails to open is reported via
43
+ * onError and omitted from the result. When false the first failure rejects
44
+ * connectToAllApps.
45
+ */
46
+ continueOnError?: boolean;
47
+ }
48
+
49
+ export declare interface ConnectToAppOptions {
50
+ /** Provider stage to connect to. Defaults to this app's own stage (ENV). */
51
+ stage?: "dev" | "prod";
52
+ /**
53
+ * Invoked when the consumed-app connection is fatally denied AFTER
54
+ * connectToApp resolved (e.g. the grant was revoked and the next reconnect
55
+ * was refused). While connectToApp is still pending, the same condition
56
+ * surfaces as a rejection instead.
57
+ */
58
+ onError?: (error: CrossAppAccessError) => void;
59
+ }
60
+
61
+ /**
62
+ * Read-only handle on another app's data backend, returned by
63
+ * {@link IronFlock.connectToApp}. Wraps a dedicated WAMP connection to the
64
+ * provider's realm; the router restricts it to subscribing `transformed.*`
65
+ * and calling `history.transformed.*`. Transforms (views) are consumable
66
+ * exactly like tables — same topic/RPC names — except for series history,
67
+ * which exists for tables only.
68
+ */
69
+ export declare class ConsumedApp {
70
+ /** Provider app name, as declared in `consumes:`. */
71
+ readonly app: string;
72
+ /** Provider stage this handle is connected to. */
73
+ readonly stage: "dev" | "prod";
74
+ /** Non-private tables the provider shares on this stage. */
75
+ readonly tables: ProviderTableInfo[];
76
+ /** Non-private transforms (views) the provider shares on this stage. */
77
+ readonly transforms: ProviderTableInfo[];
78
+ private _connection;
79
+ private _onClosed?;
80
+ constructor(app: string, stage: "dev" | "prod", catalog: ConsumedAppStageCatalog, connection: CrossbarConnection, onClosed?: () => void);
81
+ get connection(): CrossbarConnection;
82
+ get isConnected(): boolean;
83
+ private assertInCatalog;
84
+ /**
85
+ * Subscribes to realtime rows of a shared table or transform. Bulk inserts
86
+ * (`transformed.bulk.{t}`) are unrolled row-by-row through the same handler,
87
+ * so caller code always sees the single-row shape.
88
+ */
89
+ subscribeToTable(tablename: string, handler: (...args: any[]) => void, options?: object): Promise<Subscription<any[], any, string> | undefined>;
90
+ /** Queries history rows of a shared table or transform. */
91
+ getHistory(tablename: string, queryParams?: TableQueryParams): Promise<unknown>;
92
+ /** Queries down-sampled series history of a shared table (tables only — no series RPC exists for transforms). */
93
+ getSeriesHistory(tablename: string, params: SeriesQueryParams): Promise<unknown>;
94
+ /** Closes the underlying connection to the provider's realm. */
95
+ close(): Promise<void>;
96
+ }
97
+
98
+ /**
99
+ * Result of `sys.appaccess.resolve`. A stage is present only when the provider's
100
+ * data backend exists for that stage; catalogs list non-private entries only.
101
+ */
102
+ export declare interface ConsumedAppInfo {
103
+ app: string;
104
+ provider_app_key: number;
105
+ stages: {
106
+ dev?: ConsumedAppStageCatalog;
107
+ prod?: ConsumedAppStageCatalog;
108
+ };
109
+ }
110
+
111
+ /** Per-stage catalog of what a provider app shares. */
112
+ export declare interface ConsumedAppStageCatalog {
113
+ tables: ProviderTableInfo[];
114
+ transforms: ProviderTableInfo[];
115
+ }
116
+
117
+ /** Raised when reading another app's data backend is declined or misused. */
118
+ export declare class CrossAppAccessError extends Error {
119
+ readonly code: CrossAppAccessErrorCode;
120
+ constructor(code: CrossAppAccessErrorCode, message?: string);
121
+ }
122
+
123
+ export declare type CrossAppAccessErrorCode = "NO_GRANT" | "PROVIDER_NOT_INSTALLED" | "UNKNOWN_APP" | "PRIVATE_TABLE" | "NOT_AUTHORIZED";
124
+
30
125
  export declare class CrossbarConnection extends EventEmitter {
31
126
  session?: default_2.Session;
32
127
  connection?: default_2.Connection;
33
128
  serial_number?: string;
34
129
  socketURI?: string;
35
130
  realm?: string;
131
+ /**
132
+ * Opt-in (used for consumed-app connections): treat an auth/authorization
133
+ * denial on close as fatal — stop all reconnect attempts and emit
134
+ * "auth_failure" instead of retrying forever. The primary own-realm
135
+ * connection keeps the default (false): retry through every failure.
136
+ */
137
+ failOnAuthError: boolean;
36
138
  private subscriptions;
37
139
  private registrations;
38
140
  private firstConnection?;
@@ -70,6 +172,9 @@ export declare type Details = {
70
172
  caller_authrole: string;
71
173
  };
72
174
 
175
+ /** Down-sampling aggregation applied per time bucket in a series query. */
176
+ export declare type DownSampleMethod = "AVG" | "SUM" | "COUNT" | "MIN" | "MAX" | "FIRST" | "LAST";
177
+
73
178
  /**
74
179
  * Name of the per-databackend system error table. Apps report errors into it via
75
180
  * {@link IronFlock.reportError}; it behaves like any normal table, so it can be
@@ -92,12 +197,60 @@ export declare class IronFlock {
92
197
  private _isConfigured;
93
198
  private _reswarmUrl?;
94
199
  private _cburl?;
200
+ private _consumedApps;
95
201
  constructor(options?: IronFlockOptions);
96
202
  get connection(): CrossbarConnection;
97
203
  get isConnected(): boolean;
98
204
  private configureConnection;
99
205
  start(cburl?: string): Promise<void>;
100
206
  stop(): Promise<void>;
207
+ /**
208
+ * Opens a read-only connection to another app's data backend in the same
209
+ * project. The provider app must be declared in this app's data-template
210
+ * `consumes:` section and the project user must have granted access.
211
+ *
212
+ * Resolves the provider via `sys.appaccess.resolve`, then connects to the
213
+ * provider's realm with this device's credentials (router role
214
+ * `app_reader`). Connections are cached per app+stage and closed by
215
+ * {@link stop}.
216
+ *
217
+ * @throws {CrossAppAccessError} NO_GRANT | PROVIDER_NOT_INSTALLED |
218
+ * UNKNOWN_APP | NOT_AUTHORIZED
219
+ */
220
+ connectToApp(appName: string, opts?: ConnectToAppOptions): Promise<ConsumedApp>;
221
+ /**
222
+ * Lists every non-private provider catalog in this project for an app holding
223
+ * the wildcard consume grant (`consumes: [{app: "*"}]`). One
224
+ * `sys.appaccess.list` call; opens no consumed-app connections. A picker (e.g.
225
+ * a Node-RED node) renders the returned catalogs, then calls
226
+ * {@link connectToApp} per chosen provider; {@link connectToAllApps} opens
227
+ * them all eagerly.
228
+ *
229
+ * @throws {CrossAppAccessError} NO_GRANT when this app holds no wildcard grant.
230
+ */
231
+ listConsumableApps(): Promise<ConsumedAppInfo[]>;
232
+ /**
233
+ * Opens read-only connections to every non-private provider in this project
234
+ * (wildcard consumers only). Enumerates providers via {@link listConsumableApps}
235
+ * and opens each directly from its resolved info — no per-app resolve
236
+ * round-trip. Each handle is cached under the same `${app}:${stage}` key
237
+ * {@link connectToApp} uses, so a later `connectToApp(name)` returns the warmed
238
+ * handle. Providers lacking a data backend for the requested stage are skipped.
239
+ *
240
+ * @throws {CrossAppAccessError} NO_GRANT when this app holds no wildcard grant.
241
+ */
242
+ connectToAllApps(opts?: ConnectToAllAppsOptions): Promise<ConsumedApp[]>;
243
+ private openConsumedApp;
244
+ /** Caches (or reuses) a connection opened directly from a resolved provider
245
+ * info, using the same `${app}:${stage}` key as {@link connectToApp}. */
246
+ private openCachedFromInfo;
247
+ /**
248
+ * Opens the second CrossbarConnection to a provider realm from an already
249
+ * resolved {@link ConsumedAppInfo} — everything after the sys.appaccess.resolve
250
+ * round-trip. Shared by {@link connectToApp} (which resolves one provider) and
251
+ * {@link connectToAllApps} (which lists every provider in one call).
252
+ */
253
+ private openFromInfo;
101
254
  publish(topic: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
102
255
  publishToTable(tablename: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
103
256
  /**
@@ -145,6 +298,12 @@ export declare class IronFlock {
145
298
  registerFunction(topic: string, endpoint: (...args: any[]) => any, options?: default_2.IRegisterOptions): Promise<default_2.IRegistration<any, any[], any, string> | undefined>;
146
299
  register(topic: string, endpoint: (...args: any[]) => any, options?: default_2.IRegisterOptions): Promise<default_2.IRegistration<any, any[], any, string> | undefined>;
147
300
  getHistory(tablename: string, queryParams?: TableQueryParams): Promise<unknown>;
301
+ /**
302
+ * Queries down-sampled series history of an own table by calling
303
+ * `history.transformed.series.{tablename}` (tables only — no series RPC
304
+ * exists for transforms).
305
+ */
306
+ getSeriesHistory(tablename: string, params: SeriesQueryParams): Promise<unknown>;
148
307
  setDeviceLocation(long: number, lat: number): Promise<unknown>;
149
308
  getRemoteAccessUrlForPort(port: number): string | null;
150
309
  /**
@@ -186,6 +345,14 @@ export declare interface LocationParams {
186
345
  latitude: number & tags.Minimum<-90> & tags.Maximum<90>;
187
346
  }
188
347
 
348
+ /** A non-private table or transform another app shares, as listed in its catalog. */
349
+ export declare interface ProviderTableInfo {
350
+ tablename: string;
351
+ description?: string;
352
+ /** Column definitions as declared in the provider's data-template. */
353
+ columns?: Array<Record<string, unknown>>;
354
+ }
355
+
189
356
  export declare interface PublishParams {
190
357
  topic: string & tags.MinLength<1>;
191
358
  args?: unknown[];
@@ -204,6 +371,24 @@ export declare interface ReportErrorOptions {
204
371
  tsp?: string;
205
372
  }
206
373
 
374
+ /** Query parameters for `history.transformed.series.{tablename}` (mirrors fleetdb's SeriesQueryParams). */
375
+ export declare interface SeriesQueryParams {
376
+ /** Numeric columns to down-sample. */
377
+ metrics: string[];
378
+ method: DownSampleMethod;
379
+ limit: number & tags.Type<"uint32"> & tags.Minimum<1> & tags.Maximum<10000>;
380
+ /** Required — the series RPC rejects queries without a time range. */
381
+ timeRange: SeriesTimeRange;
382
+ groupBy?: string[] | null;
383
+ filterAnd?: SQLFilterAnd[] | null;
384
+ }
385
+
386
+ /**
387
+ * [start, end] tuple — ISO date-time strings or epoch-ms numbers; null = open end.
388
+ * Mirrors fleetdb's TimeRangeInput (a tuple, unlike TableQueryParams.timeRange).
389
+ */
390
+ export declare type SeriesTimeRange = [string | null, string | null] | [number | null, number | null];
391
+
207
392
  export declare interface SQLFilterAnd {
208
393
  column: string & tags.MinLength<1>;
209
394
  operator: string & tags.MinLength<1>;
@@ -236,6 +421,8 @@ export declare const validateLocationParams: ((input: unknown) => default_3.IVal
236
421
 
237
422
  export declare const validatePublishParams: ((input: unknown) => default_3.IValidation<PublishParams>) & StandardSchemaV1<PublishParams, PublishParams>;
238
423
 
424
+ export declare const validateSeriesQueryParams: ((input: unknown) => default_3.IValidation<SeriesQueryParams>) & StandardSchemaV1<SeriesQueryParams, SeriesQueryParams>;
425
+
239
426
  export declare const validateTableParams: ((input: unknown) => default_3.IValidation<TableParams>) & StandardSchemaV1<TableParams, TableParams>;
240
427
 
241
428
  export declare const validateTableQueryParams: ((input: unknown) => default_3.IValidation<TableQueryParams>) & StandardSchemaV1<TableQueryParams, TableQueryParams>;