@kuckit/sdk 2.0.0 → 2.0.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/chunk-B1JASekH.js +7 -0
- package/dist/config/define-config.d.ts +2 -2
- package/dist/config/define-config.js +1 -1
- package/dist/config/index.d.ts +5 -5
- package/dist/config/index.js +4 -4
- package/dist/config/loader.d.ts +3 -3
- package/dist/config/loader.js +2 -2
- package/dist/config/types.d.ts +1 -1
- package/dist/{container-Ngzcb6LI.d.ts → container-BQ8Ow2Ot.d.ts} +37 -3
- package/dist/{container-D0DK003A.js → container-Ct2UXGF_.js} +3 -3
- package/dist/container-Ct2UXGF_.js.map +1 -0
- package/dist/core/container.d.ts +3 -3
- package/dist/core/container.js +2 -2
- package/dist/core/core.module.d.ts +3 -2
- package/dist/core/core.module.js +1 -1
- package/dist/core.module-47w_x8z-.js +54 -0
- package/dist/core.module-47w_x8z-.js.map +1 -0
- package/dist/core.module-D8vH8AcY.d.ts +26 -0
- package/dist/{define-config-yzb59aTs.d.ts → define-config-D-gChhM6.d.ts} +2 -2
- package/dist/{define-config-GYI_W9K6.js → define-config-fjqcYWfl.js} +1 -1
- package/dist/{define-config-GYI_W9K6.js.map → define-config-fjqcYWfl.js.map} +1 -1
- package/dist/{define-module-Cw7q13EE.d.ts → define-module-CDZ2Cnss.d.ts} +2 -2
- package/dist/{define-module-B83hUzJz.js → define-module-CzsWcVHH.js} +1 -1
- package/dist/{define-module-B83hUzJz.js.map → define-module-CzsWcVHH.js.map} +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.js +11 -11
- package/dist/{loader-YEqdtcKI.d.ts → loader-0s9nW_Uz.d.ts} +8 -3
- package/dist/{loader-Ct4ZivZz.js → loader-BZuTuluL.js} +3 -3
- package/dist/{loader-Ct4ZivZz.js.map → loader-BZuTuluL.js.map} +1 -1
- package/dist/{loader-lCPWCMYx.js → loader-DKhFYG5d.js} +23 -2
- package/dist/loader-DKhFYG5d.js.map +1 -0
- package/dist/{loader-DCNm6pZB.d.ts → loader-Do1M_26D.d.ts} +3 -3
- package/dist/modules/define-module.d.ts +3 -3
- package/dist/modules/define-module.js +1 -1
- package/dist/modules/index.d.ts +6 -6
- package/dist/modules/index.js +6 -6
- package/dist/modules/loader.d.ts +3 -3
- package/dist/modules/loader.js +4 -4
- package/dist/modules/registry.d.ts +3 -3
- package/dist/modules/registry.js +1 -1
- package/dist/modules/types.d.ts +2 -2
- package/dist/{registry-DrTkgmtH.d.ts → registry-9FKJPjuY.d.ts} +2 -2
- package/dist/{registry-BPYpBtYx.js → registry-B62Oueqd.js} +1 -1
- package/dist/{registry-BPYpBtYx.js.map → registry-B62Oueqd.js.map} +1 -1
- package/dist/{registry-CfpVCPcW.d.ts → registry-BwUbpLWo.d.ts} +1 -1
- package/dist/{registry-CL_5erME.js → registry-DMY4gCiz.js} +1 -1
- package/dist/{registry-CL_5erME.js.map → registry-DMY4gCiz.js.map} +1 -1
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js +2 -2
- package/dist/schema/registry.d.ts +1 -1
- package/dist/schema/registry.js +1 -1
- package/dist/{types-DxaDmkQo.d.ts → types-Ceg8XQY6.d.ts} +8 -1
- package/dist/{types-DKCy16X1.d.ts → types-TWbGQRnv.d.ts} +11 -4
- package/dist/{types-ByO301S-.d.ts → types-TrXzdvrM.d.ts} +2 -2
- package/dist/types.d.ts +2 -2
- package/package.json +12 -8
- package/dist/container-D0DK003A.js.map +0 -1
- package/dist/core.module-Ckt9iPWn.d.ts +0 -22
- package/dist/core.module-Ctm2stcL.js +0 -48
- package/dist/core.module-Ctm2stcL.js.map +0 -1
- package/dist/loader-lCPWCMYx.js.map +0 -1
- /package/dist/{config-BeiJJZGf.js → config-Dwl_qu6x.js} +0 -0
- /package/dist/{index-Dfcz46Ma.d.ts → index-BLsEv2uZ.d.ts} +0 -0
- /package/dist/{index-CDDzqahH.d.ts → index-C9nY9t1j.d.ts} +0 -0
- /package/dist/{index-Dw5cCt-A.d.ts → index-E7Wvm5uX.d.ts} +0 -0
- /package/dist/{modules-BDQBjAbp.js → modules-CQFGHC4e.js} +0 -0
- /package/dist/{schema-BuA2HF_H.js → schema-C94Ei_S4.js} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { t as defineConfig } from "../define-config-
|
|
1
|
+
import "../types-Ceg8XQY6.js";
|
|
2
|
+
import { t as defineConfig } from "../define-config-D-gChhM6.js";
|
|
3
3
|
export { defineConfig };
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as KuckitServerConfig, i as KuckitModuleConfig, n as KuckitConfig, o as LoadedKuckitConfig, r as KuckitDiscoveryConfig, t as KuckitClientConfig } from "../types-
|
|
2
|
-
import { t as defineConfig } from "../define-config-
|
|
3
|
-
import {
|
|
4
|
-
import "../index-
|
|
5
|
-
export { KuckitClientConfig, KuckitConfig, KuckitDiscoveryConfig, KuckitModuleConfig, KuckitServerConfig, LoadedKuckitConfig, defineConfig, findConfigFile, hasUnifiedConfig, loadKuckitConfig, tryLoadKuckitConfig };
|
|
1
|
+
import { a as KuckitServerConfig, i as KuckitModuleConfig, n as KuckitConfig, o as LoadedKuckitConfig, r as KuckitDiscoveryConfig, t as KuckitClientConfig } from "../types-Ceg8XQY6.js";
|
|
2
|
+
import { t as defineConfig } from "../define-config-D-gChhM6.js";
|
|
3
|
+
import { a as tryLoadKuckitConfig, i as loadKuckitConfigSync, n as hasUnifiedConfig, r as loadKuckitConfig, t as findConfigFile } from "../loader-0s9nW_Uz.js";
|
|
4
|
+
import "../index-C9nY9t1j.js";
|
|
5
|
+
export { KuckitClientConfig, KuckitConfig, KuckitDiscoveryConfig, KuckitModuleConfig, KuckitServerConfig, LoadedKuckitConfig, defineConfig, findConfigFile, hasUnifiedConfig, loadKuckitConfig, loadKuckitConfigSync, tryLoadKuckitConfig };
|
package/dist/config/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as defineConfig } from "../define-config-
|
|
2
|
-
import {
|
|
3
|
-
import "../config-
|
|
1
|
+
import { t as defineConfig } from "../define-config-fjqcYWfl.js";
|
|
2
|
+
import { a as tryLoadKuckitConfig, i as loadKuckitConfigSync, n as hasUnifiedConfig, r as loadKuckitConfig, t as findConfigFile } from "../loader-DKhFYG5d.js";
|
|
3
|
+
import "../config-Dwl_qu6x.js";
|
|
4
4
|
|
|
5
|
-
export { defineConfig, findConfigFile, hasUnifiedConfig, loadKuckitConfig, tryLoadKuckitConfig };
|
|
5
|
+
export { defineConfig, findConfigFile, hasUnifiedConfig, loadKuckitConfig, loadKuckitConfigSync, tryLoadKuckitConfig };
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import {
|
|
3
|
-
export { findConfigFile, hasUnifiedConfig, loadKuckitConfig, tryLoadKuckitConfig };
|
|
1
|
+
import "../types-Ceg8XQY6.js";
|
|
2
|
+
import { a as tryLoadKuckitConfig, i as loadKuckitConfigSync, n as hasUnifiedConfig, r as loadKuckitConfig, t as findConfigFile } from "../loader-0s9nW_Uz.js";
|
|
3
|
+
export { findConfigFile, hasUnifiedConfig, loadKuckitConfig, loadKuckitConfigSync, tryLoadKuckitConfig };
|
package/dist/config/loader.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as tryLoadKuckitConfig, i as loadKuckitConfigSync, n as hasUnifiedConfig, r as loadKuckitConfig, t as findConfigFile } from "../loader-DKhFYG5d.js";
|
|
2
2
|
|
|
3
|
-
export { findConfigFile, hasUnifiedConfig, loadKuckitConfig, tryLoadKuckitConfig };
|
|
3
|
+
export { findConfigFile, hasUnifiedConfig, loadKuckitConfig, loadKuckitConfigSync, tryLoadKuckitConfig };
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as KuckitServerConfig, i as KuckitModuleConfig, n as KuckitConfig, o as LoadedKuckitConfig, r as KuckitDiscoveryConfig, t as KuckitClientConfig } from "../types-
|
|
1
|
+
import { a as KuckitServerConfig, i as KuckitModuleConfig, n as KuckitConfig, o as LoadedKuckitConfig, r as KuckitDiscoveryConfig, t as KuckitClientConfig } from "../types-Ceg8XQY6.js";
|
|
2
2
|
export { KuckitClientConfig, KuckitConfig, KuckitDiscoveryConfig, KuckitModuleConfig, KuckitServerConfig, LoadedKuckitConfig };
|
|
@@ -1,11 +1,45 @@
|
|
|
1
|
-
import { n as CoreContainer, t as CoreConfig } from "./types-
|
|
1
|
+
import { n as CoreContainer, t as CoreConfig } from "./types-TWbGQRnv.js";
|
|
2
|
+
import { Auth } from "@kuckit/auth";
|
|
3
|
+
import { Pool } from "pg";
|
|
2
4
|
|
|
3
5
|
//#region src/core/container.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pre-built dependencies that can be passed to createKuckitContainer.
|
|
9
|
+
* When provided, these skip the internal factory creation.
|
|
10
|
+
*/
|
|
11
|
+
interface PrebuiltDependencies {
|
|
12
|
+
/**
|
|
13
|
+
* Pre-built PostgreSQL connection pool
|
|
14
|
+
* If provided, skips createDbPool() in core.module
|
|
15
|
+
*/
|
|
16
|
+
dbPool?: Pool;
|
|
17
|
+
/**
|
|
18
|
+
* Pre-built Drizzle database instance
|
|
19
|
+
* If provided, skips createDb() in core.module
|
|
20
|
+
*/
|
|
21
|
+
db?: unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Pre-built Better-Auth instance
|
|
24
|
+
* If provided, skips createAuth() in core.module
|
|
25
|
+
*/
|
|
26
|
+
auth?: Auth;
|
|
27
|
+
/**
|
|
28
|
+
* Pre-built AI provider (e.g., google('gemini-2.5-flash'))
|
|
29
|
+
* If provided, skips aiProvider creation in core.module
|
|
30
|
+
*/
|
|
31
|
+
aiProvider?: unknown;
|
|
32
|
+
}
|
|
4
33
|
interface CreateKuckitOptions {
|
|
5
34
|
/**
|
|
6
35
|
* Core configuration for the SDK
|
|
7
36
|
*/
|
|
8
37
|
config: CoreConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Pre-built dependencies to inject instead of creating internally.
|
|
40
|
+
* Use this in composition root (apps/server) to control instantiation.
|
|
41
|
+
*/
|
|
42
|
+
prebuilt?: PrebuiltDependencies;
|
|
9
43
|
/**
|
|
10
44
|
* Optional callback to register additional services after core registration
|
|
11
45
|
*/
|
|
@@ -45,5 +79,5 @@ declare const createKuckitContainer: (opts: CreateKuckitOptions) => Promise<Core
|
|
|
45
79
|
*/
|
|
46
80
|
declare const disposeContainer: (container: CoreContainer) => Promise<void>;
|
|
47
81
|
//#endregion
|
|
48
|
-
export {
|
|
49
|
-
//# sourceMappingURL=container-
|
|
82
|
+
export { disposeContainer as i, PrebuiltDependencies as n, createKuckitContainer as r, CreateKuckitOptions as t };
|
|
83
|
+
//# sourceMappingURL=container-BQ8Ow2Ot.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as registerCoreModule } from "./core.module-
|
|
1
|
+
import { t as registerCoreModule } from "./core.module-47w_x8z-.js";
|
|
2
2
|
import { InjectionMode, asValue, createContainer } from "awilix";
|
|
3
3
|
|
|
4
4
|
//#region src/core/container.ts
|
|
@@ -30,7 +30,7 @@ import { InjectionMode, asValue, createContainer } from "awilix";
|
|
|
30
30
|
const createKuckitContainer = async (opts) => {
|
|
31
31
|
const container = createContainer({ injectionMode: InjectionMode.PROXY });
|
|
32
32
|
container.register({ config: asValue(opts.config) });
|
|
33
|
-
registerCoreModule(container);
|
|
33
|
+
registerCoreModule(container, opts.prebuilt);
|
|
34
34
|
if (opts.extraRegistrations) await opts.extraRegistrations(container);
|
|
35
35
|
return container;
|
|
36
36
|
};
|
|
@@ -47,4 +47,4 @@ const disposeContainer = async (container) => {
|
|
|
47
47
|
|
|
48
48
|
//#endregion
|
|
49
49
|
export { disposeContainer as n, createKuckitContainer as t };
|
|
50
|
-
//# sourceMappingURL=container-
|
|
50
|
+
//# sourceMappingURL=container-Ct2UXGF_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container-Ct2UXGF_.js","names":[],"sources":["../src/core/container.ts"],"sourcesContent":["import { createContainer, asValue, InjectionMode } from 'awilix'\nimport type { Pool } from 'pg'\nimport type { Auth } from '@kuckit/auth'\nimport type { CoreContainer, CoreCradle, CoreConfig } from '../types'\nimport { registerCoreModule } from './core.module'\n\n/**\n * Pre-built dependencies that can be passed to createKuckitContainer.\n * When provided, these skip the internal factory creation.\n */\nexport interface PrebuiltDependencies {\n\t/**\n\t * Pre-built PostgreSQL connection pool\n\t * If provided, skips createDbPool() in core.module\n\t */\n\tdbPool?: Pool\n\n\t/**\n\t * Pre-built Drizzle database instance\n\t * If provided, skips createDb() in core.module\n\t */\n\tdb?: unknown\n\n\t/**\n\t * Pre-built Better-Auth instance\n\t * If provided, skips createAuth() in core.module\n\t */\n\tauth?: Auth\n\n\t/**\n\t * Pre-built AI provider (e.g., google('gemini-2.5-flash'))\n\t * If provided, skips aiProvider creation in core.module\n\t */\n\taiProvider?: unknown\n}\n\nexport interface CreateKuckitOptions {\n\t/**\n\t * Core configuration for the SDK\n\t */\n\tconfig: CoreConfig\n\n\t/**\n\t * Pre-built dependencies to inject instead of creating internally.\n\t * Use this in composition root (apps/server) to control instantiation.\n\t */\n\tprebuilt?: PrebuiltDependencies\n\n\t/**\n\t * Optional callback to register additional services after core registration\n\t */\n\textraRegistrations?: (container: CoreContainer) => void | Promise<void>\n}\n\n/**\n * Factory function to create a Kuckit DI container\n *\n * This is the primary entry point for applications using the SDK.\n * It creates an Awilix container with core infrastructure services pre-registered.\n *\n * @example\n * ```ts\n * const container = await createKuckitContainer({\n * config: {\n * databaseUrl: process.env.DATABASE_URL!,\n * enableFileLogging: true,\n * logDir: './logs',\n * logLevel: 'INFO',\n * env: 'production',\n * },\n * extraRegistrations: (container) => {\n * // Register your custom services\n * container.register({\n * myService: asClass(MyService).singleton(),\n * })\n * },\n * })\n * ```\n */\nexport const createKuckitContainer = async (opts: CreateKuckitOptions): Promise<CoreContainer> => {\n\tconst container = createContainer<CoreCradle>({\n\t\tinjectionMode: InjectionMode.PROXY,\n\t})\n\n\t// Register config first (required by other registrations)\n\tcontainer.register({\n\t\tconfig: asValue(opts.config),\n\t})\n\n\t// Register core infrastructure (passing prebuilt dependencies if provided)\n\tregisterCoreModule(container, opts.prebuilt)\n\n\t// Allow custom registrations\n\tif (opts.extraRegistrations) {\n\t\tawait opts.extraRegistrations(container)\n\t}\n\n\treturn container\n}\n\n/**\n * Cleanup container resources gracefully\n *\n * Call this when shutting down your application to close database connections\n * and other resources.\n */\nexport const disposeContainer = async (container: CoreContainer): Promise<void> => {\n\tconst { dbPool } = container.cradle\n\t// Handle unknown dbPool type - check for end method\n\tif (\n\t\tdbPool &&\n\t\ttypeof dbPool === 'object' &&\n\t\t'end' in dbPool &&\n\t\ttypeof (dbPool as { end: unknown }).end === 'function'\n\t) {\n\t\tawait (dbPool as { end: () => Promise<void> }).end()\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,MAAa,wBAAwB,OAAO,SAAsD;CACjG,MAAM,YAAY,gBAA4B,EAC7C,eAAe,cAAc,OAC7B,CAAC;AAGF,WAAU,SAAS,EAClB,QAAQ,QAAQ,KAAK,OAAO,EAC5B,CAAC;AAGF,oBAAmB,WAAW,KAAK,SAAS;AAG5C,KAAI,KAAK,mBACR,OAAM,KAAK,mBAAmB,UAAU;AAGzC,QAAO;;;;;;;;AASR,MAAa,mBAAmB,OAAO,cAA4C;CAClF,MAAM,EAAE,WAAW,UAAU;AAE7B,KACC,UACA,OAAO,WAAW,YAClB,SAAS,UACT,OAAQ,OAA4B,QAAQ,WAE5C,OAAO,OAAwC,KAAK"}
|
package/dist/core/container.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { n as
|
|
3
|
-
export { CreateKuckitOptions, createKuckitContainer, disposeContainer };
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import { i as disposeContainer, n as PrebuiltDependencies, r as createKuckitContainer, t as CreateKuckitOptions } from "../container-BQ8Ow2Ot.js";
|
|
3
|
+
export { CreateKuckitOptions, PrebuiltDependencies, createKuckitContainer, disposeContainer };
|
package/dist/core/container.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../core.module-
|
|
2
|
-
import { n as disposeContainer, t as createKuckitContainer } from "../container-
|
|
1
|
+
import "../core.module-47w_x8z-.js";
|
|
2
|
+
import { n as disposeContainer, t as createKuckitContainer } from "../container-Ct2UXGF_.js";
|
|
3
3
|
|
|
4
4
|
export { createKuckitContainer, disposeContainer };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import "../container-BQ8Ow2Ot.js";
|
|
3
|
+
import { t as registerCoreModule } from "../core.module-D8vH8AcY.js";
|
|
3
4
|
export { registerCoreModule };
|
package/dist/core/core.module.js
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { t as __require } from "./chunk-B1JASekH.js";
|
|
2
|
+
import { asFunction, asValue } from "awilix";
|
|
3
|
+
import { SystemClock } from "@kuckit/domain";
|
|
4
|
+
import { createAuth } from "@kuckit/auth";
|
|
5
|
+
import { InMemoryEventBus, createDb, createDbPool, makeErrorHandler, makeInMemoryCacheStore, makeInMemoryRateLimiterStore, makeRequestLogger, makeStructuredLogger } from "@kuckit/infrastructure";
|
|
6
|
+
|
|
7
|
+
//#region src/core/core.module.ts
|
|
8
|
+
/**
|
|
9
|
+
* Register core infrastructure services into the container
|
|
10
|
+
*
|
|
11
|
+
* This registers:
|
|
12
|
+
* - Database pool and connection
|
|
13
|
+
* - Clock
|
|
14
|
+
* - Logger (structured, Loki/Prometheus compatible)
|
|
15
|
+
* - AI provider (optional - only if provided or API key available)
|
|
16
|
+
* - Auth
|
|
17
|
+
* - Event bus
|
|
18
|
+
* - Cache store
|
|
19
|
+
* - Rate limiter store
|
|
20
|
+
* - Request-scoped logger
|
|
21
|
+
*
|
|
22
|
+
* @param container - The Awilix container to register services into
|
|
23
|
+
* @param prebuilt - Optional pre-built dependencies to use instead of creating internally
|
|
24
|
+
*/
|
|
25
|
+
const registerCoreModule = (container, prebuilt) => {
|
|
26
|
+
container.register({
|
|
27
|
+
dbPool: prebuilt?.dbPool ? asValue(prebuilt.dbPool) : asFunction(({ config }) => createDbPool(config.databaseUrl)).singleton(),
|
|
28
|
+
db: prebuilt?.db ? asValue(prebuilt.db) : asFunction(({ dbPool }) => createDb(dbPool)).singleton(),
|
|
29
|
+
clock: asValue(new SystemClock()),
|
|
30
|
+
logger: asFunction(({ config }) => makeStructuredLogger({
|
|
31
|
+
enableFile: config.enableFileLogging,
|
|
32
|
+
logDir: config.logDir,
|
|
33
|
+
minLevel: config.logLevel
|
|
34
|
+
})).singleton(),
|
|
35
|
+
errorHandler: asFunction(({ logger }) => makeErrorHandler(logger)).singleton(),
|
|
36
|
+
auth: prebuilt?.auth ? asValue(prebuilt.auth) : asFunction(({ db }) => createAuth({ db })).singleton(),
|
|
37
|
+
aiProvider: prebuilt?.aiProvider ? asValue(prebuilt.aiProvider) : asFunction(() => {
|
|
38
|
+
const { google } = __require("@ai-sdk/google");
|
|
39
|
+
return google("gemini-2.5-flash");
|
|
40
|
+
}).singleton(),
|
|
41
|
+
eventBus: asFunction(({ logger }) => new InMemoryEventBus(logger)).singleton(),
|
|
42
|
+
cacheStore: asFunction(() => makeInMemoryCacheStore()).singleton(),
|
|
43
|
+
rateLimiterStore: asFunction(() => makeInMemoryRateLimiterStore()).singleton(),
|
|
44
|
+
requestLogger: asFunction(({ logger, requestId, session }) => makeRequestLogger({
|
|
45
|
+
requestId,
|
|
46
|
+
userId: session?.user?.id,
|
|
47
|
+
baseLogger: logger
|
|
48
|
+
})).scoped()
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { registerCoreModule as t };
|
|
54
|
+
//# sourceMappingURL=core.module-47w_x8z-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.module-47w_x8z-.js","names":[],"sources":["../src/core/core.module.ts"],"sourcesContent":["import { asFunction, asValue } from 'awilix'\nimport { SystemClock } from '@kuckit/domain'\nimport { createAuth } from '@kuckit/auth'\nimport {\n\tcreateDbPool,\n\tcreateDb,\n\tmakeStructuredLogger,\n\tmakeRequestLogger,\n\tmakeErrorHandler,\n\tInMemoryEventBus,\n\tmakeInMemoryCacheStore,\n\tmakeInMemoryRateLimiterStore,\n} from '@kuckit/infrastructure'\nimport type { CoreContainer } from '../types'\nimport type { PrebuiltDependencies } from './container'\n\n/**\n * Register core infrastructure services into the container\n *\n * This registers:\n * - Database pool and connection\n * - Clock\n * - Logger (structured, Loki/Prometheus compatible)\n * - AI provider (optional - only if provided or API key available)\n * - Auth\n * - Event bus\n * - Cache store\n * - Rate limiter store\n * - Request-scoped logger\n *\n * @param container - The Awilix container to register services into\n * @param prebuilt - Optional pre-built dependencies to use instead of creating internally\n */\nexport const registerCoreModule = (\n\tcontainer: CoreContainer,\n\tprebuilt?: PrebuiltDependencies\n): void => {\n\tcontainer.register({\n\t\t// Database - use prebuilt if provided, otherwise create from config\n\t\tdbPool: prebuilt?.dbPool\n\t\t\t? asValue(prebuilt.dbPool)\n\t\t\t: asFunction(({ config }) => createDbPool(config.databaseUrl)).singleton(),\n\n\t\tdb: prebuilt?.db\n\t\t\t? asValue(prebuilt.db)\n\t\t\t: asFunction(({ dbPool }) => createDb(dbPool)).singleton(),\n\n\t\t// Core services\n\t\tclock: asValue(new SystemClock()),\n\n\t\tlogger: asFunction(({ config }) =>\n\t\t\tmakeStructuredLogger({\n\t\t\t\tenableFile: config.enableFileLogging,\n\t\t\t\tlogDir: config.logDir,\n\t\t\t\tminLevel: config.logLevel,\n\t\t\t})\n\t\t).singleton(),\n\n\t\terrorHandler: asFunction(({ logger }) => makeErrorHandler(logger)).singleton(),\n\n\t\t// Auth - use prebuilt if provided, otherwise create from db\n\t\tauth: prebuilt?.auth\n\t\t\t? asValue(prebuilt.auth)\n\t\t\t: asFunction(({ db }) => createAuth({ db })).singleton(),\n\n\t\t// AI provider - use prebuilt if provided, otherwise lazy-load\n\t\taiProvider: prebuilt?.aiProvider\n\t\t\t? asValue(prebuilt.aiProvider)\n\t\t\t: asFunction(() => {\n\t\t\t\t\t// Lazy import to avoid loading @ai-sdk/google at module load time\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\t\t\t\tconst { google } = require('@ai-sdk/google')\n\t\t\t\t\treturn google('gemini-2.5-flash')\n\t\t\t\t}).singleton(),\n\n\t\t// Event bus\n\t\teventBus: asFunction(({ logger }) => new InMemoryEventBus(logger)).singleton(),\n\n\t\t// Stores - use factory functions that start cleanup timers\n\t\tcacheStore: asFunction(() => makeInMemoryCacheStore()).singleton(),\n\t\trateLimiterStore: asFunction(() => makeInMemoryRateLimiterStore()).singleton(),\n\n\t\t// Request-scoped logger (enriched with requestId and userId)\n\t\trequestLogger: asFunction(({ logger, requestId, session }) =>\n\t\t\tmakeRequestLogger({\n\t\t\t\trequestId,\n\t\t\t\tuserId: session?.user?.id,\n\t\t\t\tbaseLogger: logger,\n\t\t\t})\n\t\t).scoped(),\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,sBACZ,WACA,aACU;AACV,WAAU,SAAS;EAElB,QAAQ,UAAU,SACf,QAAQ,SAAS,OAAO,GACxB,YAAY,EAAE,aAAa,aAAa,OAAO,YAAY,CAAC,CAAC,WAAW;EAE3E,IAAI,UAAU,KACX,QAAQ,SAAS,GAAG,GACpB,YAAY,EAAE,aAAa,SAAS,OAAO,CAAC,CAAC,WAAW;EAG3D,OAAO,QAAQ,IAAI,aAAa,CAAC;EAEjC,QAAQ,YAAY,EAAE,aACrB,qBAAqB;GACpB,YAAY,OAAO;GACnB,QAAQ,OAAO;GACf,UAAU,OAAO;GACjB,CAAC,CACF,CAAC,WAAW;EAEb,cAAc,YAAY,EAAE,aAAa,iBAAiB,OAAO,CAAC,CAAC,WAAW;EAG9E,MAAM,UAAU,OACb,QAAQ,SAAS,KAAK,GACtB,YAAY,EAAE,SAAS,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,WAAW;EAGzD,YAAY,UAAU,aACnB,QAAQ,SAAS,WAAW,GAC5B,iBAAiB;GAGjB,MAAM,EAAE,qBAAmB,iBAAiB;AAC5C,UAAO,OAAO,mBAAmB;IAChC,CAAC,WAAW;EAGhB,UAAU,YAAY,EAAE,aAAa,IAAI,iBAAiB,OAAO,CAAC,CAAC,WAAW;EAG9E,YAAY,iBAAiB,wBAAwB,CAAC,CAAC,WAAW;EAClE,kBAAkB,iBAAiB,8BAA8B,CAAC,CAAC,WAAW;EAG9E,eAAe,YAAY,EAAE,QAAQ,WAAW,cAC/C,kBAAkB;GACjB;GACA,QAAQ,SAAS,MAAM;GACvB,YAAY;GACZ,CAAC,CACF,CAAC,QAAQ;EACV,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { n as CoreContainer } from "./types-TWbGQRnv.js";
|
|
2
|
+
import { n as PrebuiltDependencies } from "./container-BQ8Ow2Ot.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/core.module.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Register core infrastructure services into the container
|
|
8
|
+
*
|
|
9
|
+
* This registers:
|
|
10
|
+
* - Database pool and connection
|
|
11
|
+
* - Clock
|
|
12
|
+
* - Logger (structured, Loki/Prometheus compatible)
|
|
13
|
+
* - AI provider (optional - only if provided or API key available)
|
|
14
|
+
* - Auth
|
|
15
|
+
* - Event bus
|
|
16
|
+
* - Cache store
|
|
17
|
+
* - Rate limiter store
|
|
18
|
+
* - Request-scoped logger
|
|
19
|
+
*
|
|
20
|
+
* @param container - The Awilix container to register services into
|
|
21
|
+
* @param prebuilt - Optional pre-built dependencies to use instead of creating internally
|
|
22
|
+
*/
|
|
23
|
+
declare const registerCoreModule: (container: CoreContainer, prebuilt?: PrebuiltDependencies) => void;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { registerCoreModule as t };
|
|
26
|
+
//# sourceMappingURL=core.module-D8vH8AcY.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as KuckitConfig } from "./types-
|
|
1
|
+
import { n as KuckitConfig } from "./types-Ceg8XQY6.js";
|
|
2
2
|
|
|
3
3
|
//#region src/config/define-config.d.ts
|
|
4
4
|
|
|
@@ -31,4 +31,4 @@ import { n as KuckitConfig } from "./types-DxaDmkQo.js";
|
|
|
31
31
|
declare function defineConfig(config: KuckitConfig): KuckitConfig;
|
|
32
32
|
//#endregion
|
|
33
33
|
export { defineConfig as t };
|
|
34
|
-
//# sourceMappingURL=define-config-
|
|
34
|
+
//# sourceMappingURL=define-config-D-gChhM6.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-config-
|
|
1
|
+
{"version":3,"file":"define-config-fjqcYWfl.js","names":[],"sources":["../src/config/define-config.ts"],"sourcesContent":["import type { KuckitConfig } from './types'\n\n/**\n * Define a Kuckit configuration with full type safety.\n *\n * This helper provides IntelliSense support and type checking for your configuration.\n *\n * @example\n * ```typescript\n * // kuckit.config.ts\n * import { defineConfig } from '@kuckit/sdk'\n *\n * export default defineConfig({\n * modules: [\n * { package: '@kuckit/users-module' },\n * { package: '@acme/billing-module', config: { currency: 'USD' } },\n * ],\n *\n * server: {\n * apiPrefix: '/api',\n * },\n *\n * client: {\n * routeInjection: true,\n * },\n * })\n * ```\n */\nexport function defineConfig(config: KuckitConfig): KuckitConfig {\n\treturn config\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,aAAa,QAAoC;AAChE,QAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as KuckitModuleDefinition } from "./types-
|
|
1
|
+
import { i as KuckitModuleDefinition } from "./types-TrXzdvrM.js";
|
|
2
2
|
|
|
3
3
|
//#region src/modules/define-module.d.ts
|
|
4
4
|
|
|
@@ -53,4 +53,4 @@ import { i as KuckitModuleDefinition } from "./types-ByO301S-.js";
|
|
|
53
53
|
declare const defineKuckitModule: <TConfig = unknown>(mod: KuckitModuleDefinition<TConfig>) => KuckitModuleDefinition<TConfig>;
|
|
54
54
|
//#endregion
|
|
55
55
|
export { defineKuckitModule as t };
|
|
56
|
-
//# sourceMappingURL=define-module-
|
|
56
|
+
//# sourceMappingURL=define-module-CDZ2Cnss.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-module-
|
|
1
|
+
{"version":3,"file":"define-module-CzsWcVHH.js","names":[],"sources":["../src/modules/define-module.ts"],"sourcesContent":["import type { KuckitModuleDefinition } from './types'\n\n/**\n * Helper to define a Kuckit module with type safety\n *\n * This is the primary way to create a module for the Kuckit SDK.\n * It provides type inference for the configuration and validates\n * the module structure at compile time.\n *\n * @example\n * ```ts\n * // In your module's main file (e.g., src/module.ts)\n * import { defineKuckitModule, asClass, asFunction } from '@kuckit/sdk'\n *\n * interface BillingModuleConfig {\n * currency: string\n * taxRate: number\n * }\n *\n * export const kuckitModule = defineKuckitModule<BillingModuleConfig>({\n * id: 'acme.billing',\n * displayName: 'Billing',\n * description: 'Invoice and payment processing',\n * version: '1.0.0',\n *\n * register(ctx) {\n * ctx.container.register({\n * invoiceRepository: asClass(DrizzleInvoiceRepository).scoped(),\n * paymentService: asFunction(makePaymentService).singleton(),\n * })\n * },\n *\n * registerApi(ctx) {\n * ctx.addApiRegistration({\n * type: 'rpc-router',\n * name: 'billing',\n * router: createBillingRouter(ctx.container),\n * })\n * },\n *\n * onBootstrap(ctx) {\n * const logger = ctx.container.resolve('logger')\n * logger.info(`Billing module initialized with currency: ${ctx.config.currency}`)\n * },\n * })\n * ```\n *\n * @param mod - The module definition object\n * @returns The same module definition (for type inference)\n */\nexport const defineKuckitModule = <TConfig = unknown>(\n\tmod: KuckitModuleDefinition<TConfig>\n): KuckitModuleDefinition<TConfig> => {\n\t// Validate required fields\n\tif (!mod.id) {\n\t\tthrow new Error('Module must have an id')\n\t}\n\n\tif (typeof mod.id !== 'string' || mod.id.trim() === '') {\n\t\tthrow new Error('Module id must be a non-empty string')\n\t}\n\n\treturn mod\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAa,sBACZ,QACqC;AAErC,KAAI,CAAC,IAAI,GACR,OAAM,IAAI,MAAM,yBAAyB;AAG1C,KAAI,OAAO,IAAI,OAAO,YAAY,IAAI,GAAG,MAAM,KAAK,GACnD,OAAM,IAAI,MAAM,uCAAuC;AAGxD,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { a as KuckitServerConfig, i as KuckitModuleConfig, n as KuckitConfig, o as LoadedKuckitConfig, r as KuckitDiscoveryConfig, t as KuckitClientConfig } from "./types-
|
|
2
|
-
import { t as defineConfig } from "./define-config-
|
|
3
|
-
import {
|
|
4
|
-
import "./index-
|
|
5
|
-
import { n as CoreContainer, r as CoreCradle, t as CoreConfig } from "./types-
|
|
6
|
-
import { n as
|
|
7
|
-
import { t as registerCoreModule } from "./core.module-
|
|
8
|
-
import { a as KuckitModuleHooks, c as ModuleCapability, i as KuckitModuleDefinition, l as ModuleSpec, n as BuiltInCapability, o as KuckitModuleMeta, r as KuckitModuleContext, t as ApiRegistration } from "./types-
|
|
9
|
-
import { t as defineKuckitModule } from "./define-module-
|
|
10
|
-
import { n as createModuleShutdownHandler, r as loadKuckitModules, t as LoadModulesOptions } from "./loader-
|
|
11
|
-
import { a as resetModuleRegistry, i as getModulesWithCapability, n as ModuleRegistry, r as getModuleRegistry, t as LoadedModuleInfo } from "./registry-
|
|
12
|
-
import "./index-
|
|
13
|
-
import { i as resetSchemaRegistry, n as SchemaRegistry, r as getSchemaRegistry, t as SchemaEntry } from "./registry-
|
|
14
|
-
import { t as PgTable } from "./index-
|
|
1
|
+
import { a as KuckitServerConfig, i as KuckitModuleConfig, n as KuckitConfig, o as LoadedKuckitConfig, r as KuckitDiscoveryConfig, t as KuckitClientConfig } from "./types-Ceg8XQY6.js";
|
|
2
|
+
import { t as defineConfig } from "./define-config-D-gChhM6.js";
|
|
3
|
+
import { a as tryLoadKuckitConfig, n as hasUnifiedConfig, r as loadKuckitConfig, t as findConfigFile } from "./loader-0s9nW_Uz.js";
|
|
4
|
+
import "./index-C9nY9t1j.js";
|
|
5
|
+
import { n as CoreContainer, r as CoreCradle, t as CoreConfig } from "./types-TWbGQRnv.js";
|
|
6
|
+
import { i as disposeContainer, n as PrebuiltDependencies, r as createKuckitContainer, t as CreateKuckitOptions } from "./container-BQ8Ow2Ot.js";
|
|
7
|
+
import { t as registerCoreModule } from "./core.module-D8vH8AcY.js";
|
|
8
|
+
import { a as KuckitModuleHooks, c as ModuleCapability, i as KuckitModuleDefinition, l as ModuleSpec, n as BuiltInCapability, o as KuckitModuleMeta, r as KuckitModuleContext, t as ApiRegistration } from "./types-TrXzdvrM.js";
|
|
9
|
+
import { t as defineKuckitModule } from "./define-module-CDZ2Cnss.js";
|
|
10
|
+
import { n as createModuleShutdownHandler, r as loadKuckitModules, t as LoadModulesOptions } from "./loader-Do1M_26D.js";
|
|
11
|
+
import { a as resetModuleRegistry, i as getModulesWithCapability, n as ModuleRegistry, r as getModuleRegistry, t as LoadedModuleInfo } from "./registry-9FKJPjuY.js";
|
|
12
|
+
import "./index-E7Wvm5uX.js";
|
|
13
|
+
import { i as resetSchemaRegistry, n as SchemaRegistry, r as getSchemaRegistry, t as SchemaEntry } from "./registry-BwUbpLWo.js";
|
|
14
|
+
import { t as PgTable } from "./index-BLsEv2uZ.js";
|
|
15
15
|
import { AwilixContainer, Resolver, asClass, asFunction, asValue } from "awilix";
|
|
16
16
|
import * as Domain from "@kuckit/domain";
|
|
17
17
|
import * as Application from "@kuckit/application";
|
|
18
18
|
import * as Contracts from "@kuckit/contracts";
|
|
19
|
-
export { type ApiRegistration, Application, type AwilixContainer, type BuiltInCapability, Contracts, type CoreConfig, type CoreContainer, type CoreCradle, type CreateKuckitOptions, Domain, type KuckitClientConfig, type KuckitConfig, type KuckitDiscoveryConfig, type KuckitModuleConfig, type KuckitModuleContext, type KuckitModuleDefinition, type KuckitModuleHooks, type KuckitModuleMeta, type KuckitServerConfig, type LoadModulesOptions, type LoadedKuckitConfig, type LoadedModuleInfo, type ModuleCapability, ModuleRegistry, type ModuleSpec, type PgTable, type Resolver, type SchemaEntry, SchemaRegistry, asClass, asFunction, asValue, createKuckitContainer, createModuleShutdownHandler, defineConfig, defineKuckitModule, disposeContainer, findConfigFile, getModuleRegistry, getModulesWithCapability, getSchemaRegistry, hasUnifiedConfig, loadKuckitConfig, loadKuckitModules, registerCoreModule, resetModuleRegistry, resetSchemaRegistry, tryLoadKuckitConfig };
|
|
19
|
+
export { type ApiRegistration, Application, type AwilixContainer, type BuiltInCapability, Contracts, type CoreConfig, type CoreContainer, type CoreCradle, type CreateKuckitOptions, Domain, type KuckitClientConfig, type KuckitConfig, type KuckitDiscoveryConfig, type KuckitModuleConfig, type KuckitModuleContext, type KuckitModuleDefinition, type KuckitModuleHooks, type KuckitModuleMeta, type KuckitServerConfig, type LoadModulesOptions, type LoadedKuckitConfig, type LoadedModuleInfo, type ModuleCapability, ModuleRegistry, type ModuleSpec, type PgTable, type PrebuiltDependencies, type Resolver, type SchemaEntry, SchemaRegistry, asClass, asFunction, asValue, createKuckitContainer, createModuleShutdownHandler, defineConfig, defineKuckitModule, disposeContainer, findConfigFile, getModuleRegistry, getModulesWithCapability, getSchemaRegistry, hasUnifiedConfig, loadKuckitConfig, loadKuckitModules, registerCoreModule, resetModuleRegistry, resetSchemaRegistry, tryLoadKuckitConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { t as registerCoreModule } from "./core.module-
|
|
2
|
-
import { n as disposeContainer, t as createKuckitContainer } from "./container-
|
|
3
|
-
import { t as defineKuckitModule } from "./define-module-
|
|
4
|
-
import { i as resetModuleRegistry, n as getModuleRegistry, r as getModulesWithCapability, t as ModuleRegistry } from "./registry-
|
|
5
|
-
import { n as getSchemaRegistry, r as resetSchemaRegistry, t as SchemaRegistry } from "./registry-
|
|
6
|
-
import "./schema-
|
|
7
|
-
import { n as loadKuckitModules, t as createModuleShutdownHandler } from "./loader-
|
|
8
|
-
import "./modules-
|
|
9
|
-
import { t as defineConfig } from "./define-config-
|
|
10
|
-
import {
|
|
11
|
-
import "./config-
|
|
1
|
+
import { t as registerCoreModule } from "./core.module-47w_x8z-.js";
|
|
2
|
+
import { n as disposeContainer, t as createKuckitContainer } from "./container-Ct2UXGF_.js";
|
|
3
|
+
import { t as defineKuckitModule } from "./define-module-CzsWcVHH.js";
|
|
4
|
+
import { i as resetModuleRegistry, n as getModuleRegistry, r as getModulesWithCapability, t as ModuleRegistry } from "./registry-DMY4gCiz.js";
|
|
5
|
+
import { n as getSchemaRegistry, r as resetSchemaRegistry, t as SchemaRegistry } from "./registry-B62Oueqd.js";
|
|
6
|
+
import "./schema-C94Ei_S4.js";
|
|
7
|
+
import { n as loadKuckitModules, t as createModuleShutdownHandler } from "./loader-BZuTuluL.js";
|
|
8
|
+
import "./modules-CQFGHC4e.js";
|
|
9
|
+
import { t as defineConfig } from "./define-config-fjqcYWfl.js";
|
|
10
|
+
import { a as tryLoadKuckitConfig, n as hasUnifiedConfig, r as loadKuckitConfig, t as findConfigFile } from "./loader-DKhFYG5d.js";
|
|
11
|
+
import "./config-Dwl_qu6x.js";
|
|
12
12
|
import { asClass, asFunction, asValue } from "awilix";
|
|
13
13
|
import * as Domain from "@kuckit/domain";
|
|
14
14
|
import * as Application from "@kuckit/application";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as LoadedKuckitConfig } from "./types-
|
|
1
|
+
import { o as LoadedKuckitConfig } from "./types-Ceg8XQY6.js";
|
|
2
2
|
|
|
3
3
|
//#region src/config/loader.d.ts
|
|
4
4
|
|
|
@@ -20,10 +20,15 @@ declare function hasUnifiedConfig(cwd?: string): boolean;
|
|
|
20
20
|
* @throws Error if config file not found or invalid
|
|
21
21
|
*/
|
|
22
22
|
declare function loadKuckitConfig(cwd?: string): Promise<LoadedKuckitConfig>;
|
|
23
|
+
/**
|
|
24
|
+
* Synchronously load config (for non-async contexts like drizzle.config.ts)
|
|
25
|
+
* Uses jiti synchronously to load TypeScript config
|
|
26
|
+
*/
|
|
27
|
+
declare function loadKuckitConfigSync(cwd?: string): LoadedKuckitConfig | null;
|
|
23
28
|
/**
|
|
24
29
|
* Try to load config, returning null if not found
|
|
25
30
|
*/
|
|
26
31
|
declare function tryLoadKuckitConfig(cwd?: string): Promise<LoadedKuckitConfig | null>;
|
|
27
32
|
//#endregion
|
|
28
|
-
export { tryLoadKuckitConfig as i, hasUnifiedConfig as n, loadKuckitConfig as r, findConfigFile as t };
|
|
29
|
-
//# sourceMappingURL=loader-
|
|
33
|
+
export { tryLoadKuckitConfig as a, loadKuckitConfigSync as i, hasUnifiedConfig as n, loadKuckitConfig as r, findConfigFile as t };
|
|
34
|
+
//# sourceMappingURL=loader-0s9nW_Uz.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as getModuleRegistry } from "./registry-
|
|
2
|
-
import { n as getSchemaRegistry } from "./registry-
|
|
1
|
+
import { n as getModuleRegistry } from "./registry-DMY4gCiz.js";
|
|
2
|
+
import { n as getSchemaRegistry } from "./registry-B62Oueqd.js";
|
|
3
3
|
|
|
4
4
|
//#region src/modules/loader.ts
|
|
5
5
|
/**
|
|
@@ -174,4 +174,4 @@ const createModuleShutdownHandler = (modules, container, env) => {
|
|
|
174
174
|
|
|
175
175
|
//#endregion
|
|
176
176
|
export { loadKuckitModules as n, createModuleShutdownHandler as t };
|
|
177
|
-
//# sourceMappingURL=loader-
|
|
177
|
+
//# sourceMappingURL=loader-BZuTuluL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-Ct4ZivZz.js","names":["apiRegistrations: ApiRegistration[]","loadedModules: LoadedModule[]","validated: KuckitModuleDefinition","imported: Record<string, unknown>"],"sources":["../src/modules/loader.ts"],"sourcesContent":["import type { CoreContainer } from '../types'\nimport type { KuckitModuleDefinition, ApiRegistration, ModuleSpec, LoadedModule } from './types'\nimport { getModuleRegistry } from './registry'\nimport { getSchemaRegistry } from '../schema'\n\nexport interface LoadModulesOptions {\n\t/** DI container to register services into */\n\tcontainer: CoreContainer\n\t/** Environment name (development, production, etc.) */\n\tenv: string\n\t/** List of modules to load */\n\tmodules: ModuleSpec[]\n\t/** Hook to wire collected API registrations into your router */\n\tonApiRegistrations?: (regs: ApiRegistration[]) => void | Promise<void>\n\t/** Hook called when all modules are loaded and bootstrapped */\n\tonComplete?: () => void | Promise<void>\n}\n\n/**\n * Validates that a module has the correct shape\n */\nconst validateModule = (candidate: unknown, packageName: string): KuckitModuleDefinition => {\n\tif (!candidate || typeof candidate !== 'object') {\n\t\tthrow new Error(\n\t\t\t`Invalid Kuckit module from \"${packageName}\": expected an object with module definition`\n\t\t)\n\t}\n\n\tconst mod = candidate as Record<string, unknown>\n\n\tif (!mod.id || typeof mod.id !== 'string') {\n\t\tthrow new Error(`Invalid Kuckit module from \"${packageName}\": missing or invalid 'id' property`)\n\t}\n\n\t// Validate hook types if present\n\tconst hookNames = ['register', 'registerApi', 'onBootstrap', 'onShutdown']\n\tfor (const hookName of hookNames) {\n\t\tif (mod[hookName] !== undefined && typeof mod[hookName] !== 'function') {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid Kuckit module from \"${packageName}\": '${hookName}' must be a function`\n\t\t\t)\n\t\t}\n\t}\n\n\treturn mod as unknown as KuckitModuleDefinition\n}\n\n/**\n * Load and initialize Kuckit modules\n *\n * This function orchestrates the module loading lifecycle:\n *\n * 1. **Import Phase**: Dynamic import each module package\n * 2. **Register Phase**: Run register() hooks (DI bindings)\n * 3. **API Phase**: Run registerApi() hooks (API routes)\n * 4. **Wire Phase**: Call onApiRegistrations callback\n * 5. **Bootstrap Phase**: Run onBootstrap() hooks\n * 6. **Complete Phase**: Call onComplete callback\n *\n * @example\n * ```ts\n * await loadKuckitModules({\n * container,\n * env: 'production',\n * modules: [\n * { package: '@kuckit/users-module' },\n * { package: '@acme/billing-module', config: { currency: 'USD' } },\n * { package: './src/modules/custom', disabled: process.env.DISABLE_CUSTOM === 'true' },\n * ],\n * onApiRegistrations: (registrations) => {\n * // Wire up oRPC routers, REST routes, etc.\n * for (const reg of registrations) {\n * if (reg.type === 'rpc-router') {\n * rootRouter.merge(reg.name, reg.router)\n * }\n * }\n * },\n * onComplete: () => {\n * console.log('All modules loaded!')\n * },\n * })\n * ```\n */\nexport const loadKuckitModules = async (opts: LoadModulesOptions): Promise<void> => {\n\tconst { container, env, modules, onApiRegistrations, onComplete } = opts\n\n\tconst apiRegistrations: ApiRegistration[] = []\n\tconst loadedModules: LoadedModule[] = []\n\tconst registry = getModuleRegistry()\n\n\t// Phase 1: Import and validate all modules\n\tfor (const spec of modules) {\n\t\tif (spec.disabled) {\n\t\t\tcontinue\n\t\t}\n\n\t\tlet validated: KuckitModuleDefinition\n\n\t\t// Prefer direct module reference over dynamic import\n\t\tif (spec.module) {\n\t\t\tvalidated = validateModule(spec.module, spec.module.id ?? 'direct-module')\n\t\t} else if (spec.package) {\n\t\t\tlet imported: Record<string, unknown>\n\t\t\ttry {\n\t\t\t\timported = await import(spec.package)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Failed to import module \"${spec.package}\": ${message}`)\n\t\t\t}\n\n\t\t\t// Look for kuckitModule export (preferred) or default export\n\t\t\tconst candidate = imported.kuckitModule ?? imported.default\n\t\t\tvalidated = validateModule(candidate, spec.package)\n\t\t} else {\n\t\t\tthrow new Error('ModuleSpec must have either \"module\" or \"package\" property')\n\t\t}\n\n\t\t// Register module in the global registry (validates capabilities)\n\t\tregistry.register(validated)\n\n\t\tloadedModules.push({ ...validated, _config: spec.config })\n\t}\n\n\t// Phase 2: Run register() hooks\n\tfor (const mod of loadedModules) {\n\t\tif (mod.register) {\n\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\tconst ctx = {\n\t\t\t\tcontainer,\n\t\t\t\tenv,\n\t\t\t\tconfig: mod._config ?? {},\n\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait mod.register(ctx)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Module \"${mod.id}\" register() failed: ${message}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Phase 3: Run registerApi() hooks\n\tfor (const mod of loadedModules) {\n\t\tif (mod.registerApi) {\n\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\tconst ctx = {\n\t\t\t\tcontainer,\n\t\t\t\tenv,\n\t\t\t\tconfig: mod._config ?? {},\n\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\taddApiRegistration: (reg: ApiRegistration) => {\n\t\t\t\t\tapiRegistrations.push(reg)\n\t\t\t\t},\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait mod.registerApi(ctx)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Module \"${mod.id}\" registerApi() failed: ${message}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Phase 4: Wire API registrations\n\tif (onApiRegistrations && apiRegistrations.length > 0) {\n\t\tawait onApiRegistrations(apiRegistrations)\n\t}\n\n\t// Phase 5: Run onBootstrap() hooks\n\tfor (const mod of loadedModules) {\n\t\tif (mod.onBootstrap) {\n\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\tconst ctx = {\n\t\t\t\tcontainer,\n\t\t\t\tenv,\n\t\t\t\tconfig: mod._config ?? {},\n\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait mod.onBootstrap(ctx)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Module \"${mod.id}\" onBootstrap() failed: ${message}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Phase 6: Complete\n\tif (onComplete) {\n\t\tawait onComplete()\n\t}\n}\n\n/**\n * Create a shutdown handler for loaded modules\n *\n * Returns a function that calls onShutdown() on all modules in reverse order.\n * Call this during graceful shutdown.\n *\n * @example\n * ```ts\n * const shutdown = createModuleShutdownHandler(loadedModules, container, env)\n *\n * process.on('SIGTERM', async () => {\n * await shutdown()\n * process.exit(0)\n * })\n * ```\n */\nexport const createModuleShutdownHandler = (\n\tmodules: KuckitModuleDefinition[],\n\tcontainer: CoreContainer,\n\tenv: string\n): (() => Promise<void>) => {\n\treturn async () => {\n\t\t// Shutdown in reverse order\n\t\tfor (const mod of [...modules].reverse()) {\n\t\t\tif (mod.onShutdown) {\n\t\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\t\tconst ctx = {\n\t\t\t\t\tcontainer,\n\t\t\t\t\tenv,\n\t\t\t\t\tconfig: {},\n\t\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\t\ttableName,\n\t\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tawait mod.onShutdown(ctx)\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Log but don't throw during shutdown\n\t\t\t\t\tconsole.error(`Module \"${mod.id}\" onShutdown() failed:`, error)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"loader-BZuTuluL.js","names":["apiRegistrations: ApiRegistration[]","loadedModules: LoadedModule[]","validated: KuckitModuleDefinition","imported: Record<string, unknown>"],"sources":["../src/modules/loader.ts"],"sourcesContent":["import type { CoreContainer } from '../types'\nimport type { KuckitModuleDefinition, ApiRegistration, ModuleSpec, LoadedModule } from './types'\nimport { getModuleRegistry } from './registry'\nimport { getSchemaRegistry } from '../schema'\n\nexport interface LoadModulesOptions {\n\t/** DI container to register services into */\n\tcontainer: CoreContainer\n\t/** Environment name (development, production, etc.) */\n\tenv: string\n\t/** List of modules to load */\n\tmodules: ModuleSpec[]\n\t/** Hook to wire collected API registrations into your router */\n\tonApiRegistrations?: (regs: ApiRegistration[]) => void | Promise<void>\n\t/** Hook called when all modules are loaded and bootstrapped */\n\tonComplete?: () => void | Promise<void>\n}\n\n/**\n * Validates that a module has the correct shape\n */\nconst validateModule = (candidate: unknown, packageName: string): KuckitModuleDefinition => {\n\tif (!candidate || typeof candidate !== 'object') {\n\t\tthrow new Error(\n\t\t\t`Invalid Kuckit module from \"${packageName}\": expected an object with module definition`\n\t\t)\n\t}\n\n\tconst mod = candidate as Record<string, unknown>\n\n\tif (!mod.id || typeof mod.id !== 'string') {\n\t\tthrow new Error(`Invalid Kuckit module from \"${packageName}\": missing or invalid 'id' property`)\n\t}\n\n\t// Validate hook types if present\n\tconst hookNames = ['register', 'registerApi', 'onBootstrap', 'onShutdown']\n\tfor (const hookName of hookNames) {\n\t\tif (mod[hookName] !== undefined && typeof mod[hookName] !== 'function') {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid Kuckit module from \"${packageName}\": '${hookName}' must be a function`\n\t\t\t)\n\t\t}\n\t}\n\n\treturn mod as unknown as KuckitModuleDefinition\n}\n\n/**\n * Load and initialize Kuckit modules\n *\n * This function orchestrates the module loading lifecycle:\n *\n * 1. **Import Phase**: Dynamic import each module package\n * 2. **Register Phase**: Run register() hooks (DI bindings)\n * 3. **API Phase**: Run registerApi() hooks (API routes)\n * 4. **Wire Phase**: Call onApiRegistrations callback\n * 5. **Bootstrap Phase**: Run onBootstrap() hooks\n * 6. **Complete Phase**: Call onComplete callback\n *\n * @example\n * ```ts\n * await loadKuckitModules({\n * container,\n * env: 'production',\n * modules: [\n * { package: '@kuckit/users-module' },\n * { package: '@acme/billing-module', config: { currency: 'USD' } },\n * { package: './src/modules/custom', disabled: process.env.DISABLE_CUSTOM === 'true' },\n * ],\n * onApiRegistrations: (registrations) => {\n * // Wire up oRPC routers, REST routes, etc.\n * for (const reg of registrations) {\n * if (reg.type === 'rpc-router') {\n * rootRouter.merge(reg.name, reg.router)\n * }\n * }\n * },\n * onComplete: () => {\n * console.log('All modules loaded!')\n * },\n * })\n * ```\n */\nexport const loadKuckitModules = async (opts: LoadModulesOptions): Promise<void> => {\n\tconst { container, env, modules, onApiRegistrations, onComplete } = opts\n\n\tconst apiRegistrations: ApiRegistration[] = []\n\tconst loadedModules: LoadedModule[] = []\n\tconst registry = getModuleRegistry()\n\n\t// Phase 1: Import and validate all modules\n\tfor (const spec of modules) {\n\t\tif (spec.disabled) {\n\t\t\tcontinue\n\t\t}\n\n\t\tlet validated: KuckitModuleDefinition\n\n\t\t// Prefer direct module reference over dynamic import\n\t\tif (spec.module) {\n\t\t\tvalidated = validateModule(spec.module, spec.module.id ?? 'direct-module')\n\t\t} else if (spec.package) {\n\t\t\tlet imported: Record<string, unknown>\n\t\t\ttry {\n\t\t\t\timported = await import(spec.package)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Failed to import module \"${spec.package}\": ${message}`)\n\t\t\t}\n\n\t\t\t// Look for kuckitModule export (preferred) or default export\n\t\t\tconst candidate = imported.kuckitModule ?? imported.default\n\t\t\tvalidated = validateModule(candidate, spec.package)\n\t\t} else {\n\t\t\tthrow new Error('ModuleSpec must have either \"module\" or \"package\" property')\n\t\t}\n\n\t\t// Register module in the global registry (validates capabilities)\n\t\tregistry.register(validated)\n\n\t\tloadedModules.push({ ...validated, _config: spec.config })\n\t}\n\n\t// Phase 2: Run register() hooks\n\tfor (const mod of loadedModules) {\n\t\tif (mod.register) {\n\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\tconst ctx = {\n\t\t\t\tcontainer,\n\t\t\t\tenv,\n\t\t\t\tconfig: mod._config ?? {},\n\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait mod.register(ctx)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Module \"${mod.id}\" register() failed: ${message}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Phase 3: Run registerApi() hooks\n\tfor (const mod of loadedModules) {\n\t\tif (mod.registerApi) {\n\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\tconst ctx = {\n\t\t\t\tcontainer,\n\t\t\t\tenv,\n\t\t\t\tconfig: mod._config ?? {},\n\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\taddApiRegistration: (reg: ApiRegistration) => {\n\t\t\t\t\tapiRegistrations.push(reg)\n\t\t\t\t},\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait mod.registerApi(ctx)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Module \"${mod.id}\" registerApi() failed: ${message}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Phase 4: Wire API registrations\n\tif (onApiRegistrations && apiRegistrations.length > 0) {\n\t\tawait onApiRegistrations(apiRegistrations)\n\t}\n\n\t// Phase 5: Run onBootstrap() hooks\n\tfor (const mod of loadedModules) {\n\t\tif (mod.onBootstrap) {\n\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\tconst ctx = {\n\t\t\t\tcontainer,\n\t\t\t\tenv,\n\t\t\t\tconfig: mod._config ?? {},\n\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait mod.onBootstrap(ctx)\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error)\n\t\t\t\tthrow new Error(`Module \"${mod.id}\" onBootstrap() failed: ${message}`)\n\t\t\t}\n\t\t}\n\t}\n\n\t// Phase 6: Complete\n\tif (onComplete) {\n\t\tawait onComplete()\n\t}\n}\n\n/**\n * Create a shutdown handler for loaded modules\n *\n * Returns a function that calls onShutdown() on all modules in reverse order.\n * Call this during graceful shutdown.\n *\n * @example\n * ```ts\n * const shutdown = createModuleShutdownHandler(loadedModules, container, env)\n *\n * process.on('SIGTERM', async () => {\n * await shutdown()\n * process.exit(0)\n * })\n * ```\n */\nexport const createModuleShutdownHandler = (\n\tmodules: KuckitModuleDefinition[],\n\tcontainer: CoreContainer,\n\tenv: string\n): (() => Promise<void>) => {\n\treturn async () => {\n\t\t// Shutdown in reverse order\n\t\tfor (const mod of [...modules].reverse()) {\n\t\t\tif (mod.onShutdown) {\n\t\t\t\tconst schemaRegistry = getSchemaRegistry()\n\t\t\t\tconst ctx = {\n\t\t\t\t\tcontainer,\n\t\t\t\t\tenv,\n\t\t\t\t\tconfig: {},\n\t\t\t\t\tregisterSchema: (tableName: string, schema: unknown) => {\n\t\t\t\t\t\tschemaRegistry.register(\n\t\t\t\t\t\t\tmod.id,\n\t\t\t\t\t\t\ttableName,\n\t\t\t\t\t\t\tschema as import('drizzle-orm/pg-core').PgTable\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tawait mod.onShutdown(ctx)\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Log but don't throw during shutdown\n\t\t\t\t\tconsole.error(`Module \"${mod.id}\" onShutdown() failed:`, error)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"mappings":"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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as __require } from "./chunk-B1JASekH.js";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import { dirname, resolve } from "node:path";
|
|
3
4
|
|
|
@@ -60,6 +61,26 @@ async function loadKuckitConfig(cwd = process.cwd()) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
64
|
+
* Synchronously load config (for non-async contexts like drizzle.config.ts)
|
|
65
|
+
* Uses jiti synchronously to load TypeScript config
|
|
66
|
+
*/
|
|
67
|
+
function loadKuckitConfigSync(cwd = process.cwd()) {
|
|
68
|
+
const configPath = findConfigFile(cwd);
|
|
69
|
+
if (!configPath) return null;
|
|
70
|
+
try {
|
|
71
|
+
const { createJiti } = __require("jiti");
|
|
72
|
+
const loaded = createJiti(cwd, { interopDefault: true })(configPath);
|
|
73
|
+
const config = loaded.default ?? loaded;
|
|
74
|
+
if (!config || typeof config !== "object" || !Array.isArray(config.modules)) return null;
|
|
75
|
+
return {
|
|
76
|
+
...config,
|
|
77
|
+
_configPath: configPath
|
|
78
|
+
};
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
63
84
|
* Try to load config, returning null if not found
|
|
64
85
|
*/
|
|
65
86
|
async function tryLoadKuckitConfig(cwd = process.cwd()) {
|
|
@@ -71,5 +92,5 @@ async function tryLoadKuckitConfig(cwd = process.cwd()) {
|
|
|
71
92
|
}
|
|
72
93
|
|
|
73
94
|
//#endregion
|
|
74
|
-
export { tryLoadKuckitConfig as i, hasUnifiedConfig as n, loadKuckitConfig as r, findConfigFile as t };
|
|
75
|
-
//# sourceMappingURL=loader-
|
|
95
|
+
export { tryLoadKuckitConfig as a, loadKuckitConfigSync as i, hasUnifiedConfig as n, loadKuckitConfig as r, findConfigFile as t };
|
|
96
|
+
//# sourceMappingURL=loader-DKhFYG5d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-DKhFYG5d.js","names":["config: KuckitConfig"],"sources":["../src/config/loader.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { resolve, dirname } from 'node:path'\nimport type { KuckitConfig, LoadedKuckitConfig } from './types'\n\nconst CONFIG_FILES = ['kuckit.config.ts', 'kuckit.config.js', 'kuckit.config.mjs']\n\n/**\n * Find the config file path by searching from cwd upward\n */\nexport function findConfigFile(cwd: string = process.cwd()): string | null {\n\tlet dir = cwd\n\n\twhile (dir !== dirname(dir)) {\n\t\tfor (const file of CONFIG_FILES) {\n\t\t\tconst configPath = resolve(dir, file)\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\treturn configPath\n\t\t\t}\n\t\t}\n\t\tdir = dirname(dir)\n\t}\n\n\t// Check root directory\n\tfor (const file of CONFIG_FILES) {\n\t\tconst configPath = resolve(dir, file)\n\t\tif (existsSync(configPath)) {\n\t\t\treturn configPath\n\t\t}\n\t}\n\n\treturn null\n}\n\n/**\n * Check if a unified config file exists\n */\nexport function hasUnifiedConfig(cwd: string = process.cwd()): boolean {\n\treturn findConfigFile(cwd) !== null\n}\n\n/**\n * Load Kuckit configuration from file\n *\n * Uses jiti for TypeScript support at runtime.\n * Falls back to dynamic import for JS/MJS files.\n *\n * @param cwd - Directory to start searching from (default: process.cwd())\n * @throws Error if config file not found or invalid\n */\nexport async function loadKuckitConfig(cwd: string = process.cwd()): Promise<LoadedKuckitConfig> {\n\tconst configPath = findConfigFile(cwd)\n\n\tif (!configPath) {\n\t\tthrow new Error(\n\t\t\t`No Kuckit config file found. Create a kuckit.config.ts at your project root.\\n` +\n\t\t\t\t`Searched from: ${cwd}`\n\t\t)\n\t}\n\n\tlet config: KuckitConfig\n\n\tif (configPath.endsWith('.ts')) {\n\t\t// Use jiti for TypeScript files\n\t\tconst { createJiti } = await import('jiti')\n\t\tconst jiti = createJiti(cwd, {\n\t\t\tinteropDefault: true,\n\t\t})\n\t\tconst loaded = await jiti.import(configPath)\n\t\tconfig = (loaded as { default?: KuckitConfig }).default ?? (loaded as KuckitConfig)\n\t} else {\n\t\t// Use dynamic import for JS/MJS\n\t\tconst loaded = await import(configPath)\n\t\tconfig = loaded.default ?? loaded\n\t}\n\n\t// Validate config\n\tif (!config || typeof config !== 'object') {\n\t\tthrow new Error(`Invalid Kuckit config at ${configPath}: expected an object`)\n\t}\n\n\tif (!Array.isArray(config.modules)) {\n\t\tthrow new Error(`Invalid Kuckit config at ${configPath}: 'modules' must be an array`)\n\t}\n\n\treturn {\n\t\t...config,\n\t\t_configPath: configPath,\n\t}\n}\n\n/**\n * Synchronously load config (for non-async contexts like drizzle.config.ts)\n * Uses jiti synchronously to load TypeScript config\n */\nexport function loadKuckitConfigSync(cwd: string = process.cwd()): LoadedKuckitConfig | null {\n\tconst configPath = findConfigFile(cwd)\n\n\tif (!configPath) {\n\t\treturn null\n\t}\n\n\ttry {\n\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports\n\t\tconst { createJiti } = require('jiti')\n\t\tconst jiti = createJiti(cwd, {\n\t\t\tinteropDefault: true,\n\t\t})\n\t\tconst loaded = jiti(configPath)\n\t\tconst config: KuckitConfig = loaded.default ?? loaded\n\n\t\tif (!config || typeof config !== 'object' || !Array.isArray(config.modules)) {\n\t\t\treturn null\n\t\t}\n\n\t\treturn {\n\t\t\t...config,\n\t\t\t_configPath: configPath,\n\t\t}\n\t} catch {\n\t\treturn null\n\t}\n}\n\n/**\n * Try to load config, returning null if not found\n */\nexport async function tryLoadKuckitConfig(\n\tcwd: string = process.cwd()\n): Promise<LoadedKuckitConfig | null> {\n\ttry {\n\t\treturn await loadKuckitConfig(cwd)\n\t} catch {\n\t\treturn null\n\t}\n}\n"],"mappings":";;;;;AAIA,MAAM,eAAe;CAAC;CAAoB;CAAoB;CAAoB;;;;AAKlF,SAAgB,eAAe,MAAc,QAAQ,KAAK,EAAiB;CAC1E,IAAI,MAAM;AAEV,QAAO,QAAQ,QAAQ,IAAI,EAAE;AAC5B,OAAK,MAAM,QAAQ,cAAc;GAChC,MAAM,aAAa,QAAQ,KAAK,KAAK;AACrC,OAAI,WAAW,WAAW,CACzB,QAAO;;AAGT,QAAM,QAAQ,IAAI;;AAInB,MAAK,MAAM,QAAQ,cAAc;EAChC,MAAM,aAAa,QAAQ,KAAK,KAAK;AACrC,MAAI,WAAW,WAAW,CACzB,QAAO;;AAIT,QAAO;;;;;AAMR,SAAgB,iBAAiB,MAAc,QAAQ,KAAK,EAAW;AACtE,QAAO,eAAe,IAAI,KAAK;;;;;;;;;;;AAYhC,eAAsB,iBAAiB,MAAc,QAAQ,KAAK,EAA+B;CAChG,MAAM,aAAa,eAAe,IAAI;AAEtC,KAAI,CAAC,WACJ,OAAM,IAAI,MACT,gGACmB,MACnB;CAGF,IAAIA;AAEJ,KAAI,WAAW,SAAS,MAAM,EAAE;EAE/B,MAAM,EAAE,eAAe,MAAM,OAAO;EAIpC,MAAM,SAAS,MAHF,WAAW,KAAK,EAC5B,gBAAgB,MAChB,CAAC,CACwB,OAAO,WAAW;AAC5C,WAAU,OAAsC,WAAY;QACtD;EAEN,MAAM,SAAS,MAAM,OAAO;AAC5B,WAAS,OAAO,WAAW;;AAI5B,KAAI,CAAC,UAAU,OAAO,WAAW,SAChC,OAAM,IAAI,MAAM,4BAA4B,WAAW,sBAAsB;AAG9E,KAAI,CAAC,MAAM,QAAQ,OAAO,QAAQ,CACjC,OAAM,IAAI,MAAM,4BAA4B,WAAW,8BAA8B;AAGtF,QAAO;EACN,GAAG;EACH,aAAa;EACb;;;;;;AAOF,SAAgB,qBAAqB,MAAc,QAAQ,KAAK,EAA6B;CAC5F,MAAM,aAAa,eAAe,IAAI;AAEtC,KAAI,CAAC,WACJ,QAAO;AAGR,KAAI;EAEH,MAAM,EAAE,yBAAuB,OAAO;EAItC,MAAM,SAHO,WAAW,KAAK,EAC5B,gBAAgB,MAChB,CAAC,CACkB,WAAW;EAC/B,MAAMA,SAAuB,OAAO,WAAW;AAE/C,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,CAAC,MAAM,QAAQ,OAAO,QAAQ,CAC1E,QAAO;AAGR,SAAO;GACN,GAAG;GACH,aAAa;GACb;SACM;AACP,SAAO;;;;;;AAOT,eAAsB,oBACrB,MAAc,QAAQ,KAAK,EACU;AACrC,KAAI;AACH,SAAO,MAAM,iBAAiB,IAAI;SAC3B;AACP,SAAO"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as CoreContainer } from "./types-
|
|
2
|
-
import { i as KuckitModuleDefinition, l as ModuleSpec, t as ApiRegistration } from "./types-
|
|
1
|
+
import { n as CoreContainer } from "./types-TWbGQRnv.js";
|
|
2
|
+
import { i as KuckitModuleDefinition, l as ModuleSpec, t as ApiRegistration } from "./types-TrXzdvrM.js";
|
|
3
3
|
|
|
4
4
|
//#region src/modules/loader.d.ts
|
|
5
5
|
interface LoadModulesOptions {
|
|
@@ -70,4 +70,4 @@ declare const loadKuckitModules: (opts: LoadModulesOptions) => Promise<void>;
|
|
|
70
70
|
declare const createModuleShutdownHandler: (modules: KuckitModuleDefinition[], container: CoreContainer, env: string) => (() => Promise<void>);
|
|
71
71
|
//#endregion
|
|
72
72
|
export { createModuleShutdownHandler as n, loadKuckitModules as r, LoadModulesOptions as t };
|
|
73
|
-
//# sourceMappingURL=loader-
|
|
73
|
+
//# sourceMappingURL=loader-Do1M_26D.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import "../types-
|
|
3
|
-
import { t as defineKuckitModule } from "../define-module-
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import "../types-TrXzdvrM.js";
|
|
3
|
+
import { t as defineKuckitModule } from "../define-module-CDZ2Cnss.js";
|
|
4
4
|
export { defineKuckitModule };
|
package/dist/modules/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { a as KuckitModuleHooks, c as ModuleCapability, i as KuckitModuleDefinition, l as ModuleSpec, n as BuiltInCapability, o as KuckitModuleMeta, r as KuckitModuleContext, t as ApiRegistration } from "../types-
|
|
3
|
-
import { t as defineKuckitModule } from "../define-module-
|
|
4
|
-
import { n as createModuleShutdownHandler, r as loadKuckitModules, t as LoadModulesOptions } from "../loader-
|
|
5
|
-
import { a as resetModuleRegistry, i as getModulesWithCapability, n as ModuleRegistry, r as getModuleRegistry, t as LoadedModuleInfo } from "../registry-
|
|
6
|
-
import "../index-
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import { a as KuckitModuleHooks, c as ModuleCapability, i as KuckitModuleDefinition, l as ModuleSpec, n as BuiltInCapability, o as KuckitModuleMeta, r as KuckitModuleContext, t as ApiRegistration } from "../types-TrXzdvrM.js";
|
|
3
|
+
import { t as defineKuckitModule } from "../define-module-CDZ2Cnss.js";
|
|
4
|
+
import { n as createModuleShutdownHandler, r as loadKuckitModules, t as LoadModulesOptions } from "../loader-Do1M_26D.js";
|
|
5
|
+
import { a as resetModuleRegistry, i as getModulesWithCapability, n as ModuleRegistry, r as getModuleRegistry, t as LoadedModuleInfo } from "../registry-9FKJPjuY.js";
|
|
6
|
+
import "../index-E7Wvm5uX.js";
|
|
7
7
|
export { ApiRegistration, BuiltInCapability, KuckitModuleContext, KuckitModuleDefinition, KuckitModuleHooks, KuckitModuleMeta, LoadModulesOptions, LoadedModuleInfo, ModuleCapability, ModuleRegistry, ModuleSpec, createModuleShutdownHandler, defineKuckitModule, getModuleRegistry, getModulesWithCapability, loadKuckitModules, resetModuleRegistry };
|
package/dist/modules/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as defineKuckitModule } from "../define-module-
|
|
2
|
-
import { i as resetModuleRegistry, n as getModuleRegistry, r as getModulesWithCapability, t as ModuleRegistry } from "../registry-
|
|
3
|
-
import "../registry-
|
|
4
|
-
import "../schema-
|
|
5
|
-
import { n as loadKuckitModules, t as createModuleShutdownHandler } from "../loader-
|
|
6
|
-
import "../modules-
|
|
1
|
+
import { t as defineKuckitModule } from "../define-module-CzsWcVHH.js";
|
|
2
|
+
import { i as resetModuleRegistry, n as getModuleRegistry, r as getModulesWithCapability, t as ModuleRegistry } from "../registry-DMY4gCiz.js";
|
|
3
|
+
import "../registry-B62Oueqd.js";
|
|
4
|
+
import "../schema-C94Ei_S4.js";
|
|
5
|
+
import { n as loadKuckitModules, t as createModuleShutdownHandler } from "../loader-BZuTuluL.js";
|
|
6
|
+
import "../modules-CQFGHC4e.js";
|
|
7
7
|
|
|
8
8
|
export { ModuleRegistry, createModuleShutdownHandler, defineKuckitModule, getModuleRegistry, getModulesWithCapability, loadKuckitModules, resetModuleRegistry };
|
package/dist/modules/loader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import "../types-
|
|
3
|
-
import { n as createModuleShutdownHandler, r as loadKuckitModules, t as LoadModulesOptions } from "../loader-
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import "../types-TrXzdvrM.js";
|
|
3
|
+
import { n as createModuleShutdownHandler, r as loadKuckitModules, t as LoadModulesOptions } from "../loader-Do1M_26D.js";
|
|
4
4
|
export { LoadModulesOptions, createModuleShutdownHandler, loadKuckitModules };
|
package/dist/modules/loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../registry-
|
|
2
|
-
import "../registry-
|
|
3
|
-
import "../schema-
|
|
4
|
-
import { n as loadKuckitModules, t as createModuleShutdownHandler } from "../loader-
|
|
1
|
+
import "../registry-DMY4gCiz.js";
|
|
2
|
+
import "../registry-B62Oueqd.js";
|
|
3
|
+
import "../schema-C94Ei_S4.js";
|
|
4
|
+
import { n as loadKuckitModules, t as createModuleShutdownHandler } from "../loader-BZuTuluL.js";
|
|
5
5
|
|
|
6
6
|
export { createModuleShutdownHandler, loadKuckitModules };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import "../types-
|
|
3
|
-
import { a as resetModuleRegistry, i as getModulesWithCapability, n as ModuleRegistry, r as getModuleRegistry, t as LoadedModuleInfo } from "../registry-
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import "../types-TrXzdvrM.js";
|
|
3
|
+
import { a as resetModuleRegistry, i as getModulesWithCapability, n as ModuleRegistry, r as getModuleRegistry, t as LoadedModuleInfo } from "../registry-9FKJPjuY.js";
|
|
4
4
|
export { LoadedModuleInfo, ModuleRegistry, getModuleRegistry, getModulesWithCapability, resetModuleRegistry };
|
package/dist/modules/registry.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as resetModuleRegistry, n as getModuleRegistry, r as getModulesWithCapability, t as ModuleRegistry } from "../registry-
|
|
1
|
+
import { i as resetModuleRegistry, n as getModuleRegistry, r as getModulesWithCapability, t as ModuleRegistry } from "../registry-DMY4gCiz.js";
|
|
2
2
|
|
|
3
3
|
export { ModuleRegistry, getModuleRegistry, getModulesWithCapability, resetModuleRegistry };
|
package/dist/modules/types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../types-
|
|
2
|
-
import { a as KuckitModuleHooks, c as ModuleCapability, i as KuckitModuleDefinition, l as ModuleSpec, n as BuiltInCapability, o as KuckitModuleMeta, r as KuckitModuleContext, s as LoadedModule, t as ApiRegistration } from "../types-
|
|
1
|
+
import "../types-TWbGQRnv.js";
|
|
2
|
+
import { a as KuckitModuleHooks, c as ModuleCapability, i as KuckitModuleDefinition, l as ModuleSpec, n as BuiltInCapability, o as KuckitModuleMeta, r as KuckitModuleContext, s as LoadedModule, t as ApiRegistration } from "../types-TrXzdvrM.js";
|
|
3
3
|
export { ApiRegistration, BuiltInCapability, KuckitModuleContext, KuckitModuleDefinition, KuckitModuleHooks, KuckitModuleMeta, LoadedModule, ModuleCapability, ModuleSpec };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ModuleCapability, i as KuckitModuleDefinition } from "./types-
|
|
1
|
+
import { c as ModuleCapability, i as KuckitModuleDefinition } from "./types-TrXzdvrM.js";
|
|
2
2
|
|
|
3
3
|
//#region src/modules/registry.d.ts
|
|
4
4
|
|
|
@@ -87,4 +87,4 @@ declare function getModulesWithCapability(capability: ModuleCapability): LoadedM
|
|
|
87
87
|
declare function resetModuleRegistry(): void;
|
|
88
88
|
//#endregion
|
|
89
89
|
export { resetModuleRegistry as a, getModulesWithCapability as i, ModuleRegistry as n, getModuleRegistry as r, LoadedModuleInfo as t };
|
|
90
|
-
//# sourceMappingURL=registry-
|
|
90
|
+
//# sourceMappingURL=registry-9FKJPjuY.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-
|
|
1
|
+
{"version":3,"file":"registry-B62Oueqd.js","names":["result: Record<string, PgTable>","globalSchemaRegistry: SchemaRegistry | null"],"sources":["../src/schema/registry.ts"],"sourcesContent":["import type { PgTable } from 'drizzle-orm/pg-core'\n\n/**\n * Entry for a registered schema\n */\nexport interface SchemaEntry {\n\t/** Module that owns this schema */\n\tmoduleId: string\n\t/** Table name identifier */\n\ttableName: string\n\t/** Drizzle table schema */\n\tschema: PgTable\n}\n\n/**\n * Registry for module-owned database schemas\n *\n * Allows modules to register their Drizzle schemas during the register() hook.\n * The CLI uses this registry to aggregate schemas for drizzle-kit operations.\n */\nexport class SchemaRegistry {\n\tprivate schemas = new Map<string, SchemaEntry>()\n\n\t/**\n\t * Register a schema from a module\n\t * @param moduleId - Module identifier (e.g., 'acme.billing')\n\t * @param tableName - Table name identifier (e.g., 'invoices')\n\t * @param schema - Drizzle PgTable schema\n\t */\n\tregister(moduleId: string, tableName: string, schema: PgTable): void {\n\t\tconst key = `${moduleId}:${tableName}`\n\t\tif (this.schemas.has(key)) {\n\t\t\tthrow new Error(`Schema \"${tableName}\" already registered by module \"${moduleId}\"`)\n\t\t}\n\t\tthis.schemas.set(key, { moduleId, tableName, schema })\n\t}\n\n\t/**\n\t * Get all registered schemas\n\t */\n\tgetAll(): Map<string, SchemaEntry> {\n\t\treturn new Map(this.schemas)\n\t}\n\n\t/**\n\t * Get schemas registered by a specific module\n\t */\n\tgetByModule(moduleId: string): SchemaEntry[] {\n\t\treturn Array.from(this.schemas.values()).filter((entry) => entry.moduleId === moduleId)\n\t}\n\n\t/**\n\t * Get all schemas as a flat object for drizzle-kit\n\t * Keys are table names, values are PgTable schemas\n\t */\n\tgetAllSchemas(): Record<string, PgTable> {\n\t\tconst result: Record<string, PgTable> = {}\n\t\tfor (const entry of this.schemas.values()) {\n\t\t\tresult[entry.tableName] = entry.schema\n\t\t}\n\t\treturn result\n\t}\n\n\t/**\n\t * Check if any schemas are registered\n\t */\n\thasSchemas(): boolean {\n\t\treturn this.schemas.size > 0\n\t}\n\n\t/**\n\t * Get the count of registered schemas\n\t */\n\tget size(): number {\n\t\treturn this.schemas.size\n\t}\n\n\t/**\n\t * Clear all schemas (mainly for testing)\n\t */\n\tclear(): void {\n\t\tthis.schemas.clear()\n\t}\n}\n\n// Global schema registry instance\nlet globalSchemaRegistry: SchemaRegistry | null = null\n\n/**\n * Get the global schema registry\n * Creates one if it doesn't exist\n */\nexport function getSchemaRegistry(): SchemaRegistry {\n\tif (!globalSchemaRegistry) {\n\t\tglobalSchemaRegistry = new SchemaRegistry()\n\t}\n\treturn globalSchemaRegistry\n}\n\n/**\n * Reset the global schema registry (mainly for testing)\n */\nexport function resetSchemaRegistry(): void {\n\tglobalSchemaRegistry = null\n}\n"],"mappings":";;;;;;;AAoBA,IAAa,iBAAb,MAA4B;CAC3B,AAAQ,0BAAU,IAAI,KAA0B;;;;;;;CAQhD,SAAS,UAAkB,WAAmB,QAAuB;EACpE,MAAM,MAAM,GAAG,SAAS,GAAG;AAC3B,MAAI,KAAK,QAAQ,IAAI,IAAI,CACxB,OAAM,IAAI,MAAM,WAAW,UAAU,kCAAkC,SAAS,GAAG;AAEpF,OAAK,QAAQ,IAAI,KAAK;GAAE;GAAU;GAAW;GAAQ,CAAC;;;;;CAMvD,SAAmC;AAClC,SAAO,IAAI,IAAI,KAAK,QAAQ;;;;;CAM7B,YAAY,UAAiC;AAC5C,SAAO,MAAM,KAAK,KAAK,QAAQ,QAAQ,CAAC,CAAC,QAAQ,UAAU,MAAM,aAAa,SAAS;;;;;;CAOxF,gBAAyC;EACxC,MAAMA,SAAkC,EAAE;AAC1C,OAAK,MAAM,SAAS,KAAK,QAAQ,QAAQ,CACxC,QAAO,MAAM,aAAa,MAAM;AAEjC,SAAO;;;;;CAMR,aAAsB;AACrB,SAAO,KAAK,QAAQ,OAAO;;;;;CAM5B,IAAI,OAAe;AAClB,SAAO,KAAK,QAAQ;;;;;CAMrB,QAAc;AACb,OAAK,QAAQ,OAAO;;;AAKtB,IAAIC,uBAA8C;;;;;AAMlD,SAAgB,oBAAoC;AACnD,KAAI,CAAC,qBACJ,wBAAuB,IAAI,gBAAgB;AAE5C,QAAO;;;;;AAMR,SAAgB,sBAA4B;AAC3C,wBAAuB"}
|
|
@@ -65,4 +65,4 @@ declare function getSchemaRegistry(): SchemaRegistry;
|
|
|
65
65
|
declare function resetSchemaRegistry(): void;
|
|
66
66
|
//#endregion
|
|
67
67
|
export { resetSchemaRegistry as i, SchemaRegistry as n, getSchemaRegistry as r, SchemaEntry as t };
|
|
68
|
-
//# sourceMappingURL=registry-
|
|
68
|
+
//# sourceMappingURL=registry-BwUbpLWo.d.ts.map
|
|
@@ -129,4 +129,4 @@ function resetModuleRegistry() {
|
|
|
129
129
|
|
|
130
130
|
//#endregion
|
|
131
131
|
export { resetModuleRegistry as i, getModuleRegistry as n, getModulesWithCapability as r, ModuleRegistry as t };
|
|
132
|
-
//# sourceMappingURL=registry-
|
|
132
|
+
//# sourceMappingURL=registry-DMY4gCiz.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry-
|
|
1
|
+
{"version":3,"file":"registry-DMY4gCiz.js","names":["globalRegistry: ModuleRegistry | null"],"sources":["../src/modules/registry.ts"],"sourcesContent":["import type { ModuleCapability, KuckitModuleDefinition } from './types'\n\n/**\n * Information about a loaded module\n */\nexport interface LoadedModuleInfo {\n\t/** Module unique identifier */\n\tid: string\n\t/** Human-readable name */\n\tdisplayName?: string\n\t/** Module description */\n\tdescription?: string\n\t/** Module version */\n\tversion?: string\n\t/** Capabilities this module provides */\n\tcapabilities: ModuleCapability[]\n}\n\n/**\n * Validates that a capability string matches expected patterns\n */\nconst isValidCapability = (cap: string): cap is ModuleCapability => {\n\t// Built-in capabilities\n\tconst builtIn = [\n\t\t'nav.item',\n\t\t'settings.page',\n\t\t'dashboard.widget',\n\t\t'api.webhook',\n\t\t'api.public',\n\t\t'slot.provider',\n\t]\n\tif (builtIn.includes(cap)) return true\n\n\t// Custom capabilities must start with 'custom.'\n\tif (cap.startsWith('custom.') && cap.length > 7) return true\n\n\treturn false\n}\n\n/**\n * Registry for loaded Kuckit modules\n *\n * Tracks all loaded modules and their capabilities for querying.\n */\nexport class ModuleRegistry {\n\tprivate modules: Map<string, LoadedModuleInfo> = new Map()\n\tprivate frozen = false\n\n\t/**\n\t * Register a loaded module\n\t * @throws Error if registry is frozen or module ID already exists\n\t */\n\tregister(module: KuckitModuleDefinition): void {\n\t\tif (this.frozen) {\n\t\t\tthrow new Error(\n\t\t\t\t`ModuleRegistry is frozen. Cannot register module \"${module.id}\" after finalization.`\n\t\t\t)\n\t\t}\n\t\tif (this.modules.has(module.id)) {\n\t\t\tthrow new Error(`Module with ID \"${module.id}\" is already registered.`)\n\t\t}\n\n\t\t// Validate capabilities\n\t\tconst capabilities = module.capabilities ?? []\n\t\tfor (const cap of capabilities) {\n\t\t\tif (!isValidCapability(cap)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid capability \"${cap}\" in module \"${module.id}\". ` +\n\t\t\t\t\t\t`Capabilities must be built-in (nav.item, settings.page, etc.) or custom.* prefixed.`\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\tthis.modules.set(module.id, {\n\t\t\tid: module.id,\n\t\t\tdisplayName: module.displayName,\n\t\t\tdescription: module.description,\n\t\t\tversion: module.version,\n\t\t\tcapabilities,\n\t\t})\n\t}\n\n\t/**\n\t * Get all registered modules\n\t */\n\tgetAll(): LoadedModuleInfo[] {\n\t\treturn Array.from(this.modules.values())\n\t}\n\n\t/**\n\t * Get a module by ID\n\t */\n\tgetById(id: string): LoadedModuleInfo | undefined {\n\t\treturn this.modules.get(id)\n\t}\n\n\t/**\n\t * Check if a module is registered\n\t */\n\thas(id: string): boolean {\n\t\treturn this.modules.has(id)\n\t}\n\n\t/**\n\t * Get all modules that have a specific capability\n\t */\n\tgetWithCapability(capability: ModuleCapability): LoadedModuleInfo[] {\n\t\treturn this.getAll().filter((mod) => mod.capabilities.includes(capability))\n\t}\n\n\t/**\n\t * Check if a specific module has a capability\n\t */\n\thasCapability(moduleId: string, capability: ModuleCapability): boolean {\n\t\tconst module = this.modules.get(moduleId)\n\t\treturn module ? module.capabilities.includes(capability) : false\n\t}\n\n\t/**\n\t * Get all unique capabilities across all modules\n\t */\n\tgetAllCapabilities(): ModuleCapability[] {\n\t\tconst caps = new Set<ModuleCapability>()\n\t\tfor (const mod of this.modules.values()) {\n\t\t\tfor (const cap of mod.capabilities) {\n\t\t\t\tcaps.add(cap)\n\t\t\t}\n\t\t}\n\t\treturn Array.from(caps)\n\t}\n\n\t/**\n\t * Freeze the registry to prevent further modifications\n\t */\n\tfreeze(): void {\n\t\tthis.frozen = true\n\t}\n\n\t/**\n\t * Check if registry is frozen\n\t */\n\tisFrozen(): boolean {\n\t\treturn this.frozen\n\t}\n\n\t/**\n\t * Get the number of registered modules\n\t */\n\tget size(): number {\n\t\treturn this.modules.size\n\t}\n\n\t/**\n\t * Clear all modules (only works if not frozen)\n\t */\n\tclear(): void {\n\t\tif (this.frozen) {\n\t\t\tthrow new Error('ModuleRegistry is frozen. Cannot clear modules.')\n\t\t}\n\t\tthis.modules.clear()\n\t}\n}\n\n// Global module registry instance\nlet globalRegistry: ModuleRegistry | null = null\n\n/**\n * Get the global module registry\n * Creates one if it doesn't exist\n */\nexport function getModuleRegistry(): ModuleRegistry {\n\tif (!globalRegistry) {\n\t\tglobalRegistry = new ModuleRegistry()\n\t}\n\treturn globalRegistry\n}\n\n/**\n * Get all modules that have a specific capability\n * Convenience function that uses the global registry\n */\nexport function getModulesWithCapability(capability: ModuleCapability): LoadedModuleInfo[] {\n\treturn getModuleRegistry().getWithCapability(capability)\n}\n\n/**\n * Reset the global registry (mainly for testing)\n */\nexport function resetModuleRegistry(): void {\n\tglobalRegistry = null\n}\n"],"mappings":";;;;AAqBA,MAAM,qBAAqB,QAAyC;AAUnE,KARgB;EACf;EACA;EACA;EACA;EACA;EACA;EACA,CACW,SAAS,IAAI,CAAE,QAAO;AAGlC,KAAI,IAAI,WAAW,UAAU,IAAI,IAAI,SAAS,EAAG,QAAO;AAExD,QAAO;;;;;;;AAQR,IAAa,iBAAb,MAA4B;CAC3B,AAAQ,0BAAyC,IAAI,KAAK;CAC1D,AAAQ,SAAS;;;;;CAMjB,SAAS,QAAsC;AAC9C,MAAI,KAAK,OACR,OAAM,IAAI,MACT,qDAAqD,OAAO,GAAG,uBAC/D;AAEF,MAAI,KAAK,QAAQ,IAAI,OAAO,GAAG,CAC9B,OAAM,IAAI,MAAM,mBAAmB,OAAO,GAAG,0BAA0B;EAIxE,MAAM,eAAe,OAAO,gBAAgB,EAAE;AAC9C,OAAK,MAAM,OAAO,aACjB,KAAI,CAAC,kBAAkB,IAAI,CAC1B,OAAM,IAAI,MACT,uBAAuB,IAAI,eAAe,OAAO,GAAG,wFAEpD;AAIH,OAAK,QAAQ,IAAI,OAAO,IAAI;GAC3B,IAAI,OAAO;GACX,aAAa,OAAO;GACpB,aAAa,OAAO;GACpB,SAAS,OAAO;GAChB;GACA,CAAC;;;;;CAMH,SAA6B;AAC5B,SAAO,MAAM,KAAK,KAAK,QAAQ,QAAQ,CAAC;;;;;CAMzC,QAAQ,IAA0C;AACjD,SAAO,KAAK,QAAQ,IAAI,GAAG;;;;;CAM5B,IAAI,IAAqB;AACxB,SAAO,KAAK,QAAQ,IAAI,GAAG;;;;;CAM5B,kBAAkB,YAAkD;AACnE,SAAO,KAAK,QAAQ,CAAC,QAAQ,QAAQ,IAAI,aAAa,SAAS,WAAW,CAAC;;;;;CAM5E,cAAc,UAAkB,YAAuC;EACtE,MAAM,SAAS,KAAK,QAAQ,IAAI,SAAS;AACzC,SAAO,SAAS,OAAO,aAAa,SAAS,WAAW,GAAG;;;;;CAM5D,qBAAyC;EACxC,MAAM,uBAAO,IAAI,KAAuB;AACxC,OAAK,MAAM,OAAO,KAAK,QAAQ,QAAQ,CACtC,MAAK,MAAM,OAAO,IAAI,aACrB,MAAK,IAAI,IAAI;AAGf,SAAO,MAAM,KAAK,KAAK;;;;;CAMxB,SAAe;AACd,OAAK,SAAS;;;;;CAMf,WAAoB;AACnB,SAAO,KAAK;;;;;CAMb,IAAI,OAAe;AAClB,SAAO,KAAK,QAAQ;;;;;CAMrB,QAAc;AACb,MAAI,KAAK,OACR,OAAM,IAAI,MAAM,kDAAkD;AAEnE,OAAK,QAAQ,OAAO;;;AAKtB,IAAIA,iBAAwC;;;;;AAM5C,SAAgB,oBAAoC;AACnD,KAAI,CAAC,eACJ,kBAAiB,IAAI,gBAAgB;AAEtC,QAAO;;;;;;AAOR,SAAgB,yBAAyB,YAAkD;AAC1F,QAAO,mBAAmB,CAAC,kBAAkB,WAAW;;;;;AAMzD,SAAgB,sBAA4B;AAC3C,kBAAiB"}
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as resetSchemaRegistry, n as SchemaRegistry, r as getSchemaRegistry, t as SchemaEntry } from "../registry-
|
|
2
|
-
import { t as PgTable } from "../index-
|
|
1
|
+
import { i as resetSchemaRegistry, n as SchemaRegistry, r as getSchemaRegistry, t as SchemaEntry } from "../registry-BwUbpLWo.js";
|
|
2
|
+
import { t as PgTable } from "../index-BLsEv2uZ.js";
|
|
3
3
|
export { PgTable, SchemaEntry, SchemaRegistry, getSchemaRegistry, resetSchemaRegistry };
|
package/dist/schema/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as getSchemaRegistry, r as resetSchemaRegistry, t as SchemaRegistry } from "../registry-
|
|
2
|
-
import "../schema-
|
|
1
|
+
import { n as getSchemaRegistry, r as resetSchemaRegistry, t as SchemaRegistry } from "../registry-B62Oueqd.js";
|
|
2
|
+
import "../schema-C94Ei_S4.js";
|
|
3
3
|
|
|
4
4
|
export { SchemaRegistry, getSchemaRegistry, resetSchemaRegistry };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as resetSchemaRegistry, n as SchemaRegistry, r as getSchemaRegistry, t as SchemaEntry } from "../registry-
|
|
1
|
+
import { i as resetSchemaRegistry, n as SchemaRegistry, r as getSchemaRegistry, t as SchemaEntry } from "../registry-BwUbpLWo.js";
|
|
2
2
|
export { SchemaEntry, SchemaRegistry, getSchemaRegistry, resetSchemaRegistry };
|
package/dist/schema/registry.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as getSchemaRegistry, r as resetSchemaRegistry, t as SchemaRegistry } from "../registry-
|
|
1
|
+
import { n as getSchemaRegistry, r as resetSchemaRegistry, t as SchemaRegistry } from "../registry-B62Oueqd.js";
|
|
2
2
|
|
|
3
3
|
export { SchemaRegistry, getSchemaRegistry, resetSchemaRegistry };
|
|
@@ -9,6 +9,13 @@ interface KuckitModuleConfig<TConfig = unknown> {
|
|
|
9
9
|
config?: TConfig;
|
|
10
10
|
/** Whether this module is enabled (default: true). Can use environment variables. */
|
|
11
11
|
enabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Override the default schema directory for Drizzle schema discovery.
|
|
14
|
+
* Path is relative to the module's package root.
|
|
15
|
+
* @default 'src/server/schema'
|
|
16
|
+
* @example { package: '@acme/legacy-module', schemaDir: 'src/db/tables' }
|
|
17
|
+
*/
|
|
18
|
+
schemaDir?: string;
|
|
12
19
|
}
|
|
13
20
|
/**
|
|
14
21
|
* Discovery configuration for auto-detecting modules
|
|
@@ -84,4 +91,4 @@ interface LoadedKuckitConfig extends KuckitConfig {
|
|
|
84
91
|
}
|
|
85
92
|
//#endregion
|
|
86
93
|
export { KuckitServerConfig as a, KuckitModuleConfig as i, KuckitConfig as n, LoadedKuckitConfig as o, KuckitDiscoveryConfig as r, KuckitClientConfig as t };
|
|
87
|
-
//# sourceMappingURL=types-
|
|
94
|
+
//# sourceMappingURL=types-Ceg8XQY6.d.ts.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { AwilixContainer, Resolver } from "awilix";
|
|
2
2
|
import { CacheStore, Clock, EventBus, Logger, RateLimiterStore } from "@kuckit/domain";
|
|
3
|
-
import {
|
|
3
|
+
import { Auth } from "@kuckit/auth";
|
|
4
|
+
import { Pool } from "pg";
|
|
5
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
6
|
|
|
5
7
|
//#region src/types.d.ts
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Database types for DI
|
|
11
|
+
*/
|
|
12
|
+
type DbPool = Pool;
|
|
13
|
+
type DrizzleDb = NodePgDatabase;
|
|
7
14
|
/**
|
|
8
15
|
* Core SDK configuration
|
|
9
16
|
* This is the minimal config needed to bootstrap the SDK
|
|
@@ -28,7 +35,7 @@ interface CoreCradle {
|
|
|
28
35
|
clock: Clock;
|
|
29
36
|
logger: Logger;
|
|
30
37
|
errorHandler: unknown;
|
|
31
|
-
auth:
|
|
38
|
+
auth: Auth;
|
|
32
39
|
aiProvider: unknown;
|
|
33
40
|
eventBus: EventBus;
|
|
34
41
|
cacheStore: CacheStore;
|
|
@@ -47,5 +54,5 @@ interface CoreCradle {
|
|
|
47
54
|
*/
|
|
48
55
|
type CoreContainer = AwilixContainer<CoreCradle>;
|
|
49
56
|
//#endregion
|
|
50
|
-
export { CoreContainer as n, CoreCradle as r, CoreConfig as t };
|
|
51
|
-
//# sourceMappingURL=types-
|
|
57
|
+
export { DrizzleDb as a, DbPool as i, CoreContainer as n, CoreCradle as r, CoreConfig as t };
|
|
58
|
+
//# sourceMappingURL=types-TWbGQRnv.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CoreContainer } from "./types-
|
|
1
|
+
import { n as CoreContainer } from "./types-TWbGQRnv.js";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
|
|
4
4
|
//#region src/modules/types.d.ts
|
|
@@ -109,4 +109,4 @@ interface LoadedModule<TConfig = unknown> extends KuckitModuleDefinition<TConfig
|
|
|
109
109
|
}
|
|
110
110
|
//#endregion
|
|
111
111
|
export { KuckitModuleHooks as a, ModuleCapability as c, KuckitModuleDefinition as i, ModuleSpec as l, BuiltInCapability as n, KuckitModuleMeta as o, KuckitModuleContext as r, LoadedModule as s, ApiRegistration as t };
|
|
112
|
-
//# sourceMappingURL=types-
|
|
112
|
+
//# sourceMappingURL=types-TrXzdvrM.d.ts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as CoreContainer, r as CoreCradle, t as CoreConfig } from "./types-
|
|
2
|
-
export { CoreConfig, CoreContainer, CoreCradle };
|
|
1
|
+
import { a as DrizzleDb, i as DbPool, n as CoreContainer, r as CoreCradle, t as CoreConfig } from "./types-TWbGQRnv.js";
|
|
2
|
+
export { CoreConfig, CoreContainer, CoreCradle, DbPool, DrizzleDb };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kuckit/sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
+
"./config": {
|
|
16
|
+
"types": "./dist/config/index.d.ts",
|
|
17
|
+
"default": "./dist/config/index.js"
|
|
18
|
+
},
|
|
15
19
|
"./*": {
|
|
16
20
|
"types": "./dist/*.d.ts",
|
|
17
21
|
"default": "./dist/*.js"
|
|
@@ -22,13 +26,13 @@
|
|
|
22
26
|
"prepublishOnly": "npm run build && node ../../scripts/resolve-workspace-protocols.cjs && node ../../scripts/check-no-workspace-protocol.cjs"
|
|
23
27
|
},
|
|
24
28
|
"dependencies": {
|
|
25
|
-
"@kuckit/domain": "^2.0.
|
|
26
|
-
"@kuckit/application": "^2.0.
|
|
27
|
-
"@kuckit/infrastructure": "^2.0.
|
|
28
|
-
"@kuckit/api": "^2.0.
|
|
29
|
-
"@kuckit/contracts": "^2.0.
|
|
30
|
-
"@kuckit/auth": "^2.0.
|
|
31
|
-
"@kuckit/db": "^2.0.
|
|
29
|
+
"@kuckit/domain": "^2.0.2",
|
|
30
|
+
"@kuckit/application": "^2.0.2",
|
|
31
|
+
"@kuckit/infrastructure": "^2.0.2",
|
|
32
|
+
"@kuckit/api": "^2.0.2",
|
|
33
|
+
"@kuckit/contracts": "^2.0.2",
|
|
34
|
+
"@kuckit/auth": "^2.0.2",
|
|
35
|
+
"@kuckit/db": "^2.0.2",
|
|
32
36
|
"awilix": "^12.0.5",
|
|
33
37
|
"jiti": "^2.4.2"
|
|
34
38
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"container-D0DK003A.js","names":[],"sources":["../src/core/container.ts"],"sourcesContent":["import { createContainer, asValue, InjectionMode } from 'awilix'\nimport type { CoreContainer, CoreCradle, CoreConfig } from '../types'\nimport { registerCoreModule } from './core.module'\n\nexport interface CreateKuckitOptions {\n\t/**\n\t * Core configuration for the SDK\n\t */\n\tconfig: CoreConfig\n\n\t/**\n\t * Optional callback to register additional services after core registration\n\t */\n\textraRegistrations?: (container: CoreContainer) => void | Promise<void>\n}\n\n/**\n * Factory function to create a Kuckit DI container\n *\n * This is the primary entry point for applications using the SDK.\n * It creates an Awilix container with core infrastructure services pre-registered.\n *\n * @example\n * ```ts\n * const container = await createKuckitContainer({\n * config: {\n * databaseUrl: process.env.DATABASE_URL!,\n * enableFileLogging: true,\n * logDir: './logs',\n * logLevel: 'INFO',\n * env: 'production',\n * },\n * extraRegistrations: (container) => {\n * // Register your custom services\n * container.register({\n * myService: asClass(MyService).singleton(),\n * })\n * },\n * })\n * ```\n */\nexport const createKuckitContainer = async (opts: CreateKuckitOptions): Promise<CoreContainer> => {\n\tconst container = createContainer<CoreCradle>({\n\t\tinjectionMode: InjectionMode.PROXY,\n\t})\n\n\t// Register config first (required by other registrations)\n\tcontainer.register({\n\t\tconfig: asValue(opts.config),\n\t})\n\n\t// Register core infrastructure\n\tregisterCoreModule(container)\n\n\t// Allow custom registrations\n\tif (opts.extraRegistrations) {\n\t\tawait opts.extraRegistrations(container)\n\t}\n\n\treturn container\n}\n\n/**\n * Cleanup container resources gracefully\n *\n * Call this when shutting down your application to close database connections\n * and other resources.\n */\nexport const disposeContainer = async (container: CoreContainer): Promise<void> => {\n\tconst { dbPool } = container.cradle\n\t// Handle unknown dbPool type - check for end method\n\tif (\n\t\tdbPool &&\n\t\ttypeof dbPool === 'object' &&\n\t\t'end' in dbPool &&\n\t\ttypeof (dbPool as { end: unknown }).end === 'function'\n\t) {\n\t\tawait (dbPool as { end: () => Promise<void> }).end()\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,wBAAwB,OAAO,SAAsD;CACjG,MAAM,YAAY,gBAA4B,EAC7C,eAAe,cAAc,OAC7B,CAAC;AAGF,WAAU,SAAS,EAClB,QAAQ,QAAQ,KAAK,OAAO,EAC5B,CAAC;AAGF,oBAAmB,UAAU;AAG7B,KAAI,KAAK,mBACR,OAAM,KAAK,mBAAmB,UAAU;AAGzC,QAAO;;;;;;;;AASR,MAAa,mBAAmB,OAAO,cAA4C;CAClF,MAAM,EAAE,WAAW,UAAU;AAE7B,KACC,UACA,OAAO,WAAW,YAClB,SAAS,UACT,OAAQ,OAA4B,QAAQ,WAE5C,OAAO,OAAwC,KAAK"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { n as CoreContainer } from "./types-DKCy16X1.js";
|
|
2
|
-
|
|
3
|
-
//#region src/core/core.module.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Register core infrastructure services into the container
|
|
7
|
-
*
|
|
8
|
-
* This registers:
|
|
9
|
-
* - Database pool and connection
|
|
10
|
-
* - Clock
|
|
11
|
-
* - Logger (structured, Loki/Prometheus compatible)
|
|
12
|
-
* - AI provider
|
|
13
|
-
* - Auth
|
|
14
|
-
* - Event bus
|
|
15
|
-
* - Cache store
|
|
16
|
-
* - Rate limiter store
|
|
17
|
-
* - Request-scoped logger
|
|
18
|
-
*/
|
|
19
|
-
declare const registerCoreModule: (container: CoreContainer) => void;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { registerCoreModule as t };
|
|
22
|
-
//# sourceMappingURL=core.module-Ckt9iPWn.d.ts.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { asClass, asFunction, asValue } from "awilix";
|
|
2
|
-
import { SystemClock } from "@kuckit/domain";
|
|
3
|
-
import { google } from "@ai-sdk/google";
|
|
4
|
-
import { auth } from "@kuckit/auth";
|
|
5
|
-
import { InMemoryCacheStore, InMemoryEventBus, InMemoryRateLimiterStore, createDb, createDbPool, makeErrorHandler, makeRequestLogger, makeStructuredLogger } from "@kuckit/infrastructure";
|
|
6
|
-
|
|
7
|
-
//#region src/core/core.module.ts
|
|
8
|
-
/**
|
|
9
|
-
* Register core infrastructure services into the container
|
|
10
|
-
*
|
|
11
|
-
* This registers:
|
|
12
|
-
* - Database pool and connection
|
|
13
|
-
* - Clock
|
|
14
|
-
* - Logger (structured, Loki/Prometheus compatible)
|
|
15
|
-
* - AI provider
|
|
16
|
-
* - Auth
|
|
17
|
-
* - Event bus
|
|
18
|
-
* - Cache store
|
|
19
|
-
* - Rate limiter store
|
|
20
|
-
* - Request-scoped logger
|
|
21
|
-
*/
|
|
22
|
-
const registerCoreModule = (container) => {
|
|
23
|
-
container.register({
|
|
24
|
-
dbPool: asFunction(({ config }) => createDbPool(config.databaseUrl)).singleton(),
|
|
25
|
-
db: asFunction(({ dbPool }) => createDb(dbPool)).singleton(),
|
|
26
|
-
clock: asValue(new SystemClock()),
|
|
27
|
-
logger: asFunction(({ config }) => makeStructuredLogger({
|
|
28
|
-
enableFile: config.enableFileLogging,
|
|
29
|
-
logDir: config.logDir,
|
|
30
|
-
minLevel: config.logLevel
|
|
31
|
-
})).singleton(),
|
|
32
|
-
errorHandler: asFunction(({ logger }) => makeErrorHandler(logger)).singleton(),
|
|
33
|
-
auth: asValue(auth),
|
|
34
|
-
aiProvider: asFunction(() => google("gemini-2.5-flash")).singleton(),
|
|
35
|
-
eventBus: asFunction(({ logger }) => new InMemoryEventBus(logger)).singleton(),
|
|
36
|
-
cacheStore: asClass(InMemoryCacheStore).singleton(),
|
|
37
|
-
rateLimiterStore: asClass(InMemoryRateLimiterStore).singleton(),
|
|
38
|
-
requestLogger: asFunction(({ logger, requestId, session }) => makeRequestLogger({
|
|
39
|
-
requestId,
|
|
40
|
-
userId: session?.user?.id,
|
|
41
|
-
baseLogger: logger
|
|
42
|
-
})).scoped()
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
export { registerCoreModule as t };
|
|
48
|
-
//# sourceMappingURL=core.module-Ctm2stcL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.module-Ctm2stcL.js","names":[],"sources":["../src/core/core.module.ts"],"sourcesContent":["import { asClass, asFunction, asValue } from 'awilix'\nimport { SystemClock } from '@kuckit/domain'\nimport { google } from '@ai-sdk/google'\nimport { auth } from '@kuckit/auth'\nimport {\n\tcreateDbPool,\n\tcreateDb,\n\tmakeStructuredLogger,\n\tmakeRequestLogger,\n\tmakeErrorHandler,\n\tInMemoryEventBus,\n\tInMemoryCacheStore,\n\tInMemoryRateLimiterStore,\n} from '@kuckit/infrastructure'\nimport type { CoreContainer } from '../types'\n\n/**\n * Register core infrastructure services into the container\n *\n * This registers:\n * - Database pool and connection\n * - Clock\n * - Logger (structured, Loki/Prometheus compatible)\n * - AI provider\n * - Auth\n * - Event bus\n * - Cache store\n * - Rate limiter store\n * - Request-scoped logger\n */\nexport const registerCoreModule = (container: CoreContainer): void => {\n\tcontainer.register({\n\t\t// Database\n\t\tdbPool: asFunction(({ config }) => createDbPool(config.databaseUrl)).singleton(),\n\t\tdb: asFunction(({ dbPool }) => createDb(dbPool)).singleton(),\n\n\t\t// Core services\n\t\tclock: asValue(new SystemClock()),\n\n\t\tlogger: asFunction(({ config }) =>\n\t\t\tmakeStructuredLogger({\n\t\t\t\tenableFile: config.enableFileLogging,\n\t\t\t\tlogDir: config.logDir,\n\t\t\t\tminLevel: config.logLevel,\n\t\t\t})\n\t\t).singleton(),\n\n\t\terrorHandler: asFunction(({ logger }) => makeErrorHandler(logger)).singleton(),\n\n\t\t// External integrations\n\t\tauth: asValue(auth),\n\t\taiProvider: asFunction(() => google('gemini-2.5-flash')).singleton(),\n\n\t\t// Event bus\n\t\teventBus: asFunction(({ logger }) => new InMemoryEventBus(logger)).singleton(),\n\n\t\t// Stores\n\t\tcacheStore: asClass(InMemoryCacheStore).singleton(),\n\t\trateLimiterStore: asClass(InMemoryRateLimiterStore).singleton(),\n\n\t\t// Request-scoped logger (enriched with requestId and userId)\n\t\trequestLogger: asFunction(({ logger, requestId, session }) =>\n\t\t\tmakeRequestLogger({\n\t\t\t\trequestId,\n\t\t\t\tuserId: session?.user?.id,\n\t\t\t\tbaseLogger: logger,\n\t\t\t})\n\t\t).scoped(),\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,sBAAsB,cAAmC;AACrE,WAAU,SAAS;EAElB,QAAQ,YAAY,EAAE,aAAa,aAAa,OAAO,YAAY,CAAC,CAAC,WAAW;EAChF,IAAI,YAAY,EAAE,aAAa,SAAS,OAAO,CAAC,CAAC,WAAW;EAG5D,OAAO,QAAQ,IAAI,aAAa,CAAC;EAEjC,QAAQ,YAAY,EAAE,aACrB,qBAAqB;GACpB,YAAY,OAAO;GACnB,QAAQ,OAAO;GACf,UAAU,OAAO;GACjB,CAAC,CACF,CAAC,WAAW;EAEb,cAAc,YAAY,EAAE,aAAa,iBAAiB,OAAO,CAAC,CAAC,WAAW;EAG9E,MAAM,QAAQ,KAAK;EACnB,YAAY,iBAAiB,OAAO,mBAAmB,CAAC,CAAC,WAAW;EAGpE,UAAU,YAAY,EAAE,aAAa,IAAI,iBAAiB,OAAO,CAAC,CAAC,WAAW;EAG9E,YAAY,QAAQ,mBAAmB,CAAC,WAAW;EACnD,kBAAkB,QAAQ,yBAAyB,CAAC,WAAW;EAG/D,eAAe,YAAY,EAAE,QAAQ,WAAW,cAC/C,kBAAkB;GACjB;GACA,QAAQ,SAAS,MAAM;GACvB,YAAY;GACZ,CAAC,CACF,CAAC,QAAQ;EACV,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loader-lCPWCMYx.js","names":["config: KuckitConfig"],"sources":["../src/config/loader.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { resolve, dirname } from 'node:path'\nimport type { KuckitConfig, LoadedKuckitConfig } from './types'\n\nconst CONFIG_FILES = ['kuckit.config.ts', 'kuckit.config.js', 'kuckit.config.mjs']\n\n/**\n * Find the config file path by searching from cwd upward\n */\nexport function findConfigFile(cwd: string = process.cwd()): string | null {\n\tlet dir = cwd\n\n\twhile (dir !== dirname(dir)) {\n\t\tfor (const file of CONFIG_FILES) {\n\t\t\tconst configPath = resolve(dir, file)\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\treturn configPath\n\t\t\t}\n\t\t}\n\t\tdir = dirname(dir)\n\t}\n\n\t// Check root directory\n\tfor (const file of CONFIG_FILES) {\n\t\tconst configPath = resolve(dir, file)\n\t\tif (existsSync(configPath)) {\n\t\t\treturn configPath\n\t\t}\n\t}\n\n\treturn null\n}\n\n/**\n * Check if a unified config file exists\n */\nexport function hasUnifiedConfig(cwd: string = process.cwd()): boolean {\n\treturn findConfigFile(cwd) !== null\n}\n\n/**\n * Load Kuckit configuration from file\n *\n * Uses jiti for TypeScript support at runtime.\n * Falls back to dynamic import for JS/MJS files.\n *\n * @param cwd - Directory to start searching from (default: process.cwd())\n * @throws Error if config file not found or invalid\n */\nexport async function loadKuckitConfig(cwd: string = process.cwd()): Promise<LoadedKuckitConfig> {\n\tconst configPath = findConfigFile(cwd)\n\n\tif (!configPath) {\n\t\tthrow new Error(\n\t\t\t`No Kuckit config file found. Create a kuckit.config.ts at your project root.\\n` +\n\t\t\t\t`Searched from: ${cwd}`\n\t\t)\n\t}\n\n\tlet config: KuckitConfig\n\n\tif (configPath.endsWith('.ts')) {\n\t\t// Use jiti for TypeScript files\n\t\tconst { createJiti } = await import('jiti')\n\t\tconst jiti = createJiti(cwd, {\n\t\t\tinteropDefault: true,\n\t\t})\n\t\tconst loaded = await jiti.import(configPath)\n\t\tconfig = (loaded as { default?: KuckitConfig }).default ?? (loaded as KuckitConfig)\n\t} else {\n\t\t// Use dynamic import for JS/MJS\n\t\tconst loaded = await import(configPath)\n\t\tconfig = loaded.default ?? loaded\n\t}\n\n\t// Validate config\n\tif (!config || typeof config !== 'object') {\n\t\tthrow new Error(`Invalid Kuckit config at ${configPath}: expected an object`)\n\t}\n\n\tif (!Array.isArray(config.modules)) {\n\t\tthrow new Error(`Invalid Kuckit config at ${configPath}: 'modules' must be an array`)\n\t}\n\n\treturn {\n\t\t...config,\n\t\t_configPath: configPath,\n\t}\n}\n\n/**\n * Try to load config, returning null if not found\n */\nexport async function tryLoadKuckitConfig(\n\tcwd: string = process.cwd()\n): Promise<LoadedKuckitConfig | null> {\n\ttry {\n\t\treturn await loadKuckitConfig(cwd)\n\t} catch {\n\t\treturn null\n\t}\n}\n"],"mappings":";;;;AAIA,MAAM,eAAe;CAAC;CAAoB;CAAoB;CAAoB;;;;AAKlF,SAAgB,eAAe,MAAc,QAAQ,KAAK,EAAiB;CAC1E,IAAI,MAAM;AAEV,QAAO,QAAQ,QAAQ,IAAI,EAAE;AAC5B,OAAK,MAAM,QAAQ,cAAc;GAChC,MAAM,aAAa,QAAQ,KAAK,KAAK;AACrC,OAAI,WAAW,WAAW,CACzB,QAAO;;AAGT,QAAM,QAAQ,IAAI;;AAInB,MAAK,MAAM,QAAQ,cAAc;EAChC,MAAM,aAAa,QAAQ,KAAK,KAAK;AACrC,MAAI,WAAW,WAAW,CACzB,QAAO;;AAIT,QAAO;;;;;AAMR,SAAgB,iBAAiB,MAAc,QAAQ,KAAK,EAAW;AACtE,QAAO,eAAe,IAAI,KAAK;;;;;;;;;;;AAYhC,eAAsB,iBAAiB,MAAc,QAAQ,KAAK,EAA+B;CAChG,MAAM,aAAa,eAAe,IAAI;AAEtC,KAAI,CAAC,WACJ,OAAM,IAAI,MACT,gGACmB,MACnB;CAGF,IAAIA;AAEJ,KAAI,WAAW,SAAS,MAAM,EAAE;EAE/B,MAAM,EAAE,eAAe,MAAM,OAAO;EAIpC,MAAM,SAAS,MAHF,WAAW,KAAK,EAC5B,gBAAgB,MAChB,CAAC,CACwB,OAAO,WAAW;AAC5C,WAAU,OAAsC,WAAY;QACtD;EAEN,MAAM,SAAS,MAAM,OAAO;AAC5B,WAAS,OAAO,WAAW;;AAI5B,KAAI,CAAC,UAAU,OAAO,WAAW,SAChC,OAAM,IAAI,MAAM,4BAA4B,WAAW,sBAAsB;AAG9E,KAAI,CAAC,MAAM,QAAQ,OAAO,QAAQ,CACjC,OAAM,IAAI,MAAM,4BAA4B,WAAW,8BAA8B;AAGtF,QAAO;EACN,GAAG;EACH,aAAa;EACb;;;;;AAMF,eAAsB,oBACrB,MAAc,QAAQ,KAAK,EACU;AACrC,KAAI;AACH,SAAO,MAAM,iBAAiB,IAAI;SAC3B;AACP,SAAO"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|