@xata.io/client 0.0.0-alpha.vfde9dcf → 0.0.0-alpha.vfee45b2

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/index.d.ts CHANGED
@@ -292,6 +292,10 @@ declare type FilterExpression = {
292
292
  } & {
293
293
  [key: string]: FilterColumn;
294
294
  };
295
+ declare type HighlightExpression = {
296
+ enabled?: boolean;
297
+ encodeHTML?: boolean;
298
+ };
295
299
  declare type FilterList = FilterExpression | FilterExpression[];
296
300
  declare type FilterColumn = FilterColumnIncludes | FilterPredicate | FilterList;
297
301
  /**
@@ -377,6 +381,11 @@ declare type XataRecord$1 = {
377
381
  xata: {
378
382
  version: number;
379
383
  table?: string;
384
+ highlight?: {
385
+ [key: string]: string[] | {
386
+ [key: string]: any;
387
+ };
388
+ };
380
389
  warnings?: string[];
381
390
  };
382
391
  } & {
@@ -422,6 +431,7 @@ type schemas_SortExpression = SortExpression;
422
431
  type schemas_SortOrder = SortOrder;
423
432
  type schemas_FuzzinessExpression = FuzzinessExpression;
424
433
  type schemas_FilterExpression = FilterExpression;
434
+ type schemas_HighlightExpression = HighlightExpression;
425
435
  type schemas_FilterList = FilterList;
426
436
  type schemas_FilterColumn = FilterColumn;
427
437
  type schemas_FilterColumnIncludes = FilterColumnIncludes;
@@ -476,6 +486,7 @@ declare namespace schemas {
476
486
  schemas_SortOrder as SortOrder,
477
487
  schemas_FuzzinessExpression as FuzzinessExpression,
478
488
  schemas_FilterExpression as FilterExpression,
489
+ schemas_HighlightExpression as HighlightExpression,
479
490
  schemas_FilterList as FilterList,
480
491
  schemas_FilterColumn as FilterColumn,
481
492
  schemas_FilterColumnIncludes as FilterColumnIncludes,
@@ -2612,6 +2623,7 @@ declare type SearchTableRequestBody = {
2612
2623
  query: string;
2613
2624
  fuzziness?: FuzzinessExpression;
2614
2625
  filter?: FilterExpression;
2626
+ highlight?: HighlightExpression;
2615
2627
  };
2616
2628
  declare type SearchTableVariables = {
2617
2629
  body: SearchTableRequestBody;
@@ -2640,9 +2652,13 @@ declare type SearchBranchError = ErrorWrapper<{
2640
2652
  payload: SimpleError;
2641
2653
  }>;
2642
2654
  declare type SearchBranchRequestBody = {
2643
- tables?: string[];
2655
+ tables?: (string | {
2656
+ table: string;
2657
+ filter?: FilterExpression;
2658
+ })[];
2644
2659
  query: string;
2645
2660
  fuzziness?: FuzzinessExpression;
2661
+ highlight?: HighlightExpression;
2646
2662
  };
2647
2663
  declare type SearchBranchVariables = {
2648
2664
  body: SearchBranchRequestBody;
@@ -2851,9 +2867,9 @@ declare type SelectableColumn<O, RecursivePath extends any[] = []> = '*' | 'id'
2851
2867
  declare type SelectedPick<O extends XataRecord, Key extends SelectableColumn<O>[]> = XataRecord & UnionToIntersection<Values<{
2852
2868
  [K in Key[number]]: NestedValueAtColumn<O, K> & XataRecord;
2853
2869
  }>>;
2854
- declare type ValueAtColumn<O, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<O[K] extends XataRecord ? (V extends SelectableColumn<O[K]> ? {
2855
- V: ValueAtColumn<O[K], V>;
2856
- } : never) : O[K]> : never : never;
2870
+ declare type ValueAtColumn<O, P extends SelectableColumn<O>> = P extends '*' ? Values<O> : P extends 'id' ? string : P extends keyof O ? O[P] : P extends `${infer K}.${infer V}` ? K extends keyof O ? Values<NonNullable<O[K]> extends Record<string, any> ? V extends SelectableColumn<NonNullable<O[K]>> ? {
2871
+ V: ValueAtColumn<NonNullable<O[K]>, V>;
2872
+ } : never : O[K]> : never : never;
2857
2873
  declare type MAX_RECURSION = 5;
2858
2874
  declare type NestedColumns<O, RecursivePath extends any[]> = RecursivePath['length'] extends MAX_RECURSION ? never : If<IsObject<O>, Values<{
2859
2875
  [K in DataProps<O>]: If<IsArray<NonNullable<O[K]>>, K, // If the property is an array, we stop recursion. We don't support object arrays yet
@@ -3009,8 +3025,8 @@ declare type ValueTypeFilters<T> = T | T extends string ? StringTypeFilter : T e
3009
3025
  ],
3010
3026
  }
3011
3027
  */
3012
- declare type AggregatorFilter<Record> = {
3013
- [key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<Filter<Record>>;
3028
+ declare type AggregatorFilter<T> = {
3029
+ [key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<Filter<T>>;
3014
3030
  };
3015
3031
  /**
3016
3032
  * Existance filter
@@ -3025,10 +3041,10 @@ declare type BaseApiFilter<Record> = PropertyAccessFilter<Record> | AggregatorFi
3025
3041
  * Injects the Api filters on nested properties
3026
3042
  * Example: { filter: { settings: { plan: { $any: ['free', 'trial'] } } } }
3027
3043
  */
3028
- declare type NestedApiFilter<T> = T extends Record<string, any> ? {
3044
+ declare type NestedApiFilter<T> = {
3029
3045
  [key in keyof T]?: T[key] extends Record<string, any> ? SingleOrArray<Filter<T[key]>> : PropertyFilter<T[key]>;
3030
- } : PropertyFilter<T>;
3031
- declare type Filter<Record> = BaseApiFilter<Record> | NestedApiFilter<Record>;
3046
+ };
3047
+ declare type Filter<T> = T extends Record<string, any> ? BaseApiFilter<T> | NestedApiFilter<T> : PropertyFilter<T>;
3032
3048
 
3033
3049
  declare type SortDirection = 'asc' | 'desc';
3034
3050
  declare type SortFilterExtended<T extends XataRecord> = {
@@ -3065,7 +3081,7 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
3065
3081
  #private;
3066
3082
  readonly meta: PaginationQueryMeta;
3067
3083
  readonly records: Result[];
3068
- constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>, parent?: Partial<QueryOptions<Record>>);
3084
+ constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>, rawParent?: Partial<QueryOptions<Record>>);
3069
3085
  getQueryOptions(): QueryOptions<Record>;
3070
3086
  key(): string;
3071
3087
  /**
@@ -3107,8 +3123,8 @@ declare class Query<Record extends XataRecord, Result extends XataRecord = Recor
3107
3123
  *
3108
3124
  * @returns A new Query object.
3109
3125
  */
3110
- filter(filters: Filter<Record>): Query<Record, Result>;
3111
3126
  filter<F extends SelectableColumn<Record>>(column: F, value: Filter<ValueAtColumn<Record, F>>): Query<Record, Result>;
3127
+ filter(filters: Filter<Record>): Query<Record, Result>;
3112
3128
  /**
3113
3129
  * Builds a new query with a new sort option.
3114
3130
  * @param column The column name.
package/dist/index.mjs CHANGED
@@ -73,7 +73,12 @@ function getFetchImplementation(userFetch) {
73
73
  return fetchImpl;
74
74
  }
75
75
 
76
- class FetcherError extends Error {
76
+ class ErrorWithCause extends Error {
77
+ constructor(message, options) {
78
+ super(message, options);
79
+ }
80
+ }
81
+ class FetcherError extends ErrorWithCause {
77
82
  constructor(status, data) {
78
83
  super(getMessage(data));
79
84
  this.status = status;
@@ -990,7 +995,7 @@ var __privateSet$4 = (obj, member, value, setter) => {
990
995
  };
991
996
  var _table$1, _repository, _data;
992
997
  const _Query = class {
993
- constructor(repository, table, data, parent) {
998
+ constructor(repository, table, data, rawParent) {
994
999
  __privateAdd$5(this, _table$1, void 0);
995
1000
  __privateAdd$5(this, _repository, void 0);
996
1001
  __privateAdd$5(this, _data, { filter: {} });
@@ -1002,6 +1007,7 @@ const _Query = class {
1002
1007
  } else {
1003
1008
  __privateSet$4(this, _repository, this);
1004
1009
  }
1010
+ const parent = cleanParent(data, rawParent);
1005
1011
  __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1006
1012
  __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1007
1013
  __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
@@ -1121,6 +1127,12 @@ let Query = _Query;
1121
1127
  _table$1 = new WeakMap();
1122
1128
  _repository = new WeakMap();
1123
1129
  _data = new WeakMap();
1130
+ function cleanParent(data, parent) {
1131
+ if (isCursorPaginationOptions(data.pagination)) {
1132
+ return { ...parent, sorting: void 0, filter: void 0 };
1133
+ }
1134
+ return parent;
1135
+ }
1124
1136
 
1125
1137
  function isIdentifiable(x) {
1126
1138
  return isObject(x) && isString(x?.id);
@@ -1328,12 +1340,9 @@ class RestRepository extends Query {
1328
1340
  if (cacheQuery)
1329
1341
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1330
1342
  const data = query.getQueryOptions();
1331
- const filter = Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0;
1332
- const sort = data.sort !== void 0 ? buildSortFilter(data.sort) : void 0;
1333
- const isCursorPagination = isCursorPaginationOptions(data.pagination);
1334
1343
  const body = {
1335
- filter: isCursorPagination ? void 0 : filter,
1336
- sort: isCursorPagination ? void 0 : sort,
1344
+ filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1345
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1337
1346
  page: data.pagination,
1338
1347
  columns: data.columns
1339
1348
  };