@typespec/spec-api 0.1.0-alpha.1 → 0.1.0-alpha.10-dev.1
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/CHANGELOG.md +62 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/request-validations.d.ts.map +1 -1
- package/dist/response-utils.d.ts +19 -5
- package/dist/response-utils.d.ts.map +1 -1
- package/dist/response-utils.js +72 -5
- package/dist/response-utils.js.map +1 -1
- package/dist/scenarios.d.ts +5 -5
- package/dist/scenarios.d.ts.map +1 -1
- package/dist/scenarios.js.map +1 -1
- package/dist/types.d.ts +26 -25
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +17 -23
- package/src/index.ts +5 -7
- package/src/response-utils.ts +92 -7
- package/src/scenarios.ts +4 -10
- package/src/types.ts +29 -32
- package/temp/.tsbuildinfo +1 -1
- package/test/dyn.test.ts +32 -0
- package/vitest.config.ts +1 -1
- package/dist/routes.d.ts +0 -65
- package/dist/routes.d.ts.map +0 -1
- package/dist/routes.js +0 -79
- package/dist/routes.js.map +0 -1
- package/src/routes.ts +0 -92
package/dist/routes.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { HttpMethod, MockApiForHandler, MockRequestHandler } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Register a GET request for the provided uri.
|
|
4
|
-
* @param uri URI to match.
|
|
5
|
-
* @param func Request handler.
|
|
6
|
-
*/
|
|
7
|
-
declare function get<const T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
8
|
-
/**
|
|
9
|
-
* Register a POST request for the provided uri.
|
|
10
|
-
* @param uri URI to match.
|
|
11
|
-
* @param func Request handler.
|
|
12
|
-
*/
|
|
13
|
-
declare function post<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
14
|
-
/**
|
|
15
|
-
* Register a PUT request for the provided uri.
|
|
16
|
-
* @param uri URI to match.
|
|
17
|
-
* @param func Request handler.
|
|
18
|
-
*/
|
|
19
|
-
declare function put<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Register a PATCH request for the provided uri.
|
|
22
|
-
* @param uri URI to match.
|
|
23
|
-
* @param func Request handler.
|
|
24
|
-
*/
|
|
25
|
-
declare function patch<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
26
|
-
/**
|
|
27
|
-
* Register a DELETE request for the provided uri.
|
|
28
|
-
* @param uri URI to match.
|
|
29
|
-
* @param func Request handler.
|
|
30
|
-
*/
|
|
31
|
-
declare function deleteReq<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Register a Options request for the provided uri.
|
|
34
|
-
* @param uri URI to match.
|
|
35
|
-
* @param func Request handler.
|
|
36
|
-
*/
|
|
37
|
-
declare function options<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
38
|
-
/**
|
|
39
|
-
* Register a HEAD request for the provided uri.
|
|
40
|
-
* @param uri URI to match.
|
|
41
|
-
* @param name Name of the scenario(For coverage).
|
|
42
|
-
* @param func Request handler.
|
|
43
|
-
*/
|
|
44
|
-
declare function head<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T>;
|
|
45
|
-
/**
|
|
46
|
-
* Register a request for the provided uri.
|
|
47
|
-
* @param method Method to use.
|
|
48
|
-
* @param uri URI to match.
|
|
49
|
-
* @param func Request handler.
|
|
50
|
-
*
|
|
51
|
-
* @note prefer to use the corresponding method method directly instead of `request()`(i.e `get(), post()`)
|
|
52
|
-
*/
|
|
53
|
-
declare function request<T extends MockRequestHandler>(method: HttpMethod, uri: string, handler: T): MockApiForHandler<T>;
|
|
54
|
-
export declare const mockapi: {
|
|
55
|
-
get: typeof get;
|
|
56
|
-
post: typeof post;
|
|
57
|
-
put: typeof put;
|
|
58
|
-
patch: typeof patch;
|
|
59
|
-
delete: typeof deleteReq;
|
|
60
|
-
options: typeof options;
|
|
61
|
-
head: typeof head;
|
|
62
|
-
request: typeof request;
|
|
63
|
-
};
|
|
64
|
-
export {};
|
|
65
|
-
//# sourceMappingURL=routes.d.ts.map
|
package/dist/routes.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE/E;;;;GAIG;AACH,iBAAS,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAE3F;AAED;;;;GAIG;AACH,iBAAS,IAAI,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAEtF;AAED;;;;GAIG;AACH,iBAAS,GAAG,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAErF;AAED;;;;GAIG;AACH,iBAAS,KAAK,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAEvF;AAED;;;;GAIG;AACH,iBAAS,SAAS,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAE3F;AAED;;;;GAIG;AACH,iBAAS,OAAO,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAEzF;AAED;;;;;GAKG;AACH,iBAAS,IAAI,CAAC,CAAC,SAAS,kBAAkB,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAEtF;AAED;;;;;;;GAOG;AACH,iBAAS,OAAO,CAAC,CAAC,SAAS,kBAAkB,EAC3C,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,GACT,iBAAiB,CAAC,CAAC,CAAC,CAEtB;AAED,eAAO,MAAM,OAAO;;;;;;;;;CASnB,CAAC"}
|
package/dist/routes.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Register a GET request for the provided uri.
|
|
3
|
-
* @param uri URI to match.
|
|
4
|
-
* @param func Request handler.
|
|
5
|
-
*/
|
|
6
|
-
function get(uri, func) {
|
|
7
|
-
return request("get", uri, func);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Register a POST request for the provided uri.
|
|
11
|
-
* @param uri URI to match.
|
|
12
|
-
* @param func Request handler.
|
|
13
|
-
*/
|
|
14
|
-
function post(uri, func) {
|
|
15
|
-
return request("post", uri, func);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Register a PUT request for the provided uri.
|
|
19
|
-
* @param uri URI to match.
|
|
20
|
-
* @param func Request handler.
|
|
21
|
-
*/
|
|
22
|
-
function put(uri, func) {
|
|
23
|
-
return request("put", uri, func);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Register a PATCH request for the provided uri.
|
|
27
|
-
* @param uri URI to match.
|
|
28
|
-
* @param func Request handler.
|
|
29
|
-
*/
|
|
30
|
-
function patch(uri, func) {
|
|
31
|
-
return request("patch", uri, func);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Register a DELETE request for the provided uri.
|
|
35
|
-
* @param uri URI to match.
|
|
36
|
-
* @param func Request handler.
|
|
37
|
-
*/
|
|
38
|
-
function deleteReq(uri, func) {
|
|
39
|
-
return request("delete", uri, func);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Register a Options request for the provided uri.
|
|
43
|
-
* @param uri URI to match.
|
|
44
|
-
* @param func Request handler.
|
|
45
|
-
*/
|
|
46
|
-
function options(uri, func) {
|
|
47
|
-
return request("options", uri, func);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Register a HEAD request for the provided uri.
|
|
51
|
-
* @param uri URI to match.
|
|
52
|
-
* @param name Name of the scenario(For coverage).
|
|
53
|
-
* @param func Request handler.
|
|
54
|
-
*/
|
|
55
|
-
function head(uri, func) {
|
|
56
|
-
return request("head", uri, func);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Register a request for the provided uri.
|
|
60
|
-
* @param method Method to use.
|
|
61
|
-
* @param uri URI to match.
|
|
62
|
-
* @param func Request handler.
|
|
63
|
-
*
|
|
64
|
-
* @note prefer to use the corresponding method method directly instead of `request()`(i.e `get(), post()`)
|
|
65
|
-
*/
|
|
66
|
-
function request(method, uri, handler) {
|
|
67
|
-
return { method, uri, handler };
|
|
68
|
-
}
|
|
69
|
-
export const mockapi = {
|
|
70
|
-
get,
|
|
71
|
-
post,
|
|
72
|
-
put,
|
|
73
|
-
patch,
|
|
74
|
-
delete: deleteReq,
|
|
75
|
-
options,
|
|
76
|
-
head,
|
|
77
|
-
request,
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=routes.js.map
|
package/dist/routes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,SAAS,GAAG,CAAqC,GAAW,EAAE,IAAO;IACnE,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAA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
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Register a GET request for the provided uri.
|
|
5
|
-
* @param uri URI to match.
|
|
6
|
-
* @param func Request handler.
|
|
7
|
-
*/
|
|
8
|
-
function get<const T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
9
|
-
return request("get", uri, func);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Register a POST request for the provided uri.
|
|
14
|
-
* @param uri URI to match.
|
|
15
|
-
* @param func Request handler.
|
|
16
|
-
*/
|
|
17
|
-
function post<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
18
|
-
return request("post", uri, func);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Register a PUT request for the provided uri.
|
|
23
|
-
* @param uri URI to match.
|
|
24
|
-
* @param func Request handler.
|
|
25
|
-
*/
|
|
26
|
-
function put<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
27
|
-
return request("put", uri, func);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Register a PATCH request for the provided uri.
|
|
32
|
-
* @param uri URI to match.
|
|
33
|
-
* @param func Request handler.
|
|
34
|
-
*/
|
|
35
|
-
function patch<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
36
|
-
return request("patch", uri, func);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Register a DELETE request for the provided uri.
|
|
41
|
-
* @param uri URI to match.
|
|
42
|
-
* @param func Request handler.
|
|
43
|
-
*/
|
|
44
|
-
function deleteReq<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
45
|
-
return request("delete", uri, func);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Register a Options request for the provided uri.
|
|
50
|
-
* @param uri URI to match.
|
|
51
|
-
* @param func Request handler.
|
|
52
|
-
*/
|
|
53
|
-
function options<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
54
|
-
return request("options", uri, func);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Register a HEAD request for the provided uri.
|
|
59
|
-
* @param uri URI to match.
|
|
60
|
-
* @param name Name of the scenario(For coverage).
|
|
61
|
-
* @param func Request handler.
|
|
62
|
-
*/
|
|
63
|
-
function head<T extends MockRequestHandler>(uri: string, func: T): MockApiForHandler<T> {
|
|
64
|
-
return request<T>("head", uri, func);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Register a request for the provided uri.
|
|
69
|
-
* @param method Method to use.
|
|
70
|
-
* @param uri URI to match.
|
|
71
|
-
* @param func Request handler.
|
|
72
|
-
*
|
|
73
|
-
* @note prefer to use the corresponding method method directly instead of `request()`(i.e `get(), post()`)
|
|
74
|
-
*/
|
|
75
|
-
function request<T extends MockRequestHandler>(
|
|
76
|
-
method: HttpMethod,
|
|
77
|
-
uri: string,
|
|
78
|
-
handler: T,
|
|
79
|
-
): MockApiForHandler<T> {
|
|
80
|
-
return { method, uri, handler } as any;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const mockapi = {
|
|
84
|
-
get,
|
|
85
|
-
post,
|
|
86
|
-
put,
|
|
87
|
-
patch,
|
|
88
|
-
delete: deleteReq,
|
|
89
|
-
options,
|
|
90
|
-
head,
|
|
91
|
-
request,
|
|
92
|
-
};
|