imean-cassandra-orm 2.6.1 → 2.7.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.
- package/dist/mod.cjs +15 -48
- package/dist/mod.d.cts +1 -7
- package/dist/mod.d.ts +1 -7
- package/dist/mod.js +15 -48
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -66,21 +66,21 @@ function getNewFields(schemaFields, tableMetadata2) {
|
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
function getDeletedFields(schemaFields, tableMetadata2) {
|
|
69
|
-
return tableMetadata2.filter(
|
|
70
|
-
(
|
|
71
|
-
|
|
69
|
+
return tableMetadata2.filter(
|
|
70
|
+
(t) => !schemaFields.some(
|
|
71
|
+
(field) => field.toLowerCase() === t.column_name.toLowerCase()
|
|
72
|
+
)
|
|
73
|
+
).map((t) => t.column_name);
|
|
72
74
|
}
|
|
73
75
|
function getUpdatedFields(schemaFields, tableMetadata2, shape) {
|
|
74
76
|
return schemaFields.filter(
|
|
75
|
-
(field) => tableMetadata2.some(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
)
|
|
77
|
+
(field) => tableMetadata2.some((t) => {
|
|
78
|
+
const dbFieldName = t.column_name;
|
|
79
|
+
const schemaFieldName = field;
|
|
80
|
+
const dbType = t.type;
|
|
81
|
+
const schemaType = convertZodToCassandraType(shape[field]);
|
|
82
|
+
return dbFieldName.toLowerCase() === schemaFieldName.toLowerCase() && dbType !== schemaType;
|
|
83
|
+
})
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
86
|
function hasKeyFieldChanged(schema, newFields, deletedFields) {
|
|
@@ -821,8 +821,6 @@ function buildInsertParams(data, fieldConfigs) {
|
|
|
821
821
|
const value = data[fieldName];
|
|
822
822
|
if (value !== void 0) {
|
|
823
823
|
params.push(convertValueToCassandra(value, config));
|
|
824
|
-
} else if (!config.flags.optional) {
|
|
825
|
-
throw new Error(`\u5FC5\u586B\u5B57\u6BB5 "${fieldName}" \u672A\u63D0\u4F9B`);
|
|
826
824
|
} else {
|
|
827
825
|
params.push(null);
|
|
828
826
|
}
|
|
@@ -1015,8 +1013,8 @@ function convertValueToCassandra(value, config) {
|
|
|
1015
1013
|
}
|
|
1016
1014
|
}
|
|
1017
1015
|
function convertValueFromCassandra(value, config, zodSchema, filedName) {
|
|
1018
|
-
if (value === null
|
|
1019
|
-
return
|
|
1016
|
+
if (value === null) {
|
|
1017
|
+
return config.flags.optional ? null : void 0;
|
|
1020
1018
|
}
|
|
1021
1019
|
switch (config.type) {
|
|
1022
1020
|
case "timestamp":
|
|
@@ -1033,7 +1031,6 @@ function convertValueFromCassandra(value, config, zodSchema, filedName) {
|
|
|
1033
1031
|
return value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
1034
1032
|
case "text":
|
|
1035
1033
|
if (config.type !== "text") {
|
|
1036
|
-
console.log("value", value);
|
|
1037
1034
|
try {
|
|
1038
1035
|
return JSON.parse(value);
|
|
1039
1036
|
} catch {
|
|
@@ -1603,37 +1600,13 @@ var Types = {
|
|
|
1603
1600
|
double: zod.z.number,
|
|
1604
1601
|
enum: zod.z.enum,
|
|
1605
1602
|
object: zod.z.object,
|
|
1606
|
-
|
|
1603
|
+
json: () => createCassandraType(zod.z.any(), "text"),
|
|
1607
1604
|
float: () => createCassandraType(
|
|
1608
1605
|
zod.z.number().transform((val) => parseFloat(val.toString())),
|
|
1609
1606
|
"float"
|
|
1610
1607
|
),
|
|
1611
1608
|
int: () => createCassandraType(zod.z.number().int(), "int"),
|
|
1612
1609
|
bigint: () => createCassandraType(zod.z.bigint(), "bigint"),
|
|
1613
|
-
smallint: () => createCassandraType(
|
|
1614
|
-
zod.z.number().int().refine((val) => val >= -32768 && val <= 32767, {
|
|
1615
|
-
message: "Value must be between -32768 and 32767"
|
|
1616
|
-
}),
|
|
1617
|
-
"smallint"
|
|
1618
|
-
),
|
|
1619
|
-
tinyint: () => createCassandraType(
|
|
1620
|
-
zod.z.number().int().refine((val) => val >= -128 && val <= 127, {
|
|
1621
|
-
message: "Value must be between -128 and 127"
|
|
1622
|
-
}),
|
|
1623
|
-
"tinyint"
|
|
1624
|
-
),
|
|
1625
|
-
varint: () => createCassandraType(
|
|
1626
|
-
zod.z.number().int().transform((val) => BigInt(val)),
|
|
1627
|
-
"varint"
|
|
1628
|
-
),
|
|
1629
|
-
// 字符串类型
|
|
1630
|
-
varchar: (maxLength) => createCassandraType(zod.z.string().max(maxLength || 65535), "varchar"),
|
|
1631
|
-
ascii: () => createCassandraType(
|
|
1632
|
-
zod.z.string().refine((val) => /^[\x00-\x7F]*$/.test(val), {
|
|
1633
|
-
message: "String must contain only ASCII characters"
|
|
1634
|
-
}),
|
|
1635
|
-
"ascii"
|
|
1636
|
-
),
|
|
1637
1610
|
// 时间类型
|
|
1638
1611
|
timestamp: () => createCassandraType(zod.z.date(), "timestamp"),
|
|
1639
1612
|
time: () => createCassandraType(zod.z.date(), "time"),
|
|
@@ -1650,12 +1623,6 @@ var Types = {
|
|
|
1650
1623
|
set: (elementType) => createCassandraType(
|
|
1651
1624
|
zod.z.set(elementType),
|
|
1652
1625
|
`set<${convertZodToCassandraType(elementType)}>`
|
|
1653
|
-
),
|
|
1654
|
-
map: (keyType, valueType) => createCassandraType(
|
|
1655
|
-
zod.z.record(keyType, valueType),
|
|
1656
|
-
`map<${convertZodToCassandraType(keyType)}, ${convertZodToCassandraType(
|
|
1657
|
-
valueType
|
|
1658
|
-
)}>`
|
|
1659
1626
|
)
|
|
1660
1627
|
};
|
|
1661
1628
|
|
package/dist/mod.d.cts
CHANGED
|
@@ -132,15 +132,10 @@ declare const Types: {
|
|
|
132
132
|
<U extends string, T extends [U, ...U[]]>(values: T, params?: z.RawCreateParams): z.ZodEnum<T>;
|
|
133
133
|
};
|
|
134
134
|
object: <T extends z.ZodRawShape>(shape: T, params?: z.RawCreateParams) => z.ZodObject<T, "strip", z.ZodTypeAny, z.objectOutputType<T, z.ZodTypeAny, "strip">, z.objectInputType<T, z.ZodTypeAny, "strip">>;
|
|
135
|
-
|
|
135
|
+
json: () => z.ZodAny & CassandraTypeMarker;
|
|
136
136
|
float: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
|
|
137
137
|
int: () => z.ZodNumber & CassandraTypeMarker;
|
|
138
138
|
bigint: () => z.ZodBigInt & CassandraTypeMarker;
|
|
139
|
-
smallint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
|
|
140
|
-
tinyint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
|
|
141
|
-
varint: () => z.ZodEffects<z.ZodNumber, bigint, number> & CassandraTypeMarker;
|
|
142
|
-
varchar: (maxLength?: number) => z.ZodString & CassandraTypeMarker;
|
|
143
|
-
ascii: () => z.ZodEffects<z.ZodString, string, string> & CassandraTypeMarker;
|
|
144
139
|
timestamp: () => z.ZodDate & CassandraTypeMarker;
|
|
145
140
|
time: () => z.ZodDate & CassandraTypeMarker;
|
|
146
141
|
date: () => z.ZodDate & CassandraTypeMarker;
|
|
@@ -148,7 +143,6 @@ declare const Types: {
|
|
|
148
143
|
blob: () => z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>> & CassandraTypeMarker;
|
|
149
144
|
list: <T extends z.ZodTypeAny>(elementType: T) => z.ZodArray<T, "many"> & CassandraTypeMarker;
|
|
150
145
|
set: <T extends z.ZodTypeAny>(elementType: T) => z.ZodSet<T> & CassandraTypeMarker;
|
|
151
|
-
map: <K extends z.ZodTypeAny, V extends z.ZodTypeAny>(keyType: K, valueType: V) => z.ZodRecord<K, V> & CassandraTypeMarker;
|
|
152
146
|
};
|
|
153
147
|
|
|
154
148
|
type FieldFlags = {
|
package/dist/mod.d.ts
CHANGED
|
@@ -132,15 +132,10 @@ declare const Types: {
|
|
|
132
132
|
<U extends string, T extends [U, ...U[]]>(values: T, params?: z.RawCreateParams): z.ZodEnum<T>;
|
|
133
133
|
};
|
|
134
134
|
object: <T extends z.ZodRawShape>(shape: T, params?: z.RawCreateParams) => z.ZodObject<T, "strip", z.ZodTypeAny, z.objectOutputType<T, z.ZodTypeAny, "strip">, z.objectInputType<T, z.ZodTypeAny, "strip">>;
|
|
135
|
-
|
|
135
|
+
json: () => z.ZodAny & CassandraTypeMarker;
|
|
136
136
|
float: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
|
|
137
137
|
int: () => z.ZodNumber & CassandraTypeMarker;
|
|
138
138
|
bigint: () => z.ZodBigInt & CassandraTypeMarker;
|
|
139
|
-
smallint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
|
|
140
|
-
tinyint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
|
|
141
|
-
varint: () => z.ZodEffects<z.ZodNumber, bigint, number> & CassandraTypeMarker;
|
|
142
|
-
varchar: (maxLength?: number) => z.ZodString & CassandraTypeMarker;
|
|
143
|
-
ascii: () => z.ZodEffects<z.ZodString, string, string> & CassandraTypeMarker;
|
|
144
139
|
timestamp: () => z.ZodDate & CassandraTypeMarker;
|
|
145
140
|
time: () => z.ZodDate & CassandraTypeMarker;
|
|
146
141
|
date: () => z.ZodDate & CassandraTypeMarker;
|
|
@@ -148,7 +143,6 @@ declare const Types: {
|
|
|
148
143
|
blob: () => z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>> & CassandraTypeMarker;
|
|
149
144
|
list: <T extends z.ZodTypeAny>(elementType: T) => z.ZodArray<T, "many"> & CassandraTypeMarker;
|
|
150
145
|
set: <T extends z.ZodTypeAny>(elementType: T) => z.ZodSet<T> & CassandraTypeMarker;
|
|
151
|
-
map: <K extends z.ZodTypeAny, V extends z.ZodTypeAny>(keyType: K, valueType: V) => z.ZodRecord<K, V> & CassandraTypeMarker;
|
|
152
146
|
};
|
|
153
147
|
|
|
154
148
|
type FieldFlags = {
|
package/dist/mod.js
CHANGED
|
@@ -64,21 +64,21 @@ function getNewFields(schemaFields, tableMetadata2) {
|
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
function getDeletedFields(schemaFields, tableMetadata2) {
|
|
67
|
-
return tableMetadata2.filter(
|
|
68
|
-
(
|
|
69
|
-
|
|
67
|
+
return tableMetadata2.filter(
|
|
68
|
+
(t) => !schemaFields.some(
|
|
69
|
+
(field) => field.toLowerCase() === t.column_name.toLowerCase()
|
|
70
|
+
)
|
|
71
|
+
).map((t) => t.column_name);
|
|
70
72
|
}
|
|
71
73
|
function getUpdatedFields(schemaFields, tableMetadata2, shape) {
|
|
72
74
|
return schemaFields.filter(
|
|
73
|
-
(field) => tableMetadata2.some(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
)
|
|
75
|
+
(field) => tableMetadata2.some((t) => {
|
|
76
|
+
const dbFieldName = t.column_name;
|
|
77
|
+
const schemaFieldName = field;
|
|
78
|
+
const dbType = t.type;
|
|
79
|
+
const schemaType = convertZodToCassandraType(shape[field]);
|
|
80
|
+
return dbFieldName.toLowerCase() === schemaFieldName.toLowerCase() && dbType !== schemaType;
|
|
81
|
+
})
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
function hasKeyFieldChanged(schema, newFields, deletedFields) {
|
|
@@ -819,8 +819,6 @@ function buildInsertParams(data, fieldConfigs) {
|
|
|
819
819
|
const value = data[fieldName];
|
|
820
820
|
if (value !== void 0) {
|
|
821
821
|
params.push(convertValueToCassandra(value, config));
|
|
822
|
-
} else if (!config.flags.optional) {
|
|
823
|
-
throw new Error(`\u5FC5\u586B\u5B57\u6BB5 "${fieldName}" \u672A\u63D0\u4F9B`);
|
|
824
822
|
} else {
|
|
825
823
|
params.push(null);
|
|
826
824
|
}
|
|
@@ -1013,8 +1011,8 @@ function convertValueToCassandra(value, config) {
|
|
|
1013
1011
|
}
|
|
1014
1012
|
}
|
|
1015
1013
|
function convertValueFromCassandra(value, config, zodSchema, filedName) {
|
|
1016
|
-
if (value === null
|
|
1017
|
-
return
|
|
1014
|
+
if (value === null) {
|
|
1015
|
+
return config.flags.optional ? null : void 0;
|
|
1018
1016
|
}
|
|
1019
1017
|
switch (config.type) {
|
|
1020
1018
|
case "timestamp":
|
|
@@ -1031,7 +1029,6 @@ function convertValueFromCassandra(value, config, zodSchema, filedName) {
|
|
|
1031
1029
|
return value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
1032
1030
|
case "text":
|
|
1033
1031
|
if (config.type !== "text") {
|
|
1034
|
-
console.log("value", value);
|
|
1035
1032
|
try {
|
|
1036
1033
|
return JSON.parse(value);
|
|
1037
1034
|
} catch {
|
|
@@ -1601,37 +1598,13 @@ var Types = {
|
|
|
1601
1598
|
double: z.number,
|
|
1602
1599
|
enum: z.enum,
|
|
1603
1600
|
object: z.object,
|
|
1604
|
-
|
|
1601
|
+
json: () => createCassandraType(z.any(), "text"),
|
|
1605
1602
|
float: () => createCassandraType(
|
|
1606
1603
|
z.number().transform((val) => parseFloat(val.toString())),
|
|
1607
1604
|
"float"
|
|
1608
1605
|
),
|
|
1609
1606
|
int: () => createCassandraType(z.number().int(), "int"),
|
|
1610
1607
|
bigint: () => createCassandraType(z.bigint(), "bigint"),
|
|
1611
|
-
smallint: () => createCassandraType(
|
|
1612
|
-
z.number().int().refine((val) => val >= -32768 && val <= 32767, {
|
|
1613
|
-
message: "Value must be between -32768 and 32767"
|
|
1614
|
-
}),
|
|
1615
|
-
"smallint"
|
|
1616
|
-
),
|
|
1617
|
-
tinyint: () => createCassandraType(
|
|
1618
|
-
z.number().int().refine((val) => val >= -128 && val <= 127, {
|
|
1619
|
-
message: "Value must be between -128 and 127"
|
|
1620
|
-
}),
|
|
1621
|
-
"tinyint"
|
|
1622
|
-
),
|
|
1623
|
-
varint: () => createCassandraType(
|
|
1624
|
-
z.number().int().transform((val) => BigInt(val)),
|
|
1625
|
-
"varint"
|
|
1626
|
-
),
|
|
1627
|
-
// 字符串类型
|
|
1628
|
-
varchar: (maxLength) => createCassandraType(z.string().max(maxLength || 65535), "varchar"),
|
|
1629
|
-
ascii: () => createCassandraType(
|
|
1630
|
-
z.string().refine((val) => /^[\x00-\x7F]*$/.test(val), {
|
|
1631
|
-
message: "String must contain only ASCII characters"
|
|
1632
|
-
}),
|
|
1633
|
-
"ascii"
|
|
1634
|
-
),
|
|
1635
1608
|
// 时间类型
|
|
1636
1609
|
timestamp: () => createCassandraType(z.date(), "timestamp"),
|
|
1637
1610
|
time: () => createCassandraType(z.date(), "time"),
|
|
@@ -1648,12 +1621,6 @@ var Types = {
|
|
|
1648
1621
|
set: (elementType) => createCassandraType(
|
|
1649
1622
|
z.set(elementType),
|
|
1650
1623
|
`set<${convertZodToCassandraType(elementType)}>`
|
|
1651
|
-
),
|
|
1652
|
-
map: (keyType, valueType) => createCassandraType(
|
|
1653
|
-
z.record(keyType, valueType),
|
|
1654
|
-
`map<${convertZodToCassandraType(keyType)}, ${convertZodToCassandraType(
|
|
1655
|
-
valueType
|
|
1656
|
-
)}>`
|
|
1657
1624
|
)
|
|
1658
1625
|
};
|
|
1659
1626
|
|