@ckeditor/ckeditor-cloud-services-collaboration 54.2.12 → 54.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright (c), CKSource Holding sp. z o.o. All rights reserved.
3
+ */
4
+ import { type IServiceRequest, type IWebSocketGateway } from '../websocketgateway/websocketgateway';
5
+ export interface IConnectableService<TResult = unknown> {
6
+ /**
7
+ * Prepares the service for connecting and returns its connect request, or `undefined` when it is already connected.
8
+ */
9
+ beforeConnect(wsGateway: IWebSocketGateway): IServiceRequest | undefined;
10
+ /**
11
+ * Applies the response of the connect request and returns the service's data.
12
+ */
13
+ afterConnect(wsGateway: IWebSocketGateway, response: Buffer): TResult;
14
+ }
15
+ export type ServicesConnectResults<T extends ReadonlyArray<IConnectableService>> = {
16
+ [K in keyof T]: PromiseSettledResult<ReturnType<T[K]['afterConnect']> | void>;
17
+ };
18
+ /**
19
+ * Connects multiple services to CKEditor Cloud Services at once, instead of one after another.
20
+ */
21
+ export default class ServicesConnector {
22
+ private readonly _wsGateway;
23
+ constructor(_wsGateway: IWebSocketGateway);
24
+ /**
25
+ * Sends the connect requests of all given services as one batch request, and waits until all of them settle.
26
+ *
27
+ * A failed connect does not affect the others. The results are returned in the order of the given services.
28
+ * A service that is already connected sends no request and resolves with `undefined`.
29
+ *
30
+ * @throws {@link CKEditorCloudServicesError}
31
+ * Thrown when the WebSocket Gateway is not connected. No connect request is sent in that case.
32
+ */
33
+ connect<T extends ReadonlyArray<IConnectableService>>(services: [...T]): Promise<ServicesConnectResults<T>>;
34
+ }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import AddSuggestionResponse from './responses/addsuggestionresponse';
5
5
  import GetSuggestionResponse from './responses/getsuggestionresponse';
6
- import { type IWebSocketGateway } from '../websocketgateway/websocketgateway';
6
+ import { type IServiceRequest, type IWebSocketGateway } from '../websocketgateway/websocketgateway';
7
7
  import type { ISuggestion } from './descriptors/suggestiondescriptor';
8
8
  export declare const _SERVICE: number;
9
9
  interface ISuggestionUpdateProps {
@@ -31,6 +31,17 @@ declare class TrackChangesService extends /* #__PURE__ -- @preserve */ TrackChan
31
31
  * Connects to WebSocketGateway and starts listening on channel.
32
32
  */
33
33
  connect(wsGateway: IWebSocketGateway): Promise<ISuggestion[] | void>;
34
+ /**
35
+ * Prepares the service for connecting and returns its connect request, or `undefined` when it is already connected.
36
+ *
37
+ * @throws {@link CKEditorCloudServicesError}
38
+ * Thrown when the WebSocket Gateway is not connected.
39
+ */
40
+ beforeConnect(wsGateway: IWebSocketGateway): IServiceRequest | undefined;
41
+ /**
42
+ * Applies the response of the connect request: starts listening on the channel and on the gateway state.
43
+ */
44
+ afterConnect(wsGateway: IWebSocketGateway, response: Buffer): ISuggestion[];
34
45
  /**
35
46
  * Disconnects TrackChangesService from CKEditor Cloud Services.
36
47
  */
package/dist/version.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
2
  Copyright (c), CKSource Holding sp. z o.o. All rights reserved.
3
3
  */
4
- declare const _default: "54.2.12";
4
+ declare const _default: "54.3.0";
5
5
  export default _default;
@@ -0,0 +1,23 @@
1
+ /*
2
+ Copyright (c), CKSource Holding sp. z o.o. All rights reserved.
3
+ */
4
+ import Descriptor, { type IDescriptorBody } from './../../descriptor';
5
+ export interface IBatchRequestPart {
6
+ /**
7
+ * Numeric service id, the same as byte 0 of a single request envelope.
8
+ */
9
+ service: number;
10
+ /**
11
+ * Numeric method id, the same as byte 1 of a single request envelope.
12
+ */
13
+ method: number;
14
+ /**
15
+ * The encoded request, the same as the rest of a single request envelope.
16
+ */
17
+ message: Uint8Array;
18
+ }
19
+ export default class BatchRequestPartDescriptor extends Descriptor {
20
+ static readonly DESCRIPTOR_NAME: string;
21
+ static readonly DESCRIPTOR: IDescriptorBody;
22
+ static fromJSON(json: IBatchRequestPart): IBatchRequestPart;
23
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright (c), CKSource Holding sp. z o.o. All rights reserved.
3
+ */
4
+ import Descriptor, { type IDescriptorBody } from './../../descriptor';
5
+ import type { IPublicError } from '../../ckeditorcloudservicesservererror';
6
+ export interface IBatchResponsePart {
7
+ /**
8
+ * The error of a failed request, the same as the error of a single request.
9
+ */
10
+ error?: IPublicError;
11
+ /**
12
+ * The response of a successful request, the same as the response of a single request.
13
+ */
14
+ data?: Uint8Array;
15
+ }
16
+ export interface IBatchResponsePartJSON {
17
+ error?: string;
18
+ data?: Uint8Array;
19
+ }
20
+ export default class BatchResponsePartDescriptor extends Descriptor {
21
+ static readonly DESCRIPTOR_NAME: string;
22
+ static readonly DESCRIPTOR: IDescriptorBody;
23
+ static toJSON(part: IBatchResponsePart): IBatchResponsePartJSON;
24
+ static fromJSON(json: IBatchResponsePartJSON): IBatchResponsePart;
25
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright (c), CKSource Holding sp. z o.o. All rights reserved.
3
+ */
4
+ import Message, { type IMessage } from './../../message';
5
+ import type { IDescriptorBody } from '../../descriptor';
6
+ import { type IBatchRequestPart } from '../descriptors/batchrequestpartdescriptor';
7
+ export interface IBatchRequestMessage extends IMessage {
8
+ requests: IBatchRequestPart[];
9
+ }
10
+ /**
11
+ * Several requests sent to the WebSocket Gateway at once. The gateway processes each part as a single request.
12
+ */
13
+ export default class BatchRequestMessage extends Message {
14
+ readonly requests: IBatchRequestPart[];
15
+ static readonly DESCRIPTOR_NAME: string;
16
+ static readonly DESCRIPTOR: IDescriptorBody;
17
+ constructor(requests: IBatchRequestPart[]);
18
+ toJSON(): IBatchRequestMessage;
19
+ static fromJSON(json: IBatchRequestMessage): BatchRequestMessage;
20
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright (c), CKSource Holding sp. z o.o. All rights reserved.
3
+ */
4
+ import Message, { type IMessage } from './../../message';
5
+ import type { IDescriptorBody } from '../../descriptor';
6
+ import { type IBatchResponsePart, type IBatchResponsePartJSON } from '../descriptors/batchresponsepartdescriptor';
7
+ export interface IBatchResponseMessageJSON extends IMessage {
8
+ responses: IBatchResponsePartJSON[];
9
+ }
10
+ /**
11
+ * The responses to a {@link BatchRequestMessage}, in the order of its requests.
12
+ */
13
+ export default class BatchResponseMessage extends Message {
14
+ readonly responses: IBatchResponsePart[];
15
+ static readonly DESCRIPTOR_NAME: string;
16
+ static readonly DESCRIPTOR: IDescriptorBody;
17
+ constructor(responses: IBatchResponsePart[]);
18
+ toJSON(): IBatchResponseMessageJSON;
19
+ static fromJSON(json: IBatchResponseMessageJSON): BatchResponseMessage;
20
+ }
@@ -32,8 +32,14 @@ export interface IWebSocketGatewayConnectionOptions extends ManagerOptions {
32
32
  Encoder: (new (...args: unknown[]) => IOEncoder);
33
33
  };
34
34
  }
35
+ export interface IServiceRequest {
36
+ serviceName: number;
37
+ method: string;
38
+ buffer: Uint8Array;
39
+ }
35
40
  export interface IWebSocketGateway extends Emitter {
36
41
  _sendRequest<T extends IMessage>(serviceName: number, method: string, buffer: Uint8Array): Promise<T>;
42
+ _sendBatchRequest(requests: IServiceRequest[]): Promise<PromiseSettledResult<Buffer>[]>;
37
43
  _getChannel(serviceName: string | number, channelId: string): Channel;
38
44
  disconnect(): void;
39
45
  reconnect(): Promise<void>;
@@ -63,6 +69,13 @@ declare class WebSocketGateway extends /* #__PURE__ -- @preserve */ WebSocketGat
63
69
  private readonly _options;
64
70
  private readonly _connectionProvider;
65
71
  private readonly _userFactory;
72
+ /**
73
+ * Cleared when the gateway rejected a batch request. It is an older gateway, so later requests are sent one by one.
74
+ *
75
+ * It covers the only batch type, {@link BATCH_REQUEST_TYPE}. A second type needs a flag per type, so that a gateway
76
+ * which does not know one type keeps getting batches of the other.
77
+ */
78
+ private _isBatchSupported;
66
79
  /**
67
80
  * Represents currently logged user as taken from CMS (Token). Undefined value represents anonymous user.
68
81
  */
@@ -126,6 +139,21 @@ declare class WebSocketGateway extends /* #__PURE__ -- @preserve */ WebSocketGat
126
139
  * Sends request to CKEditor Cloud Services.
127
140
  */
128
141
  _sendRequest<TResponse extends IMessage>(serviceName: number, method: string, buffer: Uint8Array): Promise<TResponse>;
142
+ /**
143
+ * Sends the given requests as one batch request and resolves with one result per request, in the same order.
144
+ * Sends them one by one when there is only one, when there are more than {@link BATCH_MAX_PARTS}, or when the gateway
145
+ * does not support batch requests.
146
+ *
147
+ * The batch request has one timeout, and the gateway replies when all requests are processed. So when the slowest
148
+ * request times out, the whole call is rejected, including the requests the gateway has already processed.
149
+ *
150
+ * @throws {@link CKEditorCloudServicesError}
151
+ * Thrown when the WebSocket Gateway is not connected, or when the batch request times out.
152
+ *
153
+ * @throws {@link CKEditorCloudServicesServerError}
154
+ * Thrown when the gateway rejects the batch request with an error other than the `500` of older gateways.
155
+ */
156
+ _sendBatchRequest(requests: IServiceRequest[]): Promise<PromiseSettledResult<Buffer>[]>;
129
157
  /**
130
158
  * Returns {@link Channel} associated with given service.
131
159
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor-cloud-services-collaboration",
3
- "version": "54.2.12",
3
+ "version": "54.3.0",
4
4
  "description": "CKEditor Cloud Services Collaboration low-level API is required by CKEditor 5 Collaboration features to enable real-time collaborative editing in CKEditor 5.",
5
5
  "main": "dist/services.js",
6
6
  "license": "SEE LICENSE IN LICENSE.md",