@innet/server 2.0.0-beta.23 → 2.0.0-beta.25
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/hooks/useData/useData.d.ts +1 -1
- package/hooks/useData/useData.es6.js +7 -2
- package/hooks/useData/useData.js +7 -2
- package/package.json +1 -1
- package/plugins/schema/string/string.d.ts +1 -1
- package/types/isoDate.d.ts +29 -1
- package/types/isoDate.es6.js +1 -1
- package/types/isoDate.js +1 -0
- package/utils/rules/dateTo/dateTo.d.ts +2 -2
|
@@ -2,5 +2,5 @@ import { type ApiEndpoints, type TEndpoint } from '../../types';
|
|
|
2
2
|
type KeysWithField<F extends string> = {
|
|
3
3
|
[K in keyof ApiEndpoints]: F extends keyof ApiEndpoints[K] ? K : never;
|
|
4
4
|
}[keyof ApiEndpoints];
|
|
5
|
-
export declare function useData<F extends Exclude<keyof TEndpoint, 'response'>, K extends KeysWithField<F> = KeysWithField<F
|
|
5
|
+
export declare function useData<F extends Exclude<keyof TEndpoint, 'response'>, K extends KeysWithField<F> = KeysWithField<F>, T extends boolean = false>(from: F, path?: K, withThrow?: T): T extends true ? ApiEndpoints[K][F] : ApiEndpoints[K][F] | undefined;
|
|
6
6
|
export {};
|
|
@@ -8,12 +8,17 @@ import { useThrow } from '../useThrow/useThrow.es6.js';
|
|
|
8
8
|
import { useAction } from '../useAction/useAction.es6.js';
|
|
9
9
|
import { paramsContext } from '../useParams/useParams.es6.js';
|
|
10
10
|
|
|
11
|
-
function useData(from, path) {
|
|
11
|
+
function useData(from, path, withThrow) {
|
|
12
12
|
if (path) {
|
|
13
13
|
const endpoint = useEndpoint();
|
|
14
14
|
const endpointKey = `${endpoint.props.method.toUpperCase()}:${endpoint.props.path}`;
|
|
15
15
|
if (endpointKey !== path) {
|
|
16
|
-
|
|
16
|
+
if (withThrow) {
|
|
17
|
+
useThrow(`<{type}> MUST be in <endpoint> of ${path}`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
const action = useAction();
|
package/hooks/useData/useData.js
CHANGED
|
@@ -12,12 +12,17 @@ var useThrow = require('../useThrow/useThrow.js');
|
|
|
12
12
|
var useAction = require('../useAction/useAction.js');
|
|
13
13
|
var useParams = require('../useParams/useParams.js');
|
|
14
14
|
|
|
15
|
-
function useData(from, path) {
|
|
15
|
+
function useData(from, path, withThrow) {
|
|
16
16
|
if (path) {
|
|
17
17
|
const endpoint = useEndpoint.useEndpoint();
|
|
18
18
|
const endpointKey = `${endpoint.props.method.toUpperCase()}:${endpoint.props.path}`;
|
|
19
19
|
if (endpointKey !== path) {
|
|
20
|
-
|
|
20
|
+
if (withThrow) {
|
|
21
|
+
useThrow.useThrow(`<{type}> MUST be in <endpoint> of ${path}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
const action = useAction.useAction();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
2
|
import { type SchemaProps } from '../../../types';
|
|
3
|
-
export type StringProps = SchemaProps<
|
|
3
|
+
export type StringProps<T extends string = string> = SchemaProps<T> & {
|
|
4
4
|
/**
|
|
5
5
|
* An optional format modifier serves as a hint at the contents and format of the string.
|
|
6
6
|
* @see https://swagger.io/docs/specification/v3_0/data-models/data-types/#strings
|
package/types/isoDate.d.ts
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ISODateOnly = `${number}-${number}-${number}`;
|
|
2
|
+
export type ISOBasicDate = `${number}`;
|
|
3
|
+
export type ISOWeekDate = `${number}-W${number}`;
|
|
4
|
+
export type ISOWeekDayDate = `${number}-W${number}-${number}`;
|
|
5
|
+
export type ISOOrdinalDate = `${number}-${number}`;
|
|
6
|
+
export type ISOTimeHM = `${number}:${number}`;
|
|
7
|
+
export type ISOTimeOnly = `${ISOTimeHM}:${number}`;
|
|
8
|
+
export type ISOTimeUTC = `${ISOTimeOnly}Z`;
|
|
9
|
+
export type ISOTimeHMUTC = `${ISOTimeHM}Z`;
|
|
10
|
+
export type ISOTimeWithOffset = `${ISOTimeOnly}${'+' | '-'}${ISOTimeHM}`;
|
|
11
|
+
export type ISOTimeHMWithOffset = `${ISOTimeHM}${'+' | '-'}${ISOTimeHM}`;
|
|
12
|
+
export type ISOLocalDateTime = `${ISODateOnly}T${ISOTimeOnly}`;
|
|
13
|
+
export type ISOLocalDateTimeMillis = `${ISODateOnly}T${ISOTimeOnly}.${number}`;
|
|
14
|
+
export type ISODateTimeUTC = `${ISODateOnly}T${ISOTimeUTC}`;
|
|
15
|
+
export type ISODateTimeUTCFractional = `${ISOLocalDateTimeMillis}Z`;
|
|
16
|
+
export type ISODateTimeWithOffset = `${ISODateOnly}T${ISOTimeOnly}${'+' | '-'}${ISOTimeHM}`;
|
|
17
|
+
export type ISODateTimeWithOffsetCompact = `${ISODateOnly}T${ISOTimeOnly}${'+' | '-'}${number}`;
|
|
18
|
+
export type ISODateTimeWithOffsetHourOnly = `${ISODateOnly}T${ISOTimeOnly}${'+' | '-'}${number}`;
|
|
19
|
+
export type ISODateTimeWithOffsetMillis = `${ISOLocalDateTimeMillis}${'+' | '-'}${ISOTimeHM}`;
|
|
20
|
+
export type ISOBasicDateTime = `${number}T${number}`;
|
|
21
|
+
export type ISOBasicDateTimeUTC = `${number}T${number}Z`;
|
|
22
|
+
export type ISOTruncatedDate = `--${number}-${number}`;
|
|
23
|
+
export type ISOTruncatedDateTime = `--${number}-${number}T${ISOTimeOnly}`;
|
|
24
|
+
export type ISOTruncatedTime = `T${ISOTimeOnly}`;
|
|
25
|
+
export type ISOTruncatedTimeHM = `T${ISOTimeHM}`;
|
|
26
|
+
export type ISODate = ISOBasicDate | ISODateOnly | ISOOrdinalDate | ISOTruncatedDate | ISOWeekDate | ISOWeekDayDate;
|
|
27
|
+
export type ISOTime = ISOTimeHM | ISOTimeHMUTC | ISOTimeHMWithOffset | ISOTimeOnly | ISOTimeUTC | ISOTimeWithOffset | ISOTruncatedTime | ISOTruncatedTimeHM;
|
|
28
|
+
export type ISODateTime = ISOBasicDateTime | ISOBasicDateTimeUTC | ISODateTimeUTC | ISODateTimeUTCFractional | ISODateTimeWithOffset | ISODateTimeWithOffsetCompact | ISODateTimeWithOffsetHourOnly | ISODateTimeWithOffsetMillis | ISOLocalDateTime | ISOLocalDateTimeMillis | ISOTruncatedDateTime;
|
|
29
|
+
export type ISOString = ISODate | ISODateTime | ISOTime;
|
package/types/isoDate.es6.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
// ==================== DATE ONLY ====================
|
package/types/isoDate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export type DateFormat = Date |
|
|
1
|
+
import { type ISOString } from '../../../types';
|
|
2
|
+
export type DateFormat = Date | ISOString | number;
|
|
3
3
|
export type DefaultDateFormat = 'now' | DateFormat;
|
|
4
4
|
export declare function dateTo(value: any, data?: object): Date;
|