bun-query-builder 0.1.17 → 0.1.20

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,12 @@
1
1
  import type { Faker } from 'ts-mocker';
2
+ import type { ValidationType } from './schema';
3
+ // Local mirror of the runtime PivotColumnAttribute shape (kept structural so we
4
+ // don't take a hard dep on schema.ts at the type-inference layer).
5
+ declare interface InferablePivotColumnAttribute {
6
+ default?: unknown
7
+ nullable?: boolean
8
+ validation?: { rule: ValidationType; message?: Record<string, string> }
9
+ }
2
10
  /** Minimal attribute definition for type inference */
3
11
  declare interface InferableAttribute<T = unknown> {
4
12
  type?: T
@@ -256,6 +264,45 @@ export type InferGuardedKeys<TModel> = ResolveDefinition<TModel> extends infer T
256
264
  }[DefinitionAttributeKeys<TDef>]
257
265
  : never;
258
266
  // ============================================================================
267
+ // Pivot column inference (Option A)
268
+ // ============================================================================
269
+ declare type ExtractPivotRuleInput<R> = R extends { validate: (value: infer T) => any }
270
+ ? T
271
+ : R extends { test: (value: infer T) => any }
272
+ ? T
273
+ : R extends { getRules: () => Array<{ test: (value: infer T) => any }> }
274
+ ? T
275
+ : unknown;
276
+ declare type InferPivotColumnType<TCol> = TCol extends { validation: { rule: infer R } }
277
+ ? ExtractPivotRuleInput<R>
278
+ : TCol extends { default: infer D }
279
+ ? D
280
+ : unknown;
281
+ /**
282
+ * Given a model definition with `belongsToMany: { <R>: { pivot: { columns } } }`
283
+ * (Option A), infer the typed shape of `.pivot.<col>` on related rows.
284
+ *
285
+ * Falls back to `Record<string, unknown>` when:
286
+ * - The relation uses `through:` (Option B — sibling-model lookup is unsafe at
287
+ * the inference layer; runtime hydration still works.)
288
+ * - No `pivot.columns` is declared.
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * type T = InferPivotColumns<typeof Coach, 'athletes'>
293
+ * // { role: string; status: string; ... } (when role/status declared inline)
294
+ * ```
295
+ */
296
+ export type InferPivotColumns<TModel, R extends string> = ResolveDefinition<TModel> extends infer TDef
297
+ ? TDef extends { belongsToMany: infer BTM }
298
+ ? R extends keyof BTM
299
+ ? BTM[R] extends { pivot: { columns: infer Cols extends Record<string, InferablePivotColumnAttribute> } }
300
+ ? { [K in keyof Cols]: InferPivotColumnType<Cols[K]> }
301
+ : Record<string, unknown>
302
+ : Record<string, unknown>
303
+ : Record<string, unknown>
304
+ : Record<string, unknown>;
305
+ // ============================================================================
259
306
  // Internal relation name inference helpers
260
307
  // ============================================================================
261
308
  declare type InferBelongsToNames<TDef> = (TDef extends { belongsTo: readonly (infer R)[] }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-query-builder",
3
3
  "type": "module",
4
- "version": "0.1.17",
4
+ "version": "0.1.20",
5
5
  "description": "A simple yet performant query builder for TypeScript. Built with Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -85,9 +85,6 @@
85
85
  "devDependencies": {
86
86
  "bunfig": "^0.15.6"
87
87
  },
88
- "overrides": {
89
- "unconfig": "0.3.10"
90
- },
91
88
  "git-hooks": {
92
89
  "pre-commit": {
93
90
  "staged-lint": {