kysely 0.28.14 → 0.28.16

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.
@@ -1,4 +1,5 @@
1
1
  /// <reference types="./update-query-builder.d.ts" />
2
+ var _a;
2
3
  import { parseJoin, } from '../parser/join-parser.js';
3
4
  import { parseTableExpressionOrList, } from '../parser/table-parser.js';
4
5
  import { parseSelectArg, parseSelectAll, } from '../parser/select-parser.js';
@@ -19,19 +20,19 @@ export class UpdateQueryBuilder {
19
20
  this.#props = freeze(props);
20
21
  }
21
22
  where(...args) {
22
- return new UpdateQueryBuilder({
23
+ return new _a({
23
24
  ...this.#props,
24
25
  queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseValueBinaryOperationOrExpression(args)),
25
26
  });
26
27
  }
27
28
  whereRef(lhs, op, rhs) {
28
- return new UpdateQueryBuilder({
29
+ return new _a({
29
30
  ...this.#props,
30
31
  queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseReferentialBinaryOperation(lhs, op, rhs)),
31
32
  });
32
33
  }
33
34
  clearWhere() {
34
- return new UpdateQueryBuilder({
35
+ return new _a({
35
36
  ...this.#props,
36
37
  queryNode: QueryNode.cloneWithoutWhere(this.#props.queryNode),
37
38
  });
@@ -76,13 +77,13 @@ export class UpdateQueryBuilder {
76
77
  * ```
77
78
  */
78
79
  top(expression, modifiers) {
79
- return new UpdateQueryBuilder({
80
+ return new _a({
80
81
  ...this.#props,
81
82
  queryNode: QueryNode.cloneWithTop(this.#props.queryNode, parseTop(expression, modifiers)),
82
83
  });
83
84
  }
84
85
  from(from) {
85
- return new UpdateQueryBuilder({
86
+ return new _a({
86
87
  ...this.#props,
87
88
  queryNode: UpdateQueryNode.cloneWithFromItems(this.#props.queryNode, parseTableExpressionOrList(from)),
88
89
  });
@@ -100,19 +101,19 @@ export class UpdateQueryBuilder {
100
101
  return this.#join('FullJoin', args);
101
102
  }
102
103
  #join(joinType, args) {
103
- return new UpdateQueryBuilder({
104
+ return new _a({
104
105
  ...this.#props,
105
106
  queryNode: QueryNode.cloneWithJoin(this.#props.queryNode, parseJoin(joinType, args)),
106
107
  });
107
108
  }
108
109
  orderBy(...args) {
109
- return new UpdateQueryBuilder({
110
+ return new _a({
110
111
  ...this.#props,
111
112
  queryNode: QueryNode.cloneWithOrderByItems(this.#props.queryNode, parseOrderBy(args)),
112
113
  });
113
114
  }
114
115
  clearOrderBy() {
115
- return new UpdateQueryBuilder({
116
+ return new _a({
116
117
  ...this.#props,
117
118
  queryNode: QueryNode.cloneWithoutOrderBy(this.#props.queryNode),
118
119
  });
@@ -139,37 +140,37 @@ export class UpdateQueryBuilder {
139
140
  * ```
140
141
  */
141
142
  limit(limit) {
142
- return new UpdateQueryBuilder({
143
+ return new _a({
143
144
  ...this.#props,
144
145
  queryNode: UpdateQueryNode.cloneWithLimit(this.#props.queryNode, LimitNode.create(parseValueExpression(limit))),
145
146
  });
146
147
  }
147
148
  set(...args) {
148
- return new UpdateQueryBuilder({
149
+ return new _a({
149
150
  ...this.#props,
150
151
  queryNode: UpdateQueryNode.cloneWithUpdates(this.#props.queryNode, parseUpdate(...args)),
151
152
  });
152
153
  }
153
154
  returning(selection) {
154
- return new UpdateQueryBuilder({
155
+ return new _a({
155
156
  ...this.#props,
156
157
  queryNode: QueryNode.cloneWithReturning(this.#props.queryNode, parseSelectArg(selection)),
157
158
  });
158
159
  }
159
160
  returningAll(table) {
160
- return new UpdateQueryBuilder({
161
+ return new _a({
161
162
  ...this.#props,
162
163
  queryNode: QueryNode.cloneWithReturning(this.#props.queryNode, parseSelectAll(table)),
163
164
  });
164
165
  }
165
166
  output(args) {
166
- return new UpdateQueryBuilder({
167
+ return new _a({
167
168
  ...this.#props,
168
169
  queryNode: QueryNode.cloneWithOutput(this.#props.queryNode, parseSelectArg(args)),
169
170
  });
170
171
  }
171
172
  outputAll(table) {
172
- return new UpdateQueryBuilder({
173
+ return new _a({
173
174
  ...this.#props,
174
175
  queryNode: QueryNode.cloneWithOutput(this.#props.queryNode, parseSelectAll(table)),
175
176
  });
@@ -198,7 +199,7 @@ export class UpdateQueryBuilder {
198
199
  * ```
199
200
  */
200
201
  modifyEnd(modifier) {
201
- return new UpdateQueryBuilder({
202
+ return new _a({
202
203
  ...this.#props,
203
204
  queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, modifier.toOperationNode()),
204
205
  });
@@ -223,7 +224,7 @@ export class UpdateQueryBuilder {
223
224
  * ```
224
225
  */
225
226
  clearReturning() {
226
- return new UpdateQueryBuilder({
227
+ return new _a({
227
228
  ...this.#props,
228
229
  queryNode: QueryNode.cloneWithoutReturning(this.#props.queryNode),
229
230
  });
@@ -303,7 +304,7 @@ export class UpdateQueryBuilder {
303
304
  if (condition) {
304
305
  return func(this);
305
306
  }
306
- return new UpdateQueryBuilder({
307
+ return new _a({
307
308
  ...this.#props,
308
309
  });
309
310
  }
@@ -314,7 +315,7 @@ export class UpdateQueryBuilder {
314
315
  * returns a copy of this `UpdateQueryBuilder` with a new output type.
315
316
  */
316
317
  $castTo() {
317
- return new UpdateQueryBuilder(this.#props);
318
+ return new _a(this.#props);
318
319
  }
319
320
  /**
320
321
  * Narrows (parts of) the output type of the query.
@@ -375,7 +376,7 @@ export class UpdateQueryBuilder {
375
376
  * ```
376
377
  */
377
378
  $narrowType() {
378
- return new UpdateQueryBuilder(this.#props);
379
+ return new _a(this.#props);
379
380
  }
380
381
  /**
381
382
  * Asserts that query's output row type equals the given type `T`.
@@ -432,13 +433,13 @@ export class UpdateQueryBuilder {
432
433
  * ```
433
434
  */
434
435
  $assertType() {
435
- return new UpdateQueryBuilder(this.#props);
436
+ return new _a(this.#props);
436
437
  }
437
438
  /**
438
439
  * Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
439
440
  */
440
441
  withPlugin(plugin) {
441
- return new UpdateQueryBuilder({
442
+ return new _a({
442
443
  ...this.#props,
443
444
  executor: this.#props.executor.withPlugin(plugin),
444
445
  });
@@ -501,10 +502,11 @@ export class UpdateQueryBuilder {
501
502
  }
502
503
  }
503
504
  async explain(format, options) {
504
- const builder = new UpdateQueryBuilder({
505
+ const builder = new _a({
505
506
  ...this.#props,
506
507
  queryNode: QueryNode.cloneWithExplain(this.#props.queryNode, format, options),
507
508
  });
508
509
  return await builder.execute();
509
510
  }
510
511
  }
512
+ _a = UpdateQueryBuilder;
@@ -172,4 +172,58 @@ export type Insertable<R> = DrainOuterGeneric<object & {
172
172
  export type Updateable<R> = DrainOuterGeneric<{
173
173
  [K in UpdateKeys<R>]?: UpdateType<R[K]>;
174
174
  }>;
175
+ /**
176
+ * Wrap your column type to opt-out from dehydration by {@link ShallowDehydrateValue},
177
+ * when used by JSON functions, such as the ones used by the relational helpers.
178
+ *
179
+ * Why need this?
180
+ *
181
+ * An edge case surfaced in issues where a numeric string column type was actually
182
+ * not a numeric data type column, but text - and thus shouldn't be dehydrated
183
+ * to `number`.
184
+ *
185
+ * Another use case would be, when someone finds a way to keep nested columns hydrated
186
+ * at runtime, e.g. via a plugin, and wants to prevent dehydration of such columns
187
+ * at the type level.
188
+ *
189
+ * ### Examples
190
+ *
191
+ * ```ts
192
+ * import type { NonDehydrateable } from 'kysely'
193
+ * import { jsonArrayFrom } from 'kysely/helpers/postgres'
194
+ *
195
+ * const result = await db
196
+ * .withTables<{
197
+ * my_table: {
198
+ * a_column: '1' | '2' | '3',
199
+ * another_column: NonDehydrateable<'1' | '2' | '3'>,
200
+ * column_too: NonDehydrateable<ColumnType<'1' | '2' | '3'>>
201
+ * }
202
+ * }>()
203
+ * .selectFrom('person')
204
+ * .select((eb) => [
205
+ * 'id',
206
+ * jsonArrayFrom(
207
+ * eb.selectFrom('my_table')
208
+ * .select(['a_column', 'another_column', 'column_too'])
209
+ * ).as('related')
210
+ * ])
211
+ * .execute()
212
+ * ```
213
+ *
214
+ * In the example above, "a_column" will be dehydrated to `number`
215
+ * given it is a numeric string - which is normally a numeric data type column
216
+ * that gets output as a string by underlying database drivers to avoid
217
+ * precision loss or overflow.
218
+ *
219
+ * "another_column" and "column_too" will remain as `'1' | '2' | '3'`, given they're
220
+ * wrapped in `NonDehydrateable`, which prevents their dehydration.
221
+ */
222
+ export type NonDehydrateable<T> = [T] extends [
223
+ ColumnType<infer S, infer I, infer U>
224
+ ] ? ColumnType<S & {
225
+ __kysely_dehydrate__?: false;
226
+ }, I, U> : T & {
227
+ __kysely_dehydrate__?: false;
228
+ };
175
229
  export {};
@@ -183,7 +183,7 @@ export type ShallowDehydrateObject<O> = {
183
183
  * For now, we catch anything in {@link StringsWhenDataTypeNotAvailable} and convert it to `string`,
184
184
  * and anything in {@link NumbersWhenDataTypeNotAvailable} and convert it to `number`.
185
185
  */
186
- export type ShallowDehydrateValue<T> = T extends null | undefined ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
186
+ export type ShallowDehydrateValue<T> = T extends null | undefined ? T : '__kysely_dehydrate__' extends keyof NonNullable<T> ? T : T extends (infer U)[] | null | undefined ? Array<ShallowDehydrateValue<U>> | Extract<T, null | undefined> : Exclude<T, StringsWhenDataTypeNotAvailable | NumbersWhenDataTypeNotAvailable> | ([Extract<T, NumbersWhenDataTypeNotAvailable>] extends [never] ? never : number) | ([Extract<T, StringsWhenDataTypeNotAvailable>] extends [never] ? never : string);
187
187
  export type StringsWhenDataTypeNotAvailable = Date | Uint8Array;
188
188
  export type NumbersWhenDataTypeNotAvailable = bigint | NumericString;
189
189
  export type NumericString = `${number}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.28.14",
3
+ "version": "0.28.16",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,6 +27,7 @@
27
27
  "engines": {
28
28
  "node": ">=20.0.0"
29
29
  },
30
+ "type": "module",
30
31
  "main": "dist/cjs/index.js",
31
32
  "module": "dist/esm/index.js",
32
33
  "typesVersions": {
@@ -76,38 +77,38 @@
76
77
  "Igal Klebanov <igalklebanov@gmail.com>"
77
78
  ],
78
79
  "devDependencies": {
79
- "@arethetypeswrong/cli": "^0.18.2",
80
- "@ark/attest": "^0.56.0",
81
- "@types/better-sqlite3": "^7.6.13",
82
- "@types/chai": "^5.2.3",
83
- "@types/chai-as-promised": "^8.0.2",
84
- "@types/mocha": "^10.0.10",
85
- "@types/node": "^25.5.0",
86
- "@types/pg": "^8.18.0",
87
- "@types/pg-cursor": "^2.7.2",
88
- "@types/semver": "^7.7.1",
89
- "@types/sinon": "^21.0.0",
90
- "better-sqlite3": "^12.8.0",
91
- "chai": "^6.2.2",
92
- "chai-as-promised": "^8.0.2",
93
- "esbuild": "^0.27.4",
94
- "jsr": "^0.14.3",
95
- "lodash": "^4.17.23",
96
- "mocha": "^11.7.5",
97
- "mysql2": "^3.20.0",
98
- "pathe": "^2.0.3",
99
- "pg": "^8.20.0",
100
- "pg-cursor": "^2.19.0",
101
- "pkg-types": "^2.3.0",
102
- "playwright": "^1.58.2",
103
- "prettier": "^3.8.1",
104
- "semver": "^7.7.4",
105
- "sinon": "^21.0.3",
106
- "std-env": "^4.0.0",
107
- "tarn": "^3.0.2",
108
- "tedious": "^19.2.1",
109
- "tsd": "^0.33.0",
110
- "typescript": "~5.9.3"
80
+ "@arethetypeswrong/cli": "0.18.2",
81
+ "@ark/attest": "0.56.0",
82
+ "@types/better-sqlite3": "7.6.13",
83
+ "@types/chai": "5.2.3",
84
+ "@types/chai-as-promised": "8.0.2",
85
+ "@types/mocha": "10.0.10",
86
+ "@types/node": "25.5.2",
87
+ "@types/pg": "8.20.0",
88
+ "@types/pg-cursor": "2.7.2",
89
+ "@types/semver": "7.7.1",
90
+ "@types/sinon": "21.0.1",
91
+ "better-sqlite3": "12.8.0",
92
+ "chai": "6.2.2",
93
+ "chai-as-promised": "8.0.2",
94
+ "esbuild": "0.28.0",
95
+ "jsr": "0.14.3",
96
+ "lodash": "4.18.1",
97
+ "mocha": "11.7.5",
98
+ "mysql2": "3.21.0",
99
+ "pathe": "2.0.3",
100
+ "pg": "8.20.0",
101
+ "pg-cursor": "2.19.0",
102
+ "pkg-types": "2.3.0",
103
+ "playwright": "1.59.1",
104
+ "prettier": "3.8.1",
105
+ "semver": "7.7.4",
106
+ "sinon": "21.0.3",
107
+ "std-env": "4.0.0",
108
+ "tarn": "3.0.2",
109
+ "tedious": "19.2.1",
110
+ "tsd": "0.33.0",
111
+ "typescript": "6.0.2"
111
112
  },
112
113
  "scripts": {
113
114
  "clean": "rm -rf dist & rm -rf test/node/dist & rm -rf test/browser/bundle.js & rm -rf helpers",
@@ -120,11 +121,11 @@
120
121
  "test:browser": "pnpm build && pnpm test:browser:build && node test/browser/test.js",
121
122
  "test:bun": "pnpm build && bun link && cd test/bun && bun install && bun run test",
122
123
  "test:cloudflare-workers": "pnpm build && pnpm -r test --filter kysely-cloudflare-workers-test",
123
- "test:deno": "deno run --allow-env --allow-read --allow-net --no-lock test/deno/local.test.ts && deno run --allow-env --allow-read --allow-net --no-lock test/deno/cdn.test.ts",
124
+ "test:deno": "deno run --allow-env --allow-read --allow-net --no-lock test/deno/test.ts",
124
125
  "test:typings": "tsd test/typings",
125
- "test:esmimports": "node scripts/check-esm-imports.js",
126
+ "test:esmimports": "node scripts/check-esm-imports.cjs",
126
127
  "test:esbuild": "esbuild --bundle --platform=node --external:pg-native dist/esm/index.js --outfile=/dev/null",
127
- "test:exports": "attw --pack . && node scripts/check-exports.js",
128
+ "test:exports": "attw --pack . && node scripts/check-exports.cjs",
128
129
  "test:jsdocs": "deno check --doc-only --no-lock --unstable-sloppy-imports --config=\"deno.check.json\" ./src",
129
130
  "test:outdatedts": "pnpm build && cd test/outdated-ts && pnpm i && pnpm test",
130
131
  "lint:deno": "deno lint --config=\"deno.lint.json\" ./src",
@@ -132,11 +133,11 @@
132
133
  "build": "pnpm clean && (pnpm build:esm & pnpm build:cjs) && pnpm script:module-fixup && pnpm script:copy-interface-doc",
133
134
  "build:esm": "tsc -p tsconfig.json && pnpm script:add-deno-type-references",
134
135
  "build:cjs": "tsc -p tsconfig-cjs.json",
135
- "script:module-fixup": "node scripts/module-fixup.js",
136
- "script:copy-interface-doc": "node scripts/copy-interface-documentation.js",
137
- "script:add-deno-type-references": "node scripts/add-deno-type-references.js",
136
+ "script:module-fixup": "node scripts/module-fixup.cjs",
137
+ "script:copy-interface-doc": "node scripts/copy-interface-documentation.cjs",
138
+ "script:add-deno-type-references": "node scripts/add-deno-type-references.cjs",
138
139
  "script:align-versions": "node --experimental-strip-types scripts/align-versions.mts",
139
- "script:generate-site-examples": "node scripts/generate-site-examples.js",
140
+ "script:generate-site-examples": "node scripts/generate-site-examples.cjs",
140
141
  "script:exclude-test-files-for-backwards-compat": "node --experimental-strip-types scripts/exclude-test-files-for-backwards-compat.mts",
141
142
  "script:remove-global-augmentations": "node --experimental-strip-types scripts/remove-global-augmentations.mts",
142
143
  "version": "pnpm script:align-versions && git add ."