MCPcopy Create free account
hub / github.com/vercel/vercel / parseSubscriber

Function parseSubscriber

packages/python/src/subscribers.ts:121–168  ·  view source on GitHub ↗
(
  workPath: string,
  name: string,
  config: RawSubscriber
)

Source from the content-addressed store, hash-verified

119}
120
121async 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
170function parseEntrypoint(
171 name: string,

Callers 1

getPyprojectSubscribersFunction · 0.85

Calls 8

subscriberErrorFunction · 0.85
parseEntrypointFunction · 0.85
parseTopicsFunction · 0.85
parseTriggerDefaultsFunction · 0.85
testMethod · 0.80
keysMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected