Skip to content

Commit

Permalink
Merge pull request #585 from streamich/sonic-forest-2
Browse files Browse the repository at this point in the history
Use `sonic-forest` package
  • Loading branch information
streamich authored Apr 20, 2024
2 parents 107f7bd + e9dbefa commit ee70fa1
Show file tree
Hide file tree
Showing 51 changed files with 20 additions and 3,976 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"@jsonjoy.com/util": "^1.0.0",
"arg": "^5.0.2",
"hyperdyperid": "^1.2.0",
"multibase": "^4.0.6",
"sonic-forest": "^1.0.0",
"thingies": "^1.20.0"
},
"devDependencies": {
Expand All @@ -145,7 +145,6 @@
"husky": "^8.0.3",
"isomorphic-ws": "^5.0.0",
"jest": "^29.7.0",
"js-sdsl": "^4.4.0",
"json-crdt-traces": "https://github.com/streamich/json-crdt-traces#ec825401dc05cbb74b9e0b3c4d6527399f54d54d",
"json-logic-js": "^2.0.1",
"loro-crdt": "^0.4.1",
Expand All @@ -158,7 +157,6 @@
"quill-delta": "^5.0.0",
"rimraf": "^5.0.0",
"rope.js": "0.1.0",
"sorted-btree": "^1.8.1",
"tinybench": "^2.4.0",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt-extensions/peritext/slice/Slices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {printTree} from '../../../util/print/printTree';
import {SliceBehavior, SliceHeaderShift, SliceTupleIndex} from './constants';
import {SplitSlice} from './SplitSlice';
import {VecNode} from '../../../json-crdt/nodes';
import {AvlMap} from '../../../util/trees/avl/AvlMap';
import {AvlMap} from 'sonic-forest/lib/avl/AvlMap';
import type {Slice} from './types';
import type {ITimespanStruct, ITimestampStruct} from '../../../json-crdt-patch/clock';
import type {SliceType, Stateful} from '../types';
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt/hash.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CONST, updateNum} from '../json-hash';
import {ConNode, ValNode, ObjNode, VecNode, ArrNode} from './nodes';
import {AbstractRga} from './nodes/rga';
import {last2} from '../util/trees/util2';
import {last2} from 'sonic-forest/lib/util2';
import type {JsonNode} from './nodes';
import type {ITimestampStruct} from '../json-crdt-patch/clock';
import type {Model} from './model';
Expand Down
4 changes: 2 additions & 2 deletions src/json-crdt/log/Log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {FanOutUnsubscribe} from 'thingies/es2020/fanout';
import {ITimestampStruct, Patch, compare} from '../../json-crdt-patch';
import {printTree} from '../../util/print/printTree';
import {AvlMap} from '../../util/trees/avl/AvlMap';
import {AvlMap} from 'sonic-forest/lib/avl/AvlMap';
import {Model} from '../model';
import {first, next} from '../../util/trees/util';
import {first, next} from 'sonic-forest/lib/util';
import type {Printable} from '../../util/print/types';

export class Log implements Printable {
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {RootNode, ValNode, VecNode, ObjNode, StrNode, BinNode, ArrNode} from '..
import {SchemaToJsonNode} from '../schema/types';
import {printTree} from '../../util/print/printTree';
import {Extensions} from '../extensions/Extensions';
import {AvlMap} from '../../util/trees/avl/AvlMap';
import {AvlMap} from 'sonic-forest/lib/avl/AvlMap';
import type {JsonNode, JsonNodeView} from '../nodes/types';
import type {Printable} from '../../util/print/types';
import type {NodeBuilder} from '../../json-crdt-patch';
Expand Down
6 changes: 3 additions & 3 deletions src/json-crdt/nodes/rga/AbstractRga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
Timestamp,
} from '../../../json-crdt-patch/clock';
import {isUint8Array} from '@jsonjoy.com/util/lib/buffers/isUint8Array';
import {rSplay, lSplay, llSplay, rrSplay, lrSplay, rlSplay} from '../../../util/trees/splay/util';
import {splay2} from '../../../util/trees/splay/util2';
import {insert2, remove2} from '../../../util/trees/util2';
import {rSplay, lSplay, llSplay, rrSplay, lrSplay, rlSplay} from 'sonic-forest/lib/splay/util';
import {splay2} from 'sonic-forest/lib/splay/util2';
import {insert2, remove2} from 'sonic-forest/lib/util2';
import {ORIGIN} from '../../../json-crdt-patch/constants';
import {printTree} from '../../../util/print/printTree';
import {printBinary} from '../../../util/print/printBinary';
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt/nodes/str/StrNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ITimestampStruct, tick} from '../../../json-crdt-patch/clock';
import {AbstractRga, Chunk} from '../rga/AbstractRga';
import {next} from '../../../util/trees/util';
import {next} from 'sonic-forest/lib/util';
import type {JsonNode} from '..';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/json-crdt/nodes/str/__tests__/StrNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {StrNode, StrChunk} from '../StrNode';
import {equal, ITimespanStruct, ITimestampStruct, tick, ts, tss} from '../../../../json-crdt-patch/clock';
import {prev} from '../../../../util/trees/util';
import {prev} from 'sonic-forest/lib/util';

/** Validates that .find() method returns correct timestamp for every position. */
const assertFind = (type: StrNode) => {
Expand Down
2 changes: 1 addition & 1 deletion src/json-type/type/classes/OrType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as schema from '../../schema';
import {printTree} from '../../../util/print/printTree';
import {printTree} from 'sonic-forest/lib/print/printTree';
import {validateTType} from '../../schema/validate';
import {ValidatorCodegenContext} from '../../codegen/validator/ValidatorCodegenContext';
import {ValidationPath} from '../../codegen/validator/types';
Expand Down
2 changes: 1 addition & 1 deletion src/json-type/type/classes/TupleType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as schema from '../../schema';
import {printTree} from '../../../util/print/printTree';
import {printTree} from 'sonic-forest/lib/print/printTree';
import {validateTType} from '../../schema/validate';
import {ValidatorCodegenContext} from '../../codegen/validator/ValidatorCodegenContext';
import {ValidationPath} from '../../codegen/validator/types';
Expand Down
44 changes: 0 additions & 44 deletions src/util/print/__tests__/printBinary.spec.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/util/print/__tests__/printTree.spec.ts

This file was deleted.

10 changes: 1 addition & 9 deletions src/util/print/printBinary.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
type Child = (tab: string) => string;

export const printBinary = (tab = '', children: [left?: null | Child, right?: null | Child]): string => {
const [left, right] = children;
let str = '';
if (left) str += `\n${tab}${left(tab + ' ')}`;
if (right) str += `\n${tab}${right(tab + ' ')}`;
return str;
};
export * from 'sonic-forest/lib/print/printBinary';
16 changes: 1 addition & 15 deletions src/util/print/printTree.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
type Child = (tab: string) => string;

export const printTree = (tab = '', children: (Child | null)[]): string => {
children = children.filter(Boolean);
let str = '';
for (let i = 0; i < children.length; i++) {
const isLast = i >= children.length - 1;
const fn = children[i];
if (!fn) continue;
const child = fn(tab + `${isLast ? ' ' : '│'} `);
const branch = child ? (isLast ? '└─' : '├─') : '│ ';
str += `\n${tab}${branch} ${child}`;
}
return str;
};
export * from 'sonic-forest/lib/print/printTree';
9 changes: 1 addition & 8 deletions src/util/print/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
export interface Printable {
/**
* Returns a human-readable tabbed string representation of the object as a tree.
*
* @param tab String to use for indentation.
*/
toString(tab?: string): string;
}
export * from 'sonic-forest/lib/print/types';
75 changes: 0 additions & 75 deletions src/util/trees/Tree.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/util/trees/TreeNode.ts

This file was deleted.

Loading

0 comments on commit ee70fa1

Please sign in to comment.