@geolonia/geonicdb-sdk 0.13.0 → 0.14.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/README.md +28 -1
- package/ngsi-v2/index.cjs +3 -0
- package/ngsi-v2/index.cjs.map +2 -2
- package/ngsi-v2/index.d.ts +6 -0
- package/ngsi-v2/index.mjs +3 -0
- package/ngsi-v2/index.mjs.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -633,12 +633,39 @@ const rooms = await client.getEntities({ type: 'Room', limit: 20 });
|
|
|
633
633
|
| Method | Description |
|
|
634
634
|
|--------|-------------|
|
|
635
635
|
| `createNgsiV2Client(config)` | `NgsiV2Client` を生成。`config`: `baseUrl`(必須)/ `apiKey` / `service` |
|
|
636
|
-
| `getEntities(options?)` | エンティティ一覧(`type` / `q` / `limit` / `offset` / `attrs` / `options`) |
|
|
636
|
+
| `getEntities(options?)` | エンティティ一覧(`type` / `q` / `limit` / `offset` / `attrs` / `options` / `georel` / `geometry` / `coords`) |
|
|
637
637
|
| `getEntity(id, options?)` | 単一エンティティ取得 |
|
|
638
638
|
| `createEntity(entity)` | エンティティ作成 |
|
|
639
639
|
| `updateEntityAttributes(id, attrs)` | 属性の部分更新 |
|
|
640
640
|
| `deleteEntity(id)` | エンティティ削除 |
|
|
641
641
|
|
|
642
|
+
### Geospatial query (`georel` / `geometry` / `coords`)
|
|
643
|
+
|
|
644
|
+
NGSIv2 の地理空間クエリに対応。`georel`・`geometry`・`coords` は 3 つ揃えて指定する(部分指定は Orion 側で `400`)。
|
|
645
|
+
|
|
646
|
+
| Option | Type | Description |
|
|
647
|
+
|--------|------|-------------|
|
|
648
|
+
| `georel` | `string` | 地理的関係。複合形も可(例: `near;maxDistance:1000`, `coveredBy`) |
|
|
649
|
+
| `geometry` | `'point' \| 'line' \| 'polygon' \| 'box'` | ジオメトリ種別 |
|
|
650
|
+
| `coords` | `string` | WGS84 座標。複数点はセミコロン区切り(例: `35.6,139.7`) |
|
|
651
|
+
|
|
652
|
+
```ts
|
|
653
|
+
// 指定座標から半径 1km 以内
|
|
654
|
+
const nearby = await client.getEntities({
|
|
655
|
+
type: 'PublicFacility',
|
|
656
|
+
georel: 'near;maxDistance:1000',
|
|
657
|
+
geometry: 'point',
|
|
658
|
+
coords: '35.6,139.7',
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// ポリゴン内に含まれるエンティティ
|
|
662
|
+
const inArea = await client.getEntities({
|
|
663
|
+
georel: 'coveredBy',
|
|
664
|
+
geometry: 'polygon',
|
|
665
|
+
coords: '0,0;1,0;1,1;0,1;0,0',
|
|
666
|
+
});
|
|
667
|
+
```
|
|
668
|
+
|
|
642
669
|
## License
|
|
643
670
|
|
|
644
671
|
MIT
|
package/ngsi-v2/index.cjs
CHANGED
|
@@ -62,6 +62,9 @@ var NgsiV2Client = class {
|
|
|
62
62
|
if (options?.offset !== void 0) sp.set("offset", String(options.offset));
|
|
63
63
|
if (options?.attrs) sp.set("attrs", options.attrs);
|
|
64
64
|
if (options?.options) sp.set("options", options.options);
|
|
65
|
+
if (options?.georel) sp.set("georel", options.georel);
|
|
66
|
+
if (options?.geometry) sp.set("geometry", options.geometry);
|
|
67
|
+
if (options?.coords) sp.set("coords", options.coords);
|
|
65
68
|
const qs = sp.toString();
|
|
66
69
|
return this.request("GET", `/v2/entities${qs ? "?" + qs : ""}`);
|
|
67
70
|
}
|
package/ngsi-v2/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/sdk/ngsi-v2/index.ts"],
|
|
4
|
-
"sourcesContent": ["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Geolonia Inc.\n// See LICENSE in src/sdk/ for full license text.\n\n/**\n * NGSIv2 basic client \u2014 bundled per ADR\u8AD6\u70B92=a (\u6BBF\u88C1\u53EF\u78BA\u5B9A)\n *\n * Scope: basic entity CRUD only. No subscriptions, no batch ops.\n * For NGSI-LD, use the core GeonicDB client instead.\n */\n\nexport interface NgsiV2ClientConfig {\n baseUrl: string;\n /** FIWARE service (tenant) */\n service?: string;\n /** FIWARE service path */\n servicePath?: string;\n}\n\nexport interface NgsiV2Entity {\n id: string;\n type: string;\n [key: string]: string | NgsiV2Attribute | undefined;\n}\n\nexport interface NgsiV2Attribute {\n type: string;\n value: string | number | boolean | object | null;\n metadata?: Record<string, { type: string; value: unknown }>;\n}\n\nexport interface NgsiV2QueryOptions {\n type?: string;\n q?: string;\n limit?: number;\n offset?: number;\n attrs?: string;\n options?: string;\n}\n\nexport class NgsiV2Client {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(config: NgsiV2ClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '');\n this.headers = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n };\n if (config.service) this.headers['Fiware-Service'] = config.service;\n if (config.servicePath) this.headers['Fiware-ServicePath'] = config.servicePath;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: this.headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n if (!res.ok) {\n const err = await res.json().catch(() => ({ error: `HTTP ${res.status}` })) as Record<string, unknown>;\n const description = typeof err['description'] === 'string' ? err['description'] : undefined;\n const error = typeof err['error'] === 'string' ? err['error'] : undefined;\n throw new Error(description ?? error ?? `HTTP ${res.status}`);\n }\n if (res.status === 201 || res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n }\n\n /** List entities */\n async getEntities(options?: NgsiV2QueryOptions): Promise<NgsiV2Entity[]> {\n const sp = new URLSearchParams();\n if (options?.type) sp.set('type', options.type);\n if (options?.q) sp.set('q', options.q);\n if (options?.limit !== undefined) sp.set('limit', String(options.limit));\n if (options?.offset !== undefined) sp.set('offset', String(options.offset));\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n const qs = sp.toString();\n return this.request<NgsiV2Entity[]>('GET', `/v2/entities${qs ? '?' + qs : ''}`);\n }\n\n /** Get single entity by ID */\n async getEntity(entityId: string, options?: { attrs?: string; options?: string }): Promise<NgsiV2Entity> {\n const sp = new URLSearchParams();\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n const qs = sp.toString();\n return this.request<NgsiV2Entity>('GET', `/v2/entities/${encodeURIComponent(entityId)}${qs ? '?' + qs : ''}`);\n }\n\n /** Create entity */\n async createEntity(entity: NgsiV2Entity): Promise<void> {\n await this.request<void>('POST', '/v2/entities', entity);\n }\n\n /** Update entity attributes (partial) */\n async updateEntityAttributes(entityId: string, attrs: Record<string, NgsiV2Attribute>): Promise<void> {\n await this.request<void>('PATCH', `/v2/entities/${encodeURIComponent(entityId)}/attrs`, attrs);\n }\n\n /** Delete entity */\n async deleteEntity(entityId: string): Promise<void> {\n await this.request<void>('DELETE', `/v2/entities/${encodeURIComponent(entityId)}`);\n }\n}\n\nexport function createNgsiV2Client(config: NgsiV2ClientConfig): NgsiV2Client {\n return new NgsiV2Client(config);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Geolonia Inc.\n// See LICENSE in src/sdk/ for full license text.\n\n/**\n * NGSIv2 basic client \u2014 bundled per ADR\u8AD6\u70B92=a (\u6BBF\u88C1\u53EF\u78BA\u5B9A)\n *\n * Scope: basic entity CRUD only. No subscriptions, no batch ops.\n * For NGSI-LD, use the core GeonicDB client instead.\n */\n\nexport interface NgsiV2ClientConfig {\n baseUrl: string;\n /** FIWARE service (tenant) */\n service?: string;\n /** FIWARE service path */\n servicePath?: string;\n}\n\nexport interface NgsiV2Entity {\n id: string;\n type: string;\n [key: string]: string | NgsiV2Attribute | undefined;\n}\n\nexport interface NgsiV2Attribute {\n type: string;\n value: string | number | boolean | object | null;\n metadata?: Record<string, { type: string; value: unknown }>;\n}\n\nexport interface NgsiV2QueryOptions {\n type?: string;\n q?: string;\n limit?: number;\n offset?: number;\n attrs?: string;\n options?: string;\n /** Geo-relation (NGSIv2 / FIWARE Orion). Accepts compound form, e.g. 'near;maxDistance:1000' or 'coveredBy'. */\n georel?: string;\n /** Geometry type for the geo query. */\n geometry?: 'point' | 'line' | 'polygon' | 'box';\n /** WGS84 coordinate string, e.g. '35.6,139.7'. Semicolon-delimited pairs for multi-point geometries. */\n coords?: string;\n}\n\nexport class NgsiV2Client {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(config: NgsiV2ClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '');\n this.headers = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n };\n if (config.service) this.headers['Fiware-Service'] = config.service;\n if (config.servicePath) this.headers['Fiware-ServicePath'] = config.servicePath;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: this.headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n if (!res.ok) {\n const err = await res.json().catch(() => ({ error: `HTTP ${res.status}` })) as Record<string, unknown>;\n const description = typeof err['description'] === 'string' ? err['description'] : undefined;\n const error = typeof err['error'] === 'string' ? err['error'] : undefined;\n throw new Error(description ?? error ?? `HTTP ${res.status}`);\n }\n if (res.status === 201 || res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n }\n\n /** List entities */\n async getEntities(options?: NgsiV2QueryOptions): Promise<NgsiV2Entity[]> {\n const sp = new URLSearchParams();\n if (options?.type) sp.set('type', options.type);\n if (options?.q) sp.set('q', options.q);\n if (options?.limit !== undefined) sp.set('limit', String(options.limit));\n if (options?.offset !== undefined) sp.set('offset', String(options.offset));\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n if (options?.georel) sp.set('georel', options.georel);\n if (options?.geometry) sp.set('geometry', options.geometry);\n if (options?.coords) sp.set('coords', options.coords);\n const qs = sp.toString();\n return this.request<NgsiV2Entity[]>('GET', `/v2/entities${qs ? '?' + qs : ''}`);\n }\n\n /** Get single entity by ID */\n async getEntity(entityId: string, options?: { attrs?: string; options?: string }): Promise<NgsiV2Entity> {\n const sp = new URLSearchParams();\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n const qs = sp.toString();\n return this.request<NgsiV2Entity>('GET', `/v2/entities/${encodeURIComponent(entityId)}${qs ? '?' + qs : ''}`);\n }\n\n /** Create entity */\n async createEntity(entity: NgsiV2Entity): Promise<void> {\n await this.request<void>('POST', '/v2/entities', entity);\n }\n\n /** Update entity attributes (partial) */\n async updateEntityAttributes(entityId: string, attrs: Record<string, NgsiV2Attribute>): Promise<void> {\n await this.request<void>('PATCH', `/v2/entities/${encodeURIComponent(entityId)}/attrs`, attrs);\n }\n\n /** Delete entity */\n async deleteEntity(entityId: string): Promise<void> {\n await this.request<void>('DELETE', `/v2/entities/${encodeURIComponent(entityId)}`);\n }\n}\n\nexport function createNgsiV2Client(config: NgsiV2ClientConfig): NgsiV2Client {\n return new NgsiV2Client(config);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8CO,IAAM,eAAN,MAAmB;AAAA,EAIxB,YAAY,QAA4B;AAHxC,wBAAQ;AACR,wBAAQ;AAGN,SAAK,UAAU,OAAO,QAAQ,QAAQ,OAAO,EAAE;AAC/C,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV;AACA,QAAI,OAAO,QAAS,MAAK,QAAQ,gBAAgB,IAAI,OAAO;AAC5D,QAAI,OAAO,YAAa,MAAK,QAAQ,oBAAoB,IAAI,OAAO;AAAA,EACtE;AAAA,EAEA,MAAc,QAAW,QAAgB,MAAc,MAA4B;AACjF,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;AACvB,WAAO,KAAK,QAAwB,OAAO,eAAe,KAAK,MAAM,KAAK,EAAE,EAAE;AAAA,EAChF;AAAA;AAAA,EAGA,MAAM,UAAU,UAAkB,SAAuE;AACvG,UAAM,KAAK,IAAI,gBAAgB;AAC/B,QAAI,SAAS,MAAO,IAAG,IAAI,SAAS,QAAQ,KAAK;AACjD,QAAI,SAAS,QAAS,IAAG,IAAI,WAAW,QAAQ,OAAO;AACvD,UAAM,KAAK,GAAG,SAAS;AACvB,WAAO,KAAK,QAAsB,OAAO,gBAAgB,mBAAmB,QAAQ,CAAC,GAAG,KAAK,MAAM,KAAK,EAAE,EAAE;AAAA,EAC9G;AAAA;AAAA,EAGA,MAAM,aAAa,QAAqC;AACtD,UAAM,KAAK,QAAc,QAAQ,gBAAgB,MAAM;AAAA,EACzD;AAAA;AAAA,EAGA,MAAM,uBAAuB,UAAkB,OAAuD;AACpG,UAAM,KAAK,QAAc,SAAS,gBAAgB,mBAAmB,QAAQ,CAAC,UAAU,KAAK;AAAA,EAC/F;AAAA;AAAA,EAGA,MAAM,aAAa,UAAiC;AAClD,UAAM,KAAK,QAAc,UAAU,gBAAgB,mBAAmB,QAAQ,CAAC,EAAE;AAAA,EACnF;AACF;AAEO,SAAS,mBAAmB,QAA0C;AAC3E,SAAO,IAAI,aAAa,MAAM;AAChC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/ngsi-v2/index.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface NgsiV2QueryOptions {
|
|
|
33
33
|
offset?: number;
|
|
34
34
|
attrs?: string;
|
|
35
35
|
options?: string;
|
|
36
|
+
/** Geo-relation (NGSIv2 / FIWARE Orion). Accepts compound form, e.g. 'near;maxDistance:1000' or 'coveredBy'. */
|
|
37
|
+
georel?: string;
|
|
38
|
+
/** Geometry type for the geo query. */
|
|
39
|
+
geometry?: "point" | "line" | "polygon" | "box";
|
|
40
|
+
/** WGS84 coordinate string, e.g. '35.6,139.7'. Semicolon-delimited pairs for multi-point geometries. */
|
|
41
|
+
coords?: string;
|
|
36
42
|
}
|
|
37
43
|
export declare class NgsiV2Client {
|
|
38
44
|
private baseUrl;
|
package/ngsi-v2/index.mjs
CHANGED
|
@@ -39,6 +39,9 @@ var NgsiV2Client = class {
|
|
|
39
39
|
if (options?.offset !== void 0) sp.set("offset", String(options.offset));
|
|
40
40
|
if (options?.attrs) sp.set("attrs", options.attrs);
|
|
41
41
|
if (options?.options) sp.set("options", options.options);
|
|
42
|
+
if (options?.georel) sp.set("georel", options.georel);
|
|
43
|
+
if (options?.geometry) sp.set("geometry", options.geometry);
|
|
44
|
+
if (options?.coords) sp.set("coords", options.coords);
|
|
42
45
|
const qs = sp.toString();
|
|
43
46
|
return this.request("GET", `/v2/entities${qs ? "?" + qs : ""}`);
|
|
44
47
|
}
|
package/ngsi-v2/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/sdk/ngsi-v2/index.ts"],
|
|
4
|
-
"sourcesContent": ["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Geolonia Inc.\n// See LICENSE in src/sdk/ for full license text.\n\n/**\n * NGSIv2 basic client \u2014 bundled per ADR\u8AD6\u70B92=a (\u6BBF\u88C1\u53EF\u78BA\u5B9A)\n *\n * Scope: basic entity CRUD only. No subscriptions, no batch ops.\n * For NGSI-LD, use the core GeonicDB client instead.\n */\n\nexport interface NgsiV2ClientConfig {\n baseUrl: string;\n /** FIWARE service (tenant) */\n service?: string;\n /** FIWARE service path */\n servicePath?: string;\n}\n\nexport interface NgsiV2Entity {\n id: string;\n type: string;\n [key: string]: string | NgsiV2Attribute | undefined;\n}\n\nexport interface NgsiV2Attribute {\n type: string;\n value: string | number | boolean | object | null;\n metadata?: Record<string, { type: string; value: unknown }>;\n}\n\nexport interface NgsiV2QueryOptions {\n type?: string;\n q?: string;\n limit?: number;\n offset?: number;\n attrs?: string;\n options?: string;\n}\n\nexport class NgsiV2Client {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(config: NgsiV2ClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '');\n this.headers = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n };\n if (config.service) this.headers['Fiware-Service'] = config.service;\n if (config.servicePath) this.headers['Fiware-ServicePath'] = config.servicePath;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: this.headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n if (!res.ok) {\n const err = await res.json().catch(() => ({ error: `HTTP ${res.status}` })) as Record<string, unknown>;\n const description = typeof err['description'] === 'string' ? err['description'] : undefined;\n const error = typeof err['error'] === 'string' ? err['error'] : undefined;\n throw new Error(description ?? error ?? `HTTP ${res.status}`);\n }\n if (res.status === 201 || res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n }\n\n /** List entities */\n async getEntities(options?: NgsiV2QueryOptions): Promise<NgsiV2Entity[]> {\n const sp = new URLSearchParams();\n if (options?.type) sp.set('type', options.type);\n if (options?.q) sp.set('q', options.q);\n if (options?.limit !== undefined) sp.set('limit', String(options.limit));\n if (options?.offset !== undefined) sp.set('offset', String(options.offset));\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n const qs = sp.toString();\n return this.request<NgsiV2Entity[]>('GET', `/v2/entities${qs ? '?' + qs : ''}`);\n }\n\n /** Get single entity by ID */\n async getEntity(entityId: string, options?: { attrs?: string; options?: string }): Promise<NgsiV2Entity> {\n const sp = new URLSearchParams();\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n const qs = sp.toString();\n return this.request<NgsiV2Entity>('GET', `/v2/entities/${encodeURIComponent(entityId)}${qs ? '?' + qs : ''}`);\n }\n\n /** Create entity */\n async createEntity(entity: NgsiV2Entity): Promise<void> {\n await this.request<void>('POST', '/v2/entities', entity);\n }\n\n /** Update entity attributes (partial) */\n async updateEntityAttributes(entityId: string, attrs: Record<string, NgsiV2Attribute>): Promise<void> {\n await this.request<void>('PATCH', `/v2/entities/${encodeURIComponent(entityId)}/attrs`, attrs);\n }\n\n /** Delete entity */\n async deleteEntity(entityId: string): Promise<void> {\n await this.request<void>('DELETE', `/v2/entities/${encodeURIComponent(entityId)}`);\n }\n}\n\nexport function createNgsiV2Client(config: NgsiV2ClientConfig): NgsiV2Client {\n return new NgsiV2Client(config);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;
|
|
4
|
+
"sourcesContent": ["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Geolonia Inc.\n// See LICENSE in src/sdk/ for full license text.\n\n/**\n * NGSIv2 basic client \u2014 bundled per ADR\u8AD6\u70B92=a (\u6BBF\u88C1\u53EF\u78BA\u5B9A)\n *\n * Scope: basic entity CRUD only. No subscriptions, no batch ops.\n * For NGSI-LD, use the core GeonicDB client instead.\n */\n\nexport interface NgsiV2ClientConfig {\n baseUrl: string;\n /** FIWARE service (tenant) */\n service?: string;\n /** FIWARE service path */\n servicePath?: string;\n}\n\nexport interface NgsiV2Entity {\n id: string;\n type: string;\n [key: string]: string | NgsiV2Attribute | undefined;\n}\n\nexport interface NgsiV2Attribute {\n type: string;\n value: string | number | boolean | object | null;\n metadata?: Record<string, { type: string; value: unknown }>;\n}\n\nexport interface NgsiV2QueryOptions {\n type?: string;\n q?: string;\n limit?: number;\n offset?: number;\n attrs?: string;\n options?: string;\n /** Geo-relation (NGSIv2 / FIWARE Orion). Accepts compound form, e.g. 'near;maxDistance:1000' or 'coveredBy'. */\n georel?: string;\n /** Geometry type for the geo query. */\n geometry?: 'point' | 'line' | 'polygon' | 'box';\n /** WGS84 coordinate string, e.g. '35.6,139.7'. Semicolon-delimited pairs for multi-point geometries. */\n coords?: string;\n}\n\nexport class NgsiV2Client {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(config: NgsiV2ClientConfig) {\n this.baseUrl = config.baseUrl.replace(/\\/$/, '');\n this.headers = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n };\n if (config.service) this.headers['Fiware-Service'] = config.service;\n if (config.servicePath) this.headers['Fiware-ServicePath'] = config.servicePath;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers: this.headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n if (!res.ok) {\n const err = await res.json().catch(() => ({ error: `HTTP ${res.status}` })) as Record<string, unknown>;\n const description = typeof err['description'] === 'string' ? err['description'] : undefined;\n const error = typeof err['error'] === 'string' ? err['error'] : undefined;\n throw new Error(description ?? error ?? `HTTP ${res.status}`);\n }\n if (res.status === 201 || res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n }\n\n /** List entities */\n async getEntities(options?: NgsiV2QueryOptions): Promise<NgsiV2Entity[]> {\n const sp = new URLSearchParams();\n if (options?.type) sp.set('type', options.type);\n if (options?.q) sp.set('q', options.q);\n if (options?.limit !== undefined) sp.set('limit', String(options.limit));\n if (options?.offset !== undefined) sp.set('offset', String(options.offset));\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n if (options?.georel) sp.set('georel', options.georel);\n if (options?.geometry) sp.set('geometry', options.geometry);\n if (options?.coords) sp.set('coords', options.coords);\n const qs = sp.toString();\n return this.request<NgsiV2Entity[]>('GET', `/v2/entities${qs ? '?' + qs : ''}`);\n }\n\n /** Get single entity by ID */\n async getEntity(entityId: string, options?: { attrs?: string; options?: string }): Promise<NgsiV2Entity> {\n const sp = new URLSearchParams();\n if (options?.attrs) sp.set('attrs', options.attrs);\n if (options?.options) sp.set('options', options.options);\n const qs = sp.toString();\n return this.request<NgsiV2Entity>('GET', `/v2/entities/${encodeURIComponent(entityId)}${qs ? '?' + qs : ''}`);\n }\n\n /** Create entity */\n async createEntity(entity: NgsiV2Entity): Promise<void> {\n await this.request<void>('POST', '/v2/entities', entity);\n }\n\n /** Update entity attributes (partial) */\n async updateEntityAttributes(entityId: string, attrs: Record<string, NgsiV2Attribute>): Promise<void> {\n await this.request<void>('PATCH', `/v2/entities/${encodeURIComponent(entityId)}/attrs`, attrs);\n }\n\n /** Delete entity */\n async deleteEntity(entityId: string): Promise<void> {\n await this.request<void>('DELETE', `/v2/entities/${encodeURIComponent(entityId)}`);\n }\n}\n\nexport function createNgsiV2Client(config: NgsiV2ClientConfig): NgsiV2Client {\n return new NgsiV2Client(config);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AA8CO,IAAM,eAAN,MAAmB;AAAA,EAIxB,YAAY,QAA4B;AAHxC,wBAAQ;AACR,wBAAQ;AAGN,SAAK,UAAU,OAAO,QAAQ,QAAQ,OAAO,EAAE;AAC/C,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,QAAQ;AAAA,IACV;AACA,QAAI,OAAO,QAAS,MAAK,QAAQ,gBAAgB,IAAI,OAAO;AAC5D,QAAI,OAAO,YAAa,MAAK,QAAQ,oBAAoB,IAAI,OAAO;AAAA,EACtE;AAAA,EAEA,MAAc,QAAW,QAAgB,MAAc,MAA4B;AACjF,UAAM,MAAM,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,MAChD;AAAA,MACA,SAAS,KAAK;AAAA,MACd,MAAM,SAAS,SAAY,KAAK,UAAU,IAAI,IAAI;AAAA,IACpD,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,MAAM,MAAM,IAAI,KAAK,EAAE,MAAM,OAAO,EAAE,OAAO,QAAQ,IAAI,MAAM,GAAG,EAAE;AAC1E,YAAM,cAAc,OAAO,IAAI,aAAa,MAAM,WAAW,IAAI,aAAa,IAAI;AAClF,YAAM,QAAQ,OAAO,IAAI,OAAO,MAAM,WAAW,IAAI,OAAO,IAAI;AAChE,YAAM,IAAI,MAAM,eAAe,SAAS,QAAQ,IAAI,MAAM,EAAE;AAAA,IAC9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