diff --git a/auth.js b/auth.js index e32e312..71e80db 100644 --- a/auth.js +++ b/auth.js @@ -1,4 +1,5 @@ +import * as Y from 'yjs' // eslint-disable-line import * as encoding from 'lib0/encoding.js' import * as decoding from 'lib0/decoding.js' @@ -22,7 +23,7 @@ export const writePermissionDenied = (encoder, reason) => { /** * * @param {decoding.Decoder} decoder - * @param {Y} y + * @param {Y.Doc} y * @param {PermissionDeniedHandler} permissionDeniedHandler */ export const readAuthMessage = (decoder, y, permissionDeniedHandler) => { diff --git a/history.js b/history.js deleted file mode 100644 index 46469c3..0000000 --- a/history.js +++ /dev/null @@ -1,44 +0,0 @@ - -import * as encoding from 'lib0/encoding.js' -import * as decoding from 'lib0/decoding.js' -import * as Y from 'yjs' - -/** - * @typedef {Object} HistorySnapshot - * @property {Y.DeleteStore} HistorySnapshot.ds - * @property {Map} HistorySnapshot.sv - * @property {Map} HistorySnapshot.userMap - */ - -/** - * @param {encoding.Encoder} encoder - * @param {Y.Doc} y - * @param {Map} userMap - */ -export const writeHistorySnapshot = (encoder, y, userMap) => { - writeDeleteStore(encoder, y.ds) - writeStateMap(encoder, y.ss.state) - encoding.writeVarUint(encoder, userMap.size) - userMap.forEach((accountname, userid) => { - encoding.writeVarUint(encoder, userid) - encoding.writeVarString(encoder, accountname) - }) -} - -/** - * - * @param {decoding.Decoder} decoder - * @return {HistorySnapshot} - */ -export const readHistorySnapshot = decoder => { - const ds = readFreshDeleteStore(decoder) - const sm = readStateMap(decoder) - const size = decoding.readVarUint(decoder) - const userMap = new Map() - for (let i = 0; i < size; i++) { - const userid = decoding.readVarUint(decoder) - const accountname = decoding.readVarString(decoder) - userMap.set(userid, accountname) - } - return { ds, sm, userMap } -} diff --git a/package-lock.json b/package-lock.json index 3333b2f..265c167 100644 --- a/package-lock.json +++ b/package-lock.json @@ -911,6 +911,11 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "isomorphic.js": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/isomorphic.js/-/isomorphic.js-0.1.0.tgz", + "integrity": "sha512-qoOHpuSbJ56TlPR+vi0xRxdhNBbh/xFbgjB2d+ysekcM5iSh9jzxHURnACQxy0Sb9SnZhxxo9EyN+XbGcQhkAg==" + }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", @@ -965,9 +970,12 @@ } }, "lib0": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.1.0.tgz", - "integrity": "sha512-pkpnv2IJEOb6iwpcJ6BVQu9GkZ9VINKeQ/0BcArHpozqaGQYWe+ychf2p9wHKToHUnivPoGZZ7rFqrxNXjqFBg==" + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.2.3.tgz", + "integrity": "sha512-J1Gw9PT78tO3QODgvzk9NVTXTXTsru9LKq+iPOdWw5s1/QiapUKmCJMCWBrNSGkJ0f3WQkZJtGzn3azJwMDdeg==", + "requires": { + "isomorphic.js": "^0.1.0" + } }, "load-json-file": { "version": "2.0.0", @@ -1625,6 +1633,12 @@ "prelude-ls": "~1.1.2" } }, + "typescript": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", + "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==", + "dev": true + }, "uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", @@ -1687,20 +1701,12 @@ "dev": true }, "yjs": { - "version": "13.0.0-94", - "resolved": "https://registry.npmjs.org/yjs/-/yjs-13.0.0-94.tgz", - "integrity": "sha512-4HETCv/BZ4Mg9rZU+nLZXW8GGp9ugWDA1ImcyIW2hZA2n0YsIgwvROPqWpflwi/l02kfLlvLKF8nEXYk/cOsjQ==", + "version": "13.0.0-105", + "resolved": "https://registry.npmjs.org/yjs/-/yjs-13.0.0-105.tgz", + "integrity": "sha512-nsTm0LVMsOVKpRYXrJHqu9g+ISphBoEnqropblkTUFBbv0TyYVbq11CqN846ip0RC9Nq1Kh8kZ+QHUL1CHnuyA==", "dev": true, "requires": { - "lib0": "0.0.5" - }, - "dependencies": { - "lib0": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/lib0/-/lib0-0.0.5.tgz", - "integrity": "sha512-3ElV6/t5Lv0Eczlnh/05q+Uq3RxQ/Q0zdN6LVtaUERQIDDZsP/CUXEGLsV8KZTgZwVFNCPGXNWYE+3WTOo+SHw==", - "dev": true - } + "lib0": "^0.2.2" } } } diff --git a/package.json b/package.json index adbb114..d15b398 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,18 @@ "name": "y-protocols", "version": "0.1.0", "description": "Yjs encoding protocols", + "type": "module", "files": [ "dist/*", "auth.js", - "history.js", "sync.js", "awareness.js" ], "scripts": { "dist": "rm -rf dist && rollup -c", - "test": "echo 'should lint here'", - "lint": "standard", - "preversion": "npm run dist && npm run test", - "version": "npm run dist" + "test": "npm run lint", + "lint": "standard && tsc", + "preversion": "npm run dist && npm run test" }, "repository": { "type": "git", @@ -36,15 +35,16 @@ }, "homepage": "https://github.com/yjs/y-protocols#readme", "dependencies": { - "lib0": "^0.1.1" + "lib0": "^0.2.3" }, "devDependencies": { - "yjs": "13.0.0-94", "rollup": "^1.1.2", "rollup-cli": "^1.0.9", - "standard": "^12.0.1" + "standard": "^12.0.1", + "typescript": "^3.7.4", + "yjs": "13.0.0-105" }, "peerDependenies": { - "yjs": ">13.0.0-98" + "yjs": ">=13.0.0-103" } } diff --git a/rollup.config.js b/rollup.config.js index 0e710ba..090ddb4 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -6,11 +6,11 @@ const files = fs.readdirSync('./').filter(file => /(? ({ input: file, output: { - file: path.join('./dist', file), + file: path.join('./dist', file.slice(0, -3) + '.cjs'), format: 'cjs', - paths: path => { + paths: /** @param {any} path */ path => { if (/^lib0\//.test(path)) { - return `lib0/dist/${path.slice(5)}` + return `lib0/dist/${path.slice(5, -3) + '.cjs'}` } return path } diff --git a/tsconfig.json b/tsconfig.json index 0d3f7f3..8225f7c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,7 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ @@ -36,8 +36,11 @@ /* Module Resolution Options */ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + "paths": { + "yjs": ["node_modules/yjs/src/index.js"], + "lib0/*": ["node_modules/lib0/*"] + }, // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */