orchid-orm 1.5.20 → 1.5.22
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/codegen/appCodeUpdater.test.ts +7 -3
- package/src/codegen/appCodeUpdater.ts +14 -10
- package/src/codegen/updateMainFile.test.ts +19 -4
- package/src/codegen/updateMainFile.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orchid-orm",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.22",
|
|
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.22",
|
|
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
|
|
|
@@ -47,12 +47,16 @@ describe('appCodeUpdater', () => {
|
|
|
47
47
|
|
|
48
48
|
const [table] = asMock(updateTableFile).mock.calls[0];
|
|
49
49
|
expect(table.tablePath('table')).toBe(tablePath);
|
|
50
|
-
expect(table.baseTablePath).toBe(
|
|
50
|
+
expect(table.baseTablePath).toBe(
|
|
51
|
+
path.resolve(__dirname, params.baseTablePath),
|
|
52
|
+
);
|
|
51
53
|
expect(table.baseTableName).toBe(params.baseTableName);
|
|
52
54
|
expect(table.mainFilePath).toBe(mainFilePath);
|
|
53
55
|
|
|
54
56
|
const [base] = asMock(createBaseTableFile).mock.calls[0];
|
|
55
|
-
expect(base.baseTablePath).toBe(
|
|
57
|
+
expect(base.baseTablePath).toBe(
|
|
58
|
+
path.resolve(__dirname, params.baseTablePath),
|
|
59
|
+
);
|
|
56
60
|
expect(base.baseTableName).toBe(params.baseTableName);
|
|
57
61
|
});
|
|
58
62
|
|
|
@@ -14,20 +14,21 @@ export type AppCodeUpdaterConfig = {
|
|
|
14
14
|
mainFilePath: string;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const appCodeUpdater = (
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export const appCodeUpdater = ({
|
|
18
|
+
tablePath,
|
|
19
|
+
baseTablePath,
|
|
20
|
+
baseTableName,
|
|
21
|
+
mainFilePath,
|
|
22
|
+
}: SetOptional<AppCodeUpdaterConfig, 'baseTableName'>): AppCodeUpdater => {
|
|
20
23
|
return async ({ ast, options, basePath, cache: cacheObject }) => {
|
|
21
24
|
const params: AppCodeUpdaterConfig = {
|
|
22
|
-
...config,
|
|
23
|
-
baseTableName: config.baseTableName || 'BaseTable',
|
|
24
25
|
tablePath(name: string) {
|
|
25
|
-
const file =
|
|
26
|
-
return
|
|
26
|
+
const file = tablePath(name);
|
|
27
|
+
return resolvePath(basePath, file);
|
|
27
28
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
baseTablePath: resolvePath(basePath, baseTablePath),
|
|
30
|
+
baseTableName: baseTableName || 'BaseTable',
|
|
31
|
+
mainFilePath: resolvePath(basePath, mainFilePath),
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
const promises: Promise<void>[] = [
|
|
@@ -47,3 +48,6 @@ export const appCodeUpdater = (
|
|
|
47
48
|
await Promise.all(promises);
|
|
48
49
|
};
|
|
49
50
|
};
|
|
51
|
+
|
|
52
|
+
const resolvePath = (basePath: string, filePath: string) =>
|
|
53
|
+
path.isAbsolute(filePath) ? filePath : path.resolve(basePath, filePath);
|
|
@@ -85,10 +85,10 @@ export const db = custom({}, {
|
|
|
85
85
|
it('should handle object list with elements', async () => {
|
|
86
86
|
asMock(fs.readFile).mockResolvedValue(`
|
|
87
87
|
import { orchidORM } from 'orchid-orm';
|
|
88
|
-
import {
|
|
88
|
+
import { Other } from './tables/other';
|
|
89
89
|
|
|
90
90
|
export const db = orchidORM({}, {
|
|
91
|
-
|
|
91
|
+
other: Other,
|
|
92
92
|
});
|
|
93
93
|
`);
|
|
94
94
|
|
|
@@ -96,11 +96,11 @@ export const db = orchidORM({}, {
|
|
|
96
96
|
|
|
97
97
|
testWritten(`
|
|
98
98
|
import { orchidORM } from 'orchid-orm';
|
|
99
|
-
import {
|
|
99
|
+
import { Other } from './tables/other';
|
|
100
100
|
import { SomeTable } from './tables/some.table';
|
|
101
101
|
|
|
102
102
|
export const db = orchidORM({}, {
|
|
103
|
-
|
|
103
|
+
other: Other,
|
|
104
104
|
some: SomeTable,
|
|
105
105
|
});
|
|
106
106
|
`);
|
|
@@ -234,5 +234,20 @@ export const db = orchidORM({}, {
|
|
|
234
234
|
});
|
|
235
235
|
`);
|
|
236
236
|
});
|
|
237
|
+
|
|
238
|
+
it('should not insert table if table with same key exists, disregarding the import path', async () => {
|
|
239
|
+
asMock(fs.readFile).mockResolvedValue(`
|
|
240
|
+
import { orchidORM } from 'orchid-orm';
|
|
241
|
+
import { X } from './x';
|
|
242
|
+
|
|
243
|
+
export const db = orchidORM({}, {
|
|
244
|
+
some: X,
|
|
245
|
+
});
|
|
246
|
+
`);
|
|
247
|
+
|
|
248
|
+
await updateMainFile(mainFilePath, tablePath, ast.addTable, options);
|
|
249
|
+
|
|
250
|
+
expect(fs.writeFile).not.toBeCalled();
|
|
251
|
+
});
|
|
237
252
|
});
|
|
238
253
|
});
|
|
@@ -128,6 +128,12 @@ const createTable = (
|
|
|
128
128
|
);
|
|
129
129
|
if (existing.length) return;
|
|
130
130
|
|
|
131
|
+
for (const prop of object.properties) {
|
|
132
|
+
if (key === ts.prop.getName(prop)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
131
137
|
const importPos = ts.import.getEndPos(statements);
|
|
132
138
|
changes.add(
|
|
133
139
|
importPos,
|