primate 0.29.0 → 0.29.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.29.0",
3
+ "version": "0.29.2",
4
4
  "description": "Polymorphic development platform",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
@@ -19,7 +19,7 @@
19
19
  "directory": "packages/primate"
20
20
  },
21
21
  "dependencies": {
22
- "rcompat": "^0.7.2"
22
+ "rcompat": "^0.8.0"
23
23
  },
24
24
  "engines": {
25
25
  "node": ">=18"
package/src/errors.json CHANGED
@@ -91,9 +91,9 @@
91
91
  "fix": "add configuration options or remove file",
92
92
  "level": "Warn"
93
93
  },
94
- "NoHandlerForExtension": {
95
- "message": "no handler for {0} extension",
96
- "fix": "add handler module for {0} files or remove {1}",
94
+ "NoHandlerForComponent": {
95
+ "message": "no handler for {0}",
96
+ "fix": "add handler module for this component or remove {0}",
97
97
  "level": "Error"
98
98
  },
99
99
  "NoRouteToPath": {
package/src/handlers.js CHANGED
@@ -67,11 +67,12 @@ const html = (name, options) => async app => {
67
67
  };
68
68
  // }}}
69
69
  // {{{ view
70
- const view = (name, props, options) => async (app, ...rest) => {
71
- const { fullExtension: extension } = new File(name);
72
- return app.extensions[extension]?.handle(name, props, options)(app, ...rest)
73
- ?? errors.NoHandlerForExtension.throw(extension, name);
74
- };
70
+ const extensions = ["fullExtension", "extension"];
71
+ const view = (name, props, options) => (app, ...rest) => extensions
72
+ .map(extension => app.extensions[new File(name)[extension]])
73
+ .find(extension => extension?.handle)
74
+ ?.handle(name, props, options)(app, ...rest)
75
+ ?? errors.NoHandlerForComponent.throw(name);
75
76
  // }}}
76
77
 
77
78
  export { text, json, stream, redirect, error, html, view, ws, sse };
@@ -3,6 +3,8 @@ import errors from "../../errors.js";
3
3
 
4
4
  const normalize = route => {
5
5
  let i = 0;
6
+ // user/ -> user
7
+ // user/{id=number}/{id2=number} -> user/{0}/{1}
6
8
  return (route.endsWith("/") ? route.slice(0, -1) : route)
7
9
  .replaceAll(/\{(?:\w*)(?:=\w+)?\}?/gu, _ => `{${i++}}`);
8
10
  };
package/types/index.d.ts CHANGED
@@ -1,69 +1,30 @@
1
- declare module "primate" {
2
- type App = any;
3
-
4
- interface MinOptions {
5
- status: number,
6
- headers: Headers | {},
7
- }
8
-
9
- interface ErrorOptions extends MinOptions {
10
- page: string,
11
- }
12
-
13
- interface Options extends ErrorOptions {
14
- placeholders: {},
15
- }
16
-
17
- type Dispatcher = {
18
- get(property: string): string,
19
- };
20
-
21
- type RequestFacade = {
22
- body: {}
23
- path: Dispatcher,
24
- query: Dispatcher,
25
- cookies: Dispatcher,
26
- headers: Dispatcher,
27
- original: Request,
28
- };
29
-
30
- type ResponseFn = (app: App, ...rest: any) => Response;
31
- type ResponseFacade =
32
- string
33
- | object
34
- | URL
35
- | Blob
36
- | ReadableStream
37
- | Response
38
- | ResponseFn;
39
-
40
- type RouteFunction = (request?: RequestFacade) => ResponseFacade;
41
-
42
- type Streamable = ReadableStream | Blob;
43
-
44
- export type Route = {
45
- get?: RouteFunction,
46
- post?: RouteFunction,
47
- put?: RouteFunction,
48
- delete?: RouteFunction,
49
- };
50
-
51
- export function text(body: string, options?: MinOptions): ResponseFn;
52
-
53
- export function json(body: {}, options?: MinOptions): ResponseFn;
54
-
55
- export function stream(body: Streamable, options?: MinOptions): ResponseFn;
56
-
57
- export function redirect(location: string, options?: MinOptions): ResponseFn;
58
-
59
- export function html(name: string, options?: MinOptions): ResponseFn;
60
-
61
- export function view(name: string, props: {}, options?: Options): ResponseFn;
62
-
63
- export function error(body: string, options?: ErrorOptions): ResponseFn;
64
-
65
- export function sse(implementation: {
66
- open?: () => void,
67
- close?: () => void,
68
- }, options?: MinOptions): ResponseFn;
1
+ declare module 'primate' {
2
+ function _default(command: any): Promise<any>;
3
+ export default _default;
4
+ export function text(body: any, options: any): (app: any) => any;
5
+ export function json(body: any, options: any): (app: any) => any;
6
+ export function stream(body: any, options: any): (app: any) => any;
7
+ export function redirect(Location: any, { status }?: {
8
+ status?: any;
9
+ }): (app: any) => any;
10
+ export function error(body?: string, { status, page }?: {
11
+ status?: any;
12
+ page: any;
13
+ }): (app: any) => any;
14
+ export function html(name: any, options: any): (app: any) => Promise<any>;
15
+ /**
16
+ * Render a component using handler for the given filename extension.
17
+ * @param name component filename
18
+ * @param props props passed to component
19
+ * @param options rendering options
20
+ */
21
+ export function view(name: string, props: object, options: object): (app: any, ...rest: any[]) => Promise<any>;
22
+ export function ws(implementation: any): ({ server }: {
23
+ server: any;
24
+ }, _: any, { original }: {
25
+ original: any;
26
+ }) => any;
27
+ export function sse(body: any, options: any): (app: any) => any;
69
28
  }
29
+
30
+ //# sourceMappingURL=index.d.ts.map