@haathie/pgmb 0.2.5 → 0.2.7
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/README.md +31 -0
- package/lib/client.js +9 -8
- package/lib/index.js +1 -0
- package/lib/utils.js +11 -0
- package/package.json +12 -5
- package/src/abortable-async-iterator.ts +98 -0
- package/src/batcher.ts +90 -0
- package/src/client.ts +699 -0
- package/src/consts.ts +1 -0
- package/src/index.ts +6 -0
- package/src/queries.ts +570 -0
- package/src/query-types.ts +21 -0
- package/src/retry-handler.ts +125 -0
- package/src/sse.ts +148 -0
- package/src/types.ts +267 -0
- package/src/utils.ts +71 -0
- package/src/webhook-handler.ts +91 -0
- package/lib/abortable-async-iterator.d.ts +0 -14
- package/lib/batcher.d.ts +0 -12
- package/lib/client.d.ts +0 -76
- package/lib/consts.d.ts +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/queries.d.ts +0 -453
- package/lib/query-types.d.ts +0 -17
- package/lib/retry-handler.d.ts +0 -11
- package/lib/sse.d.ts +0 -4
- package/lib/types.d.ts +0 -223
- package/lib/utils.d.ts +0 -15
- package/lib/webhook-handler.d.ts +0 -6
package/src/queries.ts
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
/** Types generated for queries found in "sql/queries.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
export type DateOrString = Date | string;
|
|
5
|
+
|
|
6
|
+
export type DateOrStringArray = (DateOrString)[];
|
|
7
|
+
|
|
8
|
+
export type stringArray = (string)[];
|
|
9
|
+
|
|
10
|
+
export type unknownArray = (unknown)[];
|
|
11
|
+
|
|
12
|
+
/** 'AssertGroup' parameters type */
|
|
13
|
+
export interface IAssertGroupParams {
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 'AssertGroup' return type */
|
|
18
|
+
export type IAssertGroupResult = void;
|
|
19
|
+
|
|
20
|
+
/** 'AssertGroup' query type */
|
|
21
|
+
export interface IAssertGroupQuery {
|
|
22
|
+
params: IAssertGroupParams;
|
|
23
|
+
result: IAssertGroupResult;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const assertGroupIR: any = {"usedParamSet":{"id":true},"params":[{"name":"id","required":true,"transform":{"type":"scalar"},"locs":[{"a":50,"b":53}]}],"statement":"INSERT INTO pgmb.subscription_groups (id)\nVALUES (:id!)\nON CONFLICT DO NOTHING"};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Query generated from SQL:
|
|
30
|
+
* ```
|
|
31
|
+
* INSERT INTO pgmb.subscription_groups (id)
|
|
32
|
+
* VALUES (:id!)
|
|
33
|
+
* ON CONFLICT DO NOTHING
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const assertGroup = new PreparedQuery<IAssertGroupParams,IAssertGroupResult>(assertGroupIR);
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/** 'AssertSubscription' parameters type */
|
|
40
|
+
export interface IAssertSubscriptionParams {
|
|
41
|
+
conditionsSql?: string | null | void;
|
|
42
|
+
expiryInterval?: DateOrString | null | void;
|
|
43
|
+
groupId: string;
|
|
44
|
+
params?: unknown | null | void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 'AssertSubscription' return type */
|
|
48
|
+
export interface IAssertSubscriptionResult {
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 'AssertSubscription' query type */
|
|
53
|
+
export interface IAssertSubscriptionQuery {
|
|
54
|
+
params: IAssertSubscriptionParams;
|
|
55
|
+
result: IAssertSubscriptionResult;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const assertSubscriptionIR: any = {"usedParamSet":{"groupId":true,"conditionsSql":true,"params":true,"expiryInterval":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":98,"b":106}]},{"name":"conditionsSql","required":false,"transform":{"type":"scalar"},"locs":[{"a":119,"b":132}]},{"name":"params","required":false,"transform":{"type":"scalar"},"locs":[{"a":154,"b":160}]},{"name":"expiryInterval","required":false,"transform":{"type":"scalar"},"locs":[{"a":178,"b":192}]}],"statement":"INSERT INTO pgmb.subscriptions\n\tAS s(group_id, conditions_sql, params, expiry_interval)\nVALUES (\n\t:groupId!,\n\tCOALESCE(:conditionsSql, 'TRUE'),\n\tCOALESCE(:params::jsonb, '{}'),\n\t:expiryInterval::interval\n)\nON CONFLICT (identity) DO UPDATE\nSET\n\t-- set expiry_interval to the new value only if it's greater than the existing one\n\t-- or if the new value is NULL (indicating no expiration)\n\texpiry_interval = CASE\n\t\tWHEN EXCLUDED.expiry_interval IS NULL OR s.expiry_interval IS NULL\n\t\t\tTHEN NULL\n\t\tELSE\n\t\t\tGREATEST(s.expiry_interval, EXCLUDED.expiry_interval)\n\tEND,\n\tlast_active_at = NOW()\nRETURNING id AS \"id!\""};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Query generated from SQL:
|
|
62
|
+
* ```
|
|
63
|
+
* INSERT INTO pgmb.subscriptions
|
|
64
|
+
* AS s(group_id, conditions_sql, params, expiry_interval)
|
|
65
|
+
* VALUES (
|
|
66
|
+
* :groupId!,
|
|
67
|
+
* COALESCE(:conditionsSql, 'TRUE'),
|
|
68
|
+
* COALESCE(:params::jsonb, '{}'),
|
|
69
|
+
* :expiryInterval::interval
|
|
70
|
+
* )
|
|
71
|
+
* ON CONFLICT (identity) DO UPDATE
|
|
72
|
+
* SET
|
|
73
|
+
* -- set expiry_interval to the new value only if it's greater than the existing one
|
|
74
|
+
* -- or if the new value is NULL (indicating no expiration)
|
|
75
|
+
* expiry_interval = CASE
|
|
76
|
+
* WHEN EXCLUDED.expiry_interval IS NULL OR s.expiry_interval IS NULL
|
|
77
|
+
* THEN NULL
|
|
78
|
+
* ELSE
|
|
79
|
+
* GREATEST(s.expiry_interval, EXCLUDED.expiry_interval)
|
|
80
|
+
* END,
|
|
81
|
+
* last_active_at = NOW()
|
|
82
|
+
* RETURNING id AS "id!"
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export const assertSubscription = new PreparedQuery<IAssertSubscriptionParams,IAssertSubscriptionResult>(assertSubscriptionIR);
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/** 'DeleteSubscriptions' parameters type */
|
|
89
|
+
export interface IDeleteSubscriptionsParams {
|
|
90
|
+
ids: readonly (string)[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 'DeleteSubscriptions' return type */
|
|
94
|
+
export type IDeleteSubscriptionsResult = void;
|
|
95
|
+
|
|
96
|
+
/** 'DeleteSubscriptions' query type */
|
|
97
|
+
export interface IDeleteSubscriptionsQuery {
|
|
98
|
+
params: IDeleteSubscriptionsParams;
|
|
99
|
+
result: IDeleteSubscriptionsResult;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const deleteSubscriptionsIR: any = {"usedParamSet":{"ids":true},"params":[{"name":"ids","required":true,"transform":{"type":"array_spread"},"locs":[{"a":43,"b":47}]}],"statement":"DELETE FROM pgmb.subscriptions\nWHERE id IN :ids!"};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Query generated from SQL:
|
|
106
|
+
* ```
|
|
107
|
+
* DELETE FROM pgmb.subscriptions
|
|
108
|
+
* WHERE id IN :ids!
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export const deleteSubscriptions = new PreparedQuery<IDeleteSubscriptionsParams,IDeleteSubscriptionsResult>(deleteSubscriptionsIR);
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/** 'MarkSubscriptionsActive' parameters type */
|
|
115
|
+
export interface IMarkSubscriptionsActiveParams {
|
|
116
|
+
ids: stringArray;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 'MarkSubscriptionsActive' return type */
|
|
120
|
+
export type IMarkSubscriptionsActiveResult = void;
|
|
121
|
+
|
|
122
|
+
/** 'MarkSubscriptionsActive' query type */
|
|
123
|
+
export interface IMarkSubscriptionsActiveQuery {
|
|
124
|
+
params: IMarkSubscriptionsActiveParams;
|
|
125
|
+
result: IMarkSubscriptionsActiveResult;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const markSubscriptionsActiveIR: any = {"usedParamSet":{"ids":true},"params":[{"name":"ids","required":true,"transform":{"type":"scalar"},"locs":[{"a":88,"b":92}]}],"statement":"UPDATE pgmb.subscriptions\nSET\n\tlast_active_at = NOW()\nWHERE id IN (SELECT * FROM unnest(:ids!::pgmb.subscription_id[]))"};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Query generated from SQL:
|
|
132
|
+
* ```
|
|
133
|
+
* UPDATE pgmb.subscriptions
|
|
134
|
+
* SET
|
|
135
|
+
* last_active_at = NOW()
|
|
136
|
+
* WHERE id IN (SELECT * FROM unnest(:ids!::pgmb.subscription_id[]))
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export const markSubscriptionsActive = new PreparedQuery<IMarkSubscriptionsActiveParams,IMarkSubscriptionsActiveResult>(markSubscriptionsActiveIR);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/** 'PollForEvents' parameters type */
|
|
143
|
+
export type IPollForEventsParams = void;
|
|
144
|
+
|
|
145
|
+
/** 'PollForEvents' return type */
|
|
146
|
+
export interface IPollForEventsResult {
|
|
147
|
+
count: number;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 'PollForEvents' query type */
|
|
151
|
+
export interface IPollForEventsQuery {
|
|
152
|
+
params: IPollForEventsParams;
|
|
153
|
+
result: IPollForEventsResult;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const pollForEventsIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT count AS \"count!\" FROM pgmb.poll_for_events() AS count"};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Query generated from SQL:
|
|
160
|
+
* ```
|
|
161
|
+
* SELECT count AS "count!" FROM pgmb.poll_for_events() AS count
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export const pollForEvents = new PreparedQuery<IPollForEventsParams,IPollForEventsResult>(pollForEventsIR);
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
/** 'ReadNextEvents' parameters type */
|
|
168
|
+
export interface IReadNextEventsParams {
|
|
169
|
+
chunkSize: number;
|
|
170
|
+
cursor?: string | null | void;
|
|
171
|
+
groupId: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** 'ReadNextEvents' return type */
|
|
175
|
+
export interface IReadNextEventsResult {
|
|
176
|
+
id: string;
|
|
177
|
+
metadata: unknown;
|
|
178
|
+
nextCursor: string;
|
|
179
|
+
payload: unknown;
|
|
180
|
+
subscriptionIds: stringArray;
|
|
181
|
+
topic: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** 'ReadNextEvents' query type */
|
|
185
|
+
export interface IReadNextEventsQuery {
|
|
186
|
+
params: IReadNextEventsParams;
|
|
187
|
+
result: IReadNextEventsResult;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const readNextEventsIR: any = {"usedParamSet":{"groupId":true,"cursor":true,"chunkSize":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":197,"b":205}]},{"name":"cursor","required":false,"transform":{"type":"scalar"},"locs":[{"a":208,"b":214}]},{"name":"chunkSize","required":true,"transform":{"type":"scalar"},"locs":[{"a":217,"b":227}]}],"statement":"SELECT\n\tid AS \"id!\",\n\ttopic AS \"topic!\",\n\tpayload AS \"payload!\",\n\tmetadata AS \"metadata!\",\n\tsubscription_ids::text[] AS \"subscriptionIds!\",\n\tnext_cursor AS \"nextCursor!\"\nFROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)"};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Query generated from SQL:
|
|
194
|
+
* ```
|
|
195
|
+
* SELECT
|
|
196
|
+
* id AS "id!",
|
|
197
|
+
* topic AS "topic!",
|
|
198
|
+
* payload AS "payload!",
|
|
199
|
+
* metadata AS "metadata!",
|
|
200
|
+
* subscription_ids::text[] AS "subscriptionIds!",
|
|
201
|
+
* next_cursor AS "nextCursor!"
|
|
202
|
+
* FROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export const readNextEvents = new PreparedQuery<IReadNextEventsParams,IReadNextEventsResult>(readNextEventsIR);
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
/** 'ReadNextEventsText' parameters type */
|
|
209
|
+
export interface IReadNextEventsTextParams {
|
|
210
|
+
chunkSize: number;
|
|
211
|
+
cursor?: string | null | void;
|
|
212
|
+
groupId: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** 'ReadNextEventsText' return type */
|
|
216
|
+
export interface IReadNextEventsTextResult {
|
|
217
|
+
id: string;
|
|
218
|
+
payload: string;
|
|
219
|
+
topic: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 'ReadNextEventsText' query type */
|
|
223
|
+
export interface IReadNextEventsTextQuery {
|
|
224
|
+
params: IReadNextEventsTextParams;
|
|
225
|
+
result: IReadNextEventsTextResult;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const readNextEventsTextIR: any = {"usedParamSet":{"groupId":true,"cursor":true,"chunkSize":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":97,"b":105}]},{"name":"cursor","required":false,"transform":{"type":"scalar"},"locs":[{"a":108,"b":114}]},{"name":"chunkSize","required":true,"transform":{"type":"scalar"},"locs":[{"a":117,"b":127}]}],"statement":"SELECT\n\tid AS \"id!\",\n\ttopic AS \"topic!\",\n\tpayload::text AS \"payload!\"\nFROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)"};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Query generated from SQL:
|
|
232
|
+
* ```
|
|
233
|
+
* SELECT
|
|
234
|
+
* id AS "id!",
|
|
235
|
+
* topic AS "topic!",
|
|
236
|
+
* payload::text AS "payload!"
|
|
237
|
+
* FROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export const readNextEventsText = new PreparedQuery<IReadNextEventsTextParams,IReadNextEventsTextResult>(readNextEventsTextIR);
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
/** 'ReplayEvents' parameters type */
|
|
244
|
+
export interface IReplayEventsParams {
|
|
245
|
+
fromEventId: string;
|
|
246
|
+
groupId: string;
|
|
247
|
+
maxEvents: number;
|
|
248
|
+
subscriptionId: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** 'ReplayEvents' return type */
|
|
252
|
+
export interface IReplayEventsResult {
|
|
253
|
+
id: string;
|
|
254
|
+
metadata: unknown;
|
|
255
|
+
payload: unknown;
|
|
256
|
+
topic: string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** 'ReplayEvents' query type */
|
|
260
|
+
export interface IReplayEventsQuery {
|
|
261
|
+
params: IReplayEventsParams;
|
|
262
|
+
result: IReplayEventsResult;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const replayEventsIR: any = {"usedParamSet":{"groupId":true,"subscriptionId":true,"fromEventId":true,"maxEvents":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":116,"b":124}]},{"name":"subscriptionId","required":true,"transform":{"type":"scalar"},"locs":[{"a":128,"b":143}]},{"name":"fromEventId","required":true,"transform":{"type":"scalar"},"locs":[{"a":147,"b":159}]},{"name":"maxEvents","required":true,"transform":{"type":"scalar"},"locs":[{"a":178,"b":188}]}],"statement":"SELECT\n\tid AS \"id!\",\n\ttopic AS \"topic!\",\n\tpayload AS \"payload!\",\n\tmetadata AS \"metadata!\"\nFROM pgmb.replay_events(\n\t:groupId!,\n\t:subscriptionId!,\n\t:fromEventId!::pgmb.event_id,\n\t:maxEvents!\n)"};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Query generated from SQL:
|
|
269
|
+
* ```
|
|
270
|
+
* SELECT
|
|
271
|
+
* id AS "id!",
|
|
272
|
+
* topic AS "topic!",
|
|
273
|
+
* payload AS "payload!",
|
|
274
|
+
* metadata AS "metadata!"
|
|
275
|
+
* FROM pgmb.replay_events(
|
|
276
|
+
* :groupId!,
|
|
277
|
+
* :subscriptionId!,
|
|
278
|
+
* :fromEventId!::pgmb.event_id,
|
|
279
|
+
* :maxEvents!
|
|
280
|
+
* )
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export const replayEvents = new PreparedQuery<IReplayEventsParams,IReplayEventsResult>(replayEventsIR);
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
/** 'SetGroupCursor' parameters type */
|
|
287
|
+
export interface ISetGroupCursorParams {
|
|
288
|
+
cursor: string;
|
|
289
|
+
groupId: string;
|
|
290
|
+
releaseLock?: boolean | null | void;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** 'SetGroupCursor' return type */
|
|
294
|
+
export interface ISetGroupCursorResult {
|
|
295
|
+
success: undefined;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** 'SetGroupCursor' query type */
|
|
299
|
+
export interface ISetGroupCursorQuery {
|
|
300
|
+
params: ISetGroupCursorParams;
|
|
301
|
+
result: ISetGroupCursorResult;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const setGroupCursorIR: any = {"usedParamSet":{"groupId":true,"cursor":true,"releaseLock":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":31,"b":39}]},{"name":"cursor","required":true,"transform":{"type":"scalar"},"locs":[{"a":43,"b":50}]},{"name":"releaseLock","required":false,"transform":{"type":"scalar"},"locs":[{"a":69,"b":80}]}],"statement":"SELECT pgmb.set_group_cursor(\n\t:groupId!,\n\t:cursor!::pgmb.event_id,\n\t:releaseLock::boolean\n) AS \"success!\""};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Query generated from SQL:
|
|
308
|
+
* ```
|
|
309
|
+
* SELECT pgmb.set_group_cursor(
|
|
310
|
+
* :groupId!,
|
|
311
|
+
* :cursor!::pgmb.event_id,
|
|
312
|
+
* :releaseLock::boolean
|
|
313
|
+
* ) AS "success!"
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
export const setGroupCursor = new PreparedQuery<ISetGroupCursorParams,ISetGroupCursorResult>(setGroupCursorIR);
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
/** 'ReleaseGroupLock' parameters type */
|
|
320
|
+
export interface IReleaseGroupLockParams {
|
|
321
|
+
groupId: string;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** 'ReleaseGroupLock' return type */
|
|
325
|
+
export interface IReleaseGroupLockResult {
|
|
326
|
+
success: undefined;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** 'ReleaseGroupLock' query type */
|
|
330
|
+
export interface IReleaseGroupLockQuery {
|
|
331
|
+
params: IReleaseGroupLockParams;
|
|
332
|
+
result: IReleaseGroupLockResult;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const releaseGroupLockIR: any = {"usedParamSet":{"groupId":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":31,"b":39}]}],"statement":"SELECT pgmb.release_group_lock(:groupId!) AS \"success!\""};
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Query generated from SQL:
|
|
339
|
+
* ```
|
|
340
|
+
* SELECT pgmb.release_group_lock(:groupId!) AS "success!"
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
export const releaseGroupLock = new PreparedQuery<IReleaseGroupLockParams,IReleaseGroupLockResult>(releaseGroupLockIR);
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
/** 'WriteEvents' parameters type */
|
|
347
|
+
export interface IWriteEventsParams {
|
|
348
|
+
metadatas: unknownArray;
|
|
349
|
+
payloads: unknownArray;
|
|
350
|
+
topics: stringArray;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** 'WriteEvents' return type */
|
|
354
|
+
export interface IWriteEventsResult {
|
|
355
|
+
id: string;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** 'WriteEvents' query type */
|
|
359
|
+
export interface IWriteEventsQuery {
|
|
360
|
+
params: IWriteEventsParams;
|
|
361
|
+
result: IWriteEventsResult;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const writeEventsIR: any = {"usedParamSet":{"topics":true,"payloads":true,"metadatas":true},"params":[{"name":"topics","required":true,"transform":{"type":"scalar"},"locs":[{"a":100,"b":107}]},{"name":"payloads","required":true,"transform":{"type":"scalar"},"locs":[{"a":119,"b":128}]},{"name":"metadatas","required":true,"transform":{"type":"scalar"},"locs":[{"a":141,"b":151}]}],"statement":"INSERT INTO pgmb.events (topic, payload, metadata)\nSELECT\n\ttopic,\n\tpayload,\n\tmetadata\nFROM unnest(\n\t:topics!::TEXT[],\n\t:payloads!::JSONB[],\n\t:metadatas!::JSONB[]\n) AS t(topic, payload, metadata)\nRETURNING id AS \"id!\""};
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Query generated from SQL:
|
|
368
|
+
* ```
|
|
369
|
+
* INSERT INTO pgmb.events (topic, payload, metadata)
|
|
370
|
+
* SELECT
|
|
371
|
+
* topic,
|
|
372
|
+
* payload,
|
|
373
|
+
* metadata
|
|
374
|
+
* FROM unnest(
|
|
375
|
+
* :topics!::TEXT[],
|
|
376
|
+
* :payloads!::JSONB[],
|
|
377
|
+
* :metadatas!::JSONB[]
|
|
378
|
+
* ) AS t(topic, payload, metadata)
|
|
379
|
+
* RETURNING id AS "id!"
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
export const writeEvents = new PreparedQuery<IWriteEventsParams,IWriteEventsResult>(writeEventsIR);
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
/** 'WriteScheduledEvents' parameters type */
|
|
386
|
+
export interface IWriteScheduledEventsParams {
|
|
387
|
+
metadatas: unknownArray;
|
|
388
|
+
payloads: unknownArray;
|
|
389
|
+
topics: stringArray;
|
|
390
|
+
ts: DateOrStringArray;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** 'WriteScheduledEvents' return type */
|
|
394
|
+
export interface IWriteScheduledEventsResult {
|
|
395
|
+
id: string;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** 'WriteScheduledEvents' query type */
|
|
399
|
+
export interface IWriteScheduledEventsQuery {
|
|
400
|
+
params: IWriteScheduledEventsParams;
|
|
401
|
+
result: IWriteScheduledEventsResult;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const writeScheduledEventsIR: any = {"usedParamSet":{"ts":true,"topics":true,"payloads":true,"metadatas":true},"params":[{"name":"ts","required":true,"transform":{"type":"scalar"},"locs":[{"a":189,"b":192}]},{"name":"topics","required":true,"transform":{"type":"scalar"},"locs":[{"a":211,"b":218}]},{"name":"payloads","required":true,"transform":{"type":"scalar"},"locs":[{"a":230,"b":239}]},{"name":"metadatas","required":true,"transform":{"type":"scalar"},"locs":[{"a":252,"b":262}]}],"statement":"INSERT INTO pgmb.events (id, topic, payload, metadata)\nSELECT\n\tpgmb.create_event_id(COALESCE(ts, clock_timestamp()), pgmb.create_random_bigint()),\n\ttopic,\n\tpayload,\n\tmetadata\nFROM unnest(\n\t:ts!::TIMESTAMPTZ[],\n\t:topics!::TEXT[],\n\t:payloads!::JSONB[],\n\t:metadatas!::JSONB[]\n) AS t(ts, topic, payload, metadata)\nRETURNING id AS \"id!\""};
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Query generated from SQL:
|
|
408
|
+
* ```
|
|
409
|
+
* INSERT INTO pgmb.events (id, topic, payload, metadata)
|
|
410
|
+
* SELECT
|
|
411
|
+
* pgmb.create_event_id(COALESCE(ts, clock_timestamp()), pgmb.create_random_bigint()),
|
|
412
|
+
* topic,
|
|
413
|
+
* payload,
|
|
414
|
+
* metadata
|
|
415
|
+
* FROM unnest(
|
|
416
|
+
* :ts!::TIMESTAMPTZ[],
|
|
417
|
+
* :topics!::TEXT[],
|
|
418
|
+
* :payloads!::JSONB[],
|
|
419
|
+
* :metadatas!::JSONB[]
|
|
420
|
+
* ) AS t(ts, topic, payload, metadata)
|
|
421
|
+
* RETURNING id AS "id!"
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
export const writeScheduledEvents = new PreparedQuery<IWriteScheduledEventsParams,IWriteScheduledEventsResult>(writeScheduledEventsIR);
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
/** 'ScheduleEventRetry' parameters type */
|
|
428
|
+
export interface IScheduleEventRetryParams {
|
|
429
|
+
delayInterval: DateOrString;
|
|
430
|
+
handlerName: string;
|
|
431
|
+
ids: stringArray;
|
|
432
|
+
retryNumber: number;
|
|
433
|
+
subscriptionId: string;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** 'ScheduleEventRetry' return type */
|
|
437
|
+
export interface IScheduleEventRetryResult {
|
|
438
|
+
id: string;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** 'ScheduleEventRetry' query type */
|
|
442
|
+
export interface IScheduleEventRetryQuery {
|
|
443
|
+
params: IScheduleEventRetryParams;
|
|
444
|
+
result: IScheduleEventRetryResult;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const scheduleEventRetryIR: any = {"usedParamSet":{"delayInterval":true,"ids":true,"retryNumber":true,"handlerName":true,"subscriptionId":true},"params":[{"name":"delayInterval","required":true,"transform":{"type":"scalar"},"locs":[{"a":103,"b":117}]},{"name":"ids","required":true,"transform":{"type":"scalar"},"locs":[{"a":212,"b":216}]},{"name":"retryNumber","required":true,"transform":{"type":"scalar"},"locs":[{"a":255,"b":267}]},{"name":"handlerName","required":true,"transform":{"type":"scalar"},"locs":[{"a":294,"b":306}]},{"name":"subscriptionId","required":true,"transform":{"type":"scalar"},"locs":[{"a":319,"b":334}]}],"statement":"INSERT INTO pgmb.events (id, topic, payload, subscription_id)\nSELECT\n\tpgmb.create_event_id(\n\t\tNOW() + (:delayInterval!::INTERVAL),\n\t\tpgmb.create_random_bigint()\n\t),\n\t'pgmb-retry',\n\tjsonb_build_object(\n\t\t'ids',\n\t\t:ids!::pgmb.event_id[],\n\t\t'retryNumber',\n\t\t:retryNumber!::int,\n\t\t'handlerName',\n\t\t:handlerName!::text\n\t),\n\t:subscriptionId!::pgmb.subscription_id\nRETURNING id AS \"id!\""};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Query generated from SQL:
|
|
451
|
+
* ```
|
|
452
|
+
* INSERT INTO pgmb.events (id, topic, payload, subscription_id)
|
|
453
|
+
* SELECT
|
|
454
|
+
* pgmb.create_event_id(
|
|
455
|
+
* NOW() + (:delayInterval!::INTERVAL),
|
|
456
|
+
* pgmb.create_random_bigint()
|
|
457
|
+
* ),
|
|
458
|
+
* 'pgmb-retry',
|
|
459
|
+
* jsonb_build_object(
|
|
460
|
+
* 'ids',
|
|
461
|
+
* :ids!::pgmb.event_id[],
|
|
462
|
+
* 'retryNumber',
|
|
463
|
+
* :retryNumber!::int,
|
|
464
|
+
* 'handlerName',
|
|
465
|
+
* :handlerName!::text
|
|
466
|
+
* ),
|
|
467
|
+
* :subscriptionId!::pgmb.subscription_id
|
|
468
|
+
* RETURNING id AS "id!"
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
export const scheduleEventRetry = new PreparedQuery<IScheduleEventRetryParams,IScheduleEventRetryResult>(scheduleEventRetryIR);
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
/** 'FindEvents' parameters type */
|
|
475
|
+
export interface IFindEventsParams {
|
|
476
|
+
ids: stringArray;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** 'FindEvents' return type */
|
|
480
|
+
export interface IFindEventsResult {
|
|
481
|
+
id: string;
|
|
482
|
+
metadata: unknown;
|
|
483
|
+
payload: unknown;
|
|
484
|
+
topic: string;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** 'FindEvents' query type */
|
|
488
|
+
export interface IFindEventsQuery {
|
|
489
|
+
params: IFindEventsParams;
|
|
490
|
+
result: IFindEventsResult;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const findEventsIR: any = {"usedParamSet":{"ids":true},"params":[{"name":"ids","required":true,"transform":{"type":"scalar"},"locs":[{"a":122,"b":126}]}],"statement":"SELECT\n\tid AS \"id!\",\n\ttopic AS \"topic!\",\n\tpayload AS \"payload!\",\n\tmetadata AS \"metadata!\"\nFROM pgmb.events\nWHERE id = ANY(:ids!::pgmb.event_id[])"};
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Query generated from SQL:
|
|
497
|
+
* ```
|
|
498
|
+
* SELECT
|
|
499
|
+
* id AS "id!",
|
|
500
|
+
* topic AS "topic!",
|
|
501
|
+
* payload AS "payload!",
|
|
502
|
+
* metadata AS "metadata!"
|
|
503
|
+
* FROM pgmb.events
|
|
504
|
+
* WHERE id = ANY(:ids!::pgmb.event_id[])
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
export const findEvents = new PreparedQuery<IFindEventsParams,IFindEventsResult>(findEventsIR);
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
/** 'RemoveExpiredSubscriptions' parameters type */
|
|
511
|
+
export interface IRemoveExpiredSubscriptionsParams {
|
|
512
|
+
activeIds: stringArray;
|
|
513
|
+
groupId: string;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** 'RemoveExpiredSubscriptions' return type */
|
|
517
|
+
export interface IRemoveExpiredSubscriptionsResult {
|
|
518
|
+
deleted: string;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** 'RemoveExpiredSubscriptions' query type */
|
|
522
|
+
export interface IRemoveExpiredSubscriptionsQuery {
|
|
523
|
+
params: IRemoveExpiredSubscriptionsParams;
|
|
524
|
+
result: IRemoveExpiredSubscriptionsResult;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const removeExpiredSubscriptionsIR: any = {"usedParamSet":{"groupId":true,"activeIds":true},"params":[{"name":"groupId","required":true,"transform":{"type":"scalar"},"locs":[{"a":68,"b":76}]},{"name":"activeIds","required":true,"transform":{"type":"scalar"},"locs":[{"a":219,"b":229}]}],"statement":"WITH deleted AS (\n\tDELETE FROM pgmb.subscriptions\n\tWHERE group_id = :groupId!\n\t\tAND expiry_interval IS NOT NULL\n\t\tAND pgmb.add_interval_imm(last_active_at, expiry_interval) < NOW()\n\t\tAND id NOT IN (select * from unnest(:activeIds!::pgmb.subscription_id[]))\n\tRETURNING id\n)\nSELECT COUNT(*) AS \"deleted!\" FROM deleted"};
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Query generated from SQL:
|
|
531
|
+
* ```
|
|
532
|
+
* WITH deleted AS (
|
|
533
|
+
* DELETE FROM pgmb.subscriptions
|
|
534
|
+
* WHERE group_id = :groupId!
|
|
535
|
+
* AND expiry_interval IS NOT NULL
|
|
536
|
+
* AND pgmb.add_interval_imm(last_active_at, expiry_interval) < NOW()
|
|
537
|
+
* AND id NOT IN (select * from unnest(:activeIds!::pgmb.subscription_id[]))
|
|
538
|
+
* RETURNING id
|
|
539
|
+
* )
|
|
540
|
+
* SELECT COUNT(*) AS "deleted!" FROM deleted
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
export const removeExpiredSubscriptions = new PreparedQuery<IRemoveExpiredSubscriptionsParams,IRemoveExpiredSubscriptionsResult>(removeExpiredSubscriptionsIR);
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
/** 'MaintainEventsTable' parameters type */
|
|
547
|
+
export type IMaintainEventsTableParams = void;
|
|
548
|
+
|
|
549
|
+
/** 'MaintainEventsTable' return type */
|
|
550
|
+
export interface IMaintainEventsTableResult {
|
|
551
|
+
maintainEventsTable: undefined | null;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** 'MaintainEventsTable' query type */
|
|
555
|
+
export interface IMaintainEventsTableQuery {
|
|
556
|
+
params: IMaintainEventsTableParams;
|
|
557
|
+
result: IMaintainEventsTableResult;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const maintainEventsTableIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT pgmb.maintain_events_table()"};
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Query generated from SQL:
|
|
564
|
+
* ```
|
|
565
|
+
* SELECT pgmb.maintain_events_table()
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
export const maintainEventsTable = new PreparedQuery<IMaintainEventsTableParams,IMaintainEventsTableResult>(maintainEventsTableIR);
|
|
569
|
+
|
|
570
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type QueryResult<T> = {
|
|
2
|
+
rowCount: number
|
|
3
|
+
rows: T[]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface PgClient {
|
|
7
|
+
query<T = any>(query: string, params?: unknown[]): Promise<QueryResult<T>>
|
|
8
|
+
exec?(query: string): Promise<unknown>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PgReleasableClient extends PgClient {
|
|
12
|
+
release: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface PgPoolLike extends PgClient {
|
|
16
|
+
connect: () => Promise<PgReleasableClient>
|
|
17
|
+
on(ev: 'remove', handler: (cl: PgReleasableClient) => void): this
|
|
18
|
+
off(ev: 'remove', handler: (cl: PgReleasableClient) => void): this
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type PgClientLike = PgClient | PgPoolLike
|