lonnymq 0.0.14 → 0.0.15
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 +45 -39
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -37
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=Object.prototype.hasOwnProperty;var U=new WeakMap,J=(e)=>{var t=U.get(e),n;if(t)return t;if(t=h({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")W(e).map((E)=>!X.call(t,E)&&h(t,E,{get:()=>e[E],enumerable:!(n=Y(e,E))||n.enumerable}));return U.set(e,t),t};var K=(e,t)=>{for(var n in t)h(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(E)=>t[n]=()=>E})};var
|
|
1
|
+
var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=Object.prototype.hasOwnProperty;var U=new WeakMap,J=(e)=>{var t=U.get(e),n;if(t)return t;if(t=h({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function")W(e).map((E)=>!X.call(t,E)&&h(t,E,{get:()=>e[E],enumerable:!(n=Y(e,E))||n.enumerable}));return U.set(e,t),t};var K=(e,t)=>{for(var n in t)h(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(E)=>t[n]=()=>E})};var Te={};K(Te,{queueEventDecode:()=>x,Queue:()=>L,MessageHeartbeatCommand:()=>S,MessageDequeueCommand:()=>i,MessageDeleteCommand:()=>u,MessageDeferCommand:()=>o,MessageCreateCommand:()=>c,ChannelPolicySetCommand:()=>m,ChannelPolicyClearCommand:()=>l});module.exports=J(Te);var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),j=(e)=>({nodeType:"RAW",value:e}),Z=(e)=>{return`'${e.replace(/'/g,"''")}'`},ee=(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}`)},te=(e)=>{return`"${e.replace(/"/g,'""')}"`},se=(e)=>{if(e.nodeType==="VALUE")return ee(e.value);else if(e.nodeType==="REF")return te(e.value);else if(e.nodeType==="RAW")return e.value;else throw new Error("Unsupported SQL node type")};var a=(e,...t)=>{let n=[];for(let E=0;E<e.length;E+=1)if(n.push(e[E]),E<t.length)n.push(se(t[E]));return j(n.join(""))};class l{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}sortKeyGet(){return JSON.stringify([this.channelName,null,this.createdAt.toISOString()])}async execute(e){await e.query(a`
|
|
2
2
|
SELECT 1 FROM ${s(this.schema)}."channel_policy_clear"(
|
|
3
3
|
$1
|
|
4
4
|
)
|
|
@@ -42,7 +42,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
42
42
|
$1,
|
|
43
43
|
$2::BIGINT
|
|
44
44
|
)
|
|
45
|
-
`.value,[this.id,this.numAttempts]).then((n)=>n.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:"
|
|
45
|
+
`.value,[this.id,this.numAttempts]).then((n)=>n.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 F=(e)=>{let t=e.split(`
|
|
46
46
|
`),n=Number.MAX_SAFE_INTEGER;for(let E of t){if(E.trim().length===0)continue;let T=E.search(/\S/);n=Math.min(n,T)}return t.map((E)=>E.slice(n)).join(`
|
|
47
47
|
`).trim()};var g=require("path"),__filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",me=g.dirname(g.dirname(__filename)),ce=new RegExp(`^${me}/`),_=(e)=>{return e.replace(ce,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",q={name:_(__filename),sql:(e)=>{return[a`
|
|
48
48
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
@@ -259,7 +259,43 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
259
259
|
RETURN;
|
|
260
260
|
END;
|
|
261
261
|
$$ LANGUAGE plpgsql;
|
|
262
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",
|
|
262
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",oe=(e)=>a`
|
|
263
|
+
SELECT
|
|
264
|
+
"message"."id",
|
|
265
|
+
"message"."name",
|
|
266
|
+
"message"."state",
|
|
267
|
+
"message"."content",
|
|
268
|
+
"message"."channel_name",
|
|
269
|
+
"message"."lock_ms",
|
|
270
|
+
"message"."unlock_at",
|
|
271
|
+
"message"."num_attempts"
|
|
272
|
+
FROM ${s(e.schema)}."message"
|
|
273
|
+
WHERE "is_locked"
|
|
274
|
+
AND "unlock_at" <= ${e.now}
|
|
275
|
+
ORDER BY "unlock_at" ASC
|
|
276
|
+
`,ie=(e)=>a`
|
|
277
|
+
SELECT
|
|
278
|
+
"channel_state"."id",
|
|
279
|
+
"channel_state"."name",
|
|
280
|
+
"channel_state"."release_interval_ms",
|
|
281
|
+
"channel_state"."message_id",
|
|
282
|
+
"channel_state"."active_next_at",
|
|
283
|
+
"channel_state"."active_prev_at",
|
|
284
|
+
"channel_state"."current_concurrency"
|
|
285
|
+
FROM ${s(e.schema)}."channel_state"
|
|
286
|
+
WHERE "message_id" IS NOT NULL
|
|
287
|
+
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
288
|
+
ORDER BY "active_next_at" ASC
|
|
289
|
+
`,ue=(e)=>a`
|
|
290
|
+
SELECT
|
|
291
|
+
"message"."id",
|
|
292
|
+
"message"."dequeue_at",
|
|
293
|
+
"message"."seq_no"
|
|
294
|
+
FROM ${s(e.schema)}."message"
|
|
295
|
+
WHERE NOT "is_locked"
|
|
296
|
+
AND "channel_name" = ${e.channelName}
|
|
297
|
+
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
298
|
+
`,P={name:_(__filename),sql:(e)=>{let t=oe({now:a`v_now`,schema:e.schema}),n=ue({channelName:a`v_channel_state."name"`,schema:e.schema}),E=ie({schema:e.schema});return[a`
|
|
263
299
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" ()
|
|
264
300
|
RETURNS TABLE (
|
|
265
301
|
result_code INTEGER,
|
|
@@ -276,19 +312,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
276
312
|
BEGIN
|
|
277
313
|
v_now := NOW();
|
|
278
314
|
|
|
279
|
-
|
|
280
|
-
"message"."id",
|
|
281
|
-
"message"."name",
|
|
282
|
-
"message"."state",
|
|
283
|
-
"message"."content",
|
|
284
|
-
"message"."channel_name",
|
|
285
|
-
"message"."lock_ms",
|
|
286
|
-
"message"."unlock_at",
|
|
287
|
-
"message"."num_attempts"
|
|
288
|
-
FROM ${s(e.schema)}."message"
|
|
289
|
-
WHERE "is_locked"
|
|
290
|
-
AND "unlock_at" <= v_now
|
|
291
|
-
ORDER BY "unlock_at" ASC
|
|
315
|
+
${t}
|
|
292
316
|
FOR UPDATE
|
|
293
317
|
SKIP LOCKED
|
|
294
318
|
LIMIT 1
|
|
@@ -314,18 +338,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
314
338
|
RETURN;
|
|
315
339
|
END IF;
|
|
316
340
|
|
|
317
|
-
|
|
318
|
-
"channel_state"."id",
|
|
319
|
-
"channel_state"."name",
|
|
320
|
-
"channel_state"."release_interval_ms",
|
|
321
|
-
"channel_state"."message_id",
|
|
322
|
-
"channel_state"."active_next_at",
|
|
323
|
-
"channel_state"."active_prev_at",
|
|
324
|
-
"channel_state"."current_concurrency"
|
|
325
|
-
FROM ${s(e.schema)}."channel_state"
|
|
326
|
-
WHERE "message_id" IS NOT NULL
|
|
327
|
-
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
328
|
-
ORDER BY "active_next_at" ASC
|
|
341
|
+
${E}
|
|
329
342
|
FOR UPDATE
|
|
330
343
|
SKIP LOCKED
|
|
331
344
|
LIMIT 1
|
|
@@ -369,14 +382,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
369
382
|
"unlock_at" = v_now + (v_message_dequeue."lock_ms" * INTERVAL '1 millisecond')
|
|
370
383
|
WHERE "id" = v_message_dequeue."id";
|
|
371
384
|
|
|
372
|
-
|
|
373
|
-
"message"."id",
|
|
374
|
-
"message"."dequeue_at",
|
|
375
|
-
"message"."seq_no"
|
|
376
|
-
FROM ${s(e.schema)}."message"
|
|
377
|
-
WHERE NOT "is_locked"
|
|
378
|
-
AND "channel_name" = v_message_dequeue."channel_name"
|
|
379
|
-
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
385
|
+
${n}
|
|
380
386
|
LIMIT 1
|
|
381
387
|
INTO v_message_next;
|
|
382
388
|
|
|
@@ -491,7 +497,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
491
497
|
RETURN;
|
|
492
498
|
END;
|
|
493
499
|
$$ LANGUAGE plpgsql;
|
|
494
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",
|
|
500
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/06-function-message-defer.ts",w={name:_(__filename),sql:(e)=>{return[a`
|
|
495
501
|
CREATE FUNCTION ${s(e.schema)}."message_defer" (
|
|
496
502
|
p_id UUID,
|
|
497
503
|
p_num_attempts BIGINT,
|
|
@@ -587,7 +593,7 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
587
593
|
RETURN;
|
|
588
594
|
END;
|
|
589
595
|
$$ LANGUAGE plpgsql;
|
|
590
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",
|
|
596
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/07-function-message-heartbeat.ts",H={name:_(__filename),sql:(e)=>{return[a`
|
|
591
597
|
CREATE FUNCTION ${s(e.schema)}."message_heartbeat" (
|
|
592
598
|
p_id UUID,
|
|
593
599
|
p_num_attempts BIGINT
|
|
@@ -696,4 +702,4 @@ var{defineProperty:h,getOwnPropertyNames:W,getOwnPropertyDescriptor:Y}=Object,X=
|
|
|
696
702
|
WHERE "name" = p_name;
|
|
697
703
|
END;
|
|
698
704
|
$$ LANGUAGE plpgsql;
|
|
699
|
-
`]}};class A{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new c({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),n=new Promise((E)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(T)=>t.execute(T).then((z)=>E(z))})});return{messageId:t.id,promise:n}}}class D{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let t=new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,null,t.createdAt.toISOString()]),execute:async(n)=>{await t.execute(n)}})}clear(){let e=new l({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class p{policy;message;constructor(e){this.message=new A(e),this.policy=new D(e)}}var
|
|
705
|
+
`]}};class A{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new c({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),n=new Promise((E)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(T)=>t.execute(T).then((z)=>E(z))})});return{messageId:t.id,promise:n}}}class D{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let t=new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,null,t.createdAt.toISOString()]),execute:async(n)=>{await t.execute(n)}})}clear(){let e=new l({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class p{policy;message;constructor(e){this.message=new A(e),this.policy=new D(e)}}var de=(e,t)=>{return e.sortKey.localeCompare(t.sortKey)};class M{commands;schema;constructor(e){this.commands=[],this.schema=e.schema}channel(e){return new p({schema:this.schema,channelName:e,registerFn:(t)=>{this.commands.push(t)}})}async execute(e){for(let t of this.commands.sort(de))await t.execute(e.databaseClient)}}class y{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}async create(e){return new c({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(e.databaseClient)}}class C{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}set(e){return new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}).execute(e.databaseClient)}clear(e){return new l({schema:this.schema,channelName:this.channelName}).execute(e.databaseClient)}}class I{policy;message;constructor(e){this.message=new y({schema:e.schema,channelName:e.channelName}),this.policy=new C({schema:e.schema,channelName:e.channelName})}}class v{schema;id;isUnlocked;channelName;name;content;state;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.name=e.name,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){return new o({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(e.databaseClient)}async delete(e){return new u({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(e.databaseClient)}async heartbeat(e){return new o({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs}).execute(e.databaseClient)}}class L{schema;constructor(e){this.schema=e.schema}async dequeue(e){let n=await new i({schema:this.schema}).execute(e.databaseClient);if(n.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new v({schema:this.schema,id:n.message.id,channelName:n.message.channelName,name:n.message.name,isUnlocked:n.message.isUnlocked,content:n.message.content,state:n.message.state,numAttempts:n.message.numAttempts})};else return n}channel(e){return new I({schema:this.schema,channelName:e})}batch(){return new M({schema:this.schema})}migrations(e={}){return[q,$,b,B,P,Q,w,H,V,k].sort((t,n)=>t.name.localeCompare(n.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>F(t.value))}}
|
package/dist/index.d.ts
CHANGED
|
@@ -161,7 +161,7 @@ export type MessageHeartbeatCommandResultStateInvalid = {
|
|
|
161
161
|
resultType: "MESSAGE_STATE_INVALID";
|
|
162
162
|
};
|
|
163
163
|
export type MessageHeartbeatCommandResultMessageHeartbeated = {
|
|
164
|
-
resultType: "
|
|
164
|
+
resultType: "MESSAGE_HEARTBEATED";
|
|
165
165
|
};
|
|
166
166
|
export type MessageHeartbeatCommandResult = MessageHeartbeatCommandResultMessageNotFound | MessageHeartbeatCommandResultStateInvalid | MessageHeartbeatCommandResultMessageHeartbeated;
|
|
167
167
|
export declare class MessageHeartbeatCommand {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),
|
|
1
|
+
var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),H=(e)=>({nodeType:"RAW",value:e}),k=(e)=>{return`'${e.replace(/'/g,"''")}'`},V=(e)=>{if(e===null)return"NULL";else if(typeof e==="string")return k(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}`)},z=(e)=>{return`"${e.replace(/"/g,'""')}"`},W=(e)=>{if(e.nodeType==="VALUE")return V(e.value);else if(e.nodeType==="REF")return z(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 _=0;_<e.length;_+=1)if(a.push(e[_]),_<t.length)a.push(W(t[_]));return H(a.join(""))};class l{schema;channelName;createdAt;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.createdAt=new Date}sortKeyGet(){return JSON.stringify([this.channelName,null,this.createdAt.toISOString()])}async execute(e){await e.query(n`
|
|
2
2
|
SELECT 1 FROM ${s(this.schema)}."channel_policy_clear"(
|
|
3
3
|
$1
|
|
4
4
|
)
|
|
@@ -42,7 +42,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),w=(e)=
|
|
|
42
42
|
$1,
|
|
43
43
|
$2::BIGINT
|
|
44
44
|
)
|
|
45
|
-
`.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:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"
|
|
45
|
+
`.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:"MESSAGE_STATE_INVALID"};else if(t.result_code===2)return{resultType:"MESSAGE_HEARTBEATED"};else throw new Error("Unexpected result")}}var L=(e)=>{let t=e.split(`
|
|
46
46
|
`),a=Number.MAX_SAFE_INTEGER;for(let _ of t){if(_.trim().length===0)continue;let T=_.search(/\S/);a=Math.min(a,T)}return t.map((_)=>_.slice(a)).join(`
|
|
47
47
|
`).trim()};import{dirname as U}from"path";var __filename="/home/runner/work/lonnymq/lonnymq/src/core/path.ts",se=U(U(__filename)),ne=new RegExp(`^${se}/`),E=(e)=>{return e.replace(ne,"")};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/00-table-channel-policy.ts",O={name:E(__filename),sql:(e)=>{return[n`
|
|
48
48
|
CREATE TABLE ${s(e.schema)}."channel_policy" (
|
|
@@ -259,7 +259,43 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),w=(e)=
|
|
|
259
259
|
RETURN;
|
|
260
260
|
END;
|
|
261
261
|
$$ LANGUAGE plpgsql;
|
|
262
|
-
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",
|
|
262
|
+
`]}};var __filename="/home/runner/work/lonnymq/lonnymq/src/migration/04-function-message-dequeue.ts",ae=(e)=>n`
|
|
263
|
+
SELECT
|
|
264
|
+
"message"."id",
|
|
265
|
+
"message"."name",
|
|
266
|
+
"message"."state",
|
|
267
|
+
"message"."content",
|
|
268
|
+
"message"."channel_name",
|
|
269
|
+
"message"."lock_ms",
|
|
270
|
+
"message"."unlock_at",
|
|
271
|
+
"message"."num_attempts"
|
|
272
|
+
FROM ${s(e.schema)}."message"
|
|
273
|
+
WHERE "is_locked"
|
|
274
|
+
AND "unlock_at" <= ${e.now}
|
|
275
|
+
ORDER BY "unlock_at" ASC
|
|
276
|
+
`,re=(e)=>n`
|
|
277
|
+
SELECT
|
|
278
|
+
"channel_state"."id",
|
|
279
|
+
"channel_state"."name",
|
|
280
|
+
"channel_state"."release_interval_ms",
|
|
281
|
+
"channel_state"."message_id",
|
|
282
|
+
"channel_state"."active_next_at",
|
|
283
|
+
"channel_state"."active_prev_at",
|
|
284
|
+
"channel_state"."current_concurrency"
|
|
285
|
+
FROM ${s(e.schema)}."channel_state"
|
|
286
|
+
WHERE "message_id" IS NOT NULL
|
|
287
|
+
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
288
|
+
ORDER BY "active_next_at" ASC
|
|
289
|
+
`,Ee=(e)=>n`
|
|
290
|
+
SELECT
|
|
291
|
+
"message"."id",
|
|
292
|
+
"message"."dequeue_at",
|
|
293
|
+
"message"."seq_no"
|
|
294
|
+
FROM ${s(e.schema)}."message"
|
|
295
|
+
WHERE NOT "is_locked"
|
|
296
|
+
AND "channel_name" = ${e.channelName}
|
|
297
|
+
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
298
|
+
`,F={name:E(__filename),sql:(e)=>{let t=ae({now:n`v_now`,schema:e.schema}),a=Ee({channelName:n`v_channel_state."name"`,schema:e.schema}),_=re({schema:e.schema});return[n`
|
|
263
299
|
CREATE FUNCTION ${s(e.schema)}."message_dequeue" ()
|
|
264
300
|
RETURNS TABLE (
|
|
265
301
|
result_code INTEGER,
|
|
@@ -276,19 +312,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),w=(e)=
|
|
|
276
312
|
BEGIN
|
|
277
313
|
v_now := NOW();
|
|
278
314
|
|
|
279
|
-
|
|
280
|
-
"message"."id",
|
|
281
|
-
"message"."name",
|
|
282
|
-
"message"."state",
|
|
283
|
-
"message"."content",
|
|
284
|
-
"message"."channel_name",
|
|
285
|
-
"message"."lock_ms",
|
|
286
|
-
"message"."unlock_at",
|
|
287
|
-
"message"."num_attempts"
|
|
288
|
-
FROM ${s(e.schema)}."message"
|
|
289
|
-
WHERE "is_locked"
|
|
290
|
-
AND "unlock_at" <= v_now
|
|
291
|
-
ORDER BY "unlock_at" ASC
|
|
315
|
+
${t}
|
|
292
316
|
FOR UPDATE
|
|
293
317
|
SKIP LOCKED
|
|
294
318
|
LIMIT 1
|
|
@@ -314,18 +338,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),w=(e)=
|
|
|
314
338
|
RETURN;
|
|
315
339
|
END IF;
|
|
316
340
|
|
|
317
|
-
|
|
318
|
-
"channel_state"."id",
|
|
319
|
-
"channel_state"."name",
|
|
320
|
-
"channel_state"."release_interval_ms",
|
|
321
|
-
"channel_state"."message_id",
|
|
322
|
-
"channel_state"."active_next_at",
|
|
323
|
-
"channel_state"."active_prev_at",
|
|
324
|
-
"channel_state"."current_concurrency"
|
|
325
|
-
FROM ${s(e.schema)}."channel_state"
|
|
326
|
-
WHERE "message_id" IS NOT NULL
|
|
327
|
-
AND ("max_concurrency" IS NULL OR "current_concurrency" < "max_concurrency")
|
|
328
|
-
ORDER BY "active_next_at" ASC
|
|
341
|
+
${_}
|
|
329
342
|
FOR UPDATE
|
|
330
343
|
SKIP LOCKED
|
|
331
344
|
LIMIT 1
|
|
@@ -369,14 +382,7 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),w=(e)=
|
|
|
369
382
|
"unlock_at" = v_now + (v_message_dequeue."lock_ms" * INTERVAL '1 millisecond')
|
|
370
383
|
WHERE "id" = v_message_dequeue."id";
|
|
371
384
|
|
|
372
|
-
|
|
373
|
-
"message"."id",
|
|
374
|
-
"message"."dequeue_at",
|
|
375
|
-
"message"."seq_no"
|
|
376
|
-
FROM ${s(e.schema)}."message"
|
|
377
|
-
WHERE NOT "is_locked"
|
|
378
|
-
AND "channel_name" = v_message_dequeue."channel_name"
|
|
379
|
-
ORDER BY "dequeue_at" ASC, "seq_no" ASC
|
|
385
|
+
${a}
|
|
380
386
|
LIMIT 1
|
|
381
387
|
INTO v_message_next;
|
|
382
388
|
|
|
@@ -696,4 +702,4 @@ var r=(e)=>({nodeType:"VALUE",value:e}),s=(e)=>({nodeType:"REF",value:e}),w=(e)=
|
|
|
696
702
|
WHERE "name" = p_name;
|
|
697
703
|
END;
|
|
698
704
|
$$ LANGUAGE plpgsql;
|
|
699
|
-
`]}};class R{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new c({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),a=new Promise((_)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(T)=>t.execute(T).then((
|
|
705
|
+
`]}};class R{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}create(e){let t=new c({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}),a=new Promise((_)=>{this.registerFn({sortKey:JSON.stringify([t.channelName,t.name,t.createdAt.toISOString()]),execute:(T)=>t.execute(T).then((w)=>_(w))})});return{messageId:t.id,promise:a}}}class S{schema;channelName;registerFn;constructor(e){this.schema=e.schema,this.channelName=e.channelName,this.registerFn=e.registerFn}set(e){let t=new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs});this.registerFn({sortKey:JSON.stringify([t.channelName,null,t.createdAt.toISOString()]),execute:async(a)=>{await t.execute(a)}})}clear(){let e=new l({schema:this.schema,channelName:this.channelName});this.registerFn({sortKey:JSON.stringify([e.channelName,null,e.createdAt.toISOString()]),execute:async(t)=>{await e.execute(t)}})}}class g{policy;message;constructor(e){this.message=new R(e),this.policy=new S(e)}}var _e=(e,t)=>{return e.sortKey.localeCompare(t.sortKey)};class A{commands;schema;constructor(e){this.commands=[],this.schema=e.schema}channel(e){return new g({schema:this.schema,channelName:e,registerFn:(t)=>{this.commands.push(t)}})}async execute(e){for(let t of this.commands.sort(_e))await t.execute(e.databaseClient)}}class D{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}async create(e){return new c({schema:this.schema,channelName:this.channelName,name:e.name,content:e.content,lockMs:e.lockMs,delayMs:e.delayMs}).execute(e.databaseClient)}}class p{schema;channelName;constructor(e){this.schema=e.schema,this.channelName=e.channelName}set(e){return new m({schema:this.schema,channelName:this.channelName,maxConcurrency:e.maxConcurrency,maxSize:e.maxSize,releaseIntervalMs:e.releaseIntervalMs}).execute(e.databaseClient)}clear(e){return new l({schema:this.schema,channelName:this.channelName}).execute(e.databaseClient)}}class M{policy;message;constructor(e){this.message=new D({schema:e.schema,channelName:e.channelName}),this.policy=new p({schema:e.schema,channelName:e.channelName})}}class y{schema;id;isUnlocked;channelName;name;content;state;numAttempts;constructor(e){this.schema=e.schema,this.id=e.id,this.channelName=e.channelName,this.isUnlocked=e.isUnlocked,this.name=e.name,this.content=e.content,this.state=e.state,this.numAttempts=e.numAttempts}async defer(e){return new o({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs,state:e.state}).execute(e.databaseClient)}async delete(e){return new d({schema:this.schema,numAttempts:this.numAttempts,id:this.id}).execute(e.databaseClient)}async heartbeat(e){return new o({schema:this.schema,id:this.id,numAttempts:this.numAttempts,delayMs:e.delayMs}).execute(e.databaseClient)}}class Q{schema;constructor(e){this.schema=e.schema}async dequeue(e){let a=await new u({schema:this.schema}).execute(e.databaseClient);if(a.resultType==="MESSAGE_DEQUEUED")return{resultType:"MESSAGE_DEQUEUED",message:new y({schema:this.schema,id:a.message.id,channelName:a.message.channelName,name:a.message.name,isUnlocked:a.message.isUnlocked,content:a.message.content,state:a.message.state,numAttempts:a.message.numAttempts})};else return a}channel(e){return new M({schema:this.schema,channelName:e})}batch(){return new A({schema:this.schema})}migrations(e={}){return[O,f,x,G,F,q,$,b,P,B].sort((t,a)=>t.name.localeCompare(a.name)).flatMap((t)=>t.sql({schema:this.schema,eventChannel:e.eventChannel??null})).map((t)=>L(t.value))}}export{X as queueEventDecode,Q as Queue,v as MessageHeartbeatCommand,u as MessageDequeueCommand,d as MessageDeleteCommand,o as MessageDeferCommand,c as MessageCreateCommand,m as ChannelPolicySetCommand,l as ChannelPolicyClearCommand};
|