@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.
Files changed (88) hide show
  1. package/dist/cloudflare_bundle.js +26133 -0
  2. package/dist/io/encoder.d.ts +2 -1
  3. package/dist/io/encoder.d.ts.map +1 -1
  4. package/package.json +6 -3
  5. package/dist/connection/buffered_connection.js +0 -44
  6. package/dist/connection/buffered_connection.js.map +0 -1
  7. package/dist/connection/connection.js +0 -13
  8. package/dist/connection/connection.js.map +0 -1
  9. package/dist/connection/embedded_connection.js +0 -59
  10. package/dist/connection/embedded_connection.js.map +0 -1
  11. package/dist/connection/http_connection.js +0 -203
  12. package/dist/connection/http_connection.js.map +0 -1
  13. package/dist/connection/lambda_connection.js +0 -58
  14. package/dist/connection/lambda_connection.js.map +0 -1
  15. package/dist/embedded/api.js +0 -35
  16. package/dist/embedded/api.js.map +0 -1
  17. package/dist/embedded/handler.js +0 -28
  18. package/dist/embedded/handler.js.map +0 -1
  19. package/dist/embedded/http2_remote.js +0 -91
  20. package/dist/embedded/http2_remote.js.map +0 -1
  21. package/dist/embedded/invocation.js +0 -94
  22. package/dist/embedded/invocation.js.map +0 -1
  23. package/dist/generated/dev/restate/events.js +0 -371
  24. package/dist/generated/dev/restate/events.js.map +0 -1
  25. package/dist/generated/dev/restate/ext.js +0 -215
  26. package/dist/generated/dev/restate/ext.js.map +0 -1
  27. package/dist/generated/google/protobuf/descriptor.js +0 -6676
  28. package/dist/generated/google/protobuf/descriptor.js.map +0 -1
  29. package/dist/generated/google/protobuf/empty.js +0 -107
  30. package/dist/generated/google/protobuf/empty.js.map +0 -1
  31. package/dist/generated/google/protobuf/struct.js +0 -754
  32. package/dist/generated/google/protobuf/struct.js.map +0 -1
  33. package/dist/generated/proto/discovery.js +0 -364
  34. package/dist/generated/proto/discovery.js.map +0 -1
  35. package/dist/generated/proto/dynrpc.js +0 -668
  36. package/dist/generated/proto/dynrpc.js.map +0 -1
  37. package/dist/generated/proto/javascript.js +0 -297
  38. package/dist/generated/proto/javascript.js.map +0 -1
  39. package/dist/generated/proto/protocol.js +0 -2398
  40. package/dist/generated/proto/protocol.js.map +0 -1
  41. package/dist/generated/proto/services.js +0 -1535
  42. package/dist/generated/proto/services.js.map +0 -1
  43. package/dist/generated/proto/test.js +0 -321
  44. package/dist/generated/proto/test.js.map +0 -1
  45. package/dist/invocation.js +0 -154
  46. package/dist/invocation.js.map +0 -1
  47. package/dist/io/decoder.js +0 -133
  48. package/dist/io/decoder.js.map +0 -1
  49. package/dist/io/encoder.js +0 -68
  50. package/dist/io/encoder.js.map +0 -1
  51. package/dist/journal.js +0 -372
  52. package/dist/journal.js.map +0 -1
  53. package/dist/local_state_store.js +0 -72
  54. package/dist/local_state_store.js.map +0 -1
  55. package/dist/public_api.js +0 -58
  56. package/dist/public_api.js.map +0 -1
  57. package/dist/restate_context.js +0 -46
  58. package/dist/restate_context.js.map +0 -1
  59. package/dist/restate_context_impl.js +0 -375
  60. package/dist/restate_context_impl.js.map +0 -1
  61. package/dist/server/base_restate_server.js +0 -364
  62. package/dist/server/base_restate_server.js.map +0 -1
  63. package/dist/server/restate_lambda_handler.js +0 -247
  64. package/dist/server/restate_lambda_handler.js.map +0 -1
  65. package/dist/server/restate_server.js +0 -186
  66. package/dist/server/restate_server.js.map +0 -1
  67. package/dist/state_machine.js +0 -403
  68. package/dist/state_machine.js.map +0 -1
  69. package/dist/types/errors.js +0 -267
  70. package/dist/types/errors.js.map +0 -1
  71. package/dist/types/grpc.js +0 -68
  72. package/dist/types/grpc.js.map +0 -1
  73. package/dist/types/protocol.js +0 -125
  74. package/dist/types/protocol.js.map +0 -1
  75. package/dist/types/router.js +0 -36
  76. package/dist/types/router.js.map +0 -1
  77. package/dist/types/types.js +0 -126
  78. package/dist/types/types.js.map +0 -1
  79. package/dist/utils/assumpsions.js +0 -101
  80. package/dist/utils/assumpsions.js.map +0 -1
  81. package/dist/utils/logger.js +0 -102
  82. package/dist/utils/logger.js.map +0 -1
  83. package/dist/utils/public_utils.js +0 -49
  84. package/dist/utils/public_utils.js.map +0 -1
  85. package/dist/utils/rand.js +0 -114
  86. package/dist/utils/rand.js.map +0 -1
  87. package/dist/utils/utils.js +0 -144
  88. package/dist/utils/utils.js.map +0 -1
@@ -1,364 +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.parseService = exports.BaseRestateServer = void 0;
14
- /* eslint-disable @typescript-eslint/ban-types */
15
- const logger_1 = require("../utils/logger");
16
- const grpc_1 = require("../types/grpc");
17
- const types_1 = require("../types/types");
18
- const descriptor_1 = require("../generated/google/protobuf/descriptor");
19
- const empty_1 = require("../generated/google/protobuf/empty");
20
- const ext_1 = require("../generated/dev/restate/ext");
21
- const dynrpc_1 = require("../generated/proto/dynrpc");
22
- const restate_context_1 = require("../restate_context");
23
- const restate_context_impl_1 = require("../restate_context_impl");
24
- const assumpsions_1 = require("../utils/assumpsions");
25
- const public_api_1 = require("../public_api");
26
- const router_1 = require("../types/router");
27
- const utils_1 = require("../utils/utils");
28
- class BaseRestateServer {
29
- methods = {};
30
- discovery;
31
- dynrpcDescriptor;
32
- constructor(protocolMode) {
33
- this.discovery = {
34
- files: { file: [] },
35
- services: [],
36
- minProtocolVersion: 0,
37
- maxProtocolVersion: 0,
38
- protocolMode: protocolMode,
39
- };
40
- this.dynrpcDescriptor = copyProtoMetadata(dynrpc_1.protoMetadata);
41
- }
42
- addDescriptor(descriptor) {
43
- const desc = descriptor_1.FileDescriptorProto.fromPartial(descriptor.fileDescriptor);
44
- // extract out service options and put into the fileDescriptor
45
- for (const name in descriptor.options?.services) {
46
- if (descriptor.options?.services[name]?.options?.service_type !== undefined) {
47
- desc.service
48
- .find((desc) => desc.name === name)
49
- ?.options?.uninterpretedOption.push(descriptor_1.UninterpretedOption.fromPartial({
50
- name: [
51
- { namePart: "dev.restate.ext.service_type", isExtension: true },
52
- ],
53
- identifierValue: (0, ext_1.serviceTypeToJSON)(descriptor.options?.services[name]?.options?.service_type),
54
- }));
55
- }
56
- }
57
- // extract out field options and put into the fileDescriptor
58
- for (const messageName in descriptor.options?.messages) {
59
- for (const fieldName in descriptor.options?.messages[messageName]
60
- ?.fields) {
61
- const fields = descriptor.options?.messages[messageName]?.fields || {};
62
- if (fields[fieldName]["field"] !== undefined) {
63
- desc.messageType
64
- .find((desc) => desc.name === messageName)
65
- ?.field?.find((desc) => desc.name === fieldName)
66
- ?.options?.uninterpretedOption.push(descriptor_1.UninterpretedOption.fromPartial({
67
- name: [
68
- { namePart: "dev.restate.ext.field", isExtension: true },
69
- ],
70
- identifierValue: (0, ext_1.fieldTypeToJSON)(fields[fieldName]["field"]),
71
- }));
72
- }
73
- }
74
- }
75
- if (this.discovery.files?.file.filter((haveDesc) => desc.name === haveDesc.name).length === 0) {
76
- this.discovery.files?.file.push(desc);
77
- }
78
- descriptor.dependencies?.forEach((dep) => {
79
- this.addDescriptor(dep);
80
- });
81
- }
82
- bindService({ descriptor, service, instance }) {
83
- const spec = parseService(descriptor, service, instance);
84
- this.addDescriptor(descriptor);
85
- const qname = spec.packge === "" ? spec.name : `${spec.packge}.${spec.name}`;
86
- this.discovery.services.push(qname);
87
- for (const method of spec.methods) {
88
- const url = `/invoke/${qname}/${method.name}`;
89
- this.methods[url] = new grpc_1.HostedGrpcServiceMethod(instance, spec.packge, service, method);
90
- // note that this log will not print all the keys.
91
- logger_1.rlog.info(`Binding: ${url} -> ${JSON.stringify(method, null, "\t")}`);
92
- }
93
- }
94
- rpcHandler(keyed, route, handler) {
95
- const descriptor = createRpcMethodDescriptor(route);
96
- const localMethod = (instance, input) => {
97
- const ctx = (0, restate_context_1.useContext)(instance);
98
- if (keyed) {
99
- return dispatchKeyedRpcHandler(ctx, input, handler);
100
- }
101
- else {
102
- return dispatchUnkeyedRpcHandler(ctx, input, handler);
103
- }
104
- };
105
- const decoder = dynrpc_1.RpcRequest.decode;
106
- const encoder = (message) => dynrpc_1.RpcResponse.encode({
107
- response: (0, utils_1.jsonSafeAny)("", message.response),
108
- }).finish();
109
- const method = new grpc_1.GrpcServiceMethod(route, route, localMethod, decoder, encoder);
110
- return {
111
- descriptor: descriptor,
112
- method: method,
113
- };
114
- }
115
- stringKeyedEventHandler(keyed, route, handler) {
116
- if (!keyed) {
117
- // TODO: support unkeyed rpc event handler
118
- throw new public_api_1.TerminalError("Unkeyed Event handlers are not yet supported.");
119
- }
120
- const descriptor = createStringKeyedMethodDescriptor(route);
121
- const localMethod = (instance, input) => {
122
- const ctx = (0, restate_context_1.useContext)(instance);
123
- return dispatchKeyedEventHandler(ctx, input, handler);
124
- };
125
- const decoder = dynrpc_1.KeyedEvent.decode;
126
- const encoder = (message) => empty_1.Empty.encode(message).finish();
127
- const method = new grpc_1.GrpcServiceMethod(route, route, localMethod, decoder, encoder);
128
- return {
129
- descriptor,
130
- method: method,
131
- };
132
- }
133
- bindRpcService(name, router, keyed) {
134
- const lastDot = name.indexOf(".");
135
- const serviceName = lastDot === -1 ? name : name.substring(lastDot + 1);
136
- const servicePackage = name.substring(0, name.length - serviceName.length - 1);
137
- const desc = this.dynrpcDescriptor;
138
- const serviceGrpcSpec = keyed
139
- ? pushKeyedService(desc, name)
140
- : pushUnKeyedService(desc, name);
141
- for (const [route, handler] of Object.entries(router)) {
142
- let registration;
143
- if ((0, router_1.isEventHandler)(handler)) {
144
- const theHandler = handler.handler;
145
- registration = this.stringKeyedEventHandler(keyed, route, theHandler);
146
- }
147
- else {
148
- registration = this.rpcHandler(keyed, route, handler);
149
- }
150
- serviceGrpcSpec.method.push(registration.descriptor);
151
- const url = `/invoke/${name}/${route}`;
152
- this.methods[url] = new grpc_1.HostedGrpcServiceMethod({}, // we don't actually execute on any class instance
153
- servicePackage, serviceName, registration.method);
154
- logger_1.rlog.info(`Binding: ${url} -> ${JSON.stringify(registration.method, null, "\t")}`);
155
- }
156
- // since we modified this descriptor, we need to remove it in case it was added before,
157
- // so that the modified version is processed and added again
158
- const filteredFiles = this.discovery.files?.file.filter((haveDesc) => desc.fileDescriptor.name !== haveDesc.name);
159
- if (this.discovery.files !== undefined && filteredFiles !== undefined) {
160
- this.discovery.files.file = filteredFiles;
161
- }
162
- this.addDescriptor(desc);
163
- this.discovery.services.push(name);
164
- }
165
- methodByUrl(url) {
166
- if (url == undefined || url === null) {
167
- return undefined;
168
- }
169
- return this.methods[url];
170
- }
171
- }
172
- exports.BaseRestateServer = BaseRestateServer;
173
- /* eslint-disable @typescript-eslint/no-explicit-any */
174
- function indexProperties(instance) {
175
- const names = new Map();
176
- while (instance !== null &&
177
- instance !== undefined &&
178
- instance !== Object.prototype) {
179
- for (const property of Object.getOwnPropertyNames(instance)) {
180
- names.set(property.toLowerCase(), property);
181
- }
182
- instance = Object.getPrototypeOf(instance);
183
- }
184
- return names;
185
- }
186
- // Given:
187
- // * an instance of a class that implements a gRPC TypeScript interface,
188
- // as generated by our protoc plugin, this method
189
- // * The ProtobufFileDescriptor as generated by the protobuf plugin
190
- // * and the gRPC service name
191
- //
192
- // Return a GrpcService definition, as defined above.
193
- //
194
- // For example (see first: example.proto and example.ts):
195
- //
196
- // > parse(example.protoMetaData, "Greeter", new GreeterService())
197
- //
198
- // produces ~
199
- //
200
- // serviceName: 'Greeter',
201
- // instance: GreeterService {},
202
- // methods: {
203
- // multiword: {
204
- // localName: 'multiWord',
205
- // fn: [Function: multiWord],
206
- // inputType: [Object],
207
- // outputType: [Object]
208
- // },
209
- // greet: {
210
- // localName: 'greet',
211
- // fn: [Function: greet],
212
- // inputType: [Object],
213
- // outputType: [Object]
214
- // }
215
- // }
216
- //}
217
- //
218
- /* eslint-disable @typescript-eslint/no-explicit-any */
219
- function parseService(meta, serviceName, instance) {
220
- const svcMethods = [];
221
- // index all the existing properties that `instance` has.
222
- // we index them by the lower case represention.
223
- const names = indexProperties(instance);
224
- for (const serviceDescriptor of meta.fileDescriptor.service) {
225
- if (serviceName !== serviceDescriptor.name) {
226
- continue;
227
- }
228
- for (const methodDescriptor of serviceDescriptor.method) {
229
- const lowercaseName = methodDescriptor.name.toLowerCase();
230
- const localName = names.get(lowercaseName);
231
- if (localName === undefined || localName === null) {
232
- throw new Error(`unimplemented method ${methodDescriptor.name}`);
233
- }
234
- const fn = instance[localName];
235
- if (typeof fn !== "function") {
236
- throw new Error(`A property ${localName} exists, which coresponds to a gRPC service named ${methodDescriptor.name}, but that property is not a function.`);
237
- }
238
- const localMethod = async (instance, input) => {
239
- return await fn.call(instance, input);
240
- };
241
- let inputMessage = meta.references[methodDescriptor.inputType];
242
- // If the input message type is not defined by the proto files of the service but by a dependency (e.g. BoolValue, Empty, etc)
243
- // then we need to look for the encoders and decoders in the dependencies.
244
- if (inputMessage === undefined) {
245
- meta.dependencies?.forEach((dep) => {
246
- if (dep.references[methodDescriptor.inputType] !== undefined) {
247
- inputMessage = dep.references[methodDescriptor.inputType];
248
- }
249
- });
250
- }
251
- let outputMessage = meta.references[methodDescriptor.outputType];
252
- // If the output message type is not defined by use but by the proto files of the service (e.g. BoolValue, Empty, etc)
253
- // then we need to look for the encoders and decoders in the dependencies.
254
- if (outputMessage === undefined) {
255
- meta.dependencies?.forEach((dep) => {
256
- if (dep.references[methodDescriptor.outputType] !== undefined) {
257
- outputMessage = dep.references[methodDescriptor.outputType];
258
- }
259
- });
260
- }
261
- const decoder = (buffer) => inputMessage.decode(buffer);
262
- const encoder = (message) => outputMessage.encode(message).finish();
263
- svcMethods.push(new grpc_1.GrpcServiceMethod(methodDescriptor.name, localName, localMethod, decoder, encoder));
264
- }
265
- return new grpc_1.GrpcService(serviceName, meta.fileDescriptor.package, instance, svcMethods);
266
- }
267
- throw new Error(`Unable to find a service ${serviceName}.`);
268
- }
269
- exports.parseService = parseService;
270
- async function dispatchKeyedRpcHandler(origCtx, req, handler) {
271
- const { key, request } = (0, assumpsions_1.verifyAssumptions)(true, req);
272
- const ctx = new restate_context_impl_1.RpcContextImpl(origCtx);
273
- if (typeof key !== "string" || key.length === 0) {
274
- // we throw a terminal error here, because this cannot be patched by updating code:
275
- // if the request is wrong (missing a key), the request can never make it
276
- throw new public_api_1.TerminalError("Keyed handlers must recieve a non null or empty string key");
277
- }
278
- const jsResult = (await handler(ctx, key, request));
279
- return dynrpc_1.RpcResponse.create({ response: jsResult });
280
- }
281
- async function dispatchUnkeyedRpcHandler(origCtx, req, handler) {
282
- const { request } = (0, assumpsions_1.verifyAssumptions)(false, req);
283
- const ctx = new restate_context_impl_1.RpcContextImpl(origCtx);
284
- const result = await handler(ctx, request);
285
- return dynrpc_1.RpcResponse.create({ response: result });
286
- }
287
- async function dispatchKeyedEventHandler(origCtx, req, handler) {
288
- const ctx = new restate_context_impl_1.RpcContextImpl(origCtx);
289
- const key = req.key;
290
- if (key === null || key === undefined || key.length === 0) {
291
- // we throw a terminal error here, because this cannot be patched by updating code:
292
- // if the request is wrong (missing a key), the request can never make it
293
- throw new public_api_1.TerminalError("Keyed handlers must receive a non null or empty string key");
294
- }
295
- const jsEvent = new types_1.Event(key, req.payload, req.attributes);
296
- await handler(ctx, jsEvent);
297
- return empty_1.Empty.create({});
298
- }
299
- function copyProtoMetadata(original) {
300
- // duplicate the file descriptor. shallow, because we only need to
301
- // change one top-level field: service[]
302
- const fileDescriptorCopy = {
303
- ...original.fileDescriptor,
304
- };
305
- fileDescriptorCopy.service = [];
306
- let options = original.options;
307
- if (options !== undefined) {
308
- options = {
309
- ...original.options,
310
- };
311
- options.services = {};
312
- }
313
- return {
314
- fileDescriptor: fileDescriptorCopy,
315
- references: original.references,
316
- dependencies: original.dependencies,
317
- options: options,
318
- };
319
- }
320
- function pushKeyedService(desc, newName) {
321
- const service = {
322
- ...dynrpc_1.protoMetadata.fileDescriptor.service[0],
323
- };
324
- service.name = newName;
325
- service.method = [];
326
- desc.fileDescriptor.service.push(service);
327
- const serviceOptions = dynrpc_1.protoMetadata.options?.services?.["RpcEndpoint"];
328
- if (serviceOptions === undefined) {
329
- throw new Error("Missing service options in original RpcEndpoint proto descriptor");
330
- }
331
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
332
- desc.options.services[newName] = serviceOptions;
333
- return service;
334
- }
335
- function pushUnKeyedService(desc, newName) {
336
- const service = {
337
- ...dynrpc_1.protoMetadata.fileDescriptor.service[1],
338
- };
339
- service.name = newName;
340
- service.method = [];
341
- desc.fileDescriptor.service.push(service);
342
- const serviceOptions = dynrpc_1.protoMetadata.options?.services?.["UnkeyedRpcEndpoint"];
343
- if (serviceOptions === undefined) {
344
- throw new Error("Missing service options in original UnkeyedRpcEndpoint proto descriptor");
345
- }
346
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
347
- desc.options.services[newName] = serviceOptions;
348
- return service;
349
- }
350
- function createRpcMethodDescriptor(methodName) {
351
- const desc = {
352
- ...dynrpc_1.protoMetadata.fileDescriptor.service[0].method[0],
353
- };
354
- desc.name = methodName;
355
- return desc;
356
- }
357
- function createStringKeyedMethodDescriptor(methodName) {
358
- const desc = {
359
- ...dynrpc_1.protoMetadata.fileDescriptor.service[0].method[1],
360
- };
361
- desc.name = methodName;
362
- return desc;
363
- }
364
- //# sourceMappingURL=base_restate_server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base_restate_server.js","sourceRoot":"","sources":["../../src/server/base_restate_server.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,iDAAiD;AAEjD,4CAAuC;AACvC,wCAKuB;AAKvB,0CAAuC;AACvC,wEAGiD;AACjD,8DAA2D;AAM3D,sDAGsC;AACtC,sDAMmC;AACnC,wDAAgE;AAChE,kEAAyD;AACzD,sDAAyD;AACzD,8CAA8C;AAC9C,4CAAiD;AACjD,0CAA6C;AAQ7C,M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,CAAC;AACjB,CAAC;AAED,SAAS,yBAAyB,CAAC,UAAkB;IACnD,MAAM,IAAI,GAAG;QACX,GAAG,sBAAuB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KACrC,CAAC;IAC5B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,iCAAiC,CACxC,UAAkB;IAElB,MAAM,IAAI,GAAG;QACX,GAAG,sBAAuB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;KACrC,CAAC;IAC5B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,247 +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.LambdaRestateServer = exports.createLambdaApiGatewayHandler = void 0;
14
- const logger_1 = require("../utils/logger");
15
- const discovery_1 = require("../generated/proto/discovery");
16
- const base_restate_server_1 = require("./base_restate_server");
17
- const lambda_connection_1 = require("../connection/lambda_connection");
18
- const invocation_1 = require("../invocation");
19
- const decoder_1 = require("../io/decoder");
20
- const state_machine_1 = require("../state_machine");
21
- const errors_1 = require("../types/errors");
22
- const protocol_1 = require("../types/protocol");
23
- /**
24
- * Creates an Restate entrypoint for services deployed on AWS Lambda and invoked
25
- * through API Gateway.
26
- *
27
- * Register services on this entrypoint via {@link LambdaRestateServer.bindService } and
28
- * then create the Lambda invocation handler via {@link LambdaRestateServer.handle }.
29
- *
30
- * @example
31
- * A typical AWS Lambda entry point would look like this
32
- * ```
33
- * import * as restate from "@restatedev/restate-sdk";
34
- *
35
- * export const handler = restate
36
- * .createLambdaApiGatewayHandler()
37
- * .bindService({
38
- * service: "MyService",
39
- * instance: new myService.MyServiceImpl(),
40
- * descriptor: myService.protoMetadata,
41
- * })
42
- * .handle();
43
- * ```
44
- */
45
- function createLambdaApiGatewayHandler() {
46
- return new LambdaRestateServer();
47
- }
48
- exports.createLambdaApiGatewayHandler = createLambdaApiGatewayHandler;
49
- /**
50
- * Restate entrypoint implementation for services deployed on AWS Lambda.
51
- * This one decodes the requests, create the log event sequence that
52
- * drives the durable execution of the service invocations.
53
- */
54
- class LambdaRestateServer extends base_restate_server_1.BaseRestateServer {
55
- constructor() {
56
- super(discovery_1.ProtocolMode.REQUEST_RESPONSE);
57
- }
58
- /**
59
- * Adds a gRPC service to be served from this endpoint.
60
- *
61
- * The {@link ServiceOpts} passed here need to describe the following properties:
62
- *
63
- * - The 'service' name: the name of the gRPC service (as in the service definition proto file).
64
- * - The service 'instance': the implementation of the service logic (must implement the generated
65
- * gRPC service interface).
66
- * - The gRPC/protobuf 'descriptor': The protoMetadata descriptor that describes the service, methods,
67
- * and parameter types. It is usually found as the value 'protoMetadata' in the generated
68
- * file '(service-name).ts'
69
- *
70
- * The descriptor is generated by the protobuf compiler and needed by Restate to reflectively discover
71
- * the service details, understand payload serialization, perform HTTP/JSON-to-gRPC transcoding, or
72
- * to proxy the service.
73
- *
74
- * If you define multiple services in the same '.proto' file, you may have only one descriptor that
75
- * describes all services together. You can pass the same descriptor to multiple calls of '.bindService()'.
76
- *
77
- * If you don't find the gRPC/protobuf descriptor, make your you generated the gRPC/ProtoBuf code with
78
- * the option to generate the descriptor. For example, using the 'ts-proto' plugin, make sure you pass
79
- * the 'outputSchema=true' option. If you are using Restate's project templates, this should all be
80
- * pre-configured for you.
81
- *
82
- * @example
83
- * ```
84
- * endpoint.bindService({
85
- * service: "MyService",
86
- * instance: new myService.MyServiceImpl(),
87
- * descriptor: myService.protoMetadata
88
- * })
89
- * ```
90
- *
91
- * @param serviceOpts The options describing the service to be bound. See above for a detailed description.
92
- * @returns An instance of this LambdaRestateServer
93
- */
94
- bindService(serviceOpts) {
95
- // Implementation note: This override if here mainly to change the return type to the more
96
- // concrete type LambdaRestateServer (from BaseRestateServer).
97
- super.bindService(serviceOpts);
98
- return this;
99
- }
100
- bindRouter(path, router) {
101
- super.bindRpcService(path, router, false);
102
- return this;
103
- }
104
- bindKeyedRouter(path, router) {
105
- super.bindRpcService(path, router, true);
106
- return this;
107
- }
108
- /**
109
- * Creates the invocation handler function to be called by AWS Lambda.
110
- *
111
- * The returned type of this function is `(event: APIGatewayProxyEvent | APIGatewayProxyEventV2) => Promise<APIGatewayProxyResult | APIGatewayProxyResultV2>`.
112
- * We use `any` types here to avoid a dependency on the `@types/aws-lambda` dependency for consumers of this API.
113
- *
114
- * @example
115
- * A typical AWS Lambda entry point would use this method the follwing way:
116
- * ```
117
- * import * as restate from "@restatedev/restate-sdk";
118
- *
119
- * export const handler = restate
120
- * .createLambdaApiGatewayHandler()
121
- * .bindService({
122
- * service: "MyService",
123
- * instance: new myService.MyServiceImpl(),
124
- * descriptor: myService.protoMetadata,
125
- * })
126
- * .handle();
127
- * ```
128
- *
129
- * @returns The invocation handler function for to be called by AWS Lambda.
130
- */
131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- handle() {
133
- // return the handler and bind the current context to it, so that it can find the other methods in this class.
134
- return this.handleRequest.bind(this);
135
- }
136
- // --------------------------------------------------------------------------
137
- /**
138
- * This is the main request handling method, effectively a typed variant of `create()`.
139
- */
140
- async handleRequest(event) {
141
- let path;
142
- if ("path" in event) {
143
- // V1
144
- path = event.path;
145
- }
146
- else {
147
- // V2
148
- path = event.rawPath;
149
- }
150
- const pathSegments = path.split("/");
151
- // API Gateway can add a prefix to the path based on the name of the Lambda function and deployment stage
152
- // (e.g. /default)
153
- // So we only check the ending of the path on correctness.
154
- // Logic:
155
- // 1. Check whether there are at least three segments in the path and whether the third-last one is "invoke".
156
- // If that is the case, treat it as an invocation.
157
- // 2. See if the last one is "discover", answer with discovery.
158
- // 3. Else report "invalid path".
159
- if (pathSegments.length >= 3 &&
160
- pathSegments[pathSegments.length - 3] === "invoke") {
161
- const url = "/" + pathSegments.slice(-3).join("/");
162
- return await this.handleInvoke(url, event);
163
- }
164
- else if (pathSegments[pathSegments.length - 1] === "discover") {
165
- return this.handleDiscovery();
166
- }
167
- else {
168
- const msg = "Invalid path: path doesn't end in /invoke/SvcName/MethodName and also not in /discover: " +
169
- path;
170
- logger_1.rlog.error(msg);
171
- logger_1.rlog.trace();
172
- return this.toErrorResponse(500, msg);
173
- }
174
- }
175
- async handleInvoke(url, event) {
176
- try {
177
- const method = this.methodByUrl(url);
178
- if (event.body == null) {
179
- throw new Error("The incoming message body was null");
180
- }
181
- if (method === undefined) {
182
- if (url.includes("?")) {
183
- throw new Error(`Invalid path: path URL seems to include query parameters: ${url}`);
184
- }
185
- else {
186
- const msg = `No service found for URL: ${url}`;
187
- logger_1.rlog.error(msg);
188
- return this.toErrorResponse(404, msg);
189
- }
190
- }
191
- // build the previous journal from the events
192
- let decodedEntries = (0, decoder_1.decodeLambdaBody)(event.body);
193
- const journalBuilder = new invocation_1.InvocationBuilder(method);
194
- decodedEntries.forEach((e) => journalBuilder.handleMessage(e));
195
- const alreadyCompleted = decodedEntries.find((e) => e.messageType === protocol_1.OUTPUT_STREAM_ENTRY_MESSAGE_TYPE) !== undefined;
196
- decodedEntries = null;
197
- // set up and invoke the state machine
198
- const connection = new lambda_connection_1.LambdaConnection(alreadyCompleted);
199
- const stateMachine = new state_machine_1.StateMachine(connection, journalBuilder.build(), discovery_1.ProtocolMode.REQUEST_RESPONSE);
200
- await stateMachine.invoke();
201
- const result = await connection.getResult();
202
- return {
203
- headers: {
204
- "content-type": "application/restate",
205
- },
206
- statusCode: 200,
207
- isBase64Encoded: true,
208
- body: encodeResponse(result),
209
- };
210
- }
211
- catch (e) {
212
- const error = (0, errors_1.ensureError)(e);
213
- logger_1.rlog.error(error.message);
214
- logger_1.rlog.error(error.stack);
215
- return this.toErrorResponse(500, error.message);
216
- }
217
- }
218
- handleDiscovery() {
219
- // return discovery information
220
- logger_1.rlog.info("Answering discovery request. Announcing services: " +
221
- JSON.stringify(this.discovery.services));
222
- return {
223
- headers: {
224
- "content-type": "application/proto",
225
- },
226
- statusCode: 200,
227
- isBase64Encoded: true,
228
- body: encodeResponse(discovery_1.ServiceDiscoveryResponse.encode(this.discovery).finish()),
229
- };
230
- }
231
- toErrorResponse(code, message) {
232
- return {
233
- headers: {
234
- "content-type": "application/restate",
235
- },
236
- statusCode: code,
237
- isBase64Encoded: true,
238
- body: encodeResponse(Buffer.from(JSON.stringify({ message }))),
239
- };
240
- }
241
- }
242
- exports.LambdaRestateServer = LambdaRestateServer;
243
- function encodeResponse(data) {
244
- const buffer = data instanceof Buffer ? data : Buffer.from(data);
245
- return buffer.toString("base64");
246
- }
247
- //# sourceMappingURL=restate_lambda_handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"restate_lambda_handler.js","sourceRoot":"","sources":["../../src/server/restate_lambda_handler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,4CAAuC;AAOvC,4DAGsC;AACtC,+DAAuE;AACvE,uEAAmE;AACnE,8CAAkD;AAClD,2CAAiD;AAEjD,oDAAgD;AAChD,4CAA8C;AAE9C,gDAAqE;AAErE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,6BAA6B;IAC3C,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACnC,CAAC;AAFD,sEAEC;AAED;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,uCAAiB;IACxD;QACE,KAAK,CAAC,wBAAY,CAAC,gBAAgB,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACI,WAAW,CAAC,WAAwB;QACzC,0FAA0F;QAC1F,8D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