@scipen/ot-protocol
v0.1.0
Published
Wire protocol and OT text operation algorithm for Scipen OT
Maintainers
Readme
@scipen/ot-protocol
Type definitions, OT algorithm (TextOperation), and adapter interfaces for the OT SDK.
Foundation package that every other @scipen/ot-* package depends on. Zero runtime dependencies.
Install
pnpm add @scipen/ot-protocolWhat's inside
Type definitions (. export)
OTClientConfig,OTClientState,OTConnectionState,OTClientEventsWSClientMessage,WSServerMessage— WebSocket protocolStoredFileOp— persistence layer typesProject,ProjectFile,ProjectFolder— domain types (reserved for future project-level collaboration)
import type { OTClientConfig, WSServerMessage } from '@scipen/ot-protocol';OT algorithm (./ot export)
TextOperationclass — the core OT primitive withapply,compose,transformRawOp— serialized op format:number > 0= retain,number < 0= remove,string= insert
import { TextOperation } from '@scipen/ot-protocol/ot';
const op = new TextOperation().retain(3).insert('hello').remove(2);
op.apply('abcdef'); // 'abchellof'
const [a, b] = TextOperation.transform(opA, opB);
// apply(apply(s, opA), b) === apply(apply(s, opB), a) (TP1 convergence)Testing
pnpm test # runs tests/text-operation.test.ts — 47 cases covering apply/compose/transform/serializationCritical: modifying TextOperation.apply / compose / transform MUST come with new test cases. See root CONTRIBUTING.md.
Dependency graph
@scipen/ot-protocol (this package)
↑
ot-core, ot-adapter-browser, ot-adapter-electron-main, ot-reactLicense
MIT © SciPen Team
