@geolonia/geonicdb-sdk 0.9.0 → 0.10.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 +45 -1
- package/geonicdb.cjs +233 -13
- package/geonicdb.cjs.map +3 -3
- package/geonicdb.d.ts +525 -29
- package/geonicdb.iife.js +233 -13
- package/geonicdb.iife.js.map +3 -3
- package/geonicdb.mjs +233 -13
- package/geonicdb.mjs.map +3 -3
- package/package.json +1 -1
package/geonicdb.d.ts
CHANGED
|
@@ -1,30 +1,526 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) 2026 Geolonia Inc.
|
|
5
|
+
* Released under the MIT License. See src/sdk/LICENSE for details.
|
|
6
|
+
*/
|
|
7
|
+
/** Options for the GeonicDB SDK constructor. */
|
|
8
|
+
export interface GeonicDBOptions {
|
|
9
|
+
/** API key (or use data-api-key attribute on script tag) */
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/** Tenant name (or use data-tenant attribute on script tag) */
|
|
12
|
+
tenant?: string;
|
|
13
|
+
/** API base URL (auto-detected from script src if omitted) */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
/** WebSocket endpoint URL (auto-detected from baseUrl if omitted) */
|
|
16
|
+
wsEndpoint?: string;
|
|
17
|
+
/** Enable debug logging to console (default: false) */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Enable in-memory client-side cache with automatic ETag/If-None-Match
|
|
21
|
+
* handling and request deduplication. (Phase A, default: true)
|
|
22
|
+
*/
|
|
23
|
+
cache?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum number of cached entries (LRU eviction beyond this size).
|
|
26
|
+
* Only meaningful when `cache` is enabled. Default: 1000.
|
|
27
|
+
*/
|
|
28
|
+
cacheMaxEntries?: number;
|
|
29
|
+
/**
|
|
30
|
+
* #1105: Anonymous mode. When true, the SDK skips token acquisition and
|
|
31
|
+
* sends requests without an `Authorization` header. The server treats
|
|
32
|
+
* such requests as `role: 'anonymous'` and lets the XACML policy engine
|
|
33
|
+
* decide whether to permit them.
|
|
34
|
+
*
|
|
35
|
+
* - Cannot be combined with `apiKey` (constructor throws).
|
|
36
|
+
* - `login()` / `setCredentials()` switches the SDK out of anonymous mode
|
|
37
|
+
* for subsequent requests.
|
|
38
|
+
* - `logout()` reverts to anonymous mode.
|
|
39
|
+
* - WebSocket `connect()` is not supported in anonymous mode and throws.
|
|
40
|
+
*/
|
|
41
|
+
anonymous?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** Options for the SDK polling helper. */
|
|
44
|
+
export interface PollOptions<T = unknown> {
|
|
45
|
+
/** Polling interval in milliseconds (default: 5000). */
|
|
46
|
+
interval?: number;
|
|
47
|
+
/** Called when fresh data is received from the server (200). */
|
|
48
|
+
onData?: (data: T) => void;
|
|
49
|
+
/** Called when the server responded 304 (no change since last poll). */
|
|
50
|
+
onNoChange?: () => void;
|
|
51
|
+
/** Called on transport / HTTP errors. Polling continues unless the handler stops it. */
|
|
52
|
+
onError?: (error: unknown) => void;
|
|
53
|
+
}
|
|
54
|
+
/** Handle returned by `db.poll(...)` to control the polling loop. */
|
|
55
|
+
export interface PollHandle {
|
|
56
|
+
/** Stop the polling loop. Idempotent. */
|
|
57
|
+
stop(): void;
|
|
58
|
+
}
|
|
59
|
+
/** Options for setting credentials externally. */
|
|
60
|
+
export interface CredentialsOptions {
|
|
61
|
+
/** Access token (JWT) */
|
|
62
|
+
token: string;
|
|
63
|
+
/** Token type — default: 'Bearer' */
|
|
64
|
+
tokenType?: "Bearer" | "DPoP";
|
|
65
|
+
/** Token lifetime in seconds (default: 3600) */
|
|
66
|
+
expiresIn?: number;
|
|
67
|
+
/** Refresh token for auto-renewal */
|
|
68
|
+
refreshToken?: string;
|
|
69
|
+
}
|
|
70
|
+
/** Credentials returned after a token refresh. */
|
|
71
|
+
export interface RefreshedCredentials {
|
|
72
|
+
/** New access token */
|
|
73
|
+
token: string;
|
|
74
|
+
/** Token type */
|
|
75
|
+
tokenType: string;
|
|
76
|
+
/** Token lifetime in seconds */
|
|
77
|
+
expiresIn: number;
|
|
78
|
+
/** New refresh token */
|
|
79
|
+
refreshToken: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parameters for querying entities.
|
|
83
|
+
*
|
|
84
|
+
* NGSI-LD 1.6 §5.7.2 Query Entities が定める主要パラメータを網羅する (#1132)。
|
|
85
|
+
* 以前はサーバ側が georel / scopeQ / attrs / pick / omit / lang などを実装
|
|
86
|
+
* しているのに SDK 側で型と URL builder が `type / limit / offset / q` の
|
|
87
|
+
* 4 つしか持たず、`db.request()` に逃げる必要があった。
|
|
88
|
+
*/
|
|
89
|
+
export interface GetEntitiesParams {
|
|
90
|
+
/** Entity type filter */
|
|
91
|
+
type?: string;
|
|
92
|
+
/** Max results */
|
|
93
|
+
limit?: number;
|
|
94
|
+
/** Pagination offset */
|
|
95
|
+
offset?: number;
|
|
96
|
+
/** NGSI-LD query expression */
|
|
97
|
+
q?: string;
|
|
98
|
+
/** NGSI-LD scope query expression (`/foo`, `/foo/#`, `/foo/+`, `;` で OR) */
|
|
99
|
+
scopeQ?: string;
|
|
100
|
+
/** Geo-relation: `near`, `within`, `contains`, `intersects`, `disjoint`, `equals` */
|
|
101
|
+
georel?: string;
|
|
102
|
+
/** Geometry type: `Point`, `Polygon`, `LineString`, ... */
|
|
103
|
+
geometry?: string;
|
|
104
|
+
/** Coordinates string (semicolon-delimited pairs or flat comma-separated) */
|
|
105
|
+
coordinates?: string;
|
|
106
|
+
/** Comma-separated attribute names to retrieve */
|
|
107
|
+
attrs?: string;
|
|
108
|
+
/** Comma-separated attribute names to keep (alternative to attrs) */
|
|
109
|
+
pick?: string;
|
|
110
|
+
/** Comma-separated attribute names to remove */
|
|
111
|
+
omit?: string;
|
|
112
|
+
/** Language tag for LanguageProperty filtering */
|
|
113
|
+
lang?: string;
|
|
114
|
+
/** Order by field */
|
|
115
|
+
orderBy?: string;
|
|
116
|
+
/** Order direction: `asc` (default) or `desc` */
|
|
117
|
+
orderDirection?: "asc" | "desc";
|
|
118
|
+
/** Sort points by distance from a `near` query */
|
|
119
|
+
orderByDistance?: boolean;
|
|
120
|
+
/** Whether the response should include a count (server returns `NGSILD-Results-Count` header) */
|
|
121
|
+
count?: boolean;
|
|
122
|
+
/** GeoProperty key to use (default `location`) */
|
|
123
|
+
geoproperty?: string;
|
|
124
|
+
}
|
|
125
|
+
/** Parameters for counting entities. */
|
|
126
|
+
export interface CountEntitiesParams {
|
|
127
|
+
/** Entity type filter */
|
|
128
|
+
type?: string;
|
|
129
|
+
/** NGSI-LD query expression */
|
|
130
|
+
q?: string;
|
|
131
|
+
/** NGSI-LD scope query expression (#1132) */
|
|
132
|
+
scopeQ?: string;
|
|
133
|
+
}
|
|
134
|
+
/** Options for subscribing to entity events via WebSocket. */
|
|
135
|
+
export interface SubscribeOptions {
|
|
136
|
+
/** Entity types to subscribe to */
|
|
137
|
+
entityTypes?: string[];
|
|
138
|
+
/** Entity ID regex pattern */
|
|
139
|
+
idPattern?: string;
|
|
140
|
+
/** NGSI-LD scope query expression (#1132). Server-side filter; only events whose entity scope matches are delivered. */
|
|
141
|
+
scopeQ?: string;
|
|
142
|
+
}
|
|
143
|
+
/** Entity event received via WebSocket. */
|
|
144
|
+
export interface EntityEvent {
|
|
145
|
+
/** Event type */
|
|
146
|
+
type: "entityCreated" | "entityUpdated" | "entityDeleted";
|
|
147
|
+
/** Tenant name */
|
|
148
|
+
tenant: string;
|
|
149
|
+
/** Service path */
|
|
150
|
+
servicePath: string;
|
|
151
|
+
/** Entity ID */
|
|
152
|
+
entityId: string;
|
|
153
|
+
/** Entity type */
|
|
154
|
+
entityType: string;
|
|
155
|
+
/** Entity attributes */
|
|
156
|
+
data: Record<string, unknown>;
|
|
157
|
+
/** Complete NGSI-LD entity (id + type + attributes from data). Undefined when data is unavailable (e.g. some delete events). */
|
|
158
|
+
entity?: Record<string, unknown>;
|
|
159
|
+
/** Changed attribute names (update only) */
|
|
160
|
+
changedAttributes?: string[];
|
|
161
|
+
/** ISO 8601 timestamp */
|
|
162
|
+
timestamp: string;
|
|
163
|
+
}
|
|
164
|
+
/** Event fired when a reconnection attempt is starting. */
|
|
165
|
+
export interface ReconnectingEvent {
|
|
166
|
+
/** Current reconnection attempt number */
|
|
167
|
+
attempt: number;
|
|
168
|
+
/** Delay in ms before this attempt */
|
|
169
|
+
delay: number;
|
|
170
|
+
}
|
|
171
|
+
/** Options for `db.login(...)`. */
|
|
172
|
+
export interface LoginOptions {
|
|
173
|
+
/**
|
|
174
|
+
* If true, immediately exchange the Bearer session for a DPoP-bound
|
|
175
|
+
* sender-constrained session via `POST /auth/dpop-bind` (RFC 9449).
|
|
176
|
+
*
|
|
177
|
+
* Recommended for browser apps that persist tokens in storage that may be
|
|
178
|
+
* exposed to XSS (localStorage, sessionStorage). DPoP-bound tokens are
|
|
179
|
+
* unusable without the client's non-extractable private key, so a stolen
|
|
180
|
+
* token cannot be replayed from another origin.
|
|
181
|
+
*
|
|
182
|
+
* Throws `AuthenticationError` if DPoP is not supported in the runtime
|
|
183
|
+
* (no Web Crypto subtle.generateKey).
|
|
184
|
+
*
|
|
185
|
+
* Default: false (Bearer remains).
|
|
186
|
+
*/
|
|
187
|
+
dpop?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* If true, persist the DPoP session (non-extractable private key + tokens)
|
|
190
|
+
* to IndexedDB so the session survives a page reload. Implies `dpop: true`
|
|
191
|
+
* — passing `dpopPersist: true` without `dpop: true` throws.
|
|
192
|
+
*
|
|
193
|
+
* The private key is stored as a `CryptoKey` via the structured clone
|
|
194
|
+
* algorithm; `extractable: false` is preserved, so the key cannot be read
|
|
195
|
+
* back as JWK / PEM even with full DOM access. A token leaked from
|
|
196
|
+
* localStorage remains unusable without this SDK origin's IndexedDB.
|
|
197
|
+
*
|
|
198
|
+
* After a reload, call `db.restoreSession()` to rehydrate. Use `db.logout()`
|
|
199
|
+
* to clear the persisted entry.
|
|
200
|
+
*
|
|
201
|
+
* Default: false. Opt-out by design: shared-device flows should not enable
|
|
202
|
+
* this.
|
|
203
|
+
*/
|
|
204
|
+
dpopPersist?: boolean;
|
|
205
|
+
}
|
|
206
|
+
/** Response from the login endpoint. */
|
|
207
|
+
export interface LoginResponse {
|
|
208
|
+
accessToken: string;
|
|
209
|
+
refreshToken: string;
|
|
210
|
+
expiresIn: number;
|
|
211
|
+
/**
|
|
212
|
+
* Token scheme: `Bearer` (default) or `DPoP` when the session has been
|
|
213
|
+
* sender-constrained via `/auth/dpop-bind` (RFC 9449). Optional for
|
|
214
|
+
* backward compatibility with older server responses.
|
|
215
|
+
*/
|
|
216
|
+
tokenType?: "Bearer" | "DPoP";
|
|
217
|
+
}
|
|
218
|
+
/** Cache event payloads. */
|
|
219
|
+
export interface CacheEvent {
|
|
220
|
+
/** Cache key (typically `${method}:${path}` form). */
|
|
221
|
+
key: string;
|
|
222
|
+
/** Resource path (without method prefix). */
|
|
223
|
+
path: string;
|
|
224
|
+
}
|
|
225
|
+
/** Map of event names to their payload types. */
|
|
226
|
+
export interface GeonicDBEventMap {
|
|
227
|
+
entityCreated: EntityEvent;
|
|
228
|
+
entityUpdated: EntityEvent;
|
|
229
|
+
entityDeleted: EntityEvent;
|
|
230
|
+
open: undefined;
|
|
231
|
+
connected: undefined;
|
|
232
|
+
close: {
|
|
233
|
+
code: number;
|
|
234
|
+
reason: string;
|
|
235
|
+
};
|
|
236
|
+
disconnected: undefined;
|
|
237
|
+
reconnecting: ReconnectingEvent;
|
|
238
|
+
error: Error;
|
|
239
|
+
message: Record<string, unknown>;
|
|
240
|
+
tokenRefresh: RefreshedCredentials;
|
|
241
|
+
/** Fired when a request is served from the in-memory cache (304 received). */
|
|
242
|
+
cacheHit: CacheEvent;
|
|
243
|
+
/** Fired when a request misses cache and is fetched from the origin. */
|
|
244
|
+
cacheMiss: CacheEvent;
|
|
245
|
+
/** Fired when a cache entry is invalidated (e.g. by a WebSocket entity event). */
|
|
246
|
+
cacheInvalidated: CacheEvent;
|
|
247
|
+
}
|
|
248
|
+
/** Parameters for querying temporal entities. */
|
|
249
|
+
export interface GetTemporalEntitiesParams {
|
|
250
|
+
/** Entity type filter */
|
|
251
|
+
type?: string;
|
|
252
|
+
/** Entity ID */
|
|
253
|
+
id?: string;
|
|
254
|
+
/** Entity ID pattern (regex) */
|
|
255
|
+
idPattern?: string;
|
|
256
|
+
/** Attribute names to retrieve */
|
|
257
|
+
attrs?: string;
|
|
258
|
+
/** NGSI-LD query expression */
|
|
259
|
+
q?: string;
|
|
260
|
+
/** Time property to use (observedAt, createdAt, modifiedAt) */
|
|
261
|
+
timeproperty?: string;
|
|
262
|
+
/** Start time (ISO 8601) */
|
|
263
|
+
timeAt?: string;
|
|
264
|
+
/** End time (ISO 8601) */
|
|
265
|
+
endTimeAt?: string;
|
|
266
|
+
/** Temporal relation (before, after, between) */
|
|
267
|
+
timerel?: string;
|
|
268
|
+
/** NGSI-LD scope query expression (#1132) */
|
|
269
|
+
scopeQ?: string;
|
|
270
|
+
/** Max results */
|
|
271
|
+
limit?: number;
|
|
272
|
+
/** Pagination offset */
|
|
273
|
+
offset?: number;
|
|
274
|
+
}
|
|
275
|
+
export type Listener<T> = (data: T) => void;
|
|
276
|
+
declare class EventEmitter {
|
|
277
|
+
private _listeners;
|
|
278
|
+
on<K extends keyof GeonicDBEventMap>(event: K, callback: Listener<GeonicDBEventMap[K]>): this;
|
|
279
|
+
on(event: string, callback: Listener<unknown>): this;
|
|
280
|
+
off<K extends keyof GeonicDBEventMap>(event: K, callback?: Listener<GeonicDBEventMap[K]>): this;
|
|
281
|
+
off(event: string, callback?: Listener<unknown>): this;
|
|
282
|
+
protected emit<K extends keyof GeonicDBEventMap>(event: K, data?: GeonicDBEventMap[K]): void;
|
|
283
|
+
protected emit(event: string, data?: unknown): void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Copyright (c) 2026 Geolonia Inc.
|
|
287
|
+
* Released under the MIT License. See src/sdk/LICENSE for details.
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* Base error class for GeonicDB SDK.
|
|
291
|
+
* All SDK errors extend this class, allowing `instanceof GeonicDBError` checks.
|
|
292
|
+
*/
|
|
293
|
+
export declare class GeonicDBError extends Error {
|
|
294
|
+
/** HTTP status code (if applicable) */
|
|
295
|
+
readonly statusCode: number;
|
|
296
|
+
constructor(message: string, statusCode?: number);
|
|
297
|
+
}
|
|
298
|
+
/** 401 — Authentication failed (invalid credentials, expired token). */
|
|
299
|
+
export declare class AuthenticationError extends GeonicDBError {
|
|
300
|
+
constructor(message?: string);
|
|
301
|
+
}
|
|
302
|
+
/** 403 — Authorization denied (insufficient permissions). */
|
|
303
|
+
export declare class AuthorizationError extends GeonicDBError {
|
|
304
|
+
constructor(message?: string);
|
|
305
|
+
}
|
|
306
|
+
/** 404 — Resource not found. */
|
|
307
|
+
export declare class NotFoundError extends GeonicDBError {
|
|
308
|
+
constructor(message?: string);
|
|
309
|
+
}
|
|
310
|
+
/** 409 — Conflict (e.g. entity already exists). */
|
|
311
|
+
export declare class ConflictError extends GeonicDBError {
|
|
312
|
+
constructor(message?: string);
|
|
313
|
+
}
|
|
314
|
+
/** 422 — Validation error (bad request payload). */
|
|
315
|
+
export declare class ValidationError extends GeonicDBError {
|
|
316
|
+
constructor(message?: string);
|
|
317
|
+
}
|
|
318
|
+
/** 429 — Rate limited. */
|
|
319
|
+
export declare class RateLimitError extends GeonicDBError {
|
|
320
|
+
/** Seconds to wait before retrying (from Retry-After header) */
|
|
321
|
+
readonly retryAfter: number;
|
|
322
|
+
constructor(message?: string, retryAfter?: number);
|
|
323
|
+
}
|
|
324
|
+
/** Network error (fetch failed, DNS resolution, timeout). */
|
|
325
|
+
export declare class NetworkError extends GeonicDBError {
|
|
326
|
+
constructor(message?: string);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* GeonicDB SDK client.
|
|
330
|
+
*
|
|
331
|
+
* Handles API key auth (DPoP + PoW), Bearer JWT, entity CRUD,
|
|
332
|
+
* WebSocket event streaming, and automatic reconnection.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* import GeonicDB from '@geolonia/geonicdb-sdk';
|
|
337
|
+
*
|
|
338
|
+
* const db = new GeonicDB({
|
|
339
|
+
* apiKey: 'your-api-key',
|
|
340
|
+
* tenant: 'your-tenant',
|
|
341
|
+
* baseUrl: 'https://your-geonicdb.example.com',
|
|
342
|
+
* });
|
|
343
|
+
*
|
|
344
|
+
* const entities = await db.getEntities({ type: 'Room' });
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export declare class GeonicDB extends EventEmitter {
|
|
348
|
+
private _auth;
|
|
349
|
+
private _ws;
|
|
350
|
+
/**
|
|
351
|
+
* Legacy callback for token refresh events.
|
|
352
|
+
* Prefer `db.on('tokenRefresh', callback)` for new code.
|
|
353
|
+
* @deprecated Use `db.on('tokenRefresh', callback)` instead.
|
|
354
|
+
*/
|
|
355
|
+
onTokenRefresh: ((creds: RefreshedCredentials) => void) | null;
|
|
356
|
+
constructor(options?: GeonicDBOptions);
|
|
357
|
+
/**
|
|
358
|
+
* Drop every cached response. Useful in tests and on manual auth changes.
|
|
359
|
+
*
|
|
360
|
+
* Emits a `cacheInvalidated` event for each removed entry so listeners can
|
|
361
|
+
* track explicit flushes (the WebSocket-driven auto-invalidation was removed
|
|
362
|
+
* in #1060 to preserve the ETag/304 revalidation path; `clearCache()` is now
|
|
363
|
+
* the only path that emits this event).
|
|
364
|
+
*/
|
|
365
|
+
clearCache(): void;
|
|
366
|
+
/**
|
|
367
|
+
* Login with email and password (Bearer JWT).
|
|
368
|
+
*
|
|
369
|
+
* Pass `{ dpop: true }` to immediately upgrade the session to a DPoP
|
|
370
|
+
* sender-constrained token (RFC 9449). Recommended for browser apps that
|
|
371
|
+
* persist tokens in storage exposed to XSS (localStorage / sessionStorage),
|
|
372
|
+
* since DPoP-bound tokens are unusable without this SDK instance's
|
|
373
|
+
* non-extractable private key.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* // Bearer (default, backward compatible)
|
|
378
|
+
* await db.login('user@example.com', 'password');
|
|
379
|
+
*
|
|
380
|
+
* // DPoP-bound (recommended for SPAs)
|
|
381
|
+
* await db.login('user@example.com', 'password', { dpop: true });
|
|
382
|
+
*
|
|
383
|
+
* // DPoP-bound + persisted across reloads (browser SPA UX)
|
|
384
|
+
* await db.login('user@example.com', 'password', {
|
|
385
|
+
* dpop: true,
|
|
386
|
+
* dpopPersist: true,
|
|
387
|
+
* });
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
login(email: string, password: string, options?: LoginOptions): Promise<LoginResponse>;
|
|
391
|
+
/**
|
|
392
|
+
* Rehydrate a DPoP session previously persisted via
|
|
393
|
+
* `login({ dpop: true, dpopPersist: true })`.
|
|
394
|
+
*
|
|
395
|
+
* Returns true if a session for this tenant was found and loaded; false
|
|
396
|
+
* if there was no entry, IndexedDB is unavailable, or the persisted
|
|
397
|
+
* session was malformed. Call this at app startup before deciding
|
|
398
|
+
* whether to render the login form.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* const db = new GeonicDB({ baseUrl, tenant });
|
|
403
|
+
* if (await db.restoreSession()) {
|
|
404
|
+
* // Tokens + DPoP private key recovered from IndexedDB — boot the app.
|
|
405
|
+
* } else {
|
|
406
|
+
* // No session; show the login form.
|
|
407
|
+
* }
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
restoreSession(): Promise<boolean>;
|
|
411
|
+
/**
|
|
412
|
+
* Whether the SDK is currently operating in anonymous mode (no token held).
|
|
413
|
+
* Returns true only when `anonymous: true` was passed to the constructor
|
|
414
|
+
* AND no credentials have been set via `login()` / `setCredentials()`.
|
|
415
|
+
*/
|
|
416
|
+
isAnonymous(): boolean;
|
|
417
|
+
/**
|
|
418
|
+
* Set credentials externally (e.g. from a login API response).
|
|
419
|
+
* When tokenType is 'Bearer' with a refreshToken, DPoP/PoW is bypassed entirely.
|
|
420
|
+
*/
|
|
421
|
+
setCredentials(opts: CredentialsOptions): this;
|
|
422
|
+
/** Clear all credentials and disconnect. */
|
|
423
|
+
logout(): void;
|
|
424
|
+
/** Create a new entity. */
|
|
425
|
+
createEntity(entity: Record<string, unknown>): Promise<{
|
|
426
|
+
created: true;
|
|
427
|
+
}>;
|
|
428
|
+
/** Get a single entity by ID. */
|
|
429
|
+
getEntity(entityId: string): Promise<Record<string, unknown>>;
|
|
430
|
+
/** Query entities with optional filters. */
|
|
431
|
+
getEntities(params?: GetEntitiesParams): Promise<Record<string, unknown>[]>;
|
|
432
|
+
/**
|
|
433
|
+
* Poll for entity list changes using ETag-based revalidation (#991 Phase A).
|
|
434
|
+
*
|
|
435
|
+
* The handle's `stop()` ends the loop. Each tick performs a normal
|
|
436
|
+
* `getEntities()` call; the SDK's cache layer issues `If-None-Match`
|
|
437
|
+
* automatically. The poll detects "no change" by comparing the previous
|
|
438
|
+
* ETag with the response's ETag (the cache exposes the cached ETag on 304
|
|
439
|
+
* replays as well, so the comparison stays valid in both 200 and 304
|
|
440
|
+
* paths).
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* const handle = db.poll({ type: 'Room' }, {
|
|
445
|
+
* interval: 5000,
|
|
446
|
+
* onData: (rooms) => render(rooms),
|
|
447
|
+
* onNoChange: () => {},
|
|
448
|
+
* });
|
|
449
|
+
* // ...later
|
|
450
|
+
* handle.stop();
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
poll(params: GetEntitiesParams | undefined, options: PollOptions<Record<string, unknown>[]>): PollHandle;
|
|
454
|
+
/** Count entities matching the given filters. */
|
|
455
|
+
count(params?: CountEntitiesParams): Promise<number>;
|
|
456
|
+
/** Update entity attributes (partial). */
|
|
457
|
+
updateEntity(entityId: string, attrs: Record<string, unknown>): Promise<{
|
|
458
|
+
updated: true;
|
|
459
|
+
}>;
|
|
460
|
+
/** Delete an entity. */
|
|
461
|
+
deleteEntity(entityId: string): Promise<{
|
|
462
|
+
deleted: true;
|
|
463
|
+
}>;
|
|
464
|
+
/** List all entity types. */
|
|
465
|
+
getTypes(): Promise<Record<string, unknown>[]>;
|
|
466
|
+
/** Get details for a specific entity type. */
|
|
467
|
+
getType(typeName: string): Promise<Record<string, unknown>>;
|
|
468
|
+
/** List all attributes. */
|
|
469
|
+
getAttributes(): Promise<Record<string, unknown>[]>;
|
|
470
|
+
/** Get details for a specific attribute. */
|
|
471
|
+
getAttribute(attrName: string): Promise<Record<string, unknown>>;
|
|
472
|
+
/** Query temporal entities. */
|
|
473
|
+
getTemporalEntities(params?: GetTemporalEntitiesParams): Promise<Record<string, unknown>[]>;
|
|
474
|
+
/** Get temporal representation of a single entity. */
|
|
475
|
+
getTemporalEntity(entityId: string): Promise<Record<string, unknown>>;
|
|
476
|
+
/** Create multiple entities in a single request. */
|
|
477
|
+
batchCreate(entities: Record<string, unknown>[]): Promise<Record<string, unknown>>;
|
|
478
|
+
/** Upsert multiple entities in a single request. */
|
|
479
|
+
batchUpsert(entities: Record<string, unknown>[]): Promise<Record<string, unknown>>;
|
|
480
|
+
/** Update multiple entities in a single request. */
|
|
481
|
+
batchUpdate(entities: Record<string, unknown>[]): Promise<Record<string, unknown>>;
|
|
482
|
+
/** Delete multiple entities by ID. */
|
|
483
|
+
batchDelete(entityIds: string[]): Promise<Record<string, unknown>>;
|
|
484
|
+
/** GET request that returns parsed JSON or throws. */
|
|
485
|
+
private _jsonGet;
|
|
486
|
+
/** POST request that returns parsed JSON or throws. */
|
|
487
|
+
private _jsonPost;
|
|
488
|
+
/**
|
|
489
|
+
* Make an authenticated API request.
|
|
490
|
+
* Automatically checks response status, parses JSON, and throws on error.
|
|
491
|
+
*
|
|
492
|
+
* Empty bodies (`Content-Length: 0` 含む) は Content-Type に関係なく `null`
|
|
493
|
+
* を返す (#1145)。NGSI-LD の POST / DELETE / PATCH 系は仕様上ボディが
|
|
494
|
+
* 空だが、サーバ実装が `Content-Type: application/ld+json` を付けて返す
|
|
495
|
+
* ケースがあり、そこで `res.json()` が SyntaxError を投げて止まっていた。
|
|
496
|
+
*/
|
|
497
|
+
request(method: string, path: string, body?: unknown): Promise<unknown>;
|
|
498
|
+
/**
|
|
499
|
+
* Make an authenticated API request and return the raw Response object.
|
|
500
|
+
* Use this when you need access to response headers (e.g. NGSILD-Results-Count).
|
|
501
|
+
*/
|
|
502
|
+
requestRaw(method: string, path: string, body?: unknown): Promise<Response>;
|
|
503
|
+
/** Establish WebSocket connection (authentication is automatic). */
|
|
504
|
+
connect(): Promise<void>;
|
|
505
|
+
/** Force-reconnect (closes existing connection, preserves subscriptions). */
|
|
506
|
+
reconnect(): Promise<void>;
|
|
507
|
+
/** Disconnect WebSocket (does not fire 'disconnected' event). */
|
|
508
|
+
disconnect(): void;
|
|
509
|
+
/** Check if WebSocket is currently open. */
|
|
510
|
+
isConnected(): boolean;
|
|
511
|
+
/** Subscribe to entity events (can be called before or after connect). */
|
|
512
|
+
subscribe(options?: SubscribeOptions): void;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* 汎用クエリ文字列ビルダ。`undefined` / `null` は省略、`boolean` は
|
|
516
|
+
* `'true'` / `'false'` の文字列、`number` は `String(n)`、それ以外は文字列化。
|
|
517
|
+
* 配列 / オブジェクトはサポート対象外 (NGSI-LD 仕様内の全パラメータは
|
|
518
|
+
* primitive で表現できるため不要)。
|
|
519
|
+
*/
|
|
520
|
+
export declare function buildPathWithParams(path: string, params?: Record<string, unknown>): string;
|
|
521
|
+
|
|
1
522
|
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
GeonicDBError,
|
|
7
|
-
NetworkError,
|
|
8
|
-
NotFoundError,
|
|
9
|
-
RateLimitError,
|
|
10
|
-
ValidationError,
|
|
11
|
-
buildPathWithParams,
|
|
12
|
-
} from './index';
|
|
13
|
-
export type {
|
|
14
|
-
CacheEvent,
|
|
15
|
-
CountEntitiesParams,
|
|
16
|
-
CredentialsOptions,
|
|
17
|
-
EntityEvent,
|
|
18
|
-
GeonicDBEventMap,
|
|
19
|
-
GeonicDBOptions,
|
|
20
|
-
GetEntitiesParams,
|
|
21
|
-
GetTemporalEntitiesParams,
|
|
22
|
-
LoginOptions,
|
|
23
|
-
LoginResponse,
|
|
24
|
-
PollHandle,
|
|
25
|
-
PollOptions,
|
|
26
|
-
ReconnectingEvent,
|
|
27
|
-
RefreshedCredentials,
|
|
28
|
-
SubscribeOptions,
|
|
29
|
-
} from './index';
|
|
30
|
-
export { default } from './index';
|
|
523
|
+
GeonicDB as default,
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
export {};
|