Skip to content

Commit b97a842

Browse files
committed
style: 💄 fix linter issues
1 parent 1d96827 commit b97a842

File tree

7 files changed

+91
-42
lines changed

7 files changed

+91
-42
lines changed

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"noAssignInExpressions": "off",
3636
"noConfusingLabels": "off",
3737
"noConfusingVoidType": "off",
38-
"noConstEnum": "off"
38+
"noConstEnum": "off",
39+
"noSelfCompare": "off"
3940
},
4041
"complexity": {
4142
"noStaticOnlyClass": "off",

src/json-crdt/model/api/ModelApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {VecNode, ConNode, ObjNode, ArrNode, BinNode, StrNode, ValNode} from '../
33
import {type ApiPath, ArrApi, BinApi, ConApi, type NodeApi, ObjApi, StrApi, VecApi, ValApi} from './nodes';
44
import {PatchBuilder} from '../../../json-crdt-patch/PatchBuilder';
55
import {MergeFanOut, MicrotaskBufferFanOut} from './fanout';
6-
import {JsonNodeToProxyPathNode, proxy$} from './proxy';
6+
import {type JsonNodeToProxyPathNode, proxy$} from './proxy';
77
import {ExtNode} from '../../extensions/ExtNode';
88
import type {Patch} from '../../../json-crdt-patch/Patch';
99
import type {SyncStore} from '../../../util/events/sync-store';
@@ -109,15 +109,15 @@ export class ModelApi<N extends JsonNode = JsonNode> implements SyncStore<JsonNo
109109

110110
/**
111111
* @ignore
112-
*
112+
*
113113
* @todo Remove this getter?
114114
*/
115115
public get node() {
116116
return this.r.get();
117117
}
118118

119119
public get $(): JsonNodeToProxyPathNode<N> {
120-
return proxy$(path => {
120+
return proxy$((path) => {
121121
try {
122122
return this.wrap(this.find(path));
123123
} catch {

src/json-crdt/model/api/__tests__/NodeApi.spec.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ describe('.read()', () => {
5555
});
5656

5757
test('can read within a "con" node', () => {
58-
const doc = Model.create(s.obj({
59-
con: s.con({
60-
foo: [1, 2, 3]
58+
const doc = Model.create(
59+
s.obj({
60+
con: s.con({
61+
foo: [1, 2, 3],
62+
}),
6163
}),
62-
}))
64+
);
6365
expect(doc.api.read('/con/foo/1')).toBe(2);
6466
});
6567
});
@@ -139,16 +141,16 @@ describe('.add()', () => {
139141
test('can set key to a complex value', () => {
140142
const doc = createTypedModel();
141143
expect(doc.api.read('/obj/newKey')).toBe(undefined);
142-
doc.api.add('/obj/newKey', { nested: { deep: { value: 4 } } });
143-
expect(doc.api.read('/obj/newKey')).toEqual({ nested: { deep: { value: 4 } } });
144+
doc.api.add('/obj/newKey', {nested: {deep: {value: 4}}});
145+
expect(doc.api.read('/obj/newKey')).toEqual({nested: {deep: {value: 4}}});
144146
expect((doc.$.obj as any).newKey.$ instanceof ObjApi).toBe(true);
145147
});
146148

147149
test('can specify exact schema for the new value', () => {
148150
const doc = createTypedModel();
149151
expect(doc.api.read('/obj/newKey')).toBe(undefined);
150-
doc.api.add('/obj/newKey', s.con({ nested: { deep: { value: 4 } } }));
151-
expect(doc.api.read('/obj/newKey')).toEqual({ nested: { deep: { value: 4 } } });
152+
doc.api.add('/obj/newKey', s.con({nested: {deep: {value: 4}}}));
153+
expect(doc.api.read('/obj/newKey')).toEqual({nested: {deep: {value: 4}}});
152154
expect((doc.$.obj as any).newKey.$ instanceof ConApi).toBe(true);
153155
});
154156
});
@@ -186,7 +188,7 @@ describe('.add()', () => {
186188
expect(doc.api.read('/arr/1')).toBe('asdf');
187189
expect(success).toBe(true);
188190
});
189-
191+
190192
test('can add element to the beginning of array (on "arr" node)', () => {
191193
const doc = createTypedModel();
192194
expect(doc.api.read('/arr/0')).toBe('asdf');
@@ -306,23 +308,35 @@ describe('.add()', () => {
306308

307309
describe('"val" node', () => {
308310
test('when parent is wrapped in "val" node', () => {
309-
const doc = Model.create(s.obj({
310-
obj: s.val(s.obj({
311-
foo: s.str('bar'),
312-
})),
313-
}));
311+
const doc = Model.create(
312+
s.obj({
313+
obj: s.val(
314+
s.obj({
315+
foo: s.str('bar'),
316+
}),
317+
),
318+
}),
319+
);
314320
expect(doc.view()).toEqual({obj: {foo: 'bar'}});
315321
const success1 = doc.api.add('/obj/foo', 'baz');
316322
expect(doc.view()).toEqual({obj: {foo: 'baz'}});
317323
expect(success1).toBe(true);
318324
});
319325

320326
test('when parent is wrapped in "val" node three times', () => {
321-
const doc = Model.create(s.obj({
322-
obj: s.val(s.val(s.val(s.obj({
323-
foo: s.str('bar'),
324-
})))),
325-
}));
327+
const doc = Model.create(
328+
s.obj({
329+
obj: s.val(
330+
s.val(
331+
s.val(
332+
s.obj({
333+
foo: s.str('bar'),
334+
}),
335+
),
336+
),
337+
),
338+
}),
339+
);
326340
expect(doc.view()).toEqual({obj: {foo: 'bar'}});
327341
const success1 = doc.api.add('/obj/foo', 'baz');
328342
expect(doc.view()).toEqual({obj: {foo: 'baz'}});
@@ -363,7 +377,7 @@ describe('.replace()', () => {
363377
expect(success).toBe(false);
364378
});
365379
});
366-
380+
367381
describe('"arr" node', () => {
368382
test('can replace "val" value in "arr" node', () => {
369383
const doc = createTypedModel();

src/json-crdt/model/api/__tests__/fixtures.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ export const createUntypedModel = () => {
3333
},
3434
},
3535
},
36-
arr: [1, 2, {
37-
nested: [1, 2, 3],
38-
deep: {
39-
value: 4
40-
}
41-
}],
36+
arr: [
37+
1,
38+
2,
39+
{
40+
nested: [1, 2, 3],
41+
deep: {
42+
value: 4,
43+
},
44+
},
45+
],
4246
});
4347
return doc;
4448
};

src/json-crdt/model/api/__tests__/proxy.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ describe('proxy()', () => {
2929
});
3030

3131
test('can provide custom API', () => {
32-
const path = () => proxy((path) => ({
33-
join: () => path.join('.'),
34-
}));
32+
const path = () =>
33+
proxy((path) => ({
34+
join: () => path.join('.'),
35+
}));
3536
expect(path().a.b[2].c().join()).toBe('a.b.2.c');
3637
});
3738
});

src/json-crdt/model/api/nodes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ const breakPath = (path: ApiPath): [parent: Path | undefined, key: string | numb
2121
if (typeof path === 'number') return [void 0, path];
2222
if (typeof path === 'string') path = toPath(path);
2323
switch (path.length) {
24-
case 0: return [void 0, ''];
25-
case 1: return [void 0, path[0]];
24+
case 0:
25+
return [void 0, ''];
26+
case 1:
27+
return [void 0, path[0]];
2628
default: {
2729
const key = path[path.length - 1];
2830
const parent = path.slice(0, -1);
@@ -276,7 +278,7 @@ export class NodeApi<N extends JsonNode = JsonNode> implements Printable {
276278
} catch {}
277279
return false;
278280
}
279-
281+
280282
public remove(path: ApiPath, length: number = 1): boolean {
281283
const [parent, key] = breakPath(path);
282284
REMOVE: try {

src/json-crdt/model/api/proxy.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type JsonNodeToProxyNode<N> = N extends nodes.ConNode<any>
5353
export type JsonNodeToProxyPathNodeEnd<N> = {$?: JsonNodeApi<N>};
5454

5555
// prettier-ignore
56-
export type JsonNodeToProxyPathNode<N> = 0 extends (1 & N)
56+
export type JsonNodeToProxyPathNode<N> = 0 extends 1 & N
5757
? ProxyPathNode<{$?: NodeApi<N extends nodes.JsonNode<unknown> ? N : nodes.JsonNode>}>
5858
: N extends nodes.ArrNode<infer Element>
5959
? JsonNodeToProxyPathNode<Element>[] & JsonNodeToProxyPathNodeEnd<N>
@@ -66,15 +66,42 @@ export type JsonNodeToProxyPathNode<N> = 0 extends (1 & N)
6666
: JsonNodeToProxyPathNodeEnd<N>;
6767

6868
export type ProxyPathEndMethod<Args extends unknown[], Return> = (path: PathStep[], ...args: Args) => Return;
69-
export type ProxyPathUserEndMethod<M extends ProxyPathEndMethod<any[], any>> = M extends ProxyPathEndMethod<infer Args, infer Return> ? ((...args: Args) => Return) : never;
69+
export type ProxyPathUserEndMethod<M extends ProxyPathEndMethod<any[], any>> = M extends ProxyPathEndMethod<
70+
infer Args,
71+
infer Return
72+
>
73+
? (...args: Args) => Return
74+
: never;
7075
export type ProxyPathNodeStep<Api, Next> = Api & Record<string | number, Next>;
71-
export type ProxyPathNode<Api> = ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, any>>>>>>>>;
76+
export type ProxyPathNode<Api> = ProxyPathNodeStep<
77+
Api,
78+
ProxyPathNodeStep<
79+
Api,
80+
ProxyPathNodeStep<
81+
Api,
82+
ProxyPathNodeStep<
83+
Api,
84+
ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, ProxyPathNodeStep<Api, any>>>>
85+
>
86+
>
87+
>
88+
>;
7289

73-
export const proxy = <EndMethod extends ProxyPathEndMethod<any[], any>>(fn: EndMethod, path: PathStep[] = []): ProxyPathNode<ProxyPathUserEndMethod<EndMethod>> =>
90+
export const proxy = <EndMethod extends ProxyPathEndMethod<any[], any>>(
91+
fn: EndMethod,
92+
path: PathStep[] = [],
93+
): ProxyPathNode<ProxyPathUserEndMethod<EndMethod>> =>
7494
new Proxy(() => {}, {
7595
get: (target, prop, receiver) => (path.push(String(prop)), proxy(fn, path)),
7696
apply: (target, thisArg, args) => fn(path, ...args),
7797
}) as any;
7898

79-
export const proxy$ = <EndMethod extends ProxyPathEndMethod<any[], any>, Sentinel extends string>(fn: EndMethod, sentinel: Sentinel, path: PathStep[] = []): ProxyPathNode<{[k in Sentinel]: ReturnType<EndMethod>}> =>
80-
new Proxy({}, {get: (t, prop, r) => prop === sentinel ? fn(path) : (path.push(String(prop)), proxy$(fn, sentinel, path))}) as any;
99+
export const proxy$ = <EndMethod extends ProxyPathEndMethod<any[], any>, Sentinel extends string>(
100+
fn: EndMethod,
101+
sentinel: Sentinel,
102+
path: PathStep[] = [],
103+
): ProxyPathNode<{[k in Sentinel]: ReturnType<EndMethod>}> =>
104+
new Proxy(
105+
{},
106+
{get: (t, prop, r) => (prop === sentinel ? fn(path) : (path.push(String(prop)), proxy$(fn, sentinel, path)))},
107+
) as any;

0 commit comments

Comments
 (0)