@innet/server 2.0.0-alpha.1 → 2.0.0-alpha.11
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 +417 -29
- package/example/requests/index.d.ts +1 -1
- package/example/requests/todo/AddTodo/AddTodo.d.ts +1 -0
- package/example/requests/todo/AddTodo/index.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/index.d.ts +1 -0
- package/example/requests/todo/EditTodo/EditTodo.d.ts +1 -0
- package/example/requests/todo/EditTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodo/GetTodo.d.ts +1 -0
- package/example/requests/todo/GetTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodos/GetTodos.d.ts +1 -0
- package/example/requests/todo/GetTodos/index.d.ts +1 -0
- package/example/requests/todo/index.d.ts +5 -0
- package/example/requests/todo/todos.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/index.d.ts +1 -0
- package/example/schemas/app/ListSchema/ListSchema.d.ts +4 -1
- package/example/schemas/app/index.d.ts +1 -0
- package/example/schemas/index.d.ts +1 -3
- package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +4 -0
- package/example/schemas/todo/TodoSchema/index.d.ts +1 -0
- package/example/schemas/todo/index.d.ts +1 -0
- package/example/tags/Todo/Todo.d.ts +1 -0
- package/example/tags/Todo/index.d.ts +1 -0
- package/example/tags/index.d.ts +1 -1
- package/handler/handler.d.ts +3 -1
- package/handler/handler.es6.js +2 -0
- package/handler/handler.js +2 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.es6.js +2 -0
- package/hooks/index.js +2 -0
- package/hooks/useClientIp/index.d.ts +1 -0
- package/hooks/useClientIp/index.es6.js +1 -0
- package/hooks/useClientIp/index.js +9 -0
- package/hooks/useClientIp/useClientIp.d.ts +1 -0
- package/hooks/useClientIp/useClientIp.es6.js +9 -0
- package/hooks/useClientIp/useClientIp.js +13 -0
- package/hooks/useComponentName/useComponentName.d.ts +1 -1
- package/hooks/useRequestPlugin/index.d.ts +1 -0
- package/hooks/useRequestPlugin/index.es6.js +1 -0
- package/hooks/useRequestPlugin/index.js +9 -0
- package/hooks/useRequestPlugin/useRequestPlugin.d.ts +2 -0
- package/hooks/useRequestPlugin/useRequestPlugin.es6.js +13 -0
- package/hooks/useRequestPlugin/useRequestPlugin.js +17 -0
- package/index.es6.js +5 -1
- package/index.js +10 -0
- package/package.json +2 -2
- package/plugins/main/api/api.es6.js +18 -11
- package/plugins/main/api/api.js +18 -11
- package/plugins/main/response/index.es6.js +1 -1
- package/plugins/main/response/index.js +1 -0
- package/plugins/main/response/response.d.ts +5 -2
- package/plugins/main/response/response.es6.js +10 -2
- package/plugins/main/response/response.js +10 -1
- package/plugins/main/server/server.es6.js +4 -1
- package/plugins/main/server/server.js +4 -1
- package/plugins/request/cookie/cookie.es6.js +3 -19
- package/plugins/request/cookie/cookie.js +3 -23
- package/plugins/request/redirect/redirect.d.ts +2 -1
- package/plugins/request/success/success.d.ts +1 -0
- package/plugins/request/success/success.es6.js +13 -4
- package/plugins/request/success/success.js +13 -4
- package/plugins/schema/boolean/boolean.es6.js +2 -4
- package/plugins/schema/boolean/boolean.js +1 -3
- package/plugins/utils/dts/dts.d.ts +1 -2
- package/plugins/utils/dts/dts.es6.js +6 -25
- package/plugins/utils/dts/dts.js +5 -29
- package/plugins/utils/index.d.ts +1 -0
- package/plugins/utils/index.es6.js +1 -0
- package/plugins/utils/index.js +1 -0
- package/plugins/utils/protection/index.d.ts +1 -0
- package/plugins/utils/protection/index.es6.js +1 -0
- package/plugins/utils/protection/index.js +9 -0
- package/plugins/utils/protection/protection.d.ts +8 -0
- package/plugins/utils/protection/protection.es6.js +34 -0
- package/plugins/utils/protection/protection.js +38 -0
- package/plugins/utils/swagger/swagger.es6.js +7 -11
- package/plugins/utils/swagger/swagger.js +7 -11
- package/types.d.ts +2 -3
- package/utils/action/Action.d.ts +7 -4
- package/utils/action/Action.es6.js +25 -3
- package/utils/action/Action.js +26 -4
- package/utils/generateTypes/generateTypes.d.ts +3 -0
- package/utils/generateTypes/generateTypes.es6.js +102 -0
- package/utils/generateTypes/generateTypes.js +107 -0
- package/utils/generateTypes/generateTypes.test.d.ts +1 -0
- package/utils/generateTypes/index.d.ts +1 -0
- package/utils/generateTypes/index.es6.js +1 -0
- package/utils/generateTypes/index.js +10 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +1 -0
- package/utils/rules/objectOf/objectOf.es6.js +4 -1
- package/utils/rules/objectOf/objectOf.js +4 -1
- package/example/requests/partners/EditPartner/EditPartner.d.ts +0 -1
- package/example/requests/partners/EditPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartner/GetPartner.d.ts +0 -1
- package/example/requests/partners/GetPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartners/GetPartners.d.ts +0 -1
- package/example/requests/partners/GetPartners/index.d.ts +0 -1
- package/example/requests/partners/index.d.ts +0 -3
- package/example/schemas/address/AddressSchema/AddressSchema.d.ts +0 -1
- package/example/schemas/address/AddressSchema/index.d.ts +0 -1
- package/example/schemas/address/index.d.ts +0 -1
- package/example/schemas/location/LocationSchema/LocationSchema.d.ts +0 -1
- package/example/schemas/location/LocationSchema/index.d.ts +0 -1
- package/example/schemas/location/index.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/index.d.ts +0 -2
- package/example/tags/Partner/Partner.d.ts +0 -1
- package/example/tags/Partner/index.d.ts +0 -1
package/README.md
CHANGED
|
@@ -317,7 +317,9 @@ This section contains elements of utils.
|
|
|
317
317
|
|
|
318
318
|
[\<swagger>](#swagger)
|
|
319
319
|
[\<dev>](#dev)
|
|
320
|
-
[\<
|
|
320
|
+
[\<prod>](#prod)
|
|
321
|
+
[\<dts>](#dts)
|
|
322
|
+
[\<protection>](#protection)
|
|
321
323
|
|
|
322
324
|
---
|
|
323
325
|
|
|
@@ -374,6 +376,25 @@ export default (
|
|
|
374
376
|
)
|
|
375
377
|
```
|
|
376
378
|
|
|
379
|
+
### \<prod>
|
|
380
|
+
|
|
381
|
+
[← back](#utils)
|
|
382
|
+
|
|
383
|
+
Everything inside <prod> will work when `NODE_ENV` equals `production`.
|
|
384
|
+
|
|
385
|
+
*src/app.tsx*
|
|
386
|
+
```typescript jsx
|
|
387
|
+
export default (
|
|
388
|
+
<server>
|
|
389
|
+
<api>
|
|
390
|
+
<prod>
|
|
391
|
+
<swagger />
|
|
392
|
+
</prod>
|
|
393
|
+
</api>
|
|
394
|
+
</server>
|
|
395
|
+
)
|
|
396
|
+
```
|
|
397
|
+
|
|
377
398
|
### \<dts>
|
|
378
399
|
|
|
379
400
|
[← back](#utils)
|
|
@@ -396,21 +417,178 @@ export default (
|
|
|
396
417
|
)
|
|
397
418
|
```
|
|
398
419
|
|
|
399
|
-
|
|
400
|
-
|
|
420
|
+
You do not need to import types, use `Api` namespace everywhere.
|
|
401
421
|
Here is an example of generated types usage.
|
|
402
422
|
|
|
403
|
-
*src/GetPartner.tsx*
|
|
404
423
|
```typescript jsx
|
|
405
424
|
import { useParams } from '@innet/server'
|
|
406
425
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
426
|
+
import { todos } from '../todos'
|
|
427
|
+
|
|
428
|
+
export function DeleteTodo () {
|
|
429
|
+
const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
|
|
430
|
+
|
|
431
|
+
const todoIndex = todos.findIndex(({ id }) => id === todoId)
|
|
432
|
+
|
|
433
|
+
if (todoIndex === -1) {
|
|
434
|
+
return <error code='todoNotFound' status={404} />
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
todos.splice(todoIndex, 1)
|
|
438
|
+
|
|
439
|
+
return <success />
|
|
410
440
|
}
|
|
411
441
|
```
|
|
412
442
|
|
|
413
|
-
|
|
443
|
+
### \<protection>
|
|
444
|
+
|
|
445
|
+
This element MUST be placed in `<api>` element.
|
|
446
|
+
|
|
447
|
+
[← back](#utils)
|
|
448
|
+
|
|
449
|
+
This element adds protection page.
|
|
450
|
+
You can use it when you want to protect your application.
|
|
451
|
+
|
|
452
|
+
If protection failed content of the element should be used.
|
|
453
|
+
|
|
454
|
+
*src/app.tsx*
|
|
455
|
+
```typescript jsx
|
|
456
|
+
export default (
|
|
457
|
+
<server>
|
|
458
|
+
<api>
|
|
459
|
+
<protection>
|
|
460
|
+
<error
|
|
461
|
+
code='protection'
|
|
462
|
+
status='forbidden'
|
|
463
|
+
/>
|
|
464
|
+
</protection>
|
|
465
|
+
</api>
|
|
466
|
+
</server>
|
|
467
|
+
)
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
#### value
|
|
471
|
+
|
|
472
|
+
This prop is a secret string of protection value.
|
|
473
|
+
User must provide a protection query param equals the `value`.
|
|
474
|
+
|
|
475
|
+
By default, the value is `undefined` and protection does not work.
|
|
476
|
+
You can use `PROTECTION` env to set default protection `value`.
|
|
477
|
+
|
|
478
|
+
*src/app.tsx*
|
|
479
|
+
```typescript jsx
|
|
480
|
+
export default (
|
|
481
|
+
<server>
|
|
482
|
+
<api>
|
|
483
|
+
<protection value='secret'>
|
|
484
|
+
<error
|
|
485
|
+
code='protection'
|
|
486
|
+
status='forbidden'
|
|
487
|
+
/>
|
|
488
|
+
</protection>
|
|
489
|
+
</api>
|
|
490
|
+
</server>
|
|
491
|
+
)
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
#### maxAge
|
|
495
|
+
|
|
496
|
+
This prop sets how much time protection is qualified.
|
|
497
|
+
|
|
498
|
+
By default, the prop equals a year.
|
|
499
|
+
You can use `PROTECTION_MAX_AGE` env to set default `maxAge`.
|
|
500
|
+
|
|
501
|
+
*src/app.tsx*
|
|
502
|
+
```typescript jsx
|
|
503
|
+
export default (
|
|
504
|
+
<server>
|
|
505
|
+
<api>
|
|
506
|
+
<protection
|
|
507
|
+
maxAge={24 * 60 * 60}
|
|
508
|
+
value='secret'>
|
|
509
|
+
<error
|
|
510
|
+
code='protection'
|
|
511
|
+
status='forbidden'
|
|
512
|
+
/>
|
|
513
|
+
</protection>
|
|
514
|
+
</api>
|
|
515
|
+
</server>
|
|
516
|
+
)
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
#### excludeIp
|
|
520
|
+
|
|
521
|
+
This prop sets a list of IP addresses (split by `,`) to ignore the protection.
|
|
522
|
+
|
|
523
|
+
You can use `PROTECTED_IP` env to set default `excludeIp`.
|
|
524
|
+
|
|
525
|
+
*src/app.tsx*
|
|
526
|
+
```typescript jsx
|
|
527
|
+
export default (
|
|
528
|
+
<server>
|
|
529
|
+
<api>
|
|
530
|
+
<protection
|
|
531
|
+
excludeIp='0.0.0.0,127.0.0.0'
|
|
532
|
+
value='secret'>
|
|
533
|
+
<error
|
|
534
|
+
code='protection'
|
|
535
|
+
status='forbidden'
|
|
536
|
+
/>
|
|
537
|
+
</protection>
|
|
538
|
+
</api>
|
|
539
|
+
</server>
|
|
540
|
+
)
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
#### cookieKey
|
|
544
|
+
|
|
545
|
+
This prop sets a cookie field name used to store protection of a user.
|
|
546
|
+
|
|
547
|
+
By default, it equals `protection`.
|
|
548
|
+
You can use `PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
|
|
549
|
+
|
|
550
|
+
*src/app.tsx*
|
|
551
|
+
```typescript jsx
|
|
552
|
+
export default (
|
|
553
|
+
<server>
|
|
554
|
+
<api>
|
|
555
|
+
<protection
|
|
556
|
+
cookieKey='secret'
|
|
557
|
+
value='secret'>
|
|
558
|
+
<error
|
|
559
|
+
code='protection'
|
|
560
|
+
status='forbidden'
|
|
561
|
+
/>
|
|
562
|
+
</protection>
|
|
563
|
+
</api>
|
|
564
|
+
</server>
|
|
565
|
+
)
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
#### searchKey
|
|
569
|
+
|
|
570
|
+
This prop sets a search query field name used to check protection.
|
|
571
|
+
|
|
572
|
+
By default, it equals `protection`.
|
|
573
|
+
You can use `PROTECTION_SEARCH_KEY` env to set default `searchKey`.
|
|
574
|
+
|
|
575
|
+
*src/app.tsx*
|
|
576
|
+
```typescript jsx
|
|
577
|
+
export default (
|
|
578
|
+
<server>
|
|
579
|
+
<api>
|
|
580
|
+
<protection
|
|
581
|
+
searchKey='secret'
|
|
582
|
+
value='secret'>
|
|
583
|
+
<error
|
|
584
|
+
code='protection'
|
|
585
|
+
status='forbidden'
|
|
586
|
+
/>
|
|
587
|
+
</protection>
|
|
588
|
+
</api>
|
|
589
|
+
</server>
|
|
590
|
+
)
|
|
591
|
+
```
|
|
414
592
|
|
|
415
593
|
## API Info
|
|
416
594
|
|
|
@@ -980,6 +1158,7 @@ This element MUST be placed inside `<endpoint>`.
|
|
|
980
1158
|
It defines request body for the endpoint.
|
|
981
1159
|
`@innet/server` formats and validate the value automatically (real-time).
|
|
982
1160
|
|
|
1161
|
+
*src/app.tsx*
|
|
983
1162
|
```typescript jsx
|
|
984
1163
|
return (
|
|
985
1164
|
<server>
|
|
@@ -1013,6 +1192,105 @@ return (
|
|
|
1013
1192
|
This element MUST be placed inside `<endpoint>`.
|
|
1014
1193
|
It defines response body for the endpoint.
|
|
1015
1194
|
|
|
1195
|
+
*src/app.tsx*
|
|
1196
|
+
```typescript jsx
|
|
1197
|
+
return (
|
|
1198
|
+
<server>
|
|
1199
|
+
<api>
|
|
1200
|
+
<endpoint method='get' path='/settings'>
|
|
1201
|
+
<response>
|
|
1202
|
+
<object />
|
|
1203
|
+
</response>
|
|
1204
|
+
</endpoint>
|
|
1205
|
+
</api>
|
|
1206
|
+
</server>
|
|
1207
|
+
)
|
|
1208
|
+
```
|
|
1209
|
+
|
|
1210
|
+
#### status
|
|
1211
|
+
A status of the `<response>`.
|
|
1212
|
+
Any [HTTP status code](https://swagger.io/specification/#http-codes) can be used as a number of the property.
|
|
1213
|
+
|
|
1214
|
+
By default, `status` equals `'default'`.
|
|
1215
|
+
|
|
1216
|
+
*src/app.tsx*
|
|
1217
|
+
```typescript jsx
|
|
1218
|
+
return (
|
|
1219
|
+
<server>
|
|
1220
|
+
<api>
|
|
1221
|
+
<endpoint method='get' path='/settings'>
|
|
1222
|
+
<response status={200}>
|
|
1223
|
+
<object />
|
|
1224
|
+
</response>
|
|
1225
|
+
</endpoint>
|
|
1226
|
+
</api>
|
|
1227
|
+
</server>
|
|
1228
|
+
)
|
|
1229
|
+
```
|
|
1230
|
+
|
|
1231
|
+
To define a range of response codes, this field MAY contain the uppercase wildcard character `X`.
|
|
1232
|
+
For example, `2XX` represents all response codes between \[200-299].
|
|
1233
|
+
Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX` and `5XX`.
|
|
1234
|
+
|
|
1235
|
+
*src/app.tsx*
|
|
1236
|
+
```typescript jsx
|
|
1237
|
+
return (
|
|
1238
|
+
<server>
|
|
1239
|
+
<api>
|
|
1240
|
+
<endpoint method='get' path='/settings'>
|
|
1241
|
+
<response status='2XX'>
|
|
1242
|
+
<object />
|
|
1243
|
+
</response>
|
|
1244
|
+
</endpoint>
|
|
1245
|
+
</api>
|
|
1246
|
+
</server>
|
|
1247
|
+
)
|
|
1248
|
+
```
|
|
1249
|
+
|
|
1250
|
+
Many number statuses have a string id you can use on the property.
|
|
1251
|
+
|
|
1252
|
+
*src/app.tsx*
|
|
1253
|
+
```typescript jsx
|
|
1254
|
+
return (
|
|
1255
|
+
<server>
|
|
1256
|
+
<api>
|
|
1257
|
+
<endpoint method='get' path='/settings'>
|
|
1258
|
+
<response status='notFound'>
|
|
1259
|
+
<object />
|
|
1260
|
+
</response>
|
|
1261
|
+
</endpoint>
|
|
1262
|
+
</api>
|
|
1263
|
+
</server>
|
|
1264
|
+
)
|
|
1265
|
+
```
|
|
1266
|
+
|
|
1267
|
+
You can use many `<response>` elements in an endpoint.
|
|
1268
|
+
|
|
1269
|
+
*src/app.tsx*
|
|
1270
|
+
```typescript jsx
|
|
1271
|
+
return (
|
|
1272
|
+
<server>
|
|
1273
|
+
<api>
|
|
1274
|
+
<endpoint method='get' path='/settings'>
|
|
1275
|
+
<response status='2XX'>
|
|
1276
|
+
<object />
|
|
1277
|
+
</response>
|
|
1278
|
+
<response status='4XX'>
|
|
1279
|
+
<object>
|
|
1280
|
+
<field key='error'>
|
|
1281
|
+
<string />
|
|
1282
|
+
</field>
|
|
1283
|
+
<field optional key='data'>
|
|
1284
|
+
<object />
|
|
1285
|
+
</field>
|
|
1286
|
+
</object>
|
|
1287
|
+
</response>
|
|
1288
|
+
</endpoint>
|
|
1289
|
+
</api>
|
|
1290
|
+
</server>
|
|
1291
|
+
)
|
|
1292
|
+
```
|
|
1293
|
+
|
|
1016
1294
|
## Primitive Data
|
|
1017
1295
|
|
|
1018
1296
|
[← back](#index)
|
|
@@ -2624,6 +2902,26 @@ export default (
|
|
|
2624
2902
|
)
|
|
2625
2903
|
```
|
|
2626
2904
|
|
|
2905
|
+
#### contentType
|
|
2906
|
+
|
|
2907
|
+
This props sets response content type.
|
|
2908
|
+
By default, it checks children element to define the prop.
|
|
2909
|
+
|
|
2910
|
+
*src/app.tsx*
|
|
2911
|
+
```typescript jsx
|
|
2912
|
+
export default (
|
|
2913
|
+
<server>
|
|
2914
|
+
<api>
|
|
2915
|
+
<fallback>
|
|
2916
|
+
<success contentType='text/html'>
|
|
2917
|
+
Hello World!
|
|
2918
|
+
</success>
|
|
2919
|
+
</fallback>
|
|
2920
|
+
</api>
|
|
2921
|
+
</server>
|
|
2922
|
+
)
|
|
2923
|
+
```
|
|
2924
|
+
|
|
2627
2925
|
### \<error>
|
|
2628
2926
|
|
|
2629
2927
|
[← back](#run-time)
|
|
@@ -3310,7 +3608,7 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3310
3608
|
|
|
3311
3609
|
[← back](#index)
|
|
3312
3610
|
|
|
3313
|
-
|
|
3611
|
+
Real-time
|
|
3314
3612
|
[useRequest](#userequest)
|
|
3315
3613
|
[useResponse](#useresponse)
|
|
3316
3614
|
[useHeaders](#useheaders)
|
|
@@ -3319,29 +3617,16 @@ Hook functions give you all features to control parent element functionality.
|
|
|
3319
3617
|
[useParams](#useparams)
|
|
3320
3618
|
[useSearch](#usesearch)
|
|
3321
3619
|
[useBody](#usebody)
|
|
3620
|
+
[useClientIp](#useclientip)
|
|
3322
3621
|
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
### useServer
|
|
3326
|
-
|
|
3327
|
-
[← back](#hooks)
|
|
3328
|
-
|
|
3329
|
-
This hook MUST be used in a component placed in `<server>`.
|
|
3330
|
-
This hook returns current http(s) server instance.
|
|
3331
|
-
|
|
3332
|
-
*src/Component.tsx*
|
|
3622
|
+
Server start
|
|
3623
|
+
[useRequestPlugin](#userequestplugin)
|
|
3333
3624
|
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
export function Component () {
|
|
3338
|
-
const server = useServer()
|
|
3339
|
-
|
|
3340
|
-
console.log(server)
|
|
3625
|
+
Both
|
|
3626
|
+
[useServer](#useserver)
|
|
3627
|
+
[useComponentName](#usecomponentname)
|
|
3341
3628
|
|
|
3342
|
-
|
|
3343
|
-
}
|
|
3344
|
-
```
|
|
3629
|
+
---
|
|
3345
3630
|
|
|
3346
3631
|
### useRequest
|
|
3347
3632
|
|
|
@@ -3496,6 +3781,109 @@ export function Component () {
|
|
|
3496
3781
|
}
|
|
3497
3782
|
```
|
|
3498
3783
|
|
|
3784
|
+
### useClientIp
|
|
3785
|
+
|
|
3786
|
+
[← back](#hooks)
|
|
3787
|
+
|
|
3788
|
+
This hook returns request user IP.
|
|
3789
|
+
This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
|
|
3790
|
+
|
|
3791
|
+
*src/Component.tsx*
|
|
3792
|
+
```typescript jsx
|
|
3793
|
+
import { useClientIp } from '@innet/sever'
|
|
3794
|
+
|
|
3795
|
+
export function Component () {
|
|
3796
|
+
const ip = useClientIp()
|
|
3797
|
+
|
|
3798
|
+
return <success>{{ ip }}</success>
|
|
3799
|
+
}
|
|
3800
|
+
```
|
|
3801
|
+
|
|
3802
|
+
### useRequestPlugin
|
|
3803
|
+
|
|
3804
|
+
[← back](#hooks)
|
|
3805
|
+
|
|
3806
|
+
This hook adds a request plugin function.
|
|
3807
|
+
The function runs before check endpoints.
|
|
3808
|
+
If the function returns `true` the request handling stops, and you get full control over the request.
|
|
3809
|
+
|
|
3810
|
+
This hook MUST be used in a component placed in [\<api>](#api).
|
|
3811
|
+
|
|
3812
|
+
*src/SecretEndpoint.tsx*
|
|
3813
|
+
```typescript jsx
|
|
3814
|
+
import { useRequestPlugin } from '@innet/sever'
|
|
3815
|
+
|
|
3816
|
+
export function SecretEndpoint () {
|
|
3817
|
+
useRequestPlugin((req, res) => {
|
|
3818
|
+
if (req.url.startsWith('/secret-endpoint')) {
|
|
3819
|
+
res.statusCode = 200
|
|
3820
|
+
res.write('A secret message')
|
|
3821
|
+
res.end()
|
|
3822
|
+
return true
|
|
3823
|
+
}
|
|
3824
|
+
})
|
|
3825
|
+
}
|
|
3826
|
+
```
|
|
3827
|
+
|
|
3828
|
+
Then use the plugin in [\<api>](#api).
|
|
3829
|
+
|
|
3830
|
+
*src/app.tsx*
|
|
3831
|
+
```typescript jsx
|
|
3832
|
+
import { SecretEndpoint } from './SecretEndpoint'
|
|
3833
|
+
|
|
3834
|
+
export default (
|
|
3835
|
+
<server>
|
|
3836
|
+
<api>
|
|
3837
|
+
<fallback>
|
|
3838
|
+
<error />
|
|
3839
|
+
</fallback>
|
|
3840
|
+
<SecretEndpoint />
|
|
3841
|
+
</api>
|
|
3842
|
+
</server>
|
|
3843
|
+
)
|
|
3844
|
+
```
|
|
3845
|
+
|
|
3846
|
+
Any endpoint returns an error except for `/secret-endpoint`.
|
|
3847
|
+
Elements order does not matter.
|
|
3848
|
+
|
|
3849
|
+
### useServer
|
|
3850
|
+
|
|
3851
|
+
[← back](#hooks)
|
|
3852
|
+
|
|
3853
|
+
This hook MUST be used in a component placed in [\<server>](#server).
|
|
3854
|
+
This hook returns current http(s) server instance.
|
|
3855
|
+
|
|
3856
|
+
*src/Component.tsx*
|
|
3857
|
+
```typescript jsx
|
|
3858
|
+
import { useServer } from '@innet/sever'
|
|
3859
|
+
|
|
3860
|
+
export function Component () {
|
|
3861
|
+
const server = useServer()
|
|
3862
|
+
|
|
3863
|
+
console.log(server)
|
|
3864
|
+
|
|
3865
|
+
return <success />
|
|
3866
|
+
}
|
|
3867
|
+
```
|
|
3868
|
+
|
|
3869
|
+
### useComponentName
|
|
3870
|
+
|
|
3871
|
+
[← back](#hooks)
|
|
3872
|
+
|
|
3873
|
+
This hook returns name of current component.
|
|
3874
|
+
|
|
3875
|
+
*src/Component.tsx*
|
|
3876
|
+
```typescript jsx
|
|
3877
|
+
import { useComponentName } from '@innet/sever'
|
|
3878
|
+
|
|
3879
|
+
export function Component () {
|
|
3880
|
+
// returns this ^-------^
|
|
3881
|
+
const name = useComponentName()
|
|
3882
|
+
|
|
3883
|
+
return <success>{{ name }}</success>
|
|
3884
|
+
}
|
|
3885
|
+
```
|
|
3886
|
+
|
|
3499
3887
|
## Issues
|
|
3500
3888
|
If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
|
|
3501
3889
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './todo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function AddTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AddTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DeleteTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DeleteTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function EditTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function GetTodo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GetTodo';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function GetTodos(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GetTodos';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const todos: Api.Schemas.TodoSchema[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ListQueryParams(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ListQueryParams';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TodoSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TodoSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Todo(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Todo';
|
package/example/tags/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './Todo';
|
package/handler/handler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { context, type ContextProps, slot, type SlotProps, slots, type SlotsProps } from '@innet/jsx';
|
|
2
2
|
import { arraySync, async } from '@innet/utils';
|
|
3
|
-
import { type ApiProps, type ArrayProps, type BinaryProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DevProps, type DtsProps, type EndpointProps, type ErrorProps, type FallbackProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, type ProdProps, type ProxyProps, type RedirectProps, type RequestProps, type ResponseProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps } from '../plugins';
|
|
3
|
+
import { type ApiProps, type ArrayProps, type BinaryProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DevProps, type DtsProps, type EndpointProps, type ErrorProps, type FallbackProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, type ProdProps, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type RequestProps, type ResponseProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps } from '../plugins';
|
|
4
4
|
export declare const arrayPlugins: (typeof arraySync)[];
|
|
5
5
|
export declare const JSXPlugins: {
|
|
6
6
|
api: import("innet").HandlerPlugin;
|
|
@@ -29,6 +29,7 @@ export declare const JSXPlugins: {
|
|
|
29
29
|
object: import("innet").HandlerPlugin;
|
|
30
30
|
param: import("innet").HandlerPlugin;
|
|
31
31
|
prod: import("innet").HandlerPlugin;
|
|
32
|
+
protection: typeof protection;
|
|
32
33
|
proxy: import("innet").HandlerPlugin;
|
|
33
34
|
redirect: import("innet").HandlerPlugin;
|
|
34
35
|
request: import("innet").HandlerPlugin;
|
|
@@ -77,6 +78,7 @@ declare global {
|
|
|
77
78
|
object: ObjectProps;
|
|
78
79
|
param: ParamProps;
|
|
79
80
|
prod: ProdProps;
|
|
81
|
+
protection: ProtectionProps;
|
|
80
82
|
proxy: ProxyProps;
|
|
81
83
|
redirect: RedirectProps;
|
|
82
84
|
request: RequestProps;
|
package/handler/handler.es6.js
CHANGED
|
@@ -27,6 +27,7 @@ import { number } from '../plugins/schema/number/number.es6.js';
|
|
|
27
27
|
import { object } from '../plugins/schema/object/object.es6.js';
|
|
28
28
|
import { param } from '../plugins/main/param/param.es6.js';
|
|
29
29
|
import { prod } from '../plugins/utils/prod/prod.es6.js';
|
|
30
|
+
import { protection } from '../plugins/utils/protection/protection.es6.js';
|
|
30
31
|
import { proxy } from '../plugins/request/proxy/proxy.es6.js';
|
|
31
32
|
import { redirect } from '../plugins/request/redirect/redirect.es6.js';
|
|
32
33
|
import { request } from '../plugins/main/request/request.es6.js';
|
|
@@ -71,6 +72,7 @@ const JSXPlugins = {
|
|
|
71
72
|
object,
|
|
72
73
|
param,
|
|
73
74
|
prod,
|
|
75
|
+
protection,
|
|
74
76
|
proxy,
|
|
75
77
|
redirect,
|
|
76
78
|
request,
|
package/handler/handler.js
CHANGED
|
@@ -31,6 +31,7 @@ var number = require('../plugins/schema/number/number.js');
|
|
|
31
31
|
var object = require('../plugins/schema/object/object.js');
|
|
32
32
|
var param = require('../plugins/main/param/param.js');
|
|
33
33
|
var prod = require('../plugins/utils/prod/prod.js');
|
|
34
|
+
var protection = require('../plugins/utils/protection/protection.js');
|
|
34
35
|
var proxy = require('../plugins/request/proxy/proxy.js');
|
|
35
36
|
var redirect = require('../plugins/request/redirect/redirect.js');
|
|
36
37
|
var request = require('../plugins/main/request/request.js');
|
|
@@ -75,6 +76,7 @@ const JSXPlugins = {
|
|
|
75
76
|
object: object.object,
|
|
76
77
|
param: param.param,
|
|
77
78
|
prod: prod.prod,
|
|
79
|
+
protection: protection.protection,
|
|
78
80
|
proxy: proxy.proxy,
|
|
79
81
|
redirect: redirect.redirect,
|
|
80
82
|
request: request.request,
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.es6.js
CHANGED