sleepy-serv 0.19.0 → 0.21.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/README.md +29 -10
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/run.d.ts +3 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/core/utils.d.ts +2 -2
- package/dist/core/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/build.ts +26 -3
- package/src/cli/index.ts +7 -2
- package/src/cli/{dev.ts → run.ts} +11 -3
- package/src/core/socket.ts +18 -18
- package/src/core/utils.ts +2 -2
- package/dist/cli/dev.d.ts +0 -2
- package/dist/cli/dev.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -43,12 +43,15 @@ filesystem and generate static imports for every route at load time. This
|
|
|
43
43
|
replaces the previous dynamic `import()` and `fs.readdirSync()` approach
|
|
44
44
|
and enables compatibility with `bun build --compile --bytecode`.
|
|
45
45
|
|
|
46
|
-
The plugin is loaded automatically by the CLI commands (`sleepy dev
|
|
47
|
-
`sleepy build`). If you prefer to run your entrypoint directly, preload
|
|
46
|
+
The plugin is loaded automatically by the CLI commands (`sleepy dev`,
|
|
47
|
+
`sleepy prod`, and `sleepy build`). If you prefer to run your entrypoint directly, preload
|
|
48
48
|
the plugin yourself:
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
|
|
51
|
+
sleepy init # creates a new project
|
|
52
|
+
sleepy dev # runs the app (watch mode)
|
|
53
|
+
sleepy prod # runs the app (NO watch mode)
|
|
54
|
+
sleepy build # for building a single-file bundle via `bun build` (recommended)
|
|
52
55
|
```
|
|
53
56
|
|
|
54
57
|
### Return Value
|
|
@@ -552,7 +555,7 @@ const app = createApp(3000, {
|
|
|
552
555
|
The `app.ws` object exposes four methods for interacting with connected clients:
|
|
553
556
|
|
|
554
557
|
- `query(fn)`: return a filtered list of active sessions. The filter function receives `(clientId, data, index)` and returns a boolean. Each entry in the returned array is a `SessionEntry` with `clientId` and `app` (the application context). To list all sessions: `app.ws.query(() => true)`.
|
|
555
|
-
- `send(
|
|
558
|
+
- `send(event, body, fn)`: push a notification to clients matching a filter. The filter function receives `(clientId, data, index)` and returns a boolean. To target one client: `app.ws.send('ping', body, id => id === targetId)`.
|
|
556
559
|
- `broadcast(event, body)`: push a notification to all connected clients.
|
|
557
560
|
- `drop(fn, code?, reason?)`: close connections matching a filter. The filter function receives `(clientId, data, index)` and returns a boolean. The default code is `CloseCode.Ok` (1000), which tells the client not to reconnect. Passing a custom code (e.g. 4000) allows the client to reconnect. To drop one client: `app.ws.drop(id => id === targetId)`.
|
|
558
561
|
|
|
@@ -562,7 +565,7 @@ The same commands are available inside endpoint handlers via `req.ws`:
|
|
|
562
565
|
export default function (req) {
|
|
563
566
|
const targetId = req.query.targetId
|
|
564
567
|
|
|
565
|
-
req.ws.send(
|
|
568
|
+
req.ws.send('ping', { from: 'handler' }, id => id === targetId)
|
|
566
569
|
|
|
567
570
|
return Response.json({ ok: true })
|
|
568
571
|
}
|
|
@@ -610,19 +613,35 @@ Equivalent to:
|
|
|
610
613
|
bun --watch --preload sleepy-serv/plugin src/index.ts
|
|
611
614
|
```
|
|
612
615
|
|
|
616
|
+
### `sleepy prod`
|
|
617
|
+
|
|
618
|
+
Starts the production server with the plugin preloaded (no watch mode):
|
|
619
|
+
|
|
620
|
+
```bash
|
|
621
|
+
sleepy prod
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
Equivalent to:
|
|
625
|
+
|
|
626
|
+
```bash
|
|
627
|
+
bun --preload sleepy-serv/plugin src/index.ts
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
Use this when `bun build --compile` is not an option (e.g. dynamic
|
|
631
|
+
imports, native dependencies like `pg`, or when a single-file
|
|
632
|
+
executable is not desired).
|
|
633
|
+
|
|
613
634
|
### `sleepy build`
|
|
614
635
|
|
|
615
636
|
Produces a production build using `Bun.build()` with the plugin:
|
|
616
637
|
|
|
617
638
|
```bash
|
|
618
639
|
sleepy build
|
|
619
|
-
sleepy build --compile
|
|
620
|
-
sleepy build --compile --bytecode
|
|
621
640
|
```
|
|
622
641
|
|
|
623
|
-
Output goes to `./dist` by default.
|
|
624
|
-
|
|
625
|
-
|
|
642
|
+
Output goes to `./dist` by default. Build options like `compile`,
|
|
643
|
+
`bytecode`, and `outdir` are configured in `sleepy.config.ts` (see
|
|
644
|
+
[Configuration](#configuration)).
|
|
626
645
|
|
|
627
646
|
## Configuration
|
|
628
647
|
|
package/dist/cli/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AA+BA,wBAAsB,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC,CAyE5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AA4BA,wBAAsB,GAAG,IAAK,OAAO,CAAC,IAAI,CAAC,CAE1C;AAED,wBAAsB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC,CAE3C"}
|
package/dist/core/utils.d.ts
CHANGED
|
@@ -102,10 +102,10 @@ export type SessionEntry = {
|
|
|
102
102
|
};
|
|
103
103
|
export type FilterFn = (clientId: string, data: unknown, index: number) => boolean;
|
|
104
104
|
export type SocketCommands = {
|
|
105
|
-
query: (fn: FilterFn) => SessionEntry[];
|
|
106
|
-
send: (fn: FilterFn, event: string, body: unknown) => void;
|
|
107
105
|
broadcast: (event: string, body: unknown) => void;
|
|
106
|
+
send: (event: string, body: unknown, fn: FilterFn) => void;
|
|
108
107
|
drop: (fn: FilterFn, code?: number, reason?: string) => void;
|
|
108
|
+
query: (fn: FilterFn) => SessionEntry[];
|
|
109
109
|
};
|
|
110
110
|
export type BaseRequest = {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CAAC,EAAE,SAAS,EAAE,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;IACzB,EAAE,CAAC,EAAE,aAAa,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;CACrC,CAAA;AAED,wBAAgB,UAAU,CAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAaxD;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,GACrB,cAAc,CAQhB;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,eAAe,GACrB,kBAAkB,CAyBpB"}
|
package/package.json
CHANGED
package/src/cli/build.ts
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
1
|
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
3
|
import { loadConfig } from '../plugin/config'
|
|
4
4
|
import { scanRoutes } from '../plugin/scanner'
|
|
5
5
|
import { generateBarrelModule } from '../plugin/codegen'
|
|
6
6
|
|
|
7
7
|
import type { BunPlugin } from 'bun'
|
|
8
8
|
|
|
9
|
+
function resolveCompileOption (
|
|
10
|
+
compile: boolean | string | undefined,
|
|
11
|
+
): { outfile: string } | undefined {
|
|
12
|
+
if (!compile) {
|
|
13
|
+
return undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof compile === 'string') {
|
|
17
|
+
return { outfile: compile }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const raw = fs.readFileSync('package.json', 'utf-8')
|
|
22
|
+
const pkg = JSON.parse(raw)
|
|
23
|
+
|
|
24
|
+
if (pkg.name) {
|
|
25
|
+
return { outfile: pkg.name }
|
|
26
|
+
}
|
|
27
|
+
} catch {}
|
|
28
|
+
|
|
29
|
+
return { outfile: 'api' }
|
|
30
|
+
}
|
|
31
|
+
|
|
9
32
|
export async function build (): Promise<void> {
|
|
10
33
|
const config = await loadConfig()
|
|
11
|
-
const entrypoint = config.app?.entrypoint?? './src/index.ts'
|
|
34
|
+
const entrypoint = config.app?.entrypoint ?? './src/index.ts'
|
|
12
35
|
|
|
13
36
|
if (!fs.existsSync(entrypoint)) {
|
|
14
37
|
console.error(`Entrypoint not found: ${entrypoint}`)
|
|
@@ -45,7 +68,7 @@ export async function build (): Promise<void> {
|
|
|
45
68
|
target: 'bun',
|
|
46
69
|
minify: true,
|
|
47
70
|
bytecode: config.build?.bytecode || undefined,
|
|
48
|
-
compile: (config.build?.compile
|
|
71
|
+
compile: resolveCompileOption(config.build?.compile),
|
|
49
72
|
plugins: [...userPlugins, sleepyPlugin],
|
|
50
73
|
entrypoints: [entrypoint],
|
|
51
74
|
})
|
package/src/cli/index.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
4
|
import { init } from './init'
|
|
5
|
-
import { dev } from './dev'
|
|
6
5
|
import { build } from './build'
|
|
6
|
+
import { dev, prod } from './run'
|
|
7
7
|
|
|
8
8
|
const USAGE = `
|
|
9
9
|
Usage: sleepy <command>
|
|
@@ -11,7 +11,8 @@ Usage: sleepy <command>
|
|
|
11
11
|
Commands:
|
|
12
12
|
init Create a new sleepy-serv project
|
|
13
13
|
dev Start the dev server (watch mode)
|
|
14
|
-
|
|
14
|
+
prod Start the production server
|
|
15
|
+
build Build for production (single-file executable)
|
|
15
16
|
|
|
16
17
|
Options:
|
|
17
18
|
--help Show this help message
|
|
@@ -43,6 +44,10 @@ switch (command) {
|
|
|
43
44
|
await dev()
|
|
44
45
|
break
|
|
45
46
|
|
|
47
|
+
case 'prod':
|
|
48
|
+
await prod()
|
|
49
|
+
break
|
|
50
|
+
|
|
46
51
|
case 'build':
|
|
47
52
|
await build()
|
|
48
53
|
break
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import { loadConfig } from '../plugin/config'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
async function run (watch: boolean): Promise<void> {
|
|
5
5
|
const config = await loadConfig()
|
|
6
6
|
const entrypoint = config.app?.entrypoint ?? './src/index.ts'
|
|
7
7
|
|
|
@@ -12,10 +12,10 @@ export async function dev (): Promise<void> {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const proc = Bun.spawn([
|
|
15
|
-
'bun', '--watch',
|
|
15
|
+
'bun', watch ? '--watch' : '',
|
|
16
16
|
'--preload', 'sleepy-serv/plugin',
|
|
17
17
|
entrypoint,
|
|
18
|
-
], {
|
|
18
|
+
].filter(Boolean), {
|
|
19
19
|
stdout: 'inherit',
|
|
20
20
|
stderr: 'inherit',
|
|
21
21
|
stdin: 'inherit',
|
|
@@ -25,3 +25,11 @@ export async function dev (): Promise<void> {
|
|
|
25
25
|
|
|
26
26
|
process.exit(code)
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export async function dev (): Promise<void> {
|
|
30
|
+
await run(true)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function prod (): Promise<void> {
|
|
34
|
+
await run(false)
|
|
35
|
+
}
|
package/src/core/socket.ts
CHANGED
|
@@ -746,50 +746,50 @@ export function buildSocketCommands (state: SocketState): SocketCommands {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
return {
|
|
749
|
-
|
|
750
|
-
const
|
|
749
|
+
broadcast (event, body) {
|
|
750
|
+
for (const clientId of state.activeSessions.keys()) {
|
|
751
|
+
sendToClient(clientId, event, body)
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
send (event, body, fn) {
|
|
751
755
|
let index = 0
|
|
752
756
|
|
|
757
|
+
/* TODO: look into concurrency at some point */
|
|
753
758
|
for (const [clientId, session] of state.activeSessions) {
|
|
754
759
|
if (fn(clientId, session.ws.data, index)) {
|
|
755
|
-
|
|
756
|
-
clientId,
|
|
757
|
-
app: session.ws.data.app,
|
|
758
|
-
})
|
|
760
|
+
sendToClient(clientId, event, body)
|
|
759
761
|
}
|
|
760
762
|
|
|
761
763
|
index += 1
|
|
762
764
|
}
|
|
763
|
-
|
|
764
|
-
return results
|
|
765
765
|
},
|
|
766
|
-
|
|
766
|
+
drop (fn, code, reason) {
|
|
767
767
|
let index = 0
|
|
768
768
|
|
|
769
|
-
/* TODO: look into concurrency at some point */
|
|
770
769
|
for (const [clientId, session] of state.activeSessions) {
|
|
771
770
|
if (fn(clientId, session.ws.data, index)) {
|
|
772
|
-
|
|
771
|
+
session.ws.close(code, reason)
|
|
773
772
|
}
|
|
774
773
|
|
|
775
774
|
index += 1
|
|
776
775
|
}
|
|
777
776
|
},
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
sendToClient(clientId, event, body)
|
|
781
|
-
}
|
|
782
|
-
},
|
|
783
|
-
drop (fn, code, reason) {
|
|
777
|
+
query (fn) {
|
|
778
|
+
const results: SessionEntry[] = []
|
|
784
779
|
let index = 0
|
|
785
780
|
|
|
786
781
|
for (const [clientId, session] of state.activeSessions) {
|
|
787
782
|
if (fn(clientId, session.ws.data, index)) {
|
|
788
|
-
|
|
783
|
+
results.push({
|
|
784
|
+
clientId,
|
|
785
|
+
app: session.ws.data.app,
|
|
786
|
+
})
|
|
789
787
|
}
|
|
790
788
|
|
|
791
789
|
index += 1
|
|
792
790
|
}
|
|
791
|
+
|
|
792
|
+
return results
|
|
793
793
|
},
|
|
794
794
|
}
|
|
795
795
|
}
|
package/src/core/utils.ts
CHANGED
|
@@ -133,10 +133,10 @@ export type FilterFn = (
|
|
|
133
133
|
) => boolean
|
|
134
134
|
|
|
135
135
|
export type SocketCommands = {
|
|
136
|
-
query: (fn: FilterFn) => SessionEntry[]
|
|
137
|
-
send: (fn: FilterFn, event: string, body: unknown) => void
|
|
138
136
|
broadcast: (event: string, body: unknown) => void
|
|
137
|
+
send: (event: string, body: unknown, fn: FilterFn) => void
|
|
139
138
|
drop: (fn: FilterFn, code?: number, reason?: string) => void
|
|
139
|
+
query: (fn: FilterFn) => SessionEntry[]
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export type BaseRequest = {
|
package/dist/cli/dev.d.ts
DELETED
package/dist/cli/dev.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAGA,wBAAsB,GAAG,IAAK,OAAO,CAAC,IAAI,CAAC,CAuB1C"}
|