@web-ts-toolkit/access-router 0.29.0 → 0.31.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/index.mjs CHANGED
@@ -116,7 +116,8 @@ function setDocValue(doc, path, value) {
116
116
  }
117
117
  function getDocPermissions(modelName, doc) {
118
118
  const docPermissionField = getModelOption(modelName, "documentPermissionField");
119
- return getDocValue(doc, docPermissionField, {});
119
+ const permissions = getDocValue(doc, docPermissionField, {});
120
+ return isPlainObject2(permissions) ? permissions : {};
120
121
  }
121
122
  function toObject(doc) {
122
123
  return isDocument(doc) ? doc.toObject() : doc;
@@ -874,7 +875,8 @@ var AccessRuntime = class {
874
875
  }
875
876
  getModelRef(modelName, refPath) {
876
877
  this.ensureModelMeta(modelName);
877
- return get3(this.modelRefs, `${modelName}.${refPath}`, null);
878
+ const value = get3(this.modelRefs, `${modelName}.${refPath}`, null);
879
+ return isString4(value) ? value : null;
878
880
  }
879
881
  getModelSub(modelName) {
880
882
  this.ensureModelMeta(modelName);
@@ -1236,12 +1238,14 @@ var Base = class {
1236
1238
  // src/services/service.ts
1237
1239
  import {
1238
1240
  castArray as castArray2,
1241
+ compact as compact2,
1239
1242
  isArray as isArray6,
1240
1243
  isBoolean as isBoolean3,
1241
1244
  isFunction as isFunction3,
1242
1245
  omit,
1243
1246
  pick as pick4,
1244
- uniq as uniq2
1247
+ uniq as uniq2,
1248
+ uniqBy
1245
1249
  } from "@web-ts-toolkit/utils";
1246
1250
  import { diff } from "just-diff";
1247
1251
 
@@ -2065,7 +2069,7 @@ var Service = class extends Base {
2065
2069
  return resolveExistsOptions(this, options);
2066
2070
  }
2067
2071
  async getFieldPermissionAccess(ids) {
2068
- const uniqueIds = uniq2(ids.map((id) => String(id)).filter(Boolean));
2072
+ const uniqueIds = compact2(uniqBy(ids, (id) => String(id)).map((id) => String(id)));
2069
2073
  if (uniqueIds.length === 0) {
2070
2074
  return {
2071
2075
  readIds: /* @__PURE__ */ new Set(),
@@ -2546,6 +2550,7 @@ var Cache = class {
2546
2550
  import {
2547
2551
  castArray as castArray4,
2548
2552
  arrayToRecord,
2553
+ hasOwn as hasOwn2,
2549
2554
  isArray as isArray8,
2550
2555
  isBoolean as isBoolean4,
2551
2556
  isEmpty as isEmpty2,
@@ -2556,6 +2561,7 @@ import {
2556
2561
  } from "@web-ts-toolkit/utils";
2557
2562
 
2558
2563
  // src/permission.ts
2564
+ import { hasOwn } from "@web-ts-toolkit/utils";
2559
2565
  var Permission = class {
2560
2566
  constructor(permissions) {
2561
2567
  this.permissions = { ...permissions };
@@ -2571,7 +2577,7 @@ var Permission = class {
2571
2577
  return [permissionOrPermissions].concat(permissions);
2572
2578
  }
2573
2579
  hasKey(permission) {
2574
- return Object.prototype.hasOwnProperty.call(this.permissions, permission);
2580
+ return hasOwn(this.permissions, permission);
2575
2581
  }
2576
2582
  has(permission) {
2577
2583
  return this.permissions[permission] === true;
@@ -2621,7 +2627,7 @@ function optimizeAndFilter(clausesInput) {
2621
2627
  }
2622
2628
  let canMerge = true;
2623
2629
  for (const [key, value] of Object.entries(clause)) {
2624
- if (Object.prototype.hasOwnProperty.call(mergedClause, key) && !isEqual(mergedClause[key], value)) {
2630
+ if (hasOwn2(mergedClause, key) && !isEqual(mergedClause[key], value)) {
2625
2631
  canMerge = false;
2626
2632
  break;
2627
2633
  }
@@ -2966,7 +2972,7 @@ var Core = class {
2966
2972
  permissionSchema,
2967
2973
  access,
2968
2974
  baseFields,
2969
- hasPermission: (key) => permissions.has(key) || docPermissions[this.removePrefix(key, modelPermissionPrefix)],
2975
+ hasPermission: (key) => permissions.has(key) || Boolean(docPermissions[this.removePrefix(key, modelPermissionPrefix)]),
2970
2976
  functionArgs: [permissions, docPermissions]
2971
2977
  });
2972
2978
  }
@@ -2981,7 +2987,7 @@ var Core = class {
2981
2987
  permissionSchema,
2982
2988
  access,
2983
2989
  baseFields,
2984
- hasPermission: (key) => permissions.has(key) || docPermissions[this.removePrefix(key, modelPermissionPrefix)],
2990
+ hasPermission: (key) => permissions.has(key) || Boolean(docPermissions[this.removePrefix(key, modelPermissionPrefix)]),
2985
2991
  functionArgs: [permissions, docPermissions]
2986
2992
  });
2987
2993
  }
@@ -3271,7 +3277,7 @@ function guard(condition) {
3271
3277
  return next(new JsonRouter2.clientErrors.UnauthorizedError());
3272
3278
  }
3273
3279
  const docPermissions = getDocPermissions(modelName, result.data);
3274
- phas = (key) => permissions.has(key) || docPermissions[key];
3280
+ phas = (key) => permissions.has(key) || Boolean(docPermissions[key]);
3275
3281
  cond = _cond;
3276
3282
  }
3277
3283
  const { stringHandler, arrayHandler } = createValidator(phas);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@web-ts-toolkit/access-router",
3
3
  "description": "ACL-aware Express routers and in-memory data services for Mongoose-backed APIs",
4
4
  "homepage": "https://web-ts-toolkit.pages.dev/docs/packages/access-router",
5
- "version": "0.29.0",
5
+ "version": "0.31.0",
6
6
  "sideEffects": false,
7
7
  "keywords": [
8
8
  "express",
@@ -40,8 +40,8 @@
40
40
  "node": ">=20"
41
41
  },
42
42
  "dependencies": {
43
- "@web-ts-toolkit/express-json-router": "0.29.0",
44
- "@web-ts-toolkit/utils": "0.29.0",
43
+ "@web-ts-toolkit/express-json-router": "0.31.0",
44
+ "@web-ts-toolkit/utils": "0.31.0",
45
45
  "just-diff": "^6.0.2",
46
46
  "mongoose-schema-jsonschema": "^4.0.1",
47
47
  "sift": "^17.1.3",