orchid-orm 1.5.19 → 1.5.21
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 +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/codegen/appCodeUpdater.test.ts +17 -8
- package/src/codegen/appCodeUpdater.ts +20 -9
- 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.21",
|
|
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.21",
|
|
59
59
|
"rimraf": "^3.0.2",
|
|
60
60
|
"rollup": "^2.79.0",
|
|
61
61
|
"rollup-plugin-dts": "^4.2.2",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appCodeUpdater } from './appCodeUpdater';
|
|
2
2
|
import { asMock, ast } from './testUtils';
|
|
3
3
|
import { updateMainFile } from './updateMainFile';
|
|
4
|
-
import
|
|
4
|
+
import path from 'path';
|
|
5
5
|
import { updateTableFile } from './updateTableFile/updateTableFile';
|
|
6
6
|
import { createBaseTableFile } from './createBaseTableFile';
|
|
7
7
|
|
|
@@ -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);
|
|
@@ -42,12 +47,16 @@ describe('appCodeUpdater', () => {
|
|
|
42
47
|
|
|
43
48
|
const [table] = asMock(updateTableFile).mock.calls[0];
|
|
44
49
|
expect(table.tablePath('table')).toBe(tablePath);
|
|
45
|
-
expect(table.baseTablePath).toBe(
|
|
50
|
+
expect(table.baseTablePath).toBe(
|
|
51
|
+
path.resolve(__dirname, params.baseTablePath),
|
|
52
|
+
);
|
|
46
53
|
expect(table.baseTableName).toBe(params.baseTableName);
|
|
47
54
|
expect(table.mainFilePath).toBe(mainFilePath);
|
|
48
55
|
|
|
49
56
|
const [base] = asMock(createBaseTableFile).mock.calls[0];
|
|
50
|
-
expect(base.baseTablePath).toBe(
|
|
57
|
+
expect(base.baseTablePath).toBe(
|
|
58
|
+
path.resolve(__dirname, params.baseTablePath),
|
|
59
|
+
);
|
|
51
60
|
expect(base.baseTableName).toBe(params.baseTableName);
|
|
52
61
|
});
|
|
53
62
|
|
|
@@ -55,11 +64,11 @@ describe('appCodeUpdater', () => {
|
|
|
55
64
|
const cache = {};
|
|
56
65
|
expect(createBaseTableFile).not.toBeCalled();
|
|
57
66
|
|
|
58
|
-
await fn({ ast: ast.addTable, options: {}, cache });
|
|
67
|
+
await fn({ ast: ast.addTable, options: {}, basePath: __dirname, cache });
|
|
59
68
|
|
|
60
69
|
expect(createBaseTableFile).toBeCalledTimes(1);
|
|
61
70
|
|
|
62
|
-
await fn({ ast: ast.addTable, options: {}, cache });
|
|
71
|
+
await fn({ ast: ast.addTable, options: {}, basePath: __dirname, cache });
|
|
63
72
|
|
|
64
73
|
expect(createBaseTableFile).toBeCalledTimes(1);
|
|
65
74
|
});
|
|
@@ -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
|
|
|
@@ -13,16 +14,23 @@ export type AppCodeUpdaterConfig = {
|
|
|
13
14
|
mainFilePath: string;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
export const appCodeUpdater = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export const appCodeUpdater = ({
|
|
18
|
+
tablePath,
|
|
19
|
+
baseTablePath,
|
|
20
|
+
baseTableName,
|
|
21
|
+
mainFilePath,
|
|
22
|
+
}: SetOptional<AppCodeUpdaterConfig, 'baseTableName'>): AppCodeUpdater => {
|
|
23
|
+
return async ({ ast, options, basePath, cache: cacheObject }) => {
|
|
24
|
+
const params: AppCodeUpdaterConfig = {
|
|
25
|
+
tablePath(name: string) {
|
|
26
|
+
const file = tablePath(name);
|
|
27
|
+
return resolvePath(basePath, file);
|
|
28
|
+
},
|
|
29
|
+
baseTablePath: resolvePath(basePath, baseTablePath),
|
|
30
|
+
baseTableName: baseTableName || 'BaseTable',
|
|
31
|
+
mainFilePath: resolvePath(basePath, mainFilePath),
|
|
32
|
+
};
|
|
24
33
|
|
|
25
|
-
return async ({ ast, options, cache: cacheObject }) => {
|
|
26
34
|
const promises: Promise<void>[] = [
|
|
27
35
|
updateMainFile(params.mainFilePath, params.tablePath, ast, options),
|
|
28
36
|
updateTableFile({ ...params, ast }),
|
|
@@ -40,3 +48,6 @@ export const appCodeUpdater = (
|
|
|
40
48
|
await Promise.all(promises);
|
|
41
49
|
};
|
|
42
50
|
};
|
|
51
|
+
|
|
52
|
+
const resolvePath = (basePath: string, filePath: string) =>
|
|
53
|
+
path.isAbsolute(filePath) ? filePath : path.resolve(basePath, filePath);
|
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
|
|