@zeltjs/adapter-bun 0.8.2-canary.0 → 0.8.2-canary.2

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.cjs ADDED
@@ -0,0 +1,124 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _zeltjs_core = require("@zeltjs/core");
3
+ //#region src/bun-cli.config.ts
4
+ function _ts_decorate$1(decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ }
10
+ var BunCliConfig = class extends _zeltjs_core.CliConfig {
11
+ cwd() {
12
+ return process.cwd();
13
+ }
14
+ argv() {
15
+ return Bun.argv;
16
+ }
17
+ exit(code) {
18
+ process.exit(code);
19
+ }
20
+ setExitCode(code) {
21
+ process.exitCode = code;
22
+ }
23
+ onSignal(signal, handler) {
24
+ process.on(signal, handler);
25
+ }
26
+ offSignal(signal, handler) {
27
+ process.off(signal, handler);
28
+ }
29
+ };
30
+ BunCliConfig = _ts_decorate$1([_zeltjs_core.Config], BunCliConfig);
31
+ //#endregion
32
+ //#region src/bun-env.adaptor.ts
33
+ function _ts_decorate(decorators, target, key, desc) {
34
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
36
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
37
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
38
+ }
39
+ var BunEnvAdaptor = class extends _zeltjs_core.EnvAdaptor {
40
+ get(key) {
41
+ return Bun.env[key];
42
+ }
43
+ };
44
+ BunEnvAdaptor = _ts_decorate([_zeltjs_core.Config], BunEnvAdaptor);
45
+ //#endregion
46
+ //#region src/on-bun.ts
47
+ const createServeForHttp = (appFetch, appShutdown) => {
48
+ return (options) => {
49
+ const port = options?.port ?? 3e3;
50
+ const hostname = options?.hostname ?? "0.0.0.0";
51
+ const server = Bun.serve({
52
+ fetch: appFetch,
53
+ port,
54
+ hostname
55
+ });
56
+ const shutdown = async () => {
57
+ await server.stop();
58
+ await appShutdown();
59
+ };
60
+ return {
61
+ address: {
62
+ port: server.port ?? port,
63
+ hostname: server.hostname ?? hostname
64
+ },
65
+ shutdown
66
+ };
67
+ };
68
+ };
69
+ const getArgs = () => Bun.argv.slice(2);
70
+ const createBunApp = (readyApp, shutdown, args) => {
71
+ const base = {
72
+ ...readyApp,
73
+ args,
74
+ shutdown
75
+ };
76
+ const httpCaps = readyApp.getFeatureCapabilities(_zeltjs_core.HttpFeature);
77
+ if (!httpCaps) return base;
78
+ return {
79
+ ...base,
80
+ serve: createServeForHttp(httpCaps.fetch, shutdown)
81
+ };
82
+ };
83
+ /** @throws {ZeltLifecycleStateError} */ async function onBun(app, options = {}) {
84
+ const readyApp = await app.createRuntime({
85
+ fallbackConfigs: [BunCliConfig, BunEnvAdaptor],
86
+ warmup: options.warmup ?? true
87
+ });
88
+ const cliConfig = await readyApp.get(BunCliConfig);
89
+ const runtimeShutdown = readyApp.shutdown;
90
+ let shuttingDown = false;
91
+ const detachSignals = () => {
92
+ cliConfig.offSignal("SIGINT", gracefulShutdown);
93
+ cliConfig.offSignal("SIGTERM", gracefulShutdown);
94
+ };
95
+ const shutdown = async () => {
96
+ if (shuttingDown) return;
97
+ shuttingDown = true;
98
+ try {
99
+ await runtimeShutdown();
100
+ } finally {
101
+ detachSignals();
102
+ }
103
+ };
104
+ const gracefulShutdown = () => {
105
+ shutdown().catch(() => {});
106
+ };
107
+ cliConfig.onSignal("SIGINT", gracefulShutdown);
108
+ cliConfig.onSignal("SIGTERM", gracefulShutdown);
109
+ return createBunApp(readyApp, shutdown, getArgs());
110
+ }
111
+ //#endregion
112
+ Object.defineProperty(exports, "BunCliConfig", {
113
+ enumerable: true,
114
+ get: function() {
115
+ return BunCliConfig;
116
+ }
117
+ });
118
+ Object.defineProperty(exports, "BunEnvAdaptor", {
119
+ enumerable: true,
120
+ get: function() {
121
+ return BunEnvAdaptor;
122
+ }
123
+ });
124
+ exports.onBun = onBun;
@@ -0,0 +1,57 @@
1
+ import { CliConfig, CommandCapabilities, ConfiguredFeature, EnvAdaptor, ExecResult, FeatureApp, HttpFeature, RuntimeApp, Signal, SignalHandler } from "@zeltjs/core";
2
+
3
+ //#region src/bun-cli.config.d.ts
4
+ declare class BunCliConfig extends CliConfig {
5
+ cwd(): string;
6
+ argv(): readonly string[];
7
+ exit(code: number): never;
8
+ setExitCode(code: number): void;
9
+ onSignal(signal: Signal, handler: SignalHandler): void;
10
+ offSignal(signal: Signal, handler: SignalHandler): void;
11
+ }
12
+ //#endregion
13
+ //#region src/bun-env.adaptor.d.ts
14
+ declare class BunEnvAdaptor extends EnvAdaptor {
15
+ get(key: string): string | undefined;
16
+ }
17
+ //#endregion
18
+ //#region src/on-bun.d.ts
19
+ type ServeOptions = {
20
+ readonly port?: number;
21
+ readonly hostname?: string;
22
+ };
23
+ type ServerHandle = {
24
+ readonly address: {
25
+ port: number;
26
+ hostname: string;
27
+ };
28
+ readonly shutdown: () => Promise<void>;
29
+ };
30
+ type BunAppOptions = {
31
+ readonly warmup?: boolean;
32
+ };
33
+ type BunAppBase = {
34
+ readonly get: <T extends object>(cls: new (...args: never[]) => T) => Promise<T>;
35
+ readonly args: readonly string[];
36
+ readonly shutdown: () => Promise<void>;
37
+ };
38
+ type EnvironmentBunAppPart = {
39
+ readonly args: readonly string[];
40
+ readonly shutdown: () => Promise<void>;
41
+ };
42
+ type HttpBunAppPart = {
43
+ readonly serve: (options?: ServeOptions) => ServerHandle;
44
+ };
45
+ type HttpBunApp = BunAppBase & RuntimeApp<readonly [HttpFeature]> & HttpBunAppPart;
46
+ type CommandBunApp = BunAppBase & {
47
+ readonly commands: CommandCapabilities;
48
+ };
49
+ type FullBunApp = HttpBunApp & CommandBunApp;
50
+ type BunApp = (RuntimeApp<readonly ConfiguredFeature[]> & EnvironmentBunAppPart) & Partial<HttpBunAppPart>;
51
+ type HasFeatureClass<F extends readonly ConfiguredFeature[], TFeature extends ConfiguredFeature> = Extract<F[number], TFeature> extends never ? false : true;
52
+ type WithFeatureClass<F extends readonly ConfiguredFeature[], TFeature extends ConfiguredFeature, TPart extends object> = HasFeatureClass<F, TFeature> extends true ? TPart : unknown;
53
+ type BunAppForFeatures<F extends readonly ConfiguredFeature[]> = RuntimeApp<F> & EnvironmentBunAppPart & (number extends F['length'] ? Partial<HttpBunAppPart> : WithFeatureClass<F, HttpFeature, HttpBunAppPart>);
54
+ declare function onBun<const F extends readonly ConfiguredFeature[]>(app: FeatureApp<F>, options?: BunAppOptions): Promise<BunAppForFeatures<F>>;
55
+ //#endregion
56
+ export { type BunApp, type BunAppOptions, BunCliConfig, BunEnvAdaptor, type CommandBunApp, type ExecResult, type FullBunApp, type HttpBunApp, type ServerHandle, onBun };
57
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/bun-cli.config.ts","../src/bun-env.adaptor.ts","../src/on-bun.ts"],"mappings":";;;cAIa,YAAA,SAAqB,SAAA;EACvB,GAAA,CAAA;EAIA,IAAA,CAAA;EAIA,IAAA,CAAK,IAAA;EAIL,WAAA,CAAY,IAAA;EAIZ,QAAA,CAAS,MAAA,EAAQ,MAAA,EAAQ,OAAA,EAAS,aAAA;EAIlC,SAAA,CAAU,MAAA,EAAQ,MAAA,EAAQ,OAAA,EAAS,aAAA;AAAA;;;c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C,GAAA,EAAK,UAAA,CAAW,CAAA,GAChB,OAAA,GAAU,aAAA,GACT,OAAA,CAAQ,iBAAA,CAAkB,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CliConfig, CommandCapabilities, ConfiguredFeature, EnvAdaptor, ExecResult, FeatureApp, HttpCapabilities, RuntimeApp, Signal, SignalHandler } from "@zeltjs/core";
1
+ import { CliConfig, CommandCapabilities, ConfiguredFeature, EnvAdaptor, ExecResult, FeatureApp, HttpFeature, RuntimeApp, Signal, SignalHandler } from "@zeltjs/core";
2
2
 
3
3
  //#region src/bun-cli.config.d.ts
4
4
  declare class BunCliConfig extends CliConfig {
@@ -42,17 +42,15 @@ type EnvironmentBunAppPart = {
42
42
  type HttpBunAppPart = {
43
43
  readonly serve: (options?: ServeOptions) => ServerHandle;
44
44
  };
45
- type HttpBunApp = BunAppBase & {
46
- readonly http: HttpCapabilities;
47
- } & HttpBunAppPart;
45
+ type HttpBunApp = BunAppBase & RuntimeApp<readonly [HttpFeature]> & HttpBunAppPart;
48
46
  type CommandBunApp = BunAppBase & {
49
47
  readonly commands: CommandCapabilities;
50
48
  };
51
49
  type FullBunApp = HttpBunApp & CommandBunApp;
52
50
  type BunApp = (RuntimeApp<readonly ConfiguredFeature[]> & EnvironmentBunAppPart) & Partial<HttpBunAppPart>;
53
- type FeatureKeys<F extends readonly ConfiguredFeature[]> = F[number]['key'];
54
- type WithFeature<F extends readonly ConfiguredFeature[], TKey extends string, TPart extends object> = TKey extends FeatureKeys<F> ? TPart : unknown;
55
- type BunAppForFeatures<F extends readonly ConfiguredFeature[]> = RuntimeApp<F> & EnvironmentBunAppPart & (string extends FeatureKeys<F> ? Partial<HttpBunAppPart> : WithFeature<F, 'http', HttpBunAppPart>);
51
+ type HasFeatureClass<F extends readonly ConfiguredFeature[], TFeature extends ConfiguredFeature> = Extract<F[number], TFeature> extends never ? false : true;
52
+ type WithFeatureClass<F extends readonly ConfiguredFeature[], TFeature extends ConfiguredFeature, TPart extends object> = HasFeatureClass<F, TFeature> extends true ? TPart : unknown;
53
+ type BunAppForFeatures<F extends readonly ConfiguredFeature[]> = RuntimeApp<F> & EnvironmentBunAppPart & (number extends F['length'] ? Partial<HttpBunAppPart> : WithFeatureClass<F, HttpFeature, HttpBunAppPart>);
56
54
  declare function onBun<const F extends readonly ConfiguredFeature[]>(app: FeatureApp<F>, options?: BunAppOptions): Promise<BunAppForFeatures<F>>;
57
55
  //#endregion
58
56
  export { type BunApp, type BunAppOptions, BunCliConfig, BunEnvAdaptor, type CommandBunApp, type ExecResult, type FullBunApp, type HttpBunApp, type ServerHandle, onBun };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/bun-cli.config.ts","../src/bun-env.adaptor.ts","../src/on-bun.ts"],"mappings":";;;cAIa,YAAA,SAAqB,SAAA;EACvB,GAAA,CAAA;EAIA,IAAA,CAAA;EAIA,IAAA,CAAK,IAAA;EAIL,WAAA,CAAY,IAAA;EAIZ,QAAA,CAAS,MAAA,EAAQ,MAAA,EAAQ,OAAA,EAAS,aAAA;EAIlC,SAAA,CAAU,MAAA,EAAQ,MAAA,EAAQ,OAAA,EAAS,aAAA;AAAA;;;cCtBjC,aAAA,SAAsB,UAAA;EACxB,GAAA,CAAI,GAAA;AAAA;;;KCQV,YAAA;EAAA,SACM,IAAA;EAAA,SACA,QAAA;AAAA;AAAA,KAGC,YAAA;EAAA,SACD,OAAA;IAAW,IAAA;IAAc,QAAA;EAAA;EAAA,SACzB,QAAA,QAAgB,OAAA;AAAA;AAAA,KAGf,aAAA;EAAA,SACD,MAAA;AAAA;AAAA,KAKN,UAAA;EAAA,SACM,GAAA,qBAAwB,GAAA,UAAa,IAAA,cAAkB,CAAA,KAAM,OAAA,CAAQ,CAAA;EAAA,SACrE,IAAA;EAAA,SACA,QAAA,QAAgB,OAAA;AAAA;AAAA,KAGtB,qBAAA;EAAA,SACM,IAAA;EAAA,SACA,QAAA,QAAgB,OAAA;AAA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kB,CAAA"}
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import { CliConfig, Config, EnvAdaptor } from "@zeltjs/core";
2
- import { unsafeGetNamespacedCallable } from "@zeltjs/unsafe-type-lib";
1
+ import { CliConfig, Config, EnvAdaptor, HttpFeature } from "@zeltjs/core";
3
2
  //#region src/bun-cli.config.ts
4
3
  function _ts_decorate$1(decorators, target, key, desc) {
5
4
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -68,16 +67,16 @@ const createServeForHttp = (appFetch, appShutdown) => {
68
67
  };
69
68
  const getArgs = () => Bun.argv.slice(2);
70
69
  const createBunApp = (readyApp, shutdown, args) => {
71
- const fetch = unsafeGetNamespacedCallable(readyApp, "http", "fetch");
72
70
  const base = {
73
71
  ...readyApp,
74
72
  args,
75
73
  shutdown
76
74
  };
77
- if (typeof fetch !== "function") return base;
75
+ const httpCaps = readyApp.getFeatureCapabilities(HttpFeature);
76
+ if (!httpCaps) return base;
78
77
  return {
79
78
  ...base,
80
- serve: createServeForHttp(fetch, shutdown)
79
+ serve: createServeForHttp(httpCaps.fetch, shutdown)
81
80
  };
82
81
  };
83
82
  /** @throws {ZeltLifecycleStateError} */ async function onBun(app, options = {}) {
@@ -86,6 +85,7 @@ const createBunApp = (readyApp, shutdown, args) => {
86
85
  warmup: options.warmup ?? true
87
86
  });
88
87
  const cliConfig = await readyApp.get(BunCliConfig);
88
+ const runtimeShutdown = readyApp.shutdown;
89
89
  let shuttingDown = false;
90
90
  const detachSignals = () => {
91
91
  cliConfig.offSignal("SIGINT", gracefulShutdown);
@@ -95,7 +95,7 @@ const createBunApp = (readyApp, shutdown, args) => {
95
95
  if (shuttingDown) return;
96
96
  shuttingDown = true;
97
97
  try {
98
- await readyApp.shutdown();
98
+ await runtimeShutdown();
99
99
  } finally {
100
100
  detachSignals();
101
101
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["CliConfig","Config","BunCliConfig","cwd","process","argv","Bun","exit","code","setExitCode","exitCode","onSignal","signal","handler","on","offSignal","off","Config","EnvAdaptor","BunEnvAdaptor","get","key","Bun","env","unsafeGetNamespacedCallable","BunCliConfig","BunEnvAdaptor","createServeForHttp","appFetch","appShutdown","options","port","hostname","server","Bun","serve","fetch","shutdown","stop","address","getArgs","argv","slice","createBunApp","readyApp","args","base","onBun","app","createRuntime","fallbackConfigs","warmup","cliConfig","get","shuttingDown","detachSignals","offSignal","gracefulShutdown","catch","onSignal"],"sources":["../src/bun-cli.config.ts","../src/bun-env.adaptor.ts","../src/on-bun.ts"],"sourcesContent":["import type { Signal, SignalHandler } from '@zeltjs/core';\nimport { CliConfig, Config } from '@zeltjs/core';\n\n@Config\nexport class BunCliConfig extends CliConfig {\n override cwd(): string {\n return process.cwd();\n }\n\n override argv(): readonly string[] {\n return Bun.argv;\n }\n\n override exit(code: number): never {\n process.exit(code);\n }\n\n override setExitCode(code: number): void {\n process.exitCode = code;\n }\n\n override onSignal(signal: Signal, handler: SignalHandler): void {\n process.on(signal, handler);\n }\n\n override offSignal(signal: Signal, handler: SignalHandler): void {\n process.off(signal, handler);\n }\n}\n","import { Config, EnvAdaptor } from '@zeltjs/core';\n\n@Config\nexport class BunEnvAdaptor extends EnvAdaptor {\n override get(key: string): string | undefined {\n return Bun.env[key];\n }\n}\n","import type {\n CommandCapabilities,\n ConfiguredFeature,\n FeatureApp,\n HttpCapabilities,\n RuntimeApp,\n} from '@zeltjs/core';\nimport { unsafeGetNamespacedCallable } from '@zeltjs/unsafe-type-lib';\n\nimport { BunCliConfig } from './bun-cli.config';\nimport { BunEnvAdaptor } from './bun-env.adaptor';\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 get: <T extends object>(cls: new (...args: never[]) => T) => Promise<T>;\n readonly args: readonly string[];\n readonly shutdown: () => Promise<void>;\n};\n\ntype EnvironmentBunAppPart = {\n readonly args: readonly string[];\n readonly shutdown: () => Promise<void>;\n};\n\ntype HttpBunAppPart = {\n readonly serve: (options?: ServeOptions) => ServerHandle;\n};\n\nexport type HttpBunApp = BunAppBase & { readonly http: HttpCapabilities } & HttpBunAppPart;\n\nexport type CommandBunApp = BunAppBase & { readonly commands: CommandCapabilities };\n\nexport type FullBunApp = HttpBunApp & CommandBunApp;\n\nexport type BunApp = (RuntimeApp<readonly ConfiguredFeature[]> & EnvironmentBunAppPart) &\n Partial<HttpBunAppPart>;\n\ntype FeatureKeys<F extends readonly ConfiguredFeature[]> = F[number]['key'];\n\ntype WithFeature<\n F extends readonly ConfiguredFeature[],\n TKey extends string,\n TPart extends object,\n> = TKey extends FeatureKeys<F> ? TPart : unknown;\n\ntype BunAppForFeatures<F extends readonly ConfiguredFeature[]> = RuntimeApp<F> &\n EnvironmentBunAppPart &\n (string extends FeatureKeys<F>\n ? Partial<HttpBunAppPart>\n : WithFeature<F, 'http', HttpBunAppPart>);\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 getArgs = (): readonly string[] => Bun.argv.slice(2);\n\nconst createBunApp = (\n readyApp: RuntimeApp<readonly ConfiguredFeature[]>,\n shutdown: () => Promise<void>,\n args: readonly string[],\n): BunApp => {\n const fetch = unsafeGetNamespacedCallable<HttpCapabilities['fetch']>(readyApp, 'http', 'fetch');\n const base: RuntimeApp<readonly ConfiguredFeature[]> & EnvironmentBunAppPart = {\n ...readyApp,\n args,\n shutdown,\n };\n\n if (typeof fetch !== 'function') return base;\n return { ...base, serve: createServeForHttp(fetch, shutdown) };\n};\n\nexport function onBun<const F extends readonly ConfiguredFeature[]>(\n app: FeatureApp<F>,\n options?: BunAppOptions,\n): Promise<BunAppForFeatures<F>>;\n\n/** @throws {ZeltLifecycleStateError} */\nexport async function onBun(\n app: FeatureApp<readonly ConfiguredFeature[]>,\n options: BunAppOptions = {},\n): Promise<BunApp> {\n const readyApp = await app.createRuntime({\n fallbackConfigs: [BunCliConfig, BunEnvAdaptor],\n warmup: options.warmup ?? true,\n });\n\n const cliConfig = await readyApp.get(BunCliConfig);\n\n let shuttingDown = false;\n const detachSignals = (): void => {\n cliConfig.offSignal('SIGINT', gracefulShutdown);\n cliConfig.offSignal('SIGTERM', gracefulShutdown);\n };\n\n const shutdown = async (): Promise<void> => {\n if (shuttingDown) return;\n shuttingDown = true;\n try {\n await readyApp.shutdown();\n } finally {\n detachSignals();\n }\n };\n\n const gracefulShutdown = (): void => {\n void shutdown().catch(() => {});\n };\n\n cliConfig.onSignal('SIGINT', gracefulShutdown);\n cliConfig.onSignal('SIGTERM', gracefulShutdown);\n\n const args = getArgs();\n\n return createBunApp(readyApp, shutdown, args);\n}\n"],"mappings":";;;;;;;;;AAIA,IAAaE,eAAb,cAAkCF,UAAAA;CACvBG,MAAc;AACrB,SAAOC,QAAQD,KAAG;;CAGXE,OAA0B;AACjC,SAAOC,IAAID;;CAGJE,KAAKC,MAAqB;AACjCJ,UAAQG,KAAKC,KAAAA;;CAGNC,YAAYD,MAAoB;AACvCJ,UAAQM,WAAWF;;CAGZG,SAASC,QAAgBC,SAA8B;AAC9DT,UAAQU,GAAGF,QAAQC,QAAAA;;CAGZE,UAAUH,QAAgBC,SAA8B;AAC/DT,UAAQY,IAAIJ,QAAQC,QAAAA;;;;;;;;;;;;AC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AAME,yBAAmB;AAClBpB,YAAAA,CAAWqB,YAAM,GAAO;;AAG/BN,WAAUO,SAAS,UAAUF,iBAAAA;AAC7BL,WAAUO,SAAS,WAAWF,iBAAAA;AAI9B,QAAOd,aAAaC,UAAUP,UAFjBG,SAE2BK,CAAAA"}
1
+ {"version":3,"file":"index.js","names":["CliConfig","Config","BunCliConfig","cwd","process","argv","Bun","exit","code","setExitCode","exitCode","onSignal","signal","handler","on","offSignal","off","Config","EnvAdaptor","BunEnvAdaptor","get","key","Bun","env","HttpFeature","BunCliConfig","BunEnvAdaptor","createServeForHttp","appFetch","appShutdown","options","port","hostname","server","Bun","serve","fetch","shutdown","stop","address","getArgs","argv","slice","createBunApp","readyApp","args","base","httpCaps","getFeatureCapabilities","onBun","app","createRuntime","fallbackConfigs","warmup","cliConfig","get","runtimeShutdown","shuttingDown","detachSignals","offSignal","gracefulShutdown","catch","onSignal"],"sources":["../src/bun-cli.config.ts","../src/bun-env.adaptor.ts","../src/on-bun.ts"],"sourcesContent":["import type { Signal, SignalHandler } from '@zeltjs/core';\nimport { CliConfig, Config } from '@zeltjs/core';\n\n@Config\nexport class BunCliConfig extends CliConfig {\n override cwd(): string {\n return process.cwd();\n }\n\n override argv(): readonly string[] {\n return Bun.argv;\n }\n\n override exit(code: number): never {\n process.exit(code);\n }\n\n override setExitCode(code: number): void {\n process.exitCode = code;\n }\n\n override onSignal(signal: Signal, handler: SignalHandler): void {\n process.on(signal, handler);\n }\n\n override offSignal(signal: Signal, handler: SignalHandler): void {\n process.off(signal, handler);\n }\n}\n","import { Config, EnvAdaptor } from '@zeltjs/core';\n\n@Config\nexport class BunEnvAdaptor extends EnvAdaptor {\n override get(key: string): string | undefined {\n return Bun.env[key];\n }\n}\n","import type { CommandCapabilities, ConfiguredFeature, FeatureApp, RuntimeApp } from '@zeltjs/core';\nimport { HttpFeature } from '@zeltjs/core';\n\nimport { BunCliConfig } from './bun-cli.config';\nimport { BunEnvAdaptor } from './bun-env.adaptor';\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 get: <T extends object>(cls: new (...args: never[]) => T) => Promise<T>;\n readonly args: readonly string[];\n readonly shutdown: () => Promise<void>;\n};\n\ntype EnvironmentBunAppPart = {\n readonly args: readonly string[];\n readonly shutdown: () => Promise<void>;\n};\n\ntype HttpBunAppPart = {\n readonly serve: (options?: ServeOptions) => ServerHandle;\n};\n\nexport type HttpBunApp = BunAppBase & RuntimeApp<readonly [HttpFeature]> & HttpBunAppPart;\n\nexport type CommandBunApp = BunAppBase & { readonly commands: CommandCapabilities };\n\nexport type FullBunApp = HttpBunApp & CommandBunApp;\n\nexport type BunApp = (RuntimeApp<readonly ConfiguredFeature[]> & EnvironmentBunAppPart) &\n Partial<HttpBunAppPart>;\n\ntype HasFeatureClass<F extends readonly ConfiguredFeature[], TFeature extends ConfiguredFeature> =\n Extract<F[number], TFeature> extends never ? false : true;\n\ntype WithFeatureClass<\n F extends readonly ConfiguredFeature[],\n TFeature extends ConfiguredFeature,\n TPart extends object,\n> = HasFeatureClass<F, TFeature> extends true ? TPart : unknown;\n\ntype BunAppForFeatures<F extends readonly ConfiguredFeature[]> = RuntimeApp<F> &\n EnvironmentBunAppPart &\n (number extends F['length']\n ? Partial<HttpBunAppPart>\n : WithFeatureClass<F, HttpFeature, HttpBunAppPart>);\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 getArgs = (): readonly string[] => Bun.argv.slice(2);\n\nconst createBunApp = (\n readyApp: RuntimeApp<readonly ConfiguredFeature[]>,\n shutdown: () => Promise<void>,\n args: readonly string[],\n): BunApp => {\n const base: RuntimeApp<readonly ConfiguredFeature[]> & EnvironmentBunAppPart = {\n ...readyApp,\n args,\n shutdown,\n };\n\n const httpCaps = readyApp.getFeatureCapabilities(HttpFeature);\n if (!httpCaps) return base;\n return {\n ...base,\n serve: createServeForHttp(httpCaps.fetch, shutdown),\n };\n};\n\nexport function onBun<const F extends readonly ConfiguredFeature[]>(\n app: FeatureApp<F>,\n options?: BunAppOptions,\n): Promise<BunAppForFeatures<F>>;\n\n/** @throws {ZeltLifecycleStateError} */\nexport async function onBun<const F extends readonly ConfiguredFeature[]>(\n app: FeatureApp<F>,\n options: BunAppOptions = {},\n): Promise<BunApp> {\n const readyApp = await app.createRuntime({\n fallbackConfigs: [BunCliConfig, BunEnvAdaptor],\n warmup: options.warmup ?? true,\n });\n\n const cliConfig = await readyApp.get(BunCliConfig);\n const runtimeShutdown = readyApp.shutdown;\n\n let shuttingDown = false;\n const detachSignals = (): void => {\n cliConfig.offSignal('SIGINT', gracefulShutdown);\n cliConfig.offSignal('SIGTERM', gracefulShutdown);\n };\n\n const shutdown = async (): Promise<void> => {\n if (shuttingDown) return;\n shuttingDown = true;\n try {\n await runtimeShutdown();\n } finally {\n detachSignals();\n }\n };\n\n const gracefulShutdown = (): void => {\n void shutdown().catch(() => {});\n };\n\n cliConfig.onSignal('SIGINT', gracefulShutdown);\n cliConfig.onSignal('SIGTERM', gracefulShutdown);\n\n const args = getArgs();\n\n return createBunApp(readyApp, shutdown, args);\n}\n"],"mappings":";;;;;;;;AAIA,IAAaE,eAAb,cAAkCF,UAAAA;CACvBG,MAAc;AACrB,SAAOC,QAAQD,KAAG;;CAGXE,OAA0B;AACjC,SAA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aAAAA;CACrC,MAAM+B,kBAAkBZ,SAASP;CAEjC,IAAIoB,eAAe;CACnB,MAAMC,sBAAgB;AACpBJ,YAAUK,UAAU,UAAUC,iBAAAA;AAC9BN,YAAUK,UAAU,WAAWC,iBAAAA;;CAGjC,MAAMvB,WAAW,YAAA;AACf,MAAIoB,aAAc;AAClBA,iBAAe;AACf,MAAI;AACF,SAAMD,iBAAAA;YACE;AACRE,kBAAAA;;;CAIJ,MAAME,yBAAmB;AAClBvB,YAAAA,CAAWwB,YAAM,GAAO;;AAG/BP,WAAUQ,SAAS,UAAUF,iBAAAA;AAC7BN,WAAUQ,SAAS,WAAWF,iBAAAA;AAI9B,QAAOjB,aAAaC,UAAUP,UAFjBG,SAE2BK,CAAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeltjs/adapter-bun",
3
- "version": "0.8.2-canary.0",
3
+ "version": "0.8.2-canary.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -13,23 +13,30 @@
13
13
  },
14
14
  "exports": {
15
15
  ".": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
16
+ "import": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "require": {
21
+ "types": "./dist/index.d.cts",
22
+ "default": "./dist/index.cjs"
23
+ }
18
24
  }
19
25
  },
20
26
  "files": [
21
27
  "dist"
22
28
  ],
23
- "dependencies": {
24
- "@zeltjs/core": "0.8.2-canary.0",
25
- "@zeltjs/unsafe-type-lib": "0.8.2-canary.0"
29
+ "peerDependencies": {
30
+ "@zeltjs/core": "0.8.2-canary.2"
26
31
  },
27
32
  "devDependencies": {
28
- "@types/bun": "1.2.17"
33
+ "@types/bun": "1.2.17",
34
+ "@zeltjs/core": "0.8.2-canary.2"
29
35
  },
30
36
  "volta": {
31
37
  "extends": "../../package.json"
32
38
  },
39
+ "main": "./dist/index.cjs",
33
40
  "scripts": {
34
41
  "build": "tsdown",
35
42
  "test": "vitest run",