orchid-orm 1.5.19 → 1.5.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-test.log +26 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/codegen/appCodeUpdater.test.ts +10 -5
- package/src/codegen/appCodeUpdater.ts +14 -7
- package/src/orm.test.ts +12 -4
- package/src/transaction.test.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orchid-orm",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.20",
|
|
4
4
|
"description": "Postgres ORM",
|
|
5
5
|
"homepage": "https://orchid-orm.netlify.app/guide/orm-setup-and-overview.html",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"orchid-orm-schema-to-zod": "0.2.18",
|
|
56
56
|
"pg": "^8.7.3",
|
|
57
57
|
"pg-transactional-tests": "^1.0.7",
|
|
58
|
-
"rake-db": "2.3.
|
|
58
|
+
"rake-db": "2.3.18",
|
|
59
59
|
"rimraf": "^3.0.2",
|
|
60
60
|
"rollup": "^2.79.0",
|
|
61
61
|
"rollup-plugin-dts": "^4.2.2",
|
|
@@ -30,10 +30,15 @@ describe('appCodeUpdater', () => {
|
|
|
30
30
|
const fn = appCodeUpdater(params);
|
|
31
31
|
|
|
32
32
|
it('should call table and file updaters with proper arguments', async () => {
|
|
33
|
-
await fn({
|
|
33
|
+
await fn({
|
|
34
|
+
ast: ast.addTable,
|
|
35
|
+
options: {},
|
|
36
|
+
basePath: __dirname,
|
|
37
|
+
cache: {},
|
|
38
|
+
});
|
|
34
39
|
|
|
35
|
-
const mainFilePath = path.resolve(params.mainFilePath);
|
|
36
|
-
const tablePath = path.resolve(params.tablePath('table'));
|
|
40
|
+
const mainFilePath = path.resolve(__dirname, params.mainFilePath);
|
|
41
|
+
const tablePath = path.resolve(__dirname, params.tablePath('table'));
|
|
37
42
|
|
|
38
43
|
const main = asMock(updateMainFile).mock.calls[0];
|
|
39
44
|
expect(main[0]).toBe(mainFilePath);
|
|
@@ -55,11 +60,11 @@ describe('appCodeUpdater', () => {
|
|
|
55
60
|
const cache = {};
|
|
56
61
|
expect(createBaseTableFile).not.toBeCalled();
|
|
57
62
|
|
|
58
|
-
await fn({ ast: ast.addTable, options: {}, cache });
|
|
63
|
+
await fn({ ast: ast.addTable, options: {}, basePath: __dirname, cache });
|
|
59
64
|
|
|
60
65
|
expect(createBaseTableFile).toBeCalledTimes(1);
|
|
61
66
|
|
|
62
|
-
await fn({ ast: ast.addTable, options: {}, cache });
|
|
67
|
+
await fn({ ast: ast.addTable, options: {}, basePath: __dirname, cache });
|
|
63
68
|
|
|
64
69
|
expect(createBaseTableFile).toBeCalledTimes(1);
|
|
65
70
|
});
|
|
@@ -3,6 +3,7 @@ import * as path from 'path';
|
|
|
3
3
|
import { updateMainFile } from './updateMainFile';
|
|
4
4
|
import { updateTableFile } from './updateTableFile/updateTableFile';
|
|
5
5
|
import { createBaseTableFile } from './createBaseTableFile';
|
|
6
|
+
import { SetOptional } from 'pqb';
|
|
6
7
|
|
|
7
8
|
export class AppCodeUpdaterError extends Error {}
|
|
8
9
|
|
|
@@ -14,15 +15,21 @@ export type AppCodeUpdaterConfig = {
|
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
export const appCodeUpdater = (
|
|
17
|
-
config: AppCodeUpdaterConfig,
|
|
18
|
+
config: SetOptional<AppCodeUpdaterConfig, 'baseTableName'>,
|
|
18
19
|
): AppCodeUpdater => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
return async ({ ast, options, basePath, cache: cacheObject }) => {
|
|
21
|
+
const params: AppCodeUpdaterConfig = {
|
|
22
|
+
...config,
|
|
23
|
+
baseTableName: config.baseTableName || 'BaseTable',
|
|
24
|
+
tablePath(name: string) {
|
|
25
|
+
const file = config.tablePath(name);
|
|
26
|
+
return path.isAbsolute(file) ? file : path.resolve(basePath, file);
|
|
27
|
+
},
|
|
28
|
+
mainFilePath: path.isAbsolute(config.mainFilePath)
|
|
29
|
+
? config.mainFilePath
|
|
30
|
+
: path.resolve(basePath, config.mainFilePath),
|
|
31
|
+
};
|
|
24
32
|
|
|
25
|
-
return async ({ ast, options, cache: cacheObject }) => {
|
|
26
33
|
const promises: Promise<void>[] = [
|
|
27
34
|
updateMainFile(params.mainFilePath, params.tablePath, ast, options),
|
|
28
35
|
updateTableFile({ ...params, ast }),
|
package/src/orm.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { orchidORM } from './orm';
|
|
1
|
+
import { OrchidORM, orchidORM } from './orm';
|
|
2
2
|
import {
|
|
3
3
|
assertType,
|
|
4
4
|
expectSql,
|
|
@@ -11,6 +11,14 @@ import { createBaseTable } from './table';
|
|
|
11
11
|
describe('orm', () => {
|
|
12
12
|
useTestDatabase();
|
|
13
13
|
|
|
14
|
+
let db:
|
|
15
|
+
| OrchidORM<{ user: typeof UserTable; profile: typeof ProfileTable }>
|
|
16
|
+
| undefined;
|
|
17
|
+
|
|
18
|
+
afterEach(async () => {
|
|
19
|
+
if (db) await db.$close();
|
|
20
|
+
});
|
|
21
|
+
|
|
14
22
|
const BaseTable = createBaseTable();
|
|
15
23
|
|
|
16
24
|
type User = UserTable['columns']['type'];
|
|
@@ -31,7 +39,7 @@ describe('orm', () => {
|
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
it('should return object with provided adapter, close and transaction method, tables', () => {
|
|
34
|
-
|
|
42
|
+
db = orchidORM(pgConfig, {
|
|
35
43
|
user: UserTable,
|
|
36
44
|
profile: ProfileTable,
|
|
37
45
|
});
|
|
@@ -45,7 +53,7 @@ describe('orm', () => {
|
|
|
45
53
|
});
|
|
46
54
|
|
|
47
55
|
it('should return table which is a queryable interface', async () => {
|
|
48
|
-
|
|
56
|
+
db = orchidORM(pgConfig, {
|
|
49
57
|
user: UserTable,
|
|
50
58
|
profile: ProfileTable,
|
|
51
59
|
});
|
|
@@ -71,7 +79,7 @@ describe('orm', () => {
|
|
|
71
79
|
});
|
|
72
80
|
|
|
73
81
|
it('should be able to turn on autoPreparedStatements', () => {
|
|
74
|
-
|
|
82
|
+
db = orchidORM(
|
|
75
83
|
{ ...pgConfig, autoPreparedStatements: true },
|
|
76
84
|
{
|
|
77
85
|
user: UserTable,
|
package/src/transaction.test.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { Client } from 'pg';
|
|
|
4
4
|
import { noop } from 'pqb';
|
|
5
5
|
|
|
6
6
|
describe('transaction', () => {
|
|
7
|
+
afterAll(db.$close);
|
|
8
|
+
|
|
7
9
|
it('should have override transaction method which implicitly connects tables with a single transaction', async () => {
|
|
8
10
|
const spy = jest.spyOn(Client.prototype, 'query');
|
|
9
11
|
|