ironflock 1.3.3 → 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/README.md +144 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +137 -0
- package/dist/index.mjs +883 -486
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,9 @@ 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
|
+
|
|
73
160
|
/**
|
|
74
161
|
* Name of the per-databackend system error table. Apps report errors into it via
|
|
75
162
|
* {@link IronFlock.reportError}; it behaves like any normal table, so it can be
|
|
@@ -92,12 +179,28 @@ export declare class IronFlock {
|
|
|
92
179
|
private _isConfigured;
|
|
93
180
|
private _reswarmUrl?;
|
|
94
181
|
private _cburl?;
|
|
182
|
+
private _consumedApps;
|
|
95
183
|
constructor(options?: IronFlockOptions);
|
|
96
184
|
get connection(): CrossbarConnection;
|
|
97
185
|
get isConnected(): boolean;
|
|
98
186
|
private configureConnection;
|
|
99
187
|
start(cburl?: string): Promise<void>;
|
|
100
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;
|
|
101
204
|
publish(topic: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
|
|
102
205
|
publishToTable(tablename: string, args?: unknown[], kwargs?: Record<string, unknown>): Promise<unknown>;
|
|
103
206
|
/**
|
|
@@ -145,6 +248,12 @@ export declare class IronFlock {
|
|
|
145
248
|
registerFunction(topic: string, endpoint: (...args: any[]) => any, options?: default_2.IRegisterOptions): Promise<default_2.IRegistration<any, any[], any, string> | undefined>;
|
|
146
249
|
register(topic: string, endpoint: (...args: any[]) => any, options?: default_2.IRegisterOptions): Promise<default_2.IRegistration<any, any[], any, string> | undefined>;
|
|
147
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>;
|
|
148
257
|
setDeviceLocation(long: number, lat: number): Promise<unknown>;
|
|
149
258
|
getRemoteAccessUrlForPort(port: number): string | null;
|
|
150
259
|
/**
|
|
@@ -186,6 +295,14 @@ export declare interface LocationParams {
|
|
|
186
295
|
latitude: number & tags.Minimum<-90> & tags.Maximum<90>;
|
|
187
296
|
}
|
|
188
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
|
+
|
|
189
306
|
export declare interface PublishParams {
|
|
190
307
|
topic: string & tags.MinLength<1>;
|
|
191
308
|
args?: unknown[];
|
|
@@ -204,6 +321,24 @@ export declare interface ReportErrorOptions {
|
|
|
204
321
|
tsp?: string;
|
|
205
322
|
}
|
|
206
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
|
+
|
|
207
342
|
export declare interface SQLFilterAnd {
|
|
208
343
|
column: string & tags.MinLength<1>;
|
|
209
344
|
operator: string & tags.MinLength<1>;
|
|
@@ -236,6 +371,8 @@ export declare const validateLocationParams: ((input: unknown) => default_3.IVal
|
|
|
236
371
|
|
|
237
372
|
export declare const validatePublishParams: ((input: unknown) => default_3.IValidation<PublishParams>) & StandardSchemaV1<PublishParams, PublishParams>;
|
|
238
373
|
|
|
374
|
+
export declare const validateSeriesQueryParams: ((input: unknown) => default_3.IValidation<SeriesQueryParams>) & StandardSchemaV1<SeriesQueryParams, SeriesQueryParams>;
|
|
375
|
+
|
|
239
376
|
export declare const validateTableParams: ((input: unknown) => default_3.IValidation<TableParams>) & StandardSchemaV1<TableParams, TableParams>;
|
|
240
377
|
|
|
241
378
|
export declare const validateTableQueryParams: ((input: unknown) => default_3.IValidation<TableQueryParams>) & StandardSchemaV1<TableQueryParams, TableQueryParams>;
|