dynara 0.0.2 → 0.0.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/README.md +8 -0
- package/dist/index.js +5 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -59,8 +59,16 @@ A few conveniences:
|
|
|
59
59
|
|
|
60
60
|
- **Array params** are comma-split: `GET /items/1,2,3` with `{ itemIds: { type: 'array', items: 'number' } }` yields `[1, 2, 3]`.
|
|
61
61
|
- **Query booleans** accept `?flag=true` or a bare `?flag`.
|
|
62
|
+
- **Dates**: a `"date"` field accepts an ISO-8601 string (`"2020-01-02"`, optionally with a time part) or epoch milliseconds, and is decoded into a JS `Date` before your handler runs — `req.body.startsAt instanceof Date`. Works in bodies, query strings, and params; `"date?"` / `"date??"` behave like every other type.
|
|
62
63
|
- `req.raw` exposes the underlying `BunRequest`, and `req.server` the Bun `Server`.
|
|
63
64
|
|
|
65
|
+
```ts
|
|
66
|
+
const event = schema({ title: 'string', startsAt: 'date', endsAt: 'date??' })
|
|
67
|
+
app.post('/events', { body: event }, (req) => {
|
|
68
|
+
return { day: req.body.startsAt.getDay() } // startsAt is a Date
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
64
72
|
## Hooks
|
|
65
73
|
|
|
66
74
|
```ts
|
package/dist/index.js
CHANGED
|
@@ -131,6 +131,8 @@ var getValidationError = (obj, step) => {
|
|
|
131
131
|
return `{"cause":"Validation error","fields":{"${obj.path.slice(1)}":{"message":"${obj.message}"}}}`;
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
+
var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,6})?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
135
|
+
var dateType = (options) => Type.Transform(Type.Union([Type.String({ pattern: DATE_PATTERN.source }), Type.Number()], options)).Decode((value) => new Date(value)).Encode((value) => value instanceof Date ? value.toISOString() : value);
|
|
134
136
|
provideTypeBoxMap({
|
|
135
137
|
string: Type.String,
|
|
136
138
|
boolean: Type.Boolean,
|
|
@@ -139,6 +141,7 @@ provideTypeBoxMap({
|
|
|
139
141
|
object: Type.Object,
|
|
140
142
|
array: Type.Array,
|
|
141
143
|
bigint: Type.BigInt,
|
|
144
|
+
date: dateType,
|
|
142
145
|
union: Type.Union,
|
|
143
146
|
null: Type.Null,
|
|
144
147
|
literal: Type.Literal,
|
|
@@ -165,8 +168,9 @@ var parseBody = (schema, req) => {
|
|
|
165
168
|
const error = schema.Errors(resp).First();
|
|
166
169
|
const err = new ValidationError(error, "body");
|
|
167
170
|
rej(err);
|
|
171
|
+
return;
|
|
168
172
|
}
|
|
169
|
-
res(resp);
|
|
173
|
+
res(schema.Decode(resp));
|
|
170
174
|
});
|
|
171
175
|
});
|
|
172
176
|
};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.0.3",
|
|
15
15
|
"description": "Simple HTTP framework powered by Bun",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@sinclair/typebox": "^0.34.37",
|
|
36
|
-
"compact-json-schema": "^0.1.
|
|
36
|
+
"compact-json-schema": "^0.1.6"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|