@xata.io/client 0.1.3 → 0.1.4

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
@@ -23,8 +23,11 @@ export declare type Include<T> = {
23
23
  [key in keyof T as T[key] extends XataRecord ? key : never]?: boolean | Array<keyof Selectable<T[key]>>;
24
24
  };
25
25
  declare type SortDirection = 'asc' | 'desc';
26
- declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
26
+ declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
27
27
  declare type Constraint<T> = Partial<Record<Operator, T>>;
28
+ declare type DeepConstraint<T> = T extends Record<string, any> ? {
29
+ [key in keyof T]?: T[key] | DeepConstraint<T[key]>;
30
+ } : Constraint<T>;
28
31
  declare type ComparableType = number | Date;
29
32
  export declare const gt: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
30
33
  export declare const ge: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>;
@@ -37,6 +40,7 @@ export declare const notExists: (column: string) => Constraint<string>;
37
40
  export declare const startsWith: (value: string) => Constraint<string>;
38
41
  export declare const endsWith: (value: string) => Constraint<string>;
39
42
  export declare const pattern: (value: string) => Constraint<string>;
43
+ export declare const is: <T>(value: T) => Partial<Record<Operator, T>>;
40
44
  export declare const isNot: <T>(value: T) => Partial<Record<Operator, T>>;
41
45
  export declare const contains: <T>(value: T) => Partial<Record<Operator, T>>;
42
46
  export declare const includes: (value: string) => Constraint<string>;
@@ -44,7 +48,7 @@ export declare const includesSubstring: (value: string) => Constraint<string>;
44
48
  export declare const includesPattern: (value: string) => Constraint<string>;
45
49
  export declare const includesAll: (value: string) => Constraint<string>;
46
50
  declare type FilterConstraints<T> = {
47
- [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | Constraint<T[key]>;
51
+ [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
48
52
  };
49
53
  declare type BulkQueryOptions<T> = {
50
54
  filter?: FilterConstraints<T>;
@@ -68,7 +72,7 @@ export declare class Query<T, R = T> {
68
72
  not(...queries: Query<T, R>[]): Query<T, R>;
69
73
  none(...queries: Query<T, R>[]): Query<T, R>;
70
74
  filter(constraints: FilterConstraints<T>): Query<T, R>;
71
- filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | Constraint<T[F]>): Query<T, R>;
75
+ filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
72
76
  sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>;
73
77
  getMany(options?: BulkQueryOptions<T>): Promise<R[]>;
74
78
  getOne(options?: BulkQueryOptions<T>): Promise<R | null>;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.Query = exports.includesAll = exports.includesPattern = exports.includesSubstring = exports.includes = exports.contains = exports.isNot = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
12
+ exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.Query = exports.includesAll = exports.includesPattern = exports.includesSubstring = exports.includes = exports.contains = exports.isNot = exports.is = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
13
13
  const gt = (value) => ({ $gt: value });
14
14
  exports.gt = gt;
15
15
  const ge = (value) => ({ $ge: value });
@@ -32,14 +32,11 @@ const endsWith = (value) => ({ $endsWith: value });
32
32
  exports.endsWith = endsWith;
33
33
  const pattern = (value) => ({ $pattern: value });
34
34
  exports.pattern = pattern;
35
+ const is = (value) => ({ $is: value });
36
+ exports.is = is;
35
37
  const isNot = (value) => ({ $isNot: value });
36
38
  exports.isNot = isNot;
37
- const contains = (value) => {
38
- // if (Array.isArray(value)) {
39
- // return { $all: value.map(item => ({ $contains: item as string })) }
40
- // }
41
- return { $contains: value };
42
- };
39
+ const contains = (value) => ({ $contains: value });
43
40
  exports.contains = contains;
44
41
  // TODO: these can only be applied to columns of type "multiple"
45
42
  const includes = (value) => ({ $includes: value });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -43,6 +43,7 @@ type Operator =
43
43
  | '$endsWith'
44
44
  | '$startsWith'
45
45
  | '$pattern'
46
+ | '$is'
46
47
  | '$isNot'
47
48
  | '$contains'
48
49
  | '$includes'
@@ -52,7 +53,13 @@ type Operator =
52
53
 
53
54
  // TODO: restrict constraints depending on type?
54
55
  // E.g. startsWith cannot be used with numbers
55
- type Constraint<T> = Partial<Record<Operator, T>>; // | {$all: Record<'$contains', string>[]};
56
+ type Constraint<T> = Partial<Record<Operator, T>>;
57
+
58
+ type DeepConstraint<T> = T extends Record<string, any>
59
+ ? {
60
+ [key in keyof T]?: T[key] | DeepConstraint<T[key]>;
61
+ }
62
+ : Constraint<T>;
56
63
 
57
64
  type ComparableType = number | Date;
58
65
 
@@ -67,13 +74,9 @@ export const notExists = (column: string): Constraint<string> => ({ $notExists:
67
74
  export const startsWith = (value: string): Constraint<string> => ({ $startsWith: value });
68
75
  export const endsWith = (value: string): Constraint<string> => ({ $endsWith: value });
69
76
  export const pattern = (value: string): Constraint<string> => ({ $pattern: value });
77
+ export const is = <T>(value: T): Constraint<T> => ({ $is: value });
70
78
  export const isNot = <T>(value: T): Constraint<T> => ({ $isNot: value });
71
- export const contains = <T>(value: T): Constraint<T> => {
72
- // if (Array.isArray(value)) {
73
- // return { $all: value.map(item => ({ $contains: item as string })) }
74
- // }
75
- return { $contains: value };
76
- };
79
+ export const contains = <T>(value: T): Constraint<T> => ({ $contains: value });
77
80
 
78
81
  // TODO: these can only be applied to columns of type "multiple"
79
82
  export const includes = (value: string): Constraint<string> => ({ $includes: value });
@@ -82,7 +85,7 @@ export const includesPattern = (value: string): Constraint<string> => ({ $includ
82
85
  export const includesAll = (value: string): Constraint<string> => ({ $includesAll: value });
83
86
 
84
87
  type FilterConstraints<T> = {
85
- [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | Constraint<T[key]>;
88
+ [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
86
89
  };
87
90
 
88
91
  type BulkQueryOptions<T> = {
@@ -182,7 +185,7 @@ export class Query<T, R = T> {
182
185
  }
183
186
 
184
187
  filter(constraints: FilterConstraints<T>): Query<T, R>;
185
- filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | Constraint<T[F]>): Query<T, R>;
188
+ filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>;
186
189
  filter(a: any, b?: any): Query<T, R> {
187
190
  if (arguments.length === 1) {
188
191
  const constraints = a as FilterConstraints<T>;