summaryrefslogtreecommitdiffstats
path: root/node_modules/mongodb/lib/operations/operation.js
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/mongodb/lib/operations/operation.js
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/mongodb/lib/operations/operation.js')
-rw-r--r--node_modules/mongodb/lib/operations/operation.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/node_modules/mongodb/lib/operations/operation.js b/node_modules/mongodb/lib/operations/operation.js
new file mode 100644
index 0000000..28a9d05
--- /dev/null
+++ b/node_modules/mongodb/lib/operations/operation.js
@@ -0,0 +1,66 @@
+'use strict';
+
+const Aspect = {
+ READ_OPERATION: Symbol('READ_OPERATION'),
+ WRITE_OPERATION: Symbol('WRITE_OPERATION'),
+ RETRYABLE: Symbol('RETRYABLE'),
+ EXECUTE_WITH_SELECTION: Symbol('EXECUTE_WITH_SELECTION'),
+ NO_INHERIT_OPTIONS: Symbol('NO_INHERIT_OPTIONS')
+};
+
+/**
+ * This class acts as a parent class for any operation and is responsible for setting this.options,
+ * as well as setting and getting a session.
+ * Additionally, this class implements `hasAspect`, which determines whether an operation has
+ * a specific aspect.
+ */
+class OperationBase {
+ constructor(options) {
+ this.options = Object.assign({}, options);
+ }
+
+ hasAspect(aspect) {
+ if (this.constructor.aspects == null) {
+ return false;
+ }
+ return this.constructor.aspects.has(aspect);
+ }
+
+ set session(session) {
+ Object.assign(this.options, { session });
+ }
+
+ get session() {
+ return this.options.session;
+ }
+
+ clearSession() {
+ delete this.options.session;
+ }
+
+ get canRetryRead() {
+ return true;
+ }
+
+ execute() {
+ throw new TypeError('`execute` must be implemented for OperationBase subclasses');
+ }
+}
+
+function defineAspects(operation, aspects) {
+ if (!Array.isArray(aspects) && !(aspects instanceof Set)) {
+ aspects = [aspects];
+ }
+ aspects = new Set(aspects);
+ Object.defineProperty(operation, 'aspects', {
+ value: aspects,
+ writable: false
+ });
+ return aspects;
+}
+
+module.exports = {
+ Aspect,
+ defineAspects,
+ OperationBase
+};