@spirobel/mininext 0.2.23 → 0.2.24

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 spirobel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/html.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { HandlerReturnType, HtmlHandler, LazyHandlerReturnType, Mini } from "./url";
2
- export type HtmlStringValues<T = undefined> = HtmlString | HtmlString[] | string | number | HtmlHandler<T> | JsonString | LazyHandlerReturnType | undefined;
3
- export type JsonStringValues<T = undefined> = HtmlStringValues<T> | {
2
+ export type HtmlStringValues<T = unknown> = HtmlString | HtmlString[] | string | number | HtmlHandler<T> | JsonString | LazyHandlerReturnType | undefined;
3
+ export type JsonStringValues<T = unknown> = HtmlStringValues<T> | {
4
4
  [key: string]: any;
5
5
  };
6
6
  export declare class HtmlString extends Array {
@@ -13,13 +13,13 @@ export declare class HtmlString extends Array {
13
13
  resolve<T>(mini: Mini<T>): Promise<this>;
14
14
  flat(depth?: number): this;
15
15
  }
16
- export declare function html<X = undefined>(strings: TemplateStringsArray, ...values: HtmlStringValues<X>[]): HtmlString;
16
+ export declare function html<X = unknown>(strings: TemplateStringsArray, ...values: HtmlStringValues<X>[]): HtmlString;
17
17
  export declare class JsonString extends HtmlString {
18
18
  }
19
19
  export declare class DangerJsonInHtml extends HtmlString {
20
20
  }
21
- export declare const json: <X = undefined>(strings: TemplateStringsArray, ...values: JsonStringValues<X>[]) => JsonString;
22
- export declare const dangerjson: <X = undefined>(strings: TemplateStringsArray, ...values: JsonStringValues<X>[]) => DangerJsonInHtml;
21
+ export declare const json: <X = unknown>(strings: TemplateStringsArray, ...values: JsonStringValues<X>[]) => JsonString;
22
+ export declare const dangerjson: <X = unknown>(strings: TemplateStringsArray, ...values: JsonStringValues<X>[]) => DangerJsonInHtml;
23
23
  export declare const commonHead: HtmlString;
24
24
  export declare const cssReset: HtmlString;
25
25
  /**
package/dist/url.d.ts CHANGED
@@ -8,10 +8,10 @@ export type Form = {
8
8
  formData?: FormData;
9
9
  formName?: string;
10
10
  hiddenField?: HtmlString;
11
- actionlink<Y = undefined>(qs?: string[] | string, settings?: LinkSettings): (mini: Mini<Y>) => string;
11
+ actionlink<Y = unknown>(qs?: string[] | string, settings?: LinkSettings): (mini: Mini<Y>) => string;
12
12
  onPostSubmit<F>(cb: () => F): F | undefined;
13
13
  };
14
- export type DataMaker<X> = ((mini: Mini) => DataMakerReturnType<X>) | (() => DataMakerReturnType<X>);
14
+ export type DataMaker<X, Z = unknown> = ((mini: Mini<Z>) => DataMakerReturnType<X>) | (() => DataMakerReturnType<X>);
15
15
  export type DataMakerReturnType<X> = X | Promise<X>;
16
16
  export type HandlerReturnType = JsonString | DangerJsonInHtml | HtmlString | string | void;
17
17
  export type LazyHandlerReturnType = HandlerReturnType | Promise<HandlerReturnType>;
@@ -27,7 +27,7 @@ export type NamedFormHandlerReturnType<X> = HandlerReturnType | Promise<HandlerR
27
27
  * const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
28
28
  * ```
29
29
  */
30
- export declare class Mini<X = undefined> {
30
+ export declare class Mini<X = unknown> {
31
31
  html: typeof html<X>;
32
32
  css: typeof html<X>;
33
33
  json: typeof json<X>;
@@ -42,7 +42,7 @@ export declare class Mini<X = undefined> {
42
42
  params: URLSearchParams;
43
43
  form: Form;
44
44
  requrl: Readonly<URL>;
45
- constructor(mini: Mini<undefined | any>, data: X);
45
+ constructor(mini: Mini<unknown>, data: X);
46
46
  }
47
47
  /**
48
48
  * HtmlHandler
@@ -53,8 +53,8 @@ export declare class Mini<X = undefined> {
53
53
  * const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
54
54
  * ```
55
55
  */
56
- export type HtmlHandler<Y = undefined> = ((mini: Mini<Y>) => LazyHandlerReturnType) | (() => LazyHandlerReturnType);
57
- export type NamedFormHandler<Y = undefined, Z = undefined> = ((mini: Mini<Y>) => NamedFormHandlerReturnType<Z>) | (() => NamedFormHandlerReturnType<Z>);
56
+ export type HtmlHandler<Y = unknown> = ((mini: Mini<Y>) => LazyHandlerReturnType) | (() => LazyHandlerReturnType);
57
+ export type NamedFormHandler<Y = unknown, Z = undefined> = ((mini: Mini<Y>) => NamedFormHandlerReturnType<Z>) | (() => NamedFormHandlerReturnType<Z>);
58
58
  declare global {
59
59
  var FrontendScripts: Array<string>;
60
60
  var FrontendScriptUrls: Array<string>;
@@ -106,13 +106,14 @@ export declare class url {
106
106
  * @example const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
107
107
  * @returns
108
108
  */
109
- static data<T>(dataMaker: DataMaker<T>): {
109
+ static data<T, Z>(dataMaker: DataMaker<T, Z>): {
110
110
  /**
111
111
  * @param dataHandler the function that prepares the data for the handlers
112
112
  * @example const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
113
113
  * @returns
114
114
  */
115
- handler: (dataHandler: HtmlHandler<T>) => (oldmini: Mini) => Promise<string | void | DangerJsonInHtml>;
115
+ handler: (dataHandler: HtmlHandler<T>) => (oldmini: Mini<Z>) => Promise<string | void | DangerJsonInHtml>;
116
+ dataMaker: DataMaker<T, Z>;
116
117
  /**
117
118
  * use this to **specify the input type for the functions**,
118
119
  *
@@ -164,7 +165,7 @@ export declare class url {
164
165
  * @param handler just like a normal handler (aka you can return the form as a HtmlString), but you can optionally return additional data in formInfo
165
166
  * @returns - { formResponse: result of the handler, formInfo?: some info about the form. Totally up to you}
166
167
  */
167
- static namedForm<X = undefined, Z = undefined>(name: string, handler: NamedFormHandler<X, Z>): (mini: Mini<X>) => Promise<NamedForm<Z>>;
168
+ static namedForm<X = unknown, Z = undefined>(name: string, handler: NamedFormHandler<X, Z>): (mini: Mini<X>) => Promise<NamedForm<Z>>;
168
169
  /**
169
170
  * pass in all the query string parameter names that you want to preserve in the link
170
171
  * @param Url - the url that you want to link to (example: "/login")
package/dist/url.js CHANGED
@@ -149,6 +149,7 @@ export class url {
149
149
  return unresolvedDataHandler;
150
150
  };
151
151
  },
152
+ dataMaker,
152
153
  /**
153
154
  * use this to **specify the input type for the functions**,
154
155
  *
package/mininext/html.ts CHANGED
@@ -4,7 +4,7 @@ import type {
4
4
  LazyHandlerReturnType,
5
5
  Mini,
6
6
  } from "./url";
7
- export type HtmlStringValues<T = undefined> =
7
+ export type HtmlStringValues<T = unknown> =
8
8
  | HtmlString
9
9
  | HtmlString[]
10
10
  | string
@@ -13,7 +13,7 @@ export type HtmlStringValues<T = undefined> =
13
13
  | JsonString
14
14
  | LazyHandlerReturnType
15
15
  | undefined;
16
- export type JsonStringValues<T = undefined> =
16
+ export type JsonStringValues<T = unknown> =
17
17
  | HtmlStringValues<T>
18
18
  | { [key: string]: any };
19
19
  export class HtmlString extends Array {
@@ -62,7 +62,7 @@ export class HtmlString extends Array {
62
62
  }
63
63
  }
64
64
 
65
- export function html<X = undefined>(
65
+ export function html<X = unknown>(
66
66
  strings: TemplateStringsArray,
67
67
  ...values: HtmlStringValues<X>[]
68
68
  ) {
@@ -109,16 +109,15 @@ export function html<X = undefined>(
109
109
  }
110
110
  export class JsonString extends HtmlString {}
111
111
  export class DangerJsonInHtml extends HtmlString {}
112
- //type JsonTemplateInput <X = undefined> = (strings: TemplateStringsArray, ...values: JsonStringValues<X>[])
113
112
  function JsonTemplateProcessor(
114
113
  danger: true
115
- ): <X = undefined>(
114
+ ): <X = unknown>(
116
115
  strings: TemplateStringsArray,
117
116
  ...values: JsonStringValues<X>[]
118
117
  ) => DangerJsonInHtml;
119
118
  function JsonTemplateProcessor(
120
119
  danger?: false | undefined
121
- ): <X = undefined>(
120
+ ): <X = unknown>(
122
121
  strings: TemplateStringsArray,
123
122
  ...values: JsonStringValues<X>[]
124
123
  ) => JsonString;
@@ -127,7 +126,7 @@ function JsonTemplateProcessor(danger: boolean = false) {
127
126
  const constructorr = danger
128
127
  ? () => new DangerJsonInHtml()
129
128
  : () => new JsonString();
130
- return function <X = undefined>(
129
+ return function <X = unknown>(
131
130
  strings: TemplateStringsArray,
132
131
  ...values: JsonStringValues<X>[]
133
132
  ) {
package/mininext/url.ts CHANGED
@@ -8,15 +8,15 @@ export type Form = {
8
8
  formData?: FormData;
9
9
  formName?: string;
10
10
  hiddenField?: HtmlString;
11
- actionlink<Y = undefined>(
11
+ actionlink<Y = unknown>(
12
12
  qs?: string[] | string,
13
13
  settings?: LinkSettings
14
14
  ): (mini: Mini<Y>) => string;
15
15
  onPostSubmit<F>(cb: () => F): F | undefined;
16
16
  };
17
17
 
18
- export type DataMaker<X> =
19
- | ((mini: Mini) => DataMakerReturnType<X>)
18
+ export type DataMaker<X, Z = unknown> =
19
+ | ((mini: Mini<Z>) => DataMakerReturnType<X>)
20
20
  | (() => DataMakerReturnType<X>);
21
21
  export type DataMakerReturnType<X> = X | Promise<X>;
22
22
  export type HandlerReturnType =
@@ -46,7 +46,7 @@ export type NamedFormHandlerReturnType<X> =
46
46
  * const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
47
47
  * ```
48
48
  */
49
- export class Mini<X = undefined> {
49
+ export class Mini<X = unknown> {
50
50
  html: typeof html<X>;
51
51
  css: typeof html<X>;
52
52
  json: typeof json<X>;
@@ -63,7 +63,7 @@ export class Mini<X = undefined> {
63
63
  form!: Form;
64
64
  requrl!: Readonly<URL>;
65
65
 
66
- constructor(mini: Mini<undefined | any>, data: X) {
66
+ constructor(mini: Mini<unknown>, data: X) {
67
67
  Object.assign(this, mini);
68
68
  this.html = html<X>;
69
69
  this.css = html<X>;
@@ -99,10 +99,10 @@ export class Mini<X = undefined> {
99
99
  * const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
100
100
  * ```
101
101
  */
102
- export type HtmlHandler<Y = undefined> =
102
+ export type HtmlHandler<Y = unknown> =
103
103
  | ((mini: Mini<Y>) => LazyHandlerReturnType)
104
104
  | (() => LazyHandlerReturnType);
105
- export type NamedFormHandler<Y = undefined, Z = undefined> =
105
+ export type NamedFormHandler<Y = unknown, Z = undefined> =
106
106
  | ((mini: Mini<Y>) => NamedFormHandlerReturnType<Z>)
107
107
  | (() => NamedFormHandlerReturnType<Z>);
108
108
 
@@ -213,7 +213,7 @@ export class url {
213
213
  * @example const {html,json, css, data, req, form, link, svg, deliver, route, params, header, head } = mini //pull everything out of the mini handbag
214
214
  * @returns
215
215
  */
216
- static data<T>(dataMaker: DataMaker<T>) {
216
+ static data<T, Z>(dataMaker: DataMaker<T, Z>) {
217
217
  return {
218
218
  /**
219
219
  * @param dataHandler the function that prepares the data for the handlers
@@ -221,7 +221,7 @@ export class url {
221
221
  * @returns
222
222
  */
223
223
  handler: (dataHandler: HtmlHandler<T>) => {
224
- return async (oldmini: Mini) => {
224
+ return async (oldmini: Mini<Z>) => {
225
225
  const data = await dataMaker(oldmini);
226
226
  const mini = new Mini(oldmini, data);
227
227
 
@@ -232,6 +232,7 @@ export class url {
232
232
  return unresolvedDataHandler;
233
233
  };
234
234
  },
235
+ dataMaker,
235
236
  /**
236
237
  * use this to **specify the input type for the functions**,
237
238
  *
@@ -314,7 +315,7 @@ export class url {
314
315
  * @param handler just like a normal handler (aka you can return the form as a HtmlString), but you can optionally return additional data in formInfo
315
316
  * @returns - { formResponse: result of the handler, formInfo?: some info about the form. Totally up to you}
316
317
  */
317
- static namedForm<X = undefined, Z = undefined>(
318
+ static namedForm<X = unknown, Z = undefined>(
318
319
  name: string,
319
320
  handler: NamedFormHandler<X, Z>
320
321
  ) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  },
13
13
  "files": ["dist", "mininext"],
14
- "version": "0.2.23",
14
+ "version": "0.2.24",
15
15
  "devDependencies": {
16
16
  "@types/bun": "latest"
17
17
  },