@wix/wix-data-items-common 1.0.309 → 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.
@@ -330,90 +330,6 @@ class WixDataApi {
330
330
  skipNumber: (options == null ? void 0 : options.skip) ?? 0
331
331
  });
332
332
  }));
333
- (0, _defineProperty2.default)(this, "insertReference", withArgs(async (args, collectionName, refsOrAttr, leftOrOpts, right, options) => {
334
- let refs;
335
- let opts;
336
- let argc;
337
- if (typeof refsOrAttr === 'string') {
338
- const rights = asArray(right);
339
- refs = rights.map(r => ({
340
- relationshipName: refsOrAttr,
341
- left: leftOrOpts,
342
- right: r
343
- }));
344
- opts = options;
345
- argc = [4, 5];
346
- } else {
347
- refs = refsOrAttr;
348
- opts = leftOrOpts;
349
- argc = [2, 3];
350
- }
351
- await apiValidator().arity('insertReference', args, ...argc).collectionName(collectionName).references(refs).options(opts).validateAndReject();
352
- await this.trace('insertReference', {
353
- collectionName
354
- })(async env => this.client.bulkInsertDataItemReferences({
355
- ...env,
356
- dataCollectionId: collectionName,
357
- dataItemReferences: refs.map(r => ({
358
- referringItemFieldName: r.relationshipName,
359
- referringItemId: itemId(r.left),
360
- referencedItemId: itemId(r.right)
361
- })),
362
- ...toOptions(opts)
363
- }));
364
- }));
365
- (0, _defineProperty2.default)(this, "replaceReferences", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
366
- const rights = asArray(right);
367
- await apiValidator().arity('replaceReferences', args, 4, 5).collectionName(collectionName).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').referenceParameter(left).referenceParameters(rights).options(options).validateAndReject();
368
- await this.trace('replaceReferences', {
369
- collectionName,
370
- relationshipAttribute
371
- })(async env => this.client.replaceDataItemReferences({
372
- ...env,
373
- dataCollectionId: collectionName,
374
- referringItemFieldName: relationshipAttribute,
375
- referringItemId: itemId(left),
376
- newReferencedItemIds: rights.map(itemId),
377
- ...toOptions(options)
378
- }));
379
- }));
380
- (0, _defineProperty2.default)(this, "removeReference", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
381
- const rights = asArray(right);
382
- await apiValidator().arity('removeReference', args, 4, 5).collectionName(collectionName).referenceParameter(left).referenceRemoveParameters(rights).isNonEmptyString(relationshipAttribute, 'relationshipAttribute').options(options).validateAndReject();
383
- await this.trace('removeReference', {
384
- collectionName,
385
- relationshipAttribute
386
- })(async env => this.client.bulkRemoveDataItemReferences({
387
- ...env,
388
- dataCollectionId: collectionName,
389
- dataItemReferences: rights.map(r => ({
390
- referringItemFieldName: relationshipAttribute,
391
- referringItemId: itemId(left),
392
- referencedItemId: itemId(r)
393
- })),
394
- ...toOptions(options)
395
- }));
396
- }));
397
- (0, _defineProperty2.default)(this, "isReferenced", withArgs(async (args, collectionName, relationshipAttribute, left, right, options) => {
398
- await apiValidator().arity('isReferenced', args, 4, 5).collectionName(collectionName).referenceParameter(left).referenceParameter(right).options(options).validateAndReject();
399
- return this.trace('isReferenced', {
400
- collectionName,
401
- relationshipAttribute
402
- })(async env => {
403
- const {
404
- isReferenced
405
- } = await this.client.isReferencedDataItem({
406
- ...env,
407
- dataCollectionId: collectionName,
408
- referringItemFieldName: relationshipAttribute,
409
- referringItemId: itemId(left),
410
- referencedItemId: itemId(right),
411
- ...toReadOptions(options),
412
- consistentRead: options == null ? void 0 : options.consistentRead
413
- });
414
- return isReferenced;
415
- });
416
- }));
417
333
  this.client = new _ApiClient.ApiClient(clientFactory, allowGet);
418
334
  }
419
335
  get wixData() {
@@ -1095,6 +1011,90 @@ class WixDataApi {
1095
1011
  };
1096
1012
  });
1097
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
+ }
1098
1098
  trace(action, opts) {
1099
1099
  return async fn => {
1100
1100
  const gridAppId = await get(this.gridAppId);