imean-cassandra-orm 2.2.2 → 2.3.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 +32 -11
- package/dist/mod.js +32 -11
- package/package.json +62 -63
package/dist/mod.cjs
CHANGED
|
@@ -149,9 +149,13 @@ function dropColumns(schema, fields) {
|
|
|
149
149
|
return `ALTER TABLE ${schema.keyspace}.${schema.tableName} DROP (${fields.join(", ")});`;
|
|
150
150
|
}
|
|
151
151
|
function convertToFieldConfig(zodType, flags = {}) {
|
|
152
|
-
|
|
152
|
+
let baseType = zodType;
|
|
153
|
+
while (baseType._def && (baseType._def.typeName === "ZodOptional" || baseType._def.typeName === "ZodNullable" || baseType._def.typeName === "ZodDefault")) {
|
|
154
|
+
baseType = baseType._def.innerType;
|
|
155
|
+
}
|
|
156
|
+
if (baseType._cassandraType) {
|
|
153
157
|
return {
|
|
154
|
-
type:
|
|
158
|
+
type: baseType._cassandraType,
|
|
155
159
|
flags: {
|
|
156
160
|
partitionKey: !!flags.partitionKey,
|
|
157
161
|
clusteringKey: flags.clusteringKey || false,
|
|
@@ -161,23 +165,23 @@ function convertToFieldConfig(zodType, flags = {}) {
|
|
|
161
165
|
};
|
|
162
166
|
}
|
|
163
167
|
let type = "text";
|
|
164
|
-
if (
|
|
165
|
-
if (
|
|
168
|
+
if (baseType._def.typeName === "ZodString") {
|
|
169
|
+
if (baseType._def.checks && baseType._def.checks.some((c) => c.kind === "uuid")) {
|
|
166
170
|
type = "uuid";
|
|
167
171
|
} else {
|
|
168
172
|
type = "text";
|
|
169
173
|
}
|
|
170
|
-
} else if (
|
|
174
|
+
} else if (baseType._def.typeName === "ZodNumber") {
|
|
171
175
|
type = "double";
|
|
172
|
-
} else if (
|
|
176
|
+
} else if (baseType._def.typeName === "ZodBoolean") {
|
|
173
177
|
type = "boolean";
|
|
174
|
-
} else if (
|
|
178
|
+
} else if (baseType._def.typeName === "ZodDate") {
|
|
175
179
|
type = "timestamp";
|
|
176
|
-
} else if (
|
|
180
|
+
} else if (baseType._def.typeName === "ZodArray") {
|
|
177
181
|
type = "list";
|
|
178
|
-
} else if (
|
|
182
|
+
} else if (baseType._def.typeName === "ZodSet") {
|
|
179
183
|
type = "set";
|
|
180
|
-
} else if (
|
|
184
|
+
} else if (baseType._def.typeName === "ZodRecord") {
|
|
181
185
|
type = "map";
|
|
182
186
|
}
|
|
183
187
|
return {
|
|
@@ -370,7 +374,24 @@ function convertValueToCassandra(value, config) {
|
|
|
370
374
|
}
|
|
371
375
|
switch (config.type) {
|
|
372
376
|
case "timestamp":
|
|
373
|
-
|
|
377
|
+
if (value instanceof Date) {
|
|
378
|
+
return value;
|
|
379
|
+
}
|
|
380
|
+
if (typeof value === "string") {
|
|
381
|
+
const parsedDate = new Date(value);
|
|
382
|
+
if (isNaN(parsedDate.getTime())) {
|
|
383
|
+
throw new Error(`Invalid date string: ${value}`);
|
|
384
|
+
}
|
|
385
|
+
return parsedDate;
|
|
386
|
+
}
|
|
387
|
+
if (typeof value === "number") {
|
|
388
|
+
return new Date(value);
|
|
389
|
+
}
|
|
390
|
+
try {
|
|
391
|
+
return new Date(value);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
throw new Error(`Cannot convert value to Date: ${value}`);
|
|
394
|
+
}
|
|
374
395
|
case "uuid":
|
|
375
396
|
return typeof value === "string" ? value : value.toString();
|
|
376
397
|
case "blob":
|
package/dist/mod.js
CHANGED
|
@@ -147,9 +147,13 @@ function dropColumns(schema, fields) {
|
|
|
147
147
|
return `ALTER TABLE ${schema.keyspace}.${schema.tableName} DROP (${fields.join(", ")});`;
|
|
148
148
|
}
|
|
149
149
|
function convertToFieldConfig(zodType, flags = {}) {
|
|
150
|
-
|
|
150
|
+
let baseType = zodType;
|
|
151
|
+
while (baseType._def && (baseType._def.typeName === "ZodOptional" || baseType._def.typeName === "ZodNullable" || baseType._def.typeName === "ZodDefault")) {
|
|
152
|
+
baseType = baseType._def.innerType;
|
|
153
|
+
}
|
|
154
|
+
if (baseType._cassandraType) {
|
|
151
155
|
return {
|
|
152
|
-
type:
|
|
156
|
+
type: baseType._cassandraType,
|
|
153
157
|
flags: {
|
|
154
158
|
partitionKey: !!flags.partitionKey,
|
|
155
159
|
clusteringKey: flags.clusteringKey || false,
|
|
@@ -159,23 +163,23 @@ function convertToFieldConfig(zodType, flags = {}) {
|
|
|
159
163
|
};
|
|
160
164
|
}
|
|
161
165
|
let type = "text";
|
|
162
|
-
if (
|
|
163
|
-
if (
|
|
166
|
+
if (baseType._def.typeName === "ZodString") {
|
|
167
|
+
if (baseType._def.checks && baseType._def.checks.some((c) => c.kind === "uuid")) {
|
|
164
168
|
type = "uuid";
|
|
165
169
|
} else {
|
|
166
170
|
type = "text";
|
|
167
171
|
}
|
|
168
|
-
} else if (
|
|
172
|
+
} else if (baseType._def.typeName === "ZodNumber") {
|
|
169
173
|
type = "double";
|
|
170
|
-
} else if (
|
|
174
|
+
} else if (baseType._def.typeName === "ZodBoolean") {
|
|
171
175
|
type = "boolean";
|
|
172
|
-
} else if (
|
|
176
|
+
} else if (baseType._def.typeName === "ZodDate") {
|
|
173
177
|
type = "timestamp";
|
|
174
|
-
} else if (
|
|
178
|
+
} else if (baseType._def.typeName === "ZodArray") {
|
|
175
179
|
type = "list";
|
|
176
|
-
} else if (
|
|
180
|
+
} else if (baseType._def.typeName === "ZodSet") {
|
|
177
181
|
type = "set";
|
|
178
|
-
} else if (
|
|
182
|
+
} else if (baseType._def.typeName === "ZodRecord") {
|
|
179
183
|
type = "map";
|
|
180
184
|
}
|
|
181
185
|
return {
|
|
@@ -368,7 +372,24 @@ function convertValueToCassandra(value, config) {
|
|
|
368
372
|
}
|
|
369
373
|
switch (config.type) {
|
|
370
374
|
case "timestamp":
|
|
371
|
-
|
|
375
|
+
if (value instanceof Date) {
|
|
376
|
+
return value;
|
|
377
|
+
}
|
|
378
|
+
if (typeof value === "string") {
|
|
379
|
+
const parsedDate = new Date(value);
|
|
380
|
+
if (isNaN(parsedDate.getTime())) {
|
|
381
|
+
throw new Error(`Invalid date string: ${value}`);
|
|
382
|
+
}
|
|
383
|
+
return parsedDate;
|
|
384
|
+
}
|
|
385
|
+
if (typeof value === "number") {
|
|
386
|
+
return new Date(value);
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
return new Date(value);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
throw new Error(`Cannot convert value to Date: ${value}`);
|
|
392
|
+
}
|
|
372
393
|
case "uuid":
|
|
373
394
|
return typeof value === "string" ? value : value.toString();
|
|
374
395
|
case "blob":
|
package/package.json
CHANGED
|
@@ -1,63 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "imean-cassandra-orm",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "cassandra orm",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"cassandra",
|
|
7
|
-
"orm",
|
|
8
|
-
"database",
|
|
9
|
-
"node"
|
|
10
|
-
],
|
|
11
|
-
"author": "imean",
|
|
12
|
-
"type": "module",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"main": "dist/mod.js",
|
|
15
|
-
"module": "dist/mod.js",
|
|
16
|
-
"types": "dist/mod.d.ts",
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"types": "./dist/mod.d.ts",
|
|
20
|
-
"import": "./dist/mod.js",
|
|
21
|
-
"require": "./dist/mod.cjs"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"dist",
|
|
26
|
-
"README.md",
|
|
27
|
-
"LICENSE"
|
|
28
|
-
],
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
},
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"@opentelemetry/
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"@opentelemetry/
|
|
43
|
-
"@opentelemetry/
|
|
44
|
-
"@opentelemetry/
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "imean-cassandra-orm",
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "cassandra orm",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cassandra",
|
|
7
|
+
"orm",
|
|
8
|
+
"database",
|
|
9
|
+
"node"
|
|
10
|
+
],
|
|
11
|
+
"author": "imean",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "dist/mod.js",
|
|
15
|
+
"module": "dist/mod.js",
|
|
16
|
+
"types": "dist/mod.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/mod.d.ts",
|
|
20
|
+
"import": "./dist/mod.js",
|
|
21
|
+
"require": "./dist/mod.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"zod": "^3.x",
|
|
32
|
+
"@opentelemetry/api": "^1.x",
|
|
33
|
+
"cassandra-driver": "^4.x"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@opentelemetry/auto-instrumentations-node": "^0.55.3",
|
|
37
|
+
"@opentelemetry/exporter-logs-otlp-proto": "^0.57.1",
|
|
38
|
+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.57.1",
|
|
39
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.57.1",
|
|
40
|
+
"@opentelemetry/sdk-logs": "^0.57.1",
|
|
41
|
+
"@opentelemetry/sdk-metrics": "^1.30.1",
|
|
42
|
+
"@opentelemetry/sdk-node": "^0.57.1",
|
|
43
|
+
"@opentelemetry/sdk-trace-node": "^1.30.1",
|
|
44
|
+
"@opentelemetry/winston-transport": "^0.10.0",
|
|
45
|
+
"@types/node": "^20.0.0",
|
|
46
|
+
"@vitest/coverage-v8": "^3.0.4",
|
|
47
|
+
"tslib": "^2.8.1",
|
|
48
|
+
"tsup": "^8.0.1",
|
|
49
|
+
"tsx": "^4.19.2",
|
|
50
|
+
"typescript": "^5.3.3",
|
|
51
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
52
|
+
"vitest": "^3.0.3"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"dev": "tsx watch dev.ts",
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
62
|
+
}
|