@creator.co/wapi 1.3.19 → 1.4.0-alpha1

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.
Files changed (70) hide show
  1. package/dist/package.json +2 -1
  2. package/dist/src/API/Request.js.map +1 -1
  3. package/dist/src/API/Response.js.map +1 -1
  4. package/dist/src/API/Utils.js.map +1 -1
  5. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  6. package/dist/src/BaseEvent/Transaction.d.ts +1 -1
  7. package/dist/src/Config/Configuration.js.map +1 -1
  8. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  9. package/dist/src/Crypto/JWT.js.map +1 -1
  10. package/dist/src/Database/Database.d.ts +8 -5
  11. package/dist/src/Database/Database.js +5 -3
  12. package/dist/src/Database/Database.js.map +1 -1
  13. package/dist/src/Database/DatabaseManager.d.ts +30 -9
  14. package/dist/src/Database/DatabaseManager.js +25 -10
  15. package/dist/src/Database/DatabaseManager.js.map +1 -1
  16. package/dist/src/Database/DatabaseTransaction.d.ts +66 -31
  17. package/dist/src/Database/DatabaseTransaction.js +51 -30
  18. package/dist/src/Database/DatabaseTransaction.js.map +1 -1
  19. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -8
  20. package/dist/src/Database/integrations/knex/KnexDatabase.js +18 -13
  21. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
  22. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +39 -16
  23. package/dist/src/Database/integrations/knex/KnexTransaction.js +83 -17
  24. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
  25. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +55 -0
  26. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +126 -0
  27. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  28. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  29. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +186 -0
  30. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  31. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +16 -11
  32. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +19 -18
  33. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
  34. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +42 -16
  35. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +84 -18
  36. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
  37. package/dist/src/Database/types.d.ts +47 -26
  38. package/dist/src/Logger/Logger.d.ts +6 -6
  39. package/dist/src/Logger/Logger.js +12 -15
  40. package/dist/src/Logger/Logger.js.map +1 -1
  41. package/dist/src/Publisher/Publisher.js.map +1 -1
  42. package/dist/src/Server/RouteResolver.js.map +1 -1
  43. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  44. package/dist/src/Server/lib/Server.js.map +1 -1
  45. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  46. package/dist/src/Server/lib/container/GenericHandlerEvent.js +1 -1
  47. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  48. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  49. package/dist/src/Validation/Validator.js.map +1 -1
  50. package/package.json +2 -1
  51. package/src/BaseEvent/Transaction.ts +2 -2
  52. package/src/Database/Database.ts +8 -5
  53. package/src/Database/DatabaseManager.ts +34 -17
  54. package/src/Database/DatabaseTransaction.ts +79 -35
  55. package/src/Database/integrations/knex/KnexDatabase.ts +22 -11
  56. package/src/Database/integrations/knex/KnexTransaction.ts +52 -19
  57. package/src/Database/integrations/kysely/KyselyDatabase.ts +87 -0
  58. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  59. package/src/Database/integrations/pgsql/PostgresDatabase.ts +26 -14
  60. package/src/Database/integrations/pgsql/PostgresTransaction.ts +55 -22
  61. package/src/Database/types.ts +53 -31
  62. package/src/Logger/Logger.ts +12 -15
  63. package/tests/Database/DatabaseManager.test.ts +16 -1
  64. package/tests/Database/integrations/knex/KnexDatabase.test.ts +2 -2
  65. package/tests/Database/integrations/knex/KnexTransaction.test.ts +52 -45
  66. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +109 -0
  67. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +118 -0
  68. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +32 -6
  69. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +75 -9
  70. package/tsconfig.json +1 -0
@@ -1,10 +1,10 @@
1
- import { PoolClient } from 'pg'
1
+ import { Pool, PoolClient } from 'pg'
2
2
 
3
3
  import type { DbConfig } from '../../../../src/Database'
4
4
  import { PostgresDatabase } from '../../../../src/Database/integrations/pgsql/PostgresDatabase'
5
5
  import { PostgresTransactionImpl } from '../../../../src/Database/integrations/pgsql/PostgresTransaction'
6
6
 
7
- const testResources = (config: Partial<DbConfig<'pg'>>) => {
7
+ const testResources = async (config: Partial<DbConfig<'pg'>>) => {
8
8
  const database = {
9
9
  config: {
10
10
  autoCommit: true,
@@ -12,7 +12,7 @@ const testResources = (config: Partial<DbConfig<'pg'>>) => {
12
12
  } as DbConfig<'pg'>,
13
13
  } as PostgresDatabase
14
14
 
15
- const delegate = jest.fn().mockImplementation(() => {
15
+ const transaction = jest.fn().mockImplementation(() => {
16
16
  return {
17
17
  commit: jest.fn(),
18
18
  rollback: jest.fn(),
@@ -20,18 +20,35 @@ const testResources = (config: Partial<DbConfig<'pg'>>) => {
20
20
  }
21
21
  })() as any as PoolClient
22
22
 
23
+ const writer = jest.fn().mockImplementation(() => {
24
+ return {
25
+ connect: jest.fn(() => transaction),
26
+ }
27
+ })() as any as Pool
28
+
23
29
  return {
24
- delegate,
25
- underTest: PostgresTransactionImpl.wrapDelegate(delegate, database),
30
+ transaction,
31
+ writer,
32
+ underTest: await PostgresTransactionImpl.newTransaction(writer, database),
26
33
  }
27
34
  }
28
35
 
29
36
  describe('PostgresTransaction', () => {
37
+ test('Transaction starts opened', async () => {
38
+ const { transaction, underTest } = await testResources({})
39
+ expect(underTest.isOpen()).toBe(true)
40
+ expect(transaction.query).toHaveBeenNthCalledWith(1, 'BEGIN')
41
+
42
+ await expect(underTest.begin).rejects.toThrowError(
43
+ 'Cannot begin, transaction is already opened!'
44
+ )
45
+ })
46
+
30
47
  test('Can only commit once', async () => {
31
- const { delegate, underTest } = testResources({})
48
+ const { transaction, underTest } = await testResources({})
32
49
  await underTest.commit()
33
50
  expect(underTest.isOpen()).toBe(false)
34
- expect(delegate.query).toBeCalledWith('COMMIT')
51
+ expect(transaction.query).toBeCalledWith('COMMIT')
35
52
 
36
53
  await expect(underTest.commit).rejects.toThrowError(
37
54
  'Cannot commit, transaction is already closed!'
@@ -39,13 +56,62 @@ describe('PostgresTransaction', () => {
39
56
  })
40
57
 
41
58
  test('Can only rollback once', async () => {
42
- const { delegate, underTest } = testResources({})
59
+ const { transaction, underTest } = await testResources({})
43
60
  await underTest.rollback()
44
61
  expect(underTest.isOpen()).toBe(false)
45
- expect(delegate.query).toBeCalledWith('ROLLBACK')
62
+ expect(transaction.query).toBeCalledWith('ROLLBACK')
46
63
 
47
64
  await expect(underTest.rollback).rejects.toThrowError(
48
65
  'Cannot rollback, transaction is already closed!'
49
66
  )
50
67
  })
68
+
69
+ test("Can't open transaction twice", async () => {
70
+ const { transaction, underTest } = await testResources({})
71
+ expect(underTest.isOpen()).toBe(true)
72
+ expect(transaction.query).toHaveBeenNthCalledWith(1, 'BEGIN')
73
+
74
+ await expect(underTest.begin).rejects.toThrowError(
75
+ 'Cannot begin, transaction is already opened!'
76
+ )
77
+ })
78
+
79
+ test('Can commit, begin and commit again ', async () => {
80
+ const { transaction, underTest } = await testResources({})
81
+ await underTest.commit()
82
+ expect(underTest.isOpen()).toBe(false)
83
+ expect(transaction.query).toBeCalledWith('COMMIT')
84
+ await underTest.begin()
85
+ expect(underTest.isOpen()).toBe(true)
86
+ expect(transaction.query).toHaveBeenNthCalledWith(3, 'BEGIN')
87
+ await underTest.commit()
88
+ expect(underTest.isOpen()).toBe(false)
89
+ expect(transaction.query).toHaveBeenNthCalledWith(4, 'COMMIT')
90
+ })
91
+
92
+ test('Can commit, begin and rollback ', async () => {
93
+ const { transaction, underTest } = await testResources({})
94
+ await underTest.commit()
95
+ expect(underTest.isOpen()).toBe(false)
96
+ expect(transaction.query).toBeCalledWith('COMMIT')
97
+ await underTest.begin()
98
+ expect(underTest.isOpen()).toBe(true)
99
+ expect(transaction.query).toHaveBeenNthCalledWith(3, 'BEGIN')
100
+ await underTest.rollback()
101
+ expect(underTest.isOpen()).toBe(false)
102
+ expect(transaction.query).toHaveBeenNthCalledWith(4, 'ROLLBACK')
103
+ })
104
+
105
+ test('Can rollback, begin and commit ', async () => {
106
+ const { transaction, underTest } = await testResources({})
107
+ await underTest.rollback()
108
+ expect(underTest.isOpen()).toBe(false)
109
+ expect(transaction.query).toBeCalledWith('ROLLBACK')
110
+ await underTest.begin()
111
+ expect(underTest.isOpen()).toBe(true)
112
+ expect(transaction.query).toHaveBeenNthCalledWith(3, 'BEGIN')
113
+ await underTest.commit()
114
+ expect(underTest.isOpen()).toBe(false)
115
+ expect(transaction.query).toHaveBeenNthCalledWith(4, 'COMMIT')
116
+ })
51
117
  })
package/tsconfig.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "target": "es5",
16
16
  "outDir": "dist",
17
17
  "declaration": true,
18
+ "skipLibCheck": true,
18
19
  "strictNullChecks": true
19
20
  }
20
21
  }