Skip to content

Commit

Permalink
Merge pull request automerge#326 from jeffa5/experiment-range
Browse files Browse the repository at this point in the history
Add range and values queries
  • Loading branch information
orionz authored Apr 8, 2022
2 parents 609234b + 0755319 commit 09259e5
Show file tree
Hide file tree
Showing 27 changed files with 876 additions and 213 deletions.
4 changes: 2 additions & 2 deletions automerge-cli/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) fn map_to_json(doc: &am::Automerge, obj: &am::ObjId) -> serde_json::V
let keys = doc.keys(obj);
let mut map = serde_json::Map::new();
for k in keys {
let val = doc.value(obj, &k);
let val = doc.get(obj, &k);
match val {
Ok(Some((am::Value::Object(o), exid)))
if o == am::ObjType::Map || o == am::ObjType::Table =>
Expand All @@ -28,7 +28,7 @@ fn list_to_json(doc: &am::Automerge, obj: &am::ObjId) -> serde_json::Value {
let len = doc.length(obj);
let mut array = Vec::new();
for i in 0..len {
let val = doc.value(obj, i as usize);
let val = doc.get(obj, i as usize);
match val {
Ok(Some((am::Value::Object(o), exid)))
if o == am::ObjType::Map || o == am::ObjType::Table =>
Expand Down
2 changes: 1 addition & 1 deletion automerge-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function getActorId(doc) {
}

function conflictAt(context, objectId, prop) {
let values = context.values(objectId, prop)
let values = context.getAll(objectId, prop)
if (values.length <= 1) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions automerge-js/src/proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function parseListIndex(key) {

function valueAt(target, prop) {
const { context, objectId, path, readonly, heads} = target
let value = context.value(objectId, prop, heads)
let value = context.get(objectId, prop, heads)
if (value === undefined) {
return
}
Expand Down Expand Up @@ -293,7 +293,7 @@ const ListHandler = {
deleteProperty (target, index) {
const {context, objectId} = target
index = parseListIndex(index)
if (context.value(objectId, index)[0] == "counter") {
if (context.get(objectId, index)[0] == "counter") {
throw new TypeError('Unsupported operation: deleting a counter from a list')
}
context.delete(objectId, index)
Expand Down
8 changes: 4 additions & 4 deletions automerge-wasm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export class Automerge {
delete(obj: ObjID, prop: Prop): void;

// returns a single value - if there is a conflict return the winner
value(obj: ObjID, prop: any, heads?: Heads): FullValue | null;
get(obj: ObjID, prop: any, heads?: Heads): FullValue | null;
// return all values in case of a conflict
values(obj: ObjID, arg: any, heads?: Heads): FullValue[];
getAll(obj: ObjID, arg: any, heads?: Heads): FullValue[];
keys(obj: ObjID, heads?: Heads): string[];
text(obj: ObjID, heads?: Heads): string;
length(obj: ObjID, heads?: Heads): number;
Expand Down Expand Up @@ -178,8 +178,8 @@ export interface InitOutput {
readonly automerge_insert: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
readonly automerge_set: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
readonly automerge_inc: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly automerge_value: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly automerge_values: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly automerge_get: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly automerge_get_all: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
readonly automerge_length: (a: number, b: number, c: number, d: number, e: number) => void;
readonly automerge_del: (a: number, b: number, c: number, d: number, e: number) => void;
readonly automerge_save: (a: number, b: number) => void;
Expand Down
4 changes: 2 additions & 2 deletions automerge-wasm/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub(crate) fn map_to_js(doc: &am::AutoCommit, obj: &ObjId) -> JsValue {
let keys = doc.keys(obj);
let map = Object::new();
for k in keys {
let val = doc.value(obj, &k);
let val = doc.get(obj, &k);
match val {
Ok(Some((Value::Object(o), exid)))
if o == am::ObjType::Map || o == am::ObjType::Table =>
Expand All @@ -358,7 +358,7 @@ pub(crate) fn list_to_js(doc: &am::AutoCommit, obj: &ObjId) -> JsValue {
let len = doc.length(obj);
let array = Array::new();
for i in 0..len {
let val = doc.value(obj, i as usize);
let val = doc.get(obj, i as usize);
match val {
Ok(Some((Value::Object(o), exid)))
if o == am::ObjType::Map || o == am::ObjType::Table =>
Expand Down
18 changes: 10 additions & 8 deletions automerge-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ impl Automerge {
Ok(())
}

pub fn value(
#[wasm_bindgen(js_name = get)]
pub fn get(
&mut self,
obj: JsValue,
prop: JsValue,
Expand All @@ -287,9 +288,9 @@ impl Automerge {
let heads = get_heads(heads);
if let Ok(prop) = prop {
let value = if let Some(h) = heads {
self.0.value_at(&obj, prop, &h)?
self.0.get_at(&obj, prop, &h)?
} else {
self.0.value(&obj, prop)?
self.0.get(&obj, prop)?
};
match value {
Some((Value::Object(obj_type), obj_id)) => {
Expand All @@ -309,7 +310,8 @@ impl Automerge {
}
}

pub fn values(
#[wasm_bindgen(js_name = getAll)]
pub fn get_all(
&mut self,
obj: JsValue,
arg: JsValue,
Expand All @@ -320,9 +322,9 @@ impl Automerge {
let prop = to_prop(arg);
if let Ok(prop) = prop {
let values = if let Some(heads) = get_heads(heads) {
self.0.values_at(&obj, prop, &heads)
self.0.get_all_at(&obj, prop, &heads)
} else {
self.0.values(&obj, prop)
self.0.get_all(&obj, prop)
}
.map_err(to_js_err)?;
for value in values {
Expand Down Expand Up @@ -573,9 +575,9 @@ impl Automerge {
break;
}
let val = if is_map {
self.0.value(obj, prop)?
self.0.get(obj, prop)?
} else {
self.0.value(obj, am::Prop::Seq(prop.parse().unwrap()))?
self.0.get(obj, am::Prop::Seq(prop.parse().unwrap()))?
};
match val {
Some((am::Value::Object(am::ObjType::Map), id)) => {
Expand Down
Loading

0 comments on commit 09259e5

Please sign in to comment.