solidstep 0.1.0

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 (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/client.d.ts +4 -0
  4. package/client.d.ts.map +1 -0
  5. package/client.js +91 -0
  6. package/index.d.ts +11 -0
  7. package/index.d.ts.map +1 -0
  8. package/index.js +97 -0
  9. package/package.json +58 -0
  10. package/server.d.ts +3 -0
  11. package/server.d.ts.map +1 -0
  12. package/server.js +666 -0
  13. package/utils/cache.d.ts +5 -0
  14. package/utils/cache.d.ts.map +1 -0
  15. package/utils/cache.js +97 -0
  16. package/utils/cookies.d.ts +5 -0
  17. package/utils/cookies.d.ts.map +1 -0
  18. package/utils/cookies.js +13 -0
  19. package/utils/cors.d.ts +14 -0
  20. package/utils/cors.d.ts.map +1 -0
  21. package/utils/cors.js +15 -0
  22. package/utils/csp.d.ts +38 -0
  23. package/utils/csp.d.ts.map +1 -0
  24. package/utils/csp.js +165 -0
  25. package/utils/csrf.d.ts +5 -0
  26. package/utils/csrf.d.ts.map +1 -0
  27. package/utils/csrf.js +46 -0
  28. package/utils/error-handler.d.ts +37 -0
  29. package/utils/error-handler.d.ts.map +1 -0
  30. package/utils/error-handler.js +40 -0
  31. package/utils/fetch.client.d.ts +23 -0
  32. package/utils/fetch.client.d.ts.map +1 -0
  33. package/utils/fetch.client.js +55 -0
  34. package/utils/fetch.server.d.ts +22 -0
  35. package/utils/fetch.server.d.ts.map +1 -0
  36. package/utils/fetch.server.js +54 -0
  37. package/utils/hooks/action-state.d.ts +3 -0
  38. package/utils/hooks/action-state.d.ts.map +1 -0
  39. package/utils/hooks/action-state.js +13 -0
  40. package/utils/loader.d.ts +18 -0
  41. package/utils/loader.d.ts.map +1 -0
  42. package/utils/loader.js +23 -0
  43. package/utils/redirect.d.ts +5 -0
  44. package/utils/redirect.d.ts.map +1 -0
  45. package/utils/redirect.js +14 -0
  46. package/utils/router.d.ts +104 -0
  47. package/utils/router.d.ts.map +1 -0
  48. package/utils/router.js +258 -0
  49. package/utils/server-action.client.d.ts +2 -0
  50. package/utils/server-action.client.d.ts.map +1 -0
  51. package/utils/server-action.client.js +200 -0
  52. package/utils/server-action.server.d.ts +5 -0
  53. package/utils/server-action.server.d.ts.map +1 -0
  54. package/utils/server-action.server.js +264 -0
  55. package/utils/server-only.d.ts +2 -0
  56. package/utils/server-only.d.ts.map +1 -0
  57. package/utils/server-only.js +4 -0
  58. package/utils/types.d.ts +8 -0
  59. package/utils/types.d.ts.map +1 -0
  60. package/utils/types.js +1 -0
@@ -0,0 +1,54 @@
1
+ import { fetch } from 'undici';
2
+ /**
3
+ * It's a wrapper around the native fetch function that adds a timeout and a json parser
4
+ * @param {string} url - string - The URL to fetch
5
+ * @param {Options} [options] - {
6
+ * method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
7
+ * body?: any;
8
+ * headers?: any;
9
+ * MAX_FETCH_TIME?: number;
10
+ * }
11
+ * @param [json=true] - boolean - If the response is JSON, it will be parsed and returned.
12
+ * @returns The return type is Promise<any>
13
+ */
14
+ const Fetch = async (url, options, json = true) => {
15
+ // AbortController was added in node v14.17.0 globally
16
+ const AbortController = globalThis.AbortController;
17
+ const maxTime = options?.MAX_FETCH_TIME ?? 4000;
18
+ const controller = new AbortController();
19
+ const timeout = setTimeout(() => {
20
+ controller.abort();
21
+ }, maxTime);
22
+ try {
23
+ const response = await fetch(url, {
24
+ ...options,
25
+ signal: controller.signal,
26
+ });
27
+ if (response?.status >= 400 && response?.status <= 599) {
28
+ if (json) {
29
+ throw await response.json();
30
+ }
31
+ throw response;
32
+ }
33
+ if (json) {
34
+ const data = await response.json();
35
+ if (data) {
36
+ if (data.error)
37
+ throw data.error; // in case the status is marked as 200 but the response is an error
38
+ return data;
39
+ }
40
+ throw new Error('Not Defined');
41
+ }
42
+ return response;
43
+ }
44
+ catch (error) {
45
+ if (controller.signal.aborted) {
46
+ throw new Error('Timeout');
47
+ }
48
+ throw error;
49
+ }
50
+ finally {
51
+ clearTimeout(timeout);
52
+ }
53
+ };
54
+ export default Fetch;
@@ -0,0 +1,3 @@
1
+ declare const useActionState: () => readonly [import("solid-js").Accessor<boolean>, (callback: () => void | Promise<void>) => void];
2
+ export default useActionState;
3
+ //# sourceMappingURL=action-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-state.d.ts","sourceRoot":"","sources":["../../../utils/hooks/action-state.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,cAAc,mEAIF,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,UAU3C,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { createSignal } from 'solid-js';
2
+ const useActionState = () => {
3
+ const [isPending, setIsPending] = createSignal(false);
4
+ const startTransition = (callback) => {
5
+ setIsPending(true);
6
+ Promise.resolve(callback())
7
+ .finally(() => {
8
+ setIsPending(false);
9
+ });
10
+ };
11
+ return [isPending, startTransition];
12
+ };
13
+ export default useActionState;
@@ -0,0 +1,18 @@
1
+ type LoaderFunction<T> = (request?: Request) => Promise<T>;
2
+ type LoaderOptions = {
3
+ type?: 'defer' | 'sequential';
4
+ };
5
+ export declare const defineLoader: <T>(loader: LoaderFunction<T>, options?: LoaderOptions) => {
6
+ loader: (request?: Request) => Promise<{
7
+ data: Awaited<T>;
8
+ type: "defer" | "sequential";
9
+ }>;
10
+ options: LoaderOptions;
11
+ } | null;
12
+ export type LoaderDataFromFunction<T> = T extends {
13
+ loader: infer L extends (...args: any) => any;
14
+ } ? Awaited<ReturnType<T['loader']>> extends {
15
+ data: infer D;
16
+ } ? D : never : never;
17
+ export {};
18
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../utils/loader.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAE3D,KAAK,aAAa,GAAG;IACjB,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,QAAQ,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,aAAa;uBAE9C,OAAO;;;;;QAoB1C,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;CAAE,GAC7F,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,KAAK,GACtE,KAAK,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { isServer } from 'solid-js/web';
2
+ export const defineLoader = (loader, options) => {
3
+ if (isServer) {
4
+ const fn = async (request) => {
5
+ try {
6
+ const loaderData = await loader(request);
7
+ return {
8
+ data: loaderData,
9
+ type: options?.type || 'sequential',
10
+ };
11
+ }
12
+ catch (error) {
13
+ console.error('Error in loader:', error);
14
+ throw error; // Re-throw to allow error handling upstream
15
+ }
16
+ };
17
+ return {
18
+ loader: fn,
19
+ options: options || {},
20
+ };
21
+ }
22
+ return null; // Return null if not on the server
23
+ };
@@ -0,0 +1,5 @@
1
+ export declare class RedirectError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare const redirect: (url: string) => void;
5
+ //# sourceMappingURL=redirect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../utils/redirect.ts"],"names":[],"mappings":"AAEA,qBAAa,aAAc,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI9B;AAED,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,SAMnC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { isServer } from 'solid-js/web';
2
+ export class RedirectError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = 'RedirectError';
6
+ }
7
+ }
8
+ export const redirect = (url) => {
9
+ if (isServer) {
10
+ throw new RedirectError(url);
11
+ }
12
+ window.location.href = url;
13
+ return;
14
+ };
@@ -0,0 +1,104 @@
1
+ import { BaseFileSystemRouter } from 'vinxi/fs-router';
2
+ export declare class ServerRouter extends BaseFileSystemRouter {
3
+ toPath(src: string): string;
4
+ toRoute(filePath: string): {
5
+ type: string;
6
+ path: string;
7
+ $handler: {
8
+ src: string;
9
+ pick: string[];
10
+ };
11
+ parent?: undefined;
12
+ $component?: undefined;
13
+ $loader?: undefined;
14
+ $options?: undefined;
15
+ $generateMeta?: undefined;
16
+ } | {
17
+ type: string;
18
+ parent: string;
19
+ path: string;
20
+ $handler: {
21
+ src: string;
22
+ pick: never[];
23
+ };
24
+ $component: {
25
+ src: string;
26
+ pick: string[];
27
+ };
28
+ $loader: {
29
+ src: string;
30
+ pick: string[];
31
+ };
32
+ $options: {
33
+ src: string;
34
+ pick: string[];
35
+ };
36
+ $generateMeta?: undefined;
37
+ } | {
38
+ type: string;
39
+ path: string;
40
+ $handler: {
41
+ src: string;
42
+ pick: never[];
43
+ };
44
+ $component: {
45
+ src: string;
46
+ pick: string[];
47
+ };
48
+ $loader: {
49
+ src: string;
50
+ pick: string[];
51
+ };
52
+ $generateMeta: {
53
+ src: string;
54
+ pick: string[];
55
+ };
56
+ $options: {
57
+ src: string;
58
+ pick: string[];
59
+ };
60
+ parent?: undefined;
61
+ } | {
62
+ type: string;
63
+ path: string;
64
+ $handler: {
65
+ src: string;
66
+ pick: never[];
67
+ };
68
+ $component: {
69
+ src: string;
70
+ pick: string[];
71
+ };
72
+ $generateMeta: {
73
+ src: string;
74
+ pick: string[];
75
+ };
76
+ $options: {
77
+ src: string;
78
+ pick: string[];
79
+ };
80
+ parent?: undefined;
81
+ $loader?: undefined;
82
+ } | undefined;
83
+ }
84
+ export declare class ClientRouter extends BaseFileSystemRouter {
85
+ toPath(src: string): string;
86
+ toRoute(filePath: string): {
87
+ type: string;
88
+ parent: string;
89
+ path: string;
90
+ $component: {
91
+ src: string;
92
+ pick: string[];
93
+ };
94
+ } | {
95
+ type: string;
96
+ path: string;
97
+ $component: {
98
+ src: string;
99
+ pick: string[];
100
+ };
101
+ parent?: undefined;
102
+ } | undefined;
103
+ }
104
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../utils/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAa,MAAM,iBAAiB,CAAC;AAMlE,qBAAa,YAAa,SAAQ,oBAAoB;IAClD,MAAM,CAAC,GAAG,EAAE,MAAM;IAclB,OAAO,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsK3B;AAED,qBAAa,YAAa,SAAQ,oBAAoB;IAClD,MAAM,CAAC,GAAG,EAAE,MAAM;IAgBlB,OAAO,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;CA2E3B"}
@@ -0,0 +1,258 @@
1
+ import { BaseFileSystemRouter, cleanPath } from 'vinxi/fs-router';
2
+ import { dirname } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ const __dirname = dirname(fileURLToPath(import.meta.url));
5
+ export class ServerRouter extends BaseFileSystemRouter {
6
+ toPath(src) {
7
+ const routePath = cleanPath(src, this.config)
8
+ .replace(new RegExp(`\.(${(this.config.extensions ?? []).join('|')})$`), '')
9
+ .replace(/\/(page|route|layout|error|not-found|loading)$/, '');
10
+ // src = src
11
+ // .slice((`${__dirname}/app`).length);
12
+ // const routePath = src
13
+ // .replace(new RegExp(`\.(${(this.config.extensions ?? []).join('|')})$`), '')
14
+ // .replace(/\/(page|route|layout|error|not-found|loading)$/, '');
15
+ return routePath?.length > 0 ? routePath : '/';
16
+ }
17
+ toRoute(filePath) {
18
+ const path = this.toPath(filePath);
19
+ if ((/\/route\.(js|ts)$/).test(filePath)) {
20
+ return {
21
+ type: 'route',
22
+ path: `/route${path}`,
23
+ $handler: {
24
+ src: filePath,
25
+ pick: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
26
+ },
27
+ };
28
+ }
29
+ // biome-ignore lint/correctness/noEmptyCharacterClassInRegex: <explanation>
30
+ const scopedPackageMatch = path.match(/@[^]+/g);
31
+ if (scopedPackageMatch) {
32
+ // Remove the scoped package part
33
+ const scopedPackage = scopedPackageMatch[0];
34
+ const parent = path.replace(`/${scopedPackage}`, '');
35
+ return {
36
+ type: 'group',
37
+ parent: parent,
38
+ path: `/group${path}`,
39
+ $handler: {
40
+ src: filePath,
41
+ pick: []
42
+ },
43
+ $component: {
44
+ src: filePath,
45
+ pick: ['default'],
46
+ },
47
+ $loader: {
48
+ src: filePath,
49
+ pick: ['loader'],
50
+ },
51
+ $options: {
52
+ src: filePath,
53
+ pick: ['options'],
54
+ },
55
+ };
56
+ }
57
+ if ((/\/page\.(jsx|js|tsx|ts)$/).test(filePath)) {
58
+ return {
59
+ type: 'route',
60
+ path: `/route${path}`,
61
+ $handler: {
62
+ src: filePath,
63
+ pick: []
64
+ },
65
+ $component: {
66
+ src: filePath,
67
+ pick: ['default'],
68
+ },
69
+ $loader: {
70
+ src: filePath,
71
+ pick: ['loader'],
72
+ },
73
+ $generateMeta: {
74
+ src: filePath,
75
+ pick: ['generateMeta'],
76
+ },
77
+ $options: {
78
+ src: filePath,
79
+ pick: ['options'],
80
+ },
81
+ };
82
+ }
83
+ if ((/\/layout\.(jsx|js|tsx|ts)$/).test(filePath)) {
84
+ return {
85
+ type: 'layout',
86
+ path: `/layout${path}`,
87
+ $handler: {
88
+ src: filePath,
89
+ pick: []
90
+ },
91
+ $component: {
92
+ src: filePath,
93
+ pick: ['default'],
94
+ },
95
+ $loader: {
96
+ src: filePath,
97
+ pick: ['loader'],
98
+ },
99
+ $generateMeta: {
100
+ src: filePath,
101
+ pick: ['generateMeta'],
102
+ },
103
+ $options: {
104
+ src: filePath,
105
+ pick: ['options'],
106
+ },
107
+ };
108
+ }
109
+ if ((/\/error\.(jsx|js|tsx|ts)$/).test(filePath)) {
110
+ return {
111
+ type: 'error',
112
+ path: `/error${path}`,
113
+ $handler: {
114
+ src: filePath,
115
+ pick: []
116
+ },
117
+ $component: {
118
+ src: filePath,
119
+ pick: ['default'],
120
+ },
121
+ $generateMeta: {
122
+ src: filePath,
123
+ pick: ['generateMeta'],
124
+ },
125
+ $options: {
126
+ src: filePath,
127
+ pick: ['options'],
128
+ },
129
+ };
130
+ }
131
+ if ((/\/loading\.(jsx|js|tsx|ts)$/).test(filePath)) {
132
+ return {
133
+ type: 'loading',
134
+ path: `/loading${path}`,
135
+ $handler: {
136
+ src: filePath,
137
+ pick: []
138
+ },
139
+ $component: {
140
+ src: filePath,
141
+ pick: ['default'],
142
+ },
143
+ $generateMeta: {
144
+ src: filePath,
145
+ pick: ['generateMeta'],
146
+ },
147
+ $options: {
148
+ src: filePath,
149
+ pick: ['options'],
150
+ },
151
+ };
152
+ }
153
+ if ((/\/not-found\.(jsx|js|tsx|ts)$/).test(filePath) && path === '/') {
154
+ return {
155
+ type: 'not-found',
156
+ path: `/not-found${path}`,
157
+ $handler: {
158
+ src: filePath,
159
+ pick: []
160
+ },
161
+ $component: {
162
+ src: filePath,
163
+ pick: ['default'],
164
+ },
165
+ $generateMeta: {
166
+ src: filePath,
167
+ pick: ['generateMeta'],
168
+ },
169
+ $options: {
170
+ src: filePath,
171
+ pick: ['options'],
172
+ },
173
+ };
174
+ }
175
+ }
176
+ }
177
+ export class ClientRouter extends BaseFileSystemRouter {
178
+ toPath(src) {
179
+ const routePath = cleanPath(src, this.config)
180
+ .replace(new RegExp(`\.(${(this.config.extensions ?? []).join('|')})$`), '')
181
+ .replace(/\/(page|route|layout|error|not-found|loading)$/, '');
182
+ // src = src
183
+ // .slice((`${__dirname}/app`).length);
184
+ // const routePath = src
185
+ // .replace(new RegExp(`\.(${(this.config.extensions ?? []).join('|')})$`), '')
186
+ // .replace(/\/(page|layout|error|not-found|loading)$/, '');
187
+ return routePath?.length > 0 ? routePath : '/';
188
+ }
189
+ toRoute(filePath) {
190
+ const path = this.toPath(filePath);
191
+ // biome-ignore lint/correctness/noEmptyCharacterClassInRegex: <explanation>
192
+ const scopedPackageMatch = path.match(/@[^]+/g);
193
+ if (scopedPackageMatch) {
194
+ // Remove the scoped package part
195
+ const scopedPackage = scopedPackageMatch[0];
196
+ const parent = path.replace(`/${scopedPackage}`, '');
197
+ return {
198
+ type: 'group',
199
+ parent: parent,
200
+ path: `/group${path}`,
201
+ $component: {
202
+ src: filePath,
203
+ pick: ['default', '$css'],
204
+ },
205
+ };
206
+ }
207
+ if ((/\/page\.(jsx|js|tsx|ts)$/).test(filePath)) {
208
+ return {
209
+ type: 'route',
210
+ path: `/route${path}`,
211
+ $component: {
212
+ src: filePath,
213
+ pick: ['default', '$css'],
214
+ },
215
+ };
216
+ }
217
+ if ((/\/layout\.(jsx|js|tsx|ts)$/).test(filePath)) {
218
+ return {
219
+ type: 'layout',
220
+ path: `/layout${path}`,
221
+ $component: {
222
+ src: filePath,
223
+ pick: ['default', '$css'],
224
+ },
225
+ };
226
+ }
227
+ if ((/\/error\.(jsx|js|tsx|ts)$/).test(filePath)) {
228
+ return {
229
+ type: 'error',
230
+ path: `/error${path}`,
231
+ $component: {
232
+ src: filePath,
233
+ pick: ['default', '$css'],
234
+ },
235
+ };
236
+ }
237
+ if ((/\/loading\.(jsx|js|tsx|ts)$/).test(filePath)) {
238
+ return {
239
+ type: 'loading',
240
+ path: `/loading${path}`,
241
+ $component: {
242
+ src: filePath,
243
+ pick: ['default', '$css'],
244
+ },
245
+ };
246
+ }
247
+ if ((/\/not-found\.(jsx|js|tsx|ts)$/).test(filePath) && path === '/') {
248
+ return {
249
+ type: 'not-found',
250
+ path: `/not-found${path}`,
251
+ $component: {
252
+ src: filePath,
253
+ pick: ['default'],
254
+ },
255
+ };
256
+ }
257
+ }
258
+ }
@@ -0,0 +1,2 @@
1
+ export declare function createServerReference(fn: Function, id: string, name: string): Function;
2
+ //# sourceMappingURL=server-action.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-action.client.d.ts","sourceRoot":"","sources":["../../utils/server-action.client.ts"],"names":[],"mappings":"AA2MA,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,YAyC3E"}