@zero-server/grpc 0.9.6 → 0.9.8
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/debug.js +10 -10
- package/lib/grpc/call.js +14 -14
- package/lib/grpc/client.js +4 -4
- package/lib/grpc/codec.js +7 -7
- package/lib/grpc/credentials.js +2 -2
- package/lib/grpc/frame.js +2 -2
- package/lib/grpc/health.js +3 -3
- package/lib/grpc/index.js +3 -3
- package/lib/grpc/metadata.js +3 -3
- package/lib/grpc/proto.js +5 -5
- package/lib/grpc/reflection.js +2 -2
- package/lib/grpc/server.js +3 -3
- package/lib/grpc/status.js +2 -2
- package/lib/grpc/watch.js +1 -1
- package/package.json +2 -2
- package/types/body.d.ts +82 -14
- package/types/cli.d.ts +40 -2
- package/types/index.d.ts +19 -6
- package/types/middleware.d.ts +18 -72
- package/types/orm.d.ts +4 -13
- package/types/request.d.ts +3 -3
- package/types/webrtc.d.ts +501 -0
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// AUTO-GENERATED by .tools/generate-package-stubs.js
|
|
1
|
+
// AUTO-GENERATED by .tools/generate-package-stubs.js - edit .tools/scope-manifest.js and re-run `npm run packages:generate`.
|
|
2
2
|
export * from './types/grpc';
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// AUTO-GENERATED by .tools/generate-package-stubs.js
|
|
1
|
+
// AUTO-GENERATED by .tools/generate-package-stubs.js - edit .tools/scope-manifest.js and re-run `npm run packages:generate`.
|
|
2
2
|
'use strict';
|
|
3
3
|
const lib = require("./lib/grpc");
|
|
4
4
|
|
package/lib/debug.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* log.error('failed to connect', err);
|
|
17
17
|
* log('shorthand for debug level');
|
|
18
18
|
*
|
|
19
|
-
* // Set minimum level
|
|
19
|
+
* // Set minimum level - anything below is silenced
|
|
20
20
|
* debug.level('warn'); // only warn, error, fatal
|
|
21
21
|
* debug.level('silent'); // suppress all output
|
|
22
22
|
* debug.level('trace'); // show everything
|
|
@@ -81,7 +81,7 @@ _enabledPatterns = _parsePatterns();
|
|
|
81
81
|
*/
|
|
82
82
|
function _isEnabled(ns)
|
|
83
83
|
{
|
|
84
|
-
if (!_enabledPatterns) return true; // No DEBUG set
|
|
84
|
+
if (!_enabledPatterns) return true; // No DEBUG set - enable all
|
|
85
85
|
let enabled = false;
|
|
86
86
|
for (const { neg, re } of _enabledPatterns)
|
|
87
87
|
{
|
|
@@ -116,7 +116,7 @@ function _ts()
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* Format arguments (like console.log
|
|
119
|
+
* Format arguments (like console.log - supports %s, %d, %j, %o).
|
|
120
120
|
* @private
|
|
121
121
|
*/
|
|
122
122
|
function _format(args)
|
|
@@ -278,13 +278,13 @@ function debug(namespace)
|
|
|
278
278
|
* Messages below this level are silenced.
|
|
279
279
|
*
|
|
280
280
|
* @param {string|number} level - Level name or number.
|
|
281
|
-
* `'trace'` (0)
|
|
282
|
-
* `'debug'` (1)
|
|
283
|
-
* `'info'` (2)
|
|
284
|
-
* `'warn'` (3)
|
|
285
|
-
* `'error'` (4)
|
|
286
|
-
* `'fatal'` (5)
|
|
287
|
-
* `'silent'` (6)
|
|
281
|
+
* `'trace'` (0) - all output
|
|
282
|
+
* `'debug'` (1) - debug and above
|
|
283
|
+
* `'info'` (2) - info and above
|
|
284
|
+
* `'warn'` (3) - warn and above
|
|
285
|
+
* `'error'` (4) - error and fatal only
|
|
286
|
+
* `'fatal'` (5) - fatal only
|
|
287
|
+
* `'silent'` (6) - nothing
|
|
288
288
|
*/
|
|
289
289
|
debug.level = function(level)
|
|
290
290
|
{
|
package/lib/grpc/call.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* Wraps HTTP/2 streams with protobuf encode/decode, metadata,
|
|
5
5
|
* framing, deadline enforcement, and cancellation support.
|
|
6
6
|
*
|
|
7
|
-
* - `UnaryCall`
|
|
8
|
-
* - `ServerStreamCall`
|
|
9
|
-
* - `ClientStreamCall`
|
|
10
|
-
* - `BidiStreamCall`
|
|
7
|
+
* - `UnaryCall` - single request, single response
|
|
8
|
+
* - `ServerStreamCall` - single request, stream of responses
|
|
9
|
+
* - `ClientStreamCall` - stream of requests, single response
|
|
10
|
+
* - `BidiStreamCall` - bidirectional streaming
|
|
11
11
|
*
|
|
12
12
|
* @example | Unary handler
|
|
13
13
|
* async function GetUser(call) {
|
|
@@ -181,7 +181,7 @@ class BaseCall extends EventEmitter
|
|
|
181
181
|
|
|
182
182
|
if (!this._headersSent)
|
|
183
183
|
{
|
|
184
|
-
// Trailers-Only response
|
|
184
|
+
// Trailers-Only response - include status in initial HEADERS frame
|
|
185
185
|
this._headersSent = true;
|
|
186
186
|
try
|
|
187
187
|
{
|
|
@@ -199,7 +199,7 @@ class BaseCall extends EventEmitter
|
|
|
199
199
|
}
|
|
200
200
|
else
|
|
201
201
|
{
|
|
202
|
-
// Headers already sent
|
|
202
|
+
// Headers already sent - send trailing HEADERS after final DATA
|
|
203
203
|
this.stream.on('wantTrailers', () =>
|
|
204
204
|
{
|
|
205
205
|
try { this.stream.sendTrailers(trailHeaders); }
|
|
@@ -359,7 +359,7 @@ class BaseCall extends EventEmitter
|
|
|
359
359
|
// -- Unary Call --------------------------------------------
|
|
360
360
|
|
|
361
361
|
/**
|
|
362
|
-
* A unary gRPC call
|
|
362
|
+
* A unary gRPC call - single request message, single response message.
|
|
363
363
|
*
|
|
364
364
|
* @class
|
|
365
365
|
* @extends BaseCall
|
|
@@ -391,7 +391,7 @@ class UnaryCall extends BaseCall
|
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
/**
|
|
394
|
-
* Initialize the call
|
|
394
|
+
* Initialize the call - collect the full request body and decode it.
|
|
395
395
|
* @private
|
|
396
396
|
* @returns {Promise<void>}
|
|
397
397
|
*/
|
|
@@ -422,7 +422,7 @@ class UnaryCall extends BaseCall
|
|
|
422
422
|
// -- Server Streaming Call ---------------------------------
|
|
423
423
|
|
|
424
424
|
/**
|
|
425
|
-
* A server-streaming gRPC call
|
|
425
|
+
* A server-streaming gRPC call - single request, multiple responses.
|
|
426
426
|
* The handler calls `call.write(msg)` for each response and `call.end()` to finish.
|
|
427
427
|
*
|
|
428
428
|
* @class
|
|
@@ -481,7 +481,7 @@ class ServerStreamCall extends BaseCall
|
|
|
481
481
|
// -- Client Streaming Call ---------------------------------
|
|
482
482
|
|
|
483
483
|
/**
|
|
484
|
-
* A client-streaming gRPC call
|
|
484
|
+
* A client-streaming gRPC call - multiple requests, single response.
|
|
485
485
|
* The handler iterates `for await (const msg of call)` to consume messages,
|
|
486
486
|
* then returns the response object.
|
|
487
487
|
*
|
|
@@ -512,7 +512,7 @@ class ClientStreamCall extends BaseCall
|
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
/**
|
|
515
|
-
* Initialize
|
|
515
|
+
* Initialize - set up the frame parser to enqueue decoded messages.
|
|
516
516
|
* @private
|
|
517
517
|
*/
|
|
518
518
|
_init()
|
|
@@ -560,7 +560,7 @@ class ClientStreamCall extends BaseCall
|
|
|
560
560
|
}
|
|
561
561
|
|
|
562
562
|
/**
|
|
563
|
-
* Async iterator
|
|
563
|
+
* Async iterator - enables `for await (const msg of call)`.
|
|
564
564
|
*
|
|
565
565
|
* @returns {AsyncIterator<object>}
|
|
566
566
|
*/
|
|
@@ -589,7 +589,7 @@ class ClientStreamCall extends BaseCall
|
|
|
589
589
|
// -- Bidirectional Streaming Call ---------------------------
|
|
590
590
|
|
|
591
591
|
/**
|
|
592
|
-
* A bidirectional streaming gRPC call
|
|
592
|
+
* A bidirectional streaming gRPC call - multiple requests AND multiple responses.
|
|
593
593
|
* The handler can `for await` incoming messages while simultaneously
|
|
594
594
|
* calling `call.write()` to send responses.
|
|
595
595
|
*
|
|
@@ -673,7 +673,7 @@ class BidiStreamCall extends BaseCall
|
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
/**
|
|
676
|
-
* Async iterator
|
|
676
|
+
* Async iterator - enables `for await (const msg of call)`.
|
|
677
677
|
*
|
|
678
678
|
* @returns {AsyncIterator<object>}
|
|
679
679
|
*/
|
package/lib/grpc/client.js
CHANGED
|
@@ -266,7 +266,7 @@ class GrpcClient extends EventEmitter
|
|
|
266
266
|
// -- Unary Call -----------------------------------------
|
|
267
267
|
|
|
268
268
|
/**
|
|
269
|
-
* Make a unary gRPC call
|
|
269
|
+
* Make a unary gRPC call - send one message, receive one response.
|
|
270
270
|
*
|
|
271
271
|
* @param {string} methodName - RPC method name as defined in the proto service.
|
|
272
272
|
* @param {object} request - Request message object.
|
|
@@ -394,7 +394,7 @@ class GrpcClient extends EventEmitter
|
|
|
394
394
|
// -- Server Streaming ----------------------------------
|
|
395
395
|
|
|
396
396
|
/**
|
|
397
|
-
* Make a server-streaming gRPC call
|
|
397
|
+
* Make a server-streaming gRPC call - send one request, receive a stream of responses.
|
|
398
398
|
* Returns an async-iterable that yields decoded response messages.
|
|
399
399
|
*
|
|
400
400
|
* @param {string} methodName - RPC method name.
|
|
@@ -509,7 +509,7 @@ class GrpcClient extends EventEmitter
|
|
|
509
509
|
// -- Client Streaming ----------------------------------
|
|
510
510
|
|
|
511
511
|
/**
|
|
512
|
-
* Make a client-streaming gRPC call
|
|
512
|
+
* Make a client-streaming gRPC call - send a stream of requests, receive one response.
|
|
513
513
|
* Returns a writable object with `write()`, `end()`, and a `response` Promise.
|
|
514
514
|
*
|
|
515
515
|
* @param {string} methodName - RPC method name.
|
|
@@ -608,7 +608,7 @@ class GrpcClient extends EventEmitter
|
|
|
608
608
|
// -- Bidirectional Streaming ----------------------------
|
|
609
609
|
|
|
610
610
|
/**
|
|
611
|
-
* Make a bidirectional streaming gRPC call
|
|
611
|
+
* Make a bidirectional streaming gRPC call - send and receive streams simultaneously.
|
|
612
612
|
* Returns an object that is both writable (`write`/`end`) and async-iterable.
|
|
613
613
|
*
|
|
614
614
|
* @param {string} methodName - RPC method name.
|
package/lib/grpc/codec.js
CHANGED
|
@@ -76,7 +76,7 @@ const TYPE_INFO = {
|
|
|
76
76
|
// -- Writer ------------------------------------------------
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* Protobuf binary writer
|
|
79
|
+
* Protobuf binary writer - encodes JavaScript objects into wire-format bytes.
|
|
80
80
|
*
|
|
81
81
|
* @class
|
|
82
82
|
*
|
|
@@ -397,7 +397,7 @@ class Writer
|
|
|
397
397
|
// -- Reader ------------------------------------------------
|
|
398
398
|
|
|
399
399
|
/**
|
|
400
|
-
* Protobuf binary reader
|
|
400
|
+
* Protobuf binary reader - decodes wire-format bytes into JavaScript values.
|
|
401
401
|
*
|
|
402
402
|
* @class
|
|
403
403
|
*
|
|
@@ -762,7 +762,7 @@ class Reader
|
|
|
762
762
|
function encode(obj, messageDesc, allMessages, depth = 0)
|
|
763
763
|
{
|
|
764
764
|
if (depth > MAX_RECURSION_DEPTH)
|
|
765
|
-
throw new Error(`Maximum encoding depth (${MAX_RECURSION_DEPTH}) exceeded
|
|
765
|
+
throw new Error(`Maximum encoding depth (${MAX_RECURSION_DEPTH}) exceeded - possible circular reference`);
|
|
766
766
|
|
|
767
767
|
if (!obj || typeof obj !== 'object')
|
|
768
768
|
return Buffer.alloc(0);
|
|
@@ -809,7 +809,7 @@ function encode(obj, messageDesc, allMessages, depth = 0)
|
|
|
809
809
|
function decode(buffer, messageDesc, allMessages, depth = 0)
|
|
810
810
|
{
|
|
811
811
|
if (depth > MAX_RECURSION_DEPTH)
|
|
812
|
-
throw new Error(`Maximum decoding depth (${MAX_RECURSION_DEPTH}) exceeded
|
|
812
|
+
throw new Error(`Maximum decoding depth (${MAX_RECURSION_DEPTH}) exceeded - possible circular reference`);
|
|
813
813
|
|
|
814
814
|
if (!Buffer.isBuffer(buffer) || buffer.length === 0)
|
|
815
815
|
return _defaultObject(messageDesc);
|
|
@@ -830,7 +830,7 @@ function decode(buffer, messageDesc, allMessages, depth = 0)
|
|
|
830
830
|
|
|
831
831
|
if (!field)
|
|
832
832
|
{
|
|
833
|
-
// Unknown field
|
|
833
|
+
// Unknown field - skip it (forward compatibility)
|
|
834
834
|
reader.skipField(wireType);
|
|
835
835
|
continue;
|
|
836
836
|
}
|
|
@@ -868,7 +868,7 @@ function _encodeField(writer, field, value, allMessages, depth)
|
|
|
868
868
|
|
|
869
869
|
if (typeInfo)
|
|
870
870
|
{
|
|
871
|
-
// Scalar type
|
|
871
|
+
// Scalar type - skip default values in proto3
|
|
872
872
|
if (_isDefaultValue(field.type, value)) return;
|
|
873
873
|
|
|
874
874
|
writer.writeTag(field.number, typeInfo.wire);
|
|
@@ -913,7 +913,7 @@ function _encodeRepeated(writer, field, values, allMessages, depth)
|
|
|
913
913
|
}
|
|
914
914
|
else
|
|
915
915
|
{
|
|
916
|
-
// Non-packable (strings, bytes, messages)
|
|
916
|
+
// Non-packable (strings, bytes, messages) - one tag per element
|
|
917
917
|
for (const v of values) _encodeField(writer, field, v, allMessages, depth);
|
|
918
918
|
}
|
|
919
919
|
}
|
package/lib/grpc/credentials.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* and metadata-based credentials. Supports certificate rotation
|
|
6
6
|
* and credential composition.
|
|
7
7
|
*
|
|
8
|
-
* Uses only Node.js built-in `tls` and `fs`
|
|
8
|
+
* Uses only Node.js built-in `tls` and `fs` - no external packages.
|
|
9
9
|
*
|
|
10
10
|
* @example | Insecure (plaintext)
|
|
11
11
|
* const { ChannelCredentials, GrpcClient } = require('@zero-server/sdk');
|
|
@@ -71,7 +71,7 @@ class ChannelCredentials
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Create insecure (plaintext) credentials.
|
|
74
|
-
* No TLS
|
|
74
|
+
* No TLS - suitable for development or service-mesh environments
|
|
75
75
|
* where transport security is handled by the infrastructure.
|
|
76
76
|
*
|
|
77
77
|
* @returns {ChannelCredentials}
|
package/lib/grpc/frame.js
CHANGED
|
@@ -23,7 +23,7 @@ const log = require('../debug')('zero:grpc');
|
|
|
23
23
|
const FRAME_HEADER_SIZE = 5;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Maximum frame size (16 MB
|
|
26
|
+
* Maximum frame size (16 MB - matches the default gRPC max).
|
|
27
27
|
* @type {number}
|
|
28
28
|
*/
|
|
29
29
|
const MAX_FRAME_SIZE = 16 * 1024 * 1024;
|
|
@@ -92,7 +92,7 @@ function _buildFrame(payload, flag)
|
|
|
92
92
|
// -- Frame Decoder -----------------------------------------
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Stateful gRPC frame parser
|
|
95
|
+
* Stateful gRPC frame parser - buffers incoming data and emits complete
|
|
96
96
|
* decompressed messages. Designed to be fed chunks from an HTTP/2 stream.
|
|
97
97
|
*
|
|
98
98
|
* @class
|
package/lib/grpc/health.js
CHANGED
|
@@ -193,7 +193,7 @@ class HealthService
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
|
-
* Handle a Check RPC
|
|
196
|
+
* Handle a Check RPC - unary request for current health of a service.
|
|
197
197
|
* @param {import('./call').UnaryCall} call
|
|
198
198
|
*/
|
|
199
199
|
Check(call)
|
|
@@ -205,7 +205,7 @@ class HealthService
|
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
/**
|
|
208
|
-
* Handle a Watch RPC
|
|
208
|
+
* Handle a Watch RPC - server-stream that pushes status changes.
|
|
209
209
|
* Sends the current status immediately, then pushes on every change.
|
|
210
210
|
* @param {import('./call').ServerStreamCall} call
|
|
211
211
|
*/
|
|
@@ -232,7 +232,7 @@ class HealthService
|
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* Get the schema object needed for server registration.
|
|
235
|
-
* Avoids requiring proto parsing
|
|
235
|
+
* Avoids requiring proto parsing - returns descriptors directly.
|
|
236
236
|
* @returns {object} Schema compatible with GrpcServiceRegistry.addService
|
|
237
237
|
*/
|
|
238
238
|
getSchema()
|
package/lib/grpc/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module grpc
|
|
3
|
-
* @description Full gRPC support for zero-server
|
|
3
|
+
* @description Full gRPC support for zero-server - zero external dependencies.
|
|
4
4
|
* Provides a proto3 parser, protobuf codec, gRPC framing, call objects,
|
|
5
5
|
* a service server, and a client for all four RPC patterns.
|
|
6
6
|
*
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* - Graceful shutdown with call draining
|
|
15
15
|
* - Message size limits and deadline enforcement
|
|
16
16
|
*
|
|
17
|
-
* @example | Quick Start
|
|
17
|
+
* @example | Quick Start - Server
|
|
18
18
|
* const { createApp, parseProto } = require('@zero-server/sdk');
|
|
19
19
|
* const app = createApp();
|
|
20
20
|
* const schema = parseProto(`
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
*
|
|
36
36
|
* app.listen(50051, { http2: true });
|
|
37
37
|
*
|
|
38
|
-
* @example | Quick Start
|
|
38
|
+
* @example | Quick Start - Client
|
|
39
39
|
* const { GrpcClient, parseProto } = require('@zero-server/sdk');
|
|
40
40
|
* const schema = parseProto(fs.readFileSync('hello.proto', 'utf8'));
|
|
41
41
|
* const client = new GrpcClient('http://localhost:50051', schema, 'Greeter');
|
package/lib/grpc/metadata.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module grpc/metadata
|
|
3
|
-
* @description gRPC metadata container
|
|
3
|
+
* @description gRPC metadata container - typed key-value pairs transmitted as
|
|
4
4
|
* HTTP/2 headers (initial metadata) and trailers (trailing metadata).
|
|
5
5
|
* Keys ending in `-bin` carry binary values (base64-encoded on the wire).
|
|
6
6
|
* All other keys carry ASCII string values.
|
|
@@ -44,7 +44,7 @@ const GRPC_INTERNAL = new Set([
|
|
|
44
44
|
const MAX_KEY_LENGTH = 256;
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* Maximum total metadata size in bytes (soft limit
|
|
47
|
+
* Maximum total metadata size in bytes (soft limit - 8 KB default, configurable).
|
|
48
48
|
* @type {number}
|
|
49
49
|
*/
|
|
50
50
|
const DEFAULT_MAX_METADATA_SIZE = 8192;
|
|
@@ -52,7 +52,7 @@ const DEFAULT_MAX_METADATA_SIZE = 8192;
|
|
|
52
52
|
// -- Metadata Class ----------------------------------------
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* gRPC metadata container
|
|
55
|
+
* gRPC metadata container - type-safe key-value pairs for headers and trailers.
|
|
56
56
|
*
|
|
57
57
|
* @class
|
|
58
58
|
*
|
package/lib/grpc/proto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module grpc/proto
|
|
3
|
-
* @description Zero-dependency proto3 parser
|
|
3
|
+
* @description Zero-dependency proto3 parser - reads `.proto` file text and produces
|
|
4
4
|
* message descriptors, enum definitions, and service/RPC declarations
|
|
5
5
|
* that the codec and server use at runtime.
|
|
6
6
|
*
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* @example
|
|
18
18
|
* const { parseProto } = require('./proto');
|
|
19
19
|
* const schema = parseProto(fs.readFileSync('chat.proto', 'utf8'));
|
|
20
|
-
* // schema.messages
|
|
21
|
-
* // schema.enums
|
|
22
|
-
* // schema.services
|
|
20
|
+
* // schema.messages - { MessageName: { fields: [...] } }
|
|
21
|
+
* // schema.enums - { EnumName: { values: { ... } } }
|
|
22
|
+
* // schema.services - { ServiceName: { methods: { ... } } }
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
const fs = require('fs');
|
|
@@ -254,7 +254,7 @@ function parseProto(source, opts = {})
|
|
|
254
254
|
{
|
|
255
255
|
next(); expect('='); schema.syntax = next().value; expect(';');
|
|
256
256
|
if (schema.syntax !== 'proto3')
|
|
257
|
-
log.warn('proto file uses syntax "%s"
|
|
257
|
+
log.warn('proto file uses syntax "%s" - only proto3 is fully supported', schema.syntax);
|
|
258
258
|
}
|
|
259
259
|
else if (tok.value === 'package')
|
|
260
260
|
{
|
package/lib/grpc/reflection.js
CHANGED
|
@@ -54,7 +54,7 @@ function buildFileDescriptorProto(schema, filename)
|
|
|
54
54
|
// field 2: package (string)
|
|
55
55
|
if (schema.package) w.string(2, schema.package);
|
|
56
56
|
|
|
57
|
-
// field 3: dependency (repeated string)
|
|
57
|
+
// field 3: dependency (repeated string) - imported file names
|
|
58
58
|
if (schema.imports)
|
|
59
59
|
{
|
|
60
60
|
for (const imp of schema.imports)
|
|
@@ -191,7 +191,7 @@ function _buildFieldDescriptorProto(field, schema)
|
|
|
191
191
|
// field 9: oneof_index (if in a oneof)
|
|
192
192
|
if (field.oneofName !== undefined)
|
|
193
193
|
{
|
|
194
|
-
// Will use the index from the parent
|
|
194
|
+
// Will use the index from the parent - simplified to 0 for now
|
|
195
195
|
w.int32(9, 0);
|
|
196
196
|
}
|
|
197
197
|
|
package/lib/grpc/server.js
CHANGED
|
@@ -130,7 +130,7 @@ class GrpcServiceRegistry
|
|
|
130
130
|
{
|
|
131
131
|
if (!handlers[methodName])
|
|
132
132
|
{
|
|
133
|
-
log.warn('no handler for %s/%s
|
|
133
|
+
log.warn('no handler for %s/%s - will return UNIMPLEMENTED', serviceName, methodName);
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
const routePath = pathPrefix + '/' + methodName;
|
|
@@ -178,7 +178,7 @@ class GrpcServiceRegistry
|
|
|
178
178
|
const contentType = headers['content-type'] || '';
|
|
179
179
|
if (!contentType.startsWith('application/grpc'))
|
|
180
180
|
{
|
|
181
|
-
return false; // Not a gRPC request
|
|
181
|
+
return false; // Not a gRPC request - let the normal HTTP pipeline handle it
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
const grpcPath = headers[':path'];
|
|
@@ -290,7 +290,7 @@ class GrpcServiceRegistry
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
/**
|
|
293
|
-
* Begin draining
|
|
293
|
+
* Begin draining - reject new calls and wait for active calls to finish.
|
|
294
294
|
*
|
|
295
295
|
* @param {number} [timeout=30000] - Maximum time to wait in ms.
|
|
296
296
|
* @returns {Promise<void>}
|
package/lib/grpc/status.js
CHANGED
|
@@ -25,7 +25,7 @@ const GrpcStatus = {
|
|
|
25
25
|
OK: 0,
|
|
26
26
|
/** The operation was cancelled (typically by the caller). */
|
|
27
27
|
CANCELLED: 1,
|
|
28
|
-
/** Unknown error
|
|
28
|
+
/** Unknown error - a catch-all for unexpected failures. */
|
|
29
29
|
UNKNOWN: 2,
|
|
30
30
|
/** The client specified an invalid argument. */
|
|
31
31
|
INVALID_ARGUMENT: 3,
|
|
@@ -47,7 +47,7 @@ const GrpcStatus = {
|
|
|
47
47
|
OUT_OF_RANGE: 11,
|
|
48
48
|
/** The operation is not implemented or not supported. */
|
|
49
49
|
UNIMPLEMENTED: 12,
|
|
50
|
-
/** Internal error
|
|
50
|
+
/** Internal error - invariants expected by the server have been broken. */
|
|
51
51
|
INTERNAL: 13,
|
|
52
52
|
/** The service is currently unavailable, usually a transient condition. */
|
|
53
53
|
UNAVAILABLE: 14,
|
package/lib/grpc/watch.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Watches `.proto` files for changes using `fs.watch()` and
|
|
5
5
|
* re-parses/re-registers gRPC services automatically.
|
|
6
6
|
*
|
|
7
|
-
* **Dev-only**
|
|
7
|
+
* **Dev-only** - disabled by default when `NODE_ENV=production`.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* const { createApp, watchProto } = require('@zero-server/sdk');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zero-server/grpc",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"description": "gRPC server, client, codec, framing, status, metadata, health, reflection, balancer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zero-server",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@zero-server/sdk": ">=0.9.
|
|
48
|
+
"@zero-server/sdk": ">=0.9.8"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@zero-server/sdk": {
|
package/types/body.d.ts
CHANGED
|
@@ -1,14 +1,82 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
// TypeScript declarations for the bundled body parsers
|
|
2
|
+
// (`json`, `urlencoded`, `text`, `raw`, `multipart`).
|
|
3
|
+
//
|
|
4
|
+
// These live in `lib/body/*` at runtime and are surfaced both via the
|
|
5
|
+
// top-level SDK and the standalone `@zero-server/body` scope. They are
|
|
6
|
+
// declared here (not in `./middleware`) so the body-parser package has
|
|
7
|
+
// a self-contained declaration file.
|
|
8
|
+
|
|
9
|
+
import { MiddlewareFunction } from './middleware';
|
|
10
|
+
import { Request } from './request';
|
|
11
|
+
import { Response } from './response';
|
|
12
|
+
|
|
13
|
+
export interface BodyParserOptions {
|
|
14
|
+
/** Max body size (e.g. '10kb', '1mb'). Default: '1mb'. */
|
|
15
|
+
limit?: string | number;
|
|
16
|
+
/** Content-Type(s) to match. Accepts a string, an array of strings, or a predicate function. */
|
|
17
|
+
type?: string | string[] | ((ct: string) => boolean);
|
|
18
|
+
/** Reject non-HTTPS requests with 403. */
|
|
19
|
+
requireSecure?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Verification callback invoked with the raw buffer before parsing.
|
|
22
|
+
* Throw an error to reject the request with 403.
|
|
23
|
+
* Useful for webhook signature verification (e.g. Stripe, GitHub).
|
|
24
|
+
*/
|
|
25
|
+
verify?: (req: Request, res: Response, buf: Buffer, encoding: string) => void;
|
|
26
|
+
/** Decompress gzip/deflate/br request bodies. Default: true. When false, compressed bodies return 415. */
|
|
27
|
+
inflate?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface JsonParserOptions extends BodyParserOptions {
|
|
31
|
+
/** JSON.parse reviver function. */
|
|
32
|
+
reviver?: (key: string, value: any) => any;
|
|
33
|
+
/** Reject non-object/array roots. Default: true. */
|
|
34
|
+
strict?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface UrlencodedParserOptions extends BodyParserOptions {
|
|
38
|
+
/** Enable nested bracket parsing. Default: false. */
|
|
39
|
+
extended?: boolean;
|
|
40
|
+
/** Max number of parameters. Default: 1000. Prevents parameter flooding DoS. */
|
|
41
|
+
parameterLimit?: number;
|
|
42
|
+
/** Max nesting depth for bracket syntax. Default: 32. Prevents deep-nesting DoS. */
|
|
43
|
+
depth?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface TextParserOptions extends BodyParserOptions {
|
|
47
|
+
/** Fallback character encoding when Content-Type has no charset. Default: 'utf8'. */
|
|
48
|
+
encoding?: BufferEncoding;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface MultipartOptions {
|
|
52
|
+
/** Upload directory (default: OS temp). */
|
|
53
|
+
dir?: string;
|
|
54
|
+
/** Maximum size per file in bytes. */
|
|
55
|
+
maxFileSize?: number;
|
|
56
|
+
/** Reject non-HTTPS requests with 403. */
|
|
57
|
+
requireSecure?: boolean;
|
|
58
|
+
/** Maximum number of non-file fields. Default: 1000. */
|
|
59
|
+
maxFields?: number;
|
|
60
|
+
/** Maximum number of uploaded files. Default: 10. */
|
|
61
|
+
maxFiles?: number;
|
|
62
|
+
/** Maximum size of a single field value in bytes. Default: 1 MB. */
|
|
63
|
+
maxFieldSize?: number;
|
|
64
|
+
/** Whitelist of allowed MIME types for uploaded files (e.g. ['image/png', 'image/jpeg']). */
|
|
65
|
+
allowedMimeTypes?: string[];
|
|
66
|
+
/** Maximum combined size of all uploaded files in bytes. */
|
|
67
|
+
maxTotalSize?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface MultipartFile {
|
|
71
|
+
originalFilename: string;
|
|
72
|
+
storedName: string;
|
|
73
|
+
path: string;
|
|
74
|
+
contentType: string;
|
|
75
|
+
size: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function json(options?: JsonParserOptions): MiddlewareFunction;
|
|
79
|
+
export function urlencoded(options?: UrlencodedParserOptions): MiddlewareFunction;
|
|
80
|
+
export function text(options?: TextParserOptions): MiddlewareFunction;
|
|
81
|
+
export function raw(options?: BodyParserOptions): MiddlewareFunction;
|
|
82
|
+
export function multipart(options?: MultipartOptions): MiddlewareFunction;
|
package/types/cli.d.ts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
1
|
+
// TypeScript declarations for the bundled CLI runner (`zs` / `zh`).
|
|
2
|
+
//
|
|
3
|
+
// The CLI lives in `lib/cli.js` and is published both as the `zs` /
|
|
4
|
+
// `zh` bin scripts and as a programmatic API on the SDK. It dispatches
|
|
5
|
+
// ORM subcommands (`migrate`, `seed`, `make:*`) to `@zero-server/orm`
|
|
6
|
+
// and `webrtc:*` subcommands to `@zero-server/webrtc`, but the runner
|
|
7
|
+
// itself is scope-neutral - hence its own declaration file.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CLI runner for the bundled `zs` command.
|
|
11
|
+
*
|
|
12
|
+
* Parses `process.argv`-style input, resolves a config file
|
|
13
|
+
* (`zero.config.js` / `.zero-server.js` / `.zero-http.js`), and
|
|
14
|
+
* dispatches to the matching subcommand handler.
|
|
15
|
+
*/
|
|
16
|
+
export class CLI {
|
|
17
|
+
constructor(argv?: string[]);
|
|
18
|
+
|
|
19
|
+
/** The first positional argument (subcommand name). Defaults to `"help"`. */
|
|
20
|
+
readonly command: string;
|
|
21
|
+
|
|
22
|
+
/** Remaining positional arguments after the subcommand. */
|
|
23
|
+
readonly args: string[];
|
|
24
|
+
|
|
25
|
+
/** Parsed `--flag=value` and `-f value` pairs. */
|
|
26
|
+
readonly flags: Map<string, string>;
|
|
27
|
+
|
|
28
|
+
/** Execute the parsed command. Sets `process.exitCode` on failure. */
|
|
29
|
+
run(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* One-shot helper: `new CLI(argv).run()`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const { runCLI } = require('@zero-server/sdk');
|
|
37
|
+
* await runCLI(['migrate']);
|
|
38
|
+
* await runCLI(['make:model', 'User', '--dir=src/models']);
|
|
39
|
+
*/
|
|
40
|
+
export function runCLI(argv?: string[]): Promise<void>;
|