• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stackpress / ingest / 26180421512

20 May 2026 05:58PM UTC coverage: 68.006% (-2.0%) from 70.019%
26180421512

push

github

cblanquera
"version bump"

139 of 230 branches covered (60.43%)

Branch coverage included in aggregate %.

318 of 442 relevant lines covered (71.95%)

8.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.5
/ingest/src/plugin/EntryRouter.ts
1
//stackpress
2
import type { Method } from '@stackpress/lib/types';
3
//common
4
import type { 
5
  EntryRouterTaskItem,
6
  ActionRouterArgs,
7
  ActionRouterAction,
8
  ActionRouterListener
9
} from '../types.js';
10
//local
11
import type ActionRouter from './ActionRouter.js';
12
export default class EntryRouter<R, S, X, C = unknown, P = unknown>  {
13
  //A route map to task queues
14
  //event -> [ ...{ entry, priority } ]
15
  public readonly entries = new Map<string, Set<EntryRouterTaskItem>>();
29✔
16
  //parent router
17
  protected _router: ActionRouter<R, S, X, C, P>;
18
  //listener straight to the end
19
  protected _listen: ActionRouterListener<R, S, X, C, P>;
20

21
  /**
22
   * Sets the router
23
   */
24
  public constructor(
25
    router: ActionRouter<R, S, X, C, P>,
26
    listen: ActionRouterListener<R, S, X, C, P>
27
  ) {
28
    this._router = router;
29✔
29
    this._listen = listen;
29✔
30
  }
31

32
  /**
33
   * Makes an action from an entry pathname string
34
   * Register the entry, a provision for builders
35
   */
36
  public action(event: string, action: string, priority = 0) {
×
37
    //if the listener group does not exist, create it
38
    if (!this.entries.has(event)) {
×
39
      this.entries.set(event, new Set());
×
40
    }
41
    //add the listener to the group
42
    this.entries.get(event)?.add({ entry: action, priority });
×
43
    //return the new action
44
    return async function EntryFileAction(
×
45
      ...[ props ]: ActionRouterArgs<R, S, X, C, P>
46
    ) {
47
      //import the action
48
      const imports = await import(action) as { 
×
49
        default: ActionRouterAction<R, S, X, C, P> 
50
      };
51
      //get the default export
52
      const callback = imports.default;
×
53
      //run the action
54
      return await callback(props);
×
55
    }
56
  }
57
  
58
  /**
59
   * Route for any method
60
   */
61
  public all(
62
    path: string, 
63
    action: string, 
64
    priority?: number
65
  ) {
66
    return this.route('ALL', path, action, priority);
×
67
  }
68

69
  /**
70
   * Route for CONNECT method
71
   */
72
  public connect(
73
    path: string, 
74
    action: string, 
75
    priority?: number
76
  ) {
77
    return this.route('CONNECT', path, action, priority);
×
78
  }
79

80
  /**
81
   * Route for DELETE method
82
   */
83
  public delete(
84
    path: string, 
85
    action: string, 
86
    priority?: number
87
  ) {
88
    return this.route('DELETE', path, action, priority);
×
89
  }
90

91
  /**
92
   * Route for GET method
93
   */
94
  public get(
95
    path: string, 
96
    action: string, 
97
    priority?: number
98
  ) {
99
    return this.route('GET', path, action, priority);
×
100
  }
101

102
  /**
103
   * Route for HEAD method
104
   */
105
  public head(
106
    path: string, 
107
    action: string, 
108
    priority?: number
109
  ) {
110
    return this.route('HEAD', path, action, priority);
×
111
  }
112
  
113
  /**
114
   * Adds a callback to the given event listener
115
   */
116
  public on(
117
    event: string|RegExp, 
118
    entry: string,
119
    priority = 0
×
120
  ) {
121
    const key = this._router.eventName(event);
×
122
    const action = this.action(key, entry, priority);
×
123
    this._listen(key, action, priority);
×
124
    return this;
×
125
  }
126

127
  /**
128
   * Route for OPTIONS method
129
   */
130
  public options(
131
    path: string, 
132
    action: string, 
133
    priority?: number
134
  ) {
135
    return this.route('OPTIONS', path, action, priority);
×
136
  }
137

138
  /**
139
   * Route for PATCH method
140
   */
141
  public patch(
142
    path: string, 
143
    action: string, 
144
    priority?: number
145
  ) {
146
    return this.route('PATCH', path, action, priority);
×
147
  }
148

149
  /**
150
   * Route for POST method
151
   */
152
  public post(
153
    path: string, 
154
    action: string, 
155
    priority?: number
156
  ) {
157
    return this.route('POST', path, action, priority);
×
158
  }
159

160
  /**
161
   * Route for PUT method
162
   */
163
  public put(
164
    path: string, 
165
    action: string, 
166
    priority?: number
167
  ) {
168
    return this.route('PUT', path, action, priority);
×
169
  }
170

171
  /**
172
   * Returns a route
173
   */
174
  public route(
175
    method: Method, 
176
    path: string, 
177
    entry: string, 
178
    priority = 0
×
179
  ) {
180
    const event = this._router.eventName(method, path);
×
181
    const action = this.action(event, entry, priority);
×
182
    this._listen(event, action, priority);
×
183
    return this;
×
184
  }
185

186
  /**
187
   * Route for TRACE method
188
   */
189
  public trace(
190
    path: string, 
191
    action: string, 
192
    priority?: number
193
  ) {
194
    return this.route('TRACE', path, action, priority);
×
195
  }
196
  
197
  /**
198
   * Allows entries from other routers to apply here
199
   */
200
  public use(router: EntryRouter<R, S, X, C, P>) {
201
    //first concat their routes with this one
202
    //event -> [ ...{ entry, priority } ]
203
    router.entries.forEach((tasks, event) => {
1✔
204
      //if the listener group does not exist
205
      if (!this.entries.has(event)) {
×
206
        //create the listener group
207
        this.entries.set(event, new Set());
×
208
      }
209
      //add all the tasks to the listener group
210
      //[ ...{ entry, priority } ]
211
      //NOTE: possible duplicate tasks
212
      tasks.forEach(task => this.entries.get(event)?.add(task));
×
213
    });
214
    return this;
1✔
215
  }
216
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc