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

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 (46) 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/WixDataApi.js +126 -55
  4. package/dist/cjs/api/WixDataApi.js.map +1 -1
  5. package/dist/cjs/api/WixDataFieldModificationsBuilder.js +51 -0
  6. package/dist/cjs/api/WixDataFieldModificationsBuilder.js.map +1 -0
  7. package/dist/cjs/api/WixDataPatch.js.map +1 -1
  8. package/dist/cjs/api/impl/BaseFieldModificationsBuilder.js +85 -0
  9. package/dist/cjs/api/impl/BaseFieldModificationsBuilder.js.map +1 -0
  10. package/dist/cjs/api/impl/WixDataPatchImpl.js +13 -82
  11. package/dist/cjs/api/impl/WixDataPatchImpl.js.map +1 -1
  12. package/dist/cjs/api/index.js +13 -3
  13. package/dist/cjs/api/index.js.map +1 -1
  14. package/dist/cjs/api/types.js.map +1 -1
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/esm/api/FieldModification.js +2 -0
  17. package/dist/esm/api/FieldModification.js.map +1 -0
  18. package/dist/esm/api/WixDataApi.js +82 -48
  19. package/dist/esm/api/WixDataApi.js.map +1 -1
  20. package/dist/esm/api/WixDataFieldModificationsBuilder.js +38 -0
  21. package/dist/esm/api/WixDataFieldModificationsBuilder.js.map +1 -0
  22. package/dist/esm/api/impl/BaseFieldModificationsBuilder.js +87 -0
  23. package/dist/esm/api/impl/BaseFieldModificationsBuilder.js.map +1 -0
  24. package/dist/esm/api/impl/WixDataPatchImpl.js +10 -90
  25. package/dist/esm/api/impl/WixDataPatchImpl.js.map +1 -1
  26. package/dist/esm/api/index.js +1 -0
  27. package/dist/esm/api/index.js.map +1 -1
  28. package/dist/types/api/FieldModification.d.ts +41 -0
  29. package/dist/types/api/FieldModification.d.ts.map +1 -0
  30. package/dist/types/api/WixDataApi.d.ts +32 -3
  31. package/dist/types/api/WixDataApi.d.ts.map +1 -1
  32. package/dist/types/api/WixDataFieldModificationsBuilder.d.ts +88 -0
  33. package/dist/types/api/WixDataFieldModificationsBuilder.d.ts.map +1 -0
  34. package/dist/types/api/WixDataPatch.d.ts +17 -167
  35. package/dist/types/api/WixDataPatch.d.ts.map +1 -1
  36. package/dist/types/api/impl/BaseFieldModificationsBuilder.d.ts +21 -0
  37. package/dist/types/api/impl/BaseFieldModificationsBuilder.d.ts.map +1 -0
  38. package/dist/types/api/impl/WixDataPatchImpl.d.ts +12 -27
  39. package/dist/types/api/impl/WixDataPatchImpl.d.ts.map +1 -1
  40. package/dist/types/api/index.d.ts +4 -2
  41. package/dist/types/api/index.d.ts.map +1 -1
  42. package/dist/types/api/types.d.ts +0 -12
  43. package/dist/types/api/types.d.ts.map +1 -1
  44. package/dist/types/index.d.ts +1 -0
  45. package/dist/types/index.d.ts.map +1 -1
  46. 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":[]}
@@ -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({
@@ -639,12 +589,132 @@ class WixDataApi {
639
589
  }
640
590
  get filter() {
641
591
  return (0, _common.filterBuilder)();
642
- } // --- query, count, distinct ---
592
+ }
593
+ /**
594
+ * Returns a patch builder for the specified collection and item.
595
+ * @param collectionName - Name of the collection containing the item to patch.
596
+ * @param itemId - ID of the item to patch.
597
+ * @returns A `WixDataPatch` builder object.
598
+ */
599
+ /**
600
+ * Executes a patch directly without using the builder pattern.
601
+ * @internal
602
+ * @param collectionName - Name of the collection containing the item to patch.
603
+ * @param itemId - ID of the item to patch.
604
+ * @param fieldModifications - Field modifications to apply to the item.
605
+ * @param options - Additional options for the patch operation.
606
+ * @returns Promise that resolves to the patched item, or `null` if no item was returned.
607
+ */
608
+ patch(collectionName, itemId, fieldModifications, options) {
609
+ if (arguments.length >= 3) {
610
+ return this.executeDirectPatch(collectionName, itemId, fieldModifications, options);
611
+ }
612
+ return new _WixDataPatchImpl.WixDataPatchImpl({
613
+ collectionName,
614
+ itemId,
615
+ onRun: async (_args, patchParams, options) => {
616
+ const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
617
+ return this.trace('patch', {
618
+ collectionName
619
+ })(async env => {
620
+ const result = await this.client.patchDataItem({
621
+ ...env,
622
+ dataCollectionId: patchParams.collectionName,
623
+ patch: {
624
+ dataItemId: patchParams.itemId,
625
+ fieldModifications
626
+ },
627
+ ...toPatchOptions(options)
628
+ });
629
+ return result.dataItem ? toDataItem(result.dataItem) : null;
630
+ });
631
+ }
632
+ });
633
+ }
634
+ async executeDirectPatch(collectionName, itemId, fieldModifications, options) {
635
+ const apiFieldModifications = fieldModifications == null ? void 0 : fieldModifications.map(this.toFieldModificationApi);
636
+ return this.trace('patch', {
637
+ collectionName
638
+ })(async env => {
639
+ const result = await this.client.patchDataItem({
640
+ ...env,
641
+ dataCollectionId: collectionName,
642
+ patch: {
643
+ dataItemId: itemId,
644
+ fieldModifications: apiFieldModifications
645
+ },
646
+ ...toPatchOptions(options)
647
+ });
648
+ return result.dataItem ? toDataItem(result.dataItem) : null;
649
+ });
650
+ }
651
+
652
+ /**
653
+ * Executes a bulk patch directly without using the builder pattern.
654
+ * @internal
655
+ * @param collectionName - Name of the collection containing the items to patch.
656
+ * @param itemIds - IDs of the items to patch.
657
+ * @param fieldModifications - Field modifications to apply to the items.
658
+ * @param options - Additional options for the bulk patch operation.
659
+ * @returns Promise that resolves to bulk operation results.
660
+ */
661
+
662
+ bulkPatch(collectionName, itemIds, fieldModifications, options) {
663
+ if (arguments.length >= 3) {
664
+ return this.executeDirectBulkPatch(collectionName, itemIds, fieldModifications, options);
665
+ }
666
+ return new _WixDataPatchImpl.WixDataBulkPatchImpl({
667
+ collectionName,
668
+ itemIds,
669
+ onRun: async (_args, patchParams, options) => {
670
+ const fieldModifications = patchParams.fieldModifications.map(this.toFieldModificationApi);
671
+ return this.trace('bulkPatch', {
672
+ collectionName
673
+ })(async env => {
674
+ const {
675
+ results
676
+ } = await this.client.bulkPatchDataItems({
677
+ ...env,
678
+ dataCollectionId: patchParams.collectionName,
679
+ patches: patchParams.itemIds.map(itemId => ({
680
+ dataItemId: itemId,
681
+ fieldModifications
682
+ })),
683
+ ...toPatchOptions(options)
684
+ });
685
+ return toBulkResult(itemIds, results, ['WDE0073']);
686
+ });
687
+ }
688
+ });
689
+ }
690
+ async executeDirectBulkPatch(collectionName, itemIds, fieldModifications, options) {
691
+ const apiFieldModifications = fieldModifications == null ? void 0 : fieldModifications.map(this.toFieldModificationApi);
692
+ return this.trace('bulkPatch', {
693
+ collectionName
694
+ })(async env => {
695
+ const {
696
+ results
697
+ } = await this.client.bulkPatchDataItems({
698
+ ...env,
699
+ dataCollectionId: collectionName,
700
+ patches: itemIds.map(itemId => ({
701
+ dataItemId: itemId,
702
+ fieldModifications: apiFieldModifications
703
+ })),
704
+ ...toPatchOptions(options)
705
+ });
706
+ return toBulkResult(itemIds, results, ['WDE0073']);
707
+ });
708
+ }
709
+
710
+ // --- query, count, distinct ---
711
+
643
712
  /**
644
713
  * Returns a query builder for the specified collection.
645
714
  * @param collectionName - Name of the collection to query.
646
715
  * @returns A `WixDataQuery` builder object.
647
716
  */
717
+
648
718
  /**
649
719
  * Executes a query directly without using the builder pattern.
650
720
  * @internal
@@ -653,6 +723,7 @@ class WixDataApi {
653
723
  * @param options - Additional options including includeReferences.
654
724
  * @returns Promise that resolves to the query results.
655
725
  */
726
+
656
727
  query(collectionName, queryRequest, options) {
657
728
  // Direct query execution mode
658
729
  if (queryRequest !== undefined) {