@push-rpc/next 2.0.12 → 2.0.14
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/client/HttpClient.d.ts +11 -0
- package/dist/client/HttpClient.js +84 -0
- package/dist/client/HttpClient.js.map +1 -0
- package/dist/client/RemoteSubscriptions.d.ts +18 -0
- package/dist/client/RemoteSubscriptions.js +120 -0
- package/dist/client/RemoteSubscriptions.js.map +1 -0
- package/dist/client/RpcClientImpl.d.ts +22 -0
- package/dist/client/RpcClientImpl.js +121 -0
- package/dist/client/RpcClientImpl.js.map +1 -0
- package/dist/client/WebSocketConnection.d.ts +36 -0
- package/dist/client/WebSocketConnection.js +161 -0
- package/dist/client/WebSocketConnection.js.map +1 -0
- package/dist/client/index.d.ts +29 -0
- package/dist/client/index.js +39 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/remote.d.ts +14 -0
- package/dist/client/remote.js +66 -0
- package/dist/client/remote.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +9 -0
- package/dist/logger.js.map +1 -0
- package/dist/rpc.d.ts +37 -0
- package/dist/rpc.js +33 -0
- package/dist/rpc.js.map +1 -0
- package/dist/server/ConnectionsServer.d.ts +13 -0
- package/dist/server/ConnectionsServer.js +72 -0
- package/dist/server/ConnectionsServer.js.map +1 -0
- package/dist/server/LocalSubscriptions.d.ts +12 -0
- package/dist/server/LocalSubscriptions.js +113 -0
- package/dist/server/LocalSubscriptions.js.map +1 -0
- package/dist/server/RpcServerImpl.d.ts +24 -0
- package/dist/server/RpcServerImpl.js +200 -0
- package/dist/server/RpcServerImpl.js.map +1 -0
- package/dist/server/http.d.ts +9 -0
- package/dist/server/http.js +93 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/index.d.ts +32 -0
- package/dist/server/index.js +33 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/local.d.ts +15 -0
- package/dist/server/local.js +46 -0
- package/dist/server/local.js.map +1 -0
- package/dist/utils/cookies.d.ts +7 -0
- package/dist/utils/cookies.js +31 -0
- package/dist/utils/cookies.js.map +1 -0
- package/dist/utils/env.d.ts +6 -0
- package/dist/utils/env.js +22 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/json.d.ts +2 -0
- package/dist/utils/json.js +34 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/middleware.d.ts +2 -0
- package/dist/utils/middleware.js +34 -0
- package/dist/utils/middleware.js.map +1 -0
- package/dist/utils/promises.d.ts +5 -0
- package/dist/utils/promises.js +29 -0
- package/dist/utils/promises.js.map +1 -0
- package/dist/utils/server.d.ts +5 -0
- package/dist/utils/server.js +48 -0
- package/dist/utils/server.js.map +1 -0
- package/dist/utils/throttle.d.ts +4 -0
- package/dist/utils/throttle.js +40 -0
- package/dist/utils/throttle.js.map +1 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.js +3 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +1 -1
- package/src/client/HttpClient.ts +5 -4
- package/src/server/http.ts +10 -5
- package/package-lock.json +0 -1291
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adelay = exports.PromiseCache = void 0;
|
|
4
|
+
class PromiseCache {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.cache = {};
|
|
7
|
+
}
|
|
8
|
+
invoke(cacheKey, supplier) {
|
|
9
|
+
const key = JSON.stringify(cacheKey);
|
|
10
|
+
if (!this.cache[key]) {
|
|
11
|
+
this.cache[key] = supplier()
|
|
12
|
+
.then((r) => {
|
|
13
|
+
delete this.cache[key];
|
|
14
|
+
return r;
|
|
15
|
+
})
|
|
16
|
+
.catch((e) => {
|
|
17
|
+
delete this.cache[key];
|
|
18
|
+
throw e;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return this.cache[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PromiseCache = PromiseCache;
|
|
25
|
+
async function adelay(ms) {
|
|
26
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
27
|
+
}
|
|
28
|
+
exports.adelay = adelay;
|
|
29
|
+
//# sourceMappingURL=promises.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promises.js","sourceRoot":"","sources":["../../src/utils/promises.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAAzB;QAmBU,UAAK,GAAkC,EAAE,CAAA;IACnD,CAAC;IAnBC,MAAM,CAAI,QAAiB,EAAE,QAA0B;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;QAEpC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE;iBACzB,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;gBACV,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACtB,OAAO,CAAC,CAAA;YACV,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACtB,MAAM,CAAC,CAAA;YACT,CAAC,CAAC,CAAA;QACN,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;CAGF;AApBD,oCAoBC;AAEM,KAAK,UAAU,MAAM,CAAC,EAAU;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAC9C,CAAC;AAFD,wBAEC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.decompressRequest = void 0;
|
|
27
|
+
const zlib = __importStar(require("zlib"));
|
|
28
|
+
const stream_1 = require("stream");
|
|
29
|
+
function decompressRequest(request) {
|
|
30
|
+
const contentEncoding = (request.headers["content-encoding"] || "").toLowerCase();
|
|
31
|
+
if (!["gzip", "deflate", "br"].includes(contentEncoding)) {
|
|
32
|
+
return request;
|
|
33
|
+
}
|
|
34
|
+
const isBrotli = contentEncoding === "br";
|
|
35
|
+
const decompress = isBrotli ? zlib.createBrotliDecompress() : zlib.createUnzip();
|
|
36
|
+
const stream = new stream_1.PassThrough();
|
|
37
|
+
decompress.on("error", (error) => {
|
|
38
|
+
// Ignore empty request
|
|
39
|
+
if (error.code === "Z_BUF_ERROR") {
|
|
40
|
+
stream.end();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
stream.emit("error", error);
|
|
44
|
+
});
|
|
45
|
+
return (0, stream_1.pipeline)(request, decompress, stream, () => { });
|
|
46
|
+
}
|
|
47
|
+
exports.decompressRequest = decompressRequest;
|
|
48
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/utils/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA4B;AAC5B,mCAAmF;AAGnF,SAAgB,iBAAiB,CAAC,OAA6B;IAC7D,MAAM,eAAe,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;IAEjF,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;QACzD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,MAAM,QAAQ,GAAG,eAAe,KAAK,IAAI,CAAA;IAEzC,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAA;IAChF,MAAM,MAAM,GAAG,IAAI,oBAAiB,EAAE,CAAA;IAEtC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAU,EAAE,EAAE;QACpC,uBAAuB;QACvB,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,EAAE,CAAA;YACZ,OAAM;QACR,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,OAAO,IAAA,iBAAc,EAAC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;AAC9D,CAAC;AAvBD,8CAuBC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type ThrottleArgsReducer<D> = (prevValue: D, newValue: D) => D;
|
|
2
|
+
export declare function lastValueReducer<D>(prevValue: D, newValue: D): D;
|
|
3
|
+
export declare function groupReducer<D>(prevValue: D[], newValue: D[]): D[];
|
|
4
|
+
export declare function throttle<D>(callback: (d: D) => void, delay: number, reducer: ThrottleArgsReducer<D>): (d: D) => void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throttle = exports.groupReducer = exports.lastValueReducer = void 0;
|
|
4
|
+
function lastValueReducer(prevValue, newValue) {
|
|
5
|
+
return newValue;
|
|
6
|
+
}
|
|
7
|
+
exports.lastValueReducer = lastValueReducer;
|
|
8
|
+
function groupReducer(prevValue, newValue) {
|
|
9
|
+
if (!Array.isArray(newValue))
|
|
10
|
+
throw new Error("groupReducer should only be used with topics that return arrays");
|
|
11
|
+
return prevValue ? [...prevValue, ...newValue] : newValue;
|
|
12
|
+
}
|
|
13
|
+
exports.groupReducer = groupReducer;
|
|
14
|
+
function throttle(callback, delay, reducer) {
|
|
15
|
+
let timer;
|
|
16
|
+
let lastExec = 0;
|
|
17
|
+
let reducedArg;
|
|
18
|
+
function wrapper(d) {
|
|
19
|
+
let self = this;
|
|
20
|
+
let elapsed = Date.now() - lastExec;
|
|
21
|
+
function exec() {
|
|
22
|
+
lastExec = Date.now();
|
|
23
|
+
callback.call(self, reducedArg);
|
|
24
|
+
reducedArg = undefined;
|
|
25
|
+
}
|
|
26
|
+
if (timer) {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
}
|
|
29
|
+
reducedArg = reducer(reducedArg, d);
|
|
30
|
+
if (elapsed > delay) {
|
|
31
|
+
exec();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
timer = setTimeout(exec, delay - elapsed);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return wrapper;
|
|
38
|
+
}
|
|
39
|
+
exports.throttle = throttle;
|
|
40
|
+
//# sourceMappingURL=throttle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/utils/throttle.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAAI,SAAY,EAAE,QAAW;IAC3D,OAAO,QAAQ,CAAA;AACjB,CAAC;AAFD,4CAEC;AAED,SAAgB,YAAY,CAAI,SAAc,EAAE,QAAa;IAC3D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAA;IAEpF,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AAC3D,CAAC;AALD,oCAKC;AAED,SAAgB,QAAQ,CACtB,QAAwB,EACxB,KAAa,EACb,OAA+B;IAE/B,IAAI,KAAqB,CAAA;IACzB,IAAI,QAAQ,GAAG,CAAC,CAAA;IAEhB,IAAI,UAAe,CAAA;IAEnB,SAAS,OAAO,CAAY,CAAI;QAC9B,IAAI,IAAI,GAAG,IAAI,CAAA;QACf,IAAI,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAA;QAEnC,SAAS,IAAI;YACX,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACrB,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;YAC/B,UAAU,GAAG,SAAS,CAAA;QACxB,CAAC;QAED,IAAI,KAAK,EAAE,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;QAED,UAAU,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;QAEnC,IAAI,OAAO,GAAG,KAAK,EAAE,CAAC;YACpB,IAAI,EAAE,CAAA;QACR,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,CAAA;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAlCD,4BAkCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ExtractPromiseResult<Type> = Type extends Promise<infer X> ? X : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/client/HttpClient.ts
CHANGED
|
@@ -5,8 +5,9 @@ export class HttpClient {
|
|
|
5
5
|
constructor(
|
|
6
6
|
private url: string,
|
|
7
7
|
private clientId: string,
|
|
8
|
-
private getHeaders: () => Promise<Record<string, string
|
|
9
|
-
) {
|
|
8
|
+
private getHeaders: () => Promise<Record<string, string>>,
|
|
9
|
+
) {
|
|
10
|
+
}
|
|
10
11
|
|
|
11
12
|
async call(itemName: string, params: unknown[], callTimeout: number): Promise<unknown> {
|
|
12
13
|
return this.httpRequest("POST", itemName, params, callTimeout, await this.getHeaders())
|
|
@@ -29,7 +30,7 @@ export class HttpClient {
|
|
|
29
30
|
itemName: string,
|
|
30
31
|
params: unknown[],
|
|
31
32
|
callTimeout: number,
|
|
32
|
-
headers: Record<string, string
|
|
33
|
+
headers: Record<string, string>,
|
|
33
34
|
): Promise<unknown> {
|
|
34
35
|
const itemUrl = this.getItemUrl(itemName)
|
|
35
36
|
|
|
@@ -61,7 +62,7 @@ export class HttpClient {
|
|
|
61
62
|
contentType && contentType.includes("application/json") ? safeParseJson(text) : text
|
|
62
63
|
|
|
63
64
|
if (response.status < 200 || response.status >= 300) {
|
|
64
|
-
const error = new Error(response.
|
|
65
|
+
const error = new Error(response.headers.get("x-error") ?? undefined)
|
|
65
66
|
|
|
66
67
|
Object.assign(error, {code: response.status})
|
|
67
68
|
|
package/src/server/http.ts
CHANGED
|
@@ -10,7 +10,7 @@ export async function serveHttpRequest(
|
|
|
10
10
|
res: ServerResponse,
|
|
11
11
|
path: string,
|
|
12
12
|
hooks: HttpServerHooks,
|
|
13
|
-
createConnectionContext: (req: IncomingMessage) => Promise<RpcConnectionContext
|
|
13
|
+
createConnectionContext: (req: IncomingMessage) => Promise<RpcConnectionContext>,
|
|
14
14
|
) {
|
|
15
15
|
// if port is in options - response 404 on other URLs
|
|
16
16
|
// oherwise just handle request
|
|
@@ -65,7 +65,10 @@ export async function serveHttpRequest(
|
|
|
65
65
|
} catch (e: any) {
|
|
66
66
|
if (e.code) {
|
|
67
67
|
res.statusCode = e.code
|
|
68
|
-
|
|
68
|
+
|
|
69
|
+
if (e.message) {
|
|
70
|
+
res.setHeader("X-Error", e["message"])
|
|
71
|
+
}
|
|
69
72
|
const {code, message, stack, ...rest} = e
|
|
70
73
|
if (Object.keys(rest).length > 0) {
|
|
71
74
|
res.setHeader("Content-Type", "application/json")
|
|
@@ -77,7 +80,9 @@ export async function serveHttpRequest(
|
|
|
77
80
|
log.warn(`Error in ${req.url}.`, e)
|
|
78
81
|
|
|
79
82
|
res.statusCode = 500
|
|
80
|
-
|
|
83
|
+
if (e["message"]) {
|
|
84
|
+
res.setHeader("X-Error", e["message"])
|
|
85
|
+
}
|
|
81
86
|
res.end()
|
|
82
87
|
return
|
|
83
88
|
}
|
|
@@ -107,11 +112,11 @@ export type HttpServerHooks = {
|
|
|
107
112
|
subscribe(
|
|
108
113
|
clientId: RpcConnectionContext,
|
|
109
114
|
itemName: string,
|
|
110
|
-
parameters: unknown[]
|
|
115
|
+
parameters: unknown[],
|
|
111
116
|
): Promise<unknown>
|
|
112
117
|
unsubscribe(
|
|
113
118
|
clientId: RpcConnectionContext,
|
|
114
119
|
itemName: string,
|
|
115
|
-
parameters: unknown[]
|
|
120
|
+
parameters: unknown[],
|
|
116
121
|
): Promise<unknown>
|
|
117
122
|
}
|