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

mendoza

Package Overview
Dependencies
Maintainers
37
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mendoza - npm Package Compare versions

Comparing version 3.0.1-canary.7 to 3.0.1

70

dist/index.js

@@ -12,2 +12,3 @@ var __defProp$1 = Object.defineProperty;

};
const OPS = ["Value", "Copy", "Blank", "ReturnIntoArray", "ReturnIntoObject", "ReturnIntoObjectSameKey", "PushField", "PushElement", "PushParent", "Pop", "PushFieldCopy", "PushFieldBlank", "PushElementCopy", "PushElementBlank", "ReturnIntoObjectPop", "ReturnIntoObjectSameKeyPop", "ReturnIntoArrayPop", "ObjectSetFieldValue", "ObjectCopyField", "ObjectDeleteField", "ArrayAppendValue", "ArrayAppendSlice", "StringAppendString", "StringAppendSlice"];
class Patcher {

@@ -18,13 +19,8 @@ constructor(model, root, patch) {

__publicField$1(this, "patch");
__publicField$1(this, "i");
__publicField$1(this, "inputStack");
__publicField$1(this, "outputStack");
__publicField$1(this, "ops");
__publicField$1(this, "i", 0);
__publicField$1(this, "inputStack", []);
__publicField$1(this, "outputStack", []);
this.model = model;
this.root = root;
this.patch = patch;
this.i = 0;
this.inputStack = [];
this.outputStack = [];
this.ops = [this.processValue, this.processCopy, this.processBlank, this.processReturnIntoArray, this.processReturnIntoObject, this.processReturnIntoObjectSameKey, this.processPushField, this.processPushElement, this.processPushParent, this.processPop, this.processPushFieldCopy, this.processPushFieldBlank, this.processPushElementCopy, this.processPushElementBlank, this.processReturnIntoObjectPop, this.processReturnIntoObjectSameKeyPop, this.processReturnIntoArrayPop, this.processObjectSetFieldValue, this.processObjectCopyField, this.processObjectDeleteField, this.processArrayAppendValue, this.processArrayAppendSlice, this.processStringAppendString, this.processStringAppendSlice];
}

@@ -43,7 +39,6 @@ read() {

let opcode = this.read();
let op = this.ops[opcode];
if (!op) {
throw new Error("Unknown opcode: ".concat(opcode));
}
op.apply(this);
let op = OPS[opcode];
if (!op) throw new Error("Unknown opcode: ".concat(opcode));
let processor = "process".concat(op);
this[processor].apply(this);
}

@@ -142,5 +137,2 @@ let entry = this.outputStack.pop();

}
processPushParent() {
throw new Error("not implemented");
}
processPushElement() {

@@ -298,3 +290,3 @@ let idx = this.read();

};
let Model$1 = class Model {
class IncrementalModel {
constructor(meta) {

@@ -532,3 +524,3 @@ __publicField(this, "meta");

}
};
}
function wrap(data, meta) {

@@ -573,4 +565,4 @@ return {

if (leftType !== rightType) return right;
let leftModel = new Model$1(left.endMeta);
let rightModel = new Model$1(right.endMeta);
let leftModel = new IncrementalModel(left.endMeta);
let rightModel = new IncrementalModel(right.endMeta);
switch (leftType) {

@@ -646,3 +638,3 @@ case "object":

function applyPatch$1(left, patch, startMeta) {
let model = new Model$1(startMeta);
let model = new IncrementalModel(startMeta);
let patcher = new Patcher(model, left, patch);

@@ -659,6 +651,6 @@ return patcher.process();

});
class Model {
const SimpleModel = {
wrap(data) {
return data;
}
},
finalize(b) {

@@ -670,15 +662,15 @@ if (Array.isArray(b)) {

}
}
},
markChanged(value) {
return value;
}
},
objectGetKeys(value) {
return Object.keys(value);
}
},
objectGetField(value, key) {
return value[key];
}
},
arrayGetElement(value, idx) {
return value[idx];
}
},
copyObject(value) {

@@ -695,7 +687,7 @@ let res = {

return res;
}
},
copyArray(value) {
if (value === null) return [];
return value.slice();
}
},
copyString(value) {

@@ -706,15 +698,15 @@ return {

};
}
},
objectSetField(target, key, value) {
target.data[key] = value;
}
},
objectDeleteField(target, key) {
delete target.data[key];
}
},
arrayAppendValue(target, value) {
target.push(value);
}
},
arrayAppendSlice(target, source, left, right) {
target.push(...source.slice(left, right));
}
},
stringAppendSlice(target, source, left, right) {

@@ -725,12 +717,10 @@ const sourceString = source;

target.data += sourceString.slice(leftPos, rightPos);
}
},
stringAppendValue(target, value) {
target.data += value;
}
}
let model;
};
function applyPatch(left, patch) {
let root = left;
if (!model) model = new Model();
let patcher = new Patcher(model, root, patch);
let patcher = new Patcher(SimpleModel, root, patch);
return patcher.process();

@@ -737,0 +727,0 @@ }

{
"name": "mendoza",
"version": "3.0.1-canary.7",
"version": "3.0.1",
"description": "Mendoza, differ for structured documents",

@@ -74,3 +74,3 @@ "keywords": [

"prettier-plugin-packagejson": "^2.4.5",
"rimraf": "^3.0.2",
"rimraf": "^4.4.1",
"semantic-release": "^21.0.7",

@@ -77,0 +77,0 @@ "typescript": "^5.1.6",

@@ -44,6 +44,6 @@ import {Patcher} from './internal-patcher'

class Model<T>
class IncrementalModel<T>
implements ObjectModel<Value<T>, StringContent<T>, ObjectContent<T>, ArrayContent<T>>
{
meta: T
private meta: T

@@ -366,4 +366,4 @@ constructor(meta: T) {

let leftModel = new Model(left.endMeta)
let rightModel = new Model(right.endMeta)
let leftModel = new IncrementalModel(left.endMeta)
let rightModel = new IncrementalModel(right.endMeta)

@@ -448,5 +448,5 @@ switch (leftType) {

export function applyPatch<T>(left: Value<T>, patch: RawPatch, startMeta: T) {
let model = new Model(startMeta)
let model = new IncrementalModel(startMeta)
let patcher = new Patcher(model, left, patch)
return patcher.process()
}
import {ObjectModel} from './object-model'
import {RawPatch} from './patch'
const OPS = [
'Value',
'Copy',
'Blank',
'ReturnIntoArray',
'ReturnIntoObject',
'ReturnIntoObjectSameKey',
'PushField',
'PushElement',
'PushParent',
'Pop',
'PushFieldCopy',
'PushFieldBlank',
'PushElementCopy',
'PushElementBlank',
'ReturnIntoObjectPop',
'ReturnIntoObjectSameKeyPop',
'ReturnIntoArrayPop',
'ObjectSetFieldValue',
'ObjectCopyField',
'ObjectDeleteField',
'ArrayAppendValue',
'ArrayAppendSlice',
'StringAppendString',
'StringAppendSlice',
]
type InputEntry<V> = {

@@ -16,9 +43,8 @@ value: V

export class Patcher<V, S, O, A> {
model: ObjectModel<V, S, O, A>
root: V
patch: RawPatch
i: number
inputStack: InputEntry<V>[]
outputStack: OutputEntry<V, S, O, A>[]
ops: ((this: Patcher<V, S, O, A>) => void)[]
private model: ObjectModel<V, S, O, A>
private root: V
private patch: RawPatch
private i = 0
private inputStack: InputEntry<V>[] = []
private outputStack: OutputEntry<V, S, O, A>[] = []

@@ -29,31 +55,2 @@ constructor(model: ObjectModel<V, S, O, A>, root: V, patch: RawPatch) {

this.patch = patch
this.i = 0
this.inputStack = []
this.outputStack = []
this.ops = [
this.processValue,
this.processCopy,
this.processBlank,
this.processReturnIntoArray,
this.processReturnIntoObject,
this.processReturnIntoObjectSameKey,
this.processPushField,
this.processPushElement,
this.processPushParent,
this.processPop,
this.processPushFieldCopy,
this.processPushFieldBlank,
this.processPushElementCopy,
this.processPushElementBlank,
this.processReturnIntoObjectPop,
this.processReturnIntoObjectSameKeyPop,
this.processReturnIntoArrayPop,
this.processObjectSetFieldValue,
this.processObjectCopyField,
this.processObjectDeleteField,
this.processArrayAppendValue,
this.processArrayAppendSlice,
this.processStringAppendString,
this.processStringAppendSlice,
]
}

@@ -71,7 +68,6 @@

let opcode = this.read() as number
let op = this.ops[opcode]
if (!op) {
throw new Error(`Unknown opcode: ${opcode}`)
}
op.apply(this)
let op = OPS[opcode]
if (!op) throw new Error(`Unknown opcode: ${opcode}`)
let processor = `process${op}`
;(this as any)[processor].apply(this)
}

@@ -185,6 +181,2 @@

processPushParent() {
throw new Error('not implemented')
}
processPushElement() {

@@ -191,0 +183,0 @@ let idx = this.read() as number

@@ -10,6 +10,6 @@ import {Patcher} from './internal-patcher'

class Model implements ObjectModel<unknown, StringBuilder, ObjectBuilder, ArrayBuilder> {
const SimpleModel: ObjectModel<unknown, StringBuilder, ObjectBuilder, ArrayBuilder> = {
wrap(data: any): unknown {
return data
}
},

@@ -22,19 +22,19 @@ finalize(b: StringBuilder | ObjectBuilder | ArrayBuilder): unknown {

}
}
},
markChanged(value: unknown): unknown {
markChanged(value) {
return value
}
},
objectGetKeys(value: unknown): string[] {
return Object.keys(value as any)
}
},
objectGetField(value: unknown, key: string): unknown {
return (value as any)[key]
}
},
arrayGetElement(value: unknown, idx: number): unknown {
return (value as any[])[idx]
}
},

@@ -52,3 +52,3 @@ copyObject(value: unknown | null): ObjectBuilder {

return res
}
},

@@ -58,3 +58,3 @@ copyArray(value: unknown | null): ArrayBuilder {

return (value as ArrayBuilder).slice()
}
},

@@ -66,19 +66,19 @@ copyString(value: unknown | null): StringBuilder {

}
}
},
objectSetField(target: ObjectBuilder, key: string, value: unknown): void {
target.data[key] = value
}
},
objectDeleteField(target: ObjectBuilder, key: string): void {
delete target.data[key]
}
},
arrayAppendValue(target: ArrayBuilder, value: unknown): void {
target.push(value)
}
},
arrayAppendSlice(target: ArrayBuilder, source: unknown, left: number, right: number): void {
target.push(...(source as ArrayBuilder).slice(left, right))
}
},

@@ -92,19 +92,14 @@ stringAppendSlice(target: StringBuilder, source: unknown, left: number, right: number): void {

target.data += sourceString.slice(leftPos, rightPos)
}
},
stringAppendValue(target: StringBuilder, value: unknown): void {
target.data += value as string
}
},
}
let model: Model
// Applies a patch on a JavaScript object.
export function applyPatch(left: any, patch: RawPatch): any {
// No need to wrap because the representation is the same.
let root = left
// Reuse the same model instance
if (!model) model = new Model()
let patcher = new Patcher(model, root, patch)
let root = left // No need to wrap because the representation is the same.
let patcher = new Patcher(SimpleModel, root, patch)
return patcher.process()
}

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