@xata.io/client
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -26,4 +26,7 @@ export interface XataRecord { | ||
declare type SortDirection = 'asc' | 'desc'; | ||
declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll'; | ||
declare type Operator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll'; | ||
declare type Constraint<T> = Partial<Record<Operator, T>>; | ||
declare type DeepConstraint<T> = T extends Record<string, any> ? { | ||
[key in keyof T]?: T[key] | DeepConstraint<T[key]>; | ||
} : Constraint<T>; | ||
declare type ComparableType = number | Date; | ||
@@ -41,2 +44,3 @@ export declare const gt: <T extends ComparableType>(value: T) => Partial<Record<Operator, T>>; | ||
export declare const pattern: (value: string) => Constraint<string>; | ||
export declare const is: <T>(value: T) => Partial<Record<Operator, T>>; | ||
export declare const isNot: <T>(value: T) => Partial<Record<Operator, T>>; | ||
@@ -49,3 +53,3 @@ export declare const contains: <T>(value: T) => Partial<Record<Operator, T>>; | ||
declare type FilterConstraints<T> = { | ||
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | Constraint<T[key]>; | ||
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>; | ||
}; | ||
@@ -74,3 +78,3 @@ declare type BulkQueryOptions<T> = { | ||
filter(constraints: FilterConstraints<T>): Query<T, R>; | ||
filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | Constraint<T[F]>): Query<T, R>; | ||
filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>; | ||
sort<F extends keyof T>(column: F, direction: SortDirection): Query<T, R>; | ||
@@ -77,0 +81,0 @@ getMany(options?: BulkQueryOptions<T>): Promise<R[]>; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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; | ||
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; | ||
const gt = (value) => ({ $gt: value }); | ||
@@ -36,10 +36,7 @@ exports.gt = gt; | ||
exports.pattern = pattern; | ||
const is = (value) => ({ $is: value }); | ||
exports.is = is; | ||
const isNot = (value) => ({ $isNot: value }); | ||
exports.isNot = isNot; | ||
const contains = (value) => { | ||
// if (Array.isArray(value)) { | ||
// return { $all: value.map(item => ({ $contains: item as string })) } | ||
// } | ||
return { $contains: value }; | ||
}; | ||
const contains = (value) => ({ $contains: value }); | ||
exports.contains = contains; | ||
@@ -46,0 +43,0 @@ // TODO: these can only be applied to columns of type "multiple" |
{ | ||
"name": "@xata.io/client", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Xata.io SDK for TypeScript and JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -46,2 +46,3 @@ export interface XataRecord { | ||
| '$pattern' | ||
| '$is' | ||
| '$isNot' | ||
@@ -56,4 +57,10 @@ | '$contains' | ||
// E.g. startsWith cannot be used with numbers | ||
type Constraint<T> = Partial<Record<Operator, T>>; // | {$all: Record<'$contains', string>[]}; | ||
type Constraint<T> = Partial<Record<Operator, T>>; | ||
type DeepConstraint<T> = T extends Record<string, any> | ||
? { | ||
[key in keyof T]?: T[key] | DeepConstraint<T[key]>; | ||
} | ||
: Constraint<T>; | ||
type ComparableType = number | Date; | ||
@@ -72,9 +79,5 @@ | ||
export const pattern = (value: string): Constraint<string> => ({ $pattern: value }); | ||
export const is = <T>(value: T): Constraint<T> => ({ $is: value }); | ||
export const isNot = <T>(value: T): Constraint<T> => ({ $isNot: value }); | ||
export const contains = <T>(value: T): Constraint<T> => { | ||
// if (Array.isArray(value)) { | ||
// return { $all: value.map(item => ({ $contains: item as string })) } | ||
// } | ||
return { $contains: value }; | ||
}; | ||
export const contains = <T>(value: T): Constraint<T> => ({ $contains: value }); | ||
@@ -88,3 +91,3 @@ // TODO: these can only be applied to columns of type "multiple" | ||
type FilterConstraints<T> = { | ||
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | Constraint<T[key]>; | ||
[key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>; | ||
}; | ||
@@ -189,3 +192,3 @@ | ||
filter(constraints: FilterConstraints<T>): Query<T, R>; | ||
filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | Constraint<T[F]>): Query<T, R>; | ||
filter<F extends keyof T>(column: F, value: FilterConstraints<T[F]> | DeepConstraint<T[F]>): Query<T, R>; | ||
filter(a: any, b?: any): Query<T, R> { | ||
@@ -192,0 +195,0 @@ if (arguments.length === 1) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48737
1260