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

@kizahasi/ot-string

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kizahasi/ot-string - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0-beta.1

dist/cjs/internal/operationBuilderFactory.js

18

dist/cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OperationBuilder = exports.deserializeDownOperation = exports.serializeDownOperation = exports.composeDownOperation = exports.invertDownOperation = exports.applyBackAndRestore = exports.applyBack = exports.transformUpOperation = exports.deserializeUpOperation = exports.serializeUpOperation = exports.composeUpOperation = exports.invertUpOperation = exports.applyAndRestore = exports.apply = exports.transformTwoWayOperation = exports.diff = exports.deserizalizeTwoWayOperation = exports.serializeTwoWayOperation = exports.toUpOperation = exports.toDownOperation = exports.stateTooLong = exports.secondTooShort = exports.stateTooShort = exports.secondTooLong = exports.deleteStringNotMatch = exports.insert$ = exports.delete$ = exports.r = exports.d = exports.i = exports.NonEmptyString = exports.PositiveInt = void 0;
var positiveInt_1 = require("./internal/positiveInt");
Object.defineProperty(exports, "PositiveInt", { enumerable: true, get: function () { return positiveInt_1.PositiveInt; } });
exports.deserializeDownOperation = exports.serializeDownOperation = exports.composeDownOperation = exports.invertDownOperation = exports.applyBackAndRestore = exports.applyBack = exports.transformUpOperation = exports.deserializeUpOperation = exports.serializeUpOperation = exports.composeUpOperation = exports.invertUpOperation = exports.applyAndRestore = exports.apply = exports.transformTwoWayOperation = exports.diff = exports.deserizalizeTwoWayOperation = exports.serializeTwoWayOperation = exports.toUpOperation = exports.toDownOperation = exports.NonEmptyString = void 0;
var nonEmptyString_1 = require("./internal/nonEmptyString");
Object.defineProperty(exports, "NonEmptyString", { enumerable: true, get: function () { return nonEmptyString_1.NonEmptyString; } });
var const_1 = require("./internal/const");
Object.defineProperty(exports, "i", { enumerable: true, get: function () { return const_1.i; } });
Object.defineProperty(exports, "d", { enumerable: true, get: function () { return const_1.d; } });
Object.defineProperty(exports, "r", { enumerable: true, get: function () { return const_1.r; } });
Object.defineProperty(exports, "delete$", { enumerable: true, get: function () { return const_1.delete$; } });
Object.defineProperty(exports, "insert$", { enumerable: true, get: function () { return const_1.insert$; } });
var error_1 = require("./internal/error");
Object.defineProperty(exports, "deleteStringNotMatch", { enumerable: true, get: function () { return error_1.deleteStringNotMatch; } });
Object.defineProperty(exports, "secondTooLong", { enumerable: true, get: function () { return error_1.secondTooLong; } });
Object.defineProperty(exports, "stateTooShort", { enumerable: true, get: function () { return error_1.stateTooShort; } });
Object.defineProperty(exports, "secondTooShort", { enumerable: true, get: function () { return error_1.secondTooShort; } });
Object.defineProperty(exports, "stateTooLong", { enumerable: true, get: function () { return error_1.stateTooLong; } });
var twoWayOperation_1 = require("./internal/operation/twoWayOperation");

@@ -42,3 +28,1 @@ Object.defineProperty(exports, "toDownOperation", { enumerable: true, get: function () { return twoWayOperation_1.toDownOperation; } });

Object.defineProperty(exports, "deserializeDownOperation", { enumerable: true, get: function () { return downOperation_1.ofUnit; } });
var operationBuilder_1 = require("./internal/operationBuilder/operationBuilder");
Object.defineProperty(exports, "OperationBuilder", { enumerable: true, get: function () { return operationBuilder_1.OperationBuilder; } });
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NonEmptyString = void 0;
const positiveInt_1 = require("./positiveInt");
const ot_core_1 = require("@kizahasi/ot-core");
class NonEmptyString {

@@ -16,3 +16,3 @@ constructor(source) {

get length() {
return new positiveInt_1.PositiveInt(this.source.length);
return new ot_core_1.PositiveInt(this.source.length);
}

@@ -19,0 +19,0 @@ concat(other) {

@@ -28,13 +28,10 @@ "use strict";

const result_1 = require("@kizahasi/result");
const const_1 = require("../const");
const core_1 = require("../core");
const ot_core_1 = require("@kizahasi/ot-core");
const nonEmptyString_1 = require("../nonEmptyString");
const positiveInt_1 = require("../positiveInt");
const operationBuilderFactory_1 = require("../operationBuilder/operationBuilderFactory");
const operationBuilder_1 = require("../operationBuilder/operationBuilder");
const TextUpOperation = __importStar(require("./upOperation"));
const operationBuilderFactory_1 = require("../operationBuilderFactory");
const applyBack = ({ nextState, downOperation, }) => {
return TextUpOperation.apply({
prevState: nextState,
upOperation: (0, core_1.invertCore)(downOperation),
upOperation: (0, ot_core_1.invert)(downOperation),
});

@@ -46,3 +43,3 @@ };

prevState: nextState,
upOperation: (0, core_1.invertCore)(downOperation),
upOperation: (0, ot_core_1.invert)(downOperation),
});

@@ -54,3 +51,3 @@ if (invertedResult.isError) {

prevState: invertedResult.value.nextState,
restored: (0, core_1.invertCore)(invertedResult.value.restored),
restored: (0, ot_core_1.invert)(invertedResult.value.restored),
});

@@ -60,9 +57,9 @@ };

const compose = ({ first, second, }) => {
const result = (0, core_1.composeCore)({
first: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.downFactory, first).toUnits()),
second: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.downFactory, second).toUnits()),
const result = (0, ot_core_1.compose)({
first: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.downFactory, first).toUnits()),
second: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.downFactory, second).toUnits()),
factory: operationBuilderFactory_1.downFactory,
splitInsert: (target, deleteCount) => [
deleteCount,
new positiveInt_1.PositiveInt(target.value - deleteCount.value),
new ot_core_1.PositiveInt(target.value - deleteCount.value),
],

@@ -84,20 +81,20 @@ splitDelete: (str, index) => [

exports.compose = compose;
const invert = (source) => (0, core_1.invertCore)(source);
const invert = (source) => (0, ot_core_1.invert)(source);
exports.invert = invert;
const toUnit = (source) => {
return Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.downFactory, source).toUnits()).map(unit => {
return Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.downFactory, source).toUnits()).map(unit => {
switch (unit.type) {
case const_1.insert$:
case ot_core_1.insert$:
return {
t: const_1.i,
t: ot_core_1.i,
i: unit.insert.value,
};
case const_1.delete$:
case ot_core_1.delete$:
return {
t: const_1.d,
t: ot_core_1.d,
d: unit.delete.value,
};
case const_1.retain:
case ot_core_1.retain:
return {
t: const_1.r,
t: ot_core_1.r,
r: unit.retain.value,

@@ -110,3 +107,3 @@ };

const ofUnit = (source) => {
const builder = new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.downFactory);
const builder = new ot_core_1.OperationBuilder(operationBuilderFactory_1.downFactory);
for (const unit of source) {

@@ -117,5 +114,5 @@ if (unit == null) {

switch (unit.t) {
case const_1.r: {
case ot_core_1.r: {
const retain = unit.r;
const retainAsPositiveInt = positiveInt_1.PositiveInt.tryCreate(retain);
const retainAsPositiveInt = ot_core_1.PositiveInt.tryCreate(retain);
if (retainAsPositiveInt == null) {

@@ -127,5 +124,5 @@ continue;

}
case const_1.i: {
case ot_core_1.i: {
const insert = typeof unit.i === 'string' ? unit.i.length : unit.i;
const insertAsPositiveInt = positiveInt_1.PositiveInt.tryCreate(insert);
const insertAsPositiveInt = ot_core_1.PositiveInt.tryCreate(insert);
if (insertAsPositiveInt == null) {

@@ -137,3 +134,3 @@ continue;

}
case const_1.d: {
case ot_core_1.d: {
const del = unit.d;

@@ -140,0 +137,0 @@ const delAsPositiveInt = nonEmptyString_1.NonEmptyString.tryCreate(del);

@@ -6,11 +6,7 @@ "use strict";

const diff_match_patch_1 = require("diff-match-patch");
const const_1 = require("../const");
const core_1 = require("../core");
const ot_core_1 = require("@kizahasi/ot-core");
const nonEmptyString_1 = require("../nonEmptyString");
const positiveInt_1 = require("../positiveInt");
const operationBuilderFactory_1 = require("../operationBuilder/operationBuilderFactory");
const operation_1 = require("../operationBuilder/operation");
const operationBuilder_1 = require("../operationBuilder/operationBuilder");
const operationBuilderFactory_1 = require("../operationBuilderFactory");
const diff = ({ prevState, nextState, }) => {
const builder = new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory);
const builder = new ot_core_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory);
const dmp = new diff_match_patch_1.diff_match_patch();

@@ -23,3 +19,3 @@ dmp.diff_main(prevState, nextState).forEach(([diffType, diff]) => {

case 0:
builder.retain(new positiveInt_1.PositiveInt(diff.length));
builder.retain(new ot_core_1.PositiveInt(diff.length));
break;

@@ -35,5 +31,5 @@ case 1:

const transform = ({ first, second, }) => {
const result = (0, core_1.transformCore)({
first: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory, first).toUnits()),
second: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory, second).toUnits()),
const result = (0, ot_core_1.transform)({
first: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory, first).toUnits()),
second: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory, second).toUnits()),
factory: operationBuilderFactory_1.twoWayFactory,

@@ -56,17 +52,17 @@ splitDelete: (target, deleteCount) => [

const toUnit = (source) => {
return Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory, source).toUnits()).map(unit => {
return Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory, source).toUnits()).map(unit => {
switch (unit.type) {
case const_1.insert$:
case ot_core_1.insert$:
return {
t: const_1.i,
t: ot_core_1.i,
i: unit.insert.value,
};
case const_1.delete$:
case ot_core_1.delete$:
return {
t: const_1.d,
t: ot_core_1.d,
d: unit.delete.value,
};
case const_1.retain:
case ot_core_1.retain:
return {
t: const_1.r,
t: ot_core_1.r,
r: unit.retain.value,

@@ -79,3 +75,3 @@ };

const ofUnit = (source) => {
const builder = new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory);
const builder = new ot_core_1.OperationBuilder(operationBuilderFactory_1.twoWayFactory);
for (const unit of source) {

@@ -86,5 +82,5 @@ if (unit == null) {

switch (unit.t) {
case const_1.r: {
case ot_core_1.r: {
const retain = unit.r;
const retainAsPositiveInt = positiveInt_1.PositiveInt.tryCreate(retain);
const retainAsPositiveInt = ot_core_1.PositiveInt.tryCreate(retain);
if (retainAsPositiveInt == null) {

@@ -96,3 +92,3 @@ continue;

}
case const_1.i: {
case ot_core_1.i: {
const insert = unit.i;

@@ -106,3 +102,3 @@ const insertAsNonEpmtyString = nonEmptyString_1.NonEmptyString.tryCreate(insert);

}
case const_1.d: {
case ot_core_1.d: {
const del = unit.d;

@@ -122,3 +118,3 @@ const delAsNonEmptyString = nonEmptyString_1.NonEmptyString.tryCreate(del);

const toUpOperation = (source) => {
return (0, operation_1.mapOperation)({
return (0, ot_core_1.mapOperation)({
source,

@@ -131,3 +127,3 @@ mapInsert: insert => insert,

const toDownOperation = (source) => {
return (0, operation_1.mapOperation)({
return (0, ot_core_1.mapOperation)({
source,

@@ -134,0 +130,0 @@ mapInsert: insert => insert.length,

@@ -6,12 +6,32 @@ "use strict";

const result_1 = require("@kizahasi/result");
const const_1 = require("../const");
const core_1 = require("../core");
const ot_core_1 = require("@kizahasi/ot-core");
const nonEmptyString_1 = require("../nonEmptyString");
const positiveInt_1 = require("../positiveInt");
const operationBuilderFactory_1 = require("../operationBuilder/operationBuilderFactory");
const operationBuilder_1 = require("../operationBuilder/operationBuilder");
const operationBuilderFactory_1 = require("../operationBuilderFactory");
const insertOrReplace = {
insert: ({ state, start, replacement }) => {
var _a, _b;
return {
newState: state.substring(0, start) +
((_b = (_a = replacement.value) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '') +
state.substring(start),
};
},
replace: ({ state, start, deleteCount, replacement }) => {
var _a, _b;
const deleted = state.substring(start, start + deleteCount.value);
return {
newState: state.substring(0, start) +
((_b = (_a = replacement.value) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '') +
state.substring(start + deleteCount.value),
deleted: new nonEmptyString_1.NonEmptyString(deleted),
};
},
};
const apply = ({ prevState, upOperation, }) => {
const result = (0, core_1.applyAndRestoreCore)({
const result = (0, ot_core_1.applyAndRestore)({
...insertOrReplace,
state: prevState,
action: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, upOperation).toIterable()),
action: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, upOperation).toIterable()),
getStateLength: state => state.length,
getInsertLength: insert => insert.length.value,
getDeleteLength: del => del,

@@ -27,5 +47,8 @@ mapping: () => option_1.Option.some(undefined),

const applyAndRestore = ({ prevState, upOperation, }) => {
const result = (0, core_1.applyAndRestoreCore)({
const result = (0, ot_core_1.applyAndRestore)({
...insertOrReplace,
state: prevState,
action: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, upOperation).toIterable()),
action: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, upOperation).toIterable()),
getStateLength: state => state.length,
getInsertLength: insert => insert.length.value,
getDeleteLength: del => del,

@@ -50,5 +73,5 @@ restoreOption: {

const compose = ({ first, second, }) => {
const result = (0, core_1.composeCore)({
first: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, first).toUnits()),
second: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, second).toUnits()),
const result = (0, ot_core_1.compose)({
first: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, first).toUnits()),
second: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, second).toUnits()),
factory: operationBuilderFactory_1.upFactory,

@@ -61,3 +84,3 @@ splitInsert: (str, index) => [

deleteCount,
new positiveInt_1.PositiveInt(target.value - deleteCount.value),
new ot_core_1.PositiveInt(target.value - deleteCount.value),
],

@@ -76,9 +99,9 @@ });

const transform = ({ first, second, }) => {
const result = (0, core_1.transformCore)({
first: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, first).toUnits()),
second: Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, second).toUnits()),
const result = (0, ot_core_1.transform)({
first: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, first).toUnits()),
second: Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, second).toUnits()),
factory: operationBuilderFactory_1.upFactory,
splitDelete: (target, deleteCount) => [
deleteCount,
new positiveInt_1.PositiveInt(target.value - deleteCount.value),
new ot_core_1.PositiveInt(target.value - deleteCount.value),
],

@@ -96,20 +119,20 @@ });

exports.transform = transform;
const invert = (source) => (0, core_1.invertCore)(source);
const invert = (source) => (0, ot_core_1.invert)(source);
exports.invert = invert;
const toUnit = (source) => {
return Array.from(new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory, source).toUnits()).map(unit => {
return Array.from(new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory, source).toUnits()).map(unit => {
switch (unit.type) {
case const_1.insert$:
case ot_core_1.insert$:
return {
t: const_1.i,
t: ot_core_1.i,
i: unit.insert.value,
};
case const_1.delete$:
case ot_core_1.delete$:
return {
t: const_1.d,
t: ot_core_1.d,
d: unit.delete.value,
};
case const_1.retain:
case ot_core_1.retain:
return {
t: const_1.r,
t: ot_core_1.r,
r: unit.retain.value,

@@ -122,3 +145,3 @@ };

const ofUnit = (source) => {
const builder = new operationBuilder_1.OperationBuilder(operationBuilderFactory_1.upFactory);
const builder = new ot_core_1.OperationBuilder(operationBuilderFactory_1.upFactory);
for (const unit of source) {

@@ -129,5 +152,5 @@ if (unit == null) {

switch (unit.t) {
case const_1.r: {
case ot_core_1.r: {
const retain = unit.r;
const retainAsPositiveInt = positiveInt_1.PositiveInt.tryCreate(retain);
const retainAsPositiveInt = ot_core_1.PositiveInt.tryCreate(retain);
if (retainAsPositiveInt == null) {

@@ -139,3 +162,3 @@ continue;

}
case const_1.i: {
case ot_core_1.i: {
const insert = unit.i;

@@ -149,5 +172,5 @@ const insertAsNonEmptyString = nonEmptyString_1.NonEmptyString.tryCreate(insert);

}
case const_1.d: {
case ot_core_1.d: {
const del = typeof unit.d === 'string' ? unit.d.length : unit.d;
const delAsPositiveInt = positiveInt_1.PositiveInt.tryCreate(del);
const delAsPositiveInt = ot_core_1.PositiveInt.tryCreate(del);
if (delAsPositiveInt == null) {

@@ -154,0 +177,0 @@ continue;

@@ -1,8 +0,4 @@

export { PositiveInt } from './internal/positiveInt';
export { NonEmptyString } from './internal/nonEmptyString';
export { i, d, r, delete$, insert$ } from './internal/const';
export { deleteStringNotMatch, secondTooLong, stateTooShort, secondTooShort, stateTooLong, } from './internal/error';
export { toDownOperation, toUpOperation, toUnit as serializeTwoWayOperation, ofUnit as deserizalizeTwoWayOperation, diff as diff, transform as transformTwoWayOperation, } from './internal/operation/twoWayOperation';
export { apply, applyAndRestore, invert as invertUpOperation, compose as composeUpOperation, toUnit as serializeUpOperation, ofUnit as deserializeUpOperation, transform as transformUpOperation, } from './internal/operation/upOperation';
export { applyBack, applyBackAndRestore, invert as invertDownOperation, compose as composeDownOperation, toUnit as serializeDownOperation, ofUnit as deserializeDownOperation, } from './internal/operation/downOperation';
export { OperationBuilder } from './internal/operationBuilder/operationBuilder';

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

import { PositiveInt } from './positiveInt';
import { PositiveInt } from '@kizahasi/ot-core';
export class NonEmptyString {

@@ -3,0 +3,0 @@ constructor(source) {

import { Result } from '@kizahasi/result';
import { r, i, d, insert$, delete$, retain } from '../const';
import { invertCore, composeCore } from '../core';
import { r, i, d, insert$, delete$, retain, invert as invertCore, compose as composeCore, OperationBuilder, PositiveInt, } from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { downFactory } from '../operationBuilder/operationBuilderFactory';
import { OperationBuilder } from '../operationBuilder/operationBuilder';
import * as TextUpOperation from './upOperation';
import { downFactory } from '../operationBuilderFactory';
export const applyBack = ({ nextState, downOperation, }) => {

@@ -10,0 +7,0 @@ return TextUpOperation.apply({

import { Result } from '@kizahasi/result';
import { diff_match_patch } from 'diff-match-patch';
import { r, i, d, insert$, delete$, retain } from '../const';
import { transformCore } from '../core';
import { r, i, d, insert$, delete$, retain, transform as transformCore, PositiveInt, OperationBuilder, mapOperation, } from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { twoWayFactory } from '../operationBuilder/operationBuilderFactory';
import { mapOperation } from '../operationBuilder/operation';
import { OperationBuilder } from '../operationBuilder/operationBuilder';
import { twoWayFactory } from '../operationBuilderFactory';
export const diff = ({ prevState, nextState, }) => {

@@ -11,0 +7,0 @@ const builder = new OperationBuilder(twoWayFactory);

import { Option } from '@kizahasi/option';
import { Result } from '@kizahasi/result';
import { r, i, d, insert$, delete$, retain } from '../const';
import { composeCore, transformCore, invertCore, applyAndRestoreCore } from '../core';
import { r, i, d, insert$, delete$, retain, applyAndRestore as applyAndRestoreCore, compose as composeCore, transform as transformCore, invert as invertCore, PositiveInt, OperationBuilder, } from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { upFactory, twoWayFactory } from '../operationBuilder/operationBuilderFactory';
import { OperationBuilder } from '../operationBuilder/operationBuilder';
import { twoWayFactory, upFactory } from '../operationBuilderFactory';
const insertOrReplace = {
insert: ({ state, start, replacement }) => {
var _a, _b;
return {
newState: state.substring(0, start) +
((_b = (_a = replacement.value) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '') +
state.substring(start),
};
},
replace: ({ state, start, deleteCount, replacement }) => {
var _a, _b;
const deleted = state.substring(start, start + deleteCount.value);
return {
newState: state.substring(0, start) +
((_b = (_a = replacement.value) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '') +
state.substring(start + deleteCount.value),
deleted: new NonEmptyString(deleted),
};
},
};
export const apply = ({ prevState, upOperation, }) => {
const result = applyAndRestoreCore({
...insertOrReplace,
state: prevState,
action: Array.from(new OperationBuilder(upFactory, upOperation).toIterable()),
getStateLength: state => state.length,
getInsertLength: insert => insert.length.value,
getDeleteLength: del => del,

@@ -23,4 +43,7 @@ mapping: () => Option.some(undefined),

const result = applyAndRestoreCore({
...insertOrReplace,
state: prevState,
action: Array.from(new OperationBuilder(upFactory, upOperation).toIterable()),
getStateLength: state => state.length,
getInsertLength: insert => insert.length.value,
getDeleteLength: del => del,

@@ -27,0 +50,0 @@ restoreOption: {

@@ -1,15 +0,3 @@

export { PositiveInt } from './internal/positiveInt';
export { NonEmptyString } from './internal/nonEmptyString';
export { i, d, r, delete$, insert$ } from './internal/const';
export {
deleteStringNotMatch,
secondTooLong,
stateTooShort,
ApplyError,
secondTooShort,
stateTooLong,
ComposeAndTransformError,
} from './internal/error';
export { Insert, Delete, Replace } from './internal/type';
export {
TwoWayOperation,

@@ -45,6 +33,1 @@ TwoWayOperationUnit,

} from './internal/operation/downOperation';
export { Operation } from './internal/operationBuilder/operation';
export { OperationArrayElement } from './internal/operationBuilder/operationArrayElement';
export { OperationBuilder } from './internal/operationBuilder/operationBuilder';
export { OperationBuilderFactory } from './internal/operationBuilder/operationBuilderFactory';
export { OperationUnit } from './internal/operationBuilder/operationUnit';

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

import { PositiveInt } from './positiveInt';
import { PositiveInt } from '@kizahasi/ot-core';

@@ -3,0 +3,0 @@ export class NonEmptyString {

import { Result } from '@kizahasi/result';
import { r, i, d, insert$, delete$, retain } from '../const';
import { invertCore, composeCore } from '../core';
import { ApplyError, ComposeAndTransformError } from '../error';
import {
r,
i,
d,
insert$,
delete$,
retain,
invert as invertCore,
compose as composeCore,
ComposeAndTransformError,
Operation,
OperationBuilder,
PositiveInt,
ApplyError,
} from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { downFactory } from '../operationBuilder/operationBuilderFactory';
import { Operation } from '../operationBuilder/operation';
import { OperationBuilder } from '../operationBuilder/operationBuilder';
import * as TextTwoWayOperation from './twoWayOperation';
import * as TextUpOperation from './upOperation';
import { downFactory } from '../operationBuilderFactory';

@@ -34,3 +43,3 @@ export type DownOperation = Operation<PositiveInt, NonEmptyString>;

downOperation: DownOperation;
}): Result<string, ApplyError<PositiveInt>> => {
}): Result<string, ApplyError<NonEmptyString, PositiveInt>> => {
return TextUpOperation.apply({

@@ -50,3 +59,3 @@ prevState: nextState,

{ prevState: string; restored: TextTwoWayOperation.TwoWayOperation },
ApplyError<PositiveInt>
ApplyError<NonEmptyString, PositiveInt>
> => {

@@ -53,0 +62,0 @@ const invertedResult = TextUpOperation.applyAndRestore({

import { Result } from '@kizahasi/result';
import { diff_match_patch } from 'diff-match-patch';
import { r, i, d, insert$, delete$, retain } from '../const';
import { transformCore } from '../core';
import { ComposeAndTransformError } from '../error';
import {
r,
i,
d,
insert$,
delete$,
retain,
ComposeAndTransformError,
transform as transformCore,
PositiveInt,
Operation,
OperationBuilder,
mapOperation,
} from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { twoWayFactory } from '../operationBuilder/operationBuilderFactory';
import { Operation, mapOperation } from '../operationBuilder/operation';
import { OperationBuilder } from '../operationBuilder/operationBuilder';
import { twoWayFactory } from '../operationBuilderFactory';

@@ -12,0 +20,0 @@ export type TwoWayOperation = Operation<NonEmptyString, NonEmptyString>;

import { Option } from '@kizahasi/option';
import { Result } from '@kizahasi/result';
import { r, i, d, insert$, delete$, retain } from '../const';
import { composeCore, transformCore, invertCore, applyAndRestoreCore } from '../core';
import { ApplyError, ComposeAndTransformError } from '../error';
import {
r,
i,
d,
insert$,
delete$,
retain,
applyAndRestore as applyAndRestoreCore,
compose as composeCore,
transform as transformCore,
invert as invertCore,
ComposeAndTransformError,
PositiveInt,
Operation,
OperationBuilder,
ApplyError,
} from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { upFactory, twoWayFactory } from '../operationBuilder/operationBuilderFactory';
import { Operation } from '../operationBuilder/operation';
import { OperationBuilder } from '../operationBuilder/operationBuilder';
import * as TextTwoWayOperation from './twoWayOperation';
import { twoWayFactory, upFactory } from '../operationBuilderFactory';

@@ -28,2 +39,27 @@ export type UpOperation = Operation<NonEmptyString, PositiveInt>;

type InsertOrReplace = Pick<
Parameters<typeof applyAndRestoreCore<string, NonEmptyString, NonEmptyString, undefined>>[0],
'insert' | 'replace'
>;
const insertOrReplace: InsertOrReplace = {
insert: ({ state, start, replacement }) => {
return {
newState:
state.substring(0, start) +
(replacement.value?.value ?? '') +
state.substring(start),
};
},
replace: ({ state, start, deleteCount, replacement }) => {
const deleted = state.substring(start, start + deleteCount.value);
return {
newState:
state.substring(0, start) +
(replacement.value?.value ?? '') +
state.substring(start + deleteCount.value),
deleted: new NonEmptyString(deleted),
};
},
};
export const apply = ({

@@ -35,6 +71,9 @@ prevState,

upOperation: UpOperation;
}): Result<string, ApplyError<PositiveInt>> => {
}): Result<string, ApplyError<NonEmptyString, PositiveInt>> => {
const result = applyAndRestoreCore({
...insertOrReplace,
state: prevState,
action: Array.from(new OperationBuilder(upFactory, upOperation).toIterable()),
getStateLength: state => state.length,
getInsertLength: insert => insert.length.value,
getDeleteLength: del => del,

@@ -57,7 +96,10 @@ mapping: () => Option.some(undefined),

{ nextState: string; restored: TextTwoWayOperation.TwoWayOperation },
ApplyError<PositiveInt>
ApplyError<NonEmptyString, PositiveInt>
> => {
const result = applyAndRestoreCore({
...insertOrReplace,
state: prevState,
action: Array.from(new OperationBuilder(upFactory, upOperation).toIterable()),
getStateLength: state => state.length,
getInsertLength: insert => insert.length.value,
getDeleteLength: del => del,

@@ -64,0 +106,0 @@ restoreOption: {

@@ -1,14 +0,5 @@

export { PositiveInt } from './internal/positiveInt';
export { NonEmptyString } from './internal/nonEmptyString';
export { i, d, r, delete$, insert$ } from './internal/const';
export { deleteStringNotMatch, secondTooLong, stateTooShort, ApplyError, secondTooShort, stateTooLong, ComposeAndTransformError, } from './internal/error';
export { Insert, Delete, Replace } from './internal/type';
export { TwoWayOperation, TwoWayOperationUnit, toDownOperation, toUpOperation, toUnit as serializeTwoWayOperation, ofUnit as deserizalizeTwoWayOperation, diff as diff, transform as transformTwoWayOperation, } from './internal/operation/twoWayOperation';
export { UpOperation, UpOperationUnit, apply, applyAndRestore, invert as invertUpOperation, compose as composeUpOperation, toUnit as serializeUpOperation, ofUnit as deserializeUpOperation, transform as transformUpOperation, } from './internal/operation/upOperation';
export { DownOperation, DownOperationUnit, applyBack, applyBackAndRestore, invert as invertDownOperation, compose as composeDownOperation, toUnit as serializeDownOperation, ofUnit as deserializeDownOperation, } from './internal/operation/downOperation';
export { Operation } from './internal/operationBuilder/operation';
export { OperationArrayElement } from './internal/operationBuilder/operationArrayElement';
export { OperationBuilder } from './internal/operationBuilder/operationBuilder';
export { OperationBuilderFactory } from './internal/operationBuilder/operationBuilderFactory';
export { OperationUnit } from './internal/operationBuilder/operationUnit';
//# sourceMappingURL=index.d.ts.map

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

import { PositiveInt } from './positiveInt';
import { PositiveInt } from '@kizahasi/ot-core';
export declare class NonEmptyString {

@@ -3,0 +3,0 @@ private source;

import { Result } from '@kizahasi/result';
import { r, i, d } from '../const';
import { ApplyError, ComposeAndTransformError } from '../error';
import { r, i, d, ComposeAndTransformError, Operation, PositiveInt, ApplyError } from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { Operation } from '../operationBuilder/operation';
import * as TextTwoWayOperation from './twoWayOperation';

@@ -22,3 +19,3 @@ export type DownOperation = Operation<PositiveInt, NonEmptyString>;

downOperation: DownOperation;
}) => Result<string, ApplyError<PositiveInt>>;
}) => Result<string, ApplyError<NonEmptyString, PositiveInt>>;
export declare const applyBackAndRestore: ({ nextState, downOperation, }: {

@@ -30,3 +27,3 @@ nextState: string;

restored: TextTwoWayOperation.TwoWayOperation;
}, ApplyError<PositiveInt>>;
}, ApplyError<NonEmptyString, PositiveInt>>;
export declare const compose: ({ first, second, }: {

@@ -33,0 +30,0 @@ first: DownOperation;

import { Result } from '@kizahasi/result';
import { r, i, d } from '../const';
import { ComposeAndTransformError } from '../error';
import { r, i, d, ComposeAndTransformError, PositiveInt, Operation } from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { Operation } from '../operationBuilder/operation';
export type TwoWayOperation = Operation<NonEmptyString, NonEmptyString>;

@@ -8,0 +5,0 @@ export type TwoWayOperationUnit = {

import { Result } from '@kizahasi/result';
import { r, i, d } from '../const';
import { ApplyError, ComposeAndTransformError } from '../error';
import { r, i, d, ComposeAndTransformError, PositiveInt, Operation, ApplyError } from '@kizahasi/ot-core';
import { NonEmptyString } from '../nonEmptyString';
import { PositiveInt } from '../positiveInt';
import { Operation } from '../operationBuilder/operation';
import * as TextTwoWayOperation from './twoWayOperation';

@@ -22,3 +19,3 @@ export type UpOperation = Operation<NonEmptyString, PositiveInt>;

upOperation: UpOperation;
}) => Result<string, ApplyError<PositiveInt>>;
}) => Result<string, ApplyError<NonEmptyString, PositiveInt>>;
export declare const applyAndRestore: ({ prevState, upOperation, }: {

@@ -30,3 +27,3 @@ prevState: string;

restored: TextTwoWayOperation.TwoWayOperation;
}, ApplyError<PositiveInt>>;
}, ApplyError<NonEmptyString, PositiveInt>>;
export declare const compose: ({ first, second, }: {

@@ -33,0 +30,0 @@ first: UpOperation;

{
"version": "0.5.1",
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"typings": "dist/types/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=14"
},
"packageManager": "pnpm@8.2.0",
"scripts": {
"build": "rimraf ./dist && copyfiles \"./src/**/*.ts\" ./dist && tsc -p tsconfig.build-cjs.json && tsc -p tsconfig.build-esm.json && tsc -p tsconfig.build-types.json",
"test": "jest",
"prepare": "husky install",
"lint": "eslint src test",
"prettier": "pnpm prettier:base --write",
"prettier:base": "prettier \"**/*.{ts,js,json,yml,md}\""
},
"prettier": {
"printWidth": 100,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 4,
"arrowParens": "avoid"
},
"name": "@kizahasi/ot-string",
"author": "kizahasi",
"repository": {
"type": "git",
"url": "https://github.com/kizahasi/ot-string"
},
"description": "Operational Transfomation library for string",
"keywords": [
"operational transformation",
"operational transform",
"ot"
],
"sideEffects": false,
"devDependencies": {
"@commitlint/cli": "17.3.0",
"@commitlint/config-conventional": "17.3.0",
"@types/diff-match-patch": "1.0.32",
"@types/jest": "29.2.5",
"@typescript-eslint/eslint-plugin": "5.45.0",
"@typescript-eslint/parser": "5.45.0",
"copyfiles": "2.4.1",
"eslint": "8.28.0",
"eslint-config-prettier": "8.5.0",
"fast-check": "3.4.0",
"husky": "8.0.3",
"jest": "29.3.1",
"prettier": "2.8.7",
"rimraf": "3.0.2",
"ts-jest": "29.1.0",
"typescript": "4.9.5"
},
"dependencies": {
"@kizahasi/option": "^1.0.0",
"@kizahasi/result": "^1.0.0",
"diff-match-patch": "^1.0.5"
}
}
"name": "@kizahasi/ot-string",
"version": "0.6.0-beta.1",
"description": "Operational Transfomation library for string",
"keywords": [
"operational transformation",
"operational transform",
"ot"
],
"repository": {
"type": "git",
"url": "https://github.com/kizahasi/ot-string"
},
"license": "MIT",
"author": "kizahasi",
"sideEffects": false,
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"typings": "dist/types/index.d.ts",
"files": [
"dist"
],
"dependencies": {
"@kizahasi/option": "^1.0.0",
"@kizahasi/result": "^1.0.0",
"diff-match-patch": "^1.0.5",
"@kizahasi/ot-core": "^0.1.0-beta.1"
},
"devDependencies": {
"@types/diff-match-patch": "1.0.32",
"@types/jest": "29.2.5",
"copyfiles": "2.4.1",
"fast-check": "3.4.0",
"jest": "29.3.1",
"rimraf": "3.0.2",
"ts-jest": "29.1.0",
"typescript": "4.9.5"
},
"scripts": {
"build": "rimraf ./dist && copyfiles \"./src/**/*.ts\" ./dist && tsc -p tsconfig.build-cjs.json && tsc -p tsconfig.build-esm.json && tsc -p tsconfig.build-types.json",
"test": "jest"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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