pqb 0.3.2 → 0.3.4

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/src/utils.test.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { assertType } from './test-utils';
2
2
  import {
3
- GetTypeOrRaw,
4
- GetTypesOrRaw,
5
3
  makeRegexToFindInSql,
6
4
  MaybeArray,
7
5
  pushOrNewArray,
@@ -9,7 +7,6 @@ import {
9
7
  SetOptional,
10
8
  SomeIsTrue,
11
9
  } from './utils';
12
- import { RawExpression } from './common';
13
10
 
14
11
  describe('utils', () => {
15
12
  describe('SomeIsTrue', () => {
@@ -45,21 +42,6 @@ describe('utils', () => {
45
42
  });
46
43
  });
47
44
 
48
- describe('GetTypesOrRaw', () => {
49
- it('should add each element to union with RawExpression', () => {
50
- assertType<
51
- GetTypesOrRaw<[number, string]>,
52
- [number | RawExpression, string | RawExpression]
53
- >();
54
- });
55
- });
56
-
57
- describe('GetTypeOrRaw', () => {
58
- it('should add type to union with RawExpression', () => {
59
- assertType<GetTypeOrRaw<number>, number | RawExpression>();
60
- });
61
- });
62
-
63
45
  describe('makeRegexToFindWordInSql', () => {
64
46
  it('should return a proper regex', () => {
65
47
  const regex = makeRegexToFindInSql('\\bupdatedAt\\b');
package/src/utils.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { RawExpression } from './common';
2
1
  import { QueryData, toSqlCacheKey } from './sql';
3
2
 
4
3
  export type SomeIsTrue<T extends unknown[]> = T extends [
@@ -16,46 +15,7 @@ export type SetOptional<T, K extends PropertyKey> = Omit<T, K> & {
16
15
  [P in K]?: P extends keyof T ? T[P] : never;
17
16
  };
18
17
 
19
- export type GetTypesOrRaw<T extends [...unknown[]]> = T extends [
20
- infer Head,
21
- ...infer Tail,
22
- ]
23
- ? [GetTypeOrRaw<Head>, ...GetTypesOrRaw<Tail>]
24
- : [];
25
-
26
- export type GetTypeOrRaw<T> = T | RawExpression;
27
-
28
- // credits goes to https://stackoverflow.com/a/50375286
29
- export type UnionToIntersection<U> =
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- (U extends any ? (k: U) => void : never) extends (k: infer I) => void
32
- ? I
33
- : never;
34
-
35
18
  // Converts union to overloaded function
36
- export type UnionToOvlds<U> = UnionToIntersection<
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- U extends any ? (f: U) => void : never
39
- >;
40
-
41
- type PopPropertyKeyUnion<U> = UnionToOvlds<U> extends (
42
- a: infer A extends PropertyKey,
43
- ) => void
44
- ? A
45
- : never;
46
-
47
- type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
48
-
49
- export type PropertyKeyUnionToArray<
50
- T,
51
- A extends PropertyKey[] = [],
52
- > = IsUnion<T> extends true
53
- ? PropertyKeyUnionToArray<
54
- Exclude<T, PopPropertyKeyUnion<T>>,
55
- [PopPropertyKeyUnion<T>, ...A]
56
- >
57
- : [T, ...A];
58
-
59
19
  type OptionalPropertyNames<T> = {
60
20
  // eslint-disable-next-line @typescript-eslint/ban-types
61
21
  [K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never;
@@ -1,32 +0,0 @@
1
- import { AssertEqual } from '../test-utils';
2
- import { TableSchema } from './columnsSchema';
3
- import { columnTypes } from './columnTypes';
4
-
5
- describe('columnsSchema', () => {
6
- describe('schema methods', () => {
7
- const createSchema = () => {
8
- return new TableSchema({
9
- a: columnTypes.integer().primaryKey(),
10
- b: columnTypes.decimal().primaryKey(),
11
- c: columnTypes.text(),
12
- });
13
- };
14
-
15
- describe('.primaryKeys', () => {
16
- it('should be array of primary key names', () => {
17
- const schema = createSchema();
18
- const eq: AssertEqual<typeof schema.primaryKeys, ['a', 'b']> = true;
19
- expect(eq).toBe(true);
20
- expect(schema.primaryKeys).toEqual(['a', 'b']);
21
- });
22
- });
23
-
24
- describe('.primaryTypes', () => {
25
- const schema = createSchema();
26
- const eq: AssertEqual<typeof schema.primaryTypes, [number, number]> =
27
- true;
28
- expect(eq).toBe(true);
29
- expect(schema.primaryTypes).toEqual(undefined);
30
- });
31
- });
32
- });