| 5 | import createExcerpt from 'ember-api-docs/utils/create-excerpt'; |
| 6 | |
| 7 | export default class FunctionRoute extends Route { |
| 8 | @service |
| 9 | headData; |
| 10 | |
| 11 | @service |
| 12 | metaStore; |
| 13 | |
| 14 | @service store; |
| 15 | |
| 16 | titleToken(model) { |
| 17 | return model?.fn?.name; |
| 18 | } |
| 19 | |
| 20 | async model(params, transition) { |
| 21 | const pVParams = this.paramsFor('project-version'); |
| 22 | const { project, project_version: compactVersion } = pVParams; |
| 23 | |
| 24 | let projectObj = await this.store.findRecord('project', project); |
| 25 | let projectVersion = getFullVersion( |
| 26 | compactVersion, |
| 27 | project, |
| 28 | projectObj, |
| 29 | this.metaStore, |
| 30 | ); |
| 31 | let className = params['module']; |
| 32 | let functionName = params['fn']; |
| 33 | let fnModule; |
| 34 | |
| 35 | try { |
| 36 | fnModule = await this.store.findRecord( |
| 37 | 'class', |
| 38 | `${project}-${projectVersion}-${className}`.toLowerCase(), |
| 39 | ); |
| 40 | } catch { |
| 41 | try { |
| 42 | fnModule = await this.store.findRecord( |
| 43 | 'namespace', |
| 44 | `${project}-${projectVersion}-${className}`.toLowerCase(), |
| 45 | ); |
| 46 | } catch (e2) { |
| 47 | if (transition.to.name === transition?.from?.name) { |
| 48 | let error = new Error( |
| 49 | `We could not find function ${className}/${functionName} in v${compactVersion} of ${project}.`, |
| 50 | ); |
| 51 | error.status = 404; |
| 52 | error.attemptedProject = project; |
| 53 | error.attemptedVersion = compactVersion; |
| 54 | throw error; |
| 55 | } else { |
| 56 | throw e2; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return { |
| 62 | fnModule, |
| 63 | fn: fnModule.get('methods').find((fn) => fn.name === functionName), |
| 64 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected