@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.
- package/.github/workflows/npmpublish.yml +2 -5
- package/README.md +1 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +34 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/package.json +70 -0
- package/dist/src/API/Request.d.ts +140 -0
- package/dist/src/API/Request.js +182 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +256 -0
- package/dist/src/API/Response.js +398 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/API/Utils.d.ts +63 -0
- package/dist/src/API/Utils.js +104 -0
- package/dist/src/API/Utils.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
- package/dist/src/BaseEvent/EventProcessor.js +182 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +74 -0
- package/dist/src/BaseEvent/Process.js +142 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +39 -0
- package/dist/src/BaseEvent/Transaction.js +354 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +131 -0
- package/dist/src/Config/Configuration.js +153 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +101 -0
- package/dist/src/Config/EnvironmentVar.js +213 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +57 -0
- package/dist/src/Crypto/Crypto.js +126 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Crypto/JWT.d.ts +64 -0
- package/dist/src/Crypto/JWT.js +74 -0
- package/dist/src/Crypto/JWT.js.map +1 -0
- package/dist/src/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Globals.d.ts +161 -0
- package/dist/src/Globals.js +173 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +180 -0
- package/dist/src/Logger/Logger.js +412 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +107 -0
- package/dist/src/Mailer/Mailer.js +313 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +47 -0
- package/dist/src/Publisher/Publisher.js +141 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +41 -0
- package/dist/src/Server/RouteResolver.js +135 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +104 -0
- package/dist/src/Server/Router.js +45 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
- package/dist/src/Server/lib/ContainerServer.js +143 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +60 -0
- package/dist/src/Server/lib/Server.js +137 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
- package/dist/src/Server/lib/container/GenericHandler.js +138 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
- package/dist/src/Server/lib/container/HealthHandler.js +45 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
- package/dist/src/Server/lib/container/Proxy.js +202 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +18 -0
- package/dist/src/Server/lib/container/Utils.js +84 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +21 -0
- package/dist/src/Validation/Validator.js +48 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/jest.config.ts +2 -9
- package/package.json +10 -4
- package/src/BaseEvent/Transaction.ts +48 -18
- package/src/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- package/src/Server/lib/container/Proxy.ts +2 -1
- package/tests/BaseEvent/Transaction.test.ts +59 -0
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- 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
|
+
})
|