loro-crdt
Advanced tools
Comparing version 0.2.8-alpha to 0.2.8-alpha-1
@@ -27,3 +27,3 @@ import { ContainerID, PrelimList, PrelimMap, PrelimText } from 'loro-wasm'; | ||
}; | ||
type MapDIff = { | ||
type MapDiff = { | ||
type: "map"; | ||
@@ -39,7 +39,7 @@ diff: { | ||
}; | ||
type Diff = ListDiff | TextDiff | MapDIff; | ||
type Diff = ListDiff | TextDiff | MapDiff; | ||
interface LoroEvent { | ||
local: boolean; | ||
origin?: string; | ||
diff: Diff[]; | ||
diff: Diff; | ||
target: ContainerID; | ||
@@ -58,3 +58,7 @@ path: Path; | ||
} | ||
interface LoroList { | ||
interface Loro<T extends Record<string, any> = Record<string, any>> { | ||
getTypedMap<Key extends (keyof T) & string>(name: Key): T[Key] extends LoroMap ? T[Key] : never; | ||
getTypedList<Key extends (keyof T) & string>(name: Key): T[Key] extends LoroList ? T[Key] : never; | ||
} | ||
interface LoroList<T extends any[] = any[]> { | ||
insertContainer(txn: Transaction | Loro, pos: number, container: "Map"): LoroMap; | ||
@@ -65,2 +69,4 @@ insertContainer(txn: Transaction | Loro, pos: number, container: "List"): LoroList; | ||
get(index: number): Value; | ||
getTyped<Key extends (keyof T) & number>(loro: Loro, index: Key): T[Key]; | ||
insertTyped<Key extends (keyof T) & number>(txn: Transaction | Loro, pos: Key, value: T[Key]): void; | ||
insert(txn: Transaction | Loro, pos: number, value: Value | Prelim): void; | ||
@@ -72,3 +78,3 @@ delete(txn: Transaction | Loro, pos: number, len: number): void; | ||
} | ||
interface LoroMap { | ||
interface LoroMap<T extends Record<string, any> = Record<string, any>> { | ||
insertContainer(txn: Transaction | Loro, key: string, container_type: "Map"): LoroMap; | ||
@@ -79,3 +85,5 @@ insertContainer(txn: Transaction | Loro, key: string, container_type: "List"): LoroList; | ||
get(key: string): Value; | ||
getTyped<Key extends (keyof T) & string>(txn: Loro, key: Key): T[Key]; | ||
set(txn: Transaction | Loro, key: string, value: Value | Prelim): void; | ||
setTyped<Key extends (keyof T) & string>(txn: Transaction | Loro, key: Key, value: T[Key]): void; | ||
delete(txn: Transaction | Loro, key: string): void; | ||
@@ -95,2 +103,2 @@ subscribe(txn: Transaction | Loro, listener: Listener): number; | ||
export { Delta, Diff, ListDiff, LoroEvent, MapDIff, Path, Prelim, TextDiff, Value, isContainerId }; | ||
export { Delta, Diff, ListDiff, LoroEvent, MapDiff, Path, Prelim, TextDiff, Value, isContainerId }; |
@@ -15,2 +15,22 @@ 'use strict'; | ||
}; | ||
loroWasm.Loro.prototype.getTypedMap = loroWasm.Loro.prototype.getMap; | ||
loroWasm.Loro.prototype.getTypedList = loroWasm.Loro.prototype.getList; | ||
loroWasm.LoroList.prototype.getTyped = function(loro, index) { | ||
const value = this.get(index); | ||
if (typeof value === "string" && isContainerId(value)) { | ||
return loro.getContainerById(value); | ||
} else { | ||
return value; | ||
} | ||
}; | ||
loroWasm.LoroList.prototype.insertTyped = loroWasm.LoroList.prototype.insert; | ||
loroWasm.LoroMap.prototype.getTyped = function(loro, key) { | ||
const value = this.get(key); | ||
if (typeof value === "string" && isContainerId(value)) { | ||
return loro.getContainerById(value); | ||
} else { | ||
return value; | ||
} | ||
}; | ||
loroWasm.LoroMap.prototype.setTyped = loroWasm.LoroMap.prototype.set; | ||
loroWasm.LoroText.prototype.insert = function(txn, pos, text) { | ||
@@ -17,0 +37,0 @@ if (txn instanceof loroWasm.Loro) { |
{ | ||
"name": "loro-crdt", | ||
"version": "0.2.8-alpha", | ||
"version": "0.2.8-alpha-1", | ||
"description": "", | ||
@@ -27,4 +27,5 @@ "main": "dist/loro.js", | ||
"watch": "rollup -c -w", | ||
"test": "vitest run" | ||
"test": "vitest run", | ||
"prepublish": "pnpm run build" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69586
1269