Initial commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// packages/{{kebabCase feature}}/src/realtime/{{kebabCase channelSlug}}.channel.test.ts
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
{{camelCase channelSlug}}Channel,
|
||||
{{camelCase channelSlug}}Schema,
|
||||
} from "@/realtime/{{kebabCase channelSlug}}.channel";
|
||||
|
||||
describe("{{camelCase channelSlug}}Channel", () => {
|
||||
it("has the expected wire name", () => {
|
||||
expect({{camelCase channelSlug}}Channel.name).toBe(
|
||||
"{{kebabCase feature}}.{{kebabCase channelSlug}}",
|
||||
);
|
||||
});
|
||||
|
||||
it("validates an empty payload (stub schema)", () => {
|
||||
expect(() => {{camelCase channelSlug}}Schema.parse({})).not.toThrow();
|
||||
});
|
||||
});
|
||||
13
turbo/generators/templates/realtime/channel/channel.ts.hbs
Normal file
13
turbo/generators/templates/realtime/channel/channel.ts.hbs
Normal file
@@ -0,0 +1,13 @@
|
||||
// packages/{{kebabCase feature}}/src/realtime/{{kebabCase channelSlug}}.channel.ts
|
||||
import { z } from "zod";
|
||||
import { defineRealtimeChannel } from "@repo/core-realtime";
|
||||
|
||||
export const {{camelCase channelSlug}}Schema = z.object({}).strict();
|
||||
|
||||
export type {{pascalCase channelSlug}}Payload = z.infer<typeof {{camelCase channelSlug}}Schema>;
|
||||
|
||||
export const {{camelCase channelSlug}}Channel = defineRealtimeChannel(
|
||||
"{{kebabCase feature}}.{{kebabCase channelSlug}}",
|
||||
{{camelCase channelSlug}}Schema,
|
||||
{ scope: {{{scopeLiteral}}} },
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
// packages/{{kebabCase feature}}/src/realtime/handlers/on-{{kebabCase channelSlug}}.handler.test.ts
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { on{{pascalCase channelSlug}}Handler } from "@/realtime/handlers/on-{{kebabCase channelSlug}}.handler";
|
||||
|
||||
describe("on{{pascalCase channelSlug}}Handler", () => {
|
||||
it("returns a function (factory shape)", () => {
|
||||
const handler = on{{pascalCase channelSlug}}Handler();
|
||||
expect(typeof handler).toBe("function");
|
||||
});
|
||||
|
||||
it("does not throw on a valid stub input", async () => {
|
||||
const handler = on{{pascalCase channelSlug}}Handler();
|
||||
await expect(
|
||||
handler({} as never, { userId: "u1", roles: [] }),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
13
turbo/generators/templates/realtime/handler/handler.ts.hbs
Normal file
13
turbo/generators/templates/realtime/handler/handler.ts.hbs
Normal file
@@ -0,0 +1,13 @@
|
||||
// packages/{{kebabCase feature}}/src/realtime/handlers/on-{{kebabCase channelSlug}}.handler.ts
|
||||
import type { {{pascalCase channelSlug}}Payload } from "../{{kebabCase channelSlug}}.channel";
|
||||
import type { RealtimeContext } from "@repo/core-realtime";
|
||||
|
||||
export type IOn{{pascalCase channelSlug}}Handler = ReturnType<typeof on{{pascalCase channelSlug}}Handler>;
|
||||
|
||||
export const on{{pascalCase channelSlug}}Handler =
|
||||
() =>
|
||||
async (_input: {{pascalCase channelSlug}}Payload, _ctx: RealtimeContext): Promise<void> => {
|
||||
// TODO: implement the reaction. Inject deps via the factory's constructor
|
||||
// and use them here. The handler is wrapped in span+capture at bind time,
|
||||
// so just throwing on failure is the right shape.
|
||||
};
|
||||
Reference in New Issue
Block a user