@wix/wix-data-items-common 1.0.281 → 1.0.282
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 +157 -91
- package/dist/cjs/api/WixDataApi.js.map +1 -1
- package/dist/cjs/api/WixDataQueryBuilder.js +88 -0
- package/dist/cjs/api/WixDataQueryBuilder.js.map +1 -0
- package/dist/cjs/api/index.js +9 -1
- package/dist/cjs/api/index.js.map +1 -1
- package/dist/cjs/api/types.js.map +1 -1
- package/dist/esm/api/WixDataApi.js +148 -99
- package/dist/esm/api/WixDataApi.js.map +1 -1
- package/dist/esm/api/WixDataQueryBuilder.js +74 -0
- package/dist/esm/api/WixDataQueryBuilder.js.map +1 -0
- package/dist/esm/api/index.js +1 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/types/api/WixDataApi.d.ts +17 -2
- package/dist/types/api/WixDataApi.d.ts.map +1 -1
- package/dist/types/api/WixDataQueryBuilder.d.ts +79 -0
- package/dist/types/api/WixDataQueryBuilder.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +61 -0
- package/dist/types/api/types.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -239,97 +239,6 @@ class WixDataApi {
|
|
|
239
239
|
}
|
|
240
240
|
});
|
|
241
241
|
});
|
|
242
|
-
// --- query, count, distinct ---
|
|
243
|
-
(0, _defineProperty2.default)(this, "query", collectionName => {
|
|
244
|
-
const ensureValidQuery = invalidArgs => {
|
|
245
|
-
if (invalidArgs.length > 0) {
|
|
246
|
-
throw (0, _errors.wdeValidationError)(_errors.messages.queryValidations.queryInvalid(collectionName, invalidArgs));
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
return new _WixDataQueryImpl.WixDataQueryImpl({
|
|
250
|
-
collectionName,
|
|
251
|
-
onCount: async (args, params, options) => {
|
|
252
|
-
ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).arity('count', args, 0, 1).options(options).validateAndReturn()]);
|
|
253
|
-
return this.trace('count', {
|
|
254
|
-
collectionName
|
|
255
|
-
})(async env => {
|
|
256
|
-
const {
|
|
257
|
-
totalCount
|
|
258
|
-
} = await this.client.countDataItems({
|
|
259
|
-
...env,
|
|
260
|
-
dataCollectionId: collectionName,
|
|
261
|
-
filter: params.filterTree,
|
|
262
|
-
...toReadOptions(options)
|
|
263
|
-
});
|
|
264
|
-
return totalCount;
|
|
265
|
-
});
|
|
266
|
-
},
|
|
267
|
-
onDistinct: async (args, params, field, options) => {
|
|
268
|
-
var _toSort$find;
|
|
269
|
-
ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).arity('distinct', args, 1, 2).fieldName(field).options(options).validateAndReturn()]);
|
|
270
|
-
const order = (_toSort$find = toSort(params.orderBy).find(o => o.fieldName === field)) == null ? void 0 : _toSort$find.order;
|
|
271
|
-
const fetch = (cursorOrOffset, returnTotalCount) => this.trace('distinct', {
|
|
272
|
-
collectionName,
|
|
273
|
-
field
|
|
274
|
-
})(async env => {
|
|
275
|
-
const {
|
|
276
|
-
distinctValues,
|
|
277
|
-
pagingMetadata
|
|
278
|
-
} = await this.client.queryDistinctValues({
|
|
279
|
-
...env,
|
|
280
|
-
dataCollectionId: collectionName,
|
|
281
|
-
...toReadOptions(options),
|
|
282
|
-
...toPaging(params.limitNumber, cursorOrOffset),
|
|
283
|
-
...(isOffset(cursorOrOffset) ? {
|
|
284
|
-
fieldName: field,
|
|
285
|
-
filter: params.filterTree,
|
|
286
|
-
order,
|
|
287
|
-
returnTotalCount
|
|
288
|
-
} : {})
|
|
289
|
-
});
|
|
290
|
-
return [distinctValues, pagingMetadata];
|
|
291
|
-
});
|
|
292
|
-
const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
|
|
293
|
-
return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
|
|
294
|
-
},
|
|
295
|
-
onFind: async (args, params, options) => {
|
|
296
|
-
ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).arity('find', args, 0, 1).options(options).validateAndReturn()]);
|
|
297
|
-
const fetch = (cursorOrOffset, returnTotalCount) => this.trace('query', {
|
|
298
|
-
collectionName
|
|
299
|
-
})(async env => {
|
|
300
|
-
const {
|
|
301
|
-
dataItems,
|
|
302
|
-
pagingMetadata
|
|
303
|
-
} = await this.client.queryDataItems({
|
|
304
|
-
...env,
|
|
305
|
-
dataCollectionId: collectionName,
|
|
306
|
-
query: {
|
|
307
|
-
fields: params.projectedFields,
|
|
308
|
-
...toPaging(params.limitNumber, cursorOrOffset),
|
|
309
|
-
...(isOffset(cursorOrOffset) ? {
|
|
310
|
-
filter: params.filterTree,
|
|
311
|
-
sort: toSort(params.orderBy)
|
|
312
|
-
} : {})
|
|
313
|
-
},
|
|
314
|
-
referencedItemOptions: params.included,
|
|
315
|
-
...toReadOptions(options),
|
|
316
|
-
...(isOffset(cursorOrOffset) ? {
|
|
317
|
-
returnTotalCount
|
|
318
|
-
} : {}),
|
|
319
|
-
...(params.randomSortOptions ? {
|
|
320
|
-
sortMode: apiTypes.SortMode.RANDOM,
|
|
321
|
-
randomOptions: {
|
|
322
|
-
seed: params.randomSortOptions.seed
|
|
323
|
-
}
|
|
324
|
-
} : {})
|
|
325
|
-
});
|
|
326
|
-
return [dataItems.map(toDataItem), pagingMetadata];
|
|
327
|
-
});
|
|
328
|
-
const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
|
|
329
|
-
return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
242
|
(0, _defineProperty2.default)(this, "search", collectionName => {
|
|
334
243
|
const ensureValidQuery = invalidArgs => {
|
|
335
244
|
if (invalidArgs.length > 0) {
|
|
@@ -685,6 +594,163 @@ class WixDataApi {
|
|
|
685
594
|
}
|
|
686
595
|
get filter() {
|
|
687
596
|
return (0, _common.filterBuilder)();
|
|
597
|
+
} // --- query, count, distinct ---
|
|
598
|
+
/**
|
|
599
|
+
* Returns a query builder for the specified collection.
|
|
600
|
+
* @param collectionName - Name of the collection to query.
|
|
601
|
+
* @returns A `WixDataQuery` builder object.
|
|
602
|
+
*/
|
|
603
|
+
/**
|
|
604
|
+
* Executes a query directly without using the builder pattern.
|
|
605
|
+
* @internal
|
|
606
|
+
* @param collectionName - Name of the collection to query.
|
|
607
|
+
* @param queryRequest - Query parameters including filter, sort, paging, and fields.
|
|
608
|
+
* @param options - Additional options including referencedItemOptions.
|
|
609
|
+
* @returns Promise that resolves to the query results.
|
|
610
|
+
*/
|
|
611
|
+
query(collectionName, queryRequest, options) {
|
|
612
|
+
// Direct query execution mode
|
|
613
|
+
if (queryRequest !== undefined) {
|
|
614
|
+
return this.executeDirectQuery(collectionName, queryRequest, options);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// Builder mode
|
|
618
|
+
const ensureValidQuery = invalidArgs => {
|
|
619
|
+
if (invalidArgs.length > 0) {
|
|
620
|
+
throw (0, _errors.wdeValidationError)(_errors.messages.queryValidations.queryInvalid(collectionName, invalidArgs));
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
return new _WixDataQueryImpl.WixDataQueryImpl({
|
|
624
|
+
collectionName,
|
|
625
|
+
onCount: async (args, params, options) => {
|
|
626
|
+
ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).arity('count', args, 0, 1).options(options).validateAndReturn()]);
|
|
627
|
+
return this.trace('count', {
|
|
628
|
+
collectionName
|
|
629
|
+
})(async env => {
|
|
630
|
+
const {
|
|
631
|
+
totalCount
|
|
632
|
+
} = await this.client.countDataItems({
|
|
633
|
+
...env,
|
|
634
|
+
dataCollectionId: collectionName,
|
|
635
|
+
filter: params.filterTree,
|
|
636
|
+
...toReadOptions(options)
|
|
637
|
+
});
|
|
638
|
+
return totalCount;
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
onDistinct: async (args, params, field, options) => {
|
|
642
|
+
var _toSort$find;
|
|
643
|
+
ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).arity('distinct', args, 1, 2).fieldName(field).options(options).validateAndReturn()]);
|
|
644
|
+
const order = (_toSort$find = toSort(params.orderBy).find(o => o.fieldName === field)) == null ? void 0 : _toSort$find.order;
|
|
645
|
+
const fetch = (cursorOrOffset, returnTotalCount) => this.trace('distinct', {
|
|
646
|
+
collectionName,
|
|
647
|
+
field
|
|
648
|
+
})(async env => {
|
|
649
|
+
const {
|
|
650
|
+
distinctValues,
|
|
651
|
+
pagingMetadata
|
|
652
|
+
} = await this.client.queryDistinctValues({
|
|
653
|
+
...env,
|
|
654
|
+
dataCollectionId: collectionName,
|
|
655
|
+
...toReadOptions(options),
|
|
656
|
+
...toPaging(params.limitNumber, cursorOrOffset),
|
|
657
|
+
...(isOffset(cursorOrOffset) ? {
|
|
658
|
+
fieldName: field,
|
|
659
|
+
filter: params.filterTree,
|
|
660
|
+
order,
|
|
661
|
+
returnTotalCount
|
|
662
|
+
} : {})
|
|
663
|
+
});
|
|
664
|
+
return [distinctValues, pagingMetadata];
|
|
665
|
+
});
|
|
666
|
+
const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
|
|
667
|
+
return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
|
|
668
|
+
},
|
|
669
|
+
onFind: async (args, params, options) => {
|
|
670
|
+
ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).arity('find', args, 0, 1).options(options).validateAndReturn()]);
|
|
671
|
+
const fetch = (cursorOrOffset, returnTotalCount) => this.trace('query', {
|
|
672
|
+
collectionName
|
|
673
|
+
})(async env => {
|
|
674
|
+
const {
|
|
675
|
+
dataItems,
|
|
676
|
+
pagingMetadata
|
|
677
|
+
} = await this.client.queryDataItems({
|
|
678
|
+
...env,
|
|
679
|
+
dataCollectionId: collectionName,
|
|
680
|
+
query: {
|
|
681
|
+
fields: params.projectedFields,
|
|
682
|
+
...toPaging(params.limitNumber, cursorOrOffset),
|
|
683
|
+
...(isOffset(cursorOrOffset) ? {
|
|
684
|
+
filter: params.filterTree,
|
|
685
|
+
sort: toSort(params.orderBy)
|
|
686
|
+
} : {})
|
|
687
|
+
},
|
|
688
|
+
referencedItemOptions: params.included,
|
|
689
|
+
...toReadOptions(options),
|
|
690
|
+
...(isOffset(cursorOrOffset) ? {
|
|
691
|
+
returnTotalCount
|
|
692
|
+
} : {}),
|
|
693
|
+
...(params.randomSortOptions ? {
|
|
694
|
+
sortMode: apiTypes.SortMode.RANDOM,
|
|
695
|
+
randomOptions: {
|
|
696
|
+
seed: params.randomSortOptions.seed
|
|
697
|
+
}
|
|
698
|
+
} : {})
|
|
699
|
+
});
|
|
700
|
+
return [dataItems.map(toDataItem), pagingMetadata];
|
|
701
|
+
});
|
|
702
|
+
const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
|
|
703
|
+
return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
async executeDirectQuery(collectionName, request, options) {
|
|
708
|
+
var _request$paging, _request$cursorPaging, _request$paging2, _request$cursorPaging2, _options$referencedIt;
|
|
709
|
+
const validationErrors = apiValidator().collectionName(collectionName).options(options).validateAndReturn();
|
|
710
|
+
if (validationErrors.length > 0) {
|
|
711
|
+
throw (0, _errors.wdeValidationError)(_errors.messages.queryValidations.queryInvalid(collectionName, validationErrors));
|
|
712
|
+
}
|
|
713
|
+
const limit = ((_request$paging = request.paging) == null ? void 0 : _request$paging.limit) ?? ((_request$cursorPaging = request.cursorPaging) == null ? void 0 : _request$cursorPaging.limit);
|
|
714
|
+
const offset = ((_request$paging2 = request.paging) == null ? void 0 : _request$paging2.offset) ?? 0;
|
|
715
|
+
const cursor = (_request$cursorPaging2 = request.cursorPaging) == null ? void 0 : _request$cursorPaging2.cursor;
|
|
716
|
+
const sort = (request.sort ?? []).map(s => ({
|
|
717
|
+
[s.fieldName]: s.order === 'DESC' ? 'desc' : 'asc'
|
|
718
|
+
}));
|
|
719
|
+
const referencedItemOptions = options == null || (_options$referencedIt = options.referencedItemOptions) == null ? void 0 : _options$referencedIt.map(inc => ({
|
|
720
|
+
fieldName: inc.fieldName,
|
|
721
|
+
limit: inc.limit
|
|
722
|
+
}));
|
|
723
|
+
const fetch = (cursorOrOffset, returnTotalCount) => this.trace('query', {
|
|
724
|
+
collectionName
|
|
725
|
+
})(async env => {
|
|
726
|
+
const {
|
|
727
|
+
dataItems,
|
|
728
|
+
pagingMetadata
|
|
729
|
+
} = await this.client.queryDataItems({
|
|
730
|
+
...env,
|
|
731
|
+
dataCollectionId: collectionName,
|
|
732
|
+
query: {
|
|
733
|
+
fields: request.fields,
|
|
734
|
+
...toPaging(limit, cursorOrOffset),
|
|
735
|
+
...(isOffset(cursorOrOffset) ? {
|
|
736
|
+
filter: request.filter,
|
|
737
|
+
sort: toSort(sort)
|
|
738
|
+
} : {})
|
|
739
|
+
},
|
|
740
|
+
referencedItemOptions,
|
|
741
|
+
...toReadOptions(options),
|
|
742
|
+
...(isOffset(cursorOrOffset) ? {
|
|
743
|
+
returnTotalCount
|
|
744
|
+
} : {})
|
|
745
|
+
});
|
|
746
|
+
return [dataItems.map(toDataItem), pagingMetadata];
|
|
747
|
+
});
|
|
748
|
+
const [items, paging] = await fetch(cursor ?? offset, options == null ? void 0 : options.returnTotalCount);
|
|
749
|
+
return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
|
|
750
|
+
collectionName,
|
|
751
|
+
limitNumber: limit,
|
|
752
|
+
skipNumber: offset
|
|
753
|
+
});
|
|
688
754
|
}
|
|
689
755
|
async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
|
|
690
756
|
const request = {
|