@nmtjs/protocol 0.12.4 → 0.12.6

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 (72) hide show
  1. package/dist/client/events.d.ts +17 -0
  2. package/dist/client/events.js +26 -30
  3. package/dist/client/format.d.ts +21 -0
  4. package/dist/client/format.js +2 -3
  5. package/dist/client/index.d.ts +5 -0
  6. package/dist/client/index.js +1 -2
  7. package/dist/client/protocol.d.ts +149 -0
  8. package/dist/client/protocol.js +342 -343
  9. package/dist/client/stream.d.ts +28 -0
  10. package/dist/client/stream.js +88 -80
  11. package/dist/client/types.d.ts +8 -0
  12. package/dist/client/types.js +0 -2
  13. package/dist/common/binary.d.ts +19 -0
  14. package/dist/common/binary.js +17 -17
  15. package/dist/common/blob.d.ts +22 -0
  16. package/dist/common/blob.js +44 -40
  17. package/dist/common/enums.d.ts +41 -0
  18. package/dist/common/enums.js +45 -47
  19. package/dist/common/index.d.ts +4 -0
  20. package/dist/common/index.js +0 -2
  21. package/dist/common/types.d.ts +34 -0
  22. package/dist/common/types.js +0 -2
  23. package/dist/server/api.d.ts +34 -0
  24. package/dist/server/api.js +7 -9
  25. package/dist/server/connection.d.ts +25 -0
  26. package/dist/server/connection.js +18 -20
  27. package/dist/server/constants.d.ts +4 -0
  28. package/dist/server/constants.js +2 -4
  29. package/dist/server/format.d.ts +40 -0
  30. package/dist/server/format.js +56 -43
  31. package/dist/server/index.d.ts +11 -0
  32. package/dist/server/index.js +0 -2
  33. package/dist/server/injectables.d.ts +14 -0
  34. package/dist/server/injectables.js +18 -20
  35. package/dist/server/protocol.d.ts +118 -0
  36. package/dist/server/protocol.js +365 -384
  37. package/dist/server/registry.d.ts +3 -0
  38. package/dist/server/registry.js +3 -4
  39. package/dist/server/stream.d.ts +12 -0
  40. package/dist/server/stream.js +28 -26
  41. package/dist/server/transport.d.ts +23 -0
  42. package/dist/server/transport.js +1 -7
  43. package/dist/server/types.d.ts +13 -0
  44. package/dist/server/types.js +0 -2
  45. package/dist/server/utils.d.ts +15 -0
  46. package/dist/server/utils.js +16 -13
  47. package/package.json +17 -14
  48. package/src/server/api.ts +2 -1
  49. package/src/server/protocol.ts +1 -1
  50. package/dist/client/events.js.map +0 -1
  51. package/dist/client/format.js.map +0 -1
  52. package/dist/client/index.js.map +0 -1
  53. package/dist/client/protocol.js.map +0 -1
  54. package/dist/client/stream.js.map +0 -1
  55. package/dist/client/types.js.map +0 -1
  56. package/dist/common/binary.js.map +0 -1
  57. package/dist/common/blob.js.map +0 -1
  58. package/dist/common/enums.js.map +0 -1
  59. package/dist/common/index.js.map +0 -1
  60. package/dist/common/types.js.map +0 -1
  61. package/dist/server/api.js.map +0 -1
  62. package/dist/server/connection.js.map +0 -1
  63. package/dist/server/constants.js.map +0 -1
  64. package/dist/server/format.js.map +0 -1
  65. package/dist/server/index.js.map +0 -1
  66. package/dist/server/injectables.js.map +0 -1
  67. package/dist/server/protocol.js.map +0 -1
  68. package/dist/server/registry.js.map +0 -1
  69. package/dist/server/stream.js.map +0 -1
  70. package/dist/server/transport.js.map +0 -1
  71. package/dist/server/types.js.map +0 -1
  72. package/dist/server/utils.js.map +0 -1
@@ -0,0 +1,28 @@
1
+ import type { ProtocolBlobMetadata } from '../common/blob.ts';
2
+ export declare class ProtocolClientBlobStream extends TransformStream<any, ArrayBuffer> {
3
+ #private;
4
+ readonly source: ReadableStream;
5
+ readonly id: number;
6
+ readonly metadata: ProtocolBlobMetadata;
7
+ constructor(source: ReadableStream, id: number, metadata: ProtocolBlobMetadata);
8
+ read(size: number): Promise<ArrayBuffer | null>;
9
+ abort(error?: Error): void;
10
+ end(): Promise<void>;
11
+ }
12
+ export interface ProtocolServerStreamInterface<T = any> {
13
+ [Symbol.asyncIterator](): AsyncGenerator<T>;
14
+ abort(error?: Error): void;
15
+ }
16
+ export declare class ProtocolServerStream<T = any> extends TransformStream<any, T> implements ProtocolServerStreamInterface<T> {
17
+ #private;
18
+ constructor(options?: Transformer<any, T>);
19
+ [Symbol.asyncIterator](): AsyncGenerator<Awaited<T>, void, unknown>;
20
+ push(chunk: T): Promise<void>;
21
+ end(): Promise<void>;
22
+ abort(error?: Error): Promise<void>;
23
+ }
24
+ export declare class ProtocolServerBlobStream extends ProtocolServerStream<ArrayBuffer> {
25
+ readonly id: number;
26
+ readonly metadata: ProtocolBlobMetadata;
27
+ constructor(id: number, metadata: ProtocolBlobMetadata, options?: Transformer<any, ArrayBuffer>);
28
+ }
@@ -1,87 +1,95 @@
1
- import { defer } from "@nmtjs/common";
1
+ import { defer } from '@nmtjs/common';
2
2
  import { concat, encodeText } from "../common/binary.js";
3
3
  export class ProtocolClientBlobStream extends TransformStream {
4
- #queue;
5
- #reader;
6
- constructor(source, id, metadata) {
7
- super({
8
- start: () => {
9
- defer(() => source.pipeThrough(this));
10
- },
11
- transform: (chunk, controller) => {
12
- if (chunk instanceof ArrayBuffer) {
13
- controller.enqueue(chunk);
14
- } else if (chunk instanceof Uint8Array) {
15
- controller.enqueue(chunk.buffer);
16
- } else if (typeof chunk === "string") {
17
- controller.enqueue(encodeText(chunk));
18
- } else {
19
- throw new Error("Invalid chunk data type. Expected ArrayBuffer, Uint8Array, or string.");
20
- }
21
- }
22
- });
23
- this.source = source;
24
- this.id = id;
25
- this.metadata = metadata;
26
- this.#queue = new ArrayBuffer(0);
27
- this.#reader = this.readable.getReader();
28
- }
29
- async read(size) {
30
- while (this.#queue.byteLength < size) {
31
- const { done, value } = await this.#reader.read();
32
- if (done) {
33
- if (this.#queue.byteLength > 0) {
34
- const chunk = this.#queue;
35
- this.#queue = new ArrayBuffer(0);
36
- return chunk;
37
- }
38
- return null;
39
- }
40
- const buffer = value;
41
- this.#queue = concat(this.#queue, buffer);
42
- }
43
- const chunk = this.#queue.slice(0, size);
44
- this.#queue = this.#queue.slice(size);
45
- return chunk;
46
- }
47
- abort(error = new Error("Stream aborted")) {
48
- this.#reader.cancel(error);
49
- this.source.cancel(error);
50
- }
51
- end() {
52
- return this.source.cancel("Stream ended");
53
- }
4
+ source;
5
+ id;
6
+ metadata;
7
+ #queue;
8
+ #reader;
9
+ constructor(source, id, metadata) {
10
+ super({
11
+ start: () => {
12
+ defer(() => source.pipeThrough(this));
13
+ },
14
+ transform: (chunk, controller) => {
15
+ if (chunk instanceof ArrayBuffer) {
16
+ controller.enqueue(chunk);
17
+ }
18
+ else if (chunk instanceof Uint8Array) {
19
+ controller.enqueue(chunk.buffer);
20
+ }
21
+ else if (typeof chunk === 'string') {
22
+ controller.enqueue(encodeText(chunk));
23
+ }
24
+ else {
25
+ throw new Error('Invalid chunk data type. Expected ArrayBuffer, Uint8Array, or string.');
26
+ }
27
+ },
28
+ });
29
+ this.source = source;
30
+ this.id = id;
31
+ this.metadata = metadata;
32
+ this.#queue = new ArrayBuffer(0);
33
+ this.#reader = this.readable.getReader();
34
+ }
35
+ async read(size) {
36
+ while (this.#queue.byteLength < size) {
37
+ const { done, value } = await this.#reader.read();
38
+ if (done) {
39
+ if (this.#queue.byteLength > 0) {
40
+ const chunk = this.#queue;
41
+ this.#queue = new ArrayBuffer(0);
42
+ return chunk;
43
+ }
44
+ return null;
45
+ }
46
+ const buffer = value;
47
+ this.#queue = concat(this.#queue, buffer);
48
+ }
49
+ const chunk = this.#queue.slice(0, size);
50
+ this.#queue = this.#queue.slice(size);
51
+ return chunk;
52
+ }
53
+ abort(error = new Error('Stream aborted')) {
54
+ this.#reader.cancel(error);
55
+ this.source.cancel(error);
56
+ }
57
+ end() {
58
+ return this.source.cancel('Stream ended');
59
+ }
54
60
  }
55
61
  export class ProtocolServerStream extends TransformStream {
56
- #writer;
57
- constructor(options) {
58
- super(options);
59
- this.#writer = this.writable.getWriter();
60
- }
61
- async *[Symbol.asyncIterator]() {
62
- const reader = this.readable.getReader();
63
- while (true) {
64
- const { done, value } = await reader.read();
65
- if (!done) yield value;
66
- else break;
67
- }
68
- }
69
- async push(chunk) {
70
- await this.#writer.write(chunk);
71
- }
72
- async end() {
73
- await this.#writer.close();
74
- }
75
- async abort(error = new Error("Stream aborted")) {
76
- await this.#writer.abort(error);
77
- }
62
+ #writer;
63
+ constructor(options) {
64
+ super(options);
65
+ this.#writer = this.writable.getWriter();
66
+ }
67
+ async *[Symbol.asyncIterator]() {
68
+ const reader = this.readable.getReader();
69
+ while (true) {
70
+ const { done, value } = await reader.read();
71
+ if (!done)
72
+ yield value;
73
+ else
74
+ break;
75
+ }
76
+ }
77
+ async push(chunk) {
78
+ await this.#writer.write(chunk);
79
+ }
80
+ async end() {
81
+ await this.#writer.close();
82
+ }
83
+ async abort(error = new Error('Stream aborted')) {
84
+ await this.#writer.abort(error);
85
+ }
78
86
  }
79
87
  export class ProtocolServerBlobStream extends ProtocolServerStream {
80
- constructor(id, metadata, options) {
81
- super(options);
82
- this.id = id;
83
- this.metadata = metadata;
84
- }
88
+ id;
89
+ metadata;
90
+ constructor(id, metadata, options) {
91
+ super(options);
92
+ this.id = id;
93
+ this.metadata = metadata;
94
+ }
85
95
  }
86
-
87
- //# sourceMappingURL=stream.js.map
@@ -0,0 +1,8 @@
1
+ import type { ProtocolBlob, ProtocolBlobInterface } from '../common/blob.ts';
2
+ import type { ProtocolServerBlobStream } from './stream.ts';
3
+ export type InputType<T> = T extends ProtocolBlobInterface ? ProtocolBlob : T extends object ? {
4
+ [K in keyof T]: InputType<T[K]>;
5
+ } : T;
6
+ export type OutputType<T> = T extends ProtocolBlobInterface ? ProtocolServerBlobStream : T extends object ? {
7
+ [K in keyof T]: OutputType<T[K]>;
8
+ } : T;
@@ -1,3 +1 @@
1
1
  export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -0,0 +1,19 @@
1
+ declare const utf8decoder: TextDecoder;
2
+ export type BinaryTypes = {
3
+ Int8: number;
4
+ Int16: number;
5
+ Int32: number;
6
+ Uint8: number;
7
+ Uint16: number;
8
+ Uint32: number;
9
+ Float32: number;
10
+ Float64: number;
11
+ BigInt64: bigint;
12
+ BigUint64: bigint;
13
+ };
14
+ export declare const encodeNumber: <T extends keyof BinaryTypes>(value: BinaryTypes[T], type: T, littleEndian?: boolean) => ArrayBuffer;
15
+ export declare const decodeNumber: <T extends keyof BinaryTypes>(buffer: ArrayBuffer, type: T, offset?: number, littleEndian?: boolean) => BinaryTypes[T];
16
+ export declare const encodeText: (text: string) => ArrayBuffer;
17
+ export declare const decodeText: (buffer: Parameters<typeof utf8decoder.decode>[0]) => string;
18
+ export declare const concat: (...buffers: ArrayBuffer[]) => ArrayBuffer;
19
+ export {};
@@ -1,27 +1,27 @@
1
+ // TODO: get rid of lib DOM somehow...
2
+ /// <reference lib="dom" />
1
3
  const utf8decoder = new TextDecoder();
2
4
  const utf8encoder = new TextEncoder();
3
5
  export const encodeNumber = (value, type, littleEndian = false) => {
4
- const bytesNeeded = globalThis[`${type}Array`].BYTES_PER_ELEMENT;
5
- const ab = new ArrayBuffer(bytesNeeded);
6
- const dv = new DataView(ab);
7
- dv[`set${type}`](0, value, littleEndian);
8
- return ab;
6
+ const bytesNeeded = globalThis[`${type}Array`].BYTES_PER_ELEMENT;
7
+ const ab = new ArrayBuffer(bytesNeeded);
8
+ const dv = new DataView(ab);
9
+ dv[`set${type}`](0, value, littleEndian);
10
+ return ab;
9
11
  };
10
12
  export const decodeNumber = (buffer, type, offset = 0, littleEndian = false) => {
11
- const view = new DataView(buffer);
12
- return view[`get${type}`](offset, littleEndian);
13
+ const view = new DataView(buffer);
14
+ return view[`get${type}`](offset, littleEndian);
13
15
  };
14
16
  export const encodeText = (text) => new Uint8Array(utf8encoder.encode(text)).buffer;
15
17
  export const decodeText = (buffer) => utf8decoder.decode(buffer);
16
18
  export const concat = (...buffers) => {
17
- const totalLength = buffers.reduce((acc, buffer) => acc + buffer.byteLength, 0);
18
- const view = new Uint8Array(totalLength);
19
- let offset = 0;
20
- for (const buffer of buffers) {
21
- view.set(new Uint8Array(buffer), offset);
22
- offset += buffer.byteLength;
23
- }
24
- return view.buffer;
19
+ const totalLength = buffers.reduce((acc, buffer) => acc + buffer.byteLength, 0);
20
+ const view = new Uint8Array(totalLength);
21
+ let offset = 0;
22
+ for (const buffer of buffers) {
23
+ view.set(new Uint8Array(buffer), offset);
24
+ offset += buffer.byteLength;
25
+ }
26
+ return view.buffer;
25
27
  };
26
-
27
- //# sourceMappingURL=binary.js.map
@@ -0,0 +1,22 @@
1
+ export declare const BlobKey: unique symbol;
2
+ export type BlobKey = typeof BlobKey;
3
+ export type ProtocolBlobMetadata = {
4
+ type: string;
5
+ size?: number;
6
+ filename?: string;
7
+ };
8
+ export interface ProtocolBlobInterface {
9
+ readonly metadata: ProtocolBlobMetadata;
10
+ readonly [BlobKey]: true;
11
+ }
12
+ export declare class ProtocolBlob implements ProtocolBlobInterface {
13
+ readonly [BlobKey] = true;
14
+ readonly metadata: ProtocolBlobMetadata;
15
+ readonly source: any;
16
+ constructor(source: any, size?: number, type?: string, filename?: string);
17
+ static from(source: any, metadata?: {
18
+ size?: number;
19
+ type?: string;
20
+ filename?: string;
21
+ }): ProtocolBlob;
22
+ }
@@ -1,42 +1,46 @@
1
- export const BlobKey = Symbol.for("neemata:BlobKey");
1
+ export const BlobKey = Symbol.for('neemata:BlobKey');
2
2
  export class ProtocolBlob {
3
- [BlobKey] = true;
4
- metadata;
5
- source;
6
- constructor(source, size, type = "application/octet-stream", filename) {
7
- if (typeof size !== "undefined" && size <= 0) throw new Error("Blob size is invalid");
8
- this.source = source;
9
- this.metadata = {
10
- size,
11
- type,
12
- filename
13
- };
14
- }
15
- static from(source, metadata = {}) {
16
- let _source;
17
- if (source instanceof globalThis.ReadableStream) {
18
- _source = source;
19
- } else if ("File" in globalThis && source instanceof globalThis.File) {
20
- _source = source.stream();
21
- metadata.size = source.size;
22
- metadata.filename = source.name;
23
- } else if (source instanceof globalThis.Blob) {
24
- _source = source.stream();
25
- metadata.size = source.size;
26
- } else if (typeof source === "string") {
27
- const blob = new Blob([source]);
28
- _source = blob.stream();
29
- metadata.size = blob.size;
30
- metadata.type = metadata.type || "text/plain";
31
- } else if (source instanceof globalThis.ArrayBuffer) {
32
- const blob = new Blob([source]);
33
- _source = blob.stream();
34
- metadata.size = blob.size;
35
- } else {
36
- _source = source;
37
- }
38
- return new ProtocolBlob(_source, metadata.size, metadata.type, metadata.filename);
39
- }
3
+ [BlobKey] = true;
4
+ metadata;
5
+ source;
6
+ constructor(source, size, type = 'application/octet-stream', filename) {
7
+ if (typeof size !== 'undefined' && size <= 0)
8
+ throw new Error('Blob size is invalid');
9
+ this.source = source;
10
+ this.metadata = {
11
+ size,
12
+ type,
13
+ filename,
14
+ };
15
+ }
16
+ static from(source, metadata = {}) {
17
+ let _source;
18
+ if (source instanceof globalThis.ReadableStream) {
19
+ _source = source;
20
+ }
21
+ else if ('File' in globalThis && source instanceof globalThis.File) {
22
+ _source = source.stream();
23
+ metadata.size = source.size;
24
+ metadata.filename = source.name;
25
+ }
26
+ else if (source instanceof globalThis.Blob) {
27
+ _source = source.stream();
28
+ metadata.size = source.size;
29
+ }
30
+ else if (typeof source === 'string') {
31
+ const blob = new Blob([source]);
32
+ _source = blob.stream();
33
+ metadata.size = blob.size;
34
+ metadata.type = metadata.type || 'text/plain';
35
+ }
36
+ else if (source instanceof globalThis.ArrayBuffer) {
37
+ const blob = new Blob([source]);
38
+ _source = blob.stream();
39
+ metadata.size = blob.size;
40
+ }
41
+ else {
42
+ _source = source;
43
+ }
44
+ return new ProtocolBlob(_source, metadata.size, metadata.type, metadata.filename);
45
+ }
40
46
  }
41
-
42
- //# sourceMappingURL=blob.js.map
@@ -0,0 +1,41 @@
1
+ export declare enum ClientMessageType {
2
+ Rpc = 10,
3
+ RpcAbort = 11,
4
+ RpcStreamAbort = 12,
5
+ ClientStreamPush = 20,
6
+ ClientStreamEnd = 21,
7
+ ClientStreamAbort = 22,
8
+ ServerStreamAbort = 23,
9
+ ServerStreamPull = 24
10
+ }
11
+ export declare enum ServerMessageType {
12
+ Event = 1,
13
+ RpcResponse = 10,
14
+ RpcStreamResponse = 11,
15
+ RpcStreamChunk = 12,
16
+ RpcStreamEnd = 13,
17
+ RpcStreamAbort = 14,
18
+ ServerStreamPush = 20,
19
+ ServerStreamEnd = 21,
20
+ ServerStreamAbort = 22,
21
+ ClientStreamAbort = 23,
22
+ ClientStreamPull = 24
23
+ }
24
+ export declare enum TransportType {
25
+ Bidirectional = "Bidirectional",
26
+ Unidirectional = "Unidirectional"
27
+ }
28
+ export declare enum ErrorCode {
29
+ ValidationError = "ValidationError",
30
+ BadRequest = "BadRequest",
31
+ NotFound = "NotFound",
32
+ Forbidden = "Forbidden",
33
+ Unauthorized = "Unauthorized",
34
+ InternalServerError = "InternalServerError",
35
+ NotAcceptable = "NotAcceptable",
36
+ RequestTimeout = "RequestTimeout",
37
+ GatewayTimeout = "GatewayTimeout",
38
+ ServiceUnavailable = "ServiceUnavailable",
39
+ ClientRequestError = "ClientRequestError",
40
+ ConnectionError = "ConnectionError"
41
+ }
@@ -1,47 +1,45 @@
1
- export let ClientMessageType = /* @__PURE__ */ function(ClientMessageType) {
2
- ClientMessageType[ClientMessageType["Rpc"] = 10] = "Rpc";
3
- ClientMessageType[ClientMessageType["RpcAbort"] = 11] = "RpcAbort";
4
- ClientMessageType[ClientMessageType["RpcStreamAbort"] = 12] = "RpcStreamAbort";
5
- ClientMessageType[ClientMessageType["ClientStreamPush"] = 20] = "ClientStreamPush";
6
- ClientMessageType[ClientMessageType["ClientStreamEnd"] = 21] = "ClientStreamEnd";
7
- ClientMessageType[ClientMessageType["ClientStreamAbort"] = 22] = "ClientStreamAbort";
8
- ClientMessageType[ClientMessageType["ServerStreamAbort"] = 23] = "ServerStreamAbort";
9
- ClientMessageType[ClientMessageType["ServerStreamPull"] = 24] = "ServerStreamPull";
10
- return ClientMessageType;
11
- }({});
12
- export let ServerMessageType = /* @__PURE__ */ function(ServerMessageType) {
13
- ServerMessageType[ServerMessageType["Event"] = 1] = "Event";
14
- ServerMessageType[ServerMessageType["RpcResponse"] = 10] = "RpcResponse";
15
- ServerMessageType[ServerMessageType["RpcStreamResponse"] = 11] = "RpcStreamResponse";
16
- ServerMessageType[ServerMessageType["RpcStreamChunk"] = 12] = "RpcStreamChunk";
17
- ServerMessageType[ServerMessageType["RpcStreamEnd"] = 13] = "RpcStreamEnd";
18
- ServerMessageType[ServerMessageType["RpcStreamAbort"] = 14] = "RpcStreamAbort";
19
- ServerMessageType[ServerMessageType["ServerStreamPush"] = 20] = "ServerStreamPush";
20
- ServerMessageType[ServerMessageType["ServerStreamEnd"] = 21] = "ServerStreamEnd";
21
- ServerMessageType[ServerMessageType["ServerStreamAbort"] = 22] = "ServerStreamAbort";
22
- ServerMessageType[ServerMessageType["ClientStreamAbort"] = 23] = "ClientStreamAbort";
23
- ServerMessageType[ServerMessageType["ClientStreamPull"] = 24] = "ClientStreamPull";
24
- return ServerMessageType;
25
- }({});
26
- export let TransportType = /* @__PURE__ */ function(TransportType) {
27
- TransportType["Bidirectional"] = "Bidirectional";
28
- TransportType["Unidirectional"] = "Unidirectional";
29
- return TransportType;
30
- }({});
31
- export let ErrorCode = /* @__PURE__ */ function(ErrorCode) {
32
- ErrorCode["ValidationError"] = "ValidationError";
33
- ErrorCode["BadRequest"] = "BadRequest";
34
- ErrorCode["NotFound"] = "NotFound";
35
- ErrorCode["Forbidden"] = "Forbidden";
36
- ErrorCode["Unauthorized"] = "Unauthorized";
37
- ErrorCode["InternalServerError"] = "InternalServerError";
38
- ErrorCode["NotAcceptable"] = "NotAcceptable";
39
- ErrorCode["RequestTimeout"] = "RequestTimeout";
40
- ErrorCode["GatewayTimeout"] = "GatewayTimeout";
41
- ErrorCode["ServiceUnavailable"] = "ServiceUnavailable";
42
- ErrorCode["ClientRequestError"] = "ClientRequestError";
43
- ErrorCode["ConnectionError"] = "ConnectionError";
44
- return ErrorCode;
45
- }({});
46
-
47
- //# sourceMappingURL=enums.js.map
1
+ export var ClientMessageType;
2
+ (function (ClientMessageType) {
3
+ ClientMessageType[ClientMessageType["Rpc"] = 10] = "Rpc";
4
+ ClientMessageType[ClientMessageType["RpcAbort"] = 11] = "RpcAbort";
5
+ ClientMessageType[ClientMessageType["RpcStreamAbort"] = 12] = "RpcStreamAbort";
6
+ ClientMessageType[ClientMessageType["ClientStreamPush"] = 20] = "ClientStreamPush";
7
+ ClientMessageType[ClientMessageType["ClientStreamEnd"] = 21] = "ClientStreamEnd";
8
+ ClientMessageType[ClientMessageType["ClientStreamAbort"] = 22] = "ClientStreamAbort";
9
+ ClientMessageType[ClientMessageType["ServerStreamAbort"] = 23] = "ServerStreamAbort";
10
+ ClientMessageType[ClientMessageType["ServerStreamPull"] = 24] = "ServerStreamPull";
11
+ })(ClientMessageType || (ClientMessageType = {}));
12
+ export var ServerMessageType;
13
+ (function (ServerMessageType) {
14
+ ServerMessageType[ServerMessageType["Event"] = 1] = "Event";
15
+ ServerMessageType[ServerMessageType["RpcResponse"] = 10] = "RpcResponse";
16
+ ServerMessageType[ServerMessageType["RpcStreamResponse"] = 11] = "RpcStreamResponse";
17
+ ServerMessageType[ServerMessageType["RpcStreamChunk"] = 12] = "RpcStreamChunk";
18
+ ServerMessageType[ServerMessageType["RpcStreamEnd"] = 13] = "RpcStreamEnd";
19
+ ServerMessageType[ServerMessageType["RpcStreamAbort"] = 14] = "RpcStreamAbort";
20
+ ServerMessageType[ServerMessageType["ServerStreamPush"] = 20] = "ServerStreamPush";
21
+ ServerMessageType[ServerMessageType["ServerStreamEnd"] = 21] = "ServerStreamEnd";
22
+ ServerMessageType[ServerMessageType["ServerStreamAbort"] = 22] = "ServerStreamAbort";
23
+ ServerMessageType[ServerMessageType["ClientStreamAbort"] = 23] = "ClientStreamAbort";
24
+ ServerMessageType[ServerMessageType["ClientStreamPull"] = 24] = "ClientStreamPull";
25
+ })(ServerMessageType || (ServerMessageType = {}));
26
+ export var TransportType;
27
+ (function (TransportType) {
28
+ TransportType["Bidirectional"] = "Bidirectional";
29
+ TransportType["Unidirectional"] = "Unidirectional";
30
+ })(TransportType || (TransportType = {}));
31
+ export var ErrorCode;
32
+ (function (ErrorCode) {
33
+ ErrorCode["ValidationError"] = "ValidationError";
34
+ ErrorCode["BadRequest"] = "BadRequest";
35
+ ErrorCode["NotFound"] = "NotFound";
36
+ ErrorCode["Forbidden"] = "Forbidden";
37
+ ErrorCode["Unauthorized"] = "Unauthorized";
38
+ ErrorCode["InternalServerError"] = "InternalServerError";
39
+ ErrorCode["NotAcceptable"] = "NotAcceptable";
40
+ ErrorCode["RequestTimeout"] = "RequestTimeout";
41
+ ErrorCode["GatewayTimeout"] = "GatewayTimeout";
42
+ ErrorCode["ServiceUnavailable"] = "ServiceUnavailable";
43
+ ErrorCode["ClientRequestError"] = "ClientRequestError";
44
+ ErrorCode["ConnectionError"] = "ConnectionError";
45
+ })(ErrorCode || (ErrorCode = {}));
@@ -0,0 +1,4 @@
1
+ export * from './binary.ts';
2
+ export * from './blob.ts';
3
+ export * from './enums.ts';
4
+ export * from './types.ts';
@@ -2,5 +2,3 @@ export * from "./binary.js";
2
2
  export * from "./blob.js";
3
3
  export * from "./enums.js";
4
4
  export * from "./types.js";
5
-
6
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,34 @@
1
+ import type { OneOf } from '@nmtjs/common';
2
+ import type { ProtocolBlob, ProtocolBlobMetadata } from './blob.ts';
3
+ type Stream = any;
4
+ export interface BaseProtocolError {
5
+ code: string;
6
+ message: string;
7
+ data?: any;
8
+ }
9
+ export type ProtocolRPC = {
10
+ callId: number;
11
+ namespace: string;
12
+ procedure: string;
13
+ payload: any;
14
+ };
15
+ export type ProtocolRPCResponse<T = Stream> = OneOf<[
16
+ {
17
+ callId: number;
18
+ error: BaseProtocolError;
19
+ },
20
+ {
21
+ callId: number;
22
+ result: any;
23
+ streams: Record<number, T>;
24
+ }
25
+ ]>;
26
+ export interface EncodeRPCContext<T = Stream> {
27
+ getStream: (id: number) => T;
28
+ addStream: (blob: ProtocolBlob) => T;
29
+ }
30
+ export interface DecodeRPCContext<T = Stream> {
31
+ getStream: (id: number, callId: number) => T;
32
+ addStream: (id: number, callId: number, metadata: ProtocolBlobMetadata) => T;
33
+ }
34
+ export {};
@@ -1,3 +1 @@
1
1
  export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -0,0 +1,34 @@
1
+ import type { Async } from '@nmtjs/common';
2
+ import type { Container, Hook, MetadataStore } from '@nmtjs/core';
3
+ import type { Connection } from './connection.ts';
4
+ import { kIterableResponse } from './constants.ts';
5
+ export type ProtocolApiCallOptions = {
6
+ connection: Connection;
7
+ namespace: string;
8
+ procedure: string;
9
+ container: Container;
10
+ payload: any;
11
+ signal: AbortSignal;
12
+ metadata?: (metadata: MetadataStore) => void;
13
+ };
14
+ export type ProtocolAnyIterable<T> = ((signal: AbortSignal) => Async<AsyncIterable<T>>) | AsyncIterable<T>;
15
+ export interface ProtocolApiCallBaseResult<T = unknown> {
16
+ output: T;
17
+ }
18
+ export interface ProtocolApiCallIterableResult<Y = unknown, O = unknown> extends ProtocolApiCallBaseResult<O> {
19
+ [kIterableResponse]: true;
20
+ iterable: ProtocolAnyIterable<Y>;
21
+ onFinish?: () => void;
22
+ }
23
+ export type ProtocolApiCallResult = ProtocolApiCallBaseResult | ProtocolApiCallIterableResult;
24
+ export interface ProtocolApi {
25
+ call(options: ProtocolApiCallOptions): Promise<ProtocolApiCallResult>;
26
+ }
27
+ export declare function isIterableResult(value: ProtocolApiCallResult): value is ProtocolApiCallIterableResult;
28
+ export declare function createStreamResponse<Y, O>(iterable: ProtocolAnyIterable<Y>, output?: O, onFinish?: () => void): ProtocolApiCallIterableResult<Y, O>;
29
+ declare module '@nmtjs/core' {
30
+ interface HookType {
31
+ [Hook.OnConnect]: (connection: Connection) => any;
32
+ [Hook.OnDisconnect]: (connection: Connection) => any;
33
+ }
34
+ }
@@ -1,14 +1,12 @@
1
1
  import { kIterableResponse } from "./constants.js";
2
2
  export function isIterableResult(value) {
3
- return value && value[kIterableResponse] === true;
3
+ return value && value[kIterableResponse] === true;
4
4
  }
5
5
  export function createStreamResponse(iterable, output = undefined, onFinish) {
6
- return {
7
- [kIterableResponse]: true,
8
- iterable,
9
- output,
10
- onFinish
11
- };
6
+ return {
7
+ [kIterableResponse]: true,
8
+ iterable,
9
+ output,
10
+ onFinish,
11
+ };
12
12
  }
13
-
14
- //# sourceMappingURL=api.js.map