
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
@cranq/document-utils
Advanced tools
Utilities for manipulating documents in a document store.
A document is any record (JS object) that has a __collectionId
property.
Documents may contain other documents, or references to documents.
Documents extend the Document
type.
Example:
type Dog = {
__collectionId: "dogs",
name: string;
owner: Person;
};
type Person = {
__collectionId: "people",
name: string;
}
const buddy: Dog = {
__collectionId: "dogs",
name: "Buddy",
owner: { // sub-document
__collectionId: "people",
name: "Jane Doe"
}
}
A reference to a document identifies a document in a document store, and is a record (JS object) with exactly two properties:
References are of the Reference
type.
__collectionId
- same as the collection ID of the referenced document__documentId
- identifies the referenced document in its collectionExample:
const buddyRef: Reference<Dog> = {
__collectionId: "dogs",
__documentId: "buddy"
}
A truncated document is a document with all its sub-documents replaced with references.
Truncated documents satisfy the TruncatedDocument<D>
type,
where D extends Document
.
Example:
const buddyTruncated: TruncateDocument<Dog> = {
__collectionId: "dogs",
name: "Buddy",
owner: { // reference to sub-document
__collectionId: "people",
__documentId: "jane-doe"
}
}
A restored document is a document restored from a truncated document.
Restored documents are ordinary documents, but their restored types can be
calculated using the RestoreDocument
generic. RestoreDocument<TR>
will be the same as D
, given that TR = TruncateDocument<D>
.
A document collection is a dictionary (JS object) of truncated documents of the same collection ID, indexed by their document IDs.
The type of a document collection is based on type of the documents it contains.
Eg: DocumentCollection<D>
.
Example:
const dogs: DocumentCollection<Dog> = {
"buddy": {
__collectionId: "dogs",
name: "Buddy",
owner: {
__collectionId: "people",
__documentId: "jane-doe"
}
}
}
A document store is a dictionary (JS object) of document collections, indexed by collection IDs.
The type of a document store is based on the types of all the documents it can
store. Eg: DocumentStore<Dog | Person>
Example:
const documentStore: DocumentStore<Dog | Person> = {
"dogs": {
"buddy": {
__collectionId: "dogs",
name: "Buddy",
owner: {
__collectionId: "people",
__documentId: "jane-doe"
}
}
},
"people": {
"jane-doe": {
__collectionId: "people",
name: "Jane Doe"
}
}
}
Example:
const buddyTruncated = getDocument(documentStore, "dogs", "buddy");
Retrieving a deep document out of the store, when compared to getDocument()
,
incurs some performance penalty proportional to the complexity of the document
being retrieved, as it needs to be assembled on the fly.
Example:
const buddy = getDeepDocument(documentStore, "dogs", "buddy");
Example:
const buddyName = getField(documentStore, "dogs", "buddy", "name");
Example:
documentStore = setDocument(documentStore, "dogs", "buddy", {
__collectionId: "dogs",
name: "Buddy",
owner: {
__collectionId: "people",
__documentId: "jane-doe"
}
})
A mutable version exists for setDocument()
, with identical arguments,
and void
return type: setDocumentMutable()
.
Appending a document changes the value of specified field, leaving other fields unaffected. Fields values may be specified either as a value, or as a function - receiving current value and returning new value.
Example:
documentStore = appendDocument(documentStore, "dogs", "buddy", {
name: "Fido"
})
documentStore = appendDocument(documentStore, "people", "jane.doe", {
name: (name) => `${name} Jr.`
})
A mutable version exists for appendDocument()
, with identical arguments,
and void
return type: appendDocumentMutable()
.
Writing a deep document into the store, when compared to setDocument()
, incurs
some performance penalty proportional to the complexity of the document being
written, as it needs to be broken down on the fly.
Example:
documentStore = setDeepDocument(documentStore, "dogs", "buddy", {
__collectionId: "dogs",
name: "Buddy",
owner: {
__collectionId: "people",
name: "Jane Doe"
}
})
A mutable version exists for setDeepDocument()
, with identical arguments,
and void
return type: setDeepDocumentMutable()
.
FAQs
Document store manipulation utilities
The npm package @cranq/document-utils receives a total of 0 weekly downloads. As such, @cranq/document-utils popularity was classified as not popular.
We found that @cranq/document-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.