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/ui/common.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { MediaType } from "../ast.js";
|
|
2
|
-
type DeepPartialInner<T> = T extends (infer U)[]
|
|
3
|
-
? DeepPartialInner<U>[]
|
|
4
|
-
: T extends object
|
|
5
|
-
? {
|
|
6
|
-
[K in keyof T]?: DeepPartialInner<T[K]>;
|
|
7
|
-
}
|
|
8
|
-
: T | (null extends T ? null : never);
|
|
9
|
-
/**
|
|
10
|
-
* Recursively makes all properties of a type optional — including nested objects and arrays.
|
|
11
|
-
*
|
|
12
|
-
* Similar to TypeScript's built-in `Partial<T>`, but applies the transformation deeply across
|
|
13
|
-
* all nested structures. Useful for defining "patch" or "update" objects where only a subset
|
|
14
|
-
* of properties may be provided.
|
|
15
|
-
*
|
|
16
|
-
* **Apart of the Cloesce method grammar**, meaning the type can be apart of method parameters
|
|
17
|
-
* or return types and the generated workers and client API will act accordingly.
|
|
18
|
-
*
|
|
19
|
-
* @template T
|
|
20
|
-
* The target type to make deeply partial.
|
|
21
|
-
*
|
|
22
|
-
* @remarks
|
|
23
|
-
* - **Objects:** All properties become optional, and their values are recursively wrapped in `DeepPartial`.
|
|
24
|
-
* - **Arrays:** Arrays are preserved, but their elements are recursively made partial.
|
|
25
|
-
* - **Scalars:** Primitive values (string, number, boolean, etc.) remain unchanged.
|
|
26
|
-
* - **Nullable types:** If `null` is assignable to the type, it remains allowed.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* class User {
|
|
31
|
-
* id: string;
|
|
32
|
-
* profile: {
|
|
33
|
-
* name: string;
|
|
34
|
-
* age: number;
|
|
35
|
-
* };
|
|
36
|
-
* tags: string[];
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* // The resulting type:
|
|
40
|
-
* // {
|
|
41
|
-
* // id?: string;
|
|
42
|
-
* // profile?: { name?: string; age?: number };
|
|
43
|
-
* // tags?: (string | undefined)[];
|
|
44
|
-
* // }
|
|
45
|
-
* type PartialUser = DeepPartial<User>;
|
|
46
|
-
*
|
|
47
|
-
* const patch: PartialUser = {
|
|
48
|
-
* profile: { age: 30 } // ok
|
|
49
|
-
* };
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export type DeepPartial<T> = DeepPartialInner<T> & {
|
|
53
|
-
__brand?: "Partial";
|
|
54
|
-
};
|
|
55
|
-
export declare class Either<L, R> {
|
|
56
|
-
private readonly inner;
|
|
57
|
-
private constructor();
|
|
58
|
-
get value(): L | R;
|
|
59
|
-
static left<R>(): Either<void, R>;
|
|
60
|
-
static left<L, R = never>(value: L): Either<L, R>;
|
|
61
|
-
static right<R, L = never>(value: R): Either<L, R>;
|
|
62
|
-
isLeft(): this is Either<L, never>;
|
|
63
|
-
isRight(): this is Either<never, R>;
|
|
64
|
-
unwrap(): R;
|
|
65
|
-
unwrapLeft(): L;
|
|
66
|
-
map<B>(fn: (val: R) => B): Either<L, B>;
|
|
67
|
-
mapLeft<B>(fn: (val: L) => B): Either<B, R>;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Given a media type and some data, converts to a proper
|
|
71
|
-
* `RequestInit` body,
|
|
72
|
-
*/
|
|
73
|
-
export declare function requestBody(
|
|
74
|
-
mediaType: MediaType,
|
|
75
|
-
data: any | string | undefined,
|
|
76
|
-
): undefined | string | FormData;
|
|
77
|
-
/**
|
|
78
|
-
* The result of a Workers endpoint.
|
|
79
|
-
*
|
|
80
|
-
* @param ok True if `status` < 400
|
|
81
|
-
* @param status The HTTP Status of a Workers request
|
|
82
|
-
* @param headers All headers that the result is to be sent with or was received with
|
|
83
|
-
* @param data JSON data yielded from a request, undefined if the request was not `ok`.
|
|
84
|
-
* @param message An error text set if the request was not `ok`.
|
|
85
|
-
*
|
|
86
|
-
* @remarks If `status` is 204 `data` will always be undefined.
|
|
87
|
-
*
|
|
88
|
-
*/
|
|
89
|
-
export declare class HttpResult<T = unknown> {
|
|
90
|
-
ok: boolean;
|
|
91
|
-
status: number;
|
|
92
|
-
headers: Headers;
|
|
93
|
-
data?: T | undefined;
|
|
94
|
-
message?: string | undefined;
|
|
95
|
-
mediaType?: MediaType | undefined;
|
|
96
|
-
constructor(
|
|
97
|
-
ok: boolean,
|
|
98
|
-
status: number,
|
|
99
|
-
headers: Headers,
|
|
100
|
-
data?: T | undefined,
|
|
101
|
-
message?: string | undefined,
|
|
102
|
-
mediaType?: MediaType | undefined,
|
|
103
|
-
);
|
|
104
|
-
static ok<T>(status: number, data?: T, init?: HeadersInit): HttpResult;
|
|
105
|
-
static fail(
|
|
106
|
-
status: number,
|
|
107
|
-
message?: string,
|
|
108
|
-
init?: HeadersInit,
|
|
109
|
-
): HttpResult<never>;
|
|
110
|
-
toResponse(): Response;
|
|
111
|
-
setMediaType(mediaType: MediaType): this;
|
|
112
|
-
static fromResponse(
|
|
113
|
-
response: Response,
|
|
114
|
-
mediaType: MediaType,
|
|
115
|
-
ctor?: any,
|
|
116
|
-
array?: boolean,
|
|
117
|
-
): Promise<HttpResult<any>>;
|
|
118
|
-
}
|
|
119
|
-
export type Stream = ReadableStream<Uint8Array>;
|
|
120
|
-
export declare function b64ToU8(b64: string): Uint8Array;
|
|
121
|
-
export declare function u8ToB64(u8: Uint8Array): string;
|
|
122
|
-
export type KeysOfType<T, U> = {
|
|
123
|
-
[K in keyof T]: T[K] extends U ? (K extends string ? K : never) : never;
|
|
124
|
-
}[keyof T];
|
|
125
|
-
export {};
|
|
126
|
-
//# sourceMappingURL=common.d.ts.map
|
package/dist/ui/common.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/ui/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5C,gBAAgB,CAAC,CAAC,CAAC,EAAE,GACrB,CAAC,SAAS,MAAM,GAChB;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,C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C,IAAI;KAC5B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK;CACxE,CAAC,MAAM,CAAC,CAAC,CAAC"}
|
package/dist/ui/common.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { MediaType } from "../ast.js";
|
|
2
|
-
export class Either {
|
|
3
|
-
inner;
|
|
4
|
-
constructor(inner) {
|
|
5
|
-
this.inner = inner;
|
|
6
|
-
}
|
|
7
|
-
get value() {
|
|
8
|
-
return this.inner.ok ? this.inner.right : this.inner.left;
|
|
9
|
-
}
|
|
10
|
-
static left(value) {
|
|
11
|
-
return new Either({ ok: false, left: value });
|
|
12
|
-
}
|
|
13
|
-
static right(value) {
|
|
14
|
-
return new Either({ ok: true, right: value });
|
|
15
|
-
}
|
|
16
|
-
isLeft() {
|
|
17
|
-
return !this.inner.ok;
|
|
18
|
-
}
|
|
19
|
-
isRight() {
|
|
20
|
-
return this.inner.ok;
|
|
21
|
-
}
|
|
22
|
-
unwrap() {
|
|
23
|
-
if (!this.inner.ok) {
|
|
24
|
-
throw new Error("Tried to unwrap a Left value");
|
|
25
|
-
}
|
|
26
|
-
return this.inner.right;
|
|
27
|
-
}
|
|
28
|
-
unwrapLeft() {
|
|
29
|
-
if (this.inner.ok) {
|
|
30
|
-
throw new Error("Tried to unwrapLeft a Right value");
|
|
31
|
-
}
|
|
32
|
-
return this.inner.left;
|
|
33
|
-
}
|
|
34
|
-
map(fn) {
|
|
35
|
-
return this.inner.ok
|
|
36
|
-
? Either.right(fn(this.inner.right))
|
|
37
|
-
: Either.left(this.inner.left);
|
|
38
|
-
}
|
|
39
|
-
mapLeft(fn) {
|
|
40
|
-
return this.inner.ok
|
|
41
|
-
? Either.right(this.inner.right)
|
|
42
|
-
: Either.left(fn(this.inner.left));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Given a media type and some data, converts to a proper
|
|
47
|
-
* `RequestInit` body,
|
|
48
|
-
*/
|
|
49
|
-
export function requestBody(mediaType, data) {
|
|
50
|
-
switch (mediaType) {
|
|
51
|
-
case MediaType.Json: {
|
|
52
|
-
return JSON.stringify(data ?? {}, (_, v) =>
|
|
53
|
-
v instanceof Uint8Array ? u8ToB64(v) : v,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
case MediaType.Octet: {
|
|
57
|
-
// JSON structure isn't needed; assume the first
|
|
58
|
-
// value is the stream data
|
|
59
|
-
return Object.values(data)[0];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* The result of a Workers endpoint.
|
|
65
|
-
*
|
|
66
|
-
* @param ok True if `status` < 400
|
|
67
|
-
* @param status The HTTP Status of a Workers request
|
|
68
|
-
* @param headers All headers that the result is to be sent with or was received with
|
|
69
|
-
* @param data JSON data yielded from a request, undefined if the request was not `ok`.
|
|
70
|
-
* @param message An error text set if the request was not `ok`.
|
|
71
|
-
*
|
|
72
|
-
* @remarks If `status` is 204 `data` will always be undefined.
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
export class HttpResult {
|
|
76
|
-
ok;
|
|
77
|
-
status;
|
|
78
|
-
headers;
|
|
79
|
-
data;
|
|
80
|
-
message;
|
|
81
|
-
mediaType;
|
|
82
|
-
constructor(ok, status, headers, data, message, mediaType) {
|
|
83
|
-
this.ok = ok;
|
|
84
|
-
this.status = status;
|
|
85
|
-
this.headers = headers;
|
|
86
|
-
this.data = data;
|
|
87
|
-
this.message = message;
|
|
88
|
-
this.mediaType = mediaType;
|
|
89
|
-
}
|
|
90
|
-
static ok(status, data, init) {
|
|
91
|
-
const headers = new Headers(init);
|
|
92
|
-
return new HttpResult(true, status, headers, data, undefined);
|
|
93
|
-
}
|
|
94
|
-
static fail(status, message, init) {
|
|
95
|
-
const headers = new Headers(init);
|
|
96
|
-
return new HttpResult(false, status, headers, undefined, message);
|
|
97
|
-
}
|
|
98
|
-
toResponse() {
|
|
99
|
-
switch (this.mediaType) {
|
|
100
|
-
case MediaType.Json: {
|
|
101
|
-
this.headers.set("Content-Type", "application/json");
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
case MediaType.Octet: {
|
|
105
|
-
this.headers.set("Content-Type", "application/octet-stream");
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
case undefined: {
|
|
109
|
-
// Errors are always text.
|
|
110
|
-
this.headers.set("Content-Type", "text/plain");
|
|
111
|
-
return new Response(this.message, {
|
|
112
|
-
status: this.status,
|
|
113
|
-
headers: this.headers,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return new Response(requestBody(this.mediaType, this.data), {
|
|
118
|
-
status: this.status,
|
|
119
|
-
headers: this.headers,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
setMediaType(mediaType) {
|
|
123
|
-
this.mediaType = mediaType;
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
static async fromResponse(response, mediaType, ctor, array = false) {
|
|
127
|
-
if (response.status >= 400) {
|
|
128
|
-
return new HttpResult(
|
|
129
|
-
false,
|
|
130
|
-
response.status,
|
|
131
|
-
response.headers,
|
|
132
|
-
undefined,
|
|
133
|
-
await response.text(),
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
function instantiate(json, ctor) {
|
|
137
|
-
switch (ctor) {
|
|
138
|
-
case Date: {
|
|
139
|
-
return new Date(json);
|
|
140
|
-
}
|
|
141
|
-
case Uint8Array: {
|
|
142
|
-
return b64ToU8(json);
|
|
143
|
-
}
|
|
144
|
-
case undefined: {
|
|
145
|
-
return json;
|
|
146
|
-
}
|
|
147
|
-
default: {
|
|
148
|
-
return ctor.fromJson(json);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async function data() {
|
|
153
|
-
switch (mediaType) {
|
|
154
|
-
case MediaType.Json: {
|
|
155
|
-
let json = await response.json();
|
|
156
|
-
if (array) {
|
|
157
|
-
for (let i = 0; i < json.length; i++) {
|
|
158
|
-
json[i] = instantiate(json[i], ctor);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
json = instantiate(json, ctor);
|
|
162
|
-
}
|
|
163
|
-
return json;
|
|
164
|
-
}
|
|
165
|
-
case MediaType.Octet: {
|
|
166
|
-
return response.body;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return new HttpResult(
|
|
171
|
-
true,
|
|
172
|
-
response.status,
|
|
173
|
-
response.headers,
|
|
174
|
-
await data(),
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export function b64ToU8(b64) {
|
|
179
|
-
// Prefer Buffer in Node.js environments
|
|
180
|
-
if (typeof Buffer !== "undefined") {
|
|
181
|
-
const buffer = Buffer.from(b64, "base64");
|
|
182
|
-
return new Uint8Array(buffer);
|
|
183
|
-
}
|
|
184
|
-
// Use atob only in browser environments
|
|
185
|
-
const s = atob(b64);
|
|
186
|
-
const u8 = new Uint8Array(s.length);
|
|
187
|
-
for (let i = 0; i < s.length; i++) {
|
|
188
|
-
u8[i] = s.charCodeAt(i);
|
|
189
|
-
}
|
|
190
|
-
return u8;
|
|
191
|
-
}
|
|
192
|
-
export function u8ToB64(u8) {
|
|
193
|
-
// Prefer Buffer in Node.js environments
|
|
194
|
-
if (typeof Buffer !== "undefined") {
|
|
195
|
-
return Buffer.from(u8).toString("base64");
|
|
196
|
-
}
|
|
197
|
-
// Use btoa only in browser environments
|
|
198
|
-
let s = "";
|
|
199
|
-
for (let i = 0; i < u8.length; i++) {
|
|
200
|
-
s += String.fromCharCode(u8[i]);
|
|
201
|
-
}
|
|
202
|
-
return btoa(s);
|
|
203
|
-
}
|