Skip to content

Commit 8123dd2

Browse files
committed
style: 💄 apply Prettier
1 parent 9559e60 commit 8123dd2

File tree

20 files changed

+151
-117
lines changed

20 files changed

+151
-117
lines changed

src/__tests__/msgpack-documents.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {JsonPackExtension, JsonPackValue} from "../json-pack";
2-
import {encodeFull} from "../json-pack/util";
1+
import {JsonPackExtension, JsonPackValue} from '../json-pack';
2+
import {encodeFull} from '../json-pack/util';
33

44
export interface JsonDocument {
55
name: string;
@@ -24,9 +24,7 @@ export const msgPackDocuments: JsonDocument[] = [
2424
},
2525
{
2626
name: 'MessagePack value in array',
27-
json: [
28-
new JsonPackValue(encodeFull(null)),
29-
],
27+
json: [new JsonPackValue(encodeFull(null))],
3028
},
3129
{
3230
name: 'MessagePack extension',
@@ -36,7 +34,7 @@ export const msgPackDocuments: JsonDocument[] = [
3634
name: 'MessagePack extension in object',
3735
json: {
3836
foo: new JsonPackExtension(1, new Uint8Array([1, 2, 3])),
39-
}
37+
},
4038
},
4139
{
4240
name: 'MessagePack extension in array',

src/json-binary/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ const unwrapBinary = (value: unknown): unknown => {
3333
}
3434
case 'string': {
3535
if (item.length < minDataUri) continue;
36-
if (item.substring(0, binUriStartLength) === binUriStart) value[i] = fromBase64(item.substring(binUriStartLength));
36+
if (item.substring(0, binUriStartLength) === binUriStart)
37+
value[i] = fromBase64(item.substring(binUriStartLength));
3738
else if (item.substring(0, msgPackUriStartLength) === msgPackUriStart)
3839
value[i] = new JsonPackValue(fromBase64(item.substring(msgPackUriStartLength)));
3940
else if (item.substring(0, msgPackExtStartLength) === msgPackExtStart) value[i] = parseExtDataUri(item);
@@ -57,8 +58,8 @@ const unwrapBinary = (value: unknown): unknown => {
5758
(value as any)[key] = buf;
5859
} else if (item.substring(0, msgPackUriStartLength) === msgPackUriStart) {
5960
(value as any)[key] = new JsonPackValue(fromBase64(item.substring(msgPackUriStartLength)));
60-
}
61-
else if (item.substring(0, msgPackExtStartLength) === msgPackExtStart) (value as any)[key] = parseExtDataUri(item);
61+
} else if (item.substring(0, msgPackExtStartLength) === msgPackExtStart)
62+
(value as any)[key] = parseExtDataUri(item);
6263
}
6364
}
6465
}
@@ -67,7 +68,8 @@ const unwrapBinary = (value: unknown): unknown => {
6768
if (typeof value === 'string') {
6869
if (value.length < minDataUri) return value;
6970
if (value.substring(0, binUriStartLength) === binUriStart) return fromBase64(value.substring(binUriStartLength));
70-
if (value.substring(0, msgPackUriStartLength) === msgPackUriStart) return new JsonPackValue(fromBase64(value.substring(msgPackUriStartLength)));
71+
if (value.substring(0, msgPackUriStartLength) === msgPackUriStart)
72+
return new JsonPackValue(fromBase64(value.substring(msgPackUriStartLength)));
7173
if (value.substring(0, msgPackExtStartLength) === msgPackExtStart) return parseExtDataUri(value);
7274
else return value;
7375
}

src/json-block/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Observable} from "rxjs";
1+
import type {Observable} from 'rxjs';
22

33
export interface BlockServerApi {
44
create: () => Promise<void>;
@@ -18,7 +18,7 @@ export interface BlockClientApiMergeRequest {
1818
* There are a number of scenarios that can happen
1919
* when merging changes. The possible scenarios also depend
2020
* on the collaborative editing algorithm used for the block.
21-
*
21+
*
2222
* 1. The batch is accepted without any conflicts (changes).
2323
* 2. The batch is accepted with conflicts, hence the batch may be
2424
* be modified to resolve the conflicts. This is relevant for

src/json-crdt/codec/binary/Encoder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Encoder extends CrdtEncoder {
4646
delete this.literals;
4747
return this.flush();
4848
}
49-
49+
5050
protected encodeLiteralsTable(model: Model) {
5151
const literalFrequencies = new Map<string | number, number>();
5252
for (const node of model.nodes.iterate()) {
@@ -75,11 +75,9 @@ export class Encoder extends CrdtEncoder {
7575
}
7676
}
7777
const literals: unknown[] = [];
78-
for (const [literal, frequency] of literalFrequencies.entries())
79-
if (frequency > 1) literals.push(literal);
78+
for (const [literal, frequency] of literalFrequencies.entries()) if (frequency > 1) literals.push(literal);
8079
this.encodeArray(literals);
81-
for (let i = 0; i < literals.length; i++)
82-
this.literals!.set(literals[i], i);
80+
for (let i = 0; i < literals.length; i++) this.literals!.set(literals[i], i);
8381
}
8482

8583
protected encodeClockTable(data: Uint8Array) {

src/json-crdt/codec/binary/__tests__/ViewDecoder.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ describe('logical', () => {
99
doc1.api.root([1, 'asdf', false, {}, {foo: 'bar'}]).commit();
1010
doc1.api.str([1]).ins(4, '!').commit();
1111
doc1.api.str([4, 'foo']).del(1, 1).commit();
12-
doc1.api.arr([]).ins(1, [new Uint8Array([1, 2, 3])]).commit();
12+
doc1.api
13+
.arr([])
14+
.ins(1, [new Uint8Array([1, 2, 3])])
15+
.commit();
1316
doc1.api.bin([1]).del(2, 1).commit();
1417
doc1.api.arr([]).ins(6, ['a', 'b', 'c']).commit();
1518
doc1.api.arr([]).del(7, 1).commit();

src/json-crdt/codec/binary/__tests__/literals.spec.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import {Encoder} from '../Encoder';
44
test('encodes repeating object keys into literals table', () => {
55
const encoder = new Encoder();
66
const model1 = Model.withLogicalClock();
7-
model1.api.root({
8-
foooo: {
9-
baaar: 0,
10-
}
11-
}).commit();
7+
model1.api
8+
.root({
9+
foooo: {
10+
baaar: 0,
11+
},
12+
})
13+
.commit();
1214
const model2 = Model.withLogicalClock();
13-
model2.api.root({
14-
foooo: {
15-
foooo: 0,
16-
}
17-
}).commit();
15+
model2.api
16+
.root({
17+
foooo: {
18+
foooo: 0,
19+
},
20+
})
21+
.commit();
1822
const encoded1 = encoder.encode(model1);
1923
const encoded2 = encoder.encode(model2);
2024
expect(encoded1.byteLength > encoded2.byteLength).toBe(true);

src/json-crdt/json-patch/JsonPatchDraft.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ import {ObjectType} from '../types/lww-object/ObjectType';
66
import {UNDEFINED_ID} from '../../json-crdt-patch/constants';
77
import {toPath} from '../../json-pointer/util';
88
import type {Model} from '../model';
9-
import type {Operation, OperationAdd, OperationRemove, OperationReplace, OperationMove, OperationCopy, OperationTest, OperationStrIns, OperationStrDel} from '../../json-patch';
9+
import type {
10+
Operation,
11+
OperationAdd,
12+
OperationRemove,
13+
OperationReplace,
14+
OperationMove,
15+
OperationCopy,
16+
OperationTest,
17+
OperationStrIns,
18+
OperationStrDel,
19+
} from '../../json-patch';
1020

1121
export class JsonPatchDraft {
1222
public readonly draft = new Draft();
@@ -18,16 +28,33 @@ export class JsonPatchDraft {
1828
}
1929

2030
public applyOp(op: Operation): void {
21-
switch(op.op) {
22-
case 'add': this.applyOpAdd(op); break;
23-
case 'remove': this.applyRemove(op); break;
24-
case 'replace': this.applyReplace(op); break;
25-
case 'move': this.applyMove(op); break;
26-
case 'copy': this.applyCopy(op); break;
27-
case 'test': this.applyTest(op); break;
28-
case 'str_ins': this.applyStrIns(op); break;
29-
case 'str_del': this.applyStrDel(op); break;
30-
default: throw new Error('UNKNOWN_OP');
31+
switch (op.op) {
32+
case 'add':
33+
this.applyOpAdd(op);
34+
break;
35+
case 'remove':
36+
this.applyRemove(op);
37+
break;
38+
case 'replace':
39+
this.applyReplace(op);
40+
break;
41+
case 'move':
42+
this.applyMove(op);
43+
break;
44+
case 'copy':
45+
this.applyCopy(op);
46+
break;
47+
case 'test':
48+
this.applyTest(op);
49+
break;
50+
case 'str_ins':
51+
this.applyStrIns(op);
52+
break;
53+
case 'str_del':
54+
this.applyStrDel(op);
55+
break;
56+
default:
57+
throw new Error('UNKNOWN_OP');
3158
}
3259
}
3360

src/json-crdt/json-patch/__tests__/JsonPatch.str.spec.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const testCases: TestCase[] = [
5353
doc1: null,
5454
patches: [
5555
[{op: 'add', path: '', value: {foo: [{bar: 'baz'}]}}],
56-
[{op: 'str_ins', path: '/foo/0/bar', pos: 3, str: '!'}]
56+
[{op: 'str_ins', path: '/foo/0/bar', pos: 3, str: '!'}],
5757
],
5858
doc2: {foo: [{bar: 'baz!'}]},
5959
},
@@ -62,73 +62,56 @@ const testCases: TestCase[] = [
6262
doc1: null,
6363
patches: [
6464
[{op: 'add', path: '', value: {foo: [{bar: 'baz'}]}}],
65-
[{op: 'str_ins', path: ['foo', 0, 'bar'], pos: 3, str: '!'}]
65+
[{op: 'str_ins', path: ['foo', 0, 'bar'], pos: 3, str: '!'}],
6666
],
6767
doc2: {foo: [{bar: 'baz!'}]},
6868
},
6969
{
7070
name: 'can delete a single char',
7171
doc1: 'a',
72-
patches: [
73-
[{op: 'str_del', path: [], pos: 0, len: 1}]
74-
],
72+
patches: [[{op: 'str_del', path: [], pos: 0, len: 1}]],
7573
doc2: '',
7674
},
7775
{
7876
name: 'can delete from already empty string',
7977
doc1: '',
80-
patches: [
81-
[{op: 'str_del', path: [], pos: 0, len: 1}]
82-
],
78+
patches: [[{op: 'str_del', path: [], pos: 0, len: 1}]],
8379
doc2: '',
8480
},
8581
{
8682
name: 'can delete at the end of string',
8783
doc1: 'ab',
88-
patches: [
89-
[{op: 'str_del', path: [], pos: 1, len: 1}]
90-
],
84+
patches: [[{op: 'str_del', path: [], pos: 1, len: 1}]],
9185
doc2: 'a',
9286
},
9387
{
9488
name: 'can delete at the beginning of string',
9589
doc1: 'ab',
96-
patches: [
97-
[{op: 'str_del', path: [], pos: 0, len: 1}]
98-
],
90+
patches: [[{op: 'str_del', path: [], pos: 0, len: 1}]],
9991
doc2: 'b',
10092
},
10193
{
10294
name: 'can delete in the middle of string',
10395
doc1: 'abc',
104-
patches: [
105-
[{op: 'str_del', path: [], pos: 1, len: 1}]
106-
],
96+
patches: [[{op: 'str_del', path: [], pos: 1, len: 1}]],
10797
doc2: 'ac',
10898
},
10999
{
110100
name: 'can delete multiple chars',
111101
doc1: '1234',
112-
patches: [
113-
[{op: 'str_del', path: [], pos: 1, len: 2}],
114-
[{op: 'str_del', path: [], pos: 1, len: 5}],
115-
],
102+
patches: [[{op: 'str_del', path: [], pos: 1, len: 2}], [{op: 'str_del', path: [], pos: 1, len: 5}]],
116103
doc2: '1',
117104
},
118105
{
119106
name: 'handles deletion beyond end of string',
120107
doc1: '1234',
121-
patches: [
122-
[{op: 'str_del', path: [], pos: 1111, len: 2}],
123-
],
108+
patches: [[{op: 'str_del', path: [], pos: 1111, len: 2}]],
124109
doc2: '1234',
125110
},
126111
{
127112
name: 'can delete a string in object',
128113
doc1: {foo: '123'},
129-
patches: [
130-
[{op: 'str_del', path: '/foo', pos: 1, len: 2}],
131-
],
114+
patches: [[{op: 'str_del', path: '/foo', pos: 1, len: 2}]],
132115
doc2: {foo: '1'},
133116
},
134117
];

src/json-crdt/model/__tests__/Model.caching.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Model} from "..";
1+
import {Model} from '..';
22

33
test('returns cached value, when shallow object keys not modified', () => {
44
const model = Model.withLogicalClock();

src/json-crdt/model/__tests__/fuzzer/Picker.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,7 @@ type BinaryOp = typeof InsertBinaryDataOperation | typeof DeleteOperation;
1919
type ArrayOp = typeof InsertArrayElementsOperation | typeof DeleteOperation;
2020
type ObjectOp = typeof SetObjectKeysOperation | typeof DeleteOperation;
2121

22-
const commonKeys = [
23-
'a',
24-
'op',
25-
'test',
26-
'name',
27-
'',
28-
'__proto__',
29-
];
22+
const commonKeys = ['a', 'op', 'test', 'name', '', '__proto__'];
3023

3124
/**
3225
* This class picks random nodes from a model and picks a random

0 commit comments

Comments
 (0)