mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
27 lines
817 B
TypeScript
27 lines
817 B
TypeScript
// Loaded from https://deno.land/x/dndb@0.2.4/src/methods/updateOne.js
|
|
|
|
|
|
import { mongobj, matches } from '../../deps.ts';
|
|
import { ReadFileStream, WriteFileStream } from '../storage.ts';
|
|
|
|
export default async (filename ,query, operators, projection) => {
|
|
const readStream = new ReadFileStream(filename);
|
|
const writeStream = new WriteFileStream(filename);
|
|
let updated = [];
|
|
query = query || {};
|
|
return new Promise((resolve, reject) => {
|
|
readStream.on('document', obj => {
|
|
if (matches(query, obj) && !updated.length) {
|
|
mongobj.update(obj, operators);
|
|
updated.push(obj)
|
|
}
|
|
writeStream.emit("write", obj)
|
|
})
|
|
readStream.on("end", () => {
|
|
writeStream.emit("end");
|
|
})
|
|
writeStream.on("close", () => {
|
|
return resolve(updated[0] || null)
|
|
})
|
|
})
|
|
} |