@data-client/rest 0.12.3 → 0.12.4
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/legacy/pathTypes.js +1 -1
- package/lib/pathTypes.d.ts +4 -4
- package/lib/pathTypes.d.ts.map +1 -1
- package/lib/pathTypes.js +1 -1
- package/package.json +4 -2
- package/src/__tests__/RestEndpoint.ts +1 -1
- package/src/pathTypes.ts +16 -11
- package/ts4.1/pathTypes.d.ts +4 -4
- package/src/__tests__/types.test.ts +0 -576
package/legacy/pathTypes.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vc3JjL3BhdGhUeXBlcy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJ0eXBlIE9ubHlPcHRpb25hbDxTIGV4dGVuZHMgc3RyaW5nPiA9XG4gIFMgZXh0ZW5kcyBgJHtpbmZlciBLfX0/YCA/IEtcbiAgOiBTIGV4dGVuZHMgYCR7aW5mZXIgS30/YCA/IEtcbiAgOiBuZXZlcjtcbnR5cGUgT25seVJlcXVpcmVkPFMgZXh0ZW5kcyBzdHJpbmc+ID0gUyBleHRlbmRzIGAke3N0cmluZ30/YCA/IG5ldmVyIDogUztcblxuLyoqIFBhcmFtZXRlcnMgZm9yIGEgZ2l2ZW4gcGF0aCAqL1xuZXhwb3J0IHR5cGUgUGF0aEFyZ3M8UyBleHRlbmRzIHN0cmluZz4gPVxuICBQYXRoS2V5czxTPiBleHRlbmRzIG5ldmVyID9cbiAgICAvLyB1bmtub3duIGlzIGlkZW50aXR5IGZvciBpbnRlcnNlY3Rpb24gKCcmJylcbiAgICB1bmtub3duXG4gIDogS2V5c1RvQXJnczxQYXRoS2V5czxTPj47XG5cbi8qKiBDb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` ? K : never;
|
|
1
|
+
type OnlyOptional<S extends string> = S extends `${infer K}}?` ? K : S extends `${infer K}?` ? K : never;
|
|
2
2
|
type OnlyRequired<S extends string> = S extends `${string}?` ? never : S;
|
|
3
|
-
/** Computes the union of keys for a path string */
|
|
4
|
-
export type PathKeys<S extends string> = string extends S ? string : S extends `${infer A}\\:${infer B}` ? PathKeys<A> | PathKeys<B> : S extends `${infer A}\\?${infer B}` ? PathKeys<A> | PathKeys<B> : PathSplits<S>;
|
|
5
|
-
type PathSplits<S extends string> = S extends `${string}:${infer K}${'/' | ',' | '%' | '&'}${infer R}` ? PathSplits<`:${K}`> | PathSplits<R> : S extends `${string}:${infer K}:${infer R}` ? PathSplits<`:${K}`> | PathSplits<`:${R}`> : S extends `${string}:${infer K}` ? K : never;
|
|
6
3
|
/** Parameters for a given path */
|
|
7
4
|
export type PathArgs<S extends string> = PathKeys<S> extends never ? unknown : KeysToArgs<PathKeys<S>>;
|
|
5
|
+
/** Computes the union of keys for a path string */
|
|
6
|
+
export type PathKeys<S extends string> = string extends S ? string : S extends `${infer A}\\${':' | '?' | '+' | '*' | '{' | '}'}${infer B}` ? PathKeys<A> | PathKeys<B> : PathSplits<S>;
|
|
7
|
+
type PathSplits<S extends string> = S extends (`${string}:${infer K}${'/' | ',' | '%' | '&' | '+' | '*' | '{'}${infer R}`) ? PathSplits<`:${K}`> | PathSplits<R> : S extends `${string}:${infer K}:${infer R}` ? PathSplits<`:${K}`> | PathSplits<`:${R}`> : S extends `${string}:${infer K}` ? K : never;
|
|
8
8
|
export type KeysToArgs<Key extends string> = {
|
|
9
9
|
[K in Key as OnlyOptional<K>]?: string | number;
|
|
10
10
|
} & (OnlyRequired<Key> extends never ? unknown : {
|
package/lib/pathTypes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathTypes.d.ts","sourceRoot":"","sources":["../src/pathTypes.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,CAAC,CAAC,SAAS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B,CAAC,CAAC;AAEN,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC"}
|
package/lib/pathTypes.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vc3JjL3BhdGhUeXBlcy50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJ0eXBlIE9ubHlPcHRpb25hbDxTIGV4dGVuZHMgc3RyaW5nPiA9XG4gIFMgZXh0ZW5kcyBgJHtpbmZlciBLfX0/YCA/IEtcbiAgOiBTIGV4dGVuZHMgYCR7aW5mZXIgS30/YCA/IEtcbiAgOiBuZXZlcjtcbnR5cGUgT25seVJlcXVpcmVkPFMgZXh0ZW5kcyBzdHJpbmc+ID0gUyBleHRlbmRzIGAke3N0cmluZ30/YCA/IG5ldmVyIDogUztcblxuLyoqIFBhcmFtZXRlcnMgZm9yIGEgZ2l2ZW4gcGF0aCAqL1xuZXhwb3J0IHR5cGUgUGF0aEFyZ3M8UyBleHRlbmRzIHN0cmluZz4gPVxuICBQYXRoS2V5czxTPiBleHRlbmRzIG5ldmVyID9cbiAgICAvLyB1bmtub3duIGlzIGlkZW50aXR5IGZvciBpbnRlcnNlY3Rpb24gKCcmJylcbiAgICB1bmtub3duXG4gIDogS2V5c1RvQXJnczxQYXRoS2V5czxTPj47XG5cbi8qKiBDb21wdXRlcyB0aGUgdW5pb24gb2Yga2V5cyBmb3IgYSBwYXRoIHN0cmluZyAqL1xuZXhwb3J0IHR5cGUgUGF0aEtleXM8UyBleHRlbmRzIHN0cmluZz4gPVxuICBzdHJpbmcgZXh0ZW5kcyBTID8gc3RyaW5nXG4gIDogUyBleHRlbmRzIGAke2luZmVyIEF9XFxcXCR7JzonIHwgJz8nIHwgJysnIHwgJyonIHwgJ3snIHwgJ30nf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MgT25seVJlcXVpcmVkPEs+XTogc3RyaW5nIHwgbnVtYmVyO1xuICAgIH0gJiBSZWNvcmQ8c3RyaW5nLCBudW1iZXIgfCBzdHJpbmc+O1xuXG4vKiogUmVtb3ZlcyB0aGUgbGFzdCA6dG9rZW4gKi9cbmV4cG9ydCB0eXBlIFNob3J0ZW5QYXRoPFMgZXh0ZW5kcyBzdHJpbmc+ID1cbiAgc3RyaW5nIGV4dGVuZHMgUyA/IHN0cmluZ1xuICA6IFMgZXh0ZW5kcyBgJHtpbmZlciBCfToke2luZmVyIFJ9YCA/IFRyaW1Db2xvbjxgJHtCfToke1Nob3J0ZW5QYXRoPFI+fWA+XG4gIDogJyc7XG5cbnR5cGUgVHJpbUNvbG9uPFMgZXh0ZW5kcyBzdHJpbmc+ID1cbiAgc3RyaW5nIGV4dGVuZHMgUyA/IHN0cmluZ1xuICA6IFMgZXh0ZW5kcyBgJHtpbmZlciBSfTpgID8gUlxuICA6IFM7XG5cbmV4cG9ydCB0eXBlIFJlc291cmNlUGF0aCA9IHN0cmluZzsgLy8gYCR7c3RyaW5nfToke3N0cmluZ31gOyBUT0RPOiBNYXliZSBkbyB0aGlzIGluIHRoZSBmdXR1cmU/IFNlZW1zIHRvIGhhcmQgdG8gdW5kZXJzdGFuZCBmb3Igbm93XG4iXSwibWFwcGluZ3MiOiIiLCJpZ25vcmVMaXN0IjpbXX0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-client/rest",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"description": "Endpoints for REST APIs",
|
|
5
5
|
"homepage": "https://dataclient.io/rest",
|
|
6
6
|
"repository": {
|
|
@@ -120,7 +120,9 @@
|
|
|
120
120
|
"build": "run build:lib && run build:legacy:lib && run build:bundle",
|
|
121
121
|
"dev": "run build:lib -w",
|
|
122
122
|
"prepare": "run build:lib",
|
|
123
|
-
"prepack": "run prepare && run build:bundle && run build:legacy:lib"
|
|
123
|
+
"prepack": "run prepare && run build:bundle && run build:legacy:lib",
|
|
124
|
+
"tsc:ci": "yarn g:tsc --project tsconfig.test.json",
|
|
125
|
+
"typecheck": "run tsc:ci"
|
|
124
126
|
},
|
|
125
127
|
"author": "Nathaniel Tucker <me@ntucker.me> (https://github.com/ntucker)",
|
|
126
128
|
"funding": "https://github.com/sponsors/ntucker",
|
|
@@ -2,7 +2,7 @@ import { Entity, schema } from '@data-client/endpoint';
|
|
|
2
2
|
import { useController } from '@data-client/react';
|
|
3
3
|
import { useSuspense } from '@data-client/react';
|
|
4
4
|
import { CacheProvider } from '@data-client/react';
|
|
5
|
-
import {
|
|
5
|
+
import { CoolerArticle, CoolerArticleResource } from '__tests__/new';
|
|
6
6
|
import nock from 'nock';
|
|
7
7
|
|
|
8
8
|
import { makeRenderDataClient } from '../../../test';
|
package/src/pathTypes.ts
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
type OnlyOptional<S extends string> =
|
|
1
|
+
type OnlyOptional<S extends string> =
|
|
2
|
+
S extends `${infer K}}?` ? K
|
|
3
|
+
: S extends `${infer K}?` ? K
|
|
4
|
+
: never;
|
|
2
5
|
type OnlyRequired<S extends string> = S extends `${string}?` ? never : S;
|
|
3
6
|
|
|
7
|
+
/** Parameters for a given path */
|
|
8
|
+
export type PathArgs<S extends string> =
|
|
9
|
+
PathKeys<S> extends never ?
|
|
10
|
+
// unknown is identity for intersection ('&')
|
|
11
|
+
unknown
|
|
12
|
+
: KeysToArgs<PathKeys<S>>;
|
|
13
|
+
|
|
4
14
|
/** Computes the union of keys for a path string */
|
|
5
15
|
export type PathKeys<S extends string> =
|
|
6
16
|
string extends S ? string
|
|
7
|
-
: S extends `${infer A}
|
|
8
|
-
|
|
17
|
+
: S extends `${infer A}\\${':' | '?' | '+' | '*' | '{' | '}'}${infer B}` ?
|
|
18
|
+
PathKeys<A> | PathKeys<B>
|
|
9
19
|
: PathSplits<S>;
|
|
10
20
|
|
|
11
21
|
type PathSplits<S extends string> =
|
|
12
|
-
S extends
|
|
22
|
+
S extends (
|
|
23
|
+
`${string}:${infer K}${'/' | ',' | '%' | '&' | '+' | '*' | '{'}${infer R}`
|
|
24
|
+
) ?
|
|
13
25
|
PathSplits<`:${K}`> | PathSplits<R>
|
|
14
26
|
: S extends `${string}:${infer K}:${infer R}` ?
|
|
15
27
|
PathSplits<`:${K}`> | PathSplits<`:${R}`>
|
|
16
28
|
: S extends `${string}:${infer K}` ? K
|
|
17
29
|
: never;
|
|
18
30
|
|
|
19
|
-
/** Parameters for a given path */
|
|
20
|
-
export type PathArgs<S extends string> =
|
|
21
|
-
PathKeys<S> extends never ?
|
|
22
|
-
// unknown is identity for intersection ('&')
|
|
23
|
-
unknown
|
|
24
|
-
: KeysToArgs<PathKeys<S>>;
|
|
25
|
-
|
|
26
31
|
export type KeysToArgs<Key extends string> = {
|
|
27
32
|
[K in Key as OnlyOptional<K>]?: string | number;
|
|
28
33
|
} & (OnlyRequired<Key> extends never ? unknown
|
package/ts4.1/pathTypes.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type OnlyOptional<S extends string> = S extends `${infer K}?` ? K : never;
|
|
1
|
+
type OnlyOptional<S extends string> = S extends `${infer K}}?` ? K : S extends `${infer K}?` ? K : never;
|
|
2
2
|
type OnlyRequired<S extends string> = S extends `${string}?` ? never : S;
|
|
3
|
-
/** Computes the union of keys for a path string */
|
|
4
|
-
export type PathKeys<S extends string> = string extends S ? string : S extends `${infer A}\\:${infer B}` ? PathKeys<A> | PathKeys<B> : S extends `${infer A}\\?${infer B}` ? PathKeys<A> | PathKeys<B> : PathSplits<S>;
|
|
5
|
-
type PathSplits<S extends string> = S extends `${string}:${infer K}${'/' | ',' | '%' | '&'}${infer R}` ? PathSplits<`:${K}`> | PathSplits<R> : S extends `${string}:${infer K}:${infer R}` ? PathSplits<`:${K}`> | PathSplits<`:${R}`> : S extends `${string}:${infer K}` ? K : never;
|
|
6
3
|
/** Parameters for a given path */
|
|
7
4
|
export type PathArgs<S extends string> = PathKeys<S> extends never ? unknown : KeysToArgs<PathKeys<S>>;
|
|
5
|
+
/** Computes the union of keys for a path string */
|
|
6
|
+
export type PathKeys<S extends string> = string extends S ? string : S extends `${infer A}\\${':' | '?' | '+' | '*' | '{' | '}'}${infer B}` ? PathKeys<A> | PathKeys<B> : PathSplits<S>;
|
|
7
|
+
type PathSplits<S extends string> = S extends (`${string}:${infer K}${'/' | ',' | '%' | '&' | '+' | '*' | '{'}${infer R}`) ? PathSplits<`:${K}`> | PathSplits<R> : S extends `${string}:${infer K}:${infer R}` ? PathSplits<`:${K}`> | PathSplits<`:${R}`> : S extends `${string}:${infer K}` ? K : never;
|
|
8
8
|
export type KeysToArgs<Key extends string> = {
|
|
9
9
|
[K in Key as OnlyOptional<K>]?: string | number;
|
|
10
10
|
} & (OnlyRequired<Key> extends never ? unknown : {
|
|
@@ -1,576 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
import { Entity, schema } from '@data-client/endpoint';
|
|
3
|
-
import { useController, useSuspense } from '@data-client/react';
|
|
4
|
-
import { User } from '__tests__/new';
|
|
5
|
-
|
|
6
|
-
import createResource from '../createResource';
|
|
7
|
-
import RestEndpoint, { GetEndpoint, MutateEndpoint } from '../RestEndpoint';
|
|
8
|
-
|
|
9
|
-
it('RestEndpoint construct and extend with typed options', () => {
|
|
10
|
-
new RestEndpoint({
|
|
11
|
-
path: '/todos/',
|
|
12
|
-
getOptimisticResponse(snap, body) {
|
|
13
|
-
return body;
|
|
14
|
-
},
|
|
15
|
-
schema: User,
|
|
16
|
-
method: 'POST',
|
|
17
|
-
});
|
|
18
|
-
// variable/unknown number of args
|
|
19
|
-
new RestEndpoint({
|
|
20
|
-
path: '/todos/',
|
|
21
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
22
|
-
getOptimisticResponse(snap, ...args) {
|
|
23
|
-
return args[args.length - 1];
|
|
24
|
-
},
|
|
25
|
-
schema: User,
|
|
26
|
-
method: 'POST',
|
|
27
|
-
});
|
|
28
|
-
new RestEndpoint({
|
|
29
|
-
path: '/todos/:id',
|
|
30
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
31
|
-
getOptimisticResponse(snap, params, body) {
|
|
32
|
-
return body;
|
|
33
|
-
},
|
|
34
|
-
schema: User,
|
|
35
|
-
method: 'POST',
|
|
36
|
-
});
|
|
37
|
-
new RestEndpoint({
|
|
38
|
-
path: '/todos/:id',
|
|
39
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
40
|
-
getOptimisticResponse(snap, params, body) {
|
|
41
|
-
return body;
|
|
42
|
-
},
|
|
43
|
-
schema: User,
|
|
44
|
-
method: 'POST',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const nopath = new RestEndpoint({
|
|
48
|
-
path: '/todos/',
|
|
49
|
-
schema: User,
|
|
50
|
-
method: 'POST',
|
|
51
|
-
});
|
|
52
|
-
const somepath = new RestEndpoint({
|
|
53
|
-
path: '/todos/:id',
|
|
54
|
-
schema: User,
|
|
55
|
-
method: 'POST',
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
nopath.extend({
|
|
59
|
-
getOptimisticResponse(snap, body) {
|
|
60
|
-
return body;
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
nopath.extend({
|
|
64
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
65
|
-
getOptimisticResponse(snap, ...args) {
|
|
66
|
-
return args[args.length - 1];
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
somepath.extend({
|
|
70
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
71
|
-
getOptimisticResponse(snap, args, body) {
|
|
72
|
-
return body;
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should customize resources', () => {
|
|
78
|
-
class Todo extends Entity {
|
|
79
|
-
id = '';
|
|
80
|
-
userId = 0;
|
|
81
|
-
title = '';
|
|
82
|
-
completed = false;
|
|
83
|
-
|
|
84
|
-
static key = 'Todo';
|
|
85
|
-
pk() {
|
|
86
|
-
return this.id;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const TodoResource = createResource({
|
|
91
|
-
path: '/todos/:id',
|
|
92
|
-
schema: Todo,
|
|
93
|
-
});
|
|
94
|
-
TodoResource.create.extend({
|
|
95
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
96
|
-
getOptimisticResponse(snap, ...args) {
|
|
97
|
-
return args[args.length - 1];
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
const partial = TodoResource.partialUpdate.extend({
|
|
101
|
-
getOptimisticResponse(snap, { id }, body) {
|
|
102
|
-
return {
|
|
103
|
-
id,
|
|
104
|
-
...body,
|
|
105
|
-
};
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
() => partial({ id: 5 }, { title: 'hi' });
|
|
109
|
-
const a: MutateEndpoint<{
|
|
110
|
-
path: '/todos/';
|
|
111
|
-
body: Partial<Todo>;
|
|
112
|
-
schema: typeof Todo;
|
|
113
|
-
}> = TodoResource.create.extend({ schema: Todo }) as any;
|
|
114
|
-
a.extend({
|
|
115
|
-
searchParams: {} as { userId?: string | number } | undefined,
|
|
116
|
-
getOptimisticResponse(snap, ...args) {
|
|
117
|
-
return args[args.length - 1];
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
() => useSuspense(TodoResource.getList);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// path: ['/todos', '/todos/:id', '/todos/:id?', string]
|
|
125
|
-
it('should precisely type function arguments', () => {
|
|
126
|
-
// path: '/todos'
|
|
127
|
-
() => {
|
|
128
|
-
const optionalUndefSearch = new RestEndpoint({
|
|
129
|
-
path: '/todos',
|
|
130
|
-
searchParams: {} as
|
|
131
|
-
| {
|
|
132
|
-
userId?: string | number;
|
|
133
|
-
}
|
|
134
|
-
| undefined,
|
|
135
|
-
});
|
|
136
|
-
const optionalSearch = new RestEndpoint({
|
|
137
|
-
path: '/todos',
|
|
138
|
-
searchParams: {} as {
|
|
139
|
-
userId?: string | number;
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
const undef = new RestEndpoint({
|
|
143
|
-
path: '/todos',
|
|
144
|
-
searchParams: undefined,
|
|
145
|
-
});
|
|
146
|
-
const requiredSearch = new RestEndpoint({
|
|
147
|
-
path: '/todos',
|
|
148
|
-
searchParams: {} as {
|
|
149
|
-
userId: string | number;
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
const noSearch = new RestEndpoint({
|
|
153
|
-
path: '/todos',
|
|
154
|
-
});
|
|
155
|
-
() => optionalUndefSearch();
|
|
156
|
-
() => optionalUndefSearch({});
|
|
157
|
-
() => optionalUndefSearch({ userId: 'hi' });
|
|
158
|
-
// @ts-expect-error
|
|
159
|
-
() => optionalUndefSearch(5);
|
|
160
|
-
// @ts-expect-error
|
|
161
|
-
() => optionalUndefSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
162
|
-
|
|
163
|
-
() => optionalSearch();
|
|
164
|
-
() => optionalSearch({});
|
|
165
|
-
() => optionalSearch({ userId: 'hi' });
|
|
166
|
-
// @ts-expect-error
|
|
167
|
-
() => optionalSearch(5);
|
|
168
|
-
// @ts-expect-error
|
|
169
|
-
() => optionalSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
170
|
-
|
|
171
|
-
// @ts-expect-error
|
|
172
|
-
() => requiredSearch();
|
|
173
|
-
// @ts-expect-error
|
|
174
|
-
() => requiredSearch({});
|
|
175
|
-
() => requiredSearch({ userId: 'hi' });
|
|
176
|
-
// @ts-expect-error
|
|
177
|
-
() => requiredSearch(5);
|
|
178
|
-
// @ts-expect-error
|
|
179
|
-
() => requiredSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
180
|
-
|
|
181
|
-
() => undef();
|
|
182
|
-
// @ts-expect-error
|
|
183
|
-
() => undef({});
|
|
184
|
-
// @ts-expect-error
|
|
185
|
-
() => undef({ userId: 'hi' });
|
|
186
|
-
// @ts-expect-error
|
|
187
|
-
() => undef(5);
|
|
188
|
-
|
|
189
|
-
() => noSearch();
|
|
190
|
-
// @ts-expect-error
|
|
191
|
-
() => noSearch({});
|
|
192
|
-
// @ts-expect-error
|
|
193
|
-
() => noSearch({ userId: 'hi' });
|
|
194
|
-
// @ts-expect-error
|
|
195
|
-
() => noSearch(5);
|
|
196
|
-
};
|
|
197
|
-
// path: '/todos/:id?'
|
|
198
|
-
() => {
|
|
199
|
-
const optionalUndefSearch = new RestEndpoint({
|
|
200
|
-
path: '/todos/:id?',
|
|
201
|
-
searchParams: {} as
|
|
202
|
-
| {
|
|
203
|
-
userId?: string | number;
|
|
204
|
-
}
|
|
205
|
-
| undefined,
|
|
206
|
-
});
|
|
207
|
-
const optionalSearch = new RestEndpoint({
|
|
208
|
-
path: '/todos/:id?',
|
|
209
|
-
searchParams: {} as {
|
|
210
|
-
userId?: string | number;
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
const undef = new RestEndpoint({
|
|
214
|
-
path: '/todos/:id?',
|
|
215
|
-
searchParams: undefined,
|
|
216
|
-
});
|
|
217
|
-
const requiredSearch = new RestEndpoint({
|
|
218
|
-
path: '/todos/:id?',
|
|
219
|
-
searchParams: {} as {
|
|
220
|
-
userId: string | number;
|
|
221
|
-
},
|
|
222
|
-
});
|
|
223
|
-
const noSearch = new RestEndpoint({
|
|
224
|
-
path: '/todos/:id?',
|
|
225
|
-
});
|
|
226
|
-
() => optionalUndefSearch();
|
|
227
|
-
() => optionalUndefSearch({});
|
|
228
|
-
() => optionalUndefSearch({ id: '5' });
|
|
229
|
-
() => optionalUndefSearch({ userId: 'hi' });
|
|
230
|
-
() => optionalUndefSearch({ userId: 'hi', id: '5' });
|
|
231
|
-
// @ts-expect-error
|
|
232
|
-
() => optionalUndefSearch(5);
|
|
233
|
-
// @ts-expect-error
|
|
234
|
-
() => optionalUndefSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
235
|
-
|
|
236
|
-
() => optionalSearch();
|
|
237
|
-
() => optionalSearch({});
|
|
238
|
-
() => optionalSearch({ id: '5' });
|
|
239
|
-
() => optionalSearch({ userId: 'hi' });
|
|
240
|
-
() => optionalSearch({ userId: 'hi', id: '5' });
|
|
241
|
-
// @ts-expect-error
|
|
242
|
-
() => optionalSearch(5);
|
|
243
|
-
// @ts-expect-error
|
|
244
|
-
() => optionalSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
245
|
-
|
|
246
|
-
// @ts-expect-error
|
|
247
|
-
() => requiredSearch();
|
|
248
|
-
// @ts-expect-error
|
|
249
|
-
() => requiredSearch({});
|
|
250
|
-
// @ts-expect-error
|
|
251
|
-
() => requiredSearch({ id: '5' });
|
|
252
|
-
() => requiredSearch({ userId: 'hi' });
|
|
253
|
-
() => requiredSearch({ userId: 'hi', id: '5' });
|
|
254
|
-
// @ts-expect-error
|
|
255
|
-
() => requiredSearch(5);
|
|
256
|
-
// @ts-expect-error
|
|
257
|
-
() => requiredSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
258
|
-
|
|
259
|
-
() => undef();
|
|
260
|
-
// @ts-ignore TODO
|
|
261
|
-
() => undef({});
|
|
262
|
-
// @ts-ignore TODO
|
|
263
|
-
() => undef({ id: '5' });
|
|
264
|
-
// @ts-expect-error
|
|
265
|
-
() => undef({ userId: 'hi' });
|
|
266
|
-
// @ts-expect-error
|
|
267
|
-
() => undef(5);
|
|
268
|
-
|
|
269
|
-
() => noSearch();
|
|
270
|
-
() => noSearch({});
|
|
271
|
-
() => noSearch({ id: '5' });
|
|
272
|
-
// @ts-expect-error
|
|
273
|
-
() => noSearch({ userId: 'hi' });
|
|
274
|
-
// @ts-expect-error
|
|
275
|
-
() => noSearch(5);
|
|
276
|
-
};
|
|
277
|
-
// path: '/todos/:id'
|
|
278
|
-
() => {
|
|
279
|
-
const optionalUndefSearch = new RestEndpoint({
|
|
280
|
-
path: '/todos/:id',
|
|
281
|
-
searchParams: {} as
|
|
282
|
-
| {
|
|
283
|
-
userId?: string | number;
|
|
284
|
-
}
|
|
285
|
-
| undefined,
|
|
286
|
-
});
|
|
287
|
-
const optionalSearch = new RestEndpoint({
|
|
288
|
-
path: '/todos/:id',
|
|
289
|
-
searchParams: {} as {
|
|
290
|
-
userId?: string | number;
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
const undef = new RestEndpoint({
|
|
294
|
-
path: '/todos/:id',
|
|
295
|
-
searchParams: undefined,
|
|
296
|
-
});
|
|
297
|
-
const requiredSearch = new RestEndpoint({
|
|
298
|
-
path: '/todos/:id',
|
|
299
|
-
searchParams: {} as {
|
|
300
|
-
userId: string | number;
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
const noSearch = new RestEndpoint({
|
|
304
|
-
path: '/todos/:id',
|
|
305
|
-
});
|
|
306
|
-
// @ts-expect-error
|
|
307
|
-
() => optionalUndefSearch();
|
|
308
|
-
() => optionalUndefSearch({ id: '5' });
|
|
309
|
-
() => optionalUndefSearch({ id: '5', userId: 'hi' });
|
|
310
|
-
// @ts-expect-error
|
|
311
|
-
() => optionalUndefSearch(5);
|
|
312
|
-
() =>
|
|
313
|
-
// @ts-expect-error
|
|
314
|
-
optionalUndefSearch({ id: '5', userId: 'hi' }, { id: '5', userId: 'hi' });
|
|
315
|
-
|
|
316
|
-
// @ts-expect-error
|
|
317
|
-
() => optionalSearch();
|
|
318
|
-
() => optionalSearch({ id: '5' });
|
|
319
|
-
() => optionalSearch({ id: '5', userId: 'hi' });
|
|
320
|
-
// @ts-expect-error
|
|
321
|
-
() => optionalSearch(5);
|
|
322
|
-
// @ts-expect-error
|
|
323
|
-
() => optionalSearch({ id: '5', userId: 'hi' }, { id: '5', userId: 'hi' });
|
|
324
|
-
|
|
325
|
-
// @ts-expect-error
|
|
326
|
-
() => requiredSearch();
|
|
327
|
-
// @ts-expect-error
|
|
328
|
-
() => requiredSearch({ id: '5' });
|
|
329
|
-
() => requiredSearch({ id: '5', userId: 'hi' });
|
|
330
|
-
// @ts-expect-error
|
|
331
|
-
() => requiredSearch(5);
|
|
332
|
-
// @ts-expect-error
|
|
333
|
-
() => requiredSearch({ id: '5', userId: 'hi' }, { id: '5', userId: 'hi' });
|
|
334
|
-
|
|
335
|
-
// @ts-expect-error
|
|
336
|
-
() => undef();
|
|
337
|
-
// @ts-expect-error
|
|
338
|
-
() => undef({});
|
|
339
|
-
// @ts-expect-error
|
|
340
|
-
() => undef({ id: '5', userId: 'hi' });
|
|
341
|
-
// @ts-expect-error
|
|
342
|
-
() => undef(5);
|
|
343
|
-
|
|
344
|
-
// @ts-expect-error
|
|
345
|
-
() => noSearch();
|
|
346
|
-
() => noSearch({ id: '5' });
|
|
347
|
-
// @ts-expect-error
|
|
348
|
-
() => noSearch({ id: '5', userId: 'hi' });
|
|
349
|
-
// @ts-expect-error
|
|
350
|
-
() => noSearch(5);
|
|
351
|
-
};
|
|
352
|
-
// path: string
|
|
353
|
-
() => {
|
|
354
|
-
const optionalUndefSearch = new RestEndpoint({
|
|
355
|
-
path: '' as string,
|
|
356
|
-
searchParams: {} as
|
|
357
|
-
| {
|
|
358
|
-
userId?: string | number;
|
|
359
|
-
}
|
|
360
|
-
| undefined,
|
|
361
|
-
});
|
|
362
|
-
const optionalSearch = new RestEndpoint({
|
|
363
|
-
path: '' as string,
|
|
364
|
-
searchParams: {} as {
|
|
365
|
-
userId?: string | number;
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
const undef = new RestEndpoint({
|
|
369
|
-
path: '' as string,
|
|
370
|
-
searchParams: undefined,
|
|
371
|
-
});
|
|
372
|
-
const requiredSearch = new RestEndpoint({
|
|
373
|
-
path: '' as string,
|
|
374
|
-
searchParams: {} as {
|
|
375
|
-
userId: string | number;
|
|
376
|
-
},
|
|
377
|
-
});
|
|
378
|
-
const noSearch = new RestEndpoint({
|
|
379
|
-
path: '' as string,
|
|
380
|
-
});
|
|
381
|
-
() => optionalUndefSearch();
|
|
382
|
-
() => optionalUndefSearch({});
|
|
383
|
-
() => optionalUndefSearch({ id: '5' });
|
|
384
|
-
() => optionalUndefSearch({ userId: 'hi' });
|
|
385
|
-
() => optionalUndefSearch({ userId: 'hi', id: '5' });
|
|
386
|
-
// @ts-expect-error
|
|
387
|
-
() => optionalUndefSearch(5);
|
|
388
|
-
// @ts-expect-error
|
|
389
|
-
() => optionalUndefSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
390
|
-
|
|
391
|
-
() => optionalSearch();
|
|
392
|
-
() => optionalSearch({});
|
|
393
|
-
() => optionalSearch({ id: '5' });
|
|
394
|
-
() => optionalSearch({ userId: 'hi' });
|
|
395
|
-
() => optionalSearch({ userId: 'hi', id: '5' });
|
|
396
|
-
// @ts-expect-error
|
|
397
|
-
() => optionalSearch(5);
|
|
398
|
-
// @ts-expect-error
|
|
399
|
-
() => optionalSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
400
|
-
|
|
401
|
-
// @ts-expect-error
|
|
402
|
-
() => requiredSearch();
|
|
403
|
-
// @ts-expect-error
|
|
404
|
-
() => requiredSearch({});
|
|
405
|
-
// @ts-expect-error
|
|
406
|
-
() => requiredSearch({ id: '5' });
|
|
407
|
-
() => requiredSearch({ userId: 'hi' });
|
|
408
|
-
() => requiredSearch({ userId: 'hi', id: '5' });
|
|
409
|
-
// @ts-expect-error
|
|
410
|
-
() => requiredSearch(5);
|
|
411
|
-
// @ts-expect-error
|
|
412
|
-
() => requiredSearch({ userId: 'hi' }, { userId: 'hi' });
|
|
413
|
-
|
|
414
|
-
() => undef();
|
|
415
|
-
// @ts-ignore TODO
|
|
416
|
-
() => undef({});
|
|
417
|
-
// @ts-ignore TODO
|
|
418
|
-
() => undef({ id: '5' });
|
|
419
|
-
// @ts-expect-error
|
|
420
|
-
() => undef(5);
|
|
421
|
-
|
|
422
|
-
() => noSearch();
|
|
423
|
-
() => noSearch({});
|
|
424
|
-
() => noSearch({ id: '5' });
|
|
425
|
-
() => noSearch({ userId: 'hi' });
|
|
426
|
-
// @ts-expect-error
|
|
427
|
-
() => noSearch(5);
|
|
428
|
-
};
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
it('should allow sideEffect overrides', () => {
|
|
432
|
-
() => {
|
|
433
|
-
const getEth = new RestEndpoint({
|
|
434
|
-
urlPrefix: 'https://rpc.ankr.com',
|
|
435
|
-
path: '/eth',
|
|
436
|
-
method: 'POST',
|
|
437
|
-
body: {} as {
|
|
438
|
-
jsonrpc: string;
|
|
439
|
-
id: number;
|
|
440
|
-
method: string;
|
|
441
|
-
params: any[];
|
|
442
|
-
},
|
|
443
|
-
pollFrequency: 30 * 1000,
|
|
444
|
-
sideEffect: undefined,
|
|
445
|
-
});
|
|
446
|
-
const getEthExtend = new RestEndpoint({
|
|
447
|
-
urlPrefix: 'https://rpc.ankr.com',
|
|
448
|
-
path: '/eth',
|
|
449
|
-
method: 'POST',
|
|
450
|
-
body: {} as {
|
|
451
|
-
jsonrpc: string;
|
|
452
|
-
id: number;
|
|
453
|
-
method: string;
|
|
454
|
-
params: any[];
|
|
455
|
-
},
|
|
456
|
-
pollFrequency: 30 * 1000,
|
|
457
|
-
}).extend({ sideEffect: undefined });
|
|
458
|
-
|
|
459
|
-
const a: undefined = getEth.sideEffect;
|
|
460
|
-
const b: undefined = getEthExtend.sideEffect;
|
|
461
|
-
() => {
|
|
462
|
-
const ctrl = useController();
|
|
463
|
-
ctrl.fetch(getEth, {
|
|
464
|
-
jsonrpc: '2.0',
|
|
465
|
-
id: 1,
|
|
466
|
-
method: 'eth_getBlockByNumber',
|
|
467
|
-
params: ['latest', true],
|
|
468
|
-
});
|
|
469
|
-
useSuspense(getEth, {
|
|
470
|
-
jsonrpc: '2.0',
|
|
471
|
-
id: 1,
|
|
472
|
-
method: 'eth_getBlockByNumber',
|
|
473
|
-
params: ['latest', true],
|
|
474
|
-
});
|
|
475
|
-
// @ts-expect-error
|
|
476
|
-
ctrl.fetch(getEth, {
|
|
477
|
-
id: 1,
|
|
478
|
-
method: 'eth_getBlockByNumber',
|
|
479
|
-
params: ['latest', true],
|
|
480
|
-
});
|
|
481
|
-
// @ts-expect-error
|
|
482
|
-
useSuspense(getEth, {
|
|
483
|
-
id: 1,
|
|
484
|
-
method: 'eth_getBlockByNumber',
|
|
485
|
-
params: ['latest', true],
|
|
486
|
-
});
|
|
487
|
-
// @ts-expect-error
|
|
488
|
-
useSuspense(getEth, {
|
|
489
|
-
jsonrpc: '2.0',
|
|
490
|
-
id: 1,
|
|
491
|
-
method: 6,
|
|
492
|
-
params: ['latest', true],
|
|
493
|
-
});
|
|
494
|
-
useSuspense(
|
|
495
|
-
getEth,
|
|
496
|
-
// @ts-expect-error
|
|
497
|
-
{},
|
|
498
|
-
{
|
|
499
|
-
jsonrpc: '2.0',
|
|
500
|
-
id: 1,
|
|
501
|
-
method: 'eth_getBlockByNumber',
|
|
502
|
-
params: ['latest', true],
|
|
503
|
-
},
|
|
504
|
-
);
|
|
505
|
-
};
|
|
506
|
-
() => {
|
|
507
|
-
const ctrl = useController();
|
|
508
|
-
ctrl.fetch(getEthExtend, {
|
|
509
|
-
jsonrpc: '2.0',
|
|
510
|
-
id: 1,
|
|
511
|
-
method: 'eth_getBlockByNumber',
|
|
512
|
-
params: ['latest', true],
|
|
513
|
-
});
|
|
514
|
-
useSuspense(getEthExtend, {
|
|
515
|
-
jsonrpc: '2.0',
|
|
516
|
-
id: 1,
|
|
517
|
-
method: 'eth_getBlockByNumber',
|
|
518
|
-
params: ['latest', true],
|
|
519
|
-
});
|
|
520
|
-
// @ts-expect-error
|
|
521
|
-
ctrl.fetch(getEthExtend, {
|
|
522
|
-
id: 1,
|
|
523
|
-
method: 'eth_getBlockByNumber',
|
|
524
|
-
params: ['latest', true],
|
|
525
|
-
});
|
|
526
|
-
// @ts-expect-error
|
|
527
|
-
useSuspense(getEthExtend, {
|
|
528
|
-
id: 1,
|
|
529
|
-
method: 'eth_getBlockByNumber',
|
|
530
|
-
params: ['latest', true],
|
|
531
|
-
});
|
|
532
|
-
// @ts-expect-error
|
|
533
|
-
useSuspense(getEthExtend, {
|
|
534
|
-
jsonrpc: '2.0',
|
|
535
|
-
id: 1,
|
|
536
|
-
method: 6,
|
|
537
|
-
params: ['latest', true],
|
|
538
|
-
});
|
|
539
|
-
useSuspense(
|
|
540
|
-
getEthExtend,
|
|
541
|
-
// @ts-expect-error
|
|
542
|
-
{},
|
|
543
|
-
{
|
|
544
|
-
jsonrpc: '2.0',
|
|
545
|
-
id: 1,
|
|
546
|
-
method: 'eth_getBlockByNumber',
|
|
547
|
-
params: ['latest', true],
|
|
548
|
-
},
|
|
549
|
-
);
|
|
550
|
-
};
|
|
551
|
-
};
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
it('should handle more open ended type definitions', () => {
|
|
555
|
-
() => {
|
|
556
|
-
const unknownParams = new RestEndpoint({
|
|
557
|
-
path: '' as `${string}:${string}`,
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
unknownParams({ hi: 5 });
|
|
561
|
-
unknownParams();
|
|
562
|
-
// @ts-expect-error
|
|
563
|
-
unknownParams(5);
|
|
564
|
-
|
|
565
|
-
const explicit: GetEndpoint<{
|
|
566
|
-
path: `${string}:${string}`;
|
|
567
|
-
schema: schema.Collection<[typeof User]>;
|
|
568
|
-
}> = new RestEndpoint({
|
|
569
|
-
path: '' as `${string}:${string}`,
|
|
570
|
-
schema: new schema.Collection([User]),
|
|
571
|
-
});
|
|
572
|
-
explicit({ hi: 5 });
|
|
573
|
-
explicit.push.process({} as any, { hi: 5 });
|
|
574
|
-
explicit.push();
|
|
575
|
-
};
|
|
576
|
-
});
|