@meghjs/cli 0.5.2 → 0.5.4

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.
Files changed (61) hide show
  1. package/dist/commands/migrate.d.ts +23 -5
  2. package/dist/commands/migrate.js +44 -6
  3. package/dist/commands/new.js +7 -1
  4. package/dist/generators/auth-files.d.ts +37 -0
  5. package/dist/generators/auth-files.js +198 -0
  6. package/dist/generators/auth.d.ts +26 -0
  7. package/dist/generators/auth.js +542 -0
  8. package/dist/generators/factory.d.ts +25 -0
  9. package/dist/generators/factory.js +159 -0
  10. package/dist/generators/make.d.ts +38 -0
  11. package/dist/generators/make.js +176 -0
  12. package/dist/generators/migration-schema.d.ts +5 -0
  13. package/dist/generators/migration-schema.js +25 -2
  14. package/dist/generators/orm-model.d.ts +6 -1
  15. package/dist/generators/orm-model.js +31 -2
  16. package/dist/generators/resource.d.ts +21 -0
  17. package/dist/generators/resource.js +17 -3
  18. package/dist/generators/scaffold.d.ts +76 -0
  19. package/dist/generators/scaffold.js +353 -0
  20. package/dist/generators/update-model.d.ts +21 -0
  21. package/dist/generators/update-model.js +129 -0
  22. package/dist/program.js +175 -6
  23. package/dist/templates/cascade.d.ts +37 -0
  24. package/dist/templates/cascade.js +87 -0
  25. package/dist/templates/catalog/common.d.ts +1 -0
  26. package/dist/templates/catalog/common.js +63 -0
  27. package/dist/templates/catalog/construction.d.ts +1 -0
  28. package/dist/templates/catalog/construction.js +138 -0
  29. package/dist/templates/catalog/crm.d.ts +1 -0
  30. package/dist/templates/catalog/crm.js +81 -0
  31. package/dist/templates/catalog/ecommerce.d.ts +1 -0
  32. package/dist/templates/catalog/ecommerce.js +143 -0
  33. package/dist/templates/catalog/education.d.ts +1 -0
  34. package/dist/templates/catalog/education.js +80 -0
  35. package/dist/templates/catalog/hr.d.ts +1 -0
  36. package/dist/templates/catalog/hr.js +83 -0
  37. package/dist/templates/catalog/logistics.d.ts +1 -0
  38. package/dist/templates/catalog/logistics.js +60 -0
  39. package/dist/templates/catalog/marketing.d.ts +1 -0
  40. package/dist/templates/catalog/marketing.js +104 -0
  41. package/dist/templates/catalog/medical.d.ts +1 -0
  42. package/dist/templates/catalog/medical.js +147 -0
  43. package/dist/templates/catalog/pos.d.ts +1 -0
  44. package/dist/templates/catalog/pos.js +110 -0
  45. package/dist/templates/catalog/real-estate.d.ts +1 -0
  46. package/dist/templates/catalog/real-estate.js +171 -0
  47. package/dist/templates/fields.d.ts +64 -0
  48. package/dist/templates/fields.js +331 -0
  49. package/dist/templates/index.d.ts +27 -0
  50. package/dist/templates/index.js +175 -0
  51. package/dist/templates/migration.d.ts +7 -0
  52. package/dist/templates/migration.js +80 -0
  53. package/dist/templates/template.d.ts +37 -0
  54. package/dist/templates/template.js +36 -0
  55. package/dist/utils/dialect.d.ts +8 -0
  56. package/dist/utils/dialect.js +57 -0
  57. package/package.json +17 -5
  58. package/readme.md +30 -1
  59. package/stubs/controllers/model-controller.stub +10 -1
  60. package/stubs/seeders/database-seeder.stub +8 -0
  61. package/stubs/seeders/seeder.stub +10 -0
package/dist/program.js CHANGED
@@ -13,6 +13,9 @@ const start_1 = require("./commands/start");
13
13
  const errors_1 = require("./errors");
14
14
  const migrate_1 = require("./commands/migrate");
15
15
  const make_1 = require("./generators/make");
16
+ const scaffold_1 = require("./generators/scaffold");
17
+ const auth_1 = require("./generators/auth");
18
+ const fields_1 = require("./templates/fields");
16
19
  const log_1 = require("./utils/log");
17
20
  const stubs_1 = require("./utils/stubs");
18
21
  /**
@@ -110,8 +113,11 @@ function createProgram(run = {}) {
110
113
  "DB_NAME, ...) in the environment or .env, with optional settings in megh.database in\n" +
111
114
  "package.json. Migrations live in src/database/migrations; set megh.migrations to\n" +
112
115
  "change it. Sources are compiled with SWC first.");
113
- db("migrate", "Run pending migrations").action(() => {
114
- (0, migrate_1.migrate)({ cwd: cwd() });
116
+ db("migrate", "Run pending migrations")
117
+ .option("--seed", "Run the seeders afterwards (see db:seed)")
118
+ .option("--force", "With --seed: seed even when NODE_ENV is production")
119
+ .action((o) => {
120
+ (0, migrate_1.migrate)({ cwd: cwd(), seed: o.seed, force: o.force });
115
121
  });
116
122
  db("migrate:rollback", "Undo the last migration (or the last --step n)")
117
123
  .option("--step <n>", "Number of migrations to undo", parseInteger, 1)
@@ -121,8 +127,21 @@ function createProgram(run = {}) {
121
127
  db("migrate:reset", "Undo every migration").action(() => {
122
128
  (0, migrate_1.migrateReset)({ cwd: cwd() });
123
129
  });
124
- db("migrate:refresh", "Undo every migration, then run them all again").action(() => {
125
- (0, migrate_1.migrateRefresh)({ cwd: cwd() });
130
+ db("migrate:refresh", "Undo every migration, then run them all again")
131
+ .option("--seed", "Run the seeders afterwards (see db:seed)")
132
+ .option("--force", "With --seed: seed even when NODE_ENV is production")
133
+ .action((o) => {
134
+ (0, migrate_1.migrateRefresh)({ cwd: cwd(), seed: o.seed, force: o.force });
135
+ });
136
+ db("db:seed", "Fill the database: run the database seeder, or every seeder in file order")
137
+ .option("-s, --seeder <name>", "Run only this seeder, e.g. users for users.seeder.ts")
138
+ .option("--force", "Seed even when NODE_ENV is production")
139
+ .addHelpText("after", "\nSeeders live in src/database/seeders (set megh.seeders to change it). Without\n" +
140
+ "--seeder, database.seeder.ts runs and calls the others in its order; without it,\n" +
141
+ "every seeder runs in file-name order. A run is one transaction: if a seeder\n" +
142
+ "throws, nothing is saved.")
143
+ .action((o) => {
144
+ (0, migrate_1.dbSeed)({ cwd: cwd(), seeder: o.seeder, force: o.force });
126
145
  });
127
146
  db("migrate:status", "Show which migrations have run")
128
147
  .option("--json", "Print JSON")
@@ -138,6 +157,23 @@ function createProgram(run = {}) {
138
157
  .action((name, o) => {
139
158
  (0, make_1.makeMigration)(name, { cwd: cwd(), create: o.create, table: o.table, force: o.force });
140
159
  });
160
+ sub("make:seeder", "Create a seeder in src/database/seeders/<name>.seeder.ts")
161
+ .alias("m:sd")
162
+ .argument("<name>", "e.g. users, or database for the entry seeder db:seed runs")
163
+ .option("-f, --force", "Overwrite the file if it exists")
164
+ .action((name, o) => {
165
+ (0, make_1.makeSeeder)(name, { cwd: cwd(), force: o.force });
166
+ });
167
+ sub("make:factory", "Create a model factory in src/database/factories/<name>.factory.ts")
168
+ .alias("m:f")
169
+ .argument("<model>", "Model name, e.g. user for src/models/user.model.ts")
170
+ .option("-f, --force", "Overwrite the file if it exists")
171
+ .addHelpText("after", "\nWrites UserFactory = defineFactory(User, ({ faker }) => ({ ... })) with a Faker value\n" +
172
+ "for each column, picked from its name and type. A foreign key such as role_id uses\n" +
173
+ "RoleFactory when src/database/factories/role.factory.ts exists. Needs @faker-js/faker.")
174
+ .action((name, o) => {
175
+ (0, make_1.makeFactory)(name, { cwd: cwd(), force: o.force });
176
+ });
141
177
  // ── Generators ──────────────────────────────────────────────────────────
142
178
  const make = (name, aliases, description) => sub(name, description)
143
179
  .aliases(aliases)
@@ -147,8 +183,34 @@ function createProgram(run = {}) {
147
183
  .option("-t, --table <table>", "Table name (default: plural snake_case name, e.g. blog_posts)")
148
184
  .option("--orm", "Generate a TypeORM entity")
149
185
  .option("--root <dir>", "Folder under src/ to write to (also -rt)")
186
+ .option("--template [ref]", "Create the table from a template, e.g. ecommerce/product (no value: pick one)")
187
+ .option("--fields <list>", 'Columns to add or replace, e.g. "title,price:money,status:in(draft|live)"')
188
+ .option("--factory", "With --template/--fields: also write a factory")
189
+ .option("--no-deps", "With --template/--fields: don't create the tables foreign keys point to")
190
+ .option("-y, --yes", "Don't prompt")
191
+ .addHelpText("after", TEMPLATE_HELP)
192
+ .action(async (name, o) => {
193
+ if (o.template !== undefined || o.fields !== undefined) {
194
+ if (o.orm)
195
+ throw new errors_1.CliError("--template and --fields build Megh ORM models; leave out --orm.");
196
+ await (0, scaffold_1.makeFromTemplate)(name, { cwd: cwd(), mode: "model", ...templateOptions(o) });
197
+ return;
198
+ }
199
+ (0, make_1.makeModel)(name, { cwd: cwd(), force: o.force, table: o.table, orm: o.orm, root: o.root });
200
+ });
201
+ sub("update:model", "Sync a model's columns with its migrations, keeping relations and methods")
202
+ .alias("u:m")
203
+ .argument("<name>", "Model name, optionally nested (e.g. admin/User)")
204
+ .option("-t, --table <table>", "Table to read (default: the model's @Table, else the plural snake_case name)")
205
+ .option("--dto", "Also rewrite src/dtos/<name>.dto.ts from the updated columns")
206
+ .option("--dry-run", "Show what would change without writing")
207
+ .option("--root <dir>", "Folder under src/ the model is in (also -rt)")
208
+ .addHelpText("after", "\nAfter an alter-table migration, e.g. schema.table(\"users\", t => { t.string(\"phone\"); t.dropColumn(\"age\") }):\n" +
209
+ "new columns are added to the model, dropped ones removed, and fields still as make:model\n" +
210
+ "wrote them get the current type and nullability. Fields you customized (a name: mapping,\n" +
211
+ "a custom cast, extra options) are kept and reported.")
150
212
  .action((name, o) => {
151
- (0, make_1.makeModel)(name, { cwd: cwd(), ...o });
213
+ (0, make_1.updateModel)(name, { cwd: cwd(), table: o.table, dto: o.dto, dryRun: o.dryRun, root: o.root });
152
214
  });
153
215
  make("make:resource", ["m:r", "m:res"], "Create a REST resource for a model: its DTOs, a CRUD service and a controller")
154
216
  .option("-t, --table <table>", "Table to read the columns from when the model is missing (default: plural snake_case name)")
@@ -157,7 +219,16 @@ function createProgram(run = {}) {
157
219
  "there is none). Then src/dtos/<name>.dto.ts, src/services/<name>.service.ts and\n" +
158
220
  "src/controllers/<name>.controller.ts are written, e.g. for `make:resource user`:\n" +
159
221
  " GET /users?page=&perPage= POST /users GET|PUT|DELETE /users/:id")
160
- .action((name, o) => {
222
+ .option("--template [ref]", "Create the table from a template, e.g. ecommerce/product (no value: pick one)")
223
+ .option("--fields <list>", 'Columns to add or replace, e.g. "title,price:money,status:in(draft|live)"')
224
+ .option("--factory", "With --template/--fields: also write a factory")
225
+ .option("--no-deps", "With --template/--fields: don't create the tables foreign keys point to")
226
+ .option("-y, --yes", "Don't prompt")
227
+ .action(async (name, o) => {
228
+ if (o.template !== undefined || o.fields !== undefined) {
229
+ await (0, scaffold_1.makeFromTemplate)(name, { cwd: cwd(), mode: "resource", ...templateOptions(o) });
230
+ return;
231
+ }
161
232
  (0, make_1.makeResource)(name, { cwd: cwd(), force: o.force, table: o.table });
162
233
  });
163
234
  make("make:controller", ["m:c"], "Create a controller in src/controllers/<name>.controller.ts")
@@ -192,8 +263,106 @@ function createProgram(run = {}) {
192
263
  .action((name, o) => {
193
264
  (0, make_1.makeDto)(name, { cwd: cwd(), ...o });
194
265
  });
266
+ // ── Templates ───────────────────────────────────────────────────────────
267
+ sub("scaffold:domain", "Create the tables (and models or resources) of a domain's templates")
268
+ .alias("sc:domain")
269
+ .argument("[domain]", "e.g. ecommerce, pos, medical (no value: pick one)")
270
+ .option("--only <list>", "Only these templates, e.g. product,order,order_item", parseList)
271
+ .option("--all", "Every template of the domain, without the checklist")
272
+ .option("--resource", "Generate REST resources (DTOs, service, controller), not just models")
273
+ .option("--migrations-only", "Only write the migrations")
274
+ .option("--factory", "Also write a factory for each model")
275
+ .option("--no-deps", "Don't create the tables foreign keys point to")
276
+ .option("-f, --force", "Overwrite the generated models' files")
277
+ .option("-y, --yes", "Don't prompt: take every template (or --only) and their dependencies")
278
+ .addHelpText("after", TEMPLATE_HELP)
279
+ .action(async (domain, o) => {
280
+ await (0, scaffold_1.scaffoldDomain)(domain, {
281
+ cwd: cwd(),
282
+ only: o.only,
283
+ all: o.all,
284
+ mode: o.migrationsOnly ? "migration" : o.resource ? "resource" : "model",
285
+ factory: o.factory,
286
+ deps: o.deps,
287
+ force: o.force,
288
+ interactive: !o.yes,
289
+ });
290
+ });
291
+ // ── Auth ────────────────────────────────────────────────────────────────
292
+ sub("scaffold:auth", "Add sign-up and sign-in (JWT, API keys or both), optionally with roles and permissions")
293
+ .alias("sc:auth")
294
+ .option("--strategy <strategy>", `How clients sign in: ${auth_1.AUTH_STRATEGIES.join(", ")} (default: asked, else jwt)`)
295
+ .option("--roles <mode>", `Roles per user: ${auth_1.ROLE_MODES.join(", ")} (default: asked, else none)`)
296
+ .option("--permissions", "Roles grant permissions")
297
+ .option("--no-permissions", "Roles without permissions")
298
+ .option("-f, --force", "Overwrite the generated auth files")
299
+ .option("-y, --yes", "Don't prompt: use the options given and the defaults")
300
+ .addHelpText("after", [
301
+ "",
302
+ "Writes the users table (and roles, user_roles or users.role_id, permissions, api_keys",
303
+ "as chosen) as migrations and models; src/auth/ (password hashing, JWT or API-key helpers,",
304
+ "AppAuthentication, AppAuthorization, rbac.ts); an AuthService, DTOs and an AuthController",
305
+ "(POST /auth/register, POST /auth/login, GET /auth/me, /auth/api-keys); a roles seeder;",
306
+ "and registers them in src/app.ts. An existing users table gets the missing columns.",
307
+ ].join("\n"))
308
+ .action(async (o) => {
309
+ await (0, auth_1.scaffoldAuth)({
310
+ cwd: cwd(),
311
+ strategy: o.strategy,
312
+ roles: o.roles,
313
+ permissions: o.permissions,
314
+ force: o.force,
315
+ interactive: !o.yes,
316
+ });
317
+ });
318
+ sub("scaffold:rbac", "Add roles (one or many per user) and permissions to an app's users")
319
+ .alias("sc:rbac")
320
+ .option("--roles <mode>", "Roles per user: single or multiple (default: asked, else multiple)")
321
+ .option("--permissions", "Roles grant permissions")
322
+ .option("--no-permissions", "Roles without permissions")
323
+ .option("-f, --force", "Overwrite the generated files")
324
+ .option("-y, --yes", "Don't prompt: use the options given and the defaults")
325
+ .action(async (o) => {
326
+ await (0, auth_1.scaffoldRbac)({
327
+ cwd: cwd(),
328
+ roles: o.roles,
329
+ permissions: o.permissions,
330
+ force: o.force,
331
+ interactive: !o.yes,
332
+ });
333
+ });
334
+ sub("template:list", "List the model templates by domain")
335
+ .alias("templates")
336
+ .argument("[domain]", "Show one domain, with each template's columns")
337
+ .option("--json", "Print JSON")
338
+ .action((domain, o) => {
339
+ (0, scaffold_1.listTemplates)({ cwd: cwd(), domain, json: o.json });
340
+ });
195
341
  return { program, exitCode: () => exitCode };
196
342
  }
343
+ const TEMPLATE_HELP = [
344
+ "",
345
+ "Templates describe a table with fields from the fields library, e.g.",
346
+ ' megh make:model Product --template ecommerce/product --fields "barcode?:string(64)"',
347
+ ' megh make:model Ticket --fields "title,body,status:in(open|closed),user_id:cascade"',
348
+ "A field is name[?][:type[(args)]][:modifier]...: a preset (title, slug, price, address, ...),",
349
+ "or a type (string(n), text, integer, money, decimal(p,s), boolean, date, timestamp, json,",
350
+ "foreign(table), ...) with modifiers nullable, unique, index, default(x), in(a|b), cascade,",
351
+ "nullOnDelete, restrict. Columns ending in _id are foreign keys. Tables the foreign keys",
352
+ "point to are created too when no migration creates them. List templates: megh template:list",
353
+ ].join("\n");
354
+ /** The template options shared by make:model and make:resource. */
355
+ function templateOptions(o) {
356
+ return {
357
+ template: o.template,
358
+ fields: o.fields !== undefined ? (0, fields_1.parseFieldList)(o.fields) : undefined,
359
+ table: o.table,
360
+ force: o.force,
361
+ factory: o.factory,
362
+ deps: o.deps,
363
+ interactive: !o.yes,
364
+ };
365
+ }
197
366
  /**
198
367
  * Parse and run a command line (without the `node` and script entries).
199
368
  * Resolves to the process exit code instead of exiting, so it can be tested.
@@ -0,0 +1,37 @@
1
+ import type { MigrationTable } from "../generators/migration-schema";
2
+ import type { FieldDef } from "./fields";
3
+ /**
4
+ * SQL Server refuses a foreign key whose ON DELETE action (CASCADE or SET
5
+ * NULL) would form a cycle (a table referencing itself counts) or a second
6
+ * cascade path between two tables:
7
+ *
8
+ * "Introducing FOREIGN KEY constraint ... may cause cycles or multiple
9
+ * cascade paths."
10
+ *
11
+ * Such a foreign key gets no ON DELETE action instead, so deleting the
12
+ * referenced row fails while rows still point to it.
13
+ */
14
+ /** A foreign key with a cascading action: deleting in `from` changes `to`. */
15
+ export interface CascadeEdge {
16
+ from: string;
17
+ to: string;
18
+ }
19
+ /** The cascading foreign keys of the tables the migrations leave. */
20
+ export declare function cascadeEdges(schema: Map<string, MigrationTable>): CascadeEdge[];
21
+ export interface DroppedAction {
22
+ table: string;
23
+ column: string;
24
+ reason: string;
25
+ }
26
+ /**
27
+ * Walk the new tables' foreign keys (in the order given, ownership first:
28
+ * CASCADE before SET NULL) and drop the action of each one SQL Server would
29
+ * refuse. Returns the tables' fields, changed where needed.
30
+ */
31
+ export declare function limitCascadePaths(existing: CascadeEdge[], tables: {
32
+ table: string;
33
+ fields: FieldDef[];
34
+ }[]): {
35
+ fields: Map<string, FieldDef[]>;
36
+ dropped: DroppedAction[];
37
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cascadeEdges = cascadeEdges;
4
+ exports.limitCascadePaths = limitCascadePaths;
5
+ const CASCADING = new Set(["cascade", "set null", "set default"]);
6
+ /** The cascading foreign keys of the tables the migrations leave. */
7
+ function cascadeEdges(schema) {
8
+ const edges = [];
9
+ for (const table of schema.values()) {
10
+ for (const column of table.columns) {
11
+ const ref = column.references;
12
+ if (ref?.onDelete && CASCADING.has(ref.onDelete))
13
+ edges.push({ from: ref.table, to: table.name });
14
+ }
15
+ }
16
+ return edges;
17
+ }
18
+ /**
19
+ * Walk the new tables' foreign keys (in the order given, ownership first:
20
+ * CASCADE before SET NULL) and drop the action of each one SQL Server would
21
+ * refuse. Returns the tables' fields, changed where needed.
22
+ */
23
+ function limitCascadePaths(existing, tables) {
24
+ const graph = new Map();
25
+ const add = (e) => {
26
+ if (!graph.has(e.from))
27
+ graph.set(e.from, new Set());
28
+ graph.get(e.from).add(e.to);
29
+ };
30
+ existing.forEach(add);
31
+ const walk = (start, next) => {
32
+ const seen = new Set([start]);
33
+ const queue = [start];
34
+ while (queue.length) {
35
+ for (const n of next(queue.shift())) {
36
+ if (!seen.has(n)) {
37
+ seen.add(n);
38
+ queue.push(n);
39
+ }
40
+ }
41
+ }
42
+ return seen;
43
+ };
44
+ const descendants = (node) => walk(node, (n) => graph.get(n) ?? []);
45
+ const ancestors = (node) => walk(node, (n) => [...graph].filter(([, tos]) => tos.has(n)).map(([from]) => from));
46
+ /** Why SQL Server would refuse `from → to`, or undefined. */
47
+ const conflict = (from, to) => {
48
+ if (from === to)
49
+ return "it references its own table";
50
+ if (descendants(to).has(from))
51
+ return "it would form a cycle of cascading deletes";
52
+ const below = descendants(to);
53
+ for (const a of ancestors(from)) {
54
+ for (const b of descendants(a)) {
55
+ if (below.has(b))
56
+ return `"${a}" would reach "${b}" through two cascade paths`;
57
+ }
58
+ }
59
+ return undefined;
60
+ };
61
+ const fields = new Map(tables.map(({ table, fields: list }) => [table, list.map((f) => ({ ...f }))]));
62
+ // Every CASCADE (a row owned by its parent) is placed before any SET NULL
63
+ // (a looser link), each in the order given.
64
+ const candidates = tables
65
+ .flatMap(({ table }) => fields.get(table).map((f, i) => ({ table, f, i })))
66
+ .filter(({ f }) => f.references?.onDelete && CASCADING.has(f.references.onDelete));
67
+ const order = candidates.map((c, n) => ({ ...c, n })).sort((x, y) => rank(x.f) - rank(y.f) || x.n - y.n);
68
+ const dropped = [];
69
+ for (const { table, f, i } of order) {
70
+ const from = f.references.table;
71
+ const reason = conflict(from, table);
72
+ if (!reason) {
73
+ add({ from, to: table });
74
+ continue;
75
+ }
76
+ fields.get(table)[i] = {
77
+ ...f,
78
+ nullable: f.nullable || f.references.onDelete === "set null",
79
+ references: { table: from },
80
+ comment: "no ON DELETE action: SQL Server allows one cascade path between tables",
81
+ };
82
+ dropped.push({ table, column: f.name, reason });
83
+ }
84
+ return { fields, dropped };
85
+ }
86
+ /** CASCADE (ownership) is kept before SET NULL. */
87
+ const rank = (f) => (f.references?.onDelete === "cascade" ? 0 : 1);
@@ -0,0 +1 @@
1
+ export declare const common: import("../template").Domain;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.common = void 0;
4
+ const template_1 = require("../template");
5
+ exports.common = (0, template_1.domain)("common", "Common", "Users, roles, categories and other tables most apps share", [
6
+ [
7
+ "user",
8
+ "An account that signs in",
9
+ ["name", "email:unique", "password", "email_verified_at", "remember_token", "is_active", "last_login_at"],
10
+ { softDeletes: true },
11
+ ],
12
+ ["role", "A named set of permissions", ["name:string(64):unique", "slug:string(64):unique", "description"]],
13
+ [
14
+ "permission",
15
+ "One thing a role may do, e.g. posts.create",
16
+ ["name:string(128):unique", "group?:string(64)", "description"],
17
+ ],
18
+ ["user_role", "Which roles each user has", ["user_id:cascade", "role_id:cascade"], { pivot: true }],
19
+ [
20
+ "role_permission",
21
+ "Which permissions each role has",
22
+ ["role_id:cascade", "permission_id:cascade"],
23
+ { pivot: true },
24
+ ],
25
+ [
26
+ "category",
27
+ "A nestable category",
28
+ ["parent_id:foreign(categories):nullOnDelete", "name", "slug", "description", "image", "sort_order", "is_active"],
29
+ ],
30
+ ["tag", "A free-form label", ["name:string(64)", "slug:string(64):unique"]],
31
+ [
32
+ "address",
33
+ "A postal address of any record (addressable_type + addressable_id)",
34
+ ["addressable_type:string(64):index", "addressable_id:integer:index", "label?:string(64)", "address", "geo", "is_default:boolean:default(false)"],
35
+ ],
36
+ [
37
+ "attachment",
38
+ "An uploaded file of any record (attachable_type + attachable_id)",
39
+ [
40
+ "attachable_type:string(64):index",
41
+ "attachable_id:integer:index",
42
+ "name",
43
+ "path:string(2048)",
44
+ "disk:string(32):default(local)",
45
+ "mime_type?:string(128)",
46
+ "size:integer:default(0)",
47
+ ],
48
+ ],
49
+ [
50
+ "api_key",
51
+ "An API key of a user; only its SHA-256 hash is stored",
52
+ [
53
+ "user_id:cascade",
54
+ "name:string(100)",
55
+ "prefix:string(16):index",
56
+ "key_hash:string(64):unique",
57
+ "last_used_at?:timestamp",
58
+ "expires_at?:timestamp",
59
+ "revoked_at?:timestamp",
60
+ ],
61
+ ],
62
+ ["setting", "An application setting", ["name:string(128):unique", "value?:text", "group?:string(64)"]],
63
+ ]);
@@ -0,0 +1 @@
1
+ export declare const construction: import("../template").Domain;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.construction = void 0;
4
+ const template_1 = require("../template");
5
+ exports.construction = (0, template_1.domain)("construction", "Construction", "Building projects: sites, contractors, work orders, materials and budgets", [
6
+ ["client", "The client a project is built for", ["name", "company?:string", "email?", "phone", "address?"]],
7
+ [
8
+ "project",
9
+ "A construction project",
10
+ [
11
+ "client_id:nullOnDelete",
12
+ "manager_id:foreign(users):nullOnDelete",
13
+ "name",
14
+ "code",
15
+ "description",
16
+ "status:in(planning|active|on_hold|completed|cancelled)",
17
+ "budget?:money",
18
+ "start_date?:date",
19
+ "end_date?:date",
20
+ "address?",
21
+ ],
22
+ { softDeletes: true },
23
+ ],
24
+ [
25
+ "site",
26
+ "A site of a project",
27
+ ["project_id:cascade", "supervisor_id:foreign(users):nullOnDelete", "name", "address", "geo", "is_active"],
28
+ ],
29
+ [
30
+ "contractor",
31
+ "A contractor or subcontractor",
32
+ [
33
+ "name",
34
+ "company?:string",
35
+ "trade?:string(64)",
36
+ "email?",
37
+ "phone",
38
+ "license_number?:string(64)",
39
+ "address?",
40
+ "rating",
41
+ "is_active",
42
+ ],
43
+ ],
44
+ [
45
+ "work_order",
46
+ "A piece of work on a project",
47
+ [
48
+ "project_id:cascade",
49
+ "site_id:nullOnDelete",
50
+ "contractor_id:nullOnDelete",
51
+ "assigned_to_id:foreign(users):nullOnDelete",
52
+ "title",
53
+ "description",
54
+ "priority",
55
+ "status:in(open|in_progress|on_hold|completed|cancelled)",
56
+ "due_date",
57
+ "completed_at?:timestamp",
58
+ "estimated_cost?:money",
59
+ "actual_cost?:money",
60
+ ],
61
+ ],
62
+ [
63
+ "material",
64
+ "A building material kept in stock",
65
+ [
66
+ "name",
67
+ "sku",
68
+ "unit:string(16)",
69
+ "unit_cost:money",
70
+ "quantity_on_hand:decimal(12,3):default(0)",
71
+ "reorder_level?:decimal(12,3)",
72
+ "supplier?:string",
73
+ ],
74
+ ],
75
+ [
76
+ "equipment",
77
+ "A machine or tool",
78
+ [
79
+ "site_id:nullOnDelete",
80
+ "name",
81
+ "code",
82
+ "category?:string(64)",
83
+ "serial_number?:string(128)",
84
+ "status:in(available|in_use|maintenance|retired)",
85
+ "purchase_date?:date",
86
+ "purchase_cost?:money",
87
+ ],
88
+ { table: "equipment" },
89
+ ],
90
+ [
91
+ "timesheet",
92
+ "Hours a worker spent on a project",
93
+ [
94
+ "user_id:cascade",
95
+ "project_id:cascade",
96
+ "work_order_id:nullOnDelete",
97
+ "date",
98
+ "hours:decimal(5,2)",
99
+ "overtime_hours:decimal(5,2):default(0)",
100
+ "status:in(draft|submitted|approved|rejected)",
101
+ "notes",
102
+ ],
103
+ ],
104
+ [
105
+ "inspection",
106
+ "A site or safety inspection",
107
+ [
108
+ "project_id:cascade",
109
+ "site_id:nullOnDelete",
110
+ "inspector_name:string",
111
+ "type",
112
+ "scheduled_at?:timestamp",
113
+ "inspected_at?:timestamp",
114
+ "result:in(pending|passed|failed|conditional)",
115
+ "notes",
116
+ ],
117
+ ],
118
+ [
119
+ "change_order",
120
+ "A change to a project's scope, cost or schedule",
121
+ [
122
+ "project_id:cascade",
123
+ "requested_by_id:foreign(users):nullOnDelete",
124
+ "number:string(32):unique",
125
+ "title",
126
+ "description",
127
+ "amount",
128
+ "days_impact:integer:default(0)",
129
+ "status:in(draft|submitted|approved|rejected)",
130
+ "approved_at?:timestamp",
131
+ ],
132
+ ],
133
+ [
134
+ "budget_item",
135
+ "A budget line of a project",
136
+ ["project_id:cascade", "category:string(64)", "description", "budgeted_amount:money", "actual_amount:money:default(0)", "notes"],
137
+ ],
138
+ ]);
@@ -0,0 +1 @@
1
+ export declare const crm: import("../template").Domain;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.crm = void 0;
4
+ const template_1 = require("../template");
5
+ exports.crm = (0, template_1.domain)("crm", "CRM", "Accounts, contacts, deal pipelines and activities", [
6
+ [
7
+ "account",
8
+ "A company you sell to",
9
+ [
10
+ "owner_id:foreign(users):nullOnDelete",
11
+ "name",
12
+ "industry?:string(64)",
13
+ "website",
14
+ "phone",
15
+ "email?",
16
+ "address?",
17
+ "annual_revenue?:money",
18
+ "employee_count?:integer",
19
+ "status:in(prospect|customer|partner|inactive)",
20
+ ],
21
+ ],
22
+ [
23
+ "contact",
24
+ "A person at an account",
25
+ [
26
+ "account_id:nullOnDelete",
27
+ "owner_id:foreign(users):nullOnDelete",
28
+ "person",
29
+ "email",
30
+ "phone",
31
+ "job_title?:string(128)",
32
+ "notes",
33
+ ],
34
+ ],
35
+ ["pipeline", "A sales pipeline", ["name", "is_default:boolean:default(false)", "sort_order"]],
36
+ [
37
+ "pipeline_stage",
38
+ "A stage of a pipeline",
39
+ [
40
+ "pipeline_id:cascade",
41
+ "name",
42
+ "probability:integer:default(0)",
43
+ "sort_order",
44
+ "is_won:boolean:default(false)",
45
+ "is_lost:boolean:default(false)",
46
+ ],
47
+ ],
48
+ [
49
+ "deal",
50
+ "A sales opportunity",
51
+ [
52
+ "account_id:nullOnDelete",
53
+ "contact_id:nullOnDelete",
54
+ "pipeline_id:restrict",
55
+ "pipeline_stage_id:restrict",
56
+ "owner_id:foreign(users):nullOnDelete",
57
+ "title",
58
+ "amount:default(0)",
59
+ "currency",
60
+ "expected_close_date?:date",
61
+ "status:in(open|won|lost)",
62
+ "closed_at?:timestamp",
63
+ "lost_reason?:string(500)",
64
+ ],
65
+ ],
66
+ [
67
+ "activity",
68
+ "A call, email, meeting, task or note",
69
+ [
70
+ "user_id:nullOnDelete",
71
+ "account_id:nullOnDelete",
72
+ "contact_id:nullOnDelete",
73
+ "deal_id:nullOnDelete",
74
+ "type:in(call|email|meeting|task|note)",
75
+ "subject:string",
76
+ "description",
77
+ "due_at?:timestamp",
78
+ "completed_at?:timestamp",
79
+ ],
80
+ ],
81
+ ]);
@@ -0,0 +1 @@
1
+ export declare const ecommerce: import("../template").Domain;