
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@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
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
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.