@stndrds/schema 1.0.0-alpha.72 → 1.0.0-alpha.73

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.
@@ -15,6 +15,9 @@ var _chunkNEVERCM3js = require('./chunk-NEVERCM3.js');
15
15
  var _chunk3WTK7ESHjs = require('./chunk-3WTK7ESH.js');
16
16
 
17
17
 
18
+ var _chunkJZO52C3Fjs = require('./chunk-JZO52C3F.js');
19
+
20
+
18
21
  var _chunk3RG5ZIWIjs = require('./chunk-3RG5ZIWI.js');
19
22
 
20
23
  // src/runtime/auth/workflow-jwt.service.ts
@@ -3700,13 +3703,24 @@ function parsePipeExpression(pipeExpr) {
3700
3703
  }
3701
3704
  function renderLabelExpression(template, values, fallback = DEFAULT_LABEL_FALLBACK) {
3702
3705
  const result = template.replace(/\{\{\s*([^}]+)\s*\}\}/g, (_, expr) => {
3703
- const parts = expr.split("|").map((s) => s.trim());
3704
- const path = parts[0];
3705
- let value = getValue(values, path);
3706
+ const orParts = expr.split("||").map((s) => s.trim());
3707
+ const lastPart = orParts[orParts.length - 1];
3708
+ const pipeSplit = lastPart.split("|").map((s) => s.trim());
3709
+ orParts[orParts.length - 1] = pipeSplit[0];
3710
+ const pipes = pipeSplit.slice(1).filter(Boolean);
3711
+ const alternatives = orParts.filter(Boolean);
3712
+ let value = "";
3713
+ for (const alt of alternatives) {
3714
+ const v = getValue(values, alt);
3715
+ if (v != null && v !== "") {
3716
+ value = v;
3717
+ break;
3718
+ }
3719
+ }
3706
3720
  const isEmpty3 = value == null || value === "";
3707
- if (isEmpty3 && parts.length === 1) return "";
3708
- for (let i = 1; i < parts.length; i++) {
3709
- const { name: pipeName, args } = parsePipeExpression(parts[i]);
3721
+ if (isEmpty3 && pipes.length === 0) return "";
3722
+ for (const pipeExpr of pipes) {
3723
+ const { name: pipeName, args } = parsePipeExpression(pipeExpr);
3710
3724
  const simpleFn = simplePipes[pipeName];
3711
3725
  if (simpleFn) {
3712
3726
  if (value != null && value !== "") {
@@ -3728,13 +3742,19 @@ function isLabelExpression(value) {
3728
3742
  }
3729
3743
  function extractAttributeNames(template) {
3730
3744
  const names = [];
3731
- const regex = /\{\{\s*([^|}]+)/g;
3745
+ const regex = /\{\{\s*([^}]+)\s*\}\}/g;
3732
3746
  let match;
3733
3747
  while ((match = regex.exec(template)) !== null) {
3734
- const path = match[1].trim();
3735
- const rootName = path.split(".")[0];
3736
- if (rootName && !names.includes(rootName)) {
3737
- names.push(rootName);
3748
+ const expr = match[1].trim();
3749
+ const orParts = expr.split("||").map((s) => s.trim());
3750
+ const lastPart = orParts[orParts.length - 1];
3751
+ orParts[orParts.length - 1] = lastPart.split("|")[0].trim();
3752
+ for (const part of orParts) {
3753
+ if (!part) continue;
3754
+ const rootName = part.split(".")[0];
3755
+ if (rootName && !names.includes(rootName)) {
3756
+ names.push(rootName);
3757
+ }
3738
3758
  }
3739
3759
  }
3740
3760
  return names;
@@ -4303,7 +4323,6 @@ function createMockUserProfilesRepository(stores) {
4303
4323
  firstName: data.firstName,
4304
4324
  lastName: data.lastName,
4305
4325
  avatarUrl: data.avatarUrl,
4306
- role: _nullishCoalesce(data.role, () => ( "member")),
4307
4326
  status: _nullishCoalesce(data.status, () => ( "active")),
4308
4327
  createdAt: /* @__PURE__ */ new Date(),
4309
4328
  updatedAt: /* @__PURE__ */ new Date()
@@ -4336,12 +4355,23 @@ function createMockUserProfilesRepository(stores) {
4336
4355
  }
4337
4356
  return Promise.resolve(results);
4338
4357
  },
4339
- countByRole(role) {
4358
+ getUsersWithRoles(filters) {
4340
4359
  const tenantId = getTenantId();
4341
- const count = Array.from(stores.userProfiles.values()).filter(
4342
- (profile) => profile.tenantId === tenantId && profile.role === role
4343
- ).length;
4344
- return Promise.resolve(count);
4360
+ const profiles = Array.from(stores.userProfiles.values()).filter(
4361
+ (p) => p.tenantId === tenantId
4362
+ );
4363
+ const results = [];
4364
+ for (const profile of profiles) {
4365
+ const roleIds = Array.from(stores.userRoles.values()).filter((ur) => ur.userProfileId === profile.id && ur.tenantId === tenantId).map((ur) => ur.roleId);
4366
+ const roles = Array.from(stores.roles.values()).filter((r) => roleIds.includes(r.id));
4367
+ if (_optionalChain([filters, 'optionalAccess', _87 => _87.allowedRoles]) && filters.allowedRoles.length > 0) {
4368
+ const allowed = filters.allowedRoles;
4369
+ const hasMatchingRole = roles.some((r) => allowed.includes(r.name));
4370
+ if (!hasMatchingRole) continue;
4371
+ }
4372
+ results.push({ ...profile, roles });
4373
+ }
4374
+ return Promise.resolve(results);
4345
4375
  },
4346
4376
  updateLastLogin(id) {
4347
4377
  const profile = stores.userProfiles.get(id);
@@ -4360,7 +4390,6 @@ function createMockUserProfilesRepository(stores) {
4360
4390
  email: data.email,
4361
4391
  firstName: data.firstName,
4362
4392
  lastName: data.lastName,
4363
- role: _nullishCoalesce(data.role, () => ( "member")),
4364
4393
  status: "pending",
4365
4394
  createdAt: /* @__PURE__ */ new Date(),
4366
4395
  updatedAt: /* @__PURE__ */ new Date()
@@ -4419,7 +4448,7 @@ function createMockPermissionsRepository(stores) {
4419
4448
  },
4420
4449
  deleteRole(roleId) {
4421
4450
  const role = stores.roles.get(roleId);
4422
- if (_optionalChain([role, 'optionalAccess', _87 => _87.system])) {
4451
+ if (_optionalChain([role, 'optionalAccess', _88 => _88.system])) {
4423
4452
  return Promise.reject(new Error(`Cannot delete system role ${roleId}`));
4424
4453
  }
4425
4454
  stores.roles.delete(roleId);
@@ -4452,7 +4481,6 @@ function createMockPermissionsRepository(stores) {
4452
4481
  scope: input.scope,
4453
4482
  target: input.target,
4454
4483
  actions: input.actions,
4455
- filter: input.filter,
4456
4484
  createdAt: /* @__PURE__ */ new Date()
4457
4485
  };
4458
4486
  stores.permissions.set(perm.id, perm);
@@ -4497,7 +4525,7 @@ function createMockPermissionsRepository(stores) {
4497
4525
  const tenantId = getTenantId();
4498
4526
  const userRoleIds = Array.from(stores.userRoles.values()).filter((ur) => ur.userProfileId === userProfileId && ur.tenantId === tenantId).map((ur) => ur.roleId);
4499
4527
  const userRoles = Array.from(stores.roles.values()).filter((r) => userRoleIds.includes(r.id));
4500
- const isAdmin = userRoles.some((r) => r.name === "admin");
4528
+ const hasAdmin = userRoles.some((r) => _chunkJZO52C3Fjs.isAdminRole.call(void 0, r.name));
4501
4529
  const userPermissions = Array.from(stores.permissions.values()).filter(
4502
4530
  (p) => userRoleIds.includes(p.roleId)
4503
4531
  );
@@ -4524,7 +4552,18 @@ function createMockPermissionsRepository(stores) {
4524
4552
  }
4525
4553
  }
4526
4554
  }
4527
- return Promise.resolve({ isAdmin, objectPermissions, systemPermissions });
4555
+ return Promise.resolve({ isAdmin: hasAdmin, objectPermissions, systemPermissions });
4556
+ },
4557
+ countUsersWithRole(roleName) {
4558
+ const tenantId = getTenantId();
4559
+ const role = Array.from(stores.roles.values()).find(
4560
+ (r) => r.tenantId === tenantId && r.name === roleName
4561
+ );
4562
+ if (!role) return Promise.resolve(0);
4563
+ const userIds = new Set(
4564
+ Array.from(stores.userRoles.values()).filter((ur) => ur.roleId === role.id && ur.tenantId === tenantId).map((ur) => ur.userProfileId)
4565
+ );
4566
+ return Promise.resolve(userIds.size);
4528
4567
  }
4529
4568
  };
4530
4569
  }
@@ -4908,7 +4947,7 @@ function createMockWorkflowInstancesRepository(stores) {
4908
4947
  (i) => i.tenant_id === tenantId
4909
4948
  );
4910
4949
  const total = results.length;
4911
- if (_optionalChain([options, 'optionalAccess', _88 => _88.limit])) {
4950
+ if (_optionalChain([options, 'optionalAccess', _89 => _89.limit])) {
4912
4951
  results = results.slice(_nullishCoalesce(options.offset, () => ( 0)), (_nullishCoalesce(options.offset, () => ( 0))) + options.limit);
4913
4952
  }
4914
4953
  return Promise.resolve({ instances: results, total });
@@ -4936,7 +4975,7 @@ function createMockWorkflowInstancesRepository(stores) {
4936
4975
  pending_action: _nullishCoalesce(data.pendingAction, () => ( null)),
4937
4976
  error: null,
4938
4977
  started_by: data.startedBy,
4939
- expires_at: _nullishCoalesce(_optionalChain([data, 'access', _89 => _89.expiresAt, 'optionalAccess', _90 => _90.toISOString, 'call', _91 => _91()]), () => ( null)),
4978
+ expires_at: _nullishCoalesce(_optionalChain([data, 'access', _90 => _90.expiresAt, 'optionalAccess', _91 => _91.toISOString, 'call', _92 => _92()]), () => ( null)),
4940
4979
  created_at: now,
4941
4980
  updated_at: now,
4942
4981
  completed_at: null
@@ -4957,8 +4996,8 @@ function createMockWorkflowInstancesRepository(stores) {
4957
4996
  history: _nullishCoalesce(data.history, () => ( existing.history)),
4958
4997
  pending_action: data.pendingAction !== void 0 ? data.pendingAction : existing.pending_action,
4959
4998
  error: data.error !== void 0 ? data.error : existing.error,
4960
- expires_at: data.expiresAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _92 => _92.expiresAt, 'optionalAccess', _93 => _93.toISOString, 'call', _94 => _94()]), () => ( null)) : existing.expires_at,
4961
- completed_at: data.completedAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _95 => _95.completedAt, 'optionalAccess', _96 => _96.toISOString, 'call', _97 => _97()]), () => ( null)) : existing.completed_at,
4999
+ expires_at: data.expiresAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _93 => _93.expiresAt, 'optionalAccess', _94 => _94.toISOString, 'call', _95 => _95()]), () => ( null)) : existing.expires_at,
5000
+ completed_at: data.completedAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _96 => _96.completedAt, 'optionalAccess', _97 => _97.toISOString, 'call', _98 => _98()]), () => ( null)) : existing.completed_at,
4962
5001
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
4963
5002
  };
4964
5003
  stores.workflowInstances.set(id, updated);
@@ -4991,7 +5030,7 @@ function createMockWorkflowInstancesRepository(stores) {
4991
5030
  pending_action: _nullishCoalesce(data.pendingAction, () => ( null)),
4992
5031
  error: null,
4993
5032
  started_by: data.startedBy,
4994
- expires_at: _nullishCoalesce(_optionalChain([data, 'access', _98 => _98.expiresAt, 'optionalAccess', _99 => _99.toISOString, 'call', _100 => _100()]), () => ( null)),
5033
+ expires_at: _nullishCoalesce(_optionalChain([data, 'access', _99 => _99.expiresAt, 'optionalAccess', _100 => _100.toISOString, 'call', _101 => _101()]), () => ( null)),
4995
5034
  created_at: now,
4996
5035
  updated_at: now,
4997
5036
  completed_at: null
@@ -5014,13 +5053,13 @@ function createMockWorkflowInstancesRepository(stores) {
5014
5053
  return slotData.id === recordId;
5015
5054
  });
5016
5055
  });
5017
- if (_optionalChain([options, 'optionalAccess', _101 => _101.status])) {
5056
+ if (_optionalChain([options, 'optionalAccess', _102 => _102.status])) {
5018
5057
  results = results.filter((i) => i.status === options.status);
5019
5058
  }
5020
5059
  const total = results.length;
5021
- if (_optionalChain([options, 'optionalAccess', _102 => _102.offset]) !== void 0 || _optionalChain([options, 'optionalAccess', _103 => _103.limit]) !== void 0) {
5022
- const start = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _104 => _104.offset]), () => ( 0));
5023
- const end = _optionalChain([options, 'optionalAccess', _105 => _105.limit]) ? start + options.limit : void 0;
5060
+ if (_optionalChain([options, 'optionalAccess', _103 => _103.offset]) !== void 0 || _optionalChain([options, 'optionalAccess', _104 => _104.limit]) !== void 0) {
5061
+ const start = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _105 => _105.offset]), () => ( 0));
5062
+ const end = _optionalChain([options, 'optionalAccess', _106 => _106.limit]) ? start + options.limit : void 0;
5024
5063
  results = results.slice(start, end);
5025
5064
  }
5026
5065
  return Promise.resolve({ instances: results, total });
@@ -5076,7 +5115,7 @@ function createMockWorkflowInvitationsRepository(stores) {
5076
5115
  const updated = {
5077
5116
  ...existing,
5078
5117
  status: _nullishCoalesce(data.status, () => ( existing.status)),
5079
- accepted_at: data.acceptedAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _106 => _106.acceptedAt, 'optionalAccess', _107 => _107.toISOString, 'call', _108 => _108()]), () => ( null)) : existing.accepted_at,
5118
+ accepted_at: data.acceptedAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _107 => _107.acceptedAt, 'optionalAccess', _108 => _108.toISOString, 'call', _109 => _109()]), () => ( null)) : existing.accepted_at,
5080
5119
  expires_at: data.expiresAt !== void 0 ? data.expiresAt.toISOString() : existing.expires_at
5081
5120
  };
5082
5121
  stores.workflowInvitations.set(id, updated);
@@ -5142,7 +5181,7 @@ function createMockWorkflowAccessGrantsRepository(stores) {
5142
5181
  ...existing,
5143
5182
  last_used_at: data.lastUsedAt !== void 0 ? data.lastUsedAt.toISOString() : existing.last_used_at,
5144
5183
  revoked_token_jtis: _nullishCoalesce(data.revokedTokenJtis, () => ( existing.revoked_token_jtis)),
5145
- revoked_at: data.revokedAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _109 => _109.revokedAt, 'optionalAccess', _110 => _110.toISOString, 'call', _111 => _111()]), () => ( null)) : existing.revoked_at
5184
+ revoked_at: data.revokedAt !== void 0 ? _nullishCoalesce(_optionalChain([data, 'access', _110 => _110.revokedAt, 'optionalAccess', _111 => _111.toISOString, 'call', _112 => _112()]), () => ( null)) : existing.revoked_at
5146
5185
  };
5147
5186
  stores.workflowAccessGrants.set(id, updated);
5148
5187
  return Promise.resolve(updated);
@@ -5351,7 +5390,7 @@ var BaseService = class {
5351
5390
  * @param key - Cache key to invalidate
5352
5391
  */
5353
5392
  async invalidateCache(key) {
5354
- await _optionalChain([this, 'access', _112 => _112.cache, 'optionalAccess', _113 => _113.delete, 'call', _114 => _114(key)]);
5393
+ await _optionalChain([this, 'access', _113 => _113.cache, 'optionalAccess', _114 => _114.delete, 'call', _115 => _115(key)]);
5355
5394
  }
5356
5395
  /**
5357
5396
  * Invalidate all cache keys matching a pattern.
@@ -5359,7 +5398,7 @@ var BaseService = class {
5359
5398
  * @param pattern - Glob-style pattern (e.g., "schema:tenant-123:*")
5360
5399
  */
5361
5400
  async invalidateCachePattern(pattern) {
5362
- await _optionalChain([this, 'access', _115 => _115.cache, 'optionalAccess', _116 => _116.deletePattern, 'call', _117 => _117(pattern)]);
5401
+ await _optionalChain([this, 'access', _116 => _116.cache, 'optionalAccess', _117 => _117.deletePattern, 'call', _118 => _118(pattern)]);
5363
5402
  }
5364
5403
  /**
5365
5404
  * Invalidate all cached lists for a resource.
@@ -5574,17 +5613,17 @@ function validateOptions(options, attributeName) {
5574
5613
  const ids = /* @__PURE__ */ new Set();
5575
5614
  const values = /* @__PURE__ */ new Set();
5576
5615
  for (const option of options) {
5577
- if (!_optionalChain([option, 'access', _118 => _118.id, 'optionalAccess', _119 => _119.trim, 'call', _120 => _120()])) {
5616
+ if (!_optionalChain([option, 'access', _119 => _119.id, 'optionalAccess', _120 => _120.trim, 'call', _121 => _121()])) {
5578
5617
  throw new Error(
5579
5618
  `[AttributeBuilder] Option in "${attributeName}" has an empty or missing id.`
5580
5619
  );
5581
5620
  }
5582
- if (!_optionalChain([option, 'access', _121 => _121.value, 'optionalAccess', _122 => _122.trim, 'call', _123 => _123()])) {
5621
+ if (!_optionalChain([option, 'access', _122 => _122.value, 'optionalAccess', _123 => _123.trim, 'call', _124 => _124()])) {
5583
5622
  throw new Error(
5584
5623
  `[AttributeBuilder] Option "${option.id}" in "${attributeName}" has an empty or missing value.`
5585
5624
  );
5586
5625
  }
5587
- if (!_optionalChain([option, 'access', _124 => _124.label, 'optionalAccess', _125 => _125.trim, 'call', _126 => _126()])) {
5626
+ if (!_optionalChain([option, 'access', _125 => _125.label, 'optionalAccess', _126 => _126.trim, 'call', _127 => _127()])) {
5588
5627
  throw new Error(
5589
5628
  `[AttributeBuilder] Option "${option.id}" in "${attributeName}" has an empty or missing label.`
5590
5629
  );
@@ -5682,8 +5721,8 @@ var BaseAttributeBuilder = class {
5682
5721
  featureGate(flagName, options) {
5683
5722
  this.attr.featureGate = {
5684
5723
  flag: flagName,
5685
- expectedValue: _optionalChain([options, 'optionalAccess', _127 => _127.expectedValue]),
5686
- fallback: _optionalChain([options, 'optionalAccess', _128 => _128.fallback])
5724
+ expectedValue: _optionalChain([options, 'optionalAccess', _128 => _128.expectedValue]),
5725
+ fallback: _optionalChain([options, 'optionalAccess', _129 => _129.fallback])
5687
5726
  };
5688
5727
  return this;
5689
5728
  }
@@ -6126,7 +6165,7 @@ var BaseRelationAttributeBuilder = class extends BaseAttributeBuilder {
6126
6165
  object: objectName,
6127
6166
  ...options
6128
6167
  };
6129
- _optionalChain([this, 'access', _129 => _129.attr, 'access', _130 => _130.targets, 'optionalAccess', _131 => _131.push, 'call', _132 => _132(target)]);
6168
+ _optionalChain([this, 'access', _130 => _130.attr, 'access', _131 => _131.targets, 'optionalAccess', _132 => _132.push, 'call', _133 => _133(target)]);
6130
6169
  return this;
6131
6170
  }
6132
6171
  /**
@@ -6224,9 +6263,9 @@ var MultiRelationAttributeBuilder = class extends BaseRelationAttributeBuilder {
6224
6263
  constructor(name, label, initOptions) {
6225
6264
  super("relation", name, label);
6226
6265
  this.attr.cardinality = "many";
6227
- this.attr.targets = _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess', _133 => _133.targets]), () => ( []));
6266
+ this.attr.targets = _nullishCoalesce(_optionalChain([initOptions, 'optionalAccess', _134 => _134.targets]), () => ( []));
6228
6267
  this.attr.defaultValue = [];
6229
- if (_optionalChain([initOptions, 'optionalAccess', _134 => _134.isRequired])) {
6268
+ if (_optionalChain([initOptions, 'optionalAccess', _135 => _135.isRequired])) {
6230
6269
  this.setRequired(true);
6231
6270
  }
6232
6271
  }
@@ -6667,7 +6706,7 @@ var GroupBuilder = class {
6667
6706
  */
6668
6707
  fields(...names) {
6669
6708
  for (const name of names) {
6670
- _optionalChain([this, 'access', _135 => _135.data, 'access', _136 => _136.fields, 'optionalAccess', _137 => _137.push, 'call', _138 => _138({ attribute: name })]);
6709
+ _optionalChain([this, 'access', _136 => _136.data, 'access', _137 => _137.fields, 'optionalAccess', _138 => _138.push, 'call', _139 => _139({ attribute: name })]);
6671
6710
  }
6672
6711
  return this;
6673
6712
  }
@@ -6676,7 +6715,7 @@ var GroupBuilder = class {
6676
6715
  * @example .field("name", { span: 8, readOnly: true })
6677
6716
  */
6678
6717
  field(attribute, options) {
6679
- _optionalChain([this, 'access', _139 => _139.data, 'access', _140 => _140.fields, 'optionalAccess', _141 => _141.push, 'call', _142 => _142({ attribute, ...options })]);
6718
+ _optionalChain([this, 'access', _140 => _140.data, 'access', _141 => _141.fields, 'optionalAccess', _142 => _142.push, 'call', _143 => _143({ attribute, ...options })]);
6680
6719
  return this;
6681
6720
  }
6682
6721
  /**
@@ -6685,7 +6724,7 @@ var GroupBuilder = class {
6685
6724
  * @example .attributeGroup({ id: "address", label: "Address", attributes: ["street", "city", "postal_code"], displayTemplate: "{street}, {city}" })
6686
6725
  */
6687
6726
  attributeGroup(config, options) {
6688
- _optionalChain([this, 'access', _143 => _143.data, 'access', _144 => _144.fields, 'optionalAccess', _145 => _145.push, 'call', _146 => _146({ attributeGroup: config, ...options })]);
6727
+ _optionalChain([this, 'access', _144 => _144.data, 'access', _145 => _145.fields, 'optionalAccess', _146 => _146.push, 'call', _147 => _147({ attributeGroup: config, ...options })]);
6689
6728
  return this;
6690
6729
  }
6691
6730
  /**
@@ -7753,8 +7792,8 @@ var WorkflowFormRowBuilder = class {
7753
7792
  id: `${this.rowData.id}-${slotId}-${attribute}`,
7754
7793
  slotId,
7755
7794
  attribute,
7756
- label: _optionalChain([options, 'optionalAccess', _147 => _147.label]),
7757
- required: _optionalChain([options, 'optionalAccess', _148 => _148.required])
7795
+ label: _optionalChain([options, 'optionalAccess', _148 => _148.label]),
7796
+ required: _optionalChain([options, 'optionalAccess', _149 => _149.required])
7758
7797
  };
7759
7798
  this.rowData.fields.push(field);
7760
7799
  return this;
@@ -8045,7 +8084,7 @@ var WorkflowBuilder = class {
8045
8084
  * @param options - Slot configuration
8046
8085
  */
8047
8086
  slot(id, objectName, options) {
8048
- if (_optionalChain([this, 'access', _149 => _149.data, 'access', _150 => _150.slots, 'optionalAccess', _151 => _151.some, 'call', _152 => _152((s) => s.id === id)])) {
8087
+ if (_optionalChain([this, 'access', _150 => _150.data, 'access', _151 => _151.slots, 'optionalAccess', _152 => _152.some, 'call', _153 => _153((s) => s.id === id)])) {
8049
8088
  throw new Error(`[WorkflowBuilder] Duplicate slot id: "${id}"`);
8050
8089
  }
8051
8090
  const slot = {
@@ -8056,7 +8095,7 @@ var WorkflowBuilder = class {
8056
8095
  color: options.color,
8057
8096
  icon: options.icon
8058
8097
  };
8059
- _optionalChain([this, 'access', _153 => _153.data, 'access', _154 => _154.slots, 'optionalAccess', _155 => _155.push, 'call', _156 => _156(slot)]);
8098
+ _optionalChain([this, 'access', _154 => _154.data, 'access', _155 => _155.slots, 'optionalAccess', _156 => _156.push, 'call', _157 => _157(slot)]);
8060
8099
  return this;
8061
8100
  }
8062
8101
  // ============================================================================
@@ -8188,7 +8227,7 @@ var WorkflowBuilder = class {
8188
8227
  }
8189
8228
  }
8190
8229
  validateSlotReferences() {
8191
- const slotIds = _nullishCoalesce(_optionalChain([this, 'access', _157 => _157.data, 'access', _158 => _158.slots, 'optionalAccess', _159 => _159.reduce, 'call', _160 => _160((set, s) => set.add(s.id), /* @__PURE__ */ new Set())]), () => ( /* @__PURE__ */ new Set()));
8230
+ const slotIds = _nullishCoalesce(_optionalChain([this, 'access', _158 => _158.data, 'access', _159 => _159.slots, 'optionalAccess', _160 => _160.reduce, 'call', _161 => _161((set, s) => set.add(s.id), /* @__PURE__ */ new Set())]), () => ( /* @__PURE__ */ new Set()));
8192
8231
  for (const node of Object.values(_nullishCoalesce(this.data.nodes, () => ( {})))) {
8193
8232
  if (node.type === "form") {
8194
8233
  const referencedSlots = /* @__PURE__ */ new Set();
@@ -8506,7 +8545,7 @@ var ObjectSchemaService = class extends BaseService {
8506
8545
  constructor(adapter, nativeRegistry, options) {
8507
8546
  super(adapter);
8508
8547
  this.nativeRegistry = nativeRegistry;
8509
- this.auditService = _optionalChain([options, 'optionalAccess', _161 => _161.auditService]);
8548
+ this.auditService = _optionalChain([options, 'optionalAccess', _162 => _162.auditService]);
8510
8549
  this.bilateralValidationService = new BilateralValidationService(adapter, this);
8511
8550
  }
8512
8551
  /**
@@ -8749,7 +8788,7 @@ var ObjectSchemaService = class extends BaseService {
8749
8788
  resourceType: "attribute",
8750
8789
  resourceId: attributeId,
8751
8790
  resourceLabel: updatedDbAttr.label,
8752
- objectName: _optionalChain([dbObject, 'optionalAccess', _162 => _162.name]),
8791
+ objectName: _optionalChain([dbObject, 'optionalAccess', _163 => _163.name]),
8753
8792
  objectId: dbAttr.objectId,
8754
8793
  changes
8755
8794
  });
@@ -8782,7 +8821,7 @@ var ObjectSchemaService = class extends BaseService {
8782
8821
  );
8783
8822
  }
8784
8823
  const dbObject = await this.adapter.objects.findById(dbAttr.objectId);
8785
- if (_optionalChain([dbObject, 'optionalAccess', _163 => _163.labelExpression])) {
8824
+ if (_optionalChain([dbObject, 'optionalAccess', _164 => _164.labelExpression])) {
8786
8825
  const usedAttributes = extractAttributeNames(dbObject.labelExpression);
8787
8826
  if (usedAttributes.includes(dbAttr.name)) {
8788
8827
  throw new AttributeInUseError(dbAttr.name, "labelExpression");
@@ -8798,7 +8837,7 @@ var ObjectSchemaService = class extends BaseService {
8798
8837
  resourceType: "attribute",
8799
8838
  resourceId: attributeId,
8800
8839
  resourceLabel: dbAttr.label,
8801
- objectName: _optionalChain([dbObject, 'optionalAccess', _164 => _164.name]),
8840
+ objectName: _optionalChain([dbObject, 'optionalAccess', _165 => _165.name]),
8802
8841
  objectId: dbAttr.objectId
8803
8842
  });
8804
8843
  }
@@ -8813,9 +8852,9 @@ var ObjectSchemaService = class extends BaseService {
8813
8852
  async listAttributes(objectId, options) {
8814
8853
  const dbAttributes = await this.adapter.attributes.findByObjectId(objectId);
8815
8854
  let filtered = dbAttributes;
8816
- if (_optionalChain([options, 'optionalAccess', _165 => _165.systemOnly])) {
8855
+ if (_optionalChain([options, 'optionalAccess', _166 => _166.systemOnly])) {
8817
8856
  filtered = dbAttributes.filter((attr) => attr.system);
8818
- } else if (_optionalChain([options, 'optionalAccess', _166 => _166.customOnly])) {
8857
+ } else if (_optionalChain([options, 'optionalAccess', _167 => _167.customOnly])) {
8819
8858
  filtered = dbAttributes.filter((attr) => !attr.system);
8820
8859
  }
8821
8860
  return filtered.map((attr) => this.convertDBAttributeToAttribute(attr));
@@ -8851,14 +8890,14 @@ var ObjectSchemaService = class extends BaseService {
8851
8890
  pluralLabel: dbObject.pluralLabel,
8852
8891
  description: dbObject.description,
8853
8892
  labelExpression: dbObject.labelExpression,
8854
- icon: _optionalChain([dbObject, 'access', _167 => _167.metadata, 'optionalAccess', _168 => _168.icon])
8893
+ icon: _optionalChain([dbObject, 'access', _168 => _168.metadata, 'optionalAccess', _169 => _169.icon])
8855
8894
  };
8856
8895
  let metadata = dbObject.metadata;
8857
8896
  if (updates.icon !== void 0 || updates.metadata !== void 0) {
8858
8897
  metadata = {
8859
8898
  ...dbObject.metadata,
8860
8899
  ...updates.metadata,
8861
- icon: _nullishCoalesce(updates.icon, () => ( _optionalChain([dbObject, 'access', _169 => _169.metadata, 'optionalAccess', _170 => _170.icon])))
8900
+ icon: _nullishCoalesce(updates.icon, () => ( _optionalChain([dbObject, 'access', _170 => _170.metadata, 'optionalAccess', _171 => _171.icon])))
8862
8901
  };
8863
8902
  }
8864
8903
  const updatedDbObject = await this.adapter.objects.update(objectId, {
@@ -9101,7 +9140,7 @@ Reserved names: ${RESERVED_ATTRIBUTE_NAMES.join(", ")}`
9101
9140
  let properties = inverseDbAttr.config.properties;
9102
9141
  if (!properties) {
9103
9142
  const nativeObj = this.nativeRegistry.getByName(bilateral.object);
9104
- const nativeAttr = _optionalChain([nativeObj, 'optionalAccess', _171 => _171.attributes, 'access', _172 => _172.find, 'call', _173 => _173((a) => a.name === bilateral.attribute)]);
9143
+ const nativeAttr = _optionalChain([nativeObj, 'optionalAccess', _172 => _172.attributes, 'access', _173 => _173.find, 'call', _174 => _174((a) => a.name === bilateral.attribute)]);
9105
9144
  if (nativeAttr && "properties" in nativeAttr) {
9106
9145
  properties = nativeAttr.properties;
9107
9146
  }
@@ -9190,7 +9229,7 @@ Reserved names: ${RESERVED_ATTRIBUTE_NAMES.join(", ")}`
9190
9229
  label: dbObject.label,
9191
9230
  pluralLabel: dbObject.pluralLabel,
9192
9231
  description: dbObject.description,
9193
- icon: _optionalChain([dbObject, 'access', _174 => _174.metadata, 'optionalAccess', _175 => _175.icon]),
9232
+ icon: _optionalChain([dbObject, 'access', _175 => _175.metadata, 'optionalAccess', _176 => _176.icon]),
9194
9233
  labelExpression: dbObject.labelExpression,
9195
9234
  attributes,
9196
9235
  system: dbObject.system,
@@ -9290,7 +9329,7 @@ Reserved names: ${RESERVED_ATTRIBUTE_NAMES.join(", ")}`
9290
9329
  const hasRelationToTarget = attrs.some((attr) => {
9291
9330
  if (attr.type !== "relation") return false;
9292
9331
  const config = attr.config;
9293
- return _nullishCoalesce(_optionalChain([config, 'optionalAccess', _176 => _176.targets, 'optionalAccess', _177 => _177.some, 'call', _178 => _178((t) => t.object === targetObjectName)]), () => ( false));
9332
+ return _nullishCoalesce(_optionalChain([config, 'optionalAccess', _177 => _177.targets, 'optionalAccess', _178 => _178.some, 'call', _179 => _179((t) => t.object === targetObjectName)]), () => ( false));
9294
9333
  });
9295
9334
  if (hasRelationToTarget) {
9296
9335
  referencing.push(obj.name);
@@ -9368,7 +9407,7 @@ Native objects must have system=true. Did you forget to call .system() in your b
9368
9407
  const existing = this.objects.get(object2.name);
9369
9408
  throw new Error(
9370
9409
  `[NativeObjectRegistry] Duplicate object name "${object2.name}":
9371
- - Existing: "${_optionalChain([existing, 'optionalAccess', _179 => _179.label])}" (id: ${_optionalChain([existing, 'optionalAccess', _180 => _180.id])})
9410
+ - Existing: "${_optionalChain([existing, 'optionalAccess', _180 => _180.label])}" (id: ${_optionalChain([existing, 'optionalAccess', _181 => _181.id])})
9372
9411
  - New: "${object2.label}" (id: ${object2.id})
9373
9412
  Please use unique names for each native object.`
9374
9413
  );
@@ -9485,7 +9524,7 @@ var AuditService = class extends BaseService {
9485
9524
  this.isFlushing = false;
9486
9525
  /** Pending flush promise to allow waiting on concurrent flush */
9487
9526
  this.flushPromise = null;
9488
- if (_optionalChain([options, 'optionalAccess', _181 => _181.async]) && options.flushIntervalMs) {
9527
+ if (_optionalChain([options, 'optionalAccess', _182 => _182.async]) && options.flushIntervalMs) {
9489
9528
  this.startFlushTimer();
9490
9529
  }
9491
9530
  }
@@ -9682,7 +9721,7 @@ var AuditService = class extends BaseService {
9682
9721
  if (!this.adapter.audit) {
9683
9722
  return;
9684
9723
  }
9685
- if (_optionalChain([this, 'access', _182 => _182.options, 'optionalAccess', _183 => _183.async])) {
9724
+ if (_optionalChain([this, 'access', _183 => _183.options, 'optionalAccess', _184 => _184.async])) {
9686
9725
  this.buffer.push(entry);
9687
9726
  const batchSize = _nullishCoalesce(this.options.batchSize, () => ( 10));
9688
9727
  if (this.buffer.length >= batchSize) {
@@ -9696,7 +9735,7 @@ var AuditService = class extends BaseService {
9696
9735
  * Start the flush timer for async mode
9697
9736
  */
9698
9737
  startFlushTimer() {
9699
- const intervalMs = _nullishCoalesce(_optionalChain([this, 'access', _184 => _184.options, 'optionalAccess', _185 => _185.flushIntervalMs]), () => ( 1e3));
9738
+ const intervalMs = _nullishCoalesce(_optionalChain([this, 'access', _185 => _185.options, 'optionalAccess', _186 => _186.flushIntervalMs]), () => ( 1e3));
9700
9739
  this.flushTimer = setInterval(() => {
9701
9740
  this.flush().catch(() => {
9702
9741
  });
@@ -9726,7 +9765,7 @@ var browserStub4 = {
9726
9765
  run: (_store, callback) => callback()
9727
9766
  };
9728
9767
  var AsyncLocalStorageClass4 = null;
9729
- if (typeof process !== "undefined" && _optionalChain([process, 'access', _186 => _186.versions, 'optionalAccess', _187 => _187.node])) {
9768
+ if (typeof process !== "undefined" && _optionalChain([process, 'access', _187 => _187.versions, 'optionalAccess', _188 => _188.node])) {
9730
9769
  try {
9731
9770
  if (typeof _chunk3RG5ZIWIjs.__require !== "undefined") {
9732
9771
  const asyncHooks = _chunk3RG5ZIWIjs.__require.call(void 0, "async_hooks");
@@ -9785,7 +9824,7 @@ var BilateralSyncService = class extends BaseService {
9785
9824
  }
9786
9825
  const ctx = getSyncContext().getStore();
9787
9826
  const syncKey = `${sourceSchema.name}:${sourceRecordId}:${attributeName}`;
9788
- if (_optionalChain([ctx, 'optionalAccess', _188 => _188.syncing, 'access', _189 => _189.has, 'call', _190 => _190(syncKey)])) {
9827
+ if (_optionalChain([ctx, 'optionalAccess', _189 => _189.syncing, 'access', _190 => _190.has, 'call', _191 => _191(syncKey)])) {
9789
9828
  return;
9790
9829
  }
9791
9830
  await this.runWithSyncContext(syncKey, async () => {
@@ -10010,7 +10049,7 @@ var BilateralSyncService = class extends BaseService {
10010
10049
  const storage = getSyncContext();
10011
10050
  const existingCtx = storage.getStore();
10012
10051
  const ctx = {
10013
- syncing: new Set(_nullishCoalesce(_optionalChain([existingCtx, 'optionalAccess', _191 => _191.syncing]), () => ( [])))
10052
+ syncing: new Set(_nullishCoalesce(_optionalChain([existingCtx, 'optionalAccess', _192 => _192.syncing]), () => ( [])))
10014
10053
  };
10015
10054
  ctx.syncing.add(syncKey);
10016
10055
  return await storage.run(ctx, fn);
@@ -10072,6 +10111,21 @@ var UserService = class extends BaseService {
10072
10111
  }
10073
10112
  const users = await this.adapter.userProfiles.findByIds([...allIds]);
10074
10113
  const userMap = new Map(users.map((u) => [u.id, u]));
10114
+ const allAllowedRoles = /* @__PURE__ */ new Set();
10115
+ for (const [, { attr }] of attrIdMap) {
10116
+ if (attr.allowedRoles && attr.allowedRoles.length > 0) {
10117
+ for (const role of attr.allowedRoles) {
10118
+ allAllowedRoles.add(role);
10119
+ }
10120
+ }
10121
+ }
10122
+ let userRolesMap;
10123
+ if (allAllowedRoles.size > 0) {
10124
+ const usersWithRoles = await this.adapter.userProfiles.getUsersWithRoles({
10125
+ allowedRoles: [...allAllowedRoles]
10126
+ });
10127
+ userRolesMap = new Map(usersWithRoles.map((u) => [u.id, u.roles.map((r) => r.name)]));
10128
+ }
10075
10129
  for (const [attrName, { attr, ids }] of attrIdMap) {
10076
10130
  const invalidIds = [];
10077
10131
  const roleErrors = [];
@@ -10085,8 +10139,10 @@ var UserService = class extends BaseService {
10085
10139
  invalidIds.push(id);
10086
10140
  continue;
10087
10141
  }
10088
- if (attr.allowedRoles && attr.allowedRoles.length > 0) {
10089
- if (!attr.allowedRoles.includes(user2.role)) {
10142
+ if (attr.allowedRoles && attr.allowedRoles.length > 0 && userRolesMap) {
10143
+ const userRoleNames = _nullishCoalesce(userRolesMap.get(id), () => ( []));
10144
+ const hasAllowedRole = attr.allowedRoles.some((role) => userRoleNames.includes(role));
10145
+ if (!hasAllowedRole) {
10090
10146
  roleErrors.push(id);
10091
10147
  }
10092
10148
  }
@@ -10101,7 +10157,7 @@ var UserService = class extends BaseService {
10101
10157
  if (roleErrors.length > 0) {
10102
10158
  errors.push({
10103
10159
  attribute: attrName,
10104
- message: `Users do not have required role for ${attr.label}. Allowed roles: ${_optionalChain([attr, 'access', _192 => _192.allowedRoles, 'optionalAccess', _193 => _193.join, 'call', _194 => _194(", ")])}`,
10160
+ message: `Users do not have required role for ${attr.label}. Allowed roles: ${_optionalChain([attr, 'access', _193 => _193.allowedRoles, 'optionalAccess', _194 => _194.join, 'call', _195 => _195(", ")])}`,
10105
10161
  invalidIds: roleErrors
10106
10162
  });
10107
10163
  }
@@ -10625,7 +10681,7 @@ var RelationPropertiesService = class extends BaseService {
10625
10681
  }
10626
10682
  }
10627
10683
  }
10628
- const shouldStoreAsInverse = _optionalChain([attribute, 'access', _195 => _195.bilateral, 'optionalAccess', _196 => _196.storageOwner]) === false;
10684
+ const shouldStoreAsInverse = _optionalChain([attribute, 'access', _196 => _196.bilateral, 'optionalAccess', _197 => _197.storageOwner]) === false;
10629
10685
  let storageFromObject = schema.name;
10630
10686
  let storageFromAttribute = attributeName;
10631
10687
  if (shouldStoreAsInverse && attribute.bilateral) {
@@ -10637,7 +10693,7 @@ var RelationPropertiesService = class extends BaseService {
10637
10693
  if (shouldStoreAsInverse) {
10638
10694
  const results = await Promise.all(
10639
10695
  normalized.map(
10640
- (item) => _optionalChain([adapter, 'access', _197 => _197.relationAttributes, 'optionalAccess', _198 => _198.findBySource, 'call', _199 => _199(
10696
+ (item) => _optionalChain([adapter, 'access', _198 => _198.relationAttributes, 'optionalAccess', _199 => _199.findBySource, 'call', _200 => _200(
10641
10697
  storageFromObject,
10642
10698
  item.id,
10643
10699
  storageFromAttribute
@@ -10776,7 +10832,7 @@ var RecordQueryService = class extends BaseService {
10776
10832
  super(adapter);
10777
10833
  this.schemaService = schemaService;
10778
10834
  this.options = options;
10779
- this.policyRegistry = _optionalChain([options, 'optionalAccess', _200 => _200.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _201 => _201.policyRegistry]), () => ( defaultPolicyRegistry));
10835
+ this.policyRegistry = _optionalChain([options, 'optionalAccess', _201 => _201.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _202 => _202.policyRegistry]), () => ( defaultPolicyRegistry));
10780
10836
  this.relationPropertiesService = new RelationPropertiesService(adapter);
10781
10837
  }
10782
10838
  // ============================================================================
@@ -10827,12 +10883,12 @@ var RecordQueryService = class extends BaseService {
10827
10883
  * Internal list query execution
10828
10884
  */
10829
10885
  async executeListQuery(schema, objectId, options) {
10830
- if (_optionalChain([this, 'access', _202 => _202.options, 'optionalAccess', _203 => _203.permissionService]) && this.userId) {
10886
+ if (_optionalChain([this, 'access', _203 => _203.options, 'optionalAccess', _204 => _204.permissionService]) && this.userId) {
10831
10887
  await checkPermission(this.options.permissionService, this.userId, schema.name, "read");
10832
10888
  }
10833
- const policy = _optionalChain([options, 'optionalAccess', _204 => _204.skipPolicyFilter]) ? void 0 : getPolicy(this.policyRegistry, this.userId, schema.name);
10889
+ const policy = _optionalChain([options, 'optionalAccess', _205 => _205.skipPolicyFilter]) ? void 0 : getPolicy(this.policyRegistry, this.userId, schema.name);
10834
10890
  let effectiveOptions = options;
10835
- if (_optionalChain([policy, 'optionalAccess', _205 => _205.applyListFilter]) && this.userId) {
10891
+ if (_optionalChain([policy, 'optionalAccess', _206 => _206.applyListFilter]) && this.userId) {
10836
10892
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
10837
10893
  effectiveOptions = policy.applyListFilter(ctx, options);
10838
10894
  }
@@ -10842,10 +10898,10 @@ var RecordQueryService = class extends BaseService {
10842
10898
  );
10843
10899
  let filteredRecords = result.records;
10844
10900
  let effectiveTotal = result.total;
10845
- if (_optionalChain([policy, 'optionalAccess', _206 => _206.canAccessRecord]) && this.userId) {
10901
+ if (_optionalChain([policy, 'optionalAccess', _207 => _207.canAccessRecord]) && this.userId) {
10846
10902
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
10847
- const requestedLimit = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _207 => _207.limit]), () => ( 20));
10848
- const requestedOffset = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _208 => _208.offset]), () => ( 0));
10903
+ const requestedLimit = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _208 => _208.limit]), () => ( 20));
10904
+ const requestedOffset = _nullishCoalesce(_optionalChain([effectiveOptions, 'optionalAccess', _209 => _209.offset]), () => ( 0));
10849
10905
  const overfetchMultiplier = 5;
10850
10906
  const batchSize = requestedLimit * overfetchMultiplier;
10851
10907
  const maxScanRecords = 1e4;
@@ -10867,7 +10923,7 @@ var RecordQueryService = class extends BaseService {
10867
10923
  exhausted = true;
10868
10924
  break;
10869
10925
  }
10870
- const filtered = batch.records.filter((record) => _optionalChain([policy, 'access', _209 => _209.canAccessRecord, 'optionalCall', _210 => _210(ctx, record)]));
10926
+ const filtered = batch.records.filter((record) => _optionalChain([policy, 'access', _210 => _210.canAccessRecord, 'optionalCall', _211 => _211(ctx, record)]));
10871
10927
  collected.push(...filtered);
10872
10928
  dbOffset += batch.records.length;
10873
10929
  totalScanned += batch.records.length;
@@ -10883,7 +10939,7 @@ var RecordQueryService = class extends BaseService {
10883
10939
  filteredRecords,
10884
10940
  schema
10885
10941
  );
10886
- if (!_optionalChain([options, 'optionalAccess', _211 => _211.skipFormulas])) {
10942
+ if (!_optionalChain([options, 'optionalAccess', _212 => _212.skipFormulas])) {
10887
10943
  return {
10888
10944
  records: enrichRecordsWithFormulas(filteredRecords, schema),
10889
10945
  total: effectiveTotal
@@ -10943,7 +10999,7 @@ var RecordQueryService = class extends BaseService {
10943
10999
  * Internal search query execution
10944
11000
  */
10945
11001
  async executeSearchQuery(schema, objectId, query, options) {
10946
- if (_optionalChain([this, 'access', _212 => _212.options, 'optionalAccess', _213 => _213.permissionService]) && this.userId) {
11002
+ if (_optionalChain([this, 'access', _213 => _213.options, 'optionalAccess', _214 => _214.permissionService]) && this.userId) {
10947
11003
  await checkPermission(this.options.permissionService, this.userId, schema.name, "read");
10948
11004
  }
10949
11005
  const result = await runWithSchemaContext(
@@ -10954,7 +11010,7 @@ var RecordQueryService = class extends BaseService {
10954
11010
  result.records,
10955
11011
  schema
10956
11012
  );
10957
- if (!_optionalChain([options, 'optionalAccess', _214 => _214.skipFormulas])) {
11013
+ if (!_optionalChain([options, 'optionalAccess', _215 => _215.skipFormulas])) {
10958
11014
  return {
10959
11015
  records: enrichRecordsWithFormulas(enrichedRecords, schema),
10960
11016
  total: result.total
@@ -11137,7 +11193,7 @@ var RelationService = class extends BaseService {
11137
11193
  }
11138
11194
  const isUniversal = attr.targets.length === 1 && attr.targets[0].object === RELATION_TARGET_ANY;
11139
11195
  const validObjectIds = isUniversal ? null : await this.getValidObjectIds(attr.targets);
11140
- if (!isUniversal && _optionalChain([validObjectIds, 'optionalAccess', _215 => _215.size]) === 0) {
11196
+ if (!isUniversal && _optionalChain([validObjectIds, 'optionalAccess', _216 => _216.size]) === 0) {
11141
11197
  errors.push({
11142
11198
  attribute: attr.name,
11143
11199
  message: `No valid target objects found for ${attr.label}`
@@ -11190,7 +11246,7 @@ var RelationService = class extends BaseService {
11190
11246
  for (const target of targets) {
11191
11247
  try {
11192
11248
  const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
11193
- if (_optionalChain([objectSchema, 'optionalAccess', _216 => _216.id])) {
11249
+ if (_optionalChain([objectSchema, 'optionalAccess', _217 => _217.id])) {
11194
11250
  objectIds.add(objectSchema.id);
11195
11251
  }
11196
11252
  } catch (e15) {
@@ -11259,7 +11315,7 @@ var RelationService = class extends BaseService {
11259
11315
  const targetResults = await Promise.all(
11260
11316
  filteredTargets.map(async (target) => {
11261
11317
  const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
11262
- if (!_optionalChain([objectSchema, 'optionalAccess', _217 => _217.id])) return { options: [], total: 0 };
11318
+ if (!_optionalChain([objectSchema, 'optionalAccess', _218 => _218.id])) return { options: [], total: 0 };
11263
11319
  const objectId = objectSchema.id;
11264
11320
  const result = query ? await queryService.searchRecords(objectId, query, queryOptions) : await queryService.listRecords(objectId, queryOptions);
11265
11321
  const options = await Promise.all(
@@ -11416,8 +11472,8 @@ var RelationService = class extends BaseService {
11416
11472
  continue;
11417
11473
  }
11418
11474
  const attribute = attributeMap.get(attributeId);
11419
- const targetConfig = _optionalChain([attribute, 'optionalAccess', _218 => _218.targets, 'optionalAccess', _219 => _219.find, 'call', _220 => _220((t) => t.object === objectSchema.name)]);
11420
- const customTemplate = _optionalChain([targetConfig, 'optionalAccess', _221 => _221.displayTemplate]);
11475
+ const targetConfig = _optionalChain([attribute, 'optionalAccess', _219 => _219.targets, 'optionalAccess', _220 => _220.find, 'call', _221 => _221((t) => t.object === objectSchema.name)]);
11476
+ const customTemplate = _optionalChain([targetConfig, 'optionalAccess', _222 => _222.displayTemplate]);
11421
11477
  const label = await this.resolveLabel(record, objectSchema, customTemplate);
11422
11478
  resolved.push({
11423
11479
  _compositeId: compositeId,
@@ -11580,14 +11636,14 @@ var RollupService = class extends BaseService {
11580
11636
  const sourceSchema = getSchemaByNameFromContext(sourceObjectName);
11581
11637
  let sourceObjectId;
11582
11638
  let reverseRelationAttrName;
11583
- if (_optionalChain([sourceSchema, 'optionalAccess', _222 => _222.id])) {
11639
+ if (_optionalChain([sourceSchema, 'optionalAccess', _223 => _223.id])) {
11584
11640
  sourceObjectId = sourceSchema.id;
11585
11641
  const reverseRelationAttr = sourceSchema.attributes.find((attr) => {
11586
11642
  if (attr.type !== "relation") return false;
11587
11643
  const relationConfig = attr;
11588
- return _optionalChain([relationConfig, 'optionalAccess', _223 => _223.targets, 'optionalAccess', _224 => _224.some, 'call', _225 => _225((t) => t.object === schema.name)]);
11644
+ return _optionalChain([relationConfig, 'optionalAccess', _224 => _224.targets, 'optionalAccess', _225 => _225.some, 'call', _226 => _226((t) => t.object === schema.name)]);
11589
11645
  });
11590
- reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _226 => _226.name]);
11646
+ reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _227 => _227.name]);
11591
11647
  } else {
11592
11648
  const sourceObject = await this.adapter.objects.findByName(sourceObjectName);
11593
11649
  if (!sourceObject) {
@@ -11598,9 +11654,9 @@ var RollupService = class extends BaseService {
11598
11654
  const reverseRelationAttr = sourceAttributes.find((attr) => {
11599
11655
  if (attr.type !== "relation") return false;
11600
11656
  const relationConfig = attr.config;
11601
- return _optionalChain([relationConfig, 'optionalAccess', _227 => _227.targets, 'optionalAccess', _228 => _228.some, 'call', _229 => _229((t) => t.object === schema.name)]);
11657
+ return _optionalChain([relationConfig, 'optionalAccess', _228 => _228.targets, 'optionalAccess', _229 => _229.some, 'call', _230 => _230((t) => t.object === schema.name)]);
11602
11658
  });
11603
- reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _230 => _230.name]);
11659
+ reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _231 => _231.name]);
11604
11660
  }
11605
11661
  if (!reverseRelationAttrName) {
11606
11662
  return { value: null, recordCount: 0 };
@@ -11856,13 +11912,13 @@ var RollupService = class extends BaseService {
11856
11912
  if (!obj) continue;
11857
11913
  for (const rollupDbAttr of rollupAttrs) {
11858
11914
  const rollupConfig = rollupDbAttr.config;
11859
- if (!_optionalChain([rollupConfig, 'optionalAccess', _231 => _231.relationAttribute])) continue;
11915
+ if (!_optionalChain([rollupConfig, 'optionalAccess', _232 => _232.relationAttribute])) continue;
11860
11916
  const relationAttr = attributes.find(
11861
11917
  (a) => a.type === "relation" && a.name === rollupConfig.relationAttribute
11862
11918
  );
11863
11919
  if (!relationAttr) continue;
11864
11920
  const relationConfig = relationAttr.config;
11865
- const targetsChangedObject = _optionalChain([relationConfig, 'optionalAccess', _232 => _232.targets, 'optionalAccess', _233 => _233.some, 'call', _234 => _234(
11921
+ const targetsChangedObject = _optionalChain([relationConfig, 'optionalAccess', _233 => _233.targets, 'optionalAccess', _234 => _234.some, 'call', _235 => _235(
11866
11922
  (t) => t.object === changedSchema.name
11867
11923
  )]);
11868
11924
  if (!targetsChangedObject) continue;
@@ -11887,11 +11943,11 @@ var RecordService = class extends BaseService {
11887
11943
  constructor(adapter, options) {
11888
11944
  super(adapter);
11889
11945
  this.schemaService = new ObjectSchemaService(adapter, registry, {
11890
- auditService: _optionalChain([options, 'optionalAccess', _235 => _235.auditService])
11946
+ auditService: _optionalChain([options, 'optionalAccess', _236 => _236.auditService])
11891
11947
  });
11892
- this.permissionService = _optionalChain([options, 'optionalAccess', _236 => _236.permissionService]);
11893
- this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _237 => _237.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
11894
- this.policyRegistry = _optionalChain([options, 'optionalAccess', _238 => _238.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _239 => _239.policyRegistry]), () => ( defaultPolicyRegistry));
11948
+ this.permissionService = _optionalChain([options, 'optionalAccess', _237 => _237.permissionService]);
11949
+ this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _238 => _238.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
11950
+ this.policyRegistry = _optionalChain([options, 'optionalAccess', _239 => _239.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _240 => _240.policyRegistry]), () => ( defaultPolicyRegistry));
11895
11951
  this.recordResolver = new RecordResolverService(adapter);
11896
11952
  this.queryService = new RecordQueryService(adapter, this.schemaService, {
11897
11953
  permissionService: this.permissionService,
@@ -11906,7 +11962,7 @@ var RecordService = class extends BaseService {
11906
11962
  recordResolver: this.recordResolver
11907
11963
  });
11908
11964
  this.userService = new UserService(adapter);
11909
- this.hookRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _240 => _240.hookRegistry]), () => ( new NoopHookRegistry()));
11965
+ this.hookRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _241 => _241.hookRegistry]), () => ( new NoopHookRegistry()));
11910
11966
  this.bilateralSyncService = new BilateralSyncService(
11911
11967
  adapter,
11912
11968
  this.schemaService,
@@ -11946,25 +12002,25 @@ var RecordService = class extends BaseService {
11946
12002
  schema,
11947
12003
  this.tenantId,
11948
12004
  dataWithDefaults,
11949
- _optionalChain([options, 'optionalAccess', _241 => _241.hookMetadata])
12005
+ _optionalChain([options, 'optionalAccess', _242 => _242.hookMetadata])
11950
12006
  );
11951
- if (!_optionalChain([options, 'optionalAccess', _242 => _242.skipHooks])) {
12007
+ if (!_optionalChain([options, 'optionalAccess', _243 => _243.skipHooks])) {
11952
12008
  await this.hookRegistry.execute("beforeCreate", schema.name, hookCtx);
11953
12009
  }
11954
12010
  const normalizedData = this.relationPropertiesService.normalizeRelationValuesForStorage(
11955
12011
  schema,
11956
12012
  dataWithDefaults
11957
12013
  );
11958
- if (_optionalChain([options, 'optionalAccess', _243 => _243.validate]) !== false) {
11959
- if (_optionalChain([options, 'optionalAccess', _244 => _244.allowDraft])) {
12014
+ if (_optionalChain([options, 'optionalAccess', _244 => _244.validate]) !== false) {
12015
+ if (_optionalChain([options, 'optionalAccess', _245 => _245.allowDraft])) {
11960
12016
  _chunk3WTK7ESHjs.validateDraftOrThrow.call(void 0, schema, normalizedData);
11961
12017
  } else {
11962
12018
  _chunk3WTK7ESHjs.validateObjectOrThrow.call(void 0, schema, normalizedData);
11963
12019
  }
11964
- if (!_optionalChain([options, 'optionalAccess', _245 => _245.skipRelationValidation])) {
12020
+ if (!_optionalChain([options, 'optionalAccess', _246 => _246.skipRelationValidation])) {
11965
12021
  await this.relationService.validateRelationsOrThrow(schema, normalizedData);
11966
12022
  }
11967
- if (!_optionalChain([options, 'optionalAccess', _246 => _246.skipUserValidation])) {
12023
+ if (!_optionalChain([options, 'optionalAccess', _247 => _247.skipUserValidation])) {
11968
12024
  await this.userService.validateUsersOrThrow(schema, normalizedData);
11969
12025
  }
11970
12026
  }
@@ -11975,12 +12031,12 @@ var RecordService = class extends BaseService {
11975
12031
  data: normalizedData,
11976
12032
  label,
11977
12033
  completionStatus,
11978
- metadata: _optionalChain([options, 'optionalAccess', _247 => _247.metadata]),
12034
+ metadata: _optionalChain([options, 'optionalAccess', _248 => _248.metadata]),
11979
12035
  createdBy: this.userId
11980
12036
  });
11981
12037
  for (const [attrName, value] of Object.entries(dataWithDefaults)) {
11982
12038
  const attr = schema.attributes.find((a) => a.name === attrName);
11983
- if (_optionalChain([attr, 'optionalAccess', _248 => _248.type]) === "relation") {
12039
+ if (_optionalChain([attr, 'optionalAccess', _249 => _249.type]) === "relation") {
11984
12040
  const hasProperties2 = attr.properties !== void 0;
11985
12041
  const isBilateral = isBilateralRelation(attr);
11986
12042
  if (hasProperties2 || isBilateral) {
@@ -11996,7 +12052,7 @@ var RecordService = class extends BaseService {
11996
12052
  }
11997
12053
  for (const [attrName, value] of Object.entries(normalizedData)) {
11998
12054
  const attr = schema.attributes.find((a) => a.name === attrName);
11999
- if (_optionalChain([attr, 'optionalAccess', _249 => _249.type]) === "relation" && isBilateralRelation(attr)) {
12055
+ if (_optionalChain([attr, 'optionalAccess', _250 => _250.type]) === "relation" && isBilateralRelation(attr)) {
12000
12056
  await this.bilateralSyncService.syncBilateralRelation(
12001
12057
  schema,
12002
12058
  record.id,
@@ -12007,7 +12063,7 @@ var RecordService = class extends BaseService {
12007
12063
  );
12008
12064
  }
12009
12065
  }
12010
- if (!_optionalChain([options, 'optionalAccess', _250 => _250.skipHooks])) {
12066
+ if (!_optionalChain([options, 'optionalAccess', _251 => _251.skipHooks])) {
12011
12067
  const afterCtx = {
12012
12068
  ...hookCtx,
12013
12069
  recordId: record.id,
@@ -12025,7 +12081,7 @@ var RecordService = class extends BaseService {
12025
12081
  objectId: schema.id,
12026
12082
  recordId: record.id,
12027
12083
  recordLabel: record.label,
12028
- metadata: _optionalChain([options, 'optionalAccess', _251 => _251.hookMetadata])
12084
+ metadata: _optionalChain([options, 'optionalAccess', _252 => _252.hookMetadata])
12029
12085
  }).catch(() => {
12030
12086
  });
12031
12087
  }
@@ -12048,7 +12104,7 @@ var RecordService = class extends BaseService {
12048
12104
  return null;
12049
12105
  }
12050
12106
  const schema = await this.schemaService.getObjectSchema(record.objectId);
12051
- if (!_optionalChain([options, 'optionalAccess', _252 => _252.skipPolicyCheck])) {
12107
+ if (!_optionalChain([options, 'optionalAccess', _253 => _253.skipPolicyCheck])) {
12052
12108
  const policy = getPolicy(this.policyRegistry, this.userId, schema.name);
12053
12109
  if (policy) {
12054
12110
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
@@ -12058,11 +12114,11 @@ var RecordService = class extends BaseService {
12058
12114
  }
12059
12115
  }
12060
12116
  let enrichedRecord = record;
12061
- if (!_optionalChain([options, 'optionalAccess', _253 => _253.skipFormulas])) {
12117
+ if (!_optionalChain([options, 'optionalAccess', _254 => _254.skipFormulas])) {
12062
12118
  enrichedRecord = enrichWithFormulas(record, schema);
12063
12119
  }
12064
12120
  enrichedRecord = await this.enrichRelationProperties(enrichedRecord, schema);
12065
- if (_optionalChain([options, 'optionalAccess', _254 => _254.includeSchema])) {
12121
+ if (_optionalChain([options, 'optionalAccess', _255 => _255.includeSchema])) {
12066
12122
  const recordWithSchema = enrichedRecord;
12067
12123
  recordWithSchema.schema = schema;
12068
12124
  return recordWithSchema;
@@ -12124,9 +12180,9 @@ var RecordService = class extends BaseService {
12124
12180
  existing,
12125
12181
  mergedData,
12126
12182
  changedAttributes,
12127
- _optionalChain([options, 'optionalAccess', _255 => _255.hookMetadata])
12183
+ _optionalChain([options, 'optionalAccess', _256 => _256.hookMetadata])
12128
12184
  );
12129
- if (!_optionalChain([options, 'optionalAccess', _256 => _256.skipHooks])) {
12185
+ if (!_optionalChain([options, 'optionalAccess', _257 => _257.skipHooks])) {
12130
12186
  await this.hookRegistry.execute("beforeUpdate", schema.name, hookCtx);
12131
12187
  }
12132
12188
  const hookModifiedValues = {};
@@ -12141,16 +12197,16 @@ var RecordService = class extends BaseService {
12141
12197
  dataToUpdate
12142
12198
  );
12143
12199
  const normalizedMergedData = { ...existing.values, ...normalizedUpdate };
12144
- if (_optionalChain([options, 'optionalAccess', _257 => _257.validate]) !== false) {
12145
- if (_optionalChain([options, 'optionalAccess', _258 => _258.partial])) {
12200
+ if (_optionalChain([options, 'optionalAccess', _258 => _258.validate]) !== false) {
12201
+ if (_optionalChain([options, 'optionalAccess', _259 => _259.partial])) {
12146
12202
  _chunk3WTK7ESHjs.validateDraftOrThrow.call(void 0, schema, normalizedMergedData);
12147
12203
  } else {
12148
12204
  _chunk3WTK7ESHjs.validateObjectOrThrow.call(void 0, schema, normalizedMergedData);
12149
12205
  }
12150
- if (!_optionalChain([options, 'optionalAccess', _259 => _259.skipRelationValidation])) {
12206
+ if (!_optionalChain([options, 'optionalAccess', _260 => _260.skipRelationValidation])) {
12151
12207
  await this.relationService.validateRelationsOrThrow(schema, normalizedUpdate);
12152
12208
  }
12153
- if (!_optionalChain([options, 'optionalAccess', _260 => _260.skipUserValidation])) {
12209
+ if (!_optionalChain([options, 'optionalAccess', _261 => _261.skipUserValidation])) {
12154
12210
  await this.userService.validateUsersOrThrow(schema, normalizedUpdate);
12155
12211
  }
12156
12212
  }
@@ -12163,7 +12219,7 @@ var RecordService = class extends BaseService {
12163
12219
  __lastUpdatedBy: this.userId,
12164
12220
  __expectedUpdatedAt: existing.updatedAt instanceof Date ? existing.updatedAt.toISOString() : existing.updatedAt
12165
12221
  };
12166
- if (_optionalChain([options, 'optionalAccess', _261 => _261.metadata]) !== void 0) {
12222
+ if (_optionalChain([options, 'optionalAccess', _262 => _262.metadata]) !== void 0) {
12167
12223
  const existingMetadata = _nullishCoalesce(existing.metadata, () => ( {}));
12168
12224
  const mergedMetadata = { ...existingMetadata, ...options.metadata };
12169
12225
  const cleanedMetadata = Object.fromEntries(
@@ -12174,7 +12230,7 @@ var RecordService = class extends BaseService {
12174
12230
  const bilateralOldValues = {};
12175
12231
  for (const attrName of Object.keys(normalizedUpdate)) {
12176
12232
  const attr = schema.attributes.find((a) => a.name === attrName);
12177
- if (_optionalChain([attr, 'optionalAccess', _262 => _262.type]) === "relation" && isBilateralRelation(attr)) {
12233
+ if (_optionalChain([attr, 'optionalAccess', _263 => _263.type]) === "relation" && isBilateralRelation(attr)) {
12178
12234
  bilateralOldValues[attrName] = existing.values[attrName];
12179
12235
  }
12180
12236
  }
@@ -12182,7 +12238,7 @@ var RecordService = class extends BaseService {
12182
12238
  await this.invalidateRecordCaches(recordId, existing.objectId);
12183
12239
  for (const [attrName, value] of Object.entries(dataToUpdate)) {
12184
12240
  const attr = schema.attributes.find((a) => a.name === attrName);
12185
- if (_optionalChain([attr, 'optionalAccess', _263 => _263.type]) === "relation") {
12241
+ if (_optionalChain([attr, 'optionalAccess', _264 => _264.type]) === "relation") {
12186
12242
  const hasProperties2 = attr.properties !== void 0;
12187
12243
  const isBilateral = isBilateralRelation(attr);
12188
12244
  if (hasProperties2 || isBilateral) {
@@ -12198,7 +12254,7 @@ var RecordService = class extends BaseService {
12198
12254
  }
12199
12255
  for (const [attrName, value] of Object.entries(normalizedUpdate)) {
12200
12256
  const attr = schema.attributes.find((a) => a.name === attrName);
12201
- if (_optionalChain([attr, 'optionalAccess', _264 => _264.type]) === "relation" && isBilateralRelation(attr)) {
12257
+ if (_optionalChain([attr, 'optionalAccess', _265 => _265.type]) === "relation" && isBilateralRelation(attr)) {
12202
12258
  const oldValue = bilateralOldValues[attrName];
12203
12259
  await this.bilateralSyncService.syncBilateralRelation(
12204
12260
  schema,
@@ -12209,7 +12265,7 @@ var RecordService = class extends BaseService {
12209
12265
  );
12210
12266
  }
12211
12267
  }
12212
- if (!_optionalChain([options, 'optionalAccess', _265 => _265.skipHooks])) {
12268
+ if (!_optionalChain([options, 'optionalAccess', _266 => _266.skipHooks])) {
12213
12269
  const afterCtx = {
12214
12270
  ...hookCtx,
12215
12271
  record: updated
@@ -12224,7 +12280,7 @@ var RecordService = class extends BaseService {
12224
12280
  if (this.auditService && this.userId && allChangedAttributes.length > 0) {
12225
12281
  const changes = allChangedAttributes.map((attr) => ({
12226
12282
  field: attr,
12227
- oldValue: _optionalChain([hookCtx, 'access', _266 => _266.oldValues, 'optionalAccess', _267 => _267[attr]]),
12283
+ oldValue: _optionalChain([hookCtx, 'access', _267 => _267.oldValues, 'optionalAccess', _268 => _268[attr]]),
12228
12284
  newValue: hookCtx.newValues[attr]
12229
12285
  }));
12230
12286
  this.auditService.logRecordAction({
@@ -12235,7 +12291,7 @@ var RecordService = class extends BaseService {
12235
12291
  recordId: updated.id,
12236
12292
  recordLabel: updated.label,
12237
12293
  changes,
12238
- metadata: _optionalChain([options, 'optionalAccess', _268 => _268.hookMetadata])
12294
+ metadata: _optionalChain([options, 'optionalAccess', _269 => _269.hookMetadata])
12239
12295
  }).catch(() => {
12240
12296
  });
12241
12297
  }
@@ -12267,17 +12323,17 @@ var RecordService = class extends BaseService {
12267
12323
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
12268
12324
  checkRecordDeleteOrThrow(policy, record, ctx);
12269
12325
  }
12270
- if (_optionalChain([options, 'optionalAccess', _269 => _269.checkSystem]) && schema.system) {
12326
+ if (_optionalChain([options, 'optionalAccess', _270 => _270.checkSystem]) && schema.system) {
12271
12327
  throw new ProtectedResourceError("object", schema.name, "delete");
12272
12328
  }
12273
- if (!_optionalChain([options, 'optionalAccess', _270 => _270.skipReferenceCheck])) {
12329
+ if (!_optionalChain([options, 'optionalAccess', _271 => _271.skipReferenceCheck])) {
12274
12330
  const references = await this.adapter.objectRecords.countRecordsReferencingId(recordId);
12275
12331
  if (references.length > 0) {
12276
12332
  throw new RecordReferencedError(recordId, references);
12277
12333
  }
12278
12334
  }
12279
- const hookCtx = createContextForDelete(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _271 => _271.hookMetadata]));
12280
- if (!_optionalChain([options, 'optionalAccess', _272 => _272.skipHooks])) {
12335
+ const hookCtx = createContextForDelete(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _272 => _272.hookMetadata]));
12336
+ if (!_optionalChain([options, 'optionalAccess', _273 => _273.skipHooks])) {
12281
12337
  await this.hookRegistry.execute("beforeDelete", schema.name, hookCtx);
12282
12338
  }
12283
12339
  for (const attr of schema.attributes) {
@@ -12295,7 +12351,7 @@ var RecordService = class extends BaseService {
12295
12351
  }
12296
12352
  await this.adapter.objectRecords.delete(recordId);
12297
12353
  await this.invalidateRecordCaches(recordId, record.objectId);
12298
- if (!_optionalChain([options, 'optionalAccess', _273 => _273.skipHooks])) {
12354
+ if (!_optionalChain([options, 'optionalAccess', _274 => _274.skipHooks])) {
12299
12355
  await this.hookRegistry.execute("afterDelete", schema.name, hookCtx);
12300
12356
  }
12301
12357
  await recalculateParentRollups(record, schema, this.rollupContext);
@@ -12307,7 +12363,7 @@ var RecordService = class extends BaseService {
12307
12363
  objectId: schema.id,
12308
12364
  recordId: record.id,
12309
12365
  recordLabel: record.label,
12310
- metadata: _optionalChain([options, 'optionalAccess', _274 => _274.hookMetadata])
12366
+ metadata: _optionalChain([options, 'optionalAccess', _275 => _275.hookMetadata])
12311
12367
  }).catch(() => {
12312
12368
  });
12313
12369
  }
@@ -12368,13 +12424,13 @@ var RecordService = class extends BaseService {
12368
12424
  this.tenantId
12369
12425
  );
12370
12426
  await checkPermission(this.permissionService, this.userId, schema.name, "update");
12371
- const hookCtx = createContextForRestore(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _275 => _275.hookMetadata]));
12372
- if (!_optionalChain([options, 'optionalAccess', _276 => _276.skipHooks])) {
12427
+ const hookCtx = createContextForRestore(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _276 => _276.hookMetadata]));
12428
+ if (!_optionalChain([options, 'optionalAccess', _277 => _277.skipHooks])) {
12373
12429
  await this.hookRegistry.execute("beforeRestore", schema.name, hookCtx);
12374
12430
  }
12375
12431
  const restored = await this.adapter.objectRecords.restore(recordId);
12376
12432
  await this.invalidateRecordCaches(recordId, record.objectId);
12377
- if (!_optionalChain([options, 'optionalAccess', _277 => _277.skipHooks])) {
12433
+ if (!_optionalChain([options, 'optionalAccess', _278 => _278.skipHooks])) {
12378
12434
  const afterCtx = {
12379
12435
  ...hookCtx,
12380
12436
  record: restored
@@ -12389,7 +12445,7 @@ var RecordService = class extends BaseService {
12389
12445
  objectId: schema.id,
12390
12446
  recordId: restored.id,
12391
12447
  recordLabel: restored.label,
12392
- metadata: _optionalChain([options, 'optionalAccess', _278 => _278.hookMetadata])
12448
+ metadata: _optionalChain([options, 'optionalAccess', _279 => _279.hookMetadata])
12393
12449
  }).catch(() => {
12394
12450
  });
12395
12451
  }
@@ -12820,7 +12876,7 @@ var DocumentRendererService = class {
12820
12876
  throw new StorageDownloadNotSupportedError();
12821
12877
  }
12822
12878
  let storagePath = fileId;
12823
- if (_optionalChain([this, 'access', _279 => _279.options, 'optionalAccess', _280 => _280.filesRepository])) {
12879
+ if (_optionalChain([this, 'access', _280 => _280.options, 'optionalAccess', _281 => _281.filesRepository])) {
12824
12880
  const file2 = await this.options.filesRepository.findById(fileId);
12825
12881
  if (!file2) {
12826
12882
  throw new Error(`Template file not found: ${fileId}`);
@@ -12838,8 +12894,8 @@ var DocumentRendererService = class {
12838
12894
  for (const field of fields) {
12839
12895
  const rawValue = getContextValue(context, field.contextPath);
12840
12896
  const attrInfo = await this.getAttributeInfo(field.contextPath, workflow2);
12841
- if (_optionalChain([attrInfo, 'optionalAccess', _281 => _281.attribute])) {
12842
- if (attrInfo.attribute.type === "relation" && rawValue && _optionalChain([this, 'access', _282 => _282.options, 'optionalAccess', _283 => _283.relationService])) {
12897
+ if (_optionalChain([attrInfo, 'optionalAccess', _282 => _282.attribute])) {
12898
+ if (attrInfo.attribute.type === "relation" && rawValue && _optionalChain([this, 'access', _283 => _283.options, 'optionalAccess', _284 => _284.relationService])) {
12843
12899
  const ids = Array.isArray(rawValue) ? rawValue : [rawValue];
12844
12900
  const stringIds = ids.filter((id) => typeof id === "string");
12845
12901
  if (stringIds.length > 0) {
@@ -12860,7 +12916,7 @@ var DocumentRendererService = class {
12860
12916
  resolved.set(field.id, this.formatValueSimple(rawValue, field.fallback));
12861
12917
  }
12862
12918
  }
12863
- if (relationBatch.length > 0 && _optionalChain([this, 'access', _284 => _284.options, 'optionalAccess', _285 => _285.relationService])) {
12919
+ if (relationBatch.length > 0 && _optionalChain([this, 'access', _285 => _285.options, 'optionalAccess', _286 => _286.relationService])) {
12864
12920
  try {
12865
12921
  const batchResult = await this.options.relationService.resolveIdsBatch(
12866
12922
  relationBatch.map((r) => ({ attributeId: r.attributeId, ids: r.ids }))
@@ -12869,12 +12925,12 @@ var DocumentRendererService = class {
12869
12925
  const options = _nullishCoalesce(batchResult[attributeId], () => ( []));
12870
12926
  const labels = options.map((o) => o.label);
12871
12927
  const field = fields.find((f) => f.id === fieldId);
12872
- resolved.set(fieldId, labels.join(", ") || _optionalChain([field, 'optionalAccess', _286 => _286.fallback]) || "");
12928
+ resolved.set(fieldId, labels.join(", ") || _optionalChain([field, 'optionalAccess', _287 => _287.fallback]) || "");
12873
12929
  }
12874
12930
  } catch (e17) {
12875
12931
  for (const { fieldId, ids } of relationBatch) {
12876
12932
  const field = fields.find((f) => f.id === fieldId);
12877
- resolved.set(fieldId, ids.join(", ") || _optionalChain([field, 'optionalAccess', _287 => _287.fallback]) || "");
12933
+ resolved.set(fieldId, ids.join(", ") || _optionalChain([field, 'optionalAccess', _288 => _288.fallback]) || "");
12878
12934
  }
12879
12935
  }
12880
12936
  }
@@ -12885,7 +12941,7 @@ var DocumentRendererService = class {
12885
12941
  * Parses paths like "slots.client.firstName" to find the attribute definition
12886
12942
  */
12887
12943
  async getAttributeInfo(contextPath, workflow2) {
12888
- const schemaService = _optionalChain([this, 'access', _288 => _288.options, 'optionalAccess', _289 => _289.schemaService]);
12944
+ const schemaService = _optionalChain([this, 'access', _289 => _289.options, 'optionalAccess', _290 => _290.schemaService]);
12889
12945
  if (!schemaService) {
12890
12946
  return null;
12891
12947
  }
@@ -12898,7 +12954,7 @@ var DocumentRendererService = class {
12898
12954
  }
12899
12955
  const slotId = parts[1];
12900
12956
  const attributeName = parts[2];
12901
- const slot = _optionalChain([workflow2, 'access', _290 => _290.slots, 'optionalAccess', _291 => _291.find, 'call', _292 => _292((s) => s.id === slotId)]);
12957
+ const slot = _optionalChain([workflow2, 'access', _291 => _291.slots, 'optionalAccess', _292 => _292.find, 'call', _293 => _293((s) => s.id === slotId)]);
12902
12958
  if (!slot) {
12903
12959
  return null;
12904
12960
  }
@@ -13097,7 +13153,7 @@ var DocumentProcessingHook = class extends BaseService {
13097
13153
  const pendingIds = [];
13098
13154
  for (const [nodeId, doc] of Object.entries(context.documents)) {
13099
13155
  const metadata = doc.metadata;
13100
- if (_optionalChain([metadata, 'optionalAccess', _293 => _293.status]) === "pending") {
13156
+ if (_optionalChain([metadata, 'optionalAccess', _294 => _294.status]) === "pending") {
13101
13157
  pendingIds.push(nodeId);
13102
13158
  }
13103
13159
  }
@@ -13148,12 +13204,12 @@ var DocumentProcessingHook = class extends BaseService {
13148
13204
  }
13149
13205
  for (const slotId of targetSlotIds) {
13150
13206
  try {
13151
- const recordId = _optionalChain([context, 'access', _294 => _294.createdRecordIds, 'optionalAccess', _295 => _295[slotId]]);
13207
+ const recordId = _optionalChain([context, 'access', _295 => _295.createdRecordIds, 'optionalAccess', _296 => _296[slotId]]);
13152
13208
  if (!recordId) {
13153
13209
  continue;
13154
13210
  }
13155
- const slotDef = _optionalChain([workflow2, 'access', _296 => _296.slots, 'optionalAccess', _297 => _297.find, 'call', _298 => _298((s) => s.id === slotId)]);
13156
- const objectName = _optionalChain([slotDef, 'optionalAccess', _299 => _299.objectName]);
13211
+ const slotDef = _optionalChain([workflow2, 'access', _297 => _297.slots, 'optionalAccess', _298 => _298.find, 'call', _299 => _299((s) => s.id === slotId)]);
13212
+ const objectName = _optionalChain([slotDef, 'optionalAccess', _300 => _300.objectName]);
13157
13213
  if (!objectName) {
13158
13214
  continue;
13159
13215
  }
@@ -13170,7 +13226,7 @@ var DocumentProcessingHook = class extends BaseService {
13170
13226
  attachedDocumentIds.push(result.document.id);
13171
13227
  const record = await recordService.getRecord(recordId);
13172
13228
  if (record) {
13173
- const attachments = _nullishCoalesce(_optionalChain([record, 'access', _300 => _300.values, 'optionalAccess', _301 => _301.attachments]), () => ( []));
13229
+ const attachments = _nullishCoalesce(_optionalChain([record, 'access', _301 => _301.values, 'optionalAccess', _302 => _302.attachments]), () => ( []));
13174
13230
  await recordService.updateRecord(
13175
13231
  recordId,
13176
13232
  { attachments: [...attachments, result.document.id] },
@@ -13436,7 +13492,7 @@ var WorkflowAccessGrantService = class extends BaseService {
13436
13492
  * Check if a specific token has been revoked.
13437
13493
  */
13438
13494
  isTokenRevoked(dbGrant, jti) {
13439
- return _nullishCoalesce(_optionalChain([dbGrant, 'access', _302 => _302.revoked_token_jtis, 'optionalAccess', _303 => _303.includes, 'call', _304 => _304(jti)]), () => ( false));
13495
+ return _nullishCoalesce(_optionalChain([dbGrant, 'access', _303 => _303.revoked_token_jtis, 'optionalAccess', _304 => _304.includes, 'call', _305 => _305(jti)]), () => ( false));
13440
13496
  }
13441
13497
  /**
13442
13498
  * Validate access token payload against the grant.
@@ -13488,10 +13544,10 @@ var WorkflowInstanceService = class extends BaseService {
13488
13544
  constructor(adapter, workflowService, options) {
13489
13545
  super(adapter);
13490
13546
  this.workflowService = workflowService;
13491
- this.executorRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _305 => _305.executorRegistry]), () => ( getDefaultExecutorRegistry()));
13492
- this.schemaService = _optionalChain([options, 'optionalAccess', _306 => _306.schemaService]);
13493
- this.recordService = _optionalChain([options, 'optionalAccess', _307 => _307.recordService]);
13494
- this.documentProcessingHook = _optionalChain([options, 'optionalAccess', _308 => _308.documentProcessingHook]);
13547
+ this.executorRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _306 => _306.executorRegistry]), () => ( getDefaultExecutorRegistry()));
13548
+ this.schemaService = _optionalChain([options, 'optionalAccess', _307 => _307.schemaService]);
13549
+ this.recordService = _optionalChain([options, 'optionalAccess', _308 => _308.recordService]);
13550
+ this.documentProcessingHook = _optionalChain([options, 'optionalAccess', _309 => _309.documentProcessingHook]);
13495
13551
  }
13496
13552
  /**
13497
13553
  * Start a new workflow instance
@@ -13673,7 +13729,7 @@ var WorkflowInstanceService = class extends BaseService {
13673
13729
  if (!this.adapter.workflowInstances) {
13674
13730
  return { instances: [], total: 0 };
13675
13731
  }
13676
- if (_optionalChain([options, 'optionalAccess', _309 => _309.workflowName])) {
13732
+ if (_optionalChain([options, 'optionalAccess', _310 => _310.workflowName])) {
13677
13733
  const allDbInstances = await this.adapter.workflowInstances.findByWorkflowName(
13678
13734
  options.workflowName,
13679
13735
  { status: options.status }
@@ -13687,11 +13743,11 @@ var WorkflowInstanceService = class extends BaseService {
13687
13743
  return { instances: instances2, total: total2 };
13688
13744
  }
13689
13745
  const { instances: dbInstances, total } = await this.adapter.workflowInstances.list({
13690
- limit: _optionalChain([options, 'optionalAccess', _310 => _310.limit]),
13691
- offset: _optionalChain([options, 'optionalAccess', _311 => _311.offset])
13746
+ limit: _optionalChain([options, 'optionalAccess', _311 => _311.limit]),
13747
+ offset: _optionalChain([options, 'optionalAccess', _312 => _312.offset])
13692
13748
  });
13693
13749
  let instances = dbInstances.map((db) => this.convertDBInstanceToInstance(db));
13694
- if (_optionalChain([options, 'optionalAccess', _312 => _312.status])) {
13750
+ if (_optionalChain([options, 'optionalAccess', _313 => _313.status])) {
13695
13751
  instances = instances.filter((i) => i.status === options.status);
13696
13752
  }
13697
13753
  instances = await this.markExpiredInstances(instances);
@@ -13712,9 +13768,9 @@ var WorkflowInstanceService = class extends BaseService {
13712
13768
  return { instances: [], total: 0 };
13713
13769
  }
13714
13770
  const { instances: dbInstances, total } = await this.adapter.workflowInstances.findByRecordInSlots(objectName, recordId, {
13715
- status: _optionalChain([options, 'optionalAccess', _313 => _313.status]),
13716
- limit: _optionalChain([options, 'optionalAccess', _314 => _314.limit]),
13717
- offset: _optionalChain([options, 'optionalAccess', _315 => _315.offset])
13771
+ status: _optionalChain([options, 'optionalAccess', _314 => _314.status]),
13772
+ limit: _optionalChain([options, 'optionalAccess', _315 => _315.limit]),
13773
+ offset: _optionalChain([options, 'optionalAccess', _316 => _316.offset])
13718
13774
  });
13719
13775
  const instances = dbInstances.map((db) => this.convertDBInstanceToInstance(db));
13720
13776
  return { instances, total };
@@ -13780,7 +13836,7 @@ var WorkflowInstanceService = class extends BaseService {
13780
13836
  try {
13781
13837
  const schemas = await Promise.all(
13782
13838
  current.workflowSnapshot.slots.map(
13783
- (slot) => _optionalChain([this, 'access', _316 => _316.schemaService, 'optionalAccess', _317 => _317.getObjectSchemaByName, 'call', _318 => _318(slot.objectName)])
13839
+ (slot) => _optionalChain([this, 'access', _317 => _317.schemaService, 'optionalAccess', _318 => _318.getObjectSchemaByName, 'call', _319 => _319(slot.objectName)])
13784
13840
  )
13785
13841
  );
13786
13842
  objectDefinitions = schemas.filter(
@@ -14045,8 +14101,8 @@ var WorkflowInstanceService = class extends BaseService {
14045
14101
  */
14046
14102
  async snapshotRecord(recordId) {
14047
14103
  try {
14048
- const record = await _optionalChain([this, 'access', _319 => _319.recordService, 'optionalAccess', _320 => _320.getRecord, 'call', _321 => _321(recordId, { skipPolicyCheck: true })]);
14049
- return _optionalChain([record, 'optionalAccess', _322 => _322.values]);
14104
+ const record = await _optionalChain([this, 'access', _320 => _320.recordService, 'optionalAccess', _321 => _321.getRecord, 'call', _322 => _322(recordId, { skipPolicyCheck: true })]);
14105
+ return _optionalChain([record, 'optionalAccess', _323 => _323.values]);
14050
14106
  } catch (e21) {
14051
14107
  return void 0;
14052
14108
  }
@@ -14065,13 +14121,13 @@ var WorkflowInstanceService = class extends BaseService {
14065
14121
  for (const op of [...operations].reverse()) {
14066
14122
  try {
14067
14123
  if (op.operation === "create") {
14068
- await _optionalChain([this, 'access', _323 => _323.recordService, 'optionalAccess', _324 => _324.deleteRecord, 'call', _325 => _325(op.recordId, {
14124
+ await _optionalChain([this, 'access', _324 => _324.recordService, 'optionalAccess', _325 => _325.deleteRecord, 'call', _326 => _326(op.recordId, {
14069
14125
  skipHooks: true,
14070
14126
  skipReferenceCheck: true
14071
14127
  })]);
14072
14128
  rolledBack.push(op.slotId);
14073
14129
  } else if (op.operation === "update" && op.previousData) {
14074
- await _optionalChain([this, 'access', _326 => _326.recordService, 'optionalAccess', _327 => _327.updateRecord, 'call', _328 => _328(op.recordId, op.previousData, {
14130
+ await _optionalChain([this, 'access', _327 => _327.recordService, 'optionalAccess', _328 => _328.updateRecord, 'call', _329 => _329(op.recordId, op.previousData, {
14075
14131
  partial: false
14076
14132
  })]);
14077
14133
  rolledBack.push(op.slotId);
@@ -14195,7 +14251,7 @@ var WorkflowInstanceService = class extends BaseService {
14195
14251
  if (!this.adapter.workflowInstances) {
14196
14252
  return;
14197
14253
  }
14198
- const currentVersion = _nullishCoalesce(_optionalChain([instance, 'access', _329 => _329.context, 'access', _330 => _330.variables, 'optionalAccess', _331 => _331.__version]), () => ( 0));
14254
+ const currentVersion = _nullishCoalesce(_optionalChain([instance, 'access', _330 => _330.context, 'access', _331 => _331.variables, 'optionalAccess', _332 => _332.__version]), () => ( 0));
14199
14255
  const nextVersion = currentVersion + 1;
14200
14256
  const instanceWithVersion = {
14201
14257
  ...instance,
@@ -14476,7 +14532,7 @@ var WorkflowRelationService = class extends BaseService {
14476
14532
  if (attr.type !== "relation") continue;
14477
14533
  for (const slot of slots) {
14478
14534
  const slotData = context.slots[slot.id];
14479
- const slotRecordId = _optionalChain([slotData, 'optionalAccess', _332 => _332.id]);
14535
+ const slotRecordId = _optionalChain([slotData, 'optionalAccess', _333 => _333.id]);
14480
14536
  if (!slotRecordId) continue;
14481
14537
  const targetsSlotObject = attr.targets.some(
14482
14538
  (t) => t.object === slot.objectName
@@ -14544,7 +14600,7 @@ var WorkflowService = class extends BaseService {
14544
14600
  if (Array.isArray(options)) {
14545
14601
  this.systemWorkflows = new Map(options.map((w) => [w.name, w]));
14546
14602
  } else {
14547
- this.systemWorkflows = new Map((_nullishCoalesce(_optionalChain([options, 'optionalAccess', _333 => _333.systemWorkflows]), () => ( []))).map((w) => [w.name, w]));
14603
+ this.systemWorkflows = new Map((_nullishCoalesce(_optionalChain([options, 'optionalAccess', _334 => _334.systemWorkflows]), () => ( []))).map((w) => [w.name, w]));
14548
14604
  }
14549
14605
  }
14550
14606
  // ============================================================================
@@ -14842,7 +14898,7 @@ var WorkflowService = class extends BaseService {
14842
14898
  var UserProfileService = class extends BaseService {
14843
14899
  constructor(adapter, options) {
14844
14900
  super(adapter);
14845
- this.auditService = _optionalChain([options, 'optionalAccess', _334 => _334.auditService]);
14901
+ this.auditService = _optionalChain([options, 'optionalAccess', _335 => _335.auditService]);
14846
14902
  }
14847
14903
  // ============================================================================
14848
14904
  // CACHE MANAGEMENT
@@ -14877,7 +14933,6 @@ var UserProfileService = class extends BaseService {
14877
14933
  * email: authUser.email,
14878
14934
  * firstName: authUser.user_metadata.first_name,
14879
14935
  * lastName: authUser.user_metadata.last_name,
14880
- * role: "member",
14881
14936
  * status: "active"
14882
14937
  * });
14883
14938
  * ```
@@ -14956,7 +15011,6 @@ var UserProfileService = class extends BaseService {
14956
15011
  * {
14957
15012
  * authId: authUser.id,
14958
15013
  * email: authUser.email,
14959
- * role: "member",
14960
15014
  * status: "active"
14961
15015
  * }
14962
15016
  * );
@@ -14981,7 +15035,6 @@ var UserProfileService = class extends BaseService {
14981
15035
  const changes = buildAuditChanges(existing, data, [
14982
15036
  "firstName",
14983
15037
  "lastName",
14984
- "role",
14985
15038
  "status"
14986
15039
  ]);
14987
15040
  if (changes.length > 0) {
@@ -15005,11 +15058,13 @@ var UserProfileService = class extends BaseService {
15005
15058
  */
15006
15059
  async deleteProfile(profileId, options) {
15007
15060
  const profile = await this.getProfileOrThrow(profileId);
15008
- if (_optionalChain([options, 'optionalAccess', _335 => _335.checkAdmin])) {
15009
- if (profile.role === "admin") {
15010
- const adminCount = await this.adapter.userProfiles.countByRole("admin");
15011
- if (adminCount <= 1) {
15012
- throw new Error("Cannot delete the last admin user");
15061
+ if (_optionalChain([options, 'optionalAccess', _336 => _336.checkAdmin]) && this.adapter.permissions) {
15062
+ const ownerCount = await this.adapter.permissions.countUsersWithRole("owner");
15063
+ if (ownerCount <= 1) {
15064
+ const userRoles = await this.adapter.permissions.getUserRoles(profileId);
15065
+ const isOwner = userRoles.some((r) => r.name === "owner");
15066
+ if (isOwner) {
15067
+ throw new Error("Cannot delete the last owner user");
15013
15068
  }
15014
15069
  }
15015
15070
  }
@@ -15045,15 +15100,6 @@ var UserProfileService = class extends BaseService {
15045
15100
  async updateLastLogin(profileId) {
15046
15101
  await this.adapter.userProfiles.updateLastLogin(profileId);
15047
15102
  }
15048
- /**
15049
- * Change user role
15050
- *
15051
- * @param profileId - Profile UUID
15052
- * @param newRole - New role
15053
- */
15054
- async changeRole(profileId, newRole) {
15055
- return await this.updateProfile(profileId, { role: newRole });
15056
- }
15057
15103
  /**
15058
15104
  * Change user status
15059
15105
  *
@@ -15075,19 +15121,6 @@ var UserProfileService = class extends BaseService {
15075
15121
  () => this.adapter.userProfiles.findByEmail(email)
15076
15122
  );
15077
15123
  }
15078
- /**
15079
- * Check if user has role
15080
- */
15081
- async hasRole(profileId, role) {
15082
- const profile = await this.getProfile(profileId);
15083
- return _optionalChain([profile, 'optionalAccess', _336 => _336.role]) === role;
15084
- }
15085
- /**
15086
- * Check if user is admin
15087
- */
15088
- async isAdmin(profileId) {
15089
- return await this.hasRole(profileId, "admin");
15090
- }
15091
15124
  /**
15092
15125
  * Invite a new user by email.
15093
15126
  *
@@ -15108,7 +15141,6 @@ var UserProfileService = class extends BaseService {
15108
15141
  * email: "john@example.com",
15109
15142
  * firstName: "John",
15110
15143
  * lastName: "Doe",
15111
- * role: "member",
15112
15144
  * redirectTo: "https://app.example.com/welcome",
15113
15145
  * });
15114
15146
  * // Email sent automatically, profile.status === "pending"
@@ -17348,7 +17380,7 @@ var PermissionService = class extends BaseService {
17348
17380
  DEFAULT_ROLE_LABELS,
17349
17381
  DEFAULT_ROLE_DESCRIPTIONS,
17350
17382
  DEFAULT_ROLE_PERMISSIONS
17351
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./default-roles-C3FYDYMN.js")));
17383
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require("./default-roles-76HUWY6T.js")));
17352
17384
  const existingRoles = await this.getRoles();
17353
17385
  const existingRoleNames = existingRoles.reduce((set, r) => set.add(r.name), /* @__PURE__ */ new Set());
17354
17386
  for (const roleName of Object.values(DEFAULT_ROLES)) {