@ez4/database 0.12.0 → 0.14.0

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.
@@ -42,11 +42,11 @@ export declare namespace Database {
42
42
  */
43
43
  handler: (change: StreamChange<T>, context: Service.Context<Service<any>>) => void | Promise<void>;
44
44
  /**
45
- * Variables associated to the route.
45
+ * Variables associated to the handler.
46
46
  */
47
47
  variables?: LinkedVariables;
48
48
  /**
49
- * Max route execution time (in seconds) for the handler.
49
+ * Max execution time (in seconds) for the handler.
50
50
  */
51
51
  timeout?: number;
52
52
  /**
@@ -2,7 +2,7 @@ import type { RelationMetadata } from './relations.js';
2
2
  import type { Database } from './database.js';
3
3
  import type { Order } from './order.js';
4
4
  import type { DecomposeIndexName, DecomposePrimaryIndexNames, DecomposeUniqueIndexNames } from './indexes.js';
5
- import type { AnyObject, PartialProperties, PartialObject, FlatObject, OptionalObject, StrictObject, IsNullable, IsObjectEmpty, IsObject } from '@ez4/utils';
5
+ import type { AnyObject, PartialProperties, PartialObject, FlatObject, OptionalObject, StrictObject, IsNullable, IsObjectEmpty, IsObject, IsArray } from '@ez4/utils';
6
6
  /**
7
7
  * Query builder types.
8
8
  */
@@ -57,6 +57,9 @@ export declare namespace Query {
57
57
  where?: WhereInput<T, {}, R>;
58
58
  limit?: number;
59
59
  };
60
+ export type CountInput<T extends Database.Schema, R extends RelationMetadata> = {
61
+ where?: WhereInput<T, {}, R>;
62
+ };
60
63
  export type InsertOneResult = void;
61
64
  export type UpdateOneResult<T extends Database.Schema, S extends AnyObject, R extends RelationMetadata> = Record<T, S, R> | undefined;
62
65
  export type FindOneResult<T extends Database.Schema, S extends AnyObject, R extends RelationMetadata> = Record<T, S, R> | undefined;
@@ -79,13 +82,13 @@ export declare namespace Query {
79
82
  [P in DecomposeIndexName<keyof I>]?: Order;
80
83
  };
81
84
  export type WhereInput<T extends Database.Schema, I extends Database.Indexes<T>, R extends RelationMetadata> = WhereInputFilters<T, I, R> & WhereNot<WhereInputFilters<T, I, R>> & WhereAnd<WhereInputFilters<T, I, R>> & WhereOr<WhereInputFilters<T, I, R>>;
82
- export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains);
85
+ export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith & WhereContains<any>);
83
86
  type IndexFields<R extends RelationMetadata> = string extends R['indexes'] ? never : R['indexes'];
84
87
  type SelectFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['selects']> extends true ? T : T & R['selects'];
85
88
  type IncludeFilters<T extends AnyObject, S extends AnyObject> = {
86
89
  [P in keyof T]?: P extends keyof S ? IsObject<T[P]> extends true ? null | WhereRelationField<NonNullable<T[P]>> : never : never;
87
90
  };
88
- type WhereOperations<T> = WhereNegate<T> | WhereEqual<T> | WhereGreaterThan<T> | WhereGreaterThanOrEqual<T> | WhereLessThan<T> | WhereLessThanOrEqual<T> | WhereIn<T> | WhereBetween<T> | WhereIsMissing | WhereIsNull | WhereStartsWith | WhereContains;
91
+ type WhereOperations<T> = WhereNegate<T> | WhereEqual<T> | WhereGreaterThan<T> | WhereGreaterThanOrEqual<T> | WhereLessThan<T> | WhereLessThanOrEqual<T> | WhereIn<T> | WhereBetween<T> | WhereIsMissing | WhereIsNull | WhereStartsWith | WhereContains<T>;
89
92
  type WhereField<T> = IsObject<T> extends false ? T | WhereOperations<T> : IsNullable<T> extends true ? null | WhereObjectField<NonNullable<T>> : WhereObjectField<NonNullable<T>>;
90
93
  type WhereObjectField<T extends AnyObject> = {
91
94
  [P in keyof T]?: WhereField<T[P]>;
@@ -130,7 +133,7 @@ export declare namespace Query {
130
133
  lte: T;
131
134
  };
132
135
  type WhereIn<T> = {
133
- isIn: T[];
136
+ isIn: IsArray<T> extends true ? T : IsObject<T> extends true ? T : T[];
134
137
  };
135
138
  type WhereBetween<T> = {
136
139
  isBetween: [T, T];
@@ -144,8 +147,8 @@ export declare namespace Query {
144
147
  type WhereStartsWith = {
145
148
  startsWith: string;
146
149
  };
147
- type WhereContains = {
148
- contains: string;
150
+ type WhereContains<T> = {
151
+ contains: IsObject<T> extends true ? Partial<T> : T;
149
152
  };
150
153
  export {};
151
154
  }
@@ -82,4 +82,10 @@ export interface Table<T extends Database.Schema, I extends Database.Indexes<T>,
82
82
  * @param query Input query.
83
83
  */
84
84
  deleteMany<S extends Query.SelectInput<T, R>>(query: Query.DeleteManyInput<T, S, R>): Promise<Query.DeleteManyResult<T, S, R>>;
85
+ /**
86
+ * Count database records.
87
+ *
88
+ * @param query Input query.
89
+ */
90
+ count(query: Query.CountInput<T, R>): Promise<number>;
85
91
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ez4/database",
3
3
  "description": "EZ4: Components to build database services",
4
- "version": "0.12.0",
4
+ "version": "0.14.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -42,10 +42,10 @@
42
42
  "live:publish": "npm run test && npm publish --access public"
43
43
  },
44
44
  "dependencies": {
45
- "@ez4/common": "^0.12.0",
46
- "@ez4/project": "^0.12.0",
47
- "@ez4/reflection": "^0.12.0",
48
- "@ez4/schema": "^0.12.0",
49
- "@ez4/utils": "^0.12.0"
45
+ "@ez4/common": "^0.14.0",
46
+ "@ez4/project": "^0.14.0",
47
+ "@ez4/reflection": "^0.14.0",
48
+ "@ez4/schema": "^0.14.0",
49
+ "@ez4/utils": "^0.14.0"
50
50
  }
51
51
  }