@haathie/pgmb 0.2.0

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.
@@ -0,0 +1,453 @@
1
+ /** Types generated for queries found in "sql/queries.sql" */
2
+ import { PreparedQuery } from '@pgtyped/runtime';
3
+ export type DateOrString = Date | string;
4
+ export type DateOrStringArray = (DateOrString)[];
5
+ export type stringArray = (string)[];
6
+ export type unknownArray = (unknown)[];
7
+ /** 'AssertGroup' parameters type */
8
+ export interface IAssertGroupParams {
9
+ id: string;
10
+ }
11
+ /** 'AssertGroup' return type */
12
+ export type IAssertGroupResult = void;
13
+ /** 'AssertGroup' query type */
14
+ export interface IAssertGroupQuery {
15
+ params: IAssertGroupParams;
16
+ result: IAssertGroupResult;
17
+ }
18
+ /**
19
+ * Query generated from SQL:
20
+ * ```
21
+ * INSERT INTO pgmb.subscription_groups (id)
22
+ * VALUES (:id!)
23
+ * ON CONFLICT DO NOTHING
24
+ * ```
25
+ */
26
+ export declare const assertGroup: PreparedQuery<IAssertGroupParams, void>;
27
+ /** 'AssertSubscription' parameters type */
28
+ export interface IAssertSubscriptionParams {
29
+ conditionsSql?: string | null | void;
30
+ expiryInterval?: DateOrString | null | void;
31
+ groupId: string;
32
+ params?: unknown | null | void;
33
+ }
34
+ /** 'AssertSubscription' return type */
35
+ export interface IAssertSubscriptionResult {
36
+ id: string;
37
+ }
38
+ /** 'AssertSubscription' query type */
39
+ export interface IAssertSubscriptionQuery {
40
+ params: IAssertSubscriptionParams;
41
+ result: IAssertSubscriptionResult;
42
+ }
43
+ /**
44
+ * Query generated from SQL:
45
+ * ```
46
+ * INSERT INTO pgmb.subscriptions
47
+ * AS s(group_id, conditions_sql, params, expiry_interval)
48
+ * VALUES (
49
+ * :groupId!,
50
+ * COALESCE(:conditionsSql, 'TRUE'),
51
+ * COALESCE(:params::jsonb, '{}'),
52
+ * :expiryInterval::interval
53
+ * )
54
+ * ON CONFLICT (identity) DO UPDATE
55
+ * SET
56
+ * -- set expiry_interval to the new value only if it's greater than the existing one
57
+ * -- or if the new value is NULL (indicating no expiration)
58
+ * expiry_interval = CASE
59
+ * WHEN EXCLUDED.expiry_interval IS NULL OR s.expiry_interval IS NULL
60
+ * THEN NULL
61
+ * ELSE
62
+ * GREATEST(s.expiry_interval, EXCLUDED.expiry_interval)
63
+ * END,
64
+ * last_active_at = NOW()
65
+ * RETURNING id AS "id!"
66
+ * ```
67
+ */
68
+ export declare const assertSubscription: PreparedQuery<IAssertSubscriptionParams, IAssertSubscriptionResult>;
69
+ /** 'DeleteSubscriptions' parameters type */
70
+ export interface IDeleteSubscriptionsParams {
71
+ ids: readonly (string)[];
72
+ }
73
+ /** 'DeleteSubscriptions' return type */
74
+ export type IDeleteSubscriptionsResult = void;
75
+ /** 'DeleteSubscriptions' query type */
76
+ export interface IDeleteSubscriptionsQuery {
77
+ params: IDeleteSubscriptionsParams;
78
+ result: IDeleteSubscriptionsResult;
79
+ }
80
+ /**
81
+ * Query generated from SQL:
82
+ * ```
83
+ * DELETE FROM pgmb.subscriptions
84
+ * WHERE id IN :ids!
85
+ * ```
86
+ */
87
+ export declare const deleteSubscriptions: PreparedQuery<IDeleteSubscriptionsParams, void>;
88
+ /** 'MarkSubscriptionsActive' parameters type */
89
+ export interface IMarkSubscriptionsActiveParams {
90
+ ids: stringArray;
91
+ }
92
+ /** 'MarkSubscriptionsActive' return type */
93
+ export type IMarkSubscriptionsActiveResult = void;
94
+ /** 'MarkSubscriptionsActive' query type */
95
+ export interface IMarkSubscriptionsActiveQuery {
96
+ params: IMarkSubscriptionsActiveParams;
97
+ result: IMarkSubscriptionsActiveResult;
98
+ }
99
+ /**
100
+ * Query generated from SQL:
101
+ * ```
102
+ * UPDATE pgmb.subscriptions
103
+ * SET
104
+ * last_active_at = NOW()
105
+ * WHERE id IN (SELECT * FROM unnest(:ids!::pgmb.subscription_id[]))
106
+ * ```
107
+ */
108
+ export declare const markSubscriptionsActive: PreparedQuery<IMarkSubscriptionsActiveParams, void>;
109
+ /** 'PollForEvents' parameters type */
110
+ export type IPollForEventsParams = void;
111
+ /** 'PollForEvents' return type */
112
+ export interface IPollForEventsResult {
113
+ count: number;
114
+ }
115
+ /** 'PollForEvents' query type */
116
+ export interface IPollForEventsQuery {
117
+ params: IPollForEventsParams;
118
+ result: IPollForEventsResult;
119
+ }
120
+ /**
121
+ * Query generated from SQL:
122
+ * ```
123
+ * SELECT count AS "count!" FROM pgmb.poll_for_events() AS count
124
+ * ```
125
+ */
126
+ export declare const pollForEvents: PreparedQuery<void, IPollForEventsResult>;
127
+ /** 'ReadNextEvents' parameters type */
128
+ export interface IReadNextEventsParams {
129
+ chunkSize: number;
130
+ cursor?: string | null | void;
131
+ groupId: string;
132
+ }
133
+ /** 'ReadNextEvents' return type */
134
+ export interface IReadNextEventsResult {
135
+ id: string;
136
+ metadata: unknown;
137
+ nextCursor: string;
138
+ payload: unknown;
139
+ subscriptionIds: stringArray;
140
+ topic: string;
141
+ }
142
+ /** 'ReadNextEvents' query type */
143
+ export interface IReadNextEventsQuery {
144
+ params: IReadNextEventsParams;
145
+ result: IReadNextEventsResult;
146
+ }
147
+ /**
148
+ * Query generated from SQL:
149
+ * ```
150
+ * SELECT
151
+ * id AS "id!",
152
+ * topic AS "topic!",
153
+ * payload AS "payload!",
154
+ * metadata AS "metadata!",
155
+ * subscription_ids::text[] AS "subscriptionIds!",
156
+ * next_cursor AS "nextCursor!"
157
+ * FROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)
158
+ * ```
159
+ */
160
+ export declare const readNextEvents: PreparedQuery<IReadNextEventsParams, IReadNextEventsResult>;
161
+ /** 'ReadNextEventsText' parameters type */
162
+ export interface IReadNextEventsTextParams {
163
+ chunkSize: number;
164
+ cursor?: string | null | void;
165
+ groupId: string;
166
+ }
167
+ /** 'ReadNextEventsText' return type */
168
+ export interface IReadNextEventsTextResult {
169
+ id: string;
170
+ payload: string;
171
+ topic: string;
172
+ }
173
+ /** 'ReadNextEventsText' query type */
174
+ export interface IReadNextEventsTextQuery {
175
+ params: IReadNextEventsTextParams;
176
+ result: IReadNextEventsTextResult;
177
+ }
178
+ /**
179
+ * Query generated from SQL:
180
+ * ```
181
+ * SELECT
182
+ * id AS "id!",
183
+ * topic AS "topic!",
184
+ * payload::text AS "payload!"
185
+ * FROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)
186
+ * ```
187
+ */
188
+ export declare const readNextEventsText: PreparedQuery<IReadNextEventsTextParams, IReadNextEventsTextResult>;
189
+ /** 'ReplayEvents' parameters type */
190
+ export interface IReplayEventsParams {
191
+ fromEventId: string;
192
+ groupId: string;
193
+ maxEvents: number;
194
+ subscriptionId: string;
195
+ }
196
+ /** 'ReplayEvents' return type */
197
+ export interface IReplayEventsResult {
198
+ id: string;
199
+ metadata: unknown;
200
+ payload: unknown;
201
+ topic: string;
202
+ }
203
+ /** 'ReplayEvents' query type */
204
+ export interface IReplayEventsQuery {
205
+ params: IReplayEventsParams;
206
+ result: IReplayEventsResult;
207
+ }
208
+ /**
209
+ * Query generated from SQL:
210
+ * ```
211
+ * SELECT
212
+ * id AS "id!",
213
+ * topic AS "topic!",
214
+ * payload AS "payload!",
215
+ * metadata AS "metadata!"
216
+ * FROM pgmb.replay_events(
217
+ * :groupId!,
218
+ * :subscriptionId!,
219
+ * :fromEventId!::pgmb.event_id,
220
+ * :maxEvents!
221
+ * )
222
+ * ```
223
+ */
224
+ export declare const replayEvents: PreparedQuery<IReplayEventsParams, IReplayEventsResult>;
225
+ /** 'SetGroupCursor' parameters type */
226
+ export interface ISetGroupCursorParams {
227
+ cursor: string;
228
+ groupId: string;
229
+ releaseLock?: boolean | null | void;
230
+ }
231
+ /** 'SetGroupCursor' return type */
232
+ export interface ISetGroupCursorResult {
233
+ success: undefined;
234
+ }
235
+ /** 'SetGroupCursor' query type */
236
+ export interface ISetGroupCursorQuery {
237
+ params: ISetGroupCursorParams;
238
+ result: ISetGroupCursorResult;
239
+ }
240
+ /**
241
+ * Query generated from SQL:
242
+ * ```
243
+ * SELECT pgmb.set_group_cursor(
244
+ * :groupId!,
245
+ * :cursor!::pgmb.event_id,
246
+ * :releaseLock::boolean
247
+ * ) AS "success!"
248
+ * ```
249
+ */
250
+ export declare const setGroupCursor: PreparedQuery<ISetGroupCursorParams, ISetGroupCursorResult>;
251
+ /** 'ReleaseGroupLock' parameters type */
252
+ export interface IReleaseGroupLockParams {
253
+ groupId: string;
254
+ }
255
+ /** 'ReleaseGroupLock' return type */
256
+ export interface IReleaseGroupLockResult {
257
+ success: undefined;
258
+ }
259
+ /** 'ReleaseGroupLock' query type */
260
+ export interface IReleaseGroupLockQuery {
261
+ params: IReleaseGroupLockParams;
262
+ result: IReleaseGroupLockResult;
263
+ }
264
+ /**
265
+ * Query generated from SQL:
266
+ * ```
267
+ * SELECT pgmb.release_group_lock(:groupId!) AS "success!"
268
+ * ```
269
+ */
270
+ export declare const releaseGroupLock: PreparedQuery<IReleaseGroupLockParams, IReleaseGroupLockResult>;
271
+ /** 'WriteEvents' parameters type */
272
+ export interface IWriteEventsParams {
273
+ metadatas: unknownArray;
274
+ payloads: unknownArray;
275
+ topics: stringArray;
276
+ }
277
+ /** 'WriteEvents' return type */
278
+ export interface IWriteEventsResult {
279
+ id: string;
280
+ }
281
+ /** 'WriteEvents' query type */
282
+ export interface IWriteEventsQuery {
283
+ params: IWriteEventsParams;
284
+ result: IWriteEventsResult;
285
+ }
286
+ /**
287
+ * Query generated from SQL:
288
+ * ```
289
+ * INSERT INTO pgmb.events (topic, payload, metadata)
290
+ * SELECT
291
+ * topic,
292
+ * payload,
293
+ * metadata
294
+ * FROM unnest(
295
+ * :topics!::TEXT[],
296
+ * :payloads!::JSONB[],
297
+ * :metadatas!::JSONB[]
298
+ * ) AS t(topic, payload, metadata)
299
+ * RETURNING id AS "id!"
300
+ * ```
301
+ */
302
+ export declare const writeEvents: PreparedQuery<IWriteEventsParams, IWriteEventsResult>;
303
+ /** 'WriteScheduledEvents' parameters type */
304
+ export interface IWriteScheduledEventsParams {
305
+ metadatas: unknownArray;
306
+ payloads: unknownArray;
307
+ topics: stringArray;
308
+ ts: DateOrStringArray;
309
+ }
310
+ /** 'WriteScheduledEvents' return type */
311
+ export interface IWriteScheduledEventsResult {
312
+ id: string;
313
+ }
314
+ /** 'WriteScheduledEvents' query type */
315
+ export interface IWriteScheduledEventsQuery {
316
+ params: IWriteScheduledEventsParams;
317
+ result: IWriteScheduledEventsResult;
318
+ }
319
+ /**
320
+ * Query generated from SQL:
321
+ * ```
322
+ * INSERT INTO pgmb.events (id, topic, payload, metadata)
323
+ * SELECT
324
+ * pgmb.create_event_id(COALESCE(ts, clock_timestamp()), pgmb.create_random_bigint()),
325
+ * topic,
326
+ * payload,
327
+ * metadata
328
+ * FROM unnest(
329
+ * :ts!::TIMESTAMPTZ[],
330
+ * :topics!::TEXT[],
331
+ * :payloads!::JSONB[],
332
+ * :metadatas!::JSONB[]
333
+ * ) AS t(ts, topic, payload, metadata)
334
+ * RETURNING id AS "id!"
335
+ * ```
336
+ */
337
+ export declare const writeScheduledEvents: PreparedQuery<IWriteScheduledEventsParams, IWriteScheduledEventsResult>;
338
+ /** 'ScheduleEventRetry' parameters type */
339
+ export interface IScheduleEventRetryParams {
340
+ delayInterval: DateOrString;
341
+ handlerName: string;
342
+ ids: stringArray;
343
+ retryNumber: number;
344
+ subscriptionId: string;
345
+ }
346
+ /** 'ScheduleEventRetry' return type */
347
+ export interface IScheduleEventRetryResult {
348
+ id: string;
349
+ }
350
+ /** 'ScheduleEventRetry' query type */
351
+ export interface IScheduleEventRetryQuery {
352
+ params: IScheduleEventRetryParams;
353
+ result: IScheduleEventRetryResult;
354
+ }
355
+ /**
356
+ * Query generated from SQL:
357
+ * ```
358
+ * INSERT INTO pgmb.events (id, topic, payload, subscription_id)
359
+ * SELECT
360
+ * pgmb.create_event_id(
361
+ * NOW() + (:delayInterval!::INTERVAL),
362
+ * pgmb.create_random_bigint()
363
+ * ),
364
+ * 'pgmb-retry',
365
+ * jsonb_build_object(
366
+ * 'ids',
367
+ * :ids!::pgmb.event_id[],
368
+ * 'retryNumber',
369
+ * :retryNumber!::int,
370
+ * 'handlerName',
371
+ * :handlerName!::text
372
+ * ),
373
+ * :subscriptionId!::pgmb.subscription_id
374
+ * RETURNING id AS "id!"
375
+ * ```
376
+ */
377
+ export declare const scheduleEventRetry: PreparedQuery<IScheduleEventRetryParams, IScheduleEventRetryResult>;
378
+ /** 'FindEvents' parameters type */
379
+ export interface IFindEventsParams {
380
+ ids: stringArray;
381
+ }
382
+ /** 'FindEvents' return type */
383
+ export interface IFindEventsResult {
384
+ id: string;
385
+ metadata: unknown;
386
+ payload: unknown;
387
+ topic: string;
388
+ }
389
+ /** 'FindEvents' query type */
390
+ export interface IFindEventsQuery {
391
+ params: IFindEventsParams;
392
+ result: IFindEventsResult;
393
+ }
394
+ /**
395
+ * Query generated from SQL:
396
+ * ```
397
+ * SELECT
398
+ * id AS "id!",
399
+ * topic AS "topic!",
400
+ * payload AS "payload!",
401
+ * metadata AS "metadata!"
402
+ * FROM pgmb.events
403
+ * WHERE id = ANY(:ids!::pgmb.event_id[])
404
+ * ```
405
+ */
406
+ export declare const findEvents: PreparedQuery<IFindEventsParams, IFindEventsResult>;
407
+ /** 'RemoveExpiredSubscriptions' parameters type */
408
+ export interface IRemoveExpiredSubscriptionsParams {
409
+ activeIds: stringArray;
410
+ groupId: string;
411
+ }
412
+ /** 'RemoveExpiredSubscriptions' return type */
413
+ export interface IRemoveExpiredSubscriptionsResult {
414
+ deleted: string;
415
+ }
416
+ /** 'RemoveExpiredSubscriptions' query type */
417
+ export interface IRemoveExpiredSubscriptionsQuery {
418
+ params: IRemoveExpiredSubscriptionsParams;
419
+ result: IRemoveExpiredSubscriptionsResult;
420
+ }
421
+ /**
422
+ * Query generated from SQL:
423
+ * ```
424
+ * WITH deleted AS (
425
+ * DELETE FROM pgmb.subscriptions
426
+ * WHERE group_id = :groupId!
427
+ * AND expiry_interval IS NOT NULL
428
+ * AND pgmb.add_interval_imm(last_active_at, expiry_interval) < NOW()
429
+ * AND id NOT IN (select * from unnest(:activeIds!::pgmb.subscription_id[]))
430
+ * RETURNING id
431
+ * )
432
+ * SELECT COUNT(*) AS "deleted!" FROM deleted
433
+ * ```
434
+ */
435
+ export declare const removeExpiredSubscriptions: PreparedQuery<IRemoveExpiredSubscriptionsParams, IRemoveExpiredSubscriptionsResult>;
436
+ /** 'MaintainEventsTable' parameters type */
437
+ export type IMaintainEventsTableParams = void;
438
+ /** 'MaintainEventsTable' return type */
439
+ export interface IMaintainEventsTableResult {
440
+ maintainEventsTable: undefined | null;
441
+ }
442
+ /** 'MaintainEventsTable' query type */
443
+ export interface IMaintainEventsTableQuery {
444
+ params: IMaintainEventsTableParams;
445
+ result: IMaintainEventsTableResult;
446
+ }
447
+ /**
448
+ * Query generated from SQL:
449
+ * ```
450
+ * SELECT pgmb.maintain_events_table()
451
+ * ```
452
+ */
453
+ export declare const maintainEventsTable: PreparedQuery<void, IMaintainEventsTableResult>;
package/lib/queries.js ADDED
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maintainEventsTable = exports.removeExpiredSubscriptions = exports.findEvents = exports.scheduleEventRetry = exports.writeScheduledEvents = exports.writeEvents = exports.releaseGroupLock = exports.setGroupCursor = exports.replayEvents = exports.readNextEventsText = exports.readNextEvents = exports.pollForEvents = exports.markSubscriptionsActive = exports.deleteSubscriptions = exports.assertSubscription = exports.assertGroup = void 0;
4
+ /** Types generated for queries found in "sql/queries.sql" */
5
+ const runtime_1 = require("@pgtyped/runtime");
6
+ const assertGroupIR = { "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" };
7
+ /**
8
+ * Query generated from SQL:
9
+ * ```
10
+ * INSERT INTO pgmb.subscription_groups (id)
11
+ * VALUES (:id!)
12
+ * ON CONFLICT DO NOTHING
13
+ * ```
14
+ */
15
+ exports.assertGroup = new runtime_1.PreparedQuery(assertGroupIR);
16
+ const assertSubscriptionIR = { "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!\"" };
17
+ /**
18
+ * Query generated from SQL:
19
+ * ```
20
+ * INSERT INTO pgmb.subscriptions
21
+ * AS s(group_id, conditions_sql, params, expiry_interval)
22
+ * VALUES (
23
+ * :groupId!,
24
+ * COALESCE(:conditionsSql, 'TRUE'),
25
+ * COALESCE(:params::jsonb, '{}'),
26
+ * :expiryInterval::interval
27
+ * )
28
+ * ON CONFLICT (identity) DO UPDATE
29
+ * SET
30
+ * -- set expiry_interval to the new value only if it's greater than the existing one
31
+ * -- or if the new value is NULL (indicating no expiration)
32
+ * expiry_interval = CASE
33
+ * WHEN EXCLUDED.expiry_interval IS NULL OR s.expiry_interval IS NULL
34
+ * THEN NULL
35
+ * ELSE
36
+ * GREATEST(s.expiry_interval, EXCLUDED.expiry_interval)
37
+ * END,
38
+ * last_active_at = NOW()
39
+ * RETURNING id AS "id!"
40
+ * ```
41
+ */
42
+ exports.assertSubscription = new runtime_1.PreparedQuery(assertSubscriptionIR);
43
+ const deleteSubscriptionsIR = { "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!" };
44
+ /**
45
+ * Query generated from SQL:
46
+ * ```
47
+ * DELETE FROM pgmb.subscriptions
48
+ * WHERE id IN :ids!
49
+ * ```
50
+ */
51
+ exports.deleteSubscriptions = new runtime_1.PreparedQuery(deleteSubscriptionsIR);
52
+ const markSubscriptionsActiveIR = { "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[]))" };
53
+ /**
54
+ * Query generated from SQL:
55
+ * ```
56
+ * UPDATE pgmb.subscriptions
57
+ * SET
58
+ * last_active_at = NOW()
59
+ * WHERE id IN (SELECT * FROM unnest(:ids!::pgmb.subscription_id[]))
60
+ * ```
61
+ */
62
+ exports.markSubscriptionsActive = new runtime_1.PreparedQuery(markSubscriptionsActiveIR);
63
+ const pollForEventsIR = { "usedParamSet": {}, "params": [], "statement": "SELECT count AS \"count!\" FROM pgmb.poll_for_events() AS count" };
64
+ /**
65
+ * Query generated from SQL:
66
+ * ```
67
+ * SELECT count AS "count!" FROM pgmb.poll_for_events() AS count
68
+ * ```
69
+ */
70
+ exports.pollForEvents = new runtime_1.PreparedQuery(pollForEventsIR);
71
+ const readNextEventsIR = { "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!)" };
72
+ /**
73
+ * Query generated from SQL:
74
+ * ```
75
+ * SELECT
76
+ * id AS "id!",
77
+ * topic AS "topic!",
78
+ * payload AS "payload!",
79
+ * metadata AS "metadata!",
80
+ * subscription_ids::text[] AS "subscriptionIds!",
81
+ * next_cursor AS "nextCursor!"
82
+ * FROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)
83
+ * ```
84
+ */
85
+ exports.readNextEvents = new runtime_1.PreparedQuery(readNextEventsIR);
86
+ const readNextEventsTextIR = { "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!)" };
87
+ /**
88
+ * Query generated from SQL:
89
+ * ```
90
+ * SELECT
91
+ * id AS "id!",
92
+ * topic AS "topic!",
93
+ * payload::text AS "payload!"
94
+ * FROM pgmb.read_next_events(:groupId!, :cursor, :chunkSize!)
95
+ * ```
96
+ */
97
+ exports.readNextEventsText = new runtime_1.PreparedQuery(readNextEventsTextIR);
98
+ const replayEventsIR = { "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)" };
99
+ /**
100
+ * Query generated from SQL:
101
+ * ```
102
+ * SELECT
103
+ * id AS "id!",
104
+ * topic AS "topic!",
105
+ * payload AS "payload!",
106
+ * metadata AS "metadata!"
107
+ * FROM pgmb.replay_events(
108
+ * :groupId!,
109
+ * :subscriptionId!,
110
+ * :fromEventId!::pgmb.event_id,
111
+ * :maxEvents!
112
+ * )
113
+ * ```
114
+ */
115
+ exports.replayEvents = new runtime_1.PreparedQuery(replayEventsIR);
116
+ const setGroupCursorIR = { "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!\"" };
117
+ /**
118
+ * Query generated from SQL:
119
+ * ```
120
+ * SELECT pgmb.set_group_cursor(
121
+ * :groupId!,
122
+ * :cursor!::pgmb.event_id,
123
+ * :releaseLock::boolean
124
+ * ) AS "success!"
125
+ * ```
126
+ */
127
+ exports.setGroupCursor = new runtime_1.PreparedQuery(setGroupCursorIR);
128
+ const releaseGroupLockIR = { "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!\"" };
129
+ /**
130
+ * Query generated from SQL:
131
+ * ```
132
+ * SELECT pgmb.release_group_lock(:groupId!) AS "success!"
133
+ * ```
134
+ */
135
+ exports.releaseGroupLock = new runtime_1.PreparedQuery(releaseGroupLockIR);
136
+ const writeEventsIR = { "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!\"" };
137
+ /**
138
+ * Query generated from SQL:
139
+ * ```
140
+ * INSERT INTO pgmb.events (topic, payload, metadata)
141
+ * SELECT
142
+ * topic,
143
+ * payload,
144
+ * metadata
145
+ * FROM unnest(
146
+ * :topics!::TEXT[],
147
+ * :payloads!::JSONB[],
148
+ * :metadatas!::JSONB[]
149
+ * ) AS t(topic, payload, metadata)
150
+ * RETURNING id AS "id!"
151
+ * ```
152
+ */
153
+ exports.writeEvents = new runtime_1.PreparedQuery(writeEventsIR);
154
+ const writeScheduledEventsIR = { "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!\"" };
155
+ /**
156
+ * Query generated from SQL:
157
+ * ```
158
+ * INSERT INTO pgmb.events (id, topic, payload, metadata)
159
+ * SELECT
160
+ * pgmb.create_event_id(COALESCE(ts, clock_timestamp()), pgmb.create_random_bigint()),
161
+ * topic,
162
+ * payload,
163
+ * metadata
164
+ * FROM unnest(
165
+ * :ts!::TIMESTAMPTZ[],
166
+ * :topics!::TEXT[],
167
+ * :payloads!::JSONB[],
168
+ * :metadatas!::JSONB[]
169
+ * ) AS t(ts, topic, payload, metadata)
170
+ * RETURNING id AS "id!"
171
+ * ```
172
+ */
173
+ exports.writeScheduledEvents = new runtime_1.PreparedQuery(writeScheduledEventsIR);
174
+ const scheduleEventRetryIR = { "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!\"" };
175
+ /**
176
+ * Query generated from SQL:
177
+ * ```
178
+ * INSERT INTO pgmb.events (id, topic, payload, subscription_id)
179
+ * SELECT
180
+ * pgmb.create_event_id(
181
+ * NOW() + (:delayInterval!::INTERVAL),
182
+ * pgmb.create_random_bigint()
183
+ * ),
184
+ * 'pgmb-retry',
185
+ * jsonb_build_object(
186
+ * 'ids',
187
+ * :ids!::pgmb.event_id[],
188
+ * 'retryNumber',
189
+ * :retryNumber!::int,
190
+ * 'handlerName',
191
+ * :handlerName!::text
192
+ * ),
193
+ * :subscriptionId!::pgmb.subscription_id
194
+ * RETURNING id AS "id!"
195
+ * ```
196
+ */
197
+ exports.scheduleEventRetry = new runtime_1.PreparedQuery(scheduleEventRetryIR);
198
+ const findEventsIR = { "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[])" };
199
+ /**
200
+ * Query generated from SQL:
201
+ * ```
202
+ * SELECT
203
+ * id AS "id!",
204
+ * topic AS "topic!",
205
+ * payload AS "payload!",
206
+ * metadata AS "metadata!"
207
+ * FROM pgmb.events
208
+ * WHERE id = ANY(:ids!::pgmb.event_id[])
209
+ * ```
210
+ */
211
+ exports.findEvents = new runtime_1.PreparedQuery(findEventsIR);
212
+ const removeExpiredSubscriptionsIR = { "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" };
213
+ /**
214
+ * Query generated from SQL:
215
+ * ```
216
+ * WITH deleted AS (
217
+ * DELETE FROM pgmb.subscriptions
218
+ * WHERE group_id = :groupId!
219
+ * AND expiry_interval IS NOT NULL
220
+ * AND pgmb.add_interval_imm(last_active_at, expiry_interval) < NOW()
221
+ * AND id NOT IN (select * from unnest(:activeIds!::pgmb.subscription_id[]))
222
+ * RETURNING id
223
+ * )
224
+ * SELECT COUNT(*) AS "deleted!" FROM deleted
225
+ * ```
226
+ */
227
+ exports.removeExpiredSubscriptions = new runtime_1.PreparedQuery(removeExpiredSubscriptionsIR);
228
+ const maintainEventsTableIR = { "usedParamSet": {}, "params": [], "statement": "SELECT pgmb.maintain_events_table()" };
229
+ /**
230
+ * Query generated from SQL:
231
+ * ```
232
+ * SELECT pgmb.maintain_events_table()
233
+ * ```
234
+ */
235
+ exports.maintainEventsTable = new runtime_1.PreparedQuery(maintainEventsTableIR);