repoweaver
Version:
A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies
1 lines • 7.23 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nconst formatToList = items => Object.entries(items).map(([key, value]) => `- ${key} (${value})`).join('\\n');\nexport function validatePathConfig(config, root = true) {\n const validation = Object.assign({\n path: 'string',\n initialRouteName: 'string',\n screens: 'object'\n }, root ? null : {\n alias: 'array',\n exact: 'boolean',\n stringify: 'object',\n parse: 'object'\n });\n if (typeof config !== 'object' || config === null) {\n throw new Error(`Expected the configuration to be an object, but got ${JSON.stringify(config)}.`);\n }\n const validationErrors = Object.fromEntries(Object.keys(config).map(key => {\n if (key in validation) {\n const type = validation[key];\n const value = config[key];\n if (value !== undefined) {\n if (type === 'array') {\n if (!Array.isArray(value)) {\n return [key, `expected 'Array', got '${typeof value}'`];\n }\n } else if (typeof value !== type) {\n return [key, `expected '${type}', got '${typeof value}'`];\n }\n }\n } else {\n return [key, 'extraneous'];\n }\n return null;\n }).filter(Boolean));\n if (Object.keys(validationErrors).length) {\n throw new Error(`Found invalid properties in the configuration:\\n${formatToList(validationErrors)}\\n\\nYou can only specify the following properties:\\n${formatToList(validation)}\\n\\nIf you want to specify configuration for screens, you need to specify them under a 'screens' property.\\n\\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`);\n }\n if (root && 'path' in config && typeof config.path === 'string' && config.path.includes(':')) {\n throw new Error(`Found invalid path '${config.path}'. The 'path' in the top-level configuration cannot contain patterns for params.`);\n }\n if ('screens' in config && config.screens) {\n Object.entries(config.screens).forEach(([_, value]) => {\n if (typeof value !== 'string') {\n validatePathConfig(value, false);\n }\n });\n }\n}","map":{"version":3,"names":["formatToList","items","Object","entries","map","key","value","join","validatePathConfig","config","root","validation","assign","path","initialRouteName","screens","alias","exact","stringify","parse","Error","JSON","validationErrors","fromEntries","keys","type","undefined","Array","isArray","filter","Boolean","length","includes","forEach","_"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/core/src/validatePathConfig.tsx"],"sourcesContent":["const formatToList = (items: Record<string, string>) =>\n Object.entries(items)\n .map(([key, value]) => `- ${key} (${value})`)\n .join('\\n');\n\nexport function validatePathConfig(config: unknown, root = true) {\n const validation = {\n path: 'string',\n initialRouteName: 'string',\n screens: 'object',\n ...(root\n ? null\n : {\n alias: 'array',\n exact: 'boolean',\n stringify: 'object',\n parse: 'object',\n }),\n };\n\n if (typeof config !== 'object' || config === null) {\n throw new Error(\n `Expected the configuration to be an object, but got ${JSON.stringify(\n config\n )}.`\n );\n }\n\n const validationErrors = Object.fromEntries(\n Object.keys(config)\n .map((key) => {\n if (key in validation) {\n const type = validation[key as keyof typeof validation];\n // @ts-expect-error: we know the key exists\n const value = config[key];\n\n if (value !== undefined) {\n if (type === 'array') {\n if (!Array.isArray(value)) {\n return [key, `expected 'Array', got '${typeof value}'`];\n }\n } else if (typeof value !== type) {\n return [key, `expected '${type}', got '${typeof value}'`];\n }\n }\n } else {\n return [key, 'extraneous'];\n }\n\n return null;\n })\n .filter(Boolean) as [string, string][]\n );\n\n if (Object.keys(validationErrors).length) {\n throw new Error(\n `Found invalid properties in the configuration:\\n${formatToList(\n validationErrors\n )}\\n\\nYou can only specify the following properties:\\n${formatToList(\n validation\n )}\\n\\nIf you want to specify configuration for screens, you need to specify them under a 'screens' property.\\n\\nSee https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration.`\n );\n }\n\n if (\n root &&\n 'path' in config &&\n typeof config.path === 'string' &&\n config.path.includes(':')\n ) {\n throw new Error(\n `Found invalid path '${config.path}'. The 'path' in the top-level configuration cannot contain patterns for params.`\n );\n }\n\n if ('screens' in config && config.screens) {\n Object.entries(config.screens).forEach(([_, value]) => {\n if (typeof value !== 'string') {\n validatePathConfig(value, false);\n }\n });\n }\n}\n"],"mappings":";;AAAA,MAAMA,YAAY,GAAIC,KAA6B,IACjDC,MAAM,CAACC,OAAO,CAACF,KAAK,CAAC,CAClBG,GAA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;QAC3D;MACF;IACF,CAAC,MAAM;MACL,OAAO,CAACD,GAAG,EAAE,YAAY,CAAC;IAC5B;IAEA,OAAO,IAAI;EACb,CAAC,CAAC,CACDwB,MAAM,CAACC,OAAO,CACnB,CAAC;EAED,IAAI5B,MAAM,CAACsB,IAAI,CAACF,gBAAgB,CAAC,CAACS,MAAM,EAAE;IACxC,MAAM,IAAIX,KAAK,CACb,mDAAmDpB,YAAY,CAC7DsB,gBACF,CAAC,uDAAuDtB,YAAY,CAClEW,UACF,CAAC,kOACH,CAAC;EACH;EAEA,IACED,IAAI,IACJ,MAAM,IAAID,MAAM,IAChB,OAAOA,MAAM,CAACI,IAAI,KAAK,QAAQ,IAC/BJ,MAAM,CAACI,IAAI,CAACmB,QAAQ,CAAC,GAAG,CAAC,EACzB;IACA,MAAM,IAAIZ,KAAK,CACb,uBAAuBX,MAAM,CAACI,IAAI,kFACpC,CAAC;EACH;EAEA,IAAI,SAAS,IAAIJ,MAAM,IAAIA,MAAM,CAACM,OAAO,EAAE;IACzCb,MAAM,CAACC,OAAO,CAACM,MAAM,CAACM,OAAO,CAAC,CAACkB,OAAO,CAAC,CAAC,CAACC,CAAC,EAAE5B,KAAK,CAAC,KAAK;MACrD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;QAC7BE,kBAAkB,CAACF,KAAK,EAAE,KAAK,CAAC;MAClC;IACF,CAAC,CAAC;EACJ;AACF","ignoreList":[]},"metadata":{"hasCjsExports":false},"sourceType":"module","externalDependencies":[]}