@stacksjs/orm 0.70.72 → 0.70.74

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,9 +1,9 @@
1
- import type { AttributeKeys, ColumnName, FillableKeys, InferModelAttributes, ModelAttributes, ModelDefinition } from '@stacksjs/query-builder';
1
+ import type { InferAttributes as QueryInferAttributes, InferColumnNames as QueryInferColumnNames, InferFillableAttributes as QueryInferFillableAttributes, InferNumericColumns as QueryInferNumericColumns, ModelRow as QueryModelRow } from '@stacksjs/query-builder';
2
2
  /**
3
3
  * Extract the raw ModelDefinition from a defineModel() return value.
4
4
  * Uses the getDefinition() accessor that defineModel() provides.
5
5
  */
6
- export type Def<T> = T extends { getDefinition: () => infer D extends ModelDefinition } ? D : never;
6
+ export type Def<T> = T extends { getDefinition: () => infer D } ? D : never;
7
7
  /**
8
8
  * Extract foreign key columns from belongsTo relations.
9
9
  * e.g., belongsTo: ['Customer', 'Coupon'] → { customer_id: number, coupon_id: number }
@@ -20,7 +20,7 @@ export type BelongsToForeignKeys<TDef> = TDef extends { readonly belongsTo: read
20
20
  * import type Post from '../models/Post'
21
21
  * type PostJsonResponse = ModelRow<typeof Post>
22
22
  */
23
- export type ModelRow<T> = ModelAttributes<Def<T>> & BelongsToForeignKeys<Def<T>>;
23
+ export type ModelRow<T> = QueryModelRow<T> & BelongsToForeignKeys<Def<T>>;
24
24
  /**
25
25
  * Same as {@link ModelRow} but with every field optional. Useful for
26
26
  * partial-projection reads (`select('id', 'name')`) and test fixtures
@@ -35,7 +35,7 @@ export type ModelRowLoose<T> = Partial<ModelRow<T>>;
35
35
  * import type Post from '../models/Post'
36
36
  * type NewPost = NewModelData<typeof Post>
37
37
  */
38
- export type NewModelData<T> = Partial<InferModelAttributes<Def<T>> & BelongsToForeignKeys<Def<T>>>;
38
+ export type NewModelData<T> = Partial<QueryInferAttributes<T> & BelongsToForeignKeys<Def<T>>>;
39
39
  /**
40
40
  * Strict insertable shape: only attributes marked `fillable: true` in
41
41
  * the model definition (plus belongsTo foreign keys), partial because
@@ -45,7 +45,7 @@ export type NewModelData<T> = Partial<InferModelAttributes<Def<T>> & BelongsToFo
45
45
  * can't pass non-fillable fields to `create()` / `insert()`.
46
46
  * {@link NewModelData} is the looser sibling that allows any attribute.
47
47
  */
48
- export type ModelCreateData<T> = Partial<Pick<InferModelAttributes<Def<T>>, Extract<FillableKeys<Def<T>>, keyof InferModelAttributes<Def<T>>>> & BelongsToForeignKeys<Def<T>>>;
48
+ export type ModelCreateData<T> = Partial<QueryInferFillableAttributes<T>> & BelongsToForeignKeys<Def<T>>;
49
49
  /** Loose variant of {@link ModelCreateData} — same shape as {@link NewModelData}, aliased for naming-parity with the row types. */
50
50
  export type ModelCreateDataLoose<T> = NewModelData<T>;
51
51
  /**
@@ -56,21 +56,23 @@ export type ModelCreateDataLoose<T> = NewModelData<T>;
56
56
  * import type Post from '../models/Post'
57
57
  * type PostUpdate = UpdateModelData<typeof Post>
58
58
  */
59
- export type UpdateModelData<T> = Partial<InferModelAttributes<Def<T>> & BelongsToForeignKeys<Def<T>>>;
59
+ export type UpdateModelData<T> = Partial<QueryInferAttributes<T> & BelongsToForeignKeys<Def<T>>>;
60
60
  /**
61
61
  * Just the attribute records flagged `fillable: true` — useful for
62
62
  * code-generators and any helper that needs the typed shape of a
63
63
  * model's fillable-attribute config (e.g., admin form schemas).
64
64
  */
65
65
  export type InferFillableAttributes<T> = {
66
- [K in Extract<FillableKeys<Def<T>>, keyof Def<T>['attributes']>]: Def<T>['attributes'][K]
66
+ [K in keyof QueryInferFillableAttributes<T>]: Def<T> extends { attributes: infer A }
67
+ ? K extends keyof A ? A[K] : never
68
+ : never
67
69
  }
68
70
  /**
69
71
  * Every valid column name for the model (attributes + system fields
70
72
  * added by traits like `id`, `uuid`, `created_at`). Useful for
71
73
  * constraining query builders that accept a `column` parameter.
72
74
  */
73
- export type InferColumnNames<T> = ColumnName<Def<T>>;
75
+ export type InferColumnNames<T> = QueryInferColumnNames<T>;
74
76
  /**
75
77
  * Attribute keys whose `type` is declared as `'number'` in the model
76
78
  * definition. Used to constrain aggregate methods (`sum`, `avg`,
@@ -82,8 +84,4 @@ export type InferColumnNames<T> = ColumnName<Def<T>>;
82
84
  * `AttributeKeys<Def<T>>` here. Tighten by declaring `type: 'number'`
83
85
  * on the attribute spec when narrowing matters.
84
86
  */
85
- export type InferNumericColumns<T> = {
86
- [K in AttributeKeys<Def<T>>]: Def<T>['attributes'][K] extends { type: 'number' } ? K : never
87
- }[AttributeKeys<Def<T>>] extends infer R
88
- ? [R] extends [never] ? AttributeKeys<Def<T>> : R
89
- : never;
87
+ export type InferNumericColumns<T> = QueryInferNumericColumns<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/orm",
3
3
  "type": "module",
4
- "version": "0.70.72",
4
+ "version": "0.70.74",
5
5
  "description": "The Stacks ORM integration",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -58,13 +58,13 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@stacksjs/ts-validation": "^0.5.0",
61
- "bun-query-builder": "^0.1.38"
61
+ "bun-query-builder": "^0.1.47"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@stacksjs/build": "workspace:*",
65
- "@stacksjs/config": "0.70.72",
66
- "better-dx": "^0.2.12",
67
- "@stacksjs/query-builder": "0.70.72",
68
- "@stacksjs/types": "0.70.72"
65
+ "@stacksjs/config": "0.70.74",
66
+ "better-dx": "^0.2.16",
67
+ "@stacksjs/query-builder": "0.70.74",
68
+ "@stacksjs/types": "0.70.74"
69
69
  }
70
70
  }