@torpor/build 0.4.2 → 0.4.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @torpor/build
2
2
 
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 426f7bd: Fix: return default $page.form status and message
8
+
3
9
  ## 0.4.2
4
10
 
5
11
  ### Patch Changes
package/dist/state.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  interface PageState {
3
3
  status: number;
4
4
  url: URL;
5
- form?: Record<string, string>;
5
+ form?: Record<string, string | number>;
6
6
  error?: {
7
7
  message: string;
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torpor/build",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "A framework for building sites and apps with Torpor",
5
5
  "type": "module",
6
6
  "exports": {
@@ -162,7 +162,7 @@ async function loadView(
162
162
  params: Record<string, string>,
163
163
  template: string,
164
164
  formStatus?: number,
165
- form?: Record<string, string>,
165
+ form?: Record<string, string | number>,
166
166
  ) {
167
167
  // There must be a client endpoint with a component
168
168
  const clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;
@@ -330,11 +330,19 @@ async function runAction(
330
330
  // TODO: do not re-run hooks?
331
331
  const newUrl = new URL(url.pathname, url);
332
332
  const formStatus = result?.status;
333
- if (result?.headers.get("Content-Type")?.includes("application/json")) {
334
- $page.form = await result.json();
333
+ const formMessage = await result?.text();
334
+ if (formMessage && result?.headers.get("Content-Type")?.includes("application/json")) {
335
+ $page.form = JSON.parse(formMessage);
335
336
  } else {
336
- $page.form = undefined;
337
+ $page.form = {};
337
338
  }
339
+ // Set status and message if they haven't already been set,
340
+ // which means that you can just return e.g. forbidden() or
341
+ // forbidden("no!") and there will be something you can work
342
+ // with in your component, or you can set a completely custom
343
+ // object with whatever info you need
344
+ $page.form!.status ??= formStatus ?? 0;
345
+ $page.form!.message ??= formMessage ?? "";
338
346
  return await loadView(ev, newUrl, handler, params, template, formStatus, $page.form);
339
347
  } else {
340
348
  // If the form was submitted without javascript and there was a
@@ -1,7 +1,7 @@
1
1
  export default interface PageState {
2
2
  status: number;
3
3
  url: URL;
4
- form?: Record<string, string>;
4
+ form?: Record<string, string | number>;
5
5
  error?: {
6
6
  message: string;
7
7
  };