@wix/wix-data-items-common 1.0.305 → 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 (58) hide show
  1. package/dist/cjs/api/PagingMetadata.js +4 -0
  2. package/dist/cjs/api/PagingMetadata.js.map +1 -0
  3. package/dist/cjs/api/WixDataAggregateResponse.js +4 -0
  4. package/dist/cjs/api/WixDataAggregateResponse.js.map +1 -0
  5. package/dist/cjs/api/WixDataApi.js +82 -33
  6. package/dist/cjs/api/WixDataApi.js.map +1 -1
  7. package/dist/cjs/api/WixDataDistinctResponse.js +4 -0
  8. package/dist/cjs/api/WixDataDistinctResponse.js.map +1 -0
  9. package/dist/cjs/api/WixDataQueryReferencedItemsResponse.js +4 -0
  10. package/dist/cjs/api/WixDataQueryReferencedItemsResponse.js.map +1 -0
  11. package/dist/cjs/api/WixDataQueryResponse.js +4 -0
  12. package/dist/cjs/api/WixDataQueryResponse.js.map +1 -0
  13. package/dist/cjs/api/WixDataSearchResponse.js +4 -0
  14. package/dist/cjs/api/WixDataSearchResponse.js.map +1 -0
  15. package/dist/cjs/api/index.js +17 -1
  16. package/dist/cjs/api/index.js.map +1 -1
  17. package/dist/cjs/api/types.js.map +1 -1
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/types/data-item-types.js.map +1 -1
  20. package/dist/esm/api/PagingMetadata.js +2 -0
  21. package/dist/esm/api/PagingMetadata.js.map +1 -0
  22. package/dist/esm/api/WixDataAggregateResponse.js +2 -0
  23. package/dist/esm/api/WixDataAggregateResponse.js.map +1 -0
  24. package/dist/esm/api/WixDataApi.js +84 -32
  25. package/dist/esm/api/WixDataApi.js.map +1 -1
  26. package/dist/esm/api/WixDataDistinctResponse.js +2 -0
  27. package/dist/esm/api/WixDataDistinctResponse.js.map +1 -0
  28. package/dist/esm/api/WixDataQueryReferencedItemsResponse.js +2 -0
  29. package/dist/esm/api/WixDataQueryReferencedItemsResponse.js.map +1 -0
  30. package/dist/esm/api/WixDataQueryResponse.js +2 -0
  31. package/dist/esm/api/WixDataQueryResponse.js.map +1 -0
  32. package/dist/esm/api/WixDataSearchResponse.js +2 -0
  33. package/dist/esm/api/WixDataSearchResponse.js.map +1 -0
  34. package/dist/esm/api/index.js.map +1 -1
  35. package/dist/esm/types/data-item-types.js.map +1 -1
  36. package/dist/types/api/PagingMetadata.d.ts +25 -0
  37. package/dist/types/api/PagingMetadata.d.ts.map +1 -0
  38. package/dist/types/api/WixDataAggregateResponse.d.ts +8 -0
  39. package/dist/types/api/WixDataAggregateResponse.d.ts.map +1 -0
  40. package/dist/types/api/WixDataApi.d.ts +13 -5
  41. package/dist/types/api/WixDataApi.d.ts.map +1 -1
  42. package/dist/types/api/WixDataDistinctResponse.d.ts +8 -0
  43. package/dist/types/api/WixDataDistinctResponse.d.ts.map +1 -0
  44. package/dist/types/api/WixDataQueryReferencedItemsResponse.d.ts +23 -0
  45. package/dist/types/api/WixDataQueryReferencedItemsResponse.d.ts.map +1 -0
  46. package/dist/types/api/WixDataQueryResponse.d.ts +9 -0
  47. package/dist/types/api/WixDataQueryResponse.d.ts.map +1 -0
  48. package/dist/types/api/WixDataSearchResponse.d.ts +9 -0
  49. package/dist/types/api/WixDataSearchResponse.d.ts.map +1 -0
  50. package/dist/types/api/index.d.ts +7 -1
  51. package/dist/types/api/index.d.ts.map +1 -1
  52. package/dist/types/api/types.d.ts +18 -0
  53. package/dist/types/api/types.d.ts.map +1 -1
  54. package/dist/types/index.d.ts +1 -0
  55. package/dist/types/index.d.ts.map +1 -1
  56. package/dist/types/types/data-item-types.d.ts +3 -1
  57. package/dist/types/types/data-item-types.d.ts.map +1 -1
  58. package/package.json +2 -2
@@ -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":[]}
@@ -337,7 +337,7 @@ class WixDataApi {
337
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);
338
338
  const offset = (options == null || (_options$paging2 = options.paging) == null ? void 0 : _options$paging2.offset) ?? 0;
339
339
  const cursor = options == null || (_options$cursorPaging2 = options.cursorPaging) == null ? void 0 : _options$cursorPaging2.cursor;
340
- const fetch = (cursorOrOffset, returnTotalCount) => this.trace('distinct', {
340
+ return this.trace('distinct', {
341
341
  collectionName,
342
342
  field: fieldName
343
343
  })(async env => {
@@ -348,21 +348,18 @@ class WixDataApi {
348
348
  ...env,
349
349
  dataCollectionId: collectionName,
350
350
  ...toReadOptions(options),
351
- ...toPaging(limit, cursorOrOffset),
352
- ...(isOffset(cursorOrOffset) ? {
351
+ ...toPaging(limit, cursor ?? offset),
352
+ ...(cursor === undefined ? {
353
353
  fieldName,
354
354
  filter: options == null ? void 0 : options.filter,
355
355
  order: options == null ? void 0 : options.order,
356
- returnTotalCount
356
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
357
357
  } : {})
358
358
  });
359
- return [distinctValues, pagingMetadata];
360
- });
361
- const [items, paging] = await fetch(cursor ?? offset, options == null ? void 0 : options.returnTotalCount);
362
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
363
- collectionName,
364
- limitNumber: limit,
365
- skipNumber: offset
359
+ return {
360
+ values: distinctValues,
361
+ pagingMetadata: pagingMetadata
362
+ };
366
363
  });
367
364
  }));
368
365
  /** @internal */
@@ -498,6 +495,36 @@ class WixDataApi {
498
495
  skipNumber: (options == null ? void 0 : options.skip) ?? 0
499
496
  });
500
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
+ }));
501
528
  (0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
502
529
  let refs;
503
530
  let opts;
@@ -839,7 +866,7 @@ class WixDataApi {
839
866
  field: inc.field,
840
867
  limit: inc.limit
841
868
  }));
842
- const fetch = (cursorOrOffset, returnTotalCount) => this.trace('query', {
869
+ return this.trace('query', {
843
870
  collectionName
844
871
  })(async env => {
845
872
  var _options$includeField2;
@@ -851,28 +878,25 @@ class WixDataApi {
851
878
  dataCollectionId: collectionName,
852
879
  query: {
853
880
  fields: request.fields,
854
- ...toPaging(limit, cursorOrOffset),
855
- ...(isOffset(cursorOrOffset) ? {
881
+ ...toPaging(limit, cursor ?? offset),
882
+ ...(cursor === undefined ? {
856
883
  filter: request.filter,
857
884
  sort: toSort(sort)
858
885
  } : {})
859
886
  },
860
887
  includeReferences,
861
888
  ...toReadOptions(options),
862
- ...(isOffset(cursorOrOffset) ? {
863
- returnTotalCount
889
+ ...(cursor === undefined ? {
890
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
864
891
  } : {}),
865
892
  ...(options != null && (_options$includeField2 = options.includeFieldGroups) != null && _options$includeField2.length ? {
866
893
  includeFieldGroups: options.includeFieldGroups
867
894
  } : {})
868
895
  });
869
- return [dataItems.map(toDataItem), pagingMetadata];
870
- });
871
- const [items, paging] = await fetch(cursor ?? offset, options == null ? void 0 : options.returnTotalCount);
872
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
873
- collectionName,
874
- limitNumber: limit,
875
- skipNumber: offset
896
+ return {
897
+ items: dataItems.map(toDataItem),
898
+ pagingMetadata: pagingMetadata
899
+ };
876
900
  });
877
901
  }
878
902
 
@@ -950,7 +974,7 @@ class WixDataApi {
950
974
  field: inc.field,
951
975
  limit: inc.limit
952
976
  }));
953
- const fetch = cursorOrOffset => this.trace('search', {
977
+ return this.trace('search', {
954
978
  collectionName,
955
979
  search: request.search
956
980
  })(async env => {
@@ -969,18 +993,15 @@ class WixDataApi {
969
993
  order: s.order
970
994
  })),
971
995
  search: request.search,
972
- ...toPaging(limit, cursorOrOffset)
996
+ ...toPaging(limit, cursor ?? offset)
973
997
  },
974
998
  includeReferences,
975
999
  ...toReadOptions(options)
976
1000
  });
977
- return [dataItems.map(toDataItem), pagingMetadata];
978
- });
979
- const [items, paging] = await fetch(cursor ?? offset);
980
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
981
- collectionName,
982
- limitNumber: limit,
983
- skipNumber: offset
1001
+ return {
1002
+ items: dataItems.map(toDataItem),
1003
+ pagingMetadata: pagingMetadata
1004
+ };
984
1005
  });
985
1006
  } // --- aggregate ---
986
1007
  /**
@@ -993,7 +1014,7 @@ class WixDataApi {
993
1014
  */
994
1015
  aggregate(collectionName, pipeline, options) {
995
1016
  if (pipeline !== undefined) {
996
- return this.aggregatePipeline(collectionName, pipeline, options);
1017
+ return this.executeDirectAggregate(collectionName, pipeline, options);
997
1018
  }
998
1019
  return new _WixDataAggregateImpl.WixDataAggregateImpl({
999
1020
  collectionName,
@@ -1041,6 +1062,16 @@ class WixDataApi {
1041
1062
  }
1042
1063
  });
1043
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
+ }
1044
1075
  async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
1045
1076
  const request = {
1046
1077
  ...env,
@@ -1278,6 +1309,24 @@ function unwrapAggregationId(items) {
1278
1309
  function onlyReferencedItems(results) {
1279
1310
  return results.map(result => result.dataItem).filter(notEmpty).map(toDataItem);
1280
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
+ }
1281
1330
  function notEmpty(value) {
1282
1331
  return value != null;
1283
1332
  }