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

Function getPositionalPathType

lib/schema.js:2021–2080  ·  view source on GitHub ↗

* ignore. Deprecated re: #6405 * @param {any} self * @param {string} path * @api private

(self, path, cleanPath)

Source from the content-addressed store, hash-verified

2019 */
2020
2021function getPositionalPathType(self, path, cleanPath) {
2022 const subpaths = path.split(/\.(\d+)\.|\.(\d+)$/).filter(Boolean);
2023 if (subpaths.length < 2) {
2024 return Object.hasOwn(self.paths, subpaths[0]) ?
2025 self.paths[subpaths[0]] :
2026 'adhocOrUndefined';
2027 }
2028
2029 let val = self.path(subpaths[0]);
2030 let isNested = false;
2031 if (!val) {
2032 return 'adhocOrUndefined';
2033 }
2034
2035 const last = subpaths.length - 1;
2036
2037 for (let i = 1; i < subpaths.length; ++i) {
2038 isNested = false;
2039 const subpath = subpaths[i];
2040
2041 if (i === last && val && !/\D/.test(subpath)) {
2042 if (val.$isMongooseDocumentArray) {
2043 val = val.embeddedSchemaType;
2044 } else if (val instanceof MongooseTypes.Array) {
2045 // StringSchema, NumberSchema, etc
2046 val = val.embeddedSchemaType;
2047 } else {
2048 val = undefined;
2049 }
2050 break;
2051 }
2052
2053 // ignore if its just a position segment: path.0.subpath
2054 if (!/\D/.test(subpath)) {
2055 // Nested array
2056 if (val instanceof MongooseTypes.Array && i !== last) {
2057 val = val.embeddedSchemaType;
2058 }
2059 continue;
2060 }
2061
2062 if (!val?.schema) {
2063 val = undefined;
2064 break;
2065 }
2066
2067 const type = val.schema.pathType(subpath);
2068 isNested = (type === 'nested');
2069 val = val.schema.path(subpath);
2070 }
2071
2072 self.subpaths[cleanPath] = val;
2073 if (val) {
2074 return 'real';
2075 }
2076 if (isNested) {
2077 return 'nested';
2078 }

Callers 2

schema.jsFile · 0.85
getPositionalPathFunction · 0.85

Calls 1

testMethod · 0.80

Tested by

no test coverage detected