Compare commits

..

No commits in common. "354405a253ed70973ac025fe5112b3a4373afdc9" and "bf7037eb15118850dbe35267bcf99af7a2285dd7" have entirely different histories.

8 changed files with 22 additions and 18 deletions

View file

@ -3,7 +3,11 @@ when:
steps: steps:
build: build:
image: oven/bun:1.1.3-slim image: oven/bun:${BUN_VERSION}-slim
commands: commands:
- bun install - bun install
- bun run build - bun run build
matrix:
BUN_VERSION:
- 1.1.0

View file

@ -3,7 +3,7 @@ when:
steps: steps:
lint: lint:
image: oven/bun:1.1.3-slim image: oven/bun:1.0.33-slim
commands: commands:
- bun install - bun install
- bun run ci - bun run ci

View file

@ -13,10 +13,7 @@ steps:
matrix: matrix:
BUN_VERSION: BUN_VERSION:
- 1.1.0 - 1.1.0
- 1.1.1
- 1.1.2
- 1.1.3
services: services:
nats: nats:
image: nats:2-alpine image: nats

BIN
bun.lockb

Binary file not shown.

View file

@ -12,7 +12,7 @@
"build": "tsc --project tsconfig.build.json" "build": "tsc --project tsconfig.build.json"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.6.4", "@biomejs/biome": "1.6.3",
"@types/bun": "latest", "@types/bun": "latest",
"typescript": "^5.0.0" "typescript": "^5.0.0"
}, },
@ -20,7 +20,7 @@
"typescript": "^5.0.0" "typescript": "^5.0.0"
}, },
"dependencies": { "dependencies": {
"nats": "^2.22.0", "nats": "^2.19.0",
"zod": "^3.22.4" "zod": "^3.22.4"
} }
} }

View file

@ -29,7 +29,7 @@ export default class Service {
adaptor: string, adaptor: string,
subject: string, subject: string,
fn: RouteSubscribeTypeFn<z.infer<T>, U>, fn: RouteSubscribeTypeFn<z.infer<T>, U>,
schema?: T, schema: T | undefined = undefined,
) { ) {
this.adaptors[adaptor].subscribe( this.adaptors[adaptor].subscribe(
`${this.name}.${subject}`, `${this.name}.${subject}`,
@ -64,7 +64,7 @@ export default class Service {
} }
try { try {
const res = await fn(this, req); const res = await fn(req);
const internalResponse = { const internalResponse = {
statusCode: res.statusCode, statusCode: res.statusCode,
data: res.data, data: res.data,

View file

@ -1,8 +1,6 @@
import type { Request, Response } from "./messages.ts"; import type { Request, Response } from "./messages.ts";
import type Service from "./service.ts";
export type AdaptorSubscribeTypeFn = (msg: string) => Promise<string>; export type AdaptorSubscribeTypeFn = (msg: string) => Promise<string>;
export type RouteSubscribeTypeFn<T, U> = ( export type RouteSubscribeTypeFn<T, U> = (
srv: Service,
msg: Request<T>, msg: Request<T>,
) => Promise<Response<U>>; ) => Promise<Response<U>>;

View file

@ -27,7 +27,7 @@ test("request success", async () => {
srv.subscribe( srv.subscribe(
adaptorName, adaptorName,
subject, subject,
async (srv, msg) => { async (msg) => {
return { data: msg.data, statusCode: statusCodeExpected }; return { data: msg.data, statusCode: statusCodeExpected };
}, },
z.string(), z.string(),
@ -54,9 +54,14 @@ test("request error", async () => {
const statusCodeExpected = 500; const statusCodeExpected = 500;
srv.addAdaptor(adaptorName, new NatsAdaptor({ servers: [natsServer] })); srv.addAdaptor(adaptorName, new NatsAdaptor({ servers: [natsServer] }));
srv.subscribe(adaptorName, subject, async (srv, msg) => { srv.subscribe(
throw new RequestError("request error", 500); adaptorName,
}); subject,
async (msg) => {
throw new RequestError("request error", 500);
},
z.string(),
);
await srv.listen(); await srv.listen();
expect(() => { expect(() => {
@ -77,7 +82,7 @@ test("request adaptor not found", async () => {
const statusCodeExpected = 200; const statusCodeExpected = 200;
srv.addAdaptor(adaptorName, new NatsAdaptor({ servers: [natsServer] })); srv.addAdaptor(adaptorName, new NatsAdaptor({ servers: [natsServer] }));
srv.subscribe(adaptorName, subject, async (srv, msg) => { srv.subscribe(adaptorName, subject, async (msg) => {
return { data: msg.data, statusCode: statusCodeExpected }; return { data: msg.data, statusCode: statusCodeExpected };
}); });