turbine-orm 0.19.1 → 0.19.2

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.
@@ -6,6 +6,13 @@
6
6
  export type OrderDirection = 'asc' | 'desc';
7
7
  /** Operator object for advanced where filtering */
8
8
  export interface WhereOperator<V = unknown> {
9
+ /**
10
+ * Explicit equality: `{ equals: value }` → `column = $n`.
11
+ * `{ equals: null }` → `column IS NULL`.
12
+ * On json/jsonb columns `equals` routes to the JSONB containment filter
13
+ * ({@link JsonFilter}) instead.
14
+ */
15
+ equals?: V | null;
9
16
  gt?: V;
10
17
  gte?: V;
11
18
  lt?: V;
@@ -225,8 +232,12 @@ export interface FindManyStreamArgs<T, R extends object = {}, W extends TypedWit
225
232
  */
226
233
  batchSize?: number;
227
234
  }
228
- export interface CreateArgs<T> {
229
- data: Partial<T>;
235
+ export interface CreateArgs<T, R extends object = {}> {
236
+ /**
237
+ * Row data. On typed clients, relation names additionally accept nested
238
+ * write ops ({@link NestedCreateOp}): `create` / `connect` / `connectOrCreate`.
239
+ */
240
+ data: CreateDataInput<T, R>;
230
241
  /** Query timeout in milliseconds. Rejects with an error if exceeded. */
231
242
  timeout?: number;
232
243
  }
@@ -267,9 +278,14 @@ export type UpdateOperatorInput<V> = {
267
278
  export type UpdateInput<T> = {
268
279
  [K in keyof T]?: T[K] | UpdateOperatorInput<T[K]>;
269
280
  };
270
- export interface UpdateArgs<T> {
281
+ export interface UpdateArgs<T, R extends object = {}> {
271
282
  where: WhereClause<T>;
272
- data: UpdateInput<T>;
283
+ /**
284
+ * Update data. On typed clients, relation names additionally accept nested
285
+ * write ops ({@link NestedUpdateOp}): `create` / `connect` / `connectOrCreate`
286
+ * / `disconnect` / `set` / `delete` / `update` / `upsert`.
287
+ */
288
+ data: UpdateDataInput<T, R>;
273
289
  /** Query timeout in milliseconds. Rejects with an error if exceeded. */
274
290
  timeout?: number;
275
291
  /**
@@ -331,23 +347,57 @@ export interface UpsertArgs<T> {
331
347
  /** Query timeout in milliseconds. Rejects with an error if exceeded. */
332
348
  timeout?: number;
333
349
  }
334
- export interface ConnectOrCreateOp<T> {
350
+ /** `connectOrCreate` op: connect to the row matching `where`, or create it. */
351
+ export interface ConnectOrCreateOp<T, TR extends object = {}> {
335
352
  where: Partial<T>;
336
- create: Partial<T>;
353
+ create: CreateDataInput<T, TR>;
337
354
  }
338
- export interface NestedCreateOp<T> {
339
- create?: Partial<T> | Partial<T>[];
355
+ /** Nested write ops valid inside `create()` data for a relation field. */
356
+ export interface NestedCreateOp<T, TR extends object = {}> {
357
+ create?: CreateDataInput<T, TR> | CreateDataInput<T, TR>[];
340
358
  connect?: Partial<T> | Partial<T>[];
341
- connectOrCreate?: ConnectOrCreateOp<T> | ConnectOrCreateOp<T>[];
359
+ connectOrCreate?: ConnectOrCreateOp<T, TR> | ConnectOrCreateOp<T, TR>[];
360
+ }
361
+ /** A nested `update` op item: update the related row(s) matching `where`. `where` is optional for belongsTo relations (derived from the parent's FK). */
362
+ export interface NestedUpdateOpItem<T, TR extends object = {}> {
363
+ where?: Partial<T>;
364
+ data: UpdateDataInput<T, TR>;
342
365
  }
343
- export interface NestedUpdateOp<T> {
344
- create?: Partial<T> | Partial<T>[];
366
+ /** A nested `upsert` op item: update the row matching `where` or create it. */
367
+ export interface NestedUpsertOpItem<T, TR extends object = {}> {
368
+ where: Partial<T>;
369
+ create: CreateDataInput<T, TR>;
370
+ update: UpdateDataInput<T, TR>;
371
+ }
372
+ /** Nested write ops valid inside `update()` data for a relation field. */
373
+ export interface NestedUpdateOp<T, TR extends object = {}> {
374
+ create?: CreateDataInput<T, TR> | CreateDataInput<T, TR>[];
345
375
  connect?: Partial<T> | Partial<T>[];
346
- connectOrCreate?: ConnectOrCreateOp<T> | ConnectOrCreateOp<T>[];
376
+ connectOrCreate?: ConnectOrCreateOp<T, TR> | ConnectOrCreateOp<T, TR>[];
347
377
  disconnect?: Partial<T> | Partial<T>[];
348
378
  set?: Partial<T>[];
349
379
  delete?: Partial<T> | Partial<T>[];
380
+ update?: NestedUpdateOpItem<T, TR> | NestedUpdateOpItem<T, TR>[];
381
+ upsert?: NestedUpsertOpItem<T, TR> | NestedUpsertOpItem<T, TR>[];
350
382
  }
383
+ /**
384
+ * `create()` data input. When the relations map `R` is known (typed clients),
385
+ * each relation name additionally accepts a {@link NestedCreateOp} for the
386
+ * relation's target entity — recursively, via the target's own relations map.
387
+ * When `R` is `{}` (untyped escape hatch) this collapses to plain `Partial<T>`.
388
+ */
389
+ export type CreateDataInput<T, R extends object = {}> = [keyof R] extends [never] ? Partial<T> : Partial<T> & {
390
+ [K in keyof R]?: NestedCreateOp<RelationTarget<R[K]> & object, RelationRelations<R[K]> & object>;
391
+ };
392
+ /**
393
+ * `update()` data input. Like {@link CreateDataInput} but relation fields
394
+ * accept the full {@link NestedUpdateOp} surface (disconnect / set / delete /
395
+ * update / upsert in addition to the create-context ops), and scalar fields
396
+ * accept atomic {@link UpdateOperatorInput} objects.
397
+ */
398
+ export type UpdateDataInput<T, R extends object = {}> = [keyof R] extends [never] ? UpdateInput<T> : UpdateInput<T> & {
399
+ [K in keyof R]?: NestedUpdateOp<RelationTarget<R[K]> & object, RelationRelations<R[K]> & object>;
400
+ };
351
401
  export interface CountArgs<T> {
352
402
  where?: WhereClause<T>;
353
403
  /** Query timeout in milliseconds. Rejects with an error if exceeded. */
@@ -99,6 +99,7 @@ export function sqlToPreparedName(sql) {
99
99
  }
100
100
  /** Known operator keys — used to detect operator objects vs plain values */
101
101
  export const OPERATOR_KEYS = new Set([
102
+ 'equals',
102
103
  'gt',
103
104
  'gte',
104
105
  'lt',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turbine-orm",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "description": "Postgres-native TypeScript ORM — runs on Neon, Vercel Postgres, Cloudflare, Supabase. Streaming cursors, typed errors, single-query nested relations. One dependency, no WASM engine",
5
5
  "type": "module",
6
6
  "exports": {
@@ -50,7 +50,7 @@
50
50
  "examples": "tsx examples/examples.ts",
51
51
  "dogfood": "tsx examples/dogfood.ts",
52
52
  "test": "tsx --test --test-concurrency=1 src/test/*.test.ts",
53
- "test:unit": "tsx --test src/test/schema-builder.test.ts src/test/errors.test.ts src/test/stress.test.ts src/test/migrate.test.ts src/test/update-operators.test.ts src/test/empty-where-guard.test.ts src/test/cli.test.ts src/test/serverless.test.ts src/test/pipeline.test.ts src/test/pipeline-submittable.test.ts src/test/with-inference.test.ts src/test/operator-validation.test.ts src/test/unlimited-warning.test.ts src/test/generate-relations.test.ts src/test/stream-and-parse.test.ts src/test/sql-cache.test.ts src/test/dialect.test.ts src/test/studio.test.ts src/test/sql-injection.test.ts src/test/cli-flags.test.ts src/test/cockroachdb-adapter.test.ts src/test/yugabytedb-adapter.test.ts src/test/pg-compat.test.ts src/test/relation-filter-validation.test.ts src/test/client-coverage.test.ts src/test/schema-diff.test.ts src/test/composite-fk.test.ts src/test/retry.test.ts src/test/text-search.test.ts src/test/optimistic-lock.test.ts src/test/sql-safety-property.test.ts src/test/nested-write.test.ts src/test/nested-write-update-upsert.test.ts src/test/cursor-pagination.test.ts src/test/client-branches.test.ts src/test/is-isNot-filter.test.ts src/test/event-emitter.test.ts src/test/observe.test.ts src/test/relation-limit-param.test.ts src/test/where-guard-cache-and-relation-where.test.ts",
53
+ "test:unit": "DATABASE_URL= tsx --test src/test/*.test.ts",
54
54
  "test:coverage": "c8 tsx --test --test-concurrency=1 src/test/*.test.ts",
55
55
  "lint": "biome check src/",
56
56
  "lint:fix": "biome check --write src/",
@@ -59,7 +59,7 @@
59
59
  "prepare": "husky",
60
60
  "size": "size-limit",
61
61
  "size:check": "size-limit",
62
- "test:watch": "tsx --watch --test src/test/schema-builder.test.ts src/test/errors.test.ts src/test/stress.test.ts",
62
+ "test:watch": "tsx --watch --test src/test/*.test.ts",
63
63
  "db:seed": "psql $DATABASE_URL -v ON_ERROR_STOP=1 -f src/test/fixtures/seed.sql",
64
64
  "db:reset": "psql $DATABASE_URL -c 'DROP SCHEMA public CASCADE; CREATE SCHEMA public;' && npm run db:seed",
65
65
  "site:dev": "cd site && npm run dev",