@moriajs/core 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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/LICENSE +21 -0
- package/dist/app.d.ts +42 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +65 -0
- package/dist/app.js.map +1 -0
- package/dist/config.d.ts +61 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +18 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins.d.ts +38 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +19 -0
- package/dist/plugins.js.map +1 -0
- package/package.json +48 -0
- package/src/app.ts +103 -0
- package/src/config.ts +66 -0
- package/src/index.ts +14 -0
- package/src/plugins.ts +42 -0
- package/tsconfig.json +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Guntur D
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type FastifyInstance, type FastifyServerOptions } from 'fastify';
|
|
2
|
+
import { type MoriaConfig } from './config.js';
|
|
3
|
+
import { type MoriaPlugin } from './plugins.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options for creating a MoriaJS application.
|
|
6
|
+
*/
|
|
7
|
+
export interface MoriaAppOptions {
|
|
8
|
+
/** MoriaJS configuration (from moria.config.ts) */
|
|
9
|
+
config?: Partial<MoriaConfig>;
|
|
10
|
+
/** Additional Fastify server options */
|
|
11
|
+
fastifyOptions?: FastifyServerOptions;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The MoriaJS application instance.
|
|
15
|
+
* Wraps a Fastify instance with framework-level features.
|
|
16
|
+
*/
|
|
17
|
+
export interface MoriaApp {
|
|
18
|
+
/** The underlying Fastify instance */
|
|
19
|
+
server: FastifyInstance;
|
|
20
|
+
/** Register a MoriaJS plugin */
|
|
21
|
+
use: (plugin: MoriaPlugin) => Promise<void>;
|
|
22
|
+
/** Start the server */
|
|
23
|
+
listen: (options?: {
|
|
24
|
+
port?: number;
|
|
25
|
+
host?: string;
|
|
26
|
+
}) => Promise<string>;
|
|
27
|
+
/** Stop the server */
|
|
28
|
+
close: () => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a new MoriaJS application.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createApp } from '@moriajs/core';
|
|
36
|
+
*
|
|
37
|
+
* const app = await createApp();
|
|
38
|
+
* await app.listen({ port: 3000 });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function createApp(options?: MoriaAppOptions): Promise<MoriaApp>;
|
|
42
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAKnF,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,mDAAmD;IACnD,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9B,wCAAwC;IACxC,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB,sCAAsC;IACtC,MAAM,EAAE,eAAe,CAAC;IACxB,gCAAgC;IAChC,GAAG,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,uBAAuB;IACvB,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,sBAAsB;IACtB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,SAAS,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA0DhF"}
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Fastify from 'fastify';
|
|
2
|
+
import cors from '@fastify/cors';
|
|
3
|
+
import cookie from '@fastify/cookie';
|
|
4
|
+
import compress from '@fastify/compress';
|
|
5
|
+
import helmet from '@fastify/helmet';
|
|
6
|
+
/**
|
|
7
|
+
* Create a new MoriaJS application.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createApp } from '@moriajs/core';
|
|
12
|
+
*
|
|
13
|
+
* const app = await createApp();
|
|
14
|
+
* await app.listen({ port: 3000 });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export async function createApp(options = {}) {
|
|
18
|
+
const config = options.config ?? {};
|
|
19
|
+
const port = config.server?.port ?? 3000;
|
|
20
|
+
const host = config.server?.host ?? '0.0.0.0';
|
|
21
|
+
// Create Fastify instance with sensible defaults
|
|
22
|
+
const server = Fastify({
|
|
23
|
+
logger: {
|
|
24
|
+
level: config.server?.logLevel ?? 'info',
|
|
25
|
+
transport: process.env.NODE_ENV !== 'production'
|
|
26
|
+
? { target: 'pino-pretty', options: { colorize: true } }
|
|
27
|
+
: undefined,
|
|
28
|
+
},
|
|
29
|
+
...options.fastifyOptions,
|
|
30
|
+
});
|
|
31
|
+
// Register core plugins
|
|
32
|
+
await server.register(cors, {
|
|
33
|
+
origin: config.server?.cors?.origin ?? true,
|
|
34
|
+
credentials: config.server?.cors?.credentials ?? true,
|
|
35
|
+
});
|
|
36
|
+
await server.register(cookie);
|
|
37
|
+
await server.register(compress);
|
|
38
|
+
await server.register(helmet, {
|
|
39
|
+
// Relax CSP in development for Vite HMR
|
|
40
|
+
contentSecurityPolicy: process.env.NODE_ENV === 'production',
|
|
41
|
+
});
|
|
42
|
+
// Health check route
|
|
43
|
+
server.get('/health', async () => ({ status: 'ok', timestamp: new Date().toISOString() }));
|
|
44
|
+
// Plugin registry
|
|
45
|
+
const plugins = [];
|
|
46
|
+
const app = {
|
|
47
|
+
server,
|
|
48
|
+
async use(plugin) {
|
|
49
|
+
plugins.push(plugin);
|
|
50
|
+
await plugin.register({ server, config });
|
|
51
|
+
},
|
|
52
|
+
async listen(listenOptions) {
|
|
53
|
+
const addr = await server.listen({
|
|
54
|
+
port: listenOptions?.port ?? port,
|
|
55
|
+
host: listenOptions?.host ?? host,
|
|
56
|
+
});
|
|
57
|
+
return addr;
|
|
58
|
+
},
|
|
59
|
+
async close() {
|
|
60
|
+
await server.close();
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
return app;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=app.js.map
|
package/dist/app.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,OAA4D,MAAM,SAAS,CAAC;AACnF,OAAO,IAAI,MAAM,eAAe,CAAC;AACjC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AA6BrC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,UAA2B,EAAE;IACzD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,IAAI,SAAS,CAAC;IAE9C,iDAAiD;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC;QACnB,MAAM,EAAE;YACJ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM;YACxC,SAAS,EACL,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;gBACjC,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;gBACxD,CAAC,CAAC,SAAS;SACtB;QACD,GAAG,OAAO,CAAC,cAAc;KAC5B,CAAC,CAAC;IAEH,wBAAwB;IACxB,MAAM,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,IAAI;QAC3C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,IAAI,IAAI;KACxD,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChC,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE;QAC1B,wCAAwC;QACxC,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;KAC/D,CAAC,CAAC;IAEH,qBAAqB;IACrB,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;IAE3F,kBAAkB;IAClB,MAAM,OAAO,GAAkB,EAAE,CAAC;IAElC,MAAM,GAAG,GAAa;QAClB,MAAM;QAEN,KAAK,CAAC,GAAG,CAAC,MAAmB;YACzB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9C,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,aAAa;YACtB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;gBAC7B,IAAI,EAAE,aAAa,EAAE,IAAI,IAAI,IAAI;gBACjC,IAAI,EAAE,aAAa,EAAE,IAAI,IAAI,IAAI;aACpC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,KAAK,CAAC,KAAK;YACP,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;KACJ,CAAC;IAEF,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MoriaJS configuration type.
|
|
3
|
+
* Used in `moria.config.ts` files in user projects.
|
|
4
|
+
*/
|
|
5
|
+
export interface MoriaConfig {
|
|
6
|
+
/** Server configuration */
|
|
7
|
+
server?: {
|
|
8
|
+
/** Port to listen on (default: 3000) */
|
|
9
|
+
port?: number;
|
|
10
|
+
/** Host to bind to (default: '0.0.0.0') */
|
|
11
|
+
host?: string;
|
|
12
|
+
/** Log level (default: 'info') */
|
|
13
|
+
logLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
|
|
14
|
+
/** CORS configuration */
|
|
15
|
+
cors?: {
|
|
16
|
+
origin?: string | string[] | boolean;
|
|
17
|
+
credentials?: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** Database configuration */
|
|
21
|
+
database?: {
|
|
22
|
+
/** Database adapter: 'pg' | 'sqlite' | 'mysql' */
|
|
23
|
+
adapter?: string;
|
|
24
|
+
/** Connection URL */
|
|
25
|
+
url?: string;
|
|
26
|
+
/** Path to SQLite file (for SQLite adapter) */
|
|
27
|
+
filename?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Authentication configuration */
|
|
30
|
+
auth?: {
|
|
31
|
+
/** JWT secret key */
|
|
32
|
+
secret?: string;
|
|
33
|
+
/** Token expiration (e.g., '7d', '24h') */
|
|
34
|
+
expiresIn?: string;
|
|
35
|
+
/** Cookie name for JWT token */
|
|
36
|
+
cookieName?: string;
|
|
37
|
+
/** Enable secure cookies (HTTPS only) */
|
|
38
|
+
secureCookies?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** Vite / build configuration */
|
|
41
|
+
vite?: {
|
|
42
|
+
/** Path to Vite config file */
|
|
43
|
+
configFile?: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Helper to define a type-safe MoriaJS configuration.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // moria.config.ts
|
|
52
|
+
* import { defineConfig } from '@moriajs/core';
|
|
53
|
+
*
|
|
54
|
+
* export default defineConfig({
|
|
55
|
+
* server: { port: 3000 },
|
|
56
|
+
* database: { adapter: 'sqlite', filename: './dev.db' },
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function defineConfig(config: MoriaConfig): MoriaConfig;
|
|
61
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,2BAA2B;IAC3B,MAAM,CAAC,EAAE;QACL,wCAAwC;QACxC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,2CAA2C;QAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,kCAAkC;QAClC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;QAC9E,yBAAyB;QACzB,IAAI,CAAC,EAAE;YACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;YACrC,WAAW,CAAC,EAAE,OAAO,CAAC;SACzB,CAAC;KACL,CAAC;IAEF,6BAA6B;IAC7B,QAAQ,CAAC,EAAE;QACP,kDAAkD;QAClD,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,qBAAqB;QACrB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,+CAA+C;QAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IAEF,mCAAmC;IACnC,IAAI,CAAC,EAAE;QACH,qBAAqB;QACrB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,2CAA2C;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gCAAgC;QAChC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,yCAAyC;QACzC,aAAa,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IAEF,iCAAiC;IACjC,IAAI,CAAC,EAAE;QACH,+BAA+B;QAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACL;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAE7D"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper to define a type-safe MoriaJS configuration.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* // moria.config.ts
|
|
7
|
+
* import { defineConfig } from '@moriajs/core';
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* server: { port: 3000 },
|
|
11
|
+
* database: { adapter: 'sqlite', filename: './dev.db' },
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function defineConfig(config) {
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAiDA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAC,MAAmB;IAC5C,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moriajs/core
|
|
3
|
+
*
|
|
4
|
+
* Framework core: Fastify server factory with sensible defaults,
|
|
5
|
+
* plugin registration, and configuration system.
|
|
6
|
+
*/
|
|
7
|
+
export { createApp } from './app.js';
|
|
8
|
+
export { defineConfig } from './config.js';
|
|
9
|
+
export { defineMoriaPlugin } from './plugins.js';
|
|
10
|
+
export type { MoriaApp, MoriaAppOptions } from './app.js';
|
|
11
|
+
export type { MoriaConfig } from './config.js';
|
|
12
|
+
export type { MoriaPlugin, MoriaPluginContext } from './plugins.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moriajs/core
|
|
3
|
+
*
|
|
4
|
+
* Framework core: Fastify server factory with sensible defaults,
|
|
5
|
+
* plugin registration, and configuration system.
|
|
6
|
+
*/
|
|
7
|
+
export { createApp } from './app.js';
|
|
8
|
+
export { defineConfig } from './config.js';
|
|
9
|
+
export { defineMoriaPlugin } from './plugins.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { MoriaConfig } from './config.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context provided to MoriaJS plugins during registration.
|
|
5
|
+
*/
|
|
6
|
+
export interface MoriaPluginContext {
|
|
7
|
+
/** The Fastify server instance */
|
|
8
|
+
server: FastifyInstance;
|
|
9
|
+
/** The MoriaJS configuration */
|
|
10
|
+
config: Partial<MoriaConfig>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A MoriaJS plugin.
|
|
14
|
+
* Plugins extend the framework with additional functionality.
|
|
15
|
+
*/
|
|
16
|
+
export interface MoriaPlugin {
|
|
17
|
+
/** Unique plugin name */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Plugin registration function */
|
|
20
|
+
register: (context: MoriaPluginContext) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Helper to define a type-safe MoriaJS plugin.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { defineMoriaPlugin } from '@moriajs/core';
|
|
28
|
+
*
|
|
29
|
+
* export default defineMoriaPlugin({
|
|
30
|
+
* name: 'my-plugin',
|
|
31
|
+
* async register({ server, config }) {
|
|
32
|
+
* server.get('/my-route', async () => ({ hello: 'plugin' }));
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function defineMoriaPlugin(plugin: MoriaPlugin): MoriaPlugin;
|
|
38
|
+
//# sourceMappingURL=plugins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,kCAAkC;IAClC,MAAM,EAAE,eAAe,CAAC;IACxB,gCAAgC;IAChC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,QAAQ,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAElE"}
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper to define a type-safe MoriaJS plugin.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { defineMoriaPlugin } from '@moriajs/core';
|
|
7
|
+
*
|
|
8
|
+
* export default defineMoriaPlugin({
|
|
9
|
+
* name: 'my-plugin',
|
|
10
|
+
* async register({ server, config }) {
|
|
11
|
+
* server.get('/my-route', async () => ({ hello: 'plugin' }));
|
|
12
|
+
* },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function defineMoriaPlugin(plugin) {
|
|
17
|
+
return plugin;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAmB;IACjD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moriajs/core",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "MoriaJS framework core — Fastify server, Vite integration, and routing",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"fastify": "^5.2.0",
|
|
16
|
+
"@fastify/cors": "^11.0.0",
|
|
17
|
+
"@fastify/cookie": "^11.0.0",
|
|
18
|
+
"@fastify/compress": "^8.0.0",
|
|
19
|
+
"@fastify/static": "^9.0.0",
|
|
20
|
+
"@fastify/helmet": "^13.0.0",
|
|
21
|
+
"pino-pretty": "^13.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.7.0",
|
|
25
|
+
"rimraf": "^6.0.0",
|
|
26
|
+
"@types/node": "^22.0.0"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "Guntur-D <guntur.d.npm@gmail.com>",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/guntur-d/moriajs.git",
|
|
33
|
+
"directory": "packages/core"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/guntur-d/moriajs/tree/main/packages/core#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/guntur-d/moriajs/issues"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc",
|
|
44
|
+
"dev": "tsc --watch",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"clean": "rimraf dist .turbo"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Fastify, { type FastifyInstance, type FastifyServerOptions } from 'fastify';
|
|
2
|
+
import cors from '@fastify/cors';
|
|
3
|
+
import cookie from '@fastify/cookie';
|
|
4
|
+
import compress from '@fastify/compress';
|
|
5
|
+
import helmet from '@fastify/helmet';
|
|
6
|
+
import { type MoriaConfig } from './config.js';
|
|
7
|
+
import { type MoriaPlugin } from './plugins.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for creating a MoriaJS application.
|
|
11
|
+
*/
|
|
12
|
+
export interface MoriaAppOptions {
|
|
13
|
+
/** MoriaJS configuration (from moria.config.ts) */
|
|
14
|
+
config?: Partial<MoriaConfig>;
|
|
15
|
+
/** Additional Fastify server options */
|
|
16
|
+
fastifyOptions?: FastifyServerOptions;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The MoriaJS application instance.
|
|
21
|
+
* Wraps a Fastify instance with framework-level features.
|
|
22
|
+
*/
|
|
23
|
+
export interface MoriaApp {
|
|
24
|
+
/** The underlying Fastify instance */
|
|
25
|
+
server: FastifyInstance;
|
|
26
|
+
/** Register a MoriaJS plugin */
|
|
27
|
+
use: (plugin: MoriaPlugin) => Promise<void>;
|
|
28
|
+
/** Start the server */
|
|
29
|
+
listen: (options?: { port?: number; host?: string }) => Promise<string>;
|
|
30
|
+
/** Stop the server */
|
|
31
|
+
close: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Create a new MoriaJS application.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { createApp } from '@moriajs/core';
|
|
40
|
+
*
|
|
41
|
+
* const app = await createApp();
|
|
42
|
+
* await app.listen({ port: 3000 });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function createApp(options: MoriaAppOptions = {}): Promise<MoriaApp> {
|
|
46
|
+
const config = options.config ?? {};
|
|
47
|
+
const port = config.server?.port ?? 3000;
|
|
48
|
+
const host = config.server?.host ?? '0.0.0.0';
|
|
49
|
+
|
|
50
|
+
// Create Fastify instance with sensible defaults
|
|
51
|
+
const server = Fastify({
|
|
52
|
+
logger: {
|
|
53
|
+
level: config.server?.logLevel ?? 'info',
|
|
54
|
+
transport:
|
|
55
|
+
process.env.NODE_ENV !== 'production'
|
|
56
|
+
? { target: 'pino-pretty', options: { colorize: true } }
|
|
57
|
+
: undefined,
|
|
58
|
+
},
|
|
59
|
+
...options.fastifyOptions,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Register core plugins
|
|
63
|
+
await server.register(cors, {
|
|
64
|
+
origin: config.server?.cors?.origin ?? true,
|
|
65
|
+
credentials: config.server?.cors?.credentials ?? true,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
await server.register(cookie);
|
|
69
|
+
await server.register(compress);
|
|
70
|
+
await server.register(helmet, {
|
|
71
|
+
// Relax CSP in development for Vite HMR
|
|
72
|
+
contentSecurityPolicy: process.env.NODE_ENV === 'production',
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Health check route
|
|
76
|
+
server.get('/health', async () => ({ status: 'ok', timestamp: new Date().toISOString() }));
|
|
77
|
+
|
|
78
|
+
// Plugin registry
|
|
79
|
+
const plugins: MoriaPlugin[] = [];
|
|
80
|
+
|
|
81
|
+
const app: MoriaApp = {
|
|
82
|
+
server,
|
|
83
|
+
|
|
84
|
+
async use(plugin: MoriaPlugin) {
|
|
85
|
+
plugins.push(plugin);
|
|
86
|
+
await plugin.register({ server, config });
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
async listen(listenOptions) {
|
|
90
|
+
const addr = await server.listen({
|
|
91
|
+
port: listenOptions?.port ?? port,
|
|
92
|
+
host: listenOptions?.host ?? host,
|
|
93
|
+
});
|
|
94
|
+
return addr;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
async close() {
|
|
98
|
+
await server.close();
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return app;
|
|
103
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MoriaJS configuration type.
|
|
3
|
+
* Used in `moria.config.ts` files in user projects.
|
|
4
|
+
*/
|
|
5
|
+
export interface MoriaConfig {
|
|
6
|
+
/** Server configuration */
|
|
7
|
+
server?: {
|
|
8
|
+
/** Port to listen on (default: 3000) */
|
|
9
|
+
port?: number;
|
|
10
|
+
/** Host to bind to (default: '0.0.0.0') */
|
|
11
|
+
host?: string;
|
|
12
|
+
/** Log level (default: 'info') */
|
|
13
|
+
logLevel?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
|
|
14
|
+
/** CORS configuration */
|
|
15
|
+
cors?: {
|
|
16
|
+
origin?: string | string[] | boolean;
|
|
17
|
+
credentials?: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Database configuration */
|
|
22
|
+
database?: {
|
|
23
|
+
/** Database adapter: 'pg' | 'sqlite' | 'mysql' */
|
|
24
|
+
adapter?: string;
|
|
25
|
+
/** Connection URL */
|
|
26
|
+
url?: string;
|
|
27
|
+
/** Path to SQLite file (for SQLite adapter) */
|
|
28
|
+
filename?: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Authentication configuration */
|
|
32
|
+
auth?: {
|
|
33
|
+
/** JWT secret key */
|
|
34
|
+
secret?: string;
|
|
35
|
+
/** Token expiration (e.g., '7d', '24h') */
|
|
36
|
+
expiresIn?: string;
|
|
37
|
+
/** Cookie name for JWT token */
|
|
38
|
+
cookieName?: string;
|
|
39
|
+
/** Enable secure cookies (HTTPS only) */
|
|
40
|
+
secureCookies?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Vite / build configuration */
|
|
44
|
+
vite?: {
|
|
45
|
+
/** Path to Vite config file */
|
|
46
|
+
configFile?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Helper to define a type-safe MoriaJS configuration.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // moria.config.ts
|
|
56
|
+
* import { defineConfig } from '@moriajs/core';
|
|
57
|
+
*
|
|
58
|
+
* export default defineConfig({
|
|
59
|
+
* server: { port: 3000 },
|
|
60
|
+
* database: { adapter: 'sqlite', filename: './dev.db' },
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function defineConfig(config: MoriaConfig): MoriaConfig {
|
|
65
|
+
return config;
|
|
66
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @moriajs/core
|
|
3
|
+
*
|
|
4
|
+
* Framework core: Fastify server factory with sensible defaults,
|
|
5
|
+
* plugin registration, and configuration system.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { createApp } from './app.js';
|
|
9
|
+
export { defineConfig } from './config.js';
|
|
10
|
+
export { defineMoriaPlugin } from './plugins.js';
|
|
11
|
+
|
|
12
|
+
export type { MoriaApp, MoriaAppOptions } from './app.js';
|
|
13
|
+
export type { MoriaConfig } from './config.js';
|
|
14
|
+
export type { MoriaPlugin, MoriaPluginContext } from './plugins.js';
|
package/src/plugins.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { MoriaConfig } from './config.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context provided to MoriaJS plugins during registration.
|
|
6
|
+
*/
|
|
7
|
+
export interface MoriaPluginContext {
|
|
8
|
+
/** The Fastify server instance */
|
|
9
|
+
server: FastifyInstance;
|
|
10
|
+
/** The MoriaJS configuration */
|
|
11
|
+
config: Partial<MoriaConfig>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A MoriaJS plugin.
|
|
16
|
+
* Plugins extend the framework with additional functionality.
|
|
17
|
+
*/
|
|
18
|
+
export interface MoriaPlugin {
|
|
19
|
+
/** Unique plugin name */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Plugin registration function */
|
|
22
|
+
register: (context: MoriaPluginContext) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Helper to define a type-safe MoriaJS plugin.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { defineMoriaPlugin } from '@moriajs/core';
|
|
31
|
+
*
|
|
32
|
+
* export default defineMoriaPlugin({
|
|
33
|
+
* name: 'my-plugin',
|
|
34
|
+
* async register({ server, config }) {
|
|
35
|
+
* server.get('/my-route', async () => ({ hello: 'plugin' }));
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function defineMoriaPlugin(plugin: MoriaPlugin): MoriaPlugin {
|
|
41
|
+
return plugin;
|
|
42
|
+
}
|