metal-orm 1.0.16 → 1.0.18

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.
Files changed (64) hide show
  1. package/README.md +37 -40
  2. package/dist/decorators/index.cjs +344 -69
  3. package/dist/decorators/index.cjs.map +1 -1
  4. package/dist/decorators/index.d.cts +1 -1
  5. package/dist/decorators/index.d.ts +1 -1
  6. package/dist/decorators/index.js +344 -69
  7. package/dist/decorators/index.js.map +1 -1
  8. package/dist/index.cjs +567 -181
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +66 -30
  11. package/dist/index.d.ts +66 -30
  12. package/dist/index.js +559 -181
  13. package/dist/index.js.map +1 -1
  14. package/dist/{select-BKZrMRCQ.d.cts → select-BuMpVcVt.d.cts} +265 -74
  15. package/dist/{select-BKZrMRCQ.d.ts → select-BuMpVcVt.d.ts} +265 -74
  16. package/package.json +5 -1
  17. package/src/codegen/naming-strategy.ts +15 -10
  18. package/src/core/ast/aggregate-functions.ts +50 -4
  19. package/src/core/ast/builders.ts +23 -3
  20. package/src/core/ast/expression-builders.ts +36 -16
  21. package/src/core/ast/expression-nodes.ts +17 -9
  22. package/src/core/ast/join-node.ts +5 -3
  23. package/src/core/ast/join.ts +16 -16
  24. package/src/core/ast/query.ts +44 -29
  25. package/src/core/ddl/dialects/mssql-schema-dialect.ts +18 -0
  26. package/src/core/ddl/dialects/mysql-schema-dialect.ts +11 -0
  27. package/src/core/ddl/dialects/postgres-schema-dialect.ts +9 -0
  28. package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -0
  29. package/src/core/ddl/introspect/functions/postgres.ts +2 -6
  30. package/src/core/dialect/abstract.ts +12 -8
  31. package/src/core/dialect/base/sql-dialect.ts +58 -46
  32. package/src/core/dialect/mssql/functions.ts +24 -15
  33. package/src/core/dialect/mssql/index.ts +53 -28
  34. package/src/core/dialect/postgres/functions.ts +33 -24
  35. package/src/core/dialect/sqlite/functions.ts +19 -12
  36. package/src/core/dialect/sqlite/index.ts +22 -13
  37. package/src/core/functions/datetime.ts +2 -1
  38. package/src/core/functions/numeric.ts +2 -1
  39. package/src/core/functions/standard-strategy.ts +52 -12
  40. package/src/core/functions/text.ts +2 -1
  41. package/src/core/functions/types.ts +8 -8
  42. package/src/index.ts +5 -4
  43. package/src/orm/domain-event-bus.ts +43 -25
  44. package/src/orm/entity-meta.ts +40 -0
  45. package/src/orm/execution-context.ts +6 -0
  46. package/src/orm/hydration-context.ts +6 -4
  47. package/src/orm/orm-session.ts +35 -24
  48. package/src/orm/orm.ts +10 -10
  49. package/src/orm/query-logger.ts +15 -0
  50. package/src/orm/runtime-types.ts +60 -2
  51. package/src/orm/transaction-runner.ts +7 -0
  52. package/src/orm/unit-of-work.ts +1 -0
  53. package/src/query-builder/column-selector.ts +9 -7
  54. package/src/query-builder/insert-query-state.ts +13 -3
  55. package/src/query-builder/query-ast-service.ts +59 -38
  56. package/src/query-builder/relation-conditions.ts +38 -34
  57. package/src/query-builder/relation-manager.ts +8 -3
  58. package/src/query-builder/relation-service.ts +59 -46
  59. package/src/query-builder/select-helpers.ts +50 -0
  60. package/src/query-builder/select-query-state.ts +19 -7
  61. package/src/query-builder/select.ts +339 -167
  62. package/src/query-builder/update-query-state.ts +31 -9
  63. package/src/schema/column.ts +75 -39
  64. package/src/schema/types.ts +17 -6
@@ -1,39 +1,47 @@
1
1
  /**
2
2
  * Supported column data types for database schema definitions
3
3
  */
4
- export type ColumnType =
5
- | 'INT'
6
- | 'INTEGER'
7
- | 'BIGINT'
8
- | 'VARCHAR'
9
- | 'TEXT'
10
- | 'JSON'
11
- | 'ENUM'
12
- | 'DECIMAL'
13
- | 'FLOAT'
14
- | 'DOUBLE'
15
- | 'UUID'
16
- | 'DATE'
17
- | 'DATETIME'
18
- | 'TIMESTAMP'
19
- | 'TIMESTAMPTZ'
20
- | 'BOOLEAN'
21
- | 'int'
22
- | 'integer'
23
- | 'bigint'
24
- | 'varchar'
25
- | 'text'
26
- | 'json'
27
- | 'enum'
28
- | 'decimal'
29
- | 'float'
30
- | 'double'
31
- | 'uuid'
32
- | 'date'
33
- | 'datetime'
34
- | 'timestamp'
35
- | 'timestamptz'
36
- | 'boolean';
4
+ export type ColumnType =
5
+ | 'INT'
6
+ | 'INTEGER'
7
+ | 'BIGINT'
8
+ | 'VARCHAR'
9
+ | 'TEXT'
10
+ | 'JSON'
11
+ | 'ENUM'
12
+ | 'DECIMAL'
13
+ | 'FLOAT'
14
+ | 'DOUBLE'
15
+ | 'UUID'
16
+ | 'BINARY'
17
+ | 'VARBINARY'
18
+ | 'BLOB'
19
+ | 'BYTEA'
20
+ | 'DATE'
21
+ | 'DATETIME'
22
+ | 'TIMESTAMP'
23
+ | 'TIMESTAMPTZ'
24
+ | 'BOOLEAN'
25
+ | 'int'
26
+ | 'integer'
27
+ | 'bigint'
28
+ | 'varchar'
29
+ | 'text'
30
+ | 'json'
31
+ | 'enum'
32
+ | 'decimal'
33
+ | 'float'
34
+ | 'double'
35
+ | 'uuid'
36
+ | 'binary'
37
+ | 'varbinary'
38
+ | 'blob'
39
+ | 'bytea'
40
+ | 'date'
41
+ | 'datetime'
42
+ | 'timestamp'
43
+ | 'timestamptz'
44
+ | 'boolean';
37
45
 
38
46
  export type ReferentialAction =
39
47
  | 'NO ACTION'
@@ -138,12 +146,40 @@ export const col = {
138
146
  /**
139
147
  * Creates a UUID column definition
140
148
  */
141
- uuid: (): ColumnDef<'UUID'> => ({ name: '', type: 'UUID' }),
142
-
143
- /**
144
- * Creates a timestamp column definition
145
- */
146
- timestamp: (): ColumnDef<'TIMESTAMP'> => ({ name: '', type: 'TIMESTAMP' }),
149
+ uuid: (): ColumnDef<'UUID'> => ({ name: '', type: 'UUID' }),
150
+
151
+ /**
152
+ * Creates a binary large object column definition
153
+ */
154
+ blob: (): ColumnDef<'BLOB'> => ({ name: '', type: 'BLOB' }),
155
+
156
+ /**
157
+ * Creates a fixed-length binary column definition
158
+ */
159
+ binary: (length?: number): ColumnDef<'BINARY'> => ({
160
+ name: '',
161
+ type: 'BINARY',
162
+ args: length !== undefined ? [length] : undefined
163
+ }),
164
+
165
+ /**
166
+ * Creates a variable-length binary column definition
167
+ */
168
+ varbinary: (length?: number): ColumnDef<'VARBINARY'> => ({
169
+ name: '',
170
+ type: 'VARBINARY',
171
+ args: length !== undefined ? [length] : undefined
172
+ }),
173
+
174
+ /**
175
+ * Creates a Postgres bytea column definition
176
+ */
177
+ bytea: (): ColumnDef<'BYTEA'> => ({ name: '', type: 'BYTEA' }),
178
+
179
+ /**
180
+ * Creates a timestamp column definition
181
+ */
182
+ timestamp: (): ColumnDef<'TIMESTAMP'> => ({ name: '', type: 'TIMESTAMP' }),
147
183
 
148
184
  /**
149
185
  * Creates a timestamptz column definition
@@ -1,5 +1,5 @@
1
- import { ColumnDef } from './column.js';
2
- import { TableDef } from './table.js';
1
+ import { ColumnDef } from './column.js';
2
+ import { TableDef } from './table.js';
3
3
  import {
4
4
  RelationDef,
5
5
  HasManyRelation,
@@ -7,16 +7,27 @@ import {
7
7
  BelongsToRelation,
8
8
  BelongsToManyRelation
9
9
  } from './relation.js';
10
-
11
- /**
12
- * Maps a ColumnDef to its TypeScript type representation
13
- */
10
+
11
+ /**
12
+ * Resolves a relation definition to its target table type.
13
+ */
14
+ export type RelationTargetTable<TRel extends RelationDef> =
15
+ TRel extends HasManyRelation<infer TTarget> ? TTarget :
16
+ TRel extends HasOneRelation<infer TTarget> ? TTarget :
17
+ TRel extends BelongsToRelation<infer TTarget> ? TTarget :
18
+ TRel extends BelongsToManyRelation<infer TTarget> ? TTarget :
19
+ never;
20
+
21
+ /**
22
+ * Maps a ColumnDef to its TypeScript type representation
23
+ */
14
24
  export type ColumnToTs<T extends ColumnDef> =
15
25
  T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number :
16
26
  T['type'] extends 'BIGINT' | 'bigint' ? number | bigint :
17
27
  T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number :
18
28
  T['type'] extends 'BOOLEAN' | 'boolean' ? boolean :
19
29
  T['type'] extends 'JSON' | 'json' ? unknown :
30
+ T['type'] extends 'BLOB' | 'blob' | 'BINARY' | 'binary' | 'VARBINARY' | 'varbinary' | 'BYTEA' | 'bytea' ? Buffer :
20
31
  T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string :
21
32
  string;
22
33