Skip to content

Commit 882274c

Browse files
committed
rename x class and rename start to build
1 parent b16155b commit 882274c

File tree

10 files changed

+57
-46
lines changed

10 files changed

+57
-46
lines changed

.changeset/kind-squids-draw.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@xframework/core": minor
3+
"@xframework/next": minor
4+
---
5+
6+
rename x class and rename start to build

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@ It is a lightweight **un-opinionated** framework of pluggable modules, allowing
77
## Example
88

99
```ts
10-
import { X } from "@xframework/next";
10+
import { XFramework } from "@xframework/core";
1111
import { createDrizzleModule } from "@xframework/db/drizzle";
1212
import { createAuthJsModule } from "@xframework/auth/auth-js/next";
1313
import { createStripeModule } from "@xframework/payment/stripe";
1414

15-
export const x = X({
16-
modules: {
17-
db: createDrizzleModule(db),
18-
auth: createAuthJsModule(authConfig),
19-
stripe: createStripeModule({
20-
apiKey,
21-
webhooks: {
22-
onCustomerCreated() {
23-
// ...
24-
},
25-
},
26-
}),
27-
// ... and more ...
28-
},
29-
});
15+
export const x = new XFramework()
16+
.module("db", () => new DrizzleModule(db))
17+
.module("auth", () => new AuthJsModule(auth))
18+
.module("mailer", () => new NodemailerModule(mailer))
19+
.module("stripe", () => new StripeModule({
20+
apiKey,
21+
webhooks: {
22+
onCustomerCreated() {
23+
// ...
24+
}
25+
}
26+
}))
27+
.module("next", () => new NextModule())
28+
// ... and more ...
29+
.build();
30+
3031

3132
// Usage
3233
const users = x.db.select().from(users);

examples/mailer/src/x/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { AuthJsModule } from "@xframework/auth/authjs/next";
2-
import { X } from "@xframework/core";
2+
import { XFramework } from "@xframework/core";
33
import { DrizzleModule } from "@xframework/db/drizzle";
44
import { NodemailerModule } from "@xframework/mailer/nodemailer";
55
import { NextModule } from "@xframework/next";
66
import { db } from "../db";
77
import { auth } from "./auth";
88
import { mailer } from "./mailer";
99

10-
export const x = new X()
10+
export const x = new XFramework()
1111
.module("auth", () => new AuthJsModule(auth))
1212
.module("db", () => new DrizzleModule(db))
1313
.module("mailer", () => new NodemailerModule(mailer))
1414
.module("next", () => new NextModule())
15-
.start();
15+
.build();

examples/next-auth/src/x/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { AuthJsModule } from "@xframework/auth/authjs/next";
2-
import { X } from "@xframework/core";
2+
import { XFramework } from "@xframework/core";
33
import { DrizzleModule } from "@xframework/db/drizzle";
44
import { NextModule } from "@xframework/next";
55
import { db } from "../db";
66
import { auth } from "./auth";
77

8-
export const x = new X()
8+
export const x = new XFramework()
99
.module("db", () => new DrizzleModule(db))
1010
.module("auth", () => new AuthJsModule(auth))
1111
.module("next", () => new NextModule())
12-
.start();
12+
.build();

examples/next-drizzle/src/x/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { X } from "@xframework/core";
1+
import { XFramework } from "@xframework/core";
22
import { DrizzleModule } from "@xframework/db/drizzle";
33
import { db } from "../db";
44

5-
export const x = new X().module("db", () => new DrizzleModule(db)).start();
5+
export const x = new XFramework()
6+
.module("db", () => new DrizzleModule(db))
7+
.build();

examples/next-prisma/src/x/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { X } from "@xframework/core";
1+
import { XFramework } from "@xframework/core";
22
import { PrismaModule } from "@xframework/db/prisma";
33
import { prisma } from "../db";
44

5-
export const x = new X().module("db", () => new PrismaModule(prisma)).start();
5+
export const x = new XFramework()
6+
.module("db", () => new PrismaModule(prisma))
7+
.build();

examples/pg-boss/src/x/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { X } from "@xframework/core";
1+
import { XFramework } from "@xframework/core";
22
import { DrizzleModule } from "@xframework/db/drizzle";
33
import { PgBossModule } from "@xframework/queue/pg-boss";
44
import { count } from "drizzle-orm";
@@ -13,10 +13,10 @@ type Queues = {
1313
// biome-ignore lint/style/noNonNullAssertion: <explanation>
1414
const boss = new PgBoss(process.env.DATABASE_URL!);
1515

16-
export const x = new X()
16+
export const x = new XFramework()
1717
.module("db", () => new DrizzleModule(db))
1818
.module("queue", () => new PgBossModule<Queues>(boss))
19-
.start();
19+
.build();
2020

2121
x.queue.registerWorkers({
2222
sayHello: {

packages/core/src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { Hono } from "hono";
22
import type { Module, ModuleFactory, Modules } from "./module";
33

44
type XWithModules<T extends Modules> = Omit<
5-
X<T>,
5+
XFramework<T>,
66
"get" | "module" | "use" | "start"
77
> &
88
T;
99

1010
// biome-ignore lint/complexity/noBannedTypes: <explanation>
11-
export class X<RegisteredModules extends Modules = {}> {
11+
export class XFramework<RegisteredModules extends Modules = {}> {
1212
private modules: Map<string, Module> = new Map();
1313
private cache: Map<string, unknown> = new Map();
1414
private workers: (() => Promise<void> | void)[] = [];
@@ -26,27 +26,27 @@ export class X<RegisteredModules extends Modules = {}> {
2626
module<ModuleKey extends string, ModuleReturnType>(
2727
key: ModuleKey,
2828
factory: ModuleFactory<RegisteredModules, ModuleReturnType>,
29-
): X<RegisteredModules & { [Key in ModuleKey]: ModuleReturnType }> {
30-
const moduleInstance = factory(this as X<RegisteredModules>);
29+
): XFramework<RegisteredModules & { [Key in ModuleKey]: ModuleReturnType }> {
30+
const moduleInstance = factory(this as XFramework<RegisteredModules>);
3131

3232
void moduleInstance.initialize();
3333
this._.hono.route("/", moduleInstance.hono);
3434
this.modules.set(key, moduleInstance);
3535
this.workers.push(moduleInstance.worker.bind(moduleInstance));
3636

37-
return this as X<
37+
return this as XFramework<
3838
RegisteredModules & { [Key in ModuleKey]: ModuleReturnType }
3939
>;
4040
}
4141

4242
use<NewModules extends Modules>(
43-
other: X<NewModules>,
44-
): X<RegisteredModules & NewModules> {
43+
other: XFramework<NewModules>,
44+
): XFramework<RegisteredModules & NewModules> {
4545
other.modules.forEach((module, key) => {
4646
this.modules.set(key, module);
4747
});
4848

49-
return this as X<RegisteredModules & NewModules>;
49+
return this as XFramework<RegisteredModules & NewModules>;
5050
}
5151

5252
private get<ModuleKey extends keyof RegisteredModules>(
@@ -67,12 +67,12 @@ export class X<RegisteredModules extends Modules = {}> {
6767
return this.cache.get(key as string) as RegisteredModules[ModuleKey];
6868
}
6969

70-
start(): XWithModules<RegisteredModules> {
70+
build(): XWithModules<RegisteredModules> {
7171
return new Proxy(this, {
7272
get: (target, prop: string | symbol) => {
7373
if (prop in target) {
74-
return (target as X<RegisteredModules>)[
75-
prop as keyof X<RegisteredModules>
74+
return (target as XFramework<RegisteredModules>)[
75+
prop as keyof XFramework<RegisteredModules>
7676
];
7777
}
7878

packages/core/src/module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hono } from "hono";
2-
import type { X } from ".";
2+
import type { XFramework } from ".";
33

44
export class Module {
55
hono: Hono;
@@ -8,7 +8,7 @@ export class Module {
88
this.hono = new Hono();
99
}
1010

11-
install(x: X): unknown {
11+
install(x: XFramework): unknown {
1212
throw new Error("install method must be implemented");
1313
}
1414

@@ -20,5 +20,5 @@ export class Module {
2020
export type Modules = Record<string, unknown>;
2121

2222
export type ModuleFactory<CurrentModules extends Modules, ReturnType> = (
23-
x: X<CurrentModules>,
24-
) => Module & { install: (x: X) => ReturnType };
23+
x: XFramework<CurrentModules>,
24+
) => Module & { install: (x: XFramework) => ReturnType };

packages/next/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { X } from "@xframework/core";
1+
import type { XFramework } from "@xframework/core";
22
import { Module } from "@xframework/core/module";
33
import type { FetchEventLike } from "hono/types";
44
import { handle } from "hono/vercel";
@@ -23,7 +23,7 @@ type Handlers = {
2323
};
2424

2525
export class NextModule extends Module {
26-
install(x: X) {
26+
install(x: XFramework) {
2727
const createHandlers = (): Handlers => {
2828
const handlers = {} as Handlers;
2929

0 commit comments

Comments
 (0)