MCPcopy Create free account
hub / github.com/Automattic/mongoose / constructor

Method constructor

lib/defaults/schemaDefaultsCache.js:27–59  ·  view source on GitHub ↗
(schema)

Source from the content-addressed store, hash-verified

25
26class SchemaDefaultsCache {
27 constructor(schema) {
28 this.paths = [];
29 this.schemaTypes = [];
30 this.defaultsByNestedPath = new Map();
31
32 for (const path of Object.keys(schema.paths)) {
33 const schemaType = schema.paths[path];
34 if (schemaType.defaultValue === undefined) {
35 continue;
36 }
37 const pieces = schemaType.splitPath();
38 if (pieces[pieces.length - 1] === '$*') {
39 continue;
40 }
41 this.paths.push(path);
42 this.schemaTypes.push(schemaType);
43
44 let nestedPath = '';
45 for (let i = 0; i < pieces.length - 1; ++i) {
46 nestedPath = i === 0 ? pieces[0] : nestedPath + '.' + pieces[i];
47 if (schema.nested[nestedPath] !== true) {
48 continue;
49 }
50 let entry = this.defaultsByNestedPath.get(nestedPath);
51 if (entry == null) {
52 entry = { paths: [], schemaTypes: [], depth: i + 1 };
53 this.defaultsByNestedPath.set(nestedPath, entry);
54 }
55 entry.paths.push(path);
56 entry.schemaTypes.push(schemaType);
57 }
58 }
59 }
60}
61
62module.exports = SchemaDefaultsCache;

Callers

nothing calls this directly

Calls 2

getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected