@innet/server 2.0.0-beta.18 → 2.0.0-beta.19
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type ApiEndpoints, type TEndpoint } from '../../types';
|
|
2
|
-
export declare function useData<F extends Exclude<keyof TEndpoint, 'response'>, D extends keyof ApiEndpoints>(from: F, path?: D): ApiEndpoints[D][F];
|
|
2
|
+
export declare function useData<F extends Exclude<keyof TEndpoint, 'response'>, D extends keyof ApiEndpoints = keyof ApiEndpoints>(from: F, path?: D): ApiEndpoints[D][F];
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { useContext } from '@innet/jsx';
|
|
1
2
|
import '../useAction/index.es6.js';
|
|
2
3
|
import '../useEndpoint/index.es6.js';
|
|
4
|
+
import '../useParams/index.es6.js';
|
|
3
5
|
import '../useThrow/index.es6.js';
|
|
4
6
|
import { useEndpoint } from '../useEndpoint/useEndpoint.es6.js';
|
|
5
7
|
import { useThrow } from '../useThrow/useThrow.es6.js';
|
|
6
8
|
import { useAction } from '../useAction/useAction.es6.js';
|
|
9
|
+
import { paramsContext } from '../useParams/useParams.es6.js';
|
|
7
10
|
|
|
8
11
|
function useData(from, path) {
|
|
9
12
|
if (path) {
|
|
@@ -17,6 +20,9 @@ function useData(from, path) {
|
|
|
17
20
|
if (!action) {
|
|
18
21
|
useThrow('<{type}> MUST be in <return> or <preset>');
|
|
19
22
|
}
|
|
23
|
+
if (from === 'params') {
|
|
24
|
+
return useContext(paramsContext);
|
|
25
|
+
}
|
|
20
26
|
return action[from];
|
|
21
27
|
}
|
|
22
28
|
|
package/hooks/useData/useData.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
5
6
|
require('../useAction/index.js');
|
|
6
7
|
require('../useEndpoint/index.js');
|
|
8
|
+
require('../useParams/index.js');
|
|
7
9
|
require('../useThrow/index.js');
|
|
8
10
|
var useEndpoint = require('../useEndpoint/useEndpoint.js');
|
|
9
11
|
var useThrow = require('../useThrow/useThrow.js');
|
|
10
12
|
var useAction = require('../useAction/useAction.js');
|
|
13
|
+
var useParams = require('../useParams/useParams.js');
|
|
11
14
|
|
|
12
15
|
function useData(from, path) {
|
|
13
16
|
if (path) {
|
|
@@ -21,6 +24,9 @@ function useData(from, path) {
|
|
|
21
24
|
if (!action) {
|
|
22
25
|
useThrow.useThrow('<{type}> MUST be in <return> or <preset>');
|
|
23
26
|
}
|
|
27
|
+
if (from === 'params') {
|
|
28
|
+
return jsx.useContext(useParams.paramsContext);
|
|
29
|
+
}
|
|
24
30
|
return action[from];
|
|
25
31
|
}
|
|
26
32
|
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -75,16 +75,6 @@ export interface ValuesSchemaProps<T> extends BaseSchemaProps<T> {
|
|
|
75
75
|
value?: T;
|
|
76
76
|
values?: SchemaValues<T>;
|
|
77
77
|
}
|
|
78
|
-
export interface Bin {
|
|
79
|
-
disposition: string;
|
|
80
|
-
extension?: string;
|
|
81
|
-
fieldName: string;
|
|
82
|
-
filename: string;
|
|
83
|
-
originalFilename: string;
|
|
84
|
-
path: string;
|
|
85
|
-
size: number;
|
|
86
|
-
type: string;
|
|
87
|
-
}
|
|
88
78
|
export type TResponse = Record<ResponseStatus, unknown>;
|
|
89
79
|
export interface TEndpoint {
|
|
90
80
|
body?: unknown;
|
|
@@ -95,8 +85,6 @@ export interface TEndpoint {
|
|
|
95
85
|
search?: Record<string, unknown>;
|
|
96
86
|
}
|
|
97
87
|
export interface ApiEndpoints {
|
|
98
|
-
[key: string]: TEndpoint;
|
|
99
88
|
}
|
|
100
89
|
export interface ApiSchemas {
|
|
101
|
-
[key: string]: unknown;
|
|
102
90
|
}
|
|
@@ -97,9 +97,7 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
97
97
|
}
|
|
98
98
|
function generateTypes(docs, namespace = 'Api') {
|
|
99
99
|
var _a;
|
|
100
|
-
let result =
|
|
101
|
-
declare namespace ${namespace} {
|
|
102
|
-
`;
|
|
100
|
+
let result = '';
|
|
103
101
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
104
102
|
const paths = docs.paths;
|
|
105
103
|
if (schemas) {
|
|
@@ -174,8 +172,14 @@ declare namespace ${namespace} {
|
|
|
174
172
|
result += ' }\n';
|
|
175
173
|
}
|
|
176
174
|
}
|
|
177
|
-
const body = result + ' }
|
|
178
|
-
return
|
|
175
|
+
const body = result + ' }';
|
|
176
|
+
return `import '@innet/server'
|
|
177
|
+
${body.includes('Bin') ? 'import { Bin } from \'@innet/server\'\n' : ''}
|
|
178
|
+
declare global {
|
|
179
|
+
namespace ${namespace} {
|
|
180
|
+
${body}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
179
183
|
|
|
180
184
|
declare module '@innet/server' {
|
|
181
185
|
interface ApiEndpoints extends ${namespace}.Endpoints {}
|
|
@@ -101,9 +101,7 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
|
|
|
101
101
|
}
|
|
102
102
|
function generateTypes(docs, namespace = 'Api') {
|
|
103
103
|
var _a;
|
|
104
|
-
let result =
|
|
105
|
-
declare namespace ${namespace} {
|
|
106
|
-
`;
|
|
104
|
+
let result = '';
|
|
107
105
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
108
106
|
const paths = docs.paths;
|
|
109
107
|
if (schemas) {
|
|
@@ -178,8 +176,14 @@ declare namespace ${namespace} {
|
|
|
178
176
|
result += ' }\n';
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
|
-
const body = result + ' }
|
|
182
|
-
return
|
|
179
|
+
const body = result + ' }';
|
|
180
|
+
return `import '@innet/server'
|
|
181
|
+
${body.includes('Bin') ? 'import { Bin } from \'@innet/server\'\n' : ''}
|
|
182
|
+
declare global {
|
|
183
|
+
namespace ${namespace} {
|
|
184
|
+
${body}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
183
187
|
|
|
184
188
|
declare module '@innet/server' {
|
|
185
189
|
interface ApiEndpoints extends ${namespace}.Endpoints {}
|