@flowblade/sqlduck 0.35.0 → 0.36.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.
|
@@ -255,7 +255,7 @@ type MapRelaxedZodSchemaField<T extends z.ZodTypeAny> = T extends z.ZodDate ? st
|
|
|
255
255
|
type InferZodRelaxedDataSchema<T extends z.ZodObject<any>> = { [K in keyof T['shape']]: MapRelaxedZodSchemaField<T['shape'][K]>; };
|
|
256
256
|
//#endregion
|
|
257
257
|
//#region src/validation/zod/table-schema-zod.d.ts
|
|
258
|
-
type ZodSchemaSupportedTypes = z.ZodString | z.ZodNumber | z.ZodInt | z.ZodInt32 | z.ZodUInt32 | z.ZodBigInt | z.ZodBoolean | z.ZodDate | z.ZodISODateTime | z.ZodISOTime | z.ZodISODate | z.ZodEmail | z.ZodURL | z.ZodUUID | z.ZodCUID | z.ZodCUID2 | z.ZodULID | z.ZodEnum;
|
|
258
|
+
type ZodSchemaSupportedTypes = z.ZodString | z.ZodNumber | z.ZodInt | z.ZodInt32 | z.ZodUInt32 | z.ZodBigInt | z.ZodBoolean | z.ZodDate | z.ZodISODateTime | z.ZodISOTime | z.ZodISODate | z.ZodEmail | z.ZodURL | z.ZodUUID | z.ZodCUID | z.ZodCUID2 | z.ZodULID | z.ZodEnum | z.ZodArray;
|
|
259
259
|
type TableSchemaZod = z.ZodObject<Record<string, ZodSchemaSupportedTypes | z.ZodNullable<ZodSchemaSupportedTypes> | z.ZodCodec | z.ZodNullable<z.ZodCodec>>>;
|
|
260
260
|
//#endregion
|
|
261
261
|
export { duckDsnZodSchema as a, assertValidTableName as c, duckConnectionParamsZodSchema as d, duckValidatorsZod as i, DuckConnectionParams as l, InferZodRelaxedDataSchema as n, assertValidAliasName as o, ensureZodTableSchema as r, assertValidSchemaName as s, TableSchemaZod as t, duckAllConnectionOptionsZodSchema as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as DuckConnectionParams, n as InferZodRelaxedDataSchema, t as TableSchemaZod } from "./index-
|
|
2
|
-
import { DuckDBConnection, DuckDBType } from "@duckdb/node-api";
|
|
1
|
+
import { l as DuckConnectionParams, n as InferZodRelaxedDataSchema, t as TableSchemaZod } from "./index-Z9LfGsCV.mjs";
|
|
2
|
+
import { DuckDBConnection, DuckDBDecimalType, DuckDBListType, DuckDBType } from "@duckdb/node-api";
|
|
3
3
|
import { Logger } from "@logtape/logtape";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
import { ZodObject } from "zod";
|
|
@@ -91,6 +91,8 @@ type GetTableCreateFromZodParams<TSchema extends TableSchemaZod> = {
|
|
|
91
91
|
schema: TSchema;
|
|
92
92
|
options?: TableCreateOptions;
|
|
93
93
|
};
|
|
94
|
+
declare const duckDbTypes: [["VARCHAR", import("@duckdb/node-api").DuckDBVarCharType], ["BIGINT", import("@duckdb/node-api").DuckDBBigIntType], ["UBIGINT", import("@duckdb/node-api").DuckDBUBigIntType], ["HUGEINT", import("@duckdb/node-api").DuckDBHugeIntType], ["TIMESTAMP", import("@duckdb/node-api").DuckDBTimestampType], ["TIMESTAMP_MS", import("@duckdb/node-api").DuckDBTimestampMillisecondsType], ["UUID", import("@duckdb/node-api").DuckDBUUIDType], ["BOOLEAN", import("@duckdb/node-api").DuckDBBooleanType], ["INTEGER", import("@duckdb/node-api").DuckDBIntegerType], ["DOUBLE", import("@duckdb/node-api").DuckDBDoubleType], ["FLOAT", import("@duckdb/node-api").DuckDBFloatType], ["DATE", import("@duckdb/node-api").DuckDBDateType], ["DECIMAL", DuckDBDecimalType], ["VARCHAR[]", DuckDBListType], ["INTEGER[]", DuckDBListType], ["BOOLEAN[]", DuckDBListType], ["BIGINT[]", DuckDBListType], ["UBIGINT[]", DuckDBListType], ["UUID[]", DuckDBListType], ["DATE[]", DuckDBListType], ["TIMESTAMP[]", DuckDBListType], ["TIMESTAMP_MS[]", DuckDBListType], ["DOUBLE[]", DuckDBListType], ["FLOAT[]", DuckDBListType]];
|
|
95
|
+
type SupportedCustomDuckDbTypes = (typeof duckDbTypes)[number][0];
|
|
94
96
|
declare const getTableCreateFromZod: <TSchema extends TableSchemaZod>(params: GetTableCreateFromZodParams<TSchema>) => TableCreateFromZodResult<TSchema>;
|
|
95
97
|
//#endregion
|
|
96
98
|
//#region src/sql-duck.d.ts
|
|
@@ -438,4 +440,4 @@ declare const flowbladeLogtapeSqlduckConfig: {
|
|
|
438
440
|
//#region src/logger/sqlduck-default-logtape-logger.d.ts
|
|
439
441
|
declare const sqlduckDefaultLogtapeLogger: import("@logtape/logtape").Logger;
|
|
440
442
|
//#endregion
|
|
441
|
-
export { Database, type DuckConnectionParams, DuckDatabaseManager, DuckExtensionsManager, DuckMemory, type DuckMemoryTag, DuckSettingsManager, type DuckdbReservedKeywords, type OnChunkAppendedCb, type OnChunkAppendedStats, SqlDuck, type SqlDuckParams, Table, type ToTableParams, duckReservedKeywords, flowbladeLogtapeSqlduckConfig, getTableCreateFromZod, sqlduckDefaultLogtapeLogger, zodCodecs };
|
|
443
|
+
export { Database, type DuckConnectionParams, DuckDatabaseManager, DuckExtensionsManager, DuckMemory, type DuckMemoryTag, DuckSettingsManager, type DuckdbReservedKeywords, type OnChunkAppendedCb, type OnChunkAppendedStats, SqlDuck, type SqlDuckParams, type SupportedCustomDuckDbTypes, Table, type ToTableParams, duckReservedKeywords, flowbladeLogtapeSqlduckConfig, getTableCreateFromZod, sqlduckDefaultLogtapeLogger, zodCodecs };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as sqlduckDefaultLogtapeLogger, r as flowbladeLogtapeSqlduckConfig, t as FileSystemUtils } from "./file-system-utils-DT6smf4C.mjs";
|
|
2
2
|
import { t as duckReservedKeywords } from "./duck-reserved-keywords-BzYA7jvN.mjs";
|
|
3
3
|
import { c as duckValidatorsZod, r as assertValidAliasName, s as duckConnectionParamsZodSchema } from "./zod-DB5FHzXW.mjs";
|
|
4
|
-
import { BIGINT, BOOLEAN, DATE, DECIMAL, DOUBLE, DuckDBDataChunk, DuckDBDateValue, DuckDBDecimalType, DuckDBDecimalValue, DuckDBInstanceCache, DuckDBTimestampMillisecondsValue, DuckDBTypeId, ENUM, FLOAT, HUGEINT, INTEGER, SMALLINT, TIMESTAMP, TIMESTAMP_MS, TINYINT, UBIGINT, UHUGEINT, UINTEGER, USMALLINT, UTINYINT, UUID, VARCHAR } from "@duckdb/node-api";
|
|
4
|
+
import { BIGINT, BOOLEAN, DATE, DECIMAL, DOUBLE, DuckDBDataChunk, DuckDBDateValue, DuckDBDecimalType, DuckDBDecimalValue, DuckDBInstanceCache, DuckDBListType, DuckDBTimestampMillisecondsValue, DuckDBTypeId, ENUM, FLOAT, HUGEINT, INTEGER, LIST, SMALLINT, TIMESTAMP, TIMESTAMP_MS, TINYINT, UBIGINT, UHUGEINT, UINTEGER, USMALLINT, UTINYINT, UUID, VARCHAR, listValue } from "@duckdb/node-api";
|
|
5
5
|
import * as z from "zod";
|
|
6
6
|
import { assertNever } from "@httpx/assert";
|
|
7
7
|
import { isPlainObject } from "@httpx/plain-object";
|
|
@@ -191,6 +191,10 @@ var DuckValueConverter = class {
|
|
|
191
191
|
value
|
|
192
192
|
});
|
|
193
193
|
};
|
|
194
|
+
toList = (arrayValue) => {
|
|
195
|
+
if (arrayValue === void 0 || arrayValue === null) return null;
|
|
196
|
+
return listValue(arrayValue);
|
|
197
|
+
};
|
|
194
198
|
toTimestampMs = (value) => {
|
|
195
199
|
if (value instanceof Date) return new DuckDBTimestampMillisecondsValue(BigInt(value.getTime()));
|
|
196
200
|
if (value === void 0 || value === null) return null;
|
|
@@ -258,6 +262,9 @@ const createDuckColumnConverters = (duckTypes) => {
|
|
|
258
262
|
case DuckDBTypeId.DATE:
|
|
259
263
|
conv = converter.toDate;
|
|
260
264
|
break;
|
|
265
|
+
case DuckDBTypeId.LIST:
|
|
266
|
+
conv = converter.toList;
|
|
267
|
+
break;
|
|
261
268
|
default: throw new Error(`Unsupported duck type ${duckTypeId} / ${duckType.toString()} for column '${key}'`);
|
|
262
269
|
}
|
|
263
270
|
if (conv !== false) convMap[key] = conv;
|
|
@@ -651,11 +658,11 @@ const getScale = (value) => {
|
|
|
651
658
|
};
|
|
652
659
|
const getDuckdbNumberColumnType = (params) => {
|
|
653
660
|
const { minimum, maximum, multipleOf } = params;
|
|
654
|
-
if (minimum === void 0 || maximum === void 0) return BIGINT;
|
|
655
661
|
if (multipleOf !== void 0 && isFloatValue(multipleOf)) {
|
|
656
662
|
const scale = getScale(multipleOf);
|
|
657
663
|
return DECIMAL(18, scale);
|
|
658
664
|
}
|
|
665
|
+
if (minimum === void 0 || maximum === void 0) return BIGINT;
|
|
659
666
|
if (isFloatValue(minimum) || isFloatValue(maximum)) {
|
|
660
667
|
if (minimum >= -34028235e31 && maximum <= 34028235e31) return FLOAT;
|
|
661
668
|
return DOUBLE;
|
|
@@ -693,7 +700,18 @@ const duckDbTypes = [
|
|
|
693
700
|
["DOUBLE", DOUBLE],
|
|
694
701
|
["FLOAT", FLOAT],
|
|
695
702
|
["DATE", DATE],
|
|
696
|
-
["DECIMAL", new DuckDBDecimalType(18, 3)]
|
|
703
|
+
["DECIMAL", new DuckDBDecimalType(18, 3)],
|
|
704
|
+
["VARCHAR[]", new DuckDBListType(VARCHAR)],
|
|
705
|
+
["INTEGER[]", new DuckDBListType(INTEGER)],
|
|
706
|
+
["BOOLEAN[]", new DuckDBListType(BOOLEAN)],
|
|
707
|
+
["BIGINT[]", new DuckDBListType(BIGINT)],
|
|
708
|
+
["UBIGINT[]", new DuckDBListType(UBIGINT)],
|
|
709
|
+
["UUID[]", new DuckDBListType(UUID)],
|
|
710
|
+
["DATE[]", new DuckDBListType(DATE)],
|
|
711
|
+
["TIMESTAMP[]", new DuckDBListType(TIMESTAMP)],
|
|
712
|
+
["TIMESTAMP_MS[]", new DuckDBListType(TIMESTAMP_MS)],
|
|
713
|
+
["DOUBLE[]", new DuckDBListType(DOUBLE)],
|
|
714
|
+
["FLOAT[]", new DuckDBListType(FLOAT)]
|
|
697
715
|
];
|
|
698
716
|
const duckDbTypesMap = new Map(duckDbTypes);
|
|
699
717
|
const getTableCreateFromZod = (params) => {
|
|
@@ -710,8 +728,33 @@ const getTableCreateFromZod = (params) => {
|
|
|
710
728
|
for (const [columnName, def] of Object.entries(json.properties)) {
|
|
711
729
|
const { type, duckdbType, nullable, format, primaryKey, minimum, maximum, multipleOf } = def;
|
|
712
730
|
const c = { name: columnName };
|
|
713
|
-
if (duckdbType !== void 0 && duckDbTypesMap.has(duckdbType))
|
|
714
|
-
|
|
731
|
+
if (duckdbType !== void 0 && !duckDbTypesMap.has(duckdbType)) throw new Error(`The provided "duckdbType: '${duckdbType}'" for '${columnName}' isn't currently supported - ${JSON.stringify(def)}`);
|
|
732
|
+
const customDuckDbType = duckdbType === void 0 ? void 0 : duckDbTypesMap.get(duckdbType);
|
|
733
|
+
if (customDuckDbType === void 0) switch (type) {
|
|
734
|
+
case "array":
|
|
735
|
+
switch (def?.items?.type) {
|
|
736
|
+
case "string":
|
|
737
|
+
c.duckdbType = LIST(VARCHAR);
|
|
738
|
+
break;
|
|
739
|
+
case "integer":
|
|
740
|
+
c.duckdbType = LIST(getDuckdbNumberColumnType({
|
|
741
|
+
minimum: def?.items?.minimum,
|
|
742
|
+
maximum: def?.items?.maximum
|
|
743
|
+
}));
|
|
744
|
+
break;
|
|
745
|
+
case "number":
|
|
746
|
+
c.duckdbType = LIST(getDuckdbNumberColumnType({
|
|
747
|
+
minimum: def?.items?.minimum,
|
|
748
|
+
maximum: def?.items?.maximum,
|
|
749
|
+
multipleOf: def?.items?.multipleOf
|
|
750
|
+
}));
|
|
751
|
+
break;
|
|
752
|
+
case "boolean":
|
|
753
|
+
c.duckdbType = LIST(BOOLEAN);
|
|
754
|
+
break;
|
|
755
|
+
default: throw new Error(`The inferred duckdb array for '${columnName}' is not supported - ${JSON.stringify(def)}`);
|
|
756
|
+
}
|
|
757
|
+
break;
|
|
715
758
|
case "string":
|
|
716
759
|
if (Array.isArray(def.enum)) c.duckdbType = ENUM(def.enum);
|
|
717
760
|
else switch (format) {
|
|
@@ -748,6 +791,7 @@ const getTableCreateFromZod = (params) => {
|
|
|
748
791
|
break;
|
|
749
792
|
default: throw new Error(`Cannot guess '${columnName}' type - ${JSON.stringify(def)}`);
|
|
750
793
|
}
|
|
794
|
+
else c.duckdbType = customDuckDbType;
|
|
751
795
|
if (primaryKey === true) c.constraint = "PRIMARY KEY";
|
|
752
796
|
else if (nullable !== true) c.constraint = "NOT NULL";
|
|
753
797
|
columnTypesMap.set(columnName, c.duckdbType);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as duckDsnZodSchema, c as assertValidTableName, d as duckConnectionParamsZodSchema, i as duckValidatorsZod, n as InferZodRelaxedDataSchema, o as assertValidAliasName, r as ensureZodTableSchema, s as assertValidSchemaName, t as TableSchemaZod, u as duckAllConnectionOptionsZodSchema } from "../../index-
|
|
1
|
+
import { a as duckDsnZodSchema, c as assertValidTableName, d as duckConnectionParamsZodSchema, i as duckValidatorsZod, n as InferZodRelaxedDataSchema, o as assertValidAliasName, r as ensureZodTableSchema, s as assertValidSchemaName, t as TableSchemaZod, u as duckAllConnectionOptionsZodSchema } from "../../index-Z9LfGsCV.mjs";
|
|
2
2
|
export { type InferZodRelaxedDataSchema, type TableSchemaZod, assertValidAliasName, assertValidSchemaName, assertValidTableName, duckAllConnectionOptionsZodSchema, duckConnectionParamsZodSchema, duckDsnZodSchema, duckValidatorsZod, ensureZodTableSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowblade/sqlduck",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"@belgattitude/eslint-config-bases": "8.19.1",
|
|
96
96
|
"@dotenvx/dotenvx": "2.21.0",
|
|
97
97
|
"@duckdb/node-api": "1.5.5-r.4",
|
|
98
|
-
"@faker-js/faker": "10.
|
|
98
|
+
"@faker-js/faker": "10.6.0",
|
|
99
99
|
"@flowblade/source-kysely": "^1.7.0",
|
|
100
100
|
"@httpx/assert": "0.18.0",
|
|
101
101
|
"@mitata/counters": "0.0.8",
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"@typescript-eslint/eslint-plugin": "8.67.0",
|
|
108
108
|
"@typescript-eslint/parser": "8.67.0",
|
|
109
109
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
110
|
-
"@vitest/coverage-v8": "4.1.
|
|
111
|
-
"@vitest/ui": "4.1.
|
|
110
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
111
|
+
"@vitest/ui": "4.1.11",
|
|
112
112
|
"ansis": "4.3.1",
|
|
113
113
|
"browserslist-to-esbuild": "2.1.1",
|
|
114
114
|
"core-js": "3.50.0",
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
"typedoc-plugin-markdown": "4.12.0",
|
|
138
138
|
"typescript": "6.0.3",
|
|
139
139
|
"valibot": "1.4.2",
|
|
140
|
-
"vitest": "4.1.
|
|
140
|
+
"vitest": "4.1.11"
|
|
141
141
|
},
|
|
142
142
|
"files": [
|
|
143
143
|
"dist"
|