@creator.co/wapi 1.2.3 → 1.2.5

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 (121) hide show
  1. package/.github/workflows/npmpublish.yml +2 -5
  2. package/README.md +1 -3
  3. package/dist/index.d.ts +11 -0
  4. package/dist/index.js +24 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/jest.config.d.ts +3 -0
  7. package/dist/jest.config.js +34 -0
  8. package/dist/jest.config.js.map +1 -0
  9. package/dist/package.json +70 -0
  10. package/dist/src/API/Request.d.ts +140 -0
  11. package/dist/src/API/Request.js +182 -0
  12. package/dist/src/API/Request.js.map +1 -0
  13. package/dist/src/API/Response.d.ts +256 -0
  14. package/dist/src/API/Response.js +398 -0
  15. package/dist/src/API/Response.js.map +1 -0
  16. package/dist/src/API/Utils.d.ts +63 -0
  17. package/dist/src/API/Utils.js +104 -0
  18. package/dist/src/API/Utils.js.map +1 -0
  19. package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
  20. package/dist/src/BaseEvent/EventProcessor.js +182 -0
  21. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  22. package/dist/src/BaseEvent/Process.d.ts +74 -0
  23. package/dist/src/BaseEvent/Process.js +142 -0
  24. package/dist/src/BaseEvent/Process.js.map +1 -0
  25. package/dist/src/BaseEvent/Transaction.d.ts +39 -0
  26. package/dist/src/BaseEvent/Transaction.js +354 -0
  27. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  28. package/dist/src/Config/Configuration.d.ts +131 -0
  29. package/dist/src/Config/Configuration.js +153 -0
  30. package/dist/src/Config/Configuration.js.map +1 -0
  31. package/dist/src/Config/EnvironmentVar.d.ts +101 -0
  32. package/dist/src/Config/EnvironmentVar.js +213 -0
  33. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  34. package/dist/src/Crypto/Crypto.d.ts +57 -0
  35. package/dist/src/Crypto/Crypto.js +126 -0
  36. package/dist/src/Crypto/Crypto.js.map +1 -0
  37. package/dist/src/Crypto/JWT.d.ts +64 -0
  38. package/dist/src/Crypto/JWT.js +74 -0
  39. package/dist/src/Crypto/JWT.js.map +1 -0
  40. package/dist/src/Database/Database.d.ts +18 -0
  41. package/dist/src/Database/Database.js +18 -0
  42. package/dist/src/Database/Database.js.map +1 -0
  43. package/dist/src/Database/DatabaseManager.d.ts +32 -0
  44. package/dist/src/Database/DatabaseManager.js +50 -0
  45. package/dist/src/Database/DatabaseManager.js.map +1 -0
  46. package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
  47. package/dist/src/Database/DatabaseTransaction.js +183 -0
  48. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  49. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
  50. package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
  51. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
  52. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
  53. package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
  54. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
  55. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
  56. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
  57. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  58. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
  59. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
  60. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  61. package/dist/src/Globals.d.ts +161 -0
  62. package/dist/src/Globals.js +173 -0
  63. package/dist/src/Globals.js.map +1 -0
  64. package/dist/src/Logger/Logger.d.ts +180 -0
  65. package/dist/src/Logger/Logger.js +412 -0
  66. package/dist/src/Logger/Logger.js.map +1 -0
  67. package/dist/src/Mailer/Mailer.d.ts +107 -0
  68. package/dist/src/Mailer/Mailer.js +313 -0
  69. package/dist/src/Mailer/Mailer.js.map +1 -0
  70. package/dist/src/Publisher/Publisher.d.ts +47 -0
  71. package/dist/src/Publisher/Publisher.js +141 -0
  72. package/dist/src/Publisher/Publisher.js.map +1 -0
  73. package/dist/src/Server/RouteResolver.d.ts +41 -0
  74. package/dist/src/Server/RouteResolver.js +135 -0
  75. package/dist/src/Server/RouteResolver.js.map +1 -0
  76. package/dist/src/Server/Router.d.ts +104 -0
  77. package/dist/src/Server/Router.js +45 -0
  78. package/dist/src/Server/Router.js.map +1 -0
  79. package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
  80. package/dist/src/Server/lib/ContainerServer.js +143 -0
  81. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  82. package/dist/src/Server/lib/Server.d.ts +60 -0
  83. package/dist/src/Server/lib/Server.js +137 -0
  84. package/dist/src/Server/lib/Server.js.map +1 -0
  85. package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
  86. package/dist/src/Server/lib/container/GenericHandler.js +138 -0
  87. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  88. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
  89. package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
  90. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  91. package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
  92. package/dist/src/Server/lib/container/HealthHandler.js +45 -0
  93. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  94. package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
  95. package/dist/src/Server/lib/container/Proxy.js +202 -0
  96. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  97. package/dist/src/Server/lib/container/Utils.d.ts +18 -0
  98. package/dist/src/Server/lib/container/Utils.js +84 -0
  99. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  100. package/dist/src/Validation/Validator.d.ts +21 -0
  101. package/dist/src/Validation/Validator.js +48 -0
  102. package/dist/src/Validation/Validator.js.map +1 -0
  103. package/jest.config.ts +2 -9
  104. package/package.json +10 -4
  105. package/src/BaseEvent/Transaction.ts +48 -18
  106. package/src/Database/Database.ts +19 -0
  107. package/src/Database/DatabaseManager.ts +51 -0
  108. package/src/Database/DatabaseTransaction.ts +118 -0
  109. package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
  110. package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
  111. package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
  112. package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
  113. package/src/Database/types.d.ts +49 -0
  114. package/src/Server/lib/container/Proxy.ts +2 -1
  115. package/tests/BaseEvent/Transaction.test.ts +59 -0
  116. package/tests/Database/DatabaseManager.test.ts +55 -0
  117. package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
  118. package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
  119. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
  120. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
  121. package/tsconfig.json +5 -0
@@ -0,0 +1,133 @@
1
+ import { Knex } from 'knex'
2
+
3
+ import { KnexDatabase } from '../../../../src/Database/integrations/knex/KnexDatabase'
4
+ import { KnexTransactionImpl } from '../../../../src/Database/integrations/knex/KnexTransaction'
5
+ import type { DbConfig } from '../../../../src/Database/types'
6
+
7
+ const testResources = (config: Partial<DbConfig<'knex'>>) => {
8
+ const database = {
9
+ config: {
10
+ autoCommit: true,
11
+ ...config,
12
+ } as DbConfig<'knex'>,
13
+ } as KnexDatabase
14
+
15
+ const delegate = jest.fn().mockImplementation(() => {
16
+ return {
17
+ commit: jest.fn(),
18
+ rollback: jest.fn(),
19
+ select: jest.fn(),
20
+ }
21
+ })() as any as Knex.Transaction
22
+
23
+ return {
24
+ delegate,
25
+ underTest: KnexTransactionImpl.wrapDelegate(delegate, database),
26
+ }
27
+ }
28
+
29
+ describe('KnexTransaction', () => {
30
+ test('Can only commit once', async () => {
31
+ const { delegate, underTest } = testResources({})
32
+ await underTest.commit()
33
+ expect(underTest.isOpen).toBe(false)
34
+ expect(delegate.commit).toBeCalled()
35
+
36
+ await expect(underTest.commit).rejects.toThrowError(
37
+ 'Cannot commit, transaction is already closed!'
38
+ )
39
+ })
40
+
41
+ test("Can't commit after rollback", async () => {
42
+ const { delegate, underTest } = testResources({})
43
+ await underTest.rollback()
44
+ expect(underTest.isOpen).toBe(false)
45
+ expect(delegate.rollback).toBeCalled()
46
+
47
+ await expect(underTest.commit).rejects.toThrowError(
48
+ 'Cannot commit, transaction is already closed!'
49
+ )
50
+ })
51
+
52
+ test('Forwards calls to delegate', async () => {
53
+ const { delegate, underTest } = testResources({})
54
+ await underTest.select('name')
55
+ expect(delegate.select).toBeCalledWith('name')
56
+ })
57
+
58
+ test('Blocks delegate calls after commit', async () => {
59
+ const { delegate, underTest } = testResources({})
60
+ expect(underTest.select).toBeDefined()
61
+
62
+ await underTest.commit()
63
+ expect(delegate.commit).toBeCalled()
64
+ expect(underTest.isOpen).toBe(false)
65
+
66
+ expect(underTest.select).toBeUndefined()
67
+ })
68
+ })
69
+
70
+ describe('KnexTransaction - closeSuccess', () => {
71
+ test('Close success commits', async () => {
72
+ const { delegate, underTest } = testResources({})
73
+ await underTest.closeSuccess()
74
+ expect(delegate.commit).toBeCalled()
75
+ })
76
+
77
+ test("Close success, doesn't commit again if already committed", async () => {
78
+ const { delegate, underTest } = testResources({})
79
+ await underTest.commit()
80
+ expect(delegate.commit).toBeCalledTimes(1)
81
+ await underTest.closeSuccess()
82
+ expect(delegate.commit).toBeCalledTimes(1)
83
+ })
84
+
85
+ test('Close success, rolls back if not autocommit', async () => {
86
+ const { delegate, underTest } = testResources({ autoCommit: false })
87
+ await underTest.closeSuccess()
88
+ expect(delegate.rollback).toBeCalled()
89
+ })
90
+
91
+ test("Close success, doesn't rollback if already committed", async () => {
92
+ const { delegate, underTest } = testResources({ autoCommit: false })
93
+ await underTest.commit()
94
+ expect(delegate.commit).toBeCalledTimes(1)
95
+ await underTest.closeSuccess()
96
+ expect(delegate.rollback).not.toBeCalled()
97
+ expect(delegate.commit).toBeCalledTimes(1)
98
+ })
99
+
100
+ test("Close success, doesn't rollback if already rolled back", async () => {
101
+ const { delegate, underTest } = testResources({ autoCommit: false })
102
+ await underTest.rollback()
103
+ expect(delegate.rollback).toBeCalledTimes(1)
104
+ await underTest.closeSuccess()
105
+ expect(delegate.rollback).toBeCalledTimes(1)
106
+ expect(delegate.commit).not.toBeCalled()
107
+ })
108
+ })
109
+
110
+ describe('KnexTransaction - closeFailure', () => {
111
+ test('Close failure rolls back', async () => {
112
+ const { delegate, underTest } = testResources({})
113
+ await underTest.closeFailure()
114
+ expect(delegate.rollback).toBeCalled()
115
+ })
116
+
117
+ test("Close failure, doesn't rollback again if already rolled back", async () => {
118
+ const { delegate, underTest } = testResources({})
119
+ await underTest.rollback()
120
+ expect(delegate.rollback).toBeCalledTimes(1)
121
+ await underTest.closeFailure()
122
+ expect(delegate.rollback).toBeCalledTimes(1)
123
+ })
124
+
125
+ test("Close failure, doesn't rollback if already committed", async () => {
126
+ const { delegate, underTest } = testResources({ autoCommit: false })
127
+ await underTest.commit()
128
+ expect(delegate.commit).toBeCalledTimes(1)
129
+ await underTest.closeFailure()
130
+ expect(delegate.rollback).not.toBeCalled()
131
+ expect(delegate.commit).toBeCalledTimes(1)
132
+ })
133
+ })
@@ -0,0 +1,50 @@
1
+ import { PoolClient } from 'pg'
2
+
3
+ import { PostgresDatabase } from '../../../../src/Database/integrations/pgsql/PostgresDatabase'
4
+ import { PostgresTransactionImpl } from '../../../../src/Database/integrations/pgsql/PostgresTransaction'
5
+ import type { DbConfig } from '../../../../src/Database/types'
6
+
7
+ const config: DbConfig<'pg'> = {
8
+ type: 'pg',
9
+ username: 'username',
10
+ password: 'password',
11
+ host: 'host',
12
+ port: 1234,
13
+ database: 'database',
14
+ driver: 'driver',
15
+ maxConnections: 1,
16
+ autoCommit: true,
17
+ }
18
+
19
+ const expectedImplConfig = {
20
+ host: config.host,
21
+ port: config.port,
22
+ user: config.username,
23
+ password: config.password,
24
+ database: config.database,
25
+ max: config.maxConnections,
26
+ }
27
+
28
+ describe('PostgresDatabase', () => {
29
+ test('PostgresDatabase', async () => {
30
+ const mockTrans = {
31
+ query: jest.fn(() => {}),
32
+ } as any
33
+ const mockClient = jest.fn(
34
+ () =>
35
+ ({
36
+ connect: async () => mockTrans,
37
+ }) as PoolClient
38
+ )
39
+ PostgresDatabase['pgProvider'] = mockClient as any
40
+
41
+ const underTest = new PostgresDatabase(config)
42
+ expect(mockClient).toBeCalledWith(expectedImplConfig)
43
+
44
+ const trans = await underTest.transaction()
45
+
46
+ expect(mockTrans.query).toBeCalledWith('BEGIN')
47
+ expect(trans).toBeInstanceOf(PostgresTransactionImpl)
48
+ expect(trans['delegate']).toBe(mockTrans)
49
+ })
50
+ })
@@ -0,0 +1,51 @@
1
+ import { PoolClient } from 'pg'
2
+
3
+ import { PostgresDatabase } from '../../../../src/Database/integrations/pgsql/PostgresDatabase'
4
+ import { PostgresTransactionImpl } from '../../../../src/Database/integrations/pgsql/PostgresTransaction'
5
+ import type { DbConfig } from '../../../../src/Database/types'
6
+
7
+ const testResources = (config: Partial<DbConfig<'pg'>>) => {
8
+ const database = {
9
+ config: {
10
+ autoCommit: true,
11
+ ...config,
12
+ } as DbConfig<'pg'>,
13
+ } as PostgresDatabase
14
+
15
+ const delegate = jest.fn().mockImplementation(() => {
16
+ return {
17
+ commit: jest.fn(),
18
+ rollback: jest.fn(),
19
+ query: jest.fn(),
20
+ }
21
+ })() as any as PoolClient
22
+
23
+ return {
24
+ delegate,
25
+ underTest: PostgresTransactionImpl.wrapDelegate(delegate, database),
26
+ }
27
+ }
28
+
29
+ describe('PostgresTransaction', () => {
30
+ test('Can only commit once', async () => {
31
+ const { delegate, underTest } = testResources({})
32
+ await underTest.commit()
33
+ expect(underTest.isOpen).toBe(false)
34
+ expect(delegate.query).toBeCalledWith('COMMIT')
35
+
36
+ await expect(underTest.commit).rejects.toThrowError(
37
+ 'Cannot commit, transaction is already closed!'
38
+ )
39
+ })
40
+
41
+ test('Can only rollback once', async () => {
42
+ const { delegate, underTest } = testResources({})
43
+ await underTest.rollback()
44
+ expect(underTest.isOpen).toBe(false)
45
+ expect(delegate.query).toBeCalledWith('ROLLBACK')
46
+
47
+ await expect(underTest.rollback).rejects.toThrowError(
48
+ 'Cannot rollback, transaction is already closed!'
49
+ )
50
+ })
51
+ })
package/tsconfig.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "exclude": ["**/*.test.*", "**/__mocks__/*", "**/__tests__/*", "**/tests/*"],
3
3
  "compilerOptions": {
4
+ "lib": [
5
+ "es5",
6
+ "es6",
7
+ "dom"
8
+ ],
4
9
  "noImplicitAny": false,
5
10
  "noEmitOnError": true,
6
11
  "removeComments": false,