MCPcopy
hub / github.com/Automattic/mongoose / checkValidKey

Function checkValidKey

lib/types/map.js:352–366  ·  view source on GitHub ↗

* Since maps are stored as objects under the hood, keys must be strings * and can't contain any invalid characters * @param {string} key * @api private

(key)

Source from the content-addressed store, hash-verified

350 */
351
352function checkValidKey(key) {
353 const keyType = typeof key;
354 if (keyType !== 'string') {
355 throw new TypeError(`Mongoose maps only support string keys, got ${keyType}`);
356 }
357 if (key.startsWith('$')) {
358 throw new Error(`Mongoose maps do not support keys that start with "$", got "${key}"`);
359 }
360 if (key.includes('.')) {
361 throw new Error(`Mongoose maps do not support keys that contain ".", got "${key}"`);
362 }
363 if (specialProperties.has(key)) {
364 throw new Error(`Mongoose maps do not support reserved key name "${key}"`);
365 }
366}
367
368module.exports = MongooseMap;

Callers 2

$initMethod · 0.85
setMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…