@rudderjs/orm 1.10.0 → 1.11.0
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/dist/commands/make-factory.d.ts +15 -0
- package/dist/commands/make-factory.d.ts.map +1 -0
- package/dist/commands/make-factory.js +51 -0
- package/dist/commands/make-factory.js.map +1 -0
- package/dist/commands/make-seeder.d.ts +16 -0
- package/dist/commands/make-seeder.d.ts.map +1 -0
- package/dist/commands/make-seeder.js +39 -0
- package/dist/commands/make-seeder.js.map +1 -0
- package/package.json +12 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MakeSpec } from '@rudderjs/console';
|
|
2
|
+
/**
|
|
3
|
+
* `pnpm rudder make:factory User` → `app/Factories/UserFactory.ts`
|
|
4
|
+
*
|
|
5
|
+
* Stub matches the real `ModelFactory` abstract-class shape (see
|
|
6
|
+
* `packages/orm/src/factory.ts`): subclass + `protected modelClass` +
|
|
7
|
+
* `definition()` returning the seed attrs. The runtime is class-based,
|
|
8
|
+
* not Laravel's `Factory.define()` callback style.
|
|
9
|
+
*
|
|
10
|
+
* The base model name is inferred from the factory's stem — `UserFactory`
|
|
11
|
+
* imports `User` from `App/Models/User.js`. Users rename if their model
|
|
12
|
+
* file doesn't match the convention.
|
|
13
|
+
*/
|
|
14
|
+
export declare const makeFactorySpec: MakeSpec;
|
|
15
|
+
//# sourceMappingURL=make-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-factory.d.ts","sourceRoot":"","sources":["../../src/commands/make-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,EAAE,QAqC7B,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pnpm rudder make:factory User` → `app/Factories/UserFactory.ts`
|
|
3
|
+
*
|
|
4
|
+
* Stub matches the real `ModelFactory` abstract-class shape (see
|
|
5
|
+
* `packages/orm/src/factory.ts`): subclass + `protected modelClass` +
|
|
6
|
+
* `definition()` returning the seed attrs. The runtime is class-based,
|
|
7
|
+
* not Laravel's `Factory.define()` callback style.
|
|
8
|
+
*
|
|
9
|
+
* The base model name is inferred from the factory's stem — `UserFactory`
|
|
10
|
+
* imports `User` from `App/Models/User.js`. Users rename if their model
|
|
11
|
+
* file doesn't match the convention.
|
|
12
|
+
*/
|
|
13
|
+
export const makeFactorySpec = {
|
|
14
|
+
command: 'make:factory',
|
|
15
|
+
description: 'Create a new model factory class',
|
|
16
|
+
label: 'Factory created',
|
|
17
|
+
suffix: 'Factory',
|
|
18
|
+
directory: 'app/Factories',
|
|
19
|
+
stub: (className) => {
|
|
20
|
+
// `UserFactory` → `User`. If the user passes a name already ending in
|
|
21
|
+
// `Factory`, suffix logic above already preserved the original. Strip
|
|
22
|
+
// the suffix to recover the model name.
|
|
23
|
+
const modelName = className.replace(/Factory$/, '');
|
|
24
|
+
return `import { ModelFactory, sequence } from '@rudderjs/orm'
|
|
25
|
+
import { ${modelName} } from 'App/Models/${modelName}.js'
|
|
26
|
+
|
|
27
|
+
export class ${className} extends ModelFactory<{
|
|
28
|
+
// Fill in the attribute shape for ${modelName} — TS infers definition() against this.
|
|
29
|
+
name: string
|
|
30
|
+
email: string
|
|
31
|
+
}> {
|
|
32
|
+
protected modelClass = ${modelName}
|
|
33
|
+
|
|
34
|
+
definition() {
|
|
35
|
+
return {
|
|
36
|
+
name: 'Example',
|
|
37
|
+
email: sequence(i => \`user\${i}@example.com\`)(),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Named states — call ${className}.new().state('<name>').create()
|
|
42
|
+
// protected states() {
|
|
43
|
+
// return {
|
|
44
|
+
// admin: () => ({ role: 'admin' as const }),
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=make-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-factory.js","sourceRoot":"","sources":["../../src/commands/make-factory.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,eAAe,GAAa;IACvC,OAAO,EAAM,cAAc;IAC3B,WAAW,EAAE,kCAAkC;IAC/C,KAAK,EAAQ,iBAAiB;IAC9B,MAAM,EAAO,SAAS;IACtB,SAAS,EAAI,eAAe;IAC5B,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE;QAClB,sEAAsE;QACtE,sEAAsE;QACtE,wCAAwC;QACxC,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;QACnD,OAAO;WACA,SAAS,uBAAuB,SAAS;;eAErC,SAAS;uCACe,SAAS;;;;2BAIrB,SAAS;;;;;;;;;2BAST,SAAS;;;;;;;CAOnC,CAAA;IACC,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MakeSpec } from '@rudderjs/console';
|
|
2
|
+
/**
|
|
3
|
+
* `pnpm rudder make:seeder Users` → `database/seeders/UsersSeeder.ts`
|
|
4
|
+
*
|
|
5
|
+
* Stub matches the real `Seeder` abstract-class shape (see
|
|
6
|
+
* `packages/orm/src/seeder.ts`): subclass + `async run()` body. The
|
|
7
|
+
* `Seeder.call(OtherSeeder)` helper is shown commented so a top-level
|
|
8
|
+
* `DatabaseSeeder` can compose child seeders without hunting the docs.
|
|
9
|
+
*
|
|
10
|
+
* Directory: `database/seeders/` (project root, not `app/`) — matches
|
|
11
|
+
* Laravel's convention. The orm's `db:seed` runner already discovers
|
|
12
|
+
* `database/seeders/DatabaseSeeder.{ts,js,mts,mjs}` (see
|
|
13
|
+
* `findSeederFile()` in `packages/orm/src/commands/migrate.ts`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const makeSeederSpec: MakeSpec;
|
|
16
|
+
//# sourceMappingURL=make-seeder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-seeder.d.ts","sourceRoot":"","sources":["../../src/commands/make-seeder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,EAAE,QAwB5B,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pnpm rudder make:seeder Users` → `database/seeders/UsersSeeder.ts`
|
|
3
|
+
*
|
|
4
|
+
* Stub matches the real `Seeder` abstract-class shape (see
|
|
5
|
+
* `packages/orm/src/seeder.ts`): subclass + `async run()` body. The
|
|
6
|
+
* `Seeder.call(OtherSeeder)` helper is shown commented so a top-level
|
|
7
|
+
* `DatabaseSeeder` can compose child seeders without hunting the docs.
|
|
8
|
+
*
|
|
9
|
+
* Directory: `database/seeders/` (project root, not `app/`) — matches
|
|
10
|
+
* Laravel's convention. The orm's `db:seed` runner already discovers
|
|
11
|
+
* `database/seeders/DatabaseSeeder.{ts,js,mts,mjs}` (see
|
|
12
|
+
* `findSeederFile()` in `packages/orm/src/commands/migrate.ts`).
|
|
13
|
+
*/
|
|
14
|
+
export const makeSeederSpec = {
|
|
15
|
+
command: 'make:seeder',
|
|
16
|
+
description: 'Create a new database seeder class',
|
|
17
|
+
label: 'Seeder created',
|
|
18
|
+
suffix: 'Seeder',
|
|
19
|
+
directory: 'database/seeders',
|
|
20
|
+
stub: (className) => {
|
|
21
|
+
// `UsersSeeder` → `Users`. Useful as a hint for the example body's
|
|
22
|
+
// factory import — the user picks the actual model + factory names.
|
|
23
|
+
const subject = className.replace(/Seeder$/, '');
|
|
24
|
+
return `import { Seeder } from '@rudderjs/orm'
|
|
25
|
+
// import { ${subject}Factory } from 'App/Factories/${subject}Factory.js'
|
|
26
|
+
|
|
27
|
+
export class ${className} extends Seeder {
|
|
28
|
+
async run(): Promise<void> {
|
|
29
|
+
// Replace with your seed logic — e.g.
|
|
30
|
+
// await ${subject}Factory.new().create(10)
|
|
31
|
+
|
|
32
|
+
// Or compose other seeders from a top-level DatabaseSeeder:
|
|
33
|
+
// await this.call(${subject}Seeder)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=make-seeder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-seeder.js","sourceRoot":"","sources":["../../src/commands/make-seeder.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAa;IACtC,OAAO,EAAM,aAAa;IAC1B,WAAW,EAAE,oCAAoC;IACjD,KAAK,EAAQ,gBAAgB;IAC7B,MAAM,EAAO,QAAQ;IACrB,SAAS,EAAI,kBAAkB;IAC/B,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE;QAClB,mEAAmE;QACnE,oEAAoE;QACpE,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;QAChD,OAAO;cACG,OAAO,iCAAiC,OAAO;;eAE9C,SAAS;;;eAGT,OAAO;;;yBAGG,OAAO;;;CAG/B,CAAA;IACC,CAAC;CACF,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rudderjs/orm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,10 +29,19 @@
|
|
|
29
29
|
"./commands/prune": {
|
|
30
30
|
"import": "./dist/commands/prune.js",
|
|
31
31
|
"types": "./dist/commands/prune.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./commands/make-factory": {
|
|
34
|
+
"import": "./dist/commands/make-factory.js",
|
|
35
|
+
"types": "./dist/commands/make-factory.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./commands/make-seeder": {
|
|
38
|
+
"import": "./dist/commands/make-seeder.js",
|
|
39
|
+
"types": "./dist/commands/make-seeder.d.ts"
|
|
32
40
|
}
|
|
33
41
|
},
|
|
34
42
|
"dependencies": {
|
|
35
|
-
"@rudderjs/contracts": "^1.7.0"
|
|
43
|
+
"@rudderjs/contracts": "^1.7.0",
|
|
44
|
+
"@rudderjs/console": "^1.1.0"
|
|
36
45
|
},
|
|
37
46
|
"devDependencies": {
|
|
38
47
|
"@types/node": "^20.0.0",
|
|
@@ -44,7 +53,7 @@
|
|
|
44
53
|
"dev": "tsc -p tsconfig.build.json --watch",
|
|
45
54
|
"typecheck": "tsc --noEmit",
|
|
46
55
|
"lint": "eslint src",
|
|
47
|
-
"test": "tsc -p tsconfig.test.json && node --test dist-test/index.test.js dist-test/dirty.test.js dist-test/morph.test.js dist-test/morph-many-to-many.test.js dist-test/polymorphic-eager-load.test.js dist-test/belongs-to-many-pivot.test.js dist-test/whereHas.test.js dist-test/where-group.test.js dist-test/aggregate.test.js dist-test/seeder.test.js dist-test/prune.test.js dist-test/vector-cast.test.js dist-test/commands/migrate.test.js dist-test/commands/prune.test.js
|
|
56
|
+
"test": "tsc -p tsconfig.test.json && node --test dist-test/index.test.js dist-test/dirty.test.js dist-test/morph.test.js dist-test/morph-many-to-many.test.js dist-test/polymorphic-eager-load.test.js dist-test/belongs-to-many-pivot.test.js dist-test/whereHas.test.js dist-test/where-group.test.js dist-test/aggregate.test.js dist-test/seeder.test.js dist-test/prune.test.js dist-test/vector-cast.test.js dist-test/commands/migrate.test.js dist-test/commands/prune.test.js",
|
|
48
57
|
"clean": "rm -rf dist"
|
|
49
58
|
}
|
|
50
59
|
}
|