@odatnurd/cf-requests 0.1.4 → 0.1.5

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 (2) hide show
  1. package/aegis/index.js +16 -3
  2. package/package.json +1 -1
package/aegis/index.js CHANGED
@@ -74,17 +74,30 @@ export async function schemaTest(dataType, schema, data, validator) {
74
74
  const ctx = {
75
75
  req: {
76
76
  // These methods are used by the validator to pull the parsed data out of
77
- // the request in order to validate it.
77
+ // the request in order to validate it, except for when the data type is
78
+ // header, in which case it invokes the header() function with no name.
78
79
  param: () => data,
79
80
  json: async () => data,
80
81
  query: () => data,
81
- header: () => data,
82
82
  cookie: () => data,
83
- form: async () => data,
83
+ formData: async () => data,
84
+
85
+ // We need to populate an actual cookie header in headers for it the
86
+ // validator to be able to pull cookie data because it wants to parse it
87
+ // itself.
88
+ headers: new Headers(dataType === 'cookie'
89
+ ? { 'Cookie': Object.entries(data).map(([k,v]) => `${k}=${v}`).join('; ') }
90
+ : {}),
84
91
 
85
92
  // The validator invokes this to get headers out of the request when the
86
93
  // data type is JSON.
87
94
  header: (name) => {
95
+ // If there is no name, return the data back directly; this call pattern
96
+ // happens when the data type is header.
97
+ if (name === undefined) {
98
+ return data;
99
+ }
100
+
88
101
  return name.toLowerCase() !== 'content-type' ? undefined : {
89
102
  json: 'application/json',
90
103
  form: 'multipart/form-data',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatnurd/cf-requests",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Simple Cloudflare Hono request wrapper",
5
5
  "author": "OdatNurd (https://odatnurd.net)",
6
6
  "homepage": "https://github.com/OdatNurd/cf-requests",