@automerge/automerge
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isAutomerge = exports.toJS = exports.dump = exports.getHeads = exports.getMissingDeps = exports.decodeSyncMessage = exports.encodeSyncMessage = exports.decodeChange = exports.encodeChange = exports.initSyncState = exports.receiveSyncMessage = exports.generateSyncMessage = exports.decodeSyncState = exports.encodeSyncState = exports.equals = exports.getHistory = exports.applyChanges = exports.getAllChanges = exports.getChanges = exports.getObjectId = exports.getLastLocalChange = exports.getConflicts = exports.getActorId = exports.merge = exports.save = exports.loadIncremental = exports.load = exports.emptyChange = exports.change = exports.from = exports.free = exports.clone = exports.init = exports.getBackend = exports.use = exports.Float64 = exports.Uint = exports.Int = exports.Counter = exports.Text = exports.uuid = void 0; | ||
exports.isAutomerge = exports.toJS = exports.dump = exports.getHeads = exports.getMissingDeps = exports.decodeSyncMessage = exports.encodeSyncMessage = exports.decodeChange = exports.encodeChange = exports.initSyncState = exports.receiveSyncMessage = exports.generateSyncMessage = exports.decodeSyncState = exports.encodeSyncState = exports.equals = exports.getHistory = exports.applyChanges = exports.getAllChanges = exports.getChanges = exports.getObjectId = exports.getLastLocalChange = exports.getConflicts = exports.getActorId = exports.merge = exports.save = exports.loadIncremental = exports.load = exports.emptyChange = exports.change = exports.from = exports.free = exports.clone = exports.view = exports.init = exports.getBackend = exports.use = exports.Float64 = exports.Uint = exports.Int = exports.Counter = exports.Text = exports.uuid = void 0; | ||
/** @hidden **/ | ||
@@ -30,2 +30,5 @@ var uuid_1 = require("./uuid"); | ||
function _state(doc, checkroot = true) { | ||
if (typeof doc !== 'object') { | ||
throw new RangeError("must be the document root"); | ||
} | ||
const state = Reflect.get(doc, constants_1.STATE); | ||
@@ -90,10 +93,44 @@ if (state === undefined || (checkroot && _obj(doc) !== "_root")) { | ||
/** | ||
* Make a copy of an automerge document. | ||
* Make an immutable view of an automerge document as at `heads` | ||
* | ||
* @remarks | ||
* The document returned from this function cannot be passed to {@link change}. | ||
* This is because it shares the same underlying memory as `doc`, but it is | ||
* consequently a very cheap copy. | ||
* | ||
* Note that this function will throw an error if any of the hashes in `heads` | ||
* are not in the document. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to create a view of | ||
* @param heads - The hashes of the heads to create a view at | ||
*/ | ||
function clone(doc) { | ||
function view(doc, heads) { | ||
const state = _state(doc); | ||
const handle = state.heads ? state.handle.forkAt(state.heads) : state.handle.fork(); | ||
const clonedDoc = handle.materialize("/", undefined, Object.assign(Object.assign({}, state), { handle })); | ||
return clonedDoc; | ||
const handle = state.handle; | ||
return state.handle.materialize("/", heads, Object.assign(Object.assign({}, state), { handle, heads })); | ||
} | ||
exports.view = view; | ||
/** | ||
* Make a full writable copy of an automerge document | ||
* | ||
* @remarks | ||
* Unlike {@link view} this function makes a full copy of the memory backing | ||
* the document and can thus be passed to {@link change}. It also generates a | ||
* new actor ID so that changes made in the new document do not create duplicate | ||
* sequence numbers with respect to the old document. If you need control over | ||
* the actor ID which is generated you can pass the actor ID as the second | ||
* argument | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to clone | ||
* @param _opts - Either an actor ID to use for the new doc or an {@link InitOptions} | ||
*/ | ||
function clone(doc, _opts) { | ||
const state = _state(doc); | ||
const heads = state.heads; | ||
const opts = importOpts(_opts); | ||
const handle = state.handle.fork(opts.actor, heads); | ||
return handle.applyPatches(doc, Object.assign(Object.assign({}, state), { heads, handle })); | ||
} | ||
exports.clone = clone; | ||
@@ -192,8 +229,4 @@ /** Explicity free the memory backing a document. Note that this is note | ||
let nextState = Object.assign(Object.assign({}, state), { heads: undefined }); | ||
// @ts-ignore | ||
let nextDoc = state.handle.applyPatches(doc, nextState, callback); | ||
state.heads = heads; | ||
if (nextState.freeze) { | ||
Object.freeze(nextDoc); | ||
} | ||
return nextDoc; | ||
@@ -210,3 +243,3 @@ } | ||
if (state.heads) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -257,3 +290,3 @@ if (_readonly(doc) === false) { | ||
if (state.heads) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -533,3 +566,3 @@ if (_readonly(doc) === false) { | ||
if (state.heads) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -644,3 +677,3 @@ if (_readonly(doc) === false) { | ||
if (state.heads) { | ||
throw new RangeError("Attempting to change an out of date document - set at: " + _trace(doc)); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -647,0 +680,0 @@ if (_readonly(doc) === false) { |
@@ -82,5 +82,33 @@ /** @hidden **/ | ||
/** | ||
* Make a copy of an automerge document. | ||
* Make an immutable view of an automerge document as at `heads` | ||
* | ||
* @remarks | ||
* The document returned from this function cannot be passed to {@link change}. | ||
* This is because it shares the same underlying memory as `doc`, but it is | ||
* consequently a very cheap copy. | ||
* | ||
* Note that this function will throw an error if any of the hashes in `heads` | ||
* are not in the document. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to create a view of | ||
* @param heads - The hashes of the heads to create a view at | ||
*/ | ||
export declare function clone<T>(doc: Doc<T>): Doc<T>; | ||
export declare function view<T>(doc: Doc<T>, heads: Heads): Doc<T>; | ||
/** | ||
* Make a full writable copy of an automerge document | ||
* | ||
* @remarks | ||
* Unlike {@link view} this function makes a full copy of the memory backing | ||
* the document and can thus be passed to {@link change}. It also generates a | ||
* new actor ID so that changes made in the new document do not create duplicate | ||
* sequence numbers with respect to the old document. If you need control over | ||
* the actor ID which is generated you can pass the actor ID as the second | ||
* argument | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to clone | ||
* @param _opts - Either an actor ID to use for the new doc or an {@link InitOptions} | ||
*/ | ||
export declare function clone<T>(doc: Doc<T>, _opts?: ActorId | InitOptions<T>): Doc<T>; | ||
/** Explicity free the memory backing a document. Note that this is note | ||
@@ -87,0 +115,0 @@ * necessary in environments which support |
@@ -19,2 +19,5 @@ /** @hidden **/ | ||
function _state(doc, checkroot = true) { | ||
if (typeof doc !== 'object') { | ||
throw new RangeError("must be the document root"); | ||
} | ||
const state = Reflect.get(doc, STATE); | ||
@@ -78,10 +81,43 @@ if (state === undefined || (checkroot && _obj(doc) !== "_root")) { | ||
/** | ||
* Make a copy of an automerge document. | ||
* Make an immutable view of an automerge document as at `heads` | ||
* | ||
* @remarks | ||
* The document returned from this function cannot be passed to {@link change}. | ||
* This is because it shares the same underlying memory as `doc`, but it is | ||
* consequently a very cheap copy. | ||
* | ||
* Note that this function will throw an error if any of the hashes in `heads` | ||
* are not in the document. | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to create a view of | ||
* @param heads - The hashes of the heads to create a view at | ||
*/ | ||
export function clone(doc) { | ||
export function view(doc, heads) { | ||
const state = _state(doc); | ||
const handle = state.heads ? state.handle.forkAt(state.heads) : state.handle.fork(); | ||
const clonedDoc = handle.materialize("/", undefined, Object.assign(Object.assign({}, state), { handle })); | ||
return clonedDoc; | ||
const handle = state.handle; | ||
return state.handle.materialize("/", heads, Object.assign(Object.assign({}, state), { handle, heads })); | ||
} | ||
/** | ||
* Make a full writable copy of an automerge document | ||
* | ||
* @remarks | ||
* Unlike {@link view} this function makes a full copy of the memory backing | ||
* the document and can thus be passed to {@link change}. It also generates a | ||
* new actor ID so that changes made in the new document do not create duplicate | ||
* sequence numbers with respect to the old document. If you need control over | ||
* the actor ID which is generated you can pass the actor ID as the second | ||
* argument | ||
* | ||
* @typeParam T - The type of the value contained in the document | ||
* @param doc - The document to clone | ||
* @param _opts - Either an actor ID to use for the new doc or an {@link InitOptions} | ||
*/ | ||
export function clone(doc, _opts) { | ||
const state = _state(doc); | ||
const heads = state.heads; | ||
const opts = importOpts(_opts); | ||
const handle = state.handle.fork(opts.actor, heads); | ||
return handle.applyPatches(doc, Object.assign(Object.assign({}, state), { heads, handle })); | ||
} | ||
/** Explicity free the memory backing a document. Note that this is note | ||
@@ -176,8 +212,4 @@ * necessary in environments which support | ||
let nextState = Object.assign(Object.assign({}, state), { heads: undefined }); | ||
// @ts-ignore | ||
let nextDoc = state.handle.applyPatches(doc, nextState, callback); | ||
state.heads = heads; | ||
if (nextState.freeze) { | ||
Object.freeze(nextDoc); | ||
} | ||
return nextDoc; | ||
@@ -194,3 +226,3 @@ } | ||
if (state.heads) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -241,3 +273,3 @@ if (_readonly(doc) === false) { | ||
if (state.heads) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -506,3 +538,3 @@ if (_readonly(doc) === false) { | ||
if (state.heads) { | ||
throw new RangeError("Attempting to use an outdated Automerge document"); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -611,3 +643,3 @@ if (_readonly(doc) === false) { | ||
if (state.heads) { | ||
throw new RangeError("Attempting to change an out of date document - set at: " + _trace(doc)); | ||
throw new RangeError("Attempting to change an outdated document. Use Automerge.clone() if you wish to make a writable copy."); | ||
} | ||
@@ -614,0 +646,0 @@ if (_readonly(doc) === false) { |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "2.0.0-beta.2", | ||
"version": "2.0.0-beta.3", | ||
"description": "Javascript implementation of automerge, backed by @automerge/automerge-wasm", | ||
@@ -44,3 +44,4 @@ "homepage": "https://github.com/automerge/automerge-rs/tree/main/wrappers/javascript", | ||
"build": "tsc -p config/mjs.json && tsc -p config/cjs.json && tsc --emitDeclarationOnly", | ||
"test": "ts-mocha test/*.ts" | ||
"test": "ts-mocha test/*.ts", | ||
"watch-docs": "typedoc src/index.ts --watch --readme typedoc-readme.md" | ||
}, | ||
@@ -63,5 +64,5 @@ "devDependencies": { | ||
"dependencies": { | ||
"@automerge/automerge-wasm": "0.1.14", | ||
"@automerge/automerge-wasm": "0.1.15", | ||
"uuid": "^8.3" | ||
} | ||
} |
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
158570
30
4213
+ Added@automerge/automerge-wasm@0.1.15(transitive)
- Removed@automerge/automerge-wasm@0.1.14(transitive)