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.0.1-alpha.5 to 2.0.1-alpha.6

dist/cjs/conflicts.js

1

dist/cjs/low_level.js

@@ -6,2 +6,3 @@ "use strict";

for (const k in api) {
// eslint-disable-next-line @typescript-eslint/no-extra-semi,@typescript-eslint/no-explicit-any
;

@@ -8,0 +9,0 @@ exports.ApiHandler[k] = api[k];

54

dist/cjs/proxies.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rootProxy = exports.textProxy = exports.listProxy = exports.mapProxy = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const text_1 = require("./text");

@@ -62,3 +63,4 @@ const counter_1 = require("./counter");

else {
return (0, counter_1.getWriteableCounter)(val, context, path, objectId, prop);
const counter = (0, counter_1.getWriteableCounter)(val, context, path, objectId, prop);
return counter;
}

@@ -179,5 +181,7 @@ }

if (textV2) {
assertString(value);
context.putObject(objectId, key, value);
}
else {
assertText(value);
const text = context.putObject(objectId, key, "");

@@ -240,3 +244,3 @@ const proxyText = textProxy(context, text, [...path, key], readonly);

if (index === Symbol.hasInstance) {
return instance => {
return (instance) => {
return Array.isArray(instance);

@@ -300,2 +304,3 @@ };

if (textV2) {
assertString(value);
if (index >= context.length(objectId)) {

@@ -310,2 +315,3 @@ context.insertObject(objectId, index, value);

let text;
assertText(value);
if (index >= context.length(objectId)) {

@@ -433,3 +439,3 @@ text = context.insertObject(objectId, index, "");

Object.assign(proxied, target);
let result = new Proxy(proxied, MapHandler);
const result = new Proxy(proxied, MapHandler);
// conversion through unknown is necessary because the types are so different

@@ -452,2 +458,3 @@ return result;

Object.assign(proxied, target);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

@@ -468,3 +475,5 @@ return new Proxy(proxied, ListHandler);

};
return new Proxy(target, TextHandler);
const proxied = {};
Object.assign(proxied, target);
return new Proxy(proxied, TextHandler);
}

@@ -495,5 +504,19 @@ exports.textProxy = textProxy;

for (let i = start; i < Math.min(end, length); i++) {
if (datatype === "text" || datatype === "list" || datatype === "map") {
if (datatype === "list" || datatype === "map") {
context.putObject(objectId, i, value);
}
else if (datatype === "text") {
if (textV2) {
assertString(value);
context.putObject(objectId, i, value);
}
else {
assertText(value);
const text = context.putObject(objectId, i, "");
const proxyText = textProxy(context, text, [...path, i], readonly);
for (let i = 0; i < value.length; i++) {
proxyText[i] = value.get(i);
}
}
}
else {

@@ -573,2 +596,3 @@ context.put(objectId, i, value, datatype);

if (textV2) {
assertString(value);
context.insertObject(objectId, index, value);

@@ -705,9 +729,7 @@ }

},
// todo: remove the any
reduce(f, initalValue) {
return this.toArray().reduce(f, initalValue);
reduce(f, initialValue) {
return this.toArray().reduce(f, initialValue);
},
// todo: remove the any
reduceRight(f, initalValue) {
return this.toArray().reduceRight(f, initalValue);
reduceRight(f, initialValue) {
return this.toArray().reduceRight(f, initialValue);
},

@@ -787,1 +809,11 @@ lastIndexOf(search, fromIndex = +Infinity) {

}
function assertText(value) {
if (!(value instanceof text_1.Text)) {
throw new Error("value was not a Text instance");
}
}
function assertString(value) {
if (typeof value !== "string") {
throw new Error("value was not a string");
}
}

@@ -26,7 +26,9 @@ "use strict";

Object.defineProperty(exports, "Float64", { enumerable: true, get: function () { return types_2.Float64; } });
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return types_2.Text; } });
const text_1 = require("./text");
var text_2 = require("./text");
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return text_2.Text; } });
const low_level_1 = require("./low_level");
const raw_string_1 = require("./raw_string");
const internal_state_1 = require("./internal_state");
const conflicts_1 = require("./conflicts");
/** @hidden **/

@@ -69,3 +71,3 @@ function use(api) {

handle.registerDatatype("counter", (n) => new types_1.Counter(n));
let textV2 = opts.enableTextV2 || false;
const textV2 = opts.enableTextV2 || false;
if (textV2) {

@@ -75,2 +77,3 @@ handle.registerDatatype("str", (n) => new raw_string_1.RawString(n));

else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handle.registerDatatype("text", (n) => new text_1.Text(n));

@@ -132,3 +135,3 @@ }

// set it to undefined to indicate that this is a full fat document
const { heads: oldHeads } = state, stateSansHeads = __rest(state, ["heads"]);
const { heads: _oldHeads } = state, stateSansHeads = __rest(state, ["heads"]);
return handle.applyPatches(doc, Object.assign(Object.assign({}, stateSansHeads), { handle }));

@@ -418,47 +421,2 @@ }

exports.getActorId = getActorId;
function conflictAt(context, objectId, prop, textV2) {
const values = context.getAll(objectId, prop);
if (values.length <= 1) {
return;
}
const result = {};
for (const fullVal of values) {
switch (fullVal[0]) {
case "map":
result[fullVal[1]] = (0, proxies_1.mapProxy)(context, fullVal[1], textV2, [prop], true);
break;
case "list":
result[fullVal[1]] = (0, proxies_1.listProxy)(context, fullVal[1], textV2, [prop], true);
break;
case "text":
if (textV2) {
result[fullVal[1]] = context.text(fullVal[1]);
}
else {
result[fullVal[1]] = (0, proxies_1.textProxy)(context, objectId, [prop], true);
}
break;
//case "table":
//case "cursor":
case "str":
case "uint":
case "int":
case "f64":
case "boolean":
case "bytes":
case "null":
result[fullVal[2]] = fullVal[1];
break;
case "counter":
result[fullVal[2]] = new types_1.Counter(fullVal[1]);
break;
case "timestamp":
result[fullVal[2]] = new Date(fullVal[1]);
break;
default:
throw RangeError(`datatype ${fullVal[0]} unimplemented`);
}
}
return result;
}
/**

@@ -510,5 +468,8 @@ * Get the conflicts associated with a property

const state = (0, internal_state_1._state)(doc, false);
if (state.textV2) {
throw new Error("use unstable.getConflicts for an unstable document");
}
const objectId = (0, internal_state_1._obj)(doc);
if (objectId != null) {
return conflictAt(state.handle, objectId, prop, state.textV2);
return (0, conflicts_1.stableConflictAt)(state.handle, objectId, prop);
}

@@ -538,2 +499,3 @@ else {

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getObjectId(doc, prop) {

@@ -540,0 +502,0 @@ if (prop) {

@@ -24,2 +24,3 @@ "use strict";

}
//eslint-disable-next-line @typescript-eslint/no-explicit-any
get(index) {

@@ -26,0 +27,0 @@ return this.elems[index];

"use strict";
/**
* # The unstable API
*
* This module contains new features we are working on which are either not yet
* ready for a stable release and/or which will result in backwards incompatible
* API changes. The API of this module may change in arbitrary ways between
* point releases - we will always document what these changes are in the
* [CHANGELOG](#changelog) below, but only depend on this module if you are prepared to deal
* with frequent changes.
*
* ## Differences from stable
*
* In the stable API text objects are represented using the {@link Text} class.
* This means you must decide up front whether your string data might need
* concurrent merges in the future and if you change your mind you have to
* figure out how to migrate your data. In the unstable API the `Text` class is
* gone and all `string`s are represented using the text CRDT, allowing for
* concurrent changes. Modifying a string is done using the {@link splice}
* function. You can still access the old behaviour of strings which do not
* support merging behaviour via the {@link RawString} class.
*
* This leads to the following differences from `stable`:
*
* * There is no `unstable.Text` class, all strings are text objects
* * Reading strings in an `unstable` document is the same as reading any other
* javascript string
* * To modify strings in an `unstable` document use {@link splice}
* * The {@link AutomergeValue} type does not include the {@link Text}
* class but the {@link RawString} class is included in the {@link ScalarValue}
* type
*
* ## CHANGELOG
* * Introduce this module to expose the new API which has no `Text` class
*
*
* @module
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConflicts = exports.splice = exports.load = exports.from = exports.clone = exports.init = exports.getBackend = exports.RawString = 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;
var types_1 = require("./types");
Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return types_1.Counter; } });
Object.defineProperty(exports, "Int", { enumerable: true, get: function () { return types_1.Int; } });
Object.defineProperty(exports, "Uint", { enumerable: true, get: function () { return types_1.Uint; } });
Object.defineProperty(exports, "Float64", { enumerable: true, get: function () { return types_1.Float64; } });
var unstable_types_1 = require("./unstable_types");
Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return unstable_types_1.Counter; } });
Object.defineProperty(exports, "Int", { enumerable: true, get: function () { return unstable_types_1.Int; } });
Object.defineProperty(exports, "Uint", { enumerable: true, get: function () { return unstable_types_1.Uint; } });
Object.defineProperty(exports, "Float64", { enumerable: true, get: function () { return unstable_types_1.Float64; } });
const conflicts_1 = require("./conflicts");
var stable_1 = require("./stable");

@@ -55,3 +93,3 @@ Object.defineProperty(exports, "view", { enumerable: true, get: function () { return stable_1.view; } });

function init(_opts) {
let opts = importOpts(_opts);
const opts = importOpts(_opts);
opts.enableTextV2 = true;

@@ -77,3 +115,3 @@ return stable.init(opts);

function clone(doc, _opts) {
let opts = importOpts(_opts);
const opts = importOpts(_opts);
opts.enableTextV2 = true;

@@ -197,5 +235,14 @@ return stable.clone(doc, opts);

function getConflicts(doc, prop) {
// this function only exists to get the types to line up with future.AutomergeValue
return stable.getConflicts(doc, prop);
const state = (0, internal_state_1._state)(doc, false);
if (!state.textV2) {
throw new Error("use getConflicts for a stable document");
}
const objectId = (0, internal_state_1._obj)(doc);
if (objectId != null) {
return (0, conflicts_1.unstableConflictAt)(state.handle, objectId, prop);
}
else {
return undefined;
}
}
exports.getConflicts = getConflicts;
export function UseApi(api) {
for (const k in api) {
// eslint-disable-next-line @typescript-eslint/no-extra-semi,@typescript-eslint/no-explicit-any
;

@@ -4,0 +5,0 @@ ApiHandler[k] = api[k];

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

/* eslint-disable @typescript-eslint/no-explicit-any */
import { Text } from "./text";

@@ -59,3 +60,4 @@ import { Counter, getWriteableCounter } from "./counter";

else {
return getWriteableCounter(val, context, path, objectId, prop);
const counter = getWriteableCounter(val, context, path, objectId, prop);
return counter;
}

@@ -176,5 +178,7 @@ }

if (textV2) {
assertString(value);
context.putObject(objectId, key, value);
}
else {
assertText(value);
const text = context.putObject(objectId, key, "");

@@ -237,3 +241,3 @@ const proxyText = textProxy(context, text, [...path, key], readonly);

if (index === Symbol.hasInstance) {
return instance => {
return (instance) => {
return Array.isArray(instance);

@@ -297,2 +301,3 @@ };

if (textV2) {
assertString(value);
if (index >= context.length(objectId)) {

@@ -307,2 +312,3 @@ context.insertObject(objectId, index, value);

let text;
assertText(value);
if (index >= context.length(objectId)) {

@@ -430,3 +436,3 @@ text = context.insertObject(objectId, index, "");

Object.assign(proxied, target);
let result = new Proxy(proxied, MapHandler);
const result = new Proxy(proxied, MapHandler);
// conversion through unknown is necessary because the types are so different

@@ -448,2 +454,3 @@ return result;

Object.assign(proxied, target);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

@@ -463,3 +470,5 @@ return new Proxy(proxied, ListHandler);

};
return new Proxy(target, TextHandler);
const proxied = {};
Object.assign(proxied, target);
return new Proxy(proxied, TextHandler);
}

@@ -488,5 +497,19 @@ export function rootProxy(context, textV2, readonly) {

for (let i = start; i < Math.min(end, length); i++) {
if (datatype === "text" || datatype === "list" || datatype === "map") {
if (datatype === "list" || datatype === "map") {
context.putObject(objectId, i, value);
}
else if (datatype === "text") {
if (textV2) {
assertString(value);
context.putObject(objectId, i, value);
}
else {
assertText(value);
const text = context.putObject(objectId, i, "");
const proxyText = textProxy(context, text, [...path, i], readonly);
for (let i = 0; i < value.length; i++) {
proxyText[i] = value.get(i);
}
}
}
else {

@@ -566,2 +589,3 @@ context.put(objectId, i, value, datatype);

if (textV2) {
assertString(value);
context.insertObject(objectId, index, value);

@@ -698,9 +722,7 @@ }

},
// todo: remove the any
reduce(f, initalValue) {
return this.toArray().reduce(f, initalValue);
reduce(f, initialValue) {
return this.toArray().reduce(f, initialValue);
},
// todo: remove the any
reduceRight(f, initalValue) {
return this.toArray().reduceRight(f, initalValue);
reduceRight(f, initialValue) {
return this.toArray().reduceRight(f, initialValue);
},

@@ -780,1 +802,11 @@ lastIndexOf(search, fromIndex = +Infinity) {

}
function assertText(value) {
if (!(value instanceof Text)) {
throw new Error("value was not a Text instance");
}
}
function assertString(value) {
if (typeof value !== "string") {
throw new Error("value was not a string");
}
}

@@ -14,10 +14,12 @@ var __rest = (this && this.__rest) || function (s, e) {

export { /** @hidden */ uuid } from "./uuid";
import { rootProxy, listProxy, mapProxy, textProxy } from "./proxies";
import { rootProxy } from "./proxies";
import { STATE } from "./constants";
import { Counter, } from "./types";
export { Counter, Int, Uint, Float64, Text, } from "./types";
export { Counter, Int, Uint, Float64, } from "./types";
import { Text } from "./text";
export { Text } from "./text";
import { ApiHandler, UseApi } from "./low_level";
import { RawString } from "./raw_string";
import { _state, _is_proxy, _trace, _obj } from "./internal_state";
import { stableConflictAt } from "./conflicts";
/** @hidden **/

@@ -58,3 +60,3 @@ export function use(api) {

handle.registerDatatype("counter", (n) => new Counter(n));
let textV2 = opts.enableTextV2 || false;
const textV2 = opts.enableTextV2 || false;
if (textV2) {

@@ -64,2 +66,3 @@ handle.registerDatatype("str", (n) => new RawString(n));

else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handle.registerDatatype("text", (n) => new Text(n));

@@ -119,3 +122,3 @@ }

// set it to undefined to indicate that this is a full fat document
const { heads: oldHeads } = state, stateSansHeads = __rest(state, ["heads"]);
const { heads: _oldHeads } = state, stateSansHeads = __rest(state, ["heads"]);
return handle.applyPatches(doc, Object.assign(Object.assign({}, stateSansHeads), { handle }));

@@ -395,47 +398,2 @@ }

}
function conflictAt(context, objectId, prop, textV2) {
const values = context.getAll(objectId, prop);
if (values.length <= 1) {
return;
}
const result = {};
for (const fullVal of values) {
switch (fullVal[0]) {
case "map":
result[fullVal[1]] = mapProxy(context, fullVal[1], textV2, [prop], true);
break;
case "list":
result[fullVal[1]] = listProxy(context, fullVal[1], textV2, [prop], true);
break;
case "text":
if (textV2) {
result[fullVal[1]] = context.text(fullVal[1]);
}
else {
result[fullVal[1]] = textProxy(context, objectId, [prop], true);
}
break;
//case "table":
//case "cursor":
case "str":
case "uint":
case "int":
case "f64":
case "boolean":
case "bytes":
case "null":
result[fullVal[2]] = fullVal[1];
break;
case "counter":
result[fullVal[2]] = new Counter(fullVal[1]);
break;
case "timestamp":
result[fullVal[2]] = new Date(fullVal[1]);
break;
default:
throw RangeError(`datatype ${fullVal[0]} unimplemented`);
}
}
return result;
}
/**

@@ -487,5 +445,8 @@ * Get the conflicts associated with a property

const state = _state(doc, false);
if (state.textV2) {
throw new Error("use unstable.getConflicts for an unstable document");
}
const objectId = _obj(doc);
if (objectId != null) {
return conflictAt(state.handle, objectId, prop, state.textV2);
return stableConflictAt(state.handle, objectId, prop);
}

@@ -513,2 +474,3 @@ else {

*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getObjectId(doc, prop) {

@@ -515,0 +477,0 @@ if (prop) {

@@ -21,2 +21,3 @@ import { TEXT, STATE } from "./constants";

}
//eslint-disable-next-line @typescript-eslint/no-explicit-any
get(index) {

@@ -23,0 +24,0 @@ return this.elems[index];

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

export { Counter, Int, Uint, Float64, } from "./types";
/**
* # The unstable API
*
* This module contains new features we are working on which are either not yet
* ready for a stable release and/or which will result in backwards incompatible
* API changes. The API of this module may change in arbitrary ways between
* point releases - we will always document what these changes are in the
* [CHANGELOG](#changelog) below, but only depend on this module if you are prepared to deal
* with frequent changes.
*
* ## Differences from stable
*
* In the stable API text objects are represented using the {@link Text} class.
* This means you must decide up front whether your string data might need
* concurrent merges in the future and if you change your mind you have to
* figure out how to migrate your data. In the unstable API the `Text` class is
* gone and all `string`s are represented using the text CRDT, allowing for
* concurrent changes. Modifying a string is done using the {@link splice}
* function. You can still access the old behaviour of strings which do not
* support merging behaviour via the {@link RawString} class.
*
* This leads to the following differences from `stable`:
*
* * There is no `unstable.Text` class, all strings are text objects
* * Reading strings in an `unstable` document is the same as reading any other
* javascript string
* * To modify strings in an `unstable` document use {@link splice}
* * The {@link AutomergeValue} type does not include the {@link Text}
* class but the {@link RawString} class is included in the {@link ScalarValue}
* type
*
* ## CHANGELOG
* * Introduce this module to expose the new API which has no `Text` class
*
*
* @module
*/
export { Counter, Int, Uint, Float64, } from "./unstable_types";
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, } from "./stable";

@@ -18,3 +56,3 @@ import * as stable from "./stable";

export function init(_opts) {
let opts = importOpts(_opts);
const opts = importOpts(_opts);
opts.enableTextV2 = true;

@@ -39,3 +77,3 @@ return stable.init(opts);

export function clone(doc, _opts) {
let opts = importOpts(_opts);
const opts = importOpts(_opts);
opts.enableTextV2 = true;

@@ -155,4 +193,13 @@ return stable.clone(doc, opts);

export function getConflicts(doc, prop) {
// this function only exists to get the types to line up with future.AutomergeValue
return stable.getConflicts(doc, prop);
const state = _state(doc, false);
if (!state.textV2) {
throw new Error("use getConflicts for a stable document");
}
const objectId = _obj(doc);
if (objectId != null) {
return unstableConflictAt(state.handle, objectId, prop);
}
else {
return undefined;
}
}

@@ -0,6 +1,32 @@

import { Text } from "./text";
import { Automerge, type Heads, type ObjID, type Prop } from "@automerge/automerge-wasm";
import type { MapValue, ListValue, TextValue } from "./types";
export declare function mapProxy(context: Automerge, objectId: ObjID, textV2: boolean, path?: Prop[], readonly?: boolean, heads?: Heads): MapValue;
export declare function listProxy(context: Automerge, objectId: ObjID, textV2: boolean, path?: Prop[], readonly?: boolean, heads?: Heads): ListValue;
export declare function textProxy(context: Automerge, objectId: ObjID, path?: Prop[], readonly?: boolean, heads?: Heads): TextValue;
import type { AutomergeValue, MapValue, ListValue } from "./types";
import { type AutomergeValue as UnstableAutomergeValue, MapValue as UnstableMapValue, ListValue as UnstableListValue } from "./unstable_types";
type TargetCommon = {
context: Automerge;
objectId: ObjID;
path: Array<Prop>;
readonly: boolean;
heads?: Array<string>;
cache: object;
trace?: any;
frozen: boolean;
};
export type Text2Target = TargetCommon & {
textV2: true;
};
export type Text1Target = TargetCommon & {
textV2: false;
};
export type Target = Text1Target | Text2Target;
export type ValueType<T extends Target> = T extends Text2Target ? UnstableAutomergeValue : T extends Text1Target ? AutomergeValue : never;
type MapValueType<T extends Target> = T extends Text2Target ? UnstableMapValue : T extends Text1Target ? MapValue : never;
type ListValueType<T extends Target> = T extends Text2Target ? UnstableListValue : T extends Text1Target ? ListValue : never;
export declare function mapProxy<T extends Target>(context: Automerge, objectId: ObjID, textV2: boolean, path?: Prop[], readonly?: boolean, heads?: Heads): MapValueType<T>;
export declare function listProxy<T extends Target>(context: Automerge, objectId: ObjID, textV2: boolean, path?: Prop[], readonly?: boolean, heads?: Heads): ListValueType<T>;
interface TextProxy extends Text {
splice: (index: any, del: any, ...vals: any[]) => void;
}
export declare function textProxy(context: Automerge, objectId: ObjID, path?: Prop[], readonly?: boolean, heads?: Heads): TextProxy;
export declare function rootProxy<T>(context: Automerge, textV2: boolean, readonly?: boolean): T;
export {};
/** @hidden **/
export { /** @hidden */ uuid } from "./uuid";
import { type AutomergeValue, type Doc, type PatchCallback } from "./types";
export { type AutomergeValue, Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, type ScalarValue, Text, } from "./types";
export { type AutomergeValue, Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, type ScalarValue, } from "./types";
export { Text } from "./text";
import type { API, Actor as ActorId, Prop, ObjID, Change, DecodedChange, Heads, MaterializeValue, JsSyncState as SyncState, SyncMessage, DecodedSyncMessage } from "@automerge/automerge-wasm";
export type { PutPatch, DelPatch, SplicePatch, IncPatch, SyncMessage, } from "@automerge/automerge-wasm";
export type { PutPatch, DelPatch, SpliceTextPatch, InsertPatch, IncPatch, SyncMessage, } from "@automerge/automerge-wasm";
import { type ChangeToEncode } from "./low_level";

@@ -27,2 +28,16 @@ import { Automerge } from "@automerge/automerge-wasm";

/**
* A List is an extended Array that adds the two helper methods `deleteAt` and `insertAt`.
*/
export interface List<T> extends Array<T> {
insertAt(index: number, ...args: T[]): List<T>;
deleteAt(index: number, numDelete?: number): List<T>;
}
/**
* 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.
*/
export type Extend<T> = T extends Array<infer T> ? List<Extend<T>> : T extends Object ? {
[P in keyof T]: Extend<T[P]>;
} : T;
/**
* Function which is called by {@link change} when making changes to a `Doc<T>`

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

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

@@ -36,0 +51,0 @@ export interface State<T> {

@@ -37,3 +37,3 @@ import type { Value } from "@automerge/automerge-wasm";

*/
toSpans(): Array<Value | Object>;
toSpans(): Array<Value | object>;
/**

@@ -51,3 +51,3 @@ * Returns the content of the Text object as a simple string, so that the

*/
insertAt(index: number, ...values: Array<Value | Object>): void;
insertAt(index: number, ...values: Array<Value | object>): void;
/**

@@ -58,3 +58,3 @@ * Deletes `numDelete` list items starting at position `index`.

deleteAt(index: number, numDelete?: number): void;
map<T>(callback: (e: Value | Object) => T): void;
map<T>(callback: (e: Value | object) => T): void;
lastIndexOf(searchElement: Value, fromIndex?: number): void;

@@ -61,0 +61,0 @@ concat(other: Text): Text;

export { Text } from "./text";
import { Text } from "./text";
export { Counter } from "./counter";

@@ -9,3 +10,3 @@ export { Int, Uint, Float64 } from "./numbers";

[key: string]: AutomergeValue;
} | Array<AutomergeValue>;
} | Array<AutomergeValue> | Text;
export type MapValue = {

@@ -15,3 +16,2 @@ [key: string]: AutomergeValue;

export type ListValue = Array<AutomergeValue>;
export type TextValue = Array<AutomergeValue>;
export type ScalarValue = string | number | null | boolean | Date | Counter | Uint8Array;

@@ -18,0 +18,0 @@ /**

@@ -25,5 +25,5 @@ /**

* * There is no `unstable.Text` class, all strings are text objects
* * Reading strings in a `future` document is the same as reading any other
* * Reading strings in an `unstable` document is the same as reading any other
* javascript string
* * To modify strings in a `future` document use {@link splice}
* * To modify strings in an `unstable` document use {@link splice}
* * The {@link AutomergeValue} type does not include the {@link Text}

@@ -39,17 +39,6 @@ * class but the {@link RawString} class is included in the {@link ScalarValue}

*/
import { Counter } from "./types";
export { Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, } from "./types";
export { Counter, type Doc, Int, Uint, Float64, type Patch, type PatchCallback, type AutomergeValue, type ScalarValue, } from "./unstable_types";
import type { PatchCallback } from "./stable";
export type AutomergeValue = ScalarValue | {
[key: string]: AutomergeValue;
} | Array<AutomergeValue>;
export type MapValue = {
[key: string]: AutomergeValue;
};
export type ListValue = Array<AutomergeValue>;
export type ScalarValue = string | number | null | boolean | Date | Counter | Uint8Array | RawString;
export type Conflicts = {
[key: string]: AutomergeValue;
};
export type { PutPatch, DelPatch, SplicePatch, IncPatch, SyncMessage, } from "@automerge/automerge-wasm";
import { type UnstableConflicts as Conflicts } from "./conflicts";
export type { PutPatch, DelPatch, SpliceTextPatch, InsertPatch, IncPatch, SyncMessage, } from "@automerge/automerge-wasm";
export type { ChangeOptions, ApplyOptions, ChangeFn } from "./stable";

@@ -69,3 +58,2 @@ 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, } from "./stable";

export declare const getBackend: typeof stable.getBackend;
import { RawString } from "./raw_string";
/**

@@ -72,0 +60,0 @@ * Create a new automerge document

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

],
"version": "2.0.1-alpha.5",
"version": "2.0.1-alpha.6",
"description": "Javascript implementation of automerge, backed by @automerge/automerge-wasm",

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

"dependencies": {
"@automerge/automerge-wasm": "0.1.22",
"@automerge/automerge-wasm": "0.1.23",
"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