@stonyx/orm 0.3.2-alpha.20 → 0.3.2-alpha.22
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/dynamodb-db.js +12 -3
- package/dist/serializer.js +11 -0
- package/package.json +1 -1
- package/src/dynamodb/dynamodb-db.ts +12 -2
- package/src/serializer.ts +12 -0
|
@@ -366,7 +366,11 @@ export default class DynamoDBDB {
|
|
|
366
366
|
const changedData = {};
|
|
367
367
|
for (const col of Object.keys(schema.columns)) {
|
|
368
368
|
if (currentData[col] !== oldState[col]) {
|
|
369
|
-
|
|
369
|
+
const value = currentData[col] ?? null;
|
|
370
|
+
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
371
|
+
changedData[col] = (schema.columns[col] === 'date' && value instanceof Date)
|
|
372
|
+
? value.toISOString()
|
|
373
|
+
: value;
|
|
370
374
|
}
|
|
371
375
|
}
|
|
372
376
|
// FK changes
|
|
@@ -533,8 +537,13 @@ export default class DynamoDBDB {
|
|
|
533
537
|
if (data.id !== undefined)
|
|
534
538
|
item.id = data.id;
|
|
535
539
|
for (const col of Object.keys(schema.columns)) {
|
|
536
|
-
if (data[col] !== undefined)
|
|
537
|
-
|
|
540
|
+
if (data[col] !== undefined) {
|
|
541
|
+
const value = data[col];
|
|
542
|
+
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
543
|
+
item[col] = (schema.columns[col] === 'date' && value instanceof Date)
|
|
544
|
+
? value.toISOString()
|
|
545
|
+
: value;
|
|
546
|
+
}
|
|
538
547
|
}
|
|
539
548
|
for (const fkCol of Object.keys(schema.foreignKeys)) {
|
|
540
549
|
const relName = fkCol.replace(/_id$/, '');
|
package/dist/serializer.js
CHANGED
|
@@ -105,6 +105,17 @@ export default class Serializer {
|
|
|
105
105
|
else {
|
|
106
106
|
rec[key] = childRecord;
|
|
107
107
|
relatedRecords[key] = childRecord;
|
|
108
|
+
// Preserve the raw FK value in __data when the belongsTo handler
|
|
109
|
+
// couldn't resolve the target (e.g., memory:false model not loaded).
|
|
110
|
+
// This allows adapters to read the FK from __data as a fallback
|
|
111
|
+
// when __relationships[key] is null. Only store when `data` is a
|
|
112
|
+
// truthy non-object — i.e., a raw FK string/number that the handler
|
|
113
|
+
// attempted but failed to resolve. When `data` is null/undefined
|
|
114
|
+
// (optional empty relationship) we intentionally skip to preserve
|
|
115
|
+
// the existing behavior of not populating __data for empty FKs.
|
|
116
|
+
if (childRecord === null && data && typeof data !== 'object') {
|
|
117
|
+
parsedData[key] = data;
|
|
118
|
+
}
|
|
108
119
|
}
|
|
109
120
|
continue;
|
|
110
121
|
}
|
package/package.json
CHANGED
|
@@ -523,7 +523,11 @@ export default class DynamoDBDB {
|
|
|
523
523
|
|
|
524
524
|
for (const col of Object.keys(schema.columns)) {
|
|
525
525
|
if (currentData[col] !== oldState[col]) {
|
|
526
|
-
|
|
526
|
+
const value = currentData[col] ?? null;
|
|
527
|
+
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
528
|
+
changedData[col] = (schema.columns[col] === 'date' && value instanceof Date)
|
|
529
|
+
? value.toISOString()
|
|
530
|
+
: value;
|
|
527
531
|
}
|
|
528
532
|
}
|
|
529
533
|
|
|
@@ -739,7 +743,13 @@ export default class DynamoDBDB {
|
|
|
739
743
|
if (data.id !== undefined) item.id = data.id;
|
|
740
744
|
|
|
741
745
|
for (const col of Object.keys(schema.columns)) {
|
|
742
|
-
if (data[col] !== undefined)
|
|
746
|
+
if (data[col] !== undefined) {
|
|
747
|
+
const value = data[col];
|
|
748
|
+
// Date objects must be serialized to ISO-8601 strings for DynamoDB 'S' storage
|
|
749
|
+
item[col] = (schema.columns[col] === 'date' && value instanceof Date)
|
|
750
|
+
? value.toISOString()
|
|
751
|
+
: value;
|
|
752
|
+
}
|
|
743
753
|
}
|
|
744
754
|
|
|
745
755
|
for (const fkCol of Object.keys(schema.foreignKeys)) {
|
package/src/serializer.ts
CHANGED
|
@@ -120,6 +120,18 @@ export default class Serializer {
|
|
|
120
120
|
} else {
|
|
121
121
|
rec[key] = childRecord;
|
|
122
122
|
relatedRecords[key] = childRecord;
|
|
123
|
+
|
|
124
|
+
// Preserve the raw FK value in __data when the belongsTo handler
|
|
125
|
+
// couldn't resolve the target (e.g., memory:false model not loaded).
|
|
126
|
+
// This allows adapters to read the FK from __data as a fallback
|
|
127
|
+
// when __relationships[key] is null. Only store when `data` is a
|
|
128
|
+
// truthy non-object — i.e., a raw FK string/number that the handler
|
|
129
|
+
// attempted but failed to resolve. When `data` is null/undefined
|
|
130
|
+
// (optional empty relationship) we intentionally skip to preserve
|
|
131
|
+
// the existing behavior of not populating __data for empty FKs.
|
|
132
|
+
if (childRecord === null && data && typeof data !== 'object') {
|
|
133
|
+
parsedData[key] = data;
|
|
134
|
+
}
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
continue;
|