@zeltjs/adapter-bun 0.5.0 → 0.6.1
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/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -26
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandApp, EnvConfig, HttpApp, ReadyResult } from "@zeltjs/core";
|
|
1
|
+
import { CommandApp, EnvConfig, ExecResult, ExecResult as ExecResult$1, HttpApp, ReadyResult } from "@zeltjs/core";
|
|
2
2
|
|
|
3
3
|
//#region src/bun-env.config.d.ts
|
|
4
4
|
declare class BunEnvConfig extends EnvConfig {
|
|
@@ -20,9 +20,6 @@ type ServerHandle = {
|
|
|
20
20
|
type BunAppOptions = {
|
|
21
21
|
readonly warmup?: boolean;
|
|
22
22
|
};
|
|
23
|
-
type ExecResult = {
|
|
24
|
-
readonly exitCode: 0 | 1;
|
|
25
|
-
};
|
|
26
23
|
type BunAppBase = {
|
|
27
24
|
readonly args: readonly string[];
|
|
28
25
|
};
|
|
@@ -31,7 +28,7 @@ type HttpBunApp = ReadyResult & BunAppBase & {
|
|
|
31
28
|
readonly shutdown: () => Promise<void>;
|
|
32
29
|
};
|
|
33
30
|
type CommandBunApp = ReadyResult & BunAppBase & {
|
|
34
|
-
readonly execCommand: (argv: string[]) => Promise<ExecResult>;
|
|
31
|
+
readonly execCommand: (argv: readonly string[]) => Promise<ExecResult$1>;
|
|
35
32
|
readonly shutdown: () => Promise<void>;
|
|
36
33
|
};
|
|
37
34
|
type FullBunApp = HttpBunApp & CommandBunApp;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/bun-env.config.ts","../src/on-bun.ts"],"mappings":";;;cAGa,YAAA,SAAqB,SAAA;EACvB,GAAA,CA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AU,aAAA,GAAgB,OAAA,CAAQ,aAAA"}
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,6 @@ var BunEnvConfig = class extends EnvConfig {
|
|
|
14
14
|
BunEnvConfig = _ts_decorate([Config], BunEnvConfig);
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/on-bun.ts
|
|
17
|
-
const successResult = { exitCode: 0 };
|
|
18
|
-
const failureResult = { exitCode: 1 };
|
|
19
17
|
const createServeForHttp = (appFetch, appShutdown) => {
|
|
20
18
|
return (options) => {
|
|
21
19
|
const port = options?.port ?? 3e3;
|
|
@@ -38,26 +36,6 @@ const createServeForHttp = (appFetch, appShutdown) => {
|
|
|
38
36
|
};
|
|
39
37
|
};
|
|
40
38
|
};
|
|
41
|
-
/** @throws {ZeltLifecycleStateError} */ const runCommand = (CommandClass, get) => {
|
|
42
|
-
const instance = get(CommandClass);
|
|
43
|
-
return Promise.resolve().then(() => instance.run()).then(() => successResult).catch(() => failureResult);
|
|
44
|
-
};
|
|
45
|
-
/** @throws {ZeltLifecycleStateError} */ const createExecForCommands = (hasCommand, getCommands, get, stderr) => {
|
|
46
|
-
return async (argv) => {
|
|
47
|
-
const commandName = argv[0];
|
|
48
|
-
if (!commandName) {
|
|
49
|
-
stderr.write("No command specified\n");
|
|
50
|
-
return failureResult;
|
|
51
|
-
}
|
|
52
|
-
if (!hasCommand(commandName)) {
|
|
53
|
-
stderr.write(`Command not found: ${commandName}\n`);
|
|
54
|
-
return failureResult;
|
|
55
|
-
}
|
|
56
|
-
const CommandClass = getCommands().get(commandName);
|
|
57
|
-
if (!CommandClass) return failureResult;
|
|
58
|
-
return runCommand(CommandClass, get);
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
39
|
const getStderr = () => globalThis.process.stderr;
|
|
62
40
|
const getArgs = () => Bun.argv.slice(2);
|
|
63
41
|
const extractCapabilities = (app) => app;
|
|
@@ -70,16 +48,22 @@ const buildHttpBunApp = (caps, resolver, shutdown, args) => {
|
|
|
70
48
|
shutdown
|
|
71
49
|
};
|
|
72
50
|
};
|
|
73
|
-
|
|
74
|
-
if (typeof caps.
|
|
51
|
+
const buildCommandBunApp = (caps, resolver, shutdown, stderr, args) => {
|
|
52
|
+
if (typeof caps.execCommand !== "function") return void 0;
|
|
53
|
+
const coreExecCommand = caps.execCommand;
|
|
54
|
+
const execCommand = async (argv) => {
|
|
55
|
+
const result = await coreExecCommand(argv);
|
|
56
|
+
if (result.exitCode === 1) stderr.write(`${result.reason.message}\n`);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
75
59
|
return {
|
|
76
60
|
...resolver,
|
|
77
61
|
args,
|
|
78
|
-
execCommand
|
|
62
|
+
execCommand,
|
|
79
63
|
shutdown
|
|
80
64
|
};
|
|
81
65
|
};
|
|
82
|
-
|
|
66
|
+
const buildBunApps = (caps, resolver, shutdown, stderr, args) => ({
|
|
83
67
|
httpResult: buildHttpBunApp(caps, resolver, shutdown, args),
|
|
84
68
|
commandResult: buildCommandBunApp(caps, resolver, shutdown, stderr, args)
|
|
85
69
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Config","EnvConfig","BunEnvConfig","get","key","Bun","env","BunEnvConfig","
|
|
1
|
+
{"version":3,"file":"index.js","names":["Config","EnvConfig","BunEnvConfig","get","key","Bun","env","BunEnvConfig","createServeForHttp","appFetch","appShutdown","options","port","hostname","server","Bun","serve","fetch","shutdown","stop","address","getStderr","globalThis","process","stderr","getArgs","argv","slice","extractCapabilities","app","buildHttpBunApp","caps","resolver","args","undefined","buildCommandBunApp","execCommand","coreExecCommand","result","exitCode","write","reason","message","buildBunApps","httpResult","commandResult","mergeBunApps","fullApp","onBun","addFallbackConfig","readyOptions","warmup","ready"],"sources":["../src/bun-env.config.ts","../src/on-bun.ts"],"sourcesContent":["import { Config, EnvConfig } from '@zeltjs/core';\n\n@Config\nexport class BunEnvConfig extends EnvConfig {\n override get(key: string): string | undefined {\n return Bun.env[key];\n }\n}\n","import type { CommandApp, ExecResult, HttpApp, ReadyOptions, ReadyResult } from '@zeltjs/core';\n\nimport { BunEnvConfig } from './bun-env.config';\n\ntype ServeOptions = {\n readonly port?: number;\n readonly hostname?: string;\n};\n\nexport type ServerHandle = {\n readonly address: { port: number; hostname: string };\n readonly shutdown: () => Promise<void>;\n};\n\nexport type BunAppOptions = {\n readonly warmup?: boolean;\n};\n\nexport type { ExecResult } from '@zeltjs/core';\n\ntype BunAppBase = {\n readonly args: readonly string[];\n};\n\nexport type HttpBunApp = ReadyResult &\n BunAppBase & {\n readonly serve: (options?: ServeOptions) => ServerHandle;\n readonly shutdown: () => Promise<void>;\n };\n\nexport type CommandBunApp = ReadyResult &\n BunAppBase & {\n readonly execCommand: (argv: readonly string[]) => Promise<ExecResult>;\n readonly shutdown: () => Promise<void>;\n };\n\nexport type FullBunApp = HttpBunApp & CommandBunApp;\n\nexport type BunApp = HttpBunApp | CommandBunApp | FullBunApp;\n\ntype Stderr = { write: (s: string) => void };\n\nconst createServeForHttp = (\n appFetch: (request: Request) => Promise<Response>,\n appShutdown: () => Promise<void>,\n): ((options?: ServeOptions) => ServerHandle) => {\n return (options?: ServeOptions): ServerHandle => {\n const port = options?.port ?? 3000;\n const hostname = options?.hostname ?? '0.0.0.0';\n\n const server = Bun.serve({\n fetch: appFetch,\n port,\n hostname,\n });\n\n const shutdown = async (): Promise<void> => {\n await server.stop();\n await appShutdown();\n };\n\n return {\n address: { port: server.port ?? port, hostname: server.hostname ?? hostname },\n shutdown,\n };\n };\n};\n\nconst getStderr = (): Stderr => globalThis.process.stderr;\n\nconst getArgs = (): readonly string[] => Bun.argv.slice(2);\n\ntype AppCapabilities = {\n fetch?: (request: Request) => Promise<Response>;\n execCommand?: (argv: readonly string[]) => Promise<ExecResult>;\n};\n\nconst extractCapabilities = (app: HttpApp | CommandApp | (HttpApp & CommandApp)): AppCapabilities =>\n app;\n\ntype BuildResult = {\n httpResult: HttpBunApp | undefined;\n commandResult: CommandBunApp | undefined;\n};\n\nconst buildHttpBunApp = (\n caps: AppCapabilities,\n resolver: ReadyResult,\n shutdown: () => Promise<void>,\n args: readonly string[],\n): HttpBunApp | undefined => {\n if (typeof caps.fetch !== 'function') return undefined;\n return { ...resolver, args, serve: createServeForHttp(caps.fetch, shutdown), shutdown };\n};\n\nconst buildCommandBunApp = (\n caps: AppCapabilities,\n resolver: ReadyResult,\n shutdown: () => Promise<void>,\n stderr: Stderr,\n args: readonly string[],\n): CommandBunApp | undefined => {\n if (typeof caps.execCommand !== 'function') return undefined;\n\n const coreExecCommand = caps.execCommand;\n const execCommand = async (argv: readonly string[]): Promise<ExecResult> => {\n const result = await coreExecCommand(argv);\n if (result.exitCode === 1) {\n stderr.write(`${result.reason.message}\\n`);\n }\n return result;\n };\n\n return { ...resolver, args, execCommand, shutdown };\n};\n\nconst buildBunApps = (\n caps: AppCapabilities,\n resolver: ReadyResult,\n shutdown: () => Promise<void>,\n stderr: Stderr,\n args: readonly string[],\n): BuildResult => ({\n httpResult: buildHttpBunApp(caps, resolver, shutdown, args),\n commandResult: buildCommandBunApp(caps, resolver, shutdown, stderr, args),\n});\n\nconst mergeBunApps = (\n result: BuildResult,\n resolver: ReadyResult,\n shutdown: () => Promise<void>,\n args: readonly string[],\n): BunApp => {\n const { httpResult, commandResult } = result;\n if (httpResult && commandResult) {\n const fullApp: FullBunApp = { ...httpResult, execCommand: commandResult.execCommand };\n return fullApp;\n }\n if (httpResult) return httpResult;\n if (commandResult) return commandResult;\n return {\n ...resolver,\n args,\n shutdown,\n serve: () => ({ address: { port: 0, hostname: '' }, shutdown }),\n };\n};\n\n/** @throws {ZeltLifecycleStateError} */\nexport function onBun(app: HttpApp & CommandApp, options?: BunAppOptions): Promise<FullBunApp>;\n/** @throws {ZeltLifecycleStateError} */\nexport function onBun(app: HttpApp, options?: BunAppOptions): Promise<HttpBunApp>;\n/** @throws {ZeltLifecycleStateError} */\nexport function onBun(app: CommandApp, options?: BunAppOptions): Promise<CommandBunApp>;\n/** @throws {ZeltLifecycleStateError} */\nexport async function onBun(\n app: HttpApp | CommandApp | (HttpApp & CommandApp),\n options: BunAppOptions = {},\n): Promise<BunApp> {\n app.addFallbackConfig(BunEnvConfig);\n\n const readyOptions: ReadyOptions = { warmup: options.warmup ?? true };\n const resolver = await app.ready(readyOptions);\n\n const caps = extractCapabilities(app);\n const stderr = getStderr();\n const args = getArgs();\n const result = buildBunApps(caps, resolver, app.shutdown, stderr, args);\n\n return mergeBunApps(result, resolver, app.shutdown, args);\n}\n"],"mappings":";;;;;;;;AAGA,IAAaE,eAAb,cAAkCD,UAAAA;CACvBE,IAAIC,KAAiC;AAC5C,SAAOC,IAAIC,IAAIF;;;;;;ACqCnB,MAAMI,sBACJC,UACAC,gBAAAA;AAEA,SAAQC,YAAAA;EACN,MAAMC,OAAOD,SAASC,QAAQ;EAC9B,MAAMC,WAAWF,SAASE,YAAY;EAEtC,MAAMC,SAASC,IAAIC,MAAM;GACvBC,OAAOR;GACPG;GACAC;GACF,CAAA;EAEA,MAAMK,WAAW,YAAA;AACf,SAAMJ,OAAOK,MAAI;AACjB,SAAMT,aAAAA;;AAGR,SAAO;GACLU,SAAS;IAAER,MAAME,OAAOF,QAAQA;IAAMC,UAAUC,OAAOD,YAAYA;IAAS;GAC5EK;GACF;;;AAIJ,MAAMG,kBAA0BC,WAAWC,QAAQC;AAEnD,MAAMC,gBAAmCV,IAAIW,KAAKC,MAAM,EAAA;AAOxD,MAAMC,uBAAuBC,QAC3BA;AAOF,MAAMC,mBACJC,MACAC,UACAd,UACAe,SAAAA;AAEA,KAAI,OAAOF,KAAKd,UAAU,WAAY,QAAOiB,KAAAA;AAC7C,QAAO;EAAE,GAAGF;EAAUC;EAAMjB,OAAOR,mBAAmBuB,KAAKd,OAAOC,SAAAA;EAAWA;EAAS;;AAGxF,MAAMiB,sBACJJ,MACAC,UACAd,UACAM,QACAS,SAAAA;AAEA,KAAI,OAAOF,KAAKK,gBAAgB,WAAY,QAAOF,KA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
2
|
"name": "@zeltjs/adapter-bun",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zeltjs/core": "0.
|
|
24
|
+
"@zeltjs/core": "0.6.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bun": "1.2.17"
|