MCPcopy
hub / github.com/freshframework/fresh / applyCommandsInner

Function applyCommandsInner

packages/fresh/src/commands.ts:222–378  ·  view source on GitHub ↗
(
  root: Segment<State>,
  router: Router<Middleware<State>>,
  commands: Command<State>[],
  basePath: string,
  onError?: (err: unknown) => void,
)

Source from the content-addressed store, hash-verified

220}
221
222function applyCommandsInner<State>(
223 root: Segment<State>,
224 router: Router<Middleware<State>>,
225 commands: Command<State>[],
226 basePath: string,
227 onError?: (err: unknown) => void,
228) {
229 for (let i = 0; i < commands.length; i++) {
230 const cmd = commands[i];
231
232 switch (cmd.type) {
233 case CommandType.Middleware: {
234 const segment = getOrCreateSegment(
235 root,
236 cmd.pattern,
237 cmd.includeLastSegment,
238 );
239 segment.middlewares.push(...cmd.fns);
240 break;
241 }
242 case CommandType.NotFound: {
243 root.notFound = cmd.fn;
244 break;
245 }
246 case CommandType.Error: {
247 const segment = getOrCreateSegment(
248 root,
249 cmd.pattern,
250 cmd.includeLastSegment,
251 );
252 segment.errorRoute = cmd.item;
253 break;
254 }
255 case CommandType.App: {
256 root.app = cmd.component;
257 break;
258 }
259 case CommandType.Layout: {
260 const segment = getOrCreateSegment(
261 root,
262 cmd.pattern,
263 cmd.includeLastSegment,
264 );
265 segment.layout = {
266 component: cmd.component,
267 config: cmd.config ?? null,
268 };
269 break;
270 }
271 case CommandType.Route: {
272 const { pattern, route, config } = cmd;
273 const segment = getOrCreateSegment(
274 root,
275 pattern,
276 cmd.includeLastSegment,
277 );
278 const fns = segmentToMiddlewares(segment);
279

Callers 1

applyCommandsFunction · 0.85

Calls 9

getOrCreateSegmentFunction · 0.90
segmentToMiddlewaresFunction · 0.90
isLazyFunction · 0.90
mergePathFunction · 0.90
renderRouteFunction · 0.90
compileMiddlewaresFunction · 0.90
toRoutePathFunction · 0.90
isHandlerByMethodFunction · 0.90
addMethod · 0.65

Tested by

no test coverage detected