@nmtjs/protocol 0.14.3 → 0.14.5

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.
@@ -1,9 +1,11 @@
1
- import type { ProtocolBlobMetadata } from '../common/blob.ts';
2
- export declare class ProtocolClientBlobStream extends TransformStream<any, ArrayBuffer> {
1
+ import type { ProtocolBlobInterface, ProtocolBlobMetadata } from '../common/blob.ts';
2
+ import { BlobKey } from '../common/blob.ts';
3
+ export declare class ProtocolClientBlobStream extends TransformStream<any, ArrayBuffer> implements ProtocolBlobInterface {
3
4
  #private;
4
5
  readonly source: ReadableStream;
5
6
  readonly id: number;
6
7
  readonly metadata: ProtocolBlobMetadata;
8
+ readonly [BlobKey] = true;
7
9
  constructor(source: ReadableStream, id: number, metadata: ProtocolBlobMetadata);
8
10
  read(size: number): Promise<ArrayBuffer | null>;
9
11
  abort(error?: Error): void;
@@ -21,8 +23,9 @@ export declare class ProtocolServerStream<T = any> extends TransformStream<any,
21
23
  end(): Promise<void>;
22
24
  abort(error?: Error): Promise<void>;
23
25
  }
24
- export declare class ProtocolServerBlobStream extends ProtocolServerStream<ArrayBuffer> {
26
+ export declare class ProtocolServerBlobStream extends ProtocolServerStream<ArrayBuffer> implements ProtocolBlobInterface {
25
27
  readonly id: number;
26
28
  readonly metadata: ProtocolBlobMetadata;
29
+ readonly [BlobKey] = true;
27
30
  constructor(id: number, metadata: ProtocolBlobMetadata, options?: Transformer<any, ArrayBuffer>);
28
31
  }
@@ -1,9 +1,11 @@
1
1
  import { defer } from '@nmtjs/common';
2
2
  import { concat, encodeText } from "../common/binary.js";
3
+ import { BlobKey } from "../common/blob.js";
3
4
  export class ProtocolClientBlobStream extends TransformStream {
4
5
  source;
5
6
  id;
6
7
  metadata;
8
+ [BlobKey] = true;
7
9
  #queue;
8
10
  #reader;
9
11
  constructor(source, id, metadata) {
@@ -87,6 +89,7 @@ export class ProtocolServerStream extends TransformStream {
87
89
  export class ProtocolServerBlobStream extends ProtocolServerStream {
88
90
  id;
89
91
  metadata;
92
+ [BlobKey] = true;
90
93
  constructor(id, metadata, options) {
91
94
  super(options);
92
95
  this.id = id;
@@ -2,8 +2,8 @@ export declare const BlobKey: unique symbol;
2
2
  export type BlobKey = typeof BlobKey;
3
3
  export type ProtocolBlobMetadata = {
4
4
  type: string;
5
- size?: number;
6
- filename?: string;
5
+ size?: number | undefined;
6
+ filename?: string | undefined;
7
7
  };
8
8
  export interface ProtocolBlobInterface {
9
9
  readonly metadata: ProtocolBlobMetadata;
@@ -30,7 +30,7 @@ export declare abstract class BaseServerFormat implements BaseServerDecoder, Bas
30
30
  abstract decodeRPC(buffer: ArrayBuffer, context: DecodeRPCContext<ProtocolClientStream>): ProtocolRPC;
31
31
  }
32
32
  export declare const parseContentTypes: (types: string) => string[];
33
- export declare class Format {
33
+ export declare class ProtocolFormat {
34
34
  decoders: Map<Pattern, BaseServerDecoder>;
35
35
  encoders: Map<Pattern, BaseServerEncoder>;
36
36
  constructor(formats: BaseServerFormat[]);
@@ -27,7 +27,7 @@ export const parseContentTypes = (types) => {
27
27
  })
28
28
  .map((t) => t.type);
29
29
  };
30
- export class Format {
30
+ export class ProtocolFormat {
31
31
  decoders = new Map();
32
32
  encoders = new Map();
33
33
  constructor(formats) {
@@ -4,7 +4,7 @@ import type { ProtocolBlob, ProtocolBlobMetadata } from '../common/blob.ts';
4
4
  import type { ProtocolRPC } from '../common/types.ts';
5
5
  import type { ProtocolApi, ProtocolApiCallOptions } from './api.ts';
6
6
  import type { ConnectionOptions } from './connection.ts';
7
- import type { Format } from './format.ts';
7
+ import type { ProtocolFormat } from './format.ts';
8
8
  import type { ProtocolRegistry } from './registry.ts';
9
9
  import type { Transport } from './transport.ts';
10
10
  import type { ResolveFormatParams } from './utils.ts';
@@ -31,7 +31,7 @@ export declare class ProtocolConnections {
31
31
  constructor(application: {
32
32
  logger: Logger;
33
33
  registry: ProtocolRegistry;
34
- format: Format;
34
+ format: ProtocolFormat;
35
35
  container: Container;
36
36
  });
37
37
  get(connectionId: string): {
@@ -74,18 +74,27 @@ export declare class Protocol {
74
74
  #private;
75
75
  protected readonly application: {
76
76
  logger: Logger;
77
- format: Format;
77
+ format: ProtocolFormat;
78
78
  container: Container;
79
79
  registry: ProtocolRegistry;
80
80
  api: ProtocolApi;
81
81
  };
82
+ protected readonly options?: {
83
+ persistConnections?: {
84
+ timeout: number;
85
+ };
86
+ } | undefined;
82
87
  constructor(application: {
83
88
  logger: Logger;
84
- format: Format;
89
+ format: ProtocolFormat;
85
90
  container: Container;
86
91
  registry: ProtocolRegistry;
87
92
  api: ProtocolApi;
88
- });
93
+ }, options?: {
94
+ persistConnections?: {
95
+ timeout: number;
96
+ };
97
+ } | undefined);
89
98
  call(options: ProtocolApiCallOptions): Promise<import("./api.ts").ProtocolApiCallResult>;
90
99
  rpc(connectionId: string, rpc: ProtocolRPC, params?: ProtocolRPCOptions): Promise<void>;
91
100
  rpcRaw(connectionId: string, buffer: ArrayBuffer, params?: ProtocolRPCOptions): Promise<void>;
@@ -158,11 +158,13 @@ export class ProtocolServerStreams {
158
158
  }
159
159
  export class Protocol {
160
160
  application;
161
+ options;
161
162
  #connections;
162
163
  #clientStreams;
163
164
  #serverStreams;
164
- constructor(application) {
165
+ constructor(application, options) {
165
166
  this.application = application;
167
+ this.options = options;
166
168
  this.#connections = new ProtocolConnections(this.application);
167
169
  this.#clientStreams = new ProtocolClientStreams(this.#connections);
168
170
  this.#serverStreams = new ProtocolServerStreams(this.#connections);
@@ -1,7 +1,7 @@
1
1
  import type { BasePlugin, PluginContext } from '@nmtjs/core';
2
2
  import type { ServerMessageType } from '../common/enums.ts';
3
3
  import type { Connection } from './connection.ts';
4
- import type { Format } from './format.ts';
4
+ import type { ProtocolFormat } from './format.ts';
5
5
  import type { Protocol } from './protocol.ts';
6
6
  import type { ProtocolRegistry } from './registry.ts';
7
7
  import type { ProtocolSendMetadata } from './types.ts';
@@ -14,7 +14,7 @@ export interface Transport<T = unknown> {
14
14
  export interface TransportPluginContext extends PluginContext {
15
15
  protocol: Protocol;
16
16
  registry: ProtocolRegistry;
17
- format: Format;
17
+ format: ProtocolFormat;
18
18
  }
19
19
  export interface TransportPlugin<Type = unknown, Options = unknown> extends BasePlugin<Transport<Type>, Options, TransportPluginContext> {
20
20
  [kTransportPlugin]: any;
@@ -1,10 +1,10 @@
1
- import type { ProtocolBlob, ProtocolBlobInterface } from '../common/blob.ts';
1
+ import type { PlainType } from '@nmtjs/type/_plain';
2
+ import type { ProtocolBlobInterface } from '../common/blob.ts';
2
3
  import type { ProtocolClientStream } from './stream.ts';
3
- export type InputType<T> = T extends ProtocolBlobInterface ? ProtocolClientStream : T extends object ? {
4
- [K in keyof T]: InputType<T[K]>;
5
- } : T;
6
- export type OutputType<T> = T extends ProtocolBlobInterface ? ProtocolBlob : T extends object ? {
7
- [K in keyof T]: OutputType<T[K]>;
4
+ export type InputType<T> = T extends ProtocolBlobInterface ? ProtocolClientStream : T extends {
5
+ [PlainType]?: true;
6
+ } ? {
7
+ [K in keyof Omit<T, PlainType>]: InputType<T[K]>;
8
8
  } : T;
9
9
  export type ProtocolSendMetadata = {
10
10
  streamId?: number;
@@ -1,4 +1,4 @@
1
- import type { Format } from './format.ts';
1
+ import type { ProtocolFormat } from './format.ts';
2
2
  export type ResolveFormatParams = {
3
3
  contentType?: string | null;
4
4
  acceptType?: string | null;
@@ -9,7 +9,7 @@ export declare class UnsupportedContentTypeError extends UnsupportedFormatError
9
9
  }
10
10
  export declare class UnsupportedAcceptTypeError extends UnsupportedFormatError {
11
11
  }
12
- export declare const getFormat: (format: Format, { acceptType, contentType }: ResolveFormatParams) => {
12
+ export declare const getFormat: (format: ProtocolFormat, { acceptType, contentType }: ResolveFormatParams) => {
13
13
  encoder: import("./format.ts").BaseServerEncoder;
14
14
  decoder: import("./format.ts").BaseServerDecoder;
15
15
  };
package/package.json CHANGED
@@ -19,21 +19,21 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@nmtjs/common": "0.14.3",
23
- "@nmtjs/type": "0.14.3",
24
- "@nmtjs/core": "0.14.3"
22
+ "@nmtjs/common": "0.14.5",
23
+ "@nmtjs/type": "0.14.5",
24
+ "@nmtjs/core": "0.14.5"
25
25
  },
26
26
  "peerDependencies": {
27
- "@nmtjs/type": "0.14.3",
28
- "@nmtjs/common": "0.14.3",
29
- "@nmtjs/core": "0.14.3"
27
+ "@nmtjs/common": "0.14.5",
28
+ "@nmtjs/type": "0.14.5",
29
+ "@nmtjs/core": "0.14.5"
30
30
  },
31
31
  "files": [
32
32
  "dist",
33
33
  "LICENSE.md",
34
34
  "README.md"
35
35
  ],
36
- "version": "0.14.3",
36
+ "version": "0.14.5",
37
37
  "scripts": {
38
38
  "build": "tsc",
39
39
  "type-check": "tsc --noEmit"