@flowblade/sqlduck 0.11.0 → 0.13.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.
@@ -0,0 +1,207 @@
1
+ import * as z from "zod";
2
+ import { parseDsn } from "@httpx/dsn-parser";
3
+ //#region src/validation/core/base-validators.ts
4
+ const duckIdentifierNameRegex = /^[a-z_]\w*$/i;
5
+ const duckStorageVersionRegexp = /^v?\d{1,4}\.\d{1,4}\.\d{1,4}$/;
6
+ //#endregion
7
+ //#region src/validation/core/duck-reserved-keywords.ts
8
+ /**
9
+ * DuckDB reserved keywords that cannot be used as unquoted identifiers.
10
+ * @see https://duckdb.org/docs/sql/keywords-and-identifiers.html
11
+ */
12
+ const duckReservedKeywords = [
13
+ "ALL",
14
+ "ANALYSE",
15
+ "ANALYZE",
16
+ "AND",
17
+ "ANY",
18
+ "ARRAY",
19
+ "AS",
20
+ "ASC",
21
+ "ASYMMETRIC",
22
+ "BOTH",
23
+ "CASE",
24
+ "CAST",
25
+ "CHECK",
26
+ "COLLATE",
27
+ "COLUMN",
28
+ "CONSTRAINT",
29
+ "CREATE",
30
+ "CROSS",
31
+ "CURRENT_CATALOG",
32
+ "CURRENT_DATE",
33
+ "CURRENT_ROLE",
34
+ "CURRENT_SCHEMA",
35
+ "CURRENT_TIME",
36
+ "CURRENT_TIMESTAMP",
37
+ "CURRENT_USER",
38
+ "DEFAULT",
39
+ "DEFERRABLE",
40
+ "DESC",
41
+ "DISTINCT",
42
+ "DO",
43
+ "ELSE",
44
+ "END",
45
+ "EXCEPT",
46
+ "EXISTS",
47
+ "EXTRACT",
48
+ "FALSE",
49
+ "FETCH",
50
+ "FOR",
51
+ "FOREIGN",
52
+ "FROM",
53
+ "GRANT",
54
+ "GROUP",
55
+ "HAVING",
56
+ "IF",
57
+ "ILIKE",
58
+ "IN",
59
+ "INITIALLY",
60
+ "INNER",
61
+ "INTERSECT",
62
+ "INTO",
63
+ "IS",
64
+ "ISNULL",
65
+ "JOIN",
66
+ "LATERAL",
67
+ "LEADING",
68
+ "LEFT",
69
+ "LIKE",
70
+ "LIMIT",
71
+ "LOCALTIME",
72
+ "LOCALTIMESTAMP",
73
+ "NATURAL",
74
+ "NOT",
75
+ "NOTNULL",
76
+ "NULL",
77
+ "OFFSET",
78
+ "ON",
79
+ "ONLY",
80
+ "OR",
81
+ "ORDER",
82
+ "OUTER",
83
+ "OVERLAPS",
84
+ "PLACING",
85
+ "PRIMARY",
86
+ "REFERENCES",
87
+ "RETURNING",
88
+ "RIGHT",
89
+ "ROW",
90
+ "SELECT",
91
+ "SESSION_USER",
92
+ "SIMILAR",
93
+ "SOME",
94
+ "SYMMETRIC",
95
+ "TABLE",
96
+ "THEN",
97
+ "TO",
98
+ "TRAILING",
99
+ "TRUE",
100
+ "UNION",
101
+ "UNIQUE",
102
+ "USING",
103
+ "VARIADIC",
104
+ "VERBOSE",
105
+ "WHEN",
106
+ "WHERE",
107
+ "WINDOW",
108
+ "WITH"
109
+ ];
110
+ //#endregion
111
+ //#region src/validation/zod/duck-identifier-zod-schema.ts
112
+ const duckdbReservedKeywordsSet = new Set(duckReservedKeywords.map((k) => k.toUpperCase()));
113
+ /**
114
+ * Check whether a table name identifier is valid
115
+ */
116
+ const duckIdentifierZodSchema = z.string().min(1).max(120).regex(duckIdentifierNameRegex, "Identifier must start with a letter or underscore, and contain only letters, numbers and underscores").refine((value) => !duckdbReservedKeywordsSet.has(value.toUpperCase()), { message: `Identifier value is a DuckDB reserved keyword and cannot be used as an identifier` });
117
+ //#endregion
118
+ //#region src/validation/zod/duck-validators-zod.ts
119
+ /**
120
+ * Common validators for duckdb parameters, tables...
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * import { duckValidatorsZod } from '@flowblade/sqlduck/zod';
125
+ *
126
+ * duckValidatorsZod.tableName.parse('my_table'); // valid
127
+ * duckValidatorsZod.tableName.parse('my table'); // invalid
128
+ * ```
129
+ */
130
+ const duckValidatorsZod = {
131
+ aliasName: duckIdentifierZodSchema,
132
+ schemaName: duckIdentifierZodSchema,
133
+ tableName: duckIdentifierZodSchema
134
+ };
135
+ //#endregion
136
+ //#region src/validation/zod/duck-connection-params-zod-schema.ts
137
+ const duckAllConnectionOptionsZodSchema = z.strictObject({
138
+ accessMode: z.optional(z.enum(["READ_ONLY", "READ_WRITE"])),
139
+ compress: z.optional(z.boolean()),
140
+ type: z.optional(z.enum(["DUCKDB", "SQLITE"])),
141
+ blockSize: z.optional(z.int32().min(16384).max(262144)),
142
+ rowGroupSize: z.optional(z.int32().positive()),
143
+ storageVersion: z.optional(z.string().startsWith("v").regex(duckStorageVersionRegexp)),
144
+ encryptionKey: z.optional(z.string().min(8)),
145
+ encryptionCipher: z.optional(z.enum([
146
+ "CBC",
147
+ "CTR",
148
+ "GCM"
149
+ ]))
150
+ });
151
+ const duckConnectionParamsZodSchema = z.discriminatedUnion("type", [z.strictObject({
152
+ type: z.literal("memory"),
153
+ alias: duckValidatorsZod.aliasName,
154
+ options: z.optional(duckAllConnectionOptionsZodSchema)
155
+ }), z.strictObject({
156
+ type: z.literal("duckdb"),
157
+ path: z.string().min(4).endsWith(".db"),
158
+ alias: duckValidatorsZod.aliasName,
159
+ options: z.optional(duckAllConnectionOptionsZodSchema)
160
+ })]);
161
+ //#endregion
162
+ //#region src/validation/core/create-assert-error.ts
163
+ const createAssertError = (msgOrErrorFactory, fallbackMsg) => {
164
+ if (typeof msgOrErrorFactory === "string" || msgOrErrorFactory === void 0) return new TypeError(msgOrErrorFactory ?? fallbackMsg ?? "Assertion did not pass.");
165
+ return msgOrErrorFactory();
166
+ };
167
+ //#endregion
168
+ //#region src/validation/zod/duck-asserts-zod.ts
169
+ function assertValidAliasName(aliasName) {
170
+ const parsed = z.safeParse(duckValidatorsZod.aliasName, aliasName);
171
+ if (parsed.error) throw createAssertError(`'${aliasName}' is not a valid alias name: ${parsed.error.message}`);
172
+ }
173
+ function assertValidSchemaName(schemaName) {
174
+ const parsed = z.safeParse(duckValidatorsZod.schemaName, schemaName);
175
+ if (parsed.error) throw createAssertError(`'${schemaName}' is not a valid schema name: ${parsed.error.message}`);
176
+ }
177
+ function assertValidTableName(tableName) {
178
+ const parsed = z.safeParse(duckValidatorsZod.tableName, tableName);
179
+ if (parsed.error) throw createAssertError(`'${tableName}' is not a valid table name: ${parsed.error.message}`);
180
+ }
181
+ //#endregion
182
+ //#region src/validation/zod/parse-duck-dsn-zod.ts
183
+ const parseDuckDSNZod = (dsn) => {
184
+ const result = parseDsn(dsn);
185
+ if (!result.success) throw new Error(`Invalid DuckDB DSN - ${result.message}`);
186
+ const parsed = result.value;
187
+ const { path, ...options } = parsed.params ?? {};
188
+ return duckConnectionParamsZodSchema.parse({
189
+ type: parsed.host,
190
+ alias: parsed.db,
191
+ ...path ? { path } : {},
192
+ options: { ...options }
193
+ });
194
+ };
195
+ //#endregion
196
+ //#region src/validation/zod/is-parsable-duck-dsn-zod.ts
197
+ const isParsableDuckDsnZod = (dsn) => {
198
+ if (typeof dsn !== "string") return false;
199
+ try {
200
+ parseDuckDSNZod(dsn);
201
+ return true;
202
+ } catch {
203
+ return false;
204
+ }
205
+ };
206
+ //#endregion
207
+ export { assertValidTableName as a, duckValidatorsZod as c, assertValidSchemaName as i, duckReservedKeywords as l, parseDuckDSNZod as n, duckAllConnectionOptionsZodSchema as o, assertValidAliasName as r, duckConnectionParamsZodSchema as s, isParsableDuckDsnZod as t };
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "@flowblade/sqlduck",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
7
7
  ".": {
8
- "import": {
9
- "types": "./dist/index.d.mts",
10
- "default": "./dist/index.mjs"
11
- },
12
- "require": {
13
- "types": "./dist/index.d.cts",
14
- "default": "./dist/index.cjs"
15
- }
8
+ "types": "./dist/index.d.mts",
9
+ "default": "./dist/index.mjs"
10
+ },
11
+ "./zod": {
12
+ "types": "./dist/validation/zod/index.d.mts",
13
+ "default": "./dist/validation/zod/index.mjs"
16
14
  },
17
15
  "./package.json": "./package.json"
18
16
  },
@@ -58,11 +56,11 @@
58
56
  "@flowblade/source-duckdb": "^0.20.1",
59
57
  "@flowblade/sql-tag": "^0.3.2",
60
58
  "@httpx/assert": "^0.16.8",
59
+ "@httpx/dsn-parser": "^1.9.9",
61
60
  "@httpx/plain-object": "^2.1.8",
62
61
  "@logtape/logtape": "^2.0.5",
63
62
  "@standard-schema/spec": "^1.1.0",
64
63
  "p-queue": "9.1.0",
65
- "valibot": "^1.3.1",
66
64
  "zod": "^4.3.6"
67
65
  },
68
66
  "peerDependencies": {
@@ -70,9 +68,9 @@
70
68
  },
71
69
  "devDependencies": {
72
70
  "@belgattitude/eslint-config-bases": "8.10.0",
73
- "@dotenvx/dotenvx": "1.57.2",
71
+ "@dotenvx/dotenvx": "1.59.1",
74
72
  "@duckdb/node-api": "1.5.1-r.1",
75
- "@faker-js/faker": "10.3.0",
73
+ "@faker-js/faker": "10.4.0",
76
74
  "@flowblade/source-kysely": "^1.3.0",
77
75
  "@httpx/assert": "0.16.8",
78
76
  "@mitata/counters": "0.0.8",
@@ -80,13 +78,12 @@
80
78
  "@size-limit/file": "12.0.1",
81
79
  "@testcontainers/mssqlserver": "11.13.0",
82
80
  "@total-typescript/ts-reset": "0.6.1",
83
- "@traversable/zod": "0.0.57",
84
81
  "@types/node": "25.5.0",
85
- "@typescript-eslint/eslint-plugin": "8.57.2",
86
- "@typescript-eslint/parser": "8.57.2",
82
+ "@typescript-eslint/eslint-plugin": "8.58.0",
83
+ "@typescript-eslint/parser": "8.58.0",
87
84
  "@typescript/native-preview": "7.0.0-dev.20260324.1",
88
- "@vitest/coverage-v8": "4.1.1",
89
- "@vitest/ui": "4.1.1",
85
+ "@vitest/coverage-v8": "4.1.2",
86
+ "@vitest/ui": "4.1.2",
90
87
  "ansis": "4.2.0",
91
88
  "browserslist-to-esbuild": "2.1.1",
92
89
  "core-js": "3.49.0",
@@ -97,7 +94,7 @@
97
94
  "eslint": "8.57.1",
98
95
  "execa": "9.6.1",
99
96
  "is-in-ci": "2.0.0",
100
- "kysely": "0.28.14",
97
+ "kysely": "0.28.15",
101
98
  "mitata": "1.0.34",
102
99
  "npm-run-all2": "8.0.4",
103
100
  "prettier": "3.8.1",
@@ -105,16 +102,16 @@
105
102
  "regexp.escape": "2.0.1",
106
103
  "rimraf": "6.1.3",
107
104
  "size-limit": "12.0.1",
108
- "sql-formatter": "15.7.2",
105
+ "sql-formatter": "15.7.3",
109
106
  "tarn": "3.0.2",
110
107
  "tedious": "19.2.1",
111
108
  "testcontainers": "11.13.0",
112
- "tsdown": "0.21.5",
109
+ "tsdown": "0.21.7",
113
110
  "tsx": "4.21.0",
114
111
  "typedoc": "0.28.18",
115
112
  "typedoc-plugin-markdown": "4.11.0",
116
113
  "typescript": "6.0.2",
117
- "vitest": "4.1.1"
114
+ "vitest": "4.1.2"
118
115
  },
119
116
  "files": [
120
117
  "dist"