@stacksjs/orm 0.70.349 → 0.70.350

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.
@@ -62,6 +62,23 @@ export declare function defineModel<const TDef extends ModelDefinition>(definiti
62
62
  * vin, password hashes) into responses.
63
63
  */
64
64
  export declare function toAttrs<T = any>(value: any): T;
65
+ /**
66
+ * Thrown when a direct write fails a declared `validation.rule`.
67
+ *
68
+ * Carries `status = 422` and a per-field `errors` map, matching the shape the
69
+ * generated REST routes already return, so a handler that catches this can
70
+ * respond with the same body it would have produced through auto-CRUD. It is
71
+ * duck-typed by `mapWriteError`, which preserves any integer `status` in
72
+ * 400-599 — so an over-length value now surfaces as a 422 instead of the
73
+ * driver's raw 22001 becoming a 500 (stacksjs/stacks#2233).
74
+ */
75
+ /**
76
+ * Where `defineModel` keeps the definition it was handed.
77
+ *
78
+ * `Symbol.for`, so two copies of the ORM in one process still agree — the
79
+ * dist-only-app split makes that a real arrangement, not a hypothetical.
80
+ */
81
+ export declare const MODEL_DEFINITION: unique symbol;
65
82
  /**
66
83
  * Custom caster interface for user-defined attribute transformations.
67
84
  */
@@ -69,7 +86,7 @@ export declare interface CasterInterface {
69
86
  get(value: unknown): unknown
70
87
  set(value: unknown): unknown
71
88
  }
72
- declare interface StacksModelDefinition extends Omit<BQBModelDefinition, 'attributes' | 'indexes' | 'traits'> {
89
+ export declare interface StacksModelDefinition extends Omit<BQBModelDefinition, 'attributes' | 'indexes' | 'traits'> {
73
90
  name: string
74
91
  table: string
75
92
  primaryKey?: string
@@ -202,16 +219,6 @@ export type StacksModelStatic<TDef extends ModelDefinition> = OrmModelStatic<TDe
202
219
  /** Run `fn` with declared `validation.rule`s suppressed (bulk imports, backfills). */
203
220
  withoutValidation: <T>(fn: () => T | Promise<T>) => Promise<T>
204
221
  }
205
- /**
206
- * Thrown when a direct write fails a declared `validation.rule`.
207
- *
208
- * Carries `status = 422` and a per-field `errors` map, matching the shape the
209
- * generated REST routes already return, so a handler that catches this can
210
- * respond with the same body it would have produced through auto-CRUD. It is
211
- * duck-typed by `mapWriteError`, which preserves any integer `status` in
212
- * 400-599 — so an over-length value now surfaces as a 422 instead of the
213
- * driver's raw 22001 becoming a 500 (stacksjs/stacks#2233).
214
- */
215
222
  export declare class ModelValidationError extends Error {
216
223
  readonly status: number;
217
224
  readonly errors: Record<string, string[]>;
@@ -0,0 +1,17 @@
1
+ import type { StacksModelDefinition, StacksModelStatic } from './define-model';
2
+ /**
3
+ * A model definition with `extension` folded into it.
4
+ *
5
+ * Exported separately from {@link extendModel} so the merge can be asserted
6
+ * without booting a model.
7
+ */
8
+ export declare function mergeModelDefinition(base: StacksModelDefinition, extension: ModelExtension): StacksModelDefinition;
9
+ /**
10
+ * Define a model that is the framework's, plus what this app adds.
11
+ *
12
+ * `base` is the framework model itself — import it, do not name it — so the
13
+ * app keeps inheriting fields, traits and relations added upstream.
14
+ */
15
+ export declare function extendModel(base: unknown, extension: ModelExtension): StacksModelStatic<StacksModelDefinition>;
16
+ /** What an extension may say. Everything is optional; anything absent is inherited. */
17
+ export type ModelExtension = Partial<StacksModelDefinition>;
package/dist/index.d.ts CHANGED
@@ -233,6 +233,7 @@ export * from './model-types';
233
233
  export * from './types';
234
234
  export * from './utils';
235
235
  export * from './define-model';
236
+ export * from './extend-model';
236
237
  // Codegen for `database/types.d.ts` — augments
237
238
  // `@stacksjs/database`'s `DatabaseSchema` so `db.selectFrom(...)` gets
238
239
  // table-name autocomplete (stacksjs/stacks#1923).