Comparing version 1.0.1 to 1.1.0
@@ -447,16 +447,14 @@ /* | ||
if (res.length > 0) { | ||
// convert back to old string ops | ||
if (c.si != null || c.sd != null) { | ||
var p = c.p; | ||
for (var i = 0; i < res.length; i++) { | ||
c.o = [res[i]]; | ||
c.p = p.slice(); | ||
convertToText(c); | ||
json.append(dest, c); | ||
} | ||
} else { | ||
c.o = res; | ||
// convert back to old string ops | ||
if (c.si != null || c.sd != null) { | ||
var p = c.p; | ||
for (var i = 0; i < res.length; i++) { | ||
c.o = [res[i]]; | ||
c.p = p.slice(); | ||
convertToText(c); | ||
json.append(dest, c); | ||
} | ||
} else if (!isArray(res) || res.length > 0) { | ||
c.o = res; | ||
json.append(dest, c); | ||
} | ||
@@ -463,0 +461,0 @@ |
{ | ||
"name": "ot-json0", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "JSON OT type", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
148
README.md
@@ -9,6 +9,7 @@ # JSON0 OT Type | ||
- Embedded string editing, using the old text0 OT type | ||
- Move list items in a list, shuffling adjacent list items as needed | ||
- Object insert / object delete | ||
- Insert/delete/move/replace items in a list, shuffling adjacent list items as needed | ||
- Object insert/delete/replace | ||
- Atomic numerical add operation | ||
- Embed arbitrary subtypes | ||
- Embedded string editing, using the old text0 OT type as a subtype | ||
@@ -21,3 +22,2 @@ JSON0 is an *invertable* type - which is to say, all operations have an inverse | ||
- Embed arbitrary subtypes | ||
- Object-move | ||
@@ -59,4 +59,2 @@ - Set if null (object insert with first writer wins semantics) | ||
`{p:[path], na:x}` | adds `x` to the number at `[path]`. | ||
`{p:[path,offset], si:s}` | inserts the string `s` at offset `offset` into the string at `[path]`. | ||
`{p:[path,offset], sd:s}` | deletes the string `s` at offset `offset` from the string at `[path]`. | ||
`{p:[path,idx], li:obj}` | inserts the object `obj` before the item at `idx` in the list at `[path]`. | ||
@@ -69,2 +67,5 @@ `{p:[path,idx], ld:obj}` | deletes the object `obj` from the index `idx` in the list at `[path]`. | ||
`{p:[path,key], od:before, oi:after}` | replaces the object `before` with the object `after` at key `key` in the object at `[path]`. | ||
`{p:[path], t:subtype, o:subtypeOp}` | applies the subtype op `o` of type `t` to the object at `[path]` | ||
`{p:[path,offset], si:s}` | inserts the string `s` at offset `offset` into the string at `[path]` (uses subtypes internally). | ||
`{p:[path,offset], sd:s}` | deletes the string `s` at offset `offset` from the string at `[path]` (uses subtypes internally). | ||
@@ -96,39 +97,2 @@ --- | ||
### String operations | ||
If the content at a path is a string, an operation can edit the string | ||
in-place, either deleting characters or inserting characters. | ||
To edit a string, add the string offset to the path. For example, given the | ||
following object: | ||
{'key':[100,'abcde']} | ||
If you wanted to delete the `'d'` from the string `'abcde'`, you would use the following operation: | ||
[{p:['key',1,3],sd:'d'}] | ||
Note the path. The components, in order, are the key to the list, the index to | ||
the `'abcde'` string, and then the offset to the `'d'` character in the string. | ||
#### Insert into a string | ||
Usage: | ||
{p:PATH, si:TEXT} | ||
Insert `TEXT` at the location specified by `PATH`. The path must specify an | ||
offset in a string. | ||
#### Delete from a string | ||
Usage: | ||
{p:PATH, sd:TEXT} | ||
Delete `TEXT` at the location specified by `PATH`. The path must specify an | ||
offset in a string. `TEXT` must be contained at the location specified. | ||
--- | ||
### Lists and Objects | ||
@@ -242,5 +206,101 @@ | ||
### Subtype operations | ||
Usage: | ||
{p:PATH, t:SUBTYPE, o:OPERATION} | ||
`PATH` is the path to the object that will be modified by the subtype. | ||
`SUBTYPE` is the name of the subtype, e.g. `"text0"`. | ||
`OPERATION` is the subtype operation itself. | ||
To register a subtype, call `json0.registerSubtype` with another OT type. | ||
Specifically, a subtype is a JavaScript object with the following methods: | ||
* `apply` | ||
* `transform` | ||
* `compose` | ||
* `invert` | ||
See the [OT types documentation](https://github.com/ottypes/docs) for details on these methods. | ||
#### Text subtype | ||
The old string operations are still supported (see below) but are now implemented internally as a subtype | ||
using the `text0` type. You can either continue to use the original `si` and `sd` ops documented below, | ||
or use the `text0` type as a subtype yourself. | ||
To edit a string, create a `text0` subtype op. For example, given the | ||
following object: | ||
{'key':[100,'abcde']} | ||
If you wanted to delete the `'d'` from the string `'abcde'`, you would use the following operation: | ||
[{p:['key',1], t: 'text0', o:[{p:3, d:'d'}]} | ||
Note the path. The components, in order, are the key to the list, and the index to | ||
the `'abcde'` string. The offset to the `'d'` character in the string is given in | ||
the subtype operation. | ||
##### Insert into a string | ||
Usage: | ||
{p:PATH, t:'text0', o:[{p:OFFSET, i:TEXT}]} | ||
Insert `TEXT` to the string specified by `PATH` at the position specified by `OFFSET`. | ||
##### Delete from a string | ||
Usage: | ||
{p:PATH, t:'text0', o:[{p:OFFSET, d:TEXT}]} | ||
Delete `TEXT` in the string specified by `PATH` at the position specified by `OFFSET`. | ||
--- | ||
### String operations | ||
These operations are now internally implemented as subtype operations using the `text0` type, but you can still use them if you like. See above. | ||
If the content at a path is a string, an operation can edit the string | ||
in-place, either deleting characters or inserting characters. | ||
To edit a string, add the string offset to the path. For example, given the | ||
following object: | ||
{'key':[100,'abcde']} | ||
If you wanted to delete the `'d'` from the string `'abcde'`, you would use the following operation: | ||
[{p:['key',1,3],sd:'d'}] | ||
Note the path. The components, in order, are the key to the list, the index to | ||
the `'abcde'` string, and then the offset to the `'d'` character in the string. | ||
#### Insert into a string | ||
Usage: | ||
{p:PATH, si:TEXT} | ||
Insert `TEXT` at the location specified by `PATH`. The path must specify an | ||
offset in a string. | ||
#### Delete from a string | ||
Usage: | ||
{p:PATH, sd:TEXT} | ||
Delete `TEXT` at the location specified by `PATH`. The path must specify an | ||
offset in a string. `TEXT` must be contained at the location specified. | ||
--- | ||
# Commentary | ||
This library was written a couple of years ago by Jeremy Apthorp. It was | ||
This library was written a couple of years ago by [Jeremy Apthorp](https://github.com/nornagon). It was | ||
originally written in coffeescript as part of ShareJS, and then it got pulled | ||
@@ -247,0 +307,0 @@ out into the share/ottypes library and its finally landed here. |
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
75858
345
12
861