@open-docex/shared 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +101 -2
- package/dist/errors/catalogue.d.ts +30 -0
- package/dist/errors/catalogue.d.ts.map +1 -0
- package/dist/errors/catalogue.js +52 -0
- package/dist/errors/catalogue.js.map +1 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +9 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/open-docex-error.d.ts +81 -0
- package/dist/errors/open-docex-error.d.ts.map +1 -0
- package/dist/errors/open-docex-error.js +127 -0
- package/dist/errors/open-docex-error.js.map +1 -0
- package/dist/ids/index.d.ts +41 -0
- package/dist/ids/index.d.ts.map +1 -0
- package/dist/ids/index.js +70 -0
- package/dist/ids/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/ot/index.d.ts +4 -0
- package/dist/ot/index.d.ts.map +1 -0
- package/dist/ot/index.js +3 -0
- package/dist/ot/index.js.map +1 -0
- package/dist/ot/types.d.ts +55 -0
- package/dist/ot/types.d.ts.map +1 -0
- package/dist/ot/types.js +11 -0
- package/dist/ot/types.js.map +1 -0
- package/dist/protocol/close-codes.d.ts +39 -0
- package/dist/protocol/close-codes.d.ts.map +1 -0
- package/dist/protocol/close-codes.js +47 -0
- package/dist/protocol/close-codes.js.map +1 -0
- package/dist/protocol/codec.d.ts +32 -0
- package/dist/protocol/codec.d.ts.map +1 -0
- package/dist/protocol/codec.js +270 -0
- package/dist/protocol/codec.js.map +1 -0
- package/dist/protocol/frames.d.ts +45 -0
- package/dist/protocol/frames.d.ts.map +1 -0
- package/dist/protocol/frames.js +125 -0
- package/dist/protocol/frames.js.map +1 -0
- package/dist/protocol/index.d.ts +12 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +12 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/messages.d.ts +250 -0
- package/dist/protocol/messages.d.ts.map +1 -0
- package/dist/protocol/messages.js +7 -0
- package/dist/protocol/messages.js.map +1 -0
- package/dist/protocol/validate.d.ts +61 -0
- package/dist/protocol/validate.d.ts.map +1 -0
- package/dist/protocol/validate.js +139 -0
- package/dist/protocol/validate.js.map +1 -0
- package/dist/text/apply.d.ts +27 -0
- package/dist/text/apply.d.ts.map +1 -0
- package/dist/text/apply.js +151 -0
- package/dist/text/apply.js.map +1 -0
- package/dist/text/chunk.d.ts +33 -0
- package/dist/text/chunk.d.ts.map +1 -0
- package/dist/text/chunk.js +152 -0
- package/dist/text/chunk.js.map +1 -0
- package/dist/text/equal.d.ts +4 -0
- package/dist/text/equal.d.ts.map +1 -0
- package/dist/text/equal.js +16 -0
- package/dist/text/equal.js.map +1 -0
- package/dist/text/href.d.ts +13 -0
- package/dist/text/href.d.ts.map +1 -0
- package/dist/text/href.js +31 -0
- package/dist/text/href.js.map +1 -0
- package/dist/text/index.d.ts +18 -0
- package/dist/text/index.d.ts.map +1 -0
- package/dist/text/index.js +14 -0
- package/dist/text/index.js.map +1 -0
- package/dist/text/ot.d.ts +7 -0
- package/dist/text/ot.d.ts.map +1 -0
- package/dist/text/ot.js +136 -0
- package/dist/text/ot.js.map +1 -0
- package/dist/text/page.d.ts +35 -0
- package/dist/text/page.d.ts.map +1 -0
- package/dist/text/page.js +31 -0
- package/dist/text/page.js.map +1 -0
- package/dist/text/rebase.d.ts +50 -0
- package/dist/text/rebase.d.ts.map +1 -0
- package/dist/text/rebase.js +59 -0
- package/dist/text/rebase.js.map +1 -0
- package/dist/text/schema.d.ts +43 -0
- package/dist/text/schema.d.ts.map +1 -0
- package/dist/text/schema.js +482 -0
- package/dist/text/schema.js.map +1 -0
- package/dist/text/steps.d.ts +17 -0
- package/dist/text/steps.d.ts.map +1 -0
- package/dist/text/steps.js +14 -0
- package/dist/text/steps.js.map +1 -0
- package/dist/util/canonical-json.d.ts +16 -0
- package/dist/util/canonical-json.d.ts.map +1 -0
- package/dist/util/canonical-json.js +28 -0
- package/dist/util/canonical-json.js.map +1 -0
- package/dist/util/index.d.ts +10 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +10 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/random.d.ts +17 -0
- package/dist/util/random.d.ts.map +1 -0
- package/dist/util/random.js +40 -0
- package/dist/util/random.js.map +1 -0
- package/dist/util/utf8.d.ts +13 -0
- package/dist/util/utf8.d.ts.map +1 -0
- package/dist/util/utf8.js +38 -0
- package/dist/util/utf8.js.map +1 -0
- package/package.json +57 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@open-docex/shared`: isomorphic contracts used by `@open-docex/server` and
|
|
3
|
+
* `@open-docex/client` (LLD Part 1 §2). It runs in browsers and in Node.js, so it
|
|
4
|
+
* uses no Node or DOM APIs beyond those declared in `env.d.ts`.
|
|
5
|
+
*
|
|
6
|
+
* The root re-exports every public module (LLD Part 1 §2). Main-process code imports only
|
|
7
|
+
* the `/protocol`, `/errors` and `/ids` subpaths (N4). Modules not yet implemented
|
|
8
|
+
* (`/sheet`) is added by a later task (V2).
|
|
9
|
+
*/
|
|
10
|
+
export * from './util/index.js';
|
|
11
|
+
export * from './ids/index.js';
|
|
12
|
+
export * from './errors/index.js';
|
|
13
|
+
export * from './protocol/index.js';
|
|
14
|
+
export * from './ot/index.js';
|
|
15
|
+
export * from './text/index.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ot/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/ot/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ot/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OT Strategy interface shared by both document kinds (LLD Part 1 §7, HLD §7,
|
|
3
|
+
* §0 S-21), plus the chunk types used to send a snapshot in pieces.
|
|
4
|
+
*/
|
|
5
|
+
/** Limits for splitting a snapshot into chunks (HLD §12). */
|
|
6
|
+
export interface ChunkLimits {
|
|
7
|
+
/** Most top-level text blocks in one chunk. */
|
|
8
|
+
textBlocks: number;
|
|
9
|
+
/** Most sheet rows in one chunk. */
|
|
10
|
+
sheetRows: number;
|
|
11
|
+
/** Most bytes in one chunk's `data`, as `utf8Length(JSON.stringify(data))`. */
|
|
12
|
+
maxBytes: number;
|
|
13
|
+
}
|
|
14
|
+
/** Default chunk limits (HLD §12). */
|
|
15
|
+
export declare const DEFAULT_CHUNK_LIMITS: ChunkLimits;
|
|
16
|
+
/** One piece of a snapshot. `seq` runs 0…n-1. `D` is the kind's chunk data type. */
|
|
17
|
+
export interface Chunk<D = unknown> {
|
|
18
|
+
seq: number;
|
|
19
|
+
data: D;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The operations a document kind provides to the engine. Every method is deterministic
|
|
23
|
+
* and pure, and never mutates its inputs.
|
|
24
|
+
*
|
|
25
|
+
* Laws (LLD Part 1 §7):
|
|
26
|
+
* - L1: `apply(s, [])` returns `s` unchanged with `dropped: 0`.
|
|
27
|
+
* - L2: `applied.length + dropped == ops.length`.
|
|
28
|
+
* - L3: `rebase(ops, []) ≡ ops` and `rebase([], over) ≡ []`.
|
|
29
|
+
* - L4: `deserializeSnapshot(serializeSnapshot(s)) ≡ s`.
|
|
30
|
+
* - L5: `assemble(chunk(s, l)) ≡ s` for every `l`.
|
|
31
|
+
* - L6: chunk `seq` values are 0…n-1, and each chunk is ≤ `maxBytes`, except a chunk
|
|
32
|
+
* holding one indivisible unit that is larger by itself.
|
|
33
|
+
* - L7: `validateOps` returns normalized ops with unknown fields stripped, and throws
|
|
34
|
+
* `PROTOCOL_OP_REJECTED`.
|
|
35
|
+
* - L8: every method is deterministic and pure.
|
|
36
|
+
*
|
|
37
|
+
* @typeParam S - snapshot type
|
|
38
|
+
* @typeParam O - op type
|
|
39
|
+
* @typeParam D - chunk data type
|
|
40
|
+
*/
|
|
41
|
+
export interface OtType<S, O, D> {
|
|
42
|
+
kind: 'text' | 'sheet';
|
|
43
|
+
apply(s: S, ops: O[]): {
|
|
44
|
+
snapshot: S;
|
|
45
|
+
applied: O[];
|
|
46
|
+
dropped: number;
|
|
47
|
+
};
|
|
48
|
+
rebase(ops: O[], over: O[]): O[];
|
|
49
|
+
validateOps(ops: unknown): O[];
|
|
50
|
+
serializeSnapshot(s: S): unknown;
|
|
51
|
+
deserializeSnapshot(j: unknown): S;
|
|
52
|
+
chunk(s: S, limits: ChunkLimits): Chunk<D>[];
|
|
53
|
+
assemble(chunks: Chunk<D>[]): S;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ot/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;A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LLD Part 1 §7, HLD §7,
|
|
3
|
+
* §0 S-21), plus the chunk types used to send a snapshot in pieces.
|
|
4
|
+
*/
|
|
5
|
+
/** Default chunk limits (HLD §12). */
|
|
6
|
+
export const DEFAULT_CHUNK_LIMITS = Object.freeze({
|
|
7
|
+
textBlocks: 200,
|
|
8
|
+
sheetRows: 500,
|
|
9
|
+
maxBytes: 262_144,
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ot/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,sCAAsC;AACtC,MAAM,CAAC,MAAM,oBAAoB,GAAgB,MAAM,CAAC,MAAM,CAAC;IAC7D,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,OAAO;CAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket close codes (LLD Part 1 §5.5, §0 R-16). The close reason is the `ErrorCode`
|
|
3
|
+
* string; when there is one, the server first sends an `error` frame with it, then closes.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { ErrorCode } from '../errors/index.js';
|
|
8
|
+
/** Every close code open_docex uses. */
|
|
9
|
+
export declare const CloseCode: {
|
|
10
|
+
/** Client `destroy()`. */
|
|
11
|
+
readonly NORMAL: 1000;
|
|
12
|
+
/** Engine shutdown; reconnect with backoff and `resume`. */
|
|
13
|
+
readonly GOING_AWAY: 1001;
|
|
14
|
+
/** Worker crash (`ENGINE_RESTARTING`); reconnect with backoff and `resume`. */
|
|
15
|
+
readonly ENGINE_RESTARTING: 4001;
|
|
16
|
+
/** Engine FAILED (`ENGINE_UNAVAILABLE`); no automatic reconnect. */
|
|
17
|
+
readonly ENGINE_UNAVAILABLE: 4002;
|
|
18
|
+
/** The adopter closed the session by user or document (`ACCESS_DENIED`); no reconnect. */
|
|
19
|
+
readonly ACCESS_DENIED: 4003;
|
|
20
|
+
/** `SESSION_SLOW_CONSUMER`; reconnect at once with no `resume` (full reload). */
|
|
21
|
+
readonly SLOW_CONSUMER: 4004;
|
|
22
|
+
/** `SESSION_CLOSED`; no reconnect. */
|
|
23
|
+
readonly SESSION_CLOSED: 4005;
|
|
24
|
+
/** `DOCUMENT_FAULTED`; reload on user action. */
|
|
25
|
+
readonly DOCUMENT_FAULTED: 4006;
|
|
26
|
+
/** `PROTOCOL_VERSION_UNSUPPORTED` or `PROTOCOL_INVALID_MESSAGE`; no reconnect. */
|
|
27
|
+
readonly PROTOCOL_ERROR: 4007;
|
|
28
|
+
/** Load failed; reconnect with backoff only if the code is retryable. */
|
|
29
|
+
readonly LOAD_FAILED: 4008;
|
|
30
|
+
};
|
|
31
|
+
/** A close code value. */
|
|
32
|
+
export type CloseCode = (typeof CloseCode)[keyof typeof CloseCode];
|
|
33
|
+
/**
|
|
34
|
+
* Returns the close code for an error that closes the connection, or `undefined` for a code
|
|
35
|
+
* with no close code in LLD Part 1 §5.5. The caller decides whether an error closes: for
|
|
36
|
+
* example `ACCESS_DENIED` from `canSubmit` and asset errors keep the connection open.
|
|
37
|
+
*/
|
|
38
|
+
export declare function closeCodeFor(code: ErrorCode): CloseCode | undefined;
|
|
39
|
+
//# sourceMappingURL=close-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"close-codes.d.ts","sourceRoot":"","sources":["../../src/protocol/close-codes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,wCAAwC;AACxC,eAAO,MAAM,SAAS;IACpB,0BAA0B;;IAE1B,4DAA4D;;IAE5D,+EAA+E;;IAE/E,oEAAoE;;IAEpE,0FAA0F;;IAE1F,iFAAiF;;IAEjF,sCAAsC;;IAEtC,iDAAiD;;IAEjD,kFAAkF;;IAElF,yEAAyE;;CAEjE,CAAC;AACX,0BAA0B;AAC1B,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAkBnE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAEnE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Every close code open_docex uses. */
|
|
2
|
+
export const CloseCode = {
|
|
3
|
+
/** Client `destroy()`. */
|
|
4
|
+
NORMAL: 1000,
|
|
5
|
+
/** Engine shutdown; reconnect with backoff and `resume`. */
|
|
6
|
+
GOING_AWAY: 1001,
|
|
7
|
+
/** Worker crash (`ENGINE_RESTARTING`); reconnect with backoff and `resume`. */
|
|
8
|
+
ENGINE_RESTARTING: 4001,
|
|
9
|
+
/** Engine FAILED (`ENGINE_UNAVAILABLE`); no automatic reconnect. */
|
|
10
|
+
ENGINE_UNAVAILABLE: 4002,
|
|
11
|
+
/** The adopter closed the session by user or document (`ACCESS_DENIED`); no reconnect. */
|
|
12
|
+
ACCESS_DENIED: 4003,
|
|
13
|
+
/** `SESSION_SLOW_CONSUMER`; reconnect at once with no `resume` (full reload). */
|
|
14
|
+
SLOW_CONSUMER: 4004,
|
|
15
|
+
/** `SESSION_CLOSED`; no reconnect. */
|
|
16
|
+
SESSION_CLOSED: 4005,
|
|
17
|
+
/** `DOCUMENT_FAULTED`; reload on user action. */
|
|
18
|
+
DOCUMENT_FAULTED: 4006,
|
|
19
|
+
/** `PROTOCOL_VERSION_UNSUPPORTED` or `PROTOCOL_INVALID_MESSAGE`; no reconnect. */
|
|
20
|
+
PROTOCOL_ERROR: 4007,
|
|
21
|
+
/** Load failed; reconnect with backoff only if the code is retryable. */
|
|
22
|
+
LOAD_FAILED: 4008,
|
|
23
|
+
};
|
|
24
|
+
const BY_ERROR = {
|
|
25
|
+
ENGINE_RESTARTING: CloseCode.ENGINE_RESTARTING,
|
|
26
|
+
ENGINE_UNAVAILABLE: CloseCode.ENGINE_UNAVAILABLE,
|
|
27
|
+
ACCESS_DENIED: CloseCode.ACCESS_DENIED,
|
|
28
|
+
SESSION_SLOW_CONSUMER: CloseCode.SLOW_CONSUMER,
|
|
29
|
+
SESSION_CLOSED: CloseCode.SESSION_CLOSED,
|
|
30
|
+
DOCUMENT_FAULTED: CloseCode.DOCUMENT_FAULTED,
|
|
31
|
+
PROTOCOL_VERSION_UNSUPPORTED: CloseCode.PROTOCOL_ERROR,
|
|
32
|
+
PROTOCOL_INVALID_MESSAGE: CloseCode.PROTOCOL_ERROR,
|
|
33
|
+
DOCUMENT_NOT_FOUND: CloseCode.LOAD_FAILED,
|
|
34
|
+
DOCUMENT_TOO_LARGE: CloseCode.LOAD_FAILED,
|
|
35
|
+
CONVERSION_FAILED: CloseCode.LOAD_FAILED,
|
|
36
|
+
CONVERSION_TIMEOUT: CloseCode.LOAD_FAILED,
|
|
37
|
+
STORAGE_READ_FAILED: CloseCode.LOAD_FAILED,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns the close code for an error that closes the connection, or `undefined` for a code
|
|
41
|
+
* with no close code in LLD Part 1 §5.5. The caller decides whether an error closes: for
|
|
42
|
+
* example `ACCESS_DENIED` from `canSubmit` and asset errors keep the connection open.
|
|
43
|
+
*/
|
|
44
|
+
export function closeCodeFor(code) {
|
|
45
|
+
return Object.prototype.hasOwnProperty.call(BY_ERROR, code) ? BY_ERROR[code] : undefined;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=close-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"close-codes.js","sourceRoot":"","sources":["../../src/protocol/close-codes.ts"],"names":[],"mappings":"AAQA,wCAAwC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,0BAA0B;IAC1B,MAAM,EAAE,IAAI;IACZ,4DAA4D;IAC5D,UAAU,EAAE,IAAI;IAChB,+EAA+E;IAC/E,iBAAiB,EAAE,IAAI;IACvB,oEAAoE;IACpE,kBAAkB,EAAE,IAAI;IACxB,0FAA0F;IAC1F,aAAa,EAAE,IAAI;IACnB,iFAAiF;IACjF,aAAa,EAAE,IAAI;IACnB,sCAAsC;IACtC,cAAc,EAAE,IAAI;IACpB,iDAAiD;IACjD,gBAAgB,EAAE,IAAI;IACtB,kFAAkF;IAClF,cAAc,EAAE,IAAI;IACpB,yEAAyE;IACzE,WAAW,EAAE,IAAI;CACT,CAAC;AAIX,MAAM,QAAQ,GAA0C;IACtD,iBAAiB,EAAE,SAAS,CAAC,iBAAiB;IAC9C,kBAAkB,EAAE,SAAS,CAAC,kBAAkB;IAChD,aAAa,EAAE,SAAS,CAAC,aAAa;IACtC,qBAAqB,EAAE,SAAS,CAAC,aAAa;IAC9C,cAAc,EAAE,SAAS,CAAC,cAAc;IACxC,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;IAC5C,4BAA4B,EAAE,SAAS,CAAC,cAAc;IACtD,wBAAwB,EAAE,SAAS,CAAC,cAAc;IAClD,kBAAkB,EAAE,SAAS,CAAC,WAAW;IACzC,kBAAkB,EAAE,SAAS,CAAC,WAAW;IACzC,iBAAiB,EAAE,SAAS,CAAC,WAAW;IACxC,kBAAkB,EAAE,SAAS,CAAC,WAAW;IACzC,mBAAmB,EAAE,SAAS,CAAC,WAAW;CAC3C,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OpenDocexError } from '../errors/index.js';
|
|
2
|
+
import type { ClientMessage, ServerMessage } from './messages.js';
|
|
3
|
+
/** The result of decoding one frame. */
|
|
4
|
+
export type DecodeResult<M> = {
|
|
5
|
+
kind: 'message';
|
|
6
|
+
message: M;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'ignored';
|
|
9
|
+
type: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'invalid';
|
|
12
|
+
error: OpenDocexError;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* True for a type that is only ever sent in a binary frame: `asset-put` and `upload-chunk`.
|
|
16
|
+
* `asset` is sent in either frame kind (with `bytes` binary, without `bytes` text), so it is
|
|
17
|
+
* not binary-only.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isBinaryType(type: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Encodes a message: a binary frame when it has `bytes`, otherwise a JSON string. Does not
|
|
22
|
+
* validate the message.
|
|
23
|
+
*
|
|
24
|
+
* @throws {OpenDocexError} `PROTOCOL_INVALID_MESSAGE` when a binary header is outside
|
|
25
|
+
* 1…65 536 bytes.
|
|
26
|
+
*/
|
|
27
|
+
export declare function encodeMessage(msg: ClientMessage | ServerMessage): string | Uint8Array;
|
|
28
|
+
/** Decodes a frame a client sent. Never throws. */
|
|
29
|
+
export declare function decodeClientMessage(data: string | Uint8Array): DecodeResult<ClientMessage>;
|
|
30
|
+
/** Decodes a frame a server sent. Never throws. */
|
|
31
|
+
export declare function decodeServerMessage(data: string | Uint8Array): DecodeResult<ServerMessage>;
|
|
32
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/protocol/codec.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,KAAK,EAGV,aAAa,EAGb,aAAa,EAEd,MAAM,eAAe,CAAC;AAGvB,wCAAwC;AACxC,MAAM,MAAM,YAAY,CAAC,CAAC,IACtB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAE,CAAC;AAqO/C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAID;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,GAAG,MAAM,GAAG,UAAU,CAWrF;AAID,mDAAmD;AACnD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC,aAAa,CAAC,CAE1F;AAED,mDAAmD;AACnD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC,aAAa,CAAC,CAE1F"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message validation, encode and decode (LLD Part 1 §5.1, §5.3, §5.4).
|
|
3
|
+
*
|
|
4
|
+
* - Text frames carry a UTF-8 JSON object with a string `type`.
|
|
5
|
+
* - Binary frames ({@link writeBinaryFrame}) carry `asset-put` and `upload-chunk` (C→S) and an
|
|
6
|
+
* `asset` with bytes (S→C). An `asset` without bytes is a text frame (LLD §0 R-10).
|
|
7
|
+
* - A binary-only type in a text frame, or a text type in a binary frame, is invalid.
|
|
8
|
+
* - An unknown `type` is ignored (HLD §9).
|
|
9
|
+
*
|
|
10
|
+
* Decoders are pure and never throw: every failure is a `{ kind: 'invalid' }` result carrying
|
|
11
|
+
* `PROTOCOL_INVALID_MESSAGE`.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import { isErrorCode } from '../errors/catalogue.js';
|
|
16
|
+
import { OpenDocexError } from '../errors/index.js';
|
|
17
|
+
import { asDocumentId, isAssetId, isClientId, isEpoch } from '../ids/index.js';
|
|
18
|
+
import { decodeUtf8, readBinaryFrame, writeBinaryFrame } from './frames.js';
|
|
19
|
+
import { isPlainObject, v, ValidationError } from './validate.js';
|
|
20
|
+
const MAX = Number.MAX_SAFE_INTEGER;
|
|
21
|
+
/** Largest `upload-chunk` payload: 256 KiB (LLD Part 1 §5.2). */
|
|
22
|
+
const MAX_UPLOAD_CHUNK_BYTES = 262_144;
|
|
23
|
+
/** Largest `upload-start.name`, in characters (LLD Part 1 §5.3). */
|
|
24
|
+
const MAX_UPLOAD_NAME = 255;
|
|
25
|
+
/** Largest `UnsupportedFinding.where` (LLD Part 1 §5.2). */
|
|
26
|
+
const MAX_WHERE = 20;
|
|
27
|
+
/** An annotation ID: the {@link newRandomId} format. */
|
|
28
|
+
const ANNOTATION_ID = /^[A-Za-z0-9_-]{22}$/;
|
|
29
|
+
// --- field checks ----------------------------------------------------------------------------
|
|
30
|
+
const rev = v.int(0, MAX);
|
|
31
|
+
const clientSeq = v.int(1, MAX);
|
|
32
|
+
const reqId = v.int(0, MAX);
|
|
33
|
+
const count = v.int(0, MAX);
|
|
34
|
+
const text = v.str(MAX);
|
|
35
|
+
const clientId = v.is(isClientId, 'expected a client ID');
|
|
36
|
+
const epoch = v.is(isEpoch, 'expected an epoch');
|
|
37
|
+
const assetId = v.is(isAssetId, 'expected an asset ID');
|
|
38
|
+
const annotationId = v.str(22, ANNOTATION_ID);
|
|
39
|
+
const assetMime = v.lit('image/png', 'image/jpeg', 'image/gif');
|
|
40
|
+
/** `ops`: 1…MAX plain objects; deep op validation is `OtType.validateOps` in the Core. */
|
|
41
|
+
const ops = v.arr(v.plain(), { min: 1, max: MAX });
|
|
42
|
+
const documentId = (x, path) => {
|
|
43
|
+
if (typeof x !== 'string')
|
|
44
|
+
throw new ValidationError(path, 'expected a document ID');
|
|
45
|
+
try {
|
|
46
|
+
return asDocumentId(x);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw new ValidationError(path, 'expected a document ID');
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const unsupportedFinding = v.obj({
|
|
53
|
+
feature: v.lit('tracked-changes', 'comments', 'footnotes', 'fields', 'text-boxes', 'equations', 'charts', 'multiple-page-styles', 'first-page-header', 'odd-even-header', 'conditional-formatting', 'data-validation', 'pivot-tables', 'sheet-images', 'cell-comments', 'other'),
|
|
54
|
+
count,
|
|
55
|
+
}, { where: v.arr(text, { max: MAX_WHERE }), detail: text });
|
|
56
|
+
const conversionNotice = v.obj({ feature: v.lit('image-to-png'), count }, { where: v.arr(text, { max: MAX }) });
|
|
57
|
+
const annotation = v.obj({
|
|
58
|
+
id: annotationId,
|
|
59
|
+
kind: v.lit('bookmark', 'note'),
|
|
60
|
+
body: text,
|
|
61
|
+
authorId: text,
|
|
62
|
+
createdAt: text,
|
|
63
|
+
updatedAt: text,
|
|
64
|
+
resolved: v.bool(),
|
|
65
|
+
}, { replyTo: annotationId });
|
|
66
|
+
const annotationInput = v.obj({ id: annotationId, kind: v.lit('bookmark', 'note'), body: text, resolved: v.bool() }, { replyTo: annotationId });
|
|
67
|
+
const noticeStorage = v.obj({ type: v.lit('notice'), notice: v.lit('storage'), state: v.lit('normal', 'local', 'pending') });
|
|
68
|
+
const noticeReadOnly = v.obj({
|
|
69
|
+
type: v.lit('notice'),
|
|
70
|
+
notice: v.lit('read-only'),
|
|
71
|
+
readOnly: v.bool(),
|
|
72
|
+
reason: v.lit('unsupported-content'),
|
|
73
|
+
});
|
|
74
|
+
const noticeEngine = v.obj({ type: v.lit('notice'), notice: v.lit('engine-restarting') });
|
|
75
|
+
const notice = (x, path) => {
|
|
76
|
+
if (!isPlainObject(x))
|
|
77
|
+
throw new ValidationError(path, 'expected an object');
|
|
78
|
+
switch (x['notice']) {
|
|
79
|
+
case 'storage':
|
|
80
|
+
return noticeStorage(x, path);
|
|
81
|
+
case 'read-only':
|
|
82
|
+
return noticeReadOnly(x, path);
|
|
83
|
+
case 'engine-restarting':
|
|
84
|
+
return noticeEngine(x, path);
|
|
85
|
+
default:
|
|
86
|
+
throw new ValidationError(`${path}.notice`, 'unexpected value');
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const annotationChangedFields = v.obj({ type: v.lit('annotation-changed') }, { annotation, deletedId: annotationId });
|
|
90
|
+
/** `annotation-changed` carries exactly one of `annotation` or `deletedId` (project owner, V1-02 review). */
|
|
91
|
+
const annotationChanged = (x, path) => {
|
|
92
|
+
const m = annotationChangedFields(x, path);
|
|
93
|
+
if ((m.annotation === undefined) === (m.deletedId === undefined)) {
|
|
94
|
+
throw new ValidationError(path, 'expected exactly one of annotation or deletedId');
|
|
95
|
+
}
|
|
96
|
+
return m;
|
|
97
|
+
};
|
|
98
|
+
function table(entries) {
|
|
99
|
+
return Object.assign(Object.create(null), entries);
|
|
100
|
+
}
|
|
101
|
+
function lookup(t, type) {
|
|
102
|
+
return Object.prototype.hasOwnProperty.call(t, type) ? t[type] : undefined;
|
|
103
|
+
}
|
|
104
|
+
/** Client messages sent in text frames. */
|
|
105
|
+
const CLIENT_TEXT = table({
|
|
106
|
+
hello: v.obj({ type: v.lit('hello'), protocol: v.int(0, MAX), clientId }, { resume: v.obj({ epoch, rev }) }),
|
|
107
|
+
submit: v.obj({ type: v.lit('submit'), clientId, clientSeq, epoch, baseRev: rev, ops }),
|
|
108
|
+
'asset-get': v.obj({ type: v.lit('asset-get'), reqId, assetId }),
|
|
109
|
+
ping: v.obj({ type: v.lit('ping'), n: v.int(0, MAX) }),
|
|
110
|
+
'upload-start': v.obj({
|
|
111
|
+
type: v.lit('upload-start'),
|
|
112
|
+
reqId,
|
|
113
|
+
name: v.str(MAX_UPLOAD_NAME),
|
|
114
|
+
format: v.lit('docx', 'odt', 'xlsx', 'ods'),
|
|
115
|
+
size: count,
|
|
116
|
+
}),
|
|
117
|
+
'upload-end': v.obj({ type: v.lit('upload-end'), reqId }),
|
|
118
|
+
'annotation-list': v.obj({ type: v.lit('annotation-list'), reqId }),
|
|
119
|
+
'annotation-put': v.obj({ type: v.lit('annotation-put'), reqId, annotation: annotationInput }),
|
|
120
|
+
'annotation-delete': v.obj({ type: v.lit('annotation-delete'), reqId, id: annotationId }),
|
|
121
|
+
});
|
|
122
|
+
/** Client messages sent in binary frames. */
|
|
123
|
+
const CLIENT_BINARY = table({
|
|
124
|
+
'asset-put': v.obj({ type: v.lit('asset-put'), reqId, mime: assetMime, bytes: v.bytes(MAX) }),
|
|
125
|
+
'upload-chunk': v.obj({
|
|
126
|
+
type: v.lit('upload-chunk'),
|
|
127
|
+
reqId,
|
|
128
|
+
seq: rev,
|
|
129
|
+
bytes: v.bytes(MAX_UPLOAD_CHUNK_BYTES),
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
/** Server messages sent in text frames. */
|
|
133
|
+
const SERVER_TEXT = table({
|
|
134
|
+
'load-start': v.obj({
|
|
135
|
+
type: v.lit('load-start'),
|
|
136
|
+
epoch,
|
|
137
|
+
rev,
|
|
138
|
+
kind: v.lit('text', 'sheet'),
|
|
139
|
+
access: v.lit('edit', 'view'),
|
|
140
|
+
readOnly: v.bool(),
|
|
141
|
+
}, {
|
|
142
|
+
unsupported: v.arr(unsupportedFinding, { max: MAX }),
|
|
143
|
+
ackedClientSeq: clientSeq,
|
|
144
|
+
totalChunks: count,
|
|
145
|
+
limits: v.obj({}, { maxAssetBytes: count }),
|
|
146
|
+
conversions: v.arr(conversionNotice, { max: MAX }),
|
|
147
|
+
}),
|
|
148
|
+
'load-chunk': v.obj({ type: v.lit('load-chunk'), seq: rev, data: v.plain() }),
|
|
149
|
+
'load-done': v.obj({ type: v.lit('load-done'), rev }),
|
|
150
|
+
ack: v.obj({ type: v.lit('ack'), clientSeq, rev }, { committed: v.arr(v.plain(), { max: MAX }) }),
|
|
151
|
+
remote: v.obj({ type: v.lit('remote'), fromRev: rev, ops, clientId }),
|
|
152
|
+
error: v.obj({
|
|
153
|
+
type: v.lit('error'),
|
|
154
|
+
code: v.is(isErrorCode, 'expected an error code'),
|
|
155
|
+
retryable: v.bool(),
|
|
156
|
+
message: text,
|
|
157
|
+
}, { clientSeq, reqId }),
|
|
158
|
+
resync: v.obj({ type: v.lit('resync'), reason: v.lit('epoch-changed', 'history-unavailable', 'inconsistent') }),
|
|
159
|
+
notice,
|
|
160
|
+
asset: v.obj({ type: v.lit('asset'), reqId, assetId, mime: assetMime, size: count }),
|
|
161
|
+
pong: v.obj({ type: v.lit('pong'), n: v.int(0, MAX) }),
|
|
162
|
+
'upload-ack': v.obj({ type: v.lit('upload-ack'), reqId, receivedBytes: count }),
|
|
163
|
+
'upload-done': v.obj({ type: v.lit('upload-done'), reqId, documentId }),
|
|
164
|
+
'annotation-result': v.obj({
|
|
165
|
+
type: v.lit('annotation-result'),
|
|
166
|
+
reqId,
|
|
167
|
+
annotations: v.arr(annotation, { max: MAX }),
|
|
168
|
+
}),
|
|
169
|
+
'annotation-changed': annotationChanged,
|
|
170
|
+
});
|
|
171
|
+
/** Server messages sent in binary frames. */
|
|
172
|
+
const SERVER_BINARY = table({
|
|
173
|
+
asset: v.obj({
|
|
174
|
+
type: v.lit('asset'),
|
|
175
|
+
reqId,
|
|
176
|
+
assetId,
|
|
177
|
+
mime: assetMime,
|
|
178
|
+
size: count,
|
|
179
|
+
bytes: v.bytes(MAX),
|
|
180
|
+
}),
|
|
181
|
+
});
|
|
182
|
+
const BINARY_ONLY = new Set(['asset-put', 'upload-chunk']);
|
|
183
|
+
/**
|
|
184
|
+
* True for a type that is only ever sent in a binary frame: `asset-put` and `upload-chunk`.
|
|
185
|
+
* `asset` is sent in either frame kind (with `bytes` binary, without `bytes` text), so it is
|
|
186
|
+
* not binary-only.
|
|
187
|
+
*/
|
|
188
|
+
export function isBinaryType(type) {
|
|
189
|
+
return BINARY_ONLY.has(type);
|
|
190
|
+
}
|
|
191
|
+
// --- encode ----------------------------------------------------------------------------------
|
|
192
|
+
/**
|
|
193
|
+
* Encodes a message: a binary frame when it has `bytes`, otherwise a JSON string. Does not
|
|
194
|
+
* validate the message.
|
|
195
|
+
*
|
|
196
|
+
* @throws {OpenDocexError} `PROTOCOL_INVALID_MESSAGE` when a binary header is outside
|
|
197
|
+
* 1…65 536 bytes.
|
|
198
|
+
*/
|
|
199
|
+
export function encodeMessage(msg) {
|
|
200
|
+
if ('bytes' in msg && msg.bytes instanceof Uint8Array) {
|
|
201
|
+
const { bytes, ...rest } = msg;
|
|
202
|
+
const header = new TextEncoder().encode(JSON.stringify(rest));
|
|
203
|
+
const frame = writeBinaryFrame(header, bytes);
|
|
204
|
+
if (frame === undefined) {
|
|
205
|
+
throw new OpenDocexError('PROTOCOL_INVALID_MESSAGE', 'Binary frame header must be 1 to 65536 bytes.');
|
|
206
|
+
}
|
|
207
|
+
return frame;
|
|
208
|
+
}
|
|
209
|
+
return JSON.stringify(msg);
|
|
210
|
+
}
|
|
211
|
+
// --- decode ----------------------------------------------------------------------------------
|
|
212
|
+
/** Decodes a frame a client sent. Never throws. */
|
|
213
|
+
export function decodeClientMessage(data) {
|
|
214
|
+
return decode(data, CLIENT_TEXT, CLIENT_BINARY);
|
|
215
|
+
}
|
|
216
|
+
/** Decodes a frame a server sent. Never throws. */
|
|
217
|
+
export function decodeServerMessage(data) {
|
|
218
|
+
return decode(data, SERVER_TEXT, SERVER_BINARY);
|
|
219
|
+
}
|
|
220
|
+
function invalid(detail) {
|
|
221
|
+
return { kind: 'invalid', error: new OpenDocexError('PROTOCOL_INVALID_MESSAGE', `Invalid message: ${detail}.`) };
|
|
222
|
+
}
|
|
223
|
+
function parseObject(json) {
|
|
224
|
+
let parsed;
|
|
225
|
+
try {
|
|
226
|
+
parsed = JSON.parse(json);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
return isPlainObject(parsed) && typeof parsed['type'] === 'string' ? parsed : undefined;
|
|
232
|
+
}
|
|
233
|
+
function run(check, x) {
|
|
234
|
+
try {
|
|
235
|
+
return { kind: 'message', message: check(x, '$') };
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
if (e instanceof ValidationError)
|
|
239
|
+
return invalid(`${e.path}: ${e.reason}`);
|
|
240
|
+
return invalid('validation failed');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function decode(data, textTable, binaryTable) {
|
|
244
|
+
if (typeof data === 'string') {
|
|
245
|
+
const obj = parseObject(data);
|
|
246
|
+
if (obj === undefined)
|
|
247
|
+
return invalid('not a JSON object with a string type');
|
|
248
|
+
const type = obj['type'];
|
|
249
|
+
if (isBinaryType(type))
|
|
250
|
+
return invalid('binary-only type in a text frame');
|
|
251
|
+
const check = lookup(textTable, type);
|
|
252
|
+
return check === undefined ? { kind: 'ignored', type } : run(check, obj);
|
|
253
|
+
}
|
|
254
|
+
if (!(data instanceof Uint8Array))
|
|
255
|
+
return invalid('unsupported frame data');
|
|
256
|
+
const parts = readBinaryFrame(data);
|
|
257
|
+
if (parts === undefined)
|
|
258
|
+
return invalid('malformed binary frame');
|
|
259
|
+
const json = decodeUtf8(parts.header);
|
|
260
|
+
const hdr = json === undefined ? undefined : parseObject(json);
|
|
261
|
+
if (hdr === undefined)
|
|
262
|
+
return invalid('binary header is not a JSON object with a string type');
|
|
263
|
+
const type = hdr['type'];
|
|
264
|
+
const check = lookup(binaryTable, type);
|
|
265
|
+
if (check === undefined) {
|
|
266
|
+
return lookup(textTable, type) === undefined ? { kind: 'ignored', type } : invalid('text type in a binary frame');
|
|
267
|
+
}
|
|
268
|
+
return run(check, { ...hdr, bytes: parts.payload });
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/protocol/codec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YA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,GAAG,GAAG,CAAC,MAAM,CAAW,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IACxC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;IACpH,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binary frame layout (LLD Part 1 §5.1):
|
|
3
|
+
*
|
|
4
|
+
* | Offset | Size | Field |
|
|
5
|
+
* |---|---|---|
|
|
6
|
+
* | 0 | 1 | Magic `0xD0` |
|
|
7
|
+
* | 1 | 1 | Layout version `1` |
|
|
8
|
+
* | 2 | 4 | Header length H, uint32 big-endian, 1 ≤ H ≤ 65 536 |
|
|
9
|
+
* | 6 | H | Header: UTF-8 JSON of the message without `bytes` |
|
|
10
|
+
* | 6+H | rest | Payload, which becomes the `bytes` field |
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/** First byte of every binary frame. */
|
|
15
|
+
export declare const FRAME_MAGIC = 208;
|
|
16
|
+
/** Binary frame layout version. */
|
|
17
|
+
export declare const FRAME_VERSION = 1;
|
|
18
|
+
/** Bytes before the header: magic, version and the header length. */
|
|
19
|
+
export declare const FRAME_PREFIX_BYTES = 6;
|
|
20
|
+
/** Largest allowed header, in bytes. */
|
|
21
|
+
export declare const MAX_FRAME_HEADER_BYTES = 65536;
|
|
22
|
+
/** The parts of a binary frame. `payload` is a view into the frame, not a copy. */
|
|
23
|
+
export interface BinaryFrameParts {
|
|
24
|
+
header: Uint8Array;
|
|
25
|
+
payload: Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Builds a binary frame from a UTF-8 header and a payload. Returns `undefined` when the header
|
|
29
|
+
* length is outside 1…65 536 bytes.
|
|
30
|
+
*/
|
|
31
|
+
export declare function writeBinaryFrame(header: Uint8Array, payload: Uint8Array): Uint8Array | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Splits a binary frame. Returns `undefined` when the frame is shorter than 6 bytes, the magic
|
|
34
|
+
* or version is wrong, or the header length is outside 1…65 536 or past the end of the frame.
|
|
35
|
+
*/
|
|
36
|
+
export declare function readBinaryFrame(data: Uint8Array): BinaryFrameParts | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Strict UTF-8 decoding of a frame header. Returns `undefined` for malformed UTF-8 (overlong
|
|
39
|
+
* forms, surrogates, code points above U+10FFFF, truncated sequences).
|
|
40
|
+
*
|
|
41
|
+
* Written by hand because shared may use only the globals in `env.d.ts`, which has no
|
|
42
|
+
* `TextDecoder` (LLD Part 1 §1.4).
|
|
43
|
+
*/
|
|
44
|
+
export declare function decodeUtf8(b: Uint8Array): string | undefined;
|
|
45
|
+
//# sourceMappingURL=frames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frames.d.ts","sourceRoot":"","sources":["../../src/protocol/frames.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,wCAAwC;AACxC,eAAO,MAAM,WAAW,MAAO,CAAC;AAChC,mCAAmC;AACnC,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,qEAAqE;AACrE,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,wCAAwC;AACxC,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,CAahG;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAU9E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CA6C5D"}
|