@aromix/core 0.0.0 → 0.1.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.cts CHANGED
@@ -1,15 +1,13 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
3
  type Platform = "node" | "bun" | "cloudflare:worker";
4
- type Format = "esm" | "cjs";
5
4
  interface AromixBuildConfig {
6
5
  entry: string;
7
6
  outDir: string;
8
7
  platform: Platform;
9
- format: Format;
10
- tsconfig: string;
11
8
  sourcemap: boolean;
12
9
  minify: boolean;
10
+ tsConfig: string;
13
11
  }
14
12
  /** Identity fn :: exists purely for autocomplete and type safety */
15
13
  declare function build(options: AromixBuildConfig): AromixBuildConfig;
@@ -35,6 +33,9 @@ interface SocketCtx<Receive extends EventMap, Send extends EventMap> extends Bas
35
33
  }
36
34
  type EventMap = Record<string, unknown>;
37
35
 
36
+ declare class Builder {
37
+ }
38
+
38
39
  interface Entity {
39
40
  }
40
41
  declare function entity(options: Entity): void;
@@ -48,187 +49,15 @@ declare const Codec: {
48
49
 
49
50
  declare function toFetchHandler(): void;
50
51
 
51
- type RequestHook = (ctx: BaseCtx) => Response | void | Promise<Response | void>;
52
- type ResponseHook = (ctx: BaseCtx, res: Response) => Response | void | Promise<Response | void>;
53
- type ErrorHook = (err: unknown, ctx: BaseCtx) => Response | void | Promise<Response | void>;
54
- type Hook = {
55
- on: "Ready";
56
- run: (config: Config) => void | Promise<void>;
57
- } | {
58
- on: "Close";
59
- run: (config: Config) => void | Promise<void>;
60
- } | {
61
- on: "Request";
62
- run: RequestHook;
63
- } | {
64
- on: "Response";
65
- run: ResponseHook;
66
- } | {
67
- on: "Error";
68
- run: ErrorHook;
69
- };
70
-
71
- declare function hook<T extends Hook["on"]>(on: T, run: Extract<Hook, {
72
- on: T;
73
- }>["run"]): Extract<Hook, {
74
- on: T;
75
- }>;
76
-
77
- /**
78
- * load() — cross-runtime glob file resolver with tsconfig path alias support.
79
- *
80
- * Returns resolved absolute file paths. Does NOT import — caller drives imports.
81
- *
82
- * Supported glob features:
83
- * * — matches any segment (not path separators)
84
- * ** — matches any depth (where supported by runtime FS walk)
85
- * {a,b} — brace expansion
86
- * @alias — tsconfig `paths` aliases
87
- *
88
- * Runtimes: Node.js, Bun, Deno, Cloudflare Workers (Workers: alias-only, no FS)
89
- *
90
- * Usage:
91
- * const paths = load('@config/*')
92
- * const paths = load(['@entity/*.entity.{ts,js}', './app/users/*.ts'])
93
- *
94
- * make({ entity: load('@entity/*') })
95
- * async function make(pathMap: Record<string, string[]>) {
96
- * for (const [key, paths] of Object.entries(pathMap)) {
97
- * for (const p of paths) {
98
- * const mod = await import(p)
99
- * // ...
100
- * }
101
- * }
102
- * }
103
- */
104
- type GlobPattern = string | string[];
105
- interface LoadOptions {
106
- /** Working directory for relative patterns. Defaults to process.cwd() / Deno.cwd(). */
107
- cwd?: string;
108
- /** Path to tsconfig.json. Auto-discovered from cwd upward if not provided. */
109
- tsconfig?: string;
110
- /** Include dotfiles. Default: false. */
111
- dot?: boolean;
112
- /** Only return files (not directories). Default: true. */
113
- filesOnly?: boolean;
114
- }
115
- /**
116
- * Resolves a glob pattern (or array of patterns) to absolute file paths.
117
- * Supports tsconfig path aliases, `*` globs, and `{a,b}` brace expansion.
118
- *
119
- * @example
120
- * const paths = load('@entity\/*.entity.{ts,js}')
121
- * const paths = load(['@config\/*', './extra\/*.ts'])
122
- */
123
- declare function load(pattern: GlobPattern, options?: LoadOptions): string[];
124
- declare function clearCache(): void;
125
-
126
52
  declare function make(): void;
127
53
 
128
- declare function filter<T extends Hook["on"]>(hooks: Hook[], on: T): Extract<Hook, {
129
- on: T;
130
- }>["run"][];
131
-
132
54
  declare function plugin(): void;
133
55
 
134
- declare const programMeta: unique symbol;
135
- type ProgramMeta = typeof programMeta;
136
- interface CommandOptions<Input, Output, Deps> {
137
- name: string;
138
- input?: StandardSchemaV1<Input>;
139
- output?: StandardSchemaV1<Output>;
140
- hooks?: Hook[];
141
- run(input: Input, deps: Deps): Output | Promise<Output>;
142
- }
143
- interface Stream<Events> {
144
- emit<E extends keyof Events>(event: E, data: Events[E]): void;
145
- /**
146
- * Closes the stream.
147
- */
148
- close(): void;
149
- }
150
- interface StreamOptions<Input, Events, Deps> {
151
- name: string;
152
- input?: StandardSchemaV1<Input>;
153
- events?: StandardSchemaV1<Events>;
154
- hooks?: Hook[];
155
- run(input: Input, stream: Stream<Events>, deps: Deps): void | Promise<void>;
156
- }
157
- interface Socket<Receive, Send> {
158
- on<E extends keyof Receive>(event: E, handler: (data: Receive[E]) => void | Promise<void>): void;
159
- emit<E extends keyof Send>(event: E, data: Send[E]): void;
160
- /**
161
- * Closes the socket.
162
- */
163
- close(): void;
164
- }
165
- interface SocketOptions<Receive, Send, Deps> {
166
- name: string;
167
- receive?: StandardSchemaV1<Receive>;
168
- send?: StandardSchemaV1<Send>;
169
- hooks?: Hook[];
170
- run(socket: Socket<Receive, Send>, deps: Deps): void | Promise<void>;
171
- }
172
- type Route = {
173
- type: "command";
174
- options: CommandOptions<any, any, any>;
175
- } | {
176
- type: "stream";
177
- options: StreamOptions<any, any, any>;
178
- } | {
179
- type: "socket";
180
- options: SocketOptions<any, any, any>;
181
- };
182
- interface ProgramConfig<Deps> {
183
- name: string;
184
- deps?: Deps;
185
- hooks?: Hook[];
186
- }
187
- interface Program<Deps = any> {
188
- [programMeta]: {
189
- name: string;
190
- deps: Deps;
191
- hooks: Hook[];
192
- routes: Route[];
193
- };
194
- command<Input = any, Output = any>(options: CommandOptions<Input, Output, Deps>): void;
195
- stream<Input = any, Events = any>(options: StreamOptions<Input, Events, Deps>): void;
196
- socket<Receive = any, Send = any>(options: SocketOptions<Receive, Send, Deps>): void;
197
- }
198
-
199
- /**
200
- * Creates a new Aromix Program.
201
- * Programs group commands, streams, and sockets under a common namespace
202
- * and share dependencies and hooks.
203
- */
204
- declare function program<Deps>(config: ProgramConfig<Deps>): Program<Deps>;
205
-
206
- /**
207
- * Creates a destructurable facade object for a service instance.
208
- * Methods are bound to the instance, and properties are proxied via getters/setters.
209
- */
210
- declare function createFacadeObj<T extends object>(serviceInstance: any): T;
211
-
212
- type ServiceConstructor<T> = new (...args: any[]) => T;
213
- interface Setup {
214
- setup(): void | Promise<void>;
215
- }
216
- interface Teardown {
217
- teardown(): void | Promise<void>;
218
- }
219
- interface Lifecycle extends Setup, Teardown {
220
- }
221
- /**
222
- * Marks a class as an injectable service.
223
- */
224
- declare function provide(): ClassDecorator;
225
- /**
226
- * Resolves a service singleton instance.
227
- * Throws if the class is not decorated with @provide().
228
- */
229
- declare function inject<T>(Service: ServiceConstructor<T>): T;
230
- declare namespace inject {
231
- var facade: <T extends object>(Service: ServiceConstructor<T>) => T;
56
+ declare global {
57
+ namespace Aromix {
58
+ type GlobPattern = string | string[];
59
+ function load(pattern: GlobPattern): string[];
60
+ }
232
61
  }
233
62
 
234
- export { type AromixBuildConfig, type BaseCtx, Codec, type CommandCtx, type CommandOptions, type Config, type ErrorHook, type EventMap, type Format, type GlobPattern, type Hook, type Lifecycle, type LoadOptions, type Platform, type Program, type ProgramConfig, type ProgramMeta, type RequestHook, type ResponseHook, type Route, type ServiceConstructor, type Setup, type Socket, type SocketCtx, type SocketOptions, type Stream, type StreamCtx, type StreamOptions, type Teardown, build, clearCache, config, createFacadeObj, entity, filter, hook, inject, load, make, plugin, program, programMeta, provide, toFetchHandler };
63
+ export { type AromixBuildConfig, type BaseCtx, Builder, Codec, type CommandCtx, type Config, type EventMap, type Platform, type SocketCtx, type StreamCtx, build, config, entity, make, plugin, toFetchHandler };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
3
  type Platform = "node" | "bun" | "cloudflare:worker";
4
- type Format = "esm" | "cjs";
5
4
  interface AromixBuildConfig {
6
5
  entry: string;
7
6
  outDir: string;
8
7
  platform: Platform;
9
- format: Format;
10
- tsconfig: string;
11
8
  sourcemap: boolean;
12
9
  minify: boolean;
10
+ tsConfig: string;
13
11
  }
14
12
  /** Identity fn :: exists purely for autocomplete and type safety */
15
13
  declare function build(options: AromixBuildConfig): AromixBuildConfig;
@@ -35,6 +33,9 @@ interface SocketCtx<Receive extends EventMap, Send extends EventMap> extends Bas
35
33
  }
36
34
  type EventMap = Record<string, unknown>;
37
35
 
36
+ declare class Builder {
37
+ }
38
+
38
39
  interface Entity {
39
40
  }
40
41
  declare function entity(options: Entity): void;
@@ -48,187 +49,15 @@ declare const Codec: {
48
49
 
49
50
  declare function toFetchHandler(): void;
50
51
 
51
- type RequestHook = (ctx: BaseCtx) => Response | void | Promise<Response | void>;
52
- type ResponseHook = (ctx: BaseCtx, res: Response) => Response | void | Promise<Response | void>;
53
- type ErrorHook = (err: unknown, ctx: BaseCtx) => Response | void | Promise<Response | void>;
54
- type Hook = {
55
- on: "Ready";
56
- run: (config: Config) => void | Promise<void>;
57
- } | {
58
- on: "Close";
59
- run: (config: Config) => void | Promise<void>;
60
- } | {
61
- on: "Request";
62
- run: RequestHook;
63
- } | {
64
- on: "Response";
65
- run: ResponseHook;
66
- } | {
67
- on: "Error";
68
- run: ErrorHook;
69
- };
70
-
71
- declare function hook<T extends Hook["on"]>(on: T, run: Extract<Hook, {
72
- on: T;
73
- }>["run"]): Extract<Hook, {
74
- on: T;
75
- }>;
76
-
77
- /**
78
- * load() — cross-runtime glob file resolver with tsconfig path alias support.
79
- *
80
- * Returns resolved absolute file paths. Does NOT import — caller drives imports.
81
- *
82
- * Supported glob features:
83
- * * — matches any segment (not path separators)
84
- * ** — matches any depth (where supported by runtime FS walk)
85
- * {a,b} — brace expansion
86
- * @alias — tsconfig `paths` aliases
87
- *
88
- * Runtimes: Node.js, Bun, Deno, Cloudflare Workers (Workers: alias-only, no FS)
89
- *
90
- * Usage:
91
- * const paths = load('@config/*')
92
- * const paths = load(['@entity/*.entity.{ts,js}', './app/users/*.ts'])
93
- *
94
- * make({ entity: load('@entity/*') })
95
- * async function make(pathMap: Record<string, string[]>) {
96
- * for (const [key, paths] of Object.entries(pathMap)) {
97
- * for (const p of paths) {
98
- * const mod = await import(p)
99
- * // ...
100
- * }
101
- * }
102
- * }
103
- */
104
- type GlobPattern = string | string[];
105
- interface LoadOptions {
106
- /** Working directory for relative patterns. Defaults to process.cwd() / Deno.cwd(). */
107
- cwd?: string;
108
- /** Path to tsconfig.json. Auto-discovered from cwd upward if not provided. */
109
- tsconfig?: string;
110
- /** Include dotfiles. Default: false. */
111
- dot?: boolean;
112
- /** Only return files (not directories). Default: true. */
113
- filesOnly?: boolean;
114
- }
115
- /**
116
- * Resolves a glob pattern (or array of patterns) to absolute file paths.
117
- * Supports tsconfig path aliases, `*` globs, and `{a,b}` brace expansion.
118
- *
119
- * @example
120
- * const paths = load('@entity\/*.entity.{ts,js}')
121
- * const paths = load(['@config\/*', './extra\/*.ts'])
122
- */
123
- declare function load(pattern: GlobPattern, options?: LoadOptions): string[];
124
- declare function clearCache(): void;
125
-
126
52
  declare function make(): void;
127
53
 
128
- declare function filter<T extends Hook["on"]>(hooks: Hook[], on: T): Extract<Hook, {
129
- on: T;
130
- }>["run"][];
131
-
132
54
  declare function plugin(): void;
133
55
 
134
- declare const programMeta: unique symbol;
135
- type ProgramMeta = typeof programMeta;
136
- interface CommandOptions<Input, Output, Deps> {
137
- name: string;
138
- input?: StandardSchemaV1<Input>;
139
- output?: StandardSchemaV1<Output>;
140
- hooks?: Hook[];
141
- run(input: Input, deps: Deps): Output | Promise<Output>;
142
- }
143
- interface Stream<Events> {
144
- emit<E extends keyof Events>(event: E, data: Events[E]): void;
145
- /**
146
- * Closes the stream.
147
- */
148
- close(): void;
149
- }
150
- interface StreamOptions<Input, Events, Deps> {
151
- name: string;
152
- input?: StandardSchemaV1<Input>;
153
- events?: StandardSchemaV1<Events>;
154
- hooks?: Hook[];
155
- run(input: Input, stream: Stream<Events>, deps: Deps): void | Promise<void>;
156
- }
157
- interface Socket<Receive, Send> {
158
- on<E extends keyof Receive>(event: E, handler: (data: Receive[E]) => void | Promise<void>): void;
159
- emit<E extends keyof Send>(event: E, data: Send[E]): void;
160
- /**
161
- * Closes the socket.
162
- */
163
- close(): void;
164
- }
165
- interface SocketOptions<Receive, Send, Deps> {
166
- name: string;
167
- receive?: StandardSchemaV1<Receive>;
168
- send?: StandardSchemaV1<Send>;
169
- hooks?: Hook[];
170
- run(socket: Socket<Receive, Send>, deps: Deps): void | Promise<void>;
171
- }
172
- type Route = {
173
- type: "command";
174
- options: CommandOptions<any, any, any>;
175
- } | {
176
- type: "stream";
177
- options: StreamOptions<any, any, any>;
178
- } | {
179
- type: "socket";
180
- options: SocketOptions<any, any, any>;
181
- };
182
- interface ProgramConfig<Deps> {
183
- name: string;
184
- deps?: Deps;
185
- hooks?: Hook[];
186
- }
187
- interface Program<Deps = any> {
188
- [programMeta]: {
189
- name: string;
190
- deps: Deps;
191
- hooks: Hook[];
192
- routes: Route[];
193
- };
194
- command<Input = any, Output = any>(options: CommandOptions<Input, Output, Deps>): void;
195
- stream<Input = any, Events = any>(options: StreamOptions<Input, Events, Deps>): void;
196
- socket<Receive = any, Send = any>(options: SocketOptions<Receive, Send, Deps>): void;
197
- }
198
-
199
- /**
200
- * Creates a new Aromix Program.
201
- * Programs group commands, streams, and sockets under a common namespace
202
- * and share dependencies and hooks.
203
- */
204
- declare function program<Deps>(config: ProgramConfig<Deps>): Program<Deps>;
205
-
206
- /**
207
- * Creates a destructurable facade object for a service instance.
208
- * Methods are bound to the instance, and properties are proxied via getters/setters.
209
- */
210
- declare function createFacadeObj<T extends object>(serviceInstance: any): T;
211
-
212
- type ServiceConstructor<T> = new (...args: any[]) => T;
213
- interface Setup {
214
- setup(): void | Promise<void>;
215
- }
216
- interface Teardown {
217
- teardown(): void | Promise<void>;
218
- }
219
- interface Lifecycle extends Setup, Teardown {
220
- }
221
- /**
222
- * Marks a class as an injectable service.
223
- */
224
- declare function provide(): ClassDecorator;
225
- /**
226
- * Resolves a service singleton instance.
227
- * Throws if the class is not decorated with @provide().
228
- */
229
- declare function inject<T>(Service: ServiceConstructor<T>): T;
230
- declare namespace inject {
231
- var facade: <T extends object>(Service: ServiceConstructor<T>) => T;
56
+ declare global {
57
+ namespace Aromix {
58
+ type GlobPattern = string | string[];
59
+ function load(pattern: GlobPattern): string[];
60
+ }
232
61
  }
233
62
 
234
- export { type AromixBuildConfig, type BaseCtx, Codec, type CommandCtx, type CommandOptions, type Config, type ErrorHook, type EventMap, type Format, type GlobPattern, type Hook, type Lifecycle, type LoadOptions, type Platform, type Program, type ProgramConfig, type ProgramMeta, type RequestHook, type ResponseHook, type Route, type ServiceConstructor, type Setup, type Socket, type SocketCtx, type SocketOptions, type Stream, type StreamCtx, type StreamOptions, type Teardown, build, clearCache, config, createFacadeObj, entity, filter, hook, inject, load, make, plugin, program, programMeta, provide, toFetchHandler };
63
+ export { type AromixBuildConfig, type BaseCtx, Builder, Codec, type CommandCtx, type Config, type EventMap, type Platform, type SocketCtx, type StreamCtx, build, config, entity, make, plugin, toFetchHandler };