@celljs/grpc 0.0.0-stage → 4.4.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.
Files changed (187) hide show
  1. package/README.md +121 -2
  2. package/cell.schema.json +32 -0
  3. package/cell.yml +9 -0
  4. package/esm/node/call/async-queue.d.ts +31 -0
  5. package/esm/node/call/async-queue.js +80 -0
  6. package/esm/node/call/async-queue.js.map +1 -0
  7. package/esm/node/call/grpc-status.d.ts +33 -0
  8. package/esm/node/call/grpc-status.js +48 -0
  9. package/esm/node/call/grpc-status.js.map +1 -0
  10. package/esm/node/call/message-framer.d.ts +24 -0
  11. package/esm/node/call/message-framer.js +105 -0
  12. package/esm/node/call/message-framer.js.map +1 -0
  13. package/esm/node/call/metadata.d.ts +15 -0
  14. package/esm/node/call/metadata.js +81 -0
  15. package/esm/node/call/metadata.js.map +1 -0
  16. package/esm/node/client/grpc-channel.d.ts +64 -0
  17. package/esm/node/client/grpc-channel.js +285 -0
  18. package/esm/node/client/grpc-channel.js.map +1 -0
  19. package/esm/node/codec/proto-reader.d.ts +26 -0
  20. package/esm/node/codec/proto-reader.js +153 -0
  21. package/esm/node/codec/proto-reader.js.map +1 -0
  22. package/esm/node/codec/proto-writer.d.ts +29 -0
  23. package/esm/node/codec/proto-writer.js +150 -0
  24. package/esm/node/codec/proto-writer.js.map +1 -0
  25. package/esm/node/index.d.ts +15 -0
  26. package/esm/node/index.js +16 -0
  27. package/esm/node/index.js.map +1 -0
  28. package/esm/node/module.d.ts +3 -0
  29. package/esm/node/module.js +4 -0
  30. package/esm/node/module.js.map +1 -0
  31. package/esm/node/proto/proto-ast.d.ts +46 -0
  32. package/esm/node/proto/proto-ast.js +2 -0
  33. package/esm/node/proto/proto-ast.js.map +1 -0
  34. package/esm/node/proto/proto-parser.d.ts +45 -0
  35. package/esm/node/proto/proto-parser.js +451 -0
  36. package/esm/node/proto/proto-parser.js.map +1 -0
  37. package/esm/node/proto/proto-types.d.ts +76 -0
  38. package/esm/node/proto/proto-types.js +444 -0
  39. package/esm/node/proto/proto-types.js.map +1 -0
  40. package/esm/node/proto/proto.d.ts +57 -0
  41. package/esm/node/proto/proto.js +174 -0
  42. package/esm/node/proto/proto.js.map +1 -0
  43. package/esm/node/proto/well-known.d.ts +5 -0
  44. package/esm/node/proto/well-known.js +41 -0
  45. package/esm/node/proto/well-known.js.map +1 -0
  46. package/esm/node/server/grpc-server-lifecycle.d.ts +21 -0
  47. package/esm/node/server/grpc-server-lifecycle.js +65 -0
  48. package/esm/node/server/grpc-server-lifecycle.js.map +1 -0
  49. package/esm/node/server/grpc-server.d.ts +60 -0
  50. package/esm/node/server/grpc-server.js +312 -0
  51. package/esm/node/server/grpc-server.js.map +1 -0
  52. package/esm/node/server/grpc-service.d.ts +24 -0
  53. package/esm/node/server/grpc-service.js +38 -0
  54. package/esm/node/server/grpc-service.js.map +1 -0
  55. package/esm/node/test/proto-loader.d.ts +2 -0
  56. package/esm/node/test/proto-loader.js +13 -0
  57. package/esm/node/test/proto-loader.js.map +1 -0
  58. package/esm/node/test/test-protos.d.ts +28 -0
  59. package/esm/node/test/test-protos.js +145 -0
  60. package/esm/node/test/test-protos.js.map +1 -0
  61. package/esm/package.json +3 -0
  62. package/lib/node/call/async-queue.d.ts +32 -0
  63. package/lib/node/call/async-queue.d.ts.map +1 -0
  64. package/lib/node/call/async-queue.js +84 -0
  65. package/lib/node/call/async-queue.js.map +1 -0
  66. package/lib/node/call/grpc-status.d.ts +34 -0
  67. package/lib/node/call/grpc-status.d.ts.map +1 -0
  68. package/lib/node/call/grpc-status.js +52 -0
  69. package/lib/node/call/grpc-status.js.map +1 -0
  70. package/lib/node/call/message-framer.d.ts +25 -0
  71. package/lib/node/call/message-framer.d.ts.map +1 -0
  72. package/lib/node/call/message-framer.js +109 -0
  73. package/lib/node/call/message-framer.js.map +1 -0
  74. package/lib/node/call/metadata.d.ts +16 -0
  75. package/lib/node/call/metadata.d.ts.map +1 -0
  76. package/lib/node/call/metadata.js +84 -0
  77. package/lib/node/call/metadata.js.map +1 -0
  78. package/lib/node/client/grpc-channel.d.ts +65 -0
  79. package/lib/node/client/grpc-channel.d.ts.map +1 -0
  80. package/lib/node/client/grpc-channel.js +289 -0
  81. package/lib/node/client/grpc-channel.js.map +1 -0
  82. package/lib/node/codec/proto-reader.d.ts +27 -0
  83. package/lib/node/codec/proto-reader.d.ts.map +1 -0
  84. package/lib/node/codec/proto-reader.js +157 -0
  85. package/lib/node/codec/proto-reader.js.map +1 -0
  86. package/lib/node/codec/proto-writer.d.ts +30 -0
  87. package/lib/node/codec/proto-writer.d.ts.map +1 -0
  88. package/lib/node/codec/proto-writer.js +154 -0
  89. package/lib/node/codec/proto-writer.js.map +1 -0
  90. package/lib/node/grpc.spec.d.ts +2 -0
  91. package/lib/node/grpc.spec.d.ts.map +1 -0
  92. package/lib/node/grpc.spec.js +148 -0
  93. package/lib/node/grpc.spec.js.map +1 -0
  94. package/lib/node/index.d.ts +16 -0
  95. package/lib/node/index.d.ts.map +1 -0
  96. package/lib/node/index.js +32 -0
  97. package/lib/node/index.js.map +1 -0
  98. package/lib/node/interop.spec.d.ts +2 -0
  99. package/lib/node/interop.spec.d.ts.map +1 -0
  100. package/lib/node/interop.spec.js +194 -0
  101. package/lib/node/interop.spec.js.map +1 -0
  102. package/lib/node/module.d.ts +4 -0
  103. package/lib/node/module.d.ts.map +1 -0
  104. package/lib/node/module.js +6 -0
  105. package/lib/node/module.js.map +1 -0
  106. package/lib/node/proto/proto-ast.d.ts +47 -0
  107. package/lib/node/proto/proto-ast.d.ts.map +1 -0
  108. package/lib/node/proto/proto-ast.js +3 -0
  109. package/lib/node/proto/proto-ast.js.map +1 -0
  110. package/lib/node/proto/proto-parser.d.ts +46 -0
  111. package/lib/node/proto/proto-parser.d.ts.map +1 -0
  112. package/lib/node/proto/proto-parser.js +455 -0
  113. package/lib/node/proto/proto-parser.js.map +1 -0
  114. package/lib/node/proto/proto-parser.spec.d.ts +2 -0
  115. package/lib/node/proto/proto-parser.spec.d.ts.map +1 -0
  116. package/lib/node/proto/proto-parser.spec.js +95 -0
  117. package/lib/node/proto/proto-parser.spec.js.map +1 -0
  118. package/lib/node/proto/proto-types.d.ts +77 -0
  119. package/lib/node/proto/proto-types.d.ts.map +1 -0
  120. package/lib/node/proto/proto-types.js +449 -0
  121. package/lib/node/proto/proto-types.js.map +1 -0
  122. package/lib/node/proto/proto-types.spec.d.ts +2 -0
  123. package/lib/node/proto/proto-types.spec.d.ts.map +1 -0
  124. package/lib/node/proto/proto-types.spec.js +120 -0
  125. package/lib/node/proto/proto-types.spec.js.map +1 -0
  126. package/lib/node/proto/proto.d.ts +58 -0
  127. package/lib/node/proto/proto.d.ts.map +1 -0
  128. package/lib/node/proto/proto.js +178 -0
  129. package/lib/node/proto/proto.js.map +1 -0
  130. package/lib/node/proto/well-known.d.ts +6 -0
  131. package/lib/node/proto/well-known.d.ts.map +1 -0
  132. package/lib/node/proto/well-known.js +44 -0
  133. package/lib/node/proto/well-known.js.map +1 -0
  134. package/lib/node/server/grpc-server-lifecycle.d.ts +22 -0
  135. package/lib/node/server/grpc-server-lifecycle.d.ts.map +1 -0
  136. package/lib/node/server/grpc-server-lifecycle.js +68 -0
  137. package/lib/node/server/grpc-server-lifecycle.js.map +1 -0
  138. package/lib/node/server/grpc-server-lifecycle.spec.d.ts +2 -0
  139. package/lib/node/server/grpc-server-lifecycle.spec.d.ts.map +1 -0
  140. package/lib/node/server/grpc-server-lifecycle.spec.js +100 -0
  141. package/lib/node/server/grpc-server-lifecycle.spec.js.map +1 -0
  142. package/lib/node/server/grpc-server.d.ts +61 -0
  143. package/lib/node/server/grpc-server.d.ts.map +1 -0
  144. package/lib/node/server/grpc-server.js +316 -0
  145. package/lib/node/server/grpc-server.js.map +1 -0
  146. package/lib/node/server/grpc-service.d.ts +25 -0
  147. package/lib/node/server/grpc-service.d.ts.map +1 -0
  148. package/lib/node/server/grpc-service.js +42 -0
  149. package/lib/node/server/grpc-service.js.map +1 -0
  150. package/lib/node/test/proto-loader.d.ts +3 -0
  151. package/lib/node/test/proto-loader.d.ts.map +1 -0
  152. package/lib/node/test/proto-loader.js +16 -0
  153. package/lib/node/test/proto-loader.js.map +1 -0
  154. package/lib/node/test/test-protos.d.ts +29 -0
  155. package/lib/node/test/test-protos.d.ts.map +1 -0
  156. package/lib/node/test/test-protos.js +150 -0
  157. package/lib/node/test/test-protos.js.map +1 -0
  158. package/lib/package.spec.d.ts +2 -0
  159. package/lib/package.spec.d.ts.map +1 -0
  160. package/lib/package.spec.js +7 -0
  161. package/lib/package.spec.js.map +1 -0
  162. package/package.json +70 -4
  163. package/src/node/call/async-queue.ts +79 -0
  164. package/src/node/call/grpc-status.ts +49 -0
  165. package/src/node/call/message-framer.ts +109 -0
  166. package/src/node/call/metadata.ts +85 -0
  167. package/src/node/client/grpc-channel.ts +327 -0
  168. package/src/node/codec/proto-reader.ts +172 -0
  169. package/src/node/codec/proto-writer.ts +170 -0
  170. package/src/node/grpc.spec.ts +160 -0
  171. package/src/node/index.ts +15 -0
  172. package/src/node/interop.spec.ts +174 -0
  173. package/src/node/module.ts +4 -0
  174. package/src/node/proto/proto-ast.ts +48 -0
  175. package/src/node/proto/proto-parser.spec.ts +104 -0
  176. package/src/node/proto/proto-parser.ts +477 -0
  177. package/src/node/proto/proto-types.spec.ts +128 -0
  178. package/src/node/proto/proto-types.ts +497 -0
  179. package/src/node/proto/proto.ts +218 -0
  180. package/src/node/proto/well-known.ts +40 -0
  181. package/src/node/server/grpc-server-lifecycle.spec.ts +88 -0
  182. package/src/node/server/grpc-server-lifecycle.ts +56 -0
  183. package/src/node/server/grpc-server.ts +368 -0
  184. package/src/node/server/grpc-service.ts +40 -0
  185. package/src/node/test/proto-loader.ts +13 -0
  186. package/src/node/test/test-protos.ts +159 -0
  187. package/src/package.spec.ts +5 -0
@@ -0,0 +1,174 @@
1
+ import { ProtoParser } from './proto-parser.js';
2
+ import { EnumType, MessageType, SCALAR_KINDS } from './proto-types.js';
3
+ import { WELL_KNOWN_PROTOS } from './well-known.js';
4
+ /**
5
+ * The messages, enums and services of one or more .proto files.
6
+ *
7
+ * ```ts
8
+ * // source: the text of greeter.proto, e.g. imported with Vite's `?raw` suffix
9
+ * export const Greeter = Proto.parse(source).service('Greeter');
10
+ * ```
11
+ *
12
+ * Pass every file the sources import, in any order; imports of `google/protobuf/*.proto` well-known
13
+ * types are built in. Names are full names (`helloworld.Greeter`) or, when unambiguous, short ones.
14
+ */
15
+ export class Proto {
16
+ static parse(...sources) {
17
+ return new Proto(sources);
18
+ }
19
+ constructor(sources) {
20
+ this.types = new Map();
21
+ this.serviceMap = new Map();
22
+ const files = sources.map((source, i) => ProtoParser.parse(source, sources.length > 1 ? `<source ${i + 1}>` : '<source>'));
23
+ const included = new Set();
24
+ for (let i = 0; i < files.length; i++) {
25
+ for (const name of files[i].imports) {
26
+ if (WELL_KNOWN_PROTOS[name] && !included.has(name)) {
27
+ included.add(name);
28
+ files.push(ProtoParser.parse(WELL_KNOWN_PROTOS[name], name));
29
+ }
30
+ }
31
+ }
32
+ const pending = [];
33
+ for (const file of files) {
34
+ const prefix = file.package ? `${file.package}.` : '';
35
+ for (const message of file.messages) {
36
+ this.registerMessage(message, prefix, file.syntax, pending);
37
+ }
38
+ for (const e of file.enums) {
39
+ this.registerEnum(e, prefix);
40
+ }
41
+ }
42
+ for (const { type, ast, syntax } of pending) {
43
+ type.setFields(ast.fields.map(field => {
44
+ var _a;
45
+ const proto3 = syntax === 'proto3';
46
+ const repeated = field.rule === 'repeated' || field.keyType !== undefined;
47
+ const value = this.resolveValue(field.type, type.fullName);
48
+ const info = {
49
+ ...value,
50
+ name: camelCase(field.name),
51
+ protoName: field.name,
52
+ number: field.number,
53
+ repeated,
54
+ packed: (_a = field.packed) !== null && _a !== void 0 ? _a : (proto3 && repeated),
55
+ presence: !repeated &&
56
+ (value.kind === 'message' || field.oneof !== undefined || field.rule === 'optional' || field.rule === 'required' || !proto3),
57
+ oneof: field.oneof,
58
+ map: field.keyType ? { key: this.mapKeyKind(field.keyType, type.fullName), value } : undefined,
59
+ };
60
+ return info;
61
+ }));
62
+ }
63
+ for (const file of files) {
64
+ const prefix = file.package ? `${file.package}.` : '';
65
+ for (const service of file.services) {
66
+ const fullName = prefix + service.name;
67
+ this.serviceMap.set(fullName, {
68
+ fullName,
69
+ methods: service.methods.map(method => ({
70
+ name: method.name,
71
+ jsName: method.name[0].toLowerCase() + method.name.slice(1),
72
+ path: `/${fullName}/${method.name}`,
73
+ requestType: this.resolveMessage(method.requestType, fullName),
74
+ responseType: this.resolveMessage(method.responseType, fullName),
75
+ requestStream: method.requestStream,
76
+ responseStream: method.responseStream,
77
+ })),
78
+ });
79
+ }
80
+ }
81
+ }
82
+ get services() {
83
+ return [...this.serviceMap.values()];
84
+ }
85
+ service(name) {
86
+ return this.lookup(this.serviceMap, name, 'service');
87
+ }
88
+ message(name) {
89
+ const types = new Map([...this.types].filter(([, type]) => type instanceof MessageType));
90
+ return this.lookup(types, name, 'message');
91
+ }
92
+ enum(name) {
93
+ const types = new Map([...this.types].filter(([, type]) => type instanceof EnumType));
94
+ return this.lookup(types, name, 'enum');
95
+ }
96
+ lookup(map, name, what) {
97
+ const exact = map.get(name.replace(/^\./, ''));
98
+ if (exact) {
99
+ return exact;
100
+ }
101
+ const matches = [...map.keys()].filter(key => key.endsWith(`.${name}`));
102
+ const match = matches.length === 1 ? map.get(matches[0]) : undefined;
103
+ if (match) {
104
+ return match;
105
+ }
106
+ if (matches.length > 1) {
107
+ throw new Error(`The ${what} name '${name}' is ambiguous: ${matches.join(', ')}. Use the full name.`);
108
+ }
109
+ throw new Error(`No ${what} '${name}' in the .proto sources. ${what[0].toUpperCase() + what.slice(1)}s: ${[...map.keys()].join(', ') || 'none'}.`);
110
+ }
111
+ registerMessage(ast, prefix, syntax, pending) {
112
+ const type = new MessageType(prefix + ast.name);
113
+ this.register(type);
114
+ pending.push({ type, ast, syntax });
115
+ for (const nested of ast.messages) {
116
+ this.registerMessage(nested, `${type.fullName}.`, syntax, pending);
117
+ }
118
+ for (const e of ast.enums) {
119
+ this.registerEnum(e, `${type.fullName}.`);
120
+ }
121
+ }
122
+ registerEnum(ast, prefix) {
123
+ this.register(new EnumType(prefix + ast.name, ast.values));
124
+ }
125
+ register(type) {
126
+ if (this.types.has(type.fullName)) {
127
+ throw new Error(`The type ${type.fullName} is defined twice in the .proto sources.`);
128
+ }
129
+ this.types.set(type.fullName, type);
130
+ }
131
+ resolveValue(typeName, scope) {
132
+ if (SCALAR_KINDS.has(typeName)) {
133
+ return { kind: typeName };
134
+ }
135
+ const type = this.resolve(typeName, scope);
136
+ return type instanceof MessageType ? { kind: 'message', messageType: type } : { kind: 'enum', enumType: type };
137
+ }
138
+ resolveMessage(typeName, scope) {
139
+ const type = this.resolve(typeName, scope);
140
+ if (!(type instanceof MessageType)) {
141
+ throw new Error(`${typeName}, used by ${scope}, is an enum; methods take and return messages.`);
142
+ }
143
+ return type;
144
+ }
145
+ mapKeyKind(typeName, scope) {
146
+ if (!SCALAR_KINDS.has(typeName) || typeName === 'double' || typeName === 'float' || typeName === 'bytes') {
147
+ throw new Error(`${typeName} cannot be a map key (in ${scope}); use an integer, bool or string type.`);
148
+ }
149
+ return typeName;
150
+ }
151
+ /** Protobuf scoping: `.a.B` is absolute; otherwise the innermost enclosing scope that has the name wins. */
152
+ resolve(typeName, scope) {
153
+ if (typeName.startsWith('.')) {
154
+ const type = this.types.get(typeName.slice(1));
155
+ if (type) {
156
+ return type;
157
+ }
158
+ }
159
+ else {
160
+ const parts = scope.split('.');
161
+ for (let i = parts.length; i >= 0; i--) {
162
+ const type = this.types.get([...parts.slice(0, i), typeName].join('.'));
163
+ if (type) {
164
+ return type;
165
+ }
166
+ }
167
+ }
168
+ throw new Error(`Unknown type ${typeName} in ${scope}. If it is defined in an imported .proto file, pass that file's source to Proto.parse() too.`);
169
+ }
170
+ }
171
+ function camelCase(name) {
172
+ return name.replace(/(?!^)_+([a-zA-Z0-9])/g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AC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACxE,IAAI,IAAI,EAAE,CAAC;oBACP,OAAO,IAAI,CAAC;gBAChB,CAAC;YACL,CAAC;QACL,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gBAAgB,QAAQ,OAAO,KAAK,8FAA8F,CAAC,CAAC;IACxJ,CAAC;CACJ;AAED,SAAS,SAAS,CAAC,IAAY;IAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The well-known types of google/protobuf that services commonly import. Their messages are plain
3
+ * messages here: a Timestamp is `{ seconds: '1700000000', nanos: 0 }`, not a `Date`.
4
+ */
5
+ export declare const WELL_KNOWN_PROTOS: Readonly<Record<string, string>>;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The well-known types of google/protobuf that services commonly import. Their messages are plain
3
+ * messages here: a Timestamp is `{ seconds: '1700000000', nanos: 0 }`, not a `Date`.
4
+ */
5
+ export const WELL_KNOWN_PROTOS = {
6
+ 'google/protobuf/empty.proto': `syntax = "proto3"; package google.protobuf;
7
+ message Empty {}`,
8
+ 'google/protobuf/timestamp.proto': `syntax = "proto3"; package google.protobuf;
9
+ message Timestamp { int64 seconds = 1; int32 nanos = 2; }`,
10
+ 'google/protobuf/duration.proto': `syntax = "proto3"; package google.protobuf;
11
+ message Duration { int64 seconds = 1; int32 nanos = 2; }`,
12
+ 'google/protobuf/any.proto': `syntax = "proto3"; package google.protobuf;
13
+ message Any { string type_url = 1; bytes value = 2; }`,
14
+ 'google/protobuf/field_mask.proto': `syntax = "proto3"; package google.protobuf;
15
+ message FieldMask { repeated string paths = 1; }`,
16
+ 'google/protobuf/wrappers.proto': `syntax = "proto3"; package google.protobuf;
17
+ message DoubleValue { double value = 1; }
18
+ message FloatValue { float value = 1; }
19
+ message Int64Value { int64 value = 1; }
20
+ message UInt64Value { uint64 value = 1; }
21
+ message Int32Value { int32 value = 1; }
22
+ message UInt32Value { uint32 value = 1; }
23
+ message BoolValue { bool value = 1; }
24
+ message StringValue { string value = 1; }
25
+ message BytesValue { bytes value = 1; }`,
26
+ 'google/protobuf/struct.proto': `syntax = "proto3"; package google.protobuf;
27
+ message Struct { map<string, Value> fields = 1; }
28
+ message Value {
29
+ oneof kind {
30
+ NullValue null_value = 1;
31
+ double number_value = 2;
32
+ string string_value = 3;
33
+ bool bool_value = 4;
34
+ Struct struct_value = 5;
35
+ ListValue list_value = 6;
36
+ }
37
+ }
38
+ enum NullValue { NULL_VALUE = 0; }
39
+ message ListValue { repeated Value values = 1; }`,
40
+ };
41
+ //# sourceMappingURL=well-known.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"well-known.js","sourceRoot":"","sources":["../../../src/node/proto/well-known.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAqC;IAC/D,6BAA6B,EAAE;iBAClB;IACb,iCAAiC,EAAE;0DACmB;IACtD,gCAAgC,EAAE;yDACmB;IACrD,2BAA2B,EAAE;sDACqB;IAClD,kCAAkC,EAAE;iDACS;IAC7C,gCAAgC,EAAE;;;;;;;;;wCASE;IACpC,8BAA8B,EAAE;;;;;;;;;;;;;iDAaa;CAChD,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type Application, ApplicationLifecycle, Logger } from '@celljs/core';
2
+ import { GrpcServer } from './grpc-server.js';
3
+ export interface GrpcServerConfig {
4
+ enabled?: boolean;
5
+ port?: number;
6
+ host?: string;
7
+ maxReceiveMessageSize?: number;
8
+ }
9
+ /**
10
+ * Starts the gRPC server of the application with its {@link GrpcService} components (none: no server)
11
+ * and closes it when the application stops. `port` is the bound port once started.
12
+ */
13
+ export declare class GrpcServerLifecycle implements ApplicationLifecycle<Application> {
14
+ protected readonly services: object[];
15
+ protected readonly config?: GrpcServerConfig;
16
+ protected readonly logger: Logger;
17
+ server?: GrpcServer;
18
+ port?: number;
19
+ onStart(): Promise<void>;
20
+ onStop(): void;
21
+ }
@@ -0,0 +1,65 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { ApplicationLifecycle, Autowired, Component, getTargetClass, Logger, Optional, Value } from '@celljs/core';
11
+ import { GrpcServer } from './grpc-server.js';
12
+ import { GRPC_SERVICE, GrpcServiceUtil } from './grpc-service.js';
13
+ /**
14
+ * Starts the gRPC server of the application with its {@link GrpcService} components (none: no server)
15
+ * and closes it when the application stops. `port` is the bound port once started.
16
+ */
17
+ let GrpcServerLifecycle = class GrpcServerLifecycle {
18
+ constructor() {
19
+ this.services = [];
20
+ }
21
+ async onStart() {
22
+ var _a, _b, _c;
23
+ const config = (_a = this.config) !== null && _a !== void 0 ? _a : {};
24
+ if (this.services.length === 0 || config.enabled === false) {
25
+ return;
26
+ }
27
+ const server = new GrpcServer({
28
+ maxReceiveMessageSize: config.maxReceiveMessageSize,
29
+ onError: (error, method) => this.logger.error(error, `gRPC ${method.path}`),
30
+ });
31
+ for (const service of this.services) {
32
+ const definition = GrpcServiceUtil.getService(getTargetClass(service));
33
+ if (definition) {
34
+ server.addService(definition, service);
35
+ }
36
+ }
37
+ const host = (_b = config.host) !== null && _b !== void 0 ? _b : '127.0.0.1';
38
+ this.port = await server.listen((_c = config.port) !== null && _c !== void 0 ? _c : 50051, host);
39
+ this.server = server;
40
+ this.logger.info(`gRPC serve ${host}:${this.port}`);
41
+ }
42
+ onStop() {
43
+ var _a;
44
+ (_a = this.server) === null || _a === void 0 ? void 0 : _a.close(true);
45
+ this.server = undefined;
46
+ }
47
+ };
48
+ __decorate([
49
+ Autowired(GRPC_SERVICE),
50
+ Optional(),
51
+ __metadata("design:type", Array)
52
+ ], GrpcServerLifecycle.prototype, "services", void 0);
53
+ __decorate([
54
+ Value('grpc.server'),
55
+ __metadata("design:type", Object)
56
+ ], GrpcServerLifecycle.prototype, "config", void 0);
57
+ __decorate([
58
+ Autowired(Logger),
59
+ __metadata("design:type", Object)
60
+ ], GrpcServerLifecycle.prototype, "logger", void 0);
61
+ GrpcServerLifecycle = __decorate([
62
+ Component(ApplicationLifecycle)
63
+ ], GrpcServerLifecycle);
64
+ export { GrpcServerLifecycle };
65
+ //# sourceMappingURL=grpc-server-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grpc-server-lifecycle.js","sourceRoot":"","sources":["../../../src/node/server/grpc-server-lifecycle.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAoB,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrI,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAS/D;;;GAGG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QAGgB,aAAQ,GAAa,EAAE,CAAC;IAoC/C,CAAC;IAzBG,KAAK,CAAC,OAAO;;QACT,MAAM,MAAM,SAAG,IAAI,CAAC,MAAM,m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wB;AAG1B;IADlB,SAAS,CAAC,MAAM,CAAC;;mDACgB;AATzB,mBAAmB;IAD/B,SAAS,CAAC,oBAAoB,CAAC;GACnB,mBAAmB,CAuC/B"}
@@ -0,0 +1,60 @@
1
+ import { type Http2Server, type IncomingHttpHeaders, type ServerHttp2Session, type ServerHttp2Stream } from 'node:http2';
2
+ import { type Metadata } from '../call/metadata.js';
3
+ import type { MethodDefinition, ServiceDefinition } from '../proto/proto.js';
4
+ /** What a service method gets besides the request: the call's metadata, cancellation and response metadata. */
5
+ export interface ServerCall {
6
+ readonly method: MethodDefinition;
7
+ /** The request metadata (headers), keys in lowercase. */
8
+ readonly metadata: Metadata;
9
+ /** Aborted when the client cancels, the deadline passes or the server closes. */
10
+ readonly signal: AbortSignal;
11
+ readonly deadline?: Date;
12
+ /** Adds response metadata; only before the first response message. */
13
+ setHeader(key: string, value: Metadata[string]): void;
14
+ /** Adds metadata to the trailers that end the call. */
15
+ setTrailer(key: string, value: Metadata[string]): void;
16
+ }
17
+ type Awaitable<T> = T | Promise<T>;
18
+ type Stream<T> = Iterable<T> | AsyncIterable<T>;
19
+ /** `rpc M (Req) returns (Res)` */
20
+ export type UnaryHandler<Req = any, Res = any> = (request: Req, call: ServerCall) => Awaitable<Res>;
21
+ /** `rpc M (stream Req) returns (Res)` */
22
+ export type ClientStreamHandler<Req = any, Res = any> = (requests: AsyncIterable<Req>, call: ServerCall) => Awaitable<Res>;
23
+ /** `rpc M (Req) returns (stream Res)`: return an async generator or any (async) iterable. */
24
+ export type ServerStreamHandler<Req = any, Res = any> = (request: Req, call: ServerCall) => Awaitable<Stream<Res>>;
25
+ /** `rpc M (stream Req) returns (stream Res)` */
26
+ export type BidiStreamHandler<Req = any, Res = any> = (requests: AsyncIterable<Req>, call: ServerCall) => Awaitable<Stream<Res>>;
27
+ export interface GrpcServerOptions {
28
+ /** Largest request message accepted, in bytes. Default 4 MiB. */
29
+ maxReceiveMessageSize?: number;
30
+ /** Reports errors of service methods that are not {@link GrpcError}s. Default `console.error`. */
31
+ onError?: (error: unknown, method: MethodDefinition) => void;
32
+ }
33
+ interface Handler {
34
+ method: MethodDefinition;
35
+ fn: (...args: any[]) => any;
36
+ }
37
+ /**
38
+ * A gRPC server on `node:http2` (cleartext HTTP/2). Each method of a service is the method of the
39
+ * implementation named after it in lowerCamelCase (`SayHello` → `sayHello`); see {@link UnaryHandler}
40
+ * and the other handler types for their signatures. Methods without an implementation answer
41
+ * `UNIMPLEMENTED`.
42
+ *
43
+ * In a Cell application, use {@link GrpcService} instead: the application starts the server.
44
+ */
45
+ export declare class GrpcServer {
46
+ protected readonly options: GrpcServerOptions;
47
+ protected readonly handlers: Map<string, Handler>;
48
+ protected readonly sessions: Set<ServerHttp2Session<typeof import("http").IncomingMessage, typeof import("http").ServerResponse, typeof import("http2").Http2ServerRequest, typeof import("http2").Http2ServerResponse>>;
49
+ protected server?: Http2Server;
50
+ constructor(options?: GrpcServerOptions);
51
+ addService(service: ServiceDefinition, implementation: object): this;
52
+ /** Starts listening; resolves to the port, which is a free one when `port` is 0. */
53
+ listen(port?: number, host?: string): Promise<number>;
54
+ get port(): number | undefined;
55
+ /** Stops accepting connections and closes the open ones; `force` also cancels the calls in progress. */
56
+ close(force?: boolean): Promise<void>;
57
+ /** Serves one HTTP/2 stream; for servers of your own (`server.on('stream', ...)`). */
58
+ handleStream(stream: ServerHttp2Stream, headers: IncomingHttpHeaders): void;
59
+ }
60
+ export {};