@etohq/test-utils 1.4.0 → 1.5.1-alpha.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.d.ts.map +1 -1
- package/dist/database.js +113 -39
- package/dist/database.js.map +1 -1
- package/dist/eto-test-runner-utils/utils.d.ts +8 -0
- package/dist/eto-test-runner-utils/utils.d.ts.map +1 -1
- package/dist/eto-test-runner-utils/utils.js +15 -0
- package/dist/eto-test-runner-utils/utils.js.map +1 -1
- package/package.json +9 -9
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAezF,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAStD;AAED,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GACP,EAAE;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAgBV;AAED,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,GAAG,EAAE,QAAQ,GAAG,IAAI,CAAA;IACpB,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAEhC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,UAAU,IAAI,gBAAgB,CAAA;IAC9B,WAAW,IAAI,gBAAgB,CAAA;IAC/B,MAAM,IAAI,QAAQ,CAAA;CACnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,MAAM,GACP,EAAE;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,YAAY,CAiHf;AAED,eAAO,MAAM,iBAAiB,QAAO,GA6FnC,CAAA"}
|
package/dist/database.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.getMikroOrmConfig = getMikroOrmConfig;
|
|
|
6
6
|
exports.getMikroOrmWrapper = getMikroOrmWrapper;
|
|
7
7
|
const postgresql_1 = require("@mikro-orm/postgresql");
|
|
8
8
|
const pg_god_1 = require("pg-god");
|
|
9
|
+
const eto_test_runner_utils_1 = require("./eto-test-runner-utils");
|
|
9
10
|
const DB_HOST = process.env.DB_HOST ?? "localhost";
|
|
10
11
|
const DB_USERNAME = process.env.DB_USERNAME ?? "";
|
|
11
12
|
const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
|
|
@@ -16,15 +17,14 @@ const pgGodCredentials = {
|
|
|
16
17
|
};
|
|
17
18
|
function getDatabaseURL(dbName) {
|
|
18
19
|
const DB_HOST = process.env.DB_HOST ?? "localhost";
|
|
19
|
-
const DB_USERNAME = process.env.DB_USERNAME ?? "";
|
|
20
|
+
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres";
|
|
20
21
|
const DB_PASSWORD = process.env.DB_PASSWORD;
|
|
21
22
|
const DB_NAME = dbName ?? process.env.DB_TEMP_NAME;
|
|
22
23
|
return `postgres://${DB_USERNAME}${DB_PASSWORD ? `:${DB_PASSWORD}` : ""}@${DB_HOST}/${DB_NAME}`;
|
|
23
24
|
}
|
|
24
25
|
function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
|
|
25
26
|
const DB_URL = clientUrl ?? getDatabaseURL();
|
|
26
|
-
return {
|
|
27
|
-
type: "postgresql",
|
|
27
|
+
return (0, postgresql_1.defineConfig)({
|
|
28
28
|
clientUrl: DB_URL,
|
|
29
29
|
entities: Object.values(mikroOrmEntities),
|
|
30
30
|
schema: schema ?? process.env.ETO_DB_SCHEMA,
|
|
@@ -36,7 +36,7 @@ function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, sche
|
|
|
36
36
|
pathTs: pathToMigrations,
|
|
37
37
|
silent: true,
|
|
38
38
|
},
|
|
39
|
-
};
|
|
39
|
+
});
|
|
40
40
|
}
|
|
41
41
|
function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
|
|
42
42
|
return {
|
|
@@ -71,68 +71,142 @@ function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, sch
|
|
|
71
71
|
clientUrl: this.clientUrl,
|
|
72
72
|
schema: this.schema,
|
|
73
73
|
});
|
|
74
|
-
// Initializing the ORM
|
|
75
|
-
this.orm = await postgresql_1.MikroORM.init(OrmConfig);
|
|
76
|
-
this.manager = this.orm.em;
|
|
77
74
|
try {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
await this.orm
|
|
75
|
+
this.orm = await postgresql_1.MikroORM.init(OrmConfig);
|
|
76
|
+
this.manager = this.orm.em;
|
|
77
|
+
try {
|
|
78
|
+
await this.orm.getSchemaGenerator().ensureDatabase();
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error("Error ensuring database:", err);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
85
|
+
const pendingMigrations = await this.orm
|
|
89
86
|
.getMigrator()
|
|
90
|
-
.
|
|
87
|
+
.getPendingMigrations();
|
|
88
|
+
if (pendingMigrations && pendingMigrations.length > 0) {
|
|
89
|
+
await this.orm
|
|
90
|
+
.getMigrator()
|
|
91
|
+
.up({ migrations: pendingMigrations.map((m) => m.name) });
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await this.orm.schema.refreshDatabase();
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (this.orm) {
|
|
99
|
+
try {
|
|
100
|
+
await this.orm.close();
|
|
101
|
+
}
|
|
102
|
+
catch (closeError) {
|
|
103
|
+
console.error("Error closing ORM:", closeError);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.orm = null;
|
|
107
|
+
this.manager = null;
|
|
108
|
+
throw error;
|
|
94
109
|
}
|
|
95
110
|
},
|
|
96
111
|
async clearDatabase() {
|
|
97
112
|
if (this.orm === null) {
|
|
98
113
|
throw new Error("ORM not configured");
|
|
99
114
|
}
|
|
100
|
-
await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
|
|
101
|
-
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
102
115
|
try {
|
|
103
|
-
await this.
|
|
116
|
+
await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
|
|
117
|
+
await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
|
|
118
|
+
const closePromise = this.orm.close();
|
|
119
|
+
await (0, eto_test_runner_utils_1.execOrTimeout)(closePromise);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error("Error clearing database:", error);
|
|
123
|
+
try {
|
|
124
|
+
await this.orm?.close();
|
|
125
|
+
}
|
|
126
|
+
catch (closeError) {
|
|
127
|
+
console.error("Error during forced ORM close:", closeError);
|
|
128
|
+
}
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.orm = null;
|
|
133
|
+
this.manager = null;
|
|
104
134
|
}
|
|
105
|
-
catch { }
|
|
106
|
-
this.orm = null;
|
|
107
|
-
this.manager = null;
|
|
108
135
|
},
|
|
109
136
|
};
|
|
110
137
|
}
|
|
111
138
|
const dbTestUtilFactory = () => ({
|
|
112
139
|
pgConnection_: null,
|
|
113
140
|
create: async function (dbName) {
|
|
114
|
-
|
|
141
|
+
try {
|
|
142
|
+
await (0, pg_god_1.createDatabase)({ databaseName: dbName, errorIfExist: false }, pgGodCredentials);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
console.error("Error creating database:", error);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
115
148
|
},
|
|
116
149
|
teardown: async function ({ schema } = {}) {
|
|
117
150
|
if (!this.pgConnection_) {
|
|
118
151
|
return;
|
|
119
152
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
try {
|
|
154
|
+
const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_);
|
|
155
|
+
schema ??= "public";
|
|
156
|
+
await runRawQuery(`SET session_replication_role = 'replica';`);
|
|
157
|
+
const { rows: tableNames } = await runRawQuery(`SELECT table_name
|
|
124
158
|
FROM information_schema.tables
|
|
125
159
|
WHERE table_schema = '${schema}';`);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
160
|
+
const skipIndexPartitionPrefix = "cat_";
|
|
161
|
+
const mainPartitionTables = ["index_data", "index_relation"];
|
|
162
|
+
let hasIndexTables = false;
|
|
163
|
+
for (const { table_name } of tableNames) {
|
|
164
|
+
if (mainPartitionTables.includes(table_name)) {
|
|
165
|
+
hasIndexTables = true;
|
|
166
|
+
}
|
|
167
|
+
if (table_name.startsWith(skipIndexPartitionPrefix) ||
|
|
168
|
+
mainPartitionTables.includes(table_name)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
await runRawQuery(`DELETE FROM ${schema}."${table_name}";`);
|
|
172
|
+
}
|
|
173
|
+
if (hasIndexTables) {
|
|
174
|
+
await runRawQuery(`TRUNCATE TABLE ${schema}.index_data;`);
|
|
175
|
+
await runRawQuery(`TRUNCATE TABLE ${schema}.index_relation;`);
|
|
176
|
+
}
|
|
177
|
+
await runRawQuery(`SET session_replication_role = 'origin';`);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error("Error during database teardown:", error);
|
|
181
|
+
throw error;
|
|
129
182
|
}
|
|
130
|
-
await runRawQuery(`SET session_replication_role = 'origin';`);
|
|
131
183
|
},
|
|
132
184
|
shutdown: async function (dbName) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
185
|
+
try {
|
|
186
|
+
const cleanupPromises = [];
|
|
187
|
+
if (this.pgConnection_?.context) {
|
|
188
|
+
cleanupPromises.push((0, eto_test_runner_utils_1.execOrTimeout)(this.pgConnection_.context.destroy()));
|
|
189
|
+
}
|
|
190
|
+
if (this.pgConnection_) {
|
|
191
|
+
cleanupPromises.push((0, eto_test_runner_utils_1.execOrTimeout)(this.pgConnection_.destroy()));
|
|
192
|
+
}
|
|
193
|
+
await Promise.all(cleanupPromises);
|
|
194
|
+
return await (0, pg_god_1.dropDatabase)({ databaseName: dbName, errorIfNonExist: false }, pgGodCredentials);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error("Error during database shutdown:", error);
|
|
198
|
+
try {
|
|
199
|
+
await this.pgConnection_?.context?.destroy();
|
|
200
|
+
await this.pgConnection_?.destroy();
|
|
201
|
+
}
|
|
202
|
+
catch (cleanupError) {
|
|
203
|
+
console.error("Error during forced cleanup:", cleanupError);
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
this.pgConnection_ = null;
|
|
209
|
+
}
|
|
136
210
|
},
|
|
137
211
|
});
|
|
138
212
|
exports.dbTestUtilFactory = dbTestUtilFactory;
|
package/dist/database.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;AAeA,wCASC;AAED,8CA0BC;AAkBD,gDA2HC;AAjMD,sDAAyF;AACzF,mCAAqD;AACrD,mEAAuD;AAGvD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAA;AAClD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;AACjD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAA;AAEjD,MAAM,gBAAgB,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,WAAW;IACrB,IAAI,EAAE,OAAO;CACd,CAAA;AAED,SAAgB,cAAc,CAAC,MAAe;IAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,CAAA;IAClD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,UAAU,CAAA;IACzD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;IAC3C,MAAM,OAAO,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAA;IAElD,OAAO,cAAc,WAAW,GAC9B,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EACpC,IAAI,OAAO,IAAI,OAAO,EAAE,CAAA;AAC1B,C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E,eAAe,EAAE,KAAK,EAAE,EAChD,gBAAgB,CACjB,CAAA;QACD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAA;YACvD,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;gBAC5C,MAAM,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAA;YACrC,CAAC;YAAC,OAAO,YAAY,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,YAAY,CAAC,CAAA;YAC7D,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QAC3B,CAAC;IACH,CAAC;CACF,CAAC,CAAA;AA7FW,QAAA,iBAAiB,qBA6F5B"}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export declare function applyEnvVarsToProcess(env?: Record<any, any>): void;
|
|
2
|
+
/**
|
|
3
|
+
* Execute a function and return a promise that resolves when the function
|
|
4
|
+
* resolves or rejects when the function rejects or the timeout is reached.
|
|
5
|
+
* @param fn - The function to execute.
|
|
6
|
+
* @param timeout - The timeout in milliseconds.
|
|
7
|
+
* @returns A promise that resolves when the function resolves or rejects when the function rejects or the timeout is reached.
|
|
8
|
+
*/
|
|
9
|
+
export declare function execOrTimeout(fn: Promise<any> | (() => Promise<void>), timeout?: number): Promise<any>;
|
|
2
10
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAI3D"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,qBAAqB,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAI3D;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,EACxC,OAAO,GAAE,MAAa,gBASvB"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyEnvVarsToProcess = applyEnvVarsToProcess;
|
|
4
|
+
exports.execOrTimeout = execOrTimeout;
|
|
4
5
|
const utils_1 = require("@etohq/framework/utils");
|
|
5
6
|
function applyEnvVarsToProcess(env) {
|
|
6
7
|
if ((0, utils_1.isObject)(env)) {
|
|
7
8
|
Object.entries(env).forEach(([k, v]) => (process.env[k] = v));
|
|
8
9
|
}
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Execute a function and return a promise that resolves when the function
|
|
13
|
+
* resolves or rejects when the function rejects or the timeout is reached.
|
|
14
|
+
* @param fn - The function to execute.
|
|
15
|
+
* @param timeout - The timeout in milliseconds.
|
|
16
|
+
* @returns A promise that resolves when the function resolves or rejects when the function rejects or the timeout is reached.
|
|
17
|
+
*/
|
|
18
|
+
async function execOrTimeout(fn, timeout = 5000) {
|
|
19
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
20
|
+
setTimeout(() => reject(new Error("Timeout")), timeout).unref();
|
|
21
|
+
});
|
|
22
|
+
const fnPromise = typeof fn === "function" ? fn() : fn;
|
|
23
|
+
return Promise.race([fnPromise, timeoutPromise]);
|
|
24
|
+
}
|
|
10
25
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":";;AAEA,sDAIC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/eto-test-runner-utils/utils.ts"],"names":[],"mappings":";;AAEA,sDAIC;AASD,sCAWC;AA1BD,kDAAiD;AAEjD,SAAgB,qBAAqB,CAAC,GAAsB;IAC1D,IAAI,IAAA,gBAAQ,EAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC/D,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,aAAa,CACjC,EAAwC,EACxC,UAAkB,IAAI;IAEtB,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;IACjE,CAAC,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEtD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAA;AAClD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etohq/test-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1-alpha.0",
|
|
4
4
|
"description": "Test utils for Eto",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"author": "Eto",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@mikro-orm/core": "
|
|
24
|
-
"@mikro-orm/knex": "
|
|
25
|
-
"@mikro-orm/migrations": "
|
|
26
|
-
"@mikro-orm/postgresql": "
|
|
23
|
+
"@mikro-orm/core": "6.4.3",
|
|
24
|
+
"@mikro-orm/knex": "6.4.3",
|
|
25
|
+
"@mikro-orm/migrations": "6.4.3",
|
|
26
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
27
27
|
"@types/jest": "29.5.14",
|
|
28
28
|
"awilix": "8.0.1",
|
|
29
29
|
"jest": "29.7.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"pg-god": "1.0.12",
|
|
32
32
|
"rimraf": "5.0.2",
|
|
33
33
|
"typescript": "5.8.3",
|
|
34
|
-
"@etohq/framework": "1.
|
|
34
|
+
"@etohq/framework": "1.5.1-alpha.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@types/express": "4.17.17",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"randomatic": "3.1.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@mikro-orm/postgresql": "
|
|
43
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
44
44
|
"awilix": "8.0.1",
|
|
45
|
-
"@etohq/eto": "1.
|
|
46
|
-
"@etohq/framework": "1.
|
|
45
|
+
"@etohq/eto": "1.5.1-alpha.0",
|
|
46
|
+
"@etohq/framework": "1.5.1-alpha.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependenciesMeta": {
|
|
49
49
|
"@etohq/eto": {
|