@restatedev/restate-sdk 0.7.0 → 0.7.2-worker
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/cloudflare_bundle.js +26133 -0
- package/dist/io/encoder.d.ts +2 -1
- package/dist/io/encoder.d.ts.map +1 -1
- package/package.json +6 -3
- package/dist/connection/buffered_connection.js +0 -44
- package/dist/connection/buffered_connection.js.map +0 -1
- package/dist/connection/connection.js +0 -13
- package/dist/connection/connection.js.map +0 -1
- package/dist/connection/embedded_connection.js +0 -59
- package/dist/connection/embedded_connection.js.map +0 -1
- package/dist/connection/http_connection.js +0 -203
- package/dist/connection/http_connection.js.map +0 -1
- package/dist/connection/lambda_connection.js +0 -58
- package/dist/connection/lambda_connection.js.map +0 -1
- package/dist/embedded/api.js +0 -35
- package/dist/embedded/api.js.map +0 -1
- package/dist/embedded/handler.js +0 -28
- package/dist/embedded/handler.js.map +0 -1
- package/dist/embedded/http2_remote.js +0 -91
- package/dist/embedded/http2_remote.js.map +0 -1
- package/dist/embedded/invocation.js +0 -94
- package/dist/embedded/invocation.js.map +0 -1
- package/dist/generated/dev/restate/events.js +0 -371
- package/dist/generated/dev/restate/events.js.map +0 -1
- package/dist/generated/dev/restate/ext.js +0 -215
- package/dist/generated/dev/restate/ext.js.map +0 -1
- package/dist/generated/google/protobuf/descriptor.js +0 -6676
- package/dist/generated/google/protobuf/descriptor.js.map +0 -1
- package/dist/generated/google/protobuf/empty.js +0 -107
- package/dist/generated/google/protobuf/empty.js.map +0 -1
- package/dist/generated/google/protobuf/struct.js +0 -754
- package/dist/generated/google/protobuf/struct.js.map +0 -1
- package/dist/generated/proto/discovery.js +0 -364
- package/dist/generated/proto/discovery.js.map +0 -1
- package/dist/generated/proto/dynrpc.js +0 -668
- package/dist/generated/proto/dynrpc.js.map +0 -1
- package/dist/generated/proto/javascript.js +0 -297
- package/dist/generated/proto/javascript.js.map +0 -1
- package/dist/generated/proto/protocol.js +0 -2398
- package/dist/generated/proto/protocol.js.map +0 -1
- package/dist/generated/proto/services.js +0 -1535
- package/dist/generated/proto/services.js.map +0 -1
- package/dist/generated/proto/test.js +0 -321
- package/dist/generated/proto/test.js.map +0 -1
- package/dist/invocation.js +0 -154
- package/dist/invocation.js.map +0 -1
- package/dist/io/decoder.js +0 -133
- package/dist/io/decoder.js.map +0 -1
- package/dist/io/encoder.js +0 -68
- package/dist/io/encoder.js.map +0 -1
- package/dist/journal.js +0 -372
- package/dist/journal.js.map +0 -1
- package/dist/local_state_store.js +0 -72
- package/dist/local_state_store.js.map +0 -1
- package/dist/public_api.js +0 -58
- package/dist/public_api.js.map +0 -1
- package/dist/restate_context.js +0 -46
- package/dist/restate_context.js.map +0 -1
- package/dist/restate_context_impl.js +0 -375
- package/dist/restate_context_impl.js.map +0 -1
- package/dist/server/base_restate_server.js +0 -364
- package/dist/server/base_restate_server.js.map +0 -1
- package/dist/server/restate_lambda_handler.js +0 -247
- package/dist/server/restate_lambda_handler.js.map +0 -1
- package/dist/server/restate_server.js +0 -186
- package/dist/server/restate_server.js.map +0 -1
- package/dist/state_machine.js +0 -403
- package/dist/state_machine.js.map +0 -1
- package/dist/types/errors.js +0 -267
- package/dist/types/errors.js.map +0 -1
- package/dist/types/grpc.js +0 -68
- package/dist/types/grpc.js.map +0 -1
- package/dist/types/protocol.js +0 -125
- package/dist/types/protocol.js.map +0 -1
- package/dist/types/router.js +0 -36
- package/dist/types/router.js.map +0 -1
- package/dist/types/types.js +0 -126
- package/dist/types/types.js.map +0 -1
- package/dist/utils/assumpsions.js +0 -101
- package/dist/utils/assumpsions.js.map +0 -1
- package/dist/utils/logger.js +0 -102
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/public_utils.js +0 -49
- package/dist/utils/public_utils.js.map +0 -1
- package/dist/utils/rand.js +0 -114
- package/dist/utils/rand.js.map +0 -1
- package/dist/utils/utils.js +0 -144
- package/dist/utils/utils.js.map +0 -1
package/dist/io/encoder.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import stream from "stream";
|
|
3
4
|
import { Message } from "../types/types";
|
|
4
5
|
export declare function streamEncoder(): stream.Transform;
|
|
5
6
|
export declare function encodeMessage(msg: Message): Uint8Array;
|
|
6
|
-
export declare function encodeMessages(messages: Message[]):
|
|
7
|
+
export declare function encodeMessages(messages: Message[]): Buffer;
|
|
7
8
|
//# sourceMappingURL=encoder.d.ts.map
|
package/dist/io/encoder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/io/encoder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/io/encoder.ts"],"names":[],"mappings":";;AAWA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAU,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGjD,wBAAgB,aAAa,IAAI,MAAM,CAAC,SAAS,CAYhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAEtD;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,CA2C1D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restatedev/restate-sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-worker",
|
|
4
4
|
"description": "Typescript SDK for Restate",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">= 10"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@restatedev:registry": "https://registry.npmjs.org"
|
|
25
25
|
},
|
|
26
26
|
"type": "commonjs",
|
|
27
|
-
"main": "dist/
|
|
27
|
+
"main": "dist/cloudflare_bundle.js",
|
|
28
28
|
"types": "dist/public_api.d.ts",
|
|
29
29
|
"author": "Restate Developers",
|
|
30
30
|
"license": "MIT",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"proto": "npx buf mod update && npx buf generate",
|
|
34
34
|
"build": "tsc --noEmitOnError",
|
|
35
|
+
"build-worker": "tsc --emitDeclarationOnly --noEmitOnError && node build-worker.mjs",
|
|
35
36
|
"test": "jest --silent --maxWorkers=1",
|
|
36
37
|
"lint": "eslint --ignore-path .eslintignore --ext .ts .",
|
|
37
38
|
"format": "prettier --ignore-path .eslintignore --write \"**/*.+(js|ts|json)\"",
|
|
@@ -62,7 +63,9 @@
|
|
|
62
63
|
"ts-jest": "^29.0.5",
|
|
63
64
|
"ts-node-dev": "^2.0.0",
|
|
64
65
|
"typescript": "^4.9.5",
|
|
65
|
-
"express": "*"
|
|
66
|
+
"express": "*",
|
|
67
|
+
"esbuild": "^0.20.1",
|
|
68
|
+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3"
|
|
66
69
|
},
|
|
67
70
|
"bugs": {
|
|
68
71
|
"url": "https://github.com/restatedev/sdk-typescript/issues"
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BufferedConnection = void 0;
|
|
4
|
-
const encoder_1 = require("../io/encoder");
|
|
5
|
-
class BufferedConnection {
|
|
6
|
-
flushFn;
|
|
7
|
-
queue = [];
|
|
8
|
-
flushing = Promise.resolve();
|
|
9
|
-
constructor(flushFn) {
|
|
10
|
-
this.flushFn = flushFn;
|
|
11
|
-
}
|
|
12
|
-
send(msg) {
|
|
13
|
-
const len = this.queue.push(msg);
|
|
14
|
-
if (len === 1) {
|
|
15
|
-
// we are the first in line, therefore we schedule a flush,
|
|
16
|
-
// BUT we must wait for the previous flush to end.
|
|
17
|
-
this.flushing = this.flushing.then(() => this.scheduleFlush());
|
|
18
|
-
}
|
|
19
|
-
// we don't need to reschedule the `flush` here,
|
|
20
|
-
// because the flush happens anyway at the end of the current event loop iteration.
|
|
21
|
-
// tag along to the previously scheduled flush.
|
|
22
|
-
return this.flushing;
|
|
23
|
-
}
|
|
24
|
-
end() {
|
|
25
|
-
this.flushing = this.flushing.then(() => this.flush());
|
|
26
|
-
return this.flushing;
|
|
27
|
-
}
|
|
28
|
-
scheduleFlush() {
|
|
29
|
-
// schedule a flush at the end of the current event loop iteration.
|
|
30
|
-
return new Promise((resolve, reject) => setImmediate(() => {
|
|
31
|
-
this.flush().then(resolve).catch(reject);
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
async flush() {
|
|
35
|
-
if (this.queue.length === 0) {
|
|
36
|
-
return Promise.resolve();
|
|
37
|
-
}
|
|
38
|
-
const buffer = (0, encoder_1.encodeMessages)(this.queue);
|
|
39
|
-
this.queue = [];
|
|
40
|
-
return this.flushFn(buffer);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.BufferedConnection = BufferedConnection;
|
|
44
|
-
//# sourceMappingURL=buffered_connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buffered_connection.js","sourceRoot":"","sources":["../../src/connection/buffered_connection.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAI/C,MAAa,kBAAkB;IAIA;IAHrB,KAAK,GAAc,EAAE,CAAC;IACtB,QAAQ,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAEpD,YAA6B,OAA0C;QAA1C,YAAO,GAAP,OAAO,CAAmC;IAAG,CAAC;IAE3E,IAAI,CAAC,GAAY;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,GAAG,KAAK,CAAC,EAAE;YACb,2DAA2D;YAC3D,kDAAkD;YAClD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;SAChE;QACD,gDAAgD;QAChD,mFAAmF;QACnF,+CAA+C;QAC/C,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,GAAG;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,mEAAmE;QACnE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACrC,YAAY,CAAC,GAAG,EAAE;YAChB,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,KAAK;QACjB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC3B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QACD,MAAM,MAAM,GAAG,IAAA,wBAAc,EAAC,IAAI,CAAC,KAAK,CAAW,CAAC;QACpD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAEhB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF;AA1CD,gDA0CC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection/connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.EmbeddedConnection = exports.InvocationAlreadyCompletedError = exports.FencedOffError = void 0;
|
|
14
|
-
const buffered_connection_1 = require("./buffered_connection");
|
|
15
|
-
class FencedOffError extends Error {
|
|
16
|
-
constructor() {
|
|
17
|
-
super("FencedOff");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.FencedOffError = FencedOffError;
|
|
21
|
-
class InvocationAlreadyCompletedError extends Error {
|
|
22
|
-
constructor() {
|
|
23
|
-
super("Completed");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.InvocationAlreadyCompletedError = InvocationAlreadyCompletedError;
|
|
27
|
-
class EmbeddedConnection {
|
|
28
|
-
operationId;
|
|
29
|
-
streamId;
|
|
30
|
-
remote;
|
|
31
|
-
buffered;
|
|
32
|
-
constructor(operationId, streamId, remote) {
|
|
33
|
-
this.operationId = operationId;
|
|
34
|
-
this.streamId = streamId;
|
|
35
|
-
this.remote = remote;
|
|
36
|
-
this.buffered = new buffered_connection_1.BufferedConnection((buffer) => this.sendBuffer(buffer));
|
|
37
|
-
}
|
|
38
|
-
send(msg) {
|
|
39
|
-
return this.buffered.send(msg);
|
|
40
|
-
}
|
|
41
|
-
end() {
|
|
42
|
-
return this.buffered.end();
|
|
43
|
-
}
|
|
44
|
-
async sendBuffer(buffer) {
|
|
45
|
-
const res = await this.remote.send({
|
|
46
|
-
operationId: this.operationId,
|
|
47
|
-
streamId: this.streamId,
|
|
48
|
-
messages: buffer,
|
|
49
|
-
});
|
|
50
|
-
if (res.invalidStream !== undefined) {
|
|
51
|
-
throw new FencedOffError();
|
|
52
|
-
}
|
|
53
|
-
if (res.invocationCompleted !== undefined) {
|
|
54
|
-
throw new InvocationAlreadyCompletedError();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.EmbeddedConnection = EmbeddedConnection;
|
|
59
|
-
//# sourceMappingURL=embedded_connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"embedded_connection.js","sourceRoot":"","sources":["../../src/connection/embedded_connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAIH,+DAA2D;AAG3D,MAAa,cAAe,SAAQ,KAAK;IACvC;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;CACF;AAJD,wCAIC;AAED,MAAa,+BAAgC,SAAQ,KAAK;IACxD;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;CACF;AAJD,0EAIC;AAED,MAAa,kBAAkB;IAIV;IACA;IACA;IALX,QAAQ,CAAqB;IAErC,YACmB,WAAmB,EACnB,QAAgB,EAChB,MAAqB;QAFrB,gBAAW,GAAX,WAAW,CAAQ;QACnB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAe;QAEtC,IAAI,CAAC,QAAQ,GAAG,IAAI,wCAAkB,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,CAAC,GAAY;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAC7B,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,MAAc;QACrC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACjC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QAEH,IAAI,GAAG,CAAC,aAAa,KAAK,SAAS,EAAE;YACnC,MAAM,IAAI,cAAc,EAAE,CAAC;SAC5B;QACD,IAAI,GAAG,CAAC,mBAAmB,KAAK,SAAS,EAAE;YACzC,MAAM,IAAI,+BAA+B,EAAE,CAAC;SAC7C;IACH,CAAC;CACF;AAjCD,gDAiCC"}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.RestateHttp2Connection = void 0;
|
|
14
|
-
const decoder_1 = require("../io/decoder");
|
|
15
|
-
const logger_1 = require("../utils/logger");
|
|
16
|
-
const promises_1 = require("stream/promises");
|
|
17
|
-
const buffered_connection_1 = require("./buffered_connection");
|
|
18
|
-
// utility promise, for cases where we want to save allocation of an extra promise
|
|
19
|
-
const RESOLVED = Promise.resolve();
|
|
20
|
-
/**
|
|
21
|
-
* A duplex stream with Restate Messages over HTTP2.
|
|
22
|
-
*
|
|
23
|
-
* This stream handles the following concerns:
|
|
24
|
-
*
|
|
25
|
-
* (1) encoding and decoding of messages from and from raw bytes
|
|
26
|
-
*
|
|
27
|
-
* (2) buffering the outgoing messages, because the call sites that produce (potentially) large
|
|
28
|
-
* messages might not await their transfer. Aside from the fact that we achieve better pipelining
|
|
29
|
-
* that way, we also simply cannot guarantee that users of the Restate SDK actually await the
|
|
30
|
-
* relevant async API methods.
|
|
31
|
-
*
|
|
32
|
-
* This stream essentially buffers messages and, upon flush, sends them asynchronously, as the
|
|
33
|
-
* stream has availability. Flush requests queue up, if new data gets flushed while the previous
|
|
34
|
-
* data is still being sent.
|
|
35
|
-
*
|
|
36
|
-
* (3) Input messages can be pipelined to a sequence of consumers. For example, first to a journal,
|
|
37
|
-
* and afterwards to the state machine.
|
|
38
|
-
*
|
|
39
|
-
* (4) Handling the relevant stream events for errors and consolidating them to one error handler, plus
|
|
40
|
-
* notifications for cleanly closed input (to trigger suspension).
|
|
41
|
-
*/
|
|
42
|
-
class RestateHttp2Connection {
|
|
43
|
-
rawStream;
|
|
44
|
-
/**
|
|
45
|
-
* create a RestateDuplex stream from an http2 (duplex) stream.
|
|
46
|
-
*/
|
|
47
|
-
static from(http2stream) {
|
|
48
|
-
return new RestateHttp2Connection(http2stream);
|
|
49
|
-
}
|
|
50
|
-
// --------------------------------------------------------------------------
|
|
51
|
-
// input as decoded messages
|
|
52
|
-
sdkInput;
|
|
53
|
-
// consumer handling
|
|
54
|
-
currentConsumer = null;
|
|
55
|
-
inputBuffer = [];
|
|
56
|
-
consumerError;
|
|
57
|
-
consumerInputClosed = false;
|
|
58
|
-
outputBuffer;
|
|
59
|
-
constructor(rawStream) {
|
|
60
|
-
this.rawStream = rawStream;
|
|
61
|
-
this.sdkInput = rawStream.pipe((0, decoder_1.streamDecoder)());
|
|
62
|
-
this.outputBuffer = new buffered_connection_1.BufferedConnection((buffer) => {
|
|
63
|
-
const hasMoreCapacity = rawStream.write(buffer);
|
|
64
|
-
if (hasMoreCapacity) {
|
|
65
|
-
return RESOLVED;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
return new Promise((resolve) => rawStream.once("drain", resolve));
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
// remember and forward messages
|
|
72
|
-
this.sdkInput.on("data", (m) => {
|
|
73
|
-
// deliver message, if we have a consumer. otherwise buffer the message.
|
|
74
|
-
if (this.currentConsumer) {
|
|
75
|
-
if (this.currentConsumer.handleMessage(m)) {
|
|
76
|
-
this.removeCurrentConsumer();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.inputBuffer.push(m);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
// remember and forward close events
|
|
84
|
-
this.sdkInput.on("end", () => {
|
|
85
|
-
this.consumerInputClosed = true;
|
|
86
|
-
if (this.currentConsumer) {
|
|
87
|
-
this.currentConsumer.handleInputClosed();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
// --------- error handling --------
|
|
91
|
-
// - a.k.a. node event wrangling...
|
|
92
|
-
// the error handler for all sorts of errors coming from streams
|
|
93
|
-
const errorHandler = (e) => {
|
|
94
|
-
// make sure we don't overwrite the initial error
|
|
95
|
-
if (this.consumerError !== undefined) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
this.consumerError = e;
|
|
99
|
-
if (this.currentConsumer) {
|
|
100
|
-
this.currentConsumer.handleStreamError(e);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
// those two event types should cover all types of connection losses
|
|
104
|
-
rawStream.on("aborted", () => {
|
|
105
|
-
logger_1.rlog.error("Connection to Restate was lost");
|
|
106
|
-
errorHandler(new Error("Connection to Restate was lost"));
|
|
107
|
-
});
|
|
108
|
-
// this is both the raw http2 stream and the output SDK->Restate
|
|
109
|
-
rawStream.on("error", (e) => {
|
|
110
|
-
logger_1.rlog.error("Error in http2 stream to Restate: " + (e.stack ?? e.message));
|
|
111
|
-
errorHandler(e);
|
|
112
|
-
});
|
|
113
|
-
// these events notify of errors in the decoding pipeline
|
|
114
|
-
this.sdkInput.on("error", (e) => {
|
|
115
|
-
logger_1.rlog.error("Error in input stream (Restate to Service): " + (e.stack ?? e.message));
|
|
116
|
-
errorHandler(e);
|
|
117
|
-
});
|
|
118
|
-
// see if streams get torn down before they end cleanly
|
|
119
|
-
this.sdkInput.on("close", () => {
|
|
120
|
-
if (!this.consumerInputClosed) {
|
|
121
|
-
errorHandler(new Error("stream was destroyed before end"));
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
// --------------------------------------------------------------------------
|
|
126
|
-
// input stream handling
|
|
127
|
-
// --------------------------------------------------------------------------
|
|
128
|
-
/**
|
|
129
|
-
* Pipes the messages from this connection to the given consumer. The consumer
|
|
130
|
-
* will also receive error and stream closing notifications.
|
|
131
|
-
*
|
|
132
|
-
* Once the 'handleMessage()' method returns 'true', the consumer is immediately removed.
|
|
133
|
-
* That way, consumers can consume a bounded amount of messages (like just the initial journal).
|
|
134
|
-
*
|
|
135
|
-
* There can only be one consumer at a time.
|
|
136
|
-
*/
|
|
137
|
-
pipeToConsumer(consumer) {
|
|
138
|
-
if (this.currentConsumer !== null) {
|
|
139
|
-
throw new Error("Already piping to a consumer");
|
|
140
|
-
}
|
|
141
|
-
this.currentConsumer = consumer;
|
|
142
|
-
// propagate pre-existing information
|
|
143
|
-
if (this.consumerError) {
|
|
144
|
-
consumer.handleStreamError(this.consumerError);
|
|
145
|
-
}
|
|
146
|
-
if (this.consumerInputClosed) {
|
|
147
|
-
consumer.handleInputClosed();
|
|
148
|
-
}
|
|
149
|
-
// pipe the buffered input messages, if we buffered some before the consumer was registered
|
|
150
|
-
const input = this.inputBuffer;
|
|
151
|
-
if (input.length > 0) {
|
|
152
|
-
let i = 0;
|
|
153
|
-
while (i < input.length) {
|
|
154
|
-
const done = consumer.handleMessage(input[i]);
|
|
155
|
-
i++;
|
|
156
|
-
if (done) {
|
|
157
|
-
this.removeCurrentConsumer();
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
this.inputBuffer = i === input.length ? [] : this.inputBuffer.slice(i);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Removes the current consumer, if there is one.
|
|
166
|
-
*/
|
|
167
|
-
removeCurrentConsumer() {
|
|
168
|
-
this.currentConsumer = null;
|
|
169
|
-
}
|
|
170
|
-
// --------------------------------------------------------------------------
|
|
171
|
-
// output stream handling
|
|
172
|
-
// --------------------------------------------------------------------------
|
|
173
|
-
/**
|
|
174
|
-
* Adds a message to the output stream.
|
|
175
|
-
*
|
|
176
|
-
* This always puts the message into the node stream, but will return a promise that is resolved once
|
|
177
|
-
* further messages can be written.
|
|
178
|
-
*
|
|
179
|
-
* The reasoning is that some, but not all Restate operations return promises and are typically
|
|
180
|
-
* awaited. For example, rpc, sleep, side-effect have promises and are awaited, while one-way-sends and
|
|
181
|
-
* state updates don't return promises.
|
|
182
|
-
*
|
|
183
|
-
* As a pragmatic solution, we always accept messages, but return a promise for when the output has
|
|
184
|
-
* capacity again, so that at least the operations that await results will respect backpressure.
|
|
185
|
-
*/
|
|
186
|
-
send(msg) {
|
|
187
|
-
return this.outputBuffer.send(msg);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Ends the stream, awaiting pending writes.
|
|
191
|
-
*/
|
|
192
|
-
async end() {
|
|
193
|
-
await this.outputBuffer.end();
|
|
194
|
-
this.rawStream.end();
|
|
195
|
-
const options = {
|
|
196
|
-
error: true,
|
|
197
|
-
cleanup: true,
|
|
198
|
-
};
|
|
199
|
-
await (0, promises_1.finished)(this.rawStream, options);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.RestateHttp2Connection = RestateHttp2Connection;
|
|
203
|
-
//# sourceMappingURL=http_connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http_connection.js","sourceRoot":"","sources":["../../src/connection/http_connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAGH,2CAA8C;AAG9C,4CAAuC;AACvC,8CAA2C;AAC3C,+DAA2D;AAE3D,kFAAkF;AAClF,MAAM,QAAQ,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,sBAAsB;IAqBJ;IApB7B;;OAEG;IACI,MAAM,CAAC,IAAI,CAAC,WAA0B;QAC3C,OAAO,IAAI,sBAAsB,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,6EAA6E;IAE7E,4BAA4B;IACX,QAAQ,CAAkB;IAE3C,oBAAoB;IACZ,eAAe,GAAiC,IAAI,CAAC;IACrD,WAAW,GAAc,EAAE,CAAC;IAC5B,aAAa,CAAS;IACtB,mBAAmB,GAAG,KAAK,CAAC;IAE5B,YAAY,CAAqB;IAEzC,YAA6B,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;QACnD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,IAAA,uBAAa,GAAE,CAAC,CAAC;QAEhD,IAAI,CAAC,YAAY,GAAG,IAAI,wCAAkB,CAAC,CAAC,MAAM,EAAE,EAAE;YACpD,MAAM,eAAe,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAChD,IAAI,eAAe,EAAE;gBACnB,OAAO,QAAQ,CAAC;aACjB;iBAAM;gBACL,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;aACnE;QACH,CAAC,CAAC,CAAC;QAEH,gCAAgC;QAChC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAU,EA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vB,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC,EAAE,CAAC;gBACJ,IAAI,IAAI,EAAE;oBACR,IAAI,CAAC,qBAAqB,EAAE,CAAC;oBAC7B,MAAM;iBACP;aACF;YACD,IAAI,CAAC,WAAW,GAAG,CAAC,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACxE;IACH,CAAC;IAED;;OAEG;IACI,qBAAqB;QAC1B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED,6EAA6E;IAC7E,0BAA0B;IAC1B,6EAA6E;IAE7E;;;;;;;;;;;;OAYG;IACI,IAAI,CAAC,GAAY;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAG;QACd,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QAE9B,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QAErB,MAAM,OAAO,GAAG;YACd,KAAK,EAAE,IAAI;YACX,OAAO,EAAE,IAAI;SACd,CAAC;QAEF,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF;AAvLD,wDAuLC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.LambdaConnection = void 0;
|
|
14
|
-
const encoder_1 = require("../io/encoder");
|
|
15
|
-
const protocol_1 = require("../types/protocol");
|
|
16
|
-
const logger_1 = require("../utils/logger");
|
|
17
|
-
const RESOLVED = Promise.resolve();
|
|
18
|
-
class LambdaConnection {
|
|
19
|
-
suspendedOrCompleted;
|
|
20
|
-
// Empty buffer to store journal output messages
|
|
21
|
-
outputBuffer = Buffer.alloc(0);
|
|
22
|
-
// Callback to resolve the invocation promise of the Lambda handler when the response is ready
|
|
23
|
-
completionPromise;
|
|
24
|
-
resolveOnCompleted;
|
|
25
|
-
constructor(suspendedOrCompleted = false) {
|
|
26
|
-
this.suspendedOrCompleted = suspendedOrCompleted;
|
|
27
|
-
// Promise that signals when the invocation is over, to then flush the messages
|
|
28
|
-
this.completionPromise = new Promise((resolve) => {
|
|
29
|
-
this.resolveOnCompleted = resolve;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// Send a message back to the runtime
|
|
33
|
-
send(msg) {
|
|
34
|
-
// Add the header and the body to buffer and add to the output buffer
|
|
35
|
-
const msgBuffer = (0, encoder_1.encodeMessage)(msg);
|
|
36
|
-
this.outputBuffer = Buffer.concat([this.outputBuffer, msgBuffer]);
|
|
37
|
-
// An output message, suspension message or error message is the end of a Lambda invocation
|
|
38
|
-
if (msg.messageType === protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE ||
|
|
39
|
-
msg.messageType === protocol_1.SUSPENSION_MESSAGE_TYPE ||
|
|
40
|
-
msg.messageType === protocol_1.ERROR_MESSAGE_TYPE) {
|
|
41
|
-
this.suspendedOrCompleted = true;
|
|
42
|
-
}
|
|
43
|
-
return RESOLVED;
|
|
44
|
-
}
|
|
45
|
-
getResult() {
|
|
46
|
-
return this.completionPromise;
|
|
47
|
-
}
|
|
48
|
-
end() {
|
|
49
|
-
if (this.suspendedOrCompleted) {
|
|
50
|
-
logger_1.rlog.debug("Flushing output buffer...");
|
|
51
|
-
this.resolveOnCompleted(this.outputBuffer);
|
|
52
|
-
}
|
|
53
|
-
this.outputBuffer = Buffer.alloc(0);
|
|
54
|
-
return RESOLVED;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.LambdaConnection = LambdaConnection;
|
|
58
|
-
//# sourceMappingURL=lambda_connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lambda_connection.js","sourceRoot":"","sources":["../../src/connection/lambda_connection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAGH,2CAA8C;AAC9C,gDAI2B;AAE3B,4CAAuC;AAEvC,MAAM,QAAQ,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;AAElD,MAAa,gBAAgB;IAQP;IAPpB,gDAAgD;IACxC,YAAY,GAAW,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/C,8FAA8F;IAC7E,iBAAiB,CAAkB;IAC5C,kBAAkB,CAAiD;IAE3E,YAAoB,uBAAuB,KAAK;QAA5B,yBAAoB,GAApB,oBAAoB,CAAQ;QAC9C,+EAA+E;QAC/E,IAAI,CAAC,iBAAiB,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YACvD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,qCAAqC;IACrC,IAAI,CAAC,GAAY;QACf,qEAAqE;QACrE,MAAM,SAAS,GAAG,IAAA,uBAAa,EAAC,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;QAElE,2FAA2F;QAC3F,IACE,GAAG,CAAC,WAAW,KAAK,2CAAgC;YACpD,GAAG,CAAC,WAAW,KAAK,kCAAuB;YAC3C,GAAG,CAAC,WAAW,KAAK,6BAAkB,EACtC;YACA,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SAClC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,iBAAiB,CAAC;IAChC,CAAC;IAED,GAAG;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC7B,aAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SAC5C;QACD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA7CD,4CA6CC"}
|
package/dist/embedded/api.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.RestateConnection = exports.connection = void 0;
|
|
17
|
-
const invocation_1 = require("./invocation");
|
|
18
|
-
const handler_1 = require("./handler");
|
|
19
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
20
|
-
const http2_remote_1 = require("./http2_remote");
|
|
21
|
-
const connection = (address, opt) => new RestateConnection((0, http2_remote_1.bufConnectRemoteContext)(address, opt));
|
|
22
|
-
exports.connection = connection;
|
|
23
|
-
class RestateConnection {
|
|
24
|
-
remote;
|
|
25
|
-
constructor(remote) {
|
|
26
|
-
this.remote = remote;
|
|
27
|
-
}
|
|
28
|
-
invoke(id, input, handler, opt) {
|
|
29
|
-
const method = (0, handler_1.wrapHandler)(handler);
|
|
30
|
-
const streamId = crypto_1.default.randomUUID();
|
|
31
|
-
return (0, invocation_1.doInvoke)(this.remote, id, streamId, input, method, opt);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.RestateConnection = RestateConnection;
|
|
35
|
-
//# sourceMappingURL=api.js.map
|
package/dist/embedded/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/embedded/api.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAGH,6CAAwC;AACxC,uCAAwC;AACxC,oDAA4B;AAE5B,iDAAyD;AAqBlD,MAAM,UAAU,GAAG,CACxB,OAAe,EACf,GAA8B,EACX,EAAE,CACrB,IAAI,iBAAiB,CAAC,IAAA,sCAAuB,EAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AAJlD,QAAA,UAAU,cAIwC;AAE/D,MAAa,iBAAiB;IACC;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE/C,MAAM,CACX,EAAU,EACV,KAAQ,EACR,OAAkD,EAClD,GAA8B;QAE9B,MAAM,MAAM,GAAG,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAC;QACpC,MAAM,QAAQ,GAAG,gBAAM,CAAC,UAAU,EAAE,CAAC;QACrC,OAAO,IAAA,qBAAQ,EAAO,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACvE,CAAC;CACF;AAbD,8CAaC"}
|
package/dist/embedded/handler.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.wrapHandler = void 0;
|
|
14
|
-
const restate_context_1 = require("../restate_context");
|
|
15
|
-
const restate_context_impl_1 = require("../restate_context_impl");
|
|
16
|
-
const grpc_1 = require("../types/grpc");
|
|
17
|
-
function wrapHandler(handler) {
|
|
18
|
-
const localMethod = (instance, input) => {
|
|
19
|
-
const ctx = new restate_context_impl_1.RpcContextImpl((0, restate_context_1.useContext)(instance));
|
|
20
|
-
return handler(ctx, input);
|
|
21
|
-
};
|
|
22
|
-
const encoder = (output) => Buffer.from(JSON.stringify(output));
|
|
23
|
-
const decoder = (buf) => JSON.parse(buf.toString());
|
|
24
|
-
const method = new grpc_1.GrpcServiceMethod("", "", localMethod, decoder, encoder);
|
|
25
|
-
return new grpc_1.HostedGrpcServiceMethod({}, "", "", method);
|
|
26
|
-
}
|
|
27
|
-
exports.wrapHandler = wrapHandler;
|
|
28
|
-
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/embedded/handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,wDAA4D;AAC5D,kEAAyD;AACzD,wCAA2E;AAE3E,SAAgB,WAAW,CACzB,OAAkD;IAElD,MAAM,WAAW,GAAG,CAAC,QAAiB,EAAE,KAAQ,EAAc,EAAE;QAC9D,MAAM,GAAG,GAAG,IAAI,qCAAc,CAAC,IAAA,4BAAU,EAAC,QAAQ,CAAC,CAAC,CAAC;QACrD,OAAO,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,CAAC,MAAS,EAAc,EAAE,CACxC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,CAAC,GAAe,EAAK,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnE,MAAM,MAAM,GAAG,IAAI,wBAAiB,CAClC,EAAE,EACF,EAAE,EACF,WAAW,EACX,OAAO,EACP,OAAO,CACR,CAAC;IAEF,OAAO,IAAI,8BAAuB,CAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AArBD,kCAqBC"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.bufConnectRemoteContext = exports.RequestError = void 0;
|
|
17
|
-
const node_http2_1 = __importDefault(require("node:http2"));
|
|
18
|
-
const events_1 = require("events");
|
|
19
|
-
const services_1 = require("../generated/proto/services");
|
|
20
|
-
class RequestError extends Error {
|
|
21
|
-
url;
|
|
22
|
-
status;
|
|
23
|
-
statusText;
|
|
24
|
-
constructor(url, status, statusText) {
|
|
25
|
-
super(`${status} ${statusText ?? ""}`);
|
|
26
|
-
this.url = url;
|
|
27
|
-
this.status = status;
|
|
28
|
-
this.statusText = statusText;
|
|
29
|
-
}
|
|
30
|
-
precondtionFailed() {
|
|
31
|
-
return this.status === node_http2_1.default.constants.HTTP_STATUS_PRECONDITION_FAILED;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.RequestError = RequestError;
|
|
35
|
-
const bufConnectRemoteContext = (url, opt) => {
|
|
36
|
-
const httpClient = new ProtobufHttp2Client(url, opt);
|
|
37
|
-
return new services_1.RemoteContextClientImpl({
|
|
38
|
-
request: (service, method, data) => httpClient.post(`/${service}/${method}`, data),
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
exports.bufConnectRemoteContext = bufConnectRemoteContext;
|
|
42
|
-
class ProtobufHttp2Client {
|
|
43
|
-
ingress;
|
|
44
|
-
session;
|
|
45
|
-
additionalHeaders;
|
|
46
|
-
constructor(ingress, opt) {
|
|
47
|
-
this.ingress = ingress;
|
|
48
|
-
this.additionalHeaders = opt?.headers == undefined ? {} : opt?.headers;
|
|
49
|
-
}
|
|
50
|
-
async client() {
|
|
51
|
-
if (this.session !== undefined) {
|
|
52
|
-
return this.session;
|
|
53
|
-
}
|
|
54
|
-
const client = node_http2_1.default.connect(this.ingress);
|
|
55
|
-
client.unref();
|
|
56
|
-
client.once("goaway", () => {
|
|
57
|
-
this.session = undefined;
|
|
58
|
-
});
|
|
59
|
-
client.once("close", () => {
|
|
60
|
-
this.session = undefined;
|
|
61
|
-
});
|
|
62
|
-
this.session = client;
|
|
63
|
-
return client;
|
|
64
|
-
}
|
|
65
|
-
async post(path, body) {
|
|
66
|
-
const client = await this.client();
|
|
67
|
-
const req = client.request({
|
|
68
|
-
...{
|
|
69
|
-
[node_http2_1.default.constants.HTTP2_HEADER_SCHEME]: "http",
|
|
70
|
-
[node_http2_1.default.constants.HTTP2_HEADER_METHOD]: node_http2_1.default.constants.HTTP2_METHOD_POST,
|
|
71
|
-
[node_http2_1.default.constants.HTTP2_HEADER_PATH]: path,
|
|
72
|
-
[node_http2_1.default.constants.HTTP2_HEADER_CONTENT_TYPE]: "application/proto",
|
|
73
|
-
[node_http2_1.default.constants.HTTP2_HEADER_ACCEPT]: "application/proto",
|
|
74
|
-
[node_http2_1.default.constants.HTTP2_HEADER_CONTENT_LENGTH]: body.length,
|
|
75
|
-
},
|
|
76
|
-
...this.additionalHeaders,
|
|
77
|
-
});
|
|
78
|
-
req.end(body);
|
|
79
|
-
const [headers] = await (0, events_1.once)(req, "response");
|
|
80
|
-
const status = headers[node_http2_1.default.constants.HTTP2_HEADER_STATUS] ?? 0;
|
|
81
|
-
if (status !== 200) {
|
|
82
|
-
throw new RequestError(path, status);
|
|
83
|
-
}
|
|
84
|
-
const chunks = [];
|
|
85
|
-
for await (const chunk of req) {
|
|
86
|
-
chunks.push(chunk);
|
|
87
|
-
}
|
|
88
|
-
return Buffer.concat(chunks);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=http2_remote.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http2_remote.js","sourceRoot":"","sources":["../../src/embedded/http2_remote.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,4DAA+B;AAC/B,mCAA8B;AAC9B,0DAGqC;AAIrC,MAAa,YAAa,SAAQ,KAAK;IAEnB;IACA;IACA;IAHlB,YACkB,GAAW,EACX,MAAc,EACd,UAAmB;QAEnC,KAAK,CAAC,GAAG,MAAM,IAAI,UAAU,IAAI,EAAE,EAAE,CAAC,CAAC;QAJvB,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAS;IAGrC,CAA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