@warlock.js/cascade 4.0.59 → 4.0.88
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.
- package/cjs/contracts/driver-blueprint.contract.d.ts +4 -0
- package/cjs/contracts/driver-blueprint.contract.d.ts.map +1 -1
- package/cjs/drivers/mongo/mongodb-driver.d.ts.map +1 -1
- package/cjs/drivers/mongo/mongodb-driver.js +49 -1
- package/cjs/drivers/mongo/mongodb-driver.js.map +1 -1
- package/cjs/migration/migration.d.ts +1143 -0
- package/cjs/migration/migration.d.ts.map +1 -0
- package/cjs/migration/migration.js.map +1 -1
- package/cjs/model/model.d.ts +2 -4
- package/cjs/model/model.d.ts.map +1 -1
- package/cjs/model/model.js +0 -2
- package/cjs/model/model.js.map +1 -1
- package/cjs/utils/define-model.d.ts +372 -0
- package/cjs/utils/define-model.d.ts.map +1 -0
- package/esm/contracts/driver-blueprint.contract.d.ts +4 -0
- package/esm/contracts/driver-blueprint.contract.d.ts.map +1 -1
- package/esm/drivers/mongo/mongodb-driver.d.ts.map +1 -1
- package/esm/drivers/mongo/mongodb-driver.js +49 -1
- package/esm/drivers/mongo/mongodb-driver.js.map +1 -1
- package/esm/migration/migration.d.ts +1143 -0
- package/esm/migration/migration.d.ts.map +1 -0
- package/esm/migration/migration.js.map +1 -1
- package/esm/model/model.d.ts +2 -4
- package/esm/model/model.d.ts.map +1 -1
- package/esm/model/model.js +0 -2
- package/esm/model/model.js.map +1 -1
- package/esm/utils/define-model.d.ts +372 -0
- package/esm/utils/define-model.d.ts.map +1 -0
- package/package.json +5 -15
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import type { Infer, ObjectValidator } from "@warlock.js/seal";
|
|
2
|
+
import type { ModelSchema } from "../model/model";
|
|
3
|
+
import { Model } from "../model/model";
|
|
4
|
+
import type { DeleteStrategy, StrictMode } from "../types";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for defining a model.
|
|
7
|
+
*/
|
|
8
|
+
export type DefineModelOptions<TSchema extends ModelSchema> = {
|
|
9
|
+
/**
|
|
10
|
+
* The database table/collection name.
|
|
11
|
+
*/
|
|
12
|
+
table: string;
|
|
13
|
+
/**
|
|
14
|
+
* Model name
|
|
15
|
+
* If provided, it will be registered in the models registery
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The validation schema for the model.
|
|
20
|
+
* Use `v.object()` from @warlock.js/seal to define the schema.
|
|
21
|
+
*/
|
|
22
|
+
schema: ObjectValidator;
|
|
23
|
+
/**
|
|
24
|
+
* Optional: Delete strategy for the model.
|
|
25
|
+
* - "hard": Permanently delete records (default)
|
|
26
|
+
* - "soft": Mark records as deleted but keep them in the database
|
|
27
|
+
* - "disable": Mark records as disabled
|
|
28
|
+
*/
|
|
29
|
+
deleteStrategy?: DeleteStrategy;
|
|
30
|
+
/**
|
|
31
|
+
* Optional: Strict mode for unknown fields.
|
|
32
|
+
* - "strip": Remove unknown fields (default)
|
|
33
|
+
* - "fail": Throw error on unknown fields
|
|
34
|
+
*/
|
|
35
|
+
strictMode?: StrictMode;
|
|
36
|
+
/**
|
|
37
|
+
* Optional: Whether to automatically generate IDs.
|
|
38
|
+
* Default: false (use MongoDB's _id)
|
|
39
|
+
*/
|
|
40
|
+
autoGenerateId?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Optional: Whether to use random increments for IDs.
|
|
43
|
+
* Default: false
|
|
44
|
+
*/
|
|
45
|
+
randomIncrement?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Optional: Initial ID value when auto-generating.
|
|
48
|
+
* Default: 1
|
|
49
|
+
*/
|
|
50
|
+
initialId?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Optional: Custom instance properties (getters/setters/methods).
|
|
53
|
+
* Define computed properties, custom getters, or instance methods.
|
|
54
|
+
*
|
|
55
|
+
* The `this` context will be the Model instance, giving you access to
|
|
56
|
+
* all Model methods like `get()`, `set()`, `save()`, etc.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* properties: {
|
|
61
|
+
* get fullName(this: Model<UserSchema>) {
|
|
62
|
+
* return `${this.get("firstName")} ${this.get("lastName")}`;
|
|
63
|
+
* },
|
|
64
|
+
* get isActive(this: Model<UserSchema>) {
|
|
65
|
+
* return this.get("status") === "active";
|
|
66
|
+
* },
|
|
67
|
+
* async sendEmail(this: Model<UserSchema>, subject: string) {
|
|
68
|
+
* // this.get(), this.save(), etc. all work!
|
|
69
|
+
* },
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
properties?: ThisType<Model<TSchema>> & Record<string, any>;
|
|
74
|
+
/**
|
|
75
|
+
* Optional: Custom static methods.
|
|
76
|
+
* Define class-level methods like custom finders or utilities.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* statics: {
|
|
81
|
+
* async findByEmail(email: string) {
|
|
82
|
+
* return this.first({ email });
|
|
83
|
+
* },
|
|
84
|
+
* async findActive() {
|
|
85
|
+
* return this.query().where("status", "active").get();
|
|
86
|
+
* },
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
statics?: Record<string, any>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Define a model with a clean, concise API.
|
|
94
|
+
*
|
|
95
|
+
* This utility function creates a Model class with the specified configuration,
|
|
96
|
+
* reducing boilerplate and providing a more declarative way to define models.
|
|
97
|
+
*
|
|
98
|
+
* @param options - Model configuration options
|
|
99
|
+
* @returns A Model class with the specified configuration
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { defineModel } from "@warlock.js/cascade";
|
|
104
|
+
* import { v } from "@warlock.js/seal";
|
|
105
|
+
*
|
|
106
|
+
* export const User = defineModel({
|
|
107
|
+
* table: "users",
|
|
108
|
+
* schema: v.object({
|
|
109
|
+
* name: v.string().required().trim(),
|
|
110
|
+
* email: v.string().email().required().lowercase(),
|
|
111
|
+
* password: v.string().required().min(6),
|
|
112
|
+
* role: v.string().default("user"),
|
|
113
|
+
* }),
|
|
114
|
+
* deleteStrategy: "soft",
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // Usage
|
|
118
|
+
* const user = await User.create({
|
|
119
|
+
* name: "John Doe",
|
|
120
|
+
* email: "john@example.com",
|
|
121
|
+
* password: "secret123",
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // With type inference
|
|
128
|
+
* export const Post = defineModel({
|
|
129
|
+
* table: "posts",
|
|
130
|
+
* schema: v.object({
|
|
131
|
+
* title: v.string().required(),
|
|
132
|
+
* content: v.string().required(),
|
|
133
|
+
* authorId: v.number().required(),
|
|
134
|
+
* published: v.boolean().default(false),
|
|
135
|
+
* }),
|
|
136
|
+
* });
|
|
137
|
+
*
|
|
138
|
+
* // TypeScript knows the exact type!
|
|
139
|
+
* const post = await Post.create({
|
|
140
|
+
* title: "Hello World",
|
|
141
|
+
* content: "My first post",
|
|
142
|
+
* authorId: 1,
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* console.log(post.title); // ✅ Type-safe!
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function defineModel<TSchema extends ModelSchema, TSchemaValidator extends ObjectValidator = ObjectValidator, TProperties extends Record<string, any> = {}, TStatics extends Record<string, any> = {}>(options: DefineModelOptions<TSchema> & {
|
|
149
|
+
schema: TSchemaValidator;
|
|
150
|
+
properties?: ThisType<Model<Infer<TSchemaValidator>>> & TProperties;
|
|
151
|
+
statics?: ThisType<typeof Model<Infer<TSchemaValidator>>> & TStatics;
|
|
152
|
+
}): (new (initialData?: Infer<TSchemaValidator>) => {
|
|
153
|
+
isNew: boolean;
|
|
154
|
+
data: Infer<TSchemaValidator>;
|
|
155
|
+
readonly dirtyTracker: import("..").DatabaseDirtyTracker;
|
|
156
|
+
readonly id: number;
|
|
157
|
+
get<TKey extends string>(field: TKey): Infer<TSchemaValidator>;
|
|
158
|
+
get<TKey_1 extends string>(field: TKey_1, defaultValue: Infer<TSchemaValidator>): Infer<TSchemaValidator>;
|
|
159
|
+
get(field: string): unknown;
|
|
160
|
+
get(field: string, defaultValue: unknown): unknown;
|
|
161
|
+
only<TKey_2 extends string>(fields: TKey_2[]): Record<TKey_2, Infer<TSchemaValidator>>;
|
|
162
|
+
only(fields: string[]): Record<string, unknown>;
|
|
163
|
+
string(key: string, defaultValue?: string): string;
|
|
164
|
+
number(key: string, defaultValue?: number): number;
|
|
165
|
+
boolean(key: string, defaultValue?: boolean): boolean;
|
|
166
|
+
set<TKey_3 extends string>(field: TKey_3, value: Infer<TSchemaValidator>): any;
|
|
167
|
+
set(field: string, value: unknown): any;
|
|
168
|
+
has<TKey_4 extends string>(field: TKey_4): boolean;
|
|
169
|
+
has(field: string): boolean;
|
|
170
|
+
increment<TKey_5 extends string>(field: TKey_5, amount: number): any;
|
|
171
|
+
increment(field: string, amount: number): any;
|
|
172
|
+
decrement<TKey_6 extends string>(field: TKey_6, amount: number): any;
|
|
173
|
+
decrement(field: string, amount: number): any;
|
|
174
|
+
unset(...fields: string[]): any;
|
|
175
|
+
unset(...fields: string[]): any;
|
|
176
|
+
merge(values: Infer<TSchemaValidator>): any;
|
|
177
|
+
merge(values: Record<string, unknown>): any;
|
|
178
|
+
hasChanges(): boolean;
|
|
179
|
+
isDirty(column: string): boolean;
|
|
180
|
+
getDirtyColumnsWithValues(): Record<string, {
|
|
181
|
+
oldValue: unknown;
|
|
182
|
+
newValue: unknown;
|
|
183
|
+
}>;
|
|
184
|
+
getRemovedColumns(): string[];
|
|
185
|
+
getDirtyColumns(): string[];
|
|
186
|
+
emitEvent<TContext = unknown>(event: import("..").ModelEventName, context?: TContext): Promise<void>;
|
|
187
|
+
destroy(options?: {
|
|
188
|
+
strategy?: DeleteStrategy;
|
|
189
|
+
skipEvents?: boolean;
|
|
190
|
+
}): Promise<import("..").RemoverResult>;
|
|
191
|
+
self<TModel extends Model<ModelSchema> = any>(): import("../model/model").ChildModel<TModel>;
|
|
192
|
+
clone(): any;
|
|
193
|
+
deepFreeze<T>(obj: T): T;
|
|
194
|
+
getTableName(): string;
|
|
195
|
+
getPrimaryKey(): string;
|
|
196
|
+
getSchema(): ObjectValidator;
|
|
197
|
+
schemaHas(key: string): boolean;
|
|
198
|
+
getStrictMode(): StrictMode;
|
|
199
|
+
getConnection(): import("..").DataSource;
|
|
200
|
+
readonly embedData: Record<string, unknown>;
|
|
201
|
+
replaceData(data: Record<string, unknown>): void;
|
|
202
|
+
save(options?: import("..").WriterOptions & {
|
|
203
|
+
merge?: Infer<TSchemaValidator>;
|
|
204
|
+
}): Promise<any>;
|
|
205
|
+
serialize(): Record<string, unknown>;
|
|
206
|
+
toJSON(): any;
|
|
207
|
+
} & TProperties) & Omit<{
|
|
208
|
+
new (initialData?: Infer<TSchemaValidator>): {
|
|
209
|
+
isNew: boolean;
|
|
210
|
+
data: Infer<TSchemaValidator>;
|
|
211
|
+
readonly dirtyTracker: import("..").DatabaseDirtyTracker;
|
|
212
|
+
readonly id: number;
|
|
213
|
+
get<TKey extends string>(field: TKey): Infer<TSchemaValidator>;
|
|
214
|
+
get<TKey_1 extends string>(field: TKey_1, defaultValue: Infer<TSchemaValidator>): Infer<TSchemaValidator>;
|
|
215
|
+
get(field: string): unknown;
|
|
216
|
+
get(field: string, defaultValue: unknown): unknown;
|
|
217
|
+
only<TKey_2 extends string>(fields: TKey_2[]): Record<TKey_2, Infer<TSchemaValidator>>;
|
|
218
|
+
only(fields: string[]): Record<string, unknown>;
|
|
219
|
+
string(key: string, defaultValue?: string): string;
|
|
220
|
+
number(key: string, defaultValue?: number): number;
|
|
221
|
+
boolean(key: string, defaultValue?: boolean): boolean;
|
|
222
|
+
set<TKey_3 extends string>(field: TKey_3, value: Infer<TSchemaValidator>): any;
|
|
223
|
+
set(field: string, value: unknown): any;
|
|
224
|
+
has<TKey_4 extends string>(field: TKey_4): boolean;
|
|
225
|
+
has(field: string): boolean;
|
|
226
|
+
increment<TKey_5 extends string>(field: TKey_5, amount: number): any;
|
|
227
|
+
increment(field: string, amount: number): any;
|
|
228
|
+
decrement<TKey_6 extends string>(field: TKey_6, amount: number): any;
|
|
229
|
+
decrement(field: string, amount: number): any;
|
|
230
|
+
unset(...fields: string[]): any;
|
|
231
|
+
unset(...fields: string[]): any;
|
|
232
|
+
merge(values: Infer<TSchemaValidator>): any;
|
|
233
|
+
merge(values: Record<string, unknown>): any;
|
|
234
|
+
hasChanges(): boolean;
|
|
235
|
+
isDirty(column: string): boolean;
|
|
236
|
+
getDirtyColumnsWithValues(): Record<string, {
|
|
237
|
+
oldValue: unknown;
|
|
238
|
+
newValue: unknown;
|
|
239
|
+
}>;
|
|
240
|
+
getRemovedColumns(): string[];
|
|
241
|
+
getDirtyColumns(): string[];
|
|
242
|
+
emitEvent<TContext = unknown>(event: import("..").ModelEventName, context?: TContext): Promise<void>;
|
|
243
|
+
destroy(options?: {
|
|
244
|
+
strategy?: DeleteStrategy;
|
|
245
|
+
skipEvents?: boolean;
|
|
246
|
+
}): Promise<import("..").RemoverResult>;
|
|
247
|
+
self<TModel extends Model<ModelSchema> = any>(): import("../model/model").ChildModel<TModel>;
|
|
248
|
+
clone(): any;
|
|
249
|
+
deepFreeze<T>(obj: T): T;
|
|
250
|
+
getTableName(): string;
|
|
251
|
+
getPrimaryKey(): string;
|
|
252
|
+
getSchema(): ObjectValidator;
|
|
253
|
+
schemaHas(key: string): boolean;
|
|
254
|
+
getStrictMode(): StrictMode;
|
|
255
|
+
getConnection(): import("..").DataSource;
|
|
256
|
+
readonly embedData: Record<string, unknown>;
|
|
257
|
+
replaceData(data: Record<string, unknown>): void;
|
|
258
|
+
save(options?: import("..").WriterOptions & {
|
|
259
|
+
merge?: Infer<TSchemaValidator>;
|
|
260
|
+
}): Promise<any>;
|
|
261
|
+
serialize(): Record<string, unknown>;
|
|
262
|
+
toJSON(): any;
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* Table/collection name
|
|
266
|
+
*/
|
|
267
|
+
table: string;
|
|
268
|
+
/**
|
|
269
|
+
* Validation schema
|
|
270
|
+
*/
|
|
271
|
+
schema: any;
|
|
272
|
+
/**
|
|
273
|
+
* Delete strategy
|
|
274
|
+
*/
|
|
275
|
+
deleteStrategy: DeleteStrategy;
|
|
276
|
+
/**
|
|
277
|
+
* Strict mode
|
|
278
|
+
*/
|
|
279
|
+
strictMode: StrictMode;
|
|
280
|
+
/**
|
|
281
|
+
* Auto-generate ID
|
|
282
|
+
*/
|
|
283
|
+
autoGenerateId: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Random increment
|
|
286
|
+
*/
|
|
287
|
+
randomIncrement: boolean;
|
|
288
|
+
/**
|
|
289
|
+
* Initial ID
|
|
290
|
+
*/
|
|
291
|
+
initialId: number;
|
|
292
|
+
resource?: any;
|
|
293
|
+
resourceColumns?: string[];
|
|
294
|
+
toJsonColumns?: string[];
|
|
295
|
+
dataSource?: string | import("..").DataSource;
|
|
296
|
+
builder?: new (...args: any[]) => import("..").QueryBuilderContract<Model<ModelSchema>>;
|
|
297
|
+
primaryKey: string;
|
|
298
|
+
embed?: string[];
|
|
299
|
+
randomInitialId?: boolean | (() => number);
|
|
300
|
+
incrementIdBy?: number;
|
|
301
|
+
createdAtColumn?: string | false;
|
|
302
|
+
updatedAtColumn?: string | false;
|
|
303
|
+
deletedAtColumn: string;
|
|
304
|
+
trashTable?: string;
|
|
305
|
+
globalScopes: Map<string, import("../model/model").GlobalScopeDefinition>;
|
|
306
|
+
localScopes: Map<string, import("../model/model").LocalScopeCallback>;
|
|
307
|
+
getModel(name: string): import("../model/model").ChildModel<Model<ModelSchema>>;
|
|
308
|
+
getAllModels(): Map<string, import("../model/model").ChildModel<Model<ModelSchema>>>;
|
|
309
|
+
sync<TModel_1 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_1>, TargetModel: import("../model/model").ChildModel<Model<ModelSchema>>, targetField: string): import("..").ModelSyncOperationContract;
|
|
310
|
+
syncMany<TModel_2 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_2>, TargetModel: import("../model/model").ChildModel<Model<ModelSchema>>, targetField: string): import("..").ModelSyncOperationContract;
|
|
311
|
+
getDataSource(): import("..").DataSource;
|
|
312
|
+
applyModelDefaults(defaults: any): void;
|
|
313
|
+
addGlobalScope(name: string, callback: (query: import("..").QueryBuilderContract<unknown>) => void, options?: import("../model/model").GlobalScopeOptions): void;
|
|
314
|
+
removeGlobalScope(name: string): void;
|
|
315
|
+
addScope(name: string, callback: import("../model/model").LocalScopeCallback): void;
|
|
316
|
+
removeScope(name: string): void;
|
|
317
|
+
query<TModel_3 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_3>): import("..").QueryBuilderContract<TModel_3>;
|
|
318
|
+
newQueryBuilder<TModel_4 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_4>): import("..").QueryBuilderContract<TModel_4>;
|
|
319
|
+
first<TModel_5 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_5>, filter?: Record<string, unknown>): Promise<TModel_5>;
|
|
320
|
+
last<TModel_6 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_6>, filter?: Record<string, unknown>): Promise<TModel_6>;
|
|
321
|
+
where<TModel_7 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_7>, field: string, value: unknown): import("..").QueryBuilderContract<TModel_7>;
|
|
322
|
+
where<TModel_8 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_8>, field: string, operator: string, value: unknown): import("..").QueryBuilderContract<TModel_8>;
|
|
323
|
+
where<TModel_9 extends Model<ModelSchema> = Model<ModelSchema>>(this: (new (...args: any[]) => TModel_9) & Pick<typeof Model, "table" | "getDataSource" | "query">, conditions: import("..").WhereObject): import("..").QueryBuilderContract<TModel_9>;
|
|
324
|
+
where<TModel_10 extends Model<ModelSchema> = Model<ModelSchema>>(this: (new (...args: any[]) => TModel_10) & Pick<typeof Model, "table" | "getDataSource" | "query">, callback: import("..").WhereCallback<TModel_10>): import("..").QueryBuilderContract<TModel_10>;
|
|
325
|
+
count<TModel_11 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_11>, filter?: Record<string, unknown>): Promise<number>;
|
|
326
|
+
find<TModel_12 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_12>, id: string | number): Promise<TModel_12>;
|
|
327
|
+
all<TModel_13 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_13>, filter?: Record<string, unknown>): Promise<TModel_13[]>;
|
|
328
|
+
latest<TModel_14 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_14>, filter?: Record<string, unknown>): Promise<TModel_14[]>;
|
|
329
|
+
increase<TModel_15 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_15>, filter: Record<string, unknown>, field: string, amount: number): Promise<number>;
|
|
330
|
+
decrease<TModel_16 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_16>, filter: Record<string, unknown>, field: string, amount: number): Promise<number>;
|
|
331
|
+
atomic<TModel_17 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_17>, filter: Record<string, unknown>, operations: Record<string, unknown>): Promise<number>;
|
|
332
|
+
delete<TModel_18 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_18>, filter?: Record<string, unknown>): Promise<number>;
|
|
333
|
+
deleteOne<TModel_19 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_19>, filter?: Record<string, unknown>): Promise<number>;
|
|
334
|
+
restore<TModel_20 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_20>, id: string | number, options?: {
|
|
335
|
+
onIdConflict?: "fail" | "assignNew";
|
|
336
|
+
skipEvents?: boolean;
|
|
337
|
+
}): Promise<TModel_20>;
|
|
338
|
+
restoreAll<TModel_21 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_21>, options?: {
|
|
339
|
+
onIdConflict?: "fail" | "assignNew";
|
|
340
|
+
skipEvents?: boolean;
|
|
341
|
+
}): Promise<TModel_21[]>;
|
|
342
|
+
create<TModel_22 extends Model<ModelSchema> = Model<ModelSchema>, TSchema_1 extends ModelSchema = TModel_22 extends Model<infer S extends ModelSchema> ? S : ModelSchema>(this: import("../model/model").ChildModel<TModel_22>, data: Partial<TSchema_1>): Promise<TModel_22>;
|
|
343
|
+
createMany<TModel_23 extends Model<ModelSchema> = Model<ModelSchema>, TSchema_2 extends ModelSchema = TModel_23 extends Model<infer S_1 extends ModelSchema> ? S_1 : ModelSchema>(this: import("../model/model").ChildModel<TModel_23>, data: Partial<TSchema_2>[]): Promise<TModel_23[]>;
|
|
344
|
+
findOrCreate<TModel_24 extends Model<ModelSchema> = Model<ModelSchema>, TSchema_3 extends ModelSchema = TModel_24 extends Model<infer S_2 extends ModelSchema> ? S_2 : ModelSchema>(this: import("../model/model").ChildModel<TModel_24>, filter: Partial<TSchema_3>, data: Partial<TSchema_3>): Promise<TModel_24>;
|
|
345
|
+
updateOrCreate<TModel_25 extends Model<ModelSchema> = Model<ModelSchema>, TSchema_4 extends ModelSchema = TModel_25 extends Model<infer S_3 extends ModelSchema> ? S_3 : ModelSchema>(this: import("../model/model").ChildModel<TModel_25>, filter: Partial<TSchema_4>, data: Partial<TSchema_4>): Promise<TModel_25>;
|
|
346
|
+
events<TModel_26 extends Model<ModelSchema> = Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_26>): import("..").ModelEvents<TModel_26>;
|
|
347
|
+
$cleanup(): void;
|
|
348
|
+
on<TModel_27 extends Model<ModelSchema> = Model<ModelSchema>, TContext_1 = unknown>(this: import("../model/model").ChildModel<TModel_27>, event: import("..").ModelEventName, listener: import("..").ModelEventListener<TModel_27, TContext_1>): () => void;
|
|
349
|
+
once<TModel_28 extends Model<ModelSchema> = Model<ModelSchema>, TContext_2 = unknown>(this: import("../model/model").ChildModel<TModel_28>, event: import("..").ModelEventName, listener: import("..").ModelEventListener<TModel_28, TContext_2>): () => void;
|
|
350
|
+
off<TModel_29 extends Model<ModelSchema> = Model<ModelSchema>, TContext_3 = unknown>(this: import("../model/model").ChildModel<TModel_29>, event: import("..").ModelEventName, listener: import("..").ModelEventListener<TModel_29, TContext_3>): void;
|
|
351
|
+
globalEvents(): import("..").ModelEvents<Model<ModelSchema>>;
|
|
352
|
+
deserialize<TModel_30 extends Model<ModelSchema>>(this: import("../model/model").ChildModel<TModel_30>, data: any): TModel_30;
|
|
353
|
+
}, "new"> & TStatics;
|
|
354
|
+
/**
|
|
355
|
+
* Type helper to infer the schema type from a defined model.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* const User = defineModel({
|
|
360
|
+
* table: "users",
|
|
361
|
+
* schema: v.object({
|
|
362
|
+
* name: v.string(),
|
|
363
|
+
* email: v.string(),
|
|
364
|
+
* }),
|
|
365
|
+
* });
|
|
366
|
+
*
|
|
367
|
+
* type UserType = ModelType<typeof User>;
|
|
368
|
+
* // { name: string; email: string; }
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
export type ModelType<T extends ReturnType<typeof defineModel>> = T extends new (...args: any[]) => infer R ? R extends Model<infer S> ? S : never : never;
|
|
372
|
+
//# sourceMappingURL=define-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-model.d.ts","sourceRoot":"","sources":["../../src/utils/define-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,WAAW,IAAI;IAC5D;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,MAAM,EAAE,eAAe,CAAC;IAExB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;;OAIG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE5D;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,WAAW,CACzB,OAAO,SAAS,WAAW,EAC3B,gBAAgB,SAAS,eAAe,GAAG,eAAe,EAC1D,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,EAC5C,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,EAEzC,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,GAAG;IACrC,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACpE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;CACtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAKC;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;oBAC2B,cAAc;IAE5C;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA4BN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,WAAW,CAAC,IAAI,CAAC,SAAS,KAC1E,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,MAAM,CAAC,GACR,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GACtB,CAAC,GACD,KAAK,GACP,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warlock.js/cascade",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.88",
|
|
4
4
|
"description": "ORM for managing databases",
|
|
5
5
|
"main": "./esm/index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"@mongez/events": "^2.1.0",
|
|
9
9
|
"@mongez/reinforcements": "^2.3.17",
|
|
10
10
|
"@mongez/supportive-is": "^2.0.0",
|
|
11
|
-
"@warlock.js/context": "4.0.
|
|
12
|
-
"@warlock.js/logger": "4.0.
|
|
13
|
-
"@warlock.js/seal": "4.0.
|
|
11
|
+
"@warlock.js/context": "4.0.88",
|
|
12
|
+
"@warlock.js/logger": "4.0.88",
|
|
13
|
+
"@warlock.js/seal": "4.0.88"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"update": "npx ncu -u",
|
|
@@ -25,17 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/warlockjs/cascade"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"
|
|
29
|
-
"commander": "^11.0.0",
|
|
30
|
-
"eslint": "^8.46.0",
|
|
31
|
-
"eslint-config-prettier": "^8.9.0",
|
|
32
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
33
|
-
"eslint-plugin-unused-imports": "^3.0.0",
|
|
34
|
-
"jest": "^29.6.2",
|
|
35
|
-
"npm-check-updates": "^16.10.17",
|
|
36
|
-
"prettier": "^3.0.0",
|
|
37
|
-
"prettier-plugin-organize-imports": "^3.2.3",
|
|
38
|
-
"ts-jest": "^29.1.1",
|
|
28
|
+
"mongodb": "^7.0.0",
|
|
39
29
|
"typescript": "^5.1.6"
|
|
40
30
|
},
|
|
41
31
|
"peerDependencies": {
|