lonnymq 0.0.28 → 0.0.29

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/index.cjs CHANGED
@@ -1,91 +1,89 @@
1
- var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=Object.prototype.hasOwnProperty;var M=new WeakMap,V=(e)=>{var t=M.get(e),a;if(t)return t;if(t=h({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")k(e).map((r)=>!Q.call(t,r)&&h(t,r,{get:()=>e[r],enumerable:!(a=P(e,r))||a.enumerable}));return M.set(e,t),t};var W=(e,t)=>{for(var a in t)h(e,a,{get:t[a],enumerable:!0,configurable:!0,set:(r)=>t[a]=()=>r})};var le={};W(le,{queueEventDecode:()=>v,Queue:()=>y,MessageHeartbeatCommand:()=>d,MessageDequeueCommand:()=>m,MessageDeleteCommand:()=>u,MessageDeferCommand:()=>i,MessageCreateCommand:()=>l,ChannelPolicySetCommand:()=>c,ChannelPolicyClearCommand:()=>o});module.exports=V(le);var I=(e)=>{return e*1000};var T=I(0);var v=(e)=>{let t=JSON.parse(e);if(t.type===0)return{eventType:"MESSAGE_CREATED",id:t.id,delayMs:t.delay_ms};else if(t.type===1)return{eventType:"MESSAGE_DELETED",id:t.id};else if(t.type===2)return{eventType:"MESSAGE_DEFERRED",id:t.id,delayMs:t.delay_ms};else throw new Error("Unknown event type")};var E=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),Y=(e)=>({nodeType:"RAW",value:e}),z=(e)=>{return`'${e.replace(/'/g,"''")}'`},X=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return z(e);else if(typeof e==="number")return e.toString();else if(typeof e==="boolean")return e?"TRUE":"FALSE";else if(e instanceof Date)return`'${e.toISOString()}'`;else if(typeof e==="bigint")return e.toString();else throw new Error(`Unsupported value type: ${typeof e}`)},J=(e)=>{return`"${e.replace(/"/g,'""')}"`},j=(e)=>{if(e.nodeType==="VALUE")return X(e.value);else if(e.nodeType==="REF")return J(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var n=(e,...t)=>{let a=[];for(let r=0;r<e.length;r+=1)if(a.push(e[r]),r<t.length)a.push(j(t[r]));return Y(a.join(""))};class o{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}async execute(e){await e.query(n`
2
- SELECT 1 FROM ${s(this.schema)}."channel_policy_clear"(
1
+ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=Object.prototype.hasOwnProperty;var M=new WeakMap,V=(e)=>{var t=M.get(e),a;if(t)return t;if(t=h({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")k(e).map((E)=>!Q.call(t,E)&&h(t,E,{get:()=>e[E],enumerable:!(a=P(e,E))||a.enumerable}));return M.set(e,t),t};var W=(e,t)=>{for(var a in t)h(e,a,{get:t[a],enumerable:!0,configurable:!0,set:(E)=>t[a]=()=>E})};var le={};W(le,{Queue:()=>y,MessageHeartbeatCommand:()=>d,MessageDequeueCommand:()=>m,MessageDeleteCommand:()=>u,MessageDeferCommand:()=>i,MessageCreateCommand:()=>l,ChannelPolicySetCommand:()=>o,ChannelPolicyClearCommand:()=>c});module.exports=V(le);var r=(e)=>({nodeType:"VALUE",value:e}),n=(e)=>({nodeType:"REF",value:e}),Y=(e)=>({nodeType:"RAW",value:e}),z=(e)=>{return`'${e.replace(/'/g,"''")}'`},X=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return z(e);else if(typeof e==="number")return e.toString();else if(typeof e==="boolean")return e?"TRUE":"FALSE";else if(e instanceof Date)return`'${e.toISOString()}'`;else if(typeof e==="bigint")return e.toString();else throw new Error(`Unsupported value type: ${typeof e}`)},J=(e)=>{return`"${e.replace(/"/g,'""')}"`},j=(e)=>{if(e.nodeType==="VALUE")return X(e.value);else if(e.nodeType==="REF")return J(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var s=(e,...t)=>{let a=[];for(let E=0;E<e.length;E+=1)if(a.push(e[E]),E<t.length)a.push(j(t[E]));return Y(a.join(""))};class c{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}async execute(e){await e.query(s`
2
+ SELECT 1 FROM ${n(this.schema)}."channel_policy_clear"(
3
3
  $1
4
4
  )
5
- `.value,[this.channelName])}}class c{schema;channelName;maxConcurrency;releaseIntervalMs;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName;let t=e.maxConcurrency??null;this.maxConcurrency=t!==null?Math.max(0,t):null;let a=e.releaseIntervalMs??null;this.releaseIntervalMs=a!==null?Math.max(0,a):null,this.createdAt=new Date}async execute(e){await e.query(n`
6
- SELECT 1 FROM ${s(this.schema)}."channel_policy_set"(
5
+ `.value,[this.channelName])}}class o{schema;channelName;maxConcurrency;releaseIntervalMs;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName;let t=e.maxConcurrency??null;this.maxConcurrency=t!==null?Math.max(0,t):null;let a=e.releaseIntervalMs??null;this.releaseIntervalMs=a!==null?Math.max(0,a):null,this.createdAt=new Date}async execute(e){await e.query(s`
6
+ SELECT 1 FROM ${n(this.schema)}."channel_policy_set"(
7
7
  $1,
8
8
  $2::INTEGER,
9
9
  $3::INTEGER
10
10
  )
11
- `.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var L=require("crypto"),C=()=>{return L.randomBytes(16).toString("base64url")};class l{schema;channelName;content;delayMs;createdAt;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.schema=e.schema,this.channelName=e.channelName??C(),this.content=e.content,this.delayMs=t,this.createdAt=new Date}async execute(e){let t=await e.query(n`
11
+ `.value,[this.channelName,this.maxConcurrency,this.releaseIntervalMs])}}var I=(e)=>{return e*1000};var T=I(0);var v=require("crypto"),L=()=>{return v.randomBytes(16).toString("base64url")};class l{schema;channelName;content;delayMs;createdAt;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.schema=e.schema,this.channelName=e.channelName??L(),this.content=e.content,this.delayMs=t,this.createdAt=new Date}async execute(e){let t=await e.query(s`
12
12
  SELECT
13
13
  result_code,
14
14
  metadata
15
- FROM ${s(this.schema)}."message_create"(
15
+ FROM ${n(this.schema)}."message_create"(
16
16
  $1,
17
17
  $2,
18
18
  $3::BIGINT
19
19
  )
20
- `.value,[this.channelName,this.content,this.delayMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_CREATED",id:t.metadata.id,channelSize:t.metadata.channel_size};else throw new Error("Unexpected result code")}}class m{schema;lockMs;constructor(e){this.schema=e.schema,this.lockMs=e.lockMs}async execute(e){let t=await e.query(n`
20
+ `.value,[this.channelName,this.content,this.delayMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_CREATED",id:BigInt(t.metadata.id),channelSize:t.metadata.channel_size};else throw new Error("Unexpected result code")}}class m{schema;lockMs;constructor(e){this.schema=e.schema,this.lockMs=e.lockMs}async execute(e){let t=await e.query(s`
21
21
  SELECT
22
22
  result_code,
23
23
  metadata,
24
24
  content,
25
25
  state
26
- FROM ${s(this.schema)}."message_dequeue"($1::BIGINT)
27
- `.value,[this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE"};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",id:t.metadata.id,channelName:t.metadata.channel_name,isUnlocked:t.metadata.is_unlocked,content:t.content,state:t.state,numAttempts:t.metadata.num_attempts};else throw new Error("Unexpected dequeue result")}}class u{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.numAttempts=e.numAttempts}async execute(e){let t=await e.query(n`
28
- SELECT * FROM ${s(this.schema)}."message_delete"(
29
- $1,
26
+ FROM ${n(this.schema)}."message_dequeue"($1::BIGINT)
27
+ `.value,[this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_AVAILABLE"};else if(t.result_code===1)return{resultType:"MESSAGE_DEQUEUED",id:BigInt(t.metadata.id),channelName:t.metadata.channel_name,isUnlocked:t.metadata.is_unlocked,content:t.content,state:t.state,numAttempts:t.metadata.num_attempts};else throw new Error("Unexpected dequeue result")}}class u{schema;id;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.numAttempts=e.numAttempts}async execute(e){let t=await e.query(s`
28
+ SELECT * FROM ${n(this.schema)}."message_delete"(
29
+ $1::BIGINT,
30
30
  $2::BIGINT
31
31
  )
32
- `.value,[this.id,this.numAttempts]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}class i{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.delayMs=t,this.state=e.state??null}async execute(e){let t=await e.query(n`
33
- SELECT * FROM ${s(this.schema)}."message_defer"(
34
- $1,
32
+ `.value,[this.id.toString(),this.numAttempts]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DELETED"};else throw new Error("Unexpected result")}}class i{schema;id;numAttempts;delayMs;state;constructor(e){let t=e.delayMs===void 0?T:e.delayMs;this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.delayMs=t,this.state=e.state??null}async execute(e){let t=await e.query(s`
33
+ SELECT * FROM ${n(this.schema)}."message_defer"(
34
+ $1::BIGINT,
35
35
  $2::BIGINT,
36
36
  $3::BIGINT,
37
37
  $4
38
38
  )
39
- `.value,[this.id,this.numAttempts,this.delayMs,this.state]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DEFERRED"};else throw new Error("Unexpected result")}}class d{schema;id;numAttempts;lockMs;constructor(e){this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.lockMs=e.lockMs}async execute(e){let t=await e.query(n`
40
- SELECT * FROM ${s(this.schema)}."message_heartbeat"(
41
- $1,
39
+ `.value,[this.id.toString(),this.numAttempts,this.delayMs,this.state]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_DEFERRED"};else throw new Error("Unexpected result")}}class d{schema;id;numAttempts;lockMs;constructor(e){this.schema=e.schema,this.numAttempts=e.numAttempts,this.id=e.id,this.lockMs=e.lockMs}async execute(e){let t=await e.query(s`
40
+ SELECT * FROM ${n(this.schema)}."message_heartbeat"(
41
+ $1::BIGINT,
42
42
  $2::BIGINT,
43
43
  $3::BIGINT
44
44
  )
45
- `.value,[this.id,this.numAttempts,this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var U=(e)=>{let t=e.split(`
46
- `),a=Number.MAX_SAFE_INTEGER;for(let r of t){if(r.trim().length===0)continue;let H=r.search(/\S/);a=Math.min(a,H)}return t.map((r)=>r.slice(a)).join(`
47
- `).trim()};var S=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",ne=S.dirname(S.dirname(__filename)),ae=new RegExp(`^${ne}/`),_=(e)=>{return e.replace(ae,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/00-table-channel-policy.ts",O={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_policy_name_ux"].join("_");return[n`
48
- CREATE TABLE ${s(e.schema)}."channel_policy" (
49
- "id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
45
+ `.value,[this.id.toString(),this.numAttempts,this.lockMs]).then((a)=>a.rows[0]);if(t.result_code===0)return{resultType:"MESSAGE_NOT_FOUND"};else if(t.result_code===1)return{resultType:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var C=(e)=>{let t=e.split(`
46
+ `),a=Number.MAX_SAFE_INTEGER;for(let E of t){if(E.trim().length===0)continue;let H=E.search(/\S/);a=Math.min(a,H)}return t.map((E)=>E.slice(a)).join(`
47
+ `).trim()};var N=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",se=N.dirname(N.dirname(__filename)),ae=new RegExp(`^${se}/`),_=(e)=>{return e.replace(ae,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/00-table-channel-policy.ts",O={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_policy_name_ux"].join("_");return[s`
48
+ CREATE TABLE ${n(e.schema)}."channel_policy" (
49
+ "id" BIGSERIAL,
50
50
  "name" TEXT NOT NULL,
51
51
  "max_concurrency" INTEGER,
52
52
  "release_interval_ms" INTEGER,
53
53
  "created_at" TIMESTAMP NOT NULL,
54
54
  PRIMARY KEY ("id")
55
55
  );
56
- `,n`
57
- CREATE UNIQUE INDEX ${s(t)}
58
- ON ${s(e.schema)}."channel_policy" ("name");
59
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",f={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_state_name_ux"].join("_"),a=[e.schema,"channel_state_dequeue_ix"].join("_");return[n`
60
- CREATE TABLE ${s(e.schema)}."channel_state" (
61
- "id" UUID NOT NULL DEFAULT GEN_RANDOM_UUID(),
56
+ `,s`
57
+ CREATE UNIQUE INDEX ${n(t)}
58
+ ON ${n(e.schema)}."channel_policy" ("name");
59
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/01-table-channel-state.ts",U={name:_(__filename),sql:(e)=>{let t=[e.schema,"channel_state_name_ux"].join("_"),a=[e.schema,"channel_state_dequeue_ix"].join("_");return[s`
60
+ CREATE TABLE ${n(e.schema)}."channel_state" (
61
+ "id" BIGSERIAL,
62
62
  "name" TEXT NOT NULL,
63
63
  "max_concurrency" INTEGER,
64
64
  "release_interval_ms" INTEGER,
65
65
  "current_size" INTEGER NOT NULL,
66
66
  "current_concurrency" INTEGER NOT NULL,
67
- "message_id" UUID,
68
- "message_seq_no" BIGINT,
67
+ "message_id" BIGINT,
69
68
  "message_dequeue_at" TIMESTAMP,
70
69
  "dequeue_prev_at" TIMESTAMP NOT NULL,
71
70
  "dequeue_next_at" TIMESTAMP NULL,
72
71
  "created_at" TIMESTAMP NOT NULL,
73
72
  PRIMARY KEY ("id")
74
73
  );
75
- `,n`
76
- CREATE UNIQUE INDEX ${s(t)}
77
- ON ${s(e.schema)}."channel_state" ("name");
78
- `,n`
79
- CREATE INDEX ${s(a)}
80
- ON ${s(e.schema)}."channel_state" (
74
+ `,s`
75
+ CREATE UNIQUE INDEX ${n(t)}
76
+ ON ${n(e.schema)}."channel_state" ("name");
77
+ `,s`
78
+ CREATE INDEX ${n(a)}
79
+ ON ${n(e.schema)}."channel_state" (
81
80
  "dequeue_next_at" ASC
82
81
  ) WHERE "message_id" IS NOT NULL
83
82
  AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency");
84
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",q={name:_(__filename),sql:(e)=>{return[n`
85
- CREATE TABLE ${s(e.schema)}."message" (
86
- "id" UUID NOT NULL,
83
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/02-table-message.ts",f={name:_(__filename),sql:(e)=>{return[s`
84
+ CREATE TABLE ${n(e.schema)}."message" (
85
+ "id" BIGSERIAL NOT NULL,
87
86
  "channel_name" TEXT NOT NULL,
88
- "seq_no" BIGSERIAL NOT NULL,
89
87
  "content" BYTEA NOT NULL,
90
88
  "state" BYTEA,
91
89
  "is_locked" BOOLEAN NOT NULL,
@@ -95,20 +93,20 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
95
93
  "created_at" TIMESTAMP NOT NULL,
96
94
  PRIMARY KEY ("id")
97
95
  );
98
- `,n`
96
+ `,s`
99
97
  CREATE INDEX "message_dequeue_ix"
100
- ON ${s(e.schema)}."message" (
98
+ ON ${n(e.schema)}."message" (
101
99
  "channel_name",
102
100
  "dequeue_at" ASC,
103
- "seq_no" ASC
101
+ "id" ASC
104
102
  ) WHERE NOT "is_locked";
105
- `,n`
103
+ `,s`
106
104
  CREATE INDEX "message_locked_dequeue_ix"
107
- ON ${s(e.schema)}."message" (
105
+ ON ${n(e.schema)}."message" (
108
106
  "unlock_at" ASC
109
107
  ) WHERE "is_locked";
110
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",G={name:_(__filename),sql:(e)=>{return[n`
111
- CREATE FUNCTION ${s(e.schema)}."message_create" (
108
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/03-function-message-create.ts",G={name:_(__filename),sql:(e)=>{return[s`
109
+ CREATE FUNCTION ${n(e.schema)}."message_create" (
112
110
  p_channel_name TEXT,
113
111
  p_content BYTEA,
114
112
  p_delay_ms BIGINT
@@ -124,8 +122,7 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
124
122
  BEGIN
125
123
  v_now := NOW();
126
124
 
127
- INSERT INTO ${s(e.schema)}."message" (
128
- "id",
125
+ INSERT INTO ${n(e.schema)}."message" (
129
126
  "channel_name",
130
127
  "content",
131
128
  "is_locked",
@@ -133,7 +130,6 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
133
130
  "dequeue_at",
134
131
  "created_at"
135
132
  ) VALUES (
136
- GEN_RANDOM_UUID(),
137
133
  p_channel_name,
138
134
  p_content,
139
135
  FALSE,
@@ -142,19 +138,18 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
142
138
  v_now
143
139
  ) RETURNING
144
140
  "id",
145
- "seq_no",
146
141
  "dequeue_at"
147
142
  INTO v_message;
148
143
 
149
144
  SELECT
150
145
  "channel_policy"."max_concurrency",
151
146
  "channel_policy"."release_interval_ms"
152
- FROM ${s(e.schema)}."channel_policy"
147
+ FROM ${n(e.schema)}."channel_policy"
153
148
  WHERE "name" = p_channel_name
154
149
  FOR SHARE
155
150
  INTO v_channel_policy;
156
151
 
157
- INSERT INTO ${s(e.schema)}."channel_state" (
152
+ INSERT INTO ${n(e.schema)}."channel_state" (
158
153
  "name",
159
154
  "current_concurrency",
160
155
  "current_size",
@@ -180,51 +175,49 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
180
175
  "release_interval_ms",
181
176
  "dequeue_prev_at",
182
177
  "message_id",
183
- "message_dequeue_at",
184
- "message_seq_no"
178
+ "message_dequeue_at"
185
179
  INTO v_channel_state;
186
180
 
187
181
  IF
188
182
  v_channel_state."message_id" IS NULL OR
189
183
  v_message."dequeue_at" < v_channel_state."message_dequeue_at" OR
190
- v_message."dequeue_at" = v_channel_state."message_dequeue_at" AND v_message."seq_no" < v_channel_state."message_seq_no"
184
+ v_message."dequeue_at" = v_channel_state."message_dequeue_at" AND v_message."id" < v_channel_state."message_id"
191
185
  THEN
192
- UPDATE ${s(e.schema)}."channel_state" SET
186
+ UPDATE ${n(e.schema)}."channel_state" SET
193
187
  "current_size" = v_channel_state."current_size" + 1,
194
188
  "message_id" = v_message."id",
195
189
  "message_dequeue_at" = v_message."dequeue_at",
196
- "message_seq_no" = v_message."seq_no",
197
190
  "dequeue_next_at" = GREATEST(
198
191
  v_channel_state."dequeue_prev_at" + INTERVAL '1 MILLISECOND' * COALESCE(v_channel_state."release_interval_ms", 0),
199
192
  v_message."dequeue_at"
200
193
  )
201
194
  WHERE "id" = v_channel_state."id";
202
195
  ELSE
203
- UPDATE ${s(e.schema)}."channel_state" SET
196
+ UPDATE ${n(e.schema)}."channel_state" SET
204
197
  "current_size" = v_channel_state."current_size" + 1
205
198
  WHERE "id" = v_channel_state."id";
206
199
  END IF;
207
200
 
208
- IF ${E(e.eventChannel!==null)} THEN
201
+ IF ${r(e.eventChannel!==null)} THEN
209
202
  PERFORM PG_NOTIFY(
210
- ${E(e.eventChannel)},
203
+ ${r(e.eventChannel)},
211
204
  JSON_BUILD_OBJECT(
212
- 'type', ${E(0)},
213
- 'id', v_message."id",
205
+ 'type', ${r(0)},
206
+ 'id', v_message."id"::TEXT,
214
207
  'delay_ms', p_delay_ms
215
208
  )::TEXT
216
209
  );
217
210
  END IF;
218
211
 
219
212
  RETURN QUERY SELECT
220
- ${E(0)},
213
+ ${r(0)},
221
214
  JSON_BUILD_OBJECT(
222
- 'id', v_message."id",
215
+ 'id', v_message."id"::TEXT,
223
216
  'channel_size', v_channel_state."current_size" + 1
224
217
  );
225
218
  END;
226
219
  $$ LANGUAGE plpgsql;
227
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/04-function-message-dequeue.ts",re=(e)=>n`
220
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/04-function-message-dequeue.ts",Ee=(e)=>s`
228
221
  SELECT
229
222
  "message"."id",
230
223
  "message"."state",
@@ -232,11 +225,11 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
232
225
  "message"."channel_name",
233
226
  "message"."unlock_at",
234
227
  "message"."num_attempts"
235
- FROM ${s(e.schema)}."message"
228
+ FROM ${n(e.schema)}."message"
236
229
  WHERE "is_locked"
237
230
  AND "unlock_at" <= ${e.now}
238
231
  ORDER BY "unlock_at" ASC
239
- `,Ee=(e)=>n`
232
+ `,re=(e)=>s`
240
233
  SELECT
241
234
  "channel_state"."id",
242
235
  "channel_state"."name",
@@ -245,21 +238,20 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
245
238
  "channel_state"."dequeue_next_at",
246
239
  "channel_state"."dequeue_prev_at",
247
240
  "channel_state"."current_concurrency"
248
- FROM ${s(e.schema)}."channel_state"
241
+ FROM ${n(e.schema)}."channel_state"
249
242
  WHERE "message_id" IS NOT NULL
250
243
  AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
251
244
  ORDER BY "dequeue_next_at" ASC
252
- `,_e=(e)=>n`
245
+ `,_e=(e)=>s`
253
246
  SELECT
254
247
  "message"."id",
255
- "message"."dequeue_at",
256
- "message"."seq_no"
257
- FROM ${s(e.schema)}."message"
248
+ "message"."dequeue_at"
249
+ FROM ${n(e.schema)}."message"
258
250
  WHERE NOT "is_locked"
259
251
  AND "channel_name" = ${e.channelName}
260
- ORDER BY "dequeue_at" ASC, "seq_no" ASC
261
- `,x={name:_(__filename),sql:(e)=>{let t=re({now:n`v_now`,schema:e.schema}),a=_e({channelName:n`v_channel_state."name"`,schema:e.schema}),r=Ee({schema:e.schema});return[n`
262
- CREATE FUNCTION ${s(e.schema)}."message_dequeue" (
252
+ ORDER BY "dequeue_at" ASC, "id" ASC
253
+ `,q={name:_(__filename),sql:(e)=>{let t=Ee({now:s`v_now`,schema:e.schema}),a=_e({channelName:s`v_channel_state."name"`,schema:e.schema}),E=re({schema:e.schema});return[s`
254
+ CREATE FUNCTION ${n(e.schema)}."message_dequeue" (
263
255
  p_lock_ms BIGINT
264
256
  )
265
257
  RETURNS TABLE (
@@ -284,13 +276,13 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
284
276
  INTO v_message_locked;
285
277
 
286
278
  IF v_message_locked."id" IS NOT NULL THEN
287
- UPDATE ${s(e.schema)}."message" SET
279
+ UPDATE ${n(e.schema)}."message" SET
288
280
  "num_attempts" = v_message_locked."num_attempts" + 1,
289
281
  "unlock_at" = v_now + (p_lock_ms * INTERVAL '1 millisecond')
290
282
  WHERE "id" = v_message_locked."id";
291
283
 
292
284
  RETURN QUERY SELECT
293
- ${E(1)},
285
+ ${r(1)},
294
286
  v_message_locked.content,
295
287
  v_message_locked.state,
296
288
  JSON_BUILD_OBJECT(
@@ -302,7 +294,7 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
302
294
  RETURN;
303
295
  END IF;
304
296
 
305
- ${r}
297
+ ${E}
306
298
  FOR UPDATE
307
299
  SKIP LOCKED
308
300
  LIMIT 1
@@ -310,7 +302,7 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
310
302
 
311
303
  IF v_channel_state."id" IS NULL OR v_channel_state."dequeue_next_at" > v_now THEN
312
304
  RETURN QUERY SELECT
313
- ${E(0)},
305
+ ${r(0)},
314
306
  NULL::BYTEA,
315
307
  NULL::BYTEA,
316
308
  NULL::JSON;
@@ -323,11 +315,11 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
323
315
  "message"."content",
324
316
  "message"."num_attempts",
325
317
  "message"."state"
326
- FROM ${s(e.schema)}."message"
318
+ FROM ${n(e.schema)}."message"
327
319
  WHERE "id" = v_channel_state."message_id"
328
320
  INTO v_message_dequeue;
329
321
 
330
- UPDATE ${s(e.schema)}."message" SET
322
+ UPDATE ${n(e.schema)}."message" SET
331
323
  "is_locked" = TRUE,
332
324
  "num_attempts" = v_message_dequeue."num_attempts" + 1,
333
325
  "unlock_at" = v_now + (p_lock_ms * INTERVAL '1 millisecond')
@@ -338,17 +330,16 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
338
330
  INTO v_message_next;
339
331
 
340
332
  IF v_message_next."id" IS NULL THEN
341
- UPDATE ${s(e.schema)}."channel_state" SET
333
+ UPDATE ${n(e.schema)}."channel_state" SET
342
334
  "current_concurrency" = v_channel_state."current_concurrency" + 1,
343
335
  "dequeue_prev_at" = v_now,
344
336
  "message_id" = NULL
345
337
  WHERE "id" = v_channel_state."id";
346
338
  ELSE
347
- UPDATE ${s(e.schema)}."channel_state" SET
339
+ UPDATE ${n(e.schema)}."channel_state" SET
348
340
  "current_concurrency" = v_channel_state."current_concurrency" + 1,
349
341
  "message_id" = v_message_next."id",
350
342
  "message_dequeue_at" = v_message_next."dequeue_at",
351
- "message_seq_no" = v_message_next."seq_no",
352
343
  "dequeue_prev_at" = v_now,
353
344
  "dequeue_next_at" = GREATEST(
354
345
  v_message_next."dequeue_at",
@@ -358,11 +349,11 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
358
349
  END IF;
359
350
 
360
351
  RETURN QUERY SELECT
361
- ${E(1)},
352
+ ${r(1)},
362
353
  v_message_dequeue."content",
363
354
  v_message_dequeue."state",
364
355
  JSON_BUILD_OBJECT(
365
- 'id', v_message_dequeue."id",
356
+ 'id', v_message_dequeue."id"::TEXT,
366
357
  'is_unlocked', FALSE,
367
358
  'channel_name', v_message_dequeue."channel_name",
368
359
  'num_attempts', v_message_dequeue."num_attempts" + 1
@@ -370,9 +361,9 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
370
361
  RETURN;
371
362
  END;
372
363
  $$ LANGUAGE plpgsql;
373
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts",$={name:_(__filename),sql:(e)=>{return[n`
374
- CREATE FUNCTION ${s(e.schema)}."message_delete" (
375
- p_id UUID,
364
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/05-function-message-delete.ts",$={name:_(__filename),sql:(e)=>{return[s`
365
+ CREATE FUNCTION ${n(e.schema)}."message_delete" (
366
+ p_id BIGINT,
376
367
  p_num_attempts BIGINT
377
368
  )
378
369
  RETURNS TABLE (
@@ -388,24 +379,24 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
388
379
  "message"."channel_name",
389
380
  "message"."num_attempts",
390
381
  "message"."is_locked"
391
- FROM ${s(e.schema)}."message"
382
+ FROM ${n(e.schema)}."message"
392
383
  WHERE "id" = p_id
393
384
  FOR UPDATE
394
385
  INTO v_message;
395
386
 
396
387
  IF v_message."id" IS NULL THEN
397
388
  RETURN QUERY SELECT
398
- ${E(0)};
389
+ ${r(0)};
399
390
  RETURN;
400
391
  ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
401
392
  RETURN QUERY SELECT
402
- ${E(1)};
393
+ ${r(1)};
403
394
  RETURN;
404
395
  END IF;
405
396
 
406
397
  SELECT
407
398
  "channel_policy"."id"
408
- FROM ${s(e.schema)}."channel_policy"
399
+ FROM ${n(e.schema)}."channel_policy"
409
400
  WHERE "name" = v_message."channel_name"
410
401
  FOR SHARE
411
402
  INTO v_channel_policy;
@@ -414,42 +405,42 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
414
405
  "channel_state"."id",
415
406
  "channel_state"."current_size",
416
407
  "channel_state"."current_concurrency"
417
- FROM ${s(e.schema)}."channel_state"
408
+ FROM ${n(e.schema)}."channel_state"
418
409
  WHERE "name" = v_message."channel_name"
419
410
  FOR UPDATE
420
411
  INTO v_channel_state;
421
412
 
422
413
  IF v_channel_policy."id" IS NULL AND v_channel_state."current_size" = 1 THEN
423
- DELETE FROM ${s(e.schema)}."channel_state"
414
+ DELETE FROM ${n(e.schema)}."channel_state"
424
415
  WHERE "id" = v_channel_state."id";
425
416
  ELSE
426
- UPDATE ${s(e.schema)}."channel_state" SET
417
+ UPDATE ${n(e.schema)}."channel_state" SET
427
418
  "current_concurrency" = v_channel_state."current_concurrency" - 1,
428
419
  "current_size" = v_channel_state."current_size" - 1
429
420
  WHERE "id" = v_channel_state."id";
430
421
  END IF;
431
422
 
432
- IF ${E(e.eventChannel!==null)} THEN
423
+ IF ${r(e.eventChannel!==null)} THEN
433
424
  PERFORM PG_NOTIFY(
434
- ${E(e.eventChannel)},
425
+ ${r(e.eventChannel)},
435
426
  JSON_BUILD_OBJECT(
436
- 'type', ${E(1)},
437
- 'id', p_id
427
+ 'type', ${r(1)},
428
+ 'id', p_id::TEXT
438
429
  )::TEXT
439
430
  );
440
431
  END IF;
441
432
 
442
- DELETE FROM ${s(e.schema)}."message"
433
+ DELETE FROM ${n(e.schema)}."message"
443
434
  WHERE "id" = p_id;
444
435
 
445
436
  RETURN QUERY SELECT
446
- ${E(2)};
437
+ ${r(2)};
447
438
  RETURN;
448
439
  END;
449
440
  $$ LANGUAGE plpgsql;
450
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",F={name:_(__filename),sql:(e)=>{return[n`
451
- CREATE FUNCTION ${s(e.schema)}."message_defer" (
452
- p_id UUID,
441
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/06-function-message-defer.ts",F={name:_(__filename),sql:(e)=>{return[s`
442
+ CREATE FUNCTION ${n(e.schema)}."message_defer" (
443
+ p_id BIGINT,
453
444
  p_num_attempts BIGINT,
454
445
  p_delay_ms BIGINT,
455
446
  p_state BYTEA
@@ -469,20 +460,19 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
469
460
  "message"."id",
470
461
  "message"."channel_name",
471
462
  "message"."num_attempts",
472
- "message"."is_locked",
473
- "message"."seq_no"
474
- FROM ${s(e.schema)}."message"
463
+ "message"."is_locked"
464
+ FROM ${n(e.schema)}."message"
475
465
  WHERE "id" = p_id
476
466
  FOR UPDATE
477
467
  INTO v_message;
478
468
 
479
469
  IF v_message."id" IS NULL THEN
480
470
  RETURN QUERY SELECT
481
- ${E(0)};
471
+ ${r(0)};
482
472
  RETURN;
483
473
  ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
484
474
  RETURN QUERY SELECT
485
- ${E(1)};
475
+ ${r(1)};
486
476
  RETURN;
487
477
  END IF;
488
478
 
@@ -491,9 +481,8 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
491
481
  "channel_state"."release_interval_ms",
492
482
  "channel_state"."message_id",
493
483
  "channel_state"."message_dequeue_at",
494
- "channel_state"."dequeue_prev_at",
495
- "channel_state"."message_seq_no"
496
- FROM ${s(e.schema)}."channel_state"
484
+ "channel_state"."dequeue_prev_at"
485
+ FROM ${n(e.schema)}."channel_state"
497
486
  WHERE "name" = v_message."channel_name"
498
487
  FOR UPDATE
499
488
  INTO v_channel_state;
@@ -503,77 +492,76 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
503
492
  IF
504
493
  v_channel_state."message_id" IS NULL OR
505
494
  v_dequeue_at < v_channel_state."message_dequeue_at" OR
506
- v_dequeue_at = v_channel_state."message_dequeue_at" AND v_message."seq_no" < v_channel_state."message_seq_no"
495
+ v_dequeue_at = v_channel_state."message_dequeue_at" AND v_message."id" < v_channel_state."message_id"
507
496
  THEN
508
- UPDATE ${s(e.schema)}."channel_state" SET
497
+ UPDATE ${n(e.schema)}."channel_state" SET
509
498
  "current_concurrency" = v_channel_state."current_concurrency" - 1,
510
499
  "message_id" = v_message."id",
511
500
  "message_dequeue_at" = v_dequeue_at,
512
- "message_seq_no" = v_message."seq_no",
513
501
  "dequeue_next_at" = GREATEST(
514
502
  v_channel_state."dequeue_prev_at" + INTERVAL '1 MILLISECOND' * COALESCE(v_channel_state."release_interval_ms", 0),
515
503
  v_dequeue_at
516
504
  )
517
505
  WHERE "name" = v_message."channel_name";
518
506
  ELSE
519
- UPDATE ${s(e.schema)}."channel_state" SET
507
+ UPDATE ${n(e.schema)}."channel_state" SET
520
508
  "current_concurrency" = v_channel_state."current_concurrency" - 1
521
509
  WHERE "name" = v_message."channel_name";
522
510
  END IF;
523
511
 
524
- UPDATE ${s(e.schema)}."message" SET
512
+ UPDATE ${n(e.schema)}."message" SET
525
513
  "state" = p_state,
526
514
  "is_locked" = FALSE,
527
515
  "dequeue_at" = v_dequeue_at
528
516
  WHERE "id" = p_id;
529
517
 
530
- IF ${E(e.eventChannel!==null)} THEN
518
+ IF ${r(e.eventChannel!==null)} THEN
531
519
  PERFORM PG_NOTIFY(
532
- ${E(e.eventChannel)},
520
+ ${r(e.eventChannel)},
533
521
  JSON_BUILD_OBJECT(
534
- 'type', ${E(2)},
522
+ 'type', ${r(2)},
535
523
  'delay_ms', p_delay_ms,
536
- 'id', p_id
524
+ 'id', p_id::TEXT
537
525
  )::TEXT
538
526
  );
539
527
  END IF;
540
528
 
541
529
  RETURN QUERY SELECT
542
- ${E(2)};
530
+ ${r(2)};
543
531
  RETURN;
544
532
  END;
545
533
  $$ LANGUAGE plpgsql;
546
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",b={name:_(__filename),sql:(e)=>{return[n`
547
- CREATE FUNCTION ${s(e.schema)}."channel_policy_clear" (
534
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/08-function-channel-policy-clear.ts",b={name:_(__filename),sql:(e)=>{return[s`
535
+ CREATE FUNCTION ${n(e.schema)}."channel_policy_clear" (
548
536
  p_name TEXT
549
537
  ) RETURNS VOID AS $$
550
538
  DECLARE
551
539
  v_channel_state RECORD;
552
540
  BEGIN
553
- DELETE FROM ${s(e.schema)}."channel_policy"
541
+ DELETE FROM ${n(e.schema)}."channel_policy"
554
542
  WHERE "name" = p_name;
555
543
 
556
544
  SELECT
557
545
  "channel_state"."id",
558
546
  "channel_state"."current_size"
559
- FROM ${s(e.schema)}."channel_state"
547
+ FROM ${n(e.schema)}."channel_state"
560
548
  WHERE "name" = p_name
561
549
  FOR UPDATE
562
550
  INTO v_channel_state;
563
551
 
564
552
  IF v_channel_state."current_size" = 0 THEN
565
- DELETE FROM ${s(e.schema)}."channel_state"
553
+ DELETE FROM ${n(e.schema)}."channel_state"
566
554
  WHERE "id" = v_channel_state."id";
567
555
  ELSE
568
- UPDATE ${s(e.schema)}."channel_state" SET
556
+ UPDATE ${n(e.schema)}."channel_state" SET
569
557
  "max_concurrency" = NULL,
570
558
  "release_interval_ms" = NULL
571
559
  WHERE "name" = p_name;
572
560
  END IF;
573
561
  END;
574
562
  $$ LANGUAGE plpgsql;
575
- `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",B={name:_(__filename),sql:(e)=>{return[n`
576
- CREATE FUNCTION ${s(e.schema)}."channel_policy_set" (
563
+ `]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/install/09-function-channel-policy-set.ts",x={name:_(__filename),sql:(e)=>{return[s`
564
+ CREATE FUNCTION ${n(e.schema)}."channel_policy_set" (
577
565
  p_name TEXT,
578
566
  p_max_concurrency INTEGER,
579
567
  p_release_interval_ms INTEGER
@@ -583,7 +571,7 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
583
571
  BEGIN
584
572
  v_now := NOW();
585
573
 
586
- INSERT INTO ${s(e.schema)}."channel_policy" (
574
+ INSERT INTO ${n(e.schema)}."channel_policy" (
587
575
  "name",
588
576
  "max_concurrency",
589
577
  "release_interval_ms",
@@ -597,15 +585,15 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
597
585
  "max_concurrency" = EXCLUDED."max_concurrency",
598
586
  "release_interval_ms" = EXCLUDED."release_interval_ms";
599
587
 
600
- UPDATE ${s(e.schema)}."channel_state" SET
588
+ UPDATE ${n(e.schema)}."channel_state" SET
601
589
  "max_concurrency" = p_max_concurrency,
602
590
  "release_interval_ms" = p_release_interval_ms
603
591
  WHERE "name" = p_name;
604
592
  END;
605
593
  $$ LANGUAGE plpgsql;
606
- `]}};class R{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,channelName:this.channelName,content:e.content,delayMs:e.delayMs}),r=await a.execute(t);return{messageId:r.id,channelName:a.channelName,channelSize:r.channelSize}}}class A{schema;adaptor;channelName;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}set(e){let t=this.adaptor(e.databaseClient);return new c({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new o({schema:this.schema,channelName:this.channelName}).execute(t)}}class g{policy;message;constructor(e){this.message=new R({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new A({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class p{schema;adaptor;id;isUnlocked;channelName;content;state;numAttempts;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new i({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(t)}async delete(e){let t=this.adaptor(e.databaseClient);return new u({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(t)}async heartbeat(e){let t=this.adaptor(e.databaseClient);return new d({schema:this.schema,id:this.id,numAttempts:this.numAttempts,lockMs:e.lockMs}).execute(t)}}class D{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,content:e.content,delayMs:e.delayMs}),r=await a.execute(t);return{messageId:r.id,channelName:a.channelName,channelSize:r.channelSize}}}var __filename="/home/runner/work/lonnymq/lonnymq/src/install/07-function-message-heartbeat.ts",w={name:_(__filename),sql:(e)=>{return[n`
607
- CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
608
- p_id UUID,
594
+ `]}};class R{schema;channelName;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,channelName:this.channelName,content:e.content,delayMs:e.delayMs}),E=await a.execute(t);return{messageId:E.id,channelName:a.channelName,channelSize:E.channelSize}}}class A{schema;adaptor;channelName;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.channelName=e.channelName}set(e){let t=this.adaptor(e.databaseClient);return new o({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,releaseIntervalMs:e.releaseIntervalMs}).execute(t)}clear(e){let t=this.adaptor(e.databaseClient);return new c({schema:this.schema,channelName:this.channelName}).execute(t)}}class g{policy;message;constructor(e){this.message=new R({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName}),this.policy=new A({schema:e.schema,adaptor:e.adaptor,channelName:e.channelName})}}class D{schema;adaptor;id;isUnlocked;channelName;content;state;numAttempts;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){let t=this.adaptor(e.databaseClient);return new i({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(t)}async delete(e){let t=this.adaptor(e.databaseClient);return new u({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(t)}async heartbeat(e){let t=this.adaptor(e.databaseClient);return new d({schema:this.schema,id:this.id,numAttempts:this.numAttempts,lockMs:e.lockMs}).execute(t)}}class p{schema;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor}async create(e){let t=this.adaptor(e.databaseClient),a=new l({schema:this.schema,content:e.content,delayMs:e.delayMs}),E=await a.execute(t);return{messageId:E.id,channelName:a.channelName,channelSize:E.channelSize}}}var __filename="/home/runner/work/lonnymq/lonnymq/src/install/07-function-message-heartbeat.ts",B={name:_(__filename),sql:(e)=>{return[s`
595
+ CREATE FUNCTION ${n(e.schema)}."message_heartbeat" (
596
+ p_id BIGINT,
609
597
  p_num_attempts BIGINT,
610
598
  p_lock_ms BIGINT
611
599
  )
@@ -626,22 +614,22 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
626
614
  "message"."num_attempts",
627
615
  "message"."is_locked",
628
616
  "message"."unlock_at"
629
- FROM ${s(e.schema)}."message"
617
+ FROM ${n(e.schema)}."message"
630
618
  WHERE "id" = p_id
631
619
  FOR UPDATE
632
620
  INTO v_message;
633
621
 
634
622
  IF v_message."id" IS NULL THEN
635
623
  RETURN QUERY SELECT
636
- ${E(0)};
624
+ ${r(0)};
637
625
  RETURN;
638
626
  ELSIF NOT v_message."is_locked" OR v_message."num_attempts" <> p_num_attempts THEN
639
627
  RETURN QUERY SELECT
640
- ${E(1)};
628
+ ${r(1)};
641
629
  RETURN;
642
630
  END IF;
643
631
 
644
- UPDATE ${s(e.schema)}."message" SET
632
+ UPDATE ${n(e.schema)}."message" SET
645
633
  "unlock_at" = GREATEST(
646
634
  v_now + (p_lock_ms * INTERVAL '1 millisecond'),
647
635
  v_message."unlock_at"
@@ -649,8 +637,8 @@ var{defineProperty:h,getOwnPropertyNames:k,getOwnPropertyDescriptor:P}=Object,Q=
649
637
  WHERE "id" = p_id;
650
638
 
651
639
  RETURN QUERY SELECT
652
- ${E(2)};
640
+ ${r(2)};
653
641
  RETURN;
654
642
  END;
655
643
  $$ LANGUAGE plpgsql;
656
- `]}};class y{schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new D({schema:this.schema,adaptor:this.adaptor})}async dequeue(e){let t=new m({schema:this.schema,lockMs:e.lockMs}),a=this.adaptor(e.databaseClient),r=await t.execute(a);if(r.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new p({schema:this.schema,adaptor:this.adaptor,id:r.id,channelName:r.channelName,isUnlocked:r.isUnlocked,content:r.content,state:r.state,numAttempts:r.numAttempts})};else return r}channel(e){return new g({adaptor:this.adaptor,schema:this.schema,channelName:e})}install(e={}){return[O,f,q,G,x,$,F,w,B,b].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>U(t.value))}}
644
+ `]}};var w=(e)=>{let t=JSON.parse(e);if(t.type===0)return{eventType:"MESSAGE_CREATED",id:t.id,delayMs:t.delay_ms};else if(t.type===1)return{eventType:"MESSAGE_DELETED",id:t.id};else if(t.type===2)return{eventType:"MESSAGE_DEFERRED",id:t.id,delayMs:t.delay_ms};else throw new Error("Unknown event type")};class y{schema;message;adaptor;constructor(e){this.schema=e.schema,this.adaptor=e.adaptor?e.adaptor:(t)=>t,this.message=new p({schema:this.schema,adaptor:this.adaptor})}async dequeue(e){let t=new m({schema:this.schema,lockMs:e.lockMs}),a=this.adaptor(e.databaseClient),E=await t.execute(a);if(E.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new D({schema:this.schema,adaptor:this.adaptor,id:E.id,channelName:E.channelName,isUnlocked:E.isUnlocked,content:E.content,state:E.state,numAttempts:E.numAttempts})};else return E}channel(e){return new g({adaptor:this.adaptor,schema:this.schema,channelName:e})}install(e={}){return[O,U,f,G,q,$,F,B,x,b].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>C(t.value))}static decode(e){return w(e)}}