Every line of 'getdocumentbyid' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
22 getById(documentId) { 23 return this.http 24 .get(this.getIdRoute(documentId)); 25 }
24 find(document) { 25 return this._get(document.id); 26 }
5 function getDocumentIds(id) { 6 const isDraft = id.indexOf('drafts.') === 0 7 return { 8 published: isDraft ? id.slice('drafts.'.length) : id, 9 draft: isDraft ? id : `drafts.${id}` 10 } 11 }
197 selectDocument(idOrDocument) { 198 if (idOrDocument === null) { 199 this.elements.documentDetailsContainer.classList.add("hide"); 200 return; 201 } 202 if (typeof idOrDocument === "string") { 203 const id = idOrDocument; 204 const document = this.documents.find(doc => doc.id === id); 205 if (document) { 206 this.selectDocument(document); 207 return; 208 } 209 } 210 else { 211 const document = idOrDocument; 212 this.elements.documentDetails.innerHTML = ""; 213 const element = this.renderDocument(document, "details"); 214 this.elements.documentDetails.appendChild(element); 215 this.elements.documentDetailsContainer.classList.remove("hide"); 216 this.elements.documentDetailsContainer.scrollIntoView({ 217 behavior: "smooth", 218 block: "start", 219 }); 220 } 221 }
55 private fetchDocument(id: string): Observable { 56 const requestPath = `${DOC_CONTENT_URL_PREFIX}${id}.json`; 57 const subject = new AsyncSubject(); 58 59 this.logger.log('fetching document from', requestPath); 60 this.http 61 .get(requestPath, {responseType: 'json'}) 62 .pipe( 63 tap(data => { 64 if (!data || typeof data !== 'object') { 65 this.logger.log('received invalid data:', data); 66 throw Error('Invalid data'); 67 } 68 }), 69 catchError((error: HttpErrorResponse) => { 70 return error.status === 404 ? this.getFileNotFoundDoc(id) : this.getErrorDoc(id, error); 71 }), 72 ) 73 .subscribe(subject); 74 75 return subject.asObservable(); 76 }
58 private fetchDocument(id: string): Observable { 59 const requestPath = `${DOC_CONTENT_URL_PREFIX}${id}.json`; 60 const subject = new AsyncSubject(); 61 62 this.logger.log('fetching document from', requestPath); 63 this.http 64 .get(requestPath, {responseType: 'json'}) 65 .do(data => { 66 if (!data || typeof data !== 'object') { 67 this.logger.log('received invalid data:', data); 68 throw Error('Invalid data'); 69 } 70 }) 71 .catch((error: HttpErrorResponse) => { 72 return error.status === 404 ? this.getFileNotFoundDoc(id) : this.getErrorDoc(id, error); 73 }) 74 .subscribe(subject); 75 76 return subject.asObservable(); 77 }
87 async getDocument(collectionId, documentId) { 88 let path = '/database/collections/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId); 89 90 return await this.client.call('get', path, { 91 'content-type': 'application/json', 92 }, 93 { 94 }); 95 }
51 async getDocComplex(documentId) { 52 // **Note:** We don't make an `async` back-end call to check the full 53 // validity of `documentId` here, because that would be a waste if it turns 54 // out we've already cached a valid result. Once we determine that we need 55 // to construct a new complex (below), we'll call through to the back-end to 56 // get a file ID, and that call implicitly validates the document ID. 57 Storage.docStore.checkDocumentIdSyntax(documentId); 58 59 return this._complexes.resolveOrAdd(documentId, async () => { 60 try { 61 const startTime = Date.now(); 62 63 // This validates the document ID and lets us find out the corresponding 64 // file ID. 65 const docInfo = await Storage.docStore.getDocumentInfo(documentId); 66 const fileId = docInfo.fileId; 67 68 const file = await Storage.fileStore.getFile(fileId); 69 const result = new DocComplex(this._codec, documentId, file); 70 71 result.log.event.makingComplex(...((fileId === documentId) ? [] : [fileId])); 72 73 await result.init(); 74 75 const endTime = Date.now(); 76 result.log.event.madeComplex(...((fileId === documentId) ? [] : [fileId])); 77 result.log.metric.initTimeMsec(endTime - startTime); 78 79 return result; 80 } catch (e) { 81 log.error(`Trouble constructing complex ${documentId}.`, e); 82 throw e; // Becomes the rejection value of the promise. 83 } 84 }); 85 }
332 function getDocumentByIdOrSubject(idOrSubject) { 333 executeSearchByQuery('doc:' + idOrSubject); 334 }