MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / add

Function add

packages/hydrooj/src/model/document.ts:66–90  ·  view source on GitHub ↗
(
    domainId: string, content: Content, owner: number,
    docType: number, docId: DocID = null,
    parentType: number | null = null, parentId: DocID = null,
    args: any = {},
)

Source from the content-addressed store, hash-verified

64 args?: Partial<DocType[T]>,
65): Promise<ObjectId>;
66export async function add(
67 domainId: string, content: Content, owner: number,
68 docType: number, docId: DocID = null,
69 parentType: number | null = null, parentId: DocID = null,
70 args: any = {},
71) {
72 const _id = new ObjectId();
73 const doc: any = {
74 _id,
75 content,
76 owner,
77 domainId,
78 docType,
79 docId: docId || _id,
80 ...args,
81 };
82 if (parentType || parentId) {
83 assert(parentType && parentId);
84 doc.parentType = parentType;
85 doc.parentId = parentId;
86 }
87 await bus.parallel('document/add', doc);
88 const res = await coll.insertOne(doc);
89 return docId || res.insertedId;
90}
91
92export async function get<K extends keyof DocType>(domainId: string, docType: K, docId: DocType[K]['docId'], projection?: Projection<DocType[K]>) {
93 let cursor = coll.find({ domainId, docType, docId }).limit(1);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected