@travetto/model
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -23,3 +23,3 @@ { | ||
}, | ||
"version": "0.0.14" | ||
"version": "0.0.15" | ||
} |
import { ModelCore } from '../model'; | ||
import { Class } from '@travetto/registry'; | ||
export type Point = [number, number]; | ||
export type FieldType = string | number | Date | Point | boolean | ModelCore; | ||
export type Primitive = number | boolean | string | Date | Point; | ||
export type PrimitiveArray = Primitive[]; | ||
export type ValidFieldNames<T> = { [K in keyof T]: T[K] extends FieldType ? K : never }[keyof T]; | ||
export type FieldType = Primitive | object; | ||
export type ValidFieldNames<T> = { [K in keyof T]: T[K] extends Function ? never : (T[K] extends FieldType ? K : never) }[keyof T]; | ||
const HIDDEN = Symbol('hidden') | ||
export type RetainFields<T> = T extends { [HIDDEN]?: any } ? T : (Pick<T, ValidFieldNames<T>> & { [HIDDEN]?: any }); |
import { Class } from '@travetto/registry'; | ||
import { WhereClause } from './where'; | ||
import { RetainFields } from './common'; | ||
import { RetainFields, Point, PrimitiveArray, Primitive } from './common'; | ||
@@ -8,11 +8,20 @@ type SelectFieldFn = 'max' | 'min' | 'avg' | 'sum' | 'count'; | ||
type _SelectClause<T> = { | ||
[P in keyof T]?: T[P] extends object ? _SelectClause<T[P]> : { alias: string, calc: SelectFieldFn } | 1 | 0 | boolean; | ||
[P in keyof T]?: | ||
T[P] extends (Primitive | PrimitiveArray) ? | ||
{ alias: string, calc: SelectFieldFn } | 1 | 0 | boolean : | ||
(T[P] extends object ? _SelectClause<T[P]> : never); | ||
}; | ||
type _GroupClause<T> = { | ||
[P in keyof T]?: T[P] extends object ? _GroupClause<T[P]> : (1 | 0 | boolean) | ||
[P in keyof T]?: | ||
T[P] extends Primitive ? | ||
(1 | 0 | boolean) : | ||
(T[P] extends object ? _GroupClause<T[P]> : never); | ||
}; | ||
type _SortClause<T> = { | ||
[P in keyof T]?: T[P] extends object ? _SortClause<T[P]> : (boolean | 1 | -1); | ||
[P in keyof T]?: | ||
T[P] extends Primitive ? ( | ||
boolean | 1 | -1) : | ||
(T[P] extends object ? _SortClause<T[P]> : never); | ||
} | ||
@@ -19,0 +28,0 @@ |
@@ -50,3 +50,3 @@ import { RetainFields, Point, FieldType } from './common'; | ||
type _MatchQuery<T> = { | ||
[P in keyof T]?: T[P] extends (Date | number | string | any[] | Point | Function) ? FieldQuery<T[P]> : _MatchQuery<T[P]> | ||
[P in keyof T]?: T[P] extends (Date | number | string | (infer U)[] | Point | Function) ? FieldQuery<T[P]> : _MatchQuery<T[P]> | ||
} & { $and?: never, $or?: never, $not?: never }; | ||
@@ -53,0 +53,0 @@ |
@@ -1,1 +0,1 @@ | ||
export * from './query'; | ||
export * from './verify'; |
@@ -23,3 +23,3 @@ import { Class, ChangeEvent } from '@travetto/registry'; | ||
abstract query<T extends ModelCore, U = any>(cls: Class<T>, builder: Query<T>): Promise<U[]>; | ||
abstract query<T extends ModelCore, U = T>(cls: Class<T>, builder: Query<T>): U[]; | ||
@@ -26,0 +26,0 @@ abstract bulkProcess<T extends ModelCore>(cls: Class<T>, state: BulkState<T>): Promise<BulkResponse>; |
@@ -18,17 +18,18 @@ import { SchemaBound, View } from '@travetto/schema'; | ||
sort: [{ | ||
address: { | ||
street1: -1 | ||
} | ||
age: 1, | ||
}], | ||
where: { | ||
name: '5', | ||
names: ['1', '2'], | ||
dob: { | ||
$gte: new Date() | ||
}, | ||
address: { | ||
street2: { | ||
$eq: '5' | ||
$and: [{ | ||
name: '5', | ||
names: ['1', '2'], | ||
dob: { | ||
$gte: new Date() | ||
}, | ||
address: { | ||
street2: { | ||
$eq: '5' | ||
} | ||
} | ||
} | ||
}] | ||
} | ||
@@ -70,8 +71,9 @@ } | ||
where: { | ||
/*name: '5', | ||
dob: { | ||
$eq: new Date() | ||
}*/ | ||
$and: [{ | ||
name: '6', | ||
name: '5', | ||
dob: { | ||
$eq: new Date() | ||
} | ||
}, { | ||
name: '8', | ||
address: { | ||
@@ -78,0 +80,0 @@ street1: { |
import { Model, BaseModel, WhereClause, ModelService } from '../index'; | ||
import { Schema } from '@travetto/schema'; | ||
@Model() | ||
export class Address extends BaseModel { | ||
@Schema() | ||
export class Address { | ||
street1: string; | ||
@@ -6,0 +7,0 @@ street2: string; |
35661
897