@geolonia/geonicdb-sdk 0.16.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
@@ -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) {
@@ -1992,7 +1998,21 @@ var GeonicDB = class extends EventEmitter {
1992
1998
  "Batch create failed"
1993
1999
  );
1994
2000
  }
1995
- /** 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
+ */
1996
2016
  async batchUpsert(entities) {
1997
2017
  return this._jsonPost(
1998
2018
  "/ngsi-ld/v1/entityOperations/upsert",