imean-cassandra-orm 2.0.1 → 2.0.2
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/mod.cjs +45 -10
- package/dist/mod.js +45 -10
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -56,16 +56,26 @@ function convertZodToCassandraType(schema) {
|
|
|
56
56
|
}
|
|
57
57
|
function getNewFields(schemaFields, tableMetadata2) {
|
|
58
58
|
return schemaFields.filter(
|
|
59
|
-
(field) => !tableMetadata2.some(
|
|
59
|
+
(field) => !tableMetadata2.some(
|
|
60
|
+
(t) => t.column_name.toLowerCase() === field.toLowerCase()
|
|
61
|
+
)
|
|
60
62
|
);
|
|
61
63
|
}
|
|
62
64
|
function getDeletedFields(schemaFields, tableMetadata2) {
|
|
63
|
-
return tableMetadata2.filter((t) => !schemaFields.
|
|
65
|
+
return tableMetadata2.filter((t) => !schemaFields.some(
|
|
66
|
+
(field) => field.toLowerCase() === t.column_name.toLowerCase()
|
|
67
|
+
)).map((t) => t.column_name);
|
|
64
68
|
}
|
|
65
69
|
function getUpdatedFields(schemaFields, tableMetadata2, shape) {
|
|
66
70
|
return schemaFields.filter(
|
|
67
71
|
(field) => tableMetadata2.some(
|
|
68
|
-
(t) =>
|
|
72
|
+
(t) => {
|
|
73
|
+
const dbFieldName = t.column_name;
|
|
74
|
+
const schemaFieldName = field;
|
|
75
|
+
const dbType = t.type;
|
|
76
|
+
const schemaType = convertZodToCassandraType(shape[field]);
|
|
77
|
+
return dbFieldName.toLowerCase() === schemaFieldName.toLowerCase() && dbType !== schemaType;
|
|
78
|
+
}
|
|
69
79
|
)
|
|
70
80
|
);
|
|
71
81
|
}
|
|
@@ -298,8 +308,34 @@ function buildDeleteCql(schema, partitionKey, clusteringKey) {
|
|
|
298
308
|
}
|
|
299
309
|
function convertRowToObject(row, fieldConfigs, zodSchema) {
|
|
300
310
|
const result = {};
|
|
311
|
+
const fieldNameMap = /* @__PURE__ */ new Map();
|
|
312
|
+
Object.keys(fieldConfigs).forEach((camelCaseName) => {
|
|
313
|
+
fieldNameMap.set(camelCaseName.toLowerCase(), camelCaseName);
|
|
314
|
+
});
|
|
301
315
|
Object.entries(fieldConfigs).forEach(([fieldName, config]) => {
|
|
302
|
-
const
|
|
316
|
+
const possibleNames = [
|
|
317
|
+
fieldName,
|
|
318
|
+
// 原始驼峰名
|
|
319
|
+
fieldName.toLowerCase(),
|
|
320
|
+
// 全小写
|
|
321
|
+
fieldName.toUpperCase()
|
|
322
|
+
// 全大写
|
|
323
|
+
];
|
|
324
|
+
let value = void 0;
|
|
325
|
+
for (const possibleName of possibleNames) {
|
|
326
|
+
if (possibleName in row) {
|
|
327
|
+
value = row[possibleName];
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (value === void 0) {
|
|
332
|
+
for (const [dbFieldName, dbValue] of Object.entries(row)) {
|
|
333
|
+
if (dbFieldName.toLowerCase() === fieldName.toLowerCase()) {
|
|
334
|
+
value = dbValue;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
303
339
|
if (value !== void 0) {
|
|
304
340
|
result[fieldName] = convertValueFromCassandra(value, config);
|
|
305
341
|
}
|
|
@@ -584,13 +620,14 @@ var Model = class _Model {
|
|
|
584
620
|
}
|
|
585
621
|
if (updatedFields.length > 0) {
|
|
586
622
|
const fieldDetails = updatedFields.map((field) => {
|
|
587
|
-
const
|
|
623
|
+
const meta = tableMetadata2.find((t) => t.column_name.toLowerCase() === field.toLowerCase());
|
|
624
|
+
const existingType = meta?.type || "unknown";
|
|
588
625
|
const newType = convertZodToCassandraType(
|
|
589
626
|
this.schema.fields.shape[field]
|
|
590
627
|
);
|
|
591
628
|
return `${field}(${existingType} -> ${newType})`;
|
|
592
629
|
}).join(", ");
|
|
593
|
-
errorReason =
|
|
630
|
+
errorReason = `[${this.schema.keyspace}.${this.schema.tableName}] \u5B57\u6BB5\u7C7B\u578B\u6709\u66F4\u65B0\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u53D8\u66F4\u5B57\u6BB5: ${fieldDetails}`;
|
|
594
631
|
}
|
|
595
632
|
if (hasKeyFieldChanged(this.schema, newFields, deletedFields)) {
|
|
596
633
|
const partitionKeyFields = this.schema.partitionKeyFields;
|
|
@@ -611,9 +648,7 @@ var Model = class _Model {
|
|
|
611
648
|
if (deletedKeyFields.length > 0) {
|
|
612
649
|
keyChangeDetails.push(`\u5220\u9664\u952E\u5B57\u6BB5: ${deletedKeyFields.join(", ")}`);
|
|
613
650
|
}
|
|
614
|
-
errorReason =
|
|
615
|
-
"; "
|
|
616
|
-
)}`;
|
|
651
|
+
errorReason = `[${this.schema.keyspace}.${this.schema.tableName}] \u952E\u5B57\u6BB5\u53D1\u751F\u53D8\u66F4\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002${keyChangeDetails.join("; ")}`;
|
|
617
652
|
}
|
|
618
653
|
if (isClusteringKeyChanged(this.schema, tableMetadata2)) {
|
|
619
654
|
const existingClusteringKeys = tableMetadata2.filter((t) => t.kind === "clustering").map((t) => t.column_name);
|
|
@@ -622,7 +657,7 @@ var Model = class _Model {
|
|
|
622
657
|
);
|
|
623
658
|
const existingOrder = existingClusteringKeys.join(", ");
|
|
624
659
|
const currentOrder = currentClusteringKeys.join(", ");
|
|
625
|
-
errorReason =
|
|
660
|
+
errorReason = `[${this.schema.keyspace}.${this.schema.tableName}] \u805A\u7C7B\u952E\u914D\u7F6E\u53D1\u751F\u53D8\u5316\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u73B0\u6709\u987A\u5E8F: [${existingOrder}]\uFF0C\u65B0\u987A\u5E8F: [${currentOrder}]`;
|
|
626
661
|
}
|
|
627
662
|
}
|
|
628
663
|
if (errorReason) {
|
package/dist/mod.js
CHANGED
|
@@ -54,16 +54,26 @@ function convertZodToCassandraType(schema) {
|
|
|
54
54
|
}
|
|
55
55
|
function getNewFields(schemaFields, tableMetadata2) {
|
|
56
56
|
return schemaFields.filter(
|
|
57
|
-
(field) => !tableMetadata2.some(
|
|
57
|
+
(field) => !tableMetadata2.some(
|
|
58
|
+
(t) => t.column_name.toLowerCase() === field.toLowerCase()
|
|
59
|
+
)
|
|
58
60
|
);
|
|
59
61
|
}
|
|
60
62
|
function getDeletedFields(schemaFields, tableMetadata2) {
|
|
61
|
-
return tableMetadata2.filter((t) => !schemaFields.
|
|
63
|
+
return tableMetadata2.filter((t) => !schemaFields.some(
|
|
64
|
+
(field) => field.toLowerCase() === t.column_name.toLowerCase()
|
|
65
|
+
)).map((t) => t.column_name);
|
|
62
66
|
}
|
|
63
67
|
function getUpdatedFields(schemaFields, tableMetadata2, shape) {
|
|
64
68
|
return schemaFields.filter(
|
|
65
69
|
(field) => tableMetadata2.some(
|
|
66
|
-
(t) =>
|
|
70
|
+
(t) => {
|
|
71
|
+
const dbFieldName = t.column_name;
|
|
72
|
+
const schemaFieldName = field;
|
|
73
|
+
const dbType = t.type;
|
|
74
|
+
const schemaType = convertZodToCassandraType(shape[field]);
|
|
75
|
+
return dbFieldName.toLowerCase() === schemaFieldName.toLowerCase() && dbType !== schemaType;
|
|
76
|
+
}
|
|
67
77
|
)
|
|
68
78
|
);
|
|
69
79
|
}
|
|
@@ -296,8 +306,34 @@ function buildDeleteCql(schema, partitionKey, clusteringKey) {
|
|
|
296
306
|
}
|
|
297
307
|
function convertRowToObject(row, fieldConfigs, zodSchema) {
|
|
298
308
|
const result = {};
|
|
309
|
+
const fieldNameMap = /* @__PURE__ */ new Map();
|
|
310
|
+
Object.keys(fieldConfigs).forEach((camelCaseName) => {
|
|
311
|
+
fieldNameMap.set(camelCaseName.toLowerCase(), camelCaseName);
|
|
312
|
+
});
|
|
299
313
|
Object.entries(fieldConfigs).forEach(([fieldName, config]) => {
|
|
300
|
-
const
|
|
314
|
+
const possibleNames = [
|
|
315
|
+
fieldName,
|
|
316
|
+
// 原始驼峰名
|
|
317
|
+
fieldName.toLowerCase(),
|
|
318
|
+
// 全小写
|
|
319
|
+
fieldName.toUpperCase()
|
|
320
|
+
// 全大写
|
|
321
|
+
];
|
|
322
|
+
let value = void 0;
|
|
323
|
+
for (const possibleName of possibleNames) {
|
|
324
|
+
if (possibleName in row) {
|
|
325
|
+
value = row[possibleName];
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (value === void 0) {
|
|
330
|
+
for (const [dbFieldName, dbValue] of Object.entries(row)) {
|
|
331
|
+
if (dbFieldName.toLowerCase() === fieldName.toLowerCase()) {
|
|
332
|
+
value = dbValue;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
301
337
|
if (value !== void 0) {
|
|
302
338
|
result[fieldName] = convertValueFromCassandra(value, config);
|
|
303
339
|
}
|
|
@@ -582,13 +618,14 @@ var Model = class _Model {
|
|
|
582
618
|
}
|
|
583
619
|
if (updatedFields.length > 0) {
|
|
584
620
|
const fieldDetails = updatedFields.map((field) => {
|
|
585
|
-
const
|
|
621
|
+
const meta = tableMetadata2.find((t) => t.column_name.toLowerCase() === field.toLowerCase());
|
|
622
|
+
const existingType = meta?.type || "unknown";
|
|
586
623
|
const newType = convertZodToCassandraType(
|
|
587
624
|
this.schema.fields.shape[field]
|
|
588
625
|
);
|
|
589
626
|
return `${field}(${existingType} -> ${newType})`;
|
|
590
627
|
}).join(", ");
|
|
591
|
-
errorReason =
|
|
628
|
+
errorReason = `[${this.schema.keyspace}.${this.schema.tableName}] \u5B57\u6BB5\u7C7B\u578B\u6709\u66F4\u65B0\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u53D8\u66F4\u5B57\u6BB5: ${fieldDetails}`;
|
|
592
629
|
}
|
|
593
630
|
if (hasKeyFieldChanged(this.schema, newFields, deletedFields)) {
|
|
594
631
|
const partitionKeyFields = this.schema.partitionKeyFields;
|
|
@@ -609,9 +646,7 @@ var Model = class _Model {
|
|
|
609
646
|
if (deletedKeyFields.length > 0) {
|
|
610
647
|
keyChangeDetails.push(`\u5220\u9664\u952E\u5B57\u6BB5: ${deletedKeyFields.join(", ")}`);
|
|
611
648
|
}
|
|
612
|
-
errorReason =
|
|
613
|
-
"; "
|
|
614
|
-
)}`;
|
|
649
|
+
errorReason = `[${this.schema.keyspace}.${this.schema.tableName}] \u952E\u5B57\u6BB5\u53D1\u751F\u53D8\u66F4\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002${keyChangeDetails.join("; ")}`;
|
|
615
650
|
}
|
|
616
651
|
if (isClusteringKeyChanged(this.schema, tableMetadata2)) {
|
|
617
652
|
const existingClusteringKeys = tableMetadata2.filter((t) => t.kind === "clustering").map((t) => t.column_name);
|
|
@@ -620,7 +655,7 @@ var Model = class _Model {
|
|
|
620
655
|
);
|
|
621
656
|
const existingOrder = existingClusteringKeys.join(", ");
|
|
622
657
|
const currentOrder = currentClusteringKeys.join(", ");
|
|
623
|
-
errorReason =
|
|
658
|
+
errorReason = `[${this.schema.keyspace}.${this.schema.tableName}] \u805A\u7C7B\u952E\u914D\u7F6E\u53D1\u751F\u53D8\u5316\uFF0C\u65E0\u6CD5\u81EA\u52A8\u66F4\u65B0\u3002\u73B0\u6709\u987A\u5E8F: [${existingOrder}]\uFF0C\u65B0\u987A\u5E8F: [${currentOrder}]`;
|
|
624
659
|
}
|
|
625
660
|
}
|
|
626
661
|
if (errorReason) {
|