@woltz/rich-domain-drizzle 0.1.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 (93) hide show
  1. package/dist/cjs/batch-executor.d.ts +30 -0
  2. package/dist/cjs/batch-executor.d.ts.map +1 -0
  3. package/dist/cjs/batch-executor.js +201 -0
  4. package/dist/cjs/batch-executor.js.map +1 -0
  5. package/dist/cjs/errors.d.ts +31 -0
  6. package/dist/cjs/errors.d.ts.map +1 -0
  7. package/dist/cjs/errors.js +84 -0
  8. package/dist/cjs/errors.js.map +1 -0
  9. package/dist/cjs/index.d.ts +8 -0
  10. package/dist/cjs/index.d.ts.map +1 -0
  11. package/dist/cjs/index.js +34 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/mappers/to-domain.d.ts +11 -0
  14. package/dist/cjs/mappers/to-domain.d.ts.map +1 -0
  15. package/dist/cjs/mappers/to-domain.js +15 -0
  16. package/dist/cjs/mappers/to-domain.js.map +1 -0
  17. package/dist/cjs/mappers/to-persistence.d.ts +47 -0
  18. package/dist/cjs/mappers/to-persistence.d.ts.map +1 -0
  19. package/dist/cjs/mappers/to-persistence.js +69 -0
  20. package/dist/cjs/mappers/to-persistence.js.map +1 -0
  21. package/dist/cjs/query-builder.d.ts +24 -0
  22. package/dist/cjs/query-builder.d.ts.map +1 -0
  23. package/dist/cjs/query-builder.js +146 -0
  24. package/dist/cjs/query-builder.js.map +1 -0
  25. package/dist/cjs/repository.d.ts +46 -0
  26. package/dist/cjs/repository.d.ts.map +1 -0
  27. package/dist/cjs/repository.js +192 -0
  28. package/dist/cjs/repository.js.map +1 -0
  29. package/dist/cjs/unit-of-work.d.ts +49 -0
  30. package/dist/cjs/unit-of-work.d.ts.map +1 -0
  31. package/dist/cjs/unit-of-work.js +94 -0
  32. package/dist/cjs/unit-of-work.js.map +1 -0
  33. package/dist/esm/batch-executor.d.ts +30 -0
  34. package/dist/esm/batch-executor.d.ts.map +1 -0
  35. package/dist/esm/batch-executor.js +196 -0
  36. package/dist/esm/batch-executor.js.map +1 -0
  37. package/dist/esm/errors.d.ts +31 -0
  38. package/dist/esm/errors.d.ts.map +1 -0
  39. package/dist/esm/errors.js +75 -0
  40. package/dist/esm/errors.js.map +1 -0
  41. package/dist/esm/index.d.ts +8 -0
  42. package/dist/esm/index.d.ts.map +1 -0
  43. package/dist/esm/index.js +14 -0
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/mappers/to-domain.d.ts +11 -0
  46. package/dist/esm/mappers/to-domain.d.ts.map +1 -0
  47. package/dist/esm/mappers/to-domain.js +11 -0
  48. package/dist/esm/mappers/to-domain.js.map +1 -0
  49. package/dist/esm/mappers/to-persistence.d.ts +47 -0
  50. package/dist/esm/mappers/to-persistence.d.ts.map +1 -0
  51. package/dist/esm/mappers/to-persistence.js +65 -0
  52. package/dist/esm/mappers/to-persistence.js.map +1 -0
  53. package/dist/esm/package.json +3 -0
  54. package/dist/esm/query-builder.d.ts +24 -0
  55. package/dist/esm/query-builder.d.ts.map +1 -0
  56. package/dist/esm/query-builder.js +142 -0
  57. package/dist/esm/query-builder.js.map +1 -0
  58. package/dist/esm/repository.d.ts +46 -0
  59. package/dist/esm/repository.d.ts.map +1 -0
  60. package/dist/esm/repository.js +188 -0
  61. package/dist/esm/repository.js.map +1 -0
  62. package/dist/esm/unit-of-work.d.ts +49 -0
  63. package/dist/esm/unit-of-work.d.ts.map +1 -0
  64. package/dist/esm/unit-of-work.js +87 -0
  65. package/dist/esm/unit-of-work.js.map +1 -0
  66. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  67. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  68. package/dist/tsconfig.types.tsbuildinfo +1 -0
  69. package/dist/types/batch-executor.d.ts +30 -0
  70. package/dist/types/batch-executor.d.ts.map +1 -0
  71. package/dist/types/errors.d.ts +31 -0
  72. package/dist/types/errors.d.ts.map +1 -0
  73. package/dist/types/index.d.ts +8 -0
  74. package/dist/types/index.d.ts.map +1 -0
  75. package/dist/types/mappers/to-domain.d.ts +11 -0
  76. package/dist/types/mappers/to-domain.d.ts.map +1 -0
  77. package/dist/types/mappers/to-persistence.d.ts +47 -0
  78. package/dist/types/mappers/to-persistence.d.ts.map +1 -0
  79. package/dist/types/query-builder.d.ts +24 -0
  80. package/dist/types/query-builder.d.ts.map +1 -0
  81. package/dist/types/repository.d.ts +46 -0
  82. package/dist/types/repository.d.ts.map +1 -0
  83. package/dist/types/unit-of-work.d.ts +49 -0
  84. package/dist/types/unit-of-work.d.ts.map +1 -0
  85. package/package.json +69 -0
  86. package/src/batch-executor.ts +317 -0
  87. package/src/errors.ts +78 -0
  88. package/src/index.ts +37 -0
  89. package/src/mappers/to-domain.ts +13 -0
  90. package/src/mappers/to-persistence.ts +101 -0
  91. package/src/query-builder.ts +217 -0
  92. package/src/repository.ts +252 -0
  93. package/src/unit-of-work.ts +123 -0
@@ -0,0 +1,30 @@
1
+ import { AggregateChanges, EntitySchemaRegistry } from "@woltz/rich-domain";
2
+ import { DrizzleClient } from "./unit-of-work";
3
+ export interface DrizzleBatchExecutorConfig {
4
+ registry: EntitySchemaRegistry;
5
+ db: DrizzleClient;
6
+ tableMap: Map<string, any>;
7
+ }
8
+ export declare class DrizzleBatchExecutor {
9
+ private readonly config;
10
+ constructor(config: DrizzleBatchExecutorConfig);
11
+ /**
12
+ * Execute all batch operations in order:
13
+ * 1. Deletes (leaf → root, sorted by depth DESC)
14
+ * 2. Creates (root → leaf, sorted by depth ASC)
15
+ * 3. Updates (any order)
16
+ */
17
+ execute(changes: AggregateChanges): Promise<void>;
18
+ private executeDeletes;
19
+ private executeDeleteOwned;
20
+ private executeJunctionDelete;
21
+ private executeCreates;
22
+ private executeCreateOwned;
23
+ private executeJunctionCreate;
24
+ private executeUpdates;
25
+ private getTable;
26
+ private getJunctionTable;
27
+ private extractId;
28
+ }
29
+ export declare function executeBatch(db: DrizzleClient, changes: AggregateChanges, config: Omit<DrizzleBatchExecutorConfig, "db">): Promise<void>;
30
+ //# sourceMappingURL=batch-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-executor.d.ts","sourceRoot":"","sources":["../../src/batch-executor.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EAKrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAO/C,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,EAAE,EAAE,aAAa,CAAC;IAClB,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B;AAED,qBAAa,oBAAoB;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,0BAA0B;IAE/D;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;YAUzC,cAAc;YAgCd,kBAAkB;YAoBlB,qBAAqB;YAsCrB,cAAc;YA2Bd,kBAAkB;YA6BlB,qBAAqB;YA0DrB,cAAc;IA+B5B,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,SAAS;CASlB;AAED,wBAAsB,YAAY,CAChC,EAAE,EAAE,aAAa,EACjB,OAAO,EAAE,gBAAgB,EACzB,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,IAAI,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAGf"}
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DrizzleBatchExecutor = void 0;
4
+ exports.executeBatch = executeBatch;
5
+ const drizzle_orm_1 = require("drizzle-orm");
6
+ const errors_1 = require("./errors");
7
+ class DrizzleBatchExecutor {
8
+ config;
9
+ constructor(config) {
10
+ this.config = config;
11
+ }
12
+ /**
13
+ * Execute all batch operations in order:
14
+ * 1. Deletes (leaf → root, sorted by depth DESC)
15
+ * 2. Creates (root → leaf, sorted by depth ASC)
16
+ * 3. Updates (any order)
17
+ */
18
+ async execute(changes) {
19
+ if (changes.isEmpty())
20
+ return;
21
+ const batch = changes.toBatchOperations();
22
+ await this.executeDeletes(batch.deletes);
23
+ await this.executeCreates(batch.creates);
24
+ await this.executeUpdates(batch.updates);
25
+ }
26
+ async executeDeletes(deletes) {
27
+ const sorted = [...deletes].sort((a, b) => b.depth - a.depth);
28
+ for (const del of sorted) {
29
+ const { entity, ids, relationField, parentEntity, parentId } = del;
30
+ if (relationField && parentEntity) {
31
+ this.config.registry.validateRelationField(parentEntity, relationField);
32
+ if (this.config.registry.isReferenceCollection(parentEntity, relationField)) {
33
+ await this.executeJunctionDelete(parentEntity, relationField, parentId, ids);
34
+ }
35
+ else {
36
+ await this.executeDeleteOwned(entity, ids);
37
+ }
38
+ }
39
+ else {
40
+ await this.executeDeleteOwned(entity, ids);
41
+ }
42
+ }
43
+ }
44
+ async executeDeleteOwned(entity, ids) {
45
+ if (ids.length === 0)
46
+ return;
47
+ const table = this.getTable(entity);
48
+ try {
49
+ await this.config.db.delete(table).where((0, drizzle_orm_1.inArray)(table.id, ids));
50
+ }
51
+ catch (error) {
52
+ throw new errors_1.BatchOperationError("delete", entity, error.message || "Unknown error during deletion", error);
53
+ }
54
+ }
55
+ async executeJunctionDelete(parentEntity, relationField, parentId, ids) {
56
+ if (ids.length === 0 || !parentId)
57
+ return;
58
+ const junction = this.config.registry.getJunctionConfig(parentEntity, relationField);
59
+ if (!junction) {
60
+ throw new errors_1.MissingJunctionConfigError(parentEntity, relationField);
61
+ }
62
+ const junctionTable = this.getJunctionTable(junction.table);
63
+ try {
64
+ await this.config.db
65
+ .delete(junctionTable)
66
+ .where((0, drizzle_orm_1.and)((0, drizzle_orm_1.eq)(junctionTable[junction.sourceKey], parentId), (0, drizzle_orm_1.inArray)(junctionTable[junction.targetKey], ids)));
67
+ }
68
+ catch (error) {
69
+ throw new errors_1.BatchOperationError("disconnect", junction.table, error.message || "Failed to delete from junction table", error);
70
+ }
71
+ }
72
+ async executeCreates(creates) {
73
+ const sorted = [...creates].sort((a, b) => a.depth - b.depth);
74
+ for (const create of sorted) {
75
+ const { entity, items, relationField, parentEntity } = create;
76
+ if (relationField && parentEntity) {
77
+ this.config.registry.validateRelationField(parentEntity, relationField);
78
+ if (this.config.registry.isReferenceCollection(parentEntity, relationField)) {
79
+ await this.executeJunctionCreate(parentEntity, relationField, items);
80
+ }
81
+ else {
82
+ await this.executeCreateOwned(entity, items);
83
+ }
84
+ }
85
+ else {
86
+ await this.executeCreateOwned(entity, items);
87
+ }
88
+ }
89
+ }
90
+ async executeCreateOwned(entity, items) {
91
+ if (items.length === 0)
92
+ return;
93
+ const table = this.getTable(entity);
94
+ const records = items.map((item) => {
95
+ const entityData = this.config.registry.mapEntity(entity, item.data);
96
+ const fk = item.parentId
97
+ ? this.config.registry.getParentFk(entity, item.parentId)
98
+ : null;
99
+ return { ...entityData, ...fk };
100
+ });
101
+ try {
102
+ await this.config.db.insert(table).values(records);
103
+ }
104
+ catch (error) {
105
+ throw new errors_1.BatchOperationError("create", entity, error.message || "Unknown error during creation", error);
106
+ }
107
+ }
108
+ async executeJunctionCreate(parentEntity, relationField, items) {
109
+ if (items.length === 0)
110
+ return;
111
+ const junction = this.config.registry.getJunctionConfig(parentEntity, relationField);
112
+ if (!junction) {
113
+ throw new errors_1.MissingJunctionConfigError(parentEntity, relationField);
114
+ }
115
+ const junctionTable = this.getJunctionTable(junction.table);
116
+ const grouped = new Map();
117
+ for (const item of items) {
118
+ const parentId = item.parentId;
119
+ if (!parentId)
120
+ continue;
121
+ const entityId = this.extractId(item.data);
122
+ if (!entityId)
123
+ continue;
124
+ if (!grouped.has(parentId)) {
125
+ grouped.set(parentId, []);
126
+ }
127
+ grouped.get(parentId).push(entityId);
128
+ }
129
+ const records = [];
130
+ for (const [parentId, targetIds] of grouped) {
131
+ for (const targetId of targetIds) {
132
+ records.push({
133
+ [junction.sourceKey]: parentId,
134
+ [junction.targetKey]: targetId,
135
+ });
136
+ }
137
+ }
138
+ if (records.length === 0)
139
+ return;
140
+ try {
141
+ await this.config.db
142
+ .insert(junctionTable)
143
+ .values(records)
144
+ .onConflictDoNothing();
145
+ }
146
+ catch (error) {
147
+ throw new errors_1.BatchOperationError("connect", junction.table, error.message || "Failed to insert into junction table", error);
148
+ }
149
+ }
150
+ async executeUpdates(updates) {
151
+ for (const upd of updates) {
152
+ const table = this.getTable(upd.entity);
153
+ for (const item of upd.items) {
154
+ const mappedFields = this.config.registry.mapFields(upd.entity, item.changedFields);
155
+ if (Object.keys(mappedFields).length > 0) {
156
+ try {
157
+ await this.config.db
158
+ .update(table)
159
+ .set(mappedFields)
160
+ .where((0, drizzle_orm_1.eq)(table.id, item.id));
161
+ }
162
+ catch (error) {
163
+ throw new errors_1.BatchOperationError("update", upd.entity, error.message || "Failed to update entity", error);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ getTable(entityName) {
170
+ const table = this.config.tableMap.get(entityName);
171
+ if (!table) {
172
+ throw new errors_1.TableNotFoundError(entityName, Array.from(this.config.tableMap.keys()));
173
+ }
174
+ return table;
175
+ }
176
+ getJunctionTable(tableName) {
177
+ const table = this.config.tableMap.get(tableName);
178
+ if (!table) {
179
+ throw new errors_1.TableNotFoundError(tableName, Array.from(this.config.tableMap.keys()));
180
+ }
181
+ return table;
182
+ }
183
+ extractId(data) {
184
+ if (!data)
185
+ return undefined;
186
+ if (data.id?.value !== undefined && data.id?.value !== null) {
187
+ return String(data.id.value);
188
+ }
189
+ if (typeof data.id === "string")
190
+ return data.id;
191
+ if (typeof data.id === "number")
192
+ return String(data.id);
193
+ return undefined;
194
+ }
195
+ }
196
+ exports.DrizzleBatchExecutor = DrizzleBatchExecutor;
197
+ async function executeBatch(db, changes, config) {
198
+ const executor = new DrizzleBatchExecutor({ ...config, db });
199
+ await executor.execute(changes);
200
+ }
201
+ //# sourceMappingURL=batch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,EACzB,MAA8C;IAE9C,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,31 @@
1
+ export declare class DrizzleAdapterError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class TableNotFoundError extends DrizzleAdapterError {
5
+ readonly entityName: string;
6
+ readonly availableTables: string[];
7
+ constructor(entityName: string, availableTables: string[]);
8
+ }
9
+ export declare class NoRecordsAffectedError extends DrizzleAdapterError {
10
+ readonly operation: string;
11
+ readonly entity: string;
12
+ readonly id: string;
13
+ readonly cause?: Error | undefined;
14
+ constructor(operation: string, entity: string, id: string, cause?: Error | undefined);
15
+ }
16
+ export declare class BatchOperationError extends DrizzleAdapterError {
17
+ readonly operation: string;
18
+ readonly entity: string;
19
+ readonly cause?: Error | undefined;
20
+ constructor(operation: string, entity: string, message: string, cause?: Error | undefined);
21
+ }
22
+ export declare class DrizzleRepositoryError extends DrizzleAdapterError {
23
+ readonly cause?: Error | undefined;
24
+ constructor(message: string, cause?: Error | undefined);
25
+ }
26
+ export declare class MissingJunctionConfigError extends DrizzleAdapterError {
27
+ readonly parentEntity: string;
28
+ readonly collectionField: string;
29
+ constructor(parentEntity: string, collectionField: string);
30
+ }
31
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,mBAAmB;aAEvC,UAAU,EAAE,MAAM;aAClB,eAAe,EAAE,MAAM,EAAE;gBADzB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EAAE;CAQ5C;AAED,qBAAa,sBAAuB,SAAQ,mBAAmB;aAE3C,SAAS,EAAE,MAAM;aACjB,MAAM,EAAE,MAAM;aACd,EAAE,EAAE,MAAM;aACV,KAAK,CAAC,EAAE,KAAK;gBAHb,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC;AAED,qBAAa,mBAAoB,SAAQ,mBAAmB;aAExC,SAAS,EAAE,MAAM;aACjB,MAAM,EAAE,MAAM;aAEd,KAAK,CAAC,EAAE,KAAK;gBAHb,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EAC9B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC;AAED,qBAAa,sBAAuB,SAAQ,mBAAmB;aAG3C,KAAK,CAAC,EAAE,KAAK;gBAD7B,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC;AAED,qBAAa,0BAA2B,SAAQ,mBAAmB;aAE/C,YAAY,EAAE,MAAM;aACpB,eAAe,EAAE,MAAM;gBADvB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM;CAoB1C"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingJunctionConfigError = exports.DrizzleRepositoryError = exports.BatchOperationError = exports.NoRecordsAffectedError = exports.TableNotFoundError = exports.DrizzleAdapterError = void 0;
4
+ class DrizzleAdapterError extends Error {
5
+ constructor(message) {
6
+ super(`[DrizzleAdapter] ${message}`);
7
+ this.name = "DrizzleAdapterError";
8
+ }
9
+ }
10
+ exports.DrizzleAdapterError = DrizzleAdapterError;
11
+ class TableNotFoundError extends DrizzleAdapterError {
12
+ entityName;
13
+ availableTables;
14
+ constructor(entityName, availableTables) {
15
+ super(`Table for entity "${entityName}" not found in tableMap. ` +
16
+ `Available: ${availableTables.join(", ")}`);
17
+ this.entityName = entityName;
18
+ this.availableTables = availableTables;
19
+ this.name = "TableNotFoundError";
20
+ }
21
+ }
22
+ exports.TableNotFoundError = TableNotFoundError;
23
+ class NoRecordsAffectedError extends DrizzleAdapterError {
24
+ operation;
25
+ entity;
26
+ id;
27
+ cause;
28
+ constructor(operation, entity, id, cause) {
29
+ super(`${operation} on ${entity} (id: ${id}) affected 0 records`);
30
+ this.operation = operation;
31
+ this.entity = entity;
32
+ this.id = id;
33
+ this.cause = cause;
34
+ this.name = "NoRecordsAffectedError";
35
+ }
36
+ }
37
+ exports.NoRecordsAffectedError = NoRecordsAffectedError;
38
+ class BatchOperationError extends DrizzleAdapterError {
39
+ operation;
40
+ entity;
41
+ cause;
42
+ constructor(operation, entity, message, cause) {
43
+ super(`Batch ${operation} on ${entity} failed: ${message}`);
44
+ this.operation = operation;
45
+ this.entity = entity;
46
+ this.cause = cause;
47
+ this.name = "BatchOperationError";
48
+ }
49
+ }
50
+ exports.BatchOperationError = BatchOperationError;
51
+ class DrizzleRepositoryError extends DrizzleAdapterError {
52
+ cause;
53
+ constructor(message, cause) {
54
+ super(message);
55
+ this.cause = cause;
56
+ this.name = "DrizzleRepositoryError";
57
+ }
58
+ }
59
+ exports.DrizzleRepositoryError = DrizzleRepositoryError;
60
+ class MissingJunctionConfigError extends DrizzleAdapterError {
61
+ parentEntity;
62
+ collectionField;
63
+ constructor(parentEntity, collectionField) {
64
+ super(`Collection "${collectionField}" on entity "${parentEntity}" is of type "reference" but has no junction configured. ` +
65
+ `Drizzle does not manage junction tables automatically — you must provide the junction config. ` +
66
+ `Example:\n` +
67
+ ` collections: {\n` +
68
+ ` ${collectionField}: {\n` +
69
+ ` type: "reference",\n` +
70
+ ` entity: "TargetEntity",\n` +
71
+ ` junction: {\n` +
72
+ ` table: "${parentEntity.toLowerCase()}_${collectionField}",\n` +
73
+ ` sourceKey: "${parentEntity.toLowerCase()}Id",\n` +
74
+ ` targetKey: "targetEntityId",\n` +
75
+ ` },\n` +
76
+ ` },\n` +
77
+ ` }`);
78
+ this.parentEntity = parentEntity;
79
+ this.collectionField = collectionField;
80
+ this.name = "MissingJunctionConfigError";
81
+ }
82
+ }
83
+ exports.MissingJunctionConfigError = MissingJunctionConfigError;
84
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC;AAED,MAAa,kBAAmB,SAAQ,mBAAmB;IAEvC;IACA;IAFlB,YACkB,UAAkB,EAClB,eAAyB;QAEzC,KAAK,CACH,qBAAqB,UAAU,2BAA2B;YACxD,cAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC7C,CAAC;QANc,eAAU,GAAV,UAAU,CAAQ;QAClB,oBAAe,GAAf,eAAe,CAAU;QAMzC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAXD,gDAWC;AAED,MAAa,sBAAuB,SAAQ,mBAAmB;IAE3C;IACA;IACA;IACA;IAJlB,YACkB,SAAiB,EACjB,MAAc,EACd,EAAU,EACV,KAAa;QAE7B,KAAK,CAAC,GAAG,SAAS,OAAO,MAAM,SAAS,EAAE,sBAAsB,CAAC,CAAC;QALlD,cAAS,GAAT,SAAS,CAAQ;QACjB,WAAM,GAAN,MAAM,CAAQ;QACd,OAAE,GAAF,EAAE,CAAQ;QACV,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAVD,wDAUC;AAED,MAAa,mBAAoB,SAAQ,mBAAmB;IAExC;IACA;IAEA;IAJlB,YACkB,SAAiB,EACjB,MAAc,EAC9B,OAAe,EACC,KAAa;QAE7B,KAAK,CAAC,SAAS,SAAS,OAAO,MAAM,YAAY,OAAO,EAAE,CAAC,CAAC;QAL5C,cAAS,GAAT,SAAS,CAAQ;QACjB,WAAM,GAAN,MAAM,CAAQ;QAEd,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAVD,kDAUC;AAED,MAAa,sBAAuB,SAAQ,mBAAmB;IAG3C;IAFlB,YACE,OAAe,EACC,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AARD,wDAQC;AAED,MAAa,0BAA2B,SAAQ,mBAAmB;IAE/C;IACA;IAFlB,YACkB,YAAoB,EACpB,eAAuB;QAEvC,KAAK,CACH,eAAe,eAAe,gBAAgB,YAAY,2DAA2D;YACnH,gGAAgG;YAChG,YAAY;YACZ,oBAAoB;YACpB,OAAO,eAAe,OAAO;YAC7B,4BAA4B;YAC5B,iCAAiC;YACjC,qBAAqB;YACrB,mBAAmB,YAAY,CAAC,WAAW,EAAE,IAAI,eAAe,MAAM;YACtE,uBAAuB,YAAY,CAAC,WAAW,EAAE,QAAQ;YACzD,wCAAwC;YACxC,YAAY;YACZ,UAAU;YACV,KAAK,CACR,CAAC;QAlBc,iBAAY,GAAZ,YAAY,CAAQ;QACpB,oBAAe,GAAf,eAAe,CAAQ;QAkBvC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAvBD,gEAuBC"}
@@ -0,0 +1,8 @@
1
+ export { DrizzleUnitOfWork, DrizzleTransactionContext, UOWStorage, Transactional, getCurrentDrizzleContext, type DrizzleClient, type DrizzleTransactionClient, } from "./unit-of-work";
2
+ export { DrizzleRepository, type DrizzleRepositoryConfig } from "./repository";
3
+ export { DrizzleToPersistence } from "./mappers/to-persistence";
4
+ export { DrizzleToDomain } from "./mappers/to-domain";
5
+ export { DrizzleBatchExecutor, executeBatch, type DrizzleBatchExecutorConfig, } from "./batch-executor";
6
+ export { DrizzleQueryBuilder, type SearchableField } from "./query-builder";
7
+ export { DrizzleAdapterError, TableNotFoundError, NoRecordsAffectedError, BatchOperationError, DrizzleRepositoryError, MissingJunctionConfigError, } from "./errors";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,UAAU,EACV,aAAa,EACb,wBAAwB,EACxB,KAAK,aAAa,EAClB,KAAK,wBAAwB,GAC9B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAG/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,KAAK,0BAA0B,GAChC,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAG5E,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,UAAU,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingJunctionConfigError = exports.DrizzleRepositoryError = exports.BatchOperationError = exports.NoRecordsAffectedError = exports.TableNotFoundError = exports.DrizzleAdapterError = exports.DrizzleQueryBuilder = exports.executeBatch = exports.DrizzleBatchExecutor = exports.DrizzleToDomain = exports.DrizzleToPersistence = exports.DrizzleRepository = exports.getCurrentDrizzleContext = exports.Transactional = exports.UOWStorage = exports.DrizzleTransactionContext = exports.DrizzleUnitOfWork = void 0;
4
+ // Unit of Work
5
+ var unit_of_work_1 = require("./unit-of-work");
6
+ Object.defineProperty(exports, "DrizzleUnitOfWork", { enumerable: true, get: function () { return unit_of_work_1.DrizzleUnitOfWork; } });
7
+ Object.defineProperty(exports, "DrizzleTransactionContext", { enumerable: true, get: function () { return unit_of_work_1.DrizzleTransactionContext; } });
8
+ Object.defineProperty(exports, "UOWStorage", { enumerable: true, get: function () { return unit_of_work_1.UOWStorage; } });
9
+ Object.defineProperty(exports, "Transactional", { enumerable: true, get: function () { return unit_of_work_1.Transactional; } });
10
+ Object.defineProperty(exports, "getCurrentDrizzleContext", { enumerable: true, get: function () { return unit_of_work_1.getCurrentDrizzleContext; } });
11
+ // Repository
12
+ var repository_1 = require("./repository");
13
+ Object.defineProperty(exports, "DrizzleRepository", { enumerable: true, get: function () { return repository_1.DrizzleRepository; } });
14
+ // Mappers
15
+ var to_persistence_1 = require("./mappers/to-persistence");
16
+ Object.defineProperty(exports, "DrizzleToPersistence", { enumerable: true, get: function () { return to_persistence_1.DrizzleToPersistence; } });
17
+ var to_domain_1 = require("./mappers/to-domain");
18
+ Object.defineProperty(exports, "DrizzleToDomain", { enumerable: true, get: function () { return to_domain_1.DrizzleToDomain; } });
19
+ // Batch Executor
20
+ var batch_executor_1 = require("./batch-executor");
21
+ Object.defineProperty(exports, "DrizzleBatchExecutor", { enumerable: true, get: function () { return batch_executor_1.DrizzleBatchExecutor; } });
22
+ Object.defineProperty(exports, "executeBatch", { enumerable: true, get: function () { return batch_executor_1.executeBatch; } });
23
+ // Query Builder
24
+ var query_builder_1 = require("./query-builder");
25
+ Object.defineProperty(exports, "DrizzleQueryBuilder", { enumerable: true, get: function () { return query_builder_1.DrizzleQueryBuilder; } });
26
+ // Errors
27
+ var errors_1 = require("./errors");
28
+ Object.defineProperty(exports, "DrizzleAdapterError", { enumerable: true, get: function () { return errors_1.DrizzleAdapterError; } });
29
+ Object.defineProperty(exports, "TableNotFoundError", { enumerable: true, get: function () { return errors_1.TableNotFoundError; } });
30
+ Object.defineProperty(exports, "NoRecordsAffectedError", { enumerable: true, get: function () { return errors_1.NoRecordsAffectedError; } });
31
+ Object.defineProperty(exports, "BatchOperationError", { enumerable: true, get: function () { return errors_1.BatchOperationError; } });
32
+ Object.defineProperty(exports, "DrizzleRepositoryError", { enumerable: true, get: function () { return errors_1.DrizzleRepositoryError; } });
33
+ Object.defineProperty(exports, "MissingJunctionConfigError", { enumerable: true, get: function () { return errors_1.MissingJunctionConfigError; } });
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,+CAQwB;AAPtB,iHAAA,iBAAiB,OAAA;AACjB,yHAAA,yBAAyB,OAAA;AACzB,0GAAA,UAAU,OAAA;AACV,6GAAA,aAAa,OAAA;AACb,wHAAA,wBAAwB,OAAA;AAK1B,aAAa;AACb,2CAA+E;AAAtE,+GAAA,iBAAiB,OAAA;AAE1B,UAAU;AACV,2DAAgE;AAAvD,sHAAA,oBAAoB,OAAA;AAC7B,iDAAsD;AAA7C,4GAAA,eAAe,OAAA;AAExB,iBAAiB;AACjB,mDAI0B;AAHxB,sHAAA,oBAAoB,OAAA;AACpB,8GAAA,YAAY,OAAA;AAId,gBAAgB;AAChB,iDAA4E;AAAnE,oHAAA,mBAAmB,OAAA;AAE5B,SAAS;AACT,mCAOkB;AANhB,6GAAA,mBAAmB,OAAA;AACnB,4GAAA,kBAAkB,OAAA;AAClB,gHAAA,sBAAsB,OAAA;AACtB,6GAAA,mBAAmB,OAAA;AACnB,gHAAA,sBAAsB,OAAA;AACtB,oHAAA,0BAA0B,OAAA"}
@@ -0,0 +1,11 @@
1
+ import { Mapper } from "@woltz/rich-domain";
2
+ /**
3
+ * Base class for mapping Drizzle query results to domain entities.
4
+ * Subclass and implement build() to transform DB records to domain aggregates.
5
+ *
6
+ * This is identical to a plain Mapper<TPersistence, TDomain>.
7
+ * Provided for naming consistency with the adapter pattern.
8
+ */
9
+ export declare abstract class DrizzleToDomain<TPersistence, TDomain> extends Mapper<TPersistence, TDomain> {
10
+ }
11
+ //# sourceMappingURL=to-domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-domain.d.ts","sourceRoot":"","sources":["../../../src/mappers/to-domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;;;;;GAMG;AACH,8BAAsB,eAAe,CAAC,YAAY,EAAE,OAAO,CAAE,SAAQ,MAAM,CACzE,YAAY,EACZ,OAAO,CACR;CAAG"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DrizzleToDomain = void 0;
4
+ const rich_domain_1 = require("@woltz/rich-domain");
5
+ /**
6
+ * Base class for mapping Drizzle query results to domain entities.
7
+ * Subclass and implement build() to transform DB records to domain aggregates.
8
+ *
9
+ * This is identical to a plain Mapper<TPersistence, TDomain>.
10
+ * Provided for naming consistency with the adapter pattern.
11
+ */
12
+ class DrizzleToDomain extends rich_domain_1.Mapper {
13
+ }
14
+ exports.DrizzleToDomain = DrizzleToDomain;
15
+ //# sourceMappingURL=to-domain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-domain.js","sourceRoot":"","sources":["../../../src/mappers/to-domain.ts"],"names":[],"mappings":";;;AAAA,oDAA4C;AAE5C;;;;;;GAMG;AACH,MAAsB,eAAuC,SAAQ,oBAGpE;CAAG;AAHJ,0CAGI"}
@@ -0,0 +1,47 @@
1
+ import { Mapper, AggregateChanges, EntitySchemaRegistry } from "@woltz/rich-domain";
2
+ import { DrizzleClient, DrizzleUnitOfWork } from "../unit-of-work";
3
+ export declare abstract class DrizzleToPersistence<TDomain> extends Mapper<TDomain, void> {
4
+ protected readonly uow: DrizzleUnitOfWork;
5
+ constructor(uow: DrizzleUnitOfWork);
6
+ /**
7
+ * Schema registry for field mapping (entity → table, field → column).
8
+ */
9
+ protected abstract readonly registry: EntitySchemaRegistry;
10
+ /**
11
+ * Map of entity names to Drizzle table objects.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * protected readonly tableMap = new Map([
16
+ * ["User", usersTable],
17
+ * ["Post", postsTable],
18
+ * ]);
19
+ * ```
20
+ */
21
+ protected abstract readonly tableMap: Map<string, any>;
22
+ /**
23
+ * Get the raw db instance.
24
+ */
25
+ protected abstract getDb(): DrizzleClient;
26
+ /**
27
+ * Get current context (transaction client or raw db).
28
+ */
29
+ protected get context(): DrizzleClient;
30
+ /**
31
+ * Build persistence operations.
32
+ */
33
+ build(entity: TDomain): Promise<void>;
34
+ /**
35
+ * Handle new aggregate creation.
36
+ * Must be implemented by subclass.
37
+ */
38
+ protected abstract onCreate(aggregate: TDomain): Promise<void>;
39
+ /**
40
+ * Handle aggregate update with changes.
41
+ * Default implementation uses DrizzleBatchExecutor.
42
+ * Subclass can override for custom logic.
43
+ */
44
+ protected onUpdate(changes: AggregateChanges, _aggregate: TDomain): Promise<void>;
45
+ private handleUpdate;
46
+ }
47
+ //# sourceMappingURL=to-persistence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-persistence.d.ts","sourceRoot":"","sources":["../../../src/mappers/to-persistence.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,iBAAiB,EAGlB,MAAM,iBAAiB,CAAC;AAGzB,8BAAsB,oBAAoB,CAAC,OAAO,CAAE,SAAQ,MAAM,CAChE,OAAO,EACP,IAAI,CACL;IACa,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,iBAAiB;gBAAtB,GAAG,EAAE,iBAAiB;IAIrD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IAE3D;;;;;;;;;;OAUG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEvD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,aAAa;IAEzC;;OAEG;IACH,SAAS,KAAK,OAAO,IAAI,aAAa,CAGrC;IAED;;OAEG;IACG,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9D;;;;OAIG;cACa,QAAQ,CACtB,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,IAAI,CAAC;YAUF,YAAY;CAW3B"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DrizzleToPersistence = void 0;
13
+ const rich_domain_1 = require("@woltz/rich-domain");
14
+ const unit_of_work_1 = require("../unit-of-work");
15
+ const batch_executor_1 = require("../batch-executor");
16
+ class DrizzleToPersistence extends rich_domain_1.Mapper {
17
+ uow;
18
+ constructor(uow) {
19
+ super();
20
+ this.uow = uow;
21
+ }
22
+ /**
23
+ * Get current context (transaction client or raw db).
24
+ */
25
+ get context() {
26
+ const ctx = unit_of_work_1.UOWStorage.getStore()?.ctx;
27
+ return ctx?.client ?? this.getDb();
28
+ }
29
+ /**
30
+ * Build persistence operations.
31
+ */
32
+ async build(entity) {
33
+ const isNew = entity.isNew?.() ?? false;
34
+ if (isNew) {
35
+ await this.onCreate(entity);
36
+ }
37
+ else {
38
+ await this.handleUpdate(entity);
39
+ }
40
+ }
41
+ /**
42
+ * Handle aggregate update with changes.
43
+ * Default implementation uses DrizzleBatchExecutor.
44
+ * Subclass can override for custom logic.
45
+ */
46
+ async onUpdate(changes, _aggregate) {
47
+ const executor = new batch_executor_1.DrizzleBatchExecutor({
48
+ registry: this.registry,
49
+ db: this.context,
50
+ tableMap: this.tableMap,
51
+ });
52
+ await executor.execute(changes);
53
+ }
54
+ async handleUpdate(entity) {
55
+ const changes = entity.getChanges?.();
56
+ if (!changes || changes.isEmpty()) {
57
+ return;
58
+ }
59
+ await this.onUpdate(changes, entity);
60
+ }
61
+ }
62
+ exports.DrizzleToPersistence = DrizzleToPersistence;
63
+ __decorate([
64
+ (0, unit_of_work_1.Transactional)(),
65
+ __metadata("design:type", Function),
66
+ __metadata("design:paramtypes", [Object]),
67
+ __metadata("design:returntype", Promise)
68
+ ], DrizzleToPersistence.prototype, "handleUpdate", null);
69
+ //# sourceMappingURL=to-persistence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to-persistence.js","sourceRoot":"","sources":["../../../src/mappers/to-persistence.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAI4B;AAC5B,kDAKyB;AACzB,sDAAyD;AAEzD,MAAsB,oBAA8B,SAAQ,oBAG3D;IACgC;IAA/B,YAA+B,GAAsB;QACnD,KAAK,EAAE,CAAC;QADqB,QAAG,GAAH,GAAG,CAAmB;IAErD,CAAC;IAyBD;;OAEG;IACH,IAAc,OAAO;QACnB,MAAM,GAAG,GAAG,yBAAU,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC;QACvC,OAAO,GAAG,EAAE,MAAM,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,MAAe;QACzB,MAAM,KAAK,GAAI,MAAc,CAAC,KAAK,EAAE,EAAE,IAAI,KAAK,CAAC;QAEjD,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAQD;;;;OAIG;IACO,KAAK,CAAC,QAAQ,CACtB,OAAyB,EACzB,UAAmB;QAEnB,MAAM,QAAQ,GAAG,IAAI,qCAAoB,CAAC;YACxC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,EAAE,EAAE,IAAI,CAAC,OAAO;YAChB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAGa,AAAN,KAAK,CAAC,YAAY,CAAC,MAAe;QACxC,MAAM,OAAO,GAAI,MAAc,CAAC,UAAU,EAAE,EAE/B,CAAC;QAEd,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAClC,OAAO;QACT,CAAC;QAED,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CACF;AAvFD,oDAuFC;AAXe;IADb,IAAA,4BAAa,GAAE;;;;wDAWf"}
@@ -0,0 +1,24 @@
1
+ import { SQL } from "drizzle-orm";
2
+ import { Criteria } from "@woltz/rich-domain";
3
+ export type SearchableField<T> = keyof T | {
4
+ field: string;
5
+ caseSensitive?: boolean;
6
+ };
7
+ export declare class DrizzleQueryBuilder {
8
+ /**
9
+ * Apply Criteria to a Drizzle select query.
10
+ *
11
+ * @param criteria - The Criteria instance with filters, orders, pagination, search
12
+ * @param table - The Drizzle table object (e.g., usersTable)
13
+ * @param searchableFields - Fields to search when criteria.hasSearch()
14
+ * @returns Object with { where, orderBy, limit, offset } ready for Drizzle query
15
+ */
16
+ static apply<T>(criteria: Criteria<T>, table: any, searchableFields?: SearchableField<any>[]): {
17
+ where?: SQL;
18
+ orderBy?: SQL[];
19
+ limit?: number;
20
+ offset?: number;
21
+ };
22
+ static resolveColumn(table: any, fieldPath: string): any;
23
+ }
24
+ //# sourceMappingURL=query-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../../src/query-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAkBL,GAAG,EACJ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG9C,MAAM,MAAM,eAAe,CAAC,CAAC,IACzB,MAAM,CAAC,GACP;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAqB/C,qBAAa,mBAAmB;IAC9B;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,CAAC,EACZ,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,KAAK,EAAE,GAAG,EACV,gBAAgB,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,GACxC;QACD,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAqJD,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG;CAGzD"}