@odatnurd/cf-requests 0.1.0 → 0.1.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/README.md CHANGED
@@ -56,9 +56,6 @@ fields declared by the schema are present.
56
56
 
57
57
 
58
58
  ```js
59
- /******************************************************************************/
60
-
61
-
62
59
  import { validate, success, routeHandler } from '#lib/common';
63
60
 
64
61
  import * as testSchema from '#schemas/test';
@@ -79,7 +76,6 @@ export const $post = routeHandler(
79
76
  return success(ctx, 'request body validated', body);
80
77
  },
81
78
  );
82
-
83
79
  ```
84
80
 
85
81
  ## Methods
@@ -88,11 +84,13 @@ export const $post = routeHandler(
88
84
  export function success(ctx, message, result, status) {}
89
85
  ```
90
86
 
91
- Indicate a successful return in JSON with the given `HTTP` status code:
87
+ Indicate a successful return in JSON with the given `HTTP` status code; the
88
+ status code is used to construct the JSON as well as the response:
92
89
 
93
90
  ```js
94
91
  {
95
92
  "success": true,
93
+ status,
96
94
  message,
97
95
  data: result
98
96
  }
@@ -140,27 +138,6 @@ On success, the data is placed in the context. If the data does not pass the
140
138
  validation of the schema, the `fail()` method is invoked on it with a status of
141
139
  `422` to signify the issue directly.
142
140
 
143
- Execute a fetch operation on the provided database, using the data in `sqlargs`
144
- to create the statement(s) to be executed, and return the result(s) of the
145
- query after logging statistics such as the rows read and written, which will be
146
- annotated with the action string provided to give context to the operation.
147
-
148
- The provided `sqlargs` is a variable length list of arguments that consists of
149
- strings to be compiled to SQL, previously compiled statements, and/or arrays of
150
- values to bind to statements.
151
-
152
- For the purposes of binding, arrays will bind to the most recently seen
153
- statement, allowing you to compile one statement and bind it multiple times if
154
- desired.
155
-
156
- When more than one statement is provided, all statements will be executed as a
157
- batch operation, which implicitly runs as a transaction.
158
-
159
- The return value is the direct result of executing the query or queries given
160
- in `sqlargs`; this is either a (potentially empty) array of result rows, or an
161
- array of such arrays (if a batch). As with `dbRawQuery`, the `meta` is stripped
162
- from the results, providing you just the actual query result.
163
-
164
141
  ---
165
142
 
166
143
  ```js
@@ -184,6 +161,10 @@ export const $post = [
184
161
  body(async (ctx) => {
185
162
  const body = ctx.req.valid('json');
186
163
 
164
+ if (body.key1 != 69) {
165
+ throw new Error('key is not nice');
166
+ }
167
+
187
168
  return success(ctx, 'code test worked', body);
188
169
  }),
189
170
  ];
package/lib/handlers.js CHANGED
@@ -16,7 +16,7 @@ export const success = (ctx, message, result, status) => {
16
16
  result ??= [];
17
17
 
18
18
  ctx.status(status);
19
- return ctx.json({ success: true, message, data: result });
19
+ return ctx.json({ success: true, status, message, data: result });
20
20
  }
21
21
 
22
22
 
@@ -31,7 +31,7 @@ export const fail = (ctx, message, status, result) => {
31
31
  status ??= 400;
32
32
 
33
33
  ctx.status(status);
34
- return ctx.json({ success: false, message, data: result });
34
+ return ctx.json({ success: false, status, message, data: result });
35
35
  }
36
36
 
37
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatnurd/cf-requests",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Simple Cloudflare Hono request wrapper",
5
5
  "author": "OdatNurd (https://odatnurd.net)",
6
6
  "homepage": "https://github.com/OdatNurd/cf-requests",