@wix/wix-data-items-common 1.0.308 → 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':
@@ -329,37 +230,6 @@ class WixDataApi {
329
230
  return this.client.aggregatePipelineDataItems(request);
330
231
  });
331
232
  }));
332
- (0, _defineProperty2.default)(this, "distinct", withArgs(async (args, collectionName, fieldName, options) => {
333
- var _options$paging, _options$cursorPaging, _options$paging2, _options$cursorPaging2;
334
- await apiValidator().arity('distinct', args, 2, 3).collectionName(collectionName).fieldName(fieldName).options(options).validateAndReject();
335
- 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);
336
- const offset = (options == null || (_options$paging2 = options.paging) == null ? void 0 : _options$paging2.offset) ?? 0;
337
- const cursor = options == null || (_options$cursorPaging2 = options.cursorPaging) == null ? void 0 : _options$cursorPaging2.cursor;
338
- return this.trace('distinct', {
339
- collectionName,
340
- field: fieldName
341
- })(async env => {
342
- const {
343
- distinctValues,
344
- pagingMetadata
345
- } = await this.client.queryDistinctValues({
346
- ...env,
347
- dataCollectionId: collectionName,
348
- ...toReadOptions(options),
349
- ...toPaging(limit, cursor ?? offset),
350
- ...(cursor === undefined ? {
351
- fieldName,
352
- filter: options == null ? void 0 : options.filter,
353
- order: options == null ? void 0 : options.order,
354
- returnTotalCount: options == null ? void 0 : options.returnTotalCount
355
- } : {})
356
- });
357
- return {
358
- values: distinctValues,
359
- pagingMetadata: pagingMetadata
360
- };
361
- });
362
- }));
363
233
  /** @internal */
364
234
  (0, _defineProperty2.default)(this, "count", withArgs(async (args, collectionName, options) => {
365
235
  await apiValidator().arity('count', args, 1, 2).collectionName(collectionName).options(options).validateAndReject();
@@ -401,39 +271,6 @@ class WixDataApi {
401
271
  return toBulkResult(itemIds, results, ['WDE0073']);
402
272
  });
403
273
  }));
404
- (0, _defineProperty2.default)(this, "bulkInsert", withArgs(async (args, collectionName, items, options) => {
405
- await apiValidator().arity('bulkInsert', args, 2, 3).items(items, collectionName).bulkInsertOptions(options).collectionName(collectionName).validateAndReject();
406
- return this.trace('bulkInsert', {
407
- collectionName,
408
- options
409
- })(async appId => this.runBulkSave(appId, collectionName, items, options, (options == null ? void 0 : options.overrideExisting) ?? false));
410
- }));
411
- (0, _defineProperty2.default)(this, "bulkSave", withArgs(async (args, collectionName, items, options) => {
412
- await apiValidator().arity('bulkSave', args, 2, 3).bulkInsertOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
413
- return this.trace('bulkSave', {
414
- collectionName
415
- })(async env => this.runBulkSave(env, collectionName, items, options));
416
- }));
417
- (0, _defineProperty2.default)(this, "bulkUpdate", withArgs(async (args, collectionName, items, options) => {
418
- await apiValidator().arity('bulkUpdate', args, 2, 3).bulkUpdateOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
419
- return this.trace('bulkUpdate', {
420
- collectionName
421
- })(async env => {
422
- const {
423
- results
424
- } = await this.client.bulkUpdateDataItems({
425
- ...env,
426
- dataCollectionId: collectionName,
427
- dataItems: items.map(data => ({
428
- id: data._id,
429
- data
430
- })),
431
- ...toBulkUpdateOptions(options)
432
- });
433
- // Non-existing items are skipped and not reported as errors.
434
- return toBulkResult(items, results, ['WDE0073']);
435
- });
436
- }));
437
274
  // --- references ---
438
275
  (0, _defineProperty2.default)(this, "fetchReferenced", withArgs(async (args, collectionName, cursor, limit, options) => {
439
276
  await apiValidator().arity('fetchReferenced', args, 2, 4).isNonEmptyString(cursor, 'cursor').collectionName(collectionName).validateAndReject();
@@ -493,36 +330,6 @@ class WixDataApi {
493
330
  skipNumber: (options == null ? void 0 : options.skip) ?? 0
494
331
  });
495
332
  }));
496
- (0, _defineProperty2.default)(this, "queryReferencedItems", withArgs(async (args, collectionName, referringItem, referringItemFieldName, options) => {
497
- await apiValidator().arity('queryReferencedItems', args, 3, 4).collectionName(collectionName).referenceParameters(asArray(referringItem)).isNonEmptyString(referringItemFieldName, 'referringItemFieldName').options(options).validateAndReject();
498
- const referringItemIds = asArray(referringItem).map(itemId);
499
- return this.trace('queryReferencedItems', {
500
- collectionName,
501
- referringItemIds,
502
- options,
503
- referringItemFieldName
504
- })(async env => {
505
- const {
506
- results,
507
- pagingMetadata
508
- } = await this.client.queryReferencedDataItems({
509
- ...env,
510
- ...toReadOptions(options),
511
- dataCollectionId: collectionName,
512
- referringItemIds,
513
- referringItemFieldName,
514
- order: options == null ? void 0 : options.order,
515
- paging: options == null ? void 0 : options.paging,
516
- cursorPaging: options == null ? void 0 : options.cursorPaging,
517
- fields: options == null ? void 0 : options.fields,
518
- returnTotalCount: options == null ? void 0 : options.returnTotalCount
519
- });
520
- return {
521
- results: toReferencedResults(results ?? []),
522
- pagingMetadata: pagingMetadata
523
- };
524
- });
525
- }));
526
333
  (0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
527
334
  let refs;
528
335
  let opts;
@@ -615,12 +422,116 @@ class WixDataApi {
615
422
  get filter() {
616
423
  return (0, _common.filterBuilder)();
617
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
+
618
528
  /**
619
529
  * Returns a patch builder for the specified collection and item.
620
530
  * @param collectionName - Name of the collection containing the item to patch.
621
531
  * @param itemId - ID of the item to patch.
622
532
  * @returns A `WixDataPatch` builder object.
623
533
  */
534
+
624
535
  /**
625
536
  * Executes a patch directly without using the builder pattern.
626
537
  * @internal
@@ -630,6 +541,7 @@ class WixDataApi {
630
541
  * @param options - Additional options for the patch operation.
631
542
  * @returns Promise that resolves to the patched item, or `null` if no item was returned.
632
543
  */
544
+
633
545
  patch(collectionName, itemId, fieldModifications, options) {
634
546
  if (arguments.length >= 3) {
635
547
  return this.executeDirectPatch(collectionName, itemId, fieldModifications, options);
@@ -1070,6 +982,37 @@ class WixDataApi {
1070
982
  pagingMetadata: pagingMetadata
1071
983
  };
1072
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
+ }
1073
1016
  async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
1074
1017
  const request = {
1075
1018
  ...env,
@@ -1087,6 +1030,71 @@ class WixDataApi {
1087
1030
  const ignoreCodes = overrideExisting ? [] : ['WDE0074'];
1088
1031
  return toBulkResult(items, results, ignoreCodes);
1089
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
+ }
1090
1098
  trace(action, opts) {
1091
1099
  return async fn => {
1092
1100
  const gridAppId = await get(this.gridAppId);