@stndrds/schema 0.1.0-alpha.59 → 0.1.0-alpha.61

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.
@@ -307,8 +307,8 @@ var cacheKeys = {
307
307
  searchResults: (tenantId, objectId, hash) => `search:${tenantId}:${objectId}:${hash}`,
308
308
  /** All search results for an object (for invalidation) */
309
309
  allSearchResults: (tenantId, objectId) => `search:${tenantId}:${objectId}:*`,
310
- /** Global search results */
311
- globalSearch: (tenantId, hash) => `gsearch:${tenantId}:${hash}`,
310
+ /** Global search results (3-param signature to match cachedList pattern) */
311
+ globalSearch: (tenantId, _id, hash) => `gsearch:${tenantId}:${hash}`,
312
312
  /** All global search results for tenant (for invalidation) */
313
313
  allGlobalSearch: (tenantId) => `gsearch:${tenantId}:*`,
314
314
  // -------------------------------------------------------------------------
@@ -1885,6 +1885,41 @@ function evaluateWithTrace(condition, context) {
1885
1885
  return evaluateCondition(condition, context, true);
1886
1886
  }
1887
1887
 
1888
+ // src/types/errors.ts
1889
+ var RecordReferencedError = class extends Error {
1890
+ constructor(recordId, references) {
1891
+ const total = references.reduce((sum, r) => sum + r.count, 0);
1892
+ super(`Cannot delete record: referenced by ${total} record${total > 1 ? "s" : ""}`);
1893
+ this.recordId = recordId;
1894
+ this.references = references;
1895
+ this.code = "RECORD_REFERENCED";
1896
+ this.name = "RecordReferencedError";
1897
+ }
1898
+ };
1899
+ var AttributeInUseError = class extends Error {
1900
+ constructor(attributeName, usage) {
1901
+ super(`Cannot delete attribute "${attributeName}": used in ${usage}`);
1902
+ this.attributeName = attributeName;
1903
+ this.usage = usage;
1904
+ this.code = "ATTRIBUTE_IN_USE";
1905
+ this.name = "AttributeInUseError";
1906
+ }
1907
+ };
1908
+ var ObjectReferencedError = class extends Error {
1909
+ constructor(objectName, referencingObjects) {
1910
+ super(
1911
+ `Cannot delete object "${objectName}": target of relations in ${referencingObjects.join(", ")}`
1912
+ );
1913
+ this.objectName = objectName;
1914
+ this.referencingObjects = referencingObjects;
1915
+ this.code = "OBJECT_REFERENCED";
1916
+ this.name = "ObjectReferencedError";
1917
+ }
1918
+ };
1919
+ function getErrorMessage(error2) {
1920
+ return error2 instanceof Error ? error2.message : String(error2);
1921
+ }
1922
+
1888
1923
  // src/runtime/executors/types.ts
1889
1924
  var ExecutorRegistry = class {
1890
1925
  constructor() {
@@ -1927,7 +1962,7 @@ var ExecutorRegistry = class {
1927
1962
  return {
1928
1963
  status: "error",
1929
1964
  code: "EXECUTOR_ERROR",
1930
- message: error2 instanceof Error ? error2.message : "Unknown error",
1965
+ message: getErrorMessage(error2),
1931
1966
  retryable: true
1932
1967
  };
1933
1968
  }
@@ -2418,7 +2453,7 @@ function evaluateFormulaWithResult(expression, values) {
2418
2453
  } catch (error2) {
2419
2454
  return {
2420
2455
  value: null,
2421
- error: error2 instanceof Error ? error2.message : "Unknown error"
2456
+ error: getErrorMessage(error2)
2422
2457
  };
2423
2458
  }
2424
2459
  }
@@ -2458,7 +2493,7 @@ function validateFormulaExpression(expression) {
2458
2493
  } catch (error2) {
2459
2494
  return {
2460
2495
  valid: false,
2461
- error: error2 instanceof Error ? error2.message : "Invalid expression"
2496
+ error: getErrorMessage(error2)
2462
2497
  };
2463
2498
  }
2464
2499
  }
@@ -3949,7 +3984,6 @@ function createMockObjectRecordsRepository(stores) {
3949
3984
  objectLabel: obj?.label ?? "Unknown",
3950
3985
  label: renderLabelExpression(labelExpression, enrichedValues),
3951
3986
  recordId: r.id,
3952
- values: r.values,
3953
3987
  completionStatus: r.completionStatus,
3954
3988
  createdAt: r.createdAt,
3955
3989
  updatedAt: r.updatedAt
@@ -3957,6 +3991,36 @@ function createMockObjectRecordsRepository(stores) {
3957
3991
  });
3958
3992
  return Promise.resolve({ results, total });
3959
3993
  },
3994
+ globalSearchGrouped(query, options) {
3995
+ const limitPerGroup = options?.limitPerGroup ?? 5;
3996
+ return this.globalSearch(query, {
3997
+ objectNames: options?.objectNames,
3998
+ limit: 500,
3999
+ offset: 0
4000
+ }).then(({ results }) => {
4001
+ const groupMap = /* @__PURE__ */ new Map();
4002
+ for (const result of results) {
4003
+ let group2 = groupMap.get(result.objectName);
4004
+ if (!group2) {
4005
+ group2 = {
4006
+ objectName: result.objectName,
4007
+ objectLabel: result.objectLabel,
4008
+ results: [],
4009
+ totalInGroup: 0
4010
+ };
4011
+ groupMap.set(result.objectName, group2);
4012
+ }
4013
+ group2.totalInGroup++;
4014
+ if (group2.results.length < limitPerGroup) {
4015
+ group2.results.push(result);
4016
+ }
4017
+ }
4018
+ const groups = Array.from(groupMap.values());
4019
+ groups.sort((a, b) => b.totalInGroup - a.totalInGroup);
4020
+ const total = groups.reduce((sum, g) => sum + g.totalInGroup, 0);
4021
+ return { groups, total };
4022
+ });
4023
+ },
3960
4024
  // -------------------------------------------------------------------------
3961
4025
  // Schema Integrity Methods
3962
4026
  // -------------------------------------------------------------------------
@@ -4060,7 +4124,6 @@ function createMockObjectRecordsRepository(stores) {
4060
4124
  }
4061
4125
 
4062
4126
  // src/runtime/mock/mock-relation-attributes.ts
4063
- import { randomUUID } from "crypto";
4064
4127
  function createMockRelationAttributesRepository(stores) {
4065
4128
  return {
4066
4129
  async upsertBatch(items) {
@@ -4081,7 +4144,7 @@ function createMockRelationAttributesRepository(stores) {
4081
4144
  results.push(existing);
4082
4145
  } else {
4083
4146
  const row = {
4084
- id: randomUUID(),
4147
+ id: generateId(),
4085
4148
  tenantId: context.tenantId,
4086
4149
  fromObject: item.fromObject,
4087
4150
  fromId: item.fromId,
@@ -6927,7 +6990,6 @@ function object(config) {
6927
6990
  }
6928
6991
 
6929
6992
  // src/builders/view-builder.ts
6930
- import { randomUUID as randomUUID2 } from "crypto";
6931
6993
  import { z as z3 } from "zod";
6932
6994
  var GroupBuilder = class {
6933
6995
  constructor(id, label) {
@@ -7787,7 +7849,7 @@ var ListViewBuilder = class {
7787
7849
  columns: this.data.columns,
7788
7850
  columnSizing: this.data.columnSizing,
7789
7851
  defaultFilters: this.data.defaultFilters ? {
7790
- id: randomUUID2(),
7852
+ id: generateId(),
7791
7853
  combinator: this.data.defaultFilters.combinator,
7792
7854
  rules: this.data.defaultFilters.rules
7793
7855
  } : void 0,
@@ -7798,7 +7860,7 @@ var ListViewBuilder = class {
7798
7860
  label: tab.label,
7799
7861
  icon: tab.icon,
7800
7862
  filters: tab.filters ? {
7801
- id: randomUUID2(),
7863
+ id: generateId(),
7802
7864
  combinator: tab.filters.combinator,
7803
7865
  rules: tab.filters.rules
7804
7866
  } : void 0,
@@ -8455,38 +8517,6 @@ function isPresentationProperty(property) {
8455
8517
  return PRESENTATION_PROPERTIES.includes(property);
8456
8518
  }
8457
8519
 
8458
- // src/types/errors.ts
8459
- var RecordReferencedError = class extends Error {
8460
- constructor(recordId, references) {
8461
- const total = references.reduce((sum, r) => sum + r.count, 0);
8462
- super(`Cannot delete record: referenced by ${total} record${total > 1 ? "s" : ""}`);
8463
- this.recordId = recordId;
8464
- this.references = references;
8465
- this.code = "RECORD_REFERENCED";
8466
- this.name = "RecordReferencedError";
8467
- }
8468
- };
8469
- var AttributeInUseError = class extends Error {
8470
- constructor(attributeName, usage) {
8471
- super(`Cannot delete attribute "${attributeName}": used in ${usage}`);
8472
- this.attributeName = attributeName;
8473
- this.usage = usage;
8474
- this.code = "ATTRIBUTE_IN_USE";
8475
- this.name = "AttributeInUseError";
8476
- }
8477
- };
8478
- var ObjectReferencedError = class extends Error {
8479
- constructor(objectName, referencingObjects) {
8480
- super(
8481
- `Cannot delete object "${objectName}": target of relations in ${referencingObjects.join(", ")}`
8482
- );
8483
- this.objectName = objectName;
8484
- this.referencingObjects = referencingObjects;
8485
- this.code = "OBJECT_REFERENCED";
8486
- this.name = "ObjectReferencedError";
8487
- }
8488
- };
8489
-
8490
8520
  // src/types/system-attributes.ts
8491
8521
  var SYSTEM_ATTRIBUTES = {
8492
8522
  createdAt: {
@@ -12358,7 +12388,7 @@ var DocumentRendererService = class {
12358
12388
  throw error2;
12359
12389
  }
12360
12390
  throw new DocumentRenderError(
12361
- `Failed to render document: ${error2 instanceof Error ? error2.message : String(error2)}`,
12391
+ `Failed to render document: ${getErrorMessage(error2)}`,
12362
12392
  template.id,
12363
12393
  error2
12364
12394
  );
@@ -12630,7 +12660,7 @@ var DocumentProcessingHook = class extends BaseService {
12630
12660
  metadata: { ...metadata, status: "completed" }
12631
12661
  };
12632
12662
  } catch (error2) {
12633
- const errorMessage = error2 instanceof Error ? error2.message : String(error2);
12663
+ const errorMessage = getErrorMessage(error2);
12634
12664
  updatedDocuments[nodeId] = {
12635
12665
  ...doc,
12636
12666
  metadata: { ...metadata, status: "failed", error: errorMessage }
@@ -13097,7 +13127,7 @@ var WorkflowInstanceService = class extends BaseService {
13097
13127
  status: "failed",
13098
13128
  error: {
13099
13129
  code: "UNEXPECTED_ERROR",
13100
- message: error2 instanceof Error ? error2.message : String(error2),
13130
+ message: getErrorMessage(error2),
13101
13131
  nodeId: instance.currentNodeId,
13102
13132
  timestamp: /* @__PURE__ */ new Date()
13103
13133
  },
@@ -13143,7 +13173,7 @@ var WorkflowInstanceService = class extends BaseService {
13143
13173
  status: "failed",
13144
13174
  error: {
13145
13175
  code: "UNEXPECTED_ERROR",
13146
- message: error2 instanceof Error ? error2.message : String(error2),
13176
+ message: getErrorMessage(error2),
13147
13177
  nodeId: updatedInstance.currentNodeId,
13148
13178
  timestamp: /* @__PURE__ */ new Date()
13149
13179
  },
@@ -13584,7 +13614,7 @@ var WorkflowInstanceService = class extends BaseService {
13584
13614
  const rolledBackSlots = await this.rollbackSlotOperations(completedOperations);
13585
13615
  const rollbackInfo = rolledBackSlots.length > 0 ? ` Rolled back slots: [${rolledBackSlots.join(", ")}].` : "";
13586
13616
  throw new SchemaError(
13587
- `Failed to persist slot "${slot.id}" (${slot.objectName}): ${error2 instanceof Error ? error2.message : String(error2)}.${rollbackInfo}`,
13617
+ `Failed to persist slot "${slot.id}" (${slot.objectName}): ${getErrorMessage(error2)}.${rollbackInfo}`,
13588
13618
  SchemaErrorCode.VALIDATION_FAILED
13589
13619
  );
13590
13620
  }
@@ -15623,7 +15653,7 @@ var DocumentProcessingService = class extends BaseService {
15623
15653
  await this.documentService.recalculateStatus(job.documentId);
15624
15654
  return completedJob;
15625
15655
  } catch (error2) {
15626
- const errorMessage = error2 instanceof Error ? error2.message : "Unknown error";
15656
+ const errorMessage = getErrorMessage(error2);
15627
15657
  const failedJob = await this.adapter.documentJobs.markFailed(jobId, errorMessage);
15628
15658
  if (job.slotName) {
15629
15659
  const slot = await this.adapter.documentSlots.findByDocumentAndSlot(
@@ -15718,7 +15748,7 @@ var DocumentProcessingService = class extends BaseService {
15718
15748
  await this.documentService.updateStatus(job.documentId, "processing");
15719
15749
  return updatedJob;
15720
15750
  } catch (error2) {
15721
- const errorMessage = error2 instanceof Error ? error2.message : "Unknown error";
15751
+ const errorMessage = getErrorMessage(error2);
15722
15752
  const failedJob = await this.adapter.documentJobs.markFailed(jobId, errorMessage);
15723
15753
  await this.documentService.recalculateStatus(job.documentId);
15724
15754
  return failedJob;
@@ -15887,7 +15917,7 @@ var DocumentProcessingService = class extends BaseService {
15887
15917
  await this.documentService.recalculateStatus(job.documentId);
15888
15918
  return completedJob;
15889
15919
  } catch (error2) {
15890
- const errorMessage = error2 instanceof Error ? error2.message : "Unknown error";
15920
+ const errorMessage = getErrorMessage(error2);
15891
15921
  const failedJob = await this.adapter.documentJobs.markFailed(jobId, errorMessage);
15892
15922
  await this.documentService.recalculateStatus(job.documentId);
15893
15923
  return failedJob;
@@ -16517,23 +16547,6 @@ var GlobalSearchService = class extends BaseService {
16517
16547
  * @param query - Search query string
16518
16548
  * @param options - Search options (pagination, object filters)
16519
16549
  * @returns Matching records with object metadata and total count
16520
- *
16521
- * @example
16522
- * ```typescript
16523
- * // Basic search
16524
- * const { results, total } = await service.search("nike air");
16525
- *
16526
- * // With pagination
16527
- * const { results, total } = await service.search("nike", {
16528
- * limit: 10,
16529
- * offset: 20
16530
- * });
16531
- *
16532
- * // Filter by object types
16533
- * const { results, total } = await service.search("nike", {
16534
- * objectNames: ["products", "orders"]
16535
- * });
16536
- * ```
16537
16550
  */
16538
16551
  async search(query, options) {
16539
16552
  if (!query || query.trim().length === 0) {
@@ -16541,58 +16554,36 @@ var GlobalSearchService = class extends BaseService {
16541
16554
  }
16542
16555
  return this.cachedList(
16543
16556
  "globalSearch",
16544
- "global",
16557
+ "search",
16545
16558
  { query: query.trim(), ...options },
16546
- () => this.executeSearch(query.trim(), options)
16559
+ () => this.adapter.objectRecords.globalSearch(query.trim(), {
16560
+ limit: options?.limit ?? 20,
16561
+ offset: options?.offset ?? 0,
16562
+ objectNames: options?.objectNames
16563
+ })
16547
16564
  );
16548
16565
  }
16549
16566
  /**
16550
- * Internal search execution (extracted for caching)
16551
- */
16552
- async executeSearch(query, options) {
16553
- return await this.adapter.objectRecords.globalSearch(query, {
16554
- limit: options?.limit ?? 20,
16555
- offset: options?.offset ?? 0,
16556
- objectNames: options?.objectNames,
16557
- includeObjectInfo: options?.includeObjectInfo ?? true
16558
- });
16559
- }
16560
- /**
16561
- * Search and group results by object type
16567
+ * Search and group results by object type.
16568
+ * Delegates grouping to the database for accurate per-group counts.
16562
16569
  *
16563
16570
  * @param query - Search query string
16564
- * @param options - Search options
16565
- * @returns Results grouped by object name
16571
+ * @param options - Search options (object filters, limit per group)
16572
+ * @returns Results grouped by object name with per-group totals
16566
16573
  */
16567
16574
  async searchGrouped(query, options) {
16568
- const limitPerGroup = options?.limitPerGroup ?? 5;
16569
- const estimatedGroupCount = 10;
16570
- const fetchLimit = Math.min(limitPerGroup * estimatedGroupCount, 100);
16571
- const { results, total } = await this.search(query, {
16572
- ...options,
16573
- limit: fetchLimit,
16574
- offset: 0
16575
- });
16576
- const groupMap = /* @__PURE__ */ new Map();
16577
- for (const result of results) {
16578
- const existing = groupMap.get(result.objectName);
16579
- if (existing) {
16580
- existing.results.push(result);
16581
- } else {
16582
- groupMap.set(result.objectName, {
16583
- objectName: result.objectName,
16584
- objectLabel: result.objectLabel,
16585
- results: [result]
16586
- });
16587
- }
16575
+ if (!query || query.trim().length === 0) {
16576
+ return { groups: [], total: 0 };
16588
16577
  }
16589
- const groups = Array.from(groupMap.values()).map((g) => ({
16590
- ...g,
16591
- results: g.results.slice(0, limitPerGroup),
16592
- count: g.results.length
16593
- }));
16594
- groups.sort((a, b) => b.count - a.count);
16595
- return { groups, total };
16578
+ return this.cachedList(
16579
+ "globalSearch",
16580
+ "grouped",
16581
+ { query: query.trim(), ...options },
16582
+ () => this.adapter.objectRecords.globalSearchGrouped(query.trim(), {
16583
+ objectNames: options?.objectNames,
16584
+ limitPerGroup: options?.limitPerGroup ?? 5
16585
+ })
16586
+ );
16596
16587
  }
16597
16588
  };
16598
16589
 
@@ -17657,7 +17648,7 @@ function handleViewSyncError(result, view2, error2) {
17657
17648
  result.errors.push({
17658
17649
  viewName: view2.name,
17659
17650
  objectName: view2.object,
17660
- error: error2 instanceof Error ? error2.message : String(error2)
17651
+ error: getErrorMessage(error2)
17661
17652
  });
17662
17653
  }
17663
17654
  async function cleanupOrphanViews(tx, viewsByObjectAndType, result, options) {
@@ -17678,7 +17669,7 @@ function handleTransactionError(result, error2) {
17678
17669
  result.errors.push({
17679
17670
  viewName: "transaction",
17680
17671
  objectName: "",
17681
- error: error2 instanceof Error ? error2.message : String(error2)
17672
+ error: getErrorMessage(error2)
17682
17673
  });
17683
17674
  }
17684
17675
  function logSyncComplete(result, options) {
@@ -17749,7 +17740,7 @@ async function syncNativeObjects(adapter, nativeRegistry, options = {}) {
17749
17740
  result.success = false;
17750
17741
  result.errors.push({
17751
17742
  objectName: nativeObject.name,
17752
- error: error2 instanceof Error ? error2.message : String(error2)
17743
+ error: getErrorMessage(error2)
17753
17744
  });
17754
17745
  }
17755
17746
  }
@@ -17758,7 +17749,7 @@ async function syncNativeObjects(adapter, nativeRegistry, options = {}) {
17758
17749
  result.success = false;
17759
17750
  result.errors.push({
17760
17751
  objectName: "transaction",
17761
- error: error2 instanceof Error ? error2.message : String(error2)
17752
+ error: getErrorMessage(error2)
17762
17753
  });
17763
17754
  }
17764
17755
  if (options.verbose) {
@@ -17938,6 +17929,7 @@ export {
17938
17929
  RecordReferencedError,
17939
17930
  AttributeInUseError,
17940
17931
  ObjectReferencedError,
17932
+ getErrorMessage,
17941
17933
  NoopGeocodingAdapter,
17942
17934
  SYSTEM_FIELD_NAMES,
17943
17935
  RESERVED_ATTRIBUTE_NAMES,