wooks 0.0.1-beta.1 → 0.0.1-beta.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 +1 -1
- package/dist/src/composables/cookies.d.ts +2 -1
- package/dist/src/composables/cookies.d.ts.map +1 -1
- package/dist/src/composables/hooks.d.ts +20 -0
- package/dist/src/composables/hooks.d.ts.map +1 -0
- package/dist/src/composables/index.d.ts +1 -0
- package/dist/src/composables/index.d.ts.map +1 -1
- package/dist/wooks.cjs.prod.js +54 -2
- package/dist/wooks.d.ts +31 -0
- package/dist/wooks.esm-bundler.js +52 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<img src="./docs/icon.png" width="128px"><br>
|
|
7
|
-
<a href="https://github.com/prostojs/
|
|
7
|
+
<a href="https://github.com/prostojs/wooks/blob/main/LICENSE">
|
|
8
8
|
<img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" />
|
|
9
9
|
</a>
|
|
10
10
|
</p>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TCookieAttributes } from '../utils/set-cookie';
|
|
1
|
+
import { TCookieAttributes, TSetCookieData } from '../utils/set-cookie';
|
|
2
2
|
export declare type TCookiesCache = Record<string, string | null>;
|
|
3
3
|
export declare function useCookies(): {
|
|
4
4
|
rawCookies: string | undefined;
|
|
@@ -6,6 +6,7 @@ export declare function useCookies(): {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function useSetCookies(): {
|
|
8
8
|
setCookie: (name: string, value: string, attrs?: Partial<TCookieAttributes>) => void;
|
|
9
|
+
getCookie: (name: string) => TSetCookieData;
|
|
9
10
|
removeCookie: (name: string) => void;
|
|
10
11
|
clearCookies: () => void;
|
|
11
12
|
cookies: () => string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../../src/composables/cookies.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../../src/composables/cookies.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,iBAAiB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAErF,oBAAY,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;AAGzD,wBAAgB,UAAU;;sBAIG,MAAM;EAgBlC;AAED,wBAAgB,aAAa;sBAGA,MAAM,SAAS,MAAM,UAAU,QAAQ,iBAAiB,CAAC;sBAOzD,MAAM,KAAG,cAAc;yBAQpB,MAAM;;mBAJd,MAAM,EAAE;EAmB/B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TCookieAttributes } from '../utils/set-cookie';
|
|
2
|
+
export declare function useRespCookie(name: string): TCookieHook;
|
|
3
|
+
export declare function useRespHeader(name: string): THeaderHook;
|
|
4
|
+
export declare function useStatus(): TStatusHook;
|
|
5
|
+
export interface TWooksHook {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export declare type TCookieHook = TWooksHook & {
|
|
11
|
+
attrs: TCookieAttributes;
|
|
12
|
+
type: 'cookie';
|
|
13
|
+
};
|
|
14
|
+
export declare type THeaderHook = TWooksHook & {
|
|
15
|
+
type: 'header';
|
|
16
|
+
};
|
|
17
|
+
export declare type TStatusHook = TWooksHook & {
|
|
18
|
+
type: 'status';
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/composables/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAKvD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAqBvD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAevD;AAED,wBAAgB,SAAS,IAAI,WAAW,CAevC;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,oBAAY,WAAW,GAAG,UAAU,GAAG;IACnC,KAAK,EAAE,iBAAiB,CAAA;IACxB,IAAI,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,oBAAY,WAAW,GAAG,UAAU,GAAG;IACnC,IAAI,EAAE,QAAQ,CAAA;CACjB,CAAA;AAED,oBAAY,WAAW,GAAG,UAAU,GAAG;IACnC,IAAI,EAAE,QAAQ,CAAA;CACjB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/composables/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,OAAO,EACH,sBAAsB,EACtB,cAAc,EACd,gBAAgB,GACnB,MAAM,QAAQ,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/composables/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,OAAO,EACH,sBAAsB,EACtB,cAAc,EACd,gBAAgB,GACnB,MAAM,QAAQ,CAAA;AACf,cAAc,SAAS,CAAA"}
|
package/dist/wooks.cjs.prod.js
CHANGED
|
@@ -526,6 +526,9 @@ function useSetCookies() {
|
|
|
526
526
|
attrs: attrs || {},
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
|
+
function getCookie(name) {
|
|
530
|
+
return cache[name];
|
|
531
|
+
}
|
|
529
532
|
function cookies() {
|
|
530
533
|
return Object.entries(cache).map(([key, value]) => renderCookie(key, value));
|
|
531
534
|
}
|
|
@@ -537,6 +540,7 @@ function useSetCookies() {
|
|
|
537
540
|
}
|
|
538
541
|
return {
|
|
539
542
|
setCookie,
|
|
543
|
+
getCookie,
|
|
540
544
|
removeCookie,
|
|
541
545
|
clearCookies,
|
|
542
546
|
cookies,
|
|
@@ -812,6 +816,51 @@ function setTestHttpContext(options) {
|
|
|
812
816
|
setCurrentWooksContext(req, res, options.params || {}, cache);
|
|
813
817
|
}
|
|
814
818
|
|
|
819
|
+
function useRespCookie(name) {
|
|
820
|
+
const { setCookie, getCookie } = useSetCookies();
|
|
821
|
+
const hook = {
|
|
822
|
+
name,
|
|
823
|
+
type: 'cookie',
|
|
824
|
+
value: '',
|
|
825
|
+
attrs: {},
|
|
826
|
+
};
|
|
827
|
+
Object.defineProperty(hook, 'value', {
|
|
828
|
+
get: () => { var _a; return (_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.value; },
|
|
829
|
+
set: (value) => { var _a; return setCookie(name, value, (_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.attrs); },
|
|
830
|
+
});
|
|
831
|
+
Object.defineProperty(hook, 'attrs', {
|
|
832
|
+
get: () => { var _a; return (_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.attrs; },
|
|
833
|
+
set: (attrs) => { var _a; return setCookie(name, ((_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.value) || '', attrs); },
|
|
834
|
+
});
|
|
835
|
+
return hook;
|
|
836
|
+
}
|
|
837
|
+
function useRespHeader(name) {
|
|
838
|
+
const { setHeader, headers } = useSetHeaders();
|
|
839
|
+
const hook = {
|
|
840
|
+
name,
|
|
841
|
+
type: 'header',
|
|
842
|
+
value: '',
|
|
843
|
+
};
|
|
844
|
+
Object.defineProperty(hook, 'value', {
|
|
845
|
+
get: () => headers[name],
|
|
846
|
+
set: (value) => setHeader(name, value),
|
|
847
|
+
});
|
|
848
|
+
return hook;
|
|
849
|
+
}
|
|
850
|
+
function useStatus() {
|
|
851
|
+
const { status } = useResponse();
|
|
852
|
+
const hook = {
|
|
853
|
+
name: 'code',
|
|
854
|
+
type: 'status',
|
|
855
|
+
value: status(),
|
|
856
|
+
};
|
|
857
|
+
Object.defineProperty(hook, 'value', {
|
|
858
|
+
get: () => status(),
|
|
859
|
+
set: (code) => status(code),
|
|
860
|
+
});
|
|
861
|
+
return hook;
|
|
862
|
+
}
|
|
863
|
+
|
|
815
864
|
const httpStatusCodes = {
|
|
816
865
|
[100]: 'Continue',
|
|
817
866
|
[101]: 'Switching protocols',
|
|
@@ -1097,7 +1146,7 @@ class WooksErrorRenderer extends BaseWooksResponseRenderer {
|
|
|
1097
1146
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
1098
1147
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
1099
1148
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
1100
|
-
`<center style="color: #666;"> wooks v${"0.0.1-beta.
|
|
1149
|
+
`<center style="color: #666;"> wooks v${"0.0.1-beta.1"} </center>` +
|
|
1101
1150
|
`${keys.length ? `<pre style="${preStyles}">${JSON.stringify({ ...data, statusCode: undefined, message: undefined, error: undefined }, null, ' ')}</pre>` : ''}` +
|
|
1102
1151
|
'</body></html>';
|
|
1103
1152
|
}
|
|
@@ -1237,7 +1286,7 @@ class Wooks {
|
|
|
1237
1286
|
const found = this.router.lookup(req.method, req.url);
|
|
1238
1287
|
const ctx = {
|
|
1239
1288
|
__setHeader: {
|
|
1240
|
-
Server: 'wooks v' + "0.0.1-beta.
|
|
1289
|
+
Server: 'wooks v' + "0.0.1-beta.1",
|
|
1241
1290
|
},
|
|
1242
1291
|
};
|
|
1243
1292
|
if (found) {
|
|
@@ -2671,9 +2720,12 @@ exports.useCookies = useCookies;
|
|
|
2671
2720
|
exports.useCurrentWooksContext = useCurrentWooksContext;
|
|
2672
2721
|
exports.useHeaders = useHeaders;
|
|
2673
2722
|
exports.useRequest = useRequest;
|
|
2723
|
+
exports.useRespCookie = useRespCookie;
|
|
2724
|
+
exports.useRespHeader = useRespHeader;
|
|
2674
2725
|
exports.useResponse = useResponse;
|
|
2675
2726
|
exports.useRouteParams = useRouteParams;
|
|
2676
2727
|
exports.useSearchParams = useSearchParams;
|
|
2677
2728
|
exports.useSetCacheControl = useSetCacheControl;
|
|
2678
2729
|
exports.useSetCookies = useSetCookies;
|
|
2679
2730
|
exports.useSetHeaders = useSetHeaders;
|
|
2731
|
+
exports.useStatus = useStatus;
|
package/dist/wooks.d.ts
CHANGED
|
@@ -324,6 +324,11 @@ declare interface TCookieAttributes {
|
|
|
324
324
|
sameSite: boolean | 'Lax' | 'None' | 'Strict';
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
export declare type TCookieHook = TWooksHook & {
|
|
328
|
+
attrs: TCookieAttributes;
|
|
329
|
+
type: 'cookie';
|
|
330
|
+
};
|
|
331
|
+
|
|
327
332
|
export declare type TCookiesCache = Record<string, string | null>;
|
|
328
333
|
|
|
329
334
|
declare interface TCurrentWooksContext {
|
|
@@ -333,6 +338,10 @@ declare interface TCurrentWooksContext {
|
|
|
333
338
|
customContext: TWooksCustomContext;
|
|
334
339
|
}
|
|
335
340
|
|
|
341
|
+
export declare type THeaderHook = TWooksHook & {
|
|
342
|
+
type: 'header';
|
|
343
|
+
};
|
|
344
|
+
|
|
336
345
|
export declare type THttpBadRequestCodes = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
337
346
|
|
|
338
347
|
export declare type THttpErrorCodes = THttpBadRequestCodes | THttpServerErrorCodes;
|
|
@@ -364,6 +373,15 @@ declare interface TServeFileOptions {
|
|
|
364
373
|
index?: string;
|
|
365
374
|
}
|
|
366
375
|
|
|
376
|
+
declare type TSetCookieData = {
|
|
377
|
+
value: string;
|
|
378
|
+
attrs: Partial<TCookieAttributes>;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
export declare type TStatusHook = TWooksHook & {
|
|
382
|
+
type: 'status';
|
|
383
|
+
};
|
|
384
|
+
|
|
367
385
|
export declare interface TTestHttpContext {
|
|
368
386
|
params?: TProstoParamsType;
|
|
369
387
|
url: string;
|
|
@@ -396,6 +414,12 @@ export declare interface TWooksErrorBodyExt extends TWooksErrorBody {
|
|
|
396
414
|
|
|
397
415
|
export declare type TWooksHandler<ResType = unknown> = () => Promise<ResType> | ResType | Error | Promise<Error> | BaseWooksResponse<ResType> | Promise<BaseWooksResponse<ResType>>;
|
|
398
416
|
|
|
417
|
+
export declare interface TWooksHook {
|
|
418
|
+
name: string;
|
|
419
|
+
type: string;
|
|
420
|
+
value: string;
|
|
421
|
+
}
|
|
422
|
+
|
|
399
423
|
export declare interface TWooksOptions {
|
|
400
424
|
}
|
|
401
425
|
|
|
@@ -469,6 +493,10 @@ export declare function useRequest(): {
|
|
|
469
493
|
customContext: TWooksCustomContext;
|
|
470
494
|
};
|
|
471
495
|
|
|
496
|
+
export declare function useRespCookie(name: string): TCookieHook;
|
|
497
|
+
|
|
498
|
+
export declare function useRespHeader(name: string): THeaderHook;
|
|
499
|
+
|
|
472
500
|
export declare function useResponse(): {
|
|
473
501
|
rawResponse: (options?: TUseResponseOptions) => ServerResponse<IncomingMessage>;
|
|
474
502
|
hasResponded: () => boolean;
|
|
@@ -495,6 +523,7 @@ export declare function useSetCacheControl(): {
|
|
|
495
523
|
|
|
496
524
|
export declare function useSetCookies(): {
|
|
497
525
|
setCookie: (name: string, value: string, attrs?: Partial<TCookieAttributes>) => void;
|
|
526
|
+
getCookie: (name: string) => TSetCookieData;
|
|
498
527
|
removeCookie: (name: string) => void;
|
|
499
528
|
clearCookies: () => void;
|
|
500
529
|
cookies: () => string[];
|
|
@@ -508,6 +537,8 @@ export declare function useSetHeaders(): {
|
|
|
508
537
|
enableCors: (origin?: string) => void;
|
|
509
538
|
};
|
|
510
539
|
|
|
540
|
+
export declare function useStatus(): TStatusHook;
|
|
541
|
+
|
|
511
542
|
export declare class Wooks {
|
|
512
543
|
private options?;
|
|
513
544
|
protected router: ProstoRouter<TWooksHandler>;
|
|
@@ -517,6 +517,9 @@ function useSetCookies() {
|
|
|
517
517
|
attrs: attrs || {},
|
|
518
518
|
};
|
|
519
519
|
}
|
|
520
|
+
function getCookie(name) {
|
|
521
|
+
return cache[name];
|
|
522
|
+
}
|
|
520
523
|
function cookies() {
|
|
521
524
|
return Object.entries(cache).map(([key, value]) => renderCookie(key, value));
|
|
522
525
|
}
|
|
@@ -528,6 +531,7 @@ function useSetCookies() {
|
|
|
528
531
|
}
|
|
529
532
|
return {
|
|
530
533
|
setCookie,
|
|
534
|
+
getCookie,
|
|
531
535
|
removeCookie,
|
|
532
536
|
clearCookies,
|
|
533
537
|
cookies,
|
|
@@ -803,6 +807,51 @@ function setTestHttpContext(options) {
|
|
|
803
807
|
setCurrentWooksContext(req, res, options.params || {}, cache);
|
|
804
808
|
}
|
|
805
809
|
|
|
810
|
+
function useRespCookie(name) {
|
|
811
|
+
const { setCookie, getCookie } = useSetCookies();
|
|
812
|
+
const hook = {
|
|
813
|
+
name,
|
|
814
|
+
type: 'cookie',
|
|
815
|
+
value: '',
|
|
816
|
+
attrs: {},
|
|
817
|
+
};
|
|
818
|
+
Object.defineProperty(hook, 'value', {
|
|
819
|
+
get: () => { var _a; return (_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.value; },
|
|
820
|
+
set: (value) => { var _a; return setCookie(name, value, (_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.attrs); },
|
|
821
|
+
});
|
|
822
|
+
Object.defineProperty(hook, 'attrs', {
|
|
823
|
+
get: () => { var _a; return (_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.attrs; },
|
|
824
|
+
set: (attrs) => { var _a; return setCookie(name, ((_a = getCookie(name)) === null || _a === void 0 ? void 0 : _a.value) || '', attrs); },
|
|
825
|
+
});
|
|
826
|
+
return hook;
|
|
827
|
+
}
|
|
828
|
+
function useRespHeader(name) {
|
|
829
|
+
const { setHeader, headers } = useSetHeaders();
|
|
830
|
+
const hook = {
|
|
831
|
+
name,
|
|
832
|
+
type: 'header',
|
|
833
|
+
value: '',
|
|
834
|
+
};
|
|
835
|
+
Object.defineProperty(hook, 'value', {
|
|
836
|
+
get: () => headers[name],
|
|
837
|
+
set: (value) => setHeader(name, value),
|
|
838
|
+
});
|
|
839
|
+
return hook;
|
|
840
|
+
}
|
|
841
|
+
function useStatus() {
|
|
842
|
+
const { status } = useResponse();
|
|
843
|
+
const hook = {
|
|
844
|
+
name: 'code',
|
|
845
|
+
type: 'status',
|
|
846
|
+
value: status(),
|
|
847
|
+
};
|
|
848
|
+
Object.defineProperty(hook, 'value', {
|
|
849
|
+
get: () => status(),
|
|
850
|
+
set: (code) => status(code),
|
|
851
|
+
});
|
|
852
|
+
return hook;
|
|
853
|
+
}
|
|
854
|
+
|
|
806
855
|
const httpStatusCodes = {
|
|
807
856
|
[100]: 'Continue',
|
|
808
857
|
[101]: 'Switching protocols',
|
|
@@ -1088,7 +1137,7 @@ class WooksErrorRenderer extends BaseWooksResponseRenderer {
|
|
|
1088
1137
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
1089
1138
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
1090
1139
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
1091
|
-
`<center style="color: #666;"> wooks v${"0.0.1-beta.
|
|
1140
|
+
`<center style="color: #666;"> wooks v${"0.0.1-beta.1"} </center>` +
|
|
1092
1141
|
`${keys.length ? `<pre style="${preStyles}">${JSON.stringify({ ...data, statusCode: undefined, message: undefined, error: undefined }, null, ' ')}</pre>` : ''}` +
|
|
1093
1142
|
'</body></html>';
|
|
1094
1143
|
}
|
|
@@ -1228,7 +1277,7 @@ class Wooks {
|
|
|
1228
1277
|
const found = this.router.lookup(req.method, req.url);
|
|
1229
1278
|
const ctx = {
|
|
1230
1279
|
__setHeader: {
|
|
1231
|
-
Server: 'wooks v' + "0.0.1-beta.
|
|
1280
|
+
Server: 'wooks v' + "0.0.1-beta.1",
|
|
1232
1281
|
},
|
|
1233
1282
|
};
|
|
1234
1283
|
if (found) {
|
|
@@ -2641,4 +2690,4 @@ async function listDirectory(dirPath) {
|
|
|
2641
2690
|
'</ul></body></html>';
|
|
2642
2691
|
}
|
|
2643
2692
|
|
|
2644
|
-
export { BaseWooksResponse, BaseWooksResponseRenderer, EHttpStatusCode, Wooks, WooksError, WooksErrorRenderer, clearCacheObject, contentTypes, createResponseFrom, httpStatusCodes, registerBodyCompressor, serveFile, setTestHttpContext, statFile, useAccept, useAuthorization, useBody, useCacheObject, useCookies, useCurrentWooksContext, useHeaders, useRequest, useResponse, useRouteParams, useSearchParams, useSetCacheControl, useSetCookies, useSetHeaders };
|
|
2693
|
+
export { BaseWooksResponse, BaseWooksResponseRenderer, EHttpStatusCode, Wooks, WooksError, WooksErrorRenderer, clearCacheObject, contentTypes, createResponseFrom, httpStatusCodes, registerBodyCompressor, serveFile, setTestHttpContext, statFile, useAccept, useAuthorization, useBody, useCacheObject, useCookies, useCurrentWooksContext, useHeaders, useRequest, useRespCookie, useRespHeader, useResponse, useRouteParams, useSearchParams, useSetCacheControl, useSetCookies, useSetHeaders, useStatus };
|