@innet/server 2.0.0-beta.17 → 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
|
@@ -84,5 +84,7 @@ export interface TEndpoint {
|
|
|
84
84
|
response?: Record<string, TResponse>;
|
|
85
85
|
search?: Record<string, unknown>;
|
|
86
86
|
}
|
|
87
|
-
export
|
|
88
|
-
|
|
87
|
+
export interface ApiEndpoints {
|
|
88
|
+
}
|
|
89
|
+
export interface ApiSchemas {
|
|
90
|
+
}
|
|
@@ -97,18 +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
|
-
export interface Bin {
|
|
102
|
-
filename: string
|
|
103
|
-
fieldName: string
|
|
104
|
-
originalFilename: string
|
|
105
|
-
path: string
|
|
106
|
-
type: string
|
|
107
|
-
disposition: string
|
|
108
|
-
size: number
|
|
109
|
-
extension?: string
|
|
110
|
-
}
|
|
111
|
-
`;
|
|
100
|
+
let result = '';
|
|
112
101
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
113
102
|
const paths = docs.paths;
|
|
114
103
|
if (schemas) {
|
|
@@ -183,12 +172,18 @@ function generateTypes(docs, namespace = 'Api') {
|
|
|
183
172
|
result += ' }\n';
|
|
184
173
|
}
|
|
185
174
|
}
|
|
186
|
-
const body = result + ' }
|
|
187
|
-
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
|
+
}
|
|
188
183
|
|
|
189
184
|
declare module '@innet/server' {
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
interface ApiEndpoints extends ${namespace}.Endpoints {}
|
|
186
|
+
interface ApiSchemas extends ${namespace}.Schemas {}
|
|
192
187
|
}
|
|
193
188
|
`;
|
|
194
189
|
}
|
|
@@ -101,18 +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
|
-
export interface Bin {
|
|
106
|
-
filename: string
|
|
107
|
-
fieldName: string
|
|
108
|
-
originalFilename: string
|
|
109
|
-
path: string
|
|
110
|
-
type: string
|
|
111
|
-
disposition: string
|
|
112
|
-
size: number
|
|
113
|
-
extension?: string
|
|
114
|
-
}
|
|
115
|
-
`;
|
|
104
|
+
let result = '';
|
|
116
105
|
const schemas = (_a = docs.components) === null || _a === void 0 ? void 0 : _a.schemas;
|
|
117
106
|
const paths = docs.paths;
|
|
118
107
|
if (schemas) {
|
|
@@ -187,12 +176,18 @@ function generateTypes(docs, namespace = 'Api') {
|
|
|
187
176
|
result += ' }\n';
|
|
188
177
|
}
|
|
189
178
|
}
|
|
190
|
-
const body = result + ' }
|
|
191
|
-
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
|
+
}
|
|
192
187
|
|
|
193
188
|
declare module '@innet/server' {
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
interface ApiEndpoints extends ${namespace}.Endpoints {}
|
|
190
|
+
interface ApiSchemas extends ${namespace}.Schemas {}
|
|
196
191
|
}
|
|
197
192
|
`;
|
|
198
193
|
}
|