@thepassle/app-tools 0.9.5 → 0.9.6

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": "@thepassle/app-tools",
3
- "version": "0.9.5",
3
+ "version": "0.9.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -51,6 +51,7 @@
51
51
  "default": "./utils/*"
52
52
  },
53
53
  "./env.js": {
54
+ "types": "./types/env/dev.js",
54
55
  "development": "./env/dev.js",
55
56
  "default": "./env/prod.js"
56
57
  },
package/router/index.js CHANGED
@@ -79,11 +79,10 @@ export class Router extends EventTarget {
79
79
 
80
80
  /**
81
81
  * @template RenderResult
82
- * @returns {RenderResult}
83
82
  */
84
83
  render() {
85
84
  log(`Rendering route ${this.context.url.pathname}${this.context.url.search}`, { context: this.context, route: this.route });
86
- return this.route?.render?.(this.context);
85
+ return /** @type {RenderResult} */ (this.route?.render?.(this.context));
87
86
  }
88
87
 
89
88
  /**
@@ -0,0 +1,34 @@
1
+ export type ResponseType = 'text' | 'json' | 'stream' | 'blob' | 'arrayBuffer' | 'formData' | 'stream';
2
+ export interface Config {
3
+ plugins?: Plugin[];
4
+ responseType?: ResponseType;
5
+ baseURL?: string;
6
+ }
7
+ export type BodyMethod<R> = (url: string, data?: object, opts?: RequestOptions) => Promise<R>;
8
+ export type BodylessMethod<R> = (url: string, opts?: RequestOptions) => Promise<R>;
9
+ export type Method = 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'POST' | 'PUT' | 'PATCH';
10
+ export interface Plugin {
11
+ beforeFetch?: (meta: MetaParams) => MetaParams | Promise<MetaParams> | void;
12
+ afterFetch?: (res: Response) => void | Promise<void> | Response | Promise<Response>;
13
+ transform?: (data: any) => any;
14
+ name: string;
15
+ handleError?: (e: Error) => boolean;
16
+ }
17
+ export interface CustomRequestOptions {
18
+ transform?: (data: object) => object;
19
+ responseType?: ResponseType;
20
+ params?: Record<string, string>;
21
+ plugins?: Plugin[];
22
+ baseURL?: string;
23
+ }
24
+ export type RequestOptions = RequestInit & CustomRequestOptions;
25
+ export interface MetaParams {
26
+ responseType: string;
27
+ baseURL: string;
28
+ url: string;
29
+ method: Method;
30
+ headers: Headers;
31
+ opts?: RequestOptions;
32
+ data?: any;
33
+ fetchFn: typeof globalThis.fetch;
34
+ }
@@ -0,0 +1,19 @@
1
+ export type DialogNode = HTMLDialogElement & {
2
+ form: HTMLFormElement;
3
+ };
4
+ export interface DialogCallbacks {
5
+ opening?: <Parameters>(context: Context) => void;
6
+ opened?: <Parameters>(context: Context) => void;
7
+ closing?: (context: Context) => void;
8
+ closed?: (context: Context) => void;
9
+ }
10
+ export type Config = Record<string, DialogCallbacks>;
11
+ export interface OpenDialogOptions {
12
+ id: string;
13
+ parameters?: object;
14
+ }
15
+ export interface Context {
16
+ dialog: DialogNode | undefined;
17
+ id: string;
18
+ parameters?: Record<string, any>;
19
+ }
@@ -25,7 +25,6 @@ export class Router extends EventTarget {
25
25
  get baseUrl(): URL;
26
26
  /**
27
27
  * @template RenderResult
28
- * @returns {RenderResult}
29
28
  */
30
29
  render<RenderResult>(): RenderResult;
31
30
  /**
@@ -0,0 +1,32 @@
1
+ export interface Config {
2
+ fallback?: string;
3
+ plugins?: Plugin[];
4
+ routes: RouteDefinition[];
5
+ }
6
+ export interface Plugin {
7
+ name: string;
8
+ shouldNavigate?: (context: Context) => {
9
+ redirect: string;
10
+ condition: () => boolean | (() => Promise<Boolean>);
11
+ };
12
+ beforeNavigation?: (context: Context) => void;
13
+ afterNavigation?: (context: Context) => void;
14
+ }
15
+ export interface Context {
16
+ title?: string;
17
+ query: Record<string, string>;
18
+ params: Record<string, string>;
19
+ url: URL;
20
+ [key: string]: any;
21
+ }
22
+ export type Render<RenderResult> = (context: Context) => RenderResult;
23
+ export interface RouteDefinition<RenderResult = unknown> {
24
+ path: string;
25
+ title: string | ((context: Partial<Context>) => string);
26
+ render?: Render<RenderResult>;
27
+ plugins?: Plugin[];
28
+ }
29
+ /** @TODO URLPattern type */
30
+ export type Route = RouteDefinition & {
31
+ urlPattern?: any;
32
+ };