some progress

This commit is contained in:
Jonas_Jones 2023-03-30 20:40:42 +02:00
parent aea93a5527
commit e3c15bd288
1388 changed files with 306946 additions and 68323 deletions

7
node_modules/mongoose/lib/plugins/index.js generated vendored Normal file
View file

@ -0,0 +1,7 @@
'use strict';
exports.removeSubdocs = require('./removeSubdocs');
exports.saveSubdocs = require('./saveSubdocs');
exports.sharding = require('./sharding');
exports.trackTransaction = require('./trackTransaction');
exports.validateBeforeSave = require('./validateBeforeSave');

35
node_modules/mongoose/lib/plugins/removeSubdocs.js generated vendored Normal file
View file

@ -0,0 +1,35 @@
'use strict';
const each = require('../helpers/each');
/*!
* ignore
*/
module.exports = function removeSubdocs(schema) {
const unshift = true;
schema.s.hooks.pre('deleteOne', { document: true, query: false }, function removeSubDocsPreRemove(next) {
if (this.$isSubdocument) {
next();
return;
}
if (this.$__ == null) {
next();
return;
}
const _this = this;
const subdocs = this.$getAllSubdocs();
each(subdocs, function(subdoc, cb) {
subdoc.$__deleteOne(cb);
}, function(error) {
if (error) {
return _this.$__schema.s.hooks.execPost('deleteOne:error', _this, [_this], { error: error }, function(error) {
next(error);
});
}
next();
});
}, null, unshift);
};

66
node_modules/mongoose/lib/plugins/saveSubdocs.js generated vendored Normal file
View file

@ -0,0 +1,66 @@
'use strict';
const each = require('../helpers/each');
/*!
* ignore
*/
module.exports = function saveSubdocs(schema) {
const unshift = true;
schema.s.hooks.pre('save', false, function saveSubdocsPreSave(next) {
if (this.$isSubdocument) {
next();
return;
}
const _this = this;
const subdocs = this.$getAllSubdocs();
if (!subdocs.length) {
next();
return;
}
each(subdocs, function(subdoc, cb) {
subdoc.$__schema.s.hooks.execPre('save', subdoc, function(err) {
cb(err);
});
}, function(error) {
if (error) {
return _this.$__schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
next(error);
});
}
next();
});
}, null, unshift);
schema.s.hooks.post('save', function saveSubdocsPostSave(doc, next) {
if (this.$isSubdocument) {
next();
return;
}
const _this = this;
const subdocs = this.$getAllSubdocs();
if (!subdocs.length) {
next();
return;
}
each(subdocs, function(subdoc, cb) {
subdoc.$__schema.s.hooks.execPost('save', subdoc, [subdoc], function(err) {
cb(err);
});
}, function(error) {
if (error) {
return _this.$__schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
next(error);
});
}
next();
});
}, null, unshift);
};

83
node_modules/mongoose/lib/plugins/sharding.js generated vendored Normal file
View file

@ -0,0 +1,83 @@
'use strict';
const objectIdSymbol = require('../helpers/symbols').objectIdSymbol;
const utils = require('../utils');
/*!
* ignore
*/
module.exports = function shardingPlugin(schema) {
schema.post('init', function shardingPluginPostInit() {
storeShard.call(this);
return this;
});
schema.pre('save', function shardingPluginPreSave(next) {
applyWhere.call(this);
next();
});
schema.pre('remove', function shardingPluginPreRemove(next) {
applyWhere.call(this);
next();
});
schema.post('save', function shardingPluginPostSave() {
storeShard.call(this);
});
};
/*!
* ignore
*/
function applyWhere() {
let paths;
let len;
if (this.$__.shardval) {
paths = Object.keys(this.$__.shardval);
len = paths.length;
this.$where = this.$where || {};
for (let i = 0; i < len; ++i) {
this.$where[paths[i]] = this.$__.shardval[paths[i]];
}
}
}
/*!
* ignore
*/
module.exports.storeShard = storeShard;
/*!
* ignore
*/
function storeShard() {
// backwards compat
const key = this.$__schema.options.shardKey || this.$__schema.options.shardkey;
if (!utils.isPOJO(key)) {
return;
}
const orig = this.$__.shardval = {};
const paths = Object.keys(key);
const len = paths.length;
let val;
for (let i = 0; i < len; ++i) {
val = this.$__getValue(paths[i]);
if (val == null) {
orig[paths[i]] = val;
} else if (utils.isMongooseObject(val)) {
orig[paths[i]] = val.toObject({ depopulate: true, _isNested: true });
} else if (val instanceof Date || val[objectIdSymbol]) {
orig[paths[i]] = val;
} else if (typeof val.valueOf === 'function') {
orig[paths[i]] = val.valueOf();
} else {
orig[paths[i]] = val;
}
}
}

92
node_modules/mongoose/lib/plugins/trackTransaction.js generated vendored Normal file
View file

@ -0,0 +1,92 @@
'use strict';
const arrayAtomicsSymbol = require('../helpers/symbols').arrayAtomicsSymbol;
const sessionNewDocuments = require('../helpers/symbols').sessionNewDocuments;
const utils = require('../utils');
module.exports = function trackTransaction(schema) {
schema.pre('save', function trackTransactionPreSave() {
const session = this.$session();
if (session == null) {
return;
}
if (session.transaction == null || session[sessionNewDocuments] == null) {
return;
}
if (!session[sessionNewDocuments].has(this)) {
const initialState = {};
if (this.isNew) {
initialState.isNew = true;
}
if (this.$__schema.options.versionKey) {
initialState.versionKey = this.get(this.$__schema.options.versionKey);
}
initialState.modifiedPaths = new Set(Object.keys(this.$__.activePaths.getStatePaths('modify')));
initialState.atomics = _getAtomics(this);
session[sessionNewDocuments].set(this, initialState);
} else {
const state = session[sessionNewDocuments].get(this);
for (const path of Object.keys(this.$__.activePaths.getStatePaths('modify'))) {
state.modifiedPaths.add(path);
}
state.atomics = _getAtomics(this, state.atomics);
}
});
};
function _getAtomics(doc, previous) {
const pathToAtomics = new Map();
previous = previous || new Map();
const pathsToCheck = Object.keys(doc.$__.activePaths.init).concat(Object.keys(doc.$__.activePaths.modify));
for (const path of pathsToCheck) {
const val = doc.$__getValue(path);
if (val != null &&
Array.isArray(val) &&
utils.isMongooseDocumentArray(val) &&
val.length &&
val[arrayAtomicsSymbol] != null &&
Object.keys(val[arrayAtomicsSymbol]).length !== 0) {
const existing = previous.get(path) || {};
pathToAtomics.set(path, mergeAtomics(existing, val[arrayAtomicsSymbol]));
}
}
const dirty = doc.$__dirty();
for (const dirt of dirty) {
const path = dirt.path;
const val = dirt.value;
if (val != null && val[arrayAtomicsSymbol] != null && Object.keys(val[arrayAtomicsSymbol]).length !== 0) {
const existing = previous.get(path) || {};
pathToAtomics.set(path, mergeAtomics(existing, val[arrayAtomicsSymbol]));
}
}
return pathToAtomics;
}
function mergeAtomics(destination, source) {
destination = destination || {};
if (source.$pullAll != null) {
destination.$pullAll = (destination.$pullAll || []).concat(source.$pullAll);
}
if (source.$push != null) {
destination.$push = destination.$push || {};
destination.$push.$each = (destination.$push.$each || []).concat(source.$push.$each);
}
if (source.$addToSet != null) {
destination.$addToSet = (destination.$addToSet || []).concat(source.$addToSet);
}
if (source.$set != null) {
destination.$set = Object.assign(destination.$set || {}, source.$set);
}
return destination;
}

View file

@ -0,0 +1,51 @@
'use strict';
/*!
* ignore
*/
module.exports = function validateBeforeSave(schema) {
const unshift = true;
schema.pre('save', false, function validateBeforeSave(next, options) {
const _this = this;
// Nested docs have their own presave
if (this.$isSubdocument) {
return next();
}
const hasValidateBeforeSaveOption = options &&
(typeof options === 'object') &&
('validateBeforeSave' in options);
let shouldValidate;
if (hasValidateBeforeSaveOption) {
shouldValidate = !!options.validateBeforeSave;
} else {
shouldValidate = this.$__schema.options.validateBeforeSave;
}
// Validate
if (shouldValidate) {
const hasValidateModifiedOnlyOption = options &&
(typeof options === 'object') &&
('validateModifiedOnly' in options);
const validateOptions = hasValidateModifiedOnlyOption ?
{ validateModifiedOnly: options.validateModifiedOnly } :
null;
this.$validate(validateOptions).then(
() => {
this.$op = 'save';
next();
},
error => {
_this.$__schema.s.hooks.execPost('save:error', _this, [_this], { error: error }, function(error) {
_this.$op = 'save';
next(error);
});
}
);
} else {
next();
}
}, null, unshift);
};