@aromix/core 0.0.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.
@@ -0,0 +1,234 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+
3
+ type Platform = "node" | "bun" | "cloudflare:worker";
4
+ type Format = "esm" | "cjs";
5
+ interface AromixBuildConfig {
6
+ entry: string;
7
+ outDir: string;
8
+ platform: Platform;
9
+ format: Format;
10
+ tsconfig: string;
11
+ sourcemap: boolean;
12
+ minify: boolean;
13
+ }
14
+ /** Identity fn :: exists purely for autocomplete and type safety */
15
+ declare function build(options: AromixBuildConfig): AromixBuildConfig;
16
+
17
+ interface Config {
18
+ }
19
+ declare function config<T extends Config>(config: T | (() => T)): T;
20
+
21
+ interface BaseCtx {
22
+ id: string;
23
+ payload: unknown;
24
+ args<T>(schema: StandardSchemaV1<T>): T;
25
+ }
26
+ interface CommandCtx extends BaseCtx {
27
+ }
28
+ interface StreamCtx extends BaseCtx {
29
+ }
30
+ interface SocketCtx<Receive extends EventMap, Send extends EventMap> extends BaseCtx {
31
+ on<E extends keyof Receive>(event: E, handler: (data: Receive[E]) => void | Promise<void>): void;
32
+ send<E extends keyof Send>(event: E, data: Send[E]): void;
33
+ onClose(handler: () => void): void;
34
+ close(): void;
35
+ }
36
+ type EventMap = Record<string, unknown>;
37
+
38
+ interface Entity {
39
+ }
40
+ declare function entity(options: Entity): void;
41
+
42
+ declare const Codec: {
43
+ encode(data: unknown): Uint8Array;
44
+ decode(buf: Uint8Array): unknown;
45
+ fromRequest(req: Request): Promise<unknown>;
46
+ response(data: unknown): Response;
47
+ };
48
+
49
+ declare function toFetchHandler(): void;
50
+
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
+ declare function make(): void;
127
+
128
+ declare function filter<T extends Hook["on"]>(hooks: Hook[], on: T): Extract<Hook, {
129
+ on: T;
130
+ }>["run"][];
131
+
132
+ declare function plugin(): void;
133
+
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;
232
+ }
233
+
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 };
@@ -0,0 +1,234 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+
3
+ type Platform = "node" | "bun" | "cloudflare:worker";
4
+ type Format = "esm" | "cjs";
5
+ interface AromixBuildConfig {
6
+ entry: string;
7
+ outDir: string;
8
+ platform: Platform;
9
+ format: Format;
10
+ tsconfig: string;
11
+ sourcemap: boolean;
12
+ minify: boolean;
13
+ }
14
+ /** Identity fn :: exists purely for autocomplete and type safety */
15
+ declare function build(options: AromixBuildConfig): AromixBuildConfig;
16
+
17
+ interface Config {
18
+ }
19
+ declare function config<T extends Config>(config: T | (() => T)): T;
20
+
21
+ interface BaseCtx {
22
+ id: string;
23
+ payload: unknown;
24
+ args<T>(schema: StandardSchemaV1<T>): T;
25
+ }
26
+ interface CommandCtx extends BaseCtx {
27
+ }
28
+ interface StreamCtx extends BaseCtx {
29
+ }
30
+ interface SocketCtx<Receive extends EventMap, Send extends EventMap> extends BaseCtx {
31
+ on<E extends keyof Receive>(event: E, handler: (data: Receive[E]) => void | Promise<void>): void;
32
+ send<E extends keyof Send>(event: E, data: Send[E]): void;
33
+ onClose(handler: () => void): void;
34
+ close(): void;
35
+ }
36
+ type EventMap = Record<string, unknown>;
37
+
38
+ interface Entity {
39
+ }
40
+ declare function entity(options: Entity): void;
41
+
42
+ declare const Codec: {
43
+ encode(data: unknown): Uint8Array;
44
+ decode(buf: Uint8Array): unknown;
45
+ fromRequest(req: Request): Promise<unknown>;
46
+ response(data: unknown): Response;
47
+ };
48
+
49
+ declare function toFetchHandler(): void;
50
+
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
+ declare function make(): void;
127
+
128
+ declare function filter<T extends Hook["on"]>(hooks: Hook[], on: T): Extract<Hook, {
129
+ on: T;
130
+ }>["run"][];
131
+
132
+ declare function plugin(): void;
133
+
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;
232
+ }
233
+
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 };