@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.
- package/dist/cjs/api/FieldModification.js +4 -0
- package/dist/cjs/api/FieldModification.js.map +1 -0
- package/dist/cjs/api/PagingMetadata.js +4 -0
- package/dist/cjs/api/PagingMetadata.js.map +1 -0
- package/dist/cjs/api/WixDataAggregateResponse.js +4 -0
- package/dist/cjs/api/WixDataAggregateResponse.js.map +1 -0
- package/dist/cjs/api/WixDataApi.js +208 -88
- package/dist/cjs/api/WixDataApi.js.map +1 -1
- package/dist/cjs/api/WixDataDistinctResponse.js +4 -0
- package/dist/cjs/api/WixDataDistinctResponse.js.map +1 -0
- package/dist/cjs/api/WixDataFieldModificationsBuilder.js +51 -0
- package/dist/cjs/api/WixDataFieldModificationsBuilder.js.map +1 -0
- package/dist/cjs/api/WixDataPatch.js.map +1 -1
- package/dist/cjs/api/WixDataQueryReferencedItemsResponse.js +4 -0
- package/dist/cjs/api/WixDataQueryReferencedItemsResponse.js.map +1 -0
- package/dist/cjs/api/WixDataQueryResponse.js +4 -0
- package/dist/cjs/api/WixDataQueryResponse.js.map +1 -0
- package/dist/cjs/api/WixDataSearchResponse.js +4 -0
- package/dist/cjs/api/WixDataSearchResponse.js.map +1 -0
- package/dist/cjs/api/impl/BaseFieldModificationsBuilder.js +85 -0
- package/dist/cjs/api/impl/BaseFieldModificationsBuilder.js.map +1 -0
- package/dist/cjs/api/impl/WixDataPatchImpl.js +13 -82
- package/dist/cjs/api/impl/WixDataPatchImpl.js.map +1 -1
- package/dist/cjs/api/index.js +29 -3
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/data-item-types.js.map +1 -1
- package/dist/esm/api/FieldModification.js +2 -0
- package/dist/esm/api/FieldModification.js.map +1 -0
- package/dist/esm/api/PagingMetadata.js +2 -0
- package/dist/esm/api/PagingMetadata.js.map +1 -0
- package/dist/esm/api/WixDataAggregateResponse.js +2 -0
- package/dist/esm/api/WixDataAggregateResponse.js.map +1 -0
- package/dist/esm/api/WixDataApi.js +166 -80
- package/dist/esm/api/WixDataApi.js.map +1 -1
- package/dist/esm/api/WixDataDistinctResponse.js +2 -0
- package/dist/esm/api/WixDataDistinctResponse.js.map +1 -0
- package/dist/esm/api/WixDataFieldModificationsBuilder.js +38 -0
- package/dist/esm/api/WixDataFieldModificationsBuilder.js.map +1 -0
- package/dist/esm/api/WixDataQueryReferencedItemsResponse.js +2 -0
- package/dist/esm/api/WixDataQueryReferencedItemsResponse.js.map +1 -0
- package/dist/esm/api/WixDataQueryResponse.js +2 -0
- package/dist/esm/api/WixDataQueryResponse.js.map +1 -0
- package/dist/esm/api/WixDataSearchResponse.js +2 -0
- package/dist/esm/api/WixDataSearchResponse.js.map +1 -0
- package/dist/esm/api/impl/BaseFieldModificationsBuilder.js +87 -0
- package/dist/esm/api/impl/BaseFieldModificationsBuilder.js.map +1 -0
- package/dist/esm/api/impl/WixDataPatchImpl.js +10 -90
- package/dist/esm/api/impl/WixDataPatchImpl.js.map +1 -1
- package/dist/esm/api/index.js +1 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/types/data-item-types.js.map +1 -1
- package/dist/types/api/FieldModification.d.ts +41 -0
- package/dist/types/api/FieldModification.d.ts.map +1 -0
- package/dist/types/api/PagingMetadata.d.ts +25 -0
- package/dist/types/api/PagingMetadata.d.ts.map +1 -0
- package/dist/types/api/WixDataAggregateResponse.d.ts +8 -0
- package/dist/types/api/WixDataAggregateResponse.d.ts.map +1 -0
- package/dist/types/api/WixDataApi.d.ts +45 -8
- package/dist/types/api/WixDataApi.d.ts.map +1 -1
- package/dist/types/api/WixDataDistinctResponse.d.ts +8 -0
- package/dist/types/api/WixDataDistinctResponse.d.ts.map +1 -0
- package/dist/types/api/WixDataFieldModificationsBuilder.d.ts +88 -0
- package/dist/types/api/WixDataFieldModificationsBuilder.d.ts.map +1 -0
- package/dist/types/api/WixDataPatch.d.ts +17 -167
- package/dist/types/api/WixDataPatch.d.ts.map +1 -1
- package/dist/types/api/WixDataQueryReferencedItemsResponse.d.ts +23 -0
- package/dist/types/api/WixDataQueryReferencedItemsResponse.d.ts.map +1 -0
- package/dist/types/api/WixDataQueryResponse.d.ts +9 -0
- package/dist/types/api/WixDataQueryResponse.d.ts.map +1 -0
- package/dist/types/api/WixDataSearchResponse.d.ts +9 -0
- package/dist/types/api/WixDataSearchResponse.d.ts.map +1 -0
- package/dist/types/api/impl/BaseFieldModificationsBuilder.d.ts +21 -0
- package/dist/types/api/impl/BaseFieldModificationsBuilder.d.ts.map +1 -0
- package/dist/types/api/impl/WixDataPatchImpl.d.ts +12 -27
- package/dist/types/api/impl/WixDataPatchImpl.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +10 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +18 -12
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/data-item-types.d.ts +3 -1
- package/dist/types/types/data-item-types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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,
|
|
402
|
-
...(
|
|
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
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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,
|
|
784
|
-
...(
|
|
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
|
-
...(
|
|
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
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
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
|
-
|
|
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,
|
|
996
|
+
...toPaging(limit, cursor ?? offset)
|
|
902
997
|
},
|
|
903
998
|
includeReferences,
|
|
904
999
|
...toReadOptions(options)
|
|
905
1000
|
});
|
|
906
|
-
return
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
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.
|
|
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
|
}
|