create-m5kdev 0.17.7 → 0.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-m5kdev",
3
- "version": "0.17.7",
3
+ "version": "0.19.0",
4
4
  "license": "GPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,27 +1,29 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { collectBackendSchema, generateBackendSchemaSource } from "@m5kdev/backend/app";
4
- import { backendSchemaModules } from "../src/schema-modules";
3
+ import * as authTables from "@m5kdev/backend/modules/auth/auth.db";
4
+ import * as notificationTables from "@m5kdev/backend/modules/notification/notification.db";
5
+ import * as workflowTables from "@m5kdev/backend/modules/workflow/workflow.db";
6
+ import * as postsTables from "../src/modules/posts/posts.db";
5
7
 
6
8
  export async function generateSchema(): Promise<void> {
7
- const collected = collectBackendSchema(backendSchemaModules, {
8
- env: process.env,
9
- });
10
9
  const outputDirectory = path.resolve(process.cwd(), "src/generated");
11
10
  const outputPath = path.join(outputDirectory, "schema.ts");
12
11
 
13
12
  const source = [
14
- 'import { collectBackendSchema } from "@m5kdev/backend/app";',
15
- 'import { backendSchemaModules } from "../schema-modules";',
13
+ 'import * as authTables from "@m5kdev/backend/modules/auth/auth.db";',
14
+ 'import * as notificationTables from "@m5kdev/backend/modules/notification/notification.db";',
15
+ 'import * as workflowTables from "@m5kdev/backend/modules/workflow/workflow.db";',
16
+ 'import * as postsTables from "../modules/posts/posts.db";',
16
17
  "",
17
- "const collected = collectBackendSchema(backendSchemaModules, {",
18
- " env: process.env,",
19
- "});",
18
+ "export const schema = {",
19
+ " ...authTables,",
20
+ " ...workflowTables,",
21
+ " ...notificationTables,",
22
+ " ...postsTables,",
23
+ "};",
24
+ "",
25
+ "export type AppDbSchema = typeof schema;",
20
26
  "",
21
- generateBackendSchemaSource({
22
- schema: collected.schema,
23
- schemaExpression: "collected.schema",
24
- }),
25
27
  ].join("\n");
26
28
 
27
29
  await fs.mkdir(outputDirectory, { recursive: true });
@@ -2,44 +2,24 @@ import { type AnySQLiteColumn, integer, sqliteTable as table, text } from "drizz
2
2
  import { organizations, teams, users } from "@m5kdev/backend/modules/auth/auth.db";
3
3
  import { v4 as uuidv4 } from "uuid";
4
4
 
5
- export function createPostsTables(
6
- references: {
7
- users: { id: AnySQLiteColumn };
8
- organizations: { id: AnySQLiteColumn };
9
- teams: { id: AnySQLiteColumn };
10
- } = {
11
- users,
12
- organizations,
13
- teams,
14
- }
15
- ) {
16
- const posts = table("posts", {
17
- id: text("id").primaryKey().$default(uuidv4),
18
- authorUserId: text("author_user_id").references(() => references.users.id, {
19
- onDelete: "set null",
20
- }),
21
- organizationId: text("organization_id").references(() => references.organizations.id, {
22
- onDelete: "set null",
23
- }),
24
- teamId: text("team_id").references(() => references.teams.id, { onDelete: "set null" }),
25
- title: text("title").notNull(),
26
- slug: text("slug").notNull().unique(),
27
- excerpt: text("excerpt"),
28
- content: text("content").notNull(),
29
- status: text("status").$type<"draft" | "published">().notNull().default("draft"),
30
- publishedAt: integer("published_at", { mode: "timestamp" }),
31
- createdAt: integer("created_at", { mode: "timestamp" })
32
- .notNull()
33
- .$default(() => new Date()),
34
- updatedAt: integer("updated_at", { mode: "timestamp" }),
35
- deletedAt: integer("deleted_at", { mode: "timestamp" }),
36
- });
37
-
38
- return {
39
- posts,
40
- };
41
- }
42
-
43
- const postTables = createPostsTables();
44
-
45
- export const posts = postTables.posts;
5
+ export const posts = table("posts", {
6
+ id: text("id").primaryKey().$default(uuidv4),
7
+ authorUserId: text("author_user_id").references(() => users.id, {
8
+ onDelete: "set null",
9
+ }),
10
+ organizationId: text("organization_id").references(() => organizations.id, {
11
+ onDelete: "set null",
12
+ }),
13
+ teamId: text("team_id").references(() => teams.id, { onDelete: "set null" }),
14
+ title: text("title").notNull(),
15
+ slug: text("slug").notNull().unique(),
16
+ excerpt: text("excerpt"),
17
+ content: text("content").notNull(),
18
+ status: text("status").$type<"draft" | "published">().notNull().default("draft"),
19
+ publishedAt: integer("published_at", { mode: "timestamp" }),
20
+ createdAt: integer("created_at", { mode: "timestamp" })
21
+ .notNull()
22
+ .$default(() => new Date()),
23
+ updatedAt: integer("updated_at", { mode: "timestamp" }),
24
+ deletedAt: integer("deleted_at", { mode: "timestamp" }),
25
+ });
@@ -1,37 +1,60 @@
1
- import { defineBackendModule } from "@m5kdev/backend/app";
2
- import { createPostsTRPC } from "./posts.trpc";
3
- import { createPostsTables } from "./posts.db";
1
+ import { createBackendRouterMap } from "@m5kdev/backend/app";
2
+ import type { AuthModule } from "@m5kdev/backend/modules/auth/auth.module";
3
+ import {
4
+ BaseModule,
5
+ type ModuleRepositoriesContext,
6
+ type ModuleServicesContext,
7
+ type ModuleTRPCContext,
8
+ } from "@m5kdev/backend/modules/base/base.module";
9
+ import type * as postsTables from "./posts.db";
4
10
  import { postsGrants } from "./posts.grants";
5
11
  import { PostsRepository } from "./posts.repository";
6
12
  import { PostsService } from "./posts.service";
13
+ import { createPostsTRPC } from "./posts.trpc";
14
+
15
+ type PostsModuleDeps = { auth: AuthModule };
16
+ type PostsModuleTables = typeof postsTables;
17
+ type PostsModuleRepositories = {
18
+ posts: PostsRepository;
19
+ };
20
+ type PostsModuleServices = {
21
+ posts: PostsService;
22
+ };
23
+ type PostsModuleRouters = {
24
+ posts: ReturnType<typeof createPostsTRPC>;
25
+ };
7
26
 
8
- export const postsModule = defineBackendModule({
9
- id: "posts",
10
- dependsOn: ["auth"],
11
- db: ({ deps }) => {
12
- const authTables = deps.auth.tables as any;
27
+ export class PostsModule extends BaseModule<
28
+ PostsModuleDeps,
29
+ PostsModuleTables,
30
+ PostsModuleRepositories,
31
+ PostsModuleServices,
32
+ PostsModuleRouters
33
+ > {
34
+ readonly id = "posts";
35
+ override readonly dependsOn = ["auth"] as const;
36
+
37
+ override repositories({ db }: ModuleRepositoriesContext<PostsModuleDeps, PostsModuleTables>) {
13
38
  return {
14
- tables: createPostsTables({
15
- users: authTables.users,
16
- organizations: authTables.organizations,
17
- teams: authTables.teams,
39
+ posts: new PostsRepository({
40
+ orm: db.orm,
41
+ schema: db.schema,
42
+ table: db.schema.posts,
18
43
  }),
19
44
  };
20
- },
21
- repositories: ({ db }) => {
22
- const schema = db.schema as any;
45
+ }
46
+
47
+ override services({
48
+ repositories,
49
+ }: ModuleServicesContext<PostsModuleDeps, PostsModuleRepositories>) {
23
50
  return {
24
- posts: new PostsRepository({
25
- orm: db.orm as never,
26
- schema: { posts: schema.posts } as never,
27
- table: schema.posts,
28
- }),
51
+ posts: new PostsService({ posts: repositories.posts }, {}, postsGrants),
29
52
  };
30
- },
31
- services: ({ repositories }) => ({
32
- posts: new PostsService({ posts: repositories.posts }, {}, postsGrants),
33
- }),
34
- trpc: ({ trpc, services }) => ({
35
- posts: createPostsTRPC(trpc, services.posts),
36
- }),
37
- });
53
+ }
54
+
55
+ override trpc({ trpc, services }: ModuleTRPCContext<PostsModuleDeps, PostsModuleServices>) {
56
+ return createBackendRouterMap("posts", createPostsTRPC(trpc, services.posts));
57
+ }
58
+ }
59
+
60
+ export const postsModule = new PostsModule();
@@ -1,20 +1,16 @@
1
1
  import { defineBackendModules } from "@m5kdev/backend/app";
2
- import { createAuthBackendModule } from "@m5kdev/backend/modules/auth/auth.module";
3
- import { createEmailBackendModule } from "@m5kdev/backend/modules/email/email.module";
4
- import { createNotificationBackendModule } from "@m5kdev/backend/modules/notification/notification.module";
5
- import { createWorkflowBackendModule } from "@m5kdev/backend/modules/workflow/workflow.module";
2
+ import { AuthModule } from "@m5kdev/backend/modules/auth/auth.module";
3
+ import { EmailModule } from "@m5kdev/backend/modules/email/email.module";
4
+ import { NotificationModule } from "@m5kdev/backend/modules/notification/notification.module";
5
+ import { WorkflowModule } from "@m5kdev/backend/modules/workflow/workflow.module";
6
6
  import { templates } from "{{PACKAGE_SCOPE}}/email";
7
- import { postsModule } from "./modules/posts/posts.module";
7
+ import { PostsModule } from "./modules/posts/posts.module";
8
8
 
9
- export const emailBackendModule = createEmailBackendModule({
10
- templates: templates as never,
11
- });
9
+ export const emailBackendModule = new EmailModule(templates as never);
12
10
 
13
- export const authBackendModule = createAuthBackendModule({
14
- emailModuleId: "email",
15
- });
11
+ export const authBackendModule = new AuthModule();
16
12
 
17
- export const workflowBackendModule = createWorkflowBackendModule({
13
+ export const workflowBackendModule = new WorkflowModule({
18
14
  queues: {
19
15
  fast: { concurrency: 5 },
20
16
  },
@@ -25,8 +21,8 @@ export const workflowBackendModule = createWorkflowBackendModule({
25
21
  },
26
22
  });
27
23
 
28
- export const notificationBackendModule = createNotificationBackendModule();
29
- export const postsBackendModule = postsModule;
24
+ export const notificationBackendModule = new NotificationModule();
25
+ export const postsBackendModule = new PostsModule();
30
26
 
31
27
  export const backendModules = defineBackendModules([
32
28
  emailBackendModule,
@@ -1,5 +1,10 @@
1
1
  import { defineBackendModule, defineBackendModules } from "@m5kdev/backend/app";
2
- import { authBackendModule, notificationBackendModule, postsBackendModule, workflowBackendModule } from "./modules";
2
+ import {
3
+ authBackendModule,
4
+ notificationBackendModule,
5
+ postsBackendModule,
6
+ workflowBackendModule,
7
+ } from "./modules";
3
8
 
4
9
  export const emailSchemaModule = defineBackendModule({
5
10
  id: "email",