imean-cassandra-orm 2.2.0 → 2.2.1
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 +10 -23
- package/dist/mod.js +10 -23
- package/package.json +1 -1
package/dist/mod.cjs
CHANGED
|
@@ -5,12 +5,12 @@ var zod = require('zod');
|
|
|
5
5
|
|
|
6
6
|
// src/client.ts
|
|
7
7
|
function convertZodToCassandraType(schema) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let baseSchema = schema;
|
|
9
|
+
while (baseSchema instanceof zod.z.ZodOptional || baseSchema instanceof zod.z.ZodNullable || baseSchema instanceof zod.z.ZodDefault) {
|
|
10
|
+
baseSchema = baseSchema._def.innerType;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return convertZodToCassandraType(schema.unwrap());
|
|
12
|
+
if (baseSchema._cassandraType) {
|
|
13
|
+
return baseSchema._cassandraType;
|
|
14
14
|
}
|
|
15
15
|
while (baseSchema instanceof zod.z.ZodEffects) {
|
|
16
16
|
baseSchema = baseSchema._def.schema;
|
|
@@ -51,13 +51,10 @@ function convertZodToCassandraType(schema) {
|
|
|
51
51
|
return `set<${elementType}>`;
|
|
52
52
|
}
|
|
53
53
|
if (baseSchema instanceof zod.z.ZodRecord) {
|
|
54
|
-
const keyType = convertZodToCassandraType(baseSchema.
|
|
55
|
-
const valueType = convertZodToCassandraType(baseSchema.
|
|
54
|
+
const keyType = convertZodToCassandraType(baseSchema._def.keyType);
|
|
55
|
+
const valueType = convertZodToCassandraType(baseSchema._def.valueType);
|
|
56
56
|
return `map<${keyType}, ${valueType}>`;
|
|
57
57
|
}
|
|
58
|
-
if (baseSchema instanceof zod.z.ZodObject) {
|
|
59
|
-
return "text";
|
|
60
|
-
}
|
|
61
58
|
return "text";
|
|
62
59
|
}
|
|
63
60
|
function getNewFields(schemaFields, tableMetadata2) {
|
|
@@ -898,29 +895,19 @@ var Types = {
|
|
|
898
895
|
// 集合类型
|
|
899
896
|
list: (elementType) => createCassandraType(
|
|
900
897
|
zod.z.array(elementType),
|
|
901
|
-
`list<${
|
|
898
|
+
`list<${convertZodToCassandraType(elementType)}>`
|
|
902
899
|
),
|
|
903
900
|
set: (elementType) => createCassandraType(
|
|
904
901
|
zod.z.set(elementType),
|
|
905
|
-
`set<${
|
|
902
|
+
`set<${convertZodToCassandraType(elementType)}>`
|
|
906
903
|
),
|
|
907
904
|
map: (keyType, valueType) => createCassandraType(
|
|
908
905
|
zod.z.record(keyType, valueType),
|
|
909
|
-
`map<${
|
|
906
|
+
`map<${convertZodToCassandraType(keyType)}, ${convertZodToCassandraType(
|
|
910
907
|
valueType
|
|
911
908
|
)}>`
|
|
912
909
|
)
|
|
913
910
|
};
|
|
914
|
-
function getCassandraTypeFromZod(schema) {
|
|
915
|
-
if (schema._cassandraType) {
|
|
916
|
-
return schema._cassandraType;
|
|
917
|
-
}
|
|
918
|
-
if (schema instanceof zod.z.ZodString) return "text";
|
|
919
|
-
if (schema instanceof zod.z.ZodNumber) return "double";
|
|
920
|
-
if (schema instanceof zod.z.ZodBoolean) return "boolean";
|
|
921
|
-
if (schema instanceof zod.z.ZodDate) return "timestamp";
|
|
922
|
-
return "text";
|
|
923
|
-
}
|
|
924
911
|
|
|
925
912
|
exports.Client = Client;
|
|
926
913
|
exports.Model = Model;
|
package/dist/mod.js
CHANGED
|
@@ -3,12 +3,12 @@ import { z } from 'zod';
|
|
|
3
3
|
|
|
4
4
|
// src/client.ts
|
|
5
5
|
function convertZodToCassandraType(schema) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
let baseSchema = schema;
|
|
7
|
+
while (baseSchema instanceof z.ZodOptional || baseSchema instanceof z.ZodNullable || baseSchema instanceof z.ZodDefault) {
|
|
8
|
+
baseSchema = baseSchema._def.innerType;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return convertZodToCassandraType(schema.unwrap());
|
|
10
|
+
if (baseSchema._cassandraType) {
|
|
11
|
+
return baseSchema._cassandraType;
|
|
12
12
|
}
|
|
13
13
|
while (baseSchema instanceof z.ZodEffects) {
|
|
14
14
|
baseSchema = baseSchema._def.schema;
|
|
@@ -49,13 +49,10 @@ function convertZodToCassandraType(schema) {
|
|
|
49
49
|
return `set<${elementType}>`;
|
|
50
50
|
}
|
|
51
51
|
if (baseSchema instanceof z.ZodRecord) {
|
|
52
|
-
const keyType = convertZodToCassandraType(baseSchema.
|
|
53
|
-
const valueType = convertZodToCassandraType(baseSchema.
|
|
52
|
+
const keyType = convertZodToCassandraType(baseSchema._def.keyType);
|
|
53
|
+
const valueType = convertZodToCassandraType(baseSchema._def.valueType);
|
|
54
54
|
return `map<${keyType}, ${valueType}>`;
|
|
55
55
|
}
|
|
56
|
-
if (baseSchema instanceof z.ZodObject) {
|
|
57
|
-
return "text";
|
|
58
|
-
}
|
|
59
56
|
return "text";
|
|
60
57
|
}
|
|
61
58
|
function getNewFields(schemaFields, tableMetadata2) {
|
|
@@ -896,28 +893,18 @@ var Types = {
|
|
|
896
893
|
// 集合类型
|
|
897
894
|
list: (elementType) => createCassandraType(
|
|
898
895
|
z.array(elementType),
|
|
899
|
-
`list<${
|
|
896
|
+
`list<${convertZodToCassandraType(elementType)}>`
|
|
900
897
|
),
|
|
901
898
|
set: (elementType) => createCassandraType(
|
|
902
899
|
z.set(elementType),
|
|
903
|
-
`set<${
|
|
900
|
+
`set<${convertZodToCassandraType(elementType)}>`
|
|
904
901
|
),
|
|
905
902
|
map: (keyType, valueType) => createCassandraType(
|
|
906
903
|
z.record(keyType, valueType),
|
|
907
|
-
`map<${
|
|
904
|
+
`map<${convertZodToCassandraType(keyType)}, ${convertZodToCassandraType(
|
|
908
905
|
valueType
|
|
909
906
|
)}>`
|
|
910
907
|
)
|
|
911
908
|
};
|
|
912
|
-
function getCassandraTypeFromZod(schema) {
|
|
913
|
-
if (schema._cassandraType) {
|
|
914
|
-
return schema._cassandraType;
|
|
915
|
-
}
|
|
916
|
-
if (schema instanceof z.ZodString) return "text";
|
|
917
|
-
if (schema instanceof z.ZodNumber) return "double";
|
|
918
|
-
if (schema instanceof z.ZodBoolean) return "boolean";
|
|
919
|
-
if (schema instanceof z.ZodDate) return "timestamp";
|
|
920
|
-
return "text";
|
|
921
|
-
}
|
|
922
909
|
|
|
923
910
|
export { Client, Model, TableSchema, Types, createModel, createTableSchema, uuid };
|