uql-orm 0.21.0 → 0.23.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.
Files changed (214) hide show
  1. package/README.md +5 -4
  2. package/dist/browser/uql-browser.min.js.map +3 -3
  3. package/dist/bunSql/bunSqlCockroachDialect.d.ts +2 -2
  4. package/dist/bunSql/bunSqlCockroachDialect.js +4 -10
  5. package/dist/bunSql/bunSqlPostgresDialect.d.ts +2 -2
  6. package/dist/bunSql/bunSqlPostgresDialect.js +4 -10
  7. package/dist/cockroachdb/cockroachDialect.d.ts +20 -4
  8. package/dist/cockroachdb/cockroachDialect.js +33 -18
  9. package/dist/d1/d1Querier.d.ts +4 -3
  10. package/dist/d1/d1Querier.js +0 -3
  11. package/dist/d1/d1SqliteDialect.d.ts +7 -0
  12. package/dist/d1/d1SqliteDialect.js +9 -0
  13. package/dist/dialect/abstractDialect.d.ts +8 -3
  14. package/dist/dialect/abstractDialect.js +9 -4
  15. package/dist/dialect/abstractSqlDialect.d.ts +49 -8
  16. package/dist/dialect/abstractSqlDialect.js +95 -47
  17. package/dist/dialect/index.d.ts +1 -0
  18. package/dist/dialect/index.js +1 -0
  19. package/dist/dialect/indexSqlDialect.d.ts +57 -0
  20. package/dist/dialect/indexSqlDialect.js +101 -0
  21. package/dist/dialect/mysqlLikeSqlDialect.d.ts +26 -1
  22. package/dist/dialect/mysqlLikeSqlDialect.js +57 -1
  23. package/dist/dialect/pgLikeSqlDialect.d.ts +37 -22
  24. package/dist/dialect/pgLikeSqlDialect.js +97 -68
  25. package/dist/dialect/vectorCast.d.ts +21 -0
  26. package/dist/dialect/vectorCast.js +28 -0
  27. package/dist/dialect/vectorSqlDialect.d.ts +10 -3
  28. package/dist/dialect/vectorSqlDialect.js +19 -8
  29. package/dist/entity/decorator/bag.d.ts +35 -0
  30. package/dist/entity/decorator/bag.js +54 -0
  31. package/dist/entity/decorator/entity.d.ts +28 -2
  32. package/dist/entity/decorator/entity.js +40 -2
  33. package/dist/entity/decorator/members.d.ts +51 -0
  34. package/dist/entity/decorator/members.js +51 -0
  35. package/dist/entity/index.d.ts +3 -1
  36. package/dist/entity/index.js +3 -1
  37. package/dist/entity/metadata/definition.d.ts +23 -8
  38. package/dist/entity/metadata/definition.js +56 -100
  39. package/dist/http/contract.js +1 -2
  40. package/dist/http/handler.js +5 -26
  41. package/dist/http/query.js +1 -1
  42. package/dist/libsql/libsqlDialect.d.ts +12 -2
  43. package/dist/libsql/libsqlDialect.js +14 -2
  44. package/dist/libsql/libsqlQuerier.d.ts +9 -22
  45. package/dist/libsql/libsqlQuerier.js +9 -85
  46. package/dist/libsql/libsqlQuerierPool.d.ts +10 -8
  47. package/dist/libsql/libsqlQuerierPool.js +17 -15
  48. package/dist/maria/mariaDialect.d.ts +26 -4
  49. package/dist/maria/mariaDialect.js +54 -15
  50. package/dist/migrate/acquireQuerierForMigrations.d.ts +13 -1
  51. package/dist/migrate/acquireQuerierForMigrations.js +28 -0
  52. package/dist/migrate/builder/migrationBuilder.d.ts +9 -29
  53. package/dist/migrate/builder/migrationBuilder.js +58 -76
  54. package/dist/migrate/builder/splitSqlStatements.d.ts +0 -2
  55. package/dist/migrate/builder/splitSqlStatements.js +0 -2
  56. package/dist/migrate/builder/tableBuilder.d.ts +12 -2
  57. package/dist/migrate/builder/tableBuilder.js +71 -119
  58. package/dist/migrate/builder/types.d.ts +30 -41
  59. package/dist/migrate/cli-config.js +24 -8
  60. package/dist/migrate/cli.d.ts +3 -2
  61. package/dist/migrate/cli.js +26 -49
  62. package/dist/migrate/codegen/entityCodeGenerator.d.ts +0 -4
  63. package/dist/migrate/codegen/entityCodeGenerator.js +8 -67
  64. package/dist/migrate/codegen/fieldOptionsSource.d.ts +10 -0
  65. package/dist/migrate/codegen/fieldOptionsSource.js +55 -0
  66. package/dist/migrate/codegen/index.d.ts +0 -3
  67. package/dist/migrate/codegen/index.js +0 -6
  68. package/dist/migrate/drift/driftDetector.d.ts +10 -1
  69. package/dist/migrate/drift/driftDetector.js +22 -5
  70. package/dist/migrate/generator/indexNodeToSchema.d.ts +9 -0
  71. package/dist/migrate/generator/indexNodeToSchema.js +14 -0
  72. package/dist/migrate/generator/mongoCommand.d.ts +57 -0
  73. package/dist/migrate/generator/mongoCommand.js +26 -0
  74. package/dist/migrate/generator/mongoSchemaGenerator.d.ts +9 -20
  75. package/dist/migrate/generator/mongoSchemaGenerator.js +40 -82
  76. package/dist/migrate/index.d.ts +0 -1
  77. package/dist/migrate/index.js +0 -1
  78. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +30 -11
  79. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +61 -57
  80. package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
  81. package/dist/migrate/introspection/baseSqlIntrospector.js +3 -12
  82. package/dist/migrate/introspection/mongoIntrospector.js +9 -15
  83. package/dist/migrate/introspection/mysqlIntrospector.d.ts +5 -8
  84. package/dist/migrate/introspection/mysqlIntrospector.js +4 -10
  85. package/dist/migrate/introspection/postgresIntrospector.d.ts +5 -8
  86. package/dist/migrate/introspection/postgresIntrospector.js +4 -10
  87. package/dist/migrate/introspection/sqliteIntrospector.d.ts +6 -5
  88. package/dist/migrate/introspection/sqliteIntrospector.js +26 -18
  89. package/dist/migrate/migrator.d.ts +23 -3
  90. package/dist/migrate/migrator.js +101 -150
  91. package/dist/migrate/schemaGenerator.d.ts +26 -37
  92. package/dist/migrate/schemaGenerator.js +69 -174
  93. package/dist/migrate/schemaGeneratorAsync.d.ts +2 -2
  94. package/dist/migrate/schemaGeneratorAsync.js +3 -3
  95. package/dist/migrate/storage/databaseStorage.d.ts +2 -0
  96. package/dist/migrate/storage/databaseStorage.js +12 -27
  97. package/dist/mongo/mongoDialect.d.ts +2 -0
  98. package/dist/mongo/mongoDialect.js +14 -3
  99. package/dist/mongo/mongodbQuerier.js +171 -229
  100. package/dist/mysql/mysqlDialect.d.ts +8 -0
  101. package/dist/mysql/mysqlDialect.js +13 -0
  102. package/dist/nestjs/uqlContextInterceptor.js +58 -22
  103. package/dist/nestjs/uqlModule.d.ts +2 -11
  104. package/dist/nestjs/uqlModule.js +93 -44
  105. package/dist/postgres/postgresDialect.js +2 -2
  106. package/dist/querier/abstractQuerier.d.ts +28 -0
  107. package/dist/querier/abstractQuerier.js +47 -22
  108. package/dist/querier/abstractQuerierPool.d.ts +3 -0
  109. package/dist/querier/abstractQuerierPool.js +5 -3
  110. package/dist/querier/abstractSqlQuerier.d.ts +1 -3
  111. package/dist/querier/abstractSqlQuerier.js +48 -96
  112. package/dist/querier/index.d.ts +3 -1
  113. package/dist/querier/index.js +3 -1
  114. package/dist/querier/querierContext.browser.d.ts +12 -0
  115. package/dist/querier/querierContext.browser.js +18 -0
  116. package/dist/querier/querierContext.d.ts +22 -0
  117. package/dist/querier/querierContext.js +42 -0
  118. package/dist/querier/queryError.d.ts +22 -0
  119. package/dist/querier/queryError.js +20 -0
  120. package/dist/querier/transactional.d.ts +26 -0
  121. package/dist/querier/transactional.js +43 -0
  122. package/dist/schema/canonicalType.d.ts +14 -2
  123. package/dist/schema/canonicalType.js +41 -31
  124. package/dist/schema/index.d.ts +1 -1
  125. package/dist/schema/schemaASTBuilder.d.ts +9 -2
  126. package/dist/schema/schemaASTBuilder.js +58 -49
  127. package/dist/schema/types.d.ts +10 -58
  128. package/dist/sqlite/abstractSqliteQuerier.d.ts +46 -0
  129. package/dist/sqlite/abstractSqliteQuerier.js +44 -0
  130. package/dist/sqlite/bunSqliteAdapter.bun.d.ts +26 -0
  131. package/dist/sqlite/bunSqliteAdapter.bun.js +25 -0
  132. package/dist/sqlite/hranaQuerier.d.ts +54 -0
  133. package/dist/sqlite/hranaQuerier.js +68 -0
  134. package/dist/sqlite/hranaQuerierPool.d.ts +21 -0
  135. package/dist/sqlite/hranaQuerierPool.js +25 -0
  136. package/dist/sqlite/index.d.ts +3 -1
  137. package/dist/sqlite/index.js +3 -1
  138. package/dist/sqlite/localSqliteQuerierPool.d.ts +31 -0
  139. package/dist/sqlite/localSqliteQuerierPool.js +34 -0
  140. package/dist/sqlite/nodeSqliteAdapter.d.ts +35 -0
  141. package/dist/sqlite/nodeSqliteAdapter.js +28 -0
  142. package/dist/sqlite/nodeSqliteQuerierPool.d.ts +28 -0
  143. package/dist/sqlite/nodeSqliteQuerierPool.js +29 -0
  144. package/dist/sqlite/sqliteDialect.d.ts +18 -5
  145. package/dist/sqlite/sqliteDialect.js +23 -36
  146. package/dist/sqlite/sqliteQuerier.d.ts +16 -9
  147. package/dist/sqlite/sqliteQuerier.js +4 -27
  148. package/dist/sqlite/sqliteQuerierPool.d.ts +11 -14
  149. package/dist/sqlite/sqliteQuerierPool.js +16 -24
  150. package/dist/turso/index.d.ts +3 -0
  151. package/dist/turso/index.js +3 -0
  152. package/dist/turso/local.d.ts +3 -0
  153. package/dist/turso/local.js +3 -0
  154. package/dist/turso/tursoDialect.d.ts +15 -0
  155. package/dist/turso/tursoDialect.js +18 -0
  156. package/dist/turso/tursoLocalQuerier.d.ts +25 -0
  157. package/dist/turso/tursoLocalQuerier.js +20 -0
  158. package/dist/turso/tursoLocalQuerierPool.d.ts +32 -0
  159. package/dist/turso/tursoLocalQuerierPool.js +39 -0
  160. package/dist/turso/tursoQuerier.d.ts +10 -0
  161. package/dist/turso/tursoQuerier.js +10 -0
  162. package/dist/turso/tursoQuerierPool.d.ts +39 -0
  163. package/dist/turso/tursoQuerierPool.js +38 -0
  164. package/dist/type/config.d.ts +0 -6
  165. package/dist/type/dialect.d.ts +12 -4
  166. package/dist/type/dialect.js +7 -1
  167. package/dist/type/entity.d.ts +154 -26
  168. package/dist/type/migration.d.ts +32 -23
  169. package/dist/type/querier.d.ts +6 -0
  170. package/dist/type/vector.d.ts +5 -2
  171. package/dist/util/hook.util.js +1 -1
  172. package/dist/util/index.d.ts +1 -0
  173. package/dist/util/index.js +1 -0
  174. package/dist/util/indexColumn.util.d.ts +6 -0
  175. package/dist/util/indexColumn.util.js +26 -0
  176. package/package.json +21 -16
  177. package/dist/entity/decorator/field.d.ts +0 -2
  178. package/dist/entity/decorator/field.js +0 -7
  179. package/dist/entity/decorator/filter.d.ts +0 -7
  180. package/dist/entity/decorator/filter.js +0 -11
  181. package/dist/entity/decorator/hook.d.ts +0 -7
  182. package/dist/entity/decorator/hook.js +0 -14
  183. package/dist/entity/decorator/id.d.ts +0 -2
  184. package/dist/entity/decorator/id.js +0 -7
  185. package/dist/entity/decorator/index-decorator.d.ts +0 -29
  186. package/dist/entity/decorator/index-decorator.js +0 -26
  187. package/dist/entity/decorator/index.d.ts +0 -8
  188. package/dist/entity/decorator/index.js +0 -8
  189. package/dist/entity/decorator/relation.d.ts +0 -8
  190. package/dist/entity/decorator/relation.js +0 -19
  191. package/dist/migrate/codegen/entityMerger.d.ts +0 -114
  192. package/dist/migrate/codegen/entityMerger.js +0 -293
  193. package/dist/migrate/codegen/migrationCodeGenerator.d.ts +0 -61
  194. package/dist/migrate/codegen/migrationCodeGenerator.js +0 -355
  195. package/dist/migrate/codegen/smartRelationDetector.d.ts +0 -47
  196. package/dist/migrate/codegen/smartRelationDetector.js +0 -134
  197. package/dist/migrate/generator/index.d.ts +0 -2
  198. package/dist/migrate/generator/index.js +0 -2
  199. package/dist/migrate/sync/index.d.ts +0 -6
  200. package/dist/migrate/sync/index.js +0 -6
  201. package/dist/migrate/sync/schemaSync.d.ts +0 -131
  202. package/dist/migrate/sync/schemaSync.js +0 -259
  203. package/dist/querier/decorator/index.d.ts +0 -4
  204. package/dist/querier/decorator/index.js +0 -4
  205. package/dist/querier/decorator/injectQuerier.d.ts +0 -3
  206. package/dist/querier/decorator/injectQuerier.js +0 -33
  207. package/dist/querier/decorator/log.d.ts +0 -32
  208. package/dist/querier/decorator/log.js +0 -52
  209. package/dist/querier/decorator/serialized.d.ts +0 -6
  210. package/dist/querier/decorator/serialized.js +0 -13
  211. package/dist/querier/decorator/transactional.d.ts +0 -6
  212. package/dist/querier/decorator/transactional.js +0 -48
  213. package/dist/sqlite/betterSqlite3Dialect.d.ts +0 -9
  214. package/dist/sqlite/betterSqlite3Dialect.js +0 -9
@@ -1,259 +0,0 @@
1
- /**
2
- * Schema Sync
3
- *
4
- * Orchestrates schema synchronization between entities and database
5
- * with configurable direction modes.
6
- */
7
- import { SchemaASTBuilder } from '../../schema/schemaASTBuilder.js';
8
- import { SchemaASTDiffer } from '../../schema/schemaASTDiffer.js';
9
- /**
10
- * Service for synchronizing schemas between entities and database.
11
- */
12
- export class SchemaSync {
13
- options;
14
- constructor(options) {
15
- this.options = options;
16
- }
17
- /**
18
- * Execute schema synchronization.
19
- */
20
- async sync() {
21
- const direction = this.options.direction ?? 'bidirectional';
22
- switch (direction) {
23
- case 'entity-to-db':
24
- return this.syncEntityToDb();
25
- case 'db-to-entity':
26
- return this.syncDbToEntity();
27
- case 'bidirectional':
28
- return this.syncBidirectional();
29
- }
30
- }
31
- /**
32
- * Sync from entities to database (push).
33
- */
34
- async syncEntityToDb() {
35
- const entityAST = this.buildEntityAST();
36
- const dbAST = await this.buildDatabaseAST();
37
- const differ = new SchemaASTDiffer();
38
- const diff = differ.diff(entityAST, dbAST);
39
- // In safe mode, filter out destructive changes
40
- const safeDiff = this.options.safe ? this.filterDestructiveChanges(diff) : diff;
41
- return {
42
- direction: 'entity-to-db',
43
- success: true,
44
- dbChanges: safeDiff,
45
- entityChanges: undefined,
46
- conflicts: [],
47
- summary: this.formatSummary('entity-to-db', safeDiff),
48
- details: {
49
- db: this.getDiffCounts(safeDiff),
50
- entity: { created: 0, dropped: 0, altered: 0 },
51
- },
52
- };
53
- }
54
- /**
55
- * Sync from database to entities (pull).
56
- */
57
- async syncDbToEntity() {
58
- const entityAST = this.buildEntityAST();
59
- const dbAST = await this.buildDatabaseAST();
60
- const differ = new SchemaASTDiffer();
61
- // Diff in opposite direction: DB is source, entity is target
62
- const diff = differ.diff(dbAST, entityAST);
63
- // Apply safe mode if enabled
64
- const safeDiff = this.options.safe ? this.filterDestructiveChanges(diff) : diff;
65
- return {
66
- direction: 'db-to-entity',
67
- success: true,
68
- dbChanges: undefined,
69
- entityChanges: safeDiff,
70
- conflicts: [],
71
- summary: this.formatSummary('db-to-entity', safeDiff),
72
- details: {
73
- db: { created: 0, dropped: 0, altered: 0 },
74
- entity: this.getDiffCounts(safeDiff),
75
- },
76
- };
77
- }
78
- /**
79
- * Bidirectional sync with conflict detection.
80
- */
81
- async syncBidirectional() {
82
- const entityAST = this.buildEntityAST();
83
- const dbAST = await this.buildDatabaseAST();
84
- const differ = new SchemaASTDiffer();
85
- // Get both directions
86
- const entityToDb = differ.diff(entityAST, dbAST);
87
- const dbToEntity = differ.diff(dbAST, entityAST);
88
- // Detect conflicts (changes in both directions for same elements)
89
- const conflicts = this.detectConflicts(entityToDb, dbToEntity);
90
- // Filter out conflicting changes
91
- let safeEntityToDb = this.filterConflictingChanges(entityToDb, conflicts);
92
- let safeDbToEntity = this.filterConflictingChanges(dbToEntity, conflicts);
93
- // Apply safe mode if enabled
94
- if (this.options.safe) {
95
- safeEntityToDb = this.filterDestructiveChanges(safeEntityToDb);
96
- safeDbToEntity = this.filterDestructiveChanges(safeDbToEntity);
97
- }
98
- return {
99
- direction: 'bidirectional',
100
- success: conflicts.length === 0,
101
- dbChanges: safeEntityToDb,
102
- entityChanges: safeDbToEntity,
103
- conflicts,
104
- summary: this.formatBidirectionalSummary(safeEntityToDb, safeDbToEntity, conflicts),
105
- details: {
106
- db: this.getDiffCounts(safeEntityToDb),
107
- entity: this.getDiffCounts(safeDbToEntity),
108
- },
109
- };
110
- }
111
- /**
112
- * Build SchemaAST from entities.
113
- */
114
- buildEntityAST() {
115
- const builder = new SchemaASTBuilder();
116
- return builder.fromEntities(this.options.entities);
117
- }
118
- /**
119
- * Build SchemaAST from database.
120
- */
121
- async buildDatabaseAST() {
122
- return this.options.introspector.introspect();
123
- }
124
- /**
125
- * Filter destructive changes for safe mode.
126
- */
127
- filterDestructiveChanges(diff) {
128
- return {
129
- ...diff,
130
- tablesToDrop: [], // Never drop tables in safe mode
131
- columnDiffs: diff.columnDiffs.filter((d) => d.type !== 'drop'), // Never drop columns
132
- indexDiffs: diff.indexDiffs.filter((d) => d.type !== 'drop'),
133
- relationshipDiffs: diff.relationshipDiffs.filter((d) => d.type !== 'drop'),
134
- };
135
- }
136
- /**
137
- * Detect conflicts between bidirectional changes.
138
- */
139
- detectConflicts(entityToDb, dbToEntity) {
140
- const conflicts = [];
141
- // Find column alterations that exist in both directions (type conflicts)
142
- const entityColAlters = new Map(entityToDb.columnDiffs.filter((d) => d.type === 'alter').map((d) => [`${d.table}.${d.column}`, d]));
143
- for (const dbColDiff of dbToEntity.columnDiffs.filter((d) => d.type === 'alter')) {
144
- const key = `${dbColDiff.table}.${dbColDiff.column}`;
145
- const entityColDiff = entityColAlters.get(key);
146
- if (entityColDiff) {
147
- // Both sides want to alter the same column - conflict
148
- conflicts.push({
149
- type: 'type_mismatch',
150
- table: dbColDiff.table,
151
- column: dbColDiff.column,
152
- entityValue: entityColDiff.expected?.type,
153
- dbValue: dbColDiff.expected?.type,
154
- suggestion: `Column has different types. Entity: ${this.formatType(entityColDiff.expected?.type)}, DB: ${this.formatType(dbColDiff.expected?.type)}`,
155
- });
156
- }
157
- }
158
- return conflicts;
159
- }
160
- /**
161
- * Filter out conflicting changes.
162
- */
163
- filterConflictingChanges(diff, conflicts) {
164
- const conflictKeys = new Set(conflicts.map((c) => `${c.table}.${c.column ?? ''}`));
165
- return {
166
- ...diff,
167
- columnDiffs: diff.columnDiffs.filter((d) => !conflictKeys.has(`${d.table}.${d.column}`)),
168
- tablesToAlter: diff.tablesToAlter.filter((t) => !conflictKeys.has(`${t.name}.`)),
169
- };
170
- }
171
- /**
172
- * Get counts of changes from a diff.
173
- */
174
- getDiffCounts(diff) {
175
- return {
176
- created: diff.tablesToCreate.length + diff.columnDiffs.filter((d) => d.type === 'add').length,
177
- dropped: diff.tablesToDrop.length + diff.columnDiffs.filter((d) => d.type === 'drop').length,
178
- altered: diff.columnDiffs.filter((d) => d.type === 'alter').length,
179
- };
180
- }
181
- /**
182
- * Format summary for single-direction sync.
183
- */
184
- formatSummary(direction, diff) {
185
- const lines = [];
186
- if (direction === 'entity-to-db') {
187
- lines.push('Entity → Database Changes:');
188
- }
189
- else {
190
- lines.push('Database → Entity Changes:');
191
- }
192
- if (diff.tablesToCreate.length > 0) {
193
- lines.push(` + ${diff.tablesToCreate.length} table(s) to create`);
194
- }
195
- if (diff.tablesToDrop.length > 0) {
196
- lines.push(` - ${diff.tablesToDrop.length} table(s) to drop`);
197
- }
198
- if (diff.columnDiffs.length > 0) {
199
- const adds = diff.columnDiffs.filter((d) => d.type === 'add').length;
200
- const drops = diff.columnDiffs.filter((d) => d.type === 'drop').length;
201
- const alters = diff.columnDiffs.filter((d) => d.type === 'alter').length;
202
- if (adds)
203
- lines.push(` + ${adds} column(s) to add`);
204
- if (drops)
205
- lines.push(` - ${drops} column(s) to drop`);
206
- if (alters)
207
- lines.push(` ~ ${alters} column(s) to alter`);
208
- }
209
- if (diff.indexDiffs.length > 0) {
210
- lines.push(` ${diff.indexDiffs.length} index change(s)`);
211
- }
212
- if (!diff.hasDifferences) {
213
- lines.push(' Schema is already in sync.');
214
- }
215
- return lines.join('\n');
216
- }
217
- /**
218
- * Format summary for bidirectional sync.
219
- */
220
- formatBidirectionalSummary(entityToDb, dbToEntity, conflicts) {
221
- const lines = [];
222
- lines.push('Bidirectional Sync Report');
223
- lines.push('========================\n');
224
- if (conflicts.length > 0) {
225
- lines.push(`⚠️ ${conflicts.length} conflict(s) require manual resolution:\n`);
226
- for (const conflict of conflicts) {
227
- lines.push(` • ${conflict.table}.${conflict.column ?? ''}: ${conflict.suggestion}`);
228
- }
229
- lines.push('');
230
- }
231
- if (entityToDb.hasDifferences) {
232
- lines.push('Entity → Database:');
233
- lines.push(this.formatSummary('entity-to-db', entityToDb).split('\n').slice(1).join('\n'));
234
- lines.push('');
235
- }
236
- if (dbToEntity.hasDifferences) {
237
- lines.push('Database → Entity:');
238
- lines.push(this.formatSummary('db-to-entity', dbToEntity).split('\n').slice(1).join('\n'));
239
- }
240
- if (!entityToDb.hasDifferences && !dbToEntity.hasDifferences && conflicts.length === 0) {
241
- lines.push('✓ Schema is in sync.');
242
- }
243
- return lines.join('\n');
244
- }
245
- /**
246
- * Format type for display.
247
- */
248
- formatType(type) {
249
- if (!type?.category)
250
- return 'unknown';
251
- return type.length ? `${type.category}(${type.length})` : type.category;
252
- }
253
- }
254
- /**
255
- * Create a SchemaSync instance.
256
- */
257
- export function createSchemaSync(options) {
258
- return new SchemaSync(options);
259
- }
@@ -1,4 +0,0 @@
1
- export * from './injectQuerier.js';
2
- export * from './log.js';
3
- export * from './serialized.js';
4
- export * from './transactional.js';
@@ -1,4 +0,0 @@
1
- export * from './injectQuerier.js';
2
- export * from './log.js';
3
- export * from './serialized.js';
4
- export * from './transactional.js';
@@ -1,3 +0,0 @@
1
- import type { Key, Type } from '../../type/index.js';
2
- export declare function InjectQuerier(): (proto: Record<PropertyKey, any>, key: string, index: number) => void;
3
- export declare function getInjectedQuerierIndex<S>(service: Type<S>, key: Key<S>): any;
@@ -1,33 +0,0 @@
1
- const metadataKey = Symbol('InjectQuerier');
2
- export function InjectQuerier() {
3
- // biome-ignore lint/suspicious/noExplicitAny: `any` is required - class prototypes don't satisfy Record<K, unknown>
4
- return (proto, key, index) => {
5
- if (!proto[metadataKey]) {
6
- proto[metadataKey] = new WeakMap();
7
- }
8
- if (!proto[metadataKey].has(proto.constructor)) {
9
- proto[metadataKey].set(proto.constructor, {});
10
- }
11
- const meta = proto[metadataKey].get(proto.constructor);
12
- const isAlreadyInjected = key in meta;
13
- if (isAlreadyInjected) {
14
- throw new TypeError(`@InjectQuerier() can only appears once in '${proto.constructor.name}.${key}'}`);
15
- }
16
- meta[key] = index;
17
- };
18
- }
19
- export function getInjectedQuerierIndex(service, key) {
20
- let proto = service.prototype;
21
- while (proto.constructor !== Object) {
22
- const meta = proto[metadataKey]?.get(proto.constructor);
23
- if (meta && key in meta) {
24
- return meta[key];
25
- }
26
- const keys = Object.getOwnPropertyNames(proto);
27
- const isOwnKey = keys.includes(key);
28
- if (isOwnKey) {
29
- return;
30
- }
31
- proto = Object.getPrototypeOf(proto);
32
- }
33
- }
@@ -1,32 +0,0 @@
1
- import type { LoggerWrapper } from '../../util/logger.js';
2
- /**
3
- * A driver error enriched with context by {@link enrichError}. `query` is always attached; `values`
4
- * only when the querier's logger is configured to surface them (see {@link enrichError}) - they can
5
- * carry sensitive data (PII, tokens, etc.) and would otherwise leak into whatever error-tracking
6
- * pipeline (Sentry, console.error, ...) serializes the error, without the developer opting in.
7
- */
8
- export interface QueryError extends Error {
9
- query?: string;
10
- values?: unknown[];
11
- }
12
- /**
13
- * Tags `err` with the query it failed on (as `QueryError`) and re-throws. `values` is only attached
14
- * when `logger?.willLogValues()` is true - i.e. the app already has query values surfacing somewhere
15
- * (query-level or slow-query logging), so attaching them here doesn't introduce a new leak surface.
16
- * Shared by every query call site - `@Log()`, streams, transaction statements - so this logic lives
17
- * in one place.
18
- *
19
- * Not typed `never`: an async `catch` that calls a `never`-returning function ahead of a `finally`
20
- * containing an `if` trips a TS control-flow bug (`TS7027 Unreachable code`) unrelated to this logic.
21
- */
22
- export declare function enrichError(err: unknown, logger: LoggerWrapper | undefined, query: string, values?: unknown[]): void;
23
- /**
24
- * Decorator that logs the execution of a query method.
25
- * It tracks execution time and logs the query, parameters, and duration.
26
- * The decorated class must have a `logger` property of type LoggerWrapper.
27
- *
28
- * On failure, also attaches the query (and values, when the logger surfaces them) to the thrown
29
- * error via {@link enrichError} - so that context survives even when nothing gets logged, or is
30
- * printed in full when the app already opted into it.
31
- */
32
- export declare function Log(): (_target: object, _key: string, propDescriptor: PropertyDescriptor) => void;
@@ -1,52 +0,0 @@
1
- /**
2
- * Tags `err` with the query it failed on (as `QueryError`) and re-throws. `values` is only attached
3
- * when `logger?.willLogValues()` is true - i.e. the app already has query values surfacing somewhere
4
- * (query-level or slow-query logging), so attaching them here doesn't introduce a new leak surface.
5
- * Shared by every query call site - `@Log()`, streams, transaction statements - so this logic lives
6
- * in one place.
7
- *
8
- * Not typed `never`: an async `catch` that calls a `never`-returning function ahead of a `finally`
9
- * containing an `if` trips a TS control-flow bug (`TS7027 Unreachable code`) unrelated to this logic.
10
- */
11
- export function enrichError(err, logger, query, values) {
12
- if (err instanceof Error) {
13
- const queryError = err;
14
- queryError.query ??= query;
15
- if (values !== undefined && logger?.willLogValues()) {
16
- queryError.values ??= values;
17
- }
18
- }
19
- throw err;
20
- }
21
- /**
22
- * Decorator that logs the execution of a query method.
23
- * It tracks execution time and logs the query, parameters, and duration.
24
- * The decorated class must have a `logger` property of type LoggerWrapper.
25
- *
26
- * On failure, also attaches the query (and values, when the logger surfaces them) to the thrown
27
- * error via {@link enrichError} - so that context survives even when nothing gets logged, or is
28
- * printed in full when the app already opted into it.
29
- */
30
- export function Log() {
31
- return (_target, _key, propDescriptor) => {
32
- const originalMethod = propDescriptor.value;
33
- propDescriptor.value = async function (...args) {
34
- const startTime = performance.now();
35
- const isSql = typeof args[0] === 'string';
36
- const query = isSql ? args[0] : _key;
37
- const values = isSql ? args[1] : args;
38
- try {
39
- return await originalMethod.apply(this, args);
40
- }
41
- catch (err) {
42
- enrichError(err, this.logger, query, values);
43
- }
44
- finally {
45
- if (this.logger) {
46
- const duration = performance.now() - startTime;
47
- this.logger.logQuery(query, values, Math.round(duration));
48
- }
49
- }
50
- };
51
- };
52
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Decorator that ensures the decorated method is executed serially within the Querier instance.
3
- * It uses a private promise queue to prevent race conditions on the database connection.
4
- * Note: The decorated class must extend AbstractQuerier or implement a compatible serialize method.
5
- */
6
- export declare function Serialized(): (_target: object, _key: string, propDescriptor: PropertyDescriptor) => void;
@@ -1,13 +0,0 @@
1
- /**
2
- * Decorator that ensures the decorated method is executed serially within the Querier instance.
3
- * It uses a private promise queue to prevent race conditions on the database connection.
4
- * Note: The decorated class must extend AbstractQuerier or implement a compatible serialize method.
5
- */
6
- export function Serialized() {
7
- return (_target, _key, propDescriptor) => {
8
- const originalMethod = propDescriptor.value;
9
- propDescriptor.value = function (...args) {
10
- return this.serialize(() => originalMethod.apply(this, args));
11
- };
12
- };
13
- }
@@ -1,6 +0,0 @@
1
- import type { IsolationLevel, QuerierPool } from '../../type/index.js';
2
- export declare function Transactional({ propagation, pool, isolationLevel, }?: {
3
- readonly propagation?: 'supported' | 'required';
4
- readonly pool?: QuerierPool;
5
- readonly isolationLevel?: IsolationLevel;
6
- }): (target: object, key: string, propDescriptor: PropertyDescriptor) => void;
@@ -1,48 +0,0 @@
1
- import { getQuerierPool } from '../../options.js';
2
- import { getInjectedQuerierIndex } from './injectQuerier.js';
3
- export function Transactional({ propagation = 'required', pool, isolationLevel, } = {}) {
4
- return (target, key, propDescriptor) => {
5
- // biome-ignore lint/suspicious/noExplicitAny: decorator pattern - runtime constructor type is erased
6
- const theClass = target.constructor;
7
- const originalMethod = propDescriptor.value;
8
- const injectedQuerierIndex = getInjectedQuerierIndex(theClass, key);
9
- if (injectedQuerierIndex === undefined) {
10
- throw TypeError(`missing decorator @InjectQuerier() in '${target.constructor.name}.${key}'`);
11
- }
12
- propDescriptor.value = async function func(...args) {
13
- const params = [...args];
14
- let isOwnTransaction = false;
15
- let querier;
16
- if (params[injectedQuerierIndex]) {
17
- querier = params[injectedQuerierIndex];
18
- }
19
- else {
20
- isOwnTransaction = true;
21
- pool ??= getQuerierPool();
22
- querier = await pool.getQuerier();
23
- params[injectedQuerierIndex] = querier;
24
- }
25
- try {
26
- if (propagation === 'required' && !querier.hasOpenTransaction) {
27
- await querier.beginTransaction(isolationLevel ? { isolationLevel } : undefined);
28
- }
29
- const resp = await originalMethod.apply(this, params);
30
- if (isOwnTransaction && querier.hasOpenTransaction) {
31
- await querier.commitTransaction();
32
- }
33
- return resp;
34
- }
35
- catch (err) {
36
- if (isOwnTransaction && querier.hasOpenTransaction) {
37
- await querier.rollbackTransaction();
38
- }
39
- throw err;
40
- }
41
- finally {
42
- if (isOwnTransaction) {
43
- await querier.release();
44
- }
45
- }
46
- };
47
- };
48
- }
@@ -1,9 +0,0 @@
1
- import { SqliteDialect } from './sqliteDialect.js';
2
- /**
3
- * SQLite Dialect specialization for the `better-sqlite3` driver.
4
- *
5
- * @remarks Empty subclass by design: distinct type for pools/tests that target
6
- * better-sqlite3 and a hook for future driver-specific overrides.
7
- */
8
- export declare class BetterSqlite3Dialect extends SqliteDialect {
9
- }
@@ -1,9 +0,0 @@
1
- import { SqliteDialect } from './sqliteDialect.js';
2
- /**
3
- * SQLite Dialect specialization for the `better-sqlite3` driver.
4
- *
5
- * @remarks Empty subclass by design: distinct type for pools/tests that target
6
- * better-sqlite3 and a hook for future driver-specific overrides.
7
- */
8
- export class BetterSqlite3Dialect extends SqliteDialect {
9
- }