@wix/wix-data-items-common 1.0.308 → 1.0.310
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/WixDataApi.js +283 -275
- package/dist/cjs/api/WixDataApi.js.map +1 -1
- package/dist/cjs/api/index.js +3 -2
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/esm/api/WixDataApi.js +320 -310
- package/dist/esm/api/WixDataApi.js.map +1 -1
- package/dist/esm/api/index.js.map +1 -1
- package/dist/types/api/WixDataApi.d.ts +21 -24
- package/dist/types/api/WixDataApi.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +7 -5
- package/dist/types/api/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -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,134 +330,124 @@ class WixDataApi {
|
|
|
493
330
|
skipNumber: (options == null ? void 0 : options.skip) ?? 0
|
|
494
331
|
});
|
|
495
332
|
}));
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
-
(0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
|
|
527
|
-
let refs;
|
|
528
|
-
let opts;
|
|
529
|
-
let argc;
|
|
530
|
-
if (typeof refsOrAttr === 'string') {
|
|
531
|
-
const rights = asArray(right);
|
|
532
|
-
refs = rights.map(r => ({
|
|
533
|
-
relationshipName: refsOrAttr,
|
|
534
|
-
left: leftOrOpts,
|
|
535
|
-
right: r
|
|
536
|
-
}));
|
|
537
|
-
opts = options;
|
|
538
|
-
argc = [4, 5];
|
|
539
|
-
} else {
|
|
540
|
-
refs = refsOrAttr;
|
|
541
|
-
opts = leftOrOpts;
|
|
542
|
-
argc = [2, 3];
|
|
543
|
-
}
|
|
544
|
-
await apiValidator().arity('insertReference', args, ...argc).collectionName(collectionName).references(refs).options(opts).validateAndReject();
|
|
545
|
-
await this.trace('insertReference', {
|
|
546
|
-
collectionName
|
|
547
|
-
})(async env => this.client.bulkInsertDataItemReferences({
|
|
333
|
+
this.client = new _ApiClient.ApiClient(clientFactory, allowGet);
|
|
334
|
+
}
|
|
335
|
+
get wixData() {
|
|
336
|
+
return this;
|
|
337
|
+
}
|
|
338
|
+
get filter() {
|
|
339
|
+
return (0, _common.filterBuilder)();
|
|
340
|
+
}
|
|
341
|
+
// --- single-item methods ---
|
|
342
|
+
|
|
343
|
+
async get(collectionName, itemId, options) {
|
|
344
|
+
await apiValidator().arity('get', arguments, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
|
|
345
|
+
return this.trace('get', {
|
|
346
|
+
collectionName,
|
|
347
|
+
itemId
|
|
348
|
+
})(async env => {
|
|
349
|
+
var _options$includeField;
|
|
350
|
+
const {
|
|
351
|
+
dataItem
|
|
352
|
+
} = await this.client.getDataItem({
|
|
548
353
|
...env,
|
|
549
354
|
dataCollectionId: collectionName,
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
355
|
+
dataItemId: itemId,
|
|
356
|
+
...toReadOptions(options),
|
|
357
|
+
fields: options == null ? void 0 : options.fields,
|
|
358
|
+
includeReferences: options == null ? void 0 : options.includeReferences,
|
|
359
|
+
...(options != null && (_options$includeField = options.includeFieldGroups) != null && _options$includeField.length ? {
|
|
360
|
+
includeFieldGroups: options.includeFieldGroups
|
|
361
|
+
} : {})
|
|
362
|
+
}).catch(recover(ItemDoesNotExistCode, {}));
|
|
363
|
+
return dataItem ? toDataItem(dataItem) : null;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
async insert(collectionName, item, options) {
|
|
367
|
+
const itemAsWixData = item;
|
|
368
|
+
await apiValidator().arity('insert', arguments, 2, 3).collectionName(collectionName).item(itemAsWixData, collectionName, false).options(options).validateAndReject();
|
|
369
|
+
warnAboutBrokenFields(itemAsWixData);
|
|
370
|
+
return this.trace('insert', {
|
|
371
|
+
collectionName
|
|
372
|
+
})(async env => {
|
|
373
|
+
const {
|
|
374
|
+
dataItem
|
|
375
|
+
} = await this.client.insertDataItem({
|
|
565
376
|
...env,
|
|
566
377
|
dataCollectionId: collectionName,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
378
|
+
dataItem: {
|
|
379
|
+
id: itemAsWixData._id,
|
|
380
|
+
data: itemAsWixData
|
|
381
|
+
},
|
|
382
|
+
...toInsertOptions(options)
|
|
383
|
+
});
|
|
384
|
+
return toDataItem(dataItem);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async save(collectionName, item, options) {
|
|
388
|
+
const itemAsWixData = item;
|
|
389
|
+
await apiValidator().arity('save', arguments, 2, 3).collectionName(collectionName).item(itemAsWixData, collectionName, false).options(options).validateAndReject();
|
|
390
|
+
return this.trace('save', {
|
|
391
|
+
collectionName
|
|
392
|
+
})(async env => {
|
|
393
|
+
const {
|
|
394
|
+
dataItem
|
|
395
|
+
} = await this.client.saveDataItem({
|
|
580
396
|
...env,
|
|
581
397
|
dataCollectionId: collectionName,
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
...toOptions(options)
|
|
588
|
-
}));
|
|
589
|
-
}));
|
|
590
|
-
(0, _defineProperty2.default)(this, "isReferenced", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
|
|
591
|
-
await apiValidator().arity('isReferenced', args, 4, 5).collectionName(collectionName).referenceParameter(left).referenceParameter(right).options(options).validateAndReject();
|
|
592
|
-
return this.trace('isReferenced', {
|
|
593
|
-
collectionName,
|
|
594
|
-
relationshipAttribute
|
|
595
|
-
})(async env => {
|
|
596
|
-
const {
|
|
597
|
-
isReferenced
|
|
598
|
-
} = await this.client.isReferencedDataItem({
|
|
599
|
-
...env,
|
|
600
|
-
dataCollectionId: collectionName,
|
|
601
|
-
referringItemFieldName: relationshipAttribute,
|
|
602
|
-
referringItemId: itemId(left),
|
|
603
|
-
referencedItemId: itemId(right),
|
|
604
|
-
...toReadOptions(options),
|
|
605
|
-
consistentRead: options == null ? void 0 : options.consistentRead
|
|
606
|
-
});
|
|
607
|
-
return isReferenced;
|
|
398
|
+
dataItem: {
|
|
399
|
+
id: itemAsWixData._id,
|
|
400
|
+
data: itemAsWixData
|
|
401
|
+
},
|
|
402
|
+
...toSaveOptions(options)
|
|
608
403
|
});
|
|
609
|
-
|
|
610
|
-
|
|
404
|
+
return toDataItem(dataItem);
|
|
405
|
+
});
|
|
611
406
|
}
|
|
612
|
-
|
|
613
|
-
|
|
407
|
+
async update(collectionName, item, options) {
|
|
408
|
+
await apiValidator().arity('update', arguments, 2, 3).collectionName(collectionName).item(item, collectionName, false).options(options).validateAndReject();
|
|
409
|
+
return this.trace('update', {
|
|
410
|
+
collectionName
|
|
411
|
+
})(async env => {
|
|
412
|
+
const {
|
|
413
|
+
dataItem
|
|
414
|
+
} = await this.client.updateDataItem({
|
|
415
|
+
...env,
|
|
416
|
+
dataCollectionId: collectionName,
|
|
417
|
+
dataItem: {
|
|
418
|
+
id: item._id,
|
|
419
|
+
data: item
|
|
420
|
+
},
|
|
421
|
+
...toUpdateOptions(options)
|
|
422
|
+
});
|
|
423
|
+
return toDataItem(dataItem);
|
|
424
|
+
});
|
|
614
425
|
}
|
|
615
|
-
|
|
616
|
-
|
|
426
|
+
async remove(collectionName, itemId, options) {
|
|
427
|
+
await apiValidator().arity('remove', arguments, 2, 3).collectionName(collectionName).itemId(itemId).options(options).validateAndReject();
|
|
428
|
+
return this.trace('remove', {
|
|
429
|
+
collectionName,
|
|
430
|
+
itemId
|
|
431
|
+
})(async env => {
|
|
432
|
+
const {
|
|
433
|
+
dataItem
|
|
434
|
+
} = await this.client.removeDataItem({
|
|
435
|
+
...env,
|
|
436
|
+
dataCollectionId: collectionName,
|
|
437
|
+
dataItemId: itemId,
|
|
438
|
+
...toRemoveOptions(options)
|
|
439
|
+
}).catch(recover(ItemDoesNotExistCode, {}));
|
|
440
|
+
return dataItem ? toDataItem(dataItem) : null;
|
|
441
|
+
});
|
|
617
442
|
}
|
|
443
|
+
|
|
618
444
|
/**
|
|
619
445
|
* Returns a patch builder for the specified collection and item.
|
|
620
446
|
* @param collectionName - Name of the collection containing the item to patch.
|
|
621
447
|
* @param itemId - ID of the item to patch.
|
|
622
448
|
* @returns A `WixDataPatch` builder object.
|
|
623
449
|
*/
|
|
450
|
+
|
|
624
451
|
/**
|
|
625
452
|
* Executes a patch directly without using the builder pattern.
|
|
626
453
|
* @internal
|
|
@@ -630,6 +457,7 @@ class WixDataApi {
|
|
|
630
457
|
* @param options - Additional options for the patch operation.
|
|
631
458
|
* @returns Promise that resolves to the patched item, or `null` if no item was returned.
|
|
632
459
|
*/
|
|
460
|
+
|
|
633
461
|
patch(collectionName, itemId, fieldModifications, options) {
|
|
634
462
|
if (arguments.length >= 3) {
|
|
635
463
|
return this.executeDirectPatch(collectionName, itemId, fieldModifications, options);
|
|
@@ -1070,6 +898,37 @@ class WixDataApi {
|
|
|
1070
898
|
pagingMetadata: pagingMetadata
|
|
1071
899
|
};
|
|
1072
900
|
}
|
|
901
|
+
async distinct(collectionName, fieldName, options) {
|
|
902
|
+
var _options$paging, _options$cursorPaging, _options$paging2, _options$cursorPaging2;
|
|
903
|
+
await apiValidator().arity('distinct', arguments, 2, 3).collectionName(collectionName).fieldName(fieldName).options(options).validateAndReject();
|
|
904
|
+
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);
|
|
905
|
+
const offset = (options == null || (_options$paging2 = options.paging) == null ? void 0 : _options$paging2.offset) ?? 0;
|
|
906
|
+
const cursor = options == null || (_options$cursorPaging2 = options.cursorPaging) == null ? void 0 : _options$cursorPaging2.cursor;
|
|
907
|
+
return this.trace('distinct', {
|
|
908
|
+
collectionName,
|
|
909
|
+
field: fieldName
|
|
910
|
+
})(async env => {
|
|
911
|
+
const {
|
|
912
|
+
distinctValues,
|
|
913
|
+
pagingMetadata
|
|
914
|
+
} = await this.client.queryDistinctValues({
|
|
915
|
+
...env,
|
|
916
|
+
dataCollectionId: collectionName,
|
|
917
|
+
...toReadOptions(options),
|
|
918
|
+
...toPaging(limit, cursor ?? offset),
|
|
919
|
+
...(cursor === undefined ? {
|
|
920
|
+
fieldName,
|
|
921
|
+
filter: options == null ? void 0 : options.filter,
|
|
922
|
+
order: options == null ? void 0 : options.order,
|
|
923
|
+
returnTotalCount: options == null ? void 0 : options.returnTotalCount
|
|
924
|
+
} : {})
|
|
925
|
+
});
|
|
926
|
+
return {
|
|
927
|
+
values: distinctValues,
|
|
928
|
+
pagingMetadata: pagingMetadata
|
|
929
|
+
};
|
|
930
|
+
});
|
|
931
|
+
}
|
|
1073
932
|
async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
|
|
1074
933
|
const request = {
|
|
1075
934
|
...env,
|
|
@@ -1087,6 +946,155 @@ class WixDataApi {
|
|
|
1087
946
|
const ignoreCodes = overrideExisting ? [] : ['WDE0074'];
|
|
1088
947
|
return toBulkResult(items, results, ignoreCodes);
|
|
1089
948
|
}
|
|
949
|
+
async bulkInsert(collectionName, items, options) {
|
|
950
|
+
const itemsAsWixData = items;
|
|
951
|
+
await apiValidator().arity('bulkInsert', arguments, 2, 3).items(itemsAsWixData, collectionName).bulkInsertOptions(options).collectionName(collectionName).validateAndReject();
|
|
952
|
+
return this.trace('bulkInsert', {
|
|
953
|
+
collectionName,
|
|
954
|
+
options
|
|
955
|
+
})(async appId => this.runBulkSave(appId, collectionName, itemsAsWixData, options, (options == null ? void 0 : options.overrideExisting) ?? false));
|
|
956
|
+
}
|
|
957
|
+
async bulkSave(collectionName, items, options) {
|
|
958
|
+
const itemsAsWixData = items;
|
|
959
|
+
await apiValidator().arity('bulkSave', arguments, 2, 3).bulkInsertOptions(options).collectionName(collectionName).items(itemsAsWixData, collectionName).validateAndReject();
|
|
960
|
+
return this.trace('bulkSave', {
|
|
961
|
+
collectionName
|
|
962
|
+
})(async env => this.runBulkSave(env, collectionName, itemsAsWixData, options));
|
|
963
|
+
}
|
|
964
|
+
async bulkUpdate(collectionName, items, options) {
|
|
965
|
+
await apiValidator().arity('bulkUpdate', arguments, 2, 3).bulkUpdateOptions(options).collectionName(collectionName).items(items, collectionName).validateAndReject();
|
|
966
|
+
return this.trace('bulkUpdate', {
|
|
967
|
+
collectionName
|
|
968
|
+
})(async env => {
|
|
969
|
+
const {
|
|
970
|
+
results
|
|
971
|
+
} = await this.client.bulkUpdateDataItems({
|
|
972
|
+
...env,
|
|
973
|
+
dataCollectionId: collectionName,
|
|
974
|
+
dataItems: items.map(data => ({
|
|
975
|
+
id: data._id,
|
|
976
|
+
data
|
|
977
|
+
})),
|
|
978
|
+
...toBulkUpdateOptions(options)
|
|
979
|
+
});
|
|
980
|
+
// Non-existing items are skipped and not reported as errors.
|
|
981
|
+
return toBulkResult(items, results, ['WDE0073']);
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
async queryReferencedItems(collectionName, referringItem, referringItemFieldName, options) {
|
|
985
|
+
await apiValidator().arity('queryReferencedItems', arguments, 3, 4).collectionName(collectionName).referenceParameters(asArray(referringItem)).isNonEmptyString(referringItemFieldName, 'referringItemFieldName').options(options).validateAndReject();
|
|
986
|
+
const referringItemIds = asArray(referringItem).map(itemId);
|
|
987
|
+
return this.trace('queryReferencedItems', {
|
|
988
|
+
collectionName,
|
|
989
|
+
referringItemIds,
|
|
990
|
+
options,
|
|
991
|
+
referringItemFieldName
|
|
992
|
+
})(async env => {
|
|
993
|
+
const {
|
|
994
|
+
results,
|
|
995
|
+
pagingMetadata
|
|
996
|
+
} = await this.client.queryReferencedDataItems({
|
|
997
|
+
...env,
|
|
998
|
+
...toReadOptions(options),
|
|
999
|
+
dataCollectionId: collectionName,
|
|
1000
|
+
referringItemIds,
|
|
1001
|
+
referringItemFieldName,
|
|
1002
|
+
order: options == null ? void 0 : options.order,
|
|
1003
|
+
paging: options == null ? void 0 : options.paging,
|
|
1004
|
+
cursorPaging: options == null ? void 0 : options.cursorPaging,
|
|
1005
|
+
fields: options == null ? void 0 : options.fields,
|
|
1006
|
+
returnTotalCount: options == null ? void 0 : options.returnTotalCount
|
|
1007
|
+
});
|
|
1008
|
+
return {
|
|
1009
|
+
results: toReferencedResults(results ?? []),
|
|
1010
|
+
pagingMetadata: pagingMetadata
|
|
1011
|
+
};
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
async insertReference(collectionName, refsOrAttr, leftOrOpts, right, options) {
|
|
1015
|
+
let refs;
|
|
1016
|
+
let opts;
|
|
1017
|
+
let argc;
|
|
1018
|
+
if (typeof refsOrAttr === 'string') {
|
|
1019
|
+
const rights = asArray(right);
|
|
1020
|
+
refs = rights.map(r => ({
|
|
1021
|
+
relationshipName: refsOrAttr,
|
|
1022
|
+
left: leftOrOpts,
|
|
1023
|
+
right: r
|
|
1024
|
+
}));
|
|
1025
|
+
opts = options;
|
|
1026
|
+
argc = [4, 5];
|
|
1027
|
+
} else {
|
|
1028
|
+
refs = refsOrAttr;
|
|
1029
|
+
opts = leftOrOpts;
|
|
1030
|
+
argc = [2, 3];
|
|
1031
|
+
}
|
|
1032
|
+
await apiValidator().arity('insertReference', arguments, ...argc).collectionName(collectionName).references(refs).options(opts).validateAndReject();
|
|
1033
|
+
await this.trace('insertReference', {
|
|
1034
|
+
collectionName
|
|
1035
|
+
})(async env => this.client.bulkInsertDataItemReferences({
|
|
1036
|
+
...env,
|
|
1037
|
+
dataCollectionId: collectionName,
|
|
1038
|
+
dataItemReferences: refs.map(r => ({
|
|
1039
|
+
referringItemFieldName: r.relationshipName,
|
|
1040
|
+
referringItemId: itemId(r.left),
|
|
1041
|
+
referencedItemId: itemId(r.right)
|
|
1042
|
+
})),
|
|
1043
|
+
...toOptions(opts)
|
|
1044
|
+
}));
|
|
1045
|
+
}
|
|
1046
|
+
async replaceReferences(collectionName, relationshipAttribute, left, right, options) {
|
|
1047
|
+
const rights = asArray(right);
|
|
1048
|
+
await apiValidator().arity('replaceReferences', arguments, 4, 5).collectionName(collectionName).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').referenceParameter(left).referenceParameters(rights).options(options).validateAndReject();
|
|
1049
|
+
await this.trace('replaceReferences', {
|
|
1050
|
+
collectionName,
|
|
1051
|
+
relationshipAttribute
|
|
1052
|
+
})(async env => this.client.replaceDataItemReferences({
|
|
1053
|
+
...env,
|
|
1054
|
+
dataCollectionId: collectionName,
|
|
1055
|
+
referringItemFieldName: relationshipAttribute,
|
|
1056
|
+
referringItemId: itemId(left),
|
|
1057
|
+
newReferencedItemIds: rights.map(itemId),
|
|
1058
|
+
...toOptions(options)
|
|
1059
|
+
}));
|
|
1060
|
+
}
|
|
1061
|
+
async removeReference(collectionName, relationshipAttribute, left, right, options) {
|
|
1062
|
+
const rights = asArray(right);
|
|
1063
|
+
await apiValidator().arity('removeReference', arguments, 4, 5).collectionName(collectionName).referenceParameter(left).referenceRemoveParameters(rights).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').options(options).validateAndReject();
|
|
1064
|
+
await this.trace('removeReference', {
|
|
1065
|
+
collectionName,
|
|
1066
|
+
relationshipAttribute
|
|
1067
|
+
})(async env => this.client.bulkRemoveDataItemReferences({
|
|
1068
|
+
...env,
|
|
1069
|
+
dataCollectionId: collectionName,
|
|
1070
|
+
dataItemReferences: rights.map(r => ({
|
|
1071
|
+
referringItemFieldName: relationshipAttribute,
|
|
1072
|
+
referringItemId: itemId(left),
|
|
1073
|
+
referencedItemId: itemId(r)
|
|
1074
|
+
})),
|
|
1075
|
+
...toOptions(options)
|
|
1076
|
+
}));
|
|
1077
|
+
}
|
|
1078
|
+
async isReferenced(collectionName, relationshipAttribute, left, right, options) {
|
|
1079
|
+
await apiValidator().arity('isReferenced', arguments, 4, 5).collectionName(collectionName).referenceParameter(left).referenceParameter(right).options(options).validateAndReject();
|
|
1080
|
+
return this.trace('isReferenced', {
|
|
1081
|
+
collectionName,
|
|
1082
|
+
relationshipAttribute
|
|
1083
|
+
})(async env => {
|
|
1084
|
+
const {
|
|
1085
|
+
isReferenced
|
|
1086
|
+
} = await this.client.isReferencedDataItem({
|
|
1087
|
+
...env,
|
|
1088
|
+
dataCollectionId: collectionName,
|
|
1089
|
+
referringItemFieldName: relationshipAttribute,
|
|
1090
|
+
referringItemId: itemId(left),
|
|
1091
|
+
referencedItemId: itemId(right),
|
|
1092
|
+
...toReadOptions(options),
|
|
1093
|
+
consistentRead: options == null ? void 0 : options.consistentRead
|
|
1094
|
+
});
|
|
1095
|
+
return isReferenced;
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1090
1098
|
trace(action, opts) {
|
|
1091
1099
|
return async fn => {
|
|
1092
1100
|
const gridAppId = await get(this.gridAppId);
|