Skip to content

Commit bae7b77

Browse files
committed
style: 💄 run Prettier
1 parent 745642a commit bae7b77

File tree

5 files changed

+60
-42
lines changed

5 files changed

+60
-42
lines changed

src/json-crdt-repo/local/server-crud/ServerCrudLocalHistory.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export class ServerCrudLocalHistory implements LocalHistory {
1818
this.sync = new ServerCrudLocalHistorySync(opts.sync ?? {}, this.core);
1919
}
2020

21-
public async create(collection: string[], log: Log, id: string = genId()): Promise<{id: string, remote: Promise<void>}> {
21+
public async create(
22+
collection: string[],
23+
log: Log,
24+
id: string = genId(),
25+
): Promise<{id: string; remote: Promise<void>}> {
2226
if (log.end.clock.time <= 1) throw new Error('EMPTY_LOG');
2327
const blob = this.encode(log);
2428
await this.lockForWrite({collection, id}, async () => {
@@ -91,10 +95,16 @@ export class ServerCrudLocalHistory implements LocalHistory {
9195
// };
9296
}
9397

94-
protected async lockForWrite({collection, id}: {
95-
collection: string[];
96-
id: string;
97-
}, fn: () => Promise<void>): Promise<void> {
98+
protected async lockForWrite(
99+
{
100+
collection,
101+
id,
102+
}: {
103+
collection: string[];
104+
id: string;
105+
},
106+
fn: () => Promise<void>,
107+
): Promise<void> {
98108
const key = ['write', collection, id].join('/');
99109
await this.core.locks.lock(key, 300, 300)(fn);
100110
}

src/json-crdt-repo/local/server-crud/ServerCrudLocalHistoryCore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ export class ServerCrudLocalHistoryCore implements ServerCrudLocalHistoryCoreOpt
4545
const blob = await this.crud.get(crudCollection, DATA_FILE_NAME);
4646
return blob;
4747
}
48-
48+
4949
public async create(collection: string[], id: string, blob: Uint8Array): Promise<void> {
5050
const crudCollection = this.crudCollection(collection, id);
5151
await this.crud.put(crudCollection, DATA_FILE_NAME, blob, {throwIf: 'exists'});
5252
}
53-
53+
5454
public async update(collection: string[], id: string, blob: Uint8Array): Promise<void> {
5555
const crudCollection = this.crudCollection(collection, id);
5656
await this.crud.put(crudCollection, DATA_FILE_NAME, blob, {throwIf: 'missing'});

src/json-crdt-repo/local/server-crud/ServerCrudLocalHistorySync.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {timeout} from 'thingies/lib/timeout';
2-
import type {RemoteBlockPatch} from "../../remote/types";
3-
import type {ServerCrudLocalHistoryCore} from "./ServerCrudLocalHistoryCore";
4-
import type {BlockSyncMetadata} from "./types";
2+
import type {RemoteBlockPatch} from '../../remote/types';
3+
import type {ServerCrudLocalHistoryCore} from './ServerCrudLocalHistoryCore';
4+
import type {BlockSyncMetadata} from './types';
55

66
const SYNC_FILE_NAME = 'sync.cbor';
77

@@ -91,10 +91,16 @@ export class ServerCrudLocalHistorySync {
9191
await this.putMeta(collection, id, {time, ts: Date.now()});
9292
}
9393

94-
public async lock<T>({collection, id}: {
95-
collection: string[];
96-
id: string;
97-
}, fn: () => Promise<T>): Promise<T> {
94+
public async lock<T>(
95+
{
96+
collection,
97+
id,
98+
}: {
99+
collection: string[];
100+
id: string;
101+
},
102+
fn: () => Promise<T>,
103+
): Promise<T> {
98104
const key = ['sync', collection, id].join('/');
99105
const locker = this.core.locks.lock(key, this.remoteTimeout() + 200, 200);
100106
return await locker<T>(fn);
@@ -135,8 +141,7 @@ export class ServerCrudLocalHistorySync {
135141
await this.core.crud.info(dir, id);
136142
return true;
137143
} catch (error) {
138-
if (error instanceof DOMException && error.name === 'ResourceNotFound')
139-
return false;
144+
if (error instanceof DOMException && error.name === 'ResourceNotFound') return false;
140145
throw error;
141146
}
142147
}

src/json-crdt-repo/local/server-crud/__tests__/ServerCrudLocalHistory.spec.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import {BehaviorSubject} from 'rxjs';
99
import {setup as remoteSetup} from '../../../remote/__tests__/setup';
1010
import {tick} from 'thingies';
1111

12-
const setup = async (opts: {
13-
remote?: ReturnType<typeof remoteSetup>;
14-
local?: Partial<ServerCrudLocalHistoryOpts>;
15-
} = {}) => {
12+
const setup = async (
13+
opts: {
14+
remote?: ReturnType<typeof remoteSetup>;
15+
local?: Partial<ServerCrudLocalHistoryOpts>;
16+
} = {},
17+
) => {
1618
const remote = opts.remote ?? remoteSetup();
1719
const {fs, vol} = memfs();
1820
const printFs = () => console.log(toTreeSync(fs));
@@ -65,7 +67,7 @@ describe('.create()', () => {
6567
const res = await kit.local.create(['collection'], kit.log, kit.id);
6668
expect(res).toMatchObject({
6769
id: kit.id,
68-
remote: expect.any(Promise)
70+
remote: expect.any(Promise),
6971
});
7072
});
7173

@@ -91,11 +93,12 @@ describe('.create()', () => {
9193
});
9294

9395
describe('when not connected', () => {
94-
const setupNotConnected = () => setup({
95-
local: {
96-
connected$: new BehaviorSubject(false),
97-
}
98-
});
96+
const setupNotConnected = () =>
97+
setup({
98+
local: {
99+
connected$: new BehaviorSubject(false),
100+
},
101+
});
99102

100103
test('throws on empty log', async () => {
101104
const kit = await setupNotConnected();
@@ -108,16 +111,16 @@ describe('.create()', () => {
108111
expect(err).toEqual(new Error('EMPTY_LOG'));
109112
}
110113
});
111-
114+
112115
test('can create a new block', async () => {
113116
const kit = await setupNotConnected();
114117
const res = await kit.local.create(['collection'], kit.log, kit.id);
115118
expect(res).toMatchObject({
116119
id: kit.id,
117-
remote: expect.any(Promise)
120+
remote: expect.any(Promise),
118121
});
119122
});
120-
123+
121124
test('does not store the block on remote, throws on remote sync', async () => {
122125
const kit = await setupNotConnected();
123126
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);
@@ -130,7 +133,7 @@ describe('.create()', () => {
130133
}
131134
expect(kit.remote.services.blocks.stats().blocks).toBe(0);
132135
});
133-
136+
134137
test('marks item as "dirty" for sync', async () => {
135138
const kit = await setupNotConnected();
136139
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);
@@ -168,16 +171,16 @@ describe('.create()', () => {
168171
expect(err).toEqual(new Error('EMPTY_LOG'));
169172
}
170173
});
171-
174+
172175
test('can create a new block', async () => {
173176
const kit = await setupFaultyConnection();
174177
const res = await kit.local.create(['collection'], kit.log, kit.id);
175178
expect(res).toMatchObject({
176179
id: kit.id,
177-
remote: expect.any(Promise)
180+
remote: expect.any(Promise),
178181
});
179182
});
180-
183+
181184
test('does not store the block on remote, throws on remote sync', async () => {
182185
const kit = await setupFaultyConnection();
183186
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);
@@ -190,7 +193,7 @@ describe('.create()', () => {
190193
}
191194
expect(kit.remote.services.blocks.stats().blocks).toBe(0);
192195
});
193-
196+
194197
test('marks item as "dirty" for sync', async () => {
195198
const kit = await setupFaultyConnection();
196199
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);
@@ -236,16 +239,16 @@ describe('.create()', () => {
236239
expect(err).toEqual(new Error('EMPTY_LOG'));
237240
}
238241
});
239-
242+
240243
test('can create a new block', async () => {
241244
const kit = await setupFaultyConnection();
242245
const res = await kit.local.create(['collection'], kit.log, kit.id);
243246
expect(res).toMatchObject({
244247
id: kit.id,
245-
remote: expect.any(Promise)
248+
remote: expect.any(Promise),
246249
});
247250
});
248-
251+
249252
test('does not store the block on remote, throws on remote sync', async () => {
250253
const kit = await setupFaultyConnection();
251254
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);
@@ -258,7 +261,7 @@ describe('.create()', () => {
258261
}
259262
expect(kit.remote.services.blocks.stats().blocks).toBe(0);
260263
});
261-
264+
262265
test('marks item as "dirty" for sync', async () => {
263266
const kit = await setupFaultyConnection();
264267
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);
@@ -304,16 +307,16 @@ describe('.create()', () => {
304307
expect(err).toEqual(new Error('EMPTY_LOG'));
305308
}
306309
});
307-
310+
308311
test('can create a new block', async () => {
309312
const kit = await setupFaultyConnection();
310313
const res = await kit.local.create(['collection'], kit.log, kit.id);
311314
expect(res).toMatchObject({
312315
id: kit.id,
313-
remote: expect.any(Promise)
316+
remote: expect.any(Promise),
314317
});
315318
});
316-
319+
317320
test('marks item as "dirty" for sync, but synchronizes over time', async () => {
318321
const kit = await setupFaultyConnection();
319322
const res = await kit.local.create(['my', 'col'], kit.log, kit.id);

src/json-crdt-repo/local/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {Patch} from 'json-joy/lib/json-crdt-patch';
22
import type {Log} from 'json-joy/lib/json-crdt/log/Log';
33

44
export interface LocalHistory {
5-
create(collection: string[], log: Log, id?: string): Promise<{id: string, remote: Promise<void>}>;
5+
create(collection: string[], log: Log, id?: string): Promise<{id: string; remote: Promise<void>}>;
66
read(collection: string[], id: string): Promise<{log: Log; cursor: string}>;
77
readHistory(collection: string[], id: string, cursor: string): Promise<{log: Log; cursor: string}>;
88
update(collection: string[], id: string, patches: Patch[]): Promise<void>;

0 commit comments

Comments
 (0)