diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 159db5c1b1..b43d174755 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -38,7 +38,7 @@ jobs: - run: yarn install --frozen-lockfile - run: yarn build:all - run: yarn lint - - run: yarn prettier:check + - run: yarn format - run: yarn test:cli:pointer - run: yarn test:cli:patch - run: yarn test:cli:pack diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 105a5786ed..421d22f0d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: node-version: ${{ matrix.node-version }} cache: yarn - run: yarn install --frozen-lockfile - - run: yarn prettier:check + - run: yarn format - run: yarn lint - run: yarn test:ci --ci - run: yarn build:all diff --git a/biome.json b/biome.json new file mode 100644 index 0000000000..9286ee854f --- /dev/null +++ b/biome.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", + "organizeImports": { + "enabled": true + }, + "formatter": { + "indentStyle": "space", + "lineWidth": 120 + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + "trailingCommas": "all", + "bracketSpacing": false + } + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "style": { + "noNonNullAssertion": "off", + "useNodejsImportProtocol": "off", + "useTemplate": "off", + "noInferrableTypes": "off", + "noUselessElse": "off", + "noParameterAssign": "off", + "noCommaOperator": "off", + "useSingleVarDeclarator": "off", + "useLiteralEnumMembers": "off" + }, + "suspicious": { + "noExplicitAny": "off", + "useIsArray": "off", + "noAssignInExpressions": "off" + }, + "complexity": { + "noStaticOnlyClass": "off", + "useOptionalChain": "off" + } + } + } +} diff --git a/package.json b/package.json index 1845d677cf..3c1ccabc67 100644 --- a/package.json +++ b/package.json @@ -76,11 +76,10 @@ "lib/" ], "scripts": { - "prettier": "npx prettier@3.2.5 --write .", - "prettier:check": "npx prettier@3.2.5 --check .", - "lint": "yarn tslint", - "lint:fix": "yarn tslint --fix", - "tslint": "tslint 'src/**/*.{js,jsx,ts,tsx}' -t verbose --project .", + "format": "biome format ./src", + "format:fix": "biome format --write ./src", + "lint": "biome lint ./src", + "lint:fix": "biome lint --apply ./src", "clean": "npx rimraf@5.0.5 lib es6 es2019 es2020 esm typedocs coverage gh-pages yarn-error.log src/**/__bench__/node_modules src/**/__bench__/yarn-error.log", "build:es2020": "tsc --project tsconfig.build.json --module commonjs --target es2020 --outDir lib", "build:all": "npx concurrently@8.2.2 \"yarn build:es2020\"", @@ -137,6 +136,7 @@ "tree-dump": "^1.0.2" }, "devDependencies": { + "@biomejs/biome": "^1.9.4", "@types/benchmark": "^2.1.5", "@types/jest": "^29.5.12", "@types/react": "^18.3.11", @@ -179,16 +179,6 @@ ], "testRegex": ".*/(__tests__|__jest__|demo)/.*\\.(test|spec)\\.ts$" }, - "prettier": { - "arrowParens": "always", - "printWidth": 120, - "tabWidth": 2, - "useTabs": false, - "semi": true, - "singleQuote": true, - "trailingComma": "all", - "bracketSpacing": false - }, "config": { "commitizen": { "changelog": { diff --git a/src/__bench__/data/json-object-many-keys.js b/src/__bench__/data/json-object-many-keys.js index dcd30733fe..13a3b64f43 100644 --- a/src/__bench__/data/json-object-many-keys.js +++ b/src/__bench__/data/json-object-many-keys.js @@ -11,7 +11,6 @@ module.exports = { '-6666666': -6666666, 62343423432: 62343423432, 0.123: 0.123, - '0.0': 0.0, '-123.3434343': -123.3434343, 127: 127, 128: 128, @@ -21,8 +20,6 @@ module.exports = { 257: 257, 258: 258, 1000: 1000, - 1000: 1000, - 1000: 1000, '-222222': -222222, '-22222': -22222, a: 'a', diff --git a/src/__bench__/data/text-editing-traces/collect-trace.js b/src/__bench__/data/text-editing-traces/collect-trace.js index 37e071cf07..26c1b509e2 100644 --- a/src/__bench__/data/text-editing-traces/collect-trace.js +++ b/src/__bench__/data/text-editing-traces/collect-trace.js @@ -1,7 +1,7 @@ const fs = require('fs'); const zlib = require('zlib'); -const filename = `/Users/mini/vscodelogs/actions_14_05_2023_olcXlNJx.json`; +const filename = '/Users/mini/vscodelogs/actions_14_05_2023_olcXlNJx.json'; const targetDocFileName = '/Users/mini/dev/json-joy-blog/blog-post-1.md'; const data = fs.readFileSync(filename, 'utf8'); const lines = data.split('\n'); diff --git a/src/__bench__/payloads.ts b/src/__bench__/payloads.ts index afefab446d..79bef394af 100644 --- a/src/__bench__/payloads.ts +++ b/src/__bench__/payloads.ts @@ -44,7 +44,10 @@ export const payloads = [ export const payloadsWithCombined = [ ...(payloads.length > 1 ? (() => { - const combined = payloads.reduce((acc, payload) => [...acc, payload.data], [] as unknown[]); + const combined = payloads.reduce((acc, payload) => { + acc.push(payload.data); + return acc; + }, [] as unknown[]); return [ { data: combined, diff --git a/src/__tests__/util.ts b/src/__tests__/util.ts index 58f942ffec..e1a3c2c684 100644 --- a/src/__tests__/util.ts +++ b/src/__tests__/util.ts @@ -4,5 +4,8 @@ export const until = async (check: () => boolean, pollInterval: number = 1) => { do { if (check()) return; await tick(pollInterval); - } while (true); + } while ( + // biome-ignore lint: constant condition is intentional + true + ); }; diff --git a/src/json-cli/json-pack-test.ts b/src/json-cli/json-pack-test.ts index 2cdf4e0c31..ba426a63ab 100644 --- a/src/json-cli/json-pack-test.ts +++ b/src/json-cli/json-pack-test.ts @@ -3,12 +3,12 @@ import {spawnSync} from 'child_process'; import { testSuites, - TestCaseNil, - TestCaseBool, - TestCaseString, - TestCaseNumber, - TestCaseArray, - TestCaseMap, + type TestCaseNil, + type TestCaseBool, + type TestCaseString, + type TestCaseNumber, + type TestCaseArray, + type TestCaseMap, } from './test/msgpack-test-suite'; const bin = String(process.argv[2]); @@ -19,7 +19,7 @@ if (!bin) { } console.log(''); -console.log(`Running json-pack tests.`); +console.log('Running json-pack tests.'); console.log(''); let cntCorrect = 0; @@ -54,11 +54,11 @@ for (const name in testSuites) { const result = new Uint8Array(stdout.length); for (let i = 0; i < result.length; i++) result[i] = stdout[i]; EXPECTED: for (const exp of testCase.msgpack) { - const expected = new Uint8Array(exp.split('-').map((a) => parseInt(a, 16))); + const expected = new Uint8Array(exp.split('-').map((a) => Number.parseInt(a, 16))); if (expected.length !== result.length) continue; for (let i = 0; i < expected.length; i++) if (expected[i] !== result[i]) continue EXPECTED; isCorrect = true; - break EXPECTED; + break; } if (isCorrect) { cntCorrect++; diff --git a/src/json-cli/json-patch-test.ts b/src/json-cli/json-patch-test.ts index 3fbe72bc4d..355815ee2b 100644 --- a/src/json-cli/json-patch-test.ts +++ b/src/json-cli/json-patch-test.ts @@ -15,18 +15,18 @@ if (!bin) { let cntCorrect = 0; let cntFailed = 0; -testSuites.forEach((suite) => { +for (const suite of testSuites) { console.log(''); console.log(suite.name); console.log(''); - suite.tests.forEach((test: any) => { - if (test.disabled) return; + for (const test of suite.tests) { + if (test.disabled) break; const testName = test.comment || test.error || JSON.stringify(test.patch); if (test.expected !== undefined) { - test.patch.forEach(validateOperation); + test.patch.forEach(validateOperation as any); let isCorrect = false; - let result; + let result: unknown; try { const input = JSON.stringify(test.doc); const {stdout} = spawnSync(bin, [JSON.stringify(test.patch)], {input}); @@ -69,8 +69,8 @@ testSuites.forEach((suite) => { } if (cntFailed) process.exit(1); - }); -}); + } +} console.log(''); console.log(`Successful = ${cntCorrect}, Failed = ${cntFailed}, Total = ${cntCorrect + cntFailed}`); diff --git a/src/json-cli/json-pointer-test.ts b/src/json-cli/json-pointer-test.ts index 302ec05a32..b1a0376351 100644 --- a/src/json-cli/json-pointer-test.ts +++ b/src/json-cli/json-pointer-test.ts @@ -12,7 +12,7 @@ if (!bin) { } console.log(''); -console.log(`Running JSON Pointer tests.`); +console.log('Running JSON Pointer tests.'); console.log(''); let cntCorrect = 0; diff --git a/src/json-cli/test/op.add.tests.json.ts b/src/json-cli/test/op.add.tests.json.ts index 871dcefd2e..9e53a57735 100644 --- a/src/json-cli/test/op.add.tests.json.ts +++ b/src/json-cli/test/op.add.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.contains.tests.json.ts b/src/json-cli/test/op.contains.tests.json.ts index fde2485c1b..bc36344c2c 100644 --- a/src/json-cli/test/op.contains.tests.json.ts +++ b/src/json-cli/test/op.contains.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.copy.tests.json.ts b/src/json-cli/test/op.copy.tests.json.ts index b1633f2852..5b7349784c 100644 --- a/src/json-cli/test/op.copy.tests.json.ts +++ b/src/json-cli/test/op.copy.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.defined.tests.json.ts b/src/json-cli/test/op.defined.tests.json.ts index 0bb816d0cf..86f4c1e22d 100644 --- a/src/json-cli/test/op.defined.tests.json.ts +++ b/src/json-cli/test/op.defined.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.ends.tests.json.ts b/src/json-cli/test/op.ends.tests.json.ts index cbab149225..00258c0f0d 100644 --- a/src/json-cli/test/op.ends.tests.json.ts +++ b/src/json-cli/test/op.ends.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.extend.tests.json.ts b/src/json-cli/test/op.extend.tests.json.ts index b3ee0d200b..064dea56d1 100644 --- a/src/json-cli/test/op.extend.tests.json.ts +++ b/src/json-cli/test/op.extend.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.flip.tests.json.ts b/src/json-cli/test/op.flip.tests.json.ts index 9ca5574ee9..fa54907fe9 100644 --- a/src/json-cli/test/op.flip.tests.json.ts +++ b/src/json-cli/test/op.flip.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.in.tests.json.ts b/src/json-cli/test/op.in.tests.json.ts index 09a6914572..3fb4d0acee 100644 --- a/src/json-cli/test/op.in.tests.json.ts +++ b/src/json-cli/test/op.in.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.inc.tests.json.ts b/src/json-cli/test/op.inc.tests.json.ts index 5b0eb3a574..5ab5d7adaa 100644 --- a/src/json-cli/test/op.inc.tests.json.ts +++ b/src/json-cli/test/op.inc.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.less.tests.json.ts b/src/json-cli/test/op.less.tests.json.ts index b283b27f0d..560e2b0e85 100644 --- a/src/json-cli/test/op.less.tests.json.ts +++ b/src/json-cli/test/op.less.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.merge.tests.json.ts b/src/json-cli/test/op.merge.tests.json.ts index a9c51ca06e..09303388eb 100644 --- a/src/json-cli/test/op.merge.tests.json.ts +++ b/src/json-cli/test/op.merge.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.more.tests.json.ts b/src/json-cli/test/op.more.tests.json.ts index ed629364a3..0c7d29b606 100644 --- a/src/json-cli/test/op.more.tests.json.ts +++ b/src/json-cli/test/op.more.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.move.tests.json.ts b/src/json-cli/test/op.move.tests.json.ts index bac0d2fb88..43d13e447e 100644 --- a/src/json-cli/test/op.move.tests.json.ts +++ b/src/json-cli/test/op.move.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.remove.tests.json.ts b/src/json-cli/test/op.remove.tests.json.ts index 60c866347d..e29af9dac6 100644 --- a/src/json-cli/test/op.remove.tests.json.ts +++ b/src/json-cli/test/op.remove.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.replace.tests.json.ts b/src/json-cli/test/op.replace.tests.json.ts index 5c12f2cb81..d442b6563b 100644 --- a/src/json-cli/test/op.replace.tests.json.ts +++ b/src/json-cli/test/op.replace.tests.json.ts @@ -1,5 +1,5 @@ import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {TestCase} from './types'; +import type {TestCase} from './types'; const values: [string, unknown][] = [ ['"null"', null], diff --git a/src/json-cli/test/op.split.tests.json.ts b/src/json-cli/test/op.split.tests.json.ts index 9917195237..417b0f0be0 100644 --- a/src/json-cli/test/op.split.tests.json.ts +++ b/src/json-cli/test/op.split.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.starts.tests.json.ts b/src/json-cli/test/op.starts.tests.json.ts index 28c0d918ad..64eaba57b2 100644 --- a/src/json-cli/test/op.starts.tests.json.ts +++ b/src/json-cli/test/op.starts.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.str_del.tests.json.ts b/src/json-cli/test/op.str_del.tests.json.ts index 11152adcfe..a99e2724df 100644 --- a/src/json-cli/test/op.str_del.tests.json.ts +++ b/src/json-cli/test/op.str_del.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.str_ins.tests.json.ts b/src/json-cli/test/op.str_ins.tests.json.ts index 968f375d64..2e101399ce 100644 --- a/src/json-cli/test/op.str_ins.tests.json.ts +++ b/src/json-cli/test/op.str_ins.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.test.tests.json.ts b/src/json-cli/test/op.test.tests.json.ts index f40e0ac480..4cb901ccdc 100644 --- a/src/json-cli/test/op.test.tests.json.ts +++ b/src/json-cli/test/op.test.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.type.tests.json.ts b/src/json-cli/test/op.type.tests.json.ts index 04399aa769..7cbe79bc0d 100644 --- a/src/json-cli/test/op.type.tests.json.ts +++ b/src/json-cli/test/op.type.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/op.undefined.tests.json.ts b/src/json-cli/test/op.undefined.tests.json.ts index 1a92c19069..b53ee6f4ae 100644 --- a/src/json-cli/test/op.undefined.tests.json.ts +++ b/src/json-cli/test/op.undefined.tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/spec.json.ts b/src/json-cli/test/spec.json.ts index 3497ccb2a5..b625d17ed4 100644 --- a/src/json-cli/test/spec.json.ts +++ b/src/json-cli/test/spec.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { @@ -168,7 +168,7 @@ const testCases: TestCase[] = [ }, patch: [ // @ts-ignore - {op: 'add', path: '/baz', value: 'qux', op: 'remove'}, + {path: '/baz', value: 'qux', op: 'remove'}, ], error: "operation has two 'op' members", disabled: true, diff --git a/src/json-cli/test/suites.ts b/src/json-cli/test/suites.ts index 898d86f9ae..3d92a0e584 100644 --- a/src/json-cli/test/suites.ts +++ b/src/json-cli/test/suites.ts @@ -22,7 +22,7 @@ import op_starts_tests_json from './op.starts.tests.json'; import op_type_tests_json from './op.type.tests.json'; import op_undefined_tests_json from './op.undefined.tests.json'; import spec_json from './spec.json'; -import {TestSuite} from './types'; +import type {TestSuite} from './types'; export const testSuites: TestSuite[] = [ // JSON Patch diff --git a/src/json-cli/test/tests.json.ts b/src/json-cli/test/tests.json.ts index 14f407efe9..c6ff965988 100644 --- a/src/json-cli/test/tests.json.ts +++ b/src/json-cli/test/tests.json.ts @@ -1,4 +1,4 @@ -import {TestCase} from './types'; +import type {TestCase} from './types'; const testCases: TestCase[] = [ { diff --git a/src/json-cli/test/types.ts b/src/json-cli/test/types.ts index daf9bfe4a8..d2c7d9671c 100644 --- a/src/json-cli/test/types.ts +++ b/src/json-cli/test/types.ts @@ -1,4 +1,4 @@ -import {Operation} from '../../json-patch'; +import type {Operation} from '../../json-patch'; export interface TestCase { comment: string; diff --git a/src/json-crdt-extensions/ModelWithExt.ts b/src/json-crdt-extensions/ModelWithExt.ts index 1b22182dba..a44f7adb33 100644 --- a/src/json-crdt-extensions/ModelWithExt.ts +++ b/src/json-crdt-extensions/ModelWithExt.ts @@ -1,9 +1,9 @@ -import * as clock from '../json-crdt-patch/clock'; +import type * as clock from '../json-crdt-patch/clock'; import * as ext from './ext'; -import {NodeBuilder} from '../json-crdt-patch'; +import type {NodeBuilder} from '../json-crdt-patch'; import {Extensions} from '../json-crdt/extensions/Extensions'; import {Model} from '../json-crdt/model'; -import {SchemaToJsonNode} from '../json-crdt/schema/types'; +import type {SchemaToJsonNode} from '../json-crdt/schema/types'; const extensions = new Extensions(); diff --git a/src/json-crdt-extensions/cnt/index.ts b/src/json-crdt-extensions/cnt/index.ts index 7bf8845ed1..f8b77de46f 100644 --- a/src/json-crdt-extensions/cnt/index.ts +++ b/src/json-crdt-extensions/cnt/index.ts @@ -2,7 +2,7 @@ import {ExtensionId, ExtensionName} from '../constants'; import {NodeApi} from '../../json-crdt/model/api/nodes'; import {ExtNode} from '../../json-crdt/extensions/ExtNode'; import {Extension} from '../../json-crdt/extensions/Extension'; -import {NodeBuilder, nodes, s, type ObjNode} from '../../json-crdt'; +import {NodeBuilder, type nodes, s, type ObjNode} from '../../json-crdt'; import type {ExtApi} from '../../json-crdt'; const MNEMONIC = ExtensionName[ExtensionId.cnt]; diff --git a/src/json-crdt-extensions/constants.ts b/src/json-crdt-extensions/constants.ts index cc81ad74f0..b15b20115b 100644 --- a/src/json-crdt-extensions/constants.ts +++ b/src/json-crdt-extensions/constants.ts @@ -1,4 +1,4 @@ -export const enum ExtensionId { +export enum ExtensionId { mval = 0, cnt = 1, peritext = 2, diff --git a/src/json-crdt-extensions/peritext/Peritext.ts b/src/json-crdt-extensions/peritext/Peritext.ts index 7d5276f6c1..7f6f5de130 100644 --- a/src/json-crdt-extensions/peritext/Peritext.ts +++ b/src/json-crdt-extensions/peritext/Peritext.ts @@ -3,13 +3,13 @@ import {Anchor} from './rga/constants'; import {Point} from './rga/Point'; import {Range} from './rga/Range'; import {Editor} from './editor/Editor'; -import {ArrNode, StrNode} from '../../json-crdt/nodes'; +import {type ArrNode, StrNode} from '../../json-crdt/nodes'; import {Slices} from './slice/Slices'; import {LocalSlices} from './slice/LocalSlices'; import {Overlay} from './overlay/Overlay'; import {Chars} from './constants'; import {interval} from '../../json-crdt-patch/clock'; -import {Model, StrApi} from '../../json-crdt/model'; +import {Model, type StrApi} from '../../json-crdt/model'; import {CONST, updateNum} from '../../json-hash'; import {SESSION} from '../../json-crdt-patch/constants'; import {s} from '../../json-crdt-patch'; diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.deletions.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.deletions.spec.ts index 6df896d3e1..157ca62ff9 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.deletions.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.deletions.spec.ts @@ -1,7 +1,7 @@ import { setupAlphabetChunkSplitKit, setupAlphabetKit, - Kit, + type Kit, setupAlphabetWithDeletesKit, setupAlphabetWithTwoChunksKit, } from './setup'; diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.hashes.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.hashes.spec.ts index 76e78d467d..8ce3fa1544 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.hashes.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.hashes.spec.ts @@ -1,6 +1,6 @@ import {Model} from '../../../json-crdt/model'; import {Peritext} from '../Peritext'; -import {Editor} from '../editor/Editor'; +import type {Editor} from '../editor/Editor'; import {render} from './render'; const setup = (insertNumbers = (editor: Editor) => editor.insert('Hello world!'), sid?: number) => { diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-block.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-block.spec.ts index 757a874400..0cceef724d 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-block.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-block.spec.ts @@ -1,6 +1,6 @@ import {Model} from '../../../json-crdt/model'; import {Peritext} from '../Peritext'; -import {Editor} from '../editor/Editor'; +import type {Editor} from '../editor/Editor'; import {render} from './render'; const runInlineSlicesTests = ( diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-cursor-movement.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-cursor-movement.spec.ts index 9102646d25..659ba3a01b 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-cursor-movement.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-cursor-movement.spec.ts @@ -1,7 +1,7 @@ import {Anchor} from '../rga/constants'; import {render} from './render'; import { - Kit, + type Kit, setupAlphabetChunkSplitKit, setupAlphabetKit, setupAlphabetWithDeletesKit, diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-hash.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-hash.spec.ts index 9bb42a4afa..dbe0f8e9b3 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-hash.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-hash.spec.ts @@ -1,6 +1,6 @@ import {render} from './render'; import { - Kit, + type Kit, setupAlphabetChunkSplitKit, setupAlphabetKit, setupAlphabetWithDeletesKit, diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-inline.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-inline.spec.ts index 9b69426d2f..ff76a4f1b1 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.render-inline.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.render-inline.spec.ts @@ -1,6 +1,6 @@ import {render} from './render'; import { - Kit, + type Kit, setupNumbersKit, setupNumbersWithMultipleChunksAndDeletesKit, setupNumbersWithRgaSplitKit, diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.spec.ts index 34e973140d..94e58966f0 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.spec.ts @@ -1,7 +1,7 @@ import {Model} from '../../../json-crdt/model'; import {Peritext} from '../Peritext'; import {Anchor} from '../rga/constants'; -import {Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from './setup'; +import {type Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from './setup'; const run = (setup: () => Kit) => { test('can run .refresh() on empty state', () => { diff --git a/src/json-crdt-extensions/peritext/__tests__/Peritext.tree.spec.ts b/src/json-crdt-extensions/peritext/__tests__/Peritext.tree.spec.ts index 203560c4d3..0c4b90787b 100644 --- a/src/json-crdt-extensions/peritext/__tests__/Peritext.tree.spec.ts +++ b/src/json-crdt-extensions/peritext/__tests__/Peritext.tree.spec.ts @@ -1,7 +1,7 @@ import {InlineAttrContained, InlineAttrEnd, InlineAttrPassing, InlineAttrStart} from '../block/Inline'; -import {LeafBlock} from '../block/LeafBlock'; +import type {LeafBlock} from '../block/LeafBlock'; import {SliceTypes} from '../slice/constants'; -import {Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from './setup'; +import {type Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from './setup'; const run = (setup: () => Kit) => { describe('inline', () => { diff --git a/src/json-crdt-extensions/peritext/__tests__/render.ts b/src/json-crdt-extensions/peritext/__tests__/render.ts index 40fa2b980b..0d75332d79 100644 --- a/src/json-crdt-extensions/peritext/__tests__/render.ts +++ b/src/json-crdt-extensions/peritext/__tests__/render.ts @@ -1,5 +1,5 @@ -import {Block} from '../block/Block'; -import {Inline} from '../block/Inline'; +import type {Block} from '../block/Block'; +import type {Inline} from '../block/Inline'; import {LeafBlock} from '../block/LeafBlock'; import {stringify} from '../../../json-text/stringify'; diff --git a/src/json-crdt-extensions/peritext/__tests__/setup.ts b/src/json-crdt-extensions/peritext/__tests__/setup.ts index a6b76f0f70..754ebebaff 100644 --- a/src/json-crdt-extensions/peritext/__tests__/setup.ts +++ b/src/json-crdt-extensions/peritext/__tests__/setup.ts @@ -1,6 +1,6 @@ import {s} from '../../../json-crdt-patch'; -import {Model} from '../../../json-crdt/model'; -import {SchemaToJsonNode} from '../../../json-crdt/schema/types'; +import type {Model} from '../../../json-crdt/model'; +import type {SchemaToJsonNode} from '../../../json-crdt/schema/types'; import {ModelWithExt, ext} from '../../ModelWithExt'; export type Schema = ReturnType; diff --git a/src/json-crdt-extensions/peritext/block/Block.ts b/src/json-crdt-extensions/peritext/block/Block.ts index 32e9a9ce8f..38bbd09e70 100644 --- a/src/json-crdt-extensions/peritext/block/Block.ts +++ b/src/json-crdt-extensions/peritext/block/Block.ts @@ -1,7 +1,7 @@ import {printTree} from 'tree-dump/lib/printTree'; import {CONST, updateJson, updateNum} from '../../../json-hash'; import {MarkerOverlayPoint} from '../overlay/MarkerOverlayPoint'; -import {OverlayPoint} from '../overlay/OverlayPoint'; +import type {OverlayPoint} from '../overlay/OverlayPoint'; import {UndefEndIter, type UndefIterator} from '../../../util/iterator'; import {Inline} from './Inline'; import type {Path} from '@jsonjoy.com/json-pointer'; diff --git a/src/json-crdt-extensions/peritext/block/Blocks.ts b/src/json-crdt-extensions/peritext/block/Blocks.ts index df650464d4..c4a8880c38 100644 --- a/src/json-crdt-extensions/peritext/block/Blocks.ts +++ b/src/json-crdt-extensions/peritext/block/Blocks.ts @@ -1,5 +1,5 @@ import {Block} from './Block'; -import {MarkerOverlayPoint} from '../overlay/MarkerOverlayPoint'; +import type {MarkerOverlayPoint} from '../overlay/MarkerOverlayPoint'; import {commonLength} from '../util/commonLength'; import {printTree} from 'tree-dump/lib/printTree'; import {LeafBlock} from './LeafBlock'; diff --git a/src/json-crdt-extensions/peritext/block/Inline.ts b/src/json-crdt-extensions/peritext/block/Inline.ts index 91284ae20e..8f6c48c78a 100644 --- a/src/json-crdt-extensions/peritext/block/Inline.ts +++ b/src/json-crdt-extensions/peritext/block/Inline.ts @@ -1,5 +1,5 @@ import {printTree} from 'tree-dump/lib/printTree'; -import {OverlayPoint} from '../overlay/OverlayPoint'; +import type {OverlayPoint} from '../overlay/OverlayPoint'; import {stringify} from '../../../json-text/stringify'; import {SliceBehavior, SliceTypes} from '../slice/constants'; import {Range} from '../rga/Range'; diff --git a/src/json-crdt-extensions/peritext/block/__tests__/Blocks.refresh.spec.ts b/src/json-crdt-extensions/peritext/block/__tests__/Blocks.refresh.spec.ts index 63a357bc00..e6f3811fac 100644 --- a/src/json-crdt-extensions/peritext/block/__tests__/Blocks.refresh.spec.ts +++ b/src/json-crdt-extensions/peritext/block/__tests__/Blocks.refresh.spec.ts @@ -1,5 +1,5 @@ import { - Kit, + type Kit, setupAlphabetChunkSplitKit, setupAlphabetKit, setupAlphabetWithDeletesKit, diff --git a/src/json-crdt-extensions/peritext/block/__tests__/Inline-cursor.spec.ts b/src/json-crdt-extensions/peritext/block/__tests__/Inline-cursor.spec.ts index e3584001b7..f83a15d3e2 100644 --- a/src/json-crdt-extensions/peritext/block/__tests__/Inline-cursor.spec.ts +++ b/src/json-crdt-extensions/peritext/block/__tests__/Inline-cursor.spec.ts @@ -1,4 +1,4 @@ -import {Kit, setupKit, setupNumbersKit, setupNumbersWithTombstonesKit} from '../../__tests__/setup'; +import {type Kit, setupKit, setupNumbersKit, setupNumbersWithTombstonesKit} from '../../__tests__/setup'; import {Cursor} from '../../editor/Cursor'; import {CursorAnchor} from '../../slice/constants'; import {Inline} from '../Inline'; diff --git a/src/json-crdt-extensions/peritext/block/__tests__/Inline.key.spec.ts b/src/json-crdt-extensions/peritext/block/__tests__/Inline.key.spec.ts index 94248c0af8..5d1f632997 100644 --- a/src/json-crdt-extensions/peritext/block/__tests__/Inline.key.spec.ts +++ b/src/json-crdt-extensions/peritext/block/__tests__/Inline.key.spec.ts @@ -2,7 +2,7 @@ import {Timestamp} from '../../../../json-crdt-patch'; import {updateId} from '../../../../json-crdt/hash'; import {updateNum} from '../../../../json-hash'; import { - Kit, + type Kit, setupKit, setupNumbersKit, setupNumbersWithMultipleChunksAndDeletesKit, diff --git a/src/json-crdt-extensions/peritext/block/__tests__/Inline.spec.ts b/src/json-crdt-extensions/peritext/block/__tests__/Inline.spec.ts index 63864bc794..c4284ecb30 100644 --- a/src/json-crdt-extensions/peritext/block/__tests__/Inline.spec.ts +++ b/src/json-crdt-extensions/peritext/block/__tests__/Inline.spec.ts @@ -1,4 +1,4 @@ -import {Kit, setupKit, setupNumbersKit, setupNumbersWithTombstonesKit} from '../../__tests__/setup'; +import {type Kit, setupKit, setupNumbersKit, setupNumbersWithTombstonesKit} from '../../__tests__/setup'; import {Cursor} from '../../editor/Cursor'; import {SliceTypes} from '../../slice/constants'; import { diff --git a/src/json-crdt-extensions/peritext/constants.ts b/src/json-crdt-extensions/peritext/constants.ts index ae9b3ba98d..d23d8d1123 100644 --- a/src/json-crdt-extensions/peritext/constants.ts +++ b/src/json-crdt-extensions/peritext/constants.ts @@ -1,12 +1,12 @@ -import {nodes, s} from '../../json-crdt-patch'; +import {type nodes, s} from '../../json-crdt-patch'; import {ExtensionId, ExtensionName} from '../constants'; import type {SliceSchema} from './slice/types'; -export const enum Chars { +export enum Chars { BlockSplitSentinel = '\n', } -export const enum Position { +export enum Position { /** * Specifies the absolute start of the text, i.e. the position before the * first character. In model space it is defined as string ID and "after" @@ -30,7 +30,6 @@ export const SCHEMA = (text: string) => * The text of the node. All rich-text textual data is stored in this node. */ str: nodes.str, - /** * The slices of the node. All rich-text annotations are stored in this * node. diff --git a/src/json-crdt-extensions/peritext/editor/Cursor.ts b/src/json-crdt-extensions/peritext/editor/Cursor.ts index 5f12077642..b0e8455fda 100644 --- a/src/json-crdt-extensions/peritext/editor/Cursor.ts +++ b/src/json-crdt-extensions/peritext/editor/Cursor.ts @@ -1,5 +1,5 @@ import {printTs, tick} from '../../../json-crdt-patch'; -import {Point} from '../rga/Point'; +import type {Point} from '../rga/Point'; import {CursorAnchor} from '../slice/constants'; import {PersistedSlice} from '../slice/PersistedSlice'; diff --git a/src/json-crdt-extensions/peritext/editor/Editor.ts b/src/json-crdt-extensions/peritext/editor/Editor.ts index 99f939a83c..8f86629f01 100644 --- a/src/json-crdt-extensions/peritext/editor/Editor.ts +++ b/src/json-crdt-extensions/peritext/editor/Editor.ts @@ -2,7 +2,7 @@ import {Cursor} from './Cursor'; import {CursorAnchor, SliceBehavior} from '../slice/constants'; import {EditorSlices} from './EditorSlices'; import {next, prev} from 'sonic-forest/lib/util'; -import {ChunkSlice} from '../util/ChunkSlice'; +import type {ChunkSlice} from '../util/ChunkSlice'; import {isLetter, isPunctuation, isWhitespace} from './util'; import {Anchor} from '../rga/constants'; import {MarkerOverlayPoint} from '../overlay/MarkerOverlayPoint'; @@ -362,7 +362,7 @@ export class Editor { * @param endpoint 0 for "focus", 1 for "anchor", 2 for both. * @param collapse Whether to collapse the range to a single point. */ - public move(steps: number = 1, unit: TextRangeUnit, endpoint: 0 | 1 | 2 = 0, collapse: boolean = true): void { + public move(steps: number, unit: TextRangeUnit, endpoint: 0 | 1 | 2 = 0, collapse: boolean = true): void { this.cursors((cursor) => { switch (endpoint) { case 0: { diff --git a/src/json-crdt-extensions/peritext/editor/__tests__/Editor-iterators.spec.ts b/src/json-crdt-extensions/peritext/editor/__tests__/Editor-iterators.spec.ts index 99b48d70c2..933edb9dae 100644 --- a/src/json-crdt-extensions/peritext/editor/__tests__/Editor-iterators.spec.ts +++ b/src/json-crdt-extensions/peritext/editor/__tests__/Editor-iterators.spec.ts @@ -1,6 +1,6 @@ import {Model} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; -import {Editor} from '../Editor'; +import type {Editor} from '../Editor'; const setup = ( insertText = (editor: Editor) => { @@ -33,6 +33,7 @@ describe('.fwd()', () => { const {peritext, editor} = setup(); const iterator = editor.fwd(peritext.pointAbsStart()); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -46,6 +47,7 @@ describe('.fwd()', () => { const start = peritext.pointStart()!; const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -59,6 +61,7 @@ describe('.fwd()', () => { const start = peritext.pointAbsStart()!; const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -72,6 +75,7 @@ describe('.fwd()', () => { const start = peritext.pointStart()!; const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -85,6 +89,7 @@ describe('.fwd()', () => { const start = peritext.pointAt(2); const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -98,6 +103,7 @@ describe('.fwd()', () => { const start = peritext.pointAt(2); const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -111,6 +117,7 @@ describe('.fwd()', () => { const start = peritext.pointAt(6); const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -124,6 +131,7 @@ describe('.fwd()', () => { const start = peritext.pointAt(6); const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -143,6 +151,7 @@ describe('.fwd()', () => { const iterator = editor.fwd(start); let str = ''; const bools: boolean[] = []; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -159,6 +168,7 @@ describe('.bwd()', () => { const {peritext, editor} = setup(); const iterator = editor.bwd(peritext.pointAbsEnd()); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -172,6 +182,7 @@ describe('.bwd()', () => { const end = peritext.pointEnd()!; const iterator = editor.bwd(end); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -185,6 +196,7 @@ describe('.bwd()', () => { const end = peritext.pointAbsEnd()!; const iterator = editor.bwd(end); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -198,6 +210,7 @@ describe('.bwd()', () => { const end = peritext.pointEnd()!; const iterator = editor.bwd(end); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -211,6 +224,7 @@ describe('.bwd()', () => { const point = peritext.pointAt(2); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -224,6 +238,7 @@ describe('.bwd()', () => { const point = peritext.pointAt(2); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -237,6 +252,7 @@ describe('.bwd()', () => { const point = peritext.pointAt(6); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -250,6 +266,7 @@ describe('.bwd()', () => { const point = peritext.pointAt(6); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -269,6 +286,7 @@ describe('.bwd()', () => { const iterator = editor.bwd(start); let str = ''; const bools: boolean[] = []; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; diff --git a/src/json-crdt-extensions/peritext/editor/__tests__/Editor-movement.spec.ts b/src/json-crdt-extensions/peritext/editor/__tests__/Editor-movement.spec.ts index f32773e1bd..36e0bbf2cc 100644 --- a/src/json-crdt-extensions/peritext/editor/__tests__/Editor-movement.spec.ts +++ b/src/json-crdt-extensions/peritext/editor/__tests__/Editor-movement.spec.ts @@ -1,11 +1,16 @@ import {Model} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; -import {Kit, runAlphabetKitTestSuite, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from '../../__tests__/setup'; +import { + type Kit, + runAlphabetKitTestSuite, + setupHelloWorldKit, + setupHelloWorldWithFewEditsKit, +} from '../../__tests__/setup'; import {Point} from '../../rga/Point'; import {Anchor} from '../../rga/constants'; import {CursorAnchor} from '../../slice/constants'; -import {Editor} from '../Editor'; -import {TextRangeUnit} from '../types'; +import type {Editor} from '../Editor'; +import type {TextRangeUnit} from '../types'; const runTestsWithAlphabetKit = (setup: () => Kit) => { describe('one character movements', () => { @@ -71,6 +76,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const {peritext, editor} = setup(); const iterator = editor.fwd(peritext.pointAbsStart()); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -84,6 +90,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const start = peritext.pointStart()!; const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -97,6 +104,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const start = peritext.pointAbsStart()!; const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -110,6 +118,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const start = peritext.pointStart()!; const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -123,6 +132,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const start = peritext.pointAt(2); const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -136,6 +146,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const start = peritext.pointAt(6); const iterator = editor.fwd(start); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -153,6 +164,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const iterator = editor.fwd(start); let str = ''; const bools: boolean[] = []; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -173,6 +185,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const {peritext, editor} = setup(); const iterator = editor.bwd(peritext.pointAbsEnd()); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -186,6 +199,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const end = peritext.pointEnd()!; const iterator = editor.bwd(end); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -199,6 +213,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const end = peritext.pointAbsEnd()!; const iterator = editor.bwd(end); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -212,6 +227,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const end = peritext.pointEnd()!; const iterator = editor.bwd(end); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -225,6 +241,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const point = peritext.pointAt(2); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -238,6 +255,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const point = peritext.pointAt(2); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -251,6 +269,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const point = peritext.pointAt(6); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -264,6 +283,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const point = peritext.pointAt(6); const iterator = editor.bwd(point); let str = ''; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -281,6 +301,7 @@ const runTestsWithAlphabetKit = (setup: () => Kit) => { const iterator = editor.bwd(start); let str = ''; const bools: boolean[] = []; + // biome-ignore lint: constant condition is expected while (1) { const res = iterator(); if (!res) break; @@ -676,6 +697,7 @@ const runParagraphTests = (setup: () => Kit) => { for (const u of Object.keys(units)) { const unit = u as TextRangeUnit; let point = peritext.pointAbsStart(); + // biome-ignore lint: constant condition is expected while (1) { point = editor.skip(point, 1, unit); if (!point || point.isRelEnd() || point.isAbsEnd()) break; @@ -702,6 +724,7 @@ const runParagraphTests = (setup: () => Kit) => { for (const u of Object.keys(units)) { const unit = u as TextRangeUnit; let point = peritext.pointAbsEnd(); + // biome-ignore lint: constant condition is expected while (1) { point = editor.skip(point, -1, unit); if (!point || point.isRelStart() || point.isAbsStart()) break; diff --git a/src/json-crdt-extensions/peritext/editor/__tests__/Editor-selection.spec.ts b/src/json-crdt-extensions/peritext/editor/__tests__/Editor-selection.spec.ts index adb2b3cd93..d7d086a7ad 100644 --- a/src/json-crdt-extensions/peritext/editor/__tests__/Editor-selection.spec.ts +++ b/src/json-crdt-extensions/peritext/editor/__tests__/Editor-selection.spec.ts @@ -2,7 +2,7 @@ import {Model} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; import {Anchor} from '../../rga/constants'; import {CursorAnchor} from '../../slice/constants'; -import {Editor} from '../Editor'; +import type {Editor} from '../Editor'; const setup = (insert = (editor: Editor) => editor.insert('Hello world!'), sid?: number) => { const model = Model.create(void 0, sid); diff --git a/src/json-crdt-extensions/peritext/editor/util.ts b/src/json-crdt-extensions/peritext/editor/util.ts index 8010ba888f..0a1c668c00 100644 --- a/src/json-crdt-extensions/peritext/editor/util.ts +++ b/src/json-crdt-extensions/peritext/editor/util.ts @@ -1,4 +1,4 @@ -import {CharPredicate} from './types'; +import type {CharPredicate} from './types'; const LETTER_REGEX = /(\p{Letter}|\d)/u; const WHITESPACE_REGEX = /\s/; diff --git a/src/json-crdt-extensions/peritext/overlay/Overlay.ts b/src/json-crdt-extensions/peritext/overlay/Overlay.ts index 50f3fc26c0..82476ecb6f 100644 --- a/src/json-crdt-extensions/peritext/overlay/Overlay.ts +++ b/src/json-crdt-extensions/peritext/overlay/Overlay.ts @@ -4,15 +4,15 @@ import {first, insertLeft, insertRight, last, next, prev, remove} from 'sonic-fo import {first2, insert2, next2, remove2} from 'sonic-forest/lib/util2'; import {splay} from 'sonic-forest/lib/splay/util'; import {Anchor} from '../rga/constants'; -import {Point} from '../rga/Point'; +import type {Point} from '../rga/Point'; import {OverlayPoint} from './OverlayPoint'; import {MarkerOverlayPoint} from './MarkerOverlayPoint'; import {OverlayRefSliceEnd, OverlayRefSliceStart} from './refs'; -import {compare, ITimestampStruct} from '../../../json-crdt-patch/clock'; +import {compare, type ITimestampStruct} from '../../../json-crdt-patch/clock'; import {CONST, updateNum} from '../../../json-hash'; import {MarkerSlice} from '../slice/MarkerSlice'; -import {Range} from '../rga/Range'; -import {UndefEndIter, UndefIterator} from '../../../util/iterator'; +import type {Range} from '../rga/Range'; +import {UndefEndIter, type UndefIterator} from '../../../util/iterator'; import type {Chunk} from '../../../json-crdt/nodes/rga'; import type {Peritext} from '../Peritext'; import type {Stateful} from '../types'; @@ -348,6 +348,7 @@ export class Overlay implements Printable, Stateful { const sliceSet = this.slices; state = updateNum(state, slices.hash); if (changed) { + // biome-ignore lint: slices is not iterable slices.forEach((slice) => { let tuple: [start: OverlayPoint, end: OverlayPoint] | undefined = sliceSet.get(slice); if (tuple) { diff --git a/src/json-crdt-extensions/peritext/overlay/OverlayPoint.ts b/src/json-crdt-extensions/peritext/overlay/OverlayPoint.ts index d4fe5cc9c1..b796109a6e 100644 --- a/src/json-crdt-extensions/peritext/overlay/OverlayPoint.ts +++ b/src/json-crdt-extensions/peritext/overlay/OverlayPoint.ts @@ -1,6 +1,6 @@ import {Point} from '../rga/Point'; import {compare} from '../../../json-crdt-patch/clock'; -import {OverlayRef, OverlayRefSliceEnd, OverlayRefSliceStart} from './refs'; +import {type OverlayRef, OverlayRefSliceEnd, OverlayRefSliceStart} from './refs'; import {printTree} from 'tree-dump/lib/printTree'; import type {MarkerSlice} from '../slice/MarkerSlice'; import type {HeadlessNode} from 'sonic-forest/lib/types'; diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.chunkSlices0.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.chunkSlices0.spec.ts index c1b498d474..7c1638bb44 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.chunkSlices0.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.chunkSlices0.spec.ts @@ -1,7 +1,7 @@ import {tick} from '../../../../json-crdt-patch/clock'; import {Model} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; -import {Point} from '../../rga/Point'; +import type {Point} from '../../rga/Point'; import {Anchor} from '../../rga/constants'; import {setupNumbersWithTombstonesKit} from '../../__tests__/setup'; import type {Chunk} from '../../../../json-crdt/nodes/rga'; diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.findX.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.findX.spec.ts index 8dd0c8fd3e..5b47576632 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.findX.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.findX.spec.ts @@ -1,4 +1,4 @@ -import {Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from '../../__tests__/setup'; +import {type Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from '../../__tests__/setup'; import {Cursor} from '../../editor/Cursor'; import {OverlayRefSliceEnd} from '../refs'; diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts index 3b6abc3890..f02b08baa3 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.markers.spec.ts @@ -1,5 +1,5 @@ import { - Kit, + type Kit, setupNumbersKit, setupNumbersWithMultipleChunksAndDeletesKit, setupNumbersWithRgaSplitKit, @@ -40,7 +40,7 @@ const runMarkersTests = (setup: () => Kit) => { peritext.overlay.refresh(); const list = [...peritext.overlay.markers()]; expect(list.length).toBe(3); - list.forEach((m) => expect(m instanceof MarkerOverlayPoint).toBe(true)); + for (const m of list) expect(m instanceof MarkerOverlayPoint).toBe(true); expect(list[0].marker).toBe(m1); expect(list[1].marker).toBe(m2); expect(list[2].marker).toBe(m3); diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.pairs.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.pairs.spec.ts index b5abb42d62..0b1c51aaf3 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.pairs.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.pairs.spec.ts @@ -1,6 +1,6 @@ import {next} from 'sonic-forest/lib/util'; import { - Kit, + type Kit, setupNumbersKit, setupNumbersWithMultipleChunksAndDeletesKit, setupNumbersWithRgaSplitKit, diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.refresh.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.refresh.spec.ts index d50df0727f..fd64689ee6 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.refresh.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.refresh.spec.ts @@ -1,4 +1,4 @@ -import {Model, ObjApi} from '../../../../json-crdt/model'; +import {Model, type ObjApi} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; import {setupNumbersWithTombstonesKit} from '../../__tests__/setup'; import {Anchor} from '../../rga/constants'; diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts index bff6fdbd79..6455c6141e 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.spec.ts @@ -117,7 +117,7 @@ describe('markers', () => { peritext.refresh(); expect(markerCount(peritext)).toBe(2); const points = []; - let point; + let point: any; for (const iterator = peritext.overlay.markers0(void 0); (point = iterator()); ) points.push(point); expect(points.length).toBe(2); expect(points[0].pos()).toBe(2); diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.tuples.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.tuples.spec.ts index 1ff8652f2e..3135230252 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.tuples.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/Overlay.tuples.spec.ts @@ -1,5 +1,5 @@ import {next} from 'sonic-forest/lib/util'; -import {Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from '../../__tests__/setup'; +import {type Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit} from '../../__tests__/setup'; import {Anchor} from '../../rga/constants'; import {MarkerOverlayPoint} from '../MarkerOverlayPoint'; import {OverlayPoint} from '../OverlayPoint'; diff --git a/src/json-crdt-extensions/peritext/overlay/__tests__/OverlayPoint.spec.ts b/src/json-crdt-extensions/peritext/overlay/__tests__/OverlayPoint.spec.ts index fbeec727e6..012beba946 100644 --- a/src/json-crdt-extensions/peritext/overlay/__tests__/OverlayPoint.spec.ts +++ b/src/json-crdt-extensions/peritext/overlay/__tests__/OverlayPoint.spec.ts @@ -1,7 +1,7 @@ -import {Point} from '../../rga/Point'; +import type {Point} from '../../rga/Point'; import {setup} from '../../slice/__tests__/setup'; import {OverlayPoint} from '../OverlayPoint'; -import {OverlayRefSliceEnd, OverlayRefSliceStart} from '../refs'; +import type {OverlayRefSliceEnd, OverlayRefSliceStart} from '../refs'; const setupOverlayPoint = () => { const deps = setup(); diff --git a/src/json-crdt-extensions/peritext/rga/Point.ts b/src/json-crdt-extensions/peritext/rga/Point.ts index 23a82aa161..77120630c4 100644 --- a/src/json-crdt-extensions/peritext/rga/Point.ts +++ b/src/json-crdt-extensions/peritext/rga/Point.ts @@ -374,7 +374,8 @@ export class Point implements Pick, Printable { return; } } - return this.refAbsEnd(); + this.refAbsEnd(); + return; } if (!chunk.del && this.anchor === Anchor.Before) return; this.anchor = Anchor.Before; @@ -402,7 +403,8 @@ export class Point implements Pick, Printable { } } } - return this.refAbsStart(); + this.refAbsStart(); + return; } if (!chunk.del && this.anchor === Anchor.After) return; this.anchor = Anchor.After; diff --git a/src/json-crdt-extensions/peritext/rga/__tests__/Point.spec.ts b/src/json-crdt-extensions/peritext/rga/__tests__/Point.spec.ts index 7846e0777b..1f4a59ef61 100644 --- a/src/json-crdt-extensions/peritext/rga/__tests__/Point.spec.ts +++ b/src/json-crdt-extensions/peritext/rga/__tests__/Point.spec.ts @@ -2,7 +2,7 @@ import {Model} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; import {Anchor} from '../constants'; import {tick} from '../../../../json-crdt-patch/clock'; -import {Point} from '../Point'; +import type {Point} from '../Point'; const setup = () => { const model = Model.withLogicalClock(); diff --git a/src/json-crdt-extensions/peritext/rga/__tests__/Range.text.spec.ts b/src/json-crdt-extensions/peritext/rga/__tests__/Range.text.spec.ts index 484f808b02..2d0aeb7f49 100644 --- a/src/json-crdt-extensions/peritext/rga/__tests__/Range.text.spec.ts +++ b/src/json-crdt-extensions/peritext/rga/__tests__/Range.text.spec.ts @@ -1,5 +1,5 @@ import { - Kit, + type Kit, setupHelloWorldKit, setupHelloWorldWithFewEditsKit, setupNumbersKit, diff --git a/src/json-crdt-extensions/peritext/rga/constants.ts b/src/json-crdt-extensions/peritext/rga/constants.ts index 2b03ccef96..0bcdcdc255 100644 --- a/src/json-crdt-extensions/peritext/rga/constants.ts +++ b/src/json-crdt-extensions/peritext/rga/constants.ts @@ -1,4 +1,4 @@ -export const enum Anchor { +export enum Anchor { Before = 0, After = 1, } diff --git a/src/json-crdt-extensions/peritext/slice/PersistedSlice.ts b/src/json-crdt-extensions/peritext/slice/PersistedSlice.ts index 509990a91f..0548e24705 100644 --- a/src/json-crdt-extensions/peritext/slice/PersistedSlice.ts +++ b/src/json-crdt-extensions/peritext/slice/PersistedSlice.ts @@ -1,13 +1,13 @@ -import {hasOwnProperty} from '@jsonjoy.com/util/lib/hasOwnProperty'; +import {hasOwnProperty as hasOwnProp} from '@jsonjoy.com/util/lib/hasOwnProperty'; import {Point} from '../rga/Point'; import {Range} from '../rga/Range'; import {updateNode} from '../../../json-crdt/hash'; import {printTree} from 'tree-dump/lib/printTree'; -import {Anchor} from '../rga/constants'; +import type {Anchor} from '../rga/constants'; import {SliceHeaderMask, SliceHeaderShift, SliceBehavior, SliceTupleIndex, SliceBehaviorName} from './constants'; import {CONST} from '../../../json-hash'; import {Timestamp} from '../../../json-crdt-patch/clock'; -import {VecNode} from '../../../json-crdt/nodes'; +import type {VecNode} from '../../../json-crdt/nodes'; import {prettyOneLine} from '../../../json-pretty'; import {validateType} from './util'; import {s} from '../../../json-crdt-patch'; @@ -118,7 +118,7 @@ export class PersistedSlice extends Range implements MutableSlice this.type = params.type; changes.push([SliceTupleIndex.Type, s.con(this.type)]); } - if (hasOwnProperty(params, 'data')) changes.push([SliceTupleIndex.Data, params.data]); + if (hasOwnProp(params, 'data')) changes.push([SliceTupleIndex.Data, params.data]); if (updateHeader) { const header = (this.behavior << SliceHeaderShift.Behavior) + diff --git a/src/json-crdt-extensions/peritext/slice/Slices.ts b/src/json-crdt-extensions/peritext/slice/Slices.ts index 5f760d0841..9a94169987 100644 --- a/src/json-crdt-extensions/peritext/slice/Slices.ts +++ b/src/json-crdt-extensions/peritext/slice/Slices.ts @@ -2,7 +2,7 @@ import {AvlMap} from 'sonic-forest/lib/avl/AvlMap'; import {printTree} from 'tree-dump/lib/printTree'; import {PersistedSlice} from './PersistedSlice'; import {Timespan, compare, tss} from '../../../json-crdt-patch/clock'; -import {Range} from '../rga/Range'; +import type {Range} from '../rga/Range'; import {updateRga} from '../../../json-crdt/hash'; import {CONST, updateNum} from '../../../json-hash'; import {SliceBehavior, SliceHeaderShift, SliceTupleIndex} from './constants'; @@ -35,7 +35,9 @@ export class Slices implements Stateful, Printable { public ins< S extends PersistedSlice, - K extends new (...args: ConstructorParameters>) => S, + K extends new ( + ...args: ConstructorParameters> + ) => S, >( range: Range, behavior: SliceBehavior, @@ -170,6 +172,7 @@ export class Slices implements Stateful, Printable { } public forEach(callback: (item: Slice) => void): void { + // biome-ignore lint: list is not iterable this.list.forEach((node) => callback(node.v)); } @@ -193,6 +196,7 @@ export class Slices implements Stateful, Printable { } } let hash: number = topologyHash; + // biome-ignore lint: slices is not iterable this.list.forEach(({v: item}) => { item.refresh(); hash = updateNum(hash, item.hash); diff --git a/src/json-crdt-extensions/peritext/slice/__tests__/Slices.spec.ts b/src/json-crdt-extensions/peritext/slice/__tests__/Slices.spec.ts index 5e721e4c7e..96cd84e769 100644 --- a/src/json-crdt-extensions/peritext/slice/__tests__/Slices.spec.ts +++ b/src/json-crdt-extensions/peritext/slice/__tests__/Slices.spec.ts @@ -1,8 +1,8 @@ import {Model} from '../../../../json-crdt/model'; import {Peritext} from '../../Peritext'; -import {Range} from '../../rga/Range'; +import type {Range} from '../../rga/Range'; import {Anchor} from '../../rga/constants'; -import {PersistedSlice} from '../PersistedSlice'; +import type {PersistedSlice} from '../PersistedSlice'; import {SliceBehavior} from '../constants'; import {setup} from './setup'; diff --git a/src/json-crdt-extensions/peritext/slice/constants.ts b/src/json-crdt-extensions/peritext/slice/constants.ts index b567131bbc..66c84f4258 100644 --- a/src/json-crdt-extensions/peritext/slice/constants.ts +++ b/src/json-crdt-extensions/peritext/slice/constants.ts @@ -4,7 +4,7 @@ * end is free to move, the moving end of the cursor is "focus". By default * "anchor" is usually the start of the cursor. */ -export const enum CursorAnchor { +export enum CursorAnchor { Start = 0, End = 1, } @@ -12,24 +12,24 @@ export const enum CursorAnchor { /** * Built-in slice types. */ -export const enum SliceTypes { +export enum SliceTypes { Cursor = -1, Paragraph = 0, } -export const enum SliceHeaderMask { +export enum SliceHeaderMask { X1Anchor = 0b1, X2Anchor = 0b10, Behavior = 0b11100, } -export const enum SliceHeaderShift { +export enum SliceHeaderShift { X1Anchor = 0, X2Anchor = 1, Behavior = 2, } -export const enum SliceBehavior { +export enum SliceBehavior { /** * A Split slice, which is used to mark a block split position in the document. * For example, paragraph, heading, blockquote, etc. @@ -74,7 +74,7 @@ export enum SliceBehaviorName { /** * Specifies `vec` offsets in the {@link SliceView}. */ -export const enum SliceTupleIndex { +export enum SliceTupleIndex { Header = 0, X1 = 1, X2 = 2, diff --git a/src/json-crdt-extensions/peritext/slice/types.ts b/src/json-crdt-extensions/peritext/slice/types.ts index d40dc2c45f..abfd97f236 100644 --- a/src/json-crdt-extensions/peritext/slice/types.ts +++ b/src/json-crdt-extensions/peritext/slice/types.ts @@ -48,24 +48,20 @@ export type SliceSchema = nodes.vec< * as anchor {@link Anchor} points of the x1 and x2 points. */ header: nodes.con, - /** * ID of the start {@link Point} of the slice. */ x1: nodes.con, - /** * ID of the end {@link Point} of the slice, if 0 then it is equal to x1. */ x2: nodes.con, - /** * App specific type of the slice. For slices with "split" behavior, this * is a path of block nesting. For other slices, it specifies inline formatting, such * as bold, italic, etc.; the value has to be a primitive number or a string. */ type: nodes.con, - /** * Reference to additional metadata about the slice, usually an object. If * data is not set, it will default to `1`. For "erase" slice behavior, data @@ -74,7 +70,8 @@ export type SliceSchema = nodes.vec< * In reality this `vec` term can be of any type, it can even be missing * entirely. It is typed here as a placeholder for the actual data type. */ - data: nodes.obj<{}>, + data: nodes.obj, ] >; diff --git a/src/json-crdt-extensions/peritext/util/ChunkSlice.ts b/src/json-crdt-extensions/peritext/util/ChunkSlice.ts index 4a4a8566fa..211c3a8fca 100644 --- a/src/json-crdt-extensions/peritext/util/ChunkSlice.ts +++ b/src/json-crdt-extensions/peritext/util/ChunkSlice.ts @@ -1,6 +1,6 @@ import {CONST, updateNum} from '../../../json-hash'; import {updateId} from '../../../json-crdt/hash'; -import {ITimestampStruct, Timestamp, printTs} from '../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp, printTs} from '../../../json-crdt-patch/clock'; import type {IChunkSlice} from './types'; import type {Stateful} from '../types'; import type {Printable} from 'tree-dump/lib/types'; diff --git a/src/json-crdt-extensions/quill-delta/QuillDeltaApi.ts b/src/json-crdt-extensions/quill-delta/QuillDeltaApi.ts index 7255a30995..07a142f14a 100644 --- a/src/json-crdt-extensions/quill-delta/QuillDeltaApi.ts +++ b/src/json-crdt-extensions/quill-delta/QuillDeltaApi.ts @@ -1,6 +1,6 @@ import {QuillConst} from './constants'; -import {PathStep} from '@jsonjoy.com/json-pointer'; -import {QuillDeltaNode} from './QuillDeltaNode'; +import type {PathStep} from '@jsonjoy.com/json-pointer'; +import type {QuillDeltaNode} from './QuillDeltaNode'; import {NodeApi} from '../../json-crdt/model/api/nodes'; import {konst} from '../../json-crdt-patch/builder/Konst'; import {SliceBehavior} from '../peritext/slice/constants'; @@ -43,6 +43,7 @@ const rewriteAttributes = (txt: Peritext, attributes: QuillDeltaAttributes | und const relevantOverlappingButNotContained = new Set(); if (length) { const savedSlices = txt.savedSlices; + // biome-ignore lint: slices is not iterable slices.forEach((slice) => { if (slice instanceof PersistedSlice) { const isContained = range.contains(slice); diff --git a/src/json-crdt-extensions/quill-delta/QuillDeltaNode.ts b/src/json-crdt-extensions/quill-delta/QuillDeltaNode.ts index 9d1164250e..1f980fdcb2 100644 --- a/src/json-crdt-extensions/quill-delta/QuillDeltaNode.ts +++ b/src/json-crdt-extensions/quill-delta/QuillDeltaNode.ts @@ -1,7 +1,7 @@ import {isEmpty} from '@jsonjoy.com/util/lib/isEmpty'; import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; -import {StrNode} from '../../json-crdt/nodes/str/StrNode'; -import {ArrNode} from '../../json-crdt/nodes/arr/ArrNode'; +import type {StrNode} from '../../json-crdt/nodes/str/StrNode'; +import type {ArrNode} from '../../json-crdt/nodes/arr/ArrNode'; import {Peritext} from '../peritext'; import {ExtensionId} from '../constants'; import {MNEMONIC, QuillConst} from './constants'; diff --git a/src/json-crdt-extensions/quill-delta/__tests__/QuillDelta.spec.ts b/src/json-crdt-extensions/quill-delta/__tests__/QuillDelta.spec.ts index b9ecae29c6..2140c906b6 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/QuillDelta.spec.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/QuillDelta.spec.ts @@ -2,7 +2,7 @@ import {mval} from '../../mval'; import {quill} from '..'; import {Model} from '../../../json-crdt/model'; import Delta from 'quill-delta'; -import {QuillDeltaPatch} from '../types'; +import type {QuillDeltaPatch} from '../types'; test('can construct delta with new line character', () => { const model = Model.create(); diff --git a/src/json-crdt-extensions/quill-delta/__tests__/QuillDeltaFuzzer.ts b/src/json-crdt-extensions/quill-delta/__tests__/QuillDeltaFuzzer.ts index a4141fd689..c533a8be69 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/QuillDeltaFuzzer.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/QuillDeltaFuzzer.ts @@ -2,7 +2,7 @@ import Delta from 'quill-delta'; import {randomU32} from 'hyperdyperid/lib/randomU32'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {isEmpty} from '@jsonjoy.com/util/lib/isEmpty'; -import {QuillDeltaAttributes, QuillDeltaOp, QuillDeltaOpInsert, QuillDeltaOpRetain, QuillTrace} from '../types'; +import type {QuillDeltaAttributes, QuillDeltaOp, QuillDeltaOpInsert, QuillDeltaOpRetain, QuillTrace} from '../types'; import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; import {removeErasures} from '../util'; diff --git a/src/json-crdt-extensions/quill-delta/__tests__/fuzzing.yjs.spec.ts b/src/json-crdt-extensions/quill-delta/__tests__/fuzzing.yjs.spec.ts index 83cb44abd7..4e5e6d1193 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/fuzzing.yjs.spec.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/fuzzing.yjs.spec.ts @@ -1,6 +1,6 @@ import {QuillDeltaFuzzer} from './QuillDeltaFuzzer'; import {Doc as YDoc} from 'yjs'; -import {QuillDeltaOp, QuillDeltaOpDelete} from '../types'; +import type {QuillDeltaOp, QuillDeltaOpDelete} from '../types'; import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; import {clone} from '@jsonjoy.com/util/lib/json-clone'; diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces.spec.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces.spec.ts index f74b94f579..b2597435aa 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces.spec.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces.spec.ts @@ -2,8 +2,8 @@ import Delta from 'quill-delta'; import {mval as ValueMvExt} from '../../mval'; import {quill as QuillDeltaExt} from '..'; import {Model} from '../../../json-crdt/model'; -import {QuillTrace} from '../types'; -import {QuillDeltaApi} from '../QuillDeltaApi'; +import type {QuillTrace} from '../types'; +import type {QuillDeltaApi} from '../QuillDeltaApi'; import {insertDeleteQuillTrace} from './traces/insert-delete'; import {basicAnnotationsQuillTrace} from './traces/basic-annotations'; import {boldGrowingQuillTrace} from './traces/growing-bold'; diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/annotate-annotations.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/annotate-annotations.ts index c0e2c90c3a..af42dac846 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/annotate-annotations.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/annotate-annotations.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const annotateAnnotationsQuillTrace: QuillTrace = { contents: { diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/basic-annotations.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/basic-annotations.ts index fe52bc3684..6fc96a21b0 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/basic-annotations.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/basic-annotations.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * This trace includes only simple bold and italic annotations and growing of diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/blocks.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/blocks.ts index db8f725c43..c175fbc9c6 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/blocks.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/blocks.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * Various block operations, changing block types. diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-italic-unitalic.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-italic-unitalic.ts index 4396f8e572..b84ae06fd7 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-italic-unitalic.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-italic-unitalic.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * Bolds and italics some text, then un-italics some part. diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-unbold.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-unbold.ts index d3d64d57ab..019b24f3e3 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-unbold.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/bold-unbold.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * This stack bolds a word, then unbolds it. diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-1.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-1.ts index 8ab3af55f0..325de141dd 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-1.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-1.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz1QuillTrace: QuillTrace = { contents: { diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-2.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-2.ts index fd895a2119..b8c01fad79 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-2.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-2.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz2QuillTrace: QuillTrace = { contents: { diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-3.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-3.ts index 042d778537..c4efc79659 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-3.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-3.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz3QuillTrace: QuillTrace = { contents: { diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-4.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-4.ts index c64e300b2f..4f9505bec8 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-4.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-4.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz4QuillTrace: QuillTrace = { contents: {ops: [{insert: '0'}, {insert: {link: '1111'}}, {insert: '0'}]}, diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-5.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-5.ts index ef996d64ae..408843d06a 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-5.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-5.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz5QuillTrace: QuillTrace = { contents: {ops: [{insert: {link: 'A'}}]}, diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-6.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-6.ts index 7bdbafc723..89cb5f4ac3 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-6.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-6.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz6QuillTrace: QuillTrace = { contents: {ops: [{attributes: {italic: true}, insert: 'AA'}, {insert: 'ABBBB'}, {insert: {link: 'C'}}]}, diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-7.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-7.ts index 2ce4865976..8a66e51e25 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-7.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/fuzz-7.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; export const fuzz7QuillTrace: QuillTrace = { contents: {ops: [{insert: {link: 'B'}}, {insert: 'AABBBB'}]}, diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/general.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/general.ts index b9c5860fd1..be8fab31da 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/general.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/general.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * This trace includes almost all features of Quill Delta. diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/growing-bold.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/growing-bold.ts index 58596521f1..8218acc3a0 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/growing-bold.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/growing-bold.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * This stack trace prepends "a" to bold "b", hence "ba" is bold. diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete-image.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete-image.ts index c6afbd8504..505f8988f6 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete-image.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete-image.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * Inserts and deletes image void. diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete.ts index 928620e300..4541b51265 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/insert-delete.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * This trace includes only inserts and deletes. Including multi-character diff --git a/src/json-crdt-extensions/quill-delta/__tests__/traces/split-unsplit.ts b/src/json-crdt-extensions/quill-delta/__tests__/traces/split-unsplit.ts index 46f6c19fa9..11c51d886a 100644 --- a/src/json-crdt-extensions/quill-delta/__tests__/traces/split-unsplit.ts +++ b/src/json-crdt-extensions/quill-delta/__tests__/traces/split-unsplit.ts @@ -1,4 +1,4 @@ -import {QuillTrace} from '../../types'; +import type {QuillTrace} from '../../types'; /** * Block split and un-split. diff --git a/src/json-crdt-extensions/quill-delta/constants.ts b/src/json-crdt-extensions/quill-delta/constants.ts index 18c98c32e8..41aac40c8a 100644 --- a/src/json-crdt-extensions/quill-delta/constants.ts +++ b/src/json-crdt-extensions/quill-delta/constants.ts @@ -1,6 +1,6 @@ import {ExtensionId, ExtensionName} from '../constants'; -export const enum QuillConst { +export enum QuillConst { EmbedChar = '\n', EmbedSliceType = 0, } diff --git a/src/json-crdt-extensions/quill-delta/util.ts b/src/json-crdt-extensions/quill-delta/util.ts index 854f1f7b8d..b9f45d5a43 100644 --- a/src/json-crdt-extensions/quill-delta/util.ts +++ b/src/json-crdt-extensions/quill-delta/util.ts @@ -75,7 +75,7 @@ export const diffAttributes = ( for (let i = 0; i < oldLength; i++) { const key = oldKeys[i]; // tslint:disable-next-line:triple-equals - if (newAttributes[key] != undefined) continue; + if (newAttributes[key] !== undefined) continue; diff[key] = null; } if (isEmpty(diff)) return undefined; diff --git a/src/json-crdt-patch/Batch.ts b/src/json-crdt-patch/Batch.ts index 2fe3be9c25..cdbefe43ee 100644 --- a/src/json-crdt-patch/Batch.ts +++ b/src/json-crdt-patch/Batch.ts @@ -1,5 +1,5 @@ -import {ITimestampStruct, printTs} from './clock'; -import {Patch} from './Patch'; +import {type ITimestampStruct, printTs} from './clock'; +import type {Patch} from './Patch'; export class Batch { constructor(public patches: Patch[]) {} diff --git a/src/json-crdt-patch/Patch.ts b/src/json-crdt-patch/Patch.ts index acf189a601..179c8cb823 100644 --- a/src/json-crdt-patch/Patch.ts +++ b/src/json-crdt-patch/Patch.ts @@ -1,5 +1,5 @@ import * as operations from './operations'; -import {ITimestampStruct, ts, printTs, Timestamp} from './clock'; +import {type ITimestampStruct, ts, printTs, Timestamp} from './clock'; import {printTree} from 'tree-dump/lib/printTree'; import {encode, decode} from './codec/binary'; import type {Printable} from 'tree-dump/lib/types'; diff --git a/src/json-crdt-patch/PatchBuilder.ts b/src/json-crdt-patch/PatchBuilder.ts index c0b516054e..793cde6f7a 100644 --- a/src/json-crdt-patch/PatchBuilder.ts +++ b/src/json-crdt-patch/PatchBuilder.ts @@ -15,7 +15,7 @@ import { DelOp, NopOp, } from './operations'; -import {IClock, ITimestampStruct, ITimespanStruct, ts, Timestamp} from './clock'; +import {type IClock, type ITimestampStruct, type ITimespanStruct, ts, Timestamp} from './clock'; import {isUint8Array} from '@jsonjoy.com/util/lib/buffers/isUint8Array'; import {Patch} from './Patch'; import {ORIGIN} from './constants'; diff --git a/src/json-crdt-patch/__bench__/bench.encoding.ts b/src/json-crdt-patch/__bench__/bench.encoding.ts index 23daf72e19..72502b2b7f 100644 --- a/src/json-crdt-patch/__bench__/bench.encoding.ts +++ b/src/json-crdt-patch/__bench__/bench.encoding.ts @@ -1,10 +1,10 @@ // npx ts-node src/json-crdt-patch/__bench__/bench.encoding.ts -import {runBenchmark, IBenchmark} from '../../__bench__/runBenchmark'; +import {runBenchmark, type IBenchmark} from '../../__bench__/runBenchmark'; import json1 from '../../__tests__/fixtures/json/small-object'; import json2 from '../../__tests__/fixtures/json/simple-json-patch'; import {LogicalClock} from '../clock'; -import {Patch} from '../Patch'; +import type {Patch} from '../Patch'; import {PatchBuilder} from '../PatchBuilder'; import {encode as encodeBinary} from '../codec/binary'; import {encode as encodeCompact} from '../codec/compact-binary'; diff --git a/src/json-crdt-patch/__tests__/Patch.spec.ts b/src/json-crdt-patch/__tests__/Patch.spec.ts index 4a6c6d5952..35293d767f 100644 --- a/src/json-crdt-patch/__tests__/Patch.spec.ts +++ b/src/json-crdt-patch/__tests__/Patch.spec.ts @@ -2,7 +2,7 @@ import {Model} from '../../json-crdt/model'; import {s} from '../builder/schema'; import {LogicalClock, ts} from '../clock'; import {SESSION} from '../constants'; -import {InsArrOp} from '../operations'; +import type {InsArrOp} from '../operations'; import {PatchBuilder} from '../PatchBuilder'; describe('.rebase()', () => { diff --git a/src/json-crdt-patch/builder/schema.ts b/src/json-crdt-patch/builder/schema.ts index b916588af8..caa32a9ac5 100644 --- a/src/json-crdt-patch/builder/schema.ts +++ b/src/json-crdt-patch/builder/schema.ts @@ -135,6 +135,7 @@ export namespace nodes { */ export class obj< T extends Record, + // biome-ignore lint: TODO: improve {} type in the future O extends Record = {}, > extends NodeBuilder { public readonly type = 'obj'; diff --git a/src/json-crdt-patch/clock/clock.ts b/src/json-crdt-patch/clock/clock.ts index 998f96acca..d81e2eea17 100644 --- a/src/json-crdt-patch/clock/clock.ts +++ b/src/json-crdt-patch/clock/clock.ts @@ -1,4 +1,4 @@ -import {SESSION} from '../constants'; +import {SESSION} from '../enums'; import type {IClock, IClockVector, ITimestampStruct, ITimespanStruct} from './types'; export class Timestamp implements ITimestampStruct { @@ -196,6 +196,7 @@ export class ClockVector extends LogicalClock implements IClockVector { public fork(sessionId: number): ClockVector { const clock = new ClockVector(sessionId, this.time); if (sessionId !== this.sid) clock.observe(tick(this, -1), 1); + // biome-ignore lint: using .forEach() on Map is the fastest way to iterate this.peers.forEach((peer) => { clock.observe(peer, 1); }); @@ -212,6 +213,7 @@ export class ClockVector extends LogicalClock implements IClockVector { const last = this.peers.size; let i = 1; let lines = ''; + // biome-ignore lint: using .forEach() on Map is the fastest way to iterate this.peers.forEach((clock) => { const isLast = i === last; lines += `\n${tab}${isLast ? '└─' : '├─'} ${clock.sid}.${clock.time}`; diff --git a/src/json-crdt-patch/codec/__tests__/PatchFuzzer.ts b/src/json-crdt-patch/codec/__tests__/PatchFuzzer.ts index f0ba698ce4..4dce6902ff 100644 --- a/src/json-crdt-patch/codec/__tests__/PatchFuzzer.ts +++ b/src/json-crdt-patch/codec/__tests__/PatchFuzzer.ts @@ -1,8 +1,8 @@ import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; -import {interval, ITimestampStruct, Timespan, ClockVector, ServerClockVector, ts} from '../../clock'; +import {interval, type ITimestampStruct, Timespan, ClockVector, ServerClockVector, ts} from '../../clock'; import {SESSION} from '../../constants'; -import {Patch} from '../../Patch'; +import type {Patch} from '../../Patch'; import {PatchBuilder} from '../../PatchBuilder'; export class PatchFuzzer extends Fuzzer { diff --git a/src/json-crdt-patch/codec/__tests__/json.fuzzer.spec.ts b/src/json-crdt-patch/codec/__tests__/json.fuzzer.spec.ts index 2c486ba645..b2698946ed 100644 --- a/src/json-crdt-patch/codec/__tests__/json.fuzzer.spec.ts +++ b/src/json-crdt-patch/codec/__tests__/json.fuzzer.spec.ts @@ -6,7 +6,7 @@ import {decode as decodeCompact} from '../compact/decode'; import {encode as encodeCompactBinary} from '../compact-binary/encode'; import {decode as decodeCompactBinary} from '../compact-binary/decode'; import {encode as encodeBinary, decode as decodeBinary} from '../binary'; -import {Patch} from '../../Patch'; +import type {Patch} from '../../Patch'; const fuzzer = new PatchFuzzer(); const environments: [string, () => Patch][] = [ diff --git a/src/json-crdt-patch/codec/binary/Decoder.ts b/src/json-crdt-patch/codec/binary/Decoder.ts index ed0e00edd5..0e14895141 100644 --- a/src/json-crdt-patch/codec/binary/Decoder.ts +++ b/src/json-crdt-patch/codec/binary/Decoder.ts @@ -1,6 +1,13 @@ import {CrdtReader} from '../../util/binary/CrdtReader'; -import {interval, ITimespanStruct, ITimestampStruct, ClockVector, ServerClockVector, Timestamp} from '../../clock'; -import {Patch} from '../../Patch'; +import { + interval, + type ITimespanStruct, + type ITimestampStruct, + ClockVector, + ServerClockVector, + Timestamp, +} from '../../clock'; +import type {Patch} from '../../Patch'; import {PatchBuilder} from '../../PatchBuilder'; import {SESSION} from '../../constants'; import {CborDecoder} from '@jsonjoy.com/json-pack/lib/cbor/CborDecoder'; diff --git a/src/json-crdt-patch/codec/binary/Encoder.ts b/src/json-crdt-patch/codec/binary/Encoder.ts index f808f1b5a2..fc8c58a060 100644 --- a/src/json-crdt-patch/codec/binary/Encoder.ts +++ b/src/json-crdt-patch/codec/binary/Encoder.ts @@ -1,7 +1,7 @@ import * as operations from '../../operations'; import {JsonCrdtPatchOpcodeOverlay} from '../../constants'; import {CrdtWriter} from '../../util/binary/CrdtWriter'; -import {ITimespanStruct, ITimestampStruct, Timestamp} from '../../clock'; +import {type ITimespanStruct, type ITimestampStruct, Timestamp} from '../../clock'; import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; import type {JsonCrdtPatchOperation, Patch} from '../../Patch'; @@ -79,8 +79,8 @@ export class Encoder extends CborEncoder { protected encodeOperation(op: JsonCrdtPatchOperation): void { const writer = this.writer; - const constructor = op.constructor; - switch (constructor) { + const constr = op.constructor; + switch (constr) { case operations.NewConOp: { const operation = op; const val = operation.val; diff --git a/src/json-crdt-patch/codec/binary/shared.ts b/src/json-crdt-patch/codec/binary/shared.ts index 110427ace3..d55850d04a 100644 --- a/src/json-crdt-patch/codec/binary/shared.ts +++ b/src/json-crdt-patch/codec/binary/shared.ts @@ -1,6 +1,6 @@ import {Encoder} from './Encoder'; import {Decoder} from './Decoder'; -import {Patch} from '../../Patch'; +import type {Patch} from '../../Patch'; import {CrdtWriter} from '../../util/binary/CrdtWriter'; /** A shared instance of the {@link CrdtWriter} class. */ diff --git a/src/json-crdt-patch/codec/clock/ClockDecoder.ts b/src/json-crdt-patch/codec/clock/ClockDecoder.ts index 1686f555c4..d045ba015c 100644 --- a/src/json-crdt-patch/codec/clock/ClockDecoder.ts +++ b/src/json-crdt-patch/codec/clock/ClockDecoder.ts @@ -1,4 +1,4 @@ -import {ITimestampStruct, ClockVector, ts} from '../../clock'; +import {type ITimestampStruct, ClockVector, ts} from '../../clock'; export class ClockDecoder { /** Clock session index to logical clock. */ diff --git a/src/json-crdt-patch/codec/clock/ClockEncoder.ts b/src/json-crdt-patch/codec/clock/ClockEncoder.ts index 1391942a05..25ad3c2467 100644 --- a/src/json-crdt-patch/codec/clock/ClockEncoder.ts +++ b/src/json-crdt-patch/codec/clock/ClockEncoder.ts @@ -1,4 +1,4 @@ -import {ITimestampStruct, IClockVector, tick, Timestamp} from '../../clock'; +import {type ITimestampStruct, type IClockVector, tick, Timestamp} from '../../clock'; import {RelativeTimestamp} from './RelativeTimestamp'; class ClockTableEntry { @@ -40,6 +40,7 @@ export class ClockEncoder { public toJson(): number[] { const out: number[] = []; + // biome-ignore lint: using .forEach() on Map is the fastest way to iterate this.table.forEach((entry) => { const clock = entry.clock; out.push(clock.sid, clock.time); diff --git a/src/json-crdt-patch/codec/clock/ClockTable.ts b/src/json-crdt-patch/codec/clock/ClockTable.ts index 9d3e04d19f..3cc572ca5e 100644 --- a/src/json-crdt-patch/codec/clock/ClockTable.ts +++ b/src/json-crdt-patch/codec/clock/ClockTable.ts @@ -1,6 +1,6 @@ -import {ITimestampStruct, IClockVector, Timestamp} from '../../clock'; -import {CrdtReader} from '../../util/binary/CrdtReader'; -import {CrdtWriter} from '../../util/binary/CrdtWriter'; +import {type ITimestampStruct, type IClockVector, Timestamp} from '../../clock'; +import type {CrdtReader} from '../../util/binary/CrdtReader'; +import type {CrdtWriter} from '../../util/binary/CrdtWriter'; export class ClockTableEntry { constructor( @@ -13,6 +13,7 @@ export class ClockTable { public static from(clock: IClockVector): ClockTable { const table = new ClockTable(); table.push(new Timestamp(clock.sid, clock.time - 1)); + // biome-ignore lint: using .forEach() on Map is the fastest way to iterate clock.peers.forEach((id) => table.push(id)); return table; } @@ -30,8 +31,8 @@ export class ClockTable { public parseField(field: `${string}_${string}`): ITimestampStruct { const underscoreIndex = field.indexOf('_'); - const relativeSid = parseInt(field.slice(0, underscoreIndex), 36); - const time = parseInt(field.slice(underscoreIndex + 1), 36); + const relativeSid = Number.parseInt(field.slice(0, underscoreIndex), 36); + const time = Number.parseInt(field.slice(underscoreIndex + 1), 36); const clock = this.byIdx[relativeSid]; return new Timestamp(clock.sid, time); } diff --git a/src/json-crdt-patch/codec/compact/decode.ts b/src/json-crdt-patch/codec/compact/decode.ts index 549622a08b..172a3cd13d 100644 --- a/src/json-crdt-patch/codec/compact/decode.ts +++ b/src/json-crdt-patch/codec/compact/decode.ts @@ -1,7 +1,14 @@ import {JsonCrdtPatchOpcode} from '../../constants'; import {fromBase64} from '@jsonjoy.com/base64/lib/fromBase64'; -import {ITimespanStruct, ITimestampStruct, ClockVector, ServerClockVector, Timespan, Timestamp} from '../../clock'; -import {Patch} from '../../Patch'; +import { + type ITimespanStruct, + type ITimestampStruct, + ClockVector, + ServerClockVector, + Timespan, + Timestamp, +} from '../../clock'; +import type {Patch} from '../../Patch'; import {PatchBuilder} from '../../PatchBuilder'; import {SESSION} from '../../constants'; import type * as types from './types'; diff --git a/src/json-crdt-patch/codec/compact/encode.ts b/src/json-crdt-patch/codec/compact/encode.ts index 2e9fee7409..47a2a49612 100644 --- a/src/json-crdt-patch/codec/compact/encode.ts +++ b/src/json-crdt-patch/codec/compact/encode.ts @@ -1,6 +1,6 @@ import * as operations from '../../operations'; -import {ITimespanStruct, ITimestampStruct, Timestamp} from '../../clock'; -import {Patch} from '../../Patch'; +import {type ITimespanStruct, type ITimestampStruct, Timestamp} from '../../clock'; +import type {Patch} from '../../Patch'; import {JsonCrdtPatchOpcode, SESSION} from '../../constants'; import {toBase64} from '@jsonjoy.com/base64/lib/toBase64'; import type * as types from './types'; diff --git a/src/json-crdt-patch/codec/compact/types.ts b/src/json-crdt-patch/codec/compact/types.ts index 4d35b24ac6..6b8e5aa18f 100644 --- a/src/json-crdt-patch/codec/compact/types.ts +++ b/src/json-crdt-patch/codec/compact/types.ts @@ -1,5 +1,5 @@ import type {JsonCrdtPatchOpcode} from '../../constants'; -import {JsonCodecTimestamp} from '../verbose/types'; +import type {JsonCodecTimestamp} from '../verbose/types'; /** * Represents a JSON CRDT Patch object in *Compact encoding*. Compact encoding @@ -14,11 +14,9 @@ export type CompactCodecPatch = [ * derived from this ID. */ id: CompactCodecTimestamp, - /** Custom metadata. */ meta?: unknown, ], - /** * List of operations comprising this patch. Patches are atomic, so all * operations are applied at once. "time" part of the IDs of all operations @@ -57,7 +55,6 @@ export type CompactCodecTimestamp = | [ /** A random site ID. */ sessionId: number, - /** A logical clock sequence number. */ time: number, ] @@ -72,10 +69,8 @@ export type CompactCodecTimespan = | [ /** A random site ID. */ sessionId: number, - /** A logical clock sequence number. */ time: number, - /** * Length of the timespan, including the first timestamp identified by the * `sessionId` and `time` properties. @@ -85,7 +80,6 @@ export type CompactCodecTimespan = | [ /** Time difference relative to the Patch ID time. */ time: number, - /** * Length of the timespan, including the first timestamp identified by the * `sessionId` and `time` properties. @@ -100,13 +94,11 @@ export type CompactCodecTimespan = export type CompactCodecNewConOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.new_con, - /** * Literal JSON value, which can also contain binary data; or, a logical clock * timestamp. */ value?: unknown | undefined | CompactCodecTimestamp, - /** If true, the `value` is a timestamp. */ timestamp?: boolean, ]; @@ -118,7 +110,6 @@ export type CompactCodecNewConOperation = [ export type CompactCodecNewValOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.new_val, - /** ID of the "val" LWW-Register object latest value. */ value: CompactCodecTimestamp, ]; @@ -178,14 +169,12 @@ export type CompactCodecNewArrOperation = [ export type CompactCodecInsValOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.ins_val, - /** * Object on which to perform the operation. If omitted, or set to falsy * value, or equal to origin `[0, 0]`, the "set" operation is applied to the * root object, which is LWW Register of a pointer to another CRDT data type. */ obj: CompactCodecTimestamp, - /** * The new value of the "val" LWW-Register object. The ID of the CRDT object * to which the "val" LWW-Register will point to, if operation is successful. @@ -200,10 +189,8 @@ export type CompactCodecInsValOperation = [ export type CompactCodecInsObjOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.ins_obj, - /** Object on which to perform the operation. */ obj: CompactCodecTimestamp, - /** A map of values to apply to the "obj" LWW-Map object. */ value: Array<[key: string, value: CompactCodecTimestamp]>, ]; @@ -215,10 +202,8 @@ export type CompactCodecInsObjOperation = [ export type CompactCodecInsVecOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.ins_vec, - /** Object on which to perform the operation. */ obj: CompactCodecTimestamp, - /** A map of values to apply to the "vec" LWW-Vector object. */ value: Array<[index: number, value: CompactCodecTimestamp]>, ]; @@ -227,16 +212,13 @@ export type CompactCodecInsVecOperation = [ export type CompactCodecInsStrOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.ins_str, - /** Object on which to perform the operation. */ obj: CompactCodecTimestamp, - /** * Specifies the ID of element after which to attempt to insert the substring * using the RGA algorithm. */ after: CompactCodecTimestamp, - /** The substring to insert in the string. */ value: string, ]; @@ -245,16 +227,13 @@ export type CompactCodecInsStrOperation = [ export type CompactCodecInsBinOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.ins_bin, - /** Object on which to perform the operation. */ obj: CompactCodecTimestamp, - /** * Specifies the ID of element after which to attempt to insert the substring * using the RGA algorithm. */ after: CompactCodecTimestamp, - /** The binary data to insert, encoded using Base64. */ value: string, ]; @@ -263,16 +242,13 @@ export type CompactCodecInsBinOperation = [ export type CompactCodecInsArrOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.ins_arr, - /** Object on which to perform the operation. */ obj: CompactCodecTimestamp, - /** * Specifies the ID of element after which to attempt to insert the substring * using the RGA algorithm. */ after: CompactCodecTimestamp, - /** Values to insert in the array. */ values: JsonCodecTimestamp[], ]; @@ -285,10 +261,8 @@ export type CompactCodecInsArrOperation = [ export type CompactCodecDelOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.del, - /** Object on which to perform the operation. */ obj: CompactCodecTimestamp, - /** Range of content to delete. */ what: CompactCodecTimespan[], ]; @@ -301,7 +275,6 @@ export type CompactCodecDelOperation = [ export type CompactCodecNopOperation = [ /** Operation type. */ op: JsonCrdtPatchOpcode.nop, - /** Defaults to 1, if omitted. */ len?: number, ]; diff --git a/src/json-crdt-patch/codec/verbose/decode.ts b/src/json-crdt-patch/codec/verbose/decode.ts index 8d8d580b48..a80a4d56d9 100644 --- a/src/json-crdt-patch/codec/verbose/decode.ts +++ b/src/json-crdt-patch/codec/verbose/decode.ts @@ -1,7 +1,7 @@ import {fromBase64} from '@jsonjoy.com/base64/lib/fromBase64'; -import {ts, ClockVector, ServerClockVector, tss, ITimestampStruct} from '../../clock'; +import {ts, ClockVector, ServerClockVector, tss, type ITimestampStruct} from '../../clock'; import {SESSION} from '../../constants'; -import {Patch} from '../../Patch'; +import type {Patch} from '../../Patch'; import {PatchBuilder} from '../../PatchBuilder'; import type * as types from './types'; diff --git a/src/json-crdt-patch/codec/verbose/encode.ts b/src/json-crdt-patch/codec/verbose/encode.ts index 877b3bff09..f043fb2cf1 100644 --- a/src/json-crdt-patch/codec/verbose/encode.ts +++ b/src/json-crdt-patch/codec/verbose/encode.ts @@ -1,8 +1,8 @@ import * as operations from '../../operations'; -import {Patch} from '../../Patch'; +import type {Patch} from '../../Patch'; import {SESSION} from '../../constants'; import {toBase64} from '@jsonjoy.com/base64/lib/toBase64'; -import {ITimestampStruct, Timestamp} from '../../clock'; +import {type ITimestampStruct, Timestamp} from '../../clock'; import type * as types from './types'; const encodeTimestamp = (ts: ITimestampStruct): types.JsonCodecTimestamp => diff --git a/src/json-crdt-patch/codec/verbose/types.ts b/src/json-crdt-patch/codec/verbose/types.ts index 3554a3cb27..a8c4f05317 100644 --- a/src/json-crdt-patch/codec/verbose/types.ts +++ b/src/json-crdt-patch/codec/verbose/types.ts @@ -48,7 +48,6 @@ export type JsonCodecTimestamp = | [ /** A random site ID. */ sessionId: number, - /** A logical clock sequence number. */ time: number, ] @@ -62,10 +61,8 @@ export type JsonCodecTimestamp = export type JsonCodecTimespan = [ /** A random site ID. */ sessionId: number, - /** A logical clock sequence number. */ time: number, - /** * Length of the timespan, including the first timestamp identified by the * `sessionId` and `time` properties. diff --git a/src/json-crdt-patch/constants.ts b/src/json-crdt-patch/constants.ts index 23766c132d..4a343cbe9d 100644 --- a/src/json-crdt-patch/constants.ts +++ b/src/json-crdt-patch/constants.ts @@ -1,92 +1,10 @@ import {ts} from './clock'; +import {SESSION, SYSTEM_SESSION_TIME} from './enums'; -export const enum SESSION { - /** - * Session ID which is reserved by the JSON CRDT Patch protocol for internal - * usage. This session ID cannot be used by users when editing the documents. - */ - SYSTEM = 0, - - /** - * The only valid session ID for CRDT ran in the server clock mode. - */ - SERVER = 1, - - /** - * Use this session ID when you want to apply a patch globally, without - * attributing it to any specific user. For example, when the initial document - * is created, the default patch can be applied on all clients to result in - * the same initial state on all clients. - * - * @todo Rename or alias this to `SCHEMA`. - */ - GLOBAL = 2, - - /** - * Session ID used for models that are not shared with other users. For - * example, when a user is editing a document in a local editor, these - * documents could capture local information, like the cursor position, which - * is not shared with other users. - */ - LOCAL = 3, - - /** Max allowed session ID, they are capped at 53-bits. */ - MAX = 9007199254740991, -} - -export const enum SYSTEM_SESSION_TIME { - ORIGIN = 0, - UNDEFINED = 1, -} +export * from './enums'; /** * Represents some sort of root element or is simply the bottom value of a * logical timestamp. */ export const ORIGIN = ts(SESSION.SYSTEM, SYSTEM_SESSION_TIME.ORIGIN); - -export const enum JsonCrdtDataType { - con = 0b000, - val = 0b001, - obj = 0b010, - vec = 0b011, - str = 0b100, - bin = 0b101, - arr = 0b110, -} - -export const enum JsonCrdtPatchOpcode { - new_con = 0b00000 | JsonCrdtDataType.con, // 0 - new_val = 0b00000 | JsonCrdtDataType.val, // 1 - new_obj = 0b00000 | JsonCrdtDataType.obj, // 2 - new_vec = 0b00000 | JsonCrdtDataType.vec, // 3 - new_str = 0b00000 | JsonCrdtDataType.str, // 4 - new_bin = 0b00000 | JsonCrdtDataType.bin, // 5 - new_arr = 0b00000 | JsonCrdtDataType.arr, // 6 - ins_val = 0b01000 | JsonCrdtDataType.val, // 9 - ins_obj = 0b01000 | JsonCrdtDataType.obj, // 10 - ins_vec = 0b01000 | JsonCrdtDataType.vec, // 11 - ins_str = 0b01000 | JsonCrdtDataType.str, // 12 - ins_bin = 0b01000 | JsonCrdtDataType.bin, // 13 - ins_arr = 0b01000 | JsonCrdtDataType.arr, // 14 - del = 0b10000, // 16 - nop = 0b10001, // 17 -} - -export const enum JsonCrdtPatchOpcodeOverlay { - new_con = JsonCrdtPatchOpcode.new_con << 3, - new_val = JsonCrdtPatchOpcode.new_val << 3, - new_obj = JsonCrdtPatchOpcode.new_obj << 3, - new_vec = JsonCrdtPatchOpcode.new_vec << 3, - new_str = JsonCrdtPatchOpcode.new_str << 3, - new_bin = JsonCrdtPatchOpcode.new_bin << 3, - new_arr = JsonCrdtPatchOpcode.new_arr << 3, - ins_val = JsonCrdtPatchOpcode.ins_val << 3, - ins_obj = JsonCrdtPatchOpcode.ins_obj << 3, - ins_vec = JsonCrdtPatchOpcode.ins_vec << 3, - ins_str = JsonCrdtPatchOpcode.ins_str << 3, - ins_bin = JsonCrdtPatchOpcode.ins_bin << 3, - ins_arr = JsonCrdtPatchOpcode.ins_arr << 3, - del = JsonCrdtPatchOpcode.del << 3, - nop = JsonCrdtPatchOpcode.nop << 3, -} diff --git a/src/json-crdt-patch/enums.ts b/src/json-crdt-patch/enums.ts new file mode 100644 index 0000000000..7384cc7233 --- /dev/null +++ b/src/json-crdt-patch/enums.ts @@ -0,0 +1,84 @@ +export enum SESSION { + /** + * Session ID which is reserved by the JSON CRDT Patch protocol for internal + * usage. This session ID cannot be used by users when editing the documents. + */ + SYSTEM = 0, + + /** + * The only valid session ID for CRDT ran in the server clock mode. + */ + SERVER = 1, + + /** + * Use this session ID when you want to apply a patch globally, without + * attributing it to any specific user. For example, when the initial document + * is created, the default patch can be applied on all clients to result in + * the same initial state on all clients. + * + * @todo Rename or alias this to `SCHEMA`. + */ + GLOBAL = 2, + + /** + * Session ID used for models that are not shared with other users. For + * example, when a user is editing a document in a local editor, these + * documents could capture local information, like the cursor position, which + * is not shared with other users. + */ + LOCAL = 3, + + /** Max allowed session ID, they are capped at 53-bits. */ + MAX = 9007199254740991, +} + +export enum SYSTEM_SESSION_TIME { + ORIGIN = 0, + UNDEFINED = 1, +} + +export enum JsonCrdtDataType { + con = 0b000, + val = 0b001, + obj = 0b010, + vec = 0b011, + str = 0b100, + bin = 0b101, + arr = 0b110, +} + +export enum JsonCrdtPatchOpcode { + new_con = 0b00000 | JsonCrdtDataType.con, // 0 + new_val = 0b00000 | JsonCrdtDataType.val, // 1 + new_obj = 0b00000 | JsonCrdtDataType.obj, // 2 + new_vec = 0b00000 | JsonCrdtDataType.vec, // 3 + new_str = 0b00000 | JsonCrdtDataType.str, // 4 + new_bin = 0b00000 | JsonCrdtDataType.bin, // 5 + new_arr = 0b00000 | JsonCrdtDataType.arr, // 6 + ins_val = 0b01000 | JsonCrdtDataType.val, // 9 + ins_obj = 0b01000 | JsonCrdtDataType.obj, // 10 + ins_vec = 0b01000 | JsonCrdtDataType.vec, // 11 + ins_str = 0b01000 | JsonCrdtDataType.str, // 12 + ins_bin = 0b01000 | JsonCrdtDataType.bin, // 13 + ins_arr = 0b01000 | JsonCrdtDataType.arr, // 14 + del = 0b10000, // 16 + nop = 0b10001, // 17 +} + +export enum JsonCrdtPatchOpcodeOverlay { + new_con = JsonCrdtPatchOpcode.new_con << 3, + new_val = JsonCrdtPatchOpcode.new_val << 3, + new_obj = JsonCrdtPatchOpcode.new_obj << 3, + new_vec = JsonCrdtPatchOpcode.new_vec << 3, + new_str = JsonCrdtPatchOpcode.new_str << 3, + new_bin = JsonCrdtPatchOpcode.new_bin << 3, + new_arr = JsonCrdtPatchOpcode.new_arr << 3, + ins_val = JsonCrdtPatchOpcode.ins_val << 3, + ins_obj = JsonCrdtPatchOpcode.ins_obj << 3, + ins_vec = JsonCrdtPatchOpcode.ins_vec << 3, + ins_str = JsonCrdtPatchOpcode.ins_str << 3, + ins_bin = JsonCrdtPatchOpcode.ins_bin << 3, + ins_arr = JsonCrdtPatchOpcode.ins_arr << 3, + del = JsonCrdtPatchOpcode.del << 3, + nop = JsonCrdtPatchOpcode.nop << 3, +} diff --git a/src/json-crdt-peritext-ui/__demos__/components/App.tsx b/src/json-crdt-peritext-ui/__demos__/components/App.tsx index 66b8fec0dd..d27fe4976c 100644 --- a/src/json-crdt-peritext-ui/__demos__/components/App.tsx +++ b/src/json-crdt-peritext-ui/__demos__/components/App.tsx @@ -5,7 +5,7 @@ import {PeritextView} from '../../react'; import {renderers} from '../../renderers/default'; import {renderers as debugRenderers} from '../../renderers/debug'; -export const App: React.FC = ({}) => { +export const App: React.FC = () => { const [[model, peritext]] = React.useState(() => { const model = ModelWithExt.create(ext.peritext.new('Hello world!')); const peritext = model.s.toExt().txt; diff --git a/src/json-crdt-peritext-ui/constants.ts b/src/json-crdt-peritext-ui/constants.ts index b4c16f7a1b..acd3909907 100644 --- a/src/json-crdt-peritext-ui/constants.ts +++ b/src/json-crdt-peritext-ui/constants.ts @@ -1,8 +1,8 @@ -export const enum Char { +export enum Char { ZeroLengthSpace = '\uFEFF', } -export const enum ElementAttr { +export enum ElementAttr { InlineOffset = '__jsonjoy.com', } diff --git a/src/json-crdt-peritext-ui/dom/InputController.ts b/src/json-crdt-peritext-ui/dom/InputController.ts index 029e81a15f..afacdce25a 100644 --- a/src/json-crdt-peritext-ui/dom/InputController.ts +++ b/src/json-crdt-peritext-ui/dom/InputController.ts @@ -210,11 +210,13 @@ export class InputController implements UiLifeCycles { break; } case 'Home': - case 'End': + case 'End': { event.preventDefault(); const direction = key === 'End' ? 1 : -1; const edge = event.shiftKey ? 'focus' : 'both'; - return this.et.move(direction, 'line', edge); + this.et.move(direction, 'line', edge); + return; + } case 'a': if (event.metaKey || event.ctrlKey) { event.preventDefault(); diff --git a/src/json-crdt-peritext-ui/events/PeritextEventTarget.ts b/src/json-crdt-peritext-ui/events/PeritextEventTarget.ts index f43cb6a76d..427e6c0db9 100644 --- a/src/json-crdt-peritext-ui/events/PeritextEventTarget.ts +++ b/src/json-crdt-peritext-ui/events/PeritextEventTarget.ts @@ -1,5 +1,5 @@ import {TypedEventTarget} from './TypedEventTarget'; -import {type PeritextEventMap, CursorDetail, InlineDetail, DeleteDetail} from './types'; +import type {PeritextEventMap, CursorDetail, InlineDetail, DeleteDetail} from './types'; export type PeritextEventHandlerMap = { [K in keyof PeritextEventMap]: (event: CustomEvent) => void; diff --git a/src/json-crdt-peritext-ui/events/types.ts b/src/json-crdt-peritext-ui/events/types.ts index 80ba29243c..44ee9ff06e 100644 --- a/src/json-crdt-peritext-ui/events/types.ts +++ b/src/json-crdt-peritext-ui/events/types.ts @@ -126,7 +126,8 @@ export interface InlineDetail { pos?: [start: number, end: number][]; } -export interface MarkerDetail {} +// biome-ignore lint: empty interface is expected +export type MarkerDetail = {}; export type PeritextEventMap = { change: ChangeDetail; diff --git a/src/json-crdt-peritext-ui/react/BlockView.tsx b/src/json-crdt-peritext-ui/react/BlockView.tsx index bf68cab7f2..8fa9e99bec 100644 --- a/src/json-crdt-peritext-ui/react/BlockView.tsx +++ b/src/json-crdt-peritext-ui/react/BlockView.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import {LeafBlock} from '../../json-crdt-extensions/peritext/block/LeafBlock'; -import {Block} from '../../json-crdt-extensions/peritext/block/Block'; +import type {Block} from '../../json-crdt-extensions/peritext/block/Block'; import {InlineView} from './InlineView'; import {Char} from '../constants'; import {usePeritext} from './context'; diff --git a/src/json-crdt-peritext-ui/react/InlineView.tsx b/src/json-crdt-peritext-ui/react/InlineView.tsx index 73d52c036b..356d9da520 100644 --- a/src/json-crdt-peritext-ui/react/InlineView.tsx +++ b/src/json-crdt-peritext-ui/react/InlineView.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import {Inline} from '../../json-crdt-extensions/peritext/block/Inline'; +import type {Inline} from '../../json-crdt-extensions/peritext/block/Inline'; import {CssClass, ElementAttr} from '../constants'; import {TextView} from './TextView'; import {usePeritext} from './context'; diff --git a/src/json-crdt-peritext-ui/react/selection/AnchorView.tsx b/src/json-crdt-peritext-ui/react/selection/AnchorView.tsx index 6f929ebd4b..9d45f83d30 100644 --- a/src/json-crdt-peritext-ui/react/selection/AnchorView.tsx +++ b/src/json-crdt-peritext-ui/react/selection/AnchorView.tsx @@ -1,7 +1,9 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {usePeritext} from '../context'; -export interface AnchorViewProps {} +// biome-ignore lint: empty interface is expected +export type AnchorViewProps = {}; export const AnchorView: React.FC = (props) => { const {renderers} = usePeritext(); diff --git a/src/json-crdt-peritext-ui/react/selection/Caret.tsx b/src/json-crdt-peritext-ui/react/selection/Caret.tsx index 3cdf997116..6ea31f244c 100644 --- a/src/json-crdt-peritext-ui/react/selection/Caret.tsx +++ b/src/json-crdt-peritext-ui/react/selection/Caret.tsx @@ -1,3 +1,4 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {Char} from '../../constants'; import {usePeritext} from '../context'; diff --git a/src/json-crdt-peritext-ui/react/selection/CaretView.tsx b/src/json-crdt-peritext-ui/react/selection/CaretView.tsx index b240de000f..99f6e2fe86 100644 --- a/src/json-crdt-peritext-ui/react/selection/CaretView.tsx +++ b/src/json-crdt-peritext-ui/react/selection/CaretView.tsx @@ -1,3 +1,4 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {usePeritext} from '../context'; import {Caret} from './Caret'; diff --git a/src/json-crdt-peritext-ui/react/selection/FocusView.tsx b/src/json-crdt-peritext-ui/react/selection/FocusView.tsx index e2ba1b15ac..897ead4356 100644 --- a/src/json-crdt-peritext-ui/react/selection/FocusView.tsx +++ b/src/json-crdt-peritext-ui/react/selection/FocusView.tsx @@ -1,3 +1,4 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {usePeritext} from '../context'; import {Caret} from './Caret'; diff --git a/src/json-crdt-peritext-ui/react/types.ts b/src/json-crdt-peritext-ui/react/types.ts index 50b915dded..e1d78df84c 100644 --- a/src/json-crdt-peritext-ui/react/types.ts +++ b/src/json-crdt-peritext-ui/react/types.ts @@ -1,4 +1,4 @@ -import * as React from 'react'; +import type * as React from 'react'; import type {FocusViewProps} from './selection/FocusView'; import type {CaretViewProps} from './selection/CaretView'; import type {AnchorViewProps} from './selection/AnchorView'; diff --git a/src/json-crdt-peritext-ui/renderers/debug/RenderBlock.tsx b/src/json-crdt-peritext-ui/renderers/debug/RenderBlock.tsx index df416b8423..29e1db8a32 100644 --- a/src/json-crdt-peritext-ui/renderers/debug/RenderBlock.tsx +++ b/src/json-crdt-peritext-ui/renderers/debug/RenderBlock.tsx @@ -1,6 +1,7 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; -import type {BlockViewProps} from '../../react/BlockView'; import {useDebugCtx} from './context'; +import type {BlockViewProps} from '../../react/BlockView'; export interface RenderBlockProps extends BlockViewProps { children?: React.ReactNode; diff --git a/src/json-crdt-peritext-ui/renderers/debug/RenderInline.tsx b/src/json-crdt-peritext-ui/renderers/debug/RenderInline.tsx index 1286db41e9..90a8776681 100644 --- a/src/json-crdt-peritext-ui/renderers/debug/RenderInline.tsx +++ b/src/json-crdt-peritext-ui/renderers/debug/RenderInline.tsx @@ -1,3 +1,4 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {useDebugCtx} from './context'; import type {InlineViewProps} from '../../react/InlineView'; diff --git a/src/json-crdt-peritext-ui/renderers/debug/RenderPeritext.tsx b/src/json-crdt-peritext-ui/renderers/debug/RenderPeritext.tsx index 6e85ec28d9..a1e298b71b 100644 --- a/src/json-crdt-peritext-ui/renderers/debug/RenderPeritext.tsx +++ b/src/json-crdt-peritext-ui/renderers/debug/RenderPeritext.tsx @@ -43,7 +43,7 @@ export const RenderPeritext: React.FC = ({enabled: enabledP return (
-
{children}
diff --git a/src/json-crdt-peritext-ui/renderers/debug/index.tsx b/src/json-crdt-peritext-ui/renderers/debug/index.tsx index cf2bc9d3d0..8f78c4aa9b 100644 --- a/src/json-crdt-peritext-ui/renderers/debug/index.tsx +++ b/src/json-crdt-peritext-ui/renderers/debug/index.tsx @@ -1,11 +1,19 @@ import * as React from 'react'; -import {RendererMap} from '../../react/types'; +import type {RendererMap} from '../../react/types'; import {RenderInline} from './RenderInline'; import {RenderBlock} from './RenderBlock'; -import {RenderPeritext, RenderPeritextProps} from './RenderPeritext'; +import {RenderPeritext, type RenderPeritextProps} from './RenderPeritext'; export const renderers = (options?: Pick): RendererMap => ({ - inline: (props, children, attributes) => , - block: (props, children) => , - peritext: (props, children) => , + inline: (props, children, attributes) => ( + + {children} + + ), + block: (props, children) => {children}, + peritext: (props, children) => ( + + {children} + + ), }); diff --git a/src/json-crdt-peritext-ui/renderers/default/RenderAnchor.tsx b/src/json-crdt-peritext-ui/renderers/default/RenderAnchor.tsx index 3d23f355b1..cd18c6998f 100644 --- a/src/json-crdt-peritext-ui/renderers/default/RenderAnchor.tsx +++ b/src/json-crdt-peritext-ui/renderers/default/RenderAnchor.tsx @@ -1,7 +1,8 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {rule} from 'nano-theme'; import {Char} from '../../constants'; -import {AnchorViewProps} from '../../react/selection/AnchorView'; +import type {AnchorViewProps} from '../../react/selection/AnchorView'; const color = '#07f'; diff --git a/src/json-crdt-peritext-ui/renderers/default/RenderFocus.tsx b/src/json-crdt-peritext-ui/renderers/default/RenderFocus.tsx index e450163249..d660f61f05 100644 --- a/src/json-crdt-peritext-ui/renderers/default/RenderFocus.tsx +++ b/src/json-crdt-peritext-ui/renderers/default/RenderFocus.tsx @@ -1,3 +1,4 @@ +// biome-ignore lint: React is used for JSX import * as React from 'react'; import {rule, drule, keyframes} from 'nano-theme'; diff --git a/src/json-crdt-peritext-ui/renderers/default/index.ts b/src/json-crdt-peritext-ui/renderers/default/index.ts index 9c769ef47f..dcb039f894 100644 --- a/src/json-crdt-peritext-ui/renderers/default/index.ts +++ b/src/json-crdt-peritext-ui/renderers/default/index.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import {RendererMap} from '../../react/types'; +import type {RendererMap} from '../../react/types'; import {RenderCaret} from './RenderCaret'; import {RenderFocus} from './RenderFocus'; import {RenderAnchor} from './RenderAnchor'; diff --git a/src/json-crdt/__bench__/bench.codecs.decoding.ts b/src/json-crdt/__bench__/bench.codecs.decoding.ts index 8e03d052e0..d03be1f033 100644 --- a/src/json-crdt/__bench__/bench.codecs.decoding.ts +++ b/src/json-crdt/__bench__/bench.codecs.decoding.ts @@ -1,7 +1,7 @@ // npx ts-node src/json-crdt/__bench__/bench.codecs.decoding.ts import {payloads} from '../../__bench__/payloads'; -import {IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; +import {type IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; import {Encoder as CompactEncoder} from '../codec/structural/compact/Encoder'; import {Decoder as CompactDecoder} from '../codec/structural/compact/Decoder'; import {Encoder as VerboseEncoder} from '../codec/structural/verbose/Encoder'; diff --git a/src/json-crdt/__bench__/bench.codecs.encoding.json.ts b/src/json-crdt/__bench__/bench.codecs.encoding.json.ts index 5cba9d11f7..fd7d777c9f 100644 --- a/src/json-crdt/__bench__/bench.codecs.encoding.json.ts +++ b/src/json-crdt/__bench__/bench.codecs.encoding.json.ts @@ -1,7 +1,7 @@ // npx ts-node src/json-crdt/__bench__/bench.codecs.encoding.json.ts import {payloads} from '../../__bench__/payloads'; -import {IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; +import {type IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; import {Model} from '../model'; diff --git a/src/json-crdt/__bench__/bench.codecs.encoding.libs.ts b/src/json-crdt/__bench__/bench.codecs.encoding.libs.ts index 4c3677892a..9e3d78225c 100644 --- a/src/json-crdt/__bench__/bench.codecs.encoding.libs.ts +++ b/src/json-crdt/__bench__/bench.codecs.encoding.libs.ts @@ -1,9 +1,9 @@ // npx ts-node src/json-crdt/__bench__/bench.codecs.encoding.libs.ts import {payloads} from '../../__bench__/payloads'; -import {IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; -import {StructuralEditors, structuralEditors} from './util/structural-editors'; -import {StructuralEditor} from './util/types'; +import {type IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; +import {type StructuralEditors, structuralEditors} from './util/structural-editors'; +import type {StructuralEditor} from './util/types'; const editors: StructuralEditors[] = ['nativeJs', 'jsonJoy']; diff --git a/src/json-crdt/__bench__/bench.codecs.encoding.ts b/src/json-crdt/__bench__/bench.codecs.encoding.ts index 18bdc5d7a5..70ac12584d 100644 --- a/src/json-crdt/__bench__/bench.codecs.encoding.ts +++ b/src/json-crdt/__bench__/bench.codecs.encoding.ts @@ -1,7 +1,7 @@ // npx ts-node src/json-crdt/__bench__/bench.codecs.encoding.ts import {payloads} from '../../__bench__/payloads'; -import {IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; +import {type IBenchmark, runBenchmarkAndSave} from '../../__bench__/runBenchmark'; import {Encoder as CompactEncoder} from '../codec/structural/compact/Encoder'; import {Encoder as VerboseEncoder} from '../codec/structural/verbose/Encoder'; import {Encoder as IndexedEncoder} from '../codec/indexed/binary/Encoder'; diff --git a/src/json-crdt/__bench__/bench.codecs.sizes.ts b/src/json-crdt/__bench__/bench.codecs.sizes.ts index 0e6817da1c..36a1f5c7d1 100644 --- a/src/json-crdt/__bench__/bench.codecs.sizes.ts +++ b/src/json-crdt/__bench__/bench.codecs.sizes.ts @@ -2,7 +2,7 @@ // npx ts-node src/json-crdt/__bench__/bench.codecs.sizes.ts import {payloads} from '../../__bench__/payloads'; -import {StructuralEditors, structuralEditors} from './util/structural-editors'; +import {type StructuralEditors, structuralEditors} from './util/structural-editors'; console.clear(); diff --git a/src/json-crdt/__bench__/bench.concurrent-traces.ts b/src/json-crdt/__bench__/bench.concurrent-traces.ts index ae12ca29a5..9392f72d61 100644 --- a/src/json-crdt/__bench__/bench.concurrent-traces.ts +++ b/src/json-crdt/__bench__/bench.concurrent-traces.ts @@ -2,7 +2,7 @@ // npx ts-node src/json-crdt/__bench__/bench.concurrent-traces.ts import {loadConcurrentTrace} from './util/concurrent-trace'; -import {Patch} from '../../json-crdt-patch'; +import type {Patch} from '../../json-crdt-patch'; import {Model} from '../model'; const traceName = 'friendsforever'; diff --git a/src/json-crdt/__bench__/bench.traces.non-crdt-libs.ts b/src/json-crdt/__bench__/bench.traces.non-crdt-libs.ts index b0a794fc8f..125092b806 100644 --- a/src/json-crdt/__bench__/bench.traces.non-crdt-libs.ts +++ b/src/json-crdt/__bench__/bench.traces.non-crdt-libs.ts @@ -6,18 +6,7 @@ import {runTraceMatrix} from './util/execute'; // prettier-ignore runTraceMatrix({ - traces: [ - 'friendsforever_flat', - 'sveltecomponent', - 'rustcode', - 'seph-blog1', - 'automerge-paper', - ], - editors: [ - 'StrNode (json-joy)', - 'diamond-types-node', - 'rope.js', - 'V8 strings', - ], + traces: ['friendsforever_flat', 'sveltecomponent', 'rustcode', 'seph-blog1', 'automerge-paper'], + editors: ['StrNode (json-joy)', 'diamond-types-node', 'rope.js', 'V8 strings'], iterationsPerEditor: 50, }); diff --git a/src/json-crdt/__bench__/util/execute/index.ts b/src/json-crdt/__bench__/util/execute/index.ts index 79ef556a8d..0374af23bb 100644 --- a/src/json-crdt/__bench__/util/execute/index.ts +++ b/src/json-crdt/__bench__/util/execute/index.ts @@ -17,11 +17,11 @@ export const runTraceWithEditor = ( ) => { const trace = traces.get(traceName); const editorFactory = editors[editorName]; - let instance, view; + let instance: any, view: any; console.log('----------------------------------------------------------------------------'); console.log(editorFactory.name); console.log('----------------------------------------------------------------------------'); - let best = Infinity; + let best = Number.POSITIVE_INFINITY; let worst = 0; const measurements = []; for (let i = 0; i < iterations; i++) { diff --git a/src/json-crdt/__demos__/events-level1.ts b/src/json-crdt/__demos__/events-level1.ts index 420e540d4c..131f909fc5 100644 --- a/src/json-crdt/__demos__/events-level1.ts +++ b/src/json-crdt/__demos__/events-level1.ts @@ -11,7 +11,7 @@ console.clear(); // Import all necessary dependencies. import {Model} from '..'; -import {Patch, PatchBuilder} from '../../json-crdt-patch'; +import {type Patch, PatchBuilder} from '../../json-crdt-patch'; const subscribe = (model: Model) => { /** @@ -46,10 +46,10 @@ const subscribe = (model: Model) => { }); // The "change" events combine all "local" changes with the "patch" changes. - model.api.onChange.listen((change: number | void | Patch) => { + model.api.onChange.listen((change: number | undefined | Patch) => { console.log(`Called: "onChange", ${change}`); }); - model.api.onChanges.listen((changes: (number | void | Patch)[]) => { + model.api.onChanges.listen((changes: (number | undefined | Patch)[]) => { console.log(`Called: "onChanges", ${changes}`); }); diff --git a/src/json-crdt/__demos__/getting-started.ts b/src/json-crdt/__demos__/getting-started.ts index fea94c14d8..ec954707e1 100644 --- a/src/json-crdt/__demos__/getting-started.ts +++ b/src/json-crdt/__demos__/getting-started.ts @@ -6,7 +6,7 @@ * npx nodemon -q -x ts-node src/json-crdt/__demos__/getting-started.ts */ -import {Model, n} from '..'; +import {Model, type n} from '..'; import {vec} from '../../json-crdt-patch'; // Create a new JSON CRDT document, 1234 is the session ID. diff --git a/src/json-crdt/__demos__/type-safety.ts b/src/json-crdt/__demos__/type-safety.ts index a75346d9d4..a592eb60e7 100644 --- a/src/json-crdt/__demos__/type-safety.ts +++ b/src/json-crdt/__demos__/type-safety.ts @@ -6,7 +6,7 @@ * npx nodemon -q -x ts-node src/json-crdt/__demos__/type-safety.ts */ -import {Model, n} from '..'; +import {Model, type n} from '..'; console.clear(); diff --git a/src/json-crdt/__tests__/fuzzer/JsonCrdtFuzzer.ts b/src/json-crdt/__tests__/fuzzer/JsonCrdtFuzzer.ts index 7ee35514c6..c7eeb341a5 100644 --- a/src/json-crdt/__tests__/fuzzer/JsonCrdtFuzzer.ts +++ b/src/json-crdt/__tests__/fuzzer/JsonCrdtFuzzer.ts @@ -1,11 +1,11 @@ import {Model} from '../../model/Model'; import {SessionLogical} from './SessionLogical'; import {Picker} from './Picker'; -import {FuzzerOptions} from './types'; +import type {FuzzerOptions} from './types'; import {RandomJson} from '@jsonjoy.com/util/lib/json-random/RandomJson'; import {generateInteger} from './util'; import {PatchBuilder} from '../../../json-crdt-patch/PatchBuilder'; -import {Patch} from '../../../json-crdt-patch'; +import type {Patch} from '../../../json-crdt-patch'; export const defaultFuzzerOptions: FuzzerOptions = { startingValue: undefined, diff --git a/src/json-crdt/__tests__/fuzzer/Picker.ts b/src/json-crdt/__tests__/fuzzer/Picker.ts index 0fe744b184..1ea614ef07 100644 --- a/src/json-crdt/__tests__/fuzzer/Picker.ts +++ b/src/json-crdt/__tests__/fuzzer/Picker.ts @@ -1,9 +1,9 @@ import {DelOp, InsObjOp, InsStrOp, InsBinOp, InsArrOp} from '../../../json-crdt-patch/operations'; import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; -import {JsonNode, ObjNode, ArrNode, BinNode, StrNode} from '../../nodes'; -import {Model} from '../../model/Model'; +import type {JsonNode, ObjNode, ArrNode, BinNode, StrNode} from '../../nodes'; +import type {Model} from '../../model/Model'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; -import {FuzzerOptions} from './types'; +import type {FuzzerOptions} from './types'; type StringOp = typeof InsStrOp | typeof DelOp; type BinaryOp = typeof InsBinOp | typeof DelOp; @@ -22,6 +22,7 @@ export class Picker { public pickNode(model: Model): JsonNode | null { const nodes: JsonNode[] = []; const index = model.index; + // biome-ignore lint: index is not iterable index.forEach(({v: node}) => nodes.push(node)); if (!nodes.length) return null; return Fuzzer.pick(nodes); diff --git a/src/json-crdt/__tests__/fuzzer/SessionLogical.ts b/src/json-crdt/__tests__/fuzzer/SessionLogical.ts index fd715ef335..21e15cf7b0 100644 --- a/src/json-crdt/__tests__/fuzzer/SessionLogical.ts +++ b/src/json-crdt/__tests__/fuzzer/SessionLogical.ts @@ -13,8 +13,8 @@ import {Encoder as JsonEncoder} from '../../codec/structural/verbose/Encoder'; import {Encoder as IndexedBinaryEncoder} from '../../codec/indexed/binary/Encoder'; import {Decoder as IndexedBinaryDecoder} from '../../codec/indexed/binary/Decoder'; import {generateInteger} from './util'; -import {Model} from '../..'; -import {Patch} from '../../../json-crdt-patch/Patch'; +import type {Model} from '../..'; +import type {Patch} from '../../../json-crdt-patch/Patch'; import {PatchBuilder} from '../../../json-crdt-patch/PatchBuilder'; import {RandomJson} from '@jsonjoy.com/util/lib/json-random/RandomJson'; import {randomU32} from 'hyperdyperid/lib/randomU32'; diff --git a/src/json-crdt/__tests__/fuzzer/fuzzing-model.spec.ts b/src/json-crdt/__tests__/fuzzer/fuzzing-model.spec.ts index 4f787c043d..647b717323 100644 --- a/src/json-crdt/__tests__/fuzzer/fuzzing-model.spec.ts +++ b/src/json-crdt/__tests__/fuzzer/fuzzing-model.spec.ts @@ -3,7 +3,7 @@ import {JsonCrdtFuzzer} from './JsonCrdtFuzzer'; const runs = 10; const sessionNum = 25; -test(`model fuzz testing`, () => { +test('model fuzz testing', () => { for (let r = 0; r < runs; r++) { const fuzzer = new JsonCrdtFuzzer(); fuzzer.setupModel(); diff --git a/src/json-crdt/__tests__/fuzzer/generate-trace.ts b/src/json-crdt/__tests__/fuzzer/generate-trace.ts index 369e0c7fca..8dd3e0cd07 100644 --- a/src/json-crdt/__tests__/fuzzer/generate-trace.ts +++ b/src/json-crdt/__tests__/fuzzer/generate-trace.ts @@ -1,7 +1,7 @@ /* tslint:disable no-console */ // Run: npx ts-node src/json-crdt/__tests__/fuzzer/generate-trace.ts -import {Patch} from '../../../json-crdt-patch'; +import type {Patch} from '../../../json-crdt-patch'; import {Model} from '../../model'; import {JsonCrdtFuzzer} from './JsonCrdtFuzzer'; import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; diff --git a/src/json-crdt/codec/indexed/binary/Decoder.ts b/src/json-crdt/codec/indexed/binary/Decoder.ts index e419c411d1..572eed58d5 100644 --- a/src/json-crdt/codec/indexed/binary/Decoder.ts +++ b/src/json-crdt/codec/indexed/binary/Decoder.ts @@ -1,8 +1,8 @@ import * as nodes from '../../../nodes'; import {ClockTable} from '../../../../json-crdt-patch/codec/clock/ClockTable'; import {CrdtReader} from '../../../../json-crdt-patch/util/binary/CrdtReader'; -import {IndexedFields, FieldName, IndexedNodeFields} from './types'; -import {ITimestampStruct, IClockVector, Timestamp, ClockVector} from '../../../../json-crdt-patch/clock'; +import type {IndexedFields, FieldName, IndexedNodeFields} from './types'; +import {type ITimestampStruct, type IClockVector, Timestamp, ClockVector} from '../../../../json-crdt-patch/clock'; import {Model, UNDEFINED} from '../../../model/Model'; import {CborDecoderBase} from '@jsonjoy.com/json-pack/lib/cbor/CborDecoderBase'; import {CRDT_MAJOR} from '../../structural/binary/constants'; @@ -18,7 +18,9 @@ export class Decoder { public decode( fields: IndexedFields, - ModelConstructor: new (clock: IClockVector) => M = Model as unknown as new (clock: IClockVector) => M, + ModelConstructor: new (clock: IClockVector) => M = Model as unknown as new ( + clock: IClockVector, + ) => M, ): M { const reader = this.dec.reader; reader.reset(fields.c); @@ -29,7 +31,9 @@ export class Decoder { public decodeFields( clockTable: ClockTable, fields: IndexedNodeFields, - ModelConstructor: new (clock: IClockVector) => M = Model as unknown as new (clock: IClockVector) => M, + ModelConstructor: new (clock: IClockVector) => M = Model as unknown as new ( + clock: IClockVector, + ) => M, ): M { const reader = this.dec.reader; const firstClock = clockTable.byIdx[0]; diff --git a/src/json-crdt/codec/indexed/binary/Encoder.ts b/src/json-crdt/codec/indexed/binary/Encoder.ts index 3d3c5d55eb..dc36d07396 100644 --- a/src/json-crdt/codec/indexed/binary/Encoder.ts +++ b/src/json-crdt/codec/indexed/binary/Encoder.ts @@ -1,11 +1,11 @@ -import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; import {ClockTable} from '../../../../json-crdt-patch/codec/clock/ClockTable'; import {CrdtWriter} from '../../../../json-crdt-patch/util/binary/CrdtWriter'; import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; -import {Model} from '../../../model'; +import type {Model} from '../../../model'; import * as nodes from '../../../nodes'; import {CRDT_MAJOR_OVERLAY} from '../../structural/binary/constants'; -import {IndexedFields, FieldName} from './types'; +import type {IndexedFields, FieldName} from './types'; export class Encoder { public readonly enc: CborEncoder; @@ -30,6 +30,7 @@ export class Encoder { this.ts(rootValueId); result.r = writer.flush(); } + // biome-ignore lint: index is not iterable doc.index.forEach(({v: node}) => this.onNode(result, node)); return result; } diff --git a/src/json-crdt/codec/sidecar/binary/Decoder.ts b/src/json-crdt/codec/sidecar/binary/Decoder.ts index 157b91021d..ff62e0dfee 100644 --- a/src/json-crdt/codec/sidecar/binary/Decoder.ts +++ b/src/json-crdt/codec/sidecar/binary/Decoder.ts @@ -1,6 +1,6 @@ import {ClockDecoder} from '../../../../json-crdt-patch/codec/clock/ClockDecoder'; import {CrdtReader} from '../../../../json-crdt-patch/util/binary/CrdtReader'; -import {ITimestampStruct} from '../../../../json-crdt-patch/clock'; +import type {ITimestampStruct} from '../../../../json-crdt-patch/clock'; import {Model, UNDEFINED} from '../../../model/Model'; import {CborDecoderBase} from '@jsonjoy.com/json-pack/lib/cbor/CborDecoderBase'; import * as nodes from '../../../nodes'; @@ -10,19 +10,19 @@ import {SESSION} from '../../../../json-crdt-patch/constants'; export class Decoder { protected doc!: Model; - protected clockDecoder?: ClockDecoder; + protected clockDecoder?: ClockDecoder = undefined; protected time: number = -1; protected readonly decoder: CborDecoderBase = new CborDecoderBase(new CrdtReader()); public decode(view: unknown, meta: Uint8Array): Model { - delete this.clockDecoder; + this.clockDecoder = undefined; this.time = -1; this.decoder.reader.reset(meta); this.decodeClockTable(); const clock = this.clockDecoder!.clock; this.doc = Model.withLogicalClock(clock); this.doc.root = new nodes.RootNode(this.doc, this.cRoot(view).id); - delete this.clockDecoder; + this.clockDecoder = undefined; return this.doc; } diff --git a/src/json-crdt/codec/sidecar/binary/Encoder.ts b/src/json-crdt/codec/sidecar/binary/Encoder.ts index fed981e30d..7508a97644 100644 --- a/src/json-crdt/codec/sidecar/binary/Encoder.ts +++ b/src/json-crdt/codec/sidecar/binary/Encoder.ts @@ -1,7 +1,7 @@ import * as nodes from '../../../nodes'; import {ClockEncoder} from '../../../../json-crdt-patch/codec/clock/ClockEncoder'; import {CrdtWriter} from '../../../../json-crdt-patch/util/binary/CrdtWriter'; -import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; import {SESSION} from '../../../../json-crdt-patch/constants'; import {CRDT_MAJOR_OVERLAY} from '../../structural/binary/constants'; diff --git a/src/json-crdt/codec/sidecar/binary/__tests__/all-types-smoketest.spec.ts b/src/json-crdt/codec/sidecar/binary/__tests__/all-types-smoketest.spec.ts index 26be210bb6..08241e0b28 100644 --- a/src/json-crdt/codec/sidecar/binary/__tests__/all-types-smoketest.spec.ts +++ b/src/json-crdt/codec/sidecar/binary/__tests__/all-types-smoketest.spec.ts @@ -1,4 +1,4 @@ -import {Model} from '../../../../model'; +import type {Model} from '../../../../model'; import {runCodecAllTypesSmokeTests} from '../../../structural/verbose/__tests__/runCodecAllTypesSmokeTests'; import {Encoder} from '../Encoder'; import {Decoder} from '../Decoder'; diff --git a/src/json-crdt/codec/structural/binary/Decoder.ts b/src/json-crdt/codec/structural/binary/Decoder.ts index bda7c00f5e..e8d59c44b0 100644 --- a/src/json-crdt/codec/structural/binary/Decoder.ts +++ b/src/json-crdt/codec/structural/binary/Decoder.ts @@ -1,7 +1,7 @@ import * as nodes from '../../../nodes'; import {ClockDecoder} from '../../../../json-crdt-patch/codec/clock/ClockDecoder'; import {CrdtReader} from '../../../../json-crdt-patch/util/binary/CrdtReader'; -import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; import {Model, UNDEFINED} from '../../../model/Model'; import {CborDecoderBase} from '@jsonjoy.com/json-pack/lib/cbor/CborDecoderBase'; import {SESSION} from '../../../../json-crdt-patch/constants'; @@ -9,7 +9,7 @@ import {CRDT_MAJOR} from './constants'; export class Decoder extends CborDecoderBase { protected doc!: Model; - protected clockDecoder?: ClockDecoder; + protected clockDecoder?: ClockDecoder = undefined; protected time: number = -1; constructor() { @@ -17,7 +17,7 @@ export class Decoder extends CborDecoderBase { } public decode(data: Uint8Array, model?: Model): Model { - delete this.clockDecoder; + this.clockDecoder = undefined; this.time = -1; const reader = this.reader; reader.reset(data); @@ -35,7 +35,7 @@ export class Decoder extends CborDecoderBase { } this.doc = model; model.root = new nodes.RootNode(this.doc, this.cRoot().id); - delete this.clockDecoder; + this.clockDecoder = undefined; return model; } diff --git a/src/json-crdt/codec/structural/binary/Encoder.ts b/src/json-crdt/codec/structural/binary/Encoder.ts index 36ae0ffb14..698762f78c 100644 --- a/src/json-crdt/codec/structural/binary/Encoder.ts +++ b/src/json-crdt/codec/structural/binary/Encoder.ts @@ -1,7 +1,7 @@ import * as nodes from '../../../nodes'; import {ClockEncoder} from '../../../../json-crdt-patch/codec/clock/ClockEncoder'; import {CrdtWriter} from '../../../../json-crdt-patch/util/binary/CrdtWriter'; -import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; import {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; import {SESSION} from '../../../../json-crdt-patch/constants'; import {CRDT_MAJOR_OVERLAY} from './constants'; diff --git a/src/json-crdt/codec/structural/binary/constants.ts b/src/json-crdt/codec/structural/binary/constants.ts index 8e99ad5cea..dd11e0e824 100644 --- a/src/json-crdt/codec/structural/binary/constants.ts +++ b/src/json-crdt/codec/structural/binary/constants.ts @@ -1,6 +1,6 @@ import {JsonCrdtDataType} from '../../../../json-crdt-patch/constants'; -export const enum CRDT_MAJOR { +export enum CRDT_MAJOR { CON = JsonCrdtDataType.con, VAL = JsonCrdtDataType.val, OBJ = JsonCrdtDataType.obj, @@ -10,7 +10,7 @@ export const enum CRDT_MAJOR { ARR = JsonCrdtDataType.arr, } -export const enum CRDT_MAJOR_OVERLAY { +export enum CRDT_MAJOR_OVERLAY { CON = JsonCrdtDataType.con << 5, VAL = CRDT_MAJOR.VAL << 5, VEC = CRDT_MAJOR.VEC << 5, diff --git a/src/json-crdt/codec/structural/compact-binary/Decoder.ts b/src/json-crdt/codec/structural/compact-binary/Decoder.ts index 72d66af5e1..6bdb9d6b85 100644 --- a/src/json-crdt/codec/structural/compact-binary/Decoder.ts +++ b/src/json-crdt/codec/structural/compact-binary/Decoder.ts @@ -1,6 +1,6 @@ import {Decoder as CompactDecoder} from '../compact/Decoder'; import {decoder} from '@jsonjoy.com/json-pack/lib/msgpack/util'; -import {Model} from '../../../model'; +import type {Model} from '../../../model'; export class Decoder { protected decoder = new CompactDecoder(); diff --git a/src/json-crdt/codec/structural/compact-binary/Encoder.ts b/src/json-crdt/codec/structural/compact-binary/Encoder.ts index 0aabb7594f..ec6b875fea 100644 --- a/src/json-crdt/codec/structural/compact-binary/Encoder.ts +++ b/src/json-crdt/codec/structural/compact-binary/Encoder.ts @@ -1,6 +1,6 @@ import {Encoder as CompactEncoder} from '../compact/Encoder'; import {encoderFull} from '@jsonjoy.com/json-pack/lib/msgpack/util'; -import {Model} from '../../../model'; +import type {Model} from '../../../model'; export class Encoder { protected encoder = new CompactEncoder(); diff --git a/src/json-crdt/codec/structural/compact-binary/__tests__/all-types-smoketest.spec.ts b/src/json-crdt/codec/structural/compact-binary/__tests__/all-types-smoketest.spec.ts index cc72559a2a..c6d446c4cd 100644 --- a/src/json-crdt/codec/structural/compact-binary/__tests__/all-types-smoketest.spec.ts +++ b/src/json-crdt/codec/structural/compact-binary/__tests__/all-types-smoketest.spec.ts @@ -1,4 +1,4 @@ -import {Model} from '../../../../model'; +import type {Model} from '../../../../model'; import {Encoder} from '../Encoder'; import {Decoder} from '../Decoder'; import {runCodecAllTypesSmokeTests} from '../../verbose/__tests__/runCodecAllTypesSmokeTests'; diff --git a/src/json-crdt/codec/structural/compact/Decoder.ts b/src/json-crdt/codec/structural/compact/Decoder.ts index a1e417529c..6e11b2a6c9 100644 --- a/src/json-crdt/codec/structural/compact/Decoder.ts +++ b/src/json-crdt/codec/structural/compact/Decoder.ts @@ -1,6 +1,6 @@ import * as nodes from '../../../nodes'; import {ClockDecoder} from '../../../../json-crdt-patch/codec/clock/ClockDecoder'; -import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; import {Model, UNDEFINED} from '../../../model/Model'; import {JsonCrdtDataType, SESSION} from '../../../../json-crdt-patch/constants'; import type * as t from './types'; diff --git a/src/json-crdt/codec/structural/compact/Encoder.ts b/src/json-crdt/codec/structural/compact/Encoder.ts index 7ce90b1daa..f6bfb9d09e 100644 --- a/src/json-crdt/codec/structural/compact/Encoder.ts +++ b/src/json-crdt/codec/structural/compact/Encoder.ts @@ -1,6 +1,6 @@ import * as nodes from '../../../nodes'; import {ClockEncoder} from '../../../../json-crdt-patch/codec/clock/ClockEncoder'; -import {ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, Timestamp} from '../../../../json-crdt-patch/clock'; import {JsonCrdtDataType} from '../../../../json-crdt-patch/constants'; import {SESSION} from '../../../../json-crdt-patch/constants'; import type * as t from './types'; diff --git a/src/json-crdt/codec/structural/compact/__tests__/all-types-smoketest.spec.ts b/src/json-crdt/codec/structural/compact/__tests__/all-types-smoketest.spec.ts index cc72559a2a..c6d446c4cd 100644 --- a/src/json-crdt/codec/structural/compact/__tests__/all-types-smoketest.spec.ts +++ b/src/json-crdt/codec/structural/compact/__tests__/all-types-smoketest.spec.ts @@ -1,4 +1,4 @@ -import {Model} from '../../../../model'; +import type {Model} from '../../../../model'; import {Encoder} from '../Encoder'; import {Decoder} from '../Decoder'; import {runCodecAllTypesSmokeTests} from '../../verbose/__tests__/runCodecAllTypesSmokeTests'; diff --git a/src/json-crdt/codec/structural/verbose/Decoder.ts b/src/json-crdt/codec/structural/verbose/Decoder.ts index 0e140edd9e..082a25f85b 100644 --- a/src/json-crdt/codec/structural/verbose/Decoder.ts +++ b/src/json-crdt/codec/structural/verbose/Decoder.ts @@ -1,9 +1,9 @@ import * as nodes from '../../../nodes'; import {fromBase64} from '@jsonjoy.com/base64/lib/fromBase64'; -import {ITimestampStruct, ts, ClockVector} from '../../../../json-crdt-patch/clock'; +import {type ITimestampStruct, ts, ClockVector} from '../../../../json-crdt-patch/clock'; import {Model} from '../../../model'; import {SESSION} from '../../../../json-crdt-patch/constants'; -import * as types from './types'; +import type * as types from './types'; export class Decoder { public decode({time, root}: types.JsonCrdtVerboseDocument): Model { @@ -90,11 +90,10 @@ export class Decoder { const chunks = node.chunks; const length = chunks.length; if (length) { - const self = this; let i = 0; rga.ingest(length, () => { const c = chunks[i++]; - const id = self.cTs(c.id); + const id = this.cTs(c.id); if (typeof (c as types.JsonCrdtVerboseTombstone).span === 'number') return new nodes.ArrChunk(id, (c as types.JsonCrdtVerboseTombstone).span, undefined); else { @@ -113,11 +112,10 @@ export class Decoder { const chunks = node.chunks; const length = chunks.length; if (length) { - const self = this; let i = 0; rga.ingest(length, () => { const c = chunks[i++]; - const id = self.cTs(c.id); + const id = this.cTs(c.id); if (typeof (c as types.JsonCrdtVerboseTombstone).span === 'number') return new nodes.StrChunk(id, (c as types.JsonCrdtVerboseTombstone).span, ''); else { @@ -135,12 +133,11 @@ export class Decoder { const rga = new nodes.BinNode(id); const chunks = node.chunks; const length = chunks.length; - const self = this; if (length) { let i = 0; rga.ingest(length, () => { const c = chunks[i++]; - const id = self.cTs(c.id); + const id = this.cTs(c.id); if (typeof (c as types.JsonCrdtVerboseTombstone).span === 'number') return new nodes.BinChunk(id, (c as types.JsonCrdtVerboseTombstone).span, undefined); else { diff --git a/src/json-crdt/codec/structural/verbose/Encoder.ts b/src/json-crdt/codec/structural/verbose/Encoder.ts index 99165cbc8f..636189af21 100644 --- a/src/json-crdt/codec/structural/verbose/Encoder.ts +++ b/src/json-crdt/codec/structural/verbose/Encoder.ts @@ -1,9 +1,10 @@ import * as nodes from '../../../nodes'; import {toBase64} from '@jsonjoy.com/base64/lib/toBase64'; import {SESSION} from '../../../../json-crdt-patch/constants'; -import {ITimestampStruct, IClockVector, Timestamp} from '../../../../json-crdt-patch/clock'; -import {Model} from '../../../model'; +import {type ITimestampStruct, type IClockVector, Timestamp} from '../../../../json-crdt-patch/clock'; +import type {Model} from '../../../model'; import type * as types from './types'; +import type {Chunk} from '../../../nodes/rga'; export class Encoder { protected model!: Model; @@ -74,7 +75,7 @@ export class Encoder { public cArr(obj: nodes.ArrNode): types.JsonCrdtVerboseArr { const chunks: (types.JsonCrdtVerboseArrChunk | types.JsonCrdtVerboseTombstone)[] = []; const iterator = obj.iterator(); - let chunk; + let chunk: Chunk | undefined; while ((chunk = iterator())) chunks.push(this.cArrChunk(chunk)); return { type: 'arr', @@ -102,7 +103,7 @@ export class Encoder { public cStr(obj: nodes.StrNode): types.JsonCrdtVerboseStr { const chunks: (types.JsonCrdtVerboseStrChunk | types.JsonCrdtVerboseTombstone)[] = []; const iterator = obj.iterator(); - let chunk; + let chunk: ReturnType; while ((chunk = iterator())) chunks.push(this.cStrChunk(chunk as nodes.StrChunk)); return { type: 'str', @@ -129,7 +130,7 @@ export class Encoder { public cBin(obj: nodes.BinNode): types.JsonCrdtVerboseBin { const chunks: (types.JsonCrdtVerboseBinChunk | types.JsonCrdtVerboseTombstone)[] = []; const iterator = obj.iterator(); - let chunk; + let chunk: ReturnType; while ((chunk = iterator())) chunks.push(this.cBinChunk(chunk as nodes.BinChunk)); return { type: 'bin', diff --git a/src/json-crdt/codec/structural/verbose/__tests__/all-types-smoketest.spec.ts b/src/json-crdt/codec/structural/verbose/__tests__/all-types-smoketest.spec.ts index 96f2af05aa..36d85cae36 100644 --- a/src/json-crdt/codec/structural/verbose/__tests__/all-types-smoketest.spec.ts +++ b/src/json-crdt/codec/structural/verbose/__tests__/all-types-smoketest.spec.ts @@ -1,4 +1,4 @@ -import {Model} from '../../../../model'; +import type {Model} from '../../../../model'; import {runCodecAllTypesSmokeTests} from './runCodecAllTypesSmokeTests'; import {Encoder} from '../Encoder'; import {Decoder} from '../Decoder'; diff --git a/src/json-crdt/constants.ts b/src/json-crdt/constants.ts index 739d9e4317..39b6799810 100644 --- a/src/json-crdt/constants.ts +++ b/src/json-crdt/constants.ts @@ -1,3 +1,3 @@ -export const enum CRDT_CONSTANTS { +export enum CRDT_CONSTANTS { MAX_TUPLE_LENGTH = 255, } diff --git a/src/json-crdt/draft/Draft.ts b/src/json-crdt/draft/Draft.ts index 8a3a9356b4..d4cbdb77aa 100644 --- a/src/json-crdt/draft/Draft.ts +++ b/src/json-crdt/draft/Draft.ts @@ -1,5 +1,5 @@ -import {Patch} from '../../json-crdt-patch'; -import {Model} from '../model'; +import type {Patch} from '../../json-crdt-patch'; +import type {Model} from '../model'; /** * Terminology: diff --git a/src/json-crdt/json-patch/JsonPatch.ts b/src/json-crdt/json-patch/JsonPatch.ts index 9f84b6099c..9ffc196198 100644 --- a/src/json-crdt/json-patch/JsonPatch.ts +++ b/src/json-crdt/json-patch/JsonPatch.ts @@ -1,8 +1,8 @@ import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; -import {ObjNode, ArrNode, JsonNode, ConNode} from '../nodes'; +import {ObjNode, ArrNode, type JsonNode, ConNode} from '../nodes'; import {toPath, isChild} from '@jsonjoy.com/json-pointer/lib/util'; import {interval} from '../../json-crdt-patch/clock'; -import {PatchBuilder} from '../../json-crdt-patch/PatchBuilder'; +import type {PatchBuilder} from '../../json-crdt-patch/PatchBuilder'; import type {Path} from '@jsonjoy.com/json-pointer/lib/types'; import type {Model} from '../model'; import type {Operation} from '../../json-patch'; diff --git a/src/json-crdt/json-patch/JsonPatchStore.ts b/src/json-crdt/json-patch/JsonPatchStore.ts index 6218670473..9e3f877278 100644 --- a/src/json-crdt/json-patch/JsonPatchStore.ts +++ b/src/json-crdt/json-patch/JsonPatchStore.ts @@ -1,5 +1,5 @@ -import {SyncStore} from '../../util/events/sync-store'; -import {JsonNodeApi} from '../model/api/types'; +import type {SyncStore} from '../../util/events/sync-store'; +import type {JsonNodeApi} from '../model/api/types'; import {JsonPatch} from './JsonPatch'; import {toPath} from '@jsonjoy.com/json-pointer/lib/util'; import type {Path} from '@jsonjoy.com/json-pointer/lib/types'; diff --git a/src/json-crdt/json-patch/__tests__/JsonPatch.automated.spec.ts b/src/json-crdt/json-patch/__tests__/JsonPatch.automated.spec.ts index 8abfe60479..90ab691311 100644 --- a/src/json-crdt/json-patch/__tests__/JsonPatch.automated.spec.ts +++ b/src/json-crdt/json-patch/__tests__/JsonPatch.automated.spec.ts @@ -1,4 +1,4 @@ -import {Operation} from '../../../json-patch'; +import type {Operation} from '../../../json-patch'; import {Model} from '../../model/Model'; import {JsonPatch} from '../JsonPatch'; diff --git a/src/json-crdt/json-patch/__tests__/JsonPatch.str.spec.ts b/src/json-crdt/json-patch/__tests__/JsonPatch.str.spec.ts index 5c52362bc2..7651c550e9 100644 --- a/src/json-crdt/json-patch/__tests__/JsonPatch.str.spec.ts +++ b/src/json-crdt/json-patch/__tests__/JsonPatch.str.spec.ts @@ -1,4 +1,4 @@ -import {Operation} from '../../../json-patch'; +import type {Operation} from '../../../json-patch'; import {Model} from '../../model/Model'; import {JsonPatch} from '../JsonPatch'; diff --git a/src/json-crdt/log/Log.ts b/src/json-crdt/log/Log.ts index fd0e9f4845..470fe3fb84 100644 --- a/src/json-crdt/log/Log.ts +++ b/src/json-crdt/log/Log.ts @@ -1,8 +1,8 @@ import {AvlMap} from 'sonic-forest/lib/avl/AvlMap'; import {first, next} from 'sonic-forest/lib/util'; -import {FanOutUnsubscribe} from 'thingies/lib/fanout'; +import type {FanOutUnsubscribe} from 'thingies/lib/fanout'; import {printTree} from 'tree-dump/lib/printTree'; -import {ITimestampStruct, Patch, compare} from '../../json-crdt-patch'; +import {type ITimestampStruct, type Patch, compare} from '../../json-crdt-patch'; import {Model} from '../model'; import type {Printable} from 'tree-dump/lib/types'; import type {JsonNode} from '../nodes/types'; @@ -141,11 +141,12 @@ export class Log> implements Printable { public toString(tab?: string) { const patches: Patch[] = []; + // biome-ignore lint: patches are not iterable this.patches.forEach(({v}) => patches.push(v)); return ( - `log` + + 'log' + printTree(tab, [ - (tab) => `start` + printTree(tab, [(tab) => this.start().toString(tab)]), + (tab) => 'start' + printTree(tab, [(tab) => this.start().toString(tab)]), () => '', (tab) => 'history' + @@ -154,7 +155,7 @@ export class Log> implements Printable { patches.map((patch, i) => (tab) => `${i}: ${patch.toString(tab)}`), ), () => '', - (tab) => `end` + printTree(tab, [(tab) => this.end.toString(tab)]), + (tab) => 'end' + printTree(tab, [(tab) => this.end.toString(tab)]), ]) ); } diff --git a/src/json-crdt/log/codec/LogEncoder.ts b/src/json-crdt/log/codec/LogEncoder.ts index fdad92794f..717cb32862 100644 --- a/src/json-crdt/log/codec/LogEncoder.ts +++ b/src/json-crdt/log/codec/LogEncoder.ts @@ -1,4 +1,4 @@ -import {Log} from '../Log'; +import type {Log} from '../Log'; import {FileModelEncoding} from './constants'; import type * as types from './types'; import type {CborEncoder} from '@jsonjoy.com/json-pack/lib/cbor/CborEncoder'; @@ -64,6 +64,7 @@ export class LogEncoder { switch (patchFormat) { case 'binary': { history[0] = log.start().toBinary(); + // biome-ignore lint: allow .forEach(), for now log.patches.forEach(({v}) => { history[1].push(v.toBinary()); }); @@ -76,6 +77,7 @@ export class LogEncoder { const encodeCompact = this.options.patchCompactEncoder; if (!encodeCompact) throw new Error('NO_COMPACT_PATCH_ENCODER'); const list = history[1]; + // biome-ignore lint: allow .forEach(), for now log.patches.forEach(({v}) => { list.push(encodeCompact(v)); }); @@ -88,6 +90,7 @@ export class LogEncoder { const encodeVerbose = this.options.patchVerboseEncoder; if (!encodeVerbose) throw new Error('NO_VERBOSE_PATCH_ENCODER'); const list = history[1]; + // biome-ignore lint: allow .forEach(), for now log.patches.forEach(({v}) => { list.push(encodeVerbose(v)); }); diff --git a/src/json-crdt/log/codec/__tests__/LogDecoder.spec.ts b/src/json-crdt/log/codec/__tests__/LogDecoder.spec.ts index 623f70afc7..f05049fa24 100644 --- a/src/json-crdt/log/codec/__tests__/LogDecoder.spec.ts +++ b/src/json-crdt/log/codec/__tests__/LogDecoder.spec.ts @@ -1,7 +1,7 @@ import {Log} from '../../Log'; import {Model} from '../../../model'; import {logEncoderOpts} from '../logEncoderOpts'; -import {EncodingParams, LogEncoder} from '../LogEncoder'; +import {type EncodingParams, LogEncoder} from '../LogEncoder'; import {LogDecoder} from '../LogDecoder'; import {logDecoderOpts} from '../logDecoderOpts'; diff --git a/src/json-crdt/log/codec/constants.ts b/src/json-crdt/log/codec/constants.ts index 912083d9dd..7b9db9f8ec 100644 --- a/src/json-crdt/log/codec/constants.ts +++ b/src/json-crdt/log/codec/constants.ts @@ -1,4 +1,4 @@ -export const enum FileModelEncoding { +export enum FileModelEncoding { Auto = 0, SidecarBinary = 1, } diff --git a/src/json-crdt/log/codec/types.ts b/src/json-crdt/log/codec/types.ts index 2b278ad8ca..0124c86c9f 100644 --- a/src/json-crdt/log/codec/types.ts +++ b/src/json-crdt/log/codec/types.ts @@ -1,6 +1,10 @@ import type {FileModelEncoding} from './constants'; -export type LogMetadata = [map: {}, modelFormat: FileModelEncoding]; +export type LogMetadata = [ + // biome-ignore lint: allow brackets + map: {}, + modelFormat: FileModelEncoding, +]; export type LogComponents = [ view: unknown | null, diff --git a/src/json-crdt/model/Model.ts b/src/json-crdt/model/Model.ts index 84417d1492..aec205165e 100644 --- a/src/json-crdt/model/Model.ts +++ b/src/json-crdt/model/Model.ts @@ -2,15 +2,15 @@ import * as operations from '../../json-crdt-patch/operations'; import * as clock from '../../json-crdt-patch/clock'; import {ConNode} from '../nodes/const/ConNode'; import {encoder, decoder} from '../codec/structural/binary/shared'; -import {JsonCrdtPatchOperation, Patch} from '../../json-crdt-patch/Patch'; import {ModelApi} from './api/ModelApi'; import {ORIGIN, SESSION, SYSTEM_SESSION_TIME} from '../../json-crdt-patch/constants'; import {randomSessionId} from './util'; import {RootNode, ValNode, VecNode, ObjNode, StrNode, BinNode, ArrNode} from '../nodes'; -import {SchemaToJsonNode} from '../schema/types'; +import type {SchemaToJsonNode} from '../schema/types'; import {printTree} from 'tree-dump/lib/printTree'; import {Extensions} from '../extensions/Extensions'; import {AvlMap} from 'sonic-forest/lib/avl/AvlMap'; +import type {JsonCrdtPatchOperation, Patch} from '../../json-crdt-patch/Patch'; import type {JsonNode, JsonNodeView} from '../nodes/types'; import type {Printable} from 'tree-dump/lib/types'; import type {NodeBuilder} from '../../json-crdt-patch'; @@ -519,6 +519,7 @@ export class Model> implements Printable { api.flush(); api.builder.clock = this.clock; } + // biome-ignore lint: index is not iterable index.forEach(({v: node}) => { const api = node.api as NodeApi | undefined; if (!api) return; @@ -607,6 +608,7 @@ export class Model> implements Printable { nl, (tab) => { const nodes: JsonNode[] = []; + // biome-ignore lint: index is not iterable this.index.forEach((item) => nodes.push(item.v)); return ( `index (${nodes.length} nodes)` + diff --git a/src/json-crdt/model/__tests__/Model.root.spec.ts b/src/json-crdt/model/__tests__/Model.root.spec.ts index 61cdc10063..0f5654a28f 100644 --- a/src/json-crdt/model/__tests__/Model.root.spec.ts +++ b/src/json-crdt/model/__tests__/Model.root.spec.ts @@ -4,12 +4,12 @@ import {Model} from '../Model'; describe('Document', () => { describe('root', () => { test('default root value is undefined', () => { - const doc = Model.withLogicalClock(); + const doc = Model.create(); expect(doc.view()).toBe(undefined); }); test('can set root value to "true"', () => { - const doc = Model.withLogicalClock(); + const doc = Model.create(); const builder = new PatchBuilder(doc.clock); const t = builder.json(true); builder.root(t); @@ -18,7 +18,7 @@ describe('Document', () => { }); test('can set root value to "false"', () => { - const doc = Model.withLogicalClock(); + const doc = Model.create(); const builder = new PatchBuilder(doc.clock); const t = builder.json(true); const f = builder.json(false); @@ -29,7 +29,7 @@ describe('Document', () => { }); test('can set root value to "null"', () => { - const doc = Model.withLogicalClock(); + const doc = Model.create(); const builder = new PatchBuilder(doc.clock); const t = builder.json(true); const f = builder.json(false); diff --git a/src/json-crdt/model/__tests__/Model.setSchema.spec.ts b/src/json-crdt/model/__tests__/Model.setSchema.spec.ts index fc0064e523..0bc64fe50e 100644 --- a/src/json-crdt/model/__tests__/Model.setSchema.spec.ts +++ b/src/json-crdt/model/__tests__/Model.setSchema.spec.ts @@ -1,4 +1,4 @@ -import {nodes, s} from '../../../json-crdt-patch'; +import {type nodes, s} from '../../../json-crdt-patch'; import {SESSION} from '../../../json-crdt-patch/constants'; import {Model} from '../Model'; diff --git a/src/json-crdt/model/api/ModelApi.ts b/src/json-crdt/model/api/ModelApi.ts index e92d658244..5aa5b95458 100644 --- a/src/json-crdt/model/api/ModelApi.ts +++ b/src/json-crdt/model/api/ModelApi.ts @@ -1,9 +1,9 @@ import {FanOut} from 'thingies/lib/fanout'; import {VecNode, ConNode, ObjNode, ArrNode, BinNode, StrNode, ValNode} from '../../nodes'; -import {ApiPath, ArrApi, BinApi, ConApi, NodeApi, ObjApi, StrApi, VecApi, ValApi} from './nodes'; -import {Patch} from '../../../json-crdt-patch/Patch'; +import {type ApiPath, ArrApi, BinApi, ConApi, type NodeApi, ObjApi, StrApi, VecApi, ValApi} from './nodes'; +import type {Patch} from '../../../json-crdt-patch/Patch'; import {PatchBuilder} from '../../../json-crdt-patch/PatchBuilder'; -import {SyncStore} from '../../../util/events/sync-store'; +import type {SyncStore} from '../../../util/events/sync-store'; import {MergeFanOut, MicrotaskBufferFanOut} from './fanout'; import {ExtNode} from '../../extensions/ExtNode'; import type {Model} from '../Model'; @@ -50,9 +50,13 @@ export class ModelApi implements SyncStore(); /** Emitted when the model changes. Combines `onReset`, `onPatch` and `onLocalChange`. */ - public readonly onChange = new MergeFanOut([this.onReset, this.onPatch, this.onLocalChange]); + public readonly onChange = new MergeFanOut([ + this.onReset, + this.onPatch, + this.onLocalChange, + ]); /** Emitted when the model changes. Same as `.onChange`, but this event is emitted once per microtask. */ - public readonly onChanges = new MicrotaskBufferFanOut(this.onChange); + public readonly onChanges = new MicrotaskBufferFanOut(this.onChange); /** Emitted when the `model.api` builder change buffer is flushed. */ public readonly onFlush = new FanOut(); diff --git a/src/json-crdt/model/api/NodeEvents.ts b/src/json-crdt/model/api/NodeEvents.ts index 4321d91096..31a7bc3df7 100644 --- a/src/json-crdt/model/api/NodeEvents.ts +++ b/src/json-crdt/model/api/NodeEvents.ts @@ -1,4 +1,4 @@ -import {FanOut} from 'thingies/lib/fanout'; +import type {FanOut} from 'thingies/lib/fanout'; import {MapFanOut, OnNewFanOut} from './fanout'; import type {JsonNode, JsonNodeView} from '../../nodes'; import type {SyncStore, SyncStoreUnsubscribe} from '../../../util/events/sync-store'; diff --git a/src/json-crdt/model/api/__tests__/ModelApi.proxy.spec.ts b/src/json-crdt/model/api/__tests__/ModelApi.proxy.spec.ts index eb3c715de9..d52c17e2a1 100644 --- a/src/json-crdt/model/api/__tests__/ModelApi.proxy.spec.ts +++ b/src/json-crdt/model/api/__tests__/ModelApi.proxy.spec.ts @@ -1,8 +1,8 @@ import {Model} from '../../Model'; import {ConApi, ObjApi, StrApi, VecApi, ValApi, ArrApi, BinApi} from '../nodes'; -import {ConNode, RootNode, ObjNode, StrNode, ValNode} from '../../../nodes'; +import {ConNode, RootNode, ObjNode, StrNode, type ValNode} from '../../../nodes'; import {s} from '../../../../json-crdt-patch'; -import {ProxyNodeVal} from '../proxy'; +import type {ProxyNodeVal} from '../proxy'; test('proxy API supports object types', () => { const model = Model.withLogicalClock() as any as Model< diff --git a/src/json-crdt/model/api/__tests__/StrApi.spec.ts b/src/json-crdt/model/api/__tests__/StrApi.spec.ts index d88c7ff3e7..db2b7b73b5 100644 --- a/src/json-crdt/model/api/__tests__/StrApi.spec.ts +++ b/src/json-crdt/model/api/__tests__/StrApi.spec.ts @@ -1,5 +1,5 @@ import {s} from '../../../../json-crdt-patch'; -import {ITimestampStruct} from '../../../../json-crdt-patch/clock'; +import type {ITimestampStruct} from '../../../../json-crdt-patch/clock'; import {Model} from '../../Model'; test('can edit a simple string', () => { diff --git a/src/json-crdt/model/api/fanout.ts b/src/json-crdt/model/api/fanout.ts index 5f8fec98bf..5bfa64f428 100644 --- a/src/json-crdt/model/api/fanout.ts +++ b/src/json-crdt/model/api/fanout.ts @@ -1,4 +1,4 @@ -import {FanOut, FanOutUnsubscribe, FanOutListener} from 'thingies/lib/fanout'; +import {FanOut, type FanOutUnsubscribe, type FanOutListener} from 'thingies/lib/fanout'; /** * Merges multiple fanouts into a single fanout. The merged fanout emits the @@ -17,7 +17,7 @@ export class MergeFanOut extends FanOut { return () => { unsub(); if (!this.listeners.size) { - this.unsubs.forEach((unsub) => unsub()); + for (const unsub of this.unsubs) unsub(); this.unsubs = []; } }; diff --git a/src/json-crdt/model/api/find.ts b/src/json-crdt/model/api/find.ts index f88ff33291..425f19fc4e 100644 --- a/src/json-crdt/model/api/find.ts +++ b/src/json-crdt/model/api/find.ts @@ -1,4 +1,4 @@ -import {Path, toPath} from '@jsonjoy.com/json-pointer'; +import {type Path, toPath} from '@jsonjoy.com/json-pointer'; import {VecNode, ObjNode, ArrNode} from '../../nodes'; import type {JsonNode} from '../../nodes'; diff --git a/src/json-crdt/model/api/nodes.ts b/src/json-crdt/model/api/nodes.ts index 83bcf0f8c6..e9013b156b 100644 --- a/src/json-crdt/model/api/nodes.ts +++ b/src/json-crdt/model/api/nodes.ts @@ -1,7 +1,7 @@ import {printTree} from 'tree-dump/lib/printTree'; import {find} from './find'; -import {ITimestampStruct, Timestamp} from '../../../json-crdt-patch/clock'; -import {Path} from '@jsonjoy.com/json-pointer'; +import {type ITimestampStruct, Timestamp} from '../../../json-crdt-patch/clock'; +import type {Path} from '@jsonjoy.com/json-pointer'; import {ObjNode, ArrNode, BinNode, ConNode, VecNode, ValNode, StrNode, RootNode} from '../../nodes'; import {NodeEvents} from './NodeEvents'; import {ExtNode} from '../../extensions/ExtNode'; @@ -14,7 +14,7 @@ import type {Printable} from 'tree-dump/lib/types'; import type {JsonNodeApi} from './types'; import type {VecNodeExtensionData} from '../../schema/types'; -export type ApiPath = string | number | Path | void; +export type ApiPath = string | number | Path | undefined; /** * A generic local changes API for a JSON CRDT node. diff --git a/src/json-crdt/nodes/arr/ArrNode.ts b/src/json-crdt/nodes/arr/ArrNode.ts index 65499053ed..6792b3c4e8 100644 --- a/src/json-crdt/nodes/arr/ArrNode.ts +++ b/src/json-crdt/nodes/arr/ArrNode.ts @@ -1,6 +1,6 @@ -import {AbstractRga, Chunk} from '../rga/AbstractRga'; -import {ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; -import {Model} from '../../model'; +import {AbstractRga, type Chunk} from '../rga/AbstractRga'; +import {type ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; +import type {Model} from '../../model'; import {printBinary} from 'tree-dump/lib/printBinary'; import {printTree} from 'tree-dump/lib/printTree'; import type {JsonNode, JsonNodeView} from '..'; diff --git a/src/json-crdt/nodes/arr/__tests__/ArrNode.spec.ts b/src/json-crdt/nodes/arr/__tests__/ArrNode.spec.ts index 6faf4f5231..03d59648a2 100644 --- a/src/json-crdt/nodes/arr/__tests__/ArrNode.spec.ts +++ b/src/json-crdt/nodes/arr/__tests__/ArrNode.spec.ts @@ -1,9 +1,9 @@ import {PatchBuilder} from '../../../../json-crdt-patch/PatchBuilder'; import {Model} from '../../../model'; -import {ArrNode} from '../ArrNode'; +import type {ArrNode} from '../ArrNode'; test('can insert two booleans into an array', () => { - const doc = Model.withLogicalClock(); + const doc = Model.create(); const builder1 = new PatchBuilder(doc.clock); const arr = builder1.arr(); @@ -17,11 +17,11 @@ test('can insert two booleans into an array', () => { const builder3 = new PatchBuilder(doc.clock); const f = builder3.const(false); - const ins2 = builder3.insArr(arr, ins1, [f]); + builder3.insArr(arr, ins1, [f]); doc.applyPatch(builder3.patch); const node = doc.index.get(arr) as ArrNode; - const firstChunk = node.first(); + node.first(); expect(node.length()).toBe(2); expect(doc.view()).toEqual([true, false]); diff --git a/src/json-crdt/nodes/bin/BinNode.ts b/src/json-crdt/nodes/bin/BinNode.ts index a30fe16c19..c26e8242fc 100644 --- a/src/json-crdt/nodes/bin/BinNode.ts +++ b/src/json-crdt/nodes/bin/BinNode.ts @@ -1,6 +1,6 @@ import type {JsonNode} from '..'; -import {ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; -import {AbstractRga, Chunk} from '../rga/AbstractRga'; +import {type ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; +import {AbstractRga, type Chunk} from '../rga/AbstractRga'; /** * @ignore diff --git a/src/json-crdt/nodes/bin/__tests__/BinNode.fuzzing.spec.ts b/src/json-crdt/nodes/bin/__tests__/BinNode.fuzzing.spec.ts index 4edf96f900..159e20c7c8 100644 --- a/src/json-crdt/nodes/bin/__tests__/BinNode.fuzzing.spec.ts +++ b/src/json-crdt/nodes/bin/__tests__/BinNode.fuzzing.spec.ts @@ -1,6 +1,6 @@ /* tslint:disable no-console */ -import {ITimespanStruct, ITimestampStruct, ts} from '../../../../json-crdt-patch/clock'; +import {type ITimespanStruct, type ITimestampStruct, ts} from '../../../../json-crdt-patch/clock'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {BinNode} from '../BinNode'; import {randomU32} from 'hyperdyperid/lib/randomU32'; diff --git a/src/json-crdt/nodes/bin/__tests__/BinNode.spec.ts b/src/json-crdt/nodes/bin/__tests__/BinNode.spec.ts index acfd1f124d..d6a61e742c 100644 --- a/src/json-crdt/nodes/bin/__tests__/BinNode.spec.ts +++ b/src/json-crdt/nodes/bin/__tests__/BinNode.spec.ts @@ -1,7 +1,7 @@ import {tick} from '../../../../json-crdt-patch/clock'; import {PatchBuilder} from '../../../../json-crdt-patch/PatchBuilder'; import {Model} from '../../../model'; -import {BinNode} from '../BinNode'; +import type {BinNode} from '../BinNode'; test('merges sequential chunks', () => { const doc = Model.withLogicalClock(); diff --git a/src/json-crdt/nodes/obj/ObjNode.ts b/src/json-crdt/nodes/obj/ObjNode.ts index 67691c71a2..eef679f5e3 100644 --- a/src/json-crdt/nodes/obj/ObjNode.ts +++ b/src/json-crdt/nodes/obj/ObjNode.ts @@ -1,5 +1,5 @@ import {printTree} from 'tree-dump/lib/printTree'; -import {compare, ITimestampStruct, printTs} from '../../../json-crdt-patch/clock'; +import {compare, type ITimestampStruct, printTs} from '../../../json-crdt-patch/clock'; import type {Model} from '../../model'; import type {Printable} from 'tree-dump/lib/types'; import type {JsonNode, JsonNodeView} from '..'; diff --git a/src/json-crdt/nodes/rga/AbstractRga.ts b/src/json-crdt/nodes/rga/AbstractRga.ts index 0d3aebfa68..758a0167ca 100644 --- a/src/json-crdt/nodes/rga/AbstractRga.ts +++ b/src/json-crdt/nodes/rga/AbstractRga.ts @@ -1,8 +1,8 @@ import { compare, tick, - ITimestampStruct, - ITimespanStruct, + type ITimestampStruct, + type ITimespanStruct, tss, printTs, containsId, @@ -88,7 +88,7 @@ const next = (curr: Chunk): Chunk | undefined => { const r = curr.r; if (r) { curr = r; - let tmp; + let tmp: Chunk | undefined; while ((tmp = curr.l)) curr = tmp; return curr; } @@ -104,7 +104,7 @@ const prev = (curr: Chunk): Chunk | undefined => { const l = curr.l; if (l) { curr = l; - let tmp; + let tmp: Chunk | undefined; while ((tmp = curr.r)) curr = tmp; return curr; } diff --git a/src/json-crdt/nodes/root/RootNode.ts b/src/json-crdt/nodes/root/RootNode.ts index 36a741bfb4..bc13a46ebe 100644 --- a/src/json-crdt/nodes/root/RootNode.ts +++ b/src/json-crdt/nodes/root/RootNode.ts @@ -1,6 +1,6 @@ import {ORIGIN} from '../../../json-crdt-patch/constants'; import {ValNode} from '../val/ValNode'; -import {Model} from '../../model/Model'; +import type {Model} from '../../model/Model'; import type {ITimestampStruct} from '../../../json-crdt-patch/clock'; import type {JsonNode} from '../types'; diff --git a/src/json-crdt/nodes/str/StrNode.ts b/src/json-crdt/nodes/str/StrNode.ts index ec2d5614fb..e6faece7f4 100644 --- a/src/json-crdt/nodes/str/StrNode.ts +++ b/src/json-crdt/nodes/str/StrNode.ts @@ -1,5 +1,5 @@ -import {ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; -import {AbstractRga, Chunk} from '../rga/AbstractRga'; +import {type ITimestampStruct, tick} from '../../../json-crdt-patch/clock'; +import {AbstractRga, type Chunk} from '../rga/AbstractRga'; import {next} from 'sonic-forest/lib/util'; import type {JsonNode} from '..'; diff --git a/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-2.spec.ts b/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-2.spec.ts index ff90e4ae19..58b15fbcc1 100644 --- a/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-2.spec.ts +++ b/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-2.spec.ts @@ -1,6 +1,6 @@ /* tslint:disable no-console */ -import {ITimespanStruct, ITimestampStruct, ts} from '../../../../json-crdt-patch/clock'; +import {type ITimespanStruct, type ITimestampStruct, ts} from '../../../../json-crdt-patch/clock'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {StrNode} from '../StrNode'; import {randomU32} from 'hyperdyperid/lib/randomU32'; diff --git a/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-multiuser.spec.ts b/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-multiuser.spec.ts index fd005217c7..46f3872b54 100644 --- a/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-multiuser.spec.ts +++ b/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing-multiuser.spec.ts @@ -1,4 +1,4 @@ -import {StrNodeFuzzer, StrNodeFuzzerOptions} from './StrNodeFuzzer'; +import {StrNodeFuzzer, type StrNodeFuzzerOptions} from './StrNodeFuzzer'; const execute = (times: number, options?: Partial) => { for (let i = 0; i < times; i++) { diff --git a/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing.spec.ts b/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing.spec.ts index 4a33f2859f..c857dba448 100644 --- a/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing.spec.ts +++ b/src/json-crdt/nodes/str/__tests__/StrNode.fuzzing.spec.ts @@ -1,6 +1,6 @@ /* tslint:disable no-console */ -import {ITimespanStruct, ITimestampStruct, ts} from '../../../../json-crdt-patch/clock'; +import {type ITimespanStruct, type ITimestampStruct, ts} from '../../../../json-crdt-patch/clock'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {StrNode} from '../StrNode'; import {randomU32} from 'hyperdyperid/lib/randomU32'; diff --git a/src/json-crdt/nodes/str/__tests__/StrNode.spec.ts b/src/json-crdt/nodes/str/__tests__/StrNode.spec.ts index 449672cb55..79c0c5703e 100644 --- a/src/json-crdt/nodes/str/__tests__/StrNode.spec.ts +++ b/src/json-crdt/nodes/str/__tests__/StrNode.spec.ts @@ -1,7 +1,7 @@ /* tslint:disable no-console */ import {StrNode, StrChunk} from '../StrNode'; -import {equal, ITimespanStruct, ITimestampStruct, tick, ts, tss} from '../../../../json-crdt-patch/clock'; +import {equal, type ITimespanStruct, type ITimestampStruct, tick, ts, tss} from '../../../../json-crdt-patch/clock'; import {prev} from 'sonic-forest/lib/util'; /** Validates that .find() method returns correct timestamp for every position. */ diff --git a/src/json-crdt/nodes/str/__tests__/StrNodeFuzzer.ts b/src/json-crdt/nodes/str/__tests__/StrNodeFuzzer.ts index faa9f2d77f..9cc5a33e0d 100644 --- a/src/json-crdt/nodes/str/__tests__/StrNodeFuzzer.ts +++ b/src/json-crdt/nodes/str/__tests__/StrNodeFuzzer.ts @@ -1,9 +1,9 @@ import {equal} from 'assert'; -import {ITimespanStruct, ITimestampStruct, ClockVector, printTs, ts} from '../../../../json-crdt-patch/clock'; +import {type ITimespanStruct, type ITimestampStruct, ClockVector, printTs, ts} from '../../../../json-crdt-patch/clock'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {randomSessionId} from '../../../model/util'; import {StrNode} from '../StrNode'; -import {printTree, Printable} from 'tree-dump'; +import {printTree, type Printable} from 'tree-dump'; const printOp = (op: Op) => { if ('content' in op) { diff --git a/src/json-crdt/nodes/val/ValNode.ts b/src/json-crdt/nodes/val/ValNode.ts index 4df353c506..4ff9626ef4 100644 --- a/src/json-crdt/nodes/val/ValNode.ts +++ b/src/json-crdt/nodes/val/ValNode.ts @@ -1,4 +1,4 @@ -import {compare, ITimestampStruct, printTs} from '../../../json-crdt-patch/clock'; +import {compare, type ITimestampStruct, printTs} from '../../../json-crdt-patch/clock'; import {SESSION} from '../../../json-crdt-patch/constants'; import {printTree} from 'tree-dump/lib/printTree'; import {UNDEFINED} from '../../model/Model'; diff --git a/src/json-crdt/nodes/vec/VecNode.ts b/src/json-crdt/nodes/vec/VecNode.ts index f2c37ad228..ed07859624 100644 --- a/src/json-crdt/nodes/vec/VecNode.ts +++ b/src/json-crdt/nodes/vec/VecNode.ts @@ -1,7 +1,7 @@ import {ConNode} from '../const/ConNode'; import {CRDT_CONSTANTS} from '../../constants'; import {printTree} from 'tree-dump/lib/printTree'; -import {compare, ITimestampStruct, printTs} from '../../../json-crdt-patch/clock'; +import {compare, type ITimestampStruct, printTs} from '../../../json-crdt-patch/clock'; import type {Model} from '../../model'; import type {JsonNode, JsonNodeView} from '..'; import type {Printable} from 'tree-dump/lib/types'; diff --git a/src/json-crdt/nodes/vec/__tests__/VecNode-extension.spec.ts b/src/json-crdt/nodes/vec/__tests__/VecNode-extension.spec.ts index e8b3fb2824..fce7dd4b21 100644 --- a/src/json-crdt/nodes/vec/__tests__/VecNode-extension.spec.ts +++ b/src/json-crdt/nodes/vec/__tests__/VecNode-extension.spec.ts @@ -1,8 +1,8 @@ import {s} from '../../../../json-crdt-patch'; import {printTree} from 'tree-dump'; -import {ExtApi} from '../../../extensions/types'; +import type {ExtApi} from '../../../extensions/types'; import {Model, NodeApi} from '../../../model'; -import {StrNode} from '../../nodes'; +import type {StrNode} from '../../nodes'; import {Extension} from '../../../extensions/Extension'; import {ExtNode} from '../../../extensions/ExtNode'; diff --git a/src/json-crdt/partial-edit/PartialEdit.ts b/src/json-crdt/partial-edit/PartialEdit.ts index bc8dc2b7c7..701e2381fd 100644 --- a/src/json-crdt/partial-edit/PartialEdit.ts +++ b/src/json-crdt/partial-edit/PartialEdit.ts @@ -1,8 +1,8 @@ -import {Patch} from '../../json-crdt-patch'; +import type {Patch} from '../../json-crdt-patch'; import {ClockTable} from '../../json-crdt-patch/codec/clock/ClockTable'; -import {Decoder} from '../codec/indexed/binary/Decoder'; -import {Encoder} from '../codec/indexed/binary/Encoder'; -import {IndexedFields, FieldName, IndexedNodeFields} from '../codec/indexed/binary/types'; +import type {Decoder} from '../codec/indexed/binary/Decoder'; +import type {Encoder} from '../codec/indexed/binary/Encoder'; +import type {IndexedFields, FieldName, IndexedNodeFields} from '../codec/indexed/binary/types'; import {PartialEditModel} from './PartialEditModel'; import type {IJsonCrdtPatchEditOperation} from '../../json-crdt-patch/types'; import type {FieldEdits} from './types'; diff --git a/src/json-crdt/partial-edit/PartialEditFactory.ts b/src/json-crdt/partial-edit/PartialEditFactory.ts index 6b0a053c9d..f7e359bb98 100644 --- a/src/json-crdt/partial-edit/PartialEditFactory.ts +++ b/src/json-crdt/partial-edit/PartialEditFactory.ts @@ -1,7 +1,7 @@ import {ClockTable} from '../../json-crdt-patch/codec/clock/ClockTable'; -import {Decoder} from '../codec/indexed/binary/Decoder'; -import {Encoder} from '../codec/indexed/binary/Encoder'; -import {IndexedFields} from '../codec/indexed/binary/types'; +import type {Decoder} from '../codec/indexed/binary/Decoder'; +import type {Encoder} from '../codec/indexed/binary/Encoder'; +import type {IndexedFields} from '../codec/indexed/binary/types'; import {PartialEdit} from './PartialEdit'; export class PartialEditFactory { diff --git a/src/json-crdt/partial-edit/PartialEditModel.ts b/src/json-crdt/partial-edit/PartialEditModel.ts index f45699993a..6b3738338f 100644 --- a/src/json-crdt/partial-edit/PartialEditModel.ts +++ b/src/json-crdt/partial-edit/PartialEditModel.ts @@ -1,4 +1,4 @@ -import {ITimestampStruct} from '../../json-crdt-patch/clock'; +import type {ITimestampStruct} from '../../json-crdt-patch/clock'; import {Model} from '../model/Model'; export class PartialEditModel extends Model { diff --git a/src/json-crdt/partial-edit/__tests__/scenario.spec.ts b/src/json-crdt/partial-edit/__tests__/scenario.spec.ts index 194b6d7a15..1414c5e484 100644 --- a/src/json-crdt/partial-edit/__tests__/scenario.spec.ts +++ b/src/json-crdt/partial-edit/__tests__/scenario.spec.ts @@ -2,7 +2,7 @@ import {PartialEditFactory} from '../PartialEditFactory'; import {Encoder} from '../../codec/indexed/binary/Encoder'; import {Decoder} from '../../codec/indexed/binary/Decoder'; import {Model} from '../../model'; -import {FieldName, IndexedNodeFields} from '../../codec/indexed/binary/types'; +import type {FieldName, IndexedNodeFields} from '../../codec/indexed/binary/types'; const encoder = new Encoder(); const decoder = new Decoder(); diff --git a/src/json-crdt/schema/__tests__/toSchema.spec.ts b/src/json-crdt/schema/__tests__/toSchema.spec.ts index 1e0c7759b3..238ff14465 100644 --- a/src/json-crdt/schema/__tests__/toSchema.spec.ts +++ b/src/json-crdt/schema/__tests__/toSchema.spec.ts @@ -1,4 +1,4 @@ -import {NodeBuilder, s, nodes} from '../../../json-crdt-patch'; +import {type NodeBuilder, s, nodes} from '../../../json-crdt-patch'; import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; import {cmpUint8Array} from '@jsonjoy.com/util/lib/buffers/cmpUint8Array'; import {Model} from '../../model'; diff --git a/src/json-crdt/schema/__tests__/types.spec.ts b/src/json-crdt/schema/__tests__/types.spec.ts index edb2519db3..7fd5dc60f6 100644 --- a/src/json-crdt/schema/__tests__/types.spec.ts +++ b/src/json-crdt/schema/__tests__/types.spec.ts @@ -1,7 +1,7 @@ import {s} from '../../../json-crdt-patch'; import * as ext from '../../../json-crdt-extensions/ext'; import {Model} from '../../model'; -import {JsonNodeToSchema, SchemaToJsonNode} from '../types'; +import type {JsonNodeToSchema, SchemaToJsonNode} from '../types'; describe('can infer schema of JSON CRDT nodes', () => { test('con', () => { diff --git a/src/json-crdt/schema/toSchema.ts b/src/json-crdt/schema/toSchema.ts index c21cb1faf5..857001b1bc 100644 --- a/src/json-crdt/schema/toSchema.ts +++ b/src/json-crdt/schema/toSchema.ts @@ -1,5 +1,5 @@ -import {JsonNode, ConNode, ValNode, ObjNode, VecNode, StrNode, BinNode, ArrNode} from '../nodes'; -import {NodeBuilder, s} from '../../json-crdt-patch'; +import {type JsonNode, ConNode, ValNode, ObjNode, VecNode, StrNode, BinNode, ArrNode} from '../nodes'; +import {type NodeBuilder, s} from '../../json-crdt-patch'; import type {JsonNodeToSchema} from './types'; /** diff --git a/src/json-crdt/schema/types.ts b/src/json-crdt/schema/types.ts index bf2df60013..a2703ebbd8 100644 --- a/src/json-crdt/schema/types.ts +++ b/src/json-crdt/schema/types.ts @@ -50,7 +50,7 @@ export type JsonNodeToSchema = N extends nodes.StrNode : N extends nodes.ValNode ? builder.val> : N extends nodes.VecNode - ? (T extends ExtensionVecData + ? T extends ExtensionVecData ? EDataNode extends PeritextNode ? builder.ext : EDataNode extends QuillDeltaNode @@ -58,7 +58,7 @@ export type JsonNodeToSchema = N extends nodes.StrNode : EDataNode extends MvalNode ? builder.ext : builder.ext - : builder.vec<{[K in keyof T]: JsonNodeToSchema}>) + : builder.vec<{[K in keyof T]: JsonNodeToSchema}> : N extends nodes.ObjNode ? builder.obj<{[K in keyof T]: JsonNodeToSchema}> : N extends nodes.ArrNode diff --git a/src/json-hash/index.ts b/src/json-hash/index.ts index d9657f0f19..8b0e32c74c 100644 --- a/src/json-hash/index.ts +++ b/src/json-hash/index.ts @@ -1,7 +1,7 @@ import type {JsonValue} from '@jsonjoy.com/json-pack/lib/types'; import {sort} from '@jsonjoy.com/util/lib/sort/insertion'; -export const enum CONST { +export enum CONST { START_STATE = 5381, NULL = 982452847, diff --git a/src/json-ot/__bench__/bench.ot-string.apply.ts b/src/json-ot/__bench__/bench.ot-string.apply.ts index 2704831839..3e34548384 100644 --- a/src/json-ot/__bench__/bench.ot-string.apply.ts +++ b/src/json-ot/__bench__/bench.ot-string.apply.ts @@ -1,8 +1,8 @@ /* tslint:disable no-console */ import * as Benchmark from 'benchmark'; -import {apply, validate, StringOp} from '../types/ot-string'; -import {validate as validate2, apply as apply2, StringOp as StringOp2} from '../types/ot-string-irreversible'; +import {apply, validate, type StringOp} from '../types/ot-string'; +import {validate as validate2, apply as apply2, type StringOp as StringOp2} from '../types/ot-string-irreversible'; const {type} = require('ot-text'); const {type: type2} = require('ot-text-unicode'); const {delta: d} = require('./util'); @@ -28,25 +28,25 @@ console.log(); const suite = new Benchmark.Suite(); suite - .add(`json-joy/json-ot ot-string`, () => { + .add('json-joy/json-ot ot-string', () => { validate(op1); apply(str, op1); }) - .add(`json-joy/json-ot ot-string (reversible)`, () => { + .add('json-joy/json-ot ot-string (reversible)', () => { validate(op2); apply(str, op2); }) - .add(`json-joy/json-ot ot-string-irreversible`, () => { + .add('json-joy/json-ot ot-string-irreversible', () => { validate2(op2 as any); apply2(str, op2 as any); }) - .add(`ottypes/ot-text`, () => { + .add('ottypes/ot-text', () => { type.apply(str, op3); }) - .add(`ottypes/ot-text-unicode`, () => { + .add('ottypes/ot-text-unicode', () => { type2.apply(str, op3); }) - .add(`quilljs/delta`, () => { + .add('quilljs/delta', () => { const delta = d.create(str); d.apply(delta, d.deserialize(deltaOp)); }) diff --git a/src/json-ot/__bench__/bench.ot-string.compose-and-transform.js b/src/json-ot/__bench__/bench.ot-string.compose-and-transform.js index 9bbeec0796..3c4cfed15b 100644 --- a/src/json-ot/__bench__/bench.ot-string.compose-and-transform.js +++ b/src/json-ot/__bench__/bench.ot-string.compose-and-transform.js @@ -39,28 +39,28 @@ console.log(); const suite = new Benchmark.Suite(); suite - .add(`json-joy/json-ot ot-string`, function () { + .add('json-joy/json-ot ot-string', () => { validate(op1a); validate(op1b); apply(apply(str, compose(op1a, op1b)), transform(op1a, op1b, true)); }) - .add(`json-joy/json-ot ot-string (reversible)`, function () { + .add('json-joy/json-ot ot-string (reversible)', () => { validate(op2a); validate(op2b); apply(apply(str, compose(op2a, op2b)), transform(op2a, op2b, true)); }) - .add(`json-joy/json-ot ot-string-irreversible`, function () { + .add('json-joy/json-ot ot-string-irreversible', () => { validate2(op1a); validate2(op1b); apply2(apply2(str, compose2(op1a, op1b)), transform2(op1a, op1b, true)); }) - .add(`ottypes/ot-text`, function () { + .add('ottypes/ot-text', () => { type.apply(type.apply(str, type.compose(op3a, op3b)), type.transform(op3a, op3b, 'left')); }) - .add(`ottypes/ot-text-unicode`, function () { + .add('ottypes/ot-text-unicode', () => { type2.apply(type2.apply(str, type2.compose(op3a, op3b)), type2.transform(op3a, op3b, 'left')); }) - .add(`quilljs/delta`, function () { + .add('quilljs/delta', () => { d.serialize( d.apply( d.apply(d.create(str), d.compose(d.deserialize(op4a), d.deserialize(op4b))), @@ -68,7 +68,7 @@ suite ), ); }) - .on('cycle', function (event) { + .on('cycle', (event) => { console.log(String(event.target) + `, ${Math.round(1000000000 / event.target.hz)} ns/op`); }) .on('complete', function () { diff --git a/src/json-ot/types/ot-binary-irreversible/__tests__/BinaryOtFuzzer.ts b/src/json-ot/types/ot-binary-irreversible/__tests__/BinaryOtFuzzer.ts index f06a4a1221..6e6a79fb05 100644 --- a/src/json-ot/types/ot-binary-irreversible/__tests__/BinaryOtFuzzer.ts +++ b/src/json-ot/types/ot-binary-irreversible/__tests__/BinaryOtFuzzer.ts @@ -1,7 +1,7 @@ import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {append, normalize} from '../util'; -import {BinaryOp} from '../types'; +import type {BinaryOp} from '../types'; export class BinaryOtFuzzer extends Fuzzer { genBinary(): Uint8Array { diff --git a/src/json-ot/types/ot-binary-irreversible/__tests__/compose.spec.ts b/src/json-ot/types/ot-binary-irreversible/__tests__/compose.spec.ts index 0122506eae..2e1e2ee545 100644 --- a/src/json-ot/types/ot-binary-irreversible/__tests__/compose.spec.ts +++ b/src/json-ot/types/ot-binary-irreversible/__tests__/compose.spec.ts @@ -1,6 +1,6 @@ import {compose} from '../compose'; import {apply} from '../apply'; -import {BinaryOp} from '../types'; +import type {BinaryOp} from '../types'; const b = (...octets: number[]) => new Uint8Array(octets); diff --git a/src/json-ot/types/ot-binary-irreversible/__tests__/transform.spec.ts b/src/json-ot/types/ot-binary-irreversible/__tests__/transform.spec.ts index 1b95e03576..bee352595e 100644 --- a/src/json-ot/types/ot-binary-irreversible/__tests__/transform.spec.ts +++ b/src/json-ot/types/ot-binary-irreversible/__tests__/transform.spec.ts @@ -1,6 +1,6 @@ import {transform} from '../transform'; import {apply} from '../apply'; -import {BinaryOp} from '../types'; +import type {BinaryOp} from '../types'; const b = (...octets: number[]) => new Uint8Array(octets); diff --git a/src/json-ot/types/ot-binary-irreversible/__tests__/util.spec.ts b/src/json-ot/types/ot-binary-irreversible/__tests__/util.spec.ts index 77813b1cec..311fd94fd1 100644 --- a/src/json-ot/types/ot-binary-irreversible/__tests__/util.spec.ts +++ b/src/json-ot/types/ot-binary-irreversible/__tests__/util.spec.ts @@ -1,5 +1,5 @@ import {normalize, append} from '../util'; -import {BinaryOp} from '../types'; +import type {BinaryOp} from '../types'; const b = (...octets: number[]) => new Uint8Array(octets); diff --git a/src/json-ot/types/ot-binary-irreversible/compose.ts b/src/json-ot/types/ot-binary-irreversible/compose.ts index 21a769c326..d26dedfe70 100644 --- a/src/json-ot/types/ot-binary-irreversible/compose.ts +++ b/src/json-ot/types/ot-binary-irreversible/compose.ts @@ -63,7 +63,7 @@ export const compose = (op1: BinaryOp, op2: BinaryOp): BinaryOp => { append(op3, comp2); } } - if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Infinity)); + if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Number.POSITIVE_INFINITY)); for (; i1 < len1; i1++) append(op3, op1[i1]); trim(op3); return op3; diff --git a/src/json-ot/types/ot-binary-irreversible/index.ts b/src/json-ot/types/ot-binary-irreversible/index.ts index 6f801a1ee6..4657d02a3f 100644 --- a/src/json-ot/types/ot-binary-irreversible/index.ts +++ b/src/json-ot/types/ot-binary-irreversible/index.ts @@ -1,5 +1,5 @@ import type {OtType} from '../types'; -import {BinaryOp} from './types'; +import type {BinaryOp} from './types'; import {validate} from './validate'; import {normalize} from './util'; import {apply} from './apply'; diff --git a/src/json-ot/types/ot-binary-irreversible/transform.ts b/src/json-ot/types/ot-binary-irreversible/transform.ts index fdcb7cf7ab..112ebe9626 100644 --- a/src/json-ot/types/ot-binary-irreversible/transform.ts +++ b/src/json-ot/types/ot-binary-irreversible/transform.ts @@ -1,4 +1,4 @@ -import {BinaryOp} from './types'; +import type {BinaryOp} from './types'; import {append, chunk, componentLength, trim} from './util'; /** @@ -59,7 +59,7 @@ export const transform = (op1: BinaryOp, op2: BinaryOp, leftInsertFirst: boolean } else if (comp2 instanceof Uint8Array) { if (leftInsertFirst) { if (op1[i1] instanceof Uint8Array) { - const comp = chunk(op1[i1++], off1, Infinity); + const comp = chunk(op1[i1++], off1, Number.POSITIVE_INFINITY); off1 = 0; append(op3, comp); } @@ -67,7 +67,7 @@ export const transform = (op1: BinaryOp, op2: BinaryOp, leftInsertFirst: boolean append(op3, comp2.length); } } - if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Infinity)); + if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Number.POSITIVE_INFINITY)); for (; i1 < len1; i1++) append(op3, op1[i1]); trim(op3); return op3; diff --git a/src/json-ot/types/ot-binary-irreversible/validate.ts b/src/json-ot/types/ot-binary-irreversible/validate.ts index e2b898fc8b..a96075355d 100644 --- a/src/json-ot/types/ot-binary-irreversible/validate.ts +++ b/src/json-ot/types/ot-binary-irreversible/validate.ts @@ -1,11 +1,11 @@ import type {BinaryOp, BinaryOpComponent} from './types'; -export const enum VALIDATE_RESULT { +export enum VALIDATE_RESULT { SUCCESS = 0, - INVALID_OP, - INVALID_COMPONENT, - ADJACENT_SAME_TYPE, - NO_TRAILING_RETAIN, + INVALID_OP = 1, + INVALID_COMPONENT = 2, + ADJACENT_SAME_TYPE = 3, + NO_TRAILING_RETAIN = 4, } export const validate = (op: BinaryOp): VALIDATE_RESULT => { diff --git a/src/json-ot/types/ot-json/__tests__/fuzzer/JsonOtFuzzer.ts b/src/json-ot/types/ot-json/__tests__/fuzzer/JsonOtFuzzer.ts index 6305e1be47..dbed0028ce 100644 --- a/src/json-ot/types/ot-json/__tests__/fuzzer/JsonOtFuzzer.ts +++ b/src/json-ot/types/ot-json/__tests__/fuzzer/JsonOtFuzzer.ts @@ -1,5 +1,5 @@ import {clone} from '@jsonjoy.com/util/lib/json-clone'; -import {find, isArrayReference, isObjectReference, Path} from '@jsonjoy.com/json-pointer'; +import {find, isArrayReference, isObjectReference, type Path} from '@jsonjoy.com/json-pointer'; import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import type {JsonOp, JsonOpDataComponent, JsonOpDropComponent, JsonOpPickComponent} from '../../types'; diff --git a/src/json-ot/types/ot-json/__tests__/fuzzer/compose.fuzzer.spec.ts b/src/json-ot/types/ot-json/__tests__/fuzzer/compose.fuzzer.spec.ts index 70d978e079..3bc9d645d7 100644 --- a/src/json-ot/types/ot-json/__tests__/fuzzer/compose.fuzzer.spec.ts +++ b/src/json-ot/types/ot-json/__tests__/fuzzer/compose.fuzzer.spec.ts @@ -7,24 +7,17 @@ const fuzzer = new JsonOtFuzzer(); test('...', () => { for (let i = 0; i < 100; i++) { - let doc; - let tree1; - let tree2; - try { - doc = fuzzer.genDoc(); - let doc2 = clone(doc); - const op1 = fuzzer.genOp(doc); - tree1 = OpTree.from(op1); - doc2 = apply(doc2, op1); - const op2 = fuzzer.genOp(doc); - tree2 = OpTree.from(op2); - doc2 = apply(doc2, op2); - tree1.compose(tree2); - const op3 = tree1.toJson(); - const doc3 = apply(doc2, op3); - expect(doc3).toStrictEqual(doc2); - } catch (error) { - throw error; - } + const doc = fuzzer.genDoc(); + let doc2 = clone(doc); + const op1 = fuzzer.genOp(doc); + const tree1 = OpTree.from(op1); + doc2 = apply(doc2, op1); + const op2 = fuzzer.genOp(doc); + const tree2 = OpTree.from(op2); + doc2 = apply(doc2, op2); + tree1.compose(tree2); + const op3 = tree1.toJson(); + const doc3 = apply(doc2, op3); + expect(doc3).toStrictEqual(doc2); } }); diff --git a/src/json-ot/types/ot-json/__tests__/json-patch.automated.spec.ts b/src/json-ot/types/ot-json/__tests__/json-patch.automated.spec.ts index 69ab7a3e1e..0ca352f259 100644 --- a/src/json-ot/types/ot-json/__tests__/json-patch.automated.spec.ts +++ b/src/json-ot/types/ot-json/__tests__/json-patch.automated.spec.ts @@ -9,7 +9,7 @@ describe('automated', () => { const suite = testSuites[i]; if (!suite.isJsonPatchSpec) continue; describe(suite.name, () => { - suite.tests.forEach((test: any) => { + for (const test of suite.tests) { if (test.skipInJsonOt) return; if (test.disabled) return; const testName = test.comment || test.error || JSON.stringify(test.patch); @@ -24,13 +24,13 @@ describe('automated', () => { } else if (typeof test.error === 'string') { (test.only ? it.only : it)(testName, () => { expect(() => { - test.patch.forEach(validateOperation); + test.patch.forEach(validateOperation as any); const op = toJsonOp(test.patch); apply(test.doc, op); }).toThrowError(); }); } else throw new Error('invalid test case'); - }); + } }); } }); diff --git a/src/json-ot/types/ot-json/__tests__/tree.compose.spec.ts b/src/json-ot/types/ot-json/__tests__/tree.compose.spec.ts index 2ae774cb5d..7b57a5e11d 100644 --- a/src/json-ot/types/ot-json/__tests__/tree.compose.spec.ts +++ b/src/json-ot/types/ot-json/__tests__/tree.compose.spec.ts @@ -1,7 +1,7 @@ import {clone} from '@jsonjoy.com/util/lib/json-clone'; import {apply} from '../apply'; import {OpTree} from '../tree'; -import {JsonOp} from '../types'; +import type {JsonOp} from '../types'; test('can compose two operations', () => { const op1: JsonOp = [ diff --git a/src/json-ot/types/ot-json/apply.ts b/src/json-ot/types/ot-json/apply.ts index fe382e3076..4f10714481 100644 --- a/src/json-ot/types/ot-json/apply.ts +++ b/src/json-ot/types/ot-json/apply.ts @@ -1,5 +1,5 @@ import {find, isArrayReference, isObjectReference} from '@jsonjoy.com/json-pointer'; -import {JsonOp} from './types'; +import type {JsonOp} from './types'; import {evaluate as evalExpression} from '@jsonjoy.com/json-expression/lib/evaluate'; import {comparePath} from './util'; import {EDIT_TYPE} from './constants'; @@ -62,7 +62,7 @@ export const apply = (doc: unknown, op: JsonOp): unknown => { } for (const [type, path, operation] of edit) { const {val, obj, key} = find(doc, path); - let newVal; + let newVal: unknown; switch (type) { case EDIT_TYPE.OT_STRING: { if (typeof val !== 'string') throw new Error('NOT_STR'); diff --git a/src/json-ot/types/ot-json/constants.ts b/src/json-ot/types/ot-json/constants.ts index 207a38b4eb..651e31f30d 100644 --- a/src/json-ot/types/ot-json/constants.ts +++ b/src/json-ot/types/ot-json/constants.ts @@ -1,4 +1,4 @@ -export const enum EDIT_TYPE { +export enum EDIT_TYPE { OT_STRING = 0, OT_BINARY = 1, } diff --git a/src/json-ot/types/ot-json/tree.ts b/src/json-ot/types/ot-json/tree.ts index 0ebffaaa75..323ad55a57 100644 --- a/src/json-ot/types/ot-json/tree.ts +++ b/src/json-ot/types/ot-json/tree.ts @@ -142,8 +142,6 @@ export class OpTree { public drop: DropNode = new DropRoot(); public register = new Map(); - constructor() {} - findPick(path: Path, pathLength: number): PickNode | undefined { let parent: PickNode | undefined = this.pick; for (let i = 0; i < pathLength; i++) { @@ -250,6 +248,7 @@ export class OpTree { // Compose deletes. const d1: DropNode = this.drop; const d2: DropNode = other.drop; + // biome-ignore lint: using .forEach() is the fastest way to iterate over a Map other.register.forEach((register2) => { // Update pick path. if (register2.pick) { @@ -392,6 +391,7 @@ export class OpTree { protected pushDropNode(drop: JsonOpDropComponent[], node: DropNode): void { if (node.regId >= 0) drop.push([node.regId, node.path.slice(0, node.pathLength)]); + // biome-ignore lint: using .forEach() is the fastest way to iterate over a Map node.children.forEach((child) => { this.pushDropNode(drop, child); }); diff --git a/src/json-ot/types/ot-string-irreversible/__tests__/StringOtFuzzer.ts b/src/json-ot/types/ot-string-irreversible/__tests__/StringOtFuzzer.ts index 3f4735044f..07db193e1b 100644 --- a/src/json-ot/types/ot-string-irreversible/__tests__/StringOtFuzzer.ts +++ b/src/json-ot/types/ot-string-irreversible/__tests__/StringOtFuzzer.ts @@ -1,7 +1,7 @@ import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {append, normalize} from '../util'; -import {StringOp} from '../types'; +import type {StringOp} from '../types'; export class StringOtFuzzer extends Fuzzer { genString(): string { diff --git a/src/json-ot/types/ot-string-irreversible/__tests__/StringType.spec.ts b/src/json-ot/types/ot-string-irreversible/__tests__/StringType.spec.ts index d0b343561a..4a6cc99819 100644 --- a/src/json-ot/types/ot-string-irreversible/__tests__/StringType.spec.ts +++ b/src/json-ot/types/ot-string-irreversible/__tests__/StringType.spec.ts @@ -1,6 +1,6 @@ import {validate, normalize, apply, compose, transform} from '..'; import {append} from '../util'; -import {StringOp} from '../types'; +import type {StringOp} from '../types'; describe('validate()', () => { test('returns 0 on valid op', () => { diff --git a/src/json-ot/types/ot-string-irreversible/compose.ts b/src/json-ot/types/ot-string-irreversible/compose.ts index 402823ba63..5fb61fdfab 100644 --- a/src/json-ot/types/ot-string-irreversible/compose.ts +++ b/src/json-ot/types/ot-string-irreversible/compose.ts @@ -68,7 +68,7 @@ export const compose = (op1: StringOp, op2: StringOp): StringOp => { } } } - if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Infinity)); + if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Number.POSITIVE_INFINITY)); for (; i1 < len1; i1++) append(op3, op1[i1]); trim(op3); return op3; diff --git a/src/json-ot/types/ot-string-irreversible/index.ts b/src/json-ot/types/ot-string-irreversible/index.ts index 898dc97847..b8d750e1eb 100644 --- a/src/json-ot/types/ot-string-irreversible/index.ts +++ b/src/json-ot/types/ot-string-irreversible/index.ts @@ -1,5 +1,5 @@ import type {OtType} from '../types'; -import {StringOp} from './types'; +import type {StringOp} from './types'; import {validate} from './validate'; import {normalize} from './util'; import {apply} from './apply'; diff --git a/src/json-ot/types/ot-string-irreversible/transform.ts b/src/json-ot/types/ot-string-irreversible/transform.ts index 130c0e3d7e..b9c831fdaa 100644 --- a/src/json-ot/types/ot-string-irreversible/transform.ts +++ b/src/json-ot/types/ot-string-irreversible/transform.ts @@ -1,4 +1,4 @@ -import {StringOp} from './types'; +import type {StringOp} from './types'; import {append, chunk, componentLength, trim} from './util'; /** @@ -62,7 +62,7 @@ export const transform = (op1: StringOp, op2: StringOp, leftInsertFirst: boolean case 'string': { if (leftInsertFirst) { if (typeof op1[i1] === 'string') { - const comp = chunk(op1[i1++], off1, Infinity); + const comp = chunk(op1[i1++], off1, Number.POSITIVE_INFINITY); off1 = 0; append(op3, comp); } @@ -72,7 +72,7 @@ export const transform = (op1: StringOp, op2: StringOp, leftInsertFirst: boolean } } } - if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Infinity)); + if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Number.POSITIVE_INFINITY)); for (; i1 < len1; i1++) append(op3, op1[i1]); trim(op3); return op3; diff --git a/src/json-ot/types/ot-string-irreversible/validate.ts b/src/json-ot/types/ot-string-irreversible/validate.ts index 63dc3c8477..772ae81cd4 100644 --- a/src/json-ot/types/ot-string-irreversible/validate.ts +++ b/src/json-ot/types/ot-string-irreversible/validate.ts @@ -1,11 +1,11 @@ import type {StringOp, StringOpComponent} from './types'; -export const enum VALIDATE_RESULT { +export enum VALIDATE_RESULT { SUCCESS = 0, - INVALID_OP, - INVALID_COMPONENT, - ADJACENT_SAME_TYPE, - NO_TRAILING_RETAIN, + INVALID_OP = 1, + INVALID_COMPONENT = 2, + ADJACENT_SAME_TYPE = 3, + NO_TRAILING_RETAIN = 4, } export const validate = (op: StringOp): VALIDATE_RESULT => { diff --git a/src/json-ot/types/ot-string/__tests__/StringOtFuzzer.ts b/src/json-ot/types/ot-string/__tests__/StringOtFuzzer.ts index 647235d3f3..958736ef8c 100644 --- a/src/json-ot/types/ot-string/__tests__/StringOtFuzzer.ts +++ b/src/json-ot/types/ot-string/__tests__/StringOtFuzzer.ts @@ -1,7 +1,7 @@ import {RandomJson} from '@jsonjoy.com/util/lib/json-random'; import {Fuzzer} from '@jsonjoy.com/util/lib/Fuzzer'; import {append, normalize} from '../util'; -import {StringOp} from '../types'; +import type {StringOp} from '../types'; export class StringOtFuzzer extends Fuzzer { genString(): string { diff --git a/src/json-ot/types/ot-string/__tests__/StringType.spec.ts b/src/json-ot/types/ot-string/__tests__/StringType.spec.ts index 5e78007840..7db4121205 100644 --- a/src/json-ot/types/ot-string/__tests__/StringType.spec.ts +++ b/src/json-ot/types/ot-string/__tests__/StringType.spec.ts @@ -1,6 +1,6 @@ import {validate, normalize, apply, compose, transform} from '..'; import {append} from '../util'; -import {StringOp} from '../types'; +import type {StringOp} from '../types'; describe('validate()', () => { test('returns 0 on valid op', () => { diff --git a/src/json-ot/types/ot-string/compose.ts b/src/json-ot/types/ot-string/compose.ts index 493115e8d5..50073dec57 100644 --- a/src/json-ot/types/ot-string/compose.ts +++ b/src/json-ot/types/ot-string/compose.ts @@ -76,7 +76,7 @@ export const compose = (op1: StringOp, op2: StringOp): StringOp => { } } } - if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Infinity)); + if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Number.POSITIVE_INFINITY)); for (; i1 < len1; i1++) append(op3, op1[i1]); trim(op3); return op3; diff --git a/src/json-ot/types/ot-string/index.ts b/src/json-ot/types/ot-string/index.ts index 898dc97847..b8d750e1eb 100644 --- a/src/json-ot/types/ot-string/index.ts +++ b/src/json-ot/types/ot-string/index.ts @@ -1,5 +1,5 @@ import type {OtType} from '../types'; -import {StringOp} from './types'; +import type {StringOp} from './types'; import {validate} from './validate'; import {normalize} from './util'; import {apply} from './apply'; diff --git a/src/json-ot/types/ot-string/transform.ts b/src/json-ot/types/ot-string/transform.ts index 9931869419..64660249df 100644 --- a/src/json-ot/types/ot-string/transform.ts +++ b/src/json-ot/types/ot-string/transform.ts @@ -1,4 +1,4 @@ -import {StringOp} from './types'; +import type {StringOp} from './types'; import {append, chunk, componentLength, trim} from './util'; /** @@ -46,7 +46,7 @@ export const transform = (op1: StringOp, op2: StringOp, leftInsertFirst: boolean case 'string': { if (leftInsertFirst) { if (typeof op1[i1] === 'string') { - const comp = chunk(op1[i1++], off1, Infinity); + const comp = chunk(op1[i1++], off1, Number.POSITIVE_INFINITY); off1 = 0; append(op3, comp); } @@ -79,7 +79,7 @@ export const transform = (op1: StringOp, op2: StringOp, leftInsertFirst: boolean } } } - if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Infinity)); + if (i1 < len1 && off1) append(op3, chunk(op1[i1++], off1, Number.POSITIVE_INFINITY)); for (; i1 < len1; i1++) append(op3, op1[i1]); trim(op3); return op3; diff --git a/src/json-ot/types/ot-string/validate.ts b/src/json-ot/types/ot-string/validate.ts index 34acc16621..644925edc4 100644 --- a/src/json-ot/types/ot-string/validate.ts +++ b/src/json-ot/types/ot-string/validate.ts @@ -1,11 +1,11 @@ import type {StringOp, StringOpComponent} from './types'; -export const enum VALIDATE_RESULT { +export enum VALIDATE_RESULT { SUCCESS = 0, - INVALID_OP, - INVALID_COMPONENT, - ADJACENT_SAME_TYPE, - NO_TRAILING_RETAIN, + INVALID_OP = 1, + INVALID_COMPONENT = 2, + ADJACENT_SAME_TYPE = 3, + NO_TRAILING_RETAIN = 4, } export const validate = (op: StringOp): VALIDATE_RESULT => { diff --git a/src/json-patch-ot/__tests__/scenarios.spec.ts b/src/json-patch-ot/__tests__/scenarios.spec.ts index 6247d494e0..088870a7c4 100644 --- a/src/json-patch-ot/__tests__/scenarios.spec.ts +++ b/src/json-patch-ot/__tests__/scenarios.spec.ts @@ -1,4 +1,4 @@ -import {Operation} from '../../json-patch/types'; +import type {Operation} from '../../json-patch/types'; import {applyOps} from '../../json-patch/applyPatch'; import {transform} from '../transform'; import {decode} from '../../json-patch/codec/json'; diff --git a/src/json-patch-ot/transform.ts b/src/json-patch-ot/transform.ts index 5b1f15a4dd..6ef04b60b8 100644 --- a/src/json-patch-ot/transform.ts +++ b/src/json-patch-ot/transform.ts @@ -1,4 +1,4 @@ -import {Op} from '../json-patch/op'; +import type {Op} from '../json-patch/op'; import {xforms} from './transforms'; /** diff --git a/src/json-patch-ot/transforms/util.ts b/src/json-patch-ot/transforms/util.ts index 21da38eba3..48d274b71c 100644 --- a/src/json-patch-ot/transforms/util.ts +++ b/src/json-patch-ot/transforms/util.ts @@ -1,4 +1,4 @@ -import {isValidIndex, isChild, parent, Path} from '@jsonjoy.com/json-pointer'; +import {isValidIndex, isChild, parent, type Path} from '@jsonjoy.com/json-pointer'; export const bumpArrayPath = (path1: Path, path2: Path): undefined | Path => { const folder = parent(path1); diff --git a/src/json-patch-ot/transforms/xAdd.ts b/src/json-patch-ot/transforms/xAdd.ts index a3737875f9..29259c8dc4 100644 --- a/src/json-patch-ot/transforms/xAdd.ts +++ b/src/json-patch-ot/transforms/xAdd.ts @@ -1,6 +1,6 @@ -import {OpAdd, Op} from '../../json-patch/op'; +import type {OpAdd, Op} from '../../json-patch/op'; import {isRoot, isValidIndex, isChild, formatJsonPointer} from '@jsonjoy.com/json-pointer'; -import {Operation} from '../../json-patch/types'; +import type {Operation} from '../../json-patch/types'; import {bumpArrayPath} from './util'; import {operationToOp} from '../../json-patch/codec/json'; diff --git a/src/json-patch-ot/transforms/xMove.ts b/src/json-patch-ot/transforms/xMove.ts index 5aad6fb352..a95cd51eb6 100644 --- a/src/json-patch-ot/transforms/xMove.ts +++ b/src/json-patch-ot/transforms/xMove.ts @@ -1,5 +1,5 @@ import {operationToOp} from '../../json-patch/codec/json'; -import {OpMove, Op} from '../../json-patch/op'; +import type {OpMove, Op} from '../../json-patch/op'; import {isRoot, isChild} from '@jsonjoy.com/json-pointer'; export const xMove = (move: OpMove, op: Op): null | Op | Op[] => { diff --git a/src/json-patch-ot/transforms/xRemove.ts b/src/json-patch-ot/transforms/xRemove.ts index 3423f1b819..8b9883b905 100644 --- a/src/json-patch-ot/transforms/xRemove.ts +++ b/src/json-patch-ot/transforms/xRemove.ts @@ -1,7 +1,7 @@ -import {OpRemove, Op} from '../../json-patch/op'; +import {OpRemove, type Op} from '../../json-patch/op'; import {isRoot, isValidIndex, formatJsonPointer, isPathEqual} from '@jsonjoy.com/json-pointer'; import {lowerArrayPath} from './util'; -import {Operation} from '../../json-patch/types'; +import type {Operation} from '../../json-patch/types'; import {operationToOp} from '../../json-patch/codec/json'; export const xRemove = (add: OpRemove, op: Op): null | Op => { diff --git a/src/json-patch-ot/transforms/xStrDel.ts b/src/json-patch-ot/transforms/xStrDel.ts index a1df9c4c83..3390545d9e 100644 --- a/src/json-patch-ot/transforms/xStrDel.ts +++ b/src/json-patch-ot/transforms/xStrDel.ts @@ -1,4 +1,4 @@ -import {Op, OpStrDel, OpStrIns} from '../../json-patch/op'; +import {type Op, OpStrDel, OpStrIns} from '../../json-patch/op'; export const xStrDel = (del: OpStrDel, op: Op): null | Op | Op[] => { if (op instanceof OpStrIns) { diff --git a/src/json-patch-ot/transforms/xStrIns.ts b/src/json-patch-ot/transforms/xStrIns.ts index c8ebccc517..17d2d3d3d0 100644 --- a/src/json-patch-ot/transforms/xStrIns.ts +++ b/src/json-patch-ot/transforms/xStrIns.ts @@ -1,5 +1,5 @@ import {operationToOp} from '../../json-patch/codec/json'; -import {Op, OpStrDel, OpStrIns} from '../../json-patch/op'; +import {type Op, OpStrDel, OpStrIns} from '../../json-patch/op'; export const xStrIns = (ins: OpStrIns, op: Op): null | Op | Op[] => { if (op instanceof OpStrIns) { diff --git a/src/json-patch/__bench__/codegen.ts b/src/json-patch/__bench__/codegen.ts index 957f4484fc..d2d0d6a83f 100644 --- a/src/json-patch/__bench__/codegen.ts +++ b/src/json-patch/__bench__/codegen.ts @@ -2,7 +2,7 @@ import * as Benchmark from 'benchmark'; import {operationToOp} from '../codec/json'; -import {Operation} from '../types'; +import type {Operation} from '../types'; import {applyOps} from '../applyPatch'; import {apply, $apply} from '../codegen/apply'; @@ -26,16 +26,16 @@ const suite = new Benchmark.Suite(); const applyCompiled = $apply(patch, {mutate: false}); suite - .add(`json-patch/apply(patch, {}, message)`, () => { + .add('json-patch/apply(patch, {}, message)', () => { apply(patch, {mutate: false}, message); }) - .add(`json-patch/$apply(patch, {})(message)`, () => { + .add('json-patch/$apply(patch, {})(message)', () => { $apply(patch, {mutate: false})(message); }) - .add(`json-patch/applyOps`, () => { + .add('json-patch/applyOps', () => { applyOps(message, ops, false); }) - .add(`json-patch/applyCompiled`, () => { + .add('json-patch/applyCompiled', () => { applyCompiled(message); }) .on('cycle', (event: any) => { diff --git a/src/json-patch/__bench__/main.ts b/src/json-patch/__bench__/main.ts index eff698fb20..5c21482d7f 100644 --- a/src/json-patch/__bench__/main.ts +++ b/src/json-patch/__bench__/main.ts @@ -2,7 +2,7 @@ import * as Benchmark from 'benchmark'; import {operationToOp} from '../codec/json'; -import {Operation} from '../types'; +import type {Operation} from '../types'; import {applyPatch, applyOps} from '../applyPatch'; import {applyPatch as v2} from '../applyPatch/v2'; import {applyPatch as v3} from '../applyPatch/v3'; @@ -27,25 +27,25 @@ const ops = patch.map((op) => operationToOp(op, {})); const suite = new Benchmark.Suite(); suite - .add(`json-joy (applyPatch)`, () => { + .add('json-joy (applyPatch)', () => { applyPatch(doc, patch, {mutate: false}); }) - .add(`json-joy (applyPatch v2)`, () => { + .add('json-joy (applyPatch v2)', () => { v2(doc, patch, {mutate: false}); }) - .add(`json-joy (applyPatch v3)`, () => { + .add('json-joy (applyPatch v3)', () => { v3(doc, patch, {mutate: false}); }) - .add(`json-joy (applyPatch v4)`, () => { + .add('json-joy (applyPatch v4)', () => { v4(doc, patch, {mutate: false}); }) - .add(`json-joy (applyOps)`, () => { + .add('json-joy (applyOps)', () => { applyOps(doc, ops, false); }) - .add(`fast-json-patch`, () => { + .add('fast-json-patch', () => { applyPatchFastJsonPatch(doc, patch as any, false, false); }) - .add(`fast-json-patch (fast clone)`, () => { + .add('fast-json-patch (fast clone)', () => { const doc2 = clone(doc); applyPatchFastJsonPatch(doc2, patch as any, false, true); }) diff --git a/src/json-patch/__demos__/json-patch.ts b/src/json-patch/__demos__/json-patch.ts index 7edd304970..fcdcaab337 100644 --- a/src/json-patch/__demos__/json-patch.ts +++ b/src/json-patch/__demos__/json-patch.ts @@ -6,7 +6,7 @@ * npx ts-node src/json-patch/__demos__/json-patch.ts */ -import {applyPatch, Operation} from '../../json-patch'; +import {applyPatch, type Operation} from '../../json-patch'; const doc = { foo: { diff --git a/src/json-patch/__tests__/patch.automated.spec.ts b/src/json-patch/__tests__/patch.automated.spec.ts index a74facae2d..e4e9434e50 100644 --- a/src/json-patch/__tests__/patch.automated.spec.ts +++ b/src/json-patch/__tests__/patch.automated.spec.ts @@ -3,9 +3,9 @@ import {testSuites} from '../../json-cli/test/suites'; import {validateOperation} from '../validate'; describe('automated', () => { - testSuites.forEach((suite) => { + for (const suite of testSuites) { describe(suite.name, () => { - suite.tests.forEach((test: any) => { + for (const test of suite.tests) { if (test.disabled) return; const testName = test.comment || test.error || JSON.stringify(test.patch); if (test.expected !== undefined) { @@ -16,7 +16,7 @@ describe('automated', () => { } else if (typeof test.error === 'string') { it(testName, () => { try { - test.patch.forEach(validateOperation); + test.patch.forEach(validateOperation as any); applyPatch(test.doc, test.patch, {mutate: true}); throw new Error('Patch should have failed.'); } catch (error) { @@ -25,7 +25,7 @@ describe('automated', () => { } }); } else throw new Error('invalid test case'); - }); + } }); - }); + } }); diff --git a/src/json-patch/__tests__/spec.json.ts b/src/json-patch/__tests__/spec.json.ts index 972c4c8cc5..55a3f44725 100644 --- a/src/json-patch/__tests__/spec.json.ts +++ b/src/json-patch/__tests__/spec.json.ts @@ -166,7 +166,7 @@ export default [ }, patch: [ // @ts-ignore - {op: 'add', path: '/baz', value: 'qux', op: 'remove'}, + {path: '/baz', value: 'qux', op: 'remove'}, ], error: "operation has two 'op' members", disabled: true, diff --git a/src/json-patch/applyPatch/__tests__/ops/flip.ts b/src/json-patch/applyPatch/__tests__/ops/flip.ts index 1c516a6acb..56280270da 100644 --- a/src/json-patch/applyPatch/__tests__/ops/flip.ts +++ b/src/json-patch/applyPatch/__tests__/ops/flip.ts @@ -1,6 +1,6 @@ import type {ApplyPatch} from '../../types'; import type {Operation} from '../../../types'; -import {OperationFlip} from '../../..'; +import type {OperationFlip} from '../../..'; export const testFlipOp = (applyPatch: ApplyPatch) => { const applyOperations = (doc: unknown, ops: Operation[]) => applyPatch(doc, ops, {mutate: true}); diff --git a/src/json-patch/applyPatch/__tests__/ops/inc.ts b/src/json-patch/applyPatch/__tests__/ops/inc.ts index ae89e74cee..7a19d9bb20 100644 --- a/src/json-patch/applyPatch/__tests__/ops/inc.ts +++ b/src/json-patch/applyPatch/__tests__/ops/inc.ts @@ -1,6 +1,6 @@ import type {ApplyPatch} from '../../types'; import type {Operation} from '../../../types'; -import {OperationInc} from '../../..'; +import type {OperationInc} from '../../..'; export const testIncOp = (applyPatch: ApplyPatch) => { const applyOperations = (doc: unknown, ops: Operation[]) => applyPatch(doc, ops, {mutate: true}); diff --git a/src/json-patch/applyPatch/__tests__/ops/merge.ts b/src/json-patch/applyPatch/__tests__/ops/merge.ts index 2d288871ad..e0251b1a73 100644 --- a/src/json-patch/applyPatch/__tests__/ops/merge.ts +++ b/src/json-patch/applyPatch/__tests__/ops/merge.ts @@ -1,6 +1,6 @@ import type {ApplyPatch} from '../../types'; import type {Operation} from '../../../types'; -import {SlateElementNode, SlateNode, SlateTextNode} from '../../..'; +import type {SlateElementNode, SlateNode, SlateTextNode} from '../../..'; export const testMergeOp = (applyPatch: ApplyPatch) => { describe('merge', () => { diff --git a/src/json-patch/applyPatch/__tests__/ops/split.ts b/src/json-patch/applyPatch/__tests__/ops/split.ts index b169a13c72..dca56342fd 100644 --- a/src/json-patch/applyPatch/__tests__/ops/split.ts +++ b/src/json-patch/applyPatch/__tests__/ops/split.ts @@ -1,6 +1,6 @@ import type {ApplyPatch} from '../../types'; import type {Operation} from '../../../types'; -import {SlateElementNode, SlateNode, SlateTextNode} from '../../..'; +import type {SlateElementNode, SlateNode, SlateTextNode} from '../../..'; export const testSplitOp = (applyPatch: ApplyPatch) => { describe('split', () => { diff --git a/src/json-patch/applyPatch/__tests__/smokeTestApplyPatch.ts b/src/json-patch/applyPatch/__tests__/smokeTestApplyPatch.ts index b23edf8f80..3f768dc462 100644 --- a/src/json-patch/applyPatch/__tests__/smokeTestApplyPatch.ts +++ b/src/json-patch/applyPatch/__tests__/smokeTestApplyPatch.ts @@ -6,7 +6,7 @@ interface Options { } export const smokeTestApplyPatch = (applyPatch: ApplyPatch, {dontTestResultHistory = false}: Options = {}) => { - describe(`applyPatch [smoke tests]`, () => { + describe('applyPatch [smoke tests]', () => { describe('root replacement', () => { describe('add', () => { it('should `add` an object (on a json document of type object) - in place', () => { @@ -1987,7 +1987,7 @@ export const smokeTestApplyPatch = (applyPatch: ApplyPatch, {dontTestResultHisto } }); - it(`should not allow __proto__ modifications`, () => { + it('should not allow __proto__ modifications', () => { function SomeClass(this: any) { this.foo = 'bar'; } @@ -1995,7 +1995,7 @@ export const smokeTestApplyPatch = (applyPatch: ApplyPatch, {dontTestResultHisto const doc = new (SomeClass as any)(); const otherDoc = new (SomeClass as any)(); - const patch: any = [{op: 'replace', path: `/__proto__/x`, value: 'polluted'}]; + const patch: any = [{op: 'replace', path: '/__proto__/x', value: 'polluted'}]; expect(() => applyPatch(doc, patch, {mutate: true})).toThrow(); diff --git a/src/json-patch/applyPatch/__tests__/testApplyPatchAutomated.ts b/src/json-patch/applyPatch/__tests__/testApplyPatchAutomated.ts index 4c7a58e36f..c6201b0915 100644 --- a/src/json-patch/applyPatch/__tests__/testApplyPatchAutomated.ts +++ b/src/json-patch/applyPatch/__tests__/testApplyPatchAutomated.ts @@ -2,7 +2,7 @@ import tests_json from '../../__tests__/tests.json'; import spec_json from '../../__tests__/spec.json'; import {validateOperation} from '../../validate'; import {clone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {ApplyPatch} from '../types'; +import type {ApplyPatch} from '../types'; const testSuites = [ { @@ -16,11 +16,11 @@ const testSuites = [ ]; export const testApplyPatchAutomated = (applyPatch: ApplyPatch) => { - describe(`applyPatch [automated]`, () => { - testSuites.forEach((s) => { + describe('applyPatch [automated]', () => { + for (const s of testSuites) { const suite = clone(s) as any; describe(suite.name, () => { - suite.tests.forEach((test: any) => { + for (const test of suite.tests) { if (test.disabled) return; const testName = test.comment || test.error || JSON.stringify(test.patch); if (test.expected) { @@ -37,8 +37,8 @@ export const testApplyPatchAutomated = (applyPatch: ApplyPatch) => { }).toThrow(); }); } else throw new Error('invalid test case'); - }); + } }); - }); + } }); }; diff --git a/src/json-patch/applyPatch/types.ts b/src/json-patch/applyPatch/types.ts index f5ab4f3b1f..fb80996fef 100644 --- a/src/json-patch/applyPatch/types.ts +++ b/src/json-patch/applyPatch/types.ts @@ -1,4 +1,4 @@ -import {JsonPatchOptions, Operation} from '../types'; +import type {JsonPatchOptions, Operation} from '../types'; export interface ApplyPatchOptions extends JsonPatchOptions { /** diff --git a/src/json-patch/applyPatch/v1.ts b/src/json-patch/applyPatch/v1.ts index 14d57eefe7..f220e40bf0 100644 --- a/src/json-patch/applyPatch/v1.ts +++ b/src/json-patch/applyPatch/v1.ts @@ -1,6 +1,6 @@ import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {Operation} from '../types'; -import {Op} from '../op'; +import type {Operation} from '../types'; +import type {Op} from '../op'; import {decode} from '../codec/json'; import type {ApplyPatchOptions, OpResult, PatchResult} from './types'; diff --git a/src/json-patch/applyPatch/v2.ts b/src/json-patch/applyPatch/v2.ts index d218b4f8f9..41bca5c25b 100644 --- a/src/json-patch/applyPatch/v2.ts +++ b/src/json-patch/applyPatch/v2.ts @@ -1,5 +1,5 @@ import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {Operation} from '../types'; +import type {Operation} from '../types'; import {findByPointer} from '@jsonjoy.com/json-pointer/lib/findByPointer/v6'; import type {ApplyPatchOptions, OpResult, PatchResult} from './types'; diff --git a/src/json-patch/applyPatch/v3.ts b/src/json-patch/applyPatch/v3.ts index a8cfe390d4..cf18dfd6a6 100644 --- a/src/json-patch/applyPatch/v3.ts +++ b/src/json-patch/applyPatch/v3.ts @@ -1,9 +1,9 @@ import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {Operation} from '../types'; +import {hasOwnProperty as hasOwnProp} from '@jsonjoy.com/util/lib/hasOwnProperty'; import {findByPointer, unescapeComponent} from '@jsonjoy.com/json-pointer'; import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; +import type {Operation} from '../types'; import type {ApplyPatchOptions, OpResult, PatchResult} from './types'; -import {hasOwnProperty} from '@jsonjoy.com/util/lib/hasOwnProperty'; const {isArray} = Array; @@ -126,7 +126,7 @@ export function applyOperation(doc: unknown, operation: Operation): OpResult { } break; } - obj = hasOwnProperty(obj, key) ? (obj as any)[key] : undefined; + obj = hasOwnProp(obj, key) ? (obj as any)[key] : undefined; } else throw new Error('NOT_FOUND'); } return {doc}; diff --git a/src/json-patch/applyPatch/v4.ts b/src/json-patch/applyPatch/v4.ts index 6926e50b89..3d758f9a57 100644 --- a/src/json-patch/applyPatch/v4.ts +++ b/src/json-patch/applyPatch/v4.ts @@ -1,6 +1,6 @@ import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {Operation} from '../types'; -import {Op} from '../op'; +import type {Operation} from '../types'; +import type {Op} from '../op'; import {operationToOp} from '../codec/json'; import type {ApplyPatchOptions, OpResult, PatchResult} from './types'; diff --git a/src/json-patch/codec/binary/Decoder.ts b/src/json-patch/codec/binary/Decoder.ts index 268ffac7bc..86b0497c22 100644 --- a/src/json-patch/codec/binary/Decoder.ts +++ b/src/json-patch/codec/binary/Decoder.ts @@ -1,6 +1,6 @@ import { - AbstractPredicateOp, - Op, + type AbstractPredicateOp, + type Op, OpAdd, OpAnd, OpContains, @@ -33,8 +33,8 @@ import { } from '../../op'; import {MsgPackDecoderFast} from '@jsonjoy.com/json-pack/lib/msgpack/MsgPackDecoderFast'; import {OPCODE} from '../../constants'; -import {Path} from '@jsonjoy.com/json-pointer'; -import {JsonPatchTypes} from '../json/types'; +import type {Path} from '@jsonjoy.com/json-pointer'; +import type {JsonPatchTypes} from '../json/types'; import {createMatcherDefault} from '../../util'; import type {JsonPatchOptions} from '../../types'; import type {Reader} from '@jsonjoy.com/util/lib/buffers/Reader'; diff --git a/src/json-patch/codec/binary/Encoder.ts b/src/json-patch/codec/binary/Encoder.ts index 9eabd67a54..4da950a3fd 100644 --- a/src/json-patch/codec/binary/Encoder.ts +++ b/src/json-patch/codec/binary/Encoder.ts @@ -1,5 +1,5 @@ import {MsgPackEncoderFast as EncoderMessagePack} from '@jsonjoy.com/json-pack/lib/msgpack/MsgPackEncoderFast'; -import {Op} from '../../op'; +import type {Op} from '../../op'; export class Encoder extends EncoderMessagePack { public encode(patch: Op[]): Uint8Array { diff --git a/src/json-patch/codec/compact/Decoder.ts b/src/json-patch/codec/compact/Decoder.ts index bce2917bc1..16c473ec88 100644 --- a/src/json-patch/codec/compact/Decoder.ts +++ b/src/json-patch/codec/compact/Decoder.ts @@ -1,6 +1,6 @@ import type {JsonPatchOptions} from '../../types'; import type {CompactOp} from './types'; -import {Op} from '../../op'; +import type {Op} from '../../op'; import {decode} from './decode'; export class Decoder { diff --git a/src/json-patch/codec/compact/Encoder.ts b/src/json-patch/codec/compact/Encoder.ts index d3c5f2d298..1d935b10d2 100644 --- a/src/json-patch/codec/compact/Encoder.ts +++ b/src/json-patch/codec/compact/Encoder.ts @@ -1,6 +1,6 @@ -import {Op} from '../../op'; +import type {Op} from '../../op'; import {encode} from './encode'; -import {CompactOp, EncoderOptions} from './types'; +import type {CompactOp, EncoderOptions} from './types'; export class Encoder { constructor(public readonly options?: EncoderOptions) {} diff --git a/src/json-patch/codec/compact/decode.ts b/src/json-patch/codec/compact/decode.ts index 643e1acde2..1b89c40088 100644 --- a/src/json-patch/codec/compact/decode.ts +++ b/src/json-patch/codec/compact/decode.ts @@ -1,5 +1,5 @@ -import {Op, PredicateOp} from '../../op'; -import {CompactOp} from './types'; +import type {Op, PredicateOp} from '../../op'; +import type {CompactOp} from './types'; import {OpAdd} from '../../op/OpAdd'; import {OpRemove} from '../../op/OpRemove'; import {OpReplace} from '../../op/OpReplace'; diff --git a/src/json-patch/codec/compact/encode.ts b/src/json-patch/codec/compact/encode.ts index 26448e323a..ec8425c141 100644 --- a/src/json-patch/codec/compact/encode.ts +++ b/src/json-patch/codec/compact/encode.ts @@ -1,5 +1,5 @@ -import {Op} from '../../op'; -import {CompactOp, EncoderOptions} from './types'; +import type {Op} from '../../op'; +import type {CompactOp, EncoderOptions} from './types'; export function encode(ops: Op[], {stringOpcode = false}: EncoderOptions = {}): CompactOp[] { const operations: CompactOp[] = []; diff --git a/src/json-patch/codec/json/Decoder.ts b/src/json-patch/codec/json/Decoder.ts index 4e691b7905..f7bccc9c29 100644 --- a/src/json-patch/codec/json/Decoder.ts +++ b/src/json-patch/codec/json/Decoder.ts @@ -1,7 +1,7 @@ import type {JsonPatchOptions} from '../../types'; -import {Op} from '../../op'; +import type {Op} from '../../op'; import {decode} from './decode'; -import {Operation} from './types'; +import type {Operation} from './types'; export class Decoder { constructor(private readonly options: JsonPatchOptions) {} diff --git a/src/json-patch/codec/json/Encoder.ts b/src/json-patch/codec/json/Encoder.ts index 7ede13dfcb..2dc48bb954 100644 --- a/src/json-patch/codec/json/Encoder.ts +++ b/src/json-patch/codec/json/Encoder.ts @@ -1,6 +1,6 @@ -import {Op} from '../../op'; +import type {Op} from '../../op'; import {encode} from './encode'; -import {Operation} from './types'; +import type {Operation} from './types'; export class Encoder { public encode(patch: Op[]): Operation[] { diff --git a/src/json-patch/codec/json/__tests__/sample-operations.ts b/src/json-patch/codec/json/__tests__/sample-operations.ts index dcaafd1ca3..4d34001160 100644 --- a/src/json-patch/codec/json/__tests__/sample-operations.ts +++ b/src/json-patch/codec/json/__tests__/sample-operations.ts @@ -1,4 +1,4 @@ -import { +import type { OperationAdd, OperationAnd, OperationContains, diff --git a/src/json-patch/codec/json/decode.ts b/src/json-patch/codec/json/decode.ts index 7cf7348a70..2771794b46 100644 --- a/src/json-patch/codec/json/decode.ts +++ b/src/json-patch/codec/json/decode.ts @@ -1,5 +1,5 @@ -import {Op, PredicateOp} from '../../op'; -import {Operation} from './types'; +import type {Op, PredicateOp} from '../../op'; +import type {Operation} from './types'; import {OpAdd} from '../../op/OpAdd'; import {OpRemove} from '../../op/OpRemove'; import {OpReplace} from '../../op/OpReplace'; diff --git a/src/json-patch/codec/json/encode.ts b/src/json-patch/codec/json/encode.ts index e3f972a95f..3eacc64ad2 100644 --- a/src/json-patch/codec/json/encode.ts +++ b/src/json-patch/codec/json/encode.ts @@ -1,5 +1,5 @@ -import {Op} from '../../op'; -import {Operation} from './types'; +import type {Op} from '../../op'; +import type {Operation} from './types'; export function encode(ops: Op[]): Operation[] { const operations: Operation[] = []; diff --git a/src/json-patch/codec/json/types.ts b/src/json-patch/codec/json/types.ts index 686a80a84a..f18da763e4 100644 --- a/src/json-patch/codec/json/types.ts +++ b/src/json-patch/codec/json/types.ts @@ -1,5 +1,5 @@ import type {Path} from '@jsonjoy.com/json-pointer'; -import {OpType} from '../../opcodes'; +import type {OpType} from '../../opcodes'; export type Operation = JsonPatchOperation | PredicateOperation | JsonPatchExtendedOperation; diff --git a/src/json-patch/codegen/apply.ts b/src/json-patch/codegen/apply.ts index 7b1a8e1bfc..6b5cf3aae1 100644 --- a/src/json-patch/codegen/apply.ts +++ b/src/json-patch/codegen/apply.ts @@ -1,11 +1,11 @@ import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; -import {Operation} from '../types'; +import type {Operation} from '../types'; import {operationToOp} from '../codec/json'; import {AbstractPredicateOp} from '../op'; -import {ApplyPatchOptions} from '../applyPatch/types'; +import type {ApplyPatchOptions} from '../applyPatch/types'; import type {JsonPatchOptions} from '..'; import type {ApplyFn} from './types'; -import {compile, JavaScriptLinked, JavaScript} from '@jsonjoy.com/util/lib/codegen'; +import {compile, type JavaScriptLinked, type JavaScript} from '@jsonjoy.com/util/lib/codegen'; import {codegenOp} from './codegenOp'; export const apply = (patch: readonly Operation[], applyOptions: ApplyPatchOptions, doc: unknown): unknown => { @@ -62,7 +62,7 @@ export const $$apply = ( const js = /* js */ ` (function(${depNames.join(',')}) { return function(doc){ - ${needsToClone ? /* js */ `doc = clone(doc);` : ''} + ${needsToClone ? /* js */ 'doc = clone(doc);' : ''} return ${resultExpression}; }; })`; diff --git a/src/json-patch/codegen/ops/add.ts b/src/json-patch/codegen/ops/add.ts index 519365e43a..01ebedb04c 100644 --- a/src/json-patch/codegen/ops/add.ts +++ b/src/json-patch/codegen/ops/add.ts @@ -1,5 +1,5 @@ -import {OpAdd} from '../../op'; -import {JavaScriptLinked, compileClosure, JavaScript} from '@jsonjoy.com/util/lib/codegen'; +import type {OpAdd} from '../../op'; +import {type JavaScriptLinked, compileClosure, type JavaScript} from '@jsonjoy.com/util/lib/codegen'; import type {ApplyFn} from '../types'; import {$findRef} from '@jsonjoy.com/json-pointer/lib/codegen/findRef'; diff --git a/src/json-patch/codegen/ops/starts.ts b/src/json-patch/codegen/ops/starts.ts index 7c48349185..58bfba5f83 100644 --- a/src/json-patch/codegen/ops/starts.ts +++ b/src/json-patch/codegen/ops/starts.ts @@ -1,6 +1,6 @@ -import {OpStarts} from '../../op'; +import type {OpStarts} from '../../op'; import {$$find} from '@jsonjoy.com/json-pointer/lib/codegen/find'; -import {JavaScriptLinked, compileClosure, JavaScript} from '@jsonjoy.com/util/lib/codegen'; +import {type JavaScriptLinked, compileClosure, type JavaScript} from '@jsonjoy.com/util/lib/codegen'; import {predicateOpWrapper} from '../util'; import type {ApplyFn} from '../types'; @@ -12,7 +12,7 @@ export const $$starts = (op: OpStarts): JavaScriptLinked => { return wrapper(function(doc){ var val = find(doc); if (typeof val !== 'string') return false; - var outer = ${op.ignore_case ? /* js */ `val.toLowerCase()` : `val`}; + var outer = ${op.ignore_case ? /* js */ 'val.toLowerCase()' : 'val'}; return outer.indexOf(${JSON.stringify(compareValue)}) === 0; }); })`; diff --git a/src/json-patch/codegen/ops/test.ts b/src/json-patch/codegen/ops/test.ts index e26b4f2ace..4877640e2b 100644 --- a/src/json-patch/codegen/ops/test.ts +++ b/src/json-patch/codegen/ops/test.ts @@ -1,7 +1,7 @@ -import {OpTest} from '../../op'; +import type {OpTest} from '../../op'; import {$$find} from '@jsonjoy.com/json-pointer/lib/codegen/find'; import {$$deepEqual} from '@jsonjoy.com/util/lib/json-equal/$$deepEqual'; -import {JavaScriptLinked, compileClosure, JavaScript} from '@jsonjoy.com/util/lib/codegen'; +import {type JavaScriptLinked, compileClosure, type JavaScript} from '@jsonjoy.com/util/lib/codegen'; import {predicateOpWrapper} from '../util'; import type {ApplyFn} from '../types'; diff --git a/src/json-patch/constants.ts b/src/json-patch/constants.ts index a4c0793e76..f3be76b76a 100644 --- a/src/json-patch/constants.ts +++ b/src/json-patch/constants.ts @@ -1,4 +1,4 @@ -export const enum OPCODE { +export enum OPCODE { // JSON Patch. add = 0, remove = 1, diff --git a/src/json-patch/exec/test.ts b/src/json-patch/exec/test.ts index 3d7500f755..9541ae8eda 100644 --- a/src/json-patch/exec/test.ts +++ b/src/json-patch/exec/test.ts @@ -1,5 +1,5 @@ import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; -import {find, Path} from '@jsonjoy.com/json-pointer'; +import {find, type Path} from '@jsonjoy.com/json-pointer'; export const execTest = (path: Path, value: unknown, not: boolean, doc: unknown) => { const {val} = find(doc, path); diff --git a/src/json-patch/op/AbstractOp.ts b/src/json-patch/op/AbstractOp.ts index 4226354b00..f07b558783 100644 --- a/src/json-patch/op/AbstractOp.ts +++ b/src/json-patch/op/AbstractOp.ts @@ -2,7 +2,7 @@ import type {CompactOpBase} from '../codec/compact/types'; import type {Path} from '@jsonjoy.com/json-pointer'; import type {OpType} from '../opcodes'; import type {Operation} from '../types'; -import {OPCODE} from '../constants'; +import type {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; export abstract class AbstractOp { diff --git a/src/json-patch/op/OpAdd.ts b/src/json-patch/op/OpAdd.ts index 11274e6381..8cf7bc78b9 100644 --- a/src/json-patch/op/OpAdd.ts +++ b/src/json-patch/op/OpAdd.ts @@ -1,7 +1,7 @@ import type {CompactAddOp, OPCODE_ADD} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationAdd} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationAdd} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -18,7 +18,7 @@ export class OpAdd extends AbstractOp<'add'> { } public op() { - return 'add' as 'add'; + return 'add' as const; } public code() { diff --git a/src/json-patch/op/OpAnd.ts b/src/json-patch/op/OpAnd.ts index 51cb5ed975..73b2501256 100644 --- a/src/json-patch/op/OpAnd.ts +++ b/src/json-patch/op/OpAnd.ts @@ -1,10 +1,10 @@ import type {CompactAndOp, OPCODE_AND} from '../codec/compact/types'; import {AbstractSecondOrderPredicateOp} from './AbstractSecondOrderPredicateOp'; -import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationAnd, PredicateOperation} from '../types'; +import type {AbstractPredicateOp} from './AbstractPredicateOp'; +import type {OperationAnd, PredicateOperation} from '../types'; import {OPCODE} from '../constants'; -import {Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; -import {AbstractOp} from './AbstractOp'; +import {type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -19,7 +19,7 @@ export class OpAnd extends AbstractSecondOrderPredicateOp<'and'> { } public op() { - return 'and' as 'and'; + return 'and' as const; } public code() { diff --git a/src/json-patch/op/OpContains.ts b/src/json-patch/op/OpContains.ts index 6c18a8c2a0..d0fce4b631 100644 --- a/src/json-patch/op/OpContains.ts +++ b/src/json-patch/op/OpContains.ts @@ -1,9 +1,9 @@ import type {CompactContainsOp, OPCODE_CONTAINS} from '../codec/compact/types'; import type {OperationContains} from '../types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -20,7 +20,7 @@ export class OpContains extends AbstractPredicateOp<'contains'> { } public op() { - return 'contains' as 'contains'; + return 'contains' as const; } public code() { diff --git a/src/json-patch/op/OpCopy.ts b/src/json-patch/op/OpCopy.ts index 2f5fb82583..12a53407e1 100644 --- a/src/json-patch/op/OpCopy.ts +++ b/src/json-patch/op/OpCopy.ts @@ -1,7 +1,7 @@ import type {CompactCopyOp, OPCODE_COPY} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationCopy} from '../types'; -import {Path, find, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationCopy} from '../types'; +import {type Path, find, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OpAdd} from './OpAdd'; import {clone as deepClone} from '@jsonjoy.com/util/lib/json-clone/clone'; import {OPCODE} from '../constants'; @@ -19,7 +19,7 @@ export class OpCopy extends AbstractOp<'copy'> { } public op() { - return 'copy' as 'copy'; + return 'copy' as const; } public code() { diff --git a/src/json-patch/op/OpDefined.ts b/src/json-patch/op/OpDefined.ts index e7511338ec..304f0bf34d 100644 --- a/src/json-patch/op/OpDefined.ts +++ b/src/json-patch/op/OpDefined.ts @@ -1,21 +1,17 @@ import type {CompactDefinedOp, OPCODE_DEFINED} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationDefined} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationDefined} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** * @category JSON Predicate */ export class OpDefined extends AbstractPredicateOp<'defined'> { - constructor(path: Path) { - super(path); - } - public op() { - return 'defined' as 'defined'; + return 'defined' as const; } public code() { diff --git a/src/json-patch/op/OpEnds.ts b/src/json-patch/op/OpEnds.ts index 1649177960..a820e17b73 100644 --- a/src/json-patch/op/OpEnds.ts +++ b/src/json-patch/op/OpEnds.ts @@ -1,9 +1,9 @@ import type {CompactEndsOp, OPCODE_ENDS} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationEnds} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationEnds} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -20,7 +20,7 @@ export class OpEnds extends AbstractPredicateOp<'ends'> { } public op() { - return 'ends' as 'ends'; + return 'ends' as const; } public code() { diff --git a/src/json-patch/op/OpExtend.ts b/src/json-patch/op/OpExtend.ts index 52f7ab707b..a71824ecf8 100644 --- a/src/json-patch/op/OpExtend.ts +++ b/src/json-patch/op/OpExtend.ts @@ -1,7 +1,7 @@ import type {CompactExtendOp, OPCODE_EXTEND} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationExtend} from '../types'; -import {find, isArrayReference, isObjectReference, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationExtend} from '../types'; +import {find, isArrayReference, isObjectReference, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -20,7 +20,7 @@ export class OpExtend extends AbstractOp<'extend'> { } public op() { - return 'extend' as 'extend'; + return 'extend' as const; } public code() { diff --git a/src/json-patch/op/OpFlip.ts b/src/json-patch/op/OpFlip.ts index 2c73ad3848..b17102b807 100644 --- a/src/json-patch/op/OpFlip.ts +++ b/src/json-patch/op/OpFlip.ts @@ -1,7 +1,7 @@ import type {CompactFlipOp, OPCODE_FLIP} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationFlip} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationFlip} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -9,12 +9,8 @@ import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; * @category JSON Patch Extended */ export class OpFlip extends AbstractOp<'flip'> { - constructor(path: Path) { - super(path); - } - public op() { - return 'flip' as 'flip'; + return 'flip' as const; } public code() { diff --git a/src/json-patch/op/OpIn.ts b/src/json-patch/op/OpIn.ts index 2d34252766..da6fdf5f8a 100644 --- a/src/json-patch/op/OpIn.ts +++ b/src/json-patch/op/OpIn.ts @@ -1,9 +1,9 @@ import type {CompactInOp, OPCODE_IN} from '../codec/compact/types'; -import {OperationIn} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationIn} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {AbstractPredicateOp} from './AbstractPredicateOp'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -19,7 +19,7 @@ export class OpIn extends AbstractPredicateOp<'in'> { } public op() { - return 'in' as 'in'; + return 'in' as const; } public code() { diff --git a/src/json-patch/op/OpInc.ts b/src/json-patch/op/OpInc.ts index 51227a7f8c..6b237cbaa5 100644 --- a/src/json-patch/op/OpInc.ts +++ b/src/json-patch/op/OpInc.ts @@ -1,7 +1,7 @@ import type {CompactIncOp, OPCODE_INC} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationInc} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationInc} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -17,7 +17,7 @@ export class OpInc extends AbstractOp<'inc'> { } public op() { - return 'inc' as 'inc'; + return 'inc' as const; } public code() { diff --git a/src/json-patch/op/OpLess.ts b/src/json-patch/op/OpLess.ts index 05fecc3127..771ea45081 100644 --- a/src/json-patch/op/OpLess.ts +++ b/src/json-patch/op/OpLess.ts @@ -1,9 +1,9 @@ import type {CompactLessOp, OPCODE_LESS} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationLess} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationLess} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -18,7 +18,7 @@ export class OpLess extends AbstractPredicateOp<'less'> { } public op() { - return 'less' as 'less'; + return 'less' as const; } public code() { diff --git a/src/json-patch/op/OpMatches.ts b/src/json-patch/op/OpMatches.ts index c99311281a..7220665287 100644 --- a/src/json-patch/op/OpMatches.ts +++ b/src/json-patch/op/OpMatches.ts @@ -1,9 +1,9 @@ import type {CompactMatchesOp, OPCODE_MATCHES} from '../codec/compact/types'; import type {OperationMatches, CreateRegexMatcher, RegexMatcher} from '../types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -24,7 +24,7 @@ export class OpMatches extends AbstractPredicateOp<'matches'> { } public op() { - return 'matches' as 'matches'; + return 'matches' as const; } public code() { diff --git a/src/json-patch/op/OpMerge.ts b/src/json-patch/op/OpMerge.ts index 6c2307e7e2..ba62871d00 100644 --- a/src/json-patch/op/OpMerge.ts +++ b/src/json-patch/op/OpMerge.ts @@ -1,7 +1,7 @@ import type {CompactMergeOp, OPCODE_MERGE} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationMerge} from '../types'; -import {find, isArrayReference, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationMerge} from '../types'; +import {find, isArrayReference, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {isTextNode, isElementNode} from '../util'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -19,7 +19,7 @@ export class OpMerge extends AbstractOp<'merge'> { } public op() { - return 'merge' as 'merge'; + return 'merge' as const; } public code() { diff --git a/src/json-patch/op/OpMore.ts b/src/json-patch/op/OpMore.ts index 53b5b57ddf..b0fa9a748b 100644 --- a/src/json-patch/op/OpMore.ts +++ b/src/json-patch/op/OpMore.ts @@ -1,9 +1,9 @@ import type {CompactMoreOp, OPCODE_MORE} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationMore} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationMore} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -18,7 +18,7 @@ export class OpMore extends AbstractPredicateOp<'more'> { } public op() { - return 'more' as 'more'; + return 'more' as const; } public code() { diff --git a/src/json-patch/op/OpMove.ts b/src/json-patch/op/OpMove.ts index 2832c7e031..0bb3a7c20b 100644 --- a/src/json-patch/op/OpMove.ts +++ b/src/json-patch/op/OpMove.ts @@ -1,9 +1,9 @@ import type {CompactMoveOp, OPCODE_MOVE} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationMove} from '../types'; +import type {OperationMove} from '../types'; import {OpRemove} from './OpRemove'; import {OpAdd} from './OpAdd'; -import {Path, toPath, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import {type Path, toPath, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -19,7 +19,7 @@ export class OpMove extends AbstractOp<'move'> { } public op() { - return 'move' as 'move'; + return 'move' as const; } public code() { diff --git a/src/json-patch/op/OpNot.ts b/src/json-patch/op/OpNot.ts index 51e5924af3..e15ac36cfe 100644 --- a/src/json-patch/op/OpNot.ts +++ b/src/json-patch/op/OpNot.ts @@ -1,10 +1,10 @@ import type {CompactNotOp, OPCODE_NOT} from '../codec/compact/types'; import {AbstractSecondOrderPredicateOp} from './AbstractSecondOrderPredicateOp'; -import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationNot, PredicateOperation} from '../types'; +import type {AbstractPredicateOp} from './AbstractPredicateOp'; +import type {OperationNot, PredicateOperation} from '../types'; import {OPCODE} from '../constants'; -import {Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; -import {AbstractOp} from './AbstractOp'; +import {type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -19,7 +19,7 @@ export class OpNot extends AbstractSecondOrderPredicateOp<'not'> { } public op() { - return 'not' as 'not'; + return 'not' as const; } public code() { diff --git a/src/json-patch/op/OpOr.ts b/src/json-patch/op/OpOr.ts index 34db4a3823..9a6810d510 100644 --- a/src/json-patch/op/OpOr.ts +++ b/src/json-patch/op/OpOr.ts @@ -1,10 +1,10 @@ import type {CompactOrOp, OPCODE_OR} from '../codec/compact/types'; import {AbstractSecondOrderPredicateOp} from './AbstractSecondOrderPredicateOp'; -import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationOr, PredicateOperation} from '../types'; +import type {AbstractPredicateOp} from './AbstractPredicateOp'; +import type {OperationOr, PredicateOperation} from '../types'; import {OPCODE} from '../constants'; -import {Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; -import {AbstractOp} from './AbstractOp'; +import {type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -19,7 +19,7 @@ export class OpOr extends AbstractSecondOrderPredicateOp<'or'> { } public op() { - return 'or' as 'or'; + return 'or' as const; } public code() { diff --git a/src/json-patch/op/OpRemove.ts b/src/json-patch/op/OpRemove.ts index 5a7e9ec091..ff8401757e 100644 --- a/src/json-patch/op/OpRemove.ts +++ b/src/json-patch/op/OpRemove.ts @@ -1,7 +1,7 @@ import type {CompactRemoveOp, OPCODE_REMOVE} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationRemove} from '../types'; -import {find, isObjectReference, isArrayReference, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationRemove} from '../types'; +import {find, isObjectReference, isArrayReference, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -17,7 +17,7 @@ export class OpRemove extends AbstractOp<'remove'> { } public op() { - return 'remove' as 'remove'; + return 'remove' as const; } public code() { diff --git a/src/json-patch/op/OpReplace.ts b/src/json-patch/op/OpReplace.ts index 7c81f4fbef..5fc67cb97d 100644 --- a/src/json-patch/op/OpReplace.ts +++ b/src/json-patch/op/OpReplace.ts @@ -1,7 +1,7 @@ import type {CompactReplaceOp, OPCODE_REPLACE} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationReplace} from '../types'; -import {find, isObjectReference, isArrayReference, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationReplace} from '../types'; +import {find, isObjectReference, isArrayReference, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -18,7 +18,7 @@ export class OpReplace extends AbstractOp<'replace'> { } public op() { - return 'replace' as 'replace'; + return 'replace' as const; } public code() { diff --git a/src/json-patch/op/OpSplit.ts b/src/json-patch/op/OpSplit.ts index 02e5250f8e..48301c6930 100644 --- a/src/json-patch/op/OpSplit.ts +++ b/src/json-patch/op/OpSplit.ts @@ -1,7 +1,7 @@ import type {CompactSplitOp, OPCODE_SPLIT} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationSplit, SlateNode, SlateTextNode, SlateElementNode} from '../types'; -import {find, isObjectReference, isArrayReference, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationSplit, SlateNode, SlateTextNode, SlateElementNode} from '../types'; +import {find, isObjectReference, isArrayReference, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {isTextNode, isElementNode} from '../util'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -21,7 +21,7 @@ export class OpSplit extends AbstractOp<'split'> { } public op() { - return 'split' as 'split'; + return 'split' as const; } public code() { diff --git a/src/json-patch/op/OpStarts.ts b/src/json-patch/op/OpStarts.ts index f4fd3ed645..d1c8c1b3ae 100644 --- a/src/json-patch/op/OpStarts.ts +++ b/src/json-patch/op/OpStarts.ts @@ -1,9 +1,9 @@ import type {CompactStartsOp, OPCODE_STARTS} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationStarts} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationStarts} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -20,7 +20,7 @@ export class OpStarts extends AbstractPredicateOp<'starts'> { } public op() { - return 'starts' as 'starts'; + return 'starts' as const; } public code() { diff --git a/src/json-patch/op/OpStrDel.ts b/src/json-patch/op/OpStrDel.ts index 6f47c98d45..1bc16c289e 100644 --- a/src/json-patch/op/OpStrDel.ts +++ b/src/json-patch/op/OpStrDel.ts @@ -1,7 +1,7 @@ import type {CompactStrDelOp, OPCODE_STR_DEL} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationStrDel} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationStrDel} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -19,7 +19,7 @@ export class OpStrDel extends AbstractOp<'str_del'> { } public op() { - return 'str_del' as 'str_del'; + return 'str_del' as const; } public code() { diff --git a/src/json-patch/op/OpStrIns.ts b/src/json-patch/op/OpStrIns.ts index d322237b68..511473ef0e 100644 --- a/src/json-patch/op/OpStrIns.ts +++ b/src/json-patch/op/OpStrIns.ts @@ -1,7 +1,7 @@ import type {CompactStrInsOp, OPCODE_STR_INS} from '../codec/compact/types'; import {AbstractOp} from './AbstractOp'; -import {OperationStrIns} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationStrIns} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -18,7 +18,7 @@ export class OpStrIns extends AbstractOp<'str_ins'> { } public op() { - return 'str_ins' as 'str_ins'; + return 'str_ins' as const; } public code() { diff --git a/src/json-patch/op/OpTest.ts b/src/json-patch/op/OpTest.ts index 6cc27b6fee..289d8a25e4 100644 --- a/src/json-patch/op/OpTest.ts +++ b/src/json-patch/op/OpTest.ts @@ -1,9 +1,9 @@ import type {CompactTestOp, OPCODE_TEST} from '../codec/compact/types'; -import {OperationTest} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationTest} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {AbstractPredicateOp} from './AbstractPredicateOp'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import {deepEqual} from '@jsonjoy.com/util/lib/json-equal/deepEqual'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; @@ -21,7 +21,7 @@ export class OpTest extends AbstractPredicateOp<'test'> { } public op() { - return 'test' as 'test'; + return 'test' as const; } public code() { diff --git a/src/json-patch/op/OpTestString.ts b/src/json-patch/op/OpTestString.ts index 3e64694231..8f29f5da7c 100644 --- a/src/json-patch/op/OpTestString.ts +++ b/src/json-patch/op/OpTestString.ts @@ -1,9 +1,9 @@ import type {CompactTestStringOp, OPCODE_TEST_STRING} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationTestString} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationTestString} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -20,7 +20,7 @@ export class OpTestString extends AbstractPredicateOp<'test_string'> { } public op() { - return 'test_string' as 'test_string'; + return 'test_string' as const; } public code() { diff --git a/src/json-patch/op/OpTestStringLen.ts b/src/json-patch/op/OpTestStringLen.ts index a56e0e7c87..3c7676328d 100644 --- a/src/json-patch/op/OpTestStringLen.ts +++ b/src/json-patch/op/OpTestStringLen.ts @@ -1,9 +1,9 @@ import type {CompactTestStringLenOp, OPCODE_TEST_STRING_LEN} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationTestStringLen} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationTestStringLen} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** @@ -19,7 +19,7 @@ export class OpTestStringLen extends AbstractPredicateOp<'test_string_len'> { } public op() { - return 'test_string_len' as 'test_string_len'; + return 'test_string_len' as const; } public code() { diff --git a/src/json-patch/op/OpTestType.ts b/src/json-patch/op/OpTestType.ts index cd6e39e43c..888bfdca77 100644 --- a/src/json-patch/op/OpTestType.ts +++ b/src/json-patch/op/OpTestType.ts @@ -1,9 +1,9 @@ import type {CompactTestTypeOp, OPCODE_TEST_TYPE} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationTestType, JsTypes, JsonPatchTypes} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationTestType, JsTypes, JsonPatchTypes} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; const {isArray} = Array; @@ -20,7 +20,7 @@ export class OpTestType extends AbstractPredicateOp<'test_type'> { } public op() { - return 'test_type' as 'test_type'; + return 'test_type' as const; } public code() { diff --git a/src/json-patch/op/OpType.ts b/src/json-patch/op/OpType.ts index cf4c83a73e..ca6f4599a2 100644 --- a/src/json-patch/op/OpType.ts +++ b/src/json-patch/op/OpType.ts @@ -1,9 +1,9 @@ import type {CompactTypeOp, OPCODE_TYPE} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationType, JsonPatchTypes} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationType, JsonPatchTypes} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; const {isArray} = Array; @@ -20,7 +20,7 @@ export class OpType extends AbstractPredicateOp<'type'> { } public op() { - return 'type' as 'type'; + return 'type' as const; } public code() { @@ -31,6 +31,7 @@ export class OpType extends AbstractPredicateOp<'type'> { const {val} = find(doc, this.path); if (val === null) return this.value === 'null'; if (isArray(val)) return this.value === 'array'; + // biome-ignore lint: comparison to value is on purpose if (typeof val === this.value) return true; if (typeof val === 'number' && val === Math.round(val) && this.value === 'integer') return true; return false; diff --git a/src/json-patch/op/OpUndefined.ts b/src/json-patch/op/OpUndefined.ts index 886f276fbb..ee9e1f27f0 100644 --- a/src/json-patch/op/OpUndefined.ts +++ b/src/json-patch/op/OpUndefined.ts @@ -1,21 +1,17 @@ import type {CompactUndefinedOp, OPCODE_UNDEFINED} from '../codec/compact/types'; import {AbstractPredicateOp} from './AbstractPredicateOp'; -import {OperationUndefined} from '../types'; -import {find, Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; +import type {OperationUndefined} from '../types'; +import {find, type Path, formatJsonPointer} from '@jsonjoy.com/json-pointer'; import {OPCODE} from '../constants'; -import {AbstractOp} from './AbstractOp'; +import type {AbstractOp} from './AbstractOp'; import type {IMessagePackEncoder} from '@jsonjoy.com/json-pack/lib/msgpack'; /** * @category JSON Predicate */ export class OpUndefined extends AbstractPredicateOp<'undefined'> { - constructor(path: Path) { - super(path); - } - public op() { - return 'undefined' as 'undefined'; + return 'undefined' as const; } public code() { diff --git a/src/json-patch/util.ts b/src/json-patch/util.ts index 490478bfdd..30fbb79fe2 100644 --- a/src/json-patch/util.ts +++ b/src/json-patch/util.ts @@ -1,5 +1,5 @@ -import {CreateRegexMatcher} from '.'; -import {SlateTextNode, SlateElementNode} from './types'; +import type {CreateRegexMatcher} from '.'; +import type {SlateTextNode, SlateElementNode} from './types'; const {isArray} = Array; diff --git a/src/json-patch/validate.ts b/src/json-patch/validate.ts index 0a9651912b..bc950a44f1 100644 --- a/src/json-patch/validate.ts +++ b/src/json-patch/validate.ts @@ -1,4 +1,4 @@ -import { +import type { Operation, OperationAdd, OperationRemove, @@ -23,7 +23,7 @@ import { JsonPatchTypes, } from './types'; import {validateJsonPointer} from '@jsonjoy.com/json-pointer/lib/validate'; -import {hasOwnProperty} from '@jsonjoy.com/util/lib/hasOwnProperty'; +import {hasOwnProperty as hasOwnProp} from '@jsonjoy.com/util/lib/hasOwnProperty'; export const validateOperations = (ops: Operation[], allowMatchesOp: boolean = false) => { if (!Array.isArray(ops)) throw new Error('Not a array.'); @@ -141,11 +141,11 @@ const validateOperationAdd = (op: OperationAdd) => { }; const validateOperationRemove = (op: OperationRemove) => { - if (hasOwnProperty(op, 'oldValue') && op.oldValue === undefined) throw new Error('Invalid oldValue.'); + if (hasOwnProp(op, 'oldValue') && op.oldValue === undefined) throw new Error('Invalid oldValue.'); }; const validateOperationReplace = (op: OperationReplace) => { - if (hasOwnProperty(op, 'oldValue') && op.oldValue === undefined) throw new Error('Invalid oldValue.'); + if (hasOwnProp(op, 'oldValue') && op.oldValue === undefined) throw new Error('Invalid oldValue.'); }; const validateOperationCopy = (op: OperationCopy) => { diff --git a/src/json-size/__tests__/msgpackSizeFast.spec.ts b/src/json-size/__tests__/msgpackSizeFast.spec.ts index 50db96fd3c..9d10e5adf8 100644 --- a/src/json-size/__tests__/msgpackSizeFast.spec.ts +++ b/src/json-size/__tests__/msgpackSizeFast.spec.ts @@ -22,7 +22,7 @@ test('computes size complex object', () => { const embedded = new JsonPackValue(Buffer.from([1, 2])); const extension = new JsonPackExtension(445, new Uint8Array([1, 2, 3])); - // prettier-ignore + // biome-ignore format: keep indentation const json = { // 2 a: 1, // 2 + 1 + 9 b: true, // 2 + 1 + 1 @@ -53,7 +53,7 @@ test('computes size complex object', () => { }; const size = msgpackSizeFast(json); - // prettier-ignore + // biome-ignore format: keep groups of additions expect(size).toBe( 2 + 2 + 1 + 9 + diff --git a/src/json-size/msgpackSizeFast.ts b/src/json-size/msgpackSizeFast.ts index 933aea8936..c2c79159dc 100644 --- a/src/json-size/msgpackSizeFast.ts +++ b/src/json-size/msgpackSizeFast.ts @@ -9,6 +9,7 @@ const arraySize = (arr: unknown[]): number => { const objectSize = (obj: Record): number => { let size = 2; + // biome-ignore lint: object hasOwnProperty check is intentional, Object.hasOwn is too recent for (const key in obj) if (obj.hasOwnProperty(key)) size += 2 + key.length + msgpackSizeFast(obj[key]); return size; }; diff --git a/src/json-stable/index.ts b/src/json-stable/index.ts index 28c767561d..b4f7f1f82a 100644 --- a/src/json-stable/index.ts +++ b/src/json-stable/index.ts @@ -1,14 +1,14 @@ -import {escape} from '@jsonjoy.com/util/lib/strings/escape'; +import {escape as esc} from '@jsonjoy.com/util/lib/strings/escape'; import {sort} from '@jsonjoy.com/util/lib/sort/insertion'; import type {json_string} from '@jsonjoy.com/util/lib/json-brand'; const getKeys = Object.keys; export const stringify = (val: T): json_string => { - let i, max, str, keys, key, propVal; + let i: number, max: number, str: string, keys: string[], key: string, propVal: unknown; switch (typeof val) { case 'string': - return ('"' + escape(val) + '"') as json_string; + return ('"' + esc(val) + '"') as json_string; case 'object': if (val instanceof Array) { str = '['; @@ -26,7 +26,7 @@ export const stringify = (val: T): json_string => { key = keys[i]; propVal = stringify((val as Record)[key]); if (i && str !== '') str += ','; - str += '"' + escape(key) + '":' + propVal; + str += '"' + esc(key) + '":' + propVal; i++; } return (str + '}') as json_string; diff --git a/src/json-walk/index.ts b/src/json-walk/index.ts index 2a675b3594..27ebf803ce 100644 --- a/src/json-walk/index.ts +++ b/src/json-walk/index.ts @@ -17,6 +17,7 @@ export const walk = (value: unknown, callback: (value: unknown) => void): void = case Map: case Set: { const mapOrSet = value as Set | Map; + // biome-ignore lint: .forEach() is the fastest way to iterate over a Set or Map mapOrSet.forEach((val) => walk(val, callback)); break; } diff --git a/yarn.lock b/yarn.lock index a3bde06590..2620065240 100644 --- a/yarn.lock +++ b/yarn.lock @@ -308,6 +308,60 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== +"@biomejs/biome@^1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/biome/-/biome-1.9.4.tgz#89766281cbc3a0aae865a7ff13d6aaffea2842bf" + integrity sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog== + optionalDependencies: + "@biomejs/cli-darwin-arm64" "1.9.4" + "@biomejs/cli-darwin-x64" "1.9.4" + "@biomejs/cli-linux-arm64" "1.9.4" + "@biomejs/cli-linux-arm64-musl" "1.9.4" + "@biomejs/cli-linux-x64" "1.9.4" + "@biomejs/cli-linux-x64-musl" "1.9.4" + "@biomejs/cli-win32-arm64" "1.9.4" + "@biomejs/cli-win32-x64" "1.9.4" + +"@biomejs/cli-darwin-arm64@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.9.4.tgz#dfa376d23a54a2d8f17133c92f23c1bf2e62509f" + integrity sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw== + +"@biomejs/cli-darwin-x64@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.9.4.tgz#eafc2ce3849d385fc02238aad1ca4a73395a64d9" + integrity sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg== + +"@biomejs/cli-linux-arm64-musl@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.9.4.tgz#d780c3e01758fc90f3268357e3f19163d1f84fca" + integrity sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA== + +"@biomejs/cli-linux-arm64@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.9.4.tgz#8ed1dd0e89419a4b66a47f95aefb8c46ae6041c9" + integrity sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g== + +"@biomejs/cli-linux-x64-musl@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.9.4.tgz#f36982b966bd671a36671e1de4417963d7db15fb" + integrity sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg== + +"@biomejs/cli-linux-x64@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-linux-x64/-/cli-linux-x64-1.9.4.tgz#a0a7f56680c76b8034ddc149dbf398bdd3a462e8" + integrity sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg== + +"@biomejs/cli-win32-arm64@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.9.4.tgz#e2ef4e0084e76b7e26f0fc887c5ef1265ea56200" + integrity sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg== + +"@biomejs/cli-win32-x64@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@biomejs/cli-win32-x64/-/cli-win32-x64-1.9.4.tgz#4c7afa90e3970213599b4095e62f87e5972b2340" + integrity sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA== + "@cspotcode/source-map-support@^0.8.0": version "0.8.1" resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"