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

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.
@@ -2141,7 +2141,7 @@ var EndExecutor = class {
2141
2141
  this.nodeType = "end";
2142
2142
  }
2143
2143
  execute(node, _context) {
2144
- return complete(_nullishCoalesce(node.status, () => ( "completed")));
2144
+ return complete(node.status || "completed");
2145
2145
  }
2146
2146
  canExecute(_node, _context) {
2147
2147
  return true;
@@ -2264,10 +2264,20 @@ var FormExecutor = class {
2264
2264
  const fieldRefs = this.collectFieldRefs(node);
2265
2265
  for (const fieldRef of fieldRefs) {
2266
2266
  const slot = slots.find((s) => s.id === fieldRef.slotId);
2267
- if (!slot) continue;
2267
+ if (!slot) {
2268
+ console.warn(
2269
+ `[FormExecutor] Slot "${fieldRef.slotId}" not found in workflow definition, skipping validation`
2270
+ );
2271
+ continue;
2272
+ }
2268
2273
  if (slot.mode === "select") continue;
2269
2274
  const object2 = objects.find((o) => o.name === slot.objectName);
2270
- if (!object2) continue;
2275
+ if (!object2) {
2276
+ console.warn(
2277
+ `[FormExecutor] Object "${slot.objectName}" not found for slot "${fieldRef.slotId}", skipping validation`
2278
+ );
2279
+ continue;
2280
+ }
2271
2281
  const attribute = object2.attributes.find((a) => a.name === fieldRef.attribute);
2272
2282
  if (!_optionalChain([attribute, 'optionalAccess', _30 => _30.required])) continue;
2273
2283
  const slotInput = input[fieldRef.slotId];
@@ -2312,7 +2322,7 @@ var StartExecutor = class {
2312
2322
  }
2313
2323
  execute(node, _context) {
2314
2324
  if (!node.next) {
2315
- throw new Error(`StartNode "${node.id}" has no 'next' target defined`);
2325
+ return error("MISSING_NEXT", `StartNode "${node.id}" has no 'next' target defined`);
2316
2326
  }
2317
2327
  return success(node.next);
2318
2328
  }
@@ -2526,13 +2536,11 @@ function hasRelationReferences(expression) {
2526
2536
  return regex.test(expression);
2527
2537
  }
2528
2538
  function flattenRelationsForEval(resolvedRelations) {
2529
- const flat = {};
2539
+ const result = {};
2530
2540
  for (const [relationName, values] of Object.entries(resolvedRelations)) {
2531
- for (const [key, value] of Object.entries(values)) {
2532
- flat[`${relationName}.${key}`] = value;
2533
- }
2541
+ result[relationName] = { ...values };
2534
2542
  }
2535
- return flat;
2543
+ return result;
2536
2544
  }
2537
2545
  async function evaluateFormulaWithRelations(expression, record, schema, resolver) {
2538
2546
  const relationNames = extractRelationNames(expression);
@@ -2802,6 +2810,15 @@ function createMockAIConversationsRepository(stores) {
2802
2810
  },
2803
2811
  addMessage(input) {
2804
2812
  const now = /* @__PURE__ */ new Date();
2813
+ const conversation = stores.aiConversations.get(input.conversationId);
2814
+ if (!conversation) {
2815
+ return Promise.reject(new Error("Conversation not found"));
2816
+ }
2817
+ const tenantId = getTenantId();
2818
+ const userId = requireUserId();
2819
+ if (conversation.tenantId !== tenantId || conversation.userId !== userId) {
2820
+ return Promise.reject(new Error("Conversation not found or access denied"));
2821
+ }
2805
2822
  const message = {
2806
2823
  id: _chunkNEVERCM3js.generateId.call(void 0, ),
2807
2824
  conversationId: input.conversationId,
@@ -2819,17 +2836,23 @@ function createMockAIConversationsRepository(stores) {
2819
2836
  createdAt: now
2820
2837
  };
2821
2838
  stores.aiMessages.set(message.id, message);
2822
- const conversation = stores.aiConversations.get(input.conversationId);
2823
- if (conversation) {
2824
- conversation.messageCount++;
2825
- conversation.totalTokens += (_nullishCoalesce(input.inputTokens, () => ( 0))) + (_nullishCoalesce(input.outputTokens, () => ( 0)));
2826
- conversation.totalCost += _nullishCoalesce(input.cost, () => ( 0));
2827
- conversation.updatedAt = now;
2828
- stores.aiConversations.set(input.conversationId, conversation);
2829
- }
2839
+ conversation.messageCount++;
2840
+ conversation.totalTokens += (_nullishCoalesce(input.inputTokens, () => ( 0))) + (_nullishCoalesce(input.outputTokens, () => ( 0)));
2841
+ conversation.totalCost += _nullishCoalesce(input.cost, () => ( 0));
2842
+ conversation.updatedAt = now;
2843
+ stores.aiConversations.set(input.conversationId, conversation);
2830
2844
  return Promise.resolve(message);
2831
2845
  },
2832
2846
  listMessages(conversationId, options) {
2847
+ const conversation = stores.aiConversations.get(conversationId);
2848
+ if (!conversation) {
2849
+ return Promise.resolve({ messages: [], total: 0 });
2850
+ }
2851
+ const tenantId = getTenantId();
2852
+ const userId = requireUserId();
2853
+ if (conversation.tenantId !== tenantId || conversation.userId !== userId) {
2854
+ return Promise.resolve({ messages: [], total: 0 });
2855
+ }
2833
2856
  let results = Array.from(stores.aiMessages.values()).filter((m) => m.conversationId === conversationId).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
2834
2857
  const total = results.length;
2835
2858
  if (_optionalChain([options, 'optionalAccess', _38 => _38.limit])) {
@@ -2838,6 +2861,15 @@ function createMockAIConversationsRepository(stores) {
2838
2861
  return Promise.resolve({ messages: results, total });
2839
2862
  },
2840
2863
  getRecentMessages(conversationId, count = 20) {
2864
+ const conversation = stores.aiConversations.get(conversationId);
2865
+ if (!conversation) {
2866
+ return Promise.resolve([]);
2867
+ }
2868
+ const tenantId = getTenantId();
2869
+ const userId = requireUserId();
2870
+ if (conversation.tenantId !== tenantId || conversation.userId !== userId) {
2871
+ return Promise.resolve([]);
2872
+ }
2841
2873
  const results = Array.from(stores.aiMessages.values()).filter((m) => m.conversationId === conversationId).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()).slice(-count);
2842
2874
  return Promise.resolve(results);
2843
2875
  }
@@ -3104,7 +3136,12 @@ function createMockFilesRepository(stores) {
3104
3136
  function createMockObjectsRepository(stores) {
3105
3137
  return {
3106
3138
  findById(id) {
3107
- return Promise.resolve(_nullishCoalesce(stores.objects.get(id), () => ( null)));
3139
+ const tenantId = getTenantId();
3140
+ const obj = stores.objects.get(id);
3141
+ if (!obj || obj.tenantId !== tenantId) {
3142
+ return Promise.resolve(null);
3143
+ }
3144
+ return Promise.resolve(obj);
3108
3145
  },
3109
3146
  findByName(name) {
3110
3147
  const tenantId = getTenantId();
@@ -3144,8 +3181,9 @@ function createMockObjectsRepository(stores) {
3144
3181
  return Promise.resolve(obj);
3145
3182
  },
3146
3183
  update(id, data) {
3184
+ const tenantId = getTenantId();
3147
3185
  const existing = stores.objects.get(id);
3148
- if (!existing) {
3186
+ if (!existing || existing.tenantId !== tenantId) {
3149
3187
  return Promise.reject(new Error(`Object ${id} not found`));
3150
3188
  }
3151
3189
  const updated = {
@@ -3157,6 +3195,11 @@ function createMockObjectsRepository(stores) {
3157
3195
  return Promise.resolve(updated);
3158
3196
  },
3159
3197
  delete(id) {
3198
+ const tenantId = getTenantId();
3199
+ const existing = stores.objects.get(id);
3200
+ if (!existing || existing.tenantId !== tenantId) {
3201
+ return Promise.reject(new Error(`Object ${id} not found`));
3202
+ }
3160
3203
  stores.objects.delete(id);
3161
3204
  return Promise.resolve();
3162
3205
  },
@@ -3170,7 +3213,7 @@ function createMockObjectsRepository(stores) {
3170
3213
  upsert(data) {
3171
3214
  const tenantId = getTenantId();
3172
3215
  for (const obj of stores.objects.values()) {
3173
- if (obj.system && obj.name === data.name) {
3216
+ if (obj.tenantId === tenantId && obj.system && obj.name === data.name) {
3174
3217
  const updated = {
3175
3218
  ...obj,
3176
3219
  label: data.label,
@@ -3842,6 +3885,7 @@ function createMockObjectRecordsRepository(stores) {
3842
3885
  findById(id) {
3843
3886
  const internal = stores.objectRecords.get(id);
3844
3887
  if (!internal) return Promise.resolve(null);
3888
+ if (internal.deletedAt) return Promise.resolve(null);
3845
3889
  const { tenantId: _, ...record } = internal;
3846
3890
  return Promise.resolve(record);
3847
3891
  },
@@ -3849,7 +3893,7 @@ function createMockObjectRecordsRepository(stores) {
3849
3893
  const results = [];
3850
3894
  for (const id of ids) {
3851
3895
  const internal = stores.objectRecords.get(id);
3852
- if (internal) {
3896
+ if (internal && !internal.deletedAt) {
3853
3897
  const { tenantId: _, ...record } = internal;
3854
3898
  results.push(record);
3855
3899
  }
@@ -3910,13 +3954,18 @@ function createMockObjectRecordsRepository(stores) {
3910
3954
  return Promise.resolve(record);
3911
3955
  },
3912
3956
  delete(id) {
3913
- stores.objectRecords.delete(id);
3957
+ const existing = stores.objectRecords.get(id);
3958
+ if (!existing) {
3959
+ return Promise.reject(new Error(`ObjectRecord ${id} not found`));
3960
+ }
3961
+ existing.deletedAt = /* @__PURE__ */ new Date();
3962
+ stores.objectRecords.set(id, existing);
3914
3963
  return Promise.resolve();
3915
3964
  },
3916
3965
  list(objectId, options) {
3917
3966
  const tenantId = getTenantId();
3918
3967
  let results = Array.from(stores.objectRecords.values()).filter(
3919
- (r) => r.tenantId === tenantId && r.objectId === objectId
3968
+ (r) => r.tenantId === tenantId && r.objectId === objectId && !r.deletedAt
3920
3969
  );
3921
3970
  const total = results.length;
3922
3971
  if (_optionalChain([options, 'optionalAccess', _73 => _73.limit])) {
@@ -3929,7 +3978,7 @@ function createMockObjectRecordsRepository(stores) {
3929
3978
  const tenantId = getTenantId();
3930
3979
  const lowerQuery = query.toLowerCase();
3931
3980
  let results = Array.from(stores.objectRecords.values()).filter((r) => {
3932
- if (r.tenantId !== tenantId || r.objectId !== objectId) return false;
3981
+ if (r.tenantId !== tenantId || r.objectId !== objectId || r.deletedAt) return false;
3933
3982
  return Object.values(r.values).some(
3934
3983
  (val) => String(val).toLowerCase().includes(lowerQuery)
3935
3984
  );
@@ -3963,7 +4012,7 @@ function createMockObjectRecordsRepository(stores) {
3963
4012
  }
3964
4013
  }
3965
4014
  let matchingRecords = Array.from(stores.objectRecords.values()).filter((r) => {
3966
- if (r.tenantId !== tenantId) return false;
4015
+ if (r.tenantId !== tenantId || r.deletedAt) return false;
3967
4016
  if (!allowedObjectIds.has(r.objectId)) return false;
3968
4017
  return Object.values(r.values).some(
3969
4018
  (val) => String(val).toLowerCase().includes(lowerQuery)
@@ -4118,12 +4167,12 @@ function createMockObjectRecordsRepository(stores) {
4118
4167
  }
4119
4168
  return Promise.resolve(updated);
4120
4169
  },
4121
- findByRelation(objectName, relationAttributeName, targetRecordId) {
4122
- const obj = Array.from(stores.objects.values()).find((o) => o.name === objectName);
4170
+ findByRelation(objectId, relationAttributeName, targetRecordId) {
4171
+ const obj = stores.objects.get(objectId);
4123
4172
  if (!obj) return Promise.resolve([]);
4124
4173
  const results = [];
4125
4174
  for (const record of stores.objectRecords.values()) {
4126
- if (record.objectId !== obj.id) continue;
4175
+ if (record.objectId !== objectId) continue;
4127
4176
  const value = record.values[relationAttributeName];
4128
4177
  let matches = false;
4129
4178
  if (typeof value === "string" && value === targetRecordId) {
@@ -4283,7 +4332,12 @@ function createEmptyStores() {
4283
4332
  function createMockUserProfilesRepository(stores) {
4284
4333
  return {
4285
4334
  findById(id) {
4286
- return Promise.resolve(_nullishCoalesce(stores.userProfiles.get(id), () => ( null)));
4335
+ const tenantId = getTenantId();
4336
+ const profile = stores.userProfiles.get(id);
4337
+ if (!profile || profile.tenantId !== tenantId) {
4338
+ return Promise.resolve(null);
4339
+ }
4340
+ return Promise.resolve(profile);
4287
4341
  },
4288
4342
  findByIds(ids) {
4289
4343
  const tenantId = getTenantId();
@@ -4297,8 +4351,9 @@ function createMockUserProfilesRepository(stores) {
4297
4351
  return Promise.resolve(results);
4298
4352
  },
4299
4353
  findByAuthId(authId) {
4354
+ const tenantId = getTenantId();
4300
4355
  for (const profile of stores.userProfiles.values()) {
4301
- if (profile.authId === authId) {
4356
+ if (profile.tenantId === tenantId && profile.authId === authId) {
4302
4357
  return Promise.resolve(profile);
4303
4358
  }
4304
4359
  }
@@ -4886,6 +4941,10 @@ function createMockWorkflowsRepository(stores) {
4886
4941
  if (!existing) {
4887
4942
  return Promise.reject(new Error(`Workflow ${id} not found`));
4888
4943
  }
4944
+ const tenantId = getTenantId();
4945
+ if (existing.tenant_id !== tenantId && !existing.system) {
4946
+ return Promise.reject(new Error(`Workflow ${id} not found`));
4947
+ }
4889
4948
  const updated = {
4890
4949
  ...existing,
4891
4950
  label: _nullishCoalesce(data.label, () => ( existing.label)),
@@ -4906,6 +4965,13 @@ function createMockWorkflowsRepository(stores) {
4906
4965
  return Promise.resolve(updated);
4907
4966
  },
4908
4967
  delete(id) {
4968
+ const existing = stores.workflows.get(id);
4969
+ if (existing) {
4970
+ const tenantId = getTenantId();
4971
+ if (existing.tenant_id !== tenantId && !existing.system) {
4972
+ return Promise.reject(new Error(`Workflow ${id} not found`));
4973
+ }
4974
+ }
4909
4975
  stores.workflows.delete(id);
4910
4976
  return Promise.resolve();
4911
4977
  },
@@ -4988,6 +5054,10 @@ function createMockWorkflowInstancesRepository(stores) {
4988
5054
  if (!existing) {
4989
5055
  return Promise.reject(new Error(`WorkflowInstance ${id} not found`));
4990
5056
  }
5057
+ const tenantId = getTenantId();
5058
+ if (existing.tenant_id !== tenantId) {
5059
+ return Promise.reject(new Error(`WorkflowInstance ${id} not found`));
5060
+ }
4991
5061
  const updated = {
4992
5062
  ...existing,
4993
5063
  status: _nullishCoalesce(data.status, () => ( existing.status)),
@@ -5112,6 +5182,10 @@ function createMockWorkflowInvitationsRepository(stores) {
5112
5182
  if (!existing) {
5113
5183
  return Promise.reject(new Error(`WorkflowInvitation ${id} not found`));
5114
5184
  }
5185
+ const tenantId = getTenantId();
5186
+ if (existing.tenant_id !== tenantId) {
5187
+ return Promise.reject(new Error(`WorkflowInvitation ${id} not found`));
5188
+ }
5115
5189
  const updated = {
5116
5190
  ...existing,
5117
5191
  status: _nullishCoalesce(data.status, () => ( existing.status)),
@@ -5177,6 +5251,10 @@ function createMockWorkflowAccessGrantsRepository(stores) {
5177
5251
  if (!existing) {
5178
5252
  return Promise.reject(new Error(`WorkflowAccessGrant ${id} not found`));
5179
5253
  }
5254
+ const tenantId = getTenantId();
5255
+ if (existing.tenant_id !== tenantId) {
5256
+ return Promise.reject(new Error(`WorkflowAccessGrant ${id} not found`));
5257
+ }
5180
5258
  const updated = {
5181
5259
  ...existing,
5182
5260
  last_used_at: data.lastUsedAt !== void 0 ? data.lastUsedAt.toISOString() : existing.last_used_at,
@@ -5310,6 +5388,20 @@ var PolicyRegistry = class {
5310
5388
  };
5311
5389
  var defaultPolicyRegistry = new PolicyRegistry();
5312
5390
 
5391
+ // src/runtime/search.ts
5392
+ var SORTABLE_ATTRIBUTE_TYPES = /* @__PURE__ */ new Set([
5393
+ "text",
5394
+ "textarea",
5395
+ "number",
5396
+ "date",
5397
+ "select",
5398
+ "status",
5399
+ "multiselect",
5400
+ "checkbox",
5401
+ "rating",
5402
+ "currency"
5403
+ ]);
5404
+
5313
5405
  // src/runtime/services/base.service.ts
5314
5406
  var BaseService = class {
5315
5407
  constructor(adapter) {
@@ -5529,6 +5621,15 @@ function isBilateralRelation(attr) {
5529
5621
  function inferInverseCardinality(cardinality) {
5530
5622
  return cardinality === "one" ? "many" : "many";
5531
5623
  }
5624
+ var NON_SORTABLE_TYPES = /* @__PURE__ */ new Set([
5625
+ "richtext",
5626
+ "file",
5627
+ "document",
5628
+ "location"
5629
+ ]);
5630
+ function isAttributeSortable(attr) {
5631
+ return !NON_SORTABLE_TYPES.has(attr.type);
5632
+ }
5532
5633
 
5533
5634
  // src/types/relation-properties.ts
5534
5635
  var FORBIDDEN_PROPERTY_TYPES = [
@@ -6248,6 +6349,20 @@ var SingleRelationAttributeBuilder = class extends BaseRelationAttributeBuilder
6248
6349
  isRequired: this.attr.required
6249
6350
  }
6250
6351
  );
6352
+ if (this.attr.system) multiBuilder.system();
6353
+ if (this.attr.hidden) multiBuilder.hidden();
6354
+ if (this.attr.disabled) multiBuilder.disabled();
6355
+ if (this.attr.placeholder) multiBuilder.placeholder(this.attr.placeholder);
6356
+ if (this.attr.description) multiBuilder.description(this.attr.description);
6357
+ if (this.attr.icon) multiBuilder.icon(this.attr.icon);
6358
+ if (this.attr.order !== void 0) multiBuilder.order(this.attr.order);
6359
+ if (this.attr.metadata) multiBuilder.metadata(this.attr.metadata);
6360
+ if (this.attr.featureGate) {
6361
+ multiBuilder.featureGate(this.attr.featureGate.flag, {
6362
+ expectedValue: this.attr.featureGate.expectedValue,
6363
+ fallback: this.attr.featureGate.fallback
6364
+ });
6365
+ }
6251
6366
  return multiBuilder;
6252
6367
  }
6253
6368
  required() {
@@ -6488,6 +6603,13 @@ var DocumentAttributeBuilder = class extends BaseAttributeBuilder {
6488
6603
  this.setRequired(true);
6489
6604
  return this;
6490
6605
  }
6606
+ /**
6607
+ * Mark this attribute as optional (undo required).
6608
+ */
6609
+ optional() {
6610
+ this.setRequired(false);
6611
+ return this;
6612
+ }
6491
6613
  };
6492
6614
  function document(config) {
6493
6615
  return new DocumentAttributeBuilder(config.name, config.label);
@@ -8940,6 +9062,19 @@ var ObjectSchemaService = class extends BaseService {
8940
9062
  });
8941
9063
  });
8942
9064
  await this.invalidateCachePattern(cacheKeys.allResolvedRelations(this.tenantId));
9065
+ if (this.adapter.search) {
9066
+ const { records } = await this.adapter.objectRecords.list(objectId, { limit: 1e4 });
9067
+ this.adapter.search.bulkIndex(
9068
+ records.map((r) => ({
9069
+ record: r,
9070
+ objectName: updatedDbObject.name,
9071
+ objectLabel: updatedDbObject.label,
9072
+ attributes
9073
+ }))
9074
+ ).catch(
9075
+ (err) => console.error("[search] Bulk re-index after label refresh failed", objectId, err)
9076
+ );
9077
+ }
8943
9078
  }
8944
9079
  return this.convertDBObjectToDefinition(updatedDbObject, dbAttributes);
8945
9080
  }
@@ -11002,15 +11137,34 @@ var RecordQueryService = class extends BaseService {
11002
11137
  if (_optionalChain([this, 'access', _213 => _213.options, 'optionalAccess', _214 => _214.permissionService]) && this.userId) {
11003
11138
  await checkPermission(this.options.permissionService, this.userId, schema.name, "read");
11004
11139
  }
11005
- const result = await runWithSchemaContext(
11006
- [schema],
11007
- () => this.adapter.objectRecords.search(objectId, query, options)
11008
- );
11140
+ let result;
11141
+ if (this.adapter.search) {
11142
+ try {
11143
+ result = await this.adapter.search.searchRecords(objectId, query, {
11144
+ limit: _optionalChain([options, 'optionalAccess', _215 => _215.limit]),
11145
+ offset: _optionalChain([options, 'optionalAccess', _216 => _216.offset]),
11146
+ sorts: _optionalChain([options, 'optionalAccess', _217 => _217.sorts]),
11147
+ filters: _optionalChain([options, 'optionalAccess', _218 => _218.filters]),
11148
+ attributes: schema.attributes
11149
+ });
11150
+ result = await this.healSearchResults(result);
11151
+ } catch (e15) {
11152
+ result = await runWithSchemaContext(
11153
+ [schema],
11154
+ () => this.adapter.objectRecords.search(objectId, query, options)
11155
+ );
11156
+ }
11157
+ } else {
11158
+ result = await runWithSchemaContext(
11159
+ [schema],
11160
+ () => this.adapter.objectRecords.search(objectId, query, options)
11161
+ );
11162
+ }
11009
11163
  const enrichedRecords = await this.relationPropertiesService.enrichRecordsBatch(
11010
11164
  result.records,
11011
11165
  schema
11012
11166
  );
11013
- if (!_optionalChain([options, 'optionalAccess', _215 => _215.skipFormulas])) {
11167
+ if (!_optionalChain([options, 'optionalAccess', _219 => _219.skipFormulas])) {
11014
11168
  return {
11015
11169
  records: enrichRecordsWithFormulas(enrichedRecords, schema),
11016
11170
  total: result.total
@@ -11021,6 +11175,32 @@ var RecordQueryService = class extends BaseService {
11021
11175
  total: result.total
11022
11176
  };
11023
11177
  }
11178
+ // ==========================================================================
11179
+ // Self-healing: ghost record cleanup
11180
+ // ==========================================================================
11181
+ /**
11182
+ * Verify Meilisearch results against PostgreSQL and remove ghost records.
11183
+ * Fire-and-forget cleanup of records that no longer exist in PG.
11184
+ */
11185
+ async healSearchResults(meiliResult) {
11186
+ const { search } = this.adapter;
11187
+ if (!search || meiliResult.records.length === 0) {
11188
+ return meiliResult;
11189
+ }
11190
+ const ids = meiliResult.records.map((r) => r.id);
11191
+ const existing = await this.adapter.objectRecords.findByIds(ids);
11192
+ const existingSet = new Set(existing.map((r) => r.id));
11193
+ const ghosts = ids.filter((id) => !existingSet.has(id));
11194
+ if (ghosts.length > 0) {
11195
+ Promise.all(ghosts.map((id) => search.removeRecord(id))).catch(
11196
+ (err) => console.error("[search] Failed to clean ghost records from per-object search", err)
11197
+ );
11198
+ }
11199
+ return {
11200
+ records: meiliResult.records.filter((r) => existingSet.has(r.id)),
11201
+ total: meiliResult.total - ghosts.length
11202
+ };
11203
+ }
11024
11204
  };
11025
11205
 
11026
11206
  // src/runtime/services/record/record-resolver.service.ts
@@ -11193,7 +11373,7 @@ var RelationService = class extends BaseService {
11193
11373
  }
11194
11374
  const isUniversal = attr.targets.length === 1 && attr.targets[0].object === RELATION_TARGET_ANY;
11195
11375
  const validObjectIds = isUniversal ? null : await this.getValidObjectIds(attr.targets);
11196
- if (!isUniversal && _optionalChain([validObjectIds, 'optionalAccess', _216 => _216.size]) === 0) {
11376
+ if (!isUniversal && _optionalChain([validObjectIds, 'optionalAccess', _220 => _220.size]) === 0) {
11197
11377
  errors.push({
11198
11378
  attribute: attr.name,
11199
11379
  message: `No valid target objects found for ${attr.label}`
@@ -11246,10 +11426,10 @@ var RelationService = class extends BaseService {
11246
11426
  for (const target of targets) {
11247
11427
  try {
11248
11428
  const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
11249
- if (_optionalChain([objectSchema, 'optionalAccess', _217 => _217.id])) {
11429
+ if (_optionalChain([objectSchema, 'optionalAccess', _221 => _221.id])) {
11250
11430
  objectIds.add(objectSchema.id);
11251
11431
  }
11252
- } catch (e15) {
11432
+ } catch (e16) {
11253
11433
  }
11254
11434
  }
11255
11435
  return objectIds;
@@ -11315,7 +11495,7 @@ var RelationService = class extends BaseService {
11315
11495
  const targetResults = await Promise.all(
11316
11496
  filteredTargets.map(async (target) => {
11317
11497
  const objectSchema = await this.schemaService.getObjectSchemaByName(target.object);
11318
- if (!_optionalChain([objectSchema, 'optionalAccess', _218 => _218.id])) return { options: [], total: 0 };
11498
+ if (!_optionalChain([objectSchema, 'optionalAccess', _222 => _222.id])) return { options: [], total: 0 };
11319
11499
  const objectId = objectSchema.id;
11320
11500
  const result = query ? await queryService.searchRecords(objectId, query, queryOptions) : await queryService.listRecords(objectId, queryOptions);
11321
11501
  const options = await Promise.all(
@@ -11472,8 +11652,8 @@ var RelationService = class extends BaseService {
11472
11652
  continue;
11473
11653
  }
11474
11654
  const attribute = attributeMap.get(attributeId);
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]);
11655
+ const targetConfig = _optionalChain([attribute, 'optionalAccess', _223 => _223.targets, 'optionalAccess', _224 => _224.find, 'call', _225 => _225((t) => t.object === objectSchema.name)]);
11656
+ const customTemplate = _optionalChain([targetConfig, 'optionalAccess', _226 => _226.displayTemplate]);
11477
11657
  const label = await this.resolveLabel(record, objectSchema, customTemplate);
11478
11658
  resolved.push({
11479
11659
  _compositeId: compositeId,
@@ -11636,14 +11816,14 @@ var RollupService = class extends BaseService {
11636
11816
  const sourceSchema = getSchemaByNameFromContext(sourceObjectName);
11637
11817
  let sourceObjectId;
11638
11818
  let reverseRelationAttrName;
11639
- if (_optionalChain([sourceSchema, 'optionalAccess', _223 => _223.id])) {
11819
+ if (_optionalChain([sourceSchema, 'optionalAccess', _227 => _227.id])) {
11640
11820
  sourceObjectId = sourceSchema.id;
11641
11821
  const reverseRelationAttr = sourceSchema.attributes.find((attr) => {
11642
11822
  if (attr.type !== "relation") return false;
11643
11823
  const relationConfig = attr;
11644
- return _optionalChain([relationConfig, 'optionalAccess', _224 => _224.targets, 'optionalAccess', _225 => _225.some, 'call', _226 => _226((t) => t.object === schema.name)]);
11824
+ return _optionalChain([relationConfig, 'optionalAccess', _228 => _228.targets, 'optionalAccess', _229 => _229.some, 'call', _230 => _230((t) => t.object === schema.name)]);
11645
11825
  });
11646
- reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _227 => _227.name]);
11826
+ reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _231 => _231.name]);
11647
11827
  } else {
11648
11828
  const sourceObject = await this.adapter.objects.findByName(sourceObjectName);
11649
11829
  if (!sourceObject) {
@@ -11654,9 +11834,9 @@ var RollupService = class extends BaseService {
11654
11834
  const reverseRelationAttr = sourceAttributes.find((attr) => {
11655
11835
  if (attr.type !== "relation") return false;
11656
11836
  const relationConfig = attr.config;
11657
- return _optionalChain([relationConfig, 'optionalAccess', _228 => _228.targets, 'optionalAccess', _229 => _229.some, 'call', _230 => _230((t) => t.object === schema.name)]);
11837
+ return _optionalChain([relationConfig, 'optionalAccess', _232 => _232.targets, 'optionalAccess', _233 => _233.some, 'call', _234 => _234((t) => t.object === schema.name)]);
11658
11838
  });
11659
- reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _231 => _231.name]);
11839
+ reverseRelationAttrName = _optionalChain([reverseRelationAttr, 'optionalAccess', _235 => _235.name]);
11660
11840
  }
11661
11841
  if (!reverseRelationAttrName) {
11662
11842
  return { value: null, recordCount: 0 };
@@ -11841,7 +12021,7 @@ var RollupService = class extends BaseService {
11841
12021
  if (typeof relatedId === "string" && relatedId.length > 0) {
11842
12022
  affectedIds.push(relatedId);
11843
12023
  } else if (Array.isArray(relatedId)) {
11844
- affectedIds.push(...relatedId.filter((id) => typeof id === "string"));
12024
+ affectedIds.push(...relatedId.filter((id) => typeof id === "string" && id.length > 0));
11845
12025
  }
11846
12026
  }
11847
12027
  return [...new Set(affectedIds)];
@@ -11912,13 +12092,13 @@ var RollupService = class extends BaseService {
11912
12092
  if (!obj) continue;
11913
12093
  for (const rollupDbAttr of rollupAttrs) {
11914
12094
  const rollupConfig = rollupDbAttr.config;
11915
- if (!_optionalChain([rollupConfig, 'optionalAccess', _232 => _232.relationAttribute])) continue;
12095
+ if (!_optionalChain([rollupConfig, 'optionalAccess', _236 => _236.relationAttribute])) continue;
11916
12096
  const relationAttr = attributes.find(
11917
12097
  (a) => a.type === "relation" && a.name === rollupConfig.relationAttribute
11918
12098
  );
11919
12099
  if (!relationAttr) continue;
11920
12100
  const relationConfig = relationAttr.config;
11921
- const targetsChangedObject = _optionalChain([relationConfig, 'optionalAccess', _233 => _233.targets, 'optionalAccess', _234 => _234.some, 'call', _235 => _235(
12101
+ const targetsChangedObject = _optionalChain([relationConfig, 'optionalAccess', _237 => _237.targets, 'optionalAccess', _238 => _238.some, 'call', _239 => _239(
11922
12102
  (t) => t.object === changedSchema.name
11923
12103
  )]);
11924
12104
  if (!targetsChangedObject) continue;
@@ -11943,11 +12123,11 @@ var RecordService = class extends BaseService {
11943
12123
  constructor(adapter, options) {
11944
12124
  super(adapter);
11945
12125
  this.schemaService = new ObjectSchemaService(adapter, registry, {
11946
- auditService: _optionalChain([options, 'optionalAccess', _236 => _236.auditService])
12126
+ auditService: _optionalChain([options, 'optionalAccess', _240 => _240.auditService])
11947
12127
  });
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));
12128
+ this.permissionService = _optionalChain([options, 'optionalAccess', _241 => _241.permissionService]);
12129
+ this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _242 => _242.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
12130
+ this.policyRegistry = _optionalChain([options, 'optionalAccess', _243 => _243.policyRegistry]) === null ? null : _nullishCoalesce(_optionalChain([options, 'optionalAccess', _244 => _244.policyRegistry]), () => ( defaultPolicyRegistry));
11951
12131
  this.recordResolver = new RecordResolverService(adapter);
11952
12132
  this.queryService = new RecordQueryService(adapter, this.schemaService, {
11953
12133
  permissionService: this.permissionService,
@@ -11962,7 +12142,7 @@ var RecordService = class extends BaseService {
11962
12142
  recordResolver: this.recordResolver
11963
12143
  });
11964
12144
  this.userService = new UserService(adapter);
11965
- this.hookRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _241 => _241.hookRegistry]), () => ( new NoopHookRegistry()));
12145
+ this.hookRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _245 => _245.hookRegistry]), () => ( new NoopHookRegistry()));
11966
12146
  this.bilateralSyncService = new BilateralSyncService(
11967
12147
  adapter,
11968
12148
  this.schemaService,
@@ -12002,25 +12182,25 @@ var RecordService = class extends BaseService {
12002
12182
  schema,
12003
12183
  this.tenantId,
12004
12184
  dataWithDefaults,
12005
- _optionalChain([options, 'optionalAccess', _242 => _242.hookMetadata])
12185
+ _optionalChain([options, 'optionalAccess', _246 => _246.hookMetadata])
12006
12186
  );
12007
- if (!_optionalChain([options, 'optionalAccess', _243 => _243.skipHooks])) {
12187
+ if (!_optionalChain([options, 'optionalAccess', _247 => _247.skipHooks])) {
12008
12188
  await this.hookRegistry.execute("beforeCreate", schema.name, hookCtx);
12009
12189
  }
12010
12190
  const normalizedData = this.relationPropertiesService.normalizeRelationValuesForStorage(
12011
12191
  schema,
12012
12192
  dataWithDefaults
12013
12193
  );
12014
- if (_optionalChain([options, 'optionalAccess', _244 => _244.validate]) !== false) {
12015
- if (_optionalChain([options, 'optionalAccess', _245 => _245.allowDraft])) {
12194
+ if (_optionalChain([options, 'optionalAccess', _248 => _248.validate]) !== false) {
12195
+ if (_optionalChain([options, 'optionalAccess', _249 => _249.allowDraft])) {
12016
12196
  _chunk3WTK7ESHjs.validateDraftOrThrow.call(void 0, schema, normalizedData);
12017
12197
  } else {
12018
12198
  _chunk3WTK7ESHjs.validateObjectOrThrow.call(void 0, schema, normalizedData);
12019
12199
  }
12020
- if (!_optionalChain([options, 'optionalAccess', _246 => _246.skipRelationValidation])) {
12200
+ if (!_optionalChain([options, 'optionalAccess', _250 => _250.skipRelationValidation])) {
12021
12201
  await this.relationService.validateRelationsOrThrow(schema, normalizedData);
12022
12202
  }
12023
- if (!_optionalChain([options, 'optionalAccess', _247 => _247.skipUserValidation])) {
12203
+ if (!_optionalChain([options, 'optionalAccess', _251 => _251.skipUserValidation])) {
12024
12204
  await this.userService.validateUsersOrThrow(schema, normalizedData);
12025
12205
  }
12026
12206
  }
@@ -12031,12 +12211,12 @@ var RecordService = class extends BaseService {
12031
12211
  data: normalizedData,
12032
12212
  label,
12033
12213
  completionStatus,
12034
- metadata: _optionalChain([options, 'optionalAccess', _248 => _248.metadata]),
12214
+ metadata: _optionalChain([options, 'optionalAccess', _252 => _252.metadata]),
12035
12215
  createdBy: this.userId
12036
12216
  });
12037
12217
  for (const [attrName, value] of Object.entries(dataWithDefaults)) {
12038
12218
  const attr = schema.attributes.find((a) => a.name === attrName);
12039
- if (_optionalChain([attr, 'optionalAccess', _249 => _249.type]) === "relation") {
12219
+ if (_optionalChain([attr, 'optionalAccess', _253 => _253.type]) === "relation") {
12040
12220
  const hasProperties2 = attr.properties !== void 0;
12041
12221
  const isBilateral = isBilateralRelation(attr);
12042
12222
  if (hasProperties2 || isBilateral) {
@@ -12052,7 +12232,7 @@ var RecordService = class extends BaseService {
12052
12232
  }
12053
12233
  for (const [attrName, value] of Object.entries(normalizedData)) {
12054
12234
  const attr = schema.attributes.find((a) => a.name === attrName);
12055
- if (_optionalChain([attr, 'optionalAccess', _250 => _250.type]) === "relation" && isBilateralRelation(attr)) {
12235
+ if (_optionalChain([attr, 'optionalAccess', _254 => _254.type]) === "relation" && isBilateralRelation(attr)) {
12056
12236
  await this.bilateralSyncService.syncBilateralRelation(
12057
12237
  schema,
12058
12238
  record.id,
@@ -12063,7 +12243,7 @@ var RecordService = class extends BaseService {
12063
12243
  );
12064
12244
  }
12065
12245
  }
12066
- if (!_optionalChain([options, 'optionalAccess', _251 => _251.skipHooks])) {
12246
+ if (!_optionalChain([options, 'optionalAccess', _255 => _255.skipHooks])) {
12067
12247
  const afterCtx = {
12068
12248
  ...hookCtx,
12069
12249
  recordId: record.id,
@@ -12073,6 +12253,11 @@ var RecordService = class extends BaseService {
12073
12253
  }
12074
12254
  await recalculateParentRollups(record, schema, this.rollupContext);
12075
12255
  await this.invalidateRecordCaches(record.id, objectId);
12256
+ _optionalChain([this, 'access', _256 => _256.adapter, 'access', _257 => _257.search, 'optionalAccess', _258 => _258.indexRecord, 'call', _259 => _259(record, {
12257
+ objectName: schema.name,
12258
+ objectLabel: schema.label,
12259
+ attributes: schema.attributes
12260
+ }), 'access', _260 => _260.catch, 'call', _261 => _261((err) => console.error("[search] Failed to index created record", record.id, err))]);
12076
12261
  if (this.auditService && this.userId) {
12077
12262
  this.auditService.logRecordAction({
12078
12263
  action: "record.created",
@@ -12081,7 +12266,7 @@ var RecordService = class extends BaseService {
12081
12266
  objectId: schema.id,
12082
12267
  recordId: record.id,
12083
12268
  recordLabel: record.label,
12084
- metadata: _optionalChain([options, 'optionalAccess', _252 => _252.hookMetadata])
12269
+ metadata: _optionalChain([options, 'optionalAccess', _262 => _262.hookMetadata])
12085
12270
  }).catch(() => {
12086
12271
  });
12087
12272
  }
@@ -12104,7 +12289,7 @@ var RecordService = class extends BaseService {
12104
12289
  return null;
12105
12290
  }
12106
12291
  const schema = await this.schemaService.getObjectSchema(record.objectId);
12107
- if (!_optionalChain([options, 'optionalAccess', _253 => _253.skipPolicyCheck])) {
12292
+ if (!_optionalChain([options, 'optionalAccess', _263 => _263.skipPolicyCheck])) {
12108
12293
  const policy = getPolicy(this.policyRegistry, this.userId, schema.name);
12109
12294
  if (policy) {
12110
12295
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
@@ -12114,11 +12299,11 @@ var RecordService = class extends BaseService {
12114
12299
  }
12115
12300
  }
12116
12301
  let enrichedRecord = record;
12117
- if (!_optionalChain([options, 'optionalAccess', _254 => _254.skipFormulas])) {
12302
+ if (!_optionalChain([options, 'optionalAccess', _264 => _264.skipFormulas])) {
12118
12303
  enrichedRecord = enrichWithFormulas(record, schema);
12119
12304
  }
12120
12305
  enrichedRecord = await this.enrichRelationProperties(enrichedRecord, schema);
12121
- if (_optionalChain([options, 'optionalAccess', _255 => _255.includeSchema])) {
12306
+ if (_optionalChain([options, 'optionalAccess', _265 => _265.includeSchema])) {
12122
12307
  const recordWithSchema = enrichedRecord;
12123
12308
  recordWithSchema.schema = schema;
12124
12309
  return recordWithSchema;
@@ -12168,7 +12353,7 @@ var RecordService = class extends BaseService {
12168
12353
  if (oldVal !== null && newVal !== null && typeof oldVal === "object" && typeof newVal === "object") {
12169
12354
  try {
12170
12355
  return JSON.stringify(oldVal) !== JSON.stringify(newVal);
12171
- } catch (e16) {
12356
+ } catch (e17) {
12172
12357
  return true;
12173
12358
  }
12174
12359
  }
@@ -12180,9 +12365,9 @@ var RecordService = class extends BaseService {
12180
12365
  existing,
12181
12366
  mergedData,
12182
12367
  changedAttributes,
12183
- _optionalChain([options, 'optionalAccess', _256 => _256.hookMetadata])
12368
+ _optionalChain([options, 'optionalAccess', _266 => _266.hookMetadata])
12184
12369
  );
12185
- if (!_optionalChain([options, 'optionalAccess', _257 => _257.skipHooks])) {
12370
+ if (!_optionalChain([options, 'optionalAccess', _267 => _267.skipHooks])) {
12186
12371
  await this.hookRegistry.execute("beforeUpdate", schema.name, hookCtx);
12187
12372
  }
12188
12373
  const hookModifiedValues = {};
@@ -12197,16 +12382,16 @@ var RecordService = class extends BaseService {
12197
12382
  dataToUpdate
12198
12383
  );
12199
12384
  const normalizedMergedData = { ...existing.values, ...normalizedUpdate };
12200
- if (_optionalChain([options, 'optionalAccess', _258 => _258.validate]) !== false) {
12201
- if (_optionalChain([options, 'optionalAccess', _259 => _259.partial])) {
12385
+ if (_optionalChain([options, 'optionalAccess', _268 => _268.validate]) !== false) {
12386
+ if (_optionalChain([options, 'optionalAccess', _269 => _269.partial])) {
12202
12387
  _chunk3WTK7ESHjs.validateDraftOrThrow.call(void 0, schema, normalizedMergedData);
12203
12388
  } else {
12204
12389
  _chunk3WTK7ESHjs.validateObjectOrThrow.call(void 0, schema, normalizedMergedData);
12205
12390
  }
12206
- if (!_optionalChain([options, 'optionalAccess', _260 => _260.skipRelationValidation])) {
12391
+ if (!_optionalChain([options, 'optionalAccess', _270 => _270.skipRelationValidation])) {
12207
12392
  await this.relationService.validateRelationsOrThrow(schema, normalizedUpdate);
12208
12393
  }
12209
- if (!_optionalChain([options, 'optionalAccess', _261 => _261.skipUserValidation])) {
12394
+ if (!_optionalChain([options, 'optionalAccess', _271 => _271.skipUserValidation])) {
12210
12395
  await this.userService.validateUsersOrThrow(schema, normalizedUpdate);
12211
12396
  }
12212
12397
  }
@@ -12219,7 +12404,7 @@ var RecordService = class extends BaseService {
12219
12404
  __lastUpdatedBy: this.userId,
12220
12405
  __expectedUpdatedAt: existing.updatedAt instanceof Date ? existing.updatedAt.toISOString() : existing.updatedAt
12221
12406
  };
12222
- if (_optionalChain([options, 'optionalAccess', _262 => _262.metadata]) !== void 0) {
12407
+ if (_optionalChain([options, 'optionalAccess', _272 => _272.metadata]) !== void 0) {
12223
12408
  const existingMetadata = _nullishCoalesce(existing.metadata, () => ( {}));
12224
12409
  const mergedMetadata = { ...existingMetadata, ...options.metadata };
12225
12410
  const cleanedMetadata = Object.fromEntries(
@@ -12230,15 +12415,20 @@ var RecordService = class extends BaseService {
12230
12415
  const bilateralOldValues = {};
12231
12416
  for (const attrName of Object.keys(normalizedUpdate)) {
12232
12417
  const attr = schema.attributes.find((a) => a.name === attrName);
12233
- if (_optionalChain([attr, 'optionalAccess', _263 => _263.type]) === "relation" && isBilateralRelation(attr)) {
12418
+ if (_optionalChain([attr, 'optionalAccess', _273 => _273.type]) === "relation" && isBilateralRelation(attr)) {
12234
12419
  bilateralOldValues[attrName] = existing.values[attrName];
12235
12420
  }
12236
12421
  }
12237
12422
  const updated = await this.adapter.objectRecords.update(recordId, updatePayload);
12238
12423
  await this.invalidateRecordCaches(recordId, existing.objectId);
12424
+ _optionalChain([this, 'access', _274 => _274.adapter, 'access', _275 => _275.search, 'optionalAccess', _276 => _276.indexRecord, 'call', _277 => _277(updated, {
12425
+ objectName: schema.name,
12426
+ objectLabel: schema.label,
12427
+ attributes: schema.attributes
12428
+ }), 'access', _278 => _278.catch, 'call', _279 => _279((err) => console.error("[search] Failed to index updated record", updated.id, err))]);
12239
12429
  for (const [attrName, value] of Object.entries(dataToUpdate)) {
12240
12430
  const attr = schema.attributes.find((a) => a.name === attrName);
12241
- if (_optionalChain([attr, 'optionalAccess', _264 => _264.type]) === "relation") {
12431
+ if (_optionalChain([attr, 'optionalAccess', _280 => _280.type]) === "relation") {
12242
12432
  const hasProperties2 = attr.properties !== void 0;
12243
12433
  const isBilateral = isBilateralRelation(attr);
12244
12434
  if (hasProperties2 || isBilateral) {
@@ -12254,7 +12444,7 @@ var RecordService = class extends BaseService {
12254
12444
  }
12255
12445
  for (const [attrName, value] of Object.entries(normalizedUpdate)) {
12256
12446
  const attr = schema.attributes.find((a) => a.name === attrName);
12257
- if (_optionalChain([attr, 'optionalAccess', _265 => _265.type]) === "relation" && isBilateralRelation(attr)) {
12447
+ if (_optionalChain([attr, 'optionalAccess', _281 => _281.type]) === "relation" && isBilateralRelation(attr)) {
12258
12448
  const oldValue = bilateralOldValues[attrName];
12259
12449
  await this.bilateralSyncService.syncBilateralRelation(
12260
12450
  schema,
@@ -12265,7 +12455,7 @@ var RecordService = class extends BaseService {
12265
12455
  );
12266
12456
  }
12267
12457
  }
12268
- if (!_optionalChain([options, 'optionalAccess', _266 => _266.skipHooks])) {
12458
+ if (!_optionalChain([options, 'optionalAccess', _282 => _282.skipHooks])) {
12269
12459
  const afterCtx = {
12270
12460
  ...hookCtx,
12271
12461
  record: updated
@@ -12280,7 +12470,7 @@ var RecordService = class extends BaseService {
12280
12470
  if (this.auditService && this.userId && allChangedAttributes.length > 0) {
12281
12471
  const changes = allChangedAttributes.map((attr) => ({
12282
12472
  field: attr,
12283
- oldValue: _optionalChain([hookCtx, 'access', _267 => _267.oldValues, 'optionalAccess', _268 => _268[attr]]),
12473
+ oldValue: _optionalChain([hookCtx, 'access', _283 => _283.oldValues, 'optionalAccess', _284 => _284[attr]]),
12284
12474
  newValue: hookCtx.newValues[attr]
12285
12475
  }));
12286
12476
  this.auditService.logRecordAction({
@@ -12291,7 +12481,7 @@ var RecordService = class extends BaseService {
12291
12481
  recordId: updated.id,
12292
12482
  recordLabel: updated.label,
12293
12483
  changes,
12294
- metadata: _optionalChain([options, 'optionalAccess', _269 => _269.hookMetadata])
12484
+ metadata: _optionalChain([options, 'optionalAccess', _285 => _285.hookMetadata])
12295
12485
  }).catch(() => {
12296
12486
  });
12297
12487
  }
@@ -12323,17 +12513,17 @@ var RecordService = class extends BaseService {
12323
12513
  const ctx = buildPolicyContext(schema.name, this.userId, this.tenantId);
12324
12514
  checkRecordDeleteOrThrow(policy, record, ctx);
12325
12515
  }
12326
- if (_optionalChain([options, 'optionalAccess', _270 => _270.checkSystem]) && schema.system) {
12516
+ if (_optionalChain([options, 'optionalAccess', _286 => _286.checkSystem]) && schema.system) {
12327
12517
  throw new ProtectedResourceError("object", schema.name, "delete");
12328
12518
  }
12329
- if (!_optionalChain([options, 'optionalAccess', _271 => _271.skipReferenceCheck])) {
12519
+ if (!_optionalChain([options, 'optionalAccess', _287 => _287.skipReferenceCheck])) {
12330
12520
  const references = await this.adapter.objectRecords.countRecordsReferencingId(recordId);
12331
12521
  if (references.length > 0) {
12332
12522
  throw new RecordReferencedError(recordId, references);
12333
12523
  }
12334
12524
  }
12335
- const hookCtx = createContextForDelete(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _272 => _272.hookMetadata]));
12336
- if (!_optionalChain([options, 'optionalAccess', _273 => _273.skipHooks])) {
12525
+ const hookCtx = createContextForDelete(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _288 => _288.hookMetadata]));
12526
+ if (!_optionalChain([options, 'optionalAccess', _289 => _289.skipHooks])) {
12337
12527
  await this.hookRegistry.execute("beforeDelete", schema.name, hookCtx);
12338
12528
  }
12339
12529
  for (const attr of schema.attributes) {
@@ -12351,7 +12541,8 @@ var RecordService = class extends BaseService {
12351
12541
  }
12352
12542
  await this.adapter.objectRecords.delete(recordId);
12353
12543
  await this.invalidateRecordCaches(recordId, record.objectId);
12354
- if (!_optionalChain([options, 'optionalAccess', _274 => _274.skipHooks])) {
12544
+ _optionalChain([this, 'access', _290 => _290.adapter, 'access', _291 => _291.search, 'optionalAccess', _292 => _292.removeRecord, 'call', _293 => _293(recordId), 'access', _294 => _294.catch, 'call', _295 => _295((err) => console.error("[search] Failed to remove deleted record", recordId, err))]);
12545
+ if (!_optionalChain([options, 'optionalAccess', _296 => _296.skipHooks])) {
12355
12546
  await this.hookRegistry.execute("afterDelete", schema.name, hookCtx);
12356
12547
  }
12357
12548
  await recalculateParentRollups(record, schema, this.rollupContext);
@@ -12363,7 +12554,7 @@ var RecordService = class extends BaseService {
12363
12554
  objectId: schema.id,
12364
12555
  recordId: record.id,
12365
12556
  recordLabel: record.label,
12366
- metadata: _optionalChain([options, 'optionalAccess', _275 => _275.hookMetadata])
12557
+ metadata: _optionalChain([options, 'optionalAccess', _297 => _297.hookMetadata])
12367
12558
  }).catch(() => {
12368
12559
  });
12369
12560
  }
@@ -12424,13 +12615,18 @@ var RecordService = class extends BaseService {
12424
12615
  this.tenantId
12425
12616
  );
12426
12617
  await checkPermission(this.permissionService, this.userId, schema.name, "update");
12427
- const hookCtx = createContextForRestore(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _276 => _276.hookMetadata]));
12428
- if (!_optionalChain([options, 'optionalAccess', _277 => _277.skipHooks])) {
12618
+ const hookCtx = createContextForRestore(schema, this.tenantId, record, _optionalChain([options, 'optionalAccess', _298 => _298.hookMetadata]));
12619
+ if (!_optionalChain([options, 'optionalAccess', _299 => _299.skipHooks])) {
12429
12620
  await this.hookRegistry.execute("beforeRestore", schema.name, hookCtx);
12430
12621
  }
12431
12622
  const restored = await this.adapter.objectRecords.restore(recordId);
12432
12623
  await this.invalidateRecordCaches(recordId, record.objectId);
12433
- if (!_optionalChain([options, 'optionalAccess', _278 => _278.skipHooks])) {
12624
+ _optionalChain([this, 'access', _300 => _300.adapter, 'access', _301 => _301.search, 'optionalAccess', _302 => _302.indexRecord, 'call', _303 => _303(restored, {
12625
+ objectName: schema.name,
12626
+ objectLabel: schema.label,
12627
+ attributes: schema.attributes
12628
+ }), 'access', _304 => _304.catch, 'call', _305 => _305((err) => console.error("[search] Failed to index restored record", restored.id, err))]);
12629
+ if (!_optionalChain([options, 'optionalAccess', _306 => _306.skipHooks])) {
12434
12630
  const afterCtx = {
12435
12631
  ...hookCtx,
12436
12632
  record: restored
@@ -12445,7 +12641,7 @@ var RecordService = class extends BaseService {
12445
12641
  objectId: schema.id,
12446
12642
  recordId: restored.id,
12447
12643
  recordLabel: restored.label,
12448
- metadata: _optionalChain([options, 'optionalAccess', _279 => _279.hookMetadata])
12644
+ metadata: _optionalChain([options, 'optionalAccess', _307 => _307.hookMetadata])
12449
12645
  }).catch(() => {
12450
12646
  });
12451
12647
  }
@@ -12876,7 +13072,7 @@ var DocumentRendererService = class {
12876
13072
  throw new StorageDownloadNotSupportedError();
12877
13073
  }
12878
13074
  let storagePath = fileId;
12879
- if (_optionalChain([this, 'access', _280 => _280.options, 'optionalAccess', _281 => _281.filesRepository])) {
13075
+ if (_optionalChain([this, 'access', _308 => _308.options, 'optionalAccess', _309 => _309.filesRepository])) {
12880
13076
  const file2 = await this.options.filesRepository.findById(fileId);
12881
13077
  if (!file2) {
12882
13078
  throw new Error(`Template file not found: ${fileId}`);
@@ -12894,8 +13090,8 @@ var DocumentRendererService = class {
12894
13090
  for (const field of fields) {
12895
13091
  const rawValue = getContextValue(context, field.contextPath);
12896
13092
  const attrInfo = await this.getAttributeInfo(field.contextPath, workflow2);
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])) {
13093
+ if (_optionalChain([attrInfo, 'optionalAccess', _310 => _310.attribute])) {
13094
+ if (attrInfo.attribute.type === "relation" && rawValue && _optionalChain([this, 'access', _311 => _311.options, 'optionalAccess', _312 => _312.relationService])) {
12899
13095
  const ids = Array.isArray(rawValue) ? rawValue : [rawValue];
12900
13096
  const stringIds = ids.filter((id) => typeof id === "string");
12901
13097
  if (stringIds.length > 0) {
@@ -12916,7 +13112,7 @@ var DocumentRendererService = class {
12916
13112
  resolved.set(field.id, this.formatValueSimple(rawValue, field.fallback));
12917
13113
  }
12918
13114
  }
12919
- if (relationBatch.length > 0 && _optionalChain([this, 'access', _285 => _285.options, 'optionalAccess', _286 => _286.relationService])) {
13115
+ if (relationBatch.length > 0 && _optionalChain([this, 'access', _313 => _313.options, 'optionalAccess', _314 => _314.relationService])) {
12920
13116
  try {
12921
13117
  const batchResult = await this.options.relationService.resolveIdsBatch(
12922
13118
  relationBatch.map((r) => ({ attributeId: r.attributeId, ids: r.ids }))
@@ -12925,12 +13121,12 @@ var DocumentRendererService = class {
12925
13121
  const options = _nullishCoalesce(batchResult[attributeId], () => ( []));
12926
13122
  const labels = options.map((o) => o.label);
12927
13123
  const field = fields.find((f) => f.id === fieldId);
12928
- resolved.set(fieldId, labels.join(", ") || _optionalChain([field, 'optionalAccess', _287 => _287.fallback]) || "");
13124
+ resolved.set(fieldId, labels.join(", ") || _optionalChain([field, 'optionalAccess', _315 => _315.fallback]) || "");
12929
13125
  }
12930
- } catch (e17) {
13126
+ } catch (e18) {
12931
13127
  for (const { fieldId, ids } of relationBatch) {
12932
13128
  const field = fields.find((f) => f.id === fieldId);
12933
- resolved.set(fieldId, ids.join(", ") || _optionalChain([field, 'optionalAccess', _288 => _288.fallback]) || "");
13129
+ resolved.set(fieldId, ids.join(", ") || _optionalChain([field, 'optionalAccess', _316 => _316.fallback]) || "");
12934
13130
  }
12935
13131
  }
12936
13132
  }
@@ -12941,7 +13137,7 @@ var DocumentRendererService = class {
12941
13137
  * Parses paths like "slots.client.firstName" to find the attribute definition
12942
13138
  */
12943
13139
  async getAttributeInfo(contextPath, workflow2) {
12944
- const schemaService = _optionalChain([this, 'access', _289 => _289.options, 'optionalAccess', _290 => _290.schemaService]);
13140
+ const schemaService = _optionalChain([this, 'access', _317 => _317.options, 'optionalAccess', _318 => _318.schemaService]);
12945
13141
  if (!schemaService) {
12946
13142
  return null;
12947
13143
  }
@@ -12954,7 +13150,7 @@ var DocumentRendererService = class {
12954
13150
  }
12955
13151
  const slotId = parts[1];
12956
13152
  const attributeName = parts[2];
12957
- const slot = _optionalChain([workflow2, 'access', _291 => _291.slots, 'optionalAccess', _292 => _292.find, 'call', _293 => _293((s) => s.id === slotId)]);
13153
+ const slot = _optionalChain([workflow2, 'access', _319 => _319.slots, 'optionalAccess', _320 => _320.find, 'call', _321 => _321((s) => s.id === slotId)]);
12958
13154
  if (!slot) {
12959
13155
  return null;
12960
13156
  }
@@ -12963,7 +13159,7 @@ var DocumentRendererService = class {
12963
13159
  try {
12964
13160
  schema = await schemaService.getObjectSchemaByName(slot.objectName);
12965
13161
  this.schemaCache.set(slot.objectName, schema);
12966
- } catch (e18) {
13162
+ } catch (e19) {
12967
13163
  return null;
12968
13164
  }
12969
13165
  }
@@ -13153,7 +13349,7 @@ var DocumentProcessingHook = class extends BaseService {
13153
13349
  const pendingIds = [];
13154
13350
  for (const [nodeId, doc] of Object.entries(context.documents)) {
13155
13351
  const metadata = doc.metadata;
13156
- if (_optionalChain([metadata, 'optionalAccess', _294 => _294.status]) === "pending") {
13352
+ if (_optionalChain([metadata, 'optionalAccess', _322 => _322.status]) === "pending") {
13157
13353
  pendingIds.push(nodeId);
13158
13354
  }
13159
13355
  }
@@ -13204,12 +13400,12 @@ var DocumentProcessingHook = class extends BaseService {
13204
13400
  }
13205
13401
  for (const slotId of targetSlotIds) {
13206
13402
  try {
13207
- const recordId = _optionalChain([context, 'access', _295 => _295.createdRecordIds, 'optionalAccess', _296 => _296[slotId]]);
13403
+ const recordId = _optionalChain([context, 'access', _323 => _323.createdRecordIds, 'optionalAccess', _324 => _324[slotId]]);
13208
13404
  if (!recordId) {
13209
13405
  continue;
13210
13406
  }
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]);
13407
+ const slotDef = _optionalChain([workflow2, 'access', _325 => _325.slots, 'optionalAccess', _326 => _326.find, 'call', _327 => _327((s) => s.id === slotId)]);
13408
+ const objectName = _optionalChain([slotDef, 'optionalAccess', _328 => _328.objectName]);
13213
13409
  if (!objectName) {
13214
13410
  continue;
13215
13411
  }
@@ -13226,14 +13422,14 @@ var DocumentProcessingHook = class extends BaseService {
13226
13422
  attachedDocumentIds.push(result.document.id);
13227
13423
  const record = await recordService.getRecord(recordId);
13228
13424
  if (record) {
13229
- const attachments = _nullishCoalesce(_optionalChain([record, 'access', _301 => _301.values, 'optionalAccess', _302 => _302.attachments]), () => ( []));
13425
+ const attachments = _nullishCoalesce(_optionalChain([record, 'access', _329 => _329.values, 'optionalAccess', _330 => _330.attachments]), () => ( []));
13230
13426
  await recordService.updateRecord(
13231
13427
  recordId,
13232
13428
  { attachments: [...attachments, result.document.id] },
13233
13429
  { partial: true }
13234
13430
  );
13235
13431
  }
13236
- } catch (e19) {
13432
+ } catch (e20) {
13237
13433
  }
13238
13434
  }
13239
13435
  return attachedDocumentIds;
@@ -13492,7 +13688,7 @@ var WorkflowAccessGrantService = class extends BaseService {
13492
13688
  * Check if a specific token has been revoked.
13493
13689
  */
13494
13690
  isTokenRevoked(dbGrant, jti) {
13495
- return _nullishCoalesce(_optionalChain([dbGrant, 'access', _303 => _303.revoked_token_jtis, 'optionalAccess', _304 => _304.includes, 'call', _305 => _305(jti)]), () => ( false));
13691
+ return _nullishCoalesce(_optionalChain([dbGrant, 'access', _331 => _331.revoked_token_jtis, 'optionalAccess', _332 => _332.includes, 'call', _333 => _333(jti)]), () => ( false));
13496
13692
  }
13497
13693
  /**
13498
13694
  * Validate access token payload against the grant.
@@ -13544,10 +13740,10 @@ var WorkflowInstanceService = class extends BaseService {
13544
13740
  constructor(adapter, workflowService, options) {
13545
13741
  super(adapter);
13546
13742
  this.workflowService = workflowService;
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]);
13743
+ this.executorRegistry = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _334 => _334.executorRegistry]), () => ( getDefaultExecutorRegistry()));
13744
+ this.schemaService = _optionalChain([options, 'optionalAccess', _335 => _335.schemaService]);
13745
+ this.recordService = _optionalChain([options, 'optionalAccess', _336 => _336.recordService]);
13746
+ this.documentProcessingHook = _optionalChain([options, 'optionalAccess', _337 => _337.documentProcessingHook]);
13551
13747
  }
13552
13748
  /**
13553
13749
  * Start a new workflow instance
@@ -13729,7 +13925,7 @@ var WorkflowInstanceService = class extends BaseService {
13729
13925
  if (!this.adapter.workflowInstances) {
13730
13926
  return { instances: [], total: 0 };
13731
13927
  }
13732
- if (_optionalChain([options, 'optionalAccess', _310 => _310.workflowName])) {
13928
+ if (_optionalChain([options, 'optionalAccess', _338 => _338.workflowName])) {
13733
13929
  const allDbInstances = await this.adapter.workflowInstances.findByWorkflowName(
13734
13930
  options.workflowName,
13735
13931
  { status: options.status }
@@ -13743,11 +13939,11 @@ var WorkflowInstanceService = class extends BaseService {
13743
13939
  return { instances: instances2, total: total2 };
13744
13940
  }
13745
13941
  const { instances: dbInstances, total } = await this.adapter.workflowInstances.list({
13746
- limit: _optionalChain([options, 'optionalAccess', _311 => _311.limit]),
13747
- offset: _optionalChain([options, 'optionalAccess', _312 => _312.offset])
13942
+ limit: _optionalChain([options, 'optionalAccess', _339 => _339.limit]),
13943
+ offset: _optionalChain([options, 'optionalAccess', _340 => _340.offset])
13748
13944
  });
13749
13945
  let instances = dbInstances.map((db) => this.convertDBInstanceToInstance(db));
13750
- if (_optionalChain([options, 'optionalAccess', _313 => _313.status])) {
13946
+ if (_optionalChain([options, 'optionalAccess', _341 => _341.status])) {
13751
13947
  instances = instances.filter((i) => i.status === options.status);
13752
13948
  }
13753
13949
  instances = await this.markExpiredInstances(instances);
@@ -13768,9 +13964,9 @@ var WorkflowInstanceService = class extends BaseService {
13768
13964
  return { instances: [], total: 0 };
13769
13965
  }
13770
13966
  const { instances: dbInstances, total } = await this.adapter.workflowInstances.findByRecordInSlots(objectName, recordId, {
13771
- status: _optionalChain([options, 'optionalAccess', _314 => _314.status]),
13772
- limit: _optionalChain([options, 'optionalAccess', _315 => _315.limit]),
13773
- offset: _optionalChain([options, 'optionalAccess', _316 => _316.offset])
13967
+ status: _optionalChain([options, 'optionalAccess', _342 => _342.status]),
13968
+ limit: _optionalChain([options, 'optionalAccess', _343 => _343.limit]),
13969
+ offset: _optionalChain([options, 'optionalAccess', _344 => _344.offset])
13774
13970
  });
13775
13971
  const instances = dbInstances.map((db) => this.convertDBInstanceToInstance(db));
13776
13972
  return { instances, total };
@@ -13836,13 +14032,13 @@ var WorkflowInstanceService = class extends BaseService {
13836
14032
  try {
13837
14033
  const schemas = await Promise.all(
13838
14034
  current.workflowSnapshot.slots.map(
13839
- (slot) => _optionalChain([this, 'access', _317 => _317.schemaService, 'optionalAccess', _318 => _318.getObjectSchemaByName, 'call', _319 => _319(slot.objectName)])
14035
+ (slot) => _optionalChain([this, 'access', _345 => _345.schemaService, 'optionalAccess', _346 => _346.getObjectSchemaByName, 'call', _347 => _347(slot.objectName)])
13840
14036
  )
13841
14037
  );
13842
14038
  objectDefinitions = schemas.filter(
13843
14039
  (s) => s !== void 0
13844
14040
  );
13845
- } catch (e20) {
14041
+ } catch (e21) {
13846
14042
  }
13847
14043
  }
13848
14044
  const executorContext = {
@@ -14101,9 +14297,9 @@ var WorkflowInstanceService = class extends BaseService {
14101
14297
  */
14102
14298
  async snapshotRecord(recordId) {
14103
14299
  try {
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]);
14106
- } catch (e21) {
14300
+ const record = await _optionalChain([this, 'access', _348 => _348.recordService, 'optionalAccess', _349 => _349.getRecord, 'call', _350 => _350(recordId, { skipPolicyCheck: true })]);
14301
+ return _optionalChain([record, 'optionalAccess', _351 => _351.values]);
14302
+ } catch (e22) {
14107
14303
  return void 0;
14108
14304
  }
14109
14305
  }
@@ -14121,18 +14317,18 @@ var WorkflowInstanceService = class extends BaseService {
14121
14317
  for (const op of [...operations].reverse()) {
14122
14318
  try {
14123
14319
  if (op.operation === "create") {
14124
- await _optionalChain([this, 'access', _324 => _324.recordService, 'optionalAccess', _325 => _325.deleteRecord, 'call', _326 => _326(op.recordId, {
14320
+ await _optionalChain([this, 'access', _352 => _352.recordService, 'optionalAccess', _353 => _353.deleteRecord, 'call', _354 => _354(op.recordId, {
14125
14321
  skipHooks: true,
14126
14322
  skipReferenceCheck: true
14127
14323
  })]);
14128
14324
  rolledBack.push(op.slotId);
14129
14325
  } else if (op.operation === "update" && op.previousData) {
14130
- await _optionalChain([this, 'access', _327 => _327.recordService, 'optionalAccess', _328 => _328.updateRecord, 'call', _329 => _329(op.recordId, op.previousData, {
14326
+ await _optionalChain([this, 'access', _355 => _355.recordService, 'optionalAccess', _356 => _356.updateRecord, 'call', _357 => _357(op.recordId, op.previousData, {
14131
14327
  partial: false
14132
14328
  })]);
14133
14329
  rolledBack.push(op.slotId);
14134
14330
  }
14135
- } catch (e22) {
14331
+ } catch (e23) {
14136
14332
  }
14137
14333
  }
14138
14334
  return rolledBack;
@@ -14251,7 +14447,7 @@ var WorkflowInstanceService = class extends BaseService {
14251
14447
  if (!this.adapter.workflowInstances) {
14252
14448
  return;
14253
14449
  }
14254
- const currentVersion = _nullishCoalesce(_optionalChain([instance, 'access', _330 => _330.context, 'access', _331 => _331.variables, 'optionalAccess', _332 => _332.__version]), () => ( 0));
14450
+ const currentVersion = _nullishCoalesce(_optionalChain([instance, 'access', _358 => _358.context, 'access', _359 => _359.variables, 'optionalAccess', _360 => _360.__version]), () => ( 0));
14255
14451
  const nextVersion = currentVersion + 1;
14256
14452
  const instanceWithVersion = {
14257
14453
  ...instance,
@@ -14532,7 +14728,7 @@ var WorkflowRelationService = class extends BaseService {
14532
14728
  if (attr.type !== "relation") continue;
14533
14729
  for (const slot of slots) {
14534
14730
  const slotData = context.slots[slot.id];
14535
- const slotRecordId = _optionalChain([slotData, 'optionalAccess', _333 => _333.id]);
14731
+ const slotRecordId = _optionalChain([slotData, 'optionalAccess', _361 => _361.id]);
14536
14732
  if (!slotRecordId) continue;
14537
14733
  const targetsSlotObject = attr.targets.some(
14538
14734
  (t) => t.object === slot.objectName
@@ -14600,7 +14796,7 @@ var WorkflowService = class extends BaseService {
14600
14796
  if (Array.isArray(options)) {
14601
14797
  this.systemWorkflows = new Map(options.map((w) => [w.name, w]));
14602
14798
  } else {
14603
- this.systemWorkflows = new Map((_nullishCoalesce(_optionalChain([options, 'optionalAccess', _334 => _334.systemWorkflows]), () => ( []))).map((w) => [w.name, w]));
14799
+ this.systemWorkflows = new Map((_nullishCoalesce(_optionalChain([options, 'optionalAccess', _362 => _362.systemWorkflows]), () => ( []))).map((w) => [w.name, w]));
14604
14800
  }
14605
14801
  }
14606
14802
  // ============================================================================
@@ -14898,7 +15094,7 @@ var WorkflowService = class extends BaseService {
14898
15094
  var UserProfileService = class extends BaseService {
14899
15095
  constructor(adapter, options) {
14900
15096
  super(adapter);
14901
- this.auditService = _optionalChain([options, 'optionalAccess', _335 => _335.auditService]);
15097
+ this.auditService = _optionalChain([options, 'optionalAccess', _363 => _363.auditService]);
14902
15098
  }
14903
15099
  // ============================================================================
14904
15100
  // CACHE MANAGEMENT
@@ -15058,7 +15254,7 @@ var UserProfileService = class extends BaseService {
15058
15254
  */
15059
15255
  async deleteProfile(profileId, options) {
15060
15256
  const profile = await this.getProfileOrThrow(profileId);
15061
- if (_optionalChain([options, 'optionalAccess', _336 => _336.checkAdmin]) && this.adapter.permissions) {
15257
+ if (_optionalChain([options, 'optionalAccess', _364 => _364.checkAdmin]) && this.adapter.permissions) {
15062
15258
  const ownerCount = await this.adapter.permissions.countUsersWithRole("owner");
15063
15259
  if (ownerCount <= 1) {
15064
15260
  const userRoles = await this.adapter.permissions.getUserRoles(profileId);
@@ -15546,7 +15742,7 @@ var DocumentTemplateService = class extends BaseService {
15546
15742
  * Includes both system templates and tenant-specific templates.
15547
15743
  */
15548
15744
  async listTemplates(options) {
15549
- if (_optionalChain([options, 'optionalAccess', _337 => _337.systemOnly])) {
15745
+ if (_optionalChain([options, 'optionalAccess', _365 => _365.systemOnly])) {
15550
15746
  return SYSTEM_TEMPLATES;
15551
15747
  }
15552
15748
  const templates = [...SYSTEM_TEMPLATES];
@@ -15629,8 +15825,8 @@ var DocumentTemplateService = class extends BaseService {
15629
15825
  var DocumentService = class extends BaseService {
15630
15826
  constructor(adapter, options) {
15631
15827
  super(adapter);
15632
- this.templateService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _338 => _338.templateService]), () => ( new DocumentTemplateService(adapter)));
15633
- this.fileService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _339 => _339.fileService]), () => ( null));
15828
+ this.templateService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _366 => _366.templateService]), () => ( new DocumentTemplateService(adapter)));
15829
+ this.fileService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _367 => _367.fileService]), () => ( null));
15634
15830
  }
15635
15831
  // ============================================================================
15636
15832
  // CREATE
@@ -15881,7 +16077,7 @@ var DocumentService = class extends BaseService {
15881
16077
  */
15882
16078
  async isComplete(documentId) {
15883
16079
  const document2 = await this.getDocument(documentId);
15884
- return _optionalChain([document2, 'optionalAccess', _340 => _340.status]) !== "draft";
16080
+ return _optionalChain([document2, 'optionalAccess', _368 => _368.status]) !== "draft";
15885
16081
  }
15886
16082
  /**
15887
16083
  * Get document with its template and slots.
@@ -16139,7 +16335,7 @@ var DocumentProcessingService = class extends BaseService {
16139
16335
  type: "signature",
16140
16336
  provider: this.config.signatureAdapter.name,
16141
16337
  input: { signers, ...options },
16142
- expiresAt: _optionalChain([options, 'optionalAccess', _341 => _341.expiresAt])
16338
+ expiresAt: _optionalChain([options, 'optionalAccess', _369 => _369.expiresAt])
16143
16339
  });
16144
16340
  return job;
16145
16341
  }
@@ -16296,7 +16492,7 @@ var DocumentProcessingService = class extends BaseService {
16296
16492
  }
16297
16493
  const document2 = await this.documentService.getDocumentOrThrow(documentId);
16298
16494
  const template = await this.templateService.getTemplateOrThrow(document2.templateId);
16299
- if (!_optionalChain([template, 'access', _342 => _342.autoProcessing, 'optionalAccess', _343 => _343.identityVerification, 'optionalAccess', _344 => _344.enabled])) {
16495
+ if (!_optionalChain([template, 'access', _370 => _370.autoProcessing, 'optionalAccess', _371 => _371.identityVerification, 'optionalAccess', _372 => _372.enabled])) {
16300
16496
  throw new Error("Identity verification is not enabled for this document type");
16301
16497
  }
16302
16498
  const job = await this.adapter.documentJobs.create({
@@ -16382,13 +16578,13 @@ var DocumentProcessingService = class extends BaseService {
16382
16578
  const template = await this.templateService.getTemplateOrThrow(document2.templateId);
16383
16579
  const slots = await this.documentService.getSlots(documentId);
16384
16580
  const jobs = [];
16385
- if (_optionalChain([template, 'access', _345 => _345.autoProcessing, 'optionalAccess', _346 => _346.ocr, 'optionalAccess', _347 => _347.enabled]) && this.config.ocrAdapter) {
16581
+ if (_optionalChain([template, 'access', _373 => _373.autoProcessing, 'optionalAccess', _374 => _374.ocr, 'optionalAccess', _375 => _375.enabled]) && this.config.ocrAdapter) {
16386
16582
  for (const slot of slots) {
16387
16583
  const job = await this.processOcr(documentId, slot.slotName);
16388
16584
  jobs.push(job);
16389
16585
  }
16390
16586
  }
16391
- if (_optionalChain([template, 'access', _348 => _348.autoProcessing, 'optionalAccess', _349 => _349.identityVerification, 'optionalAccess', _350 => _350.enabled]) && this.config.identityAdapter) {
16587
+ if (_optionalChain([template, 'access', _376 => _376.autoProcessing, 'optionalAccess', _377 => _377.identityVerification, 'optionalAccess', _378 => _378.enabled]) && this.config.identityAdapter) {
16392
16588
  const job = await this.verifyIdentity(documentId);
16393
16589
  jobs.push(job);
16394
16590
  }
@@ -16459,15 +16655,15 @@ var DocumentProcessingService = class extends BaseService {
16459
16655
  return {
16460
16656
  ocr: {
16461
16657
  available: !!this.config.ocrAdapter,
16462
- provider: _optionalChain([this, 'access', _351 => _351.config, 'access', _352 => _352.ocrAdapter, 'optionalAccess', _353 => _353.name])
16658
+ provider: _optionalChain([this, 'access', _379 => _379.config, 'access', _380 => _380.ocrAdapter, 'optionalAccess', _381 => _381.name])
16463
16659
  },
16464
16660
  signature: {
16465
16661
  available: !!this.config.signatureAdapter,
16466
- provider: _optionalChain([this, 'access', _354 => _354.config, 'access', _355 => _355.signatureAdapter, 'optionalAccess', _356 => _356.name])
16662
+ provider: _optionalChain([this, 'access', _382 => _382.config, 'access', _383 => _383.signatureAdapter, 'optionalAccess', _384 => _384.name])
16467
16663
  },
16468
16664
  identityVerification: {
16469
16665
  available: !!this.config.identityAdapter,
16470
- provider: _optionalChain([this, 'access', _357 => _357.config, 'access', _358 => _358.identityAdapter, 'optionalAccess', _359 => _359.name])
16666
+ provider: _optionalChain([this, 'access', _385 => _385.config, 'access', _386 => _386.identityAdapter, 'optionalAccess', _387 => _387.name])
16471
16667
  }
16472
16668
  };
16473
16669
  }
@@ -16477,7 +16673,7 @@ var DocumentProcessingService = class extends BaseService {
16477
16673
  var FileService = class extends BaseService {
16478
16674
  constructor(adapter, options) {
16479
16675
  super(adapter);
16480
- this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _360 => _360.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
16676
+ this.auditService = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _388 => _388.auditService]), () => ( (adapter.audit ? new AuditService(adapter) : void 0)));
16481
16677
  }
16482
16678
  // ============================================================================
16483
16679
  // UPLOAD (requires StorageAdapter)
@@ -16616,7 +16812,7 @@ var FileService = class extends BaseService {
16616
16812
  */
16617
16813
  async getFile(fileId) {
16618
16814
  const file2 = await this.adapter.files.findById(fileId);
16619
- if (_optionalChain([file2, 'optionalAccess', _361 => _361.deletedAt])) {
16815
+ if (_optionalChain([file2, 'optionalAccess', _389 => _389.deletedAt])) {
16620
16816
  return null;
16621
16817
  }
16622
16818
  return file2;
@@ -16678,12 +16874,12 @@ var FileService = class extends BaseService {
16678
16874
  */
16679
16875
  async deleteFile(fileId, options) {
16680
16876
  const file2 = await this.getFileOrThrow(fileId);
16681
- if (_optionalChain([options, 'optionalAccess', _362 => _362.checkOwnership]) && options.userId) {
16877
+ if (_optionalChain([options, 'optionalAccess', _390 => _390.checkOwnership]) && options.userId) {
16682
16878
  if (file2.uploadedBy !== options.userId) {
16683
16879
  throw new Error("You can only delete files you uploaded");
16684
16880
  }
16685
16881
  }
16686
- if (_optionalChain([options, 'optionalAccess', _363 => _363.hard])) {
16882
+ if (_optionalChain([options, 'optionalAccess', _391 => _391.hard])) {
16687
16883
  await this.adapter.files.hardDelete(fileId);
16688
16884
  } else {
16689
16885
  await this.adapter.files.delete(fileId);
@@ -16714,7 +16910,7 @@ var FileService = class extends BaseService {
16714
16910
  }
16715
16911
  const file2 = await this.getFileOrThrow(fileId);
16716
16912
  await this.adapter.storage.delete(file2.storagePath);
16717
- if (_optionalChain([options, 'optionalAccess', _364 => _364.hard])) {
16913
+ if (_optionalChain([options, 'optionalAccess', _392 => _392.hard])) {
16718
16914
  await this.adapter.files.hardDelete(fileId);
16719
16915
  } else {
16720
16916
  await this.adapter.files.delete(fileId);
@@ -16740,15 +16936,15 @@ var FileService = class extends BaseService {
16740
16936
  const fileResults = await Promise.all(fileIds.map((id) => this.getFile(id)));
16741
16937
  const files = fileResults.filter((f) => f !== null);
16742
16938
  if (files.length === 0) return;
16743
- if (_optionalChain([options, 'optionalAccess', _365 => _365.deleteFromStorage]) && this.adapter.storage) {
16939
+ if (_optionalChain([options, 'optionalAccess', _393 => _393.deleteFromStorage]) && this.adapter.storage) {
16744
16940
  const BATCH_SIZE = 10;
16745
16941
  for (let i = 0; i < files.length; i += BATCH_SIZE) {
16746
16942
  const batch = files.slice(i, i + BATCH_SIZE);
16747
- await Promise.all(batch.map((file2) => _optionalChain([this, 'access', _366 => _366.adapter, 'access', _367 => _367.storage, 'optionalAccess', _368 => _368.delete, 'call', _369 => _369(file2.storagePath)])));
16943
+ await Promise.all(batch.map((file2) => _optionalChain([this, 'access', _394 => _394.adapter, 'access', _395 => _395.storage, 'optionalAccess', _396 => _396.delete, 'call', _397 => _397(file2.storagePath)])));
16748
16944
  }
16749
16945
  }
16750
16946
  const idsToDelete = files.map((f) => f.id);
16751
- if (_optionalChain([options, 'optionalAccess', _370 => _370.hard])) {
16947
+ if (_optionalChain([options, 'optionalAccess', _398 => _398.hard])) {
16752
16948
  await Promise.all(idsToDelete.map((id) => this.adapter.files.hardDelete(id)));
16753
16949
  } else {
16754
16950
  await Promise.all(idsToDelete.map((id) => this.adapter.files.delete(id)));
@@ -16756,12 +16952,12 @@ var FileService = class extends BaseService {
16756
16952
  if (this.auditService && this.userId) {
16757
16953
  await Promise.all(
16758
16954
  files.map(
16759
- (file2) => _optionalChain([this, 'access', _371 => _371.auditService, 'optionalAccess', _372 => _372.logFileAction, 'call', _373 => _373({
16955
+ (file2) => _optionalChain([this, 'access', _399 => _399.auditService, 'optionalAccess', _400 => _400.logFileAction, 'call', _401 => _401({
16760
16956
  action: "file.deleted",
16761
16957
  actorId: _nullishCoalesce(this.userId, () => ( "")),
16762
16958
  fileId: file2.id,
16763
16959
  fileName: file2.name,
16764
- metadata: { deletedFromStorage: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _374 => _374.deleteFromStorage]), () => ( false)) }
16960
+ metadata: { deletedFromStorage: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _402 => _402.deleteFromStorage]), () => ( false)) }
16765
16961
  })])
16766
16962
  )
16767
16963
  );
@@ -16839,7 +17035,7 @@ var FileService = class extends BaseService {
16839
17035
  if (!file2) {
16840
17036
  return false;
16841
17037
  }
16842
- if (_optionalChain([options, 'optionalAccess', _375 => _375.isAdmin])) {
17038
+ if (_optionalChain([options, 'optionalAccess', _403 => _403.isAdmin])) {
16843
17039
  return true;
16844
17040
  }
16845
17041
  if (file2.visibility === "public") {
@@ -16849,7 +17045,7 @@ var FileService = class extends BaseService {
16849
17045
  return true;
16850
17046
  }
16851
17047
  if (file2.visibility === "restricted") {
16852
- return _nullishCoalesce(_optionalChain([file2, 'access', _376 => _376.allowedUsers, 'optionalAccess', _377 => _377.includes, 'call', _378 => _378(userId)]), () => ( false));
17048
+ return _nullishCoalesce(_optionalChain([file2, 'access', _404 => _404.allowedUsers, 'optionalAccess', _405 => _405.includes, 'call', _406 => _406(userId)]), () => ( false));
16853
17049
  }
16854
17050
  return false;
16855
17051
  }
@@ -16944,7 +17140,7 @@ function withTimeout(promise, ms, label) {
16944
17140
  var GeocodingService = class {
16945
17141
  constructor(adapter, options) {
16946
17142
  this.adapter = adapter;
16947
- this.timeoutMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _379 => _379.timeoutMs]), () => ( GEOCODING_TIMEOUT_MS));
17143
+ this.timeoutMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _407 => _407.timeoutMs]), () => ( GEOCODING_TIMEOUT_MS));
16948
17144
  }
16949
17145
  /**
16950
17146
  * Search for address suggestions as the user types
@@ -16999,16 +17195,24 @@ var GlobalSearchService = class extends BaseService {
16999
17195
  if (!query || query.trim().length === 0) {
17000
17196
  return { results: [], total: 0 };
17001
17197
  }
17002
- return this.cachedList(
17003
- "globalSearch",
17004
- "search",
17005
- { query: query.trim(), ...options },
17006
- () => this.adapter.objectRecords.globalSearch(query.trim(), {
17007
- limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _380 => _380.limit]), () => ( 20)),
17008
- offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _381 => _381.offset]), () => ( 0)),
17009
- objectNames: _optionalChain([options, 'optionalAccess', _382 => _382.objectNames])
17010
- })
17011
- );
17198
+ const trimmed = query.trim();
17199
+ if (this.adapter.search) {
17200
+ try {
17201
+ const raw = await this.adapter.search.globalSearch(trimmed, {
17202
+ objectNames: _optionalChain([options, 'optionalAccess', _408 => _408.objectNames]),
17203
+ limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _409 => _409.limit]), () => ( 20)),
17204
+ offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _410 => _410.offset]), () => ( 0))
17205
+ });
17206
+ return await this.healGlobalSearchResults(raw);
17207
+ } catch (err) {
17208
+ console.error("[search] External search failed, falling back to PostgreSQL", err);
17209
+ }
17210
+ }
17211
+ return this.adapter.objectRecords.globalSearch(trimmed, {
17212
+ limit: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _411 => _411.limit]), () => ( 20)),
17213
+ offset: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _412 => _412.offset]), () => ( 0)),
17214
+ objectNames: _optionalChain([options, 'optionalAccess', _413 => _413.objectNames])
17215
+ });
17012
17216
  }
17013
17217
  /**
17014
17218
  * Search and group results by object type.
@@ -17022,15 +17226,72 @@ var GlobalSearchService = class extends BaseService {
17022
17226
  if (!query || query.trim().length === 0) {
17023
17227
  return { groups: [], total: 0 };
17024
17228
  }
17025
- return this.cachedList(
17026
- "globalSearch",
17027
- "grouped",
17028
- { query: query.trim(), ...options },
17029
- () => this.adapter.objectRecords.globalSearchGrouped(query.trim(), {
17030
- objectNames: _optionalChain([options, 'optionalAccess', _383 => _383.objectNames]),
17031
- limitPerGroup: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _384 => _384.limitPerGroup]), () => ( 5))
17032
- })
17033
- );
17229
+ const trimmed = query.trim();
17230
+ if (this.adapter.search) {
17231
+ try {
17232
+ const raw = await this.adapter.search.globalSearchGrouped(trimmed, {
17233
+ objectNames: _optionalChain([options, 'optionalAccess', _414 => _414.objectNames])
17234
+ });
17235
+ return await this.healGroupedSearchResults(raw);
17236
+ } catch (err) {
17237
+ console.error("[search] External grouped search failed, falling back to PostgreSQL", err);
17238
+ }
17239
+ }
17240
+ return this.adapter.objectRecords.globalSearchGrouped(trimmed, {
17241
+ objectNames: _optionalChain([options, 'optionalAccess', _415 => _415.objectNames]),
17242
+ limitPerGroup: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _416 => _416.limitPerGroup]), () => ( 5))
17243
+ });
17244
+ }
17245
+ // ==========================================================================
17246
+ // Self-healing: ghost record cleanup
17247
+ // ==========================================================================
17248
+ /**
17249
+ * Verify Meilisearch results against PostgreSQL and remove ghost records.
17250
+ * GlobalSearchResultItem uses `recordId` (not `id`) as the record identifier.
17251
+ */
17252
+ async healGlobalSearchResults(meiliResult) {
17253
+ const { search } = this.adapter;
17254
+ if (!search || meiliResult.results.length === 0) {
17255
+ return meiliResult;
17256
+ }
17257
+ const ids = meiliResult.results.map((r) => r.recordId);
17258
+ const existing = await this.adapter.objectRecords.findByIds(ids);
17259
+ const existingSet = new Set(existing.map((r) => r.id));
17260
+ const ghosts = ids.filter((id) => !existingSet.has(id));
17261
+ if (ghosts.length > 0) {
17262
+ Promise.all(ghosts.map((id) => search.removeRecord(id))).catch(
17263
+ (err) => console.error("[search] Failed to clean ghost records", err)
17264
+ );
17265
+ }
17266
+ return {
17267
+ results: meiliResult.results.filter((r) => existingSet.has(r.recordId)),
17268
+ total: meiliResult.total - ghosts.length
17269
+ };
17270
+ }
17271
+ /**
17272
+ * Verify grouped Meilisearch results against PostgreSQL and remove ghost records.
17273
+ * Filters ghosts from each group and removes empty groups.
17274
+ */
17275
+ async healGroupedSearchResults(raw) {
17276
+ const { search } = this.adapter;
17277
+ if (!search) return raw;
17278
+ const allIds = raw.groups.flatMap((g) => g.results.map((r) => r.recordId));
17279
+ if (allIds.length === 0) return raw;
17280
+ const existing = await this.adapter.objectRecords.findByIds(allIds);
17281
+ const existingSet = new Set(existing.map((r) => r.id));
17282
+ const ghosts = allIds.filter((id) => !existingSet.has(id));
17283
+ if (ghosts.length > 0) {
17284
+ Promise.all(ghosts.map((id) => search.removeRecord(id))).catch(
17285
+ (err) => console.error("[search] Failed to clean ghost records", err)
17286
+ );
17287
+ }
17288
+ return {
17289
+ groups: raw.groups.map((g) => {
17290
+ const filtered = g.results.filter((r) => existingSet.has(r.recordId));
17291
+ return { ...g, results: filtered, totalInGroup: filtered.length };
17292
+ }).filter((g) => g.results.length > 0),
17293
+ total: raw.total - ghosts.length
17294
+ };
17034
17295
  }
17035
17296
  };
17036
17297
 
@@ -17045,7 +17306,7 @@ var PermissionService = class extends BaseService {
17045
17306
  }
17046
17307
  this.permissionsRepo = adapter.permissions;
17047
17308
  this.permissionCache = _nullishCoalesce(adapter.cache, () => ( new NoopCacheAdapter()));
17048
- this.auditService = _optionalChain([options, 'optionalAccess', _385 => _385.auditService]);
17309
+ this.auditService = _optionalChain([options, 'optionalAccess', _417 => _417.auditService]);
17049
17310
  }
17050
17311
  // ============================================================================
17051
17312
  // PERMISSION CHECKS
@@ -17064,11 +17325,11 @@ var PermissionService = class extends BaseService {
17064
17325
  return true;
17065
17326
  }
17066
17327
  const wildcardPerms = permissions.objectPermissions["*"];
17067
- if (_optionalChain([wildcardPerms, 'optionalAccess', _386 => _386.includes, 'call', _387 => _387(action)])) {
17328
+ if (_optionalChain([wildcardPerms, 'optionalAccess', _418 => _418.includes, 'call', _419 => _419(action)])) {
17068
17329
  return true;
17069
17330
  }
17070
17331
  const objectPerms = permissions.objectPermissions[objectName];
17071
- return _nullishCoalesce(_optionalChain([objectPerms, 'optionalAccess', _388 => _388.includes, 'call', _389 => _389(action)]), () => ( false));
17332
+ return _nullishCoalesce(_optionalChain([objectPerms, 'optionalAccess', _420 => _420.includes, 'call', _421 => _421(action)]), () => ( false));
17072
17333
  }
17073
17334
  /**
17074
17335
  * Check if user can access an object, throw ForbiddenError if not.
@@ -17123,12 +17384,12 @@ var PermissionService = class extends BaseService {
17123
17384
  if (permissions.isAdmin) {
17124
17385
  return true;
17125
17386
  }
17126
- const wildcardPerms = _optionalChain([permissions, 'access', _390 => _390.systemPermissions, 'optionalAccess', _391 => _391["*"]]);
17127
- if (_optionalChain([wildcardPerms, 'optionalAccess', _392 => _392.includes, 'call', _393 => _393(action)])) {
17387
+ const wildcardPerms = _optionalChain([permissions, 'access', _422 => _422.systemPermissions, 'optionalAccess', _423 => _423["*"]]);
17388
+ if (_optionalChain([wildcardPerms, 'optionalAccess', _424 => _424.includes, 'call', _425 => _425(action)])) {
17128
17389
  return true;
17129
17390
  }
17130
- const resourcePerms = _optionalChain([permissions, 'access', _394 => _394.systemPermissions, 'optionalAccess', _395 => _395[resource]]);
17131
- return _nullishCoalesce(_optionalChain([resourcePerms, 'optionalAccess', _396 => _396.includes, 'call', _397 => _397(action)]), () => ( false));
17391
+ const resourcePerms = _optionalChain([permissions, 'access', _426 => _426.systemPermissions, 'optionalAccess', _427 => _427[resource]]);
17392
+ return _nullishCoalesce(_optionalChain([resourcePerms, 'optionalAccess', _428 => _428.includes, 'call', _429 => _429(action)]), () => ( false));
17132
17393
  }
17133
17394
  /**
17134
17395
  * Check if user can access a system resource, throw ForbiddenError if not.
@@ -17157,8 +17418,8 @@ var PermissionService = class extends BaseService {
17157
17418
  if (permissions.isAdmin) {
17158
17419
  return { canRead: true, canCreate: true, canUpdate: true, canDelete: true };
17159
17420
  }
17160
- const wildcardPerms = _nullishCoalesce(_optionalChain([permissions, 'access', _398 => _398.systemPermissions, 'optionalAccess', _399 => _399["*"]]), () => ( []));
17161
- const resourcePerms = _nullishCoalesce(_optionalChain([permissions, 'access', _400 => _400.systemPermissions, 'optionalAccess', _401 => _401[resource]]), () => ( []));
17421
+ const wildcardPerms = _nullishCoalesce(_optionalChain([permissions, 'access', _430 => _430.systemPermissions, 'optionalAccess', _431 => _431["*"]]), () => ( []));
17422
+ const resourcePerms = _nullishCoalesce(_optionalChain([permissions, 'access', _432 => _432.systemPermissions, 'optionalAccess', _433 => _433[resource]]), () => ( []));
17162
17423
  const allPerms = /* @__PURE__ */ new Set([...wildcardPerms, ...resourcePerms]);
17163
17424
  return {
17164
17425
  canRead: allPerms.has("read"),
@@ -17301,7 +17562,7 @@ var PermissionService = class extends BaseService {
17301
17562
  action: "role.updated",
17302
17563
  actorId: this.userId,
17303
17564
  roleId,
17304
- roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _402 => _402.label]), () => ( roleId)),
17565
+ roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _434 => _434.label]), () => ( roleId)),
17305
17566
  metadata: { permissionsUpdated: true, permissionCount: permissions.length }
17306
17567
  });
17307
17568
  }
@@ -17331,7 +17592,7 @@ var PermissionService = class extends BaseService {
17331
17592
  action: "role.assigned",
17332
17593
  actorId: this.userId,
17333
17594
  roleId,
17334
- roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _403 => _403.label]), () => ( roleId)),
17595
+ roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _435 => _435.label]), () => ( roleId)),
17335
17596
  targetUserId: userProfileId
17336
17597
  });
17337
17598
  }
@@ -17349,7 +17610,7 @@ var PermissionService = class extends BaseService {
17349
17610
  action: "role.revoked",
17350
17611
  actorId: this.userId,
17351
17612
  roleId,
17352
- roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _404 => _404.label]), () => ( roleId)),
17613
+ roleLabel: _nullishCoalesce(_optionalChain([role, 'optionalAccess', _436 => _436.label]), () => ( roleId)),
17353
17614
  targetUserId: userProfileId
17354
17615
  });
17355
17616
  }
@@ -17824,7 +18085,7 @@ var ViewService = class extends BaseService {
17824
18085
  dbView.objectName,
17825
18086
  dbView.type,
17826
18087
  objectDefinition,
17827
- dbView.type === "detail" ? _nullishCoalesce(_optionalChain([dbView, 'access', _405 => _405.config, 'optionalAccess', _406 => _406.layout]), () => ( "page")) : void 0
18088
+ dbView.type === "detail" ? _nullishCoalesce(_optionalChain([dbView, 'access', _437 => _437.config, 'optionalAccess', _438 => _438.layout]), () => ( "page")) : void 0
17828
18089
  );
17829
18090
  const newConfig = generated.config;
17830
18091
  const updated = await this.adapter.views.update(viewId, { config: newConfig });
@@ -18218,7 +18479,7 @@ async function syncSingleObject(adapter, nativeObject, result, options) {
18218
18479
  `Cannot sync shared object "${nativeObject.name}": masterTenantId must be configured in tenant options`
18219
18480
  );
18220
18481
  }
18221
- if (options.tenantId && options.tenantId !== options.masterTenantId) {
18482
+ if (!options.tenantId || options.tenantId !== options.masterTenantId) {
18222
18483
  throw new Error(
18223
18484
  `Cannot sync shared object "${nativeObject.name}": only master tenant "${options.masterTenantId}" can sync shared objects (current: "${options.tenantId}")`
18224
18485
  );
@@ -18226,12 +18487,13 @@ async function syncSingleObject(adapter, nativeObject, result, options) {
18226
18487
  }
18227
18488
  const existingObject = await adapter.objects.findSystemByName(nativeObject.name);
18228
18489
  const isNew = !existingObject;
18229
- updateObjectStats(result, isNew);
18230
18490
  if (options.dryRun) {
18491
+ updateObjectStats(result, isNew);
18231
18492
  await handleDryRun(adapter, nativeObject, existingObject, result, options, isNew);
18232
18493
  return;
18233
18494
  }
18234
18495
  const dbObject = await upsertObject(adapter, nativeObject, options);
18496
+ updateObjectStats(result, isNew);
18235
18497
  await syncAttributes(adapter, nativeObject, dbObject, existingObject, result);
18236
18498
  if (!isNew) {
18237
18499
  await cleanupAttributes(adapter, dbObject.id, nativeObject, result);
@@ -18260,6 +18522,11 @@ async function handleDryRun(adapter, nativeObject, existingObject, result, optio
18260
18522
  }
18261
18523
  result.attributesSynced++;
18262
18524
  }
18525
+ const codeAttributeNames = nativeObject.attributes.map((attr) => attr.name);
18526
+ const wouldBeDeleted = existingAttrs.filter(
18527
+ (a) => a.system && !codeAttributeNames.includes(a.name)
18528
+ );
18529
+ result.attributesDeleted += wouldBeDeleted.length;
18263
18530
  }
18264
18531
  async function upsertObject(adapter, nativeObject, _options) {
18265
18532
  return await adapter.objects.upsert({
@@ -18695,4 +18962,7 @@ var NoopGeocodingAdapter = class {
18695
18962
 
18696
18963
 
18697
18964
 
18698
- exports.IDENTITY_PROPERTIES = IDENTITY_PROPERTIES; exports.BEHAVIOR_PROPERTIES = BEHAVIOR_PROPERTIES; exports.PRESENTATION_PROPERTIES = PRESENTATION_PROPERTIES; exports.isIdentityProperty = isIdentityProperty; exports.isBehaviorProperty = isBehaviorProperty; exports.isPresentationProperty = isPresentationProperty; exports.RELATION_TARGET_ANY = RELATION_TARGET_ANY; exports.isUniversalRelation = isUniversalRelation; exports.isBilateralRelation = isBilateralRelation; exports.inferInverseCardinality = inferInverseCardinality; exports.RecordReferencedError = RecordReferencedError; exports.AttributeInUseError = AttributeInUseError; exports.ObjectReferencedError = ObjectReferencedError; exports.getErrorMessage = getErrorMessage; exports.NoopGeocodingAdapter = NoopGeocodingAdapter; exports.SYSTEM_FIELD_NAMES = SYSTEM_FIELD_NAMES; exports.RESERVED_ATTRIBUTE_NAMES = RESERVED_ATTRIBUTE_NAMES; exports.PolicyViolationError = PolicyViolationError; exports.FORBIDDEN_PROPERTY_TYPES = FORBIDDEN_PROPERTY_TYPES; exports.SYSTEM_ATTRIBUTES = SYSTEM_ATTRIBUTES; exports.getSystemAttributeList = getSystemAttributeList; exports.isSystemAttribute = isSystemAttribute; exports.isSystemAttributeObject = isSystemAttributeObject; exports.isSimpleFormNode = isSimpleFormNode; exports.isAdvancedFormNode = isAdvancedFormNode; exports.isStartNode = isStartNode; exports.isFormNode = isFormNode; exports.isConditionNode = isConditionNode; exports.isDocumentNode = isDocumentNode; exports.isEndNode = isEndNode; exports.getNodeOutputs = getNodeOutputs; exports.isConditionRule = isConditionRule; exports.isConditionGroup = isConditionGroup; exports.eq = eq; exports.neq = neq; exports.and = and; exports.or = or; exports.inValues = inValues; exports.isWorkflowDefinition = isWorkflowDefinition; exports.isWorkflowPublished = isWorkflowPublished; exports.isSystemWorkflow = isSystemWorkflow; exports.isInstanceTerminal = isInstanceTerminal; exports.isInstanceWaiting = isInstanceWaiting; exports.canResumeInstance = canResumeInstance; exports.createStartTransition = createStartTransition; exports.isInvitationValid = isInvitationValid; exports.isInvitationAccepted = isInvitationAccepted; exports.isInvitationExpired = isInvitationExpired; exports.isGrantValid = isGrantValid; exports.isGrantRevoked = isGrantRevoked; exports.isTokenRevoked = isTokenRevoked; exports.isGrantExpired = isGrantExpired; exports.canAccessNode = canAccessNode; exports.createEmptyContext = createEmptyContext; exports.getContextValue = getContextValue; exports.setContextValue = setContextValue; exports.DEFAULT_THEME = DEFAULT_THEME; exports.mergeWithDefaults = mergeWithDefaults; exports.generateCssVariables = generateCssVariables; exports.isInstanceEvent = isInstanceEvent; exports.isNodeEvent = isNodeEvent; exports.isInvitationOrGrantEvent = isInvitationOrGrantEvent; exports.ConditionOperatorSchema = ConditionOperatorSchema; exports.ConditionRuleSchema = ConditionRuleSchema; exports.ConditionGroupSchema = ConditionGroupSchema; exports.StartNodeSchema = StartNodeSchema; exports.FormFieldRefSchema = FormFieldRefSchema; exports.FlowRowFieldSchema = FlowRowFieldSchema; exports.FlowRowSchema = FlowRowSchema; exports.FormNodeSchema = FormNodeSchema; exports.ConditionNodeSchema = ConditionNodeSchema; exports.DocumentNodeSchema = DocumentNodeSchema; exports.EndNodeSchema = EndNodeSchema; exports.WorkflowNodeSchema = WorkflowNodeSchema; exports.SlotModeSchema = SlotModeSchema; exports.WorkflowSlotSchema = WorkflowSlotSchema; exports.AuthMethodSchema = AuthMethodSchema; exports.ShareStatusSchema = ShareStatusSchema; exports.WorkflowShareSchema = WorkflowShareSchema; exports.CreateShareInputSchema = CreateShareInputSchema; exports.NodePositionSchema = NodePositionSchema; exports.ViewportSchema = ViewportSchema; exports.WorkflowLayoutSchema = WorkflowLayoutSchema; exports.ThemeColorsSchema = ThemeColorsSchema; exports.ThemeLogoSchema = ThemeLogoSchema; exports.WorkflowThemeSchema = WorkflowThemeSchema; exports.WorkflowConfigSchema = WorkflowConfigSchema; exports.WorkflowStatusSchema = WorkflowStatusSchema; exports.WorkflowDefinitionSchema = WorkflowDefinitionSchema; exports.isEmpty = isEmpty; exports.isNotEmpty = isNotEmpty; exports.toUndefinedIfEmpty = toUndefinedIfEmpty; exports.hasProperties = hasProperties; exports.EMPTY_VALUE_PLACEHOLDER = EMPTY_VALUE_PLACEHOLDER; exports.formatAttributeValue = formatAttributeValue; exports.DEFAULT_LABEL_FALLBACK = DEFAULT_LABEL_FALLBACK; exports.renderLabelExpression = renderLabelExpression; exports.isLabelExpression = isLabelExpression; exports.extractAttributeNames = extractAttributeNames; exports.enrichValuesForDisplay = enrichValuesForDisplay; exports.enrichValuesWithSelectLabels = enrichValuesWithSelectLabels; exports.extractRelationIds = extractRelationIds; exports.computeLabelWithRelations = computeLabelWithRelations; exports.SchemaErrorCode = SchemaErrorCode; exports.SchemaError = SchemaError; exports.NotFoundError = NotFoundError; exports.ObjectNotFoundError = ObjectNotFoundError; exports.AttributeNotFoundError = AttributeNotFoundError; exports.RecordNotFoundError = RecordNotFoundError; exports.UserProfileNotFoundError = UserProfileNotFoundError; exports.FileNotFoundError = FileNotFoundError; exports.ValidationError = ValidationError; exports.ProtectedResourceError = ProtectedResourceError; exports.SyncError = SyncError; exports.NotSystemObjectError = NotSystemObjectError; exports.DuplicateError = DuplicateError; exports.isSchemaError = isSchemaError; exports.isNotFoundError = isNotFoundError; exports.isValidationError = isValidationError; exports.isProtectedResourceError = isProtectedResourceError; exports.ForbiddenError = ForbiddenError; exports.ProtectedRoleError = ProtectedRoleError; exports.RoleNotFoundError = RoleNotFoundError; exports.isForbiddenError = isForbiddenError; exports.ConcurrentModificationError = ConcurrentModificationError; exports.text = text; exports.textarea = textarea; exports.richtext = richtext; exports.number = number; exports.checkbox = checkbox; exports.date = date; exports.phone = phone; exports.currency = currency; exports.status = status; exports.select = select; exports.multiselect = multiselect; exports.location = location; exports.file = file; exports.user = user; exports.relation = relation; exports.rating = rating; exports.formula = formula; exports.rollup = rollup; exports.document = document; exports.ObjectBuilder = ObjectBuilder; exports.object = object; exports.GroupBuilder = GroupBuilder; exports.RelationGroupBuilder = RelationGroupBuilder; exports.TableTabConfig = TableTabConfig; exports.CustomTabConfig = CustomTabConfig; exports.RichtextTabConfig = RichtextTabConfig; exports.ActivityTabConfig = ActivityTabConfig; exports.FlowsTabConfig = FlowsTabConfig; exports.DocumentsTabConfig = DocumentsTabConfig; exports.TabBuilder = TabBuilder; exports.DetailViewBuilder = DetailViewBuilder; exports.ViewBuilder = ViewBuilder; exports.detailView = detailView; exports.view = view; exports.ListViewBuilder = ListViewBuilder; exports.ListViewTabConfigBuilder = ListViewTabConfigBuilder; exports.listView = listView; exports.group = group; exports.relationGroup = relationGroup; exports.WorkflowFormRowBuilder = WorkflowFormRowBuilder; exports.WorkflowFormBuilder = WorkflowFormBuilder; exports.WorkflowSimpleFormBuilder = WorkflowSimpleFormBuilder; exports.WorkflowConditionBuilder = WorkflowConditionBuilder; exports.WorkflowEndBuilder = WorkflowEndBuilder; exports.WorkflowStartBuilder = WorkflowStartBuilder; exports.WorkflowBuilder = WorkflowBuilder; exports.workflow = workflow; exports.registry = registry; exports.SYSTEM_TEMPLATE_IDS = SYSTEM_TEMPLATE_IDS; exports.FRENCH_ID_CARD = FRENCH_ID_CARD; exports.PASSPORT = PASSPORT; exports.DRIVING_LICENSE = DRIVING_LICENSE; exports.PROOF_OF_ADDRESS = PROOF_OF_ADDRESS; exports.SIGNABLE_CONTRACT = SIGNABLE_CONTRACT; exports.GENERIC_DOCUMENT = GENERIC_DOCUMENT; exports.SYSTEM_TEMPLATES = SYSTEM_TEMPLATES; exports.getSystemTemplate = getSystemTemplate; exports.isSystemTemplate = isSystemTemplate; exports.WorkflowJwtService = WorkflowJwtService; exports.hashOptions = hashOptions; exports.cacheKeys = cacheKeys; exports.cacheTtl = cacheTtl; exports.defaultTtl = defaultTtl; exports.NoopCacheAdapter = NoopCacheAdapter; exports.formatRecord = formatRecord; exports.formatRecords = formatRecords; exports.createDefaultState = createDefaultState; exports.SHORTCUT_TO_FILTER_OPERATOR = SHORTCUT_TO_FILTER_OPERATOR; exports.QueryNoResultError = QueryNoResultError; exports.QueryMultipleResultsError = QueryMultipleResultsError; exports.TenantContextError = TenantContextError; exports.FeatureFlagsContextError = FeatureFlagsContextError; exports.isFeatureEnabled = isFeatureEnabled; exports.getFeatureValue = getFeatureValue; exports.getFeatureFlags = getFeatureFlags; exports.tryGetFeatureValue = tryGetFeatureValue; exports.hasFeatureFlagsContext = hasFeatureFlagsContext; exports.runWithFeatureFlags = runWithFeatureFlags; exports.withFeatureFlags = withFeatureFlags; exports.getSchemaFromContext = getSchemaFromContext; exports.getSchemaByNameFromContext = getSchemaByNameFromContext; exports.hasSchemaContext = hasSchemaContext; exports.getSchemaContext = getSchemaContext; exports.addSchemaToContext = addSchemaToContext; exports.runWithSchemaContext = runWithSchemaContext; exports.runWithMergedSchemaContext = runWithMergedSchemaContext; exports.getContext = getContext2; exports.getTenantId = getTenantId; exports.getUserId = getUserId; exports.hasContext = hasContext; exports.runWithContext = runWithContext; exports.withTenantContext = withTenantContext; exports.QueryBuilder = QueryBuilder; exports.createQueryBuilder = createQueryBuilder; exports.evaluateCondition = evaluateCondition; exports.evaluate = evaluate; exports.evaluateWithTrace = evaluateWithTrace; exports.ExecutorRegistry = ExecutorRegistry; exports.success = success; exports.wait = wait; exports.complete = complete; exports.error = error; exports.ConditionExecutor = ConditionExecutor; exports.DocumentExecutor = DocumentExecutor; exports.EndExecutor = EndExecutor; exports.FormExecutor = FormExecutor; exports.StartExecutor = StartExecutor; exports.createDefaultExecutorRegistry = createDefaultExecutorRegistry; exports.getDefaultExecutorRegistry = getDefaultExecutorRegistry; exports.evaluateFormula = evaluateFormula; exports.evaluateFormulaWithResult = evaluateFormulaWithResult; exports.formatFormulaResult = formatFormulaResult; exports.evaluateFormulaAttribute = evaluateFormulaAttribute; exports.validateFormulaExpression = validateFormulaExpression; exports.extractFormulaVariables = extractFormulaVariables; exports.extractRelationReferences = extractRelationReferences; exports.extractRelationNames = extractRelationNames; exports.hasRelationReferences = hasRelationReferences; exports.flattenRelationsForEval = flattenRelationsForEval; exports.evaluateFormulaWithRelations = evaluateFormulaWithRelations; exports.evaluateFormulaAttributeWithRelations = evaluateFormulaAttributeWithRelations; exports.InvalidPathError = InvalidPathError; exports.MaxDepthExceededError = MaxDepthExceededError; exports.parsePath = parsePath; exports.validatePath = validatePath; exports.pathHasManyCardinality = pathHasManyCardinality; exports.getPathDepth = getPathDepth; exports.getTargetAttributeName = getTargetAttributeName; exports.getRelationPath = getRelationPath; exports.traversePath = traversePath; exports.resolveSingleValue = resolveSingleValue; exports.resolveMultiplePaths = resolveMultiplePaths; exports.NoopHookRegistry = NoopHookRegistry; exports.createMockAdapter = createMockAdapter; exports.PolicyRegistry = PolicyRegistry; exports.defaultPolicyRegistry = defaultPolicyRegistry; exports.BaseService = BaseService; exports.BaseRepository = BaseRepository; exports.SchemaContextAwareRepository = SchemaContextAwareRepository; exports.buildAuditChanges = buildAuditChanges; exports.ObjectSchemaService = ObjectSchemaService; exports.AuditService = AuditService; exports.UserService = UserService; exports.applyDefaultValues = applyDefaultValues; exports.checkPermission = checkPermission; exports.getPolicy = getPolicy; exports.buildPolicyContext = buildPolicyContext; exports.checkRecordAccess = checkRecordAccess; exports.checkRecordModifyOrThrow = checkRecordModifyOrThrow; exports.checkRecordDeleteOrThrow = checkRecordDeleteOrThrow; exports.checkSharedObjectWriteAccess = checkSharedObjectWriteAccess; exports.computeLabel = computeLabel; exports.enrichWithFormulas = enrichWithFormulas; exports.enrichRecordsWithFormulas = enrichRecordsWithFormulas; exports.createContextForCreate = createContextForCreate; exports.createContextForUpdate = createContextForUpdate; exports.createContextForDelete = createContextForDelete; exports.createContextForRestore = createContextForRestore; exports.recalculateParentRollups = recalculateParentRollups; exports.RelationPropertiesService = RelationPropertiesService; exports.RecordQueryService = RecordQueryService; exports.RecordResolverService = RecordResolverService; exports.RelationService = RelationService; exports.RollupService = RollupService; exports.RecordService = RecordService; exports.FormulaResolverService = FormulaResolverService; exports.RollupScheduler = RollupScheduler; exports.DocumentRenderError = DocumentRenderError; exports.StorageDownloadNotSupportedError = StorageDownloadNotSupportedError; exports.DocumentRendererService = DocumentRendererService; exports.DocumentProcessingHook = DocumentProcessingHook; exports.GrantNotFoundError = GrantNotFoundError; exports.GrantExpiredError = GrantExpiredError; exports.GrantRevokedError = GrantRevokedError; exports.TokenRevokedError = TokenRevokedError; exports.WorkflowAccessGrantService = WorkflowAccessGrantService; exports.WorkflowInstanceService = WorkflowInstanceService; exports.InvitationNotFoundError = InvitationNotFoundError; exports.InvitationExpiredError = InvitationExpiredError; exports.InvitationAlreadyAcceptedError = InvitationAlreadyAcceptedError; exports.InvitationRevokedError = InvitationRevokedError; exports.WorkflowInvitationService = WorkflowInvitationService; exports.WorkflowRelationService = WorkflowRelationService; exports.WorkflowService = WorkflowService; exports.UserProfileService = UserProfileService; exports.DocumentGenerationTemplateNotFoundError = DocumentGenerationTemplateNotFoundError; exports.DocumentGenerationNotConfiguredError = DocumentGenerationNotConfiguredError; exports.DocumentGenerationService = DocumentGenerationService; exports.DocumentTemplateService = DocumentTemplateService; exports.DocumentService = DocumentService; exports.DocumentProcessingService = DocumentProcessingService; exports.FileService = FileService; exports.GeocodingService = GeocodingService; exports.GlobalSearchService = GlobalSearchService; exports.PermissionService = PermissionService; exports.ViewService = ViewService; exports.seedRegistryViews = seedRegistryViews; exports.syncNativeViews = syncNativeViews; exports.verifyRegistryViewsSeeded = verifyRegistryViewsSeeded; exports.verifyNativeViewsSync = verifyNativeViewsSync; exports.getViewSeedPreview = getViewSeedPreview; exports.getViewSyncPreview = getViewSyncPreview; exports.syncNativeObjects = syncNativeObjects; exports.verifyNativeObjectsSync = verifyNativeObjectsSync; exports.getSyncPreview = getSyncPreview; exports.syncAll = syncAll;
18965
+
18966
+
18967
+
18968
+ exports.IDENTITY_PROPERTIES = IDENTITY_PROPERTIES; exports.BEHAVIOR_PROPERTIES = BEHAVIOR_PROPERTIES; exports.PRESENTATION_PROPERTIES = PRESENTATION_PROPERTIES; exports.isIdentityProperty = isIdentityProperty; exports.isBehaviorProperty = isBehaviorProperty; exports.isPresentationProperty = isPresentationProperty; exports.RELATION_TARGET_ANY = RELATION_TARGET_ANY; exports.isUniversalRelation = isUniversalRelation; exports.isBilateralRelation = isBilateralRelation; exports.inferInverseCardinality = inferInverseCardinality; exports.NON_SORTABLE_TYPES = NON_SORTABLE_TYPES; exports.isAttributeSortable = isAttributeSortable; exports.RecordReferencedError = RecordReferencedError; exports.AttributeInUseError = AttributeInUseError; exports.ObjectReferencedError = ObjectReferencedError; exports.getErrorMessage = getErrorMessage; exports.NoopGeocodingAdapter = NoopGeocodingAdapter; exports.SYSTEM_FIELD_NAMES = SYSTEM_FIELD_NAMES; exports.RESERVED_ATTRIBUTE_NAMES = RESERVED_ATTRIBUTE_NAMES; exports.PolicyViolationError = PolicyViolationError; exports.FORBIDDEN_PROPERTY_TYPES = FORBIDDEN_PROPERTY_TYPES; exports.SYSTEM_ATTRIBUTES = SYSTEM_ATTRIBUTES; exports.getSystemAttributeList = getSystemAttributeList; exports.isSystemAttribute = isSystemAttribute; exports.isSystemAttributeObject = isSystemAttributeObject; exports.isSimpleFormNode = isSimpleFormNode; exports.isAdvancedFormNode = isAdvancedFormNode; exports.isStartNode = isStartNode; exports.isFormNode = isFormNode; exports.isConditionNode = isConditionNode; exports.isDocumentNode = isDocumentNode; exports.isEndNode = isEndNode; exports.getNodeOutputs = getNodeOutputs; exports.isConditionRule = isConditionRule; exports.isConditionGroup = isConditionGroup; exports.eq = eq; exports.neq = neq; exports.and = and; exports.or = or; exports.inValues = inValues; exports.isWorkflowDefinition = isWorkflowDefinition; exports.isWorkflowPublished = isWorkflowPublished; exports.isSystemWorkflow = isSystemWorkflow; exports.isInstanceTerminal = isInstanceTerminal; exports.isInstanceWaiting = isInstanceWaiting; exports.canResumeInstance = canResumeInstance; exports.createStartTransition = createStartTransition; exports.isInvitationValid = isInvitationValid; exports.isInvitationAccepted = isInvitationAccepted; exports.isInvitationExpired = isInvitationExpired; exports.isGrantValid = isGrantValid; exports.isGrantRevoked = isGrantRevoked; exports.isTokenRevoked = isTokenRevoked; exports.isGrantExpired = isGrantExpired; exports.canAccessNode = canAccessNode; exports.createEmptyContext = createEmptyContext; exports.getContextValue = getContextValue; exports.setContextValue = setContextValue; exports.DEFAULT_THEME = DEFAULT_THEME; exports.mergeWithDefaults = mergeWithDefaults; exports.generateCssVariables = generateCssVariables; exports.isInstanceEvent = isInstanceEvent; exports.isNodeEvent = isNodeEvent; exports.isInvitationOrGrantEvent = isInvitationOrGrantEvent; exports.ConditionOperatorSchema = ConditionOperatorSchema; exports.ConditionRuleSchema = ConditionRuleSchema; exports.ConditionGroupSchema = ConditionGroupSchema; exports.StartNodeSchema = StartNodeSchema; exports.FormFieldRefSchema = FormFieldRefSchema; exports.FlowRowFieldSchema = FlowRowFieldSchema; exports.FlowRowSchema = FlowRowSchema; exports.FormNodeSchema = FormNodeSchema; exports.ConditionNodeSchema = ConditionNodeSchema; exports.DocumentNodeSchema = DocumentNodeSchema; exports.EndNodeSchema = EndNodeSchema; exports.WorkflowNodeSchema = WorkflowNodeSchema; exports.SlotModeSchema = SlotModeSchema; exports.WorkflowSlotSchema = WorkflowSlotSchema; exports.AuthMethodSchema = AuthMethodSchema; exports.ShareStatusSchema = ShareStatusSchema; exports.WorkflowShareSchema = WorkflowShareSchema; exports.CreateShareInputSchema = CreateShareInputSchema; exports.NodePositionSchema = NodePositionSchema; exports.ViewportSchema = ViewportSchema; exports.WorkflowLayoutSchema = WorkflowLayoutSchema; exports.ThemeColorsSchema = ThemeColorsSchema; exports.ThemeLogoSchema = ThemeLogoSchema; exports.WorkflowThemeSchema = WorkflowThemeSchema; exports.WorkflowConfigSchema = WorkflowConfigSchema; exports.WorkflowStatusSchema = WorkflowStatusSchema; exports.WorkflowDefinitionSchema = WorkflowDefinitionSchema; exports.isEmpty = isEmpty; exports.isNotEmpty = isNotEmpty; exports.toUndefinedIfEmpty = toUndefinedIfEmpty; exports.hasProperties = hasProperties; exports.EMPTY_VALUE_PLACEHOLDER = EMPTY_VALUE_PLACEHOLDER; exports.formatAttributeValue = formatAttributeValue; exports.DEFAULT_LABEL_FALLBACK = DEFAULT_LABEL_FALLBACK; exports.renderLabelExpression = renderLabelExpression; exports.isLabelExpression = isLabelExpression; exports.extractAttributeNames = extractAttributeNames; exports.enrichValuesForDisplay = enrichValuesForDisplay; exports.enrichValuesWithSelectLabels = enrichValuesWithSelectLabels; exports.extractRelationIds = extractRelationIds; exports.computeLabelWithRelations = computeLabelWithRelations; exports.SchemaErrorCode = SchemaErrorCode; exports.SchemaError = SchemaError; exports.NotFoundError = NotFoundError; exports.ObjectNotFoundError = ObjectNotFoundError; exports.AttributeNotFoundError = AttributeNotFoundError; exports.RecordNotFoundError = RecordNotFoundError; exports.UserProfileNotFoundError = UserProfileNotFoundError; exports.FileNotFoundError = FileNotFoundError; exports.ValidationError = ValidationError; exports.ProtectedResourceError = ProtectedResourceError; exports.SyncError = SyncError; exports.NotSystemObjectError = NotSystemObjectError; exports.DuplicateError = DuplicateError; exports.isSchemaError = isSchemaError; exports.isNotFoundError = isNotFoundError; exports.isValidationError = isValidationError; exports.isProtectedResourceError = isProtectedResourceError; exports.ForbiddenError = ForbiddenError; exports.ProtectedRoleError = ProtectedRoleError; exports.RoleNotFoundError = RoleNotFoundError; exports.isForbiddenError = isForbiddenError; exports.ConcurrentModificationError = ConcurrentModificationError; exports.text = text; exports.textarea = textarea; exports.richtext = richtext; exports.number = number; exports.checkbox = checkbox; exports.date = date; exports.phone = phone; exports.currency = currency; exports.status = status; exports.select = select; exports.multiselect = multiselect; exports.location = location; exports.file = file; exports.user = user; exports.relation = relation; exports.rating = rating; exports.formula = formula; exports.rollup = rollup; exports.document = document; exports.ObjectBuilder = ObjectBuilder; exports.object = object; exports.GroupBuilder = GroupBuilder; exports.RelationGroupBuilder = RelationGroupBuilder; exports.TableTabConfig = TableTabConfig; exports.CustomTabConfig = CustomTabConfig; exports.RichtextTabConfig = RichtextTabConfig; exports.ActivityTabConfig = ActivityTabConfig; exports.FlowsTabConfig = FlowsTabConfig; exports.DocumentsTabConfig = DocumentsTabConfig; exports.TabBuilder = TabBuilder; exports.DetailViewBuilder = DetailViewBuilder; exports.ViewBuilder = ViewBuilder; exports.detailView = detailView; exports.view = view; exports.ListViewBuilder = ListViewBuilder; exports.ListViewTabConfigBuilder = ListViewTabConfigBuilder; exports.listView = listView; exports.group = group; exports.relationGroup = relationGroup; exports.WorkflowFormRowBuilder = WorkflowFormRowBuilder; exports.WorkflowFormBuilder = WorkflowFormBuilder; exports.WorkflowSimpleFormBuilder = WorkflowSimpleFormBuilder; exports.WorkflowConditionBuilder = WorkflowConditionBuilder; exports.WorkflowEndBuilder = WorkflowEndBuilder; exports.WorkflowStartBuilder = WorkflowStartBuilder; exports.WorkflowBuilder = WorkflowBuilder; exports.workflow = workflow; exports.registry = registry; exports.SYSTEM_TEMPLATE_IDS = SYSTEM_TEMPLATE_IDS; exports.FRENCH_ID_CARD = FRENCH_ID_CARD; exports.PASSPORT = PASSPORT; exports.DRIVING_LICENSE = DRIVING_LICENSE; exports.PROOF_OF_ADDRESS = PROOF_OF_ADDRESS; exports.SIGNABLE_CONTRACT = SIGNABLE_CONTRACT; exports.GENERIC_DOCUMENT = GENERIC_DOCUMENT; exports.SYSTEM_TEMPLATES = SYSTEM_TEMPLATES; exports.getSystemTemplate = getSystemTemplate; exports.isSystemTemplate = isSystemTemplate; exports.WorkflowJwtService = WorkflowJwtService; exports.hashOptions = hashOptions; exports.cacheKeys = cacheKeys; exports.cacheTtl = cacheTtl; exports.defaultTtl = defaultTtl; exports.NoopCacheAdapter = NoopCacheAdapter; exports.formatRecord = formatRecord; exports.formatRecords = formatRecords; exports.createDefaultState = createDefaultState; exports.SHORTCUT_TO_FILTER_OPERATOR = SHORTCUT_TO_FILTER_OPERATOR; exports.QueryNoResultError = QueryNoResultError; exports.QueryMultipleResultsError = QueryMultipleResultsError; exports.TenantContextError = TenantContextError; exports.FeatureFlagsContextError = FeatureFlagsContextError; exports.isFeatureEnabled = isFeatureEnabled; exports.getFeatureValue = getFeatureValue; exports.getFeatureFlags = getFeatureFlags; exports.tryGetFeatureValue = tryGetFeatureValue; exports.hasFeatureFlagsContext = hasFeatureFlagsContext; exports.runWithFeatureFlags = runWithFeatureFlags; exports.withFeatureFlags = withFeatureFlags; exports.getSchemaFromContext = getSchemaFromContext; exports.getSchemaByNameFromContext = getSchemaByNameFromContext; exports.hasSchemaContext = hasSchemaContext; exports.getSchemaContext = getSchemaContext; exports.addSchemaToContext = addSchemaToContext; exports.runWithSchemaContext = runWithSchemaContext; exports.runWithMergedSchemaContext = runWithMergedSchemaContext; exports.getContext = getContext2; exports.getTenantId = getTenantId; exports.getUserId = getUserId; exports.hasContext = hasContext; exports.runWithContext = runWithContext; exports.withTenantContext = withTenantContext; exports.QueryBuilder = QueryBuilder; exports.createQueryBuilder = createQueryBuilder; exports.evaluateCondition = evaluateCondition; exports.evaluate = evaluate; exports.evaluateWithTrace = evaluateWithTrace; exports.ExecutorRegistry = ExecutorRegistry; exports.success = success; exports.wait = wait; exports.complete = complete; exports.error = error; exports.ConditionExecutor = ConditionExecutor; exports.DocumentExecutor = DocumentExecutor; exports.EndExecutor = EndExecutor; exports.FormExecutor = FormExecutor; exports.StartExecutor = StartExecutor; exports.createDefaultExecutorRegistry = createDefaultExecutorRegistry; exports.getDefaultExecutorRegistry = getDefaultExecutorRegistry; exports.evaluateFormula = evaluateFormula; exports.evaluateFormulaWithResult = evaluateFormulaWithResult; exports.formatFormulaResult = formatFormulaResult; exports.evaluateFormulaAttribute = evaluateFormulaAttribute; exports.validateFormulaExpression = validateFormulaExpression; exports.extractFormulaVariables = extractFormulaVariables; exports.extractRelationReferences = extractRelationReferences; exports.extractRelationNames = extractRelationNames; exports.hasRelationReferences = hasRelationReferences; exports.flattenRelationsForEval = flattenRelationsForEval; exports.evaluateFormulaWithRelations = evaluateFormulaWithRelations; exports.evaluateFormulaAttributeWithRelations = evaluateFormulaAttributeWithRelations; exports.InvalidPathError = InvalidPathError; exports.MaxDepthExceededError = MaxDepthExceededError; exports.parsePath = parsePath; exports.validatePath = validatePath; exports.pathHasManyCardinality = pathHasManyCardinality; exports.getPathDepth = getPathDepth; exports.getTargetAttributeName = getTargetAttributeName; exports.getRelationPath = getRelationPath; exports.traversePath = traversePath; exports.resolveSingleValue = resolveSingleValue; exports.resolveMultiplePaths = resolveMultiplePaths; exports.NoopHookRegistry = NoopHookRegistry; exports.createMockAdapter = createMockAdapter; exports.PolicyRegistry = PolicyRegistry; exports.defaultPolicyRegistry = defaultPolicyRegistry; exports.SORTABLE_ATTRIBUTE_TYPES = SORTABLE_ATTRIBUTE_TYPES; exports.BaseService = BaseService; exports.BaseRepository = BaseRepository; exports.SchemaContextAwareRepository = SchemaContextAwareRepository; exports.buildAuditChanges = buildAuditChanges; exports.ObjectSchemaService = ObjectSchemaService; exports.AuditService = AuditService; exports.UserService = UserService; exports.applyDefaultValues = applyDefaultValues; exports.checkPermission = checkPermission; exports.getPolicy = getPolicy; exports.buildPolicyContext = buildPolicyContext; exports.checkRecordAccess = checkRecordAccess; exports.checkRecordModifyOrThrow = checkRecordModifyOrThrow; exports.checkRecordDeleteOrThrow = checkRecordDeleteOrThrow; exports.checkSharedObjectWriteAccess = checkSharedObjectWriteAccess; exports.computeLabel = computeLabel; exports.enrichWithFormulas = enrichWithFormulas; exports.enrichRecordsWithFormulas = enrichRecordsWithFormulas; exports.createContextForCreate = createContextForCreate; exports.createContextForUpdate = createContextForUpdate; exports.createContextForDelete = createContextForDelete; exports.createContextForRestore = createContextForRestore; exports.recalculateParentRollups = recalculateParentRollups; exports.RelationPropertiesService = RelationPropertiesService; exports.RecordQueryService = RecordQueryService; exports.RecordResolverService = RecordResolverService; exports.RelationService = RelationService; exports.RollupService = RollupService; exports.RecordService = RecordService; exports.FormulaResolverService = FormulaResolverService; exports.RollupScheduler = RollupScheduler; exports.DocumentRenderError = DocumentRenderError; exports.StorageDownloadNotSupportedError = StorageDownloadNotSupportedError; exports.DocumentRendererService = DocumentRendererService; exports.DocumentProcessingHook = DocumentProcessingHook; exports.GrantNotFoundError = GrantNotFoundError; exports.GrantExpiredError = GrantExpiredError; exports.GrantRevokedError = GrantRevokedError; exports.TokenRevokedError = TokenRevokedError; exports.WorkflowAccessGrantService = WorkflowAccessGrantService; exports.WorkflowInstanceService = WorkflowInstanceService; exports.InvitationNotFoundError = InvitationNotFoundError; exports.InvitationExpiredError = InvitationExpiredError; exports.InvitationAlreadyAcceptedError = InvitationAlreadyAcceptedError; exports.InvitationRevokedError = InvitationRevokedError; exports.WorkflowInvitationService = WorkflowInvitationService; exports.WorkflowRelationService = WorkflowRelationService; exports.WorkflowService = WorkflowService; exports.UserProfileService = UserProfileService; exports.DocumentGenerationTemplateNotFoundError = DocumentGenerationTemplateNotFoundError; exports.DocumentGenerationNotConfiguredError = DocumentGenerationNotConfiguredError; exports.DocumentGenerationService = DocumentGenerationService; exports.DocumentTemplateService = DocumentTemplateService; exports.DocumentService = DocumentService; exports.DocumentProcessingService = DocumentProcessingService; exports.FileService = FileService; exports.GeocodingService = GeocodingService; exports.GlobalSearchService = GlobalSearchService; exports.PermissionService = PermissionService; exports.ViewService = ViewService; exports.seedRegistryViews = seedRegistryViews; exports.syncNativeViews = syncNativeViews; exports.verifyRegistryViewsSeeded = verifyRegistryViewsSeeded; exports.verifyNativeViewsSync = verifyNativeViewsSync; exports.getViewSeedPreview = getViewSeedPreview; exports.getViewSyncPreview = getViewSyncPreview; exports.syncNativeObjects = syncNativeObjects; exports.verifyNativeObjectsSync = verifyNativeObjectsSync; exports.getSyncPreview = getSyncPreview; exports.syncAll = syncAll;