Skip to content

Commit 76bb748

Browse files
committed
style(json-crdt): 💄 run Prettier
1 parent f9e1ff7 commit 76bb748

File tree

4 files changed

+38
-56
lines changed

4 files changed

+38
-56
lines changed

src/json-crdt/file/File.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
import {Model} from "../model";
2-
import {PatchLog} from "./PatchLog";
3-
import {FileModelEncoding} from "./constants";
1+
import {Model} from '../model';
2+
import {PatchLog} from './PatchLog';
3+
import {FileModelEncoding} from './constants';
44
import {Encoder as SidecarEncoder} from '../codec/sidecar/binary/Encoder';
55
import {Encoder as StructuralEncoderCompact} from '../codec/structural/compact/Encoder';
66
import {Encoder as StructuralEncoderVerbose} from '../codec/structural/verbose/Encoder';
77
import {encode as encodeCompact} from '../../json-crdt-patch/codec/compact/encode';
88
import {encode as encodeVerbose} from '../../json-crdt-patch/codec/verbose/encode';
9-
import {printTree} from "../../util/print/printTree";
10-
import type * as types from "./types";
11-
import type {Printable} from "../../util/print/types";
9+
import {printTree} from '../../util/print/printTree';
10+
import type * as types from './types';
11+
import type {Printable} from '../../util/print/types';
1212

1313
export class File implements Printable {
1414
public static fromModel(model: Model<any>): File {
1515
return new File(model, PatchLog.fromModel(model));
1616
}
1717

18-
constructor(
19-
public readonly model: Model,
20-
public readonly history: PatchLog,
21-
) {}
18+
constructor(public readonly model: Model, public readonly history: PatchLog) {}
2219

2320
public serialize(params: types.FileSerializeParams = {}): types.FileWriteSequence {
2421
const view = this.model.view();
25-
const metadata: types.FileMetadata = [
26-
{},
27-
FileModelEncoding.SidecarBinary,
28-
];
22+
const metadata: types.FileMetadata = [{}, FileModelEncoding.SidecarBinary];
2923
let model: Uint8Array | unknown | null = null;
3024
const modelFormat = params.model ?? 'sidecar';
3125
switch (modelFormat) {
@@ -54,10 +48,7 @@ export class File implements Printable {
5448
default:
5549
throw new Error(`Invalid model format: ${modelFormat}`);
5650
}
57-
const history: types.FileWriteSequenceHistory = [
58-
null,
59-
[],
60-
];
51+
const history: types.FileWriteSequenceHistory = [null, []];
6152
const patchFormat = params.history ?? 'binary';
6253
switch (patchFormat) {
6354
case 'binary': {
@@ -84,21 +75,12 @@ export class File implements Printable {
8475
default:
8576
throw new Error(`Invalid history format: ${patchFormat}`);
8677
}
87-
return [
88-
view,
89-
metadata,
90-
model,
91-
history,
92-
];
78+
return [view, metadata, model, history];
9379
}
9480

9581
// ---------------------------------------------------------------- Printable
9682

9783
public toString(tab?: string) {
98-
return `file` + printTree(tab, [
99-
(tab) => this.model.toString(tab),
100-
() => '',
101-
(tab) => this.history.toString(tab),
102-
]);
84+
return `file` + printTree(tab, [(tab) => this.model.toString(tab), () => '', (tab) => this.history.toString(tab)]);
10385
}
10486
}

src/json-crdt/file/PatchLog.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {ITimestampStruct, Patch, compare} from "../../json-crdt-patch";
2-
import {printTree} from "../../util/print/printTree";
3-
import {AvlMap} from "../../util/trees/avl/AvlMap";
4-
import {Model} from "../model";
5-
import type {Printable} from "../../util/print/types";
1+
import {ITimestampStruct, Patch, compare} from '../../json-crdt-patch';
2+
import {printTree} from '../../util/print/printTree';
3+
import {AvlMap} from '../../util/trees/avl/AvlMap';
4+
import {Model} from '../model';
5+
import type {Printable} from '../../util/print/types';
66

77
export class PatchLog implements Printable {
88
public static fromModel(model: Model<any>): PatchLog {
@@ -17,7 +17,7 @@ export class PatchLog implements Printable {
1717

1818
public readonly patches = new AvlMap<ITimestampStruct, Patch>(compare);
1919

20-
constructor (public readonly start: Model) {}
20+
constructor(public readonly start: Model) {}
2121

2222
public push(patch: Patch): void {
2323
const id = patch.getId();
@@ -30,10 +30,18 @@ export class PatchLog implements Printable {
3030
public toString(tab?: string) {
3131
const log: Patch[] = [];
3232
this.patches.forEach(({v}) => log.push(v));
33-
return `log` + printTree(tab, [
34-
(tab) => this.start.toString(tab),
35-
() => '',
36-
(tab) => 'history' + printTree(tab, log.map((patch, i) => (tab) => `${i}: ${patch.toString(tab)}`)),
37-
]);
33+
return (
34+
`log` +
35+
printTree(tab, [
36+
(tab) => this.start.toString(tab),
37+
() => '',
38+
(tab) =>
39+
'history' +
40+
printTree(
41+
tab,
42+
log.map((patch, i) => (tab) => `${i}: ${patch.toString(tab)}`),
43+
),
44+
])
45+
);
3846
}
3947
}

src/json-crdt/file/__tests__/File.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import {Model} from '../../model';
33
import {File} from '../File';
44

55
test('can create File from new model', () => {
6-
const model = Model.withServerClock()
7-
.setSchema(s.obj({
6+
const model = Model.withServerClock().setSchema(
7+
s.obj({
88
foo: s.str('bar'),
9-
}));
9+
}),
10+
);
1011
const file = File.fromModel(model);
1112
expect(file.history.start.view()).toBe(undefined);
1213
expect(file.model.view()).toEqual({

src/json-crdt/file/types.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import type {FileModelEncoding} from "./constants";
1+
import type {FileModelEncoding} from './constants';
22

3-
export type FileMetadata = [
4-
map: {},
5-
modelFormat: FileModelEncoding,
6-
];
3+
export type FileMetadata = [map: {}, modelFormat: FileModelEncoding];
74

85
export type FileWriteSequence = [
96
view: unknown | null,
@@ -12,15 +9,9 @@ export type FileWriteSequence = [
129
history: FileWriteSequenceHistory,
1310
];
1411

15-
export type FileWriteSequenceHistory = [
16-
model: Uint8Array | unknown | null,
17-
patches: Array<Uint8Array | unknown>,
18-
];
12+
export type FileWriteSequenceHistory = [model: Uint8Array | unknown | null, patches: Array<Uint8Array | unknown>];
1913

20-
export type FileReadSequence = [
21-
...FileWriteSequence,
22-
...frontier: Array<Uint8Array | unknown>,
23-
];
14+
export type FileReadSequence = [...FileWriteSequence, ...frontier: Array<Uint8Array | unknown>];
2415

2516
export interface FileSerializeParams {
2617
noView?: boolean;

0 commit comments

Comments
 (0)