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

Method add

packages/fresh/src/router.ts:69–111  ·  view source on GitHub ↗
(
    method: Method,
    pathname: string,
    item: T,
  )

Source from the content-addressed store, hash-verified

67 }
68
69 add(
70 method: Method,
71 pathname: string,
72 item: T,
73 ) {
74 let allowed = this.#allowed.get(pathname);
75 if (allowed === undefined) {
76 allowed = new Set();
77 this.#allowed.set(pathname, allowed);
78 }
79
80 allowed.add(method);
81
82 let byMethod: RouteByMethod<T>;
83 if (IS_PATTERN.test(pathname)) {
84 let def = this.#dynamics.get(pathname);
85 if (def === undefined) {
86 def = {
87 pattern: new URLPattern({ pathname }),
88 byMethod: newByMethod(),
89 };
90 this.#dynamics.set(pathname, def);
91 this.#dynamicArr.push(def);
92 }
93
94 byMethod = def.byMethod;
95 } else {
96 let def = this.#statics.get(pathname);
97 if (def === undefined) {
98 def = {
99 pattern: pathname,
100 byMethod: newByMethod(),
101 };
102 this.#statics.set(pathname, def);
103 }
104
105 byMethod = def.byMethod;
106 }
107
108 if (byMethod[method] === null) {
109 byMethod[method] = item;
110 }
111 }
112
113 match(method: Method, url: URL): RouteResult<T> {
114 const result: RouteResult<T> = {

Callers

nothing calls this directly

Calls 3

newByMethodFunction · 0.85
addMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected