@contember/engine-actions 2.0.9 → 2.0.10
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/development/src/dispatch/EventsRepository.cjs +1 -1
- package/dist/development/src/dispatch/EventsRepository.cjs.map +1 -1
- package/dist/development/src/dispatch/EventsRepository.js +1 -1
- package/dist/development/src/dispatch/EventsRepository.js.map +1 -1
- package/dist/production/src/dispatch/EventsRepository.cjs +1 -1
- package/dist/production/src/dispatch/EventsRepository.cjs.map +1 -1
- package/dist/production/src/dispatch/EventsRepository.js +1 -1
- package/dist/production/src/dispatch/EventsRepository.js.map +1 -1
- package/dist/tests/cases/unit/eventsRepository.test.d.ts +2 -0
- package/dist/tests/cases/unit/eventsRepository.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/dispatch/EventsRepository.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/dispatch/EventsRepository.ts +2 -1
- package/tests/cases/unit/eventsRepository.test.ts +82 -0
package/package.json
CHANGED
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@contember/authorization": "2.0.
|
|
26
|
-
"@contember/database": "2.0.
|
|
27
|
-
"@contember/database-migrations": "2.0.
|
|
28
|
-
"@contember/engine-common": "2.0.
|
|
29
|
-
"@contember/engine-content-api": "2.0.
|
|
30
|
-
"@contember/engine-http": "2.0.
|
|
31
|
-
"@contember/engine-plugins": "2.0.
|
|
32
|
-
"@contember/engine-system-api": "2.0.
|
|
33
|
-
"@contember/engine-tenant-api": "2.0.
|
|
34
|
-
"@contember/graphql-utils": "2.0.
|
|
35
|
-
"@contember/logger": "2.0.
|
|
36
|
-
"@contember/schema": "2.0.
|
|
37
|
-
"@contember/schema-utils": "2.0.
|
|
38
|
-
"@contember/typesafe": "2.0.
|
|
25
|
+
"@contember/authorization": "2.0.10",
|
|
26
|
+
"@contember/database": "2.0.10",
|
|
27
|
+
"@contember/database-migrations": "2.0.10",
|
|
28
|
+
"@contember/engine-common": "2.0.10",
|
|
29
|
+
"@contember/engine-content-api": "2.0.10",
|
|
30
|
+
"@contember/engine-http": "2.0.10",
|
|
31
|
+
"@contember/engine-plugins": "2.0.10",
|
|
32
|
+
"@contember/engine-system-api": "2.0.10",
|
|
33
|
+
"@contember/engine-tenant-api": "2.0.10",
|
|
34
|
+
"@contember/graphql-utils": "2.0.10",
|
|
35
|
+
"@contember/logger": "2.0.10",
|
|
36
|
+
"@contember/schema": "2.0.10",
|
|
37
|
+
"@contember/schema-utils": "2.0.10",
|
|
38
|
+
"@contember/typesafe": "2.0.10",
|
|
39
39
|
"@graphql-tools/schema": "^10.0.7",
|
|
40
40
|
"graphql-tag": "^2.12.6"
|
|
41
41
|
},
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"pg": "^8.5.0"
|
|
50
50
|
},
|
|
51
51
|
"type": "module",
|
|
52
|
-
"version": "2.0.
|
|
52
|
+
"version": "2.0.10",
|
|
53
53
|
"repository": {
|
|
54
54
|
"type": "git",
|
|
55
55
|
"url": "git+https://github.com/contember/contember.git",
|
|
@@ -31,7 +31,8 @@ export class EventsRepository {
|
|
|
31
31
|
return await this.fetchBatch(actions, db)
|
|
32
32
|
}
|
|
33
33
|
const batchSize = (target.batchSize ?? DEFAULT_BATCH_SIZE) - 1
|
|
34
|
-
|
|
34
|
+
// A batch is delivered to the primary event's target, so it may only take events of that target.
|
|
35
|
+
const batch = batchSize > 0 ? await this.fetchInternal(db, batchSize, primaryEvent.target) : []
|
|
35
36
|
return { ok: true, events: [primaryEvent, ...batch], target }
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { Client, Connection, EventManager } from '@contember/database'
|
|
3
|
+
import { Actions } from '@contember/schema'
|
|
4
|
+
import { EventsRepository } from '../../../src/dispatch/EventsRepository'
|
|
5
|
+
import { EventRow } from '../../../src/model/types'
|
|
6
|
+
import { testUuid } from '../../src/uuid'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Answers statements from a script, then with an empty result, so what is under test is the
|
|
10
|
+
* repository's own bookkeeping rather than any SQL. Every statement is recorded in `queries`.
|
|
11
|
+
*/
|
|
12
|
+
const createStubClient = (responses: Connection.Result[] = [], queries: { sql: string; parameters: readonly any[] }[] = []): Client => {
|
|
13
|
+
const remaining = [...responses]
|
|
14
|
+
const eventManager = new EventManager()
|
|
15
|
+
const query = async <Row extends Record<string, any>>(sql: string, parameters: readonly any[] = []): Promise<Connection.Result<Row>> => {
|
|
16
|
+
queries.push({ sql, parameters })
|
|
17
|
+
const next = remaining.shift() ?? { rowCount: 0, rows: [] }
|
|
18
|
+
return { rowCount: next.rowCount, rows: next.rows as Row[] }
|
|
19
|
+
}
|
|
20
|
+
const transaction: Connection.TransactionLike = {
|
|
21
|
+
eventManager,
|
|
22
|
+
isClosed: false,
|
|
23
|
+
query,
|
|
24
|
+
scope: cb => Promise.resolve(cb(transaction)),
|
|
25
|
+
transaction: cb => Promise.resolve(cb(transaction)),
|
|
26
|
+
on: () => () => {},
|
|
27
|
+
rollback: async () => {},
|
|
28
|
+
commit: async () => {},
|
|
29
|
+
}
|
|
30
|
+
const connection: Connection.ConnectionLike = {
|
|
31
|
+
eventManager,
|
|
32
|
+
query,
|
|
33
|
+
scope: cb => Promise.resolve(cb(transaction)),
|
|
34
|
+
transaction: cb => Promise.resolve(cb(transaction)),
|
|
35
|
+
}
|
|
36
|
+
return new Client(connection, 'system', {})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const now = new Date('2024-06-20T12:00:00Z')
|
|
40
|
+
|
|
41
|
+
const eventRow: EventRow = {
|
|
42
|
+
created_at: now,
|
|
43
|
+
id: testUuid(1),
|
|
44
|
+
trigger: 'test',
|
|
45
|
+
target: 'test_target',
|
|
46
|
+
last_state_change: now,
|
|
47
|
+
log: [],
|
|
48
|
+
num_retries: 0,
|
|
49
|
+
resolved_at: null,
|
|
50
|
+
transaction_id: testUuid(2),
|
|
51
|
+
stage_id: testUuid(3),
|
|
52
|
+
visible_at: now,
|
|
53
|
+
payload: { operation: 'delete', trigger: 'test', entity: 'Article', id: testUuid(5) },
|
|
54
|
+
priority: 1,
|
|
55
|
+
schema_id: 1,
|
|
56
|
+
state: 'processing',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('fetchBatch', () => {
|
|
60
|
+
test("fills a batch only with events of the primary event's target", async () => {
|
|
61
|
+
const queries: { sql: string; parameters: readonly any[] }[] = []
|
|
62
|
+
const target: Actions.WebhookTarget = {
|
|
63
|
+
name: 'test_target',
|
|
64
|
+
type: 'webhook',
|
|
65
|
+
url: 'http://localhost',
|
|
66
|
+
maxAttempts: 3,
|
|
67
|
+
batchSize: 3,
|
|
68
|
+
}
|
|
69
|
+
const client = createStubClient([
|
|
70
|
+
{ rowCount: 1, rows: [eventRow] },
|
|
71
|
+
{ rowCount: 0, rows: [] },
|
|
72
|
+
], queries)
|
|
73
|
+
|
|
74
|
+
const result = await new EventsRepository().fetchBatch({ triggers: {}, targets: { test_target: target } }, client)
|
|
75
|
+
|
|
76
|
+
expect(result).toEqual({ ok: true, events: [eventRow], target })
|
|
77
|
+
expect(queries).toHaveLength(2)
|
|
78
|
+
// the rest of the batch goes to the same webhook — it must not pick up events of other targets
|
|
79
|
+
expect(queries[1].sql).toContain('"target" = ?')
|
|
80
|
+
expect(queries[1].parameters).toContain('test_target')
|
|
81
|
+
})
|
|
82
|
+
})
|