@wix/wix-data-items-common 1.0.307 → 1.0.309

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.
@@ -73,105 +73,6 @@ class WixDataApi {
73
73
  });
74
74
  });
75
75
  }));
76
- // --- single-item methods ---
77
- (0, _defineProperty2.default)(this, "get", withArgs(async (args, collectionName, itemId, options) => {
78
- await apiValidator().arity('get', args, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
79
- return this.trace('get', {
80
- collectionName,
81
- itemId
82
- })(async env => {
83
- var _options$includeField;
84
- const {
85
- dataItem
86
- } = await this.client.getDataItem({
87
- ...env,
88
- dataCollectionId: collectionName,
89
- dataItemId: itemId,
90
- ...toReadOptions(options),
91
- fields: options == null ? void 0 : options.fields,
92
- includeReferences: options == null ? void 0 : options.includeReferences,
93
- ...(options != null && (_options$includeField = options.includeFieldGroups) != null && _options$includeField.length ? {
94
- includeFieldGroups: options.includeFieldGroups
95
- } : {})
96
- }).catch(recover(ItemDoesNotExistCode, {}));
97
- return dataItem ? toDataItem(dataItem) : null;
98
- });
99
- }));
100
- (0, _defineProperty2.default)(this, "insert", withArgs(async (args, collectionName, item, options) => {
101
- await apiValidator().arity('insert', args, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
102
- warnAboutBrokenFields(item);
103
- return this.trace('insert', {
104
- collectionName
105
- })(async env => {
106
- const {
107
- dataItem
108
- } = await this.client.insertDataItem({
109
- ...env,
110
- dataCollectionId: collectionName,
111
- dataItem: {
112
- id: item._id,
113
- data: item
114
- },
115
- ...toInsertOptions(options)
116
- });
117
- return toDataItem(dataItem);
118
- });
119
- }));
120
- (0, _defineProperty2.default)(this, "save", withArgs(async (args, collectionName, item, options) => {
121
- await apiValidator().arity('save', args, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
122
- return this.trace('save', {
123
- collectionName
124
- })(async env => {
125
- const {
126
- dataItem
127
- } = await this.client.saveDataItem({
128
- ...env,
129
- dataCollectionId: collectionName,
130
- dataItem: {
131
- id: item._id,
132
- data: item
133
- },
134
- ...toSaveOptions(options)
135
- });
136
- return toDataItem(dataItem);
137
- });
138
- }));
139
- (0, _defineProperty2.default)(this, "update", withArgs(async (args, collectionName, item, options) => {
140
- await apiValidator().arity('update', args, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
141
- return this.trace('update', {
142
- collectionName
143
- })(async env => {
144
- const {
145
- dataItem
146
- } = await this.client.updateDataItem({
147
- ...env,
148
- dataCollectionId: collectionName,
149
- dataItem: {
150
- id: item._id,
151
- data: item
152
- },
153
- ...toUpdateOptions(options)
154
- });
155
- return toDataItem(dataItem);
156
- });
157
- }));
158
- (0, _defineProperty2.default)(this, "remove", withArgs(async (args, collectionName, itemId, options) => {
159
- await apiValidator().arity('remove', args, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
160
- return this.trace('remove', {
161
- collectionName,
162
- itemId
163
- })(async env => {
164
- const {
165
- dataItem
166
- } = await this.client.removeDataItem({
167
- ...env,
168
- dataCollectionId: collectionName,
169
- dataItemId: itemId,
170
- ...toRemoveOptions(options)
171
- }).catch(recover(ItemDoesNotExistCode, {}));
172
- return dataItem ? toDataItem(dataItem) : null;
173
- });
174
- }));
175
76
  (0, _defineProperty2.default)(this, "toFieldModificationApi", fieldModification => {
176
77
  switch (fieldModification.action) {
177
78
  case 'SET_FIELD':
@@ -213,32 +114,27 @@ class WixDataApi {
213
114
  };
214
115
  }
215
116
  });
216
- (0, _defineProperty2.default)(this, "asyncPatchByFilter", (collectionName, filter) => {
117
+ (0, _defineProperty2.default)(this, "asyncPatchByFilter", withArgs(async (args, collectionName, filter, fieldModifications, options) => {
118
+ await apiValidator().arity('asyncPatchByFilter', args, 3, 4).collectionName(collectionName).options(options).validateAndReject();
217
119
  const apiFilter = createExplicitFilter(filter);
218
- return new _WixDataPatchImpl.WixDataPatchByFilterImpl({
219
- collectionName,
220
- filter: apiFilter,
221
- onRun: async (_args, patchParams, options) => {
222
- const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
223
- return this.trace('asyncPatchByFilter', {
224
- collectionName
225
- })(async env => {
226
- const {
227
- jobId
228
- } = await this.client.asyncPatchDataItemsByFilter({
229
- ...env,
230
- dataCollectionId: patchParams.collectionName,
231
- filter: patchParams.filter,
232
- fieldModifications,
233
- ...toAsyncByFilterOptions(options)
234
- });
235
- return {
236
- jobId: jobId
237
- };
238
- });
239
- }
120
+ const apiFieldModifications = fieldModifications.map(this.toFieldModificationApi);
121
+ return this.trace('asyncPatchByFilter', {
122
+ collectionName
123
+ })(async env => {
124
+ const {
125
+ jobId
126
+ } = await this.client.asyncPatchDataItemsByFilter({
127
+ ...env,
128
+ dataCollectionId: collectionName,
129
+ filter: apiFilter,
130
+ fieldModifications: apiFieldModifications,
131
+ ...toAsyncPatchByFilterOptions(options)
132
+ });
133
+ return {
134
+ jobId: jobId
135
+ };
240
136
  });
241
- });
137
+ }));
242
138
  (0, _defineProperty2.default)(this, "asyncRemoveByFilter", withArgs(async (args, collectionName, filter, options) => {
243
139
  await apiValidator().arity('asyncRemoveByFilter', args, 2, 3).collectionName(collectionName).options(options).validateAndReject();
244
140
  const apiFilter = createExplicitFilter(filter);
@@ -334,37 +230,6 @@ class WixDataApi {
334
230
  return this.client.aggregatePipelineDataItems(request);
335
231
  });
336
232
  }));
337
- (0, _defineProperty2.default)(this, "distinct", withArgs(async (args, collectionName, fieldName, options) => {
338
- var _options$paging, _options$cursorPaging, _options$paging2, _options$cursorPaging2;
339
- await apiValidator().arity('distinct', args, 2, 3).collectionName(collectionName).fieldName(fieldName).options(options).validateAndReject();
340
- 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);
341
- const offset = (options == null || (_options$paging2 = options.paging) == null ? void 0 : _options$paging2.offset) ?? 0;
342
- const cursor = options == null || (_options$cursorPaging2 = options.cursorPaging) == null ? void 0 : _options$cursorPaging2.cursor;
343
- return this.trace('distinct', {
344
- collectionName,
345
- field: fieldName
346
- })(async env => {
347
- const {
348
- distinctValues,
349
- pagingMetadata
350
- } = await this.client.queryDistinctValues({
351
- ...env,
352
- dataCollectionId: collectionName,
353
- ...toReadOptions(options),
354
- ...toPaging(limit, cursor ?? offset),
355
- ...(cursor === undefined ? {
356
- fieldName,
357
- filter: options == null ? void 0 : options.filter,
358
- order: options == null ? void 0 : options.order,
359
- returnTotalCount: options == null ? void 0 : options.returnTotalCount
360
- } : {})
361
- });
362
- return {
363
- values: distinctValues,
364
- pagingMetadata: pagingMetadata
365
- };
366
- });
367
- }));
368
233
  /** @internal */
369
234
  (0, _defineProperty2.default)(this, "count", withArgs(async (args, collectionName, options) => {
370
235
  await apiValidator().arity('count', args, 1, 2).collectionName(collectionName).options(options).validateAndReject();
@@ -406,39 +271,6 @@ class WixDataApi {
406
271
  return toBulkResult(itemIds, results, ['WDE0073']);
407
272
  });
408
273
  }));
409
- (0, _defineProperty2.default)(this, "bulkInsert", withArgs(async (args, collectionName, items, options) => {
410
- await apiValidator().arity('bulkInsert', args, 2, 3).items(items, collectionName).bulkInsertOptions(options).collectionName(collectionName).validateAndReject();
411
- return this.trace('bulkInsert', {
412
- collectionName,
413
- options
414
- })(async appId => this.runBulkSave(appId, collectionName, items, options, (options == null ? void 0 : options.overrideExisting) ?? false));
415
- }));
416
- (0, _defineProperty2.default)(this, "bulkSave", withArgs(async (args, collectionName, items, options) => {
417
- await apiValidator().arity('bulkSave', args, 2, 3).bulkInsertOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
418
- return this.trace('bulkSave', {
419
- collectionName
420
- })(async env => this.runBulkSave(env, collectionName, items, options));
421
- }));
422
- (0, _defineProperty2.default)(this, "bulkUpdate", withArgs(async (args, collectionName, items, options) => {
423
- await apiValidator().arity('bulkUpdate', args, 2, 3).bulkUpdateOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
424
- return this.trace('bulkUpdate', {
425
- collectionName
426
- })(async env => {
427
- const {
428
- results
429
- } = await this.client.bulkUpdateDataItems({
430
- ...env,
431
- dataCollectionId: collectionName,
432
- dataItems: items.map(data => ({
433
- id: data._id,
434
- data
435
- })),
436
- ...toBulkUpdateOptions(options)
437
- });
438
- // Non-existing items are skipped and not reported as errors.
439
- return toBulkResult(items, results, ['WDE0073']);
440
- });
441
- }));
442
274
  // --- references ---
443
275
  (0, _defineProperty2.default)(this, "fetchReferenced", withArgs(async (args, collectionName, cursor, limit, options) => {
444
276
  await apiValidator().arity('fetchReferenced', args, 2, 4).isNonEmptyString(cursor, 'cursor').collectionName(collectionName).validateAndReject();
@@ -498,36 +330,6 @@ class WixDataApi {
498
330
  skipNumber: (options == null ? void 0 : options.skip) ?? 0
499
331
  });
500
332
  }));
501
- (0, _defineProperty2.default)(this, "queryReferencedItems", withArgs(async (args, collectionName, referringItem, referringItemFieldName, options) => {
502
- await apiValidator().arity('queryReferencedItems', args, 3, 4).collectionName(collectionName).referenceParameters(asArray(referringItem)).isNonEmptyString(referringItemFieldName, 'referringItemFieldName').options(options).validateAndReject();
503
- const referringItemIds = asArray(referringItem).map(itemId);
504
- return this.trace('queryReferencedItems', {
505
- collectionName,
506
- referringItemIds,
507
- options,
508
- referringItemFieldName
509
- })(async env => {
510
- const {
511
- results,
512
- pagingMetadata
513
- } = await this.client.queryReferencedDataItems({
514
- ...env,
515
- ...toReadOptions(options),
516
- dataCollectionId: collectionName,
517
- referringItemIds,
518
- referringItemFieldName,
519
- order: options == null ? void 0 : options.order,
520
- paging: options == null ? void 0 : options.paging,
521
- cursorPaging: options == null ? void 0 : options.cursorPaging,
522
- fields: options == null ? void 0 : options.fields,
523
- returnTotalCount: options == null ? void 0 : options.returnTotalCount
524
- });
525
- return {
526
- results: toReferencedResults(results ?? []),
527
- pagingMetadata: pagingMetadata
528
- };
529
- });
530
- }));
531
333
  (0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
532
334
  let refs;
533
335
  let opts;
@@ -620,12 +422,116 @@ class WixDataApi {
620
422
  get filter() {
621
423
  return (0, _common.filterBuilder)();
622
424
  }
425
+ // --- single-item methods ---
426
+
427
+ async get(collectionName, itemId, options) {
428
+ await apiValidator().arity('get', arguments, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
429
+ return this.trace('get', {
430
+ collectionName,
431
+ itemId
432
+ })(async env => {
433
+ var _options$includeField;
434
+ const {
435
+ dataItem
436
+ } = await this.client.getDataItem({
437
+ ...env,
438
+ dataCollectionId: collectionName,
439
+ dataItemId: itemId,
440
+ ...toReadOptions(options),
441
+ fields: options == null ? void 0 : options.fields,
442
+ includeReferences: options == null ? void 0 : options.includeReferences,
443
+ ...(options != null && (_options$includeField = options.includeFieldGroups) != null && _options$includeField.length ? {
444
+ includeFieldGroups: options.includeFieldGroups
445
+ } : {})
446
+ }).catch(recover(ItemDoesNotExistCode, {}));
447
+ return dataItem ? toDataItem(dataItem) : null;
448
+ });
449
+ }
450
+ async insert(collectionName, item, options) {
451
+ const itemAsWixData = item;
452
+ await apiValidator().arity('insert', arguments, 2, 3).collectionName(collectionName).item(itemAsWixData, collectionName, false).options(options).validateAndReject();
453
+ warnAboutBrokenFields(itemAsWixData);
454
+ return this.trace('insert', {
455
+ collectionName
456
+ })(async env => {
457
+ const {
458
+ dataItem
459
+ } = await this.client.insertDataItem({
460
+ ...env,
461
+ dataCollectionId: collectionName,
462
+ dataItem: {
463
+ id: itemAsWixData._id,
464
+ data: itemAsWixData
465
+ },
466
+ ...toInsertOptions(options)
467
+ });
468
+ return toDataItem(dataItem);
469
+ });
470
+ }
471
+ async save(collectionName, item, options) {
472
+ const itemAsWixData = item;
473
+ await apiValidator().arity('save', arguments, 2, 3).collectionName(collectionName).item(itemAsWixData, collectionName, false).options(options).validateAndReject();
474
+ return this.trace('save', {
475
+ collectionName
476
+ })(async env => {
477
+ const {
478
+ dataItem
479
+ } = await this.client.saveDataItem({
480
+ ...env,
481
+ dataCollectionId: collectionName,
482
+ dataItem: {
483
+ id: itemAsWixData._id,
484
+ data: itemAsWixData
485
+ },
486
+ ...toSaveOptions(options)
487
+ });
488
+ return toDataItem(dataItem);
489
+ });
490
+ }
491
+ async update(collectionName, item, options) {
492
+ await apiValidator().arity('update', arguments, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
493
+ return this.trace('update', {
494
+ collectionName
495
+ })(async env => {
496
+ const {
497
+ dataItem
498
+ } = await this.client.updateDataItem({
499
+ ...env,
500
+ dataCollectionId: collectionName,
501
+ dataItem: {
502
+ id: item._id,
503
+ data: item
504
+ },
505
+ ...toUpdateOptions(options)
506
+ });
507
+ return toDataItem(dataItem);
508
+ });
509
+ }
510
+ async remove(collectionName, itemId, options) {
511
+ await apiValidator().arity('remove', arguments, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
512
+ return this.trace('remove', {
513
+ collectionName,
514
+ itemId
515
+ })(async env => {
516
+ const {
517
+ dataItem
518
+ } = await this.client.removeDataItem({
519
+ ...env,
520
+ dataCollectionId: collectionName,
521
+ dataItemId: itemId,
522
+ ...toRemoveOptions(options)
523
+ }).catch(recover(ItemDoesNotExistCode, {}));
524
+ return dataItem ? toDataItem(dataItem) : null;
525
+ });
526
+ }
527
+
623
528
  /**
624
529
  * Returns a patch builder for the specified collection and item.
625
530
  * @param collectionName - Name of the collection containing the item to patch.
626
531
  * @param itemId - ID of the item to patch.
627
532
  * @returns A `WixDataPatch` builder object.
628
533
  */
534
+
629
535
  /**
630
536
  * Executes a patch directly without using the builder pattern.
631
537
  * @internal
@@ -635,6 +541,7 @@ class WixDataApi {
635
541
  * @param options - Additional options for the patch operation.
636
542
  * @returns Promise that resolves to the patched item, or `null` if no item was returned.
637
543
  */
544
+
638
545
  patch(collectionName, itemId, fieldModifications, options) {
639
546
  if (arguments.length >= 3) {
640
547
  return this.executeDirectPatch(collectionName, itemId, fieldModifications, options);
@@ -1075,6 +982,37 @@ class WixDataApi {
1075
982
  pagingMetadata: pagingMetadata
1076
983
  };
1077
984
  }
985
+ async distinct(collectionName, fieldName, options) {
986
+ var _options$paging, _options$cursorPaging, _options$paging2, _options$cursorPaging2;
987
+ await apiValidator().arity('distinct', arguments, 2, 3).collectionName(collectionName).fieldName(fieldName).options(options).validateAndReject();
988
+ 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);
989
+ const offset = (options == null || (_options$paging2 = options.paging) == null ? void 0 : _options$paging2.offset) ?? 0;
990
+ const cursor = options == null || (_options$cursorPaging2 = options.cursorPaging) == null ? void 0 : _options$cursorPaging2.cursor;
991
+ return this.trace('distinct', {
992
+ collectionName,
993
+ field: fieldName
994
+ })(async env => {
995
+ const {
996
+ distinctValues,
997
+ pagingMetadata
998
+ } = await this.client.queryDistinctValues({
999
+ ...env,
1000
+ dataCollectionId: collectionName,
1001
+ ...toReadOptions(options),
1002
+ ...toPaging(limit, cursor ?? offset),
1003
+ ...(cursor === undefined ? {
1004
+ fieldName,
1005
+ filter: options == null ? void 0 : options.filter,
1006
+ order: options == null ? void 0 : options.order,
1007
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
1008
+ } : {})
1009
+ });
1010
+ return {
1011
+ values: distinctValues,
1012
+ pagingMetadata: pagingMetadata
1013
+ };
1014
+ });
1015
+ }
1078
1016
  async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
1079
1017
  const request = {
1080
1018
  ...env,
@@ -1092,6 +1030,71 @@ class WixDataApi {
1092
1030
  const ignoreCodes = overrideExisting ? [] : ['WDE0074'];
1093
1031
  return toBulkResult(items, results, ignoreCodes);
1094
1032
  }
1033
+ async bulkInsert(collectionName, items, options) {
1034
+ const itemsAsWixData = items;
1035
+ await apiValidator().arity('bulkInsert', arguments, 2, 3).items(itemsAsWixData, collectionName).bulkInsertOptions(options).collectionName(collectionName).validateAndReject();
1036
+ return this.trace('bulkInsert', {
1037
+ collectionName,
1038
+ options
1039
+ })(async appId => this.runBulkSave(appId, collectionName, itemsAsWixData, options, (options == null ? void 0 : options.overrideExisting) ?? false));
1040
+ }
1041
+ async bulkSave(collectionName, items, options) {
1042
+ const itemsAsWixData = items;
1043
+ await apiValidator().arity('bulkSave', arguments, 2, 3).bulkInsertOptions(options).collectionName(collectionName).items(itemsAsWixData, collectionName).validateAndReject();
1044
+ return this.trace('bulkSave', {
1045
+ collectionName
1046
+ })(async env => this.runBulkSave(env, collectionName, itemsAsWixData, options));
1047
+ }
1048
+ async bulkUpdate(collectionName, items, options) {
1049
+ await apiValidator().arity('bulkUpdate', arguments, 2, 3).bulkUpdateOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
1050
+ return this.trace('bulkUpdate', {
1051
+ collectionName
1052
+ })(async env => {
1053
+ const {
1054
+ results
1055
+ } = await this.client.bulkUpdateDataItems({
1056
+ ...env,
1057
+ dataCollectionId: collectionName,
1058
+ dataItems: items.map(data => ({
1059
+ id: data._id,
1060
+ data
1061
+ })),
1062
+ ...toBulkUpdateOptions(options)
1063
+ });
1064
+ // Non-existing items are skipped and not reported as errors.
1065
+ return toBulkResult(items, results, ['WDE0073']);
1066
+ });
1067
+ }
1068
+ async queryReferencedItems(collectionName, referringItem, referringItemFieldName, options) {
1069
+ await apiValidator().arity('queryReferencedItems', arguments, 3, 4).collectionName(collectionName).referenceParameters(asArray(referringItem)).isNonEmptyString(referringItemFieldName, 'referringItemFieldName').options(options).validateAndReject();
1070
+ const referringItemIds = asArray(referringItem).map(itemId);
1071
+ return this.trace('queryReferencedItems', {
1072
+ collectionName,
1073
+ referringItemIds,
1074
+ options,
1075
+ referringItemFieldName
1076
+ })(async env => {
1077
+ const {
1078
+ results,
1079
+ pagingMetadata
1080
+ } = await this.client.queryReferencedDataItems({
1081
+ ...env,
1082
+ ...toReadOptions(options),
1083
+ dataCollectionId: collectionName,
1084
+ referringItemIds,
1085
+ referringItemFieldName,
1086
+ order: options == null ? void 0 : options.order,
1087
+ paging: options == null ? void 0 : options.paging,
1088
+ cursorPaging: options == null ? void 0 : options.cursorPaging,
1089
+ fields: options == null ? void 0 : options.fields,
1090
+ returnTotalCount: options == null ? void 0 : options.returnTotalCount
1091
+ });
1092
+ return {
1093
+ results: toReferencedResults(results ?? []),
1094
+ pagingMetadata: pagingMetadata
1095
+ };
1096
+ });
1097
+ }
1095
1098
  trace(action, opts) {
1096
1099
  return async fn => {
1097
1100
  const gridAppId = await get(this.gridAppId);
@@ -1129,10 +1132,10 @@ function toBulkPatchOptions(options) {
1129
1132
  ...conditionOptions(options == null ? void 0 : options.condition)
1130
1133
  };
1131
1134
  }
1132
- function toAsyncByFilterOptions(options) {
1135
+ function toAsyncRemoveByFilterOptions(options) {
1133
1136
  return toAsyncOptions(options);
1134
1137
  }
1135
- function toAsyncRemoveByFilterOptions(options) {
1138
+ function toAsyncPatchByFilterOptions(options) {
1136
1139
  return toAsyncOptions(options);
1137
1140
  }
1138
1141
  function toAsyncOptions(options) {