New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hadron-document

Package Overview
Dependencies
Maintainers
0
Versions
546
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hadron-document - npm Package Compare versions

Comparing version 0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a to 0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723

29

dist/document.d.ts

@@ -9,3 +9,11 @@ import type { Element } from './element';

Cancel: string;
Expanded: string;
Collapsed: string;
VisibleElementsChanged: string;
EditingStarted: string;
EditingFinished: string;
MarkedForDeletion: string;
DeletionFinished: string;
};
export declare const DEFAULT_VISIBLE_ELEMENTS = 25;
export declare class Document extends EventEmitter {

@@ -19,2 +27,7 @@ uuid: string;

currentType: 'Document';
size: number | null;
expanded: boolean;
maxVisibleElementsCount: number;
editing: boolean;
markedForDeletion: boolean;
cancel(): void;

@@ -50,4 +63,20 @@ constructor(doc: BSONObject, cloned?: boolean);

toEJSON(source?: 'original' | 'current', options?: HadronEJSONOptions): string;
expand(): void;
collapse(): void;
getVisibleElements(): Element[];
setMaxVisibleElementsCount(newCount: number): void;
getTotalVisibleElementsCount(): number;
startEditing(elementId?: string, field?: 'key' | 'value' | 'type'): void;
finishEditing(): void;
onUpdateStart(): void;
onUpdateSuccess(doc: Record<string, unknown>): void;
onUpdateBlocked(): void;
onUpdateError(error: Error): void;
markForDeletion(): void;
finishDeletion(): void;
onRemoveStart(): void;
onRemoveSuccess(): void;
onRemoveError(error: Error): void;
}
export default Document;
//# sourceMappingURL=document.d.ts.map

111

dist/document.js

@@ -6,3 +6,3 @@ 'use strict';

Object.defineProperty(exports, "__esModule", { value: true });
exports.Document = exports.Events = void 0;
exports.Document = exports.DEFAULT_VISIBLE_ELEMENTS = exports.Events = void 0;
const element_1 = require("./element");

@@ -13,9 +13,29 @@ const eventemitter3_1 = __importDefault(require("eventemitter3"));

const utils_1 = require("./utils");
const _1 = require(".");
exports.Events = {
Cancel: 'Document::Cancel',
Expanded: 'Document::Expanded',
Collapsed: 'Document::Collapsed',
VisibleElementsChanged: 'Document::VisibleElementsChanged',
EditingStarted: 'Document::EditingStarted',
EditingFinished: 'Document::EditingFinished',
MarkedForDeletion: 'Document::MarkedForDeletion',
DeletionFinished: 'Document::DeletionFinished',
};
const ID = '_id';
exports.DEFAULT_VISIBLE_ELEMENTS = 25;
class Document extends eventemitter3_1.default {
cancel() {
for (const element of Array.from(this.elements)) {
element.cancel();
}
this.emit(exports.Events.Cancel);
}
constructor(doc, cloned = false) {
super();
this.size = null;
this.expanded = false;
this.maxVisibleElementsCount = exports.DEFAULT_VISIBLE_ELEMENTS;
this.editing = false;
this.markedForDeletion = false;
this.uuid = new bson_1.UUID().toHexString();

@@ -29,10 +49,4 @@ this.doc = doc;

}
cancel() {
for (const element of Array.from(this.elements)) {
element.cancel();
}
this.emit(exports.Events.Cancel);
}
apply(doc) {
if (typeof (doc === null || doc === void 0 ? void 0 : doc.generateObject) === 'function') {
if (typeof doc?.generateObject === 'function') {
doc = doc.generateObject();

@@ -124,2 +138,3 @@ }

newElement._bubbleUp(element_1.Events.Added, newElement, this);
this.emit(exports.Events.VisibleElementsChanged, this);
return newElement;

@@ -130,2 +145,3 @@ }

newElement._bubbleUp(element_1.Events.Added, newElement, this);
this.emit(exports.Events.VisibleElementsChanged, this);
return newElement;

@@ -135,3 +151,4 @@ }

const newElement = this.elements.insertAfter(element, key, value);
newElement === null || newElement === void 0 ? void 0 : newElement._bubbleUp(element_1.Events.Added, newElement, this);
newElement?._bubbleUp(element_1.Events.Added, newElement, this);
this.emit(exports.Events.VisibleElementsChanged, this);
return newElement;

@@ -178,2 +195,78 @@ }

}
expand() {
this.expanded = true;
for (const element of this.elements) {
element.expand(true);
}
this.emit(exports.Events.Expanded);
this.emit(exports.Events.VisibleElementsChanged, this);
}
collapse() {
this.expanded = false;
for (const element of this.elements) {
element.collapse();
}
this.emit(exports.Events.Collapsed);
this.emit(exports.Events.VisibleElementsChanged, this);
}
getVisibleElements() {
return [...this.elements].slice(0, this.maxVisibleElementsCount);
}
setMaxVisibleElementsCount(newCount) {
this.maxVisibleElementsCount = newCount;
this.emit(exports.Events.VisibleElementsChanged, this);
}
getTotalVisibleElementsCount() {
const visibleElements = this.getVisibleElements();
return visibleElements.reduce((totalVisibleChildElements, element) => {
return (totalVisibleChildElements + 1 + element.getTotalVisibleElementsCount());
}, 0);
}
startEditing(elementId, field) {
if (!this.editing) {
this.editing = true;
this.emit(_1.DocumentEvents.EditingStarted, elementId, field);
}
}
finishEditing() {
if (this.editing) {
this.editing = false;
this.emit(_1.DocumentEvents.EditingFinished);
}
}
onUpdateStart() {
this.emit('update-start');
}
onUpdateSuccess(doc) {
this.emit('update-success', doc);
this.finishEditing();
}
onUpdateBlocked() {
this.emit('update-blocked');
}
onUpdateError(error) {
this.emit('update-error', error.message);
}
markForDeletion() {
if (!this.markedForDeletion) {
this.markedForDeletion = true;
this.emit(_1.DocumentEvents.MarkedForDeletion);
}
}
finishDeletion() {
if (this.markedForDeletion) {
this.markedForDeletion = false;
this.emit(_1.DocumentEvents.DeletionFinished);
}
}
onRemoveStart() {
this.emit('remove-start');
}
onRemoveSuccess() {
this.emit('remove-success');
this.finishDeletion();
}
onRemoveError(error) {
this.emit('remove-error', error.message);
}
}

@@ -180,0 +273,0 @@ exports.Document = Document;

10

dist/editor/date.js

@@ -59,5 +59,9 @@ "use strict";

_formattedValue() {
return new Date(this.element.currentValue)
.toISOString()
.replace('Z', '+00:00');
const date = new Date(this.element.currentValue);
try {
return date.toISOString().replace('Z', '+00:00');
}
catch {
return String(date);
}
}

@@ -64,0 +68,0 @@ }

@@ -36,4 +36,4 @@ import StandardEditor from './standard';

export default _default;
export declare type Editor = DateEditor | StandardEditor | StringEditor | Decimal128Editor | DoubleEditor | Int32Editor | Int64Editor | NullEditor | UndefinedEditor | ObjectIdEditor;
export type Editor = DateEditor | StandardEditor | StringEditor | Decimal128Editor | DoubleEditor | Int32Editor | Int64Editor | NullEditor | UndefinedEditor | ObjectIdEditor;
export { DateEditor, StandardEditor, StringEditor, Decimal128Editor, DoubleEditor, Int32Editor, Int64Editor, NullEditor, UndefinedEditor, ObjectIdEditor, };
//# sourceMappingURL=index.d.ts.map

@@ -9,4 +9,7 @@ declare const _default: {

readonly Valid: "Element::Valid";
readonly Expanded: "Element::Expanded";
readonly Collapsed: "Element::Collapsed";
readonly VisibleElementsChanged: "Element::VisibleElementsChanged";
};
export default _default;
//# sourceMappingURL=element-events.d.ts.map

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

Valid: 'Element::Valid',
Expanded: 'Element::Expanded',
Collapsed: 'Element::Collapsed',
VisibleElementsChanged: 'Element::VisibleElementsChanged',
};
//# sourceMappingURL=element-events.js.map

@@ -11,2 +11,4 @@ import EventEmitter from 'eventemitter3';

export declare function isInternalFieldPath(path: string | number): boolean;
export declare const DEFAULT_VISIBLE_ELEMENTS = 25;
export declare function isValueExpandable(value: BSONValue): value is BSONObject | BSONArray;
export declare class Element extends EventEmitter {

@@ -29,2 +31,4 @@ uuid: string;

decrypted: boolean;
expanded: boolean;
maxVisibleElementsCount: number;
cancel(): void;

@@ -56,2 +60,3 @@ constructor(key: string | number, value: BSONValue | number, parent?: Element | Document | null, added?: boolean);

_isObjectIdEqual(): boolean;
_isExpandable(): boolean;
isLast(): boolean;

@@ -76,2 +81,4 @@ isRenamed(): boolean;

revert(): void;
expand(expandChildren?: boolean): void;
collapse(): void;
_bubbleUp(evt: typeof Events[keyof typeof Events], ...data: BSONArray): void;

@@ -81,5 +88,8 @@ _convertToEmptyObject(): void;

_isElementEmpty(element: Element | undefined | null): boolean;
_isExpandable(value: BSONValue): value is BSONObject | BSONArray;
_generateElements(object: BSONObject | BSONArray): ElementList;
_removeAddedElements(): void;
getVisibleElements(): Element[];
setMaxVisibleElementsCount(newCount: number): void;
getTotalVisibleElementsCount(): number;
private emitVisibleElementsChanged;
static get Events(): typeof ElementEvents;

@@ -95,2 +105,4 @@ }

get(key: string | number): Element | undefined;
some(predicate: (value: Element, index: number, array: Element[]) => unknown): boolean;
every(predicate: (value: Element, index: number, array: Element[]) => unknown): boolean;
get firstElement(): Element | undefined;

@@ -97,0 +109,0 @@ get lastElement(): Element | undefined;

@@ -6,8 +6,5 @@ 'use strict';

Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementList = exports.Element = exports.isInternalFieldPath = exports.Events = exports.DATE_FORMAT = void 0;
exports.ElementList = exports.Element = exports.isValueExpandable = exports.DEFAULT_VISIBLE_ELEMENTS = exports.isInternalFieldPath = exports.Events = exports.DATE_FORMAT = void 0;
const eventemitter3_1 = __importDefault(require("eventemitter3"));
const lodash_isplainobject_1 = __importDefault(require("lodash.isplainobject"));
const lodash_isarray_1 = __importDefault(require("lodash.isarray"));
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
const lodash_isstring_1 = __importDefault(require("lodash.isstring"));
const lodash_1 = require("lodash");
const object_generator_1 = __importDefault(require("./object-generator"));

@@ -38,5 +35,22 @@ const hadron_type_checker_1 = __importDefault(require("hadron-type-checker"));

];
exports.DEFAULT_VISIBLE_ELEMENTS = 25;
function isValueExpandable(value) {
return (0, lodash_1.isPlainObject)(value) || (0, lodash_1.isArray)(value);
}
exports.isValueExpandable = isValueExpandable;
class Element extends eventemitter3_1.default {
cancel() {
if (this.elements) {
for (const element of Array.from(this.elements)) {
element.cancel();
}
}
if (this.isModified()) {
this.revert();
}
}
constructor(key, value, parent = null, added = false) {
super();
this.expanded = false;
this.maxVisibleElementsCount = exports.DEFAULT_VISIBLE_ELEMENTS;
this.uuid = new bson_1.UUID().toHexString();

@@ -55,3 +69,3 @@ this.key = key;

}
if (this._isExpandable(value)) {
if (isValueExpandable(value)) {
this.originalExpandableValue = value;

@@ -75,19 +89,7 @@ this.elements = this._generateElements(value);

}
cancel() {
if (this.elements) {
for (const element of Array.from(this.elements)) {
element.cancel();
}
}
if (this.isModified()) {
this.revert();
}
}
get nextElement() {
var _a, _b;
return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.findNext(this);
return this.parent?.elements?.findNext(this);
}
get previousElement() {
var _a, _b;
return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.findPrevious(this);
return this.parent?.elements?.findPrevious(this);
}

@@ -105,7 +107,7 @@ _getLevel() {

this.currentType = hadron_type_checker_1.default.type(value);
if (this._isExpandable(value) && !this._isExpandable(this.currentValue)) {
if (isValueExpandable(value) && !isValueExpandable(this.currentValue)) {
this.currentValue = null;
this.elements = this._generateElements(value);
}
else if (!this._isExpandable(value) && this.elements) {
else if (!isValueExpandable(value) && this.elements) {
this.currentValue = value;

@@ -145,3 +147,3 @@ this.elements = undefined;

let parent = this.parent;
while (parent === null || parent === void 0 ? void 0 : parent.parent) {
while (parent?.parent) {
parent = parent.parent;

@@ -152,8 +154,6 @@ }

get(key) {
var _a;
return (_a = this.elements) === null || _a === void 0 ? void 0 : _a.get(key);
return this.elements?.get(key);
}
at(i) {
var _a;
return (_a = this.elements) === null || _a === void 0 ? void 0 : _a.at(i);
return this.elements?.at(i);
}

@@ -190,2 +190,3 @@ rename(key) {

newElement._bubbleUp(element_events_1.default.Added, newElement, this);
this.emitVisibleElementsChanged();
return newElement;

@@ -199,8 +200,8 @@ }

this._bubbleUp(element_events_1.default.Added, newElement);
this.emitVisibleElementsChanged();
return newElement;
}
insertPlaceholder() {
var _a, _b;
const placeholderValue = this.currentType === 'Array' && ((_a = this.elements) === null || _a === void 0 ? void 0 : _a.lastElement)
? (0, utils_1.getDefaultValueForType)((_b = this.elements) === null || _b === void 0 ? void 0 : _b.lastElement.currentType)
const placeholderValue = this.currentType === 'Array' && this.elements?.lastElement
? (0, utils_1.getDefaultValueForType)(this.elements?.lastElement.currentType)
: '';

@@ -210,4 +211,3 @@ return this.insertEnd('', placeholderValue);

insertSiblingPlaceholder() {
var _a;
const placeholderValue = ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.currentType) === 'Array'
const placeholderValue = this.parent?.currentType === 'Array'
? (0, utils_1.getDefaultValueForType)(this.currentType)

@@ -218,4 +218,3 @@ : '';

isAdded() {
var _a;
return this.added || !!((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isAdded());
return this.added || !!this.parent?.isAdded();
}

@@ -241,7 +240,6 @@ isBlank() {

isDuplicateKey(value) {
var _a, _b;
if (value === '') {
return false;
}
for (const element of (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : []) {
for (const element of this.parent?.elements ?? []) {
if (element.uuid !== this.uuid && element.currentKey === value) {

@@ -260,9 +258,9 @@ return true;

_valuesEqual() {
if (this.currentType === 'Date' && (0, lodash_isstring_1.default)(this.currentValue)) {
return (0, lodash_isequal_1.default)(this.value, new Date(this.currentValue));
if (this.currentType === 'Date' && (0, lodash_1.isString)(this.currentValue)) {
return (0, lodash_1.isEqual)(this.value, new Date(this.currentValue));
}
else if (this.currentType === 'ObjectId' && (0, lodash_isstring_1.default)(this.currentValue)) {
else if (this.currentType === 'ObjectId' && (0, lodash_1.isString)(this.currentValue)) {
return this._isObjectIdEqual();
}
return (0, lodash_isequal_1.default)(this.value, this.currentValue);
return (0, lodash_1.isEqual)(this.value, this.currentValue);
}

@@ -277,5 +275,7 @@ _isObjectIdEqual() {

}
_isExpandable() {
return this.currentType === 'Array' || this.currentType === 'Object';
}
isLast() {
var _a, _b;
return ((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.lastElement) === this;
return this.parent?.elements?.lastElement === this;
}

@@ -328,6 +328,5 @@ isRenamed() {

_isKeyLegallyEditable() {
var _a;
return (this.isParentEditable() &&
(this.isAdded() ||
((this.currentKey !== ID || !((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isRoot())) &&
((this.currentKey !== ID || !this.parent?.isRoot()) &&
!this.isInternalField())));

@@ -381,2 +380,3 @@ }

this._bubbleUp(element_events_1.default.Removed, this, this.parent);
this.emitVisibleElementsChanged(this.parent);
}

@@ -386,4 +386,7 @@ }

if (this.isAdded()) {
this.parent.elements.remove(this);
this.parent?.elements?.remove(this);
this._bubbleUp(element_events_1.default.Removed, this, this.parent);
if (this.parent) {
this.emitVisibleElementsChanged(this.parent);
}
delete this.parent;

@@ -412,2 +415,28 @@ }

}
expand(expandChildren = false) {
if (!this._isExpandable()) {
return;
}
this.expanded = true;
if (expandChildren && this.elements) {
for (const element of this.elements) {
element.expand(expandChildren);
}
}
this.emit(_1.ElementEvents.Expanded, this);
this.emitVisibleElementsChanged();
}
collapse() {
if (!this._isExpandable()) {
return;
}
this.expanded = false;
if (this.elements) {
for (const element of this.elements) {
element.collapse();
}
}
this.emit(_1.ElementEvents.Collapsed, this);
this.emitVisibleElementsChanged();
}
_bubbleUp(evt, ...data) {

@@ -436,5 +465,2 @@ this.emit(evt, ...data);

}
_isExpandable(value) {
return (0, lodash_isplainobject_1.default)(value) || (0, lodash_isarray_1.default)(value);
}
_generateElements(object) {

@@ -452,2 +478,31 @@ return new ElementList(this, object);

}
getVisibleElements() {
if (!this.elements || !this.expanded) {
return [];
}
return [...this.elements].slice(0, this.maxVisibleElementsCount);
}
setMaxVisibleElementsCount(newCount) {
if (!this._isExpandable()) {
return;
}
this.maxVisibleElementsCount = newCount;
this.emitVisibleElementsChanged();
}
getTotalVisibleElementsCount() {
if (!this.elements || !this.expanded) {
return 0;
}
return this.getVisibleElements().reduce((totalVisibleChildElements, element) => {
return (totalVisibleChildElements + 1 + element.getTotalVisibleElementsCount());
}, 0);
}
emitVisibleElementsChanged(targetElement = this) {
if (targetElement.isRoot()) {
targetElement.emit(_1.DocumentEvents.VisibleElementsChanged, targetElement);
}
else if (targetElement.expanded) {
targetElement._bubbleUp(element_events_1.default.VisibleElementsChanged, targetElement, targetElement.getRoot());
}
}
static get Events() {

@@ -461,3 +516,3 @@ return _1.ElementEvents;

this.parent = parent;
this.elements = Object.entries(originalDoc !== null && originalDoc !== void 0 ? originalDoc : {}).map(([k, v]) => {
this.elements = Object.entries(originalDoc ?? {}).map(([k, v]) => {
return new Element(this.isArray() ? parseInt(k, 10) : k, v, parent, parent.isRoot() ? parent.cloned : false);

@@ -480,2 +535,8 @@ });

}
some(predicate) {
return this.elements.some(predicate);
}
every(predicate) {
return this.elements.every(predicate);
}
get firstElement() {

@@ -482,0 +543,0 @@ return this.elements[0];

@@ -1,9 +0,9 @@

import Document, { Events as DocumentEvents } from './document';
import Element, { Events as ElementEvents, isInternalFieldPath } from './element';
import Document, { Events as DocumentEvents, DEFAULT_VISIBLE_ELEMENTS as DEFAULT_VISIBLE_DOCUMENT_ELEMENTS } from './document';
import Element, { Events as ElementEvents, isInternalFieldPath, DEFAULT_VISIBLE_ELEMENTS } from './element';
import ElementEditor from './editor';
import type { Editor } from './editor';
import { getDefaultValueForType } from './utils';
import { getDefaultValueForType, objectToIdiomaticEJSON } from './utils';
export default Document;
export type { Editor };
export { Document, DocumentEvents, Element, ElementEvents, ElementEditor, isInternalFieldPath, getDefaultValueForType, };
export { Document, DocumentEvents, DEFAULT_VISIBLE_DOCUMENT_ELEMENTS, Element, ElementEvents, DEFAULT_VISIBLE_ELEMENTS, ElementEditor, isInternalFieldPath, getDefaultValueForType, objectToIdiomaticEJSON, };
//# sourceMappingURL=index.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultValueForType = exports.isInternalFieldPath = exports.ElementEditor = exports.ElementEvents = exports.Element = exports.DocumentEvents = exports.Document = void 0;
exports.objectToIdiomaticEJSON = exports.getDefaultValueForType = exports.isInternalFieldPath = exports.ElementEditor = exports.DEFAULT_VISIBLE_ELEMENTS = exports.ElementEvents = exports.Element = exports.DEFAULT_VISIBLE_DOCUMENT_ELEMENTS = exports.DocumentEvents = exports.Document = void 0;
const document_1 = __importStar(require("./document"));
exports.Document = document_1.default;
Object.defineProperty(exports, "DocumentEvents", { enumerable: true, get: function () { return document_1.Events; } });
Object.defineProperty(exports, "DEFAULT_VISIBLE_DOCUMENT_ELEMENTS", { enumerable: true, get: function () { return document_1.DEFAULT_VISIBLE_ELEMENTS; } });
const element_1 = __importStar(require("./element"));

@@ -38,2 +39,3 @@ exports.Element = element_1.default;

Object.defineProperty(exports, "isInternalFieldPath", { enumerable: true, get: function () { return element_1.isInternalFieldPath; } });
Object.defineProperty(exports, "DEFAULT_VISIBLE_ELEMENTS", { enumerable: true, get: function () { return element_1.DEFAULT_VISIBLE_ELEMENTS; } });
const editor_1 = __importDefault(require("./editor"));

@@ -43,3 +45,4 @@ exports.ElementEditor = editor_1.default;

Object.defineProperty(exports, "getDefaultValueForType", { enumerable: true, get: function () { return utils_1.getDefaultValueForType; } });
Object.defineProperty(exports, "objectToIdiomaticEJSON", { enumerable: true, get: function () { return utils_1.objectToIdiomaticEJSON; } });
exports.default = document_1.default;
//# sourceMappingURL=index.js.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectGenerator = void 0;
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
const lodash_1 = require("lodash");
const DECRYPTED_KEYS = Symbol.for('@@mdb.decryptedKeys');

@@ -97,8 +94,7 @@ function maybeDecorateWithDecryptedKeys(object, element) {

static recursivelyGatherFieldsAndValuesForUpdate(target, keyInclusionOptions, includeUpdatedFields) {
var _a, _b, _c, _d, _e;
const originalFields = [];
const newFields = [];
const alwaysIncludeKeys = (_a = keyInclusionOptions.alwaysIncludeKeys) !== null && _a !== void 0 ? _a : [];
const includableEncryptedKeys = (_b = keyInclusionOptions.includableEncryptedKeys) !== null && _b !== void 0 ? _b : [];
for (const element of (_c = target.elements) !== null && _c !== void 0 ? _c : []) {
const alwaysIncludeKeys = keyInclusionOptions.alwaysIncludeKeys ?? [];
const includableEncryptedKeys = keyInclusionOptions.includableEncryptedKeys ?? [];
for (const element of target.elements ?? []) {
const isArrayIndex = target.currentType === 'Array';

@@ -165,3 +161,3 @@ const canIncludeOriginalValue = !element.isValueDecrypted() ||

let wasRenamedToKeyOfPreviouslyExistingElement = false;
for (const otherElement of (_d = target.elements) !== null && _d !== void 0 ? _d : []) {
for (const otherElement of target.elements ?? []) {
if (otherElement !== element &&

@@ -195,3 +191,3 @@ otherElement.key === element.currentKey) {

let wasRemovedAndLaterReplacedByNewElement = false;
for (const otherElement of (_e = target.elements) !== null && _e !== void 0 ? _e : []) {
for (const otherElement of target.elements ?? []) {
if (otherElement !== element &&

@@ -214,3 +210,3 @@ otherElement.currentKey === element.key) {

if (entry.value === DoesNotExist) {
if (newFields.some((otherEntry) => (0, lodash_isequal_1.default)(otherEntry.path, entry.path) && entry !== otherEntry)) {
if (newFields.some((otherEntry) => (0, lodash_1.isEqual)(otherEntry.path, entry.path) && entry !== otherEntry)) {
newFields.splice(i, 1);

@@ -289,3 +285,2 @@ continue;

static generateUpdateDoc(target) {
var _a, _b;
const { newFields } = ObjectGenerator.recursivelyGatherFieldsAndValuesForUpdate(target, {}, true);

@@ -303,7 +298,7 @@ if (newFields.some(({ path }) => path.some(({ key }) => key.includes('.') || key.startsWith('$')))) {

if (value === DoesNotExist) {
(_a = updateDoc.$unset) !== null && _a !== void 0 ? _a : (updateDoc.$unset = {});
updateDoc.$unset ??= {};
updateDoc.$unset[path.map(({ key }) => key).join('.')] = true;
}
else {
(_b = updateDoc.$set) !== null && _b !== void 0 ? _b : (updateDoc.$set = {});
updateDoc.$set ??= {};
updateDoc.$set[path.map(({ key }) => key).join('.')] = value;

@@ -310,0 +305,0 @@ }

@@ -1,12 +0,11 @@

import { EJSON } from 'bson';
import type { TypeCastMap, TypeCastTypes } from 'hadron-type-checker';
export declare function fieldStringLen(value: unknown): number;
export declare type BSONObject = TypeCastMap['Object'];
export declare type BSONArray = TypeCastMap['Array'];
export declare type BSONValue = TypeCastMap[TypeCastTypes];
export type BSONObject = TypeCastMap['Object'];
export type BSONArray = TypeCastMap['Array'];
export type BSONValue = TypeCastMap[TypeCastTypes];
export interface HadronEJSONOptions {
indent?: number | string;
}
export declare function objectToIdiomaticEJSON(value: Readonly<EJSON.SerializableTypes>, options?: HadronEJSONOptions): string;
export declare function getDefaultValueForType(type: keyof TypeCastMap): string | boolean | Date | Record<string, unknown> | unknown[] | import("bson").Binary | import("bson").Code | import("bson").Decimal128 | import("bson").Double | import("bson").Int32 | import("bson").Long | import("bson").MaxKey | import("bson").MinKey | import("bson").ObjectID | import("bson").BSONRegExp | import("bson").BSONSymbol | import("bson").Timestamp | null | undefined;
export declare function objectToIdiomaticEJSON(value: any, options?: HadronEJSONOptions): string;
export declare function getDefaultValueForType(type: keyof TypeCastMap): string | boolean | Date | Record<string, unknown> | unknown[] | import("bson").Binary | import("bson").Code | import("bson").Decimal128 | import("bson").Double | import("bson").Int32 | import("bson").Long | import("bson").MaxKey | import("bson").MinKey | import("bson").ObjectId | import("bson").BSONRegExp | import("bson").BSONSymbol | import("bson").Timestamp | null | undefined;
//# sourceMappingURL=utils.d.ts.map

@@ -10,3 +10,3 @@ {

"homepage": "https://github.com/mongodb-js/compass",
"version": "0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a",
"version": "0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723",
"repository": {

@@ -34,6 +34,6 @@ "type": "git",

"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
"clean": "rimraf dist",
"clean": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" || true",
"precompile": "npm run clean",
"compile": "tsc -p tsconfig.json",
"depcheck": "depcheck",
"depcheck": "compass-scripts check-peer-deps && depcheck",
"eslint": "eslint",

@@ -45,27 +45,18 @@ "prettier": "prettier",

"test": "mocha",
"test-cov": "nyc -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
"test-cov": "nyc --compact=false --produce-source-map=false -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
"test-watch": "npm run test -- --watch",
"test-ci": "npm run test-cov",
"reformat": "npm run prettier -- --write ."
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
},
"dependencies": {
"bson": "^4.4.1",
"debug": "^4.2.0",
"bson": "^6.7.0",
"eventemitter3": "^4.0.0",
"hadron-type-checker": "0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a",
"lodash.foreach": "^4.5.0",
"lodash.isarray": "^4.0.0",
"lodash.isequal": "^4.5.0",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1"
"hadron-type-checker": "0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723",
"lodash": "^4.17.21"
},
"devDependencies": {
"@mongodb-js/eslint-config-compass": "0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a",
"@mongodb-js/mocha-config-compass": "0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a",
"@mongodb-js/prettier-config-compass": "0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a",
"@mongodb-js/tsconfig-compass": "0.0.0-next-3e67b8063fbcd84b0bfd6451e2568968fbdba25a",
"@types/lodash.isarray": "^4.0.6",
"@types/lodash.isequal": "^4.5.5",
"@types/lodash.isplainobject": "^4.0.6",
"@types/lodash.isstring": "^4.0.6",
"@mongodb-js/eslint-config-compass": "0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723",
"@mongodb-js/mocha-config-compass": "0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723",
"@mongodb-js/prettier-config-compass": "0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723",
"@mongodb-js/tsconfig-compass": "0.0.0-next-40feb530037f84aa3d3a86e24346e9cfc5003723",
"chai": "^4.2.0",

@@ -75,7 +66,8 @@ "depcheck": "^1.4.1",

"eslint-config-mongodb-js": "^5.0.3",
"mocha": "^7.0.1",
"moment": "^2.27.0",
"prettier": "^2.7.1"
"mocha": "^10.2.0",
"moment": "^2.29.4",
"prettier": "^2.7.1",
"sinon": "^17.0.1"
},
"gitHead": "3e67b8063fbcd84b0bfd6451e2568968fbdba25a"
"gitHead": "40feb530037f84aa3d3a86e24346e9cfc5003723"
}

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

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

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