@geolonia/geonicdb-sdk 0.15.0 → 0.17.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/geonicdb.mjs CHANGED
@@ -46,7 +46,7 @@ var RECONNECT_MAX_ATTEMPTS = 10;
46
46
  var RECONNECT_BASE_MS = 1e3;
47
47
  var RECONNECT_MAX_DELAY_MS = 3e4;
48
48
  var SUB_PROTOCOL = "access_token";
49
- var NGSI_LD_CORE_CONTEXT = "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld";
49
+ var NGSI_LD_CORE_CONTEXT = "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.9.jsonld";
50
50
  var SDK_CACHE_MAX_ENTRIES_DEFAULT = 1e3;
51
51
  var SDK_POLL_INTERVAL_MS_DEFAULT = 5e3;
52
52
  var DPOP_IDB_NAME = "geonicdb-sdk";
@@ -1210,13 +1210,12 @@ var _AuthManager = class _AuthManager {
1210
1210
  }
1211
1211
  const url = this._baseUrl + path;
1212
1212
  const isDPoP = this._tokenType === "DPoP" && !!this._dpopKeyPair && token !== null;
1213
- const isEntityWrite = path.split("?")[0].startsWith("/ngsi-ld/v1/entities");
1213
+ const pathname = path.split("?")[0];
1214
+ const isNgsiLdWrite = pathname.startsWith("/ngsi-ld/v1/") && pathname !== "/ngsi-ld/v1/jsonldContexts";
1215
+ const withCoreContext = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && !("@context" in value) ? { ...value, "@context": NGSI_LD_CORE_CONTEXT } : value;
1214
1216
  let effectiveBody = body;
1215
- if (isEntityWrite && effectiveBody !== null && typeof effectiveBody === "object" && !Array.isArray(effectiveBody) && !("@context" in effectiveBody)) {
1216
- effectiveBody = {
1217
- ...effectiveBody,
1218
- "@context": NGSI_LD_CORE_CONTEXT
1219
- };
1217
+ if (isNgsiLdWrite && effectiveBody !== void 0) {
1218
+ effectiveBody = Array.isArray(effectiveBody) ? effectiveBody.map(withCoreContext) : withCoreContext(effectiveBody);
1220
1219
  }
1221
1220
  const bodyStr = effectiveBody !== void 0 ? JSON.stringify(effectiveBody) : void 0;
1222
1221
  const doRequest = async (reqToken, dpopNonce) => {
@@ -1362,6 +1361,7 @@ var WebSocketManager = class {
1362
1361
  if (options.entityTypes) msg.entityTypes = options.entityTypes;
1363
1362
  if (options.idPattern) msg.idPattern = options.idPattern;
1364
1363
  if (options.scopeQ) msg.scopeQ = options.scopeQ;
1364
+ if (options["@context"]) msg["@context"] = options["@context"];
1365
1365
  }
1366
1366
  this._subscription = msg;
1367
1367
  if (this._pendingSubscription) return;
@@ -1429,6 +1429,10 @@ var WebSocketManager = class {
1429
1429
  return;
1430
1430
  }
1431
1431
  if (msg.type === "pong") return;
1432
+ if (msg.type === "subscribed") {
1433
+ this._emit("subscribed", void 0);
1434
+ return;
1435
+ }
1432
1436
  if (msg.type === "dpop_verified") {
1433
1437
  this._pendingSubscription = false;
1434
1438
  if (this._subscription) {
@@ -1895,7 +1899,9 @@ var GeonicDB = class extends EventEmitter {
1895
1899
  limit: 0,
1896
1900
  type: params?.type,
1897
1901
  q: params?.q,
1898
- scopeQ: params?.scopeQ
1902
+ scopeQ: params?.scopeQ,
1903
+ // #2278: clause 5.7.2.4 の "too wide query" 免除条件 (e) local scope。
1904
+ local: params?.local
1899
1905
  });
1900
1906
  const res = await this._auth.request("GET", path);
1901
1907
  if (!res.ok) {
@@ -1931,7 +1937,13 @@ var GeonicDB = class extends EventEmitter {
1931
1937
  return { deleted: true };
1932
1938
  }
1933
1939
  // --- Types / Attributes Discovery ---
1934
- /** List all entity types. */
1940
+ /**
1941
+ * List all entity types.
1942
+ *
1943
+ * `details` 未指定の `GET /types` は ETSI OpenAPI v1.8.1 準拠の
1944
+ * `EntityTypeList` オブジェクト(`{ id, type: 'EntityTypeList', typeList }`)を返す。
1945
+ * 型名の一覧は `typeList` から取得する。
1946
+ */
1935
1947
  async getTypes() {
1936
1948
  return this._jsonGet("/ngsi-ld/v1/types", "Types query failed");
1937
1949
  }
@@ -1942,7 +1954,13 @@ var GeonicDB = class extends EventEmitter {
1942
1954
  "Type not found"
1943
1955
  );
1944
1956
  }
1945
- /** List all attributes. */
1957
+ /**
1958
+ * List all attributes.
1959
+ *
1960
+ * `details` 未指定の `GET /attributes` は ETSI OpenAPI v1.8.1 準拠の
1961
+ * `AttributeList` オブジェクト(`{ id, type: 'AttributeList', attributeList }`)を返す。
1962
+ * 属性名の一覧は `attributeList` から取得する。
1963
+ */
1946
1964
  async getAttributes() {
1947
1965
  return this._jsonGet("/ngsi-ld/v1/attributes", "Attributes query failed");
1948
1966
  }
@@ -1980,7 +1998,21 @@ var GeonicDB = class extends EventEmitter {
1980
1998
  "Batch create failed"
1981
1999
  );
1982
2000
  }
1983
- /** Upsert multiple entities in a single request. */
2001
+ /**
2002
+ * Upsert multiple entities in a single request.
2003
+ *
2004
+ * #1742: the server follows ETSI GS CIM 009 clause 5.6.8.5 / Table 6.15.3.1-1:
2005
+ * - **201** with a `string[]` of the **created** entity IDs, when at least one entity
2006
+ * was newly created and none failed (merely updated entities are not listed);
2007
+ * - **204** with no body, when every entity already existed and was updated
2008
+ * (`_jsonPost` maps this to `{}`);
2009
+ * - **207** with a `BatchOperationResult` (`{ created, updated, errors }`), on partial
2010
+ * or total failure.
2011
+ *
2012
+ * The return type reflects all three shapes. Narrow with `Array.isArray(result)` to
2013
+ * detect the "something was created" case.
2014
+ * https://cim.etsi.org/NGSI-LD/official/clause-6.html
2015
+ */
1984
2016
  async batchUpsert(entities) {
1985
2017
  return this._jsonPost(
1986
2018
  "/ngsi-ld/v1/entityOperations/upsert",