@stonyx/orm 0.3.2-beta.81 → 0.3.2-beta.83
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.
- package/dist/dynamodb/connection.d.ts +1 -0
- package/dist/dynamodb/dynamodb-db.d.ts +1 -0
- package/dist/dynamodb/dynamodb-db.js +14 -11
- package/dist/types/orm-types.d.ts +1 -0
- package/package.json +1 -1
- package/src/dynamodb/connection.ts +1 -0
- package/src/dynamodb/dynamodb-db.ts +15 -11
- package/src/types/orm-types.ts +1 -0
|
@@ -91,6 +91,7 @@ export default class DynamoDBDB {
|
|
|
91
91
|
private _gsiRegistry;
|
|
92
92
|
constructor(deps?: Partial<DynamoDBDeps>);
|
|
93
93
|
private requireClient;
|
|
94
|
+
private _resolveTableName;
|
|
94
95
|
/** Resolve Orm singleton — falls back to real import in production. */
|
|
95
96
|
private _getOrm;
|
|
96
97
|
init(): Promise<void>;
|
|
@@ -110,6 +110,9 @@ export default class DynamoDBDB {
|
|
|
110
110
|
throw new Error('DynamoDBDB client not initialized — call init() first');
|
|
111
111
|
return this.client;
|
|
112
112
|
}
|
|
113
|
+
_resolveTableName(modelName) {
|
|
114
|
+
return (this.dbConfig.tablePrefix ?? '') + sanitizeTableName(this.deps.getPluralName(modelName));
|
|
115
|
+
}
|
|
113
116
|
/** Resolve Orm singleton — falls back to real import in production. */
|
|
114
117
|
async _getOrm() {
|
|
115
118
|
if (this.deps._importOrm)
|
|
@@ -141,7 +144,7 @@ export default class DynamoDBDB {
|
|
|
141
144
|
clientOptions.endpoint = this.dbConfig.endpoint;
|
|
142
145
|
const rawClient = new DynamoDBClient(clientOptions);
|
|
143
146
|
for (const [modelName, schema] of Object.entries(schemas)) {
|
|
144
|
-
const tableName =
|
|
147
|
+
const tableName = this._resolveTableName(modelName);
|
|
145
148
|
const gsis = this._buildGsiDefinitions(modelName, schema);
|
|
146
149
|
try {
|
|
147
150
|
const desc = await rawClient.send(new DescribeTableCommand({ TableName: tableName }));
|
|
@@ -209,7 +212,7 @@ export default class DynamoDBDB {
|
|
|
209
212
|
const schema = schemas[modelName];
|
|
210
213
|
if (!schema)
|
|
211
214
|
return undefined;
|
|
212
|
-
const tableName =
|
|
215
|
+
const tableName = this._resolveTableName(modelName);
|
|
213
216
|
const { GetCommand } = await this.deps.loadDocClientCommands();
|
|
214
217
|
const params = this.deps.buildGetItem(tableName, { id });
|
|
215
218
|
try {
|
|
@@ -237,7 +240,7 @@ export default class DynamoDBDB {
|
|
|
237
240
|
const schema = schemas[modelName];
|
|
238
241
|
if (!schema)
|
|
239
242
|
return [];
|
|
240
|
-
const tableName =
|
|
243
|
+
const tableName = this._resolveTableName(modelName);
|
|
241
244
|
try {
|
|
242
245
|
let items;
|
|
243
246
|
if (!conditions || Object.keys(conditions).length === 0) {
|
|
@@ -292,7 +295,7 @@ export default class DynamoDBDB {
|
|
|
292
295
|
continue;
|
|
293
296
|
}
|
|
294
297
|
const schema = schemas[modelName];
|
|
295
|
-
const tableName =
|
|
298
|
+
const tableName = this._resolveTableName(modelName);
|
|
296
299
|
try {
|
|
297
300
|
const items = await this._paginatedScan(tableName);
|
|
298
301
|
for (const item of items) {
|
|
@@ -325,7 +328,7 @@ export default class DynamoDBDB {
|
|
|
325
328
|
if (!record)
|
|
326
329
|
return;
|
|
327
330
|
const isPendingId = context.rawData?.__pendingSqlId === true;
|
|
328
|
-
const tableName =
|
|
331
|
+
const tableName = this._resolveTableName(modelName);
|
|
329
332
|
// For models with a pending ID, generate a unique replacement ID
|
|
330
333
|
let finalId = record.id;
|
|
331
334
|
if (isPendingId) {
|
|
@@ -358,7 +361,7 @@ export default class DynamoDBDB {
|
|
|
358
361
|
const record = context.record;
|
|
359
362
|
if (!record)
|
|
360
363
|
return;
|
|
361
|
-
const tableName =
|
|
364
|
+
const tableName = this._resolveTableName(modelName);
|
|
362
365
|
const id = record.id;
|
|
363
366
|
const oldState = context.oldState || {};
|
|
364
367
|
const currentData = record.__data;
|
|
@@ -368,7 +371,7 @@ export default class DynamoDBDB {
|
|
|
368
371
|
if (currentData[col] !== oldState[col]) {
|
|
369
372
|
const value = currentData[col] ?? null;
|
|
370
373
|
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
371
|
-
changedData[col] = (
|
|
374
|
+
changedData[col] = (value instanceof Date)
|
|
372
375
|
? value.toISOString()
|
|
373
376
|
: value;
|
|
374
377
|
}
|
|
@@ -398,7 +401,7 @@ export default class DynamoDBDB {
|
|
|
398
401
|
const id = context.recordId;
|
|
399
402
|
if (id == null)
|
|
400
403
|
return;
|
|
401
|
-
const tableName =
|
|
404
|
+
const tableName = this._resolveTableName(modelName);
|
|
402
405
|
const { DeleteCommand } = await this.deps.loadDocClientCommands();
|
|
403
406
|
const params = this.deps.buildDeleteItem(tableName, { id });
|
|
404
407
|
await this.requireClient().send(new DeleteCommand(params));
|
|
@@ -444,7 +447,7 @@ export default class DynamoDBDB {
|
|
|
444
447
|
_buildGsiRegistry() {
|
|
445
448
|
const schemas = this.deps.introspectModels();
|
|
446
449
|
for (const [modelName, schema] of Object.entries(schemas)) {
|
|
447
|
-
const tableName =
|
|
450
|
+
const tableName = this._resolveTableName(modelName);
|
|
448
451
|
const modelGsis = new Map();
|
|
449
452
|
for (const fkCol of Object.keys(schema.foreignKeys)) {
|
|
450
453
|
const gsiName = `${tableName}-${fkCol}-index`;
|
|
@@ -493,7 +496,7 @@ export default class DynamoDBDB {
|
|
|
493
496
|
});
|
|
494
497
|
}
|
|
495
498
|
_buildGsiDefinitions(modelName, schema) {
|
|
496
|
-
const tableName =
|
|
499
|
+
const tableName = this._resolveTableName(modelName);
|
|
497
500
|
const gsis = [];
|
|
498
501
|
for (const fkCol of Object.keys(schema.foreignKeys)) {
|
|
499
502
|
const gsiName = `${tableName}-${fkCol}-index`;
|
|
@@ -540,7 +543,7 @@ export default class DynamoDBDB {
|
|
|
540
543
|
if (data[col] !== undefined) {
|
|
541
544
|
const value = data[col];
|
|
542
545
|
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
543
|
-
item[col] = (
|
|
546
|
+
item[col] = (value instanceof Date)
|
|
544
547
|
? value.toISOString()
|
|
545
548
|
: value;
|
|
546
549
|
}
|
package/package.json
CHANGED
|
@@ -217,6 +217,10 @@ export default class DynamoDBDB {
|
|
|
217
217
|
return this.client;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
private _resolveTableName(modelName: string): string {
|
|
221
|
+
return (this.dbConfig.tablePrefix ?? '') + sanitizeTableName(this.deps.getPluralName(modelName));
|
|
222
|
+
}
|
|
223
|
+
|
|
220
224
|
/** Resolve Orm singleton — falls back to real import in production. */
|
|
221
225
|
private async _getOrm(): Promise<OrmModule> {
|
|
222
226
|
if (this.deps._importOrm) return this.deps._importOrm();
|
|
@@ -253,7 +257,7 @@ export default class DynamoDBDB {
|
|
|
253
257
|
const rawClient = new DynamoDBClient(clientOptions);
|
|
254
258
|
|
|
255
259
|
for (const [modelName, schema] of Object.entries(schemas)) {
|
|
256
|
-
const tableName =
|
|
260
|
+
const tableName = this._resolveTableName(modelName);
|
|
257
261
|
const gsis = this._buildGsiDefinitions(modelName, schema);
|
|
258
262
|
|
|
259
263
|
try {
|
|
@@ -338,7 +342,7 @@ export default class DynamoDBDB {
|
|
|
338
342
|
const schema = schemas[modelName];
|
|
339
343
|
if (!schema) return undefined;
|
|
340
344
|
|
|
341
|
-
const tableName =
|
|
345
|
+
const tableName = this._resolveTableName(modelName);
|
|
342
346
|
const { GetCommand } = await this.deps.loadDocClientCommands();
|
|
343
347
|
|
|
344
348
|
const params = this.deps.buildGetItem(tableName, { id });
|
|
@@ -372,7 +376,7 @@ export default class DynamoDBDB {
|
|
|
372
376
|
const schema = schemas[modelName];
|
|
373
377
|
if (!schema) return [];
|
|
374
378
|
|
|
375
|
-
const tableName =
|
|
379
|
+
const tableName = this._resolveTableName(modelName);
|
|
376
380
|
|
|
377
381
|
try {
|
|
378
382
|
let items: Record<string, unknown>[];
|
|
@@ -439,7 +443,7 @@ export default class DynamoDBDB {
|
|
|
439
443
|
}
|
|
440
444
|
|
|
441
445
|
const schema = schemas[modelName];
|
|
442
|
-
const tableName =
|
|
446
|
+
const tableName = this._resolveTableName(modelName);
|
|
443
447
|
|
|
444
448
|
try {
|
|
445
449
|
const items = await this._paginatedScan(tableName);
|
|
@@ -475,7 +479,7 @@ export default class DynamoDBDB {
|
|
|
475
479
|
if (!record) return;
|
|
476
480
|
|
|
477
481
|
const isPendingId = context.rawData?.__pendingSqlId === true;
|
|
478
|
-
const tableName =
|
|
482
|
+
const tableName = this._resolveTableName(modelName);
|
|
479
483
|
|
|
480
484
|
// For models with a pending ID, generate a unique replacement ID
|
|
481
485
|
let finalId: unknown = record.id;
|
|
@@ -513,7 +517,7 @@ export default class DynamoDBDB {
|
|
|
513
517
|
const record = context.record;
|
|
514
518
|
if (!record) return;
|
|
515
519
|
|
|
516
|
-
const tableName =
|
|
520
|
+
const tableName = this._resolveTableName(modelName);
|
|
517
521
|
const id = record.id;
|
|
518
522
|
const oldState = context.oldState || {};
|
|
519
523
|
const currentData = record.__data;
|
|
@@ -525,7 +529,7 @@ export default class DynamoDBDB {
|
|
|
525
529
|
if (currentData[col] !== oldState[col]) {
|
|
526
530
|
const value = currentData[col] ?? null;
|
|
527
531
|
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
528
|
-
changedData[col] = (
|
|
532
|
+
changedData[col] = (value instanceof Date)
|
|
529
533
|
? value.toISOString()
|
|
530
534
|
: value;
|
|
531
535
|
}
|
|
@@ -558,7 +562,7 @@ export default class DynamoDBDB {
|
|
|
558
562
|
const id = context.recordId;
|
|
559
563
|
if (id == null) return;
|
|
560
564
|
|
|
561
|
-
const tableName =
|
|
565
|
+
const tableName = this._resolveTableName(modelName);
|
|
562
566
|
const { DeleteCommand } = await this.deps.loadDocClientCommands();
|
|
563
567
|
const params = this.deps.buildDeleteItem(tableName, { id });
|
|
564
568
|
await this.requireClient().send(new DeleteCommand(params));
|
|
@@ -620,7 +624,7 @@ export default class DynamoDBDB {
|
|
|
620
624
|
const schemas = this.deps.introspectModels();
|
|
621
625
|
|
|
622
626
|
for (const [modelName, schema] of Object.entries(schemas)) {
|
|
623
|
-
const tableName =
|
|
627
|
+
const tableName = this._resolveTableName(modelName);
|
|
624
628
|
const modelGsis = new Map<string, string>();
|
|
625
629
|
|
|
626
630
|
for (const fkCol of Object.keys(schema.foreignKeys)) {
|
|
@@ -682,7 +686,7 @@ export default class DynamoDBDB {
|
|
|
682
686
|
}
|
|
683
687
|
|
|
684
688
|
private _buildGsiDefinitions(modelName: string, schema: ModelSchema): unknown[] {
|
|
685
|
-
const tableName =
|
|
689
|
+
const tableName = this._resolveTableName(modelName);
|
|
686
690
|
const gsis: unknown[] = [];
|
|
687
691
|
|
|
688
692
|
for (const fkCol of Object.keys(schema.foreignKeys)) {
|
|
@@ -746,7 +750,7 @@ export default class DynamoDBDB {
|
|
|
746
750
|
if (data[col] !== undefined) {
|
|
747
751
|
const value = data[col];
|
|
748
752
|
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
749
|
-
item[col] = (
|
|
753
|
+
item[col] = (value instanceof Date)
|
|
750
754
|
? value.toISOString()
|
|
751
755
|
: value;
|
|
752
756
|
}
|