cloesce 0.0.4-unstable.0 → 0.0.4-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/README.md → README.md} +212 -67
- package/dist/cli.js +37 -21
- package/dist/common.d.ts +89 -41
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +93 -38
- package/dist/extractor/extract.d.ts +9 -9
- package/dist/extractor/extract.d.ts.map +1 -1
- package/dist/extractor/extract.js +128 -149
- package/dist/generator.wasm +0 -0
- package/dist/orm.wasm +0 -0
- package/dist/router/crud.d.ts.map +1 -1
- package/dist/router/crud.js +25 -20
- package/dist/router/router.d.ts +71 -15
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +190 -109
- package/dist/router/wasm.d.ts +10 -3
- package/dist/router/wasm.d.ts.map +1 -1
- package/dist/router/wasm.js +12 -6
- package/dist/ui/backend.d.ts +431 -41
- package/dist/ui/backend.d.ts.map +1 -1
- package/dist/ui/backend.js +391 -90
- package/dist/ui/client.d.ts +2 -1
- package/dist/ui/client.d.ts.map +1 -1
- package/dist/ui/client.js +1 -0
- package/package.json +2 -2
package/dist/common.d.ts
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
export type DeepPartial<T> = T extends (infer U)[] ? DeepPartial<U>[] : T extends object ? {
|
|
2
|
-
[K in keyof T]?: DeepPartial<T[K]>;
|
|
3
|
-
} : T;
|
|
4
|
-
export type Either<L, R> = {
|
|
5
|
-
ok: false;
|
|
6
|
-
value: L;
|
|
7
|
-
} | {
|
|
8
|
-
ok: true;
|
|
9
|
-
value: R;
|
|
10
|
-
};
|
|
11
|
-
export declare function left<L>(value: L): Either<L, never>;
|
|
12
|
-
export declare function right<R>(value: R): Either<never, R>;
|
|
13
1
|
export declare enum ExtractorErrorCode {
|
|
14
2
|
MissingExport = 0,
|
|
15
3
|
AppMissingDefaultExport = 1,
|
|
16
4
|
UnknownType = 2,
|
|
17
5
|
MultipleGenericType = 3,
|
|
18
|
-
|
|
6
|
+
InvalidDataSourceDefinition = 4,
|
|
19
7
|
InvalidPartialType = 5,
|
|
20
8
|
InvalidIncludeTree = 6,
|
|
21
9
|
InvalidAttributeModifier = 7,
|
|
@@ -25,9 +13,10 @@ export declare enum ExtractorErrorCode {
|
|
|
25
13
|
MissingNavigationPropertyReference = 11,
|
|
26
14
|
MissingManyToManyUniqueId = 12,
|
|
27
15
|
MissingPrimaryKey = 13,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
MissingDatabaseBinding = 14,
|
|
17
|
+
MissingWranglerEnv = 15,
|
|
18
|
+
TooManyWranglerEnvs = 16,
|
|
19
|
+
MissingFile = 17
|
|
31
20
|
}
|
|
32
21
|
export declare function getErrorInfo(code: ExtractorErrorCode): {
|
|
33
22
|
description: string;
|
|
@@ -40,36 +29,91 @@ export declare class ExtractorError {
|
|
|
40
29
|
constructor(code: ExtractorErrorCode);
|
|
41
30
|
addContext(fn: (val: string | undefined) => string | undefined): void;
|
|
42
31
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
data?: T;
|
|
47
|
-
message?: string;
|
|
48
|
-
};
|
|
32
|
+
type DeepPartialInner<T> = T extends (infer U)[] ? DeepPartialInner<U>[] : T extends object ? {
|
|
33
|
+
[K in keyof T]?: DeepPartialInner<T[K]>;
|
|
34
|
+
} : T | (null extends T ? null : never);
|
|
49
35
|
/**
|
|
50
|
-
*
|
|
36
|
+
* Recursively makes all properties of a type optional — including nested objects and arrays.
|
|
37
|
+
*
|
|
38
|
+
* Similar to TypeScript's built-in `Partial<T>`, but applies the transformation deeply across
|
|
39
|
+
* all nested structures. Useful for defining "patch" or "update" objects where only a subset
|
|
40
|
+
* of properties may be provided.
|
|
41
|
+
*
|
|
42
|
+
* **Apart of the Cloesce method grammar**, meaning the type can be apart of method parameters
|
|
43
|
+
* or return types and the generated workers and client API will act accordingly.
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* The target type to make deeply partial.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* - **Objects:** All properties become optional, and their values are recursively wrapped in `DeepPartial`.
|
|
50
|
+
* - **Arrays:** Arrays are preserved, but their elements are recursively made partial.
|
|
51
|
+
* - **Scalars:** Primitive values (string, number, boolean, etc.) remain unchanged.
|
|
52
|
+
* - **Nullable types:** If `null` is assignable to the type, it remains allowed.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* class User {
|
|
57
|
+
* id: string;
|
|
58
|
+
* profile: {
|
|
59
|
+
* name: string;
|
|
60
|
+
* age: number;
|
|
61
|
+
* };
|
|
62
|
+
* tags: string[];
|
|
63
|
+
* }
|
|
51
64
|
*
|
|
52
|
-
*
|
|
65
|
+
* // The resulting type:
|
|
66
|
+
* // {
|
|
67
|
+
* // id?: string;
|
|
68
|
+
* // profile?: { name?: string; age?: number };
|
|
69
|
+
* // tags?: (string | undefined)[];
|
|
70
|
+
* // }
|
|
71
|
+
* type PartialUser = DeepPartial<User>;
|
|
72
|
+
*
|
|
73
|
+
* const patch: PartialUser = {
|
|
74
|
+
* profile: { age: 30 } // ok
|
|
75
|
+
* };
|
|
76
|
+
* ```
|
|
53
77
|
*/
|
|
54
|
-
export type
|
|
55
|
-
|
|
78
|
+
export type DeepPartial<T> = DeepPartialInner<T> & {
|
|
79
|
+
__brand?: "Partial";
|
|
80
|
+
};
|
|
81
|
+
export declare class Either<L, R> {
|
|
82
|
+
private readonly inner;
|
|
83
|
+
private constructor();
|
|
84
|
+
get value(): L | R;
|
|
85
|
+
static left<L, R = never>(value: L): Either<L, R>;
|
|
86
|
+
static right<R, L = never>(value: R): Either<L, R>;
|
|
87
|
+
isLeft(): this is Either<L, never>;
|
|
88
|
+
isRight(): this is Either<never, R>;
|
|
89
|
+
unwrap(): R;
|
|
90
|
+
unwrapLeft(): L;
|
|
91
|
+
map<B>(fn: (val: R) => B): Either<L, B>;
|
|
92
|
+
mapLeft<B>(fn: (val: L) => B): Either<B, R>;
|
|
93
|
+
}
|
|
94
|
+
export declare class HttpResult<T = unknown> {
|
|
95
|
+
ok: boolean;
|
|
96
|
+
status: number;
|
|
97
|
+
headers: Headers;
|
|
98
|
+
data?: T | undefined;
|
|
99
|
+
message?: string | undefined;
|
|
100
|
+
constructor(ok: boolean, status: number, headers: Headers, data?: T | undefined, message?: string | undefined);
|
|
101
|
+
static ok<T>(status: number, data?: T, init?: HeadersInit): HttpResult;
|
|
102
|
+
static fail(status: number, message?: string, init?: HeadersInit): HttpResult<never>;
|
|
103
|
+
toResponse(): Response;
|
|
104
|
+
static fromJSON<T = unknown>(obj: {
|
|
105
|
+
ok: boolean;
|
|
106
|
+
status: number;
|
|
107
|
+
headers: Record<string, string>;
|
|
108
|
+
data?: T;
|
|
109
|
+
message?: string;
|
|
110
|
+
}): HttpResult<T>;
|
|
111
|
+
}
|
|
56
112
|
export type KeysOfType<T, U> = {
|
|
57
113
|
[K in keyof T]: T[K] extends U ? (K extends string ? K : never) : never;
|
|
58
114
|
}[keyof T];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* appropriate location, with global middleware happening before any routing occurs.
|
|
62
|
-
*/
|
|
63
|
-
export declare class CloesceApp {
|
|
64
|
-
global: MiddlewareFn[];
|
|
65
|
-
model: Map<string, MiddlewareFn[]>;
|
|
66
|
-
method: Map<string, Map<string, MiddlewareFn[]>>;
|
|
67
|
-
useGlobal(m: MiddlewareFn): void;
|
|
68
|
-
useModel<T>(ctor: new () => T, m: MiddlewareFn): void;
|
|
69
|
-
useMethod<T>(ctor: new () => T, method: KeysOfType<T, (...args: any) => any>, m: MiddlewareFn): void;
|
|
70
|
-
}
|
|
71
|
-
export type CrudKind = "POST" | "GET" | "LIST";
|
|
72
|
-
export type CidlType = "Void" | "Integer" | "Real" | "Text" | "Blob" | {
|
|
115
|
+
export type CrudKind = "SAVE" | "GET" | "LIST";
|
|
116
|
+
export type CidlType = "Void" | "Integer" | "Real" | "Text" | "Blob" | "DateIso" | "Boolean" | {
|
|
73
117
|
DataSource: string;
|
|
74
118
|
} | {
|
|
75
119
|
Inject: string;
|
|
@@ -133,6 +177,7 @@ export interface Model {
|
|
|
133
177
|
navigation_properties: NavigationProperty[];
|
|
134
178
|
methods: Record<string, ModelMethod>;
|
|
135
179
|
data_sources: Record<string, DataSource>;
|
|
180
|
+
cruds: CrudKind[];
|
|
136
181
|
source_path: string;
|
|
137
182
|
}
|
|
138
183
|
export interface PlainOldObject {
|
|
@@ -151,14 +196,17 @@ export interface DataSource {
|
|
|
151
196
|
export interface WranglerEnv {
|
|
152
197
|
name: string;
|
|
153
198
|
source_path: string;
|
|
199
|
+
db_binding: string;
|
|
200
|
+
vars: Record<string, CidlType>;
|
|
154
201
|
}
|
|
155
202
|
export interface CloesceAst {
|
|
156
203
|
version: string;
|
|
157
204
|
project_name: string;
|
|
158
|
-
language:
|
|
205
|
+
language: string;
|
|
159
206
|
wrangler_env: WranglerEnv;
|
|
160
207
|
models: Record<string, Model>;
|
|
161
208
|
poos: Record<string, PlainOldObject>;
|
|
162
209
|
app_source: string | null;
|
|
163
210
|
}
|
|
211
|
+
export {};
|
|
164
212
|
//# sourceMappingURL=common.d.ts.map
|
package/dist/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAC5B,aAAa,IAAA;IACb,uBAAuB,IAAA;IACvB,WAAW,IAAA;IACX,mBAAmB,IAAA;IACnB,2BAA2B,IAAA;IAC3B,kBAAkB,IAAA;IAClB,kBAAkB,IAAA;IAClB,wBAAwB,IAAA;IACxB,wBAAwB,IAAA;IACxB,kCAAkC,IAAA;IAClC,kCAAkC,KAAA;IAClC,kCAAkC,KAAA;IAClC,yBA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EAAE,MAAM,GAAG,eAAe,CAAC;CAChC;AAED,eAAO,MAAM,cAAc,SAAS,CAAC;AACrC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,eAAe,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,WAAW,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACrC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
|
package/dist/common.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
export function left(value) {
|
|
2
|
-
return { ok: false, value };
|
|
3
|
-
}
|
|
4
|
-
export function right(value) {
|
|
5
|
-
return { ok: true, value };
|
|
6
|
-
}
|
|
7
1
|
export var ExtractorErrorCode;
|
|
8
2
|
(function (ExtractorErrorCode) {
|
|
9
3
|
ExtractorErrorCode[ExtractorErrorCode["MissingExport"] = 0] = "MissingExport";
|
|
10
4
|
ExtractorErrorCode[ExtractorErrorCode["AppMissingDefaultExport"] = 1] = "AppMissingDefaultExport";
|
|
11
5
|
ExtractorErrorCode[ExtractorErrorCode["UnknownType"] = 2] = "UnknownType";
|
|
12
6
|
ExtractorErrorCode[ExtractorErrorCode["MultipleGenericType"] = 3] = "MultipleGenericType";
|
|
13
|
-
ExtractorErrorCode[ExtractorErrorCode["
|
|
7
|
+
ExtractorErrorCode[ExtractorErrorCode["InvalidDataSourceDefinition"] = 4] = "InvalidDataSourceDefinition";
|
|
14
8
|
ExtractorErrorCode[ExtractorErrorCode["InvalidPartialType"] = 5] = "InvalidPartialType";
|
|
15
9
|
ExtractorErrorCode[ExtractorErrorCode["InvalidIncludeTree"] = 6] = "InvalidIncludeTree";
|
|
16
10
|
ExtractorErrorCode[ExtractorErrorCode["InvalidAttributeModifier"] = 7] = "InvalidAttributeModifier";
|
|
@@ -20,9 +14,10 @@ export var ExtractorErrorCode;
|
|
|
20
14
|
ExtractorErrorCode[ExtractorErrorCode["MissingNavigationPropertyReference"] = 11] = "MissingNavigationPropertyReference";
|
|
21
15
|
ExtractorErrorCode[ExtractorErrorCode["MissingManyToManyUniqueId"] = 12] = "MissingManyToManyUniqueId";
|
|
22
16
|
ExtractorErrorCode[ExtractorErrorCode["MissingPrimaryKey"] = 13] = "MissingPrimaryKey";
|
|
23
|
-
ExtractorErrorCode[ExtractorErrorCode["
|
|
24
|
-
ExtractorErrorCode[ExtractorErrorCode["
|
|
25
|
-
ExtractorErrorCode[ExtractorErrorCode["
|
|
17
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingDatabaseBinding"] = 14] = "MissingDatabaseBinding";
|
|
18
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingWranglerEnv"] = 15] = "MissingWranglerEnv";
|
|
19
|
+
ExtractorErrorCode[ExtractorErrorCode["TooManyWranglerEnvs"] = 16] = "TooManyWranglerEnvs";
|
|
20
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingFile"] = 17] = "MissingFile";
|
|
26
21
|
})(ExtractorErrorCode || (ExtractorErrorCode = {}));
|
|
27
22
|
const errorInfoMap = {
|
|
28
23
|
[ExtractorErrorCode.MissingExport]: {
|
|
@@ -45,9 +40,9 @@ const errorInfoMap = {
|
|
|
45
40
|
description: "Cloesce does not yet support types with multiple generics",
|
|
46
41
|
suggestion: "Simplify your type to use only a single generic parameter, ie Foo<T>",
|
|
47
42
|
},
|
|
48
|
-
[ExtractorErrorCode.
|
|
49
|
-
description: "Data Sources must be
|
|
50
|
-
suggestion: "Declare your data source as `static readonly
|
|
43
|
+
[ExtractorErrorCode.InvalidDataSourceDefinition]: {
|
|
44
|
+
description: "Data Sources must be explicitly typed as a static Include Tree",
|
|
45
|
+
suggestion: "Declare your data source as `static readonly _: IncludeTree<Model>`",
|
|
51
46
|
},
|
|
52
47
|
[ExtractorErrorCode.InvalidIncludeTree]: {
|
|
53
48
|
description: "Invalid Include Tree",
|
|
@@ -81,6 +76,10 @@ const errorInfoMap = {
|
|
|
81
76
|
description: "Missing primary key on a model",
|
|
82
77
|
suggestion: "Add a primary key field to your model (e.g., `id: number`)",
|
|
83
78
|
},
|
|
79
|
+
[ExtractorErrorCode.MissingDatabaseBinding]: {
|
|
80
|
+
description: "Missing a database binding in the WranglerEnv definition",
|
|
81
|
+
suggestion: "Add a `D1Database` to your WranglerEnv",
|
|
82
|
+
},
|
|
84
83
|
[ExtractorErrorCode.MissingWranglerEnv]: {
|
|
85
84
|
description: "Missing a wrangler environment definition in the project",
|
|
86
85
|
suggestion: "Add a @WranglerEnv class in your project.",
|
|
@@ -108,34 +107,90 @@ export class ExtractorError {
|
|
|
108
107
|
this.context = fn(this.context ?? "");
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
export class Either {
|
|
111
|
+
inner;
|
|
112
|
+
constructor(inner) {
|
|
113
|
+
this.inner = inner;
|
|
114
|
+
}
|
|
115
|
+
get value() {
|
|
116
|
+
return this.inner.ok ? this.inner.right : this.inner.left;
|
|
117
|
+
}
|
|
118
|
+
static left(value) {
|
|
119
|
+
return new Either({ ok: false, left: value });
|
|
120
|
+
}
|
|
121
|
+
static right(value) {
|
|
122
|
+
return new Either({ ok: true, right: value });
|
|
123
|
+
}
|
|
124
|
+
isLeft() {
|
|
125
|
+
return !this.inner.ok;
|
|
126
|
+
}
|
|
127
|
+
isRight() {
|
|
128
|
+
return this.inner.ok;
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
if (!this.
|
|
132
|
-
|
|
130
|
+
unwrap() {
|
|
131
|
+
if (!this.inner.ok) {
|
|
132
|
+
throw new Error("Tried to unwrap a Left value");
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
return this.inner.right;
|
|
135
|
+
}
|
|
136
|
+
unwrapLeft() {
|
|
137
|
+
if (this.inner.ok) {
|
|
138
|
+
throw new Error("Tried to unwrapLeft a Right value");
|
|
137
139
|
}
|
|
138
|
-
|
|
140
|
+
return this.inner.left;
|
|
141
|
+
}
|
|
142
|
+
map(fn) {
|
|
143
|
+
return this.inner.ok
|
|
144
|
+
? Either.right(fn(this.inner.right))
|
|
145
|
+
: Either.left(this.inner.left);
|
|
146
|
+
}
|
|
147
|
+
mapLeft(fn) {
|
|
148
|
+
return this.inner.ok
|
|
149
|
+
? Either.right(this.inner.right)
|
|
150
|
+
: Either.left(fn(this.inner.left));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export class HttpResult {
|
|
154
|
+
ok;
|
|
155
|
+
status;
|
|
156
|
+
headers;
|
|
157
|
+
data;
|
|
158
|
+
message;
|
|
159
|
+
constructor(ok, status, headers, data, message) {
|
|
160
|
+
this.ok = ok;
|
|
161
|
+
this.status = status;
|
|
162
|
+
this.headers = headers;
|
|
163
|
+
this.data = data;
|
|
164
|
+
this.message = message;
|
|
165
|
+
}
|
|
166
|
+
static ok(status, data, init) {
|
|
167
|
+
const headers = new Headers(init ?? {
|
|
168
|
+
"Content-Type": "application/json",
|
|
169
|
+
});
|
|
170
|
+
return new HttpResult(true, status, headers, data, undefined);
|
|
171
|
+
}
|
|
172
|
+
static fail(status, message, init) {
|
|
173
|
+
const headers = new Headers(init ?? {
|
|
174
|
+
"Content-Type": "application/json",
|
|
175
|
+
});
|
|
176
|
+
return new HttpResult(false, status, headers, undefined, message);
|
|
177
|
+
}
|
|
178
|
+
toResponse() {
|
|
179
|
+
const body = JSON.stringify({
|
|
180
|
+
ok: this.ok,
|
|
181
|
+
status: this.status,
|
|
182
|
+
data: this.data,
|
|
183
|
+
message: this.message,
|
|
184
|
+
headers: Object.fromEntries(this.headers.entries()),
|
|
185
|
+
});
|
|
186
|
+
return new Response(body, {
|
|
187
|
+
status: this.status,
|
|
188
|
+
headers: this.headers,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
static fromJSON(obj) {
|
|
192
|
+
const headers = new Headers(obj.headers);
|
|
193
|
+
return new HttpResult(obj.ok, obj.status, headers, obj.data, obj.message);
|
|
139
194
|
}
|
|
140
195
|
}
|
|
141
196
|
export function isNullableType(ty) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Project } from "ts-morph";
|
|
2
|
-
import { CloesceAst, Either, ExtractorError } from "../common.js";
|
|
1
|
+
import { Project, Type, SourceFile, MethodDeclaration, ClassDeclaration, Expression } from "ts-morph";
|
|
2
|
+
import { CidlIncludeTree, CloesceAst, CidlType, Either, HttpVerb, Model, ModelMethod, WranglerEnv, ExtractorError, PlainOldObject } from "../common.js";
|
|
3
3
|
export declare class CidlExtractor {
|
|
4
4
|
projectName: string;
|
|
5
5
|
version: string;
|
|
6
6
|
constructor(projectName: string, version: string);
|
|
7
7
|
extract(project: Project): Either<ExtractorError, CloesceAst>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
static app(sourceFile: SourceFile): Either<ExtractorError, string>;
|
|
9
|
+
static model(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, Model>;
|
|
10
|
+
static poo(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, PlainOldObject>;
|
|
11
|
+
static env(classDecl: ClassDeclaration, sourceFile: SourceFile): Either<ExtractorError, WranglerEnv>;
|
|
11
12
|
private static readonly primTypeMap;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private static crudMethod;
|
|
13
|
+
static cidlType(type: Type, inject?: boolean): Either<ExtractorError, CidlType>;
|
|
14
|
+
static includeTree(expr: Expression | undefined, currentClass: ClassDeclaration, sf: SourceFile): Either<ExtractorError, CidlIncludeTree>;
|
|
15
|
+
static method(modelName: string, method: MethodDeclaration, httpVerb: HttpVerb): Either<ExtractorError, ModelMethod>;
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/extractor/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/extractor/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,OAAO,EACP,IAAI,EACJ,UAAU,EAEV,iBAAiB,EAEjB,gBAAgB,EAEhB,UAAU,EAEX,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,eAAe,EACf,UAAU,EACV,QAAQ,EAER,MAAM,EACN,QAAQ,EACR,KAAK,EAEL,WAAW,EAGX,WAAW,EACX,cAAc,EAEd,cAAc,EAEf,MAAM,cAAc,CAAC;AAuBtB,qBAAa,aAAa;IAEf,WAAW,EAAE,MAAM;IACnB,OAAO,EAAE,MAAM;gBADf,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM;IAGxB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC;IA8F7D,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC;IA8BlE,MAAM,CAAC,KAAK,CACV,SAAS,EAAE,gB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