@contember/engine-common 1.2.1 → 1.3.0-alpha.2
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/dist/src/MigrationVersionHelper.d.ts +9 -0
- package/dist/src/MigrationVersionHelper.d.ts.map +1 -0
- package/dist/src/MigrationVersionHelper.js +45 -0
- package/dist/src/MigrationVersionHelper.js.map +1 -0
- package/dist/src/eventEmitter/events.d.ts +13 -0
- package/dist/src/eventEmitter/events.d.ts.map +1 -0
- package/dist/src/eventEmitter/events.js +27 -0
- package/dist/src/eventEmitter/events.js.map +1 -0
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/runnable/Runnable.d.ts +13 -0
- package/dist/src/runnable/Runnable.d.ts.map +1 -0
- package/dist/src/runnable/Runnable.js +3 -0
- package/dist/src/runnable/Runnable.js.map +1 -0
- package/dist/src/runnable/Supervisor.d.ts +15 -0
- package/dist/src/runnable/Supervisor.d.ts.map +1 -0
- package/dist/src/runnable/Supervisor.js +75 -0
- package/dist/src/runnable/Supervisor.js.map +1 -0
- package/dist/src/runnable/index.d.ts +3 -0
- package/dist/src/runnable/index.d.ts.map +1 -0
- package/dist/src/{events → runnable}/index.js +2 -3
- package/dist/src/runnable/index.js.map +1 -0
- package/dist/src/runnable/utils.d.ts +2 -0
- package/dist/src/runnable/utils.d.ts.map +1 -0
- package/dist/src/runnable/utils.js +21 -0
- package/dist/src/runnable/utils.js.map +1 -0
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
- package/src/MigrationVersionHelper.ts +46 -0
- package/src/eventEmitter/events.ts +30 -0
- package/src/index.ts +3 -1
- package/src/runnable/Runnable.ts +15 -0
- package/src/runnable/Supervisor.ts +82 -0
- package/src/runnable/index.ts +2 -0
- package/src/runnable/utils.ts +21 -0
- package/src/tsconfig.json +4 -1
- package/tests/cases/supervisor.test.ts +204 -0
- package/dist/src/events/Event.d.ts +0 -53
- package/dist/src/events/Event.d.ts.map +0 -1
- package/dist/src/events/Event.js +0 -46
- package/dist/src/events/Event.js.map +0 -1
- package/dist/src/events/EventType.d.ts +0 -7
- package/dist/src/events/EventType.d.ts.map +0 -1
- package/dist/src/events/EventType.js +0 -15
- package/dist/src/events/EventType.js.map +0 -1
- package/dist/src/events/index.d.ts +0 -4
- package/dist/src/events/index.d.ts.map +0 -1
- package/dist/src/events/index.js.map +0 -1
- package/dist/src/events/utils.d.ts +0 -3
- package/dist/src/events/utils.d.ts.map +0 -1
- package/dist/src/events/utils.js +0 -9
- package/dist/src/events/utils.js.map +0 -1
- package/src/events/Event.ts +0 -56
- package/src/events/EventType.ts +0 -11
- package/src/events/index.ts +0 -3
- package/src/events/utils.ts +0 -6
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type EventMap = {
|
|
2
|
+
[name: string]: (arg: any) => any
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type EventUnlisten = () => void
|
|
6
|
+
|
|
7
|
+
export interface EventEmitter<E extends EventMap> {
|
|
8
|
+
on<K extends keyof E>(event: K, cb: E[K]): EventUnlisten
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class EventManager<E extends EventMap> implements EventEmitter<E> {
|
|
12
|
+
private listeners: {
|
|
13
|
+
[K in keyof E]?: E[K][]
|
|
14
|
+
} = {}
|
|
15
|
+
|
|
16
|
+
public on<K extends keyof E>(event: K, cb: E[K]): EventUnlisten {
|
|
17
|
+
(this.listeners[event] ??= []).push(cb)
|
|
18
|
+
return () => {
|
|
19
|
+
return this.listeners[event] = this.listeners[event]?.filter(it => it !== cb)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public fire<K extends keyof E>(event: K, args: Parameters<E[K]>[0]): ReturnType<E[K]>[] {
|
|
24
|
+
const result: ReturnType<E[K]>[] = []
|
|
25
|
+
for (const cb of this.listeners[event] ?? []) {
|
|
26
|
+
result.push(cb(args))
|
|
27
|
+
}
|
|
28
|
+
return result
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Logger } from '@contember/logger'
|
|
2
|
+
|
|
3
|
+
export type RunnableArgs = {
|
|
4
|
+
onError: (e: any) => void
|
|
5
|
+
onClose?: () => void
|
|
6
|
+
logger: Logger
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Runnable {
|
|
10
|
+
run(args: RunnableArgs): Promise<Running>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Running {
|
|
14
|
+
end(): Promise<void>
|
|
15
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Runnable, RunnableArgs, Running } from './Runnable'
|
|
2
|
+
import { abortableTimeout } from './utils'
|
|
3
|
+
|
|
4
|
+
export type SupervisorOptions = {
|
|
5
|
+
max?: number
|
|
6
|
+
startupMax?: number
|
|
7
|
+
minBackoff?: number
|
|
8
|
+
maxBackoff?: number
|
|
9
|
+
exponentiationBase?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Supervisor implements Runnable {
|
|
13
|
+
constructor(
|
|
14
|
+
private runnable: Runnable,
|
|
15
|
+
private options: SupervisorOptions = {},
|
|
16
|
+
) {
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async run(args: RunnableArgs): Promise<Running> {
|
|
20
|
+
const { logger, onError } = args
|
|
21
|
+
let restartCount = 0
|
|
22
|
+
const abortController = new AbortController()
|
|
23
|
+
let innerRunning: Running | undefined
|
|
24
|
+
let wasHealthy = false
|
|
25
|
+
|
|
26
|
+
await new Promise<void>(async (resolve, reject) => {
|
|
27
|
+
while (!abortController.signal.aborted) {
|
|
28
|
+
try {
|
|
29
|
+
await new Promise<void>(async (resolveRunning, rejectRunning) => {
|
|
30
|
+
try {
|
|
31
|
+
innerRunning = await this.runnable.run({
|
|
32
|
+
onClose: resolveRunning,
|
|
33
|
+
onError: rejectRunning,
|
|
34
|
+
logger: logger.child({ runningId: Math.random().toString().substring(2) }),
|
|
35
|
+
})
|
|
36
|
+
restartCount = 0
|
|
37
|
+
resolve()
|
|
38
|
+
wasHealthy = true
|
|
39
|
+
} catch (e) {
|
|
40
|
+
rejectRunning(e)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
} catch (e) {
|
|
44
|
+
innerRunning = undefined
|
|
45
|
+
const shouldRestart = wasHealthy
|
|
46
|
+
? (this.options.max === undefined || restartCount++ < this.options.max)
|
|
47
|
+
: (restartCount++ < (this.options.startupMax ?? 10))
|
|
48
|
+
if (shouldRestart) {
|
|
49
|
+
const timeoutMs = Math.ceil(Math.min(
|
|
50
|
+
Math.pow(this.options.exponentiationBase ?? 2, restartCount - 1) * (this.options.minBackoff ?? 1_000),
|
|
51
|
+
this.options.maxBackoff ?? 60_000,
|
|
52
|
+
))
|
|
53
|
+
logger.error(`Runnable crashed, restarting in ${timeoutMs} ms ...`, {
|
|
54
|
+
error: e,
|
|
55
|
+
})
|
|
56
|
+
await abortableTimeout(timeoutMs, abortController.signal)
|
|
57
|
+
if (!abortController.signal.aborted) {
|
|
58
|
+
logger.info(`Restarting runnable now`)
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
logger.error(`Runnable crashed, stopping`, {
|
|
62
|
+
error: e,
|
|
63
|
+
})
|
|
64
|
+
if (wasHealthy) {
|
|
65
|
+
onError(e)
|
|
66
|
+
} else {
|
|
67
|
+
reject(e)
|
|
68
|
+
}
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
async end(): Promise<void> {
|
|
77
|
+
abortController.abort()
|
|
78
|
+
await innerRunning?.end()
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const abortableTimeout = async (timeoutMs: number, abortSignal: AbortSignal): Promise<void> => {
|
|
2
|
+
if (abortSignal.aborted) {
|
|
3
|
+
return Promise.resolve()
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
let cleanup: (() => void)[] = []
|
|
7
|
+
|
|
8
|
+
const abortPromise = new Promise(resolve => {
|
|
9
|
+
abortSignal.addEventListener('abort', resolve)
|
|
10
|
+
cleanup.push(() => abortSignal.removeEventListener('abort', resolve))
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const timeoutPromise = new Promise<void>(resolve => {
|
|
14
|
+
const timeoutHandle = setTimeout(resolve, timeoutMs)
|
|
15
|
+
cleanup.push(() => clearTimeout(timeoutHandle))
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
await Promise.race([abortPromise, timeoutPromise])
|
|
19
|
+
cleanup.forEach(it => it())
|
|
20
|
+
}
|
|
21
|
+
|
package/src/tsconfig.json
CHANGED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { createLogger, TestLoggerHandler } from '@contember/logger'
|
|
2
|
+
import { assert, test, expect } from 'vitest'
|
|
3
|
+
import { Runnable, RunnableArgs, Running, Supervisor } from '../../src'
|
|
4
|
+
|
|
5
|
+
const shouldNotHappenCallback = () => {
|
|
6
|
+
throw new Error('should not happen')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const createTestLogger = (out = false) => {
|
|
10
|
+
const testHandler = new TestLoggerHandler(out)
|
|
11
|
+
const logger = createLogger(testHandler)
|
|
12
|
+
return { logger, testLogger: testHandler }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test('supervisor: start - end', async () => {
|
|
16
|
+
const { logger, testLogger } = createTestLogger()
|
|
17
|
+
const okRunnable = new class OkRunnable implements Runnable {
|
|
18
|
+
async run(args: RunnableArgs): Promise<Running> {
|
|
19
|
+
logger.info('Starting runnable')
|
|
20
|
+
await new Promise(resolve => setTimeout(resolve, 1))
|
|
21
|
+
logger.info('Runnable started')
|
|
22
|
+
return {
|
|
23
|
+
end: async () => {
|
|
24
|
+
logger.info('Runnable terminated')
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const supervisor = new Supervisor(okRunnable)
|
|
30
|
+
const running = await supervisor.run({
|
|
31
|
+
logger,
|
|
32
|
+
onError: shouldNotHappenCallback,
|
|
33
|
+
})
|
|
34
|
+
await running.end()
|
|
35
|
+
assert.deepEqual(testLogger.messages.map(it => it.message), [
|
|
36
|
+
'Starting runnable',
|
|
37
|
+
'Runnable started',
|
|
38
|
+
'Runnable terminated',
|
|
39
|
+
])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
test('supervisor: retry start', async () => {
|
|
44
|
+
const { logger, testLogger } = createTestLogger()
|
|
45
|
+
let attempt = 0
|
|
46
|
+
const okRunnable = new class OkRunnable implements Runnable {
|
|
47
|
+
async run(args: RunnableArgs): Promise<Running> {
|
|
48
|
+
const thisAttempt = ++attempt
|
|
49
|
+
logger.info(`Starting runnable #${thisAttempt}`)
|
|
50
|
+
await new Promise(resolve => setTimeout(resolve, 1))
|
|
51
|
+
if (thisAttempt < 3) {
|
|
52
|
+
logger.info(`Runnable #${thisAttempt} failed to start`)
|
|
53
|
+
throw new Error()
|
|
54
|
+
}
|
|
55
|
+
logger.info(`Runnable #${thisAttempt} started`)
|
|
56
|
+
return {
|
|
57
|
+
end: async () => {
|
|
58
|
+
logger.info(`Runnable #${thisAttempt} terminated`)
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const supervisor = new Supervisor(okRunnable, { minBackoff: 1 })
|
|
65
|
+
const running = await supervisor.run({
|
|
66
|
+
logger,
|
|
67
|
+
onError: shouldNotHappenCallback,
|
|
68
|
+
})
|
|
69
|
+
await running.end()
|
|
70
|
+
assert.deepEqual(testLogger.messages.map(it => it.message), [
|
|
71
|
+
'Starting runnable #1',
|
|
72
|
+
'Runnable #1 failed to start',
|
|
73
|
+
'Runnable crashed, restarting in 1 ms ...',
|
|
74
|
+
'Restarting runnable now',
|
|
75
|
+
'Starting runnable #2',
|
|
76
|
+
'Runnable #2 failed to start',
|
|
77
|
+
'Runnable crashed, restarting in 2 ms ...',
|
|
78
|
+
'Restarting runnable now',
|
|
79
|
+
'Starting runnable #3',
|
|
80
|
+
'Runnable #3 started',
|
|
81
|
+
'Runnable #3 terminated',
|
|
82
|
+
|
|
83
|
+
])
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
test('supervisor: failed to start', async () => {
|
|
88
|
+
const { logger, testLogger } = createTestLogger()
|
|
89
|
+
const okRunnable = new class OkRunnable implements Runnable {
|
|
90
|
+
async run(args: RunnableArgs): Promise<Running> {
|
|
91
|
+
logger.info(`Starting runnable`)
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, 1))
|
|
93
|
+
throw new Error('failed to start')
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const supervisor = new Supervisor(okRunnable, { startupMax: 0 })
|
|
98
|
+
const runningPromise = supervisor.run({
|
|
99
|
+
logger,
|
|
100
|
+
onError: shouldNotHappenCallback,
|
|
101
|
+
})
|
|
102
|
+
await expect(runningPromise).rejects.toThrow('failed to start')
|
|
103
|
+
assert.deepEqual(testLogger.messages.map(it => it.message), [
|
|
104
|
+
'Starting runnable',
|
|
105
|
+
'Runnable crashed, stopping: failed to start',
|
|
106
|
+
])
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
test('supervisor: crash after start, restarts', async () => {
|
|
111
|
+
const { logger, testLogger } = createTestLogger()
|
|
112
|
+
let attempt = 0
|
|
113
|
+
const okRunnable = new class OkRunnable implements Runnable {
|
|
114
|
+
async run(args: RunnableArgs): Promise<Running> {
|
|
115
|
+
const thisAttempt = ++attempt
|
|
116
|
+
logger.info(`Starting runnable #${thisAttempt}`)
|
|
117
|
+
await new Promise(resolve => setTimeout(resolve, 1))
|
|
118
|
+
if (thisAttempt === 1) {
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
args.onError(new Error())
|
|
121
|
+
}, 50)
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
end: async () => {
|
|
125
|
+
logger.info(`Runnable #${thisAttempt} terminated`)
|
|
126
|
+
args.onClose()
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const supervisor = new Supervisor(okRunnable, { minBackoff: 1 })
|
|
133
|
+
const running = await supervisor.run({
|
|
134
|
+
logger,
|
|
135
|
+
onError: shouldNotHappenCallback,
|
|
136
|
+
})
|
|
137
|
+
await new Promise(resolve => setTimeout(resolve, 100))
|
|
138
|
+
await running.end()
|
|
139
|
+
assert.deepEqual(testLogger.messages.map(it => it.message), [
|
|
140
|
+
'Starting runnable #1',
|
|
141
|
+
'Runnable crashed, restarting in 1 ms ...',
|
|
142
|
+
'Restarting runnable now',
|
|
143
|
+
'Starting runnable #2',
|
|
144
|
+
'Runnable #2 terminated',
|
|
145
|
+
|
|
146
|
+
])
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
test('supervisor: failed to restart', async () => {
|
|
151
|
+
const { logger, testLogger } = createTestLogger()
|
|
152
|
+
let attempt = 0
|
|
153
|
+
const okRunnable = new class OkRunnable implements Runnable {
|
|
154
|
+
async run(args: RunnableArgs): Promise<Running> {
|
|
155
|
+
const thisAttempt = ++attempt
|
|
156
|
+
logger.info(`Starting runnable #${thisAttempt}`)
|
|
157
|
+
await new Promise(resolve => setTimeout(resolve, 1))
|
|
158
|
+
if (thisAttempt === 1) {
|
|
159
|
+
setTimeout(() => {
|
|
160
|
+
args.onError(new Error())
|
|
161
|
+
}, 50)
|
|
162
|
+
} else {
|
|
163
|
+
throw new Error('failed to restart')
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
end: async () => {
|
|
167
|
+
logger.info(`Runnable #${thisAttempt} terminated`)
|
|
168
|
+
args.onClose()
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const supervisor = new Supervisor(okRunnable, { minBackoff: 1, max: 5 })
|
|
175
|
+
const errorPromise = new Promise(async (resolve, reject) => {
|
|
176
|
+
await supervisor.run({
|
|
177
|
+
logger,
|
|
178
|
+
onError: reject,
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
await expect(errorPromise).rejects.toThrow('failed to restart')
|
|
183
|
+
|
|
184
|
+
assert.deepEqual(testLogger.messages.map(it => it.message), [
|
|
185
|
+
'Starting runnable #1',
|
|
186
|
+
'Runnable crashed, restarting in 1 ms ...',
|
|
187
|
+
'Restarting runnable now',
|
|
188
|
+
'Starting runnable #2',
|
|
189
|
+
'Runnable crashed, restarting in 2 ms ...: failed to restart',
|
|
190
|
+
'Restarting runnable now',
|
|
191
|
+
'Starting runnable #3',
|
|
192
|
+
'Runnable crashed, restarting in 4 ms ...: failed to restart',
|
|
193
|
+
'Restarting runnable now',
|
|
194
|
+
'Starting runnable #4',
|
|
195
|
+
'Runnable crashed, restarting in 8 ms ...: failed to restart',
|
|
196
|
+
'Restarting runnable now',
|
|
197
|
+
'Starting runnable #5',
|
|
198
|
+
'Runnable crashed, restarting in 16 ms ...: failed to restart',
|
|
199
|
+
'Restarting runnable now',
|
|
200
|
+
'Starting runnable #6',
|
|
201
|
+
'Runnable crashed, stopping: failed to restart',
|
|
202
|
+
])
|
|
203
|
+
})
|
|
204
|
+
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { EventType } from './EventType';
|
|
2
|
-
export declare type ContentEvent = UpdateEvent | CreateEvent | DeleteEvent;
|
|
3
|
-
export declare type AnyEvent = ContentEvent;
|
|
4
|
-
export interface Event {
|
|
5
|
-
readonly type: EventType;
|
|
6
|
-
readonly id: string;
|
|
7
|
-
readonly createdAt: Date;
|
|
8
|
-
readonly transactionId: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class UpdateEvent implements Event {
|
|
11
|
-
readonly id: string;
|
|
12
|
-
readonly createdAt: Date;
|
|
13
|
-
readonly appliedAt: Date;
|
|
14
|
-
readonly identityId: string;
|
|
15
|
-
readonly transactionId: string;
|
|
16
|
-
readonly rowId: string[];
|
|
17
|
-
readonly tableName: string;
|
|
18
|
-
readonly values: {
|
|
19
|
-
[column: string]: any;
|
|
20
|
-
};
|
|
21
|
-
readonly type = EventType.update;
|
|
22
|
-
constructor(id: string, createdAt: Date, appliedAt: Date, identityId: string, transactionId: string, rowId: string[], tableName: string, values: {
|
|
23
|
-
[column: string]: any;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export declare class CreateEvent implements Event {
|
|
27
|
-
readonly id: string;
|
|
28
|
-
readonly createdAt: Date;
|
|
29
|
-
readonly appliedAt: Date;
|
|
30
|
-
readonly identityId: string;
|
|
31
|
-
readonly transactionId: string;
|
|
32
|
-
readonly rowId: string[];
|
|
33
|
-
readonly tableName: string;
|
|
34
|
-
readonly values: {
|
|
35
|
-
[column: string]: any;
|
|
36
|
-
};
|
|
37
|
-
readonly type = EventType.create;
|
|
38
|
-
constructor(id: string, createdAt: Date, appliedAt: Date, identityId: string, transactionId: string, rowId: string[], tableName: string, values: {
|
|
39
|
-
[column: string]: any;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
export declare class DeleteEvent implements Event {
|
|
43
|
-
readonly id: string;
|
|
44
|
-
readonly createdAt: Date;
|
|
45
|
-
readonly appliedAt: Date;
|
|
46
|
-
readonly identityId: string;
|
|
47
|
-
readonly transactionId: string;
|
|
48
|
-
readonly rowId: string[];
|
|
49
|
-
readonly tableName: string;
|
|
50
|
-
readonly type = EventType.delete;
|
|
51
|
-
constructor(id: string, createdAt: Date, appliedAt: Date, identityId: string, transactionId: string, rowId: string[], tableName: string);
|
|
52
|
-
}
|
|
53
|
-
//#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M;aACjB,MAAM,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAVlD,SAAgB,IAAI,oBAAmB;gBAGtB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,IAAI,EACf,SAAS,EAAE,IAAI,EACf,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;CAElD;AAED,qBAAa,WAAY,YAAW,KAAK;aAIvB,EAAE,EAAE,MAAM;aACV,SAAS,EAAE,IAAI;aACf,SAAS,EAAE,IAAI;aACf,UAAU,EAAE,MAAM;aAClB,aAAa,EAAE,MAAM;aACrB,KAAK,EAAE,MAAM,EAAE;aACf,SAAS,EAAE,MAAM;IATlC,SAAgB,IAAI,oBAAmB;gBAGtB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,IAAI,EACf,SAAS,EAAE,IAAI,EACf,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,MAAM;CAElC"}
|
package/dist/src/events/Event.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeleteEvent = exports.CreateEvent = exports.UpdateEvent = void 0;
|
|
4
|
-
const EventType_1 = require("./EventType");
|
|
5
|
-
class UpdateEvent {
|
|
6
|
-
constructor(id, createdAt, appliedAt, identityId, transactionId, rowId, tableName, values) {
|
|
7
|
-
this.id = id;
|
|
8
|
-
this.createdAt = createdAt;
|
|
9
|
-
this.appliedAt = appliedAt;
|
|
10
|
-
this.identityId = identityId;
|
|
11
|
-
this.transactionId = transactionId;
|
|
12
|
-
this.rowId = rowId;
|
|
13
|
-
this.tableName = tableName;
|
|
14
|
-
this.values = values;
|
|
15
|
-
this.type = EventType_1.EventType.update;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.UpdateEvent = UpdateEvent;
|
|
19
|
-
class CreateEvent {
|
|
20
|
-
constructor(id, createdAt, appliedAt, identityId, transactionId, rowId, tableName, values) {
|
|
21
|
-
this.id = id;
|
|
22
|
-
this.createdAt = createdAt;
|
|
23
|
-
this.appliedAt = appliedAt;
|
|
24
|
-
this.identityId = identityId;
|
|
25
|
-
this.transactionId = transactionId;
|
|
26
|
-
this.rowId = rowId;
|
|
27
|
-
this.tableName = tableName;
|
|
28
|
-
this.values = values;
|
|
29
|
-
this.type = EventType_1.EventType.create;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.CreateEvent = CreateEvent;
|
|
33
|
-
class DeleteEvent {
|
|
34
|
-
constructor(id, createdAt, appliedAt, identityId, transactionId, rowId, tableName) {
|
|
35
|
-
this.id = id;
|
|
36
|
-
this.createdAt = createdAt;
|
|
37
|
-
this.appliedAt = appliedAt;
|
|
38
|
-
this.identityId = identityId;
|
|
39
|
-
this.transactionId = transactionId;
|
|
40
|
-
this.rowId = rowId;
|
|
41
|
-
this.tableName = tableName;
|
|
42
|
-
this.type = EventType_1.EventType.delete;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.DeleteEvent = DeleteEvent;
|
|
46
|
-
//# sourceMappingURL=Event.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","sourceRoot":"","sources":["../../../src/events/Event.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAavC,MAAa,WAAW;IAGvB,YACiB,EAAU,EACV,SAAe,EACf,SAAe,EACf,UAAkB,EAClB,aAAqB,EACrB,KAAe,EACf,SAAiB,EACjB,MAAiC;QAPjC,OAAE,GAAF,EAAE,CAAQ;QACV,cAAS,GAAT,SAAS,CAAM;QACf,cAAS,GAAT,SAAS,CAAM;QACf,eAAU,GAAV,UAAU,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AAED,eAAO,MAAM,aAAa,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAIhF,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContentEvents = exports.EventType = void 0;
|
|
4
|
-
var EventType;
|
|
5
|
-
(function (EventType) {
|
|
6
|
-
EventType["delete"] = "delete";
|
|
7
|
-
EventType["update"] = "update";
|
|
8
|
-
EventType["create"] = "create";
|
|
9
|
-
})(EventType = exports.EventType || (exports.EventType = {}));
|
|
10
|
-
exports.ContentEvents = [
|
|
11
|
-
EventType.delete,
|
|
12
|
-
EventType.update,
|
|
13
|
-
EventType.create,
|
|
14
|
-
];
|
|
15
|
-
//# sourceMappingURL=EventType.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventType.js","sourceRoot":"","sources":["../../../src/events/EventType.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAIX;AAJD,WAAY,SAAS;IACpB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;AAClB,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB;AAEY,QAAA,aAAa,GAA2D;IACpF,SAAS,CAAC,MAAM;IAChB,SAAS,CAAC,MAAM;IAChB,SAAS,CAAC,MAAM;CAChB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/events/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,8CAA2B;AAC3B,0CAAuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/events/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAGhD,eAAO,MAAM,cAAc,OAAQ,QAAQ,uBAE1C,CAAA"}
|
package/dist/src/events/utils.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isContentEvent = void 0;
|
|
4
|
-
const EventType_1 = require("./EventType");
|
|
5
|
-
const isContentEvent = (it) => {
|
|
6
|
-
return EventType_1.ContentEvents.includes(it.type);
|
|
7
|
-
};
|
|
8
|
-
exports.isContentEvent = isContentEvent;
|
|
9
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/events/utils.ts"],"names":[],"mappings":";;;AACA,2CAA2C;AAEpC,MAAM,cAAc,GAAG,CAAC,EAAY,EAAsB,EAAE;IAClE,OAAO,yBAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,IAA4B,CAAC,CAAA;AAC/D,CAAC,CAAA;AAFY,QAAA,cAAc,kBAE1B"}
|
package/src/events/Event.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { EventType } from './EventType'
|
|
2
|
-
|
|
3
|
-
export type ContentEvent = UpdateEvent | CreateEvent | DeleteEvent
|
|
4
|
-
export type AnyEvent = ContentEvent
|
|
5
|
-
|
|
6
|
-
export interface Event {
|
|
7
|
-
readonly type: EventType
|
|
8
|
-
readonly id: string
|
|
9
|
-
readonly createdAt: Date
|
|
10
|
-
readonly transactionId: string
|
|
11
|
-
// readonly errors?: string[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class UpdateEvent implements Event {
|
|
15
|
-
public readonly type = EventType.update
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
public readonly id: string,
|
|
19
|
-
public readonly createdAt: Date,
|
|
20
|
-
public readonly appliedAt: Date,
|
|
21
|
-
public readonly identityId: string,
|
|
22
|
-
public readonly transactionId: string,
|
|
23
|
-
public readonly rowId: string[],
|
|
24
|
-
public readonly tableName: string,
|
|
25
|
-
public readonly values: { [column: string]: any },
|
|
26
|
-
) {}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export class CreateEvent implements Event {
|
|
30
|
-
public readonly type = EventType.create
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
public readonly id: string,
|
|
34
|
-
public readonly createdAt: Date,
|
|
35
|
-
public readonly appliedAt: Date,
|
|
36
|
-
public readonly identityId: string,
|
|
37
|
-
public readonly transactionId: string,
|
|
38
|
-
public readonly rowId: string[],
|
|
39
|
-
public readonly tableName: string,
|
|
40
|
-
public readonly values: { [column: string]: any },
|
|
41
|
-
) {}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export class DeleteEvent implements Event {
|
|
45
|
-
public readonly type = EventType.delete
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
public readonly id: string,
|
|
49
|
-
public readonly createdAt: Date,
|
|
50
|
-
public readonly appliedAt: Date,
|
|
51
|
-
public readonly identityId: string,
|
|
52
|
-
public readonly transactionId: string,
|
|
53
|
-
public readonly rowId: string[],
|
|
54
|
-
public readonly tableName: string,
|
|
55
|
-
) {}
|
|
56
|
-
}
|
package/src/events/EventType.ts
DELETED
package/src/events/index.ts
DELETED
package/src/events/utils.ts
DELETED