cloesce 0.0.5-unstable.1 → 0.0.5-unstable.10
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/dist/ast.d.ts +96 -106
- package/dist/ast.d.ts.map +1 -1
- package/dist/ast.js +12 -12
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +330 -368
- package/dist/common.d.ts +23 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +78 -0
- package/dist/extractor/err.d.ts +25 -26
- package/dist/extractor/err.d.ts.map +1 -1
- package/dist/extractor/err.js +95 -129
- package/dist/extractor/extract.d.ts +24 -61
- package/dist/extractor/extract.d.ts.map +1 -1
- package/dist/extractor/extract.js +1006 -836
- package/dist/generator.wasm +0 -0
- package/dist/orm.wasm +0 -0
- package/dist/router/crud.d.ts +2 -3
- package/dist/router/crud.d.ts.map +1 -1
- package/dist/router/crud.js +58 -48
- package/dist/router/orm.d.ts +66 -0
- package/dist/router/orm.d.ts.map +1 -0
- package/dist/router/orm.js +447 -0
- package/dist/router/router.d.ts +93 -139
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +389 -432
- package/dist/router/validator.d.ts +7 -12
- package/dist/router/validator.d.ts.map +1 -1
- package/dist/router/validator.js +190 -159
- package/dist/router/wasm.d.ts +26 -67
- package/dist/router/wasm.d.ts.map +1 -1
- package/dist/router/wasm.js +52 -103
- package/dist/ui/backend.d.ts +103 -382
- package/dist/ui/backend.d.ts.map +1 -1
- package/dist/ui/backend.js +143 -430
- package/package.json +4 -10
- package/dist/ui/client.d.ts +0 -7
- package/dist/ui/client.d.ts.map +0 -1
- package/dist/ui/client.js +0 -2
- package/dist/ui/common.d.ts +0 -126
- package/dist/ui/common.d.ts.map +0 -1
- package/dist/ui/common.js +0 -203
package/dist/router/router.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OrmWasmExports } from "./wasm.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Either
|
|
4
|
-
import {
|
|
2
|
+
import { CloesceAst, Model, ApiMethod, Service, CrudKind } from "../ast.js";
|
|
3
|
+
import { Either } from "../common.js";
|
|
4
|
+
import { KeysOfType, HttpResult } from "../ui/backend.js";
|
|
5
5
|
/**
|
|
6
6
|
* Dependency injection container, mapping an object type name to an instance of that object.
|
|
7
7
|
*
|
|
@@ -15,177 +15,131 @@ export type DependencyContainer = Map<string, any>;
|
|
|
15
15
|
*/
|
|
16
16
|
export type ConstructorRegistry = Record<string, new () => any>;
|
|
17
17
|
/**
|
|
18
|
-
* Singleton instance containing the
|
|
18
|
+
* Singleton instance containing the CIDL, constructor registry, and wasm binary.
|
|
19
19
|
* These values are guaranteed to never change throughout a workers lifetime.
|
|
20
20
|
*/
|
|
21
21
|
export declare class RuntimeContainer {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Disposes the singleton instance. For testing purposes only.
|
|
35
|
-
*/
|
|
36
|
-
static dispose(): void;
|
|
22
|
+
readonly ast: CloesceAst;
|
|
23
|
+
readonly constructorRegistry: ConstructorRegistry;
|
|
24
|
+
readonly wasm: OrmWasmExports;
|
|
25
|
+
private static instance;
|
|
26
|
+
private constructor();
|
|
27
|
+
static init(ast: CloesceAst, constructorRegistry: ConstructorRegistry, wasm?: WebAssembly.Instance): Promise<void>;
|
|
28
|
+
static get(): RuntimeContainer;
|
|
29
|
+
/**
|
|
30
|
+
* Disposes the singleton instance. For testing purposes only.
|
|
31
|
+
*/
|
|
32
|
+
static dispose(): void;
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
39
35
|
* Given a request, this represents a map of each body / url param name to
|
|
40
36
|
* its actual value. Unknown, as the a request can be anything.
|
|
41
37
|
*/
|
|
42
38
|
export type RequestParamMap = Record<string, unknown>;
|
|
43
|
-
export type MiddlewareFn = (
|
|
44
|
-
|
|
45
|
-
) => Promise<HttpResult | void>;
|
|
46
|
-
export type ResultMiddlewareFn = (
|
|
47
|
-
di: DependencyContainer,
|
|
48
|
-
result: HttpResult,
|
|
49
|
-
) => Promise<HttpResult | void>;
|
|
39
|
+
export type MiddlewareFn = (di: DependencyContainer) => Promise<HttpResult | void>;
|
|
40
|
+
export type ResultMiddlewareFn = (di: DependencyContainer, result: HttpResult) => Promise<HttpResult | void>;
|
|
50
41
|
/**
|
|
51
42
|
* Expected states in which the router may exit.
|
|
52
43
|
*/
|
|
53
44
|
export declare enum RouterError {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
UnknownPrefix = 0,
|
|
46
|
+
UnknownRoute = 1,
|
|
47
|
+
UnmatchedHttpVerb = 2,
|
|
48
|
+
InstantiatedMethodMissingPrimaryKey = 3,
|
|
49
|
+
InstantiatedMethodMissingKeyParam = 4,
|
|
50
|
+
RequestMissingBody = 5,
|
|
51
|
+
RequestBodyMissingParameters = 6,
|
|
52
|
+
RequestBodyInvalidParameter = 7,
|
|
53
|
+
InstantiatedMethodMissingDataSource = 8,
|
|
54
|
+
MissingDependency = 9,
|
|
55
|
+
InvalidDatabaseQuery = 10,
|
|
56
|
+
ModelNotFound = 11,
|
|
57
|
+
UncaughtException = 12
|
|
66
58
|
}
|
|
67
59
|
export declare class CloesceApp {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
* @typeParam T - The namespace type
|
|
114
|
-
* @param ctor - The namespace constructor
|
|
115
|
-
* @param method - The method name on the namespace.
|
|
116
|
-
* @param m - The middleware function to register.
|
|
117
|
-
*/
|
|
118
|
-
onMethod<T>(
|
|
119
|
-
ctor: new () => T,
|
|
120
|
-
method: KeysOfType<T, (...args: any) => any>,
|
|
121
|
-
m: MiddlewareFn,
|
|
122
|
-
): void;
|
|
123
|
-
private router;
|
|
124
|
-
/**
|
|
125
|
-
* Runs the Cloesce app. Intended to be called from the generated workers code.
|
|
126
|
-
*/
|
|
127
|
-
run(
|
|
128
|
-
request: Request,
|
|
129
|
-
env: any,
|
|
130
|
-
ast: CloesceAst,
|
|
131
|
-
ctorReg: ConstructorRegistry,
|
|
132
|
-
): Promise<Response>;
|
|
60
|
+
routePrefix: string;
|
|
61
|
+
static init(ast: CloesceAst, ctorReg: ConstructorRegistry): Promise<CloesceApp>;
|
|
62
|
+
private globalMiddleware;
|
|
63
|
+
/**
|
|
64
|
+
* Registers global middleware that runs before all requests.
|
|
65
|
+
*
|
|
66
|
+
* Runs before namespace middleware, request validation, and method middleware.
|
|
67
|
+
*
|
|
68
|
+
* TODO: Middleware may violate the API contract and return unexpected types
|
|
69
|
+
*
|
|
70
|
+
* @param m - The middleware function to register.
|
|
71
|
+
*/
|
|
72
|
+
onRun(m: MiddlewareFn): void;
|
|
73
|
+
private namespaceMiddleware;
|
|
74
|
+
/**
|
|
75
|
+
* Registers middleware for a specific namespace (model or service)
|
|
76
|
+
*
|
|
77
|
+
* Runs before request validation and method middleware.
|
|
78
|
+
*
|
|
79
|
+
* TODO: Middleware may violate the API contract and return unexpected types
|
|
80
|
+
*
|
|
81
|
+
* @typeParam T - The namespace type
|
|
82
|
+
* @param ctor - The namespace's constructor (used to derive its name).
|
|
83
|
+
* @param m - The middleware function to register.
|
|
84
|
+
*/
|
|
85
|
+
onNamespace<T>(ctor: new () => T, m: MiddlewareFn): void;
|
|
86
|
+
private methodMiddleware;
|
|
87
|
+
/**
|
|
88
|
+
* Registers middleware for a specific method on a namespace
|
|
89
|
+
*
|
|
90
|
+
* Runs after namespace middleware and request validation.
|
|
91
|
+
*
|
|
92
|
+
* TODO: Middleware may violate the API contract and return unexpected types
|
|
93
|
+
*
|
|
94
|
+
* @typeParam T - The namespace type
|
|
95
|
+
* @param ctor - The namespace constructor
|
|
96
|
+
* @param method - The method name on the namespace.
|
|
97
|
+
* @param m - The middleware function to register.
|
|
98
|
+
*/
|
|
99
|
+
onMethod<T>(ctor: new () => T, method: KeysOfType<T, (...args: any) => any> | CrudKind, m: MiddlewareFn): void;
|
|
100
|
+
private router;
|
|
101
|
+
/**
|
|
102
|
+
* Runs the Cloesce app. Intended to be called from the generated workers code.
|
|
103
|
+
*/
|
|
104
|
+
run(request: Request, env: any): Promise<Response>;
|
|
133
105
|
}
|
|
134
106
|
export type MatchedRoute = {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
107
|
+
kind: "model" | "service";
|
|
108
|
+
namespace: string;
|
|
109
|
+
method: ApiMethod;
|
|
110
|
+
primaryKey: string | null;
|
|
111
|
+
keyParams: Record<string, string>;
|
|
112
|
+
model?: Model;
|
|
113
|
+
service?: Service;
|
|
141
114
|
};
|
|
142
115
|
/**
|
|
143
116
|
* Matches a request to an ApiInvocation
|
|
144
117
|
* @param apiRoute The route from the domain to the actual API, ie https://foo.com/route/to/api => route/to/api/
|
|
145
118
|
* @returns 404 or a matched route.
|
|
146
119
|
*/
|
|
147
|
-
declare function matchRoute(
|
|
148
|
-
request: Request,
|
|
149
|
-
ast: CloesceAst,
|
|
150
|
-
routePrefix: string,
|
|
151
|
-
): Either<HttpResult, MatchedRoute>;
|
|
120
|
+
declare function matchRoute(request: Request, ast: CloesceAst, routePrefix: string): Either<HttpResult, MatchedRoute>;
|
|
152
121
|
/**
|
|
153
122
|
* Validates the request's body/search params against a ModelMethod
|
|
154
123
|
* @returns 400 or a `RequestParamMap` consisting of each parameters name mapped to its value, and
|
|
155
124
|
* a data source
|
|
156
125
|
*/
|
|
157
|
-
declare function validateRequest(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
route: MatchedRoute,
|
|
162
|
-
): Promise<
|
|
163
|
-
Either<
|
|
164
|
-
HttpResult,
|
|
165
|
-
{
|
|
166
|
-
params: RequestParamMap;
|
|
167
|
-
dataSource: string | null;
|
|
168
|
-
}
|
|
169
|
-
>
|
|
170
|
-
>;
|
|
126
|
+
declare function validateRequest(request: Request, ast: CloesceAst, ctorReg: ConstructorRegistry, route: MatchedRoute): Promise<Either<HttpResult, {
|
|
127
|
+
params: RequestParamMap;
|
|
128
|
+
dataSource: string | null;
|
|
129
|
+
}>>;
|
|
171
130
|
/**
|
|
172
131
|
* Calls a method on a model given a list of parameters.
|
|
173
132
|
* @returns 500 on an uncaught client error, 200 with a result body on success
|
|
174
133
|
*/
|
|
175
|
-
declare function methodDispatch(
|
|
176
|
-
obj: any,
|
|
177
|
-
di: DependencyContainer,
|
|
178
|
-
route: MatchedRoute,
|
|
179
|
-
params: Record<string, unknown>,
|
|
180
|
-
): Promise<HttpResult<unknown>>;
|
|
134
|
+
declare function methodDispatch(obj: any, di: DependencyContainer, route: MatchedRoute, params: Record<string, unknown>): Promise<HttpResult<unknown>>;
|
|
181
135
|
/**
|
|
182
136
|
* For testing purposes
|
|
183
137
|
*/
|
|
184
138
|
export declare const _cloesceInternal: {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
139
|
+
matchRoute: typeof matchRoute;
|
|
140
|
+
validateRequest: typeof validateRequest;
|
|
141
|
+
methodDispatch: typeof methodDispatch;
|
|
142
|
+
RuntimeContainer: typeof RuntimeContainer;
|
|
189
143
|
};
|
|
190
144
|
export {};
|
|
191
|
-
//# sourceMappingURL=router.d.ts.map
|
|
145
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,WAAW,CAAC;AAGxD,OAAO,EACL,UAAU,EACV,KAAK,EACL,SAAS,EAET,OAAO,EAEP,QAAQ,EACT,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,MAAM,EAAiB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAO,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,CAAC;AAEhE;;;GAGG;AACH,qBAAa,gBAAgB;aAGT,GAAG,EAAE,UAAU;aACf,mBAAmB,EAAE,mBAAmB;aACxC,IAAI,EAAE,cAAc;IAJtC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA+B;IACtD,OAAO;WAMM,IAAI,CACf,GAAG,EAAE,UAAU,EACf,mBAAmB,EAAE,mBAAmB,EACxC,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ;IAO7B,MAAM,CAAC,GAAG,IAAI,gBAAgB;IAI9B;;OAEG;IACH,MAAM,CAAC,OAAO;CAGf;AAED;;;GAGG;AACH,MA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