Skip to content

Commit d38a560

Browse files
committed
feat: support effect labels
1 parent 8ec2d36 commit d38a560

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99
],
1010
"license": "MIT",
1111
"scripts": {
12-
"build": "tsc -b",
13-
"bump": "yarn yakumo version",
14-
"dep": "yarn yakumo upgrade",
15-
"pub": "yarn yakumo publish",
16-
"test": "yarn yakumo mocha -r esbuild-register -t 10000",
12+
"build": "yarn yakumo build",
13+
"test": "yarn yakumo mocha --import tsx -t 10000",
1714
"test:text": "shx rm -rf coverage && c8 -r text yarn test",
1815
"test:json": "shx rm -rf coverage && c8 -r json yarn test",
1916
"test:html": "shx rm -rf coverage && c8 -r html yarn test"
2017
},
2118
"devDependencies": {
22-
"@types/mocha": "^9.1.1",
19+
"@types/mocha": "^10.0.10",
2320
"@types/node": "^22.7.5",
2421
"c8": "^7.14.0",
2522
"esbuild": "^0.25.0",
26-
"esbuild-register": "^3.5.0",
2723
"mocha": "^11.1.0",
2824
"shx": "^0.3.4",
25+
"tsx": "npm:@cordiverse/[email protected]",
2926
"typescript": "^5.8.2",
3027
"yakumo": "^2.0.0-alpha.2",
3128
"yakumo-esbuild": "^2.0.0-alpha.2",

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cordisjs/plugin-server",
33
"description": "Server plugin for cordis",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"type": "module",
66
"main": "lib/index.js",
77
"types": "lib/index.d.ts",
@@ -30,11 +30,11 @@
3030
"plugin"
3131
],
3232
"peerDependencies": {
33-
"cordis": "^4.0.0-alpha.5"
33+
"cordis": "^4.0.0-alpha.6"
3434
},
3535
"devDependencies": {
3636
"@types/accepts": "^1.3.7",
37-
"cordis": "^4.0.0-alpha.5"
37+
"cordis": "^4.0.0-alpha.6"
3838
},
3939
"dependencies": {
4040
"@types/ws": "^8.5.10",

packages/core/src/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Context, DisposableList, Service, z } from 'cordis'
2-
import { defineProperty, Dict, isNullable, trimSlash } from 'cosmokit'
2+
import { defineProperty, isNullable, trimSlash } from 'cosmokit'
33
import * as http from 'node:http'
44
import { Keys, pathToRegexp } from 'path-to-regexp'
55
import { WebSocket, WebSocketServer } from 'ws'
@@ -116,7 +116,7 @@ export class WsRoute extends Route {
116116
socket.close()
117117
}
118118
}
119-
})
119+
}, `ctx.server.ws(${typeof path === 'string' ? JSON.stringify(path) : path})`)
120120
}
121121
}
122122

@@ -125,18 +125,18 @@ export type Middleware<P = any> = (req: Request & { params: P }, res: Response,
125125
class HttpRoute extends Route {
126126
dispose: () => Promise<void>
127127

128-
constructor(server: Server, public method: Server.Method | undefined, path: string | RegExp, public callback: Middleware) {
129-
super(server, method ?? 'ALL', path)
128+
constructor(server: Server, public method: string, path: string | RegExp, public callback: Middleware) {
129+
super(server, method, path)
130130
const self = this
131131
this.dispose = server.ctx.effect(function* () {
132132
yield server.httpRoutes.push(self)
133133
yield server.ctx.on('server/__route', async (req, res, next) => {
134-
if (method && req.method !== method) return next()
134+
if (method !== 'all' && req.method.toLowerCase() !== method) return next()
135135
const params = self.check(req)
136136
if (!params) return next()
137137
return callback(Object.assign(Object.create(req), { params }), res, next)
138138
})
139-
})
139+
}, `ctx.server.${method}(${typeof path === 'string' ? JSON.stringify(path) : path})`)
140140
}
141141
}
142142

@@ -158,7 +158,7 @@ class Server extends Service {
158158
static {
159159
for (const method of Server.methods) {
160160
defineProperty(Server.prototype, method, function (this: Server, path: string | RegExp, middleware: Middleware) {
161-
return new HttpRoute(this, method === 'all' ? undefined : method.toUpperCase() as Server.Method, path, middleware)
161+
return new HttpRoute(this, method, path, middleware)
162162
})
163163
}
164164
}
@@ -198,7 +198,7 @@ class Server extends Service {
198198
}
199199

200200
if (!isNullable(res.body)) return
201-
const methods = new Set<Server.Method>()
201+
const methods = new Set<string>()
202202
let asterisk = false
203203
for (const route of this.httpRoutes) {
204204
if (!route.check(req)) continue
@@ -305,8 +305,6 @@ class Server extends Service {
305305
}
306306

307307
namespace Server {
308-
export type Method = 'GET' | 'DELETE' | 'HEAD' | 'POST' | 'PUT' | 'PATCH'
309-
310308
export interface Config extends ListenOptions {
311309
host: string
312310
port: number

packages/temp/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
],
3030
"devDependencies": {
3131
"@cordisjs/plugin-http": "^1.0.0",
32-
"@cordisjs/plugin-server": "^1.0.1",
33-
"cordis": "^4.0.0-alpha.5"
32+
"@cordisjs/plugin-server": "^1.0.2",
33+
"cordis": "^4.0.0-alpha.6"
3434
},
3535
"peerDependencies": {
36-
"@cordisjs/plugin-server": "^1.0.1",
37-
"cordis": "^4.0.0-alpha.5"
36+
"@cordisjs/plugin-server": "^1.0.2",
37+
"cordis": "^4.0.0-alpha.6"
3838
},
3939
"dependencies": {
4040
"cosmokit": "^1.7.3"

yakumo.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- id: k9knuj
2+
name: yakumo
3+
config:
4+
pipeline:
5+
build:
6+
- tsc
7+
- esbuild
8+
- id: itydft
9+
name: yakumo-esbuild
10+
- id: ep025k
11+
name: yakumo-tsc

0 commit comments

Comments
 (0)