ironflock 1.3.2 → 1.5.1

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,95 @@ export declare interface CallParams {
27
28
  kwargs?: Record<string, unknown>;
28
29
  }
29
30
 
31
+ export declare interface ConnectToAppOptions {
32
+ /** Provider stage to connect to. Defaults to this app's own stage (ENV). */
33
+ stage?: "dev" | "prod";
34
+ /**
35
+ * Invoked when the consumed-app connection is fatally denied AFTER
36
+ * connectToApp resolved (e.g. the grant was revoked and the next reconnect
37
+ * was refused). While connectToApp is still pending, the same condition
38
+ * surfaces as a rejection instead.
39
+ */
40
+ onError?: (error: CrossAppAccessError) => void;
41
+ }
42
+
43
+ /**
44
+ * Read-only handle on another app's data backend, returned by
45
+ * {@link IronFlock.connectToApp}. Wraps a dedicated WAMP connection to the
46
+ * provider's realm; the router restricts it to subscribing `transformed.*`
47
+ * and calling `history.transformed.*`. Transforms (views) are consumable
48
+ * exactly like tables — same topic/RPC names — except for series history,
49
+ * which exists for tables only.
50
+ */
51
+ export declare class ConsumedApp {
52
+ /** Provider app name, as declared in `consumes:`. */
53
+ readonly app: string;
54
+ /** Provider stage this handle is connected to. */
55
+ readonly stage: "dev" | "prod";
56
+ /** Non-private tables the provider shares on this stage. */
57
+ readonly tables: ProviderTableInfo[];
58
+ /** Non-private transforms (views) the provider shares on this stage. */
59
+ readonly transforms: ProviderTableInfo[];
60
+ private _connection;
61
+ private _onClosed?;
62
+ constructor(app: string, stage: "dev" | "prod", catalog: ConsumedAppStageCatalog, connection: CrossbarConnection, onClosed?: () => void);
63
+ get connection(): CrossbarConnection;
64
+ get isConnected(): boolean;
65
+ private assertInCatalog;
66
+ /**
67
+ * Subscribes to realtime rows of a shared table or transform. Bulk inserts
68
+ * (`transformed.bulk.{t}`) are unrolled row-by-row through the same handler,
69
+ * so caller code always sees the single-row shape.
70
+ */
71
+ subscribeToTable(tablename: string, handler: (...args: any[]) => void, options?: object): Promise<Subscription<any[], any, string> | undefined>;
72
+ /** Queries history rows of a shared table or transform. */
73
+ getHistory(tablename: string, queryParams?: TableQueryParams): Promise<unknown>;
74
+ /** Queries down-sampled series history of a shared table (tables only — no series RPC exists for transforms). */
75
+ getSeriesHistory(tablename: string, params: SeriesQueryParams): Promise<unknown>;
76
+ /** Closes the underlying connection to the provider's realm. */
77
+ close(): Promise<void>;
78
+ }
79
+
80
+ /**
81
+ * Result of `sys.appaccess.resolve`. A stage is present only when the provider's
82
+ * data backend exists for that stage; catalogs list non-private entries only.
83
+ */
84
+ export declare interface ConsumedAppInfo {
85
+ app: string;
86
+ provider_app_key: number;
87
+ stages: {
88
+ dev?: ConsumedAppStageCatalog;
89
+ prod?: ConsumedAppStageCatalog;
90
+ };
91
+ }
92
+
93
+ /** Per-stage catalog of what a provider app shares. */
94
+ export declare interface ConsumedAppStageCatalog {
95
+ tables: ProviderTableInfo[];
96
+ transforms: ProviderTableInfo[];
97
+ }
98
+
99
+ /** Raised when reading another app's data backend is declined or misused. */
100
+ export declare class CrossAppAccessError extends Error {
101
+ readonly code: CrossAppAccessErrorCode;
102
+ constructor(code: CrossAppAccessErrorCode, message?: string);
103
+ }
104
+
105
+ export declare type CrossAppAccessErrorCode = "NO_GRANT" | "PROVIDER_NOT_INSTALLED" | "UNKNOWN_APP" | "PRIVATE_TABLE" | "NOT_AUTHORIZED";
106
+
30
107
  export declare class CrossbarConnection extends EventEmitter {
31
108
  session?: default_2.Session;
32
109
  connection?: default_2.Connection;
33
110
  serial_number?: string;
34
111
  socketURI?: string;
35
112
  realm?: string;
113
+ /**
114
+ * Opt-in (used for consumed-app connections): treat an auth/authorization
115
+ * denial on close as fatal — stop all reconnect attempts and emit
116
+ * "auth_failure" instead of retrying forever. The primary own-realm
117
+ * connection keeps the default (false): retry through every failure.
118
+ */
119
+ failOnAuthError: boolean;
36
120
  private subscriptions;
37
121
  private registrations;
38
122
  private firstConnection?;
@@ -70,6 +154,19 @@ export declare type Details = {
70
154
  caller_authrole: string;
71
155
  };
72
156
 
157
+ /** Down-sampling aggregation applied per time bucket in a series query. */
158
+ export declare type DownSampleMethod = "AVG" | "SUM" | "COUNT" | "MIN" | "MAX" | "FIRST" | "LAST";
159
+
160
+ /**
161
+ * Name of the per-databackend system error table. Apps report errors into it via
162
+ * {@link IronFlock.reportError}; it behaves like any normal table, so it can be
163
+ * queried (getHistory) and streamed (subscribeToTable) and used in board-templates.
164
+ */
165
+ export declare const ERROR_LOGS_TABLE = "error-logs";
166
+
167
+ /** Severity level recorded alongside a reported error. */
168
+ export declare type ErrorLevel = "error" | "warn" | "info" | "debug";
169
+
73
170
  export declare class IronFlock {
74
171
  private _connection;
75
172
  private _serialNumber;
@@ -82,14 +179,45 @@ export declare class IronFlock {
82
179
  private _isConfigured;
83
180
  private _reswarmUrl?;
84
181
  private _cburl?;
182
+ private _consumedApps;
85
183
  constructor(options?: IronFlockOptions);
86
184
  get connection(): CrossbarConnection;
87
185
  get isConnected(): boolean;
88
186
  private configureConnection;
89
187
  start(cburl?: string): Promise<void>;
90
188
  stop(): Promise<void>;
189
+ /**
190
+ * Opens a read-only connection to another app's data backend in the same
191
+ * project. The provider app must be declared in this app's data-template
192
+ * `consumes:` section and the project user must have granted access.
193
+ *
194
+ * Resolves the provider via `sys.appaccess.resolve`, then connects to the
195
+ * provider's realm with this device's credentials (router role
196
+ * `app_reader`). Connections are cached per app+stage and closed by
197
+ * {@link stop}.
198
+ *
199
+ * @throws {CrossAppAccessError} NO_GRANT | PROVIDER_NOT_INSTALLED |
200
+ * UNKNOWN_APP | NOT_AUTHORIZED
201
+ */
202
+ connectToApp(appName: string, opts?: ConnectToAppOptions): Promise<ConsumedApp>;
203
+ private openConsumedApp;
91
204
  publish(topic: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
92
205
  publishToTable(tablename: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
206
+ /**
207
+ * Reports an application error into the databackend's `error-logs` table.
208
+ *
209
+ * This is a thin convenience wrapper over {@link publishToTable} /
210
+ * {@link appendToTable}: it stamps the row with `source: "app"`, a severity
211
+ * `level`, and a timestamp, then writes it like any normal table row. The error
212
+ * therefore lands in the same `error-logs` table that fleetdb system errors use
213
+ * (tagged `source: "system"`), and is delivered in realtime on
214
+ * `transformed.error-logs` — the channel board-templates consume — without
215
+ * touching the platform error-toast channel (`databackend.errors.*`).
216
+ *
217
+ * @param error An error message, or an Error whose stack/message is recorded.
218
+ * @param opts Optional level (default "error"), append flag, and tsp override.
219
+ */
220
+ reportError(error: string | Error, opts?: ReportErrorOptions): Promise<unknown>;
93
221
  appendToTable(tablename: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
94
222
  /**
95
223
  * Publishes many rows in a single message (bulk insert) to the dedicated topic
@@ -120,6 +248,12 @@ export declare class IronFlock {
120
248
  registerFunction(topic: string, endpoint: (...args: any[]) => any, options?: default_2.IRegisterOptions): Promise<default_2.IRegistration<any, any[], any, string> | undefined>;
121
249
  register(topic: string, endpoint: (...args: any[]) => any, options?: default_2.IRegisterOptions): Promise<default_2.IRegistration<any, any[], any, string> | undefined>;
122
250
  getHistory(tablename: string, queryParams?: TableQueryParams): Promise<unknown>;
251
+ /**
252
+ * Queries down-sampled series history of an own table by calling
253
+ * `history.transformed.series.{tablename}` (tables only — no series RPC
254
+ * exists for transforms).
255
+ */
256
+ getSeriesHistory(tablename: string, params: SeriesQueryParams): Promise<unknown>;
123
257
  setDeviceLocation(long: number, lat: number): Promise<unknown>;
124
258
  getRemoteAccessUrlForPort(port: number): string | null;
125
259
  /**
@@ -161,12 +295,50 @@ export declare interface LocationParams {
161
295
  latitude: number & tags.Minimum<-90> & tags.Maximum<90>;
162
296
  }
163
297
 
298
+ /** A non-private table or transform another app shares, as listed in its catalog. */
299
+ export declare interface ProviderTableInfo {
300
+ tablename: string;
301
+ description?: string;
302
+ /** Column definitions as declared in the provider's data-template. */
303
+ columns?: Array<Record<string, unknown>>;
304
+ }
305
+
164
306
  export declare interface PublishParams {
165
307
  topic: string & tags.MinLength<1>;
166
308
  args?: unknown[];
167
309
  kwargs?: Record<string, unknown>;
168
310
  }
169
311
 
312
+ export declare interface ReportErrorOptions {
313
+ /** Severity level. Defaults to "error". */
314
+ level?: ErrorLevel;
315
+ /**
316
+ * When true, use the RPC append path (resolves with the insert outcome).
317
+ * Defaults to false: fire-and-forget publish, matching typical logging.
318
+ */
319
+ append?: boolean;
320
+ /** ISO-8601 timestamp override. Defaults to the current time. */
321
+ tsp?: string;
322
+ }
323
+
324
+ /** Query parameters for `history.transformed.series.{tablename}` (mirrors fleetdb's SeriesQueryParams). */
325
+ export declare interface SeriesQueryParams {
326
+ /** Numeric columns to down-sample. */
327
+ metrics: string[];
328
+ method: DownSampleMethod;
329
+ limit: number & tags.Type<"uint32"> & tags.Minimum<1> & tags.Maximum<10000>;
330
+ /** Required — the series RPC rejects queries without a time range. */
331
+ timeRange: SeriesTimeRange;
332
+ groupBy?: string[] | null;
333
+ filterAnd?: SQLFilterAnd[] | null;
334
+ }
335
+
336
+ /**
337
+ * [start, end] tuple — ISO date-time strings or epoch-ms numbers; null = open end.
338
+ * Mirrors fleetdb's TimeRangeInput (a tuple, unlike TableQueryParams.timeRange).
339
+ */
340
+ export declare type SeriesTimeRange = [string | null, string | null] | [number | null, number | null];
341
+
170
342
  export declare interface SQLFilterAnd {
171
343
  column: string & tags.MinLength<1>;
172
344
  operator: string & tags.MinLength<1>;
@@ -199,6 +371,8 @@ export declare const validateLocationParams: ((input: unknown) => default_3.IVal
199
371
 
200
372
  export declare const validatePublishParams: ((input: unknown) => default_3.IValidation<PublishParams>) & StandardSchemaV1<PublishParams, PublishParams>;
201
373
 
374
+ export declare const validateSeriesQueryParams: ((input: unknown) => default_3.IValidation<SeriesQueryParams>) & StandardSchemaV1<SeriesQueryParams, SeriesQueryParams>;
375
+
202
376
  export declare const validateTableParams: ((input: unknown) => default_3.IValidation<TableParams>) & StandardSchemaV1<TableParams, TableParams>;
203
377
 
204
378
  export declare const validateTableQueryParams: ((input: unknown) => default_3.IValidation<TableQueryParams>) & StandardSchemaV1<TableQueryParams, TableQueryParams>;