@wix/wix-data-items-common 1.0.289 → 1.0.291

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.
@@ -244,49 +244,6 @@ class WixDataApi {
244
244
  }
245
245
  });
246
246
  });
247
- (0, _defineProperty2.default)(this, "search", collectionName => {
248
- const ensureValidQuery = invalidArgs => {
249
- if (invalidArgs.length > 0) {
250
- throw (0, _errors.wdeValidationError)(_errors.messages.queryValidations.queryInvalid(collectionName, invalidArgs));
251
- }
252
- };
253
- return new _WixDataSearchImpl.WixDataSearchImpl({
254
- collectionName,
255
- onRun: async (params, options) => {
256
- ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).options(options).validateAndReturn()]);
257
- const expression = params.queryText;
258
- const fetch = cursorOrOffset => this.trace('search', {
259
- collectionName,
260
- expression
261
- })(async env => {
262
- const request = {
263
- ...env,
264
- dataCollectionId: collectionName,
265
- search: {
266
- filter: params.filterTree,
267
- sort: toSort(params.orderBy),
268
- fields: params.projectedFields,
269
- search: {
270
- expression: params.queryText,
271
- fuzzy: params.isFuzzy,
272
- mode: params.searchMode
273
- },
274
- ...toPaging(params.limitNumber, cursorOrOffset)
275
- },
276
- includeReferences: params.included,
277
- ...toReadOptions(options)
278
- };
279
- const {
280
- dataItems,
281
- pagingMetadata
282
- } = await this.client.searchDataItems(request);
283
- return [dataItems.map(toDataItem), pagingMetadata];
284
- });
285
- const [items, paging] = await fetch(params.skipNumber);
286
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
287
- }
288
- });
289
- });
290
247
  // NOTE find method is not implemented
291
248
  (0, _defineProperty2.default)(this, "fetch", withArgs(async (args, collectionName, cursor, limit, options) => {
292
249
  await apiValidator().arity('fetch', args, 2, 4).collectionName(collectionName).isNonEmptyString(cursor, 'cursor').validateAndReject();
@@ -313,54 +270,6 @@ class WixDataApi {
313
270
  skipNumber: 0
314
271
  });
315
272
  }));
316
- // --- aggregate ---
317
- (0, _defineProperty2.default)(this, "aggregate", collectionName => {
318
- return new _WixDataAggregateImpl.WixDataAggregateImpl({
319
- collectionName,
320
- onRun: async (args, params, options) => {
321
- const validationErrors = [...params.invalidArguments, ...apiValidator().arity('run', args, 0, 1).collectionName(collectionName).options(options).validateAndReturn()];
322
- if (validationErrors.length > 0) {
323
- throw (0, _errors.wdeValidationError)(_errors.messages.aggregateValidations.aggregateInvalid(collectionName, validationErrors));
324
- }
325
- const fetch = (cursorOrOffset, returnTotalCount) => this.trace('aggregate', {
326
- collectionName
327
- })(async env => {
328
- const toOperation = field => field ? {
329
- itemFieldName: field
330
- } : undefined;
331
- const {
332
- results,
333
- pagingMetadata
334
- } = await this.client.aggregateDataItems({
335
- ...env,
336
- dataCollectionId: collectionName,
337
- ...toPaging(params.limitNumber, cursorOrOffset),
338
- ...toReadOptions(options),
339
- ...(isOffset(cursorOrOffset) ? {
340
- initialFilter: params.filterTree,
341
- aggregation: {
342
- groupingFields: params.groupBy,
343
- operations: params.aggregates.map(a => ({
344
- resultFieldName: a.name,
345
- average: toOperation(a.avg),
346
- min: toOperation(a.min),
347
- max: toOperation(a.max),
348
- sum: toOperation(a.sum),
349
- itemCount: a.count ? {} : undefined
350
- }))
351
- },
352
- finalFilter: params.havingTree,
353
- sort: toSort(params.orderBy),
354
- returnTotalCount
355
- } : {})
356
- });
357
- return [unwrapAggregationId(results), pagingMetadata];
358
- });
359
- const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
360
- return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
361
- }
362
- });
363
- });
364
273
  (0, _defineProperty2.default)(this, "fetchAggregate", withArgs(async (args, collectionName, cursor, limit, options) => {
365
274
  await apiValidator().arity('fetchAggregate', args, 2, 4).collectionName(collectionName).isNonEmptyString(cursor, 'cursor').validateAndReject();
366
275
  const fetch = cursorOrOffset => this.trace('aggregate', {
@@ -821,6 +730,176 @@ class WixDataApi {
821
730
  skipNumber: offset
822
731
  });
823
732
  }
733
+
734
+ /**
735
+ * Returns a search builder for the specified collection.
736
+ * @param collectionName - Name of the collection to search.
737
+ * @returns A `WixDataSearch` builder object.
738
+ */
739
+
740
+ /**
741
+ * Executes a search directly without using the builder pattern.
742
+ * @internal
743
+ * @param collectionName - Name of the collection to search.
744
+ * @param searchRequest - Search parameters including expression, filter, sort, and paging.
745
+ * @param options - Additional options including referencedItemOptions.
746
+ * @returns Promise that resolves to the search results.
747
+ */
748
+
749
+ search(collectionName, searchRequest, options) {
750
+ if (searchRequest !== undefined) {
751
+ return this.executeDirectSearch(collectionName, searchRequest, options);
752
+ }
753
+ const ensureValidQuery = invalidArgs => {
754
+ if (invalidArgs.length > 0) {
755
+ throw (0, _errors.wdeValidationError)(_errors.messages.queryValidations.queryInvalid(collectionName, invalidArgs));
756
+ }
757
+ };
758
+ return new _WixDataSearchImpl.WixDataSearchImpl({
759
+ collectionName,
760
+ onRun: async (params, options) => {
761
+ ensureValidQuery([...params.invalidArguments, ...apiValidator().collectionName(collectionName).options(options).validateAndReturn()]);
762
+ const expression = params.queryText;
763
+ const fetch = cursorOrOffset => this.trace('search', {
764
+ collectionName,
765
+ expression
766
+ })(async env => {
767
+ const request = {
768
+ ...env,
769
+ dataCollectionId: collectionName,
770
+ search: {
771
+ filter: params.filterTree,
772
+ sort: toSort(params.orderBy),
773
+ fields: params.projectedFields,
774
+ search: {
775
+ expression: params.queryText,
776
+ fuzzy: params.isFuzzy,
777
+ mode: params.searchMode
778
+ },
779
+ ...toPaging(params.limitNumber, cursorOrOffset)
780
+ },
781
+ includeReferences: params.included,
782
+ ...toReadOptions(options)
783
+ };
784
+ const {
785
+ dataItems,
786
+ pagingMetadata
787
+ } = await this.client.searchDataItems(request);
788
+ return [dataItems.map(toDataItem), pagingMetadata];
789
+ });
790
+ const [items, paging] = await fetch(params.skipNumber);
791
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
792
+ }
793
+ });
794
+ }
795
+ async executeDirectSearch(collectionName, request, options) {
796
+ var _request$paging3, _request$cursorPaging3, _request$paging4, _request$cursorPaging4, _options$includeRefer2;
797
+ const validationErrors = apiValidator().collectionName(collectionName).options(options).validateAndReturn();
798
+ if (validationErrors.length > 0) {
799
+ throw (0, _errors.wdeValidationError)(_errors.messages.queryValidations.queryInvalid(collectionName, validationErrors));
800
+ }
801
+ const limit = ((_request$paging3 = request.paging) == null ? void 0 : _request$paging3.limit) ?? ((_request$cursorPaging3 = request.cursorPaging) == null ? void 0 : _request$cursorPaging3.limit);
802
+ const offset = ((_request$paging4 = request.paging) == null ? void 0 : _request$paging4.offset) ?? 0;
803
+ const cursor = (_request$cursorPaging4 = request.cursorPaging) == null ? void 0 : _request$cursorPaging4.cursor;
804
+ const includeReferences = options == null || (_options$includeRefer2 = options.includeReferences) == null ? void 0 : _options$includeRefer2.map(inc => ({
805
+ field: inc.field,
806
+ limit: inc.limit
807
+ }));
808
+ const fetch = cursorOrOffset => this.trace('search', {
809
+ collectionName,
810
+ expression: request.expression
811
+ })(async env => {
812
+ var _request$sort;
813
+ const {
814
+ dataItems,
815
+ pagingMetadata
816
+ } = await this.client.searchDataItems({
817
+ ...env,
818
+ dataCollectionId: collectionName,
819
+ search: {
820
+ fields: request.fields,
821
+ filter: request.filter,
822
+ sort: (_request$sort = request.sort) == null ? void 0 : _request$sort.map(s => ({
823
+ fieldName: s.fieldName,
824
+ order: s.order
825
+ })),
826
+ search: {
827
+ expression: request.expression,
828
+ fuzzy: request.fuzzy,
829
+ mode: request.mode
830
+ },
831
+ ...toPaging(limit, cursorOrOffset)
832
+ },
833
+ includeReferences,
834
+ ...toReadOptions(options)
835
+ });
836
+ return [dataItems.map(toDataItem), pagingMetadata];
837
+ });
838
+ const [items, paging] = await fetch(cursor ?? offset);
839
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, {
840
+ collectionName,
841
+ limitNumber: limit,
842
+ skipNumber: offset
843
+ });
844
+ } // --- aggregate ---
845
+ /**
846
+ * Executes an aggregation pipeline directly on a data collection.
847
+ * @internal
848
+ * @param collectionName - Name of the collection to run the aggregation on.
849
+ * @param pipeline - Aggregation pipeline with stages and paging.
850
+ * @param options - Options for running the aggregation.
851
+ * @returns Promise that resolves to the aggregation results.
852
+ */
853
+ aggregate(collectionName, pipeline, options) {
854
+ if (pipeline !== undefined) {
855
+ return this.aggregatePipeline(collectionName, pipeline, options);
856
+ }
857
+ return new _WixDataAggregateImpl.WixDataAggregateImpl({
858
+ collectionName,
859
+ onRun: async (args, params, options) => {
860
+ const validationErrors = [...params.invalidArguments, ...apiValidator().arity('run', args, 0, 1).collectionName(collectionName).options(options).validateAndReturn()];
861
+ if (validationErrors.length > 0) {
862
+ throw (0, _errors.wdeValidationError)(_errors.messages.aggregateValidations.aggregateInvalid(collectionName, validationErrors));
863
+ }
864
+ const fetch = (cursorOrOffset, returnTotalCount) => this.trace('aggregate', {
865
+ collectionName
866
+ })(async env => {
867
+ const toOperation = field => field ? {
868
+ itemFieldName: field
869
+ } : undefined;
870
+ const {
871
+ results,
872
+ pagingMetadata
873
+ } = await this.client.aggregateDataItems({
874
+ ...env,
875
+ dataCollectionId: collectionName,
876
+ ...toPaging(params.limitNumber, cursorOrOffset),
877
+ ...toReadOptions(options),
878
+ ...(isOffset(cursorOrOffset) ? {
879
+ initialFilter: params.filterTree,
880
+ aggregation: {
881
+ groupingFields: params.groupBy,
882
+ operations: params.aggregates.map(a => ({
883
+ resultFieldName: a.name,
884
+ average: toOperation(a.avg),
885
+ min: toOperation(a.min),
886
+ max: toOperation(a.max),
887
+ sum: toOperation(a.sum),
888
+ itemCount: a.count ? {} : undefined
889
+ }))
890
+ },
891
+ finalFilter: params.havingTree,
892
+ sort: toSort(params.orderBy),
893
+ returnTotalCount
894
+ } : {})
895
+ });
896
+ return [unwrapAggregationId(results), pagingMetadata];
897
+ });
898
+ const [items, paging] = await fetch(params.skipNumber, options == null ? void 0 : options.returnTotalCount);
899
+ return new _WixDataResultImpl.WixDataResultImpl(items, paging, fetch, params);
900
+ }
901
+ });
902
+ }
824
903
  async runBulkSave(env, collectionName, items, options, overrideExisting = true) {
825
904
  const request = {
826
905
  ...env,