imean-cassandra-orm 2.2.2 → 2.4.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 +63 -17
- package/dist/mod.js +63 -17
- package/package.json +1 -1
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":
|
|
@@ -378,7 +399,16 @@ function convertValueToCassandra(value, config) {
|
|
|
378
399
|
case "text":
|
|
379
400
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
380
401
|
default:
|
|
381
|
-
|
|
402
|
+
const type = config.type;
|
|
403
|
+
switch (type) {
|
|
404
|
+
case "list<text>":
|
|
405
|
+
case "set<text>":
|
|
406
|
+
return value.map(
|
|
407
|
+
(item) => typeof item === "string" ? item : JSON.stringify(item)
|
|
408
|
+
);
|
|
409
|
+
default:
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
382
412
|
}
|
|
383
413
|
}
|
|
384
414
|
function convertValueFromCassandra(value, config) {
|
|
@@ -399,13 +429,29 @@ function convertValueFromCassandra(value, config) {
|
|
|
399
429
|
case "blob":
|
|
400
430
|
return value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
401
431
|
case "text":
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
432
|
+
if (config.type !== "text") {
|
|
433
|
+
try {
|
|
434
|
+
return JSON.parse(value);
|
|
435
|
+
} catch {
|
|
436
|
+
return value;
|
|
437
|
+
}
|
|
406
438
|
}
|
|
407
|
-
default:
|
|
408
439
|
return value;
|
|
440
|
+
default:
|
|
441
|
+
const type = config.type;
|
|
442
|
+
switch (type) {
|
|
443
|
+
case "list<text>":
|
|
444
|
+
case "set<text>":
|
|
445
|
+
return value.map((item) => {
|
|
446
|
+
try {
|
|
447
|
+
return JSON.parse(item);
|
|
448
|
+
} catch {
|
|
449
|
+
return item;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
default:
|
|
453
|
+
return value;
|
|
454
|
+
}
|
|
409
455
|
}
|
|
410
456
|
}
|
|
411
457
|
var queryHelper = {
|
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":
|
|
@@ -376,7 +397,16 @@ function convertValueToCassandra(value, config) {
|
|
|
376
397
|
case "text":
|
|
377
398
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
378
399
|
default:
|
|
379
|
-
|
|
400
|
+
const type = config.type;
|
|
401
|
+
switch (type) {
|
|
402
|
+
case "list<text>":
|
|
403
|
+
case "set<text>":
|
|
404
|
+
return value.map(
|
|
405
|
+
(item) => typeof item === "string" ? item : JSON.stringify(item)
|
|
406
|
+
);
|
|
407
|
+
default:
|
|
408
|
+
return value;
|
|
409
|
+
}
|
|
380
410
|
}
|
|
381
411
|
}
|
|
382
412
|
function convertValueFromCassandra(value, config) {
|
|
@@ -397,13 +427,29 @@ function convertValueFromCassandra(value, config) {
|
|
|
397
427
|
case "blob":
|
|
398
428
|
return value instanceof Uint8Array ? value : new Uint8Array(value);
|
|
399
429
|
case "text":
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
430
|
+
if (config.type !== "text") {
|
|
431
|
+
try {
|
|
432
|
+
return JSON.parse(value);
|
|
433
|
+
} catch {
|
|
434
|
+
return value;
|
|
435
|
+
}
|
|
404
436
|
}
|
|
405
|
-
default:
|
|
406
437
|
return value;
|
|
438
|
+
default:
|
|
439
|
+
const type = config.type;
|
|
440
|
+
switch (type) {
|
|
441
|
+
case "list<text>":
|
|
442
|
+
case "set<text>":
|
|
443
|
+
return value.map((item) => {
|
|
444
|
+
try {
|
|
445
|
+
return JSON.parse(item);
|
|
446
|
+
} catch {
|
|
447
|
+
return item;
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
default:
|
|
451
|
+
return value;
|
|
452
|
+
}
|
|
407
453
|
}
|
|
408
454
|
}
|
|
409
455
|
var queryHelper = {
|