Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 732x 732x 172484x 32517296x 495558x 32021738x 699399x 699399x 529757x 169642x 100366x 69276x 69276x 31322339x 2834x 31319505x 172x 4x 4x 155493x | import type { Document } from './bson';
/** @public */
export const ReadConcernLevel = Object.freeze({
local: 'local',
majority: 'majority',
linearizable: 'linearizable',
available: 'available',
snapshot: 'snapshot'
} as const);
/** @public */
export type ReadConcernLevel = (typeof ReadConcernLevel)[keyof typeof ReadConcernLevel];
/** @public */
export type ReadConcernLike = ReadConcern | { level: ReadConcernLevel } | ReadConcernLevel;
/**
* The MongoDB ReadConcern, which allows for control of the consistency and isolation properties
* of the data read from replica sets and replica set shards.
* @public
*
* @see https://www.mongodb.com/docs/manual/reference/read-concern/index.html
*/
export class ReadConcern {
level: ReadConcernLevel | string;
/** Constructs a ReadConcern from the read concern level.*/
constructor(level: ReadConcernLevel) {
/**
* A spec test exists that allows level to be any string.
* "invalid readConcern with out stage"
* @see ./test/spec/crud/v2/aggregate-out-readConcern.json
* @see https://github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.md#unknown-levels-and-additional-options-for-string-based-readconcerns
*/
this.level = ReadConcernLevel[level] ?? level;
}
/**
* Construct a ReadConcern given an options object.
*
* @param options - The options object from which to extract the write concern.
*/
static fromOptions(options?: {
readConcern?: ReadConcernLike;
level?: ReadConcernLevel;
}): ReadConcern | undefined {
if (options == null) {
return;
}
if (options.readConcern) {
const { readConcern } = options;
if (readConcern instanceof ReadConcern) {
return readConcern;
} else if (typeof readConcern === 'string') {
return new ReadConcern(readConcern);
} else Eif ('level' in readConcern && readConcern.level) {
return new ReadConcern(readConcern.level);
}
}
if (options.level) {
return new ReadConcern(options.level);
}
return;
}
static get MAJORITY(): 'majority' {
return ReadConcernLevel.majority;
}
static get AVAILABLE(): 'available' {
return ReadConcernLevel.available;
}
static get LINEARIZABLE(): 'linearizable' {
return ReadConcernLevel.linearizable;
}
static get SNAPSHOT(): 'snapshot' {
return ReadConcernLevel.snapshot;
}
toJSON(): Document {
return { level: this.level };
}
}
|