Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@automerge/automerge

Package Overview
Dependencies
Maintainers
4
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automerge/automerge - npm Package Compare versions

Comparing version 2.1.0-alpha.3 to 2.1.0-alpha.4

3

dist/cjs/constants.js
"use strict";
// Properties of the document root object
Object.defineProperty(exports, "__esModule", { value: true });
exports.TEXT = exports.COUNTER = exports.F64 = exports.INT = exports.UINT = exports.IS_PROXY = exports.OBJECT_ID = exports.TRACE = exports.STATE = void 0;
exports.TEXT = exports.COUNTER = exports.F64 = exports.INT = exports.UINT = exports.CLEAR_CACHE = exports.IS_PROXY = exports.OBJECT_ID = exports.TRACE = exports.STATE = void 0;
exports.STATE = Symbol.for("_am_meta"); // symbol used to hide application metadata on automerge objects

@@ -9,2 +9,3 @@ exports.TRACE = Symbol.for("_am_trace"); // used for debugging

exports.IS_PROXY = Symbol.for("_am_isProxy"); // symbol used to test if the document is a proxy object
exports.CLEAR_CACHE = Symbol.for("_am_clearCache"); // symbol used to tell a proxy object to clear its cache
exports.UINT = Symbol.for("_am_uint");

@@ -11,0 +12,0 @@ exports.INT = Symbol.for("_am_int");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._is_proxy = exports._obj = exports._trace = exports._state = void 0;
exports._is_proxy = exports._obj = exports._trace = exports._clear_cache = exports._state = void 0;
const constants_1 = require("./constants");

@@ -18,2 +18,6 @@ function _state(doc, checkroot = true) {

exports._state = _state;
function _clear_cache(doc) {
Reflect.set(doc, constants_1.CLEAR_CACHE, true);
}
exports._clear_cache = _clear_cache;
function _trace(doc) {

@@ -20,0 +24,0 @@ return Reflect.get(doc, constants_1.TRACE);

@@ -162,2 +162,5 @@ "use strict";

}
if (key === constants_1.CLEAR_CACHE) {
return true;
}
const [value, datatype] = import_value(val, textV2);

@@ -557,2 +560,6 @@ if (frozen) {

index = parseListIndex(index);
// if del is undefined, delete until the end of the list
if (typeof del !== "number") {
del = context.length(objectId) - index;
}
del = parseListIndex(del);

@@ -559,0 +566,0 @@ for (const val of vals) {

@@ -14,3 +14,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.diff = exports.getHistory = exports.applyChanges = exports.getAllChanges = exports.getChanges = exports.getObjectId = exports.getLastLocalChange = exports.getConflicts = exports.getActorId = exports.merge = exports.save = exports.saveIncremental = exports.loadIncremental = exports.load = exports.emptyChange = exports.change = exports.from = exports.free = exports.clone = exports.view = exports.init = exports.getBackend = exports.use = exports.Text = exports.Float64 = exports.Uint = exports.Int = exports.Counter = 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.diff = exports.getHistory = exports.applyChanges = exports.getAllChanges = exports.getChanges = exports.getObjectId = exports.getLastLocalChange = exports.getConflicts = exports.getActorId = exports.merge = exports.save = exports.saveIncremental = exports.loadIncremental = exports.load = exports.emptyChange = exports.changeAt = exports.change = exports.from = exports.free = exports.clone = exports.view = exports.init = exports.getBackend = exports.use = exports.deleteAt = exports.insertAt = exports.Text = exports.Float64 = exports.Uint = exports.Int = exports.Counter = exports.uuid = void 0;
/** @hidden **/

@@ -35,2 +35,30 @@ var uuid_1 = require("./uuid");

const conflicts_1 = require("./conflicts");
/**
* Function for use in {@link change} which inserts values into a list at a given index
* @param list
* @param index
* @param values
*/
function insertAt(list, index, ...values) {
if (!(0, internal_state_1._is_proxy)(list)) {
throw new RangeError("object cannot be modified outside of a change block");
}
;
list.insertAt(index, ...values);
}
exports.insertAt = insertAt;
/**
* Function for use in {@link change} which deletes values from a list at a given index
* @param list
* @param index
* @param numDelete
*/
function deleteAt(list, index, numDelete) {
if (!(0, internal_state_1._is_proxy)(list)) {
throw new RangeError("object cannot be modified outside of a change block");
}
;
list.deleteAt(index, numDelete);
}
exports.deleteAt = deleteAt;
/** @hidden **/

@@ -134,2 +162,3 @@ function use(api) {

const handle = state.handle.fork(opts.actor, heads);
handle.updateDiffCursor();
// `change` uses the presence of state.heads to determine if we are in a view

@@ -231,2 +260,17 @@ // set it to undefined to indicate that this is a full fat document

exports.change = change;
function changeAt(doc, scope, options, callback) {
if (typeof options === "function") {
return _change(doc, {}, options, scope);
}
else if (typeof callback === "function") {
if (typeof options === "string") {
options = { message: options };
}
return _change(doc, options, callback, scope);
}
else {
throw RangeError("Invalid args for changeAt");
}
}
exports.changeAt = changeAt;
function progressDocument(doc, heads, callback) {

@@ -240,6 +284,6 @@ if (heads == null) {

if (callback != null) {
let headsBefore = state.heads;
let { value, patches } = state.handle.applyAndReturnPatches(doc, nextState);
const headsBefore = state.heads;
const { value, patches } = state.handle.applyAndReturnPatches(doc, nextState);
if (patches.length > 0) {
let before = view(doc, headsBefore || []);
const before = view(doc, headsBefore || []);
callback(patches, { before, after: value });

@@ -255,3 +299,3 @@ }

}
function _change(doc, options, callback) {
function _change(doc, options, callback, scope) {
if (typeof callback !== "function") {

@@ -270,2 +314,5 @@ throw new RangeError("invalid change function");

}
if (scope) {
state.handle.isolate(scope);
}
const heads = state.handle.getHeads();

@@ -282,2 +329,3 @@ try {

state.handle.commit(options.message, options.time);
state.handle.integrate();
return progressDocument(doc, heads, options.patchCallback || state.patchCallback);

@@ -284,0 +332,0 @@ }

@@ -40,3 +40,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getConflicts = exports.marks = exports.unmark = exports.mark = exports.splice = exports.load = exports.from = exports.clone = exports.init = exports.getBackend = exports.RawString = exports.diff = exports.getObjectId = exports.isAutomerge = exports.toJS = exports.dump = 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.getLastLocalChange = exports.getActorId = exports.merge = exports.save = exports.loadIncremental = exports.emptyChange = exports.change = exports.getHeads = exports.free = exports.view = exports.Float64 = exports.Uint = exports.Int = exports.Counter = void 0;
exports.getConflicts = exports.marks = exports.unmark = exports.mark = exports.splice = exports.load = exports.from = exports.clone = exports.init = exports.getBackend = exports.RawString = exports.deleteAt = exports.insertAt = exports.diff = exports.getObjectId = exports.isAutomerge = exports.toJS = exports.dump = 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.getLastLocalChange = exports.getActorId = exports.merge = exports.save = exports.loadIncremental = exports.emptyChange = exports.changeAt = exports.change = exports.getHeads = exports.free = exports.view = exports.Float64 = exports.Uint = exports.Int = exports.Counter = void 0;
var unstable_types_1 = require("./unstable_types");

@@ -53,2 +53,3 @@ Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return unstable_types_1.Counter; } });

Object.defineProperty(exports, "change", { enumerable: true, get: function () { return stable_1.change; } });
Object.defineProperty(exports, "changeAt", { enumerable: true, get: function () { return stable_1.changeAt; } });
Object.defineProperty(exports, "emptyChange", { enumerable: true, get: function () { return stable_1.emptyChange; } });

@@ -80,2 +81,4 @@ Object.defineProperty(exports, "loadIncremental", { enumerable: true, get: function () { return stable_1.loadIncremental; } });

Object.defineProperty(exports, "diff", { enumerable: true, get: function () { return stable_1.diff; } });
Object.defineProperty(exports, "insertAt", { enumerable: true, get: function () { return stable_1.insertAt; } });
Object.defineProperty(exports, "deleteAt", { enumerable: true, get: function () { return stable_1.deleteAt; } });
const stable = require("./stable");

@@ -179,3 +182,3 @@ var raw_string_1 = require("./raw_string");

}
function splice(doc, prop, index, del, newText) {
function splice(doc, path, index, del, newText) {
if (!(0, internal_state_1._is_proxy)(doc)) {

@@ -189,3 +192,5 @@ throw new RangeError("object cannot be modified outside of a change block");

}
const value = `${objectId}/${prop}`;
(0, internal_state_1._clear_cache)(doc);
path.unshift(objectId);
const value = path.join("/");
try {

@@ -199,3 +204,3 @@ return state.handle.splice(value, index, del, newText);

exports.splice = splice;
function mark(doc, prop, range, name, value) {
function mark(doc, path, range, name, value) {
if (!(0, internal_state_1._is_proxy)(doc)) {

@@ -209,3 +214,4 @@ throw new RangeError("object cannot be modified outside of a change block");

}
const obj = `${objectId}/${prop}`;
path.unshift(objectId);
const obj = path.join("/");
try {

@@ -219,3 +225,3 @@ return state.handle.mark(obj, range, name, value);

exports.mark = mark;
function unmark(doc, prop, range, name) {
function unmark(doc, path, range, name) {
if (!(0, internal_state_1._is_proxy)(doc)) {

@@ -229,3 +235,4 @@ throw new RangeError("object cannot be modified outside of a change block");

}
const obj = `${objectId}/${prop}`;
path.unshift(objectId);
const obj = path.join("/");
try {

@@ -232,0 +239,0 @@ return state.handle.unmark(obj, range, name);

@@ -5,2 +5,3 @@ export declare const STATE: unique symbol;

export declare const IS_PROXY: unique symbol;
export declare const CLEAR_CACHE: unique symbol;
export declare const UINT: unique symbol;

@@ -7,0 +8,0 @@ export declare const INT: unique symbol;

@@ -11,4 +11,5 @@ import { type ObjID, type Heads, Automerge } from "@automerge/automerge-wasm";

export declare function _state<T>(doc: Doc<T>, checkroot?: boolean): InternalState<T>;
export declare function _clear_cache<T>(doc: Doc<T>): void;
export declare function _trace<T>(doc: Doc<T>): string | undefined;
export declare function _obj<T>(doc: Doc<T>): ObjID | null;
export declare function _is_proxy<T>(doc: Doc<T>): boolean;

@@ -6,2 +6,3 @@ // Properties of the document root object

export const IS_PROXY = Symbol.for("_am_isProxy"); // symbol used to test if the document is a proxy object
export const CLEAR_CACHE = Symbol.for("_am_clearCache"); // symbol used to tell a proxy object to clear its cache
export const UINT = Symbol.for("_am_uint");

@@ -8,0 +9,0 @@ export const INT = Symbol.for("_am_int");

@@ -1,2 +0,2 @@

import { STATE, OBJECT_ID, TRACE, IS_PROXY } from "./constants";
import { STATE, OBJECT_ID, CLEAR_CACHE, TRACE, IS_PROXY } from "./constants";
export function _state(doc, checkroot = true) {

@@ -14,2 +14,5 @@ if (typeof doc !== "object") {

}
export function _clear_cache(doc) {
Reflect.set(doc, CLEAR_CACHE, true);
}
export function _trace(doc) {

@@ -16,0 +19,0 @@ return Reflect.get(doc, TRACE);

/* eslint-disable @typescript-eslint/no-explicit-any */
import { Text } from "./text";
import { Counter, getWriteableCounter } from "./counter";
import { STATE, TRACE, IS_PROXY, OBJECT_ID, COUNTER, INT, UINT, F64, } from "./constants";
import { STATE, TRACE, IS_PROXY, OBJECT_ID, CLEAR_CACHE, COUNTER, INT, UINT, F64, } from "./constants";
import { RawString } from "./raw_string";

@@ -159,2 +159,5 @@ function parseListIndex(key) {

}
if (key === CLEAR_CACHE) {
return true;
}
const [value, datatype] = import_value(val, textV2);

@@ -550,2 +553,6 @@ if (frozen) {

index = parseListIndex(index);
// if del is undefined, delete until the end of the list
if (typeof del !== "number") {
del = context.length(objectId) - index;
}
del = parseListIndex(del);

@@ -552,0 +559,0 @@ for (const val of vals) {

@@ -25,2 +25,28 @@ var __rest = (this && this.__rest) || function (s, e) {

import { stableConflictAt } from "./conflicts";
/**
* Function for use in {@link change} which inserts values into a list at a given index
* @param list
* @param index
* @param values
*/
export function insertAt(list, index, ...values) {
if (!_is_proxy(list)) {
throw new RangeError("object cannot be modified outside of a change block");
}
;
list.insertAt(index, ...values);
}
/**
* Function for use in {@link change} which deletes values from a list at a given index
* @param list
* @param index
* @param numDelete
*/
export function deleteAt(list, index, numDelete) {
if (!_is_proxy(list)) {
throw new RangeError("object cannot be modified outside of a change block");
}
;
list.deleteAt(index, numDelete);
}
/** @hidden **/

@@ -120,2 +146,3 @@ export function use(api) {

const handle = state.handle.fork(opts.actor, heads);
handle.updateDiffCursor();
// `change` uses the presence of state.heads to determine if we are in a view

@@ -213,2 +240,16 @@ // set it to undefined to indicate that this is a full fat document

}
export function changeAt(doc, scope, options, callback) {
if (typeof options === "function") {
return _change(doc, {}, options, scope);
}
else if (typeof callback === "function") {
if (typeof options === "string") {
options = { message: options };
}
return _change(doc, options, callback, scope);
}
else {
throw RangeError("Invalid args for changeAt");
}
}
function progressDocument(doc, heads, callback) {

@@ -222,6 +263,6 @@ if (heads == null) {

if (callback != null) {
let headsBefore = state.heads;
let { value, patches } = state.handle.applyAndReturnPatches(doc, nextState);
const headsBefore = state.heads;
const { value, patches } = state.handle.applyAndReturnPatches(doc, nextState);
if (patches.length > 0) {
let before = view(doc, headsBefore || []);
const before = view(doc, headsBefore || []);
callback(patches, { before, after: value });

@@ -237,3 +278,3 @@ }

}
function _change(doc, options, callback) {
function _change(doc, options, callback, scope) {
if (typeof callback !== "function") {

@@ -252,2 +293,5 @@ throw new RangeError("invalid change function");

}
if (scope) {
state.handle.isolate(scope);
}
const heads = state.handle.getHeads();

@@ -264,2 +308,3 @@ try {

state.handle.commit(options.message, options.time);
state.handle.integrate();
return progressDocument(doc, heads, options.patchCallback || state.patchCallback);

@@ -266,0 +311,0 @@ }

@@ -40,3 +40,3 @@ /**

import { unstableConflictAt } from "./conflicts";
export { view, free, getHeads, change, emptyChange, loadIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, } from "./stable";
export { view, free, getHeads, change, changeAt, emptyChange, loadIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, insertAt, deleteAt, } from "./stable";
import * as stable from "./stable";

@@ -46,3 +46,3 @@ export { RawString } from "./raw_string";

export const getBackend = stable.getBackend;
import { _is_proxy, _state, _obj } from "./internal_state";
import { _is_proxy, _state, _obj, _clear_cache } from "./internal_state";
/**

@@ -136,3 +136,3 @@ * Create a new automerge document

}
export function splice(doc, prop, index, del, newText) {
export function splice(doc, path, index, del, newText) {
if (!_is_proxy(doc)) {

@@ -146,3 +146,5 @@ throw new RangeError("object cannot be modified outside of a change block");

}
const value = `${objectId}/${prop}`;
_clear_cache(doc);
path.unshift(objectId);
const value = path.join("/");
try {

@@ -155,3 +157,3 @@ return state.handle.splice(value, index, del, newText);

}
export function mark(doc, prop, range, name, value) {
export function mark(doc, path, range, name, value) {
if (!_is_proxy(doc)) {

@@ -165,3 +167,4 @@ throw new RangeError("object cannot be modified outside of a change block");

}
const obj = `${objectId}/${prop}`;
path.unshift(objectId);
const obj = path.join("/");
try {

@@ -174,3 +177,3 @@ return state.handle.mark(obj, range, name, value);

}
export function unmark(doc, prop, range, name) {
export function unmark(doc, path, range, name) {
if (!_is_proxy(doc)) {

@@ -184,3 +187,4 @@ throw new RangeError("object cannot be modified outside of a change block");

}
const obj = `${objectId}/${prop}`;
path.unshift(objectId);
const obj = path.join("/");
try {

@@ -187,0 +191,0 @@ return state.handle.unmark(obj, range, name);

@@ -44,9 +44,16 @@ /** @hidden **/

/**
* To extend an arbitrary type, we have to turn any arrays that are part of the type's definition into Lists.
* So we recurse through the properties of T, turning any Arrays we find into Lists.
* Function for use in {@link change} which inserts values into a list at a given index
* @param list
* @param index
* @param values
*/
export type Extend<T> = T extends Array<infer T> ? List<Extend<T>> : T extends Object ? {
[P in keyof T]: Extend<T[P]>;
} : T;
export declare function insertAt<T>(list: T[], index: number, ...values: T[]): void;
/**
* Function for use in {@link change} which deletes values from a list at a given index
* @param list
* @param index
* @param numDelete
*/
export declare function deleteAt<T>(list: T[], index: number, numDelete?: number): void;
/**
* Function which is called by {@link change} when making changes to a `Doc<T>`

@@ -57,3 +64,3 @@ * @typeParam T - The type of value contained in the document

*/
export type ChangeFn<T> = (doc: Extend<T>) => void;
export type ChangeFn<T> = (doc: T) => void;
/** @hidden **/

@@ -194,2 +201,3 @@ export interface State<T> {

export declare function change<T>(doc: Doc<T>, options: string | ChangeOptions<T> | ChangeFn<T>, callback?: ChangeFn<T>): Doc<T>;
export declare function changeAt<T>(doc: Doc<T>, scope: Heads, options: string | ChangeOptions<T> | ChangeFn<T>, callback?: ChangeFn<T>): Doc<T>;
/**

@@ -196,0 +204,0 @@ * Make a change to a document which does not modify the document

@@ -40,7 +40,7 @@ /**

import type { Mark, MarkRange, MarkValue } from "./unstable_types";
import type { PatchCallback } from "./stable";
import { type PatchCallback } from "./stable";
import { type UnstableConflicts as Conflicts } from "./conflicts";
export type { PutPatch, DelPatch, SpliceTextPatch, InsertPatch, IncPatch, SyncMessage, Heads, } from "@automerge/automerge-wasm";
export type { ChangeOptions, ApplyOptions, ChangeFn } from "./stable";
export { view, free, getHeads, change, emptyChange, loadIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, } from "./stable";
export { view, free, getHeads, change, changeAt, emptyChange, loadIncremental, save, merge, getActorId, getLastLocalChange, getChanges, getAllChanges, applyChanges, getHistory, equals, encodeSyncState, decodeSyncState, generateSyncMessage, receiveSyncMessage, initSyncState, encodeChange, decodeChange, encodeSyncMessage, decodeSyncMessage, getMissingDeps, dump, toJS, isAutomerge, getObjectId, diff, insertAt, deleteAt, } from "./stable";
export type InitOptions<T> = {

@@ -117,5 +117,5 @@ /** The actor ID to use for this document, a random one will be generated if `null` is passed */

export declare function load<T>(data: Uint8Array, _opts?: ActorId | InitOptions<T>): Doc<T>;
export declare function splice<T>(doc: Doc<T>, prop: stable.Prop, index: number, del: number, newText?: string): string[] | undefined;
export declare function mark<T>(doc: Doc<T>, prop: stable.Prop, range: MarkRange, name: string, value: MarkValue): void;
export declare function unmark<T>(doc: Doc<T>, prop: stable.Prop, range: MarkRange, name: string): void;
export declare function splice<T>(doc: Doc<T>, path: stable.Prop[], index: number, del: number, newText?: string): string[] | undefined;
export declare function mark<T>(doc: Doc<T>, path: stable.Prop[], range: MarkRange, name: string, value: MarkValue): void;
export declare function unmark<T>(doc: Doc<T>, path: stable.Prop[], range: MarkRange, name: string): void;
export declare function marks<T>(doc: Doc<T>, prop: stable.Prop): Mark[];

@@ -122,0 +122,0 @@ /**

@@ -7,3 +7,3 @@ {

],
"version": "2.1.0-alpha.3",
"version": "2.1.0-alpha.4",
"description": "Javascript implementation of automerge, backed by @automerge/automerge-wasm",

@@ -54,5 +54,5 @@ "homepage": "https://github.com/automerge/automerge/tree/main/javascript",

"dependencies": {
"@automerge/automerge-wasm": "^0.2.2",
"@automerge/automerge-wasm": "^0.2.3",
"uuid": "^9.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc