@loadstrike/loadstrike-sdk 1.0.26901 → 1.0.27301
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/README.md +3 -3
- package/dist/cjs/index.js +31 -2
- package/dist/cjs/local.js +74 -2
- package/dist/cjs/runtime.js +422 -2
- package/dist/cjs/sinks.js +262 -1
- package/dist/cjs/transports.js +659 -12
- package/dist/esm/index.js +3 -3
- package/dist/esm/local.js +74 -2
- package/dist/esm/runtime.js +414 -1
- package/dist/esm/sinks.js +249 -0
- package/dist/esm/transports.js +652 -11
- package/dist/types/contracts.d.ts +30 -0
- package/dist/types/index.d.ts +7 -7
- package/dist/types/runtime.d.ts +120 -0
- package/dist/types/sinks.d.ts +136 -0
- package/dist/types/transports.d.ts +194 -2
- package/package.json +1 -1
package/dist/esm/transports.js
CHANGED
|
@@ -285,6 +285,337 @@ class PushDiffusionEndpointDefinitionModel extends TrafficEndpointDefinitionMode
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
+
export const GrpcMethodTypes = {
|
|
289
|
+
Unary: "Unary",
|
|
290
|
+
ServerStreaming: "ServerStreaming",
|
|
291
|
+
ClientStreaming: "ClientStreaming",
|
|
292
|
+
BidirectionalStreaming: "BidirectionalStreaming"
|
|
293
|
+
};
|
|
294
|
+
export class GrpcNativeClientOptions {
|
|
295
|
+
constructor(initial = {}) {
|
|
296
|
+
this.UseReflection = false;
|
|
297
|
+
this.UseTls = true;
|
|
298
|
+
this.AllowUntrustedCertificates = false;
|
|
299
|
+
this.DeadlineSeconds = 30;
|
|
300
|
+
this.Metadata = {};
|
|
301
|
+
this.RequestPayloadJsonStream = [];
|
|
302
|
+
const raw = asRecordOrEmpty(initial);
|
|
303
|
+
this.ProtoFilePath = pickOptionalEndpointString(raw, "ProtoFilePath", "protoFilePath");
|
|
304
|
+
this.DescriptorSetPath = pickOptionalEndpointString(raw, "DescriptorSetPath", "descriptorSetPath");
|
|
305
|
+
this.UseReflection = pickEndpointBoolean(raw, "UseReflection", "useReflection") ?? false;
|
|
306
|
+
this.UseTls = pickEndpointBoolean(raw, "UseTls", "useTls") ?? true;
|
|
307
|
+
this.AllowUntrustedCertificates = pickEndpointBoolean(raw, "AllowUntrustedCertificates", "allowUntrustedCertificates") ?? false;
|
|
308
|
+
const deadlineMs = pickOptionalEndpointNumber(raw, "DeadlineMs", "deadlineMs");
|
|
309
|
+
const deadlineSeconds = pickOptionalEndpointNumber(raw, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline");
|
|
310
|
+
this.DeadlineSeconds = deadlineMs != null ? deadlineMs / 1000 : (deadlineSeconds ?? 30);
|
|
311
|
+
this.Metadata = pickEndpointStringRecord(raw, "Metadata", "metadata");
|
|
312
|
+
this.RequestPayloadJson = pickOptionalEndpointString(raw, "RequestPayloadJson", "requestPayloadJson");
|
|
313
|
+
this.RequestPayloadJsonStream = pickEndpointStringArray(raw, "RequestPayloadJsonStream", "requestPayloadJsonStream") ?? [];
|
|
314
|
+
}
|
|
315
|
+
Validate() {
|
|
316
|
+
this.validate();
|
|
317
|
+
}
|
|
318
|
+
validate() {
|
|
319
|
+
if (this.DeadlineSeconds <= 0) {
|
|
320
|
+
throw new RangeError("Deadline must be greater than zero.");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
export const GrpcStatusMapper = {
|
|
325
|
+
fromStatusCode(statusCode) {
|
|
326
|
+
const names = {
|
|
327
|
+
0: "OK",
|
|
328
|
+
1: "CANCELLED",
|
|
329
|
+
2: "UNKNOWN",
|
|
330
|
+
3: "INVALID_ARGUMENT",
|
|
331
|
+
4: "DEADLINE_EXCEEDED",
|
|
332
|
+
5: "NOT_FOUND",
|
|
333
|
+
6: "ALREADY_EXISTS",
|
|
334
|
+
7: "PERMISSION_DENIED",
|
|
335
|
+
8: "RESOURCE_EXHAUSTED",
|
|
336
|
+
9: "FAILED_PRECONDITION",
|
|
337
|
+
10: "ABORTED",
|
|
338
|
+
11: "OUT_OF_RANGE",
|
|
339
|
+
12: "UNIMPLEMENTED",
|
|
340
|
+
13: "INTERNAL",
|
|
341
|
+
14: "UNAVAILABLE",
|
|
342
|
+
15: "DATA_LOSS",
|
|
343
|
+
16: "UNAUTHENTICATED"
|
|
344
|
+
};
|
|
345
|
+
const normalized = Number.isFinite(statusCode) ? Math.trunc(statusCode) : 2;
|
|
346
|
+
const statusName = names[normalized] ?? "UNKNOWN";
|
|
347
|
+
return {
|
|
348
|
+
statusCode: normalized,
|
|
349
|
+
StatusCode: normalized,
|
|
350
|
+
statusName,
|
|
351
|
+
StatusName: statusName,
|
|
352
|
+
isSuccess: normalized === 0,
|
|
353
|
+
IsSuccess: normalized === 0
|
|
354
|
+
};
|
|
355
|
+
},
|
|
356
|
+
FromStatusCode(statusCode) {
|
|
357
|
+
return this.fromStatusCode(statusCode);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
export class ProtocolMetricSnapshot {
|
|
361
|
+
constructor(initial = {}) {
|
|
362
|
+
this.protocol = "";
|
|
363
|
+
this.Protocol = "";
|
|
364
|
+
this.requests = 0;
|
|
365
|
+
this.Requests = 0;
|
|
366
|
+
this.messagesSent = 0;
|
|
367
|
+
this.MessagesSent = 0;
|
|
368
|
+
this.messagesReceived = 0;
|
|
369
|
+
this.MessagesReceived = 0;
|
|
370
|
+
this.latencyMs = 0;
|
|
371
|
+
this.LatencyMs = 0;
|
|
372
|
+
this.streamDurationMs = 0;
|
|
373
|
+
this.StreamDurationMs = 0;
|
|
374
|
+
this.bytesSent = 0;
|
|
375
|
+
this.BytesSent = 0;
|
|
376
|
+
this.bytesReceived = 0;
|
|
377
|
+
this.BytesReceived = 0;
|
|
378
|
+
this.reconnects = 0;
|
|
379
|
+
this.Reconnects = 0;
|
|
380
|
+
this.errors = 0;
|
|
381
|
+
this.Errors = 0;
|
|
382
|
+
this.status = "";
|
|
383
|
+
this.Status = "";
|
|
384
|
+
const raw = asRecordOrEmpty(initial);
|
|
385
|
+
this.protocol = pickOptionalEndpointString(raw, "protocol", "Protocol") ?? "";
|
|
386
|
+
this.Protocol = this.protocol;
|
|
387
|
+
this.requests = pickOptionalEndpointNumber(raw, "requests", "Requests") ?? 0;
|
|
388
|
+
this.Requests = this.requests;
|
|
389
|
+
this.messagesSent = pickOptionalEndpointNumber(raw, "messagesSent", "MessagesSent") ?? 0;
|
|
390
|
+
this.MessagesSent = this.messagesSent;
|
|
391
|
+
this.messagesReceived = pickOptionalEndpointNumber(raw, "messagesReceived", "MessagesReceived") ?? 0;
|
|
392
|
+
this.MessagesReceived = this.messagesReceived;
|
|
393
|
+
this.latencyMs = pickOptionalEndpointNumber(raw, "latencyMs", "LatencyMs") ?? 0;
|
|
394
|
+
this.LatencyMs = this.latencyMs;
|
|
395
|
+
this.streamDurationMs = pickOptionalEndpointNumber(raw, "streamDurationMs", "StreamDurationMs") ?? 0;
|
|
396
|
+
this.StreamDurationMs = this.streamDurationMs;
|
|
397
|
+
this.bytesSent = pickOptionalEndpointNumber(raw, "bytesSent", "BytesSent") ?? 0;
|
|
398
|
+
this.BytesSent = this.bytesSent;
|
|
399
|
+
this.bytesReceived = pickOptionalEndpointNumber(raw, "bytesReceived", "BytesReceived") ?? 0;
|
|
400
|
+
this.BytesReceived = this.bytesReceived;
|
|
401
|
+
this.reconnects = pickOptionalEndpointNumber(raw, "reconnects", "Reconnects") ?? 0;
|
|
402
|
+
this.Reconnects = this.reconnects;
|
|
403
|
+
this.errors = pickOptionalEndpointNumber(raw, "errors", "Errors") ?? 0;
|
|
404
|
+
this.Errors = this.errors;
|
|
405
|
+
this.status = pickOptionalEndpointString(raw, "status", "Status") ?? "";
|
|
406
|
+
this.Status = this.status;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
class GrpcEndpointDefinitionModel extends TrafficEndpointDefinitionModel {
|
|
410
|
+
constructor(initial) {
|
|
411
|
+
super(initial);
|
|
412
|
+
this.Kind = "Grpc";
|
|
413
|
+
this.Target = "";
|
|
414
|
+
this.ServiceName = "";
|
|
415
|
+
this.MethodName = "";
|
|
416
|
+
this.MethodType = "Unary";
|
|
417
|
+
this.DeadlineSeconds = 30;
|
|
418
|
+
this.ConnectionMetadata = {};
|
|
419
|
+
this.Metadata = {};
|
|
420
|
+
initializeGrpcEndpointDefinitionModel(this, initial);
|
|
421
|
+
}
|
|
422
|
+
Validate() {
|
|
423
|
+
super.Validate();
|
|
424
|
+
requireNonEmptyString(this.Target, "Target must be provided for gRPC endpoint definitions.");
|
|
425
|
+
requireNonEmptyString(this.ServiceName, "ServiceName must be provided for gRPC endpoint definitions.");
|
|
426
|
+
requireNonEmptyString(this.MethodName, "MethodName must be provided for gRPC endpoint definitions.");
|
|
427
|
+
requireNonEmptyString(this.MethodType, "MethodType must be provided for gRPC endpoint definitions.");
|
|
428
|
+
if (this.DeadlineSeconds <= 0) {
|
|
429
|
+
throw new RangeError("Deadline must be greater than zero.");
|
|
430
|
+
}
|
|
431
|
+
this.NativeClient?.validate();
|
|
432
|
+
if (this.Mode === "Produce" && typeof this.ProduceAsync !== "function" && !this.NativeClient) {
|
|
433
|
+
throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
|
|
434
|
+
}
|
|
435
|
+
if (this.Mode === "Consume" && typeof this.ConsumeAsync !== "function" && !this.NativeClient) {
|
|
436
|
+
throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
export class WebSocketReconnectPolicy {
|
|
441
|
+
constructor(initial = {}) {
|
|
442
|
+
this.MaxAttempts = 0;
|
|
443
|
+
this.maxAttempts = 0;
|
|
444
|
+
this.DelaySeconds = 1;
|
|
445
|
+
this.delaySeconds = 1;
|
|
446
|
+
const raw = asRecordOrEmpty(initial);
|
|
447
|
+
this.MaxAttempts = Math.trunc(pickOptionalEndpointNumber(raw, "MaxAttempts", "maxAttempts") ?? 0);
|
|
448
|
+
this.maxAttempts = this.MaxAttempts;
|
|
449
|
+
const delayMs = pickOptionalEndpointNumber(raw, "DelayMs", "delayMs");
|
|
450
|
+
this.DelaySeconds = delayMs != null
|
|
451
|
+
? delayMs / 1000
|
|
452
|
+
: (pickOptionalEndpointNumber(raw, "DelaySeconds", "delaySeconds", "Delay", "delay") ?? 1);
|
|
453
|
+
this.delaySeconds = this.DelaySeconds;
|
|
454
|
+
}
|
|
455
|
+
Validate() {
|
|
456
|
+
this.validate();
|
|
457
|
+
}
|
|
458
|
+
validate() {
|
|
459
|
+
if (this.MaxAttempts < 0) {
|
|
460
|
+
throw new RangeError("MaxAttempts cannot be negative.");
|
|
461
|
+
}
|
|
462
|
+
if (this.DelaySeconds < 0) {
|
|
463
|
+
throw new RangeError("Delay cannot be negative.");
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
export class WebSocketMessageSpec {
|
|
468
|
+
constructor(initial = {}) {
|
|
469
|
+
this.Kind = "Text";
|
|
470
|
+
this.kind = "Text";
|
|
471
|
+
const raw = asRecordOrEmpty(initial);
|
|
472
|
+
this.Kind = pickOptionalEndpointString(raw, "Kind", "kind") ?? "Text";
|
|
473
|
+
this.kind = this.Kind;
|
|
474
|
+
this.TextPayload = pickOptionalEndpointString(raw, "TextPayload", "textPayload");
|
|
475
|
+
this.textPayload = this.TextPayload;
|
|
476
|
+
const binary = pickEndpointValue(raw, "BinaryPayload", "binaryPayload");
|
|
477
|
+
if (binary instanceof Uint8Array) {
|
|
478
|
+
this.BinaryPayload = binary;
|
|
479
|
+
}
|
|
480
|
+
else if (Array.isArray(binary)) {
|
|
481
|
+
this.BinaryPayload = Uint8Array.from(binary.map((value) => Number(value) & 0xff));
|
|
482
|
+
}
|
|
483
|
+
this.binaryPayload = this.BinaryPayload;
|
|
484
|
+
}
|
|
485
|
+
static Text(payload) {
|
|
486
|
+
return new WebSocketMessageSpec({ Kind: "Text", TextPayload: payload });
|
|
487
|
+
}
|
|
488
|
+
static Binary(payload) {
|
|
489
|
+
return new WebSocketMessageSpec({ Kind: "Binary", BinaryPayload: payload });
|
|
490
|
+
}
|
|
491
|
+
Validate() {
|
|
492
|
+
this.validate();
|
|
493
|
+
}
|
|
494
|
+
validate() {
|
|
495
|
+
if (this.Kind.toLowerCase() === "text" && this.TextPayload == null) {
|
|
496
|
+
throw new Error("Text WebSocket messages require TextPayload.");
|
|
497
|
+
}
|
|
498
|
+
if (this.Kind.toLowerCase() === "binary" && this.BinaryPayload == null) {
|
|
499
|
+
throw new Error("Binary WebSocket messages require BinaryPayload.");
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
export class WebSocketExpectedMessage {
|
|
504
|
+
constructor(initial = {}) {
|
|
505
|
+
this.TimeoutSeconds = 30;
|
|
506
|
+
this.timeoutSeconds = 30;
|
|
507
|
+
const raw = asRecordOrEmpty(initial);
|
|
508
|
+
this.ContainsText = pickOptionalEndpointString(raw, "ContainsText", "containsText");
|
|
509
|
+
this.containsText = this.ContainsText;
|
|
510
|
+
const bytes = pickEndpointValue(raw, "ContainsBytes", "containsBytes");
|
|
511
|
+
if (bytes instanceof Uint8Array) {
|
|
512
|
+
this.ContainsBytes = bytes;
|
|
513
|
+
}
|
|
514
|
+
else if (Array.isArray(bytes)) {
|
|
515
|
+
this.ContainsBytes = Uint8Array.from(bytes.map((value) => Number(value) & 0xff));
|
|
516
|
+
}
|
|
517
|
+
this.containsBytes = this.ContainsBytes;
|
|
518
|
+
const timeoutMs = pickOptionalEndpointNumber(raw, "TimeoutMs", "timeoutMs");
|
|
519
|
+
this.TimeoutSeconds = timeoutMs != null
|
|
520
|
+
? timeoutMs / 1000
|
|
521
|
+
: (pickOptionalEndpointNumber(raw, "TimeoutSeconds", "timeoutSeconds", "Timeout", "timeout") ?? 30);
|
|
522
|
+
this.timeoutSeconds = this.TimeoutSeconds;
|
|
523
|
+
}
|
|
524
|
+
Validate() {
|
|
525
|
+
this.validate();
|
|
526
|
+
}
|
|
527
|
+
validate() {
|
|
528
|
+
if (this.TimeoutSeconds <= 0) {
|
|
529
|
+
throw new RangeError("Timeout must be greater than zero.");
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
export class WebSocketNativeClientOptions {
|
|
534
|
+
constructor(initial = {}) {
|
|
535
|
+
this.Headers = {};
|
|
536
|
+
this.headers = {};
|
|
537
|
+
this.Cookies = [];
|
|
538
|
+
this.cookies = [];
|
|
539
|
+
this.Reconnect = new WebSocketReconnectPolicy();
|
|
540
|
+
this.reconnect = this.Reconnect;
|
|
541
|
+
this.Messages = [];
|
|
542
|
+
this.messages = [];
|
|
543
|
+
this.ExpectedMessages = [];
|
|
544
|
+
this.expectedMessages = [];
|
|
545
|
+
const raw = asRecordOrEmpty(initial);
|
|
546
|
+
this.Headers = pickEndpointStringRecord(raw, "Headers", "headers");
|
|
547
|
+
this.headers = this.Headers;
|
|
548
|
+
this.Cookies = pickEndpointStringArray(raw, "Cookies", "cookies") ?? [];
|
|
549
|
+
this.cookies = this.Cookies;
|
|
550
|
+
const pingMs = pickOptionalEndpointNumber(raw, "PingIntervalMs", "pingIntervalMs");
|
|
551
|
+
const pingSeconds = pickOptionalEndpointNumber(raw, "PingIntervalSeconds", "pingIntervalSeconds", "PingInterval", "pingInterval");
|
|
552
|
+
this.PingIntervalSeconds = pingMs != null ? pingMs / 1000 : pingSeconds;
|
|
553
|
+
this.pingIntervalSeconds = this.PingIntervalSeconds;
|
|
554
|
+
const reconnect = pickEndpointValue(raw, "Reconnect", "reconnect");
|
|
555
|
+
this.Reconnect = reconnect instanceof WebSocketReconnectPolicy
|
|
556
|
+
? reconnect
|
|
557
|
+
: new WebSocketReconnectPolicy(asRecordOrEmpty(reconnect));
|
|
558
|
+
this.reconnect = this.Reconnect;
|
|
559
|
+
this.Messages = normalizeWebSocketMessages(pickEndpointValue(raw, "Messages", "messages"));
|
|
560
|
+
this.messages = this.Messages;
|
|
561
|
+
this.ExpectedMessages = normalizeWebSocketExpectedMessages(pickEndpointValue(raw, "ExpectedMessages", "expectedMessages"));
|
|
562
|
+
this.expectedMessages = this.ExpectedMessages;
|
|
563
|
+
}
|
|
564
|
+
Validate() {
|
|
565
|
+
this.validate();
|
|
566
|
+
}
|
|
567
|
+
validate() {
|
|
568
|
+
if (this.PingIntervalSeconds != null && this.PingIntervalSeconds <= 0) {
|
|
569
|
+
throw new RangeError("PingInterval must be greater than zero.");
|
|
570
|
+
}
|
|
571
|
+
this.Reconnect.validate();
|
|
572
|
+
for (const message of this.Messages) {
|
|
573
|
+
message.validate();
|
|
574
|
+
}
|
|
575
|
+
for (const expected of this.ExpectedMessages) {
|
|
576
|
+
expected.validate();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
class WebSocketEndpointDefinitionModel extends TrafficEndpointDefinitionModel {
|
|
581
|
+
constructor(initial) {
|
|
582
|
+
super(initial);
|
|
583
|
+
this.Kind = "WebSocket";
|
|
584
|
+
this.Url = "";
|
|
585
|
+
this.Subprotocols = [];
|
|
586
|
+
this.ConnectTimeoutSeconds = 30;
|
|
587
|
+
this.CloseTimeoutSeconds = 5;
|
|
588
|
+
this.ConnectionMetadata = {};
|
|
589
|
+
initializeWebSocketEndpointDefinitionModel(this, initial);
|
|
590
|
+
}
|
|
591
|
+
Validate() {
|
|
592
|
+
super.Validate();
|
|
593
|
+
const url = requireNonEmptyString(this.Url, "Url must be provided for WebSocket endpoint definitions.");
|
|
594
|
+
let parsed;
|
|
595
|
+
try {
|
|
596
|
+
parsed = new URL(url);
|
|
597
|
+
}
|
|
598
|
+
catch {
|
|
599
|
+
throw new Error("Url must be an absolute ws:// or wss:// URI.");
|
|
600
|
+
}
|
|
601
|
+
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
602
|
+
throw new Error("Url must be an absolute ws:// or wss:// URI.");
|
|
603
|
+
}
|
|
604
|
+
if (this.ConnectTimeoutSeconds <= 0) {
|
|
605
|
+
throw new RangeError("ConnectTimeout must be greater than zero.");
|
|
606
|
+
}
|
|
607
|
+
if (this.CloseTimeoutSeconds <= 0) {
|
|
608
|
+
throw new RangeError("CloseTimeout must be greater than zero.");
|
|
609
|
+
}
|
|
610
|
+
this.NativeClient?.validate();
|
|
611
|
+
if (this.Mode === "Produce" && typeof this.ProduceAsync !== "function" && !this.NativeClient) {
|
|
612
|
+
throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
|
|
613
|
+
}
|
|
614
|
+
if (this.Mode === "Consume" && typeof this.ConsumeAsync !== "function" && !this.NativeClient) {
|
|
615
|
+
throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
288
619
|
export const TrafficEndpointDefinition = TrafficEndpointDefinitionModel;
|
|
289
620
|
export const HttpEndpointDefinition = HttpEndpointDefinitionModel;
|
|
290
621
|
export const KafkaEndpointDefinition = KafkaEndpointDefinitionModel;
|
|
@@ -295,6 +626,8 @@ export const AzureEventHubsEndpointDefinition = AzureEventHubsEndpointDefinition
|
|
|
295
626
|
export const SqsEndpointDefinition = SqsEndpointDefinitionModel;
|
|
296
627
|
export const DelegateStreamEndpointDefinition = DelegateStreamEndpointDefinitionModel;
|
|
297
628
|
export const PushDiffusionEndpointDefinition = PushDiffusionEndpointDefinitionModel;
|
|
629
|
+
export const GrpcEndpointDefinition = GrpcEndpointDefinitionModel;
|
|
630
|
+
export const WebSocketEndpointDefinition = WebSocketEndpointDefinitionModel;
|
|
298
631
|
export const HttpOAuth2ClientCredentialsOptions = HttpOAuth2ClientCredentialsOptionsModel;
|
|
299
632
|
export const HttpAuthOptions = HttpAuthOptionsModel;
|
|
300
633
|
export const KafkaSaslOptions = KafkaSaslOptionsModel;
|
|
@@ -744,6 +1077,113 @@ function initializePushDiffusionEndpointDefinitionModel(target, initial) {
|
|
|
744
1077
|
target.SubscribeAsync = subscribeAsync;
|
|
745
1078
|
}
|
|
746
1079
|
}
|
|
1080
|
+
function initializeGrpcEndpointDefinitionModel(target, initial) {
|
|
1081
|
+
const raw = asRecordOrEmpty(initial);
|
|
1082
|
+
const targetUrl = pickOptionalEndpointString(raw, "Target", "target");
|
|
1083
|
+
if (targetUrl) {
|
|
1084
|
+
target.Target = targetUrl;
|
|
1085
|
+
}
|
|
1086
|
+
const serviceName = pickOptionalEndpointString(raw, "ServiceName", "serviceName");
|
|
1087
|
+
if (serviceName) {
|
|
1088
|
+
target.ServiceName = serviceName;
|
|
1089
|
+
}
|
|
1090
|
+
const methodName = pickOptionalEndpointString(raw, "MethodName", "methodName");
|
|
1091
|
+
if (methodName) {
|
|
1092
|
+
target.MethodName = methodName;
|
|
1093
|
+
}
|
|
1094
|
+
const methodType = pickOptionalEndpointString(raw, "MethodType", "methodType");
|
|
1095
|
+
if (methodType) {
|
|
1096
|
+
target.MethodType = methodType;
|
|
1097
|
+
}
|
|
1098
|
+
const deadlineMs = pickOptionalEndpointNumber(raw, "DeadlineMs", "deadlineMs");
|
|
1099
|
+
const deadlineSeconds = pickOptionalEndpointNumber(raw, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline");
|
|
1100
|
+
if (deadlineMs != null) {
|
|
1101
|
+
target.DeadlineSeconds = deadlineMs / 1000;
|
|
1102
|
+
}
|
|
1103
|
+
else if (deadlineSeconds != null) {
|
|
1104
|
+
target.DeadlineSeconds = deadlineSeconds;
|
|
1105
|
+
}
|
|
1106
|
+
const produce = pickEndpointFunction(raw, "Produce", "produce");
|
|
1107
|
+
if (produce) {
|
|
1108
|
+
target.Produce = produce;
|
|
1109
|
+
}
|
|
1110
|
+
const consume = pickEndpointFunction(raw, "Consume", "consume");
|
|
1111
|
+
if (consume) {
|
|
1112
|
+
target.Consume = consume;
|
|
1113
|
+
}
|
|
1114
|
+
const produceAsync = pickEndpointFunction(raw, "ProduceAsync", "produceAsync");
|
|
1115
|
+
if (produceAsync) {
|
|
1116
|
+
target.ProduceAsync = produceAsync;
|
|
1117
|
+
}
|
|
1118
|
+
const consumeAsync = pickEndpointFunction(raw, "ConsumeAsync", "consumeAsync");
|
|
1119
|
+
if (consumeAsync) {
|
|
1120
|
+
target.ConsumeAsync = consumeAsync;
|
|
1121
|
+
}
|
|
1122
|
+
if (hasAnyEndpointField(raw, ["ConnectionMetadata", "connectionMetadata"])) {
|
|
1123
|
+
target.ConnectionMetadata = pickEndpointStringRecord(raw, "ConnectionMetadata", "connectionMetadata");
|
|
1124
|
+
}
|
|
1125
|
+
if (hasAnyEndpointField(raw, ["Metadata", "metadata"])) {
|
|
1126
|
+
target.Metadata = pickEndpointStringRecord(raw, "Metadata", "metadata");
|
|
1127
|
+
}
|
|
1128
|
+
if (hasAnyEndpointField(raw, ["NativeClient", "nativeClient"])) {
|
|
1129
|
+
const nativeClient = pickEndpointValue(raw, "NativeClient", "nativeClient");
|
|
1130
|
+
target.NativeClient = nativeClient instanceof GrpcNativeClientOptions
|
|
1131
|
+
? nativeClient
|
|
1132
|
+
: new GrpcNativeClientOptions(asRecordOrEmpty(nativeClient));
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
function initializeWebSocketEndpointDefinitionModel(target, initial) {
|
|
1136
|
+
const raw = asRecordOrEmpty(initial);
|
|
1137
|
+
const url = pickOptionalEndpointString(raw, "Url", "url");
|
|
1138
|
+
if (url) {
|
|
1139
|
+
target.Url = url;
|
|
1140
|
+
}
|
|
1141
|
+
const subprotocols = pickEndpointStringArray(raw, "Subprotocols", "subprotocols");
|
|
1142
|
+
if (subprotocols) {
|
|
1143
|
+
target.Subprotocols = subprotocols;
|
|
1144
|
+
}
|
|
1145
|
+
const connectMs = pickOptionalEndpointNumber(raw, "ConnectTimeoutMs", "connectTimeoutMs");
|
|
1146
|
+
const connectSeconds = pickOptionalEndpointNumber(raw, "ConnectTimeoutSeconds", "connectTimeoutSeconds", "ConnectTimeout", "connectTimeout");
|
|
1147
|
+
if (connectMs != null) {
|
|
1148
|
+
target.ConnectTimeoutSeconds = connectMs / 1000;
|
|
1149
|
+
}
|
|
1150
|
+
else if (connectSeconds != null) {
|
|
1151
|
+
target.ConnectTimeoutSeconds = connectSeconds;
|
|
1152
|
+
}
|
|
1153
|
+
const closeMs = pickOptionalEndpointNumber(raw, "CloseTimeoutMs", "closeTimeoutMs");
|
|
1154
|
+
const closeSeconds = pickOptionalEndpointNumber(raw, "CloseTimeoutSeconds", "closeTimeoutSeconds", "CloseTimeout", "closeTimeout");
|
|
1155
|
+
if (closeMs != null) {
|
|
1156
|
+
target.CloseTimeoutSeconds = closeMs / 1000;
|
|
1157
|
+
}
|
|
1158
|
+
else if (closeSeconds != null) {
|
|
1159
|
+
target.CloseTimeoutSeconds = closeSeconds;
|
|
1160
|
+
}
|
|
1161
|
+
const produce = pickEndpointFunction(raw, "Produce", "produce");
|
|
1162
|
+
if (produce) {
|
|
1163
|
+
target.Produce = produce;
|
|
1164
|
+
}
|
|
1165
|
+
const consume = pickEndpointFunction(raw, "Consume", "consume");
|
|
1166
|
+
if (consume) {
|
|
1167
|
+
target.Consume = consume;
|
|
1168
|
+
}
|
|
1169
|
+
const produceAsync = pickEndpointFunction(raw, "ProduceAsync", "produceAsync");
|
|
1170
|
+
if (produceAsync) {
|
|
1171
|
+
target.ProduceAsync = produceAsync;
|
|
1172
|
+
}
|
|
1173
|
+
const consumeAsync = pickEndpointFunction(raw, "ConsumeAsync", "consumeAsync");
|
|
1174
|
+
if (consumeAsync) {
|
|
1175
|
+
target.ConsumeAsync = consumeAsync;
|
|
1176
|
+
}
|
|
1177
|
+
if (hasAnyEndpointField(raw, ["ConnectionMetadata", "connectionMetadata"])) {
|
|
1178
|
+
target.ConnectionMetadata = pickEndpointStringRecord(raw, "ConnectionMetadata", "connectionMetadata");
|
|
1179
|
+
}
|
|
1180
|
+
if (hasAnyEndpointField(raw, ["NativeClient", "nativeClient"])) {
|
|
1181
|
+
const nativeClient = pickEndpointValue(raw, "NativeClient", "nativeClient");
|
|
1182
|
+
target.NativeClient = nativeClient instanceof WebSocketNativeClientOptions
|
|
1183
|
+
? nativeClient
|
|
1184
|
+
: new WebSocketNativeClientOptions(asRecordOrEmpty(nativeClient));
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
747
1187
|
function validateTrafficEndpointDefinitionModel(target) {
|
|
748
1188
|
requireNonEmptyString(target.Name, "Endpoint name must be provided.");
|
|
749
1189
|
if (target.Mode !== "Produce" && target.Mode !== "Consume") {
|
|
@@ -1878,6 +2318,10 @@ class PushDiffusionEndpointAdapter extends CallbackAdapter {
|
|
|
1878
2318
|
}
|
|
1879
2319
|
class DelegateStreamEndpointAdapter extends CallbackAdapter {
|
|
1880
2320
|
}
|
|
2321
|
+
class GrpcEndpointAdapter extends CallbackAdapter {
|
|
2322
|
+
}
|
|
2323
|
+
class WebSocketEndpointAdapter extends CallbackAdapter {
|
|
2324
|
+
}
|
|
1881
2325
|
export class EndpointAdapterFactory {
|
|
1882
2326
|
static create(endpoint) {
|
|
1883
2327
|
if (endpoint instanceof TrafficEndpointDefinitionModel) {
|
|
@@ -1904,6 +2348,10 @@ export class EndpointAdapterFactory {
|
|
|
1904
2348
|
return new PushDiffusionEndpointAdapter(normalized);
|
|
1905
2349
|
case "DelegateStream":
|
|
1906
2350
|
return new DelegateStreamEndpointAdapter(normalized);
|
|
2351
|
+
case "Grpc":
|
|
2352
|
+
return new GrpcEndpointAdapter(normalized);
|
|
2353
|
+
case "WebSocket":
|
|
2354
|
+
return new WebSocketEndpointAdapter(normalized);
|
|
1907
2355
|
default:
|
|
1908
2356
|
throw new Error(`Unsupported endpoint kind: ${String(normalized?.kind ?? "")}.`);
|
|
1909
2357
|
}
|
|
@@ -2066,6 +2514,66 @@ const PUSH_DIFFUSION_ENDPOINT_FLAT_KEYS = [
|
|
|
2066
2514
|
"subscribeAsync"
|
|
2067
2515
|
];
|
|
2068
2516
|
const DELEGATE_STREAM_ENDPOINT_FLAT_KEYS = [
|
|
2517
|
+
"Produce",
|
|
2518
|
+
"produce",
|
|
2519
|
+
"Consume",
|
|
2520
|
+
"consume",
|
|
2521
|
+
"ProduceAsync",
|
|
2522
|
+
"produceAsync",
|
|
2523
|
+
"ConsumeAsync",
|
|
2524
|
+
"consumeAsync",
|
|
2525
|
+
"ConnectionMetadata",
|
|
2526
|
+
"connectionMetadata",
|
|
2527
|
+
"NativeClient",
|
|
2528
|
+
"nativeClient"
|
|
2529
|
+
];
|
|
2530
|
+
const GRPC_ENDPOINT_FLAT_KEYS = [
|
|
2531
|
+
"Target",
|
|
2532
|
+
"target",
|
|
2533
|
+
"ServiceName",
|
|
2534
|
+
"serviceName",
|
|
2535
|
+
"MethodName",
|
|
2536
|
+
"methodName",
|
|
2537
|
+
"MethodType",
|
|
2538
|
+
"methodType",
|
|
2539
|
+
"Deadline",
|
|
2540
|
+
"deadline",
|
|
2541
|
+
"DeadlineSeconds",
|
|
2542
|
+
"deadlineSeconds",
|
|
2543
|
+
"DeadlineMs",
|
|
2544
|
+
"deadlineMs",
|
|
2545
|
+
"Metadata",
|
|
2546
|
+
"metadata",
|
|
2547
|
+
"Produce",
|
|
2548
|
+
"produce",
|
|
2549
|
+
"Consume",
|
|
2550
|
+
"consume",
|
|
2551
|
+
"ProduceAsync",
|
|
2552
|
+
"produceAsync",
|
|
2553
|
+
"ConsumeAsync",
|
|
2554
|
+
"consumeAsync",
|
|
2555
|
+
"ConnectionMetadata",
|
|
2556
|
+
"connectionMetadata",
|
|
2557
|
+
"NativeClient",
|
|
2558
|
+
"nativeClient"
|
|
2559
|
+
];
|
|
2560
|
+
const WEB_SOCKET_ENDPOINT_FLAT_KEYS = [
|
|
2561
|
+
"Url",
|
|
2562
|
+
"url",
|
|
2563
|
+
"Subprotocols",
|
|
2564
|
+
"subprotocols",
|
|
2565
|
+
"ConnectTimeout",
|
|
2566
|
+
"connectTimeout",
|
|
2567
|
+
"ConnectTimeoutSeconds",
|
|
2568
|
+
"connectTimeoutSeconds",
|
|
2569
|
+
"ConnectTimeoutMs",
|
|
2570
|
+
"connectTimeoutMs",
|
|
2571
|
+
"CloseTimeout",
|
|
2572
|
+
"closeTimeout",
|
|
2573
|
+
"CloseTimeoutSeconds",
|
|
2574
|
+
"closeTimeoutSeconds",
|
|
2575
|
+
"CloseTimeoutMs",
|
|
2576
|
+
"closeTimeoutMs",
|
|
2069
2577
|
"Produce",
|
|
2070
2578
|
"produce",
|
|
2071
2579
|
"Consume",
|
|
@@ -2111,7 +2619,9 @@ function normalizeEndpointDefinition(endpoint) {
|
|
|
2111
2619
|
azureEventHubs: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "AzureEventHubs", ["azureEventHubs", "AzureEventHubs"], AZURE_EVENT_HUBS_ENDPOINT_FLAT_KEYS)),
|
|
2112
2620
|
sqs: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "Sqs", ["sqs", "Sqs"], SQS_ENDPOINT_FLAT_KEYS)),
|
|
2113
2621
|
pushDiffusion: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "PushDiffusion", ["pushDiffusion", "PushDiffusion"], PUSH_DIFFUSION_ENDPOINT_FLAT_KEYS)),
|
|
2114
|
-
delegate: normalizeDelegateEndpointOptions(pickEndpointTransportRecord(raw, kind, "DelegateStream", ["delegate", "Delegate", "DelegateStream"], DELEGATE_STREAM_ENDPOINT_FLAT_KEYS))
|
|
2622
|
+
delegate: normalizeDelegateEndpointOptions(pickEndpointTransportRecord(raw, kind, "DelegateStream", ["delegate", "Delegate", "DelegateStream"], DELEGATE_STREAM_ENDPOINT_FLAT_KEYS)),
|
|
2623
|
+
grpc: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "Grpc", ["grpc", "Grpc"], GRPC_ENDPOINT_FLAT_KEYS)),
|
|
2624
|
+
webSocket: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "WebSocket", ["webSocket", "WebSocket"], WEB_SOCKET_ENDPOINT_FLAT_KEYS))
|
|
2115
2625
|
};
|
|
2116
2626
|
}
|
|
2117
2627
|
function resolveEndpointKind(raw) {
|
|
@@ -2197,6 +2707,32 @@ function resolveEndpointKind(raw) {
|
|
|
2197
2707
|
])) {
|
|
2198
2708
|
return "PushDiffusion";
|
|
2199
2709
|
}
|
|
2710
|
+
if (Object.keys(pickEndpointRecord(raw, "grpc", "Grpc")).length || hasAnyEndpointField(raw, [
|
|
2711
|
+
"Target",
|
|
2712
|
+
"target",
|
|
2713
|
+
"ServiceName",
|
|
2714
|
+
"serviceName",
|
|
2715
|
+
"MethodName",
|
|
2716
|
+
"methodName",
|
|
2717
|
+
"MethodType",
|
|
2718
|
+
"methodType",
|
|
2719
|
+
"NativeClient",
|
|
2720
|
+
"nativeClient"
|
|
2721
|
+
])) {
|
|
2722
|
+
return "Grpc";
|
|
2723
|
+
}
|
|
2724
|
+
if (Object.keys(pickEndpointRecord(raw, "webSocket", "WebSocket")).length || hasAnyEndpointField(raw, [
|
|
2725
|
+
"Subprotocols",
|
|
2726
|
+
"subprotocols",
|
|
2727
|
+
"ConnectTimeoutSeconds",
|
|
2728
|
+
"connectTimeoutSeconds",
|
|
2729
|
+
"CloseTimeoutSeconds",
|
|
2730
|
+
"closeTimeoutSeconds",
|
|
2731
|
+
"NativeClient",
|
|
2732
|
+
"nativeClient"
|
|
2733
|
+
])) {
|
|
2734
|
+
return "WebSocket";
|
|
2735
|
+
}
|
|
2200
2736
|
if (Object.keys(pickEndpointRecord(raw, "delegate", "Delegate", "DelegateStream")).length || hasAnyEndpointField(raw, [
|
|
2201
2737
|
"Produce",
|
|
2202
2738
|
"produce",
|
|
@@ -2327,6 +2863,22 @@ function normalizeDelegateEndpointOptions(options) {
|
|
|
2327
2863
|
function normalizeProtocolOptions(options) {
|
|
2328
2864
|
return Object.keys(options).length ? options : undefined;
|
|
2329
2865
|
}
|
|
2866
|
+
function normalizeWebSocketMessages(value) {
|
|
2867
|
+
if (!Array.isArray(value)) {
|
|
2868
|
+
return [];
|
|
2869
|
+
}
|
|
2870
|
+
return value.map((entry) => entry instanceof WebSocketMessageSpec
|
|
2871
|
+
? entry
|
|
2872
|
+
: new WebSocketMessageSpec(asRecordOrEmpty(entry)));
|
|
2873
|
+
}
|
|
2874
|
+
function normalizeWebSocketExpectedMessages(value) {
|
|
2875
|
+
if (!Array.isArray(value)) {
|
|
2876
|
+
return [];
|
|
2877
|
+
}
|
|
2878
|
+
return value.map((entry) => entry instanceof WebSocketExpectedMessage
|
|
2879
|
+
? entry
|
|
2880
|
+
: new WebSocketExpectedMessage(asRecordOrEmpty(entry)));
|
|
2881
|
+
}
|
|
2330
2882
|
function pickEndpointValue(record, ...keys) {
|
|
2331
2883
|
return pickProtocolValue(record, ...keys);
|
|
2332
2884
|
}
|
|
@@ -2440,10 +2992,8 @@ function validateEndpointDefinition(endpoint) {
|
|
|
2440
2992
|
if (mode !== "Produce" && mode !== "Consume") {
|
|
2441
2993
|
throw new Error(`Unsupported endpoint mode: ${mode}.`);
|
|
2442
2994
|
}
|
|
2443
|
-
const hasProduceDelegate =
|
|
2444
|
-
|
|
2445
|
-
const hasConsumeDelegate = typeof endpoint.delegate?.consume === "function"
|
|
2446
|
-
|| typeof endpoint.delegate?.consumeAsync === "function";
|
|
2995
|
+
const hasProduceDelegate = Boolean(resolveProduceDelegate(endpoint) || resolveStructuredProduceDelegate(endpoint));
|
|
2996
|
+
const hasConsumeDelegate = Boolean(resolveConsumeDelegate(endpoint) || resolveStructuredConsumeDelegate(endpoint) || resolveStructuredConsumeStreamDelegate(endpoint));
|
|
2447
2997
|
const hasModeDelegate = mode === "Produce" ? hasProduceDelegate : hasConsumeDelegate;
|
|
2448
2998
|
switch (kind) {
|
|
2449
2999
|
case "Http":
|
|
@@ -2473,6 +3023,12 @@ function validateEndpointDefinition(endpoint) {
|
|
|
2473
3023
|
case "DelegateStream":
|
|
2474
3024
|
validateDelegateStreamEndpoint(endpoint, mode);
|
|
2475
3025
|
return;
|
|
3026
|
+
case "Grpc":
|
|
3027
|
+
validateGrpcEndpoint(endpoint, mode);
|
|
3028
|
+
return;
|
|
3029
|
+
case "WebSocket":
|
|
3030
|
+
validateWebSocketEndpoint(endpoint, mode);
|
|
3031
|
+
return;
|
|
2476
3032
|
default:
|
|
2477
3033
|
throw new Error(`Unsupported endpoint kind: ${kind}.`);
|
|
2478
3034
|
}
|
|
@@ -2548,6 +3104,65 @@ function validateDelegateStreamEndpoint(endpoint, mode) {
|
|
|
2548
3104
|
throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
|
|
2549
3105
|
}
|
|
2550
3106
|
}
|
|
3107
|
+
function validateGrpcEndpoint(endpoint, mode) {
|
|
3108
|
+
const options = asRecordOrEmpty(endpoint.grpc);
|
|
3109
|
+
requireNonEmptyString(optionString(options, "Target", "target"), "Target must be provided for gRPC endpoint definitions.");
|
|
3110
|
+
requireNonEmptyString(optionString(options, "ServiceName", "serviceName"), "ServiceName must be provided for gRPC endpoint definitions.");
|
|
3111
|
+
requireNonEmptyString(optionString(options, "MethodName", "methodName"), "MethodName must be provided for gRPC endpoint definitions.");
|
|
3112
|
+
requireNonEmptyString(optionString(options, "MethodType", "methodType") || "Unary", "MethodType must be provided for gRPC endpoint definitions.");
|
|
3113
|
+
const deadlineMs = optionNumber(options, "DeadlineMs", "deadlineMs");
|
|
3114
|
+
const deadlineSeconds = optionNumber(options, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline");
|
|
3115
|
+
if ((hasOptionValue(options, "DeadlineMs", "deadlineMs") && deadlineMs <= 0)
|
|
3116
|
+
|| (hasOptionValue(options, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline") && deadlineSeconds <= 0)) {
|
|
3117
|
+
throw new RangeError("Deadline must be greater than zero.");
|
|
3118
|
+
}
|
|
3119
|
+
const nativeClient = pickEndpointValue(options, "NativeClient", "nativeClient");
|
|
3120
|
+
if (nativeClient != null) {
|
|
3121
|
+
new GrpcNativeClientOptions(asRecordOrEmpty(nativeClient)).validate();
|
|
3122
|
+
}
|
|
3123
|
+
if (mode === "Produce" && !resolveStructuredProduceDelegate(endpoint) && !resolveProduceDelegate(endpoint) && nativeClient == null) {
|
|
3124
|
+
throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
|
|
3125
|
+
}
|
|
3126
|
+
if (mode === "Consume" && !resolveStructuredConsumeDelegate(endpoint) && !resolveStructuredConsumeStreamDelegate(endpoint) && !resolveConsumeDelegate(endpoint) && nativeClient == null) {
|
|
3127
|
+
throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
function validateWebSocketEndpoint(endpoint, mode) {
|
|
3131
|
+
const options = asRecordOrEmpty(endpoint.webSocket);
|
|
3132
|
+
const url = requireNonEmptyString(optionString(options, "Url", "url"), "Url must be provided for WebSocket endpoint definitions.");
|
|
3133
|
+
let parsed;
|
|
3134
|
+
try {
|
|
3135
|
+
parsed = new URL(url);
|
|
3136
|
+
}
|
|
3137
|
+
catch {
|
|
3138
|
+
throw new Error("Url must be an absolute ws:// or wss:// URI.");
|
|
3139
|
+
}
|
|
3140
|
+
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
3141
|
+
throw new Error("Url must be an absolute ws:// or wss:// URI.");
|
|
3142
|
+
}
|
|
3143
|
+
const connectMs = optionNumber(options, "ConnectTimeoutMs", "connectTimeoutMs");
|
|
3144
|
+
const connectSeconds = optionNumber(options, "ConnectTimeoutSeconds", "connectTimeoutSeconds", "ConnectTimeout", "connectTimeout");
|
|
3145
|
+
const closeMs = optionNumber(options, "CloseTimeoutMs", "closeTimeoutMs");
|
|
3146
|
+
const closeSeconds = optionNumber(options, "CloseTimeoutSeconds", "closeTimeoutSeconds", "CloseTimeout", "closeTimeout");
|
|
3147
|
+
if ((hasOptionValue(options, "ConnectTimeoutMs", "connectTimeoutMs") && connectMs <= 0)
|
|
3148
|
+
|| (hasOptionValue(options, "ConnectTimeoutSeconds", "connectTimeoutSeconds", "ConnectTimeout", "connectTimeout") && connectSeconds <= 0)) {
|
|
3149
|
+
throw new RangeError("ConnectTimeout must be greater than zero.");
|
|
3150
|
+
}
|
|
3151
|
+
if ((hasOptionValue(options, "CloseTimeoutMs", "closeTimeoutMs") && closeMs <= 0)
|
|
3152
|
+
|| (hasOptionValue(options, "CloseTimeoutSeconds", "closeTimeoutSeconds", "CloseTimeout", "closeTimeout") && closeSeconds <= 0)) {
|
|
3153
|
+
throw new RangeError("CloseTimeout must be greater than zero.");
|
|
3154
|
+
}
|
|
3155
|
+
const nativeClient = pickEndpointValue(options, "NativeClient", "nativeClient");
|
|
3156
|
+
if (nativeClient != null) {
|
|
3157
|
+
new WebSocketNativeClientOptions(asRecordOrEmpty(nativeClient)).validate();
|
|
3158
|
+
}
|
|
3159
|
+
if (mode === "Produce" && !resolveStructuredProduceDelegate(endpoint) && !resolveProduceDelegate(endpoint) && nativeClient == null) {
|
|
3160
|
+
throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
|
|
3161
|
+
}
|
|
3162
|
+
if (mode === "Consume" && !resolveStructuredConsumeDelegate(endpoint) && !resolveStructuredConsumeStreamDelegate(endpoint) && !resolveConsumeDelegate(endpoint) && nativeClient == null) {
|
|
3163
|
+
throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
2551
3166
|
function validateHttpAuthOptions(options) {
|
|
2552
3167
|
const auth = options.auth;
|
|
2553
3168
|
if (!auth) {
|
|
@@ -3190,6 +3805,10 @@ function createDelegateRequestEndpointView(endpoint) {
|
|
|
3190
3805
|
return new AzureEventHubsEndpointDefinition(endpoint);
|
|
3191
3806
|
case "PushDiffusion":
|
|
3192
3807
|
return new PushDiffusionEndpointDefinition(endpoint);
|
|
3808
|
+
case "Grpc":
|
|
3809
|
+
return new GrpcEndpointDefinition(endpoint);
|
|
3810
|
+
case "WebSocket":
|
|
3811
|
+
return new WebSocketEndpointDefinition(endpoint);
|
|
3193
3812
|
default:
|
|
3194
3813
|
return new DelegateStreamEndpointDefinition(endpoint);
|
|
3195
3814
|
}
|
|
@@ -3408,12 +4027,20 @@ function parseBodyObject(body) {
|
|
|
3408
4027
|
function resolveStructuredProduceDelegate(endpoint) {
|
|
3409
4028
|
return endpoint.delegate?.produceAsync
|
|
3410
4029
|
?? endpoint.pushDiffusion?.PublishAsync
|
|
3411
|
-
?? endpoint.pushDiffusion?.publishAsync
|
|
4030
|
+
?? endpoint.pushDiffusion?.publishAsync
|
|
4031
|
+
?? endpoint.grpc?.ProduceAsync
|
|
4032
|
+
?? endpoint.grpc?.produceAsync
|
|
4033
|
+
?? endpoint.webSocket?.ProduceAsync
|
|
4034
|
+
?? endpoint.webSocket?.produceAsync;
|
|
3412
4035
|
}
|
|
3413
4036
|
function resolveStructuredConsumeDelegate(endpoint) {
|
|
3414
4037
|
const delegate = endpoint.delegate?.consumeAsync
|
|
3415
4038
|
?? endpoint.pushDiffusion?.SubscribeAsync
|
|
3416
|
-
?? endpoint.pushDiffusion?.subscribeAsync
|
|
4039
|
+
?? endpoint.pushDiffusion?.subscribeAsync
|
|
4040
|
+
?? endpoint.grpc?.ConsumeAsync
|
|
4041
|
+
?? endpoint.grpc?.consumeAsync
|
|
4042
|
+
?? endpoint.webSocket?.ConsumeAsync
|
|
4043
|
+
?? endpoint.webSocket?.consumeAsync;
|
|
3417
4044
|
return typeof delegate === "function" && delegate.length === 0
|
|
3418
4045
|
? delegate
|
|
3419
4046
|
: undefined;
|
|
@@ -3421,22 +4048,36 @@ function resolveStructuredConsumeDelegate(endpoint) {
|
|
|
3421
4048
|
function resolveStructuredConsumeStreamDelegate(endpoint) {
|
|
3422
4049
|
const delegate = endpoint.delegate?.consumeAsync
|
|
3423
4050
|
?? endpoint.pushDiffusion?.SubscribeAsync
|
|
3424
|
-
?? endpoint.pushDiffusion?.subscribeAsync
|
|
4051
|
+
?? endpoint.pushDiffusion?.subscribeAsync
|
|
4052
|
+
?? endpoint.grpc?.ConsumeAsync
|
|
4053
|
+
?? endpoint.grpc?.consumeAsync
|
|
4054
|
+
?? endpoint.webSocket?.ConsumeAsync
|
|
4055
|
+
?? endpoint.webSocket?.consumeAsync;
|
|
3425
4056
|
return typeof delegate === "function" && delegate.length > 0
|
|
3426
4057
|
? delegate
|
|
3427
4058
|
: undefined;
|
|
3428
4059
|
}
|
|
3429
4060
|
function resolveProduceDelegate(endpoint) {
|
|
3430
|
-
return endpoint.delegate?.produce
|
|
4061
|
+
return endpoint.delegate?.produce
|
|
4062
|
+
?? endpoint.grpc?.Produce
|
|
4063
|
+
?? endpoint.grpc?.produce
|
|
4064
|
+
?? endpoint.webSocket?.Produce
|
|
4065
|
+
?? endpoint.webSocket?.produce;
|
|
3431
4066
|
}
|
|
3432
4067
|
function resolveConsumeDelegate(endpoint) {
|
|
3433
|
-
return endpoint.delegate?.consume
|
|
4068
|
+
return endpoint.delegate?.consume
|
|
4069
|
+
?? endpoint.grpc?.Consume
|
|
4070
|
+
?? endpoint.grpc?.consume
|
|
4071
|
+
?? endpoint.webSocket?.Consume
|
|
4072
|
+
?? endpoint.webSocket?.consume;
|
|
3434
4073
|
}
|
|
3435
4074
|
function resolveConnectionMetadata(endpoint) {
|
|
3436
4075
|
return {
|
|
3437
4076
|
...(endpoint.connectionMetadata ?? {}),
|
|
3438
4077
|
...(endpoint.delegate?.connectionMetadata ?? {}),
|
|
3439
|
-
...toStringRecord(endpoint.pushDiffusion?.ConnectionProperties ?? endpoint.pushDiffusion?.connectionProperties)
|
|
4078
|
+
...toStringRecord(endpoint.pushDiffusion?.ConnectionProperties ?? endpoint.pushDiffusion?.connectionProperties),
|
|
4079
|
+
...toStringRecord(endpoint.grpc?.ConnectionMetadata ?? endpoint.grpc?.connectionMetadata),
|
|
4080
|
+
...toStringRecord(endpoint.webSocket?.ConnectionMetadata ?? endpoint.webSocket?.connectionMetadata)
|
|
3440
4081
|
};
|
|
3441
4082
|
}
|
|
3442
4083
|
function isStructuredProduceResult(value) {
|