( workPath: string, name: string, config: RawSubscriber )
| 119 | } |
| 120 | |
| 121 | async function parseSubscriber( |
| 122 | workPath: string, |
| 123 | name: string, |
| 124 | config: RawSubscriber |
| 125 | ): Promise<Subscriber> { |
| 126 | if (!SUBSCRIBER_NAME_RE.test(name)) { |
| 127 | throw subscriberError( |
| 128 | `subscriber name "${name}" is invalid. Names must start with a letter, end with an alphanumeric character, and contain only alphanumeric characters, hyphens, and underscores` |
| 129 | ); |
| 130 | } |
| 131 | if (!config || typeof config !== 'object' || Array.isArray(config)) { |
| 132 | throw subscriberError(`subscriber "${name}" must be an object`); |
| 133 | } |
| 134 | |
| 135 | for (const key of Object.keys(config)) { |
| 136 | if (!SUBSCRIBER_FIELD_NAMES.has(key)) { |
| 137 | throw subscriberError( |
| 138 | `subscriber "${name}" has unrecognized field "${key}"` |
| 139 | ); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | if (typeof config.entrypoint !== 'string') { |
| 144 | throw subscriberError( |
| 145 | `subscriber "${name}" must define string field "entrypoint"` |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | const entrypoint = parseEntrypoint(name, config.entrypoint); |
| 150 | const existingEntrypoint = await resolveExistingEntrypoint( |
| 151 | workPath, |
| 152 | entrypoint.filePath |
| 153 | ); |
| 154 | if (!existingEntrypoint) { |
| 155 | throw subscriberError( |
| 156 | `subscriber "${name}" has entrypoint "${config.entrypoint}" but file "${entrypoint.filePath}" does not exist` |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | return { |
| 161 | name, |
| 162 | entrypoint: existingEntrypoint, |
| 163 | moduleName: entrypoint.moduleName, |
| 164 | variableName: entrypoint.variableName, |
| 165 | topics: parseTopics(name, config.topics), |
| 166 | triggerDefaults: parseTriggerDefaults(name, config), |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | function parseEntrypoint( |
| 171 | name: string, |
no test coverage detected