@ez4/database 0.25.0 → 0.27.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.
@@ -1,6 +1,6 @@
1
- import type { DecomposeIndexName } from './indexes.js';
2
- import type { TableMetadata } from './table.js';
3
- import type { Database } from './database.js';
1
+ import type { DecomposeIndexName } from './indexes';
2
+ import type { TableMetadata } from './table';
3
+ import type { Database } from './database';
4
4
  /**
5
5
  * Query order types.
6
6
  */
@@ -16,9 +16,9 @@ export declare const enum OrderMode {
16
16
  AnyColumns = "any"
17
17
  }
18
18
  /**
19
- * Order utils.
19
+ * Order mode utils.
20
20
  */
21
- export declare namespace OrderUtils {
21
+ export declare namespace OrderModeUtils {
22
22
  /**
23
23
  * Order input for index columns.
24
24
  */
@@ -1,4 +1,4 @@
1
- import type { DatabaseEngine, EngineUtils } from './engine.js';
1
+ import type { DatabaseEngine, EngineUtils } from './engine';
2
2
  /**
3
3
  * Pagination mode.
4
4
  */
@@ -7,9 +7,9 @@ export declare const enum PaginationMode {
7
7
  Offset = "offset"
8
8
  }
9
9
  /**
10
- * Pagination utils.
10
+ * Pagination mode utils.
11
11
  */
12
- export declare namespace PaginationUtils {
12
+ export declare namespace PaginationModeUtils {
13
13
  /**
14
14
  * Get the pagination range based on the given database engine.
15
15
  */
@@ -1,5 +1,5 @@
1
- import type { EngineUtils } from './engine.js';
2
- import type { Database } from './database.js';
1
+ import type { EngineUtils } from './engine';
2
+ import type { Database } from './database';
3
3
  /**
4
4
  * Parameters mode.
5
5
  */
@@ -8,9 +8,9 @@ export declare const enum ParametersMode {
8
8
  OnlyIndex = "index"
9
9
  }
10
10
  /**
11
- * Parameters utils.
11
+ * Parameters mode utils.
12
12
  */
13
- export declare namespace ParametersUtils {
13
+ export declare namespace ParametersModeUtils {
14
14
  /**
15
15
  * Get the parameters type based on the given database service.
16
16
  */
@@ -1,11 +1,12 @@
1
- import type { DecomposeIndexName, PrimaryIndexes, UniqueIndexes } from './indexes.js';
2
- import type { DatabaseEngine } from './engine.js';
3
- import type { RelationMetadata } from './relations.js';
4
- import type { InsensitiveUtils } from './insensitive.js';
5
- import type { PaginationUtils } from './pagination.js';
6
- import type { TableMetadata } from './table.js';
7
- import type { OrderUtils } from './order.js';
8
- import type { Database } from './database.js';
1
+ import type { DecomposeIndexName, PrimaryIndexes, UniqueIndexes } from './indexes';
2
+ import type { DatabaseEngine } from './engine';
3
+ import type { RelationMetadata } from './relations';
4
+ import type { InsensitiveModeUtils } from './insensitive';
5
+ import type { PaginationModeUtils } from './pagination';
6
+ import type { OrderModeUtils } from './order';
7
+ import type { LockModeUtils } from './lock';
8
+ import type { TableMetadata } from './table';
9
+ import type { Database } from './database';
9
10
  import type { AnyObject, PartialProperties, PartialObject, FlatObject, OptionalObject, StrictObject, IsNullable, IsObjectEmpty, IsObject, IsArray, Prettify } from '@ez4/utils';
10
11
  /**
11
12
  * Query builder types.
@@ -16,17 +17,20 @@ export declare namespace Query {
16
17
  data: Prettify<InsertDataInput<T>>;
17
18
  };
18
19
  export type UpdateOneInput<S extends AnyObject, T extends TableMetadata> = {
20
+ lock?: LockModeUtils.Input<T>;
19
21
  select?: StrictSelectInput<S, T>;
20
22
  include?: StrictIncludeInput<S, T>;
21
23
  data: Prettify<OptionalObject<UpdateDataInput<T>>>;
22
24
  where: WhereInput<T, true>;
23
25
  };
24
26
  export type FindOneInput<S extends AnyObject, T extends TableMetadata> = {
27
+ lock?: LockModeUtils.Input<T>;
25
28
  select: StrictSelectInput<S, T>;
26
29
  include?: StrictIncludeInput<S, T>;
27
30
  where: WhereInput<T, true>;
28
31
  };
29
32
  export type UpsertOneInput<S extends AnyObject, T extends TableMetadata> = {
33
+ lock?: LockModeUtils.Input<T>;
30
34
  select?: StrictSelectInput<S, T>;
31
35
  include?: StrictIncludeInput<S, T>;
32
36
  update: Prettify<OptionalObject<UpdateDataInput<T>>>;
@@ -41,20 +45,22 @@ export declare namespace Query {
41
45
  export type InsertManyInput<T extends TableMetadata> = {
42
46
  data: Prettify<T['schema']>[];
43
47
  };
44
- export type UpdateManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T['engine']> & {
48
+ export type UpdateManyInput<S extends AnyObject, T extends TableMetadata> = PaginationModeUtils.End<T['engine']> & {
49
+ lock?: LockModeUtils.Input<T>;
45
50
  select?: StrictSelectInput<S, T>;
46
51
  include?: StrictIncludeInput<S, T>;
47
52
  data: Prettify<OptionalObject<UpdateDataInput<T>>>;
48
53
  where?: WhereInput<T>;
49
54
  };
50
- export type FindManyInput<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Range<T['engine']> & {
51
- count?: C;
55
+ export type FindManyInput<S extends AnyObject, C extends boolean, T extends TableMetadata> = PaginationModeUtils.Range<T['engine']> & {
56
+ lock?: LockModeUtils.Input<T>;
52
57
  select: StrictSelectInput<S, T>;
53
58
  include?: StrictIncludeInput<S, T>;
54
59
  where?: WhereInput<T>;
55
60
  order?: OrderInput<T>;
61
+ count?: C;
56
62
  };
57
- export type DeleteManyInput<S extends AnyObject, T extends TableMetadata> = PaginationUtils.End<T['engine']> & {
63
+ export type DeleteManyInput<S extends AnyObject, T extends TableMetadata> = PaginationModeUtils.End<T['engine']> & {
58
64
  select?: StrictSelectInput<S, T>;
59
65
  include?: StrictIncludeInput<S, T>;
60
66
  where?: WhereInput<T>;
@@ -62,31 +68,30 @@ export declare namespace Query {
62
68
  export type CountInput<T extends TableMetadata> = {
63
69
  where?: WhereInput<T>;
64
70
  };
65
- export type InsertOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>;
66
- export type UpdateOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
67
- export type FindOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
68
- export type UpsertOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>;
69
- export type DeleteOneResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T> | undefined;
70
- export type UpdateManyResult<S extends AnyObject, T extends TableMetadata> = S extends never ? void : Record<S, T>[];
71
+ export type InsertOneResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T>;
72
+ export type UpdateOneResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T> | undefined;
73
+ export type FindOneResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T> | undefined;
74
+ export type UpsertOneResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T>;
75
+ export type DeleteOneResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T> | undefined;
76
+ export type UpdateManyResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T>[];
71
77
  export type InsertManyResult = void;
72
- export type FindManyResult<S extends AnyObject, T extends TableMetadata, C extends boolean> = PaginationUtils.Result<T['engine']> & (C extends true ? {
73
- records: Record<S, T>[];
78
+ export type FindManyResult<S extends AnyObject, C extends boolean, T extends TableMetadata> = PaginationModeUtils.Result<T['engine']> & {
79
+ records: SelectInput<T> extends S ? void : Record<S, T>[];
80
+ } & (false extends C ? {} : {
74
81
  total: number;
75
- } : {
76
- records: Record<S, T>[];
77
82
  });
78
- export type DeleteManyResult<S extends AnyObject, T extends TableMetadata> = Record<S, T>[];
79
- export type Record<S extends AnyObject, T extends TableMetadata> = S extends never ? undefined : PartialObject<SelectFields<T['schema'], T['relations']>, S>;
80
- export type SelectInput<T extends TableMetadata> = PartialProperties<SelectFields<T['schema'], T['relations']>>;
81
- export type StrictSelectInput<S extends AnyObject, T extends TableMetadata> = StrictObject<S, FlatObject<SelectFields<T['schema'], T['relations']>>>;
83
+ export type DeleteManyResult<S extends AnyObject, T extends TableMetadata> = SelectInput<T> extends S ? void : Record<S, T>[];
84
+ export type Record<S extends AnyObject, T extends TableMetadata> = PartialObject<SelectOutputFields<T['schema'], T['relations']>, S>;
85
+ export type SelectInput<T extends TableMetadata> = PartialProperties<SelectInputFields<T['schema'], T['relations']>>;
86
+ export type StrictSelectInput<S extends AnyObject, T extends TableMetadata> = StrictObject<S, SelectInputFields<T['schema'], T['relations']>>;
82
87
  export type InsertDataInput<T extends TableMetadata> = IsObjectEmpty<T['relations']['changes']> extends false ? Omit<T['schema'] & T['relations']['changes'], T['relations']['indexes']> : T['schema'];
83
88
  export type UpdateDataInput<T extends TableMetadata> = AtomicDataInput<IsObjectEmpty<T['relations']['changes']> extends false ? Omit<T['schema'] & FlatObject<T['relations']['changes']>, T['relations']['indexes']> : T['schema']>;
84
- export type OrderInput<T extends TableMetadata> = OrderUtils.Input<T>;
89
+ export type OrderInput<T extends TableMetadata> = OrderModeUtils.Input<T>;
85
90
  export type StrictIncludeInput<S extends AnyObject, T extends TableMetadata> = IsObjectEmpty<T['relations']['filters']> extends true ? never : {
86
- [P in keyof T['relations']['filters']]?: P extends keyof S ? StrictIncludeRelation<T['relations']['filters'][P], T['engine']> : never;
91
+ [P in keyof T['relations']['filters']]?: P extends keyof S ? StrictIncludeRelation<NonNullable<T['relations']['filters'][P]>, T['engine']> : never;
87
92
  };
88
- export type StrictIncludeOrder<V extends AnyObject> = OrderUtils.AnyInput<V>;
89
- export type StrictIncludeRelation<V extends AnyObject, E extends DatabaseEngine> = PaginationUtils.Range<E> & {
93
+ export type StrictIncludeOrder<V extends AnyObject> = OrderModeUtils.AnyInput<V>;
94
+ export type StrictIncludeRelation<V extends AnyObject, E extends DatabaseEngine> = PaginationModeUtils.Range<E> & {
90
95
  where?: WhereRelationField<V, E>;
91
96
  order?: StrictIncludeOrder<V>;
92
97
  };
@@ -95,8 +100,9 @@ export declare namespace Query {
95
100
  AND?: WhereInput<T>[];
96
101
  OR?: WhereInput<T>[];
97
102
  }>;
98
- type SelectFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['selects']> extends true ? T : T & R['selects'];
99
- type WhereOperations<V, E extends DatabaseEngine> = WhereNegate<V> | WhereEqual<V> | WhereGreaterThan<V> | WhereGreaterThanOrEqual<V> | WhereLessThan<V> | WhereLessThanOrEqual<V> | WhereIn<V> | WhereBetween<V> | WhereIsMissing | WhereIsNull | WhereStartsWith<E> | WhereContains<V, E>;
103
+ type SelectInputFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['selects']> extends true ? T : T & R['selects'];
104
+ type SelectOutputFields<T extends Database.Schema, R extends RelationMetadata> = IsObjectEmpty<R['records']> extends true ? T : T & R['records'];
105
+ type WhereOperations<V, E extends DatabaseEngine> = WhereNegate<V, E> | WhereEqual<V, E> | WhereGreaterThan<V> | WhereGreaterThanOrEqual<V> | WhereLessThan<V> | WhereLessThanOrEqual<V> | WhereIn<V> | WhereBetween<V> | WhereIsMissing | WhereIsNull | WhereStartsWith<E> | WhereContains<V, E>;
100
106
  type WhereField<V, E extends DatabaseEngine> = IsObject<V> extends false ? V | WhereOperations<V, E> : IsNullable<V> extends true ? null | WhereObjectField<NonNullable<V>, E> : WhereObjectField<NonNullable<V>, E>;
101
107
  type WhereObjectField<V extends AnyObject, E extends DatabaseEngine> = {
102
108
  [P in keyof V]?: WhereField<V[P], E>;
@@ -120,11 +126,11 @@ export declare namespace Query {
120
126
  };
121
127
  type WhereCommonFilters<V extends AnyObject, T extends TableMetadata, I extends Database.Indexes> = IsObjectEmpty<I> extends true ? WhereObjectField<V, T['engine']> : WhereRequiredFilters<V, I> & WhereOptionalFilters<V, T, I>;
122
128
  type WhereInputFilters<T extends TableMetadata, I extends Database.Indexes> = WhereCommonFilters<T['schema'], T, I> & (IsObjectEmpty<T['relations']['filters']> extends false ? WhereRelationFilters<T['relations']['filters'], T['engine']> : {});
123
- export type WhereOperators = keyof (WhereNegate<any> & WhereEqual<any> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith<never> & WhereContains<any, never>);
124
- type WhereNegate<V> = {
129
+ export type WhereOperators = keyof (WhereNegate<any, never> & WhereEqual<any, never> & WhereGreaterThan<any> & WhereGreaterThanOrEqual<any> & WhereLessThan<any> & WhereLessThanOrEqual<any> & WhereIn<any> & WhereBetween<any> & WhereIsMissing & WhereIsNull & WhereStartsWith<never> & WhereContains<any, never>);
130
+ type WhereNegate<V, E extends DatabaseEngine> = (V extends string ? InsensitiveModeUtils.Input<E> : {}) & {
125
131
  not: V;
126
132
  };
127
- type WhereEqual<V> = {
133
+ type WhereEqual<V, E extends DatabaseEngine> = (V extends string ? InsensitiveModeUtils.Input<E> : {}) & {
128
134
  equal: V;
129
135
  };
130
136
  type WhereGreaterThan<V> = {
@@ -151,10 +157,10 @@ export declare namespace Query {
151
157
  type WhereIsNull = {
152
158
  isNull: boolean;
153
159
  };
154
- type WhereStartsWith<E extends DatabaseEngine> = InsensitiveUtils.Input<E> & {
160
+ type WhereStartsWith<E extends DatabaseEngine> = InsensitiveModeUtils.Input<E> & {
155
161
  startsWith: string;
156
162
  };
157
- type WhereContains<V, E extends DatabaseEngine> = (V extends string ? InsensitiveUtils.Input<E> : {}) & {
163
+ type WhereContains<V, E extends DatabaseEngine> = (V extends string ? InsensitiveModeUtils.Input<E> : {}) & {
158
164
  contains: IsObject<V> extends true ? Partial<V> : V;
159
165
  };
160
166
  export type AtomicOperators = keyof (AtomicIncrement & AtomicDecrement & AtomicMultiply & AtomicDivide);
@@ -1,14 +1,15 @@
1
- import type { AnyObject, ArrayRest, PropertyType, ExclusiveType, IsArrayEmpty, IsUndefined } from '@ez4/utils';
2
- import type { IndexedTables, PrimaryIndexes, UniqueIndexes } from './indexes.js';
3
- import type { Database, DatabaseTables } from './database.js';
4
- import type { TableSchemas } from './schemas.js';
1
+ import type { AnyObject, ArrayRest, PropertyType, ExclusiveType, IsArrayEmpty, IsUndefined, FlatObject, MergeObject } from '@ez4/utils';
2
+ import type { IndexedTables, PrimaryIndexes, UniqueIndexes } from './indexes';
3
+ import type { Database, DatabaseTables } from './database';
4
+ import type { TableSchemas } from './schemas';
5
5
  /**
6
6
  * Internal relation type.
7
7
  */
8
8
  export type RelationMetadata = {
9
- filters: Record<string, {}>;
10
- selects: Record<string, {}>;
11
- changes: Record<string, {}>;
9
+ filters: Record<string, AnyObject | undefined>;
10
+ selects: Record<string, AnyObject | undefined>;
11
+ changes: Record<string, AnyObject | undefined>;
12
+ records: Record<string, AnyObject | undefined>;
12
13
  indexes: string;
13
14
  };
14
15
  /**
@@ -30,16 +31,16 @@ export type RelationTargetAlias<T> = T extends `${string}@${infer U}` ? U : neve
30
31
  /**
31
32
  * Given a database service `T`, it produces an object with all relation tables.
32
33
  */
33
- export type RelationTables<T extends Database.Service> = MergeRelations<DatabaseTables<T>, TableSchemas<T>, IndexedTables<T>>;
34
+ export type RelationTables<T extends Database.Service> = MergeRelations<DatabaseTables<T>, DatabaseTables<T>, TableSchemas<T>, IndexedTables<T>>;
34
35
  /**
35
36
  * Given a list of tables with relations `T`, it produces an object containing all the
36
37
  * relation tables.
37
38
  */
38
- type MergeRelations<T extends Database.Table[], S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>> = IsArrayEmpty<T> extends false ? TableRelation<T[0], S, I> & MergeRelations<ArrayRest<T>, S, I> : {};
39
+ type MergeRelations<T extends Database.Table[], C extends Database.Table[], S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>> = IsArrayEmpty<C> extends false ? TableRelation<T, C[0], S, I> & MergeRelations<T, ArrayRest<C>, S, I> : {};
39
40
  /**
40
41
  * Given a database table `T`, it produces an object containing all its relations.
41
42
  */
42
- type TableRelation<T, S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>> = T extends {
43
+ type TableRelation<T extends Database.Table[], C extends Database.Table, S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>> = C extends {
43
44
  name: infer N;
44
45
  relations: infer R;
45
46
  } ? N extends string ? R extends AnyObject ? {
@@ -47,7 +48,8 @@ type TableRelation<T, S extends Record<string, Database.Schema>, I extends Recor
47
48
  indexes: RelationIndexes<PropertyType<N, I>, R>;
48
49
  filters: FilterableRelationSchemas<S, R>;
49
50
  changes: RequiredRelationSchemas<PropertyType<N, S>, S, I, R, true> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, true>;
50
- selects: RequiredRelationSchemas<PropertyType<N, S>, S, I, R, false> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, false>;
51
+ selects: FlatObject<RequiredRelationSchemas<PropertyType<N, S>, S, I, R, false>> & FlatObject<OptionalRelationSchemas<PropertyType<N, S>, S, I, R, false>> & NestedRelationSelects<T, S, I, R>;
52
+ records: MergeObject<RequiredRelationSchemas<PropertyType<N, S>, S, I, R, false> & OptionalRelationSchemas<PropertyType<N, S>, S, I, R, false>, NestedRelationRecords<T, S, I, R>>;
51
53
  };
52
54
  } : {} : {} : {};
53
55
  /**
@@ -74,6 +76,22 @@ type RequiredRelationSchemas<T extends Database.Schema, S extends Record<string,
74
76
  type OptionalRelationSchemas<T extends Database.Schema, S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>, R extends AnyObject, E extends boolean> = {
75
77
  [C in keyof R as IsOptionalRelation<R[C], C, T, I, E> extends true ? RelationTargetAlias<C> : never]?: RelationSchema<R[C], C, T, S, I, E>;
76
78
  };
79
+ /**
80
+ * Produce an object containing all nested relation schemas for select operations.
81
+ */
82
+ type NestedRelationSelects<T extends Database.Table[], S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>, R extends AnyObject> = {
83
+ [C in keyof R as RelationTargetAlias<C>]?: RelationSourceTable<R[C]> extends keyof MergeRelations<T, T, S, I> ? MergeRelations<T, T, S, I>[RelationSourceTable<R[C]>] extends {
84
+ selects: infer N;
85
+ } ? N : never : never;
86
+ };
87
+ /**
88
+ * Produce an object containing all nested relation schemas for records.
89
+ */
90
+ type NestedRelationRecords<T extends Database.Table[], S extends Record<string, Database.Schema>, I extends Record<string, Database.Indexes>, R extends AnyObject> = {
91
+ [C in keyof R as RelationTargetAlias<C>]?: RelationSourceTable<R[C]> extends keyof MergeRelations<T, T, S, I> ? MergeRelations<T, T, S, I>[RelationSourceTable<R[C]>] extends {
92
+ records: infer N;
93
+ } ? N : never : never;
94
+ };
77
95
  /**
78
96
  * Check whether a relation is optional or not.
79
97
  */
@@ -1,5 +1,5 @@
1
1
  import type { ArrayRest, IsArrayEmpty } from '@ez4/utils';
2
- import type { Database, DatabaseTables } from './database.js';
2
+ import type { Database, DatabaseTables } from './database';
3
3
  /**
4
4
  * Given a database service `T`, it produces an object containing all tables with schemas.
5
5
  */
@@ -1,10 +1,10 @@
1
1
  import type { AnyObject, PropertyExists } from '@ez4/utils';
2
- import type { RelationMetadata, RelationTables } from './relations.js';
3
- import type { IndexedTables } from './indexes.js';
4
- import type { TableSchemas } from './schemas.js';
5
- import type { Database } from './database.js';
6
- import type { DatabaseEngine } from './engine.js';
7
- import type { Query } from './query.js';
2
+ import type { RelationMetadata, RelationTables } from './relations';
3
+ import type { IndexedTables } from './indexes';
4
+ import type { TableSchemas } from './schemas';
5
+ import type { Database } from './database';
6
+ import type { DatabaseEngine } from './engine';
7
+ import type { Query } from './query';
8
8
  /**
9
9
  * Given an indexed table `T` and a property `P`, it returns all the indexes corresponding
10
10
  * to the given property.
@@ -44,7 +44,7 @@ export interface Table<T extends TableMetadata> {
44
44
  *
45
45
  * @param query Input query.
46
46
  */
47
- insertOne<S extends Query.SelectInput<T> = never>(query: Query.InsertOneInput<S, T>): Promise<Query.InsertOneResult<S, T>>;
47
+ insertOne<S extends Query.SelectInput<T>>(query: Query.InsertOneInput<S, T>): Promise<Query.InsertOneResult<S, T>>;
48
48
  /**
49
49
  * Find one database record.
50
50
  *
@@ -56,19 +56,19 @@ export interface Table<T extends TableMetadata> {
56
56
  *
57
57
  * @param query Input query.
58
58
  */
59
- updateOne<S extends Query.SelectInput<T> = never>(query: Query.UpdateOneInput<S, T>): Promise<Query.UpdateOneResult<S, T>>;
59
+ updateOne<S extends Query.SelectInput<T>>(query: Query.UpdateOneInput<S, T>): Promise<Query.UpdateOneResult<S, T>>;
60
60
  /**
61
61
  * Try to insert a database record, and if it already exists, perform an update instead.
62
62
  *
63
63
  * @param query Input query.
64
64
  */
65
- upsertOne<S extends Query.SelectInput<T> = never>(query: Query.UpsertOneInput<S, T>): Promise<Query.UpsertOneResult<S, T>>;
65
+ upsertOne<S extends Query.SelectInput<T>>(query: Query.UpsertOneInput<S, T>): Promise<Query.UpsertOneResult<S, T>>;
66
66
  /**
67
67
  * Delete one database record.
68
68
  *
69
69
  * @param query Input query.
70
70
  */
71
- deleteOne<S extends Query.SelectInput<T> = never>(query: Query.DeleteOneInput<S, T>): Promise<Query.DeleteOneResult<S, T>>;
71
+ deleteOne<S extends Query.SelectInput<T>>(query: Query.DeleteOneInput<S, T>): Promise<Query.DeleteOneResult<S, T>>;
72
72
  /**
73
73
  * Insert multiple records into the database.
74
74
  *
@@ -80,19 +80,19 @@ export interface Table<T extends TableMetadata> {
80
80
  *
81
81
  * @param query Input query.
82
82
  */
83
- findMany<S extends Query.SelectInput<T>, C extends boolean = false>(query: Query.FindManyInput<S, T, C>): Promise<Query.FindManyResult<S, T, C>>;
83
+ findMany<S extends Query.SelectInput<T>, C extends boolean>(query: Query.FindManyInput<S, C, T>): Promise<Query.FindManyResult<S, C, T>>;
84
84
  /**
85
85
  * Update multiple database records.
86
86
  *
87
87
  * @param query Input query.
88
88
  */
89
- updateMany<S extends Query.SelectInput<T> = never>(query: Query.UpdateManyInput<S, T>): Promise<Query.UpdateManyResult<S, T>>;
89
+ updateMany<S extends Query.SelectInput<T>>(query: Query.UpdateManyInput<S, T>): Promise<Query.UpdateManyResult<S, T>>;
90
90
  /**
91
91
  * Delete multiple database records.
92
92
  *
93
93
  * @param query Input query.
94
94
  */
95
- deleteMany<S extends Query.SelectInput<T> = never>(query: Query.DeleteManyInput<S, T>): Promise<Query.DeleteManyResult<S, T>>;
95
+ deleteMany<S extends Query.SelectInput<T>>(query: Query.DeleteManyInput<S, T>): Promise<Query.DeleteManyResult<S, T>>;
96
96
  /**
97
97
  * Count database records.
98
98
  *
@@ -1,11 +1,11 @@
1
- import type { TableIndex, TableMetadata, TableRelation } from './table.js';
2
- import type { RelationTables } from './relations.js';
3
- import type { IndexedTables } from './indexes.js';
4
- import type { EngineUtils } from './engine.js';
5
- import type { TableSchemas } from './schemas.js';
6
- import type { Database } from './database.js';
7
- import type { Client } from './client.js';
8
- import type { Query } from './query.js';
1
+ import type { TableIndex, TableMetadata, TableRelation } from './table';
2
+ import type { RelationTables } from './relations';
3
+ import type { IndexedTables } from './indexes';
4
+ import type { EngineUtils } from './engine';
5
+ import type { TableSchemas } from './schemas';
6
+ import type { Database } from './database';
7
+ import type { Client } from './client';
8
+ import type { Query } from './query';
9
9
  /**
10
10
  * Transaction mode.
11
11
  */
@@ -14,9 +14,9 @@ export declare const enum TransactionMode {
14
14
  Static = "static"
15
15
  }
16
16
  /**
17
- * Transaction utils.
17
+ * Transaction mode utils.
18
18
  */
19
- export declare namespace TransactionUtils {
19
+ export declare namespace TransactionModeUtils {
20
20
  /**
21
21
  * Extract the operation result from an interactive transaction.
22
22
  */
@@ -1,13 +1,15 @@
1
- import type { ParametersMode } from '../services/parameters.js';
2
- import type { TransactionMode } from '../services/transaction.js';
3
- import type { InsensitiveMode } from '../services/insensitive.js';
4
- import type { PaginationMode } from '../services/pagination.js';
5
- import type { OrderMode } from '../services/order.js';
1
+ import type { ParametersMode } from '../services/parameters';
2
+ import type { TransactionMode } from '../services/transaction';
3
+ import type { InsensitiveMode } from '../services/insensitive';
4
+ import type { PaginationMode } from '../services/pagination';
5
+ import type { OrderMode } from '../services/order';
6
+ import type { LockMode } from '../services/lock';
6
7
  export type DatabaseEngine = {
7
8
  parametersMode: ParametersMode;
8
9
  transactionMode: TransactionMode;
9
10
  insensitiveMode: InsensitiveMode;
10
11
  paginationMode: PaginationMode;
11
12
  orderMode: OrderMode;
13
+ lockMode: LockMode;
12
14
  name: string;
13
15
  };
@@ -1,4 +1,4 @@
1
- import type { Index } from '../services/indexes.js';
1
+ import type { Index } from '../services/indexes';
2
2
  export type TableIndex = {
3
3
  name: string;
4
4
  columns: string[];
@@ -1,4 +1,4 @@
1
- import type { Index } from '../services/indexes.js';
1
+ import type { Index } from '../services/indexes';
2
2
  export type TableRelation = {
3
3
  sourceTable: string;
4
4
  sourceColumn: string;
@@ -1,7 +1,7 @@
1
1
  import type { ServiceMetadata } from '@ez4/project/library';
2
- import type { DatabaseScalability } from './scalability.js';
3
- import type { DatabaseEngine } from './engine.js';
4
- import type { DatabaseTable } from './table.js';
2
+ import type { DatabaseScalability } from './scalability';
3
+ import type { DatabaseEngine } from './engine';
4
+ import type { DatabaseTable } from './table';
5
5
  export declare const ServiceType = "@ez4/database";
6
6
  export type DatabaseService = ServiceMetadata & {
7
7
  type: typeof ServiceType;
@@ -1,6 +1,6 @@
1
1
  import type { LinkedVariables } from '@ez4/project/library';
2
2
  import type { ServiceListener } from '@ez4/common/library';
3
- import type { StreamHandler } from './handler.js';
3
+ import type { StreamHandler } from './handler';
4
4
  export type TableStream = {
5
5
  listener?: ServiceListener;
6
6
  handler: StreamHandler;
@@ -1,7 +1,7 @@
1
- import type { TableRelation } from './relations.js';
2
- import type { TableIndex } from './indexes.js';
3
- import type { TableSchema } from './schema.js';
4
- import type { TableStream } from './stream.js';
1
+ import type { TableRelation } from './relations';
2
+ import type { TableIndex } from './indexes';
3
+ import type { TableSchema } from './schema';
4
+ import type { TableStream } from './stream';
5
5
  export type DatabaseTable = {
6
6
  name: string;
7
7
  schema: TableSchema;
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.25.0",
4
+ "version": "0.27.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -11,7 +11,7 @@
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/sbalmt/ez4.git",
14
- "directory": "packages/database"
14
+ "directory": "contracts/database"
15
15
  },
16
16
  "engines": {
17
17
  "node": ">=22.7"
@@ -29,24 +29,23 @@
29
29
  }
30
30
  },
31
31
  "workspaces": [
32
- "packages/*"
32
+ "foundation/*",
33
+ "contracts/*"
33
34
  ],
34
35
  "scripts": {
35
36
  "lint": "eslint --cache",
36
37
  "clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
37
- "build": "tsc -p tsconfig.json && node tools/bundler.mjs",
38
- "test": "npm run test:types && node --test --import ../../tools/tsnode.mjs test/*.spec.ts",
39
- "test:only": "npm run test:types && node --test-only --test --import ../../tools/tsnode.mjs test/*.spec.ts",
40
- "test:types": "npm run build && tsc -p tsconfig.test.json",
38
+ "build": "tsc && node tools/bundler.mjs",
39
+ "test": "npm run build && ez4 test",
41
40
  "local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
42
41
  "clean:registry": "rm -rf ../../.registry/@ez4/database",
43
- "live:publish": "npm publish --access public"
42
+ "live:publish": "npm run build && npm publish --access public"
44
43
  },
45
44
  "dependencies": {
46
- "@ez4/common": "^0.25.0",
47
- "@ez4/project": "^0.25.0",
48
- "@ez4/reflection": "^0.25.0",
49
- "@ez4/schema": "^0.25.0",
50
- "@ez4/utils": "^0.25.0"
45
+ "@ez4/common": "^0.27.0",
46
+ "@ez4/project": "^0.27.0",
47
+ "@ez4/reflection": "^0.27.0",
48
+ "@ez4/schema": "^0.27.0",
49
+ "@ez4/utils": "^0.27.0"
51
50
  }
52
51
  }