@wix/wix-data-items-common 1.0.290 → 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();
@@ -774,8 +731,117 @@ class WixDataApi {
774
731
  });
775
732
  }
776
733
 
777
- // --- aggregate ---
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
+ */
778
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 ---
779
845
  /**
780
846
  * Executes an aggregation pipeline directly on a data collection.
781
847
  * @internal
@@ -784,7 +850,6 @@ class WixDataApi {
784
850
  * @param options - Options for running the aggregation.
785
851
  * @returns Promise that resolves to the aggregation results.
786
852
  */
787
-
788
853
  aggregate(collectionName, pipeline, options) {
789
854
  if (pipeline !== undefined) {
790
855
  return this.aggregatePipeline(collectionName, pipeline, options);