@wix/wix-data-items-common 1.0.304 → 1.0.306

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.
Files changed (86) hide show
  1. package/dist/cjs/api/FieldModification.js +4 -0
  2. package/dist/cjs/api/FieldModification.js.map +1 -0
  3. package/dist/cjs/api/PagingMetadata.js +4 -0
  4. package/dist/cjs/api/PagingMetadata.js.map +1 -0
  5. package/dist/cjs/api/WixDataAggregateResponse.js +4 -0
  6. package/dist/cjs/api/WixDataAggregateResponse.js.map +1 -0
  7. package/dist/cjs/api/WixDataApi.js +208 -88
  8. package/dist/cjs/api/WixDataApi.js.map +1 -1
  9. package/dist/cjs/api/WixDataDistinctResponse.js +4 -0
  10. package/dist/cjs/api/WixDataDistinctResponse.js.map +1 -0
  11. package/dist/cjs/api/WixDataFieldModificationsBuilder.js +51 -0
  12. package/dist/cjs/api/WixDataFieldModificationsBuilder.js.map +1 -0
  13. package/dist/cjs/api/WixDataPatch.js.map +1 -1
  14. package/dist/cjs/api/WixDataQueryReferencedItemsResponse.js +4 -0
  15. package/dist/cjs/api/WixDataQueryReferencedItemsResponse.js.map +1 -0
  16. package/dist/cjs/api/WixDataQueryResponse.js +4 -0
  17. package/dist/cjs/api/WixDataQueryResponse.js.map +1 -0
  18. package/dist/cjs/api/WixDataSearchResponse.js +4 -0
  19. package/dist/cjs/api/WixDataSearchResponse.js.map +1 -0
  20. package/dist/cjs/api/impl/BaseFieldModificationsBuilder.js +85 -0
  21. package/dist/cjs/api/impl/BaseFieldModificationsBuilder.js.map +1 -0
  22. package/dist/cjs/api/impl/WixDataPatchImpl.js +13 -82
  23. package/dist/cjs/api/impl/WixDataPatchImpl.js.map +1 -1
  24. package/dist/cjs/api/index.js +29 -3
  25. package/dist/cjs/api/index.js.map +1 -1
  26. package/dist/cjs/api/types.js.map +1 -1
  27. package/dist/cjs/index.js.map +1 -1
  28. package/dist/cjs/types/data-item-types.js.map +1 -1
  29. package/dist/esm/api/FieldModification.js +2 -0
  30. package/dist/esm/api/FieldModification.js.map +1 -0
  31. package/dist/esm/api/PagingMetadata.js +2 -0
  32. package/dist/esm/api/PagingMetadata.js.map +1 -0
  33. package/dist/esm/api/WixDataAggregateResponse.js +2 -0
  34. package/dist/esm/api/WixDataAggregateResponse.js.map +1 -0
  35. package/dist/esm/api/WixDataApi.js +166 -80
  36. package/dist/esm/api/WixDataApi.js.map +1 -1
  37. package/dist/esm/api/WixDataDistinctResponse.js +2 -0
  38. package/dist/esm/api/WixDataDistinctResponse.js.map +1 -0
  39. package/dist/esm/api/WixDataFieldModificationsBuilder.js +38 -0
  40. package/dist/esm/api/WixDataFieldModificationsBuilder.js.map +1 -0
  41. package/dist/esm/api/WixDataQueryReferencedItemsResponse.js +2 -0
  42. package/dist/esm/api/WixDataQueryReferencedItemsResponse.js.map +1 -0
  43. package/dist/esm/api/WixDataQueryResponse.js +2 -0
  44. package/dist/esm/api/WixDataQueryResponse.js.map +1 -0
  45. package/dist/esm/api/WixDataSearchResponse.js +2 -0
  46. package/dist/esm/api/WixDataSearchResponse.js.map +1 -0
  47. package/dist/esm/api/impl/BaseFieldModificationsBuilder.js +87 -0
  48. package/dist/esm/api/impl/BaseFieldModificationsBuilder.js.map +1 -0
  49. package/dist/esm/api/impl/WixDataPatchImpl.js +10 -90
  50. package/dist/esm/api/impl/WixDataPatchImpl.js.map +1 -1
  51. package/dist/esm/api/index.js +1 -0
  52. package/dist/esm/api/index.js.map +1 -1
  53. package/dist/esm/types/data-item-types.js.map +1 -1
  54. package/dist/types/api/FieldModification.d.ts +41 -0
  55. package/dist/types/api/FieldModification.d.ts.map +1 -0
  56. package/dist/types/api/PagingMetadata.d.ts +25 -0
  57. package/dist/types/api/PagingMetadata.d.ts.map +1 -0
  58. package/dist/types/api/WixDataAggregateResponse.d.ts +8 -0
  59. package/dist/types/api/WixDataAggregateResponse.d.ts.map +1 -0
  60. package/dist/types/api/WixDataApi.d.ts +45 -8
  61. package/dist/types/api/WixDataApi.d.ts.map +1 -1
  62. package/dist/types/api/WixDataDistinctResponse.d.ts +8 -0
  63. package/dist/types/api/WixDataDistinctResponse.d.ts.map +1 -0
  64. package/dist/types/api/WixDataFieldModificationsBuilder.d.ts +88 -0
  65. package/dist/types/api/WixDataFieldModificationsBuilder.d.ts.map +1 -0
  66. package/dist/types/api/WixDataPatch.d.ts +17 -167
  67. package/dist/types/api/WixDataPatch.d.ts.map +1 -1
  68. package/dist/types/api/WixDataQueryReferencedItemsResponse.d.ts +23 -0
  69. package/dist/types/api/WixDataQueryReferencedItemsResponse.d.ts.map +1 -0
  70. package/dist/types/api/WixDataQueryResponse.d.ts +9 -0
  71. package/dist/types/api/WixDataQueryResponse.d.ts.map +1 -0
  72. package/dist/types/api/WixDataSearchResponse.d.ts +9 -0
  73. package/dist/types/api/WixDataSearchResponse.d.ts.map +1 -0
  74. package/dist/types/api/impl/BaseFieldModificationsBuilder.d.ts +21 -0
  75. package/dist/types/api/impl/BaseFieldModificationsBuilder.d.ts.map +1 -0
  76. package/dist/types/api/impl/WixDataPatchImpl.d.ts +12 -27
  77. package/dist/types/api/impl/WixDataPatchImpl.d.ts.map +1 -1
  78. package/dist/types/api/index.d.ts +10 -2
  79. package/dist/types/api/index.d.ts.map +1 -1
  80. package/dist/types/api/types.d.ts +18 -12
  81. package/dist/types/api/types.d.ts.map +1 -1
  82. package/dist/types/index.d.ts +2 -0
  83. package/dist/types/index.d.ts.map +1 -1
  84. package/dist/types/types/data-item-types.d.ts +3 -1
  85. package/dist/types/types/data-item-types.d.ts.map +1 -1
  86. package/package.json +2 -2
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ //# sourceMappingURL=FieldModification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../src/api/FieldModification.ts"],"sourcesContent":["export interface SetField {\n /**\n * Path of the field ID to be modified. Nested fields can be specified using dot notation.\n */\n fieldPath: string\n action: 'SET_FIELD'\n value: any\n}\n\nexport interface RemoveField {\n /**\n * Path of the field ID to be modified. Nested fields can be specified using dot notation.\n */\n fieldPath: string\n action: 'REMOVE_FIELD'\n}\n\nexport interface IncrementField {\n /**\n * Path of the field ID to be modified. Nested fields can be specified using dot notation.\n */\n fieldPath: string\n action: 'INCREMENT_FIELD'\n value: any\n}\n\nexport interface AppendToArray {\n /**\n * Path of the field ID to be modified. Nested fields can be specified using dot notation.\n */\n fieldPath: string\n action: 'APPEND_TO_ARRAY'\n value: any\n}\n\nexport interface RemoveFromArray {\n /**\n * Path of the field ID to be modified. Nested fields can be specified using dot notation.\n */\n fieldPath: string\n action: 'REMOVE_FROM_ARRAY'\n value: any\n}\n\nexport type FieldModification =\n | SetField\n | RemoveField\n | IncrementField\n | AppendToArray\n | RemoveFromArray\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ //# sourceMappingURL=PagingMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../src/api/PagingMetadata.ts"],"sourcesContent":["export interface PagingMetadata {\n /** Number of items returned in the response. */\n count?: number | null\n /** Offset that was requested. */\n offset?: number | null\n /** Total number of items that match the query. Returned if offset paging is used, `returnTotalCount` is `true` in the request, and `tooManyToCount` is false. */\n total?: number | null\n /** Whether the server failed to calculate the `total` field. */\n tooManyToCount?: boolean | null\n /** Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used. */\n cursors?: Cursors\n /**\n * Indicates if there are more results after the current page.\n * If `true`, another page of results can be retrieved.\n * If `false`, this is the last page.\n */\n hasNext?: boolean | null\n}\n\nexport interface Cursors {\n /** Cursor pointing to next page in the list of results. */\n next?: string | null\n /** Cursor pointing to previous page in the list of results. */\n prev?: string | null\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ //# sourceMappingURL=WixDataAggregateResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../src/api/WixDataAggregateResponse.ts"],"sourcesContent":["import { PagingMetadata } from './PagingMetadata'\n\nexport interface WixDataAggregateResponse<Result = Record<string, any>> {\n /** Aggregated results. */\n results: Result[]\n\n /** Paging information. */\n pagingMetadata: PagingMetadata\n}\n"],"mappings":"","ignoreList":[]}
@@ -176,7 +176,7 @@ class WixDataApi {
176
176
  action: apiTypes.ACTION.SET_FIELD,
177
177
  fieldPath: fieldModification.fieldPath,
178
178
  setFieldOptions: {
179
- value: fieldModification.actionOptions
179
+ value: fieldModification.value
180
180
  }
181
181
  };
182
182
  case 'REMOVE_FIELD':
@@ -189,7 +189,7 @@ class WixDataApi {
189
189
  action: apiTypes.ACTION.INCREMENT_FIELD,
190
190
  fieldPath: fieldModification.fieldPath,
191
191
  incrementFieldOptions: {
192
- value: fieldModification.actionOptions
192
+ value: fieldModification.value
193
193
  }
194
194
  };
195
195
  case 'APPEND_TO_ARRAY':
@@ -197,7 +197,7 @@ class WixDataApi {
197
197
  action: apiTypes.ACTION.APPEND_TO_ARRAY,
198
198
  fieldPath: fieldModification.fieldPath,
199
199
  appendToArrayOptions: {
200
- value: fieldModification.actionOptions
200
+ value: fieldModification.value
201
201
  }
202
202
  };
203
203
  case 'REMOVE_FROM_ARRAY':
@@ -205,61 +205,11 @@ class WixDataApi {
205
205
  action: apiTypes.ACTION.REMOVE_FROM_ARRAY,
206
206
  fieldPath: fieldModification.fieldPath,
207
207
  removeFromArrayOptions: {
208
- value: fieldModification.actionOptions
208
+ value: fieldModification.value
209
209
  }
210
210
  };
211
- default:
212
- throw new Error('Invalid patch action');
213
211
  }
214
212
  });
215
- (0, _defineProperty2.default)(this, "patch", (collectionName, itemId) => {
216
- return new _WixDataPatchImpl.WixDataPatchImpl({
217
- collectionName,
218
- itemId,
219
- onRun: async (_args, patchParams, options) => {
220
- const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
221
- return this.trace('patch', {
222
- collectionName
223
- })(async env => {
224
- const result = await this.client.patchDataItem({
225
- ...env,
226
- dataCollectionId: patchParams.collectionName,
227
- patch: {
228
- dataItemId: patchParams.itemId,
229
- fieldModifications
230
- },
231
- ...toPatchOptions(options)
232
- });
233
- return result.dataItem ? toDataItem(result.dataItem) : null;
234
- });
235
- }
236
- });
237
- });
238
- (0, _defineProperty2.default)(this, "bulkPatch", (collectionName, itemIds) => {
239
- return new _WixDataPatchImpl.WixDataBulkPatchImpl({
240
- collectionName,
241
- itemIds,
242
- onRun: async (_args, patchParams, options) => {
243
- const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
244
- return this.trace('bulkPatch', {
245
- collectionName
246
- })(async env => {
247
- const {
248
- results
249
- } = await this.client.bulkPatchDataItems({
250
- ...env,
251
- dataCollectionId: patchParams.collectionName,
252
- patches: patchParams.itemIds.map(itemId => ({
253
- dataItemId: itemId,
254
- fieldModifications
255
- })),
256
- ...toPatchOptions(options)
257
- });
258
- return toBulkResult(itemIds, results, ['WDE0073']);
259
- });
260
- }
261
- });
262
- });
263
213
  (0, _defineProperty2.default)(this, "asyncPatchByFilter", (collectionName, filter) => {
264
214
  const apiFilter = createExplicitFilter(filter);
265
215
  return new _WixDataPatchImpl.WixDataPatchByFilterImpl({
@@ -387,7 +337,7 @@ class WixDataApi {
387
337
  const limit = (options == null || (_options$paging = options.paging) == null ? void 0 : _options$paging.limit) ?? (options == null || (_options$cursorPaging = options.cursorPaging) == null ? void 0 : _options$cursorPaging.limit);
388
338
  const offset = (options == null || (_options$paging2 = options.paging) == null ? void 0 : _options$paging2.offset) ?? 0;
389
339
  const cursor = options == null || (_options$cursorPaging2 = options.cursorPaging) == null ? void 0 : _options$cursorPaging2.cursor;
390
- const fetch = (cursorOrOffset, returnTotalCount) => this.trace('distinct', {
340
+ return this.trace('distinct', {
391
341
  collectionName,
392
342
  field: fieldName
393
343
  })(async env => {
@@ -398,21 +348,18 @@ class WixDataApi {
398
348
  ...env,
399
349
  dataCollectionId: collectionName,
400
350
  ...toReadOptions(options),
401
- ...toPaging(limit, cursorOrOffset),
402
- ...(isOffset(cursorOrOffset) ? {
351
+ ...toPaging(limit, cursor ?? offset),
352
+ ...(cursor === undefined ? {
403
353
  fieldName,
404
354
  filter: options == null ? void 0 : options.filter,
405
355
  order: options == null ? void 0 : options.order,
406
- returnTotalCount
356
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
407
357
  } : {})
408
358
  });
409
- return [distinctValues, pagingMetadata];
410
- });
411
- const [items, paging] = await fetch(cursor ?? offset, options == null ? void 0 : options.returnTotalCount);
412
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
413
- collectionName,
414
- limitNumber: limit,
415
- skipNumber: offset
359
+ return {
360
+ values: distinctValues,
361
+ pagingMetadata: pagingMetadata
362
+ };
416
363
  });
417
364
  }));
418
365
  /** @internal */
@@ -548,6 +495,36 @@ class WixDataApi {
548
495
  skipNumber: (options == null ? void 0 : options.skip) ?? 0
549
496
  });
550
497
  }));
498
+ (0, _defineProperty2.default)(this, "queryReferencedItems", withArgs(async (args, collectionName, referringItem, referringItemFieldName, options) => {
499
+ await apiValidator().arity('queryReferencedItems', args, 3, 4).collectionName(collectionName).referenceParameters(asArray(referringItem)).isNonEmptyString(referringItemFieldName, 'referringItemFieldName').options(options).validateAndReject();
500
+ const referringItemIds = asArray(referringItem).map(itemId);
501
+ return this.trace('queryReferencedItems', {
502
+ collectionName,
503
+ referringItemIds,
504
+ options,
505
+ referringItemFieldName
506
+ })(async env => {
507
+ const {
508
+ results,
509
+ pagingMetadata
510
+ } = await this.client.queryReferencedDataItems({
511
+ ...env,
512
+ ...toReadOptions(options),
513
+ dataCollectionId: collectionName,
514
+ referringItemIds,
515
+ referringItemFieldName,
516
+ order: options == null ? void 0 : options.order,
517
+ paging: options == null ? void 0 : options.paging,
518
+ cursorPaging: options == null ? void 0 : options.cursorPaging,
519
+ fields: options == null ? void 0 : options.fields,
520
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
521
+ });
522
+ return {
523
+ results: toReferencedResults(results ?? []),
524
+ pagingMetadata: pagingMetadata
525
+ };
526
+ });
527
+ }));
551
528
  (0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
552
529
  let refs;
553
530
  let opts;
@@ -639,12 +616,132 @@ class WixDataApi {
639
616
  }
640
617
  get filter() {
641
618
  return (0, _common.filterBuilder)();
642
- } // --- query, count, distinct ---
619
+ }
620
+ /**
621
+ * Returns a patch builder for the specified collection and item.
622
+ * @param collectionName - Name of the collection containing the item to patch.
623
+ * @param itemId - ID of the item to patch.
624
+ * @returns A `WixDataPatch` builder object.
625
+ */
626
+ /**
627
+ * Executes a patch directly without using the builder pattern.
628
+ * @internal
629
+ * @param collectionName - Name of the collection containing the item to patch.
630
+ * @param itemId - ID of the item to patch.
631
+ * @param fieldModifications - Field modifications to apply to the item.
632
+ * @param options - Additional options for the patch operation.
633
+ * @returns Promise that resolves to the patched item, or `null` if no item was returned.
634
+ */
635
+ patch(collectionName, itemId, fieldModifications, options) {
636
+ if (arguments.length >= 3) {
637
+ return this.executeDirectPatch(collectionName, itemId, fieldModifications, options);
638
+ }
639
+ return new _WixDataPatchImpl.WixDataPatchImpl({
640
+ collectionName,
641
+ itemId,
642
+ onRun: async (_args, patchParams, options) => {
643
+ const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
644
+ return this.trace('patch', {
645
+ collectionName
646
+ })(async env => {
647
+ const result = await this.client.patchDataItem({
648
+ ...env,
649
+ dataCollectionId: patchParams.collectionName,
650
+ patch: {
651
+ dataItemId: patchParams.itemId,
652
+ fieldModifications
653
+ },
654
+ ...toPatchOptions(options)
655
+ });
656
+ return result.dataItem ? toDataItem(result.dataItem) : null;
657
+ });
658
+ }
659
+ });
660
+ }
661
+ async executeDirectPatch(collectionName, itemId, fieldModifications, options) {
662
+ const apiFieldModifications = fieldModifications == null ? void 0 : fieldModifications.map(this.toFieldModificationApi);
663
+ return this.trace('patch', {
664
+ collectionName
665
+ })(async env => {
666
+ const result = await this.client.patchDataItem({
667
+ ...env,
668
+ dataCollectionId: collectionName,
669
+ patch: {
670
+ dataItemId: itemId,
671
+ fieldModifications: apiFieldModifications
672
+ },
673
+ ...toPatchOptions(options)
674
+ });
675
+ return result.dataItem ? toDataItem(result.dataItem) : null;
676
+ });
677
+ }
678
+
679
+ /**
680
+ * Executes a bulk patch directly without using the builder pattern.
681
+ * @internal
682
+ * @param collectionName - Name of the collection containing the items to patch.
683
+ * @param itemIds - IDs of the items to patch.
684
+ * @param fieldModifications - Field modifications to apply to the items.
685
+ * @param options - Additional options for the bulk patch operation.
686
+ * @returns Promise that resolves to bulk operation results.
687
+ */
688
+
689
+ bulkPatch(collectionName, itemIds, fieldModifications, options) {
690
+ if (arguments.length >= 3) {
691
+ return this.executeDirectBulkPatch(collectionName, itemIds, fieldModifications, options);
692
+ }
693
+ return new _WixDataPatchImpl.WixDataBulkPatchImpl({
694
+ collectionName,
695
+ itemIds,
696
+ onRun: async (_args, patchParams, options) => {
697
+ const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
698
+ return this.trace('bulkPatch', {
699
+ collectionName
700
+ })(async env => {
701
+ const {
702
+ results
703
+ } = await this.client.bulkPatchDataItems({
704
+ ...env,
705
+ dataCollectionId: patchParams.collectionName,
706
+ patches: patchParams.itemIds.map(itemId => ({
707
+ dataItemId: itemId,
708
+ fieldModifications
709
+ })),
710
+ ...toPatchOptions(options)
711
+ });
712
+ return toBulkResult(itemIds, results, ['WDE0073']);
713
+ });
714
+ }
715
+ });
716
+ }
717
+ async executeDirectBulkPatch(collectionName, itemIds, fieldModifications, options) {
718
+ const apiFieldModifications = fieldModifications == null ? void 0 : fieldModifications.map(this.toFieldModificationApi);
719
+ return this.trace('bulkPatch', {
720
+ collectionName
721
+ })(async env => {
722
+ const {
723
+ results
724
+ } = await this.client.bulkPatchDataItems({
725
+ ...env,
726
+ dataCollectionId: collectionName,
727
+ patches: itemIds.map(itemId => ({
728
+ dataItemId: itemId,
729
+ fieldModifications: apiFieldModifications
730
+ })),
731
+ ...toPatchOptions(options)
732
+ });
733
+ return toBulkResult(itemIds, results, ['WDE0073']);
734
+ });
735
+ }
736
+
737
+ // --- query, count, distinct ---
738
+
643
739
  /**
644
740
  * Returns a query builder for the specified collection.
645
741
  * @param collectionName - Name of the collection to query.
646
742
  * @returns A `WixDataQuery` builder object.
647
743
  */
744
+
648
745
  /**
649
746
  * Executes a query directly without using the builder pattern.
650
747
  * @internal
@@ -653,6 +750,7 @@ class WixDataApi {
653
750
  * @param options - Additional options including includeReferences.
654
751
  * @returns Promise that resolves to the query results.
655
752
  */
753
+
656
754
  query(collectionName, queryRequest, options) {
657
755
  // Direct query execution mode
658
756
  if (queryRequest !== undefined) {
@@ -768,7 +866,7 @@ class WixDataApi {
768
866
  field: inc.field,
769
867
  limit: inc.limit
770
868
  }));
771
- const fetch = (cursorOrOffset, returnTotalCount) => this.trace('query', {
869
+ return this.trace('query', {
772
870
  collectionName
773
871
  })(async env => {
774
872
  var _options$includeField2;
@@ -780,28 +878,25 @@ class WixDataApi {
780
878
  dataCollectionId: collectionName,
781
879
  query: {
782
880
  fields: request.fields,
783
- ...toPaging(limit, cursorOrOffset),
784
- ...(isOffset(cursorOrOffset) ? {
881
+ ...toPaging(limit, cursor ?? offset),
882
+ ...(cursor === undefined ? {
785
883
  filter: request.filter,
786
884
  sort: toSort(sort)
787
885
  } : {})
788
886
  },
789
887
  includeReferences,
790
888
  ...toReadOptions(options),
791
- ...(isOffset(cursorOrOffset) ? {
792
- returnTotalCount
889
+ ...(cursor === undefined ? {
890
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
793
891
  } : {}),
794
892
  ...(options != null && (_options$includeField2 = options.includeFieldGroups) != null && _options$includeField2.length ? {
795
893
  includeFieldGroups: options.includeFieldGroups
796
894
  } : {})
797
895
  });
798
- return [dataItems.map(toDataItem), pagingMetadata];
799
- });
800
- const [items, paging] = await fetch(cursor ?? offset, options == null ? void 0 : options.returnTotalCount);
801
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
802
- collectionName,
803
- limitNumber: limit,
804
- skipNumber: offset
896
+ return {
897
+ items: dataItems.map(toDataItem),
898
+ pagingMetadata: pagingMetadata
899
+ };
805
900
  });
806
901
  }
807
902
 
@@ -879,7 +974,7 @@ class WixDataApi {
879
974
  field: inc.field,
880
975
  limit: inc.limit
881
976
  }));
882
- const fetch = cursorOrOffset => this.trace('search', {
977
+ return this.trace('search', {
883
978
  collectionName,
884
979
  search: request.search
885
980
  })(async env => {
@@ -898,18 +993,15 @@ class WixDataApi {
898
993
  order: s.order
899
994
  })),
900
995
  search: request.search,
901
- ...toPaging(limit, cursorOrOffset)
996
+ ...toPaging(limit, cursor ?? offset)
902
997
  },
903
998
  includeReferences,
904
999
  ...toReadOptions(options)
905
1000
  });
906
- return [dataItems.map(toDataItem), pagingMetadata];
907
- });
908
- const [items, paging] = await fetch(cursor ?? offset);
909
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
910
- collectionName,
911
- limitNumber: limit,
912
- skipNumber: offset
1001
+ return {
1002
+ items: dataItems.map(toDataItem),
1003
+ pagingMetadata: pagingMetadata
1004
+ };
913
1005
  });
914
1006
  } // --- aggregate ---
915
1007
  /**
@@ -922,7 +1014,7 @@ class WixDataApi {
922
1014
  */
923
1015
  aggregate(collectionName, pipeline, options) {
924
1016
  if (pipeline !== undefined) {
925
- return this.aggregatePipeline(collectionName, pipeline, options);
1017
+ return this.executeDirectAggregate(collectionName, pipeline, options);
926
1018
  }
927
1019
  return new _WixDataAggregateImpl.WixDataAggregateImpl({
928
1020
  collectionName,
@@ -970,6 +1062,16 @@ class WixDataApi {
970
1062
  }
971
1063
  });
972
1064
  }
1065
+ async executeDirectAggregate(collectionName, pipeline, options) {
1066
+ const {
1067
+ results,
1068
+ pagingMetadata
1069
+ } = await this.aggregatePipeline(collectionName, pipeline, options);
1070
+ return {
1071
+ results: results,
1072
+ pagingMetadata: pagingMetadata
1073
+ };
1074
+ }
973
1075
  async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
974
1076
  const request = {
975
1077
  ...env,
@@ -1207,6 +1309,24 @@ function unwrapAggregationId(items) {
1207
1309
  function onlyReferencedItems(results) {
1208
1310
  return results.map(result => result.dataItem).filter(notEmpty).map(toDataItem);
1209
1311
  }
1312
+ function toReferencedResults(results) {
1313
+ return results.map(result => {
1314
+ const wireResult = result;
1315
+ const unresolvedReference = wireResult.unresolvedReference;
1316
+ const referencedResult = {
1317
+ referringItemId: wireResult.referringItemId ?? (unresolvedReference == null ? void 0 : unresolvedReference.referringItemId)
1318
+ };
1319
+ if (result.dataItem) {
1320
+ referencedResult.item = toDataItem(result.dataItem);
1321
+ } else {
1322
+ referencedResult.unresolvedReference = {
1323
+ referencedItemId: unresolvedReference == null ? void 0 : unresolvedReference.referencedItemId,
1324
+ unauthorized: (unresolvedReference == null ? void 0 : unresolvedReference.unauthorized) ?? false
1325
+ };
1326
+ }
1327
+ return referencedResult;
1328
+ });
1329
+ }
1210
1330
  function notEmpty(value) {
1211
1331
  return value != null;
1212
1332
  }