@ez4/local-queue 0.22.0 → 0.24.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.
- package/dist/handlers/lambda.d.ts +3 -0
- package/dist/main.cjs +25 -20
- package/dist/main.mjs +22 -17
- package/dist/provider/emulator.d.ts +7 -4
- package/dist/service/client.d.ts +1 -1
- package/package.json +7 -6
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { QueueImport, QueueService, QueueSubscription } from '@ez4/queue/library';
|
|
2
|
+
import type { EmulateServiceContext, ServeOptions } from '@ez4/project/library';
|
|
3
|
+
export declare const processLambdaMessage: (service: QueueService | QueueImport, options: ServeOptions, context: EmulateServiceContext, subscription: QueueSubscription, message: Buffer) => Promise<void>;
|
package/dist/main.cjs
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
n
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
"use strict";var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var i=(e,r)=>g(e,"name",{value:r,configurable:!0});var z=(e,r)=>{for(var t in r)g(e,t,{get:r[t],enumerable:!0})},T=(e,r,t,o)=>{if(r&&
|
|
2
|
+
typeof r=="object"||typeof r=="function")for(let s of R(r))!C.call(e,s)&&s!==t&&
|
|
3
|
+
g(e,s,{get:()=>r[s],enumerable:!(o=I(r,s))||o.enumerable});return e};var O=e=>T(g({},"__esModule",{value:!0}),e);var H={};z(H,{registerTriggers:()=>$});module.exports=O(H);var l=require("@ez4/queue/library"),M=require("@ez4/project/library");var b=require("@ez4/project/library"),S=require("@ez4/queue/utils"),f=require("@ez4/local-common"),
|
|
4
|
+
q=require("@ez4/utils");var m=require("@ez4/local-common"),v=require("@ez4/utils");var y=i(async(e,r,t,o,s)=>{let u=await(0,m.createModule)({listener:o.listener,handler:o.
|
|
5
|
+
handler,version:r.version,variables:{...r.variables,...e.variables,...o.variables}}),
|
|
6
|
+
n=e.services&&t.makeClients(e.services),a,c={requestId:(0,v.getRandomUUID)()};try{
|
|
7
|
+
await(0,m.onBegin)(u,n,c),a={...c,message:s},await(0,m.onReady)(u,n,a),await u.handler(
|
|
8
|
+
a,n)}catch(d){await(0,m.onError)(u,n,a??c,d)}finally{await(0,m.onEnd)(u,n,c)}},"\
|
|
9
|
+
processLambdaMessage");var p=require("@ez4/project/library"),Q=require("@ez4/queue/utils");var h=i((e,r,t)=>{let o=(0,p.getServiceName)(e,t),s=`http://${t.serviceHost}/${o}`;
|
|
10
|
+
return new class{async sendMessage(u){p.Logger.log(`\u2709\uFE0F Sending message to Queue\
|
|
11
|
+
[${e}] at ${s}`);let n=await(0,Q.getJsonStringMessage)(u,r);try{(await fetch(s,
|
|
12
|
+
{method:"POST",body:n,headers:{"content-type":"application/json"}})).ok||p.Logger.
|
|
13
|
+
error(`Queue [${e}] isn't available.`)}catch(a){p.Logger.error(`${a}`)}}async receiveMessage(){
|
|
14
|
+
throw new Error("Receive message isn't supported yet.")}}},"createQueueClient");var E=i((e,r,t)=>{let{name:o,schema:s}=e;return{type:"Queue",name:o,identifier:(0,b.getServiceName)(
|
|
15
|
+
o,r),clientHandler:i(()=>h(o,s,r),"clientHandler"),requestHandler:i(u=>j(e,r,t,u),
|
|
16
|
+
"requestHandler")}},"registerQueueServices"),j=i(async(e,r,t,o)=>{let{method:s,path:u,
|
|
17
|
+
body:n}=o;if(s!=="POST"||u!=="/"||!n)throw new Error("Unsupported queue request.");
|
|
18
|
+
try{let a=(0,q.getRandomInteger)(0,e.subscriptions.length-1),c=e.subscriptions[a],
|
|
19
|
+
d=JSON.parse(n.toString()),x=await(0,S.getJsonMessage)(d,e.schema);return c&&await y(
|
|
20
|
+
e,r,t,c,x),(0,f.getResponseSuccess)(201)}catch(a){if(!(a instanceof S.MalformedMessageError))
|
|
21
|
+
throw a;return(0,f.getResponseError)(400,{message:a.message,details:a.details})}},
|
|
22
|
+
"handleQueueMessage");var w=!1,$=i(()=>{w||((0,l.registerTriggers)(),(0,M.createTrigger)("@ez4/local-q\
|
|
23
|
+
ueue",{"emulator:getServices":i(({service:e,options:r,context:t})=>(0,l.isQueueService)(
|
|
24
|
+
e)||(0,l.isQueueImport)(e)?E(e,r,t):null,"emulator:getServices")}),w=!0)},"regis\
|
|
25
|
+
terTriggers");0&&(module.exports={registerTriggers});
|
|
21
26
|
//# sourceMappingURL=main.cjs.map
|
package/dist/main.mjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
import{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
var v=Object.defineProperty;var o=(e,r)=>v(e,"name",{value:r,configurable:!0});import{isQueueImport as j,isQueueService as $,registerTriggers as H}from"@ez4/queue/library";
|
|
2
|
+
import{createTrigger as J}from"@ez4/project/library";import{getServiceName as x}from"@ez4/project/library";import{getJsonMessage as I,
|
|
3
|
+
MalformedMessageError as R}from"@ez4/queue/utils";import{getResponseError as C,getResponseSuccess as z}from"@ez4/local-common";
|
|
4
|
+
import{getRandomInteger as T}from"@ez4/utils";import{createModule as y,onBegin as Q,onEnd as h,onError as b,onReady as q}from"@ez4/local-common";
|
|
5
|
+
import{getRandomUUID as E}from"@ez4/utils";var l=o(async(e,r,i,s,n)=>{let a=await y({listener:s.listener,handler:s.handler,
|
|
6
|
+
version:r.version,variables:{...r.variables,...e.variables,...s.variables}}),u=e.
|
|
7
|
+
services&&i.makeClients(e.services),t,m={requestId:E()};try{await Q(a,u,m),t={...m,
|
|
8
|
+
message:n},await q(a,u,t),await a.handler(t,u)}catch(c){await b(a,u,t??m,c)}finally{
|
|
9
|
+
await h(a,u,m)}},"processLambdaMessage");import{getServiceName as w,Logger as p}from"@ez4/project/library";import{getJsonStringMessage as M}from"@ez4/queue/utils";var g=o((e,r,i)=>{let s=w(e,i),n=`http://${i.serviceHost}/${s}`;return new class{async sendMessage(a){
|
|
10
|
+
p.log(`\u2709\uFE0F Sending message to Queue [${e}] at ${n}`);let u=await M(a,r);
|
|
11
|
+
try{(await fetch(n,{method:"POST",body:u,headers:{"content-type":"application/js\
|
|
12
|
+
on"}})).ok||p.error(`Queue [${e}] isn't available.`)}catch(t){p.error(`${t}`)}}async receiveMessage(){
|
|
13
|
+
throw new Error("Receive message isn't supported yet.")}}},"createQueueClient");var S=o((e,r,i)=>{let{name:s,schema:n}=e;return{type:"Queue",name:s,identifier:x(
|
|
14
|
+
s,r),clientHandler:o(()=>g(s,n,r),"clientHandler"),requestHandler:o(a=>O(e,r,i,a),
|
|
15
|
+
"requestHandler")}},"registerQueueServices"),O=o(async(e,r,i,s)=>{let{method:n,path:a,
|
|
16
|
+
body:u}=s;if(n!=="POST"||a!=="/"||!u)throw new Error("Unsupported queue request.");
|
|
17
|
+
try{let t=T(0,e.subscriptions.length-1),m=e.subscriptions[t],c=JSON.parse(u.toString()),
|
|
18
|
+
d=await I(c,e.schema);return m&&await l(e,r,i,m,d),z(201)}catch(t){if(!(t instanceof
|
|
19
|
+
R))throw t;return C(400,{message:t.message,details:t.details})}},"handleQueueMes\
|
|
20
|
+
sage");var f=!1,se=o(()=>{f||(H(),J("@ez4/local-queue",{"emulator:getServices":o(({service:e,
|
|
21
|
+
options:r,context:i})=>$(e)||j(e)?S(e,r,i):null,"emulator:getServices")}),f=!0)},
|
|
22
|
+
"registerTriggers");export{se as registerTriggers};
|
|
18
23
|
//# sourceMappingURL=main.mjs.map
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { EmulateServiceContext, EmulatorServiceRequest, ServeOptions } from '@ez4/project/library';
|
|
2
|
-
import type { QueueService } from '@ez4/queue/library';
|
|
3
|
-
|
|
4
|
-
export declare const registerQueueServices: (service: QueueService, options: ServeOptions, context: EmulateServiceContext) => {
|
|
2
|
+
import type { QueueImport, QueueService } from '@ez4/queue/library';
|
|
3
|
+
export declare const registerQueueServices: (service: QueueService | QueueImport, options: ServeOptions, context: EmulateServiceContext) => {
|
|
5
4
|
type: string;
|
|
6
5
|
name: string;
|
|
7
6
|
identifier: string;
|
|
8
|
-
clientHandler: () => import("@ez4/queue").Client<Queue.Service<any>>;
|
|
7
|
+
clientHandler: () => import("@ez4/queue").Client<import("@ez4/queue").Queue.Service<any>>;
|
|
9
8
|
requestHandler: (request: EmulatorServiceRequest) => Promise<{
|
|
9
|
+
body?: string | undefined;
|
|
10
10
|
status: number;
|
|
11
|
+
headers: {
|
|
12
|
+
"content-type"?: string | undefined;
|
|
13
|
+
};
|
|
11
14
|
}>;
|
|
12
15
|
};
|
package/dist/service/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Client, Queue } from '@ez4/queue';
|
|
2
1
|
import type { ServeOptions } from '@ez4/project/library';
|
|
3
2
|
import type { MessageSchema } from '@ez4/queue/utils';
|
|
3
|
+
import type { Client, Queue } from '@ez4/queue';
|
|
4
4
|
export declare const createQueueClient: <T extends Queue.Service<any>>(serviceName: string, messageSchema: MessageSchema, serveOptions: ServeOptions) => Client<T>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/local-queue",
|
|
3
3
|
"description": "EZ4: Local queue emulator",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.24.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"providers/local/*"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
+
"lint": "eslint --cache",
|
|
32
33
|
"clean": "rm -f *.tsbuildinfo && rm -rf dist/*",
|
|
33
34
|
"build": "tsc -p tsconfig.json && node tools/bundler.mjs",
|
|
34
35
|
"test": "npm run test:types && node --test --import ../../../tools/tsnode.mjs test/*.spec.ts",
|
|
@@ -39,10 +40,10 @@
|
|
|
39
40
|
"live:publish": "npm run test && npm publish --access public"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@ez4/common": "^0.
|
|
43
|
-
"@ez4/local-common": "^0.
|
|
44
|
-
"@ez4/project": "^0.
|
|
45
|
-
"@ez4/queue": "^0.
|
|
46
|
-
"@ez4/utils": "^0.
|
|
43
|
+
"@ez4/common": "^0.24.0",
|
|
44
|
+
"@ez4/local-common": "^0.24.0",
|
|
45
|
+
"@ez4/project": "^0.24.0",
|
|
46
|
+
"@ez4/queue": "^0.24.0",
|
|
47
|
+
"@ez4/utils": "^0.24.0"
|
|
47
48
|
}
|
|
48
49
|
}
|