@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
|
@@ -68,111 +68,6 @@ export class WixDataApi {
|
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
|
-
// --- single-item methods ---
|
|
72
|
-
this.get = withArgs(async (args, collectionName, itemId, options) => {
|
|
73
|
-
await apiValidator()
|
|
74
|
-
.arity('get', args, 2, 3)
|
|
75
|
-
.collectionName(collectionName)
|
|
76
|
-
.itemId(itemId)
|
|
77
|
-
.options(options)
|
|
78
|
-
.validateAndReject();
|
|
79
|
-
return this.trace('get', { collectionName, itemId })(async (env) => {
|
|
80
|
-
const { dataItem } = await this.client
|
|
81
|
-
.getDataItem({
|
|
82
|
-
...env,
|
|
83
|
-
dataCollectionId: collectionName,
|
|
84
|
-
dataItemId: itemId,
|
|
85
|
-
...toReadOptions(options),
|
|
86
|
-
fields: options?.fields,
|
|
87
|
-
includeReferences: options?.includeReferences,
|
|
88
|
-
...(options?.includeFieldGroups?.length
|
|
89
|
-
? { includeFieldGroups: options.includeFieldGroups }
|
|
90
|
-
: {}),
|
|
91
|
-
})
|
|
92
|
-
.catch(recover(ItemDoesNotExistCode, {}));
|
|
93
|
-
return dataItem ? toDataItem(dataItem) : null;
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
this.insert = withArgs(async (args, collectionName, item, options) => {
|
|
97
|
-
await apiValidator()
|
|
98
|
-
.arity('insert', args, 2, 3)
|
|
99
|
-
.collectionName(collectionName)
|
|
100
|
-
.item(item, collectionName, false)
|
|
101
|
-
.options(options)
|
|
102
|
-
.validateAndReject();
|
|
103
|
-
warnAboutBrokenFields(item);
|
|
104
|
-
return this.trace('insert', { collectionName })(async (env) => {
|
|
105
|
-
const { dataItem } = await this.client.insertDataItem({
|
|
106
|
-
...env,
|
|
107
|
-
dataCollectionId: collectionName,
|
|
108
|
-
dataItem: {
|
|
109
|
-
id: item._id,
|
|
110
|
-
data: item,
|
|
111
|
-
},
|
|
112
|
-
...toInsertOptions(options),
|
|
113
|
-
});
|
|
114
|
-
return toDataItem(dataItem);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
this.save = withArgs(async (args, collectionName, item, options) => {
|
|
118
|
-
await apiValidator()
|
|
119
|
-
.arity('save', args, 2, 3)
|
|
120
|
-
.collectionName(collectionName)
|
|
121
|
-
.item(item, collectionName, false)
|
|
122
|
-
.options(options)
|
|
123
|
-
.validateAndReject();
|
|
124
|
-
return this.trace('save', { collectionName })(async (env) => {
|
|
125
|
-
const { dataItem } = await this.client.saveDataItem({
|
|
126
|
-
...env,
|
|
127
|
-
dataCollectionId: collectionName,
|
|
128
|
-
dataItem: {
|
|
129
|
-
id: item._id,
|
|
130
|
-
data: item,
|
|
131
|
-
},
|
|
132
|
-
...toSaveOptions(options),
|
|
133
|
-
});
|
|
134
|
-
return toDataItem(dataItem);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
this.update = withArgs(async (args, collectionName, item, options) => {
|
|
138
|
-
await apiValidator()
|
|
139
|
-
.arity('update', args, 2, 3)
|
|
140
|
-
.collectionName(collectionName)
|
|
141
|
-
.item(item, collectionName, false)
|
|
142
|
-
.options(options)
|
|
143
|
-
.validateAndReject();
|
|
144
|
-
return this.trace('update', { collectionName })(async (env) => {
|
|
145
|
-
const { dataItem } = await this.client.updateDataItem({
|
|
146
|
-
...env,
|
|
147
|
-
dataCollectionId: collectionName,
|
|
148
|
-
dataItem: {
|
|
149
|
-
id: item._id,
|
|
150
|
-
data: item,
|
|
151
|
-
},
|
|
152
|
-
...toUpdateOptions(options),
|
|
153
|
-
});
|
|
154
|
-
return toDataItem(dataItem);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
this.remove = withArgs(async (args, collectionName, itemId, options) => {
|
|
158
|
-
await apiValidator()
|
|
159
|
-
.arity('remove', args, 2, 3)
|
|
160
|
-
.collectionName(collectionName)
|
|
161
|
-
.itemId(itemId)
|
|
162
|
-
.options(options)
|
|
163
|
-
.validateAndReject();
|
|
164
|
-
return this.trace('remove', { collectionName, itemId })(async (env) => {
|
|
165
|
-
const { dataItem } = await this.client
|
|
166
|
-
.removeDataItem({
|
|
167
|
-
...env,
|
|
168
|
-
dataCollectionId: collectionName,
|
|
169
|
-
dataItemId: itemId,
|
|
170
|
-
...toRemoveOptions(options),
|
|
171
|
-
})
|
|
172
|
-
.catch(recover(ItemDoesNotExistCode, {}));
|
|
173
|
-
return dataItem ? toDataItem(dataItem) : null;
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
71
|
this.toFieldModificationApi = (fieldModification) => {
|
|
177
72
|
switch (fieldModification.action) {
|
|
178
73
|
case 'SET_FIELD':
|
|
@@ -322,37 +217,6 @@ export class WixDataApi {
|
|
|
322
217
|
return this.client.aggregatePipelineDataItems(request);
|
|
323
218
|
});
|
|
324
219
|
});
|
|
325
|
-
this.distinct = withArgs(async (args, collectionName, fieldName, options) => {
|
|
326
|
-
await apiValidator()
|
|
327
|
-
.arity('distinct', args, 2, 3)
|
|
328
|
-
.collectionName(collectionName)
|
|
329
|
-
.fieldName(fieldName)
|
|
330
|
-
.options(options)
|
|
331
|
-
.validateAndReject();
|
|
332
|
-
const limit = options?.paging?.limit ?? options?.cursorPaging?.limit;
|
|
333
|
-
const offset = options?.paging?.offset ?? 0;
|
|
334
|
-
const cursor = options?.cursorPaging?.cursor;
|
|
335
|
-
return this.trace('distinct', { collectionName, field: fieldName })(async (env) => {
|
|
336
|
-
const { distinctValues, pagingMetadata } = await this.client.queryDistinctValues({
|
|
337
|
-
...env,
|
|
338
|
-
dataCollectionId: collectionName,
|
|
339
|
-
...toReadOptions(options),
|
|
340
|
-
...toPaging(limit, cursor ?? offset),
|
|
341
|
-
...(cursor === undefined
|
|
342
|
-
? {
|
|
343
|
-
fieldName,
|
|
344
|
-
filter: options?.filter,
|
|
345
|
-
order: options?.order,
|
|
346
|
-
returnTotalCount: options?.returnTotalCount,
|
|
347
|
-
}
|
|
348
|
-
: {}),
|
|
349
|
-
});
|
|
350
|
-
return {
|
|
351
|
-
values: distinctValues,
|
|
352
|
-
pagingMetadata: pagingMetadata,
|
|
353
|
-
};
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
220
|
/** @internal */
|
|
357
221
|
this.count = withArgs(async (args, collectionName, options) => {
|
|
358
222
|
await apiValidator()
|
|
@@ -390,45 +254,6 @@ export class WixDataApi {
|
|
|
390
254
|
return toBulkResult(itemIds, results, ['WDE0073']);
|
|
391
255
|
});
|
|
392
256
|
});
|
|
393
|
-
this.bulkInsert = withArgs(async (args, collectionName, items, options) => {
|
|
394
|
-
await apiValidator()
|
|
395
|
-
.arity('bulkInsert', args, 2, 3)
|
|
396
|
-
.items(items, collectionName)
|
|
397
|
-
.bulkInsertOptions(options)
|
|
398
|
-
.collectionName(collectionName)
|
|
399
|
-
.validateAndReject();
|
|
400
|
-
return this.trace('bulkInsert', { collectionName, options })(async (appId) => this.runBulkSave(appId, collectionName, items, options, options?.overrideExisting ?? false));
|
|
401
|
-
});
|
|
402
|
-
this.bulkSave = withArgs(async (args, collectionName, items, options) => {
|
|
403
|
-
await apiValidator()
|
|
404
|
-
.arity('bulkSave', args, 2, 3)
|
|
405
|
-
.bulkInsertOptions(options)
|
|
406
|
-
.collectionName(collectionName)
|
|
407
|
-
.items(items, collectionName)
|
|
408
|
-
.validateAndReject();
|
|
409
|
-
return this.trace('bulkSave', { collectionName })(async (env) => this.runBulkSave(env, collectionName, items, options));
|
|
410
|
-
});
|
|
411
|
-
this.bulkUpdate = withArgs(async (args, collectionName, items, options) => {
|
|
412
|
-
await apiValidator()
|
|
413
|
-
.arity('bulkUpdate', args, 2, 3)
|
|
414
|
-
.bulkUpdateOptions(options)
|
|
415
|
-
.collectionName(collectionName)
|
|
416
|
-
.items(items, collectionName)
|
|
417
|
-
.validateAndReject();
|
|
418
|
-
return this.trace('bulkUpdate', { collectionName })(async (env) => {
|
|
419
|
-
const { results } = await this.client.bulkUpdateDataItems({
|
|
420
|
-
...env,
|
|
421
|
-
dataCollectionId: collectionName,
|
|
422
|
-
dataItems: items.map((data) => ({
|
|
423
|
-
id: data._id,
|
|
424
|
-
data,
|
|
425
|
-
})),
|
|
426
|
-
...toBulkUpdateOptions(options),
|
|
427
|
-
});
|
|
428
|
-
// Non-existing items are skipped and not reported as errors.
|
|
429
|
-
return toBulkResult(items, results, ['WDE0073']);
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
257
|
// --- references ---
|
|
433
258
|
this.fetchReferenced = withArgs(async (args, collectionName, cursor, limit, options) => {
|
|
434
259
|
await apiValidator()
|
|
@@ -496,152 +321,124 @@ export class WixDataApi {
|
|
|
496
321
|
skipNumber: options?.skip ?? 0,
|
|
497
322
|
});
|
|
498
323
|
});
|
|
499
|
-
this.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
referringItemIds,
|
|
519
|
-
referringItemFieldName,
|
|
520
|
-
order: options?.order,
|
|
521
|
-
paging: options?.paging,
|
|
522
|
-
cursorPaging: options?.cursorPaging,
|
|
523
|
-
fields: options?.fields,
|
|
524
|
-
returnTotalCount: options?.returnTotalCount,
|
|
525
|
-
});
|
|
526
|
-
return {
|
|
527
|
-
results: toReferencedResults(results ?? []),
|
|
528
|
-
pagingMetadata: pagingMetadata,
|
|
529
|
-
};
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
this.insertReference = withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
|
|
533
|
-
let refs;
|
|
534
|
-
let opts;
|
|
535
|
-
let argc;
|
|
536
|
-
if (typeof refsOrAttr === 'string') {
|
|
537
|
-
const rights = asArray(right);
|
|
538
|
-
refs = rights.map((r) => ({
|
|
539
|
-
relationshipName: refsOrAttr,
|
|
540
|
-
left: leftOrOpts,
|
|
541
|
-
right: r,
|
|
542
|
-
}));
|
|
543
|
-
opts = options;
|
|
544
|
-
argc = [4, 5];
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
refs = refsOrAttr;
|
|
548
|
-
opts = leftOrOpts;
|
|
549
|
-
argc = [2, 3];
|
|
550
|
-
}
|
|
551
|
-
await apiValidator()
|
|
552
|
-
.arity('insertReference', args, ...argc)
|
|
553
|
-
.collectionName(collectionName)
|
|
554
|
-
.references(refs)
|
|
555
|
-
.options(opts)
|
|
556
|
-
.validateAndReject();
|
|
557
|
-
await this.trace('insertReference', { collectionName })(async (env) => this.client.bulkInsertDataItemReferences({
|
|
324
|
+
this.client = new ApiClient(clientFactory, allowGet);
|
|
325
|
+
}
|
|
326
|
+
get wixData() {
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
get filter() {
|
|
330
|
+
return filterBuilder();
|
|
331
|
+
}
|
|
332
|
+
// --- single-item methods ---
|
|
333
|
+
async get(collectionName, itemId, options) {
|
|
334
|
+
await apiValidator()
|
|
335
|
+
.arity('get', arguments, 2, 3)
|
|
336
|
+
.collectionName(collectionName)
|
|
337
|
+
.itemId(itemId)
|
|
338
|
+
.options(options)
|
|
339
|
+
.validateAndReject();
|
|
340
|
+
return this.trace('get', { collectionName, itemId })(async (env) => {
|
|
341
|
+
const { dataItem } = await this.client
|
|
342
|
+
.getDataItem({
|
|
558
343
|
...env,
|
|
559
344
|
dataCollectionId: collectionName,
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
345
|
+
dataItemId: itemId,
|
|
346
|
+
...toReadOptions(options),
|
|
347
|
+
fields: options?.fields,
|
|
348
|
+
includeReferences: options?.includeReferences,
|
|
349
|
+
...(options?.includeFieldGroups?.length
|
|
350
|
+
? { includeFieldGroups: options.includeFieldGroups }
|
|
351
|
+
: {}),
|
|
352
|
+
})
|
|
353
|
+
.catch(recover(ItemDoesNotExistCode, {}));
|
|
354
|
+
return dataItem
|
|
355
|
+
? toDataItem(dataItem)
|
|
356
|
+
: null;
|
|
567
357
|
});
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
relationshipAttribute,
|
|
581
|
-
})(async (env) => this.client.replaceDataItemReferences({
|
|
358
|
+
}
|
|
359
|
+
async insert(collectionName, item, options) {
|
|
360
|
+
const itemAsWixData = item;
|
|
361
|
+
await apiValidator()
|
|
362
|
+
.arity('insert', arguments, 2, 3)
|
|
363
|
+
.collectionName(collectionName)
|
|
364
|
+
.item(itemAsWixData, collectionName, false)
|
|
365
|
+
.options(options)
|
|
366
|
+
.validateAndReject();
|
|
367
|
+
warnAboutBrokenFields(itemAsWixData);
|
|
368
|
+
return this.trace('insert', { collectionName })(async (env) => {
|
|
369
|
+
const { dataItem } = await this.client.insertDataItem({
|
|
582
370
|
...env,
|
|
583
371
|
dataCollectionId: collectionName,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
372
|
+
dataItem: {
|
|
373
|
+
id: itemAsWixData._id,
|
|
374
|
+
data: itemAsWixData,
|
|
375
|
+
},
|
|
376
|
+
...toInsertOptions(options),
|
|
377
|
+
});
|
|
378
|
+
return toDataItem(dataItem);
|
|
589
379
|
});
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
await this.
|
|
601
|
-
collectionName,
|
|
602
|
-
relationshipAttribute,
|
|
603
|
-
})(async (env) => this.client.bulkRemoveDataItemReferences({
|
|
380
|
+
}
|
|
381
|
+
async save(collectionName, item, options) {
|
|
382
|
+
const itemAsWixData = item;
|
|
383
|
+
await apiValidator()
|
|
384
|
+
.arity('save', arguments, 2, 3)
|
|
385
|
+
.collectionName(collectionName)
|
|
386
|
+
.item(itemAsWixData, collectionName, false)
|
|
387
|
+
.options(options)
|
|
388
|
+
.validateAndReject();
|
|
389
|
+
return this.trace('save', { collectionName })(async (env) => {
|
|
390
|
+
const { dataItem } = await this.client.saveDataItem({
|
|
604
391
|
...env,
|
|
605
392
|
dataCollectionId: collectionName,
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
...toOptions(options),
|
|
612
|
-
}));
|
|
613
|
-
});
|
|
614
|
-
this.isReferenced = withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
|
|
615
|
-
await apiValidator()
|
|
616
|
-
.arity('isReferenced', args, 4, 5)
|
|
617
|
-
.collectionName(collectionName)
|
|
618
|
-
.referenceParameter(left)
|
|
619
|
-
.referenceParameter(right)
|
|
620
|
-
.options(options)
|
|
621
|
-
.validateAndReject();
|
|
622
|
-
return this.trace('isReferenced', {
|
|
623
|
-
collectionName,
|
|
624
|
-
relationshipAttribute,
|
|
625
|
-
})(async (env) => {
|
|
626
|
-
const { isReferenced } = await this.client.isReferencedDataItem({
|
|
627
|
-
...env,
|
|
628
|
-
dataCollectionId: collectionName,
|
|
629
|
-
referringItemFieldName: relationshipAttribute,
|
|
630
|
-
referringItemId: itemId(left),
|
|
631
|
-
referencedItemId: itemId(right),
|
|
632
|
-
...toReadOptions(options),
|
|
633
|
-
consistentRead: options?.consistentRead,
|
|
634
|
-
});
|
|
635
|
-
return isReferenced;
|
|
393
|
+
dataItem: {
|
|
394
|
+
id: itemAsWixData._id,
|
|
395
|
+
data: itemAsWixData,
|
|
396
|
+
},
|
|
397
|
+
...toSaveOptions(options),
|
|
636
398
|
});
|
|
399
|
+
return toDataItem(dataItem);
|
|
637
400
|
});
|
|
638
|
-
this.client = new ApiClient(clientFactory, allowGet);
|
|
639
401
|
}
|
|
640
|
-
|
|
641
|
-
|
|
402
|
+
async update(collectionName, item, options) {
|
|
403
|
+
await apiValidator()
|
|
404
|
+
.arity('update', arguments, 2, 3)
|
|
405
|
+
.collectionName(collectionName)
|
|
406
|
+
.item(item, collectionName, false)
|
|
407
|
+
.options(options)
|
|
408
|
+
.validateAndReject();
|
|
409
|
+
return this.trace('update', { collectionName })(async (env) => {
|
|
410
|
+
const { dataItem } = await this.client.updateDataItem({
|
|
411
|
+
...env,
|
|
412
|
+
dataCollectionId: collectionName,
|
|
413
|
+
dataItem: {
|
|
414
|
+
id: item._id,
|
|
415
|
+
data: item,
|
|
416
|
+
},
|
|
417
|
+
...toUpdateOptions(options),
|
|
418
|
+
});
|
|
419
|
+
return toDataItem(dataItem);
|
|
420
|
+
});
|
|
642
421
|
}
|
|
643
|
-
|
|
644
|
-
|
|
422
|
+
async remove(collectionName, itemId, options) {
|
|
423
|
+
await apiValidator()
|
|
424
|
+
.arity('remove', arguments, 2, 3)
|
|
425
|
+
.collectionName(collectionName)
|
|
426
|
+
.itemId(itemId)
|
|
427
|
+
.options(options)
|
|
428
|
+
.validateAndReject();
|
|
429
|
+
return this.trace('remove', { collectionName, itemId })(async (env) => {
|
|
430
|
+
const { dataItem } = await this.client
|
|
431
|
+
.removeDataItem({
|
|
432
|
+
...env,
|
|
433
|
+
dataCollectionId: collectionName,
|
|
434
|
+
dataItemId: itemId,
|
|
435
|
+
...toRemoveOptions(options),
|
|
436
|
+
})
|
|
437
|
+
.catch(recover(ItemDoesNotExistCode, {}));
|
|
438
|
+
return dataItem
|
|
439
|
+
? toDataItem(dataItem)
|
|
440
|
+
: null;
|
|
441
|
+
});
|
|
645
442
|
}
|
|
646
443
|
patch(collectionName, itemId, fieldModifications, options) {
|
|
647
444
|
if (arguments.length >= 3) {
|
|
@@ -679,7 +476,9 @@ export class WixDataApi {
|
|
|
679
476
|
},
|
|
680
477
|
...toPatchOptions(options),
|
|
681
478
|
});
|
|
682
|
-
return result.dataItem
|
|
479
|
+
return result.dataItem
|
|
480
|
+
? toDataItem(result.dataItem)
|
|
481
|
+
: null;
|
|
683
482
|
});
|
|
684
483
|
}
|
|
685
484
|
bulkPatch(collectionName, itemIds, fieldModifications, options) {
|
|
@@ -1017,6 +816,37 @@ export class WixDataApi {
|
|
|
1017
816
|
pagingMetadata: pagingMetadata,
|
|
1018
817
|
};
|
|
1019
818
|
}
|
|
819
|
+
async distinct(collectionName, fieldName, options) {
|
|
820
|
+
await apiValidator()
|
|
821
|
+
.arity('distinct', arguments, 2, 3)
|
|
822
|
+
.collectionName(collectionName)
|
|
823
|
+
.fieldName(fieldName)
|
|
824
|
+
.options(options)
|
|
825
|
+
.validateAndReject();
|
|
826
|
+
const limit = options?.paging?.limit ?? options?.cursorPaging?.limit;
|
|
827
|
+
const offset = options?.paging?.offset ?? 0;
|
|
828
|
+
const cursor = options?.cursorPaging?.cursor;
|
|
829
|
+
return this.trace('distinct', { collectionName, field: fieldName })(async (env) => {
|
|
830
|
+
const { distinctValues, pagingMetadata } = await this.client.queryDistinctValues({
|
|
831
|
+
...env,
|
|
832
|
+
dataCollectionId: collectionName,
|
|
833
|
+
...toReadOptions(options),
|
|
834
|
+
...toPaging(limit, cursor ?? offset),
|
|
835
|
+
...(cursor === undefined
|
|
836
|
+
? {
|
|
837
|
+
fieldName,
|
|
838
|
+
filter: options?.filter,
|
|
839
|
+
order: options?.order,
|
|
840
|
+
returnTotalCount: options?.returnTotalCount,
|
|
841
|
+
}
|
|
842
|
+
: {}),
|
|
843
|
+
});
|
|
844
|
+
return {
|
|
845
|
+
values: distinctValues,
|
|
846
|
+
pagingMetadata: pagingMetadata,
|
|
847
|
+
};
|
|
848
|
+
});
|
|
849
|
+
}
|
|
1020
850
|
async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
|
|
1021
851
|
const request = {
|
|
1022
852
|
...env,
|
|
@@ -1034,6 +864,186 @@ export class WixDataApi {
|
|
|
1034
864
|
const ignoreCodes = overrideExisting ? [] : ['WDE0074'];
|
|
1035
865
|
return toBulkResult(items, results, ignoreCodes);
|
|
1036
866
|
}
|
|
867
|
+
async bulkInsert(collectionName, items, options) {
|
|
868
|
+
const itemsAsWixData = items;
|
|
869
|
+
await apiValidator()
|
|
870
|
+
.arity('bulkInsert', arguments, 2, 3)
|
|
871
|
+
.items(itemsAsWixData, collectionName)
|
|
872
|
+
.bulkInsertOptions(options)
|
|
873
|
+
.collectionName(collectionName)
|
|
874
|
+
.validateAndReject();
|
|
875
|
+
return this.trace('bulkInsert', { collectionName, options })(async (appId) => this.runBulkSave(appId, collectionName, itemsAsWixData, options, options?.overrideExisting ?? false));
|
|
876
|
+
}
|
|
877
|
+
async bulkSave(collectionName, items, options) {
|
|
878
|
+
const itemsAsWixData = items;
|
|
879
|
+
await apiValidator()
|
|
880
|
+
.arity('bulkSave', arguments, 2, 3)
|
|
881
|
+
.bulkInsertOptions(options)
|
|
882
|
+
.collectionName(collectionName)
|
|
883
|
+
.items(itemsAsWixData, collectionName)
|
|
884
|
+
.validateAndReject();
|
|
885
|
+
return this.trace('bulkSave', { collectionName })(async (env) => this.runBulkSave(env, collectionName, itemsAsWixData, options));
|
|
886
|
+
}
|
|
887
|
+
async bulkUpdate(collectionName, items, options) {
|
|
888
|
+
await apiValidator()
|
|
889
|
+
.arity('bulkUpdate', arguments, 2, 3)
|
|
890
|
+
.bulkUpdateOptions(options)
|
|
891
|
+
.collectionName(collectionName)
|
|
892
|
+
.items(items, collectionName)
|
|
893
|
+
.validateAndReject();
|
|
894
|
+
return this.trace('bulkUpdate', { collectionName })(async (env) => {
|
|
895
|
+
const { results } = await this.client.bulkUpdateDataItems({
|
|
896
|
+
...env,
|
|
897
|
+
dataCollectionId: collectionName,
|
|
898
|
+
dataItems: items.map((data) => ({
|
|
899
|
+
id: data._id,
|
|
900
|
+
data,
|
|
901
|
+
})),
|
|
902
|
+
...toBulkUpdateOptions(options),
|
|
903
|
+
});
|
|
904
|
+
// Non-existing items are skipped and not reported as errors.
|
|
905
|
+
return toBulkResult(items, results, ['WDE0073']);
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
async queryReferencedItems(collectionName, referringItem, referringItemFieldName, options) {
|
|
909
|
+
await apiValidator()
|
|
910
|
+
.arity('queryReferencedItems', arguments, 3, 4)
|
|
911
|
+
.collectionName(collectionName)
|
|
912
|
+
.referenceParameters(asArray(referringItem))
|
|
913
|
+
.isNonEmptyString(referringItemFieldName, 'referringItemFieldName')
|
|
914
|
+
.options(options)
|
|
915
|
+
.validateAndReject();
|
|
916
|
+
const referringItemIds = asArray(referringItem).map(itemId);
|
|
917
|
+
return this.trace('queryReferencedItems', {
|
|
918
|
+
collectionName,
|
|
919
|
+
referringItemIds,
|
|
920
|
+
options,
|
|
921
|
+
referringItemFieldName,
|
|
922
|
+
})(async (env) => {
|
|
923
|
+
const { results, pagingMetadata } = await this.client.queryReferencedDataItems({
|
|
924
|
+
...env,
|
|
925
|
+
...toReadOptions(options),
|
|
926
|
+
dataCollectionId: collectionName,
|
|
927
|
+
referringItemIds,
|
|
928
|
+
referringItemFieldName,
|
|
929
|
+
order: options?.order,
|
|
930
|
+
paging: options?.paging,
|
|
931
|
+
cursorPaging: options?.cursorPaging,
|
|
932
|
+
fields: options?.fields,
|
|
933
|
+
returnTotalCount: options?.returnTotalCount,
|
|
934
|
+
});
|
|
935
|
+
return {
|
|
936
|
+
results: toReferencedResults(results ?? []),
|
|
937
|
+
pagingMetadata: pagingMetadata,
|
|
938
|
+
};
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
async insertReference(collectionName, refsOrAttr, leftOrOpts, right, options) {
|
|
942
|
+
let refs;
|
|
943
|
+
let opts;
|
|
944
|
+
let argc;
|
|
945
|
+
if (typeof refsOrAttr === 'string') {
|
|
946
|
+
const rights = asArray(right);
|
|
947
|
+
refs = rights.map((r) => ({
|
|
948
|
+
relationshipName: refsOrAttr,
|
|
949
|
+
left: leftOrOpts,
|
|
950
|
+
right: r,
|
|
951
|
+
}));
|
|
952
|
+
opts = options;
|
|
953
|
+
argc = [4, 5];
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
refs = refsOrAttr;
|
|
957
|
+
opts = leftOrOpts;
|
|
958
|
+
argc = [2, 3];
|
|
959
|
+
}
|
|
960
|
+
await apiValidator()
|
|
961
|
+
.arity('insertReference', arguments, ...argc)
|
|
962
|
+
.collectionName(collectionName)
|
|
963
|
+
.references(refs)
|
|
964
|
+
.options(opts)
|
|
965
|
+
.validateAndReject();
|
|
966
|
+
await this.trace('insertReference', { collectionName })(async (env) => this.client.bulkInsertDataItemReferences({
|
|
967
|
+
...env,
|
|
968
|
+
dataCollectionId: collectionName,
|
|
969
|
+
dataItemReferences: refs.map((r) => ({
|
|
970
|
+
referringItemFieldName: r.relationshipName,
|
|
971
|
+
referringItemId: itemId(r.left),
|
|
972
|
+
referencedItemId: itemId(r.right),
|
|
973
|
+
})),
|
|
974
|
+
...toOptions(opts),
|
|
975
|
+
}));
|
|
976
|
+
}
|
|
977
|
+
async replaceReferences(collectionName, relationshipAttribute, left, right, options) {
|
|
978
|
+
const rights = asArray(right);
|
|
979
|
+
await apiValidator()
|
|
980
|
+
.arity('replaceReferences', arguments, 4, 5)
|
|
981
|
+
.collectionName(collectionName)
|
|
982
|
+
.isNonEmptyString(relationshipAttribute, 'relationshipAttribute')
|
|
983
|
+
.referenceParameter(left)
|
|
984
|
+
.referenceParameters(rights)
|
|
985
|
+
.options(options)
|
|
986
|
+
.validateAndReject();
|
|
987
|
+
await this.trace('replaceReferences', {
|
|
988
|
+
collectionName,
|
|
989
|
+
relationshipAttribute,
|
|
990
|
+
})(async (env) => this.client.replaceDataItemReferences({
|
|
991
|
+
...env,
|
|
992
|
+
dataCollectionId: collectionName,
|
|
993
|
+
referringItemFieldName: relationshipAttribute,
|
|
994
|
+
referringItemId: itemId(left),
|
|
995
|
+
newReferencedItemIds: rights.map(itemId),
|
|
996
|
+
...toOptions(options),
|
|
997
|
+
}));
|
|
998
|
+
}
|
|
999
|
+
async removeReference(collectionName, relationshipAttribute, left, right, options) {
|
|
1000
|
+
const rights = asArray(right);
|
|
1001
|
+
await apiValidator()
|
|
1002
|
+
.arity('removeReference', arguments, 4, 5)
|
|
1003
|
+
.collectionName(collectionName)
|
|
1004
|
+
.referenceParameter(left)
|
|
1005
|
+
.referenceRemoveParameters(rights)
|
|
1006
|
+
.isNonEmptyString(relationshipAttribute, 'relationshipAttribute')
|
|
1007
|
+
.options(options)
|
|
1008
|
+
.validateAndReject();
|
|
1009
|
+
await this.trace('removeReference', {
|
|
1010
|
+
collectionName,
|
|
1011
|
+
relationshipAttribute,
|
|
1012
|
+
})(async (env) => this.client.bulkRemoveDataItemReferences({
|
|
1013
|
+
...env,
|
|
1014
|
+
dataCollectionId: collectionName,
|
|
1015
|
+
dataItemReferences: rights.map((r) => ({
|
|
1016
|
+
referringItemFieldName: relationshipAttribute,
|
|
1017
|
+
referringItemId: itemId(left),
|
|
1018
|
+
referencedItemId: itemId(r),
|
|
1019
|
+
})),
|
|
1020
|
+
...toOptions(options),
|
|
1021
|
+
}));
|
|
1022
|
+
}
|
|
1023
|
+
async isReferenced(collectionName, relationshipAttribute, left, right, options) {
|
|
1024
|
+
await apiValidator()
|
|
1025
|
+
.arity('isReferenced', arguments, 4, 5)
|
|
1026
|
+
.collectionName(collectionName)
|
|
1027
|
+
.referenceParameter(left)
|
|
1028
|
+
.referenceParameter(right)
|
|
1029
|
+
.options(options)
|
|
1030
|
+
.validateAndReject();
|
|
1031
|
+
return this.trace('isReferenced', {
|
|
1032
|
+
collectionName,
|
|
1033
|
+
relationshipAttribute,
|
|
1034
|
+
})(async (env) => {
|
|
1035
|
+
const { isReferenced } = await this.client.isReferencedDataItem({
|
|
1036
|
+
...env,
|
|
1037
|
+
dataCollectionId: collectionName,
|
|
1038
|
+
referringItemFieldName: relationshipAttribute,
|
|
1039
|
+
referringItemId: itemId(left),
|
|
1040
|
+
referencedItemId: itemId(right),
|
|
1041
|
+
...toReadOptions(options),
|
|
1042
|
+
consistentRead: options?.consistentRead,
|
|
1043
|
+
});
|
|
1044
|
+
return isReferenced;
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1037
1047
|
trace(action, opts) {
|
|
1038
1048
|
return async (fn) => {
|
|
1039
1049
|
const gridAppId = await get(this.gridAppId);
|