pqb 0.3.6 → 0.3.7

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.
@@ -1,5 +1,5 @@
1
1
  import {
2
- AssertEqual,
2
+ assertType,
3
3
  expectQueryNotMutated,
4
4
  expectSql,
5
5
  User,
@@ -48,8 +48,7 @@ describe('update', () => {
48
48
  [users[0].id, users[1].id],
49
49
  );
50
50
 
51
- const eq: AssertEqual<Awaited<typeof query>, number> = true;
52
- expect(eq).toBe(true);
51
+ assertType<Awaited<typeof query>, number>();
53
52
 
54
53
  const result = await query;
55
54
  expect(result).toBe(count);
@@ -77,8 +76,7 @@ describe('update', () => {
77
76
  );
78
77
 
79
78
  const result = await query;
80
- const eq: AssertEqual<typeof result, number> = true;
81
- expect(eq).toBe(true);
79
+ assertType<typeof result, number>();
82
80
 
83
81
  expect(result).toBe(1);
84
82
 
@@ -109,8 +107,7 @@ describe('update', () => {
109
107
  );
110
108
 
111
109
  const result = await query;
112
- const eq: AssertEqual<typeof result, number> = true;
113
- expect(eq).toBe(true);
110
+ assertType<typeof result, number>();
114
111
 
115
112
  expect(typeof result).toBe('number');
116
113
 
@@ -137,8 +134,7 @@ describe('update', () => {
137
134
  );
138
135
 
139
136
  const result = await query;
140
- const eq: AssertEqual<typeof result, { id: number; name: string }> = true;
141
- expect(eq).toBe(true);
137
+ assertType<typeof result, { id: number; name: string }>();
142
138
 
143
139
  const updated = await User.take();
144
140
  expect(updated).toMatchObject({ ...userData, ...update });
@@ -163,8 +159,7 @@ describe('update', () => {
163
159
  );
164
160
 
165
161
  const result = await query;
166
- const eq: AssertEqual<typeof result, typeof User.type> = true;
167
- expect(eq).toBe(true);
162
+ assertType<typeof result, typeof User.type>();
168
163
 
169
164
  const updated = await User.take();
170
165
  expect(updated).toMatchObject({ ...userData, ...update });
@@ -196,8 +191,7 @@ describe('update', () => {
196
191
  );
197
192
 
198
193
  const result = await query;
199
- const eq: AssertEqual<typeof result, { id: number; name: string }[]> = true;
200
- expect(eq).toBe(true);
194
+ assertType<typeof result, { id: number; name: string }[]>();
201
195
 
202
196
  const updated = await User.take();
203
197
  expect(updated).toMatchObject({ ...userData, ...update });
@@ -231,8 +225,7 @@ describe('update', () => {
231
225
  const result = await query;
232
226
  expect(result[0]).toMatchObject({ ...userData, ...update });
233
227
 
234
- const eq: AssertEqual<typeof result, typeof User['type'][]> = true;
235
- expect(eq).toBe(true);
228
+ assertType<typeof result, typeof User['type'][]>();
236
229
 
237
230
  const updated = await User.take();
238
231
  expect(updated).toMatchObject({ ...userData, ...update });
@@ -256,8 +249,7 @@ describe('update', () => {
256
249
  ['new name', null, 1],
257
250
  );
258
251
 
259
- const eq: AssertEqual<Awaited<typeof query>, number> = true;
260
- expect(eq).toBe(true);
252
+ assertType<Awaited<typeof query>, number>();
261
253
  });
262
254
 
263
255
  it('should support raw sql as a value', () => {
@@ -274,8 +266,7 @@ describe('update', () => {
274
266
  [1],
275
267
  );
276
268
 
277
- const eq: AssertEqual<Awaited<typeof query>, number> = true;
278
- expect(eq).toBe(true);
269
+ assertType<Awaited<typeof query>, number>();
279
270
  });
280
271
 
281
272
  it('should return one record when searching for one to update', async () => {
@@ -301,8 +292,7 @@ describe('update', () => {
301
292
  );
302
293
 
303
294
  const result = await query;
304
- const eq: AssertEqual<typeof result, typeof User.type> = true;
305
- expect(eq).toBe(true);
295
+ assertType<typeof result, typeof User.type>();
306
296
 
307
297
  expect(result).toMatchObject({ ...userData, ...update });
308
298
  });
@@ -312,8 +302,7 @@ describe('update', () => {
312
302
  .findBy({ id: 1 })
313
303
  .update({ name: 'new name' });
314
304
 
315
- const eq: AssertEqual<Awaited<typeof query>, typeof User.type> = true;
316
- expect(eq).toBe(true);
305
+ assertType<Awaited<typeof query>, typeof User.type>();
317
306
 
318
307
  await expect(query).rejects.toThrow();
319
308
  });
@@ -378,8 +367,7 @@ describe('update', () => {
378
367
  [3],
379
368
  );
380
369
 
381
- const eq: AssertEqual<Awaited<typeof query>, { id: number }[]> = true;
382
- expect(eq).toBe(true);
370
+ assertType<Awaited<typeof query>, { id: number }[]>();
383
371
  });
384
372
  });
385
373
 
@@ -423,8 +411,7 @@ describe('update', () => {
423
411
  [3],
424
412
  );
425
413
 
426
- const eq: AssertEqual<Awaited<typeof query>, { id: number }[]> = true;
427
- expect(eq).toBe(true);
414
+ assertType<Awaited<typeof query>, { id: number }[]>();
428
415
  });
429
416
  });
430
417
 
@@ -1,4 +1,4 @@
1
- import { AssertEqual, User, userData, useTestDatabase } from '../test-utils';
1
+ import { assertType, User, userData, useTestDatabase } from '../test-utils';
2
2
 
3
3
  describe('upsert', () => {
4
4
  useTestDatabase();
@@ -9,8 +9,7 @@ describe('upsert', () => {
9
9
  create: userData,
10
10
  });
11
11
 
12
- const eq: AssertEqual<Awaited<typeof query>, void> = true;
13
- expect(eq).toBe(true);
12
+ assertType<Awaited<typeof query>, void>();
14
13
  });
15
14
 
16
15
  it('should update record if exists', async () => {
@@ -1,5 +1,5 @@
1
1
  import {
2
- AssertEqual,
2
+ assertType,
3
3
  expectQueryNotMutated,
4
4
  expectSql,
5
5
  User,
@@ -33,8 +33,7 @@ describe('window functions', () => {
33
33
  partitionBy: 'age',
34
34
  });
35
35
 
36
- const eq: AssertEqual<typeof value, { row_number: number }[]> = true;
37
- expect(eq).toBe(true);
36
+ assertType<typeof value, { row_number: number }[]>();
38
37
 
39
38
  expect(value).toEqual(
40
39
  (results as number[]).map((item) => ({ [functionName]: item })),
package/src/test-utils.ts CHANGED
@@ -4,7 +4,6 @@ import {
4
4
  patchPgForTransactions,
5
5
  rollbackTransaction,
6
6
  startTransaction,
7
- unpatchPgForTransactions,
8
7
  } from 'pg-transactional-tests';
9
8
  import { Client } from 'pg';
10
9
  import { quote } from './quote';
@@ -88,7 +87,7 @@ export const expectQueryNotMutated = (q: Query) => {
88
87
  expectSql(q.toSql(), `SELECT * FROM "${q.table}"`);
89
88
  };
90
89
 
91
- export type AssertEqual<T, Expected> = [T] extends [Expected]
90
+ type AssertEqual<T, Expected> = [T] extends [Expected]
92
91
  ? [Expected] extends [T]
93
92
  ? true
94
93
  : false
@@ -138,17 +137,10 @@ export const messageData = {
138
137
  };
139
138
 
140
139
  export const useTestDatabase = () => {
141
- beforeAll(() => {
142
- patchPgForTransactions();
143
- });
144
- beforeEach(async () => {
145
- await startTransaction(dbClient);
146
- });
147
- afterEach(async () => {
148
- await rollbackTransaction(dbClient);
149
- });
140
+ beforeAll(patchPgForTransactions);
141
+ beforeEach(startTransaction);
142
+ afterEach(rollbackTransaction);
150
143
  afterAll(async () => {
151
- unpatchPgForTransactions();
152
144
  await dbClient.end();
153
145
  });
154
146
  };