orchid-orm 1.5.21 → 1.5.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchid-orm",
3
- "version": "1.5.21",
3
+ "version": "1.5.23",
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.21",
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",
@@ -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 { Some } from './tables/some';
88
+ import { Other } from './tables/other';
89
89
 
90
90
  export const db = orchidORM({}, {
91
- some: Some,
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 { Some } from './tables/some';
99
+ import { Other } from './tables/other';
100
100
  import { SomeTable } from './tables/some.table';
101
101
 
102
102
  export const db = orchidORM({}, {
103
- some: Some,
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,
@@ -1,8 +1,13 @@
1
1
  import path from 'path';
2
2
 
3
3
  export const getImportPath = (from: string, to: string) => {
4
- const rel = path.posix.relative(path.dirname(from), to);
4
+ const rel = path
5
+ .relative(path.dirname(from), to)
6
+ .split(path.sep)
7
+ .join(path.posix.sep);
8
+
5
9
  const importPath =
6
10
  rel.startsWith('./') || rel.startsWith('../') ? rel : `./${rel}`;
11
+
7
12
  return importPath.replace(/\.[tj]s$/, '');
8
13
  };