MCPcopy Create free account
hub / github.com/callstack/agent-device / parseReplayEnvLine

Function parseReplayEnvLine

src/replay/script.ts:117–142  ·  view source on GitHub ↗
(trimmed: string, lineNumber: number)

Source from the content-addressed store, hash-verified

115}
116
117function parseReplayEnvLine(trimmed: string, lineNumber: number): { key: string; value: string } {
118 const body = trimmed.slice(3).replace(/^[\s]+/, '');
119 const eqIndex = body.indexOf('=');
120 if (eqIndex <= 0) {
121 throw new AppError(
122 'INVALID_ARGS',
123 `Invalid env directive on line ${lineNumber}: expected "env KEY=VALUE".`,
124 );
125 }
126 const key = body.slice(0, eqIndex);
127 if (!REPLAY_VAR_KEY_RE.test(key)) {
128 throw new AppError(
129 'INVALID_ARGS',
130 `Invalid env key "${key}" on line ${lineNumber}: keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`,
131 );
132 }
133 if (key.startsWith('AD_')) {
134 throw new AppError(
135 'INVALID_ARGS',
136 `Invalid env key "${key}" on line ${lineNumber}: the AD_* namespace is reserved for built-in variables. Rename ${key} to avoid the AD_ prefix.`,
137 );
138 }
139 const rawValue = body.slice(eqIndex + 1);
140 const value = decodeReplayEnvValue(rawValue, lineNumber);
141 return { key, value };
142}
143
144function decodeReplayEnvValue(raw: string, lineNumber: number): string {
145 if (raw.length === 0) return '';

Callers 1

ingestEnvLineFunction · 0.85

Calls 2

decodeReplayEnvValueFunction · 0.85
startsWithMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…