@casekit/sql 0.0.0-20250331202540 → 0.0.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.
Files changed (3) hide show
  1. package/build/sql.d.ts +15 -9
  2. package/build/sql.js +24 -13
  3. package/package.json +14 -14
package/build/sql.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import pg from "pg";
2
- import { ZodSchema, z } from "zod";
2
+ import { ZodType, z } from "zod";
3
3
  type SQLStatementTaggedTemplateLiteral<ResultType extends pg.QueryResultRow = pg.QueryResultRow> = (fragments: TemplateStringsArray, ...values: readonly unknown[]) => SQLStatement<ResultType>;
4
4
  /**
5
5
  * @function
@@ -17,13 +17,13 @@ type SQLStatementTaggedTemplateLiteral<ResultType extends pg.QueryResultRow = pg
17
17
  * `;
18
18
  */
19
19
  declare function sql<ResultType extends pg.QueryResultRow = pg.QueryResultRow>(fragments: TemplateStringsArray, ...values: readonly unknown[]): SQLStatement<ResultType>;
20
- declare function sql<ResultType extends pg.QueryResultRow = pg.QueryResultRow>(schema: z.ZodSchema<ResultType>): SQLStatementTaggedTemplateLiteral<ResultType>;
20
+ declare function sql<ResultType extends pg.QueryResultRow = pg.QueryResultRow>(schema: z.ZodType<ResultType>): SQLStatementTaggedTemplateLiteral<ResultType>;
21
21
  declare namespace sql {
22
22
  var array: (values: readonly unknown[]) => SQLValueArray;
23
- var ident: (value: string) => SQLStatement<pg.QueryResultRow>;
24
- var literal: (value: string) => SQLStatement<pg.QueryResultRow>;
25
- var join: (values: SQLStatement[], separator?: string) => SQLStatement<pg.QueryResultRow>;
26
- var value: (value: unknown) => SQLValueArray | SQLStatement<pg.QueryResultRow>;
23
+ var ident: (value: string) => SQLStatement<import("pg").QueryResultRow>;
24
+ var literal: (value: string) => SQLStatement<import("pg").QueryResultRow>;
25
+ var join: (values: SQLStatement[], separator?: string) => SQLStatement<import("pg").QueryResultRow>;
26
+ var value: (value: unknown) => SQLValueArray | SQLStatement<import("pg").QueryResultRow>;
27
27
  }
28
28
  /**
29
29
  * Class representing a SQL statement created by the `sql` template tag.
@@ -39,8 +39,11 @@ declare namespace sql {
39
39
  export declare class SQLStatement<ResultType extends pg.QueryResultRow = pg.QueryResultRow> {
40
40
  readonly _text: string[];
41
41
  readonly _values: unknown[];
42
- protected _schema?: ZodSchema<ResultType>;
42
+ protected _schema?: ZodType<ResultType>;
43
43
  constructor(text?: readonly string[] | string, values?: readonly unknown[]);
44
+ private static readonly __classId;
45
+ readonly __classId: symbol;
46
+ static [Symbol.hasInstance](obj: any): boolean;
44
47
  /**
45
48
  * This accessor is called by node-postgres when passed as a query,
46
49
  * allowing us to pass a SQLStatement to `client.query` directly.
@@ -76,12 +79,12 @@ export declare class SQLStatement<ResultType extends pg.QueryResultRow = pg.Quer
76
79
  * The Zod schema that will be used to parse and validate
77
80
  * the results of the query when it is passed to `orm.query`.
78
81
  */
79
- get schema(): ZodSchema<ResultType> | undefined;
82
+ get schema(): ZodType<ResultType> | undefined;
80
83
  /**
81
84
  * Assign a zod schema to this SQLStatement, which will be used to validate
82
85
  * the result of the query when it is passed to `orm.query`.
83
86
  */
84
- withSchema<Schema extends ZodSchema>(schema: Schema): SQLStatement<z.infer<Schema>>;
87
+ withSchema<Schema extends ZodType<pg.QueryResultRow>>(schema: Schema): SQLStatement<z.infer<Schema>>;
85
88
  }
86
89
  /**
87
90
  * A class to wrap an array value that we don't want
@@ -90,5 +93,8 @@ export declare class SQLStatement<ResultType extends pg.QueryResultRow = pg.Quer
90
93
  export declare class SQLValueArray {
91
94
  values: unknown[];
92
95
  constructor(values: readonly unknown[]);
96
+ private static readonly __classId;
97
+ readonly __classId: symbol;
98
+ static [Symbol.hasInstance](obj: any): boolean;
93
99
  }
94
100
  export { sql };
package/build/sql.js CHANGED
@@ -77,7 +77,7 @@ const expandFragment = ([fragment, value]) => {
77
77
  }
78
78
  };
79
79
  function sql(fragmentsOrSchema, ...values) {
80
- if (fragmentsOrSchema instanceof z.ZodSchema) {
80
+ if (fragmentsOrSchema instanceof z.ZodType) {
81
81
  return (fragments, ...values) => sql(fragments, ...values).withSchema(fragmentsOrSchema);
82
82
  }
83
83
  const result = zip(fragmentsOrSchema, values)
@@ -109,17 +109,14 @@ export class SQLStatement {
109
109
  // any instantiation of this class in memory, so we encode a random
110
110
  // uuid and override instanceof to check this in place of the usual check.
111
111
  // see https://github.com/colinhacks/zod/issues/2241 for more info
112
- // private static readonly __classId = Symbol.for(
113
- // "@casekit/orm/sql/SQLStatement-1C9E8AD8-4B55-41F0-95D0-934891ADB0C0",
114
- // );
115
- // public readonly __classId = SQLStatement.__classId;
116
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
- // static [Symbol.hasInstance](obj: any) {
118
- // return (
119
- // // eslint-disable-next-line
120
- // !!obj && obj.__classId === SQLStatement.__classId
121
- // );
122
- // }
112
+ static __classId = Symbol.for("@casekit/orm/sql/SQLStatement-1C9E8AD8-4B55-41F0-95D0-934891ADB0C0");
113
+ __classId = SQLStatement.__classId;
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
+ static [Symbol.hasInstance](obj) {
116
+ return (
117
+ // eslint-disable-next-line
118
+ !!obj && obj.__classId === SQLStatement.__classId);
119
+ }
123
120
  /**
124
121
  * This accessor is called by node-postgres when passed as a query,
125
122
  * allowing us to pass a SQLStatement to `client.query` directly.
@@ -191,7 +188,8 @@ export class SQLStatement {
191
188
  */
192
189
  withSchema(schema) {
193
190
  const self = this;
194
- self._schema = schema;
191
+ // @ts-expect-error - TODO figure out how to make this work with ZodType
192
+ this._schema = schema;
195
193
  return self;
196
194
  }
197
195
  }
@@ -204,6 +202,19 @@ export class SQLValueArray {
204
202
  constructor(values) {
205
203
  this.values = [...values];
206
204
  }
205
+ // this weirdness deals with the case where we have multiple instantiations
206
+ // of this class, breaking instanceof. we want instanceof to work for
207
+ // any instantiation of this class in memory, so we encode a random
208
+ // uuid and override instanceof to check this in place of the usual check.
209
+ // see https://github.com/colinhacks/zod/issues/2241 for more info
210
+ static __classId = Symbol.for("@casekit/orm/sql/SQLValueArray-67F77E7C-EB62-46DD-813E-BF58710D5CEC");
211
+ __classId = SQLValueArray.__classId;
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ static [Symbol.hasInstance](obj) {
214
+ return (
215
+ // eslint-disable-next-line
216
+ !!obj && obj.__classId === SQLValueArray.__classId);
217
+ }
207
218
  }
208
219
  const array = (values) => new SQLValueArray(values);
209
220
  const ident = (value) => new SQLStatement(pg.escapeIdentifier(value));
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
1
  {
2
2
  "name": "@casekit/sql",
3
3
  "description": "",
4
- "version": "0.0.0-20250331202540",
4
+ "version": "0.0.1",
5
5
  "author": "",
6
6
  "dependencies": {
7
7
  "@casekit/unindent": "^1.0.5",
8
- "es-toolkit": "^1.33.0",
9
- "sql-formatter": "^15.5.1",
10
- "@casekit/toolbox": "0.0.0-20250331202540"
8
+ "es-toolkit": "^1.39.3",
9
+ "sql-formatter": "^15.6.5",
10
+ "@casekit/toolbox": "0.0.1"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
14
- "@types/node": "^22.13.13",
15
- "@types/pg": "^8.11.11",
16
- "@vitest/coverage-v8": "^3.0.9",
17
- "dotenv": "^16.4.7",
14
+ "@types/node": "^24.0.3",
15
+ "@types/pg": "^8.15.4",
16
+ "@vitest/coverage-v8": "^3.2.4",
17
+ "dotenv": "^16.5.0",
18
18
  "prettier": "^3.5.3",
19
- "prettier-plugin-svelte": "^3.3.3",
19
+ "prettier-plugin-svelte": "^3.4.0",
20
+ "typescript": "^5.8.3",
20
21
  "vite-tsconfig-paths": "^5.1.4",
21
- "vitest": "^3.0.9",
22
- "@casekit/prettier-config": "0.0.0-20250331202540",
23
- "@casekit/tsconfig": "0.0.0-20250331202540"
22
+ "vitest": "^3.2.4",
23
+ "@casekit/tsconfig": "0.0.1",
24
+ "@casekit/prettier-config": "0.0.1"
24
25
  },
25
26
  "exports": {
26
27
  ".": "./build/index.js"
@@ -33,10 +34,9 @@
33
34
  },
34
35
  "keywords": [],
35
36
  "license": "ISC",
36
- "main": "index.js",
37
37
  "peerDependencies": {
38
38
  "pg": "^8.13.1",
39
- "zod": "^3.24.2"
39
+ "zod": "^4.0.17"
40
40
  },
41
41
  "prettier": "@casekit/prettier-config",
42
42
  "type": "module",