imean-cassandra-orm 2.2.0 → 2.2.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 CHANGED
@@ -5,12 +5,12 @@ var zod = require('zod');
5
5
 
6
6
  // src/client.ts
7
7
  function convertZodToCassandraType(schema) {
8
- if (schema._cassandraType) {
9
- return schema._cassandraType;
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
- let baseSchema = schema instanceof zod.z.ZodEffects ? schema._def.schema : schema;
12
- if (schema instanceof zod.z.ZodOptional) {
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.keySchema);
55
- const valueType = convertZodToCassandraType(baseSchema.valueSchema);
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) {
@@ -859,10 +856,7 @@ var Types = {
859
856
  "float"
860
857
  ),
861
858
  int: () => createCassandraType(zod.z.number().int(), "int"),
862
- bigint: () => createCassandraType(
863
- zod.z.number().int().transform((val) => BigInt(val)),
864
- "bigint"
865
- ),
859
+ bigint: () => createCassandraType(zod.z.bigint(), "bigint"),
866
860
  smallint: () => createCassandraType(
867
861
  zod.z.number().int().refine((val) => val >= -32768 && val <= 32767, {
868
862
  message: "Value must be between -32768 and 32767"
@@ -898,29 +892,19 @@ var Types = {
898
892
  // 集合类型
899
893
  list: (elementType) => createCassandraType(
900
894
  zod.z.array(elementType),
901
- `list<${getCassandraTypeFromZod(elementType)}>`
895
+ `list<${convertZodToCassandraType(elementType)}>`
902
896
  ),
903
897
  set: (elementType) => createCassandraType(
904
898
  zod.z.set(elementType),
905
- `set<${getCassandraTypeFromZod(elementType)}>`
899
+ `set<${convertZodToCassandraType(elementType)}>`
906
900
  ),
907
901
  map: (keyType, valueType) => createCassandraType(
908
902
  zod.z.record(keyType, valueType),
909
- `map<${getCassandraTypeFromZod(keyType)}, ${getCassandraTypeFromZod(
903
+ `map<${convertZodToCassandraType(keyType)}, ${convertZodToCassandraType(
910
904
  valueType
911
905
  )}>`
912
906
  )
913
907
  };
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
908
 
925
909
  exports.Client = Client;
926
910
  exports.Model = Model;
package/dist/mod.d.cts CHANGED
@@ -26,7 +26,7 @@ declare const Types: {
26
26
  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">>;
27
27
  float: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
28
28
  int: () => z.ZodNumber & CassandraTypeMarker;
29
- bigint: () => z.ZodEffects<z.ZodNumber, bigint, number> & CassandraTypeMarker;
29
+ bigint: () => z.ZodBigInt & CassandraTypeMarker;
30
30
  smallint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
31
31
  tinyint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
32
32
  varint: () => z.ZodEffects<z.ZodNumber, bigint, number> & CassandraTypeMarker;
package/dist/mod.d.ts CHANGED
@@ -26,7 +26,7 @@ declare const Types: {
26
26
  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">>;
27
27
  float: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
28
28
  int: () => z.ZodNumber & CassandraTypeMarker;
29
- bigint: () => z.ZodEffects<z.ZodNumber, bigint, number> & CassandraTypeMarker;
29
+ bigint: () => z.ZodBigInt & CassandraTypeMarker;
30
30
  smallint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
31
31
  tinyint: () => z.ZodEffects<z.ZodNumber, number, number> & CassandraTypeMarker;
32
32
  varint: () => z.ZodEffects<z.ZodNumber, bigint, number> & CassandraTypeMarker;
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
- if (schema._cassandraType) {
7
- return schema._cassandraType;
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
- let baseSchema = schema instanceof z.ZodEffects ? schema._def.schema : schema;
10
- if (schema instanceof z.ZodOptional) {
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.keySchema);
53
- const valueType = convertZodToCassandraType(baseSchema.valueSchema);
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) {
@@ -857,10 +854,7 @@ var Types = {
857
854
  "float"
858
855
  ),
859
856
  int: () => createCassandraType(z.number().int(), "int"),
860
- bigint: () => createCassandraType(
861
- z.number().int().transform((val) => BigInt(val)),
862
- "bigint"
863
- ),
857
+ bigint: () => createCassandraType(z.bigint(), "bigint"),
864
858
  smallint: () => createCassandraType(
865
859
  z.number().int().refine((val) => val >= -32768 && val <= 32767, {
866
860
  message: "Value must be between -32768 and 32767"
@@ -896,28 +890,18 @@ var Types = {
896
890
  // 集合类型
897
891
  list: (elementType) => createCassandraType(
898
892
  z.array(elementType),
899
- `list<${getCassandraTypeFromZod(elementType)}>`
893
+ `list<${convertZodToCassandraType(elementType)}>`
900
894
  ),
901
895
  set: (elementType) => createCassandraType(
902
896
  z.set(elementType),
903
- `set<${getCassandraTypeFromZod(elementType)}>`
897
+ `set<${convertZodToCassandraType(elementType)}>`
904
898
  ),
905
899
  map: (keyType, valueType) => createCassandraType(
906
900
  z.record(keyType, valueType),
907
- `map<${getCassandraTypeFromZod(keyType)}, ${getCassandraTypeFromZod(
901
+ `map<${convertZodToCassandraType(keyType)}, ${convertZodToCassandraType(
908
902
  valueType
909
903
  )}>`
910
904
  )
911
905
  };
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
906
 
923
907
  export { Client, Model, TableSchema, Types, createModel, createTableSchema, uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imean-cassandra-orm",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "cassandra orm",
5
5
  "keywords": [
6
6
  "cassandra",