MCPcopy Create free account
hub / github.com/hey-api/hey-api / compileInputPath

Function compileInputPath

packages/shared/src/config/input/path.ts:6–98  ·  view source on GitHub ↗
(input: Omit<Input, 'watch'>)

Source from the content-addressed store, hash-verified

4import type { Input } from './types';
5
6export function compileInputPath(input: Omit<Input, 'watch'>) {
7 const result: Pick<
8 Partial<Input>,
9 | 'api_key'
10 | 'branch'
11 | 'commit_sha'
12 | 'organization'
13 | 'project'
14 | 'registry'
15 | 'tags'
16 | 'uuid'
17 | 'version'
18 > &
19 Pick<Input, 'path'> = {
20 ...input,
21 path: '',
22 };
23
24 if (input.path && (typeof input.path !== 'string' || input.registry !== 'hey-api')) {
25 result.path = input.path;
26 return result;
27 }
28
29 const [basePath, baseQuery] = input.path.split('?');
30 const queryParts = (baseQuery || '').split('&');
31 const queryPath = queryParts.map((part) => part.split('='));
32
33 let path = basePath || '';
34 if (path.endsWith('/')) {
35 path = path.slice(0, path.length - 1);
36 }
37
38 const [, pathUrl] = path.split('://');
39 const [baseUrl, organization, project] = (pathUrl || '').split('/');
40 result.organization = organization || input.organization;
41 result.project = project || input.project;
42
43 const queryParams: Array<string> = [];
44
45 const kApiKey = 'api_key';
46 result.api_key =
47 queryPath.find(([key]) => key === kApiKey)?.[1] || input.api_key || process.env.HEY_API_TOKEN;
48 if (result.api_key) {
49 queryParams.push(`${kApiKey}=${result.api_key}`);
50 }
51
52 const kBranch = 'branch';
53 result.branch = queryPath.find(([key]) => key === kBranch)?.[1] || input.branch;
54 if (result.branch) {
55 queryParams.push(`${kBranch}=${result.branch}`);
56 }
57
58 const kCommitSha = 'commit_sha';
59 result.commit_sha = queryPath.find(([key]) => key === kCommitSha)?.[1] || input.commit_sha;
60 if (result.commit_sha) {
61 queryParams.push(`${kCommitSha}=${result.commit_sha}`);
62 }
63

Callers 3

path.test.tsFile · 0.90
createClientFunction · 0.90
createClientFunction · 0.90

Calls 4

sliceMethod · 0.80
findMethod · 0.80
pushMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected