@etohq/framework 1.5.5-next-20260415055708 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/database/encore.d.ts +74 -5
- package/dist/database/encore.d.ts.map +1 -1
- package/dist/database/encore.js +64 -0
- package/dist/database/encore.js.map +1 -1
- package/dist/database/index.d.ts +1 -0
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +1 -0
- package/dist/database/index.js.map +1 -1
- package/dist/database/service.d.ts +36 -0
- package/dist/database/service.d.ts.map +1 -0
- package/dist/database/service.js +104 -0
- package/dist/database/service.js.map +1 -0
- package/package.json +9 -9
|
@@ -2,16 +2,16 @@ import { knex } from "@mikro-orm/postgresql";
|
|
|
2
2
|
/**
|
|
3
3
|
* Encore SQLDatabase interface for type safety
|
|
4
4
|
* This represents the SQLDatabase object from Encore's runtime
|
|
5
|
+
* We only require connectionString for our use case
|
|
5
6
|
*/
|
|
6
7
|
export interface EncoreSQLDatabase {
|
|
7
8
|
/** Connection string for the database */
|
|
8
9
|
connectionString: string;
|
|
9
|
-
/** Query method
|
|
10
|
-
query(
|
|
11
|
-
rows: any[];
|
|
12
|
-
}>;
|
|
10
|
+
/** Query method - signature varies by Encore version */
|
|
11
|
+
query?: (...args: any[]) => any;
|
|
13
12
|
/** Connection string for use with standard PostgreSQL drivers */
|
|
14
|
-
stdConnString
|
|
13
|
+
stdConnString?: string;
|
|
14
|
+
[key: string]: any;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Type guard to check if an object is an Encore SQLDatabase
|
|
@@ -81,6 +81,75 @@ export type EncoreConnectionFactory = (moduleKey: string, schema?: string) => En
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
export declare function createEncoreConnectionFactory(databaseMap: Record<string, EncoreSQLDatabase>): EncoreConnectionFactory;
|
|
84
|
+
/**
|
|
85
|
+
* Module database configuration for service-oriented setup
|
|
86
|
+
*/
|
|
87
|
+
export interface ModuleDatabaseConfig {
|
|
88
|
+
/** Map of module keys to their corresponding SQLDatabases */
|
|
89
|
+
modules: Record<string, EncoreSQLDatabase>;
|
|
90
|
+
/** Default database for modules not in the map */
|
|
91
|
+
default: EncoreSQLDatabase;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Result of createConnectionFactory - provides everything needed for runtime setup
|
|
95
|
+
*/
|
|
96
|
+
export interface ConnectionFactoryResult {
|
|
97
|
+
/** Connection factory function for module database routing */
|
|
98
|
+
connectionFactory: (moduleKey: string, schema?: string) => EncoreSQLDatabase;
|
|
99
|
+
/** Connection string of the default database */
|
|
100
|
+
defaultUrl: string;
|
|
101
|
+
/** The default SQLDatabase instance */
|
|
102
|
+
defaultDatabase: EncoreSQLDatabase;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Create a connection factory with default fallback for service-oriented setup
|
|
106
|
+
*
|
|
107
|
+
* This is the recommended way to configure database routing in eto applications.
|
|
108
|
+
* It provides a single source of truth for module-to-database mapping with sensible defaults.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* // services/admin/databases.ts
|
|
113
|
+
* import { SQLDatabase } from "encore.dev/storage/sqldb"
|
|
114
|
+
* import { createConnectionFactory } from "@etohq/framework"
|
|
115
|
+
*
|
|
116
|
+
* export const databases = {
|
|
117
|
+
* core: new SQLDatabase("conz_db", { migrations: "./migrations/core" }),
|
|
118
|
+
* execution: new SQLDatabase("execution_db", { migrations: "./migrations/execution" }),
|
|
119
|
+
* session: new SQLDatabase("session_db", { migrations: "./migrations/session" }),
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* export const dbConfig = createConnectionFactory({
|
|
123
|
+
* modules: {
|
|
124
|
+
* execution: databases.execution,
|
|
125
|
+
* compliance: databases.execution, // shares with execution
|
|
126
|
+
* ona: databases.execution, // shares with execution
|
|
127
|
+
* session: databases.session,
|
|
128
|
+
* },
|
|
129
|
+
* default: databases.core,
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // services/admin/runtime.ts
|
|
136
|
+
* import { dbConfig } from "./databases"
|
|
137
|
+
*
|
|
138
|
+
* const runtime = new EtoRuntime({...})
|
|
139
|
+
*
|
|
140
|
+
* await runtime.create({
|
|
141
|
+
* projectConfig: {
|
|
142
|
+
* databaseUrl: dbConfig.defaultUrl,
|
|
143
|
+
* },
|
|
144
|
+
* })
|
|
145
|
+
*
|
|
146
|
+
* // In loader
|
|
147
|
+
* export default withLoader({
|
|
148
|
+
* connectionFactory: dbConfig.connectionFactory,
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function createConnectionFactory(config: ModuleDatabaseConfig): ConnectionFactoryResult;
|
|
84
153
|
/**
|
|
85
154
|
* Database routing configuration for eto runtime
|
|
86
155
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encore.d.ts","sourceRoot":"","sources":["../../src/database/encore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAE5C
|
|
1
|
+
{"version":3,"file":"encore.d.ts","sourceRoot":"","sources":["../../src/database/encore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAE5C;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,gBAAgB,EAAE,MAAM,CAAA;IACxB,wDAAwD;IACxD,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;IAC/B,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GA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iB,CAAA;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,oBAAoB,GAC3B,uBAAuB,CAmBzB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,6DAA6D;IAC7D,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAAA;CACvC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA;AACf,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA"}
|
package/dist/database/encore.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.pgConnectionLoader = exports.knex = void 0;
|
|
|
4
4
|
exports.isEncoreSQLDatabase = isEncoreSQLDatabase;
|
|
5
5
|
exports.createEncoreKnex = createEncoreKnex;
|
|
6
6
|
exports.createEncoreConnectionFactory = createEncoreConnectionFactory;
|
|
7
|
+
exports.createConnectionFactory = createConnectionFactory;
|
|
7
8
|
const postgresql_1 = require("@mikro-orm/postgresql");
|
|
8
9
|
Object.defineProperty(exports, "knex", { enumerable: true, get: function () { return postgresql_1.knex; } });
|
|
9
10
|
/**
|
|
@@ -84,6 +85,69 @@ function createEncoreConnectionFactory(databaseMap) {
|
|
|
84
85
|
return db;
|
|
85
86
|
};
|
|
86
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a connection factory with default fallback for service-oriented setup
|
|
90
|
+
*
|
|
91
|
+
* This is the recommended way to configure database routing in eto applications.
|
|
92
|
+
* It provides a single source of truth for module-to-database mapping with sensible defaults.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* // services/admin/databases.ts
|
|
97
|
+
* import { SQLDatabase } from "encore.dev/storage/sqldb"
|
|
98
|
+
* import { createConnectionFactory } from "@etohq/framework"
|
|
99
|
+
*
|
|
100
|
+
* export const databases = {
|
|
101
|
+
* core: new SQLDatabase("conz_db", { migrations: "./migrations/core" }),
|
|
102
|
+
* execution: new SQLDatabase("execution_db", { migrations: "./migrations/execution" }),
|
|
103
|
+
* session: new SQLDatabase("session_db", { migrations: "./migrations/session" }),
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* export const dbConfig = createConnectionFactory({
|
|
107
|
+
* modules: {
|
|
108
|
+
* execution: databases.execution,
|
|
109
|
+
* compliance: databases.execution, // shares with execution
|
|
110
|
+
* ona: databases.execution, // shares with execution
|
|
111
|
+
* session: databases.session,
|
|
112
|
+
* },
|
|
113
|
+
* default: databases.core,
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // services/admin/runtime.ts
|
|
120
|
+
* import { dbConfig } from "./databases"
|
|
121
|
+
*
|
|
122
|
+
* const runtime = new EtoRuntime({...})
|
|
123
|
+
*
|
|
124
|
+
* await runtime.create({
|
|
125
|
+
* projectConfig: {
|
|
126
|
+
* databaseUrl: dbConfig.defaultUrl,
|
|
127
|
+
* },
|
|
128
|
+
* })
|
|
129
|
+
*
|
|
130
|
+
* // In loader
|
|
131
|
+
* export default withLoader({
|
|
132
|
+
* connectionFactory: dbConfig.connectionFactory,
|
|
133
|
+
* })
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
function createConnectionFactory(config) {
|
|
137
|
+
const { modules, default: defaultDb } = config;
|
|
138
|
+
const connectionFactory = (moduleKey, schema) => {
|
|
139
|
+
const db = modules[moduleKey];
|
|
140
|
+
if (db) {
|
|
141
|
+
return db;
|
|
142
|
+
}
|
|
143
|
+
return defaultDb;
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
connectionFactory,
|
|
147
|
+
defaultUrl: defaultDb.connectionString,
|
|
148
|
+
defaultDatabase: defaultDb,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
87
151
|
var pg_connection_loader_1 = require("./pg-connection-loader");
|
|
88
152
|
Object.defineProperty(exports, "pgConnectionLoader", { enumerable: true, get: function () { return pg_connection_loader_1.pgConnectionLoader; } });
|
|
89
153
|
//# sourceMappingURL=encore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encore.js","sourceRoot":"","sources":["../../src/database/encore.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"encore.js","sourceRoot":"","sources":["../../src/database/encore.ts"],"names":[],"mappings":";;;AAoBA,kDAOC;AAyCD,4CAoBC;AA8BD,sEAgBC;AAwED,0DAqBC;AAnOD,sDAA4C;AA6OnC,qFA7OA,iBAAI,OA6OA;AA5Nb;;GAEG;AACH,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,OAAO,CACL,GAAG;QACH,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAO,GAAG,CAAC,gBAAgB,KAAK,QAAQ;QACxC,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU,CAChC,CAAA;AACH,CAAC;AAoBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,gBAAgB,CAC9B,MAAwB;IAExB,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEvD,OAAO,IAAA,iBAAI,EAAW;QACpB,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,MAAM;QAClB,UAAU,EAAE;YACV,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;SAC/C;QACD,IAAI,EAAE;YACJ,oBAAoB,EAAE,KAAK;YAC3B,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;YACnB,GAAG,EAAE,IAAI,EAAE,GAAG;YACd,iBAAiB,EAAE,IAAI,EAAE,iBAAiB;YAC1C,kBAAkB,EAAE,IAAI,EAAE,kBAAkB;YAC5C,yBAAyB,EAAE,IAAI,EAAE,yBAAyB;SAC3D;KACF,CAAC,CAAA;AACJ,CAAC;AAUD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,6BAA6B,CAC3C,WAA8C;IAE9C,OAAO,CACL,SAAiB,EACjB,MAAe,EACgB,EAAE;QACjC,MAAM,EAAE,GAAG,WAAW,CAAC,SAAS,CAAC,CAAA;QACjC,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,OAAO,CAAC,IAAI,CACV,wCAAwC,SAAS,kBAAkB,CACpE,CAAA;YACD,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;AACH,CAAC;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,SAAgB,uBAAuB,CACrC,MAA4B;IAE5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAA;IAE9C,MAAM,iBAAiB,GAAG,CACxB,SAAiB,EACjB,MAAe,EACI,EAAE;QACrB,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;QAC7B,IAAI,EAAE,EAAE,CAAC;YACP,OAAO,EAAE,CAAA;QACX,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC,CAAA;IAED,OAAO;QACL,iBAAiB;QACjB,UAAU,EAAE,SAAS,CAAC,gBAAgB;QACtC,eAAe,EAAE,SAAS;KAC3B,CAAA;AACH,CAAC;AAWD,+DAA2D;AAAlD,0HAAA,kBAAkB,OAAA"}
|
package/dist/database/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
package/dist/database/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
require("../types/container");
|
|
18
18
|
__exportStar(require("./pg-connection-loader"), exports);
|
|
19
19
|
__exportStar(require("./encore"), exports);
|
|
20
|
+
__exportStar(require("./service"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8BAA2B;AAC3B,yDAAsC;AACtC,2CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8BAA2B;AAC3B,yDAAsC;AACtC,2CAAwB;AACxB,4CAAyB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Eto } from "../eto";
|
|
2
|
+
import type { EtoContainer } from "../container";
|
|
3
|
+
import type { FlagSettings } from "@etohq/types";
|
|
4
|
+
import { type EncoreSQLDatabase } from "./encore";
|
|
5
|
+
export interface ServiceModuleDefinition<TKey extends string = string> {
|
|
6
|
+
key: TKey;
|
|
7
|
+
defaultPackage: string | any;
|
|
8
|
+
label?: string;
|
|
9
|
+
resolvePath?: string;
|
|
10
|
+
isRequired?: boolean;
|
|
11
|
+
options?: Record<string, any>;
|
|
12
|
+
isQueryable?: boolean;
|
|
13
|
+
dependencies?: string[];
|
|
14
|
+
__passSharedContainer?: boolean;
|
|
15
|
+
defaultModuleDeclaration?: any;
|
|
16
|
+
database?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ServiceConfig {
|
|
19
|
+
name: string;
|
|
20
|
+
databases: Record<string, EncoreSQLDatabase>;
|
|
21
|
+
defaultDatabase?: string;
|
|
22
|
+
modules: ServiceModuleDefinition[];
|
|
23
|
+
featureFlags?: (string | Record<string, FlagSettings>)[];
|
|
24
|
+
backgroundLoaders?: (() => Promise<void>)[];
|
|
25
|
+
requestMetaProvider?: () => any;
|
|
26
|
+
onReady?: (eto: Eto) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export interface ServiceInstance {
|
|
29
|
+
getEto: () => Promise<Eto>;
|
|
30
|
+
getContainer: () => Promise<EtoContainer>;
|
|
31
|
+
isReady: () => boolean;
|
|
32
|
+
connectionFactory: (moduleKey: string, schema?: string) => EncoreSQLDatabase;
|
|
33
|
+
defaultUrl: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function defineService(config: ServiceConfig): ServiceInstance;
|
|
36
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/database/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAA0B,YAAY,EAAE,MAAM,cAAc,CAAA;AACxE,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAI1E,MAAM,WAAW,uBAAuB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IACnE,GAAG,EAAE,IAAI,CAAA;IACT,cAAc,EAAE,MAAM,GAAG,GAAG,CAAA;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,wBAAwB,CAAC,EAAE,GAAG,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;IAC5C,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,uBAAuB,EAAE,CAAA;IAClC,YAAY,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,CAAA;IACxD,iBAAiB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAA;IAC3C,mBAAmB,CAAC,EAAE,MAAM,GAAG,CAAA;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACtC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1B,YAAY,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAA;IACzC,OAAO,EAAE,MAAM,OAAO,CAAA;IACtB,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,iBAAiB,CAAA;IAC5E,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe,CAsFpE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineService = defineService;
|
|
4
|
+
const encore_1 = require("./encore");
|
|
5
|
+
const eto_1 = require("../eto");
|
|
6
|
+
const loader_1 = require("../loader");
|
|
7
|
+
function defineService(config) {
|
|
8
|
+
const { databases, defaultDatabase, modules, featureFlags, backgroundLoaders, requestMetaProvider, onReady, } = config;
|
|
9
|
+
const defaultDb = defaultDatabase
|
|
10
|
+
? databases[defaultDatabase]
|
|
11
|
+
: Object.values(databases)[0];
|
|
12
|
+
const moduleToDb = buildModuleDatabaseMap(modules, databases, defaultDb);
|
|
13
|
+
const dbConfig = (0, encore_1.createConnectionFactory)({
|
|
14
|
+
modules: moduleToDb,
|
|
15
|
+
default: defaultDb,
|
|
16
|
+
});
|
|
17
|
+
const modulesWithDb = injectDatabaseConfig(modules, dbConfig.connectionFactory);
|
|
18
|
+
let etoInstance = null;
|
|
19
|
+
let etoInitPromise = null;
|
|
20
|
+
const loader = (0, loader_1.withLoader)({
|
|
21
|
+
directory: ".",
|
|
22
|
+
modulesDefinitionInput: modulesWithDb,
|
|
23
|
+
linkModule: undefined,
|
|
24
|
+
featureFlags: featureFlags ?? [],
|
|
25
|
+
backgroundLoaders: backgroundLoaders ?? [],
|
|
26
|
+
});
|
|
27
|
+
const runtimeOptions = {};
|
|
28
|
+
if (requestMetaProvider) {
|
|
29
|
+
runtimeOptions.requestMetaProvider = requestMetaProvider;
|
|
30
|
+
}
|
|
31
|
+
const runtime = new eto_1.EtoRuntime({
|
|
32
|
+
loader,
|
|
33
|
+
runtime: {
|
|
34
|
+
options: runtimeOptions,
|
|
35
|
+
},
|
|
36
|
+
generateTypes: false,
|
|
37
|
+
env: {},
|
|
38
|
+
});
|
|
39
|
+
const initializeEto = async () => {
|
|
40
|
+
if (!etoInitPromise) {
|
|
41
|
+
etoInitPromise = runtime
|
|
42
|
+
.create({
|
|
43
|
+
projectConfig: {
|
|
44
|
+
databaseUrl: dbConfig.defaultUrl,
|
|
45
|
+
http: {
|
|
46
|
+
jwtSecret: "test",
|
|
47
|
+
cookieSecret: "test",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
.then(async (eto) => {
|
|
52
|
+
etoInstance = eto;
|
|
53
|
+
if (onReady) {
|
|
54
|
+
await onReady(eto);
|
|
55
|
+
}
|
|
56
|
+
return eto;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return etoInitPromise;
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
getEto: async () => initializeEto(),
|
|
63
|
+
getContainer: async () => {
|
|
64
|
+
const eto = await initializeEto();
|
|
65
|
+
return eto.container;
|
|
66
|
+
},
|
|
67
|
+
isReady: () => etoInstance !== null,
|
|
68
|
+
connectionFactory: dbConfig.connectionFactory,
|
|
69
|
+
defaultUrl: dbConfig.defaultUrl,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function buildModuleDatabaseMap(modules, databases, defaultDb) {
|
|
73
|
+
const map = {};
|
|
74
|
+
for (const module of modules) {
|
|
75
|
+
const moduleKey = module.key;
|
|
76
|
+
if (!moduleKey)
|
|
77
|
+
continue;
|
|
78
|
+
const dbName = module.database;
|
|
79
|
+
if (dbName && databases[dbName]) {
|
|
80
|
+
map[moduleKey] = databases[dbName];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
map[moduleKey] = defaultDb;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return map;
|
|
87
|
+
}
|
|
88
|
+
function injectDatabaseConfig(modules, connectionFactory) {
|
|
89
|
+
return modules.map((module) => {
|
|
90
|
+
const { database: _, ...rest } = module;
|
|
91
|
+
const existingOptions = rest.options || {};
|
|
92
|
+
return {
|
|
93
|
+
...rest,
|
|
94
|
+
options: {
|
|
95
|
+
...existingOptions,
|
|
96
|
+
database: {
|
|
97
|
+
connectionFactory,
|
|
98
|
+
schema: "public",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/database/service.ts"],"names":[],"mappings":";;AAwCA,sCAsFC;AA3HD,qCAA0E;AAC1E,gCAAmC;AACnC,sCAAsC;AAmCtC,SAAgB,aAAa,CAAC,MAAqB;IACjD,MAAM,EACJ,SAAS,EACT,eAAe,E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AG,SAAS,CAAA;QACtC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,oBAAoB,CAC3B,OAAkC,EAClC,iBAA4E;IAE5E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAA;QAEvC,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAA;QAE1C,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE;gBACP,GAAG,eAAe;gBAClB,QAAQ,EAAE;oBACR,iBAAiB;oBACjB,MAAM,EAAE,QAAQ;iBACjB;aACF;SACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etohq/framework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -199,13 +199,13 @@
|
|
|
199
199
|
"ulid": "2.3.0",
|
|
200
200
|
"stack-trace": "0.0.10",
|
|
201
201
|
"ora": "5.4.1",
|
|
202
|
-
"@etohq/link-modules-sdk": "
|
|
203
|
-
"@etohq/modules-sdk": "
|
|
204
|
-
"@etohq/orchestration": "
|
|
205
|
-
"@etohq/runtime": "
|
|
206
|
-
"@etohq/
|
|
207
|
-
"@etohq/workflows-sdk": "
|
|
208
|
-
"@etohq/
|
|
202
|
+
"@etohq/link-modules-sdk": "2.0.0",
|
|
203
|
+
"@etohq/modules-sdk": "2.0.0",
|
|
204
|
+
"@etohq/orchestration": "2.0.0",
|
|
205
|
+
"@etohq/runtime": "2.0.0",
|
|
206
|
+
"@etohq/types": "2.0.0",
|
|
207
|
+
"@etohq/workflows-sdk": "2.0.0",
|
|
208
|
+
"@etohq/utils": "2.0.0"
|
|
209
209
|
},
|
|
210
210
|
"peerDependencies": {
|
|
211
211
|
"@mikro-orm/cli": "6.4.3",
|
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
"ioredis": "5.4.1",
|
|
218
218
|
"pg": "8.13.0",
|
|
219
219
|
"vite": "5.2.11",
|
|
220
|
-
"@etohq/cli": "
|
|
220
|
+
"@etohq/cli": "2.0.0"
|
|
221
221
|
},
|
|
222
222
|
"peerDependenciesMeta": {
|
|
223
223
|
"@mikro-orm/cli": {
|