nexusframework 0.3.0-beta.72 → 0.3.0-beta.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE.md +55 -55
  2. package/README.md +12 -12
  3. package/about/index.json +5 -5
  4. package/about/index.nhp +4 -4
  5. package/icon.png +0 -0
  6. package/index.d.ts +12 -15
  7. package/index.js +94 -81
  8. package/index.js.map +1 -1
  9. package/index.ts +101 -89
  10. package/indexOfSkeleton.nhp +133 -133
  11. package/legacySkeleton.nhp +22 -22
  12. package/loader/overlay.css +1 -1
  13. package/loader/overlay.html +25 -25
  14. package/loader/overlay.scss +152 -152
  15. package/package.json +102 -89
  16. package/scripts/es5/compat.js +101 -0
  17. package/scripts/es5/compat.js.map +1 -0
  18. package/scripts/es5/compat.min.js +2 -0
  19. package/scripts/es5/compat.min.js.map +1 -0
  20. package/scripts/es5/loader.js +0 -0
  21. package/scripts/es5/loader.js.map +0 -0
  22. package/scripts/es5/loader.min.js +1 -1
  23. package/scripts/es5/loader.min.js.map +0 -0
  24. package/scripts/es5/nexusframeworkclient.js +1092 -1103
  25. package/scripts/es5/nexusframeworkclient.js.map +1 -1
  26. package/scripts/es5/nexusframeworkclient.min.js +1 -1
  27. package/scripts/es5/nexusframeworkclient.min.js.map +1 -1
  28. package/scripts/es6/compat.js +65 -0
  29. package/scripts/es6/compat.js.map +1 -0
  30. package/scripts/es6/compat.min.js +2 -0
  31. package/scripts/es6/compat.min.js.map +1 -0
  32. package/scripts/es6/loader.js +0 -0
  33. package/scripts/es6/loader.js.map +0 -0
  34. package/scripts/es6/loader.min.js +1 -1
  35. package/scripts/es6/loader.min.js.map +0 -0
  36. package/scripts/es6/nexusframeworkclient.js +1026 -1049
  37. package/scripts/es6/nexusframeworkclient.js.map +1 -1
  38. package/scripts/es6/nexusframeworkclient.min.js +1 -1
  39. package/scripts/es6/nexusframeworkclient.min.js.map +1 -1
  40. package/scripts/index.d.ts +259 -251
  41. package/scripts/src/compat.ts +62 -0
  42. package/scripts/src/loader.ts +385 -385
  43. package/scripts/src/nexusframeworkclient.ts +1163 -1185
  44. package/scripts/tsconfig.json +11 -11
  45. package/src/cli.d.ts +1 -0
  46. package/src/cli.js +102 -102
  47. package/src/cli.js.map +1 -1
  48. package/src/cli.ts +101 -101
  49. package/src/compileScripts.d.ts +2 -2
  50. package/src/compileScripts.js +145 -145
  51. package/src/compileScripts.js.map +1 -1
  52. package/src/compileScripts.ts +153 -153
  53. package/src/nexusframework.d.ts +177 -168
  54. package/src/nexusframework.js +3578 -3422
  55. package/src/nexusframework.js.map +1 -1
  56. package/src/nexusframework.ts +3631 -3473
  57. package/templates/basic/package.json +3 -3
  58. package/templates/basic/www/skeleton.nhp +1 -1
  59. package/templates/bootstrap/package.json +2 -2
  60. package/templates/bootstrap/www/skeleton.nhp +1 -1
  61. package/templates/bootstrap-material-design/package.json +2 -2
  62. package/templates/bootstrap-material-design/www/skeleton.nhp +1 -1
  63. package/tsconfig.json +25 -22
  64. package/types.d.ts +612 -564
package/types.d.ts CHANGED
@@ -1,564 +1,612 @@
1
- import { NexusFramework } from "./src/nexusframework";
2
- import { CacheGenerator } from "lru-weak-cache/types";
3
- import { nexusfork } from "nexusfork/types";
4
-
5
- import { Template } from "nhp/lib/Template";
6
-
7
- import { Agent, Details } from "useragent";
8
-
9
- declare interface UploadedFile {
10
- /**
11
- * The original filename when uploaded.
12
- */
13
- originalname: string,
14
- destination: string,
15
- /**
16
- * The name of the field the file was uploaded to.
17
- */
18
- fieldname: string,
19
- filename: string,
20
- mimetype: string,
21
- /**
22
- * The full path and filename where the file was uploaded to.
23
- */
24
- path: string,
25
- size: number
26
- }
27
-
28
- declare const enum BodyProcessor {
29
- URLEncoded,
30
- MultipartFormData,
31
- JSONBody
32
- }
33
-
34
- declare interface AvatarLookup {
35
- (size: number, cb: (err: Error, avatarUrl?: string) => void): void;
36
- }
37
-
38
- declare interface User {
39
- isGuest?: boolean;
40
- isAdmin?: boolean;
41
- isEditor?: boolean;
42
- isModerator?: boolean;
43
- isDeveloper?: boolean;
44
- isOwner?: boolean;
45
- level?: number;
46
-
47
- name?: string;
48
- id?: string | number;
49
- displayName?: string;
50
- email?: string;
51
-
52
- /**
53
- * Return an avatar at or above the requested size.
54
- * Or contains the only available avatar as a URL.
55
- */
56
- avatar?: string | AvatarLookup;
57
- /**
58
- * Check for a specific permission.
59
- */
60
- permission?(perm: string, cb: (err: Error, hasPermission?: boolean) => void): void;
61
- /**
62
- * Write meta data.
63
- */
64
- writeMeta?(key: string, value: any, cb: (err: Error) => void): void;
65
- /**
66
- * Read meta data.
67
- */
68
- readMeta?(key: string, cb: (err: Error, data?: any) => void): void;
69
-
70
- [key: string]: any;
71
- }
72
- declare interface StaticMountOptions {
73
- autoIndexSkeleton?: string | Template;
74
- noOtherMounts?: boolean;
75
- autoIndex?: boolean;
76
- mutable?: boolean;
77
- }
78
- declare interface Resource {
79
- source: string | URL;
80
- inline?: boolean;
81
- integrity?: string;
82
- dependencies?: string[];
83
- }
84
- declare interface Font {
85
- name: string;
86
- weight?: number;
87
- italic?: boolean;
88
- }
89
- declare interface RenderOptions {
90
- /**
91
- * The root path.
92
- */
93
- root?: string;
94
-
95
- /**
96
- * The NHP skeleton to use for this mount, relative to the root path (if set).
97
- */
98
- skeleton?: string | Template;
99
- /**
100
- * The page system skeleton to use for this mount, relative to the root path (if set).
101
- */
102
- pagesysskeleton?: string | PageSystemSkeleton;
103
- /**
104
- * The legacy NHP skeleton to use for this mount, relative to the root path (if set).
105
- */
106
- legacyskeleton?: string | Template;
107
- /**
108
- * The NHP skeleton to use for displaying folder directories, relative to the root path (if set).
109
- */
110
- autoindexskeleton?: string | Template;
111
-
112
- /**
113
- * Paths to error documents, relative to the pages of this mount.
114
- */
115
- errordoc?: {[index: string]: string};
116
-
117
- fonts?: (Font|string)[];
118
- scripts?: Resource[];
119
- styles?: Resource[];
120
-
121
- locals?: Object;
122
-
123
- /**
124
- * Paths to icons.
125
- */
126
- icons?: {[index: string]: string | URL};
127
- }
128
- declare interface ImageResizerOptions {
129
- square?: boolean;
130
- notransparency?: boolean;
131
- sizes?: number[] | number[][];
132
- cache?: number | {minAge?:number,maxAge?:number,capacity?:number,resetTimersOnAccess?:boolean} | false | undefined;
133
- diskcache?: string;
134
- }
135
- declare interface MountOptions extends RenderOptions {
136
- /**
137
- * The path to icon to use in all required sizes, relative to the root path (if set).
138
- */
139
- iconfile?: string;
140
-
141
- /**
142
- * If true, the path will be mounted with filesystem changes applied as they're detected.
143
- */
144
- mutable?: boolean;
145
- }
146
- export type FunctionOrString = Function | string;
147
- export type FunctionOrStringOrEitherWithData = FunctionOrString | {impl: FunctionOrString, data: any};
148
- declare interface PageSystemSkeleton {
149
- (template: string, options: any, req: Request, res: Response, next: (err: Error, data?: any) => void): void;
150
- }
151
- export type UserAgentDetails = Agent & Details & {es6?: boolean, legacy?: boolean};
152
- declare interface Request extends nexusfork.WebRequest {
153
- /**
154
- * The user, if any;
155
- */
156
- user?: User;
157
- /**
158
- * Information about the seragent of the request.
159
- * Provided by seragent.
160
- */
161
- useragent?: UserAgentDetails;
162
- /**
163
- * The NexusFramework instance.
164
- */
165
- nexusframework?: NexusFramework;
166
- /**
167
- * The request handler mapping.
168
- */
169
- mapping?: RequestHandlerMethodExtendedMapping;
170
- /**
171
- * An array of all the RegExp matches while processing the request.
172
- */
173
- matches?: RegExpMatchArray[];
174
- /**
175
- * The current RegExp match while procesing the request.
176
- */
177
- match?: RegExpMatchArray;
178
- /**
179
- * The current mount.
180
- */
181
- mount?: RequestHandlerEntry;
182
- /**
183
- * True when requested through the Page System API.
184
- */
185
- pagesys?: boolean;
186
- /**
187
- * The associated Socket.IO Socket, if requested through the page API and using Socket.IO.
188
- */
189
- io?: SocketIO.Socket;
190
- /**
191
- * Whether or not the client accepts webp.
192
- */
193
- webp?: boolean;
194
- /**
195
- * Either "webp" or "png" depending on the request.
196
- */
197
- webpOrPng: string;
198
- /**
199
- * Either "webp" or "jpg" depending on the request.
200
- */
201
- webpOrJpg: string;
202
- /**
203
- * Either "webp" or "gif" depending on the request.
204
- */
205
- webpOrGif: string;
206
- /**
207
- * True if this request is either .xhr or .io.
208
- */
209
- xhrOrIO?: boolean;
210
- /**
211
- * Contains an array of uploaded files.
212
- * These files are destroyed automatically when the response ends.
213
- */
214
- files?: {[index: string]: UploadedFile|UploadedFile[]};
215
- /**
216
- * Process the request body.
217
- * By default all processors are usable, and the processor chosen is determined by the request content-type header.
218
- *
219
- * @param cb The callback
220
- * @param processors The processors, all by default
221
- */
222
- processBody?(cb: (err?: Error) => void, ...processors: BodyProcessor[]): Request;
223
- /**
224
- * Read the request body to a Buffer.
225
- */
226
- readBody?(cb: (err: Error, data?: Buffer) => void, limit?: number): void;
227
- /**
228
- * The subdirectory nexusframework was requested from, if one.
229
- */
230
- buildUrl?(uri?: string): string;
231
- /**
232
- * The site url for the directory and domain nexusframework was requested from.
233
- */
234
- siteUrl?: string;
235
- /**
236
- * The subdirectory nexusframework was requested from, if one.
237
- */
238
- sitePrefix?: string;
239
- }
240
- declare interface Renderer {
241
- (out: {write: (data: string) => void},flush?:() => void): void
242
- }
243
- declare interface SocialTags {
244
- /**
245
- * The url of the page, will use the request to build this as a fallback when available
246
- */
247
- url?: string | URL;
248
- /**
249
- * The title of the page, will use res.locals.title as a fallback when available
250
- */
251
- title?: string;
252
- /**
253
- * The title of the site.
254
- */
255
- siteTitle?: string;
256
- /**
257
- * The url to an image to display for this page.
258
- */
259
- image?: string | URL;
260
- /**
261
- * The url to a relevant page.
262
- */
263
- seeAlso?: string | URL;
264
- /**
265
- * The description of this page.
266
- */
267
- description: string;
268
- /**
269
- * The type of twitter card, will use summary by default
270
- */
271
- twitterCard?: string;
272
-
273
- }
274
- declare interface Response extends nexusfork.WebResponse {
275
- renderoptions?: RenderOptions;
276
-
277
- /**
278
- * Render a page using a template engine and serve it.
279
- * This method will use the skeleton if available, `render` will not.
280
- *
281
- * @param filename The absolute path to a file to render, or template source
282
- * @param options The variables to use for rendering
283
- */
284
- sendRender(filename: string, locals?: any): Response;
285
-
286
- /**
287
- * Replace the render options for this response.
288
- */
289
- setRenderOptions(options: RenderOptions): void;
290
- /**
291
- * Override the render options for this response.
292
- */
293
- applyRenderOptions(options: RenderOptions): void;
294
-
295
- /**
296
- * Enable the NexusFramework Loader to the script queue, and defer all scripts and styles,
297
- * as well as display a configurable loading screen.
298
- */
299
- enableLoader(): void;
300
-
301
- /**
302
- * Set a meta tag in the header html.
303
- */
304
- setMetaTag(name: string, content?: string): void;
305
- setSocialTags(info: SocialTags): void;
306
-
307
- /**
308
- * Add a style to the style queue.
309
- */
310
- addStyle(url: string, integrity?: string, ...deps: string[]): void;
311
- addInlineStyle(source: string, ...deps: string[]): void;
312
- /**
313
- * Add a font from Google's library, with the specified weight.
314
- *
315
- * @param family The font family
316
- * @param weight The font weight, default 400
317
- * @param italic Italic, default false
318
- */
319
- addFont(family: string, weight?: number, italic?: boolean): void;
320
- /**
321
- * Add a renderer to the header.
322
- */
323
- addHeaderRenderer(renderer: Renderer | string): void;
324
- /**
325
- * Push the script and style queue.
326
- * Stores it for popping later.
327
- *
328
- * @param andClear And clear the queue
329
- */
330
- pushResourceQueues(andClear?: boolean): void;
331
- /**
332
- * Pops a script and style queue.
333
- */
334
- popResourceQueues(): void;
335
- clearScripts(): void;
336
- clearStyles(): void;
337
- clearFonts(): void;
338
-
339
- /**
340
- * Add a name to the body's classes.
341
- */
342
- addBodyClassName(name: string): void;
343
- /**
344
- * Remove a name to the body's classes.
345
- */
346
- removeBodyClassName(name: string): void;
347
- /**
348
- * Add a renderer after the body.
349
- */
350
- addAfterBodyRenderer(renderer: Renderer | string): void;
351
-
352
- /**
353
- * Add a renderer to the footer.
354
- */
355
- addFooterRenderer(renderer: Renderer | string): void;
356
- /**
357
- * Add a script to the script queue.
358
- */
359
- addScript(url: string, integrity?: string, ...deps: string[]): void;
360
- addInlineScript(source: string, ...deps: string[]): void;
361
- /**
362
- * Add the Socket.IO Client to the script queue.
363
- */
364
- addSocketIOClient(): void;
365
- /**
366
- * Add the NexusFramework Client to the script queue.
367
- *
368
- * @param includeSocketIO Whether or not to include and rely on Socket.IO, true by default
369
- * @param autoEnablePageSystem Whether or not to enable the page system automatically, false by default
370
- */
371
- addNexusFrameworkClient(includeSocketIO?: boolean, autoEnablePageSystem?: boolean): void;
372
-
373
- /**
374
- * Write the header html to the stream.
375
- * Try to position this just before the ending </head> tag.
376
- */
377
- writeHeaderHtml(out?: NodeJS.WritableStream): void;
378
- /**
379
- * Write the after body html to the stream.
380
- * Try to position this just after the <body> tag.
381
- */
382
- writeAfterBodyHtml(out?: NodeJS.WritableStream): void;
383
- /**
384
- * Write the footer html to the stream.
385
- * Try to position this just before the ending </body> tag.
386
- */
387
- sendFooterHtml(out?: NodeJS.WritableStream): void;
388
-
389
- /**
390
- * Retreive the data used by NexusFrameworkLoader.load().
391
- */
392
- getLoaderData(): any;
393
- }
394
- declare interface RequestHandler {
395
- (req: Request, res: Response, next: (err?: Error) => void): void;
396
- }
397
- declare interface NHPRequestHandler {
398
- (req: Request, res: Response, next: (err?: Error, renderLocals?: any) => void): void;
399
- }
400
- declare interface RequestHandlerMethodMapping {
401
- use?: NHPRequestHandler;
402
- get?: NHPRequestHandler;
403
- put?: NHPRequestHandler;
404
- post?: NHPRequestHandler;
405
- head?: NHPRequestHandler;
406
- patch?: NHPRequestHandler;
407
- del?: NHPRequestHandler;
408
- }
409
- declare interface RequestHandlerMethodExtendedMapping extends RequestHandlerMethodMapping {
410
- exists?: ExistsRequestHandler;
411
- access?: AccessRequestHandler;
412
- }
413
- declare interface MappedRequestHandler extends RequestHandler, RequestHandlerMethodMapping {}
414
- declare interface ExtendedMappedRequestHandler extends RequestHandler, RequestHandlerMethodExtendedMapping {}
415
- declare interface ExistsRequestHandler {
416
- (req: Request, res: Response, exists: (err?: Error) => void, doesntExist: () => void): void;
417
- }
418
- declare interface RouteRequestHandler {
419
- (req: Request, res: Response, next: (err?: Error, routedpath?: string) => void, skip: () => void): void;
420
- }
421
- declare interface AccessRequestHandler {
422
- (req: Request, res: Response, allowed: (err?: Error) => void, denied: () => void): void;
423
- }
424
- declare interface Handler {
425
- (req: Request, res: Response, next?: (err: Error) => void): void;
426
- }
427
- interface RecursivePath {
428
- [0]: string;
429
- [index: number]: RecursivePath | string;
430
- }
431
- interface RequestHandlerEntry {
432
- readonly leaf?: boolean;
433
- handle: RequestHandler;
434
-
435
- /**
436
- * Fetches children for this entry.
437
- */
438
- children(): RequestHandlerChildEntry[];
439
- /**
440
- * Fetches the paths for children of this entry.
441
- */
442
- childPaths(cb: (paths: string[]) => void, deep?: false): void;
443
- /**
444
- * Fetches the paths for children of this entry recursively.
445
- */
446
- childPaths(cb: (paths: (RecursivePath | string)[]) => void, deep: true): void;
447
- /**
448
- * Fetches the child at path.
449
- *
450
- * @param path The path to search.
451
- * @param createIfNotExists Whether or not to create the path if it doesn't exist.
452
- */
453
- childAt(path: string, createIfNotExists?: boolean): RequestHandlerChildEntry;
454
- /**
455
- * Fetches the child at path.
456
- *
457
- * @param path The path.
458
- * @param handler The handler to set.
459
- * @param createIfNotExists Whether or not to create the path if it doesn't exist, true by default.
460
- */
461
- setChild(path: string, handler: RequestHandlerChildEntry, createIfNotExists?: boolean): void;
462
-
463
- /**
464
- * Fetches the view filename.
465
- *
466
- * @param type The type of view to fetch, by default its "nhp".
467
- */
468
- view(type?: string): string;
469
- /**
470
- * Set the view filename for type.
471
- *
472
- * @param filename The view filename
473
- * @param type The type of view to set, by default its "nhp".
474
- */
475
- setView(filename: string, type?: string): void;
476
-
477
- /**
478
- * Fetches the index handler for this entry.
479
- */
480
- index(): RequestHandlerEntry;
481
- /**
482
- * Set the index handler for this entry.
483
- */
484
- setIndex(index: RequestHandlerEntry): void;
485
-
486
- /**
487
- * Fetches the route resolver for this entry.
488
- */
489
- routeHandler(): RouteRequestHandler;
490
- /**
491
- * Fetches the access handler for this entry.
492
- */
493
- accessHandler(): AccessRequestHandler;
494
- /**
495
- * Fetches the existence handler for this entry.
496
- */
497
- existsHandler(): ExistsRequestHandler;
498
- /**
499
- * Set the route resolver for this entry.
500
- */
501
- setRouteHandler(index: RouteRequestHandler): void;
502
- /**
503
- * Set the access handler for this entry.
504
- */
505
- setAccessHandler(index: AccessRequestHandler): void;
506
- /**
507
- * Set the existence handler for this entry.
508
- */
509
- setExistsHandler(index: ExistsRequestHandler): void;
510
- /**
511
- * Destroy this entry and all children
512
- */
513
- destroy(): void;
514
- }
515
- interface RequestHandlerChildEntry extends RequestHandlerEntry {
516
- readonly pattern: RegExp;
517
- readonly rawPattern: string;
518
- }
519
- declare interface Mount extends MountOptions {
520
- /**
521
- * The filesystem path.
522
- */
523
- fspath: string;
524
- /**
525
- * The web path.
526
- */
527
- webpath: string;
528
- }
529
- declare interface Config extends MountOptions {
530
- /**
531
- * The pages path, relative to the root path.
532
- * Default "pages"
533
- */
534
- pages?: string;
535
- /**
536
- * The URL prefix
537
- * Default "/"
538
- */
539
- prefix?: string;
540
- /**
541
- * When true, the loader will not be enabled for compatible browsers.
542
- * The loader is required for the dynamic page system.
543
- */
544
- noloader?: boolean;
545
- /**
546
- * When true, scripts will not be served on {{prefix}}/:scripts
547
- */
548
- noscripts?: boolean;
549
- /**
550
- * When true, about will not be served on {{prefix}}/:about
551
- */
552
- noabout?: boolean;
553
- /**
554
- * When true, disables logging.
555
- */
556
- nologging?: boolean;
557
- /**
558
- * When true, no Socket.IO instance will be created on {{prefix}}/:io
559
- */
560
- noio?: boolean;
561
- mounts?: Mount[] | Mount;
562
- modules?: string[] | string;
563
- [key: string]: any;
564
- }
1
+ import { NexusFramework } from "./src/nexusframework";
2
+ import { CacheGenerator } from "lru-weak-cache/types";
3
+ import { nexusfork } from "nexusfork/types";
4
+
5
+ import { Template } from "nhp/lib/Template";
6
+
7
+ import { Agent, Details } from "useragent";
8
+
9
+ declare interface UploadedFile {
10
+ /**
11
+ * The original filename when uploaded.
12
+ */
13
+ originalname: string,
14
+ destination: string,
15
+ /**
16
+ * The name of the field the file was uploaded to.
17
+ */
18
+ fieldname: string,
19
+ filename: string,
20
+ mimetype: string,
21
+ /**
22
+ * The full path and filename where the file was uploaded to.
23
+ */
24
+ path: string,
25
+ size: number
26
+ }
27
+
28
+ declare const enum BodyProcessor {
29
+ URLEncoded,
30
+ MultipartFormData,
31
+ JSONBody
32
+ }
33
+
34
+ declare interface AvatarFormats {
35
+ webp: string;
36
+ gif?: string;
37
+ png?: string;
38
+ jpg?: string;
39
+ }
40
+
41
+ declare interface AvatarSizes {
42
+ icon: AvatarFormats;
43
+ small: AvatarFormats;
44
+ medium: AvatarFormats;
45
+ large: AvatarFormats;
46
+ huge: AvatarFormats;
47
+ }
48
+
49
+ declare interface AvatarLookup extends AvatarSizes {
50
+ ["x2"]: AvatarSizes
51
+ ["x3"]: AvatarSizes
52
+ ["x4"]: AvatarSizes
53
+ }
54
+
55
+ declare interface User {
56
+ name?: string;
57
+ id?: string | number;
58
+ displayName?: string;
59
+ email?: string;
60
+
61
+ /**
62
+ * Return an avatar at or above the requested size.
63
+ * Or contains the only available avatar as a URL.
64
+ */
65
+ avatar?: string | AvatarLookup;
66
+ }
67
+ declare interface StaticMountOptions {
68
+ autoIndexSkeleton?: string | Template;
69
+ noOtherMounts?: boolean;
70
+ autoIndex?: boolean;
71
+ mutable?: boolean;
72
+ }
73
+ declare interface Resource {
74
+ source: string | URL;
75
+ inline?: boolean;
76
+ integrity?: string;
77
+ dependencies?: string[];
78
+ }
79
+ declare interface Font {
80
+ name: string;
81
+ weight?: number;
82
+ italic?: boolean;
83
+ }
84
+ declare interface RenderOptions {
85
+ /**
86
+ * The root path.
87
+ */
88
+ root?: string;
89
+
90
+ /**
91
+ * The NHP skeleton to use for this mount, relative to the root path (if set).
92
+ */
93
+ skeleton?: string | Template;
94
+ /**
95
+ * The page system skeleton to use for this mount, relative to the root path (if set).
96
+ */
97
+ pagesysskeleton?: string | PageSystemSkeleton;
98
+ /**
99
+ * The legacy NHP skeleton to use for this mount, relative to the root path (if set).
100
+ */
101
+ legacyskeleton?: string | Template;
102
+ /**
103
+ * The NHP skeleton to use for displaying folder directories, relative to the root path (if set).
104
+ */
105
+ autoindexskeleton?: string | Template;
106
+
107
+ /**
108
+ * Paths to error documents, relative to the pages of this mount.
109
+ */
110
+ errordoc?: {[index: string]: string};
111
+
112
+ fonts?: (Font|string)[];
113
+ scripts?: Resource[];
114
+ styles?: Resource[];
115
+
116
+ locals?: ResponseLocals<User>;
117
+
118
+ /**
119
+ * Paths to icons.
120
+ */
121
+ icons?: {[index: string]: string | URL};
122
+ }
123
+ declare interface ImageResizerOptions {
124
+ square?: boolean;
125
+ notransparency?: boolean;
126
+ sizes?: number[] | number[][];
127
+ cache?: number | {minAge?:number,maxAge?:number,capacity?:number,resetTimersOnAccess?:boolean} | false | undefined;
128
+ diskcache?: string;
129
+ }
130
+ declare interface MountOptions extends RenderOptions {
131
+ /**
132
+ * The path to icon to use in all required sizes, relative to the root path (if set).
133
+ */
134
+ iconfile?: string;
135
+
136
+ /**
137
+ * If true, the path will be mounted with filesystem changes applied as they're detected.
138
+ */
139
+ mutable?: boolean;
140
+ }
141
+ export type ApiTypes = ("bson" | "json" | "debug" | "xml");
142
+ export type FunctionOrString = Function | string;
143
+ export type FunctionOrStringOrEitherWithData = FunctionOrString | {impl: FunctionOrString, data: any};
144
+ declare interface PageSystemSkeleton {
145
+ (template: string, options: any, req: Request, res: Response, next: (err: Error, data?: any) => void): void;
146
+ }
147
+ export type UserAgentDetails = Agent & Details & {es6?: boolean, legacy?: boolean};
148
+ declare interface BaseLocals<U extends User> {
149
+ /**
150
+ * The user, if any;
151
+ */
152
+ user?: U;
153
+ /**
154
+ * Information about the seragent of the request.
155
+ * Provided by seragent.
156
+ */
157
+ useragent?: UserAgentDetails;
158
+ /**
159
+ * Whether or not the client accepts webp.
160
+ */
161
+ webp?: boolean;
162
+ /**
163
+ * Either "webp" or "png" depending on the request.
164
+ */
165
+ webpOrPng?: string;
166
+ /**
167
+ * Either "webp" or "jpg" depending on the request.
168
+ */
169
+ webpOrJpg?: string;
170
+ /**
171
+ * Either "webp" or "gif" depending on the request.
172
+ */
173
+ webpOrGif?: string;
174
+ /**
175
+ * The site url for the directory and domain nexusframework was requested from.
176
+ */
177
+ siteUrl?: string;
178
+ /**
179
+ * The subdirectory nexusframework was requested from, if one.
180
+ */
181
+ sitePrefix?: string;
182
+ }
183
+ declare interface Request<U extends User> extends BaseLocals<U>, nexusfork.WebRequest {
184
+ res: Response<ResponseLocals<U>>;
185
+ /**
186
+ * The NexusFramework instance.
187
+ */
188
+ nexusframework?: NexusFramework;
189
+ /**
190
+ * The request handler mapping.
191
+ */
192
+ mapping?: RequestHandlerMethodExtendedMapping;
193
+ /**
194
+ * An array of all the RegExp matches while processing the request.
195
+ */
196
+ matches?: RegExpMatchArray[];
197
+ /**
198
+ * The current RegExp match while procesing the request.
199
+ */
200
+ match?: RegExpMatchArray;
201
+ /**
202
+ * The current mount.
203
+ */
204
+ mount?: RequestHandlerEntry;
205
+ /**
206
+ * True when requested through the Page System API.
207
+ */
208
+ pagesys?: boolean;
209
+ /**
210
+ * The associated Socket.IO Socket, if requested through the page API and using Socket.IO.
211
+ */
212
+ io?: SocketIO.Socket;
213
+ /**
214
+ * The API encoder being used for this request, if any.
215
+ */
216
+ api?: ApiTypes;
217
+ /**
218
+ * True if this request is either .xhr or .io.
219
+ */
220
+ xhrOrIO?: boolean;
221
+ /**
222
+ * Contains an array of uploaded files.
223
+ * These files are destroyed automatically when the response ends.
224
+ */
225
+ files?: {[index: string]: UploadedFile|UploadedFile[]};
226
+ /**
227
+ * Process the request body.
228
+ * By default all processors are usable, and the processor chosen is determined by the request content-type header.
229
+ *
230
+ * @param cb The callback
231
+ * @param processors The processors, all by default
232
+ */
233
+ processBody?(cb: (err?: Error) => void, ...processors: BodyProcessor[]): Request;
234
+ /**
235
+ * Read the request body to a Buffer.
236
+ */
237
+ readBody?(cb: (err: Error, data?: Buffer) => void, limit?: number): void;
238
+ /**
239
+ * The subdirectory nexusframework was requested from, if one.
240
+ */
241
+ buildUrl?(uri?: string): string;
242
+ }
243
+ declare interface Renderer {
244
+ (out: {write: (data: string) => void},flush?:() => void): void
245
+ }
246
+ declare interface SocialTags {
247
+ /**
248
+ * The url of the page, will use the request to build this as a fallback when available
249
+ */
250
+ url?: string | URL;
251
+ /**
252
+ * The title of the page, will use res.locals.title as a fallback when available
253
+ */
254
+ title?: string;
255
+ /**
256
+ * The title of the site.
257
+ */
258
+ siteTitle?: string;
259
+ /**
260
+ * The url to an image to display for this page.
261
+ */
262
+ image?: string | URL;
263
+ /**
264
+ * The url to a relevant page.
265
+ */
266
+ seeAlso?: string | URL;
267
+ /**
268
+ * The description of this page.
269
+ */
270
+ description: string;
271
+ /**
272
+ * The type of twitter card, will use summary by default
273
+ */
274
+ twitterCard?: string;
275
+
276
+ }
277
+ declare interface ResponseLocals<U extends User> extends BaseLocals<U> {
278
+ [key: string]: any;
279
+ }
280
+ declare interface Response<U extends User, L extends ResponseLocals<U>> extends nexusfork.WebResponse {
281
+ locals: L;
282
+ req: Request<U>;
283
+ renderoptions?: RenderOptions;
284
+
285
+ /**
286
+ * Render a page using a template engine and serve it.
287
+ * This method will use the skeleton if available, `render` will not.
288
+ *
289
+ * @param filename The absolute path to a file to render, or template source
290
+ * @param options The variables to use for rendering
291
+ */
292
+ sendRender(filename: string, locals?: any): Response;
293
+
294
+ /**
295
+ * Replace the render options for this response.
296
+ */
297
+ setRenderOptions(options: RenderOptions): void;
298
+ /**
299
+ * Override the render options for this response.
300
+ */
301
+ applyRenderOptions(options: RenderOptions): void;
302
+
303
+ /**
304
+ * Enable the NexusFramework Loader to the script queue, and defer all scripts and styles,
305
+ * as well as display a configurable loading screen.
306
+ */
307
+ enableLoader(): void;
308
+
309
+ /**
310
+ * Set a meta tag in the header html.
311
+ */
312
+ setMetaTag(name: string, content?: string): void;
313
+ setSocialTags(info: SocialTags): void;
314
+
315
+ /**
316
+ * Add a style to the style queue.
317
+ */
318
+ addStyle(url: string, integrity?: string, ...deps: string[]): void;
319
+ addInlineStyle(source: string, ...deps: string[]): void;
320
+ /**
321
+ * Add a font from Google's library, with the specified weight.
322
+ *
323
+ * @param family The font family
324
+ * @param weight The font weight, default 400
325
+ * @param italic Italic, default false
326
+ */
327
+ addFont(family: string, weight?: number, italic?: boolean): void;
328
+ /**
329
+ * Add a renderer to the header.
330
+ */
331
+ addHeaderRenderer(renderer: Renderer | string): void;
332
+ /**
333
+ * Push the script and style queue.
334
+ * Stores it for popping later.
335
+ *
336
+ * @param andClear And clear the queue
337
+ */
338
+ pushResourceQueues(andClear?: boolean): void;
339
+ /**
340
+ * Pops a script and style queue.
341
+ */
342
+ popResourceQueues(): void;
343
+ clearScripts(): void;
344
+ clearStyles(): void;
345
+ clearFonts(): void;
346
+
347
+ /**
348
+ * Add a name to the body's classes.
349
+ */
350
+ addBodyClassName(name: string): void;
351
+ /**
352
+ * Remove a name to the body's classes.
353
+ */
354
+ removeBodyClassName(name: string): void;
355
+ /**
356
+ * Add a renderer after the body.
357
+ */
358
+ addAfterBodyRenderer(renderer: Renderer | string): void;
359
+
360
+ /**
361
+ * Add a renderer to the footer.
362
+ */
363
+ addFooterRenderer(renderer: Renderer | string): void;
364
+ /**
365
+ * Add a script to the script queue.
366
+ */
367
+ addScript(url: string, integrity?: string, ...deps: string[]): void;
368
+ addInlineScript(source: string, ...deps: string[]): void;
369
+ /**
370
+ * Add the Socket.IO Client to the script queue.
371
+ */
372
+ addSocketIOClient(): void;
373
+ /**
374
+ * Add the NexusFramework Client to the script queue.
375
+ *
376
+ * @param includeSocketIO Whether or not to include and rely on Socket.IO, true by default
377
+ * @param autoEnablePageSystem Whether or not to enable the page system automatically, false by default
378
+ */
379
+ addNexusFrameworkClient(includeSocketIO?: boolean, autoEnablePageSystem?: boolean): void;
380
+
381
+ /**
382
+ * Write the header html to the stream.
383
+ * Try to position this just before the ending </head> tag.
384
+ */
385
+ writeHeaderHtml(out?: NodeJS.WritableStream): void;
386
+ /**
387
+ * Write the after body html to the stream.
388
+ * Try to position this just after the <body> tag.
389
+ */
390
+ writeAfterBodyHtml(out?: NodeJS.WritableStream): void;
391
+ /**
392
+ * Write the footer html to the stream.
393
+ * Try to position this just before the ending </body> tag.
394
+ */
395
+ sendFooterHtml(out?: NodeJS.WritableStream): void;
396
+
397
+ /**
398
+ * Retreive the data used by NexusFrameworkLoader.load().
399
+ */
400
+ getLoaderData(): any;
401
+ }
402
+ declare interface RequestHandler<I extends Request<User>, O extends Response<User>> {
403
+ (req: I, res: O, next: (err?: Error) => void): void;
404
+ }
405
+ declare interface NHPRequestHandler<I extends Request<User>, O extends Response<User>> {
406
+ (req: I, res: O, next: (err?: Error, renderLocals?: any) => void): void;
407
+ }
408
+ declare interface RequestHandlerMethodMapping {
409
+ use?: NHPRequestHandler<any, any>;
410
+ get?: NHPRequestHandler<any, any>;
411
+ put?: NHPRequestHandler<any, any>;
412
+ post?: NHPRequestHandler<any, any>;
413
+ head?: NHPRequestHandler<any, any>;
414
+ patch?: NHPRequestHandler<any, any>;
415
+ del?: NHPRequestHandler<any, any>;
416
+ }
417
+ declare interface RequestHandlerMethodExtendedMapping extends RequestHandlerMethodMapping {
418
+ exists?: ExistsRequestHandler<any, any>;
419
+ access?: AccessRequestHandler<any, any>;
420
+ }
421
+ declare interface MappedRequestHandler extends RequestHandler<any, any>, RequestHandlerMethodMapping {}
422
+ declare interface ExtendedMappedRequestHandler extends RequestHandler<any, any>, RequestHandlerMethodExtendedMapping {}
423
+ declare interface ExistsRequestHandler<I extends Request<User>, O extends Response<User>> {
424
+ (req: I, res: O, exists: (err?: Error) => void, doesntExist: () => void): void;
425
+ }
426
+ declare interface RouteRequestHandler<I extends Request<User>, O extends Response<User>> {
427
+ (req: I, res: O, next: (err?: Error, routedpath?: string) => void, skip: () => void): void;
428
+ }
429
+ declare interface AccessRequestHandler<I extends Request<User>, O extends Response<User>> {
430
+ (req: I, res: O, allowed: (err?: Error) => void, denied: () => void): void;
431
+ }
432
+ declare interface Handler<I extends Request<User>, O extends Response<User>> {
433
+ (req: I, res: O, next?: (err: Error) => void): void;
434
+ }
435
+ interface RecursivePath {
436
+ [0]: string;
437
+ [index: number]: RecursivePath | string;
438
+ }
439
+ interface RequestHandlerEntry {
440
+ readonly leaf?: boolean;
441
+ handle: RequestHandler;
442
+
443
+ /**
444
+ * Fetches children for this entry.
445
+ */
446
+ children(): RequestHandlerChildEntry[];
447
+ /**
448
+ * Fetches the paths for children of this entry.
449
+ */
450
+ childPaths(cb: (paths: string[]) => void, deep?: false): void;
451
+ /**
452
+ * Fetches the paths for children of this entry recursively.
453
+ */
454
+ childPaths(cb: (paths: (RecursivePath | string)[]) => void, deep: true): void;
455
+ /**
456
+ * Fetches the child at path.
457
+ *
458
+ * @param path The path to search.
459
+ * @param createIfNotExists Whether or not to create the path if it doesn't exist.
460
+ */
461
+ childAt(path: string, createIfNotExists?: boolean): RequestHandlerChildEntry;
462
+ /**
463
+ * Fetches the child at path.
464
+ *
465
+ * @param path The path.
466
+ * @param handler The handler to set.
467
+ * @param createIfNotExists Whether or not to create the path if it doesn't exist, true by default.
468
+ */
469
+ setChild(path: string, handler: RequestHandlerChildEntry, createIfNotExists?: boolean): void;
470
+
471
+ /**
472
+ * Fetches the view filename.
473
+ *
474
+ * @param type The type of view to fetch, by default its "nhp".
475
+ */
476
+ view(type?: string): string;
477
+ /**
478
+ * Set the view filename for type.
479
+ *
480
+ * @param filename The view filename
481
+ * @param type The type of view to set, by default its "nhp".
482
+ */
483
+ setView(filename: string, type?: string): void;
484
+
485
+ /**
486
+ * Fetches the index handler for this entry.
487
+ */
488
+ index(): RequestHandlerEntry;
489
+ /**
490
+ * Set the index handler for this entry.
491
+ */
492
+ setIndex(index: RequestHandlerEntry): void;
493
+
494
+ /**
495
+ * Fetches the route resolver for this entry.
496
+ */
497
+ routeHandler(): RouteRequestHandler;
498
+ /**
499
+ * Fetches the access handler for this entry.
500
+ */
501
+ accessHandler(): AccessRequestHandler;
502
+ /**
503
+ * Fetches the existence handler for this entry.
504
+ */
505
+ existsHandler(): ExistsRequestHandler;
506
+ /**
507
+ * Set the route resolver for this entry.
508
+ */
509
+ setRouteHandler(index: RouteRequestHandler): void;
510
+ /**
511
+ * Set the access handler for this entry.
512
+ */
513
+ setAccessHandler(index: AccessRequestHandler): void;
514
+ /**
515
+ * Set the existence handler for this entry.
516
+ */
517
+ setExistsHandler(index: ExistsRequestHandler): void;
518
+ /**
519
+ * Destroy this entry and all children
520
+ */
521
+ destroy(): void;
522
+ }
523
+ interface RequestHandlerChildEntry extends RequestHandlerEntry {
524
+ readonly pattern: RegExp;
525
+ readonly rawPattern: string;
526
+ }
527
+ type APIEncoder<U extends User, L extends ResponseLocals<U>> = (locals: L, req: Request<U>, res: Response<L>) => void;
528
+ declare interface Mount extends MountOptions {
529
+ /**
530
+ * The filesystem path.
531
+ */
532
+ fspath: string;
533
+ /**
534
+ * The web path.
535
+ */
536
+ webpath: string;
537
+ }
538
+ declare interface APIResponse {
539
+ code: number;
540
+ warnings?: string[];
541
+ error?: {
542
+ type: string,
543
+ message: string,
544
+ stack: string
545
+ };
546
+
547
+ [key: string]: any;
548
+ }
549
+ declare interface Config extends MountOptions {
550
+ /**
551
+ * The pages path, relative to the root path.
552
+ * Default "pages"
553
+ */
554
+ pages?: string;
555
+ /**
556
+ * The URL prefix
557
+ * Default "/"
558
+ */
559
+ prefix?: string;
560
+ /**
561
+ * When true, the loader will not be enabled for compatible browsers.
562
+ * The loader is required for the dynamic page system.
563
+ */
564
+ noloader?: boolean;
565
+ /**
566
+ * When true, scripts will not be served on {{prefix}}/:scripts
567
+ */
568
+ noscripts?: boolean;
569
+ /**
570
+ * When true, about will not be served on {{prefix}}/:about
571
+ */
572
+ noabout?: boolean;
573
+ /**
574
+ * When true, disables logging.
575
+ */
576
+ nologging?: boolean;
577
+ /**
578
+ * When true, no Socket.IO instance will be created on {{prefix}}/:io
579
+ */
580
+ noio?: boolean;
581
+ /**
582
+ * When true, no API support will be installed
583
+ */
584
+ noapi?: boolean;
585
+ /**
586
+ * When true, serves the socket.io library to guests too.
587
+ */
588
+ guestio?: boolean;
589
+ /**
590
+ * When true, enables the page system over Socket.IO
591
+ */
592
+ iopagesys?: boolean;
593
+ /**
594
+ * Override the socket.io path
595
+ */
596
+ iopath?: string;
597
+ /**
598
+ * When true, the page system will not be initialized
599
+ */
600
+ nopagesys?: boolean;
601
+ /**
602
+ * Any items in this array are disabled from the built-in API encoders
603
+ */
604
+ apiblacklist?: ApiTypes[];
605
+ /**
606
+ * Any items in this array are filtered from the response of API calls
607
+ */
608
+ apifilter?: string[];
609
+ mounts?: Mount[] | Mount;
610
+ modules?: string[] | string;
611
+ [key: string]: any;
612
+ }