1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.WriteConcern = exports.WRITE_CONCERN_KEYS = void 0;
- exports.WRITE_CONCERN_KEYS = ['w', 'wtimeout', 'j', 'journal', 'fsync'];
- class WriteConcern {
-
- constructor(w, wtimeoutMS, journal, fsync) {
- if (w != null) {
- if (!Number.isNaN(Number(w))) {
- this.w = Number(w);
- }
- else {
- this.w = w;
- }
- }
- if (wtimeoutMS != null) {
- this.wtimeoutMS = this.wtimeout = wtimeoutMS;
- }
- if (journal != null) {
- this.journal = this.j = journal;
- }
- if (fsync != null) {
- this.journal = this.j = fsync ? true : false;
- }
- }
-
- static apply(command, writeConcern) {
- const wc = {};
-
- if (writeConcern.w != null)
- wc.w = writeConcern.w;
- if (writeConcern.wtimeoutMS != null)
- wc.wtimeout = writeConcern.wtimeoutMS;
- if (writeConcern.journal != null)
- wc.j = writeConcern.j;
- command.writeConcern = wc;
- return command;
- }
-
- static fromOptions(options, inherit) {
- if (options == null)
- return undefined;
- inherit = inherit ?? {};
- let opts;
- if (typeof options === 'string' || typeof options === 'number') {
- opts = { w: options };
- }
- else if (options instanceof WriteConcern) {
- opts = options;
- }
- else {
- opts = options.writeConcern;
- }
- const parentOpts = inherit instanceof WriteConcern ? inherit : inherit.writeConcern;
- const { w = undefined, wtimeout = undefined, j = undefined, fsync = undefined, journal = undefined, wtimeoutMS = undefined } = {
- ...parentOpts,
- ...opts
- };
- if (w != null ||
- wtimeout != null ||
- wtimeoutMS != null ||
- j != null ||
- journal != null ||
- fsync != null) {
- return new WriteConcern(w, wtimeout ?? wtimeoutMS, j ?? journal, fsync);
- }
- return undefined;
- }
- }
- exports.WriteConcern = WriteConcern;
|