cloesce 0.0.5-unstable.1 → 0.0.5-unstable.11
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/backend.d.ts
CHANGED
|
@@ -1,66 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DeepPartial, Either, KeysOfType } from "./common.js";
|
|
3
|
-
import { CrudKind } from "../ast.js";
|
|
1
|
+
import { CrudKind, MediaType } from "../ast.js";
|
|
4
2
|
/**
|
|
5
3
|
* cloesce/backend
|
|
6
4
|
*/
|
|
7
|
-
export {
|
|
8
|
-
CloesceApp,
|
|
9
|
-
DependencyContainer as DependencyInjector,
|
|
10
|
-
} from "../router/router.js";
|
|
5
|
+
export { CloesceApp, DependencyContainer } from "../router/router.js";
|
|
11
6
|
export type { MiddlewareFn, ResultMiddlewareFn } from "../router/router.js";
|
|
12
|
-
export { HttpResult, Either, Stream } from "./common.js";
|
|
13
|
-
export type { DeepPartial } from "./common.js";
|
|
14
7
|
export type { CrudKind } from "../ast.js";
|
|
8
|
+
export { Orm } from "../router/orm.js";
|
|
9
|
+
export { R2ObjectBody } from "@cloudflare/workers-types";
|
|
15
10
|
/**
|
|
16
|
-
*
|
|
11
|
+
* Base class for a Cloudflare KV model or navigation property.
|
|
17
12
|
*
|
|
18
|
-
*
|
|
19
|
-
* - a D1 table definition (via `cloesce migrate`)
|
|
20
|
-
* - backend API endpoints (Workers)
|
|
21
|
-
* - a frontend client API
|
|
22
|
-
* - Cloudflare Wrangler configurations
|
|
13
|
+
* Consists of a `key`, `value`, and optional `metadata`.
|
|
23
14
|
*
|
|
24
|
-
*
|
|
15
|
+
* @template V The type of the value stored in the KValue. Note that KV is schema-less,
|
|
16
|
+
* so this type is not enforced at runtime, but serves as the type the client expects.
|
|
25
17
|
*
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* name: string;
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
18
|
+
* @remarks
|
|
19
|
+
* - The `key` is a string that uniquely identifies the entry in the KV store.
|
|
20
|
+
* - The `value` is of generic type `V`, allowing flexibility in the type of data stored.
|
|
21
|
+
* - `V` must be serializable to JSON.
|
|
22
|
+
* - The `metadata` can hold any additional information associated with the KV entry.
|
|
34
23
|
*/
|
|
35
|
-
export declare
|
|
36
|
-
|
|
24
|
+
export declare class KValue<V> {
|
|
25
|
+
key: string;
|
|
26
|
+
raw: unknown | null;
|
|
27
|
+
metadata: unknown | null;
|
|
28
|
+
get value(): V | null;
|
|
29
|
+
}
|
|
37
30
|
/**
|
|
38
|
-
*
|
|
31
|
+
* The result of a Workers endpoint.
|
|
39
32
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
33
|
+
* @param ok True if `status` < 400
|
|
34
|
+
* @param status The HTTP Status of a Workers request
|
|
35
|
+
* @param headers All headers that the result is to be sent with or was received with
|
|
36
|
+
* @param data JSON data yielded from a request, undefined if the request was not `ok`.
|
|
37
|
+
* @param message An error text set if the request was not `ok`.
|
|
43
38
|
*
|
|
44
|
-
*
|
|
39
|
+
* @remarks If `status` is 204 `data` will always be undefined.
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
export declare class HttpResult<T = unknown> {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
status: number;
|
|
45
|
+
headers: Headers;
|
|
46
|
+
data?: T | undefined;
|
|
47
|
+
message?: string | undefined;
|
|
48
|
+
mediaType?: MediaType | undefined;
|
|
49
|
+
constructor(ok: boolean, status: number, headers: Headers, data?: T | undefined, message?: string | undefined, mediaType?: MediaType | undefined);
|
|
50
|
+
static ok<T>(status: number, data?: T, init?: HeadersInit): HttpResult<T>;
|
|
51
|
+
static fail(status: number, message?: string, init?: HeadersInit): HttpResult<never>;
|
|
52
|
+
toResponse(): Response;
|
|
53
|
+
setMediaType(mediaType: MediaType): this;
|
|
54
|
+
}
|
|
55
|
+
type DeepPartialInner<T> = T extends (infer U)[] ? DeepPartialInner<U>[] : T extends object ? {
|
|
56
|
+
[K in keyof T]?: DeepPartialInner<T[K]>;
|
|
57
|
+
} : T | (null extends T ? null : never);
|
|
58
|
+
/**
|
|
59
|
+
* Recursively makes all properties of a type optional — including nested objects and arrays.
|
|
60
|
+
*
|
|
61
|
+
* Similar to TypeScript's built-in `Partial<T>`, but applies the transformation deeply across
|
|
62
|
+
* all nested structures. Useful for defining "patch" or "update" objects where only a subset
|
|
63
|
+
* of properties may be provided.
|
|
64
|
+
*
|
|
65
|
+
* **Apart of the Cloesce method grammar**, meaning the type can be apart of method parameters
|
|
66
|
+
* or return types and the generated workers and client API will act accordingly.
|
|
67
|
+
*
|
|
68
|
+
* @template T
|
|
69
|
+
* The target type to make deeply partial.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* - **Objects:** All properties become optional, and their values are recursively wrapped in `DeepPartial`.
|
|
73
|
+
* - **Arrays:** Arrays are preserved, but their elements are recursively made partial.
|
|
74
|
+
* - **Scalars:** Primitive values (string, number, boolean, etc.) remain unchanged.
|
|
75
|
+
* - **Nullable types:** If `null` is assignable to the type, it remains allowed.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
45
78
|
* ```ts
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
79
|
+
* class User {
|
|
80
|
+
* id: string;
|
|
81
|
+
* profile: {
|
|
82
|
+
* name: string;
|
|
83
|
+
* age: number;
|
|
84
|
+
* };
|
|
85
|
+
* tags: string[];
|
|
50
86
|
* }
|
|
51
87
|
*
|
|
52
|
-
* //
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
88
|
+
* // The resulting type:
|
|
89
|
+
* // {
|
|
90
|
+
* // id?: string;
|
|
91
|
+
* // profile?: { name?: string; age?: number };
|
|
92
|
+
* // tags?: (string | undefined)[];
|
|
93
|
+
* // }
|
|
94
|
+
* type PartialUser = DeepPartial<User>;
|
|
95
|
+
*
|
|
96
|
+
* const patch: PartialUser = {
|
|
97
|
+
* profile: { age: 30 } // ok
|
|
98
|
+
* };
|
|
61
99
|
* ```
|
|
62
100
|
*/
|
|
63
|
-
export
|
|
101
|
+
export type DeepPartial<T> = DeepPartialInner<T> & {
|
|
102
|
+
__brand?: "Partial";
|
|
103
|
+
};
|
|
104
|
+
export type KeysOfType<T, U> = {
|
|
105
|
+
[K in keyof T]: T[K] extends U ? (K extends string ? K : never) : never;
|
|
106
|
+
}[keyof T];
|
|
107
|
+
export declare const Model: (_kinds?: CrudKind[]) => ClassDecorator;
|
|
108
|
+
export declare const Service: ClassDecorator;
|
|
64
109
|
/**
|
|
65
110
|
* Declares a Wrangler environment definition.
|
|
66
111
|
*
|
|
@@ -100,6 +145,9 @@ export declare const WranglerEnv: ClassDecorator;
|
|
|
100
145
|
* ```
|
|
101
146
|
*/
|
|
102
147
|
export declare const PrimaryKey: PropertyDecorator;
|
|
148
|
+
export declare const KeyParam: PropertyDecorator;
|
|
149
|
+
export declare const KV: (_keyFormat?: string, _namespaceBinding?: string) => PropertyDecorator;
|
|
150
|
+
export declare const R2: (_keyFormat?: string, _bucketBinding?: string) => PropertyDecorator;
|
|
103
151
|
/**
|
|
104
152
|
* Exposes a class method as an HTTP GET endpoint.
|
|
105
153
|
* The method will appear in both backend and generated client APIs.
|
|
@@ -125,102 +173,8 @@ export declare const PATCH: MethodDecorator;
|
|
|
125
173
|
* The method will appear in both backend and generated client APIs.
|
|
126
174
|
*/
|
|
127
175
|
export declare const DELETE: MethodDecorator;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*
|
|
131
|
-
* Data sources describe SQL left joins related to each
|
|
132
|
-
* models navigation properties.
|
|
133
|
-
*
|
|
134
|
-
* Example:
|
|
135
|
-
* ```ts
|
|
136
|
-
* @D1
|
|
137
|
-
* export class Dog {
|
|
138
|
-
* @PrimaryKey
|
|
139
|
-
* id: number;
|
|
140
|
-
*
|
|
141
|
-
* name: string;
|
|
142
|
-
* }
|
|
143
|
-
*
|
|
144
|
-
* @D1
|
|
145
|
-
* export class Person {
|
|
146
|
-
* @PrimaryKey
|
|
147
|
-
* id: number;
|
|
148
|
-
*
|
|
149
|
-
* @ForeignKey(Dog)
|
|
150
|
-
* dogId: number;
|
|
151
|
-
*
|
|
152
|
-
* @OneToOne("dogId")
|
|
153
|
-
* dog: Dog | undefined;
|
|
154
|
-
*
|
|
155
|
-
* @DataSource
|
|
156
|
-
* static readonly default: IncludeTree<Person> = {
|
|
157
|
-
* dog: {}, // join Dog table when querying Person with `default` data source
|
|
158
|
-
* };
|
|
159
|
-
* }
|
|
160
|
-
*
|
|
161
|
-
* // When queried via the ORM or client API:
|
|
162
|
-
* const orm = Orm.fromD1(env.db);
|
|
163
|
-
* const people = await orm.list(Person, Person.default);
|
|
164
|
-
*
|
|
165
|
-
* // => Person { id: 1, dogId: 2, dog: { id: 2, name: "Fido" } }[]
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
export declare const DataSource: PropertyDecorator;
|
|
169
|
-
/**
|
|
170
|
-
* Declares a one-to-many relationship between models.
|
|
171
|
-
*
|
|
172
|
-
* The argument is the foreign key property name on the
|
|
173
|
-
* related model.
|
|
174
|
-
*
|
|
175
|
-
* Example:
|
|
176
|
-
* ```ts
|
|
177
|
-
* @OneToMany("personId")
|
|
178
|
-
* dogs: Dog[];
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
export declare const OneToMany: (
|
|
182
|
-
_foreignKeyColumn: string,
|
|
183
|
-
) => PropertyDecorator;
|
|
184
|
-
/**
|
|
185
|
-
* Declares a one-to-one relationship between models.
|
|
186
|
-
*
|
|
187
|
-
* The argument is the foreign key property name that links
|
|
188
|
-
* the two tables.
|
|
189
|
-
*
|
|
190
|
-
* Example:
|
|
191
|
-
* ```ts
|
|
192
|
-
* @OneToOne("dogId")
|
|
193
|
-
* dog: Dog | undefined;
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
export declare const OneToOne: (_foreignKeyColumn: string) => PropertyDecorator;
|
|
197
|
-
/**
|
|
198
|
-
* Declares a many-to-many relationship between models.
|
|
199
|
-
*
|
|
200
|
-
* The argument is a unique identifier for the generated
|
|
201
|
-
* junction table used to connect the two entities.
|
|
202
|
-
*
|
|
203
|
-
* Example:
|
|
204
|
-
* ```ts
|
|
205
|
-
* @ManyToMany("StudentsCourses")
|
|
206
|
-
* courses: Course[];
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
export declare const ManyToMany: (_uniqueId: string) => PropertyDecorator;
|
|
210
|
-
/**
|
|
211
|
-
* Declares a foreign key relationship between models.
|
|
212
|
-
* Directly translates to a SQLite foreign key.
|
|
213
|
-
*
|
|
214
|
-
* The argument must reference either a model class or the
|
|
215
|
-
* name of a model class as a string. The property type must
|
|
216
|
-
* match the target model’s primary key type.
|
|
217
|
-
*
|
|
218
|
-
* Example:
|
|
219
|
-
* ```ts
|
|
220
|
-
* @ForeignKey(Dog)
|
|
221
|
-
* dogId: number;
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
176
|
+
export declare function OneToMany<T>(_selector: (model: T) => T[keyof T]): PropertyDecorator;
|
|
177
|
+
export declare function OneToOne<T>(_selector: (model: T) => T[keyof T]): PropertyDecorator;
|
|
224
178
|
export declare const ForeignKey: <T>(_Model: T | string) => PropertyDecorator;
|
|
225
179
|
/**
|
|
226
180
|
* Marks a method parameter for dependency injection.
|
|
@@ -240,35 +194,6 @@ export declare const ForeignKey: <T>(_Model: T | string) => PropertyDecorator;
|
|
|
240
194
|
* ```
|
|
241
195
|
*/
|
|
242
196
|
export declare const Inject: ParameterDecorator;
|
|
243
|
-
/**
|
|
244
|
-
* Enables automatic CRUD method generation for a model.
|
|
245
|
-
*
|
|
246
|
-
* The argument is a list of CRUD operation kinds
|
|
247
|
-
* (e.g. `"SAVE"`, `"GET"`, `"LIST"`) to generate for the model.
|
|
248
|
-
*
|
|
249
|
-
* Cloesce will emit corresponding backend methods and frontend
|
|
250
|
-
* client bindings automatically, removing the need to manually
|
|
251
|
-
* define common API operations.
|
|
252
|
-
*
|
|
253
|
-
* CRUD Operations:
|
|
254
|
-
* - **"SAVE"** — Performs an *upsert* (insert, update, or both) for a model instance.
|
|
255
|
-
* - **"GET"** — Retrieves a single record by its primary key, optionally using a `DataSource`.
|
|
256
|
-
* - **"LIST"** — Retrieves all records for the model, using the specified `DataSource`.
|
|
257
|
-
*
|
|
258
|
-
* The generated methods are static, exposed through both the backend
|
|
259
|
-
* and the frontend client API.
|
|
260
|
-
*
|
|
261
|
-
* Example:
|
|
262
|
-
* ```ts
|
|
263
|
-
* @CRUD(["SAVE", "GET", "LIST"])
|
|
264
|
-
* @D1
|
|
265
|
-
* export class CrudHaver {
|
|
266
|
-
* @PrimaryKey id: number;
|
|
267
|
-
* name: string;
|
|
268
|
-
* }
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
export declare const CRUD: (_kinds: CrudKind[]) => ClassDecorator;
|
|
272
197
|
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
273
198
|
/**
|
|
274
199
|
* A recursive type describing which related models to include
|
|
@@ -296,14 +221,10 @@ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
|
296
221
|
* }
|
|
297
222
|
* ```
|
|
298
223
|
*/
|
|
299
|
-
export type IncludeTree<T> = (T extends Primitive
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
? IncludeTree<NonNullable<U>>
|
|
304
|
-
: IncludeTree<NonNullable<T[K]>>;
|
|
305
|
-
}) & {
|
|
306
|
-
__brand?: "IncludeTree";
|
|
224
|
+
export type IncludeTree<T> = (T extends Primitive ? never : {
|
|
225
|
+
[K in keyof T]?: T[K] extends (infer U)[] ? IncludeTree<NonNullable<U>> : IncludeTree<NonNullable<T[K]>>;
|
|
226
|
+
}) & {
|
|
227
|
+
__brand?: "IncludeTree";
|
|
307
228
|
};
|
|
308
229
|
/**
|
|
309
230
|
* Represents the name of a `@DataSource` available on a model type `T`,
|
|
@@ -330,11 +251,8 @@ export type IncludeTree<T> = (T extends Primitive
|
|
|
330
251
|
* async foo(ds: "default" | "none"): Promise<void> {...}
|
|
331
252
|
* ```
|
|
332
253
|
*/
|
|
333
|
-
export type DataSourceOf<T extends object> = (
|
|
334
|
-
|
|
335
|
-
| "none"
|
|
336
|
-
) & {
|
|
337
|
-
__brand?: "DataSource";
|
|
254
|
+
export type DataSourceOf<T extends object> = (KeysOfType<T, IncludeTree<T>> | "none") & {
|
|
255
|
+
__brand?: "DataSource";
|
|
338
256
|
};
|
|
339
257
|
/**
|
|
340
258
|
* A branded `number` type indicating that the corresponding
|
|
@@ -354,203 +272,6 @@ export type DataSourceOf<T extends object> = (
|
|
|
354
272
|
* ```
|
|
355
273
|
*/
|
|
356
274
|
export type Integer = number & {
|
|
357
|
-
|
|
275
|
+
__brand?: "Integer";
|
|
358
276
|
};
|
|
359
|
-
|
|
360
|
-
* Exposes the ORM primitives Cloesce uses to interact with D1 databases.
|
|
361
|
-
*/
|
|
362
|
-
export declare class Orm {
|
|
363
|
-
private db;
|
|
364
|
-
private constructor();
|
|
365
|
-
/**
|
|
366
|
-
* Creates an instance of an `Orm`
|
|
367
|
-
* @param db The database to use for ORM calls.
|
|
368
|
-
*/
|
|
369
|
-
static fromD1(db: D1Database): Orm;
|
|
370
|
-
/**
|
|
371
|
-
* Maps SQL records to an instantiated Model. The records must be flat
|
|
372
|
-
* (e.g., of the form "id, name, address") or derive from a Cloesce data source view
|
|
373
|
-
* (e.g., of the form "Horse.id, Horse.name, Horse.address")
|
|
374
|
-
*
|
|
375
|
-
* Assumes the data is formatted correctly, throwing an error otherwise.
|
|
376
|
-
*
|
|
377
|
-
* @param ctor The model constructor
|
|
378
|
-
* @param records D1 Result records
|
|
379
|
-
* @param includeTree Include tree to define the relationships to join.
|
|
380
|
-
*/
|
|
381
|
-
static mapSql<T extends object>(
|
|
382
|
-
ctor: new () => T,
|
|
383
|
-
records: Record<string, any>[],
|
|
384
|
-
includeTree?: IncludeTree<T> | null,
|
|
385
|
-
): T[];
|
|
386
|
-
/**
|
|
387
|
-
* Executes an "upsert" query, adding or augmenting a model in the database.
|
|
388
|
-
*
|
|
389
|
-
* If a model's primary key is not defined in `newModel`, the query is assumed to be an insert.
|
|
390
|
-
*
|
|
391
|
-
* If a model's primary key _is_ defined, but some attributes are missing, the query is assumed to be an update.
|
|
392
|
-
*
|
|
393
|
-
* Finally, if the primary key is defined, but all attributes are included, a SQLite upsert will be performed.
|
|
394
|
-
*
|
|
395
|
-
* In any other case, an error string will be returned.
|
|
396
|
-
*
|
|
397
|
-
* ### Inserting a new Model
|
|
398
|
-
* ```ts
|
|
399
|
-
* const model = {name: "julio", lastname: "pumpkin"};
|
|
400
|
-
* const idRes = await orm.upsert(Person, model, null);
|
|
401
|
-
* ```
|
|
402
|
-
*
|
|
403
|
-
* ### Updating an existing model
|
|
404
|
-
* ```ts
|
|
405
|
-
* const model = {id: 1, name: "timothy"};
|
|
406
|
-
* const idRes = await orm.upsert(Person, model, null);
|
|
407
|
-
* // (in db)=> {id: 1, name: "timothy", lastname: "pumpkin"}
|
|
408
|
-
* ```
|
|
409
|
-
*
|
|
410
|
-
* ### Upserting a model
|
|
411
|
-
* ```ts
|
|
412
|
-
* // (assume a Person already exists)
|
|
413
|
-
* const model = {
|
|
414
|
-
* id: 1,
|
|
415
|
-
* lastname: "burger", // updates last name
|
|
416
|
-
* dog: {
|
|
417
|
-
* name: "fido" // insert dog relationship
|
|
418
|
-
* }
|
|
419
|
-
* };
|
|
420
|
-
* const idRes = await orm.upsert(Person, model, null);
|
|
421
|
-
* // (in db)=> Person: {id: 1, dogId: 1 ...} ; Dog: {id: 1, name: "fido"}
|
|
422
|
-
* ```
|
|
423
|
-
*
|
|
424
|
-
* @param ctor A model constructor.
|
|
425
|
-
* @param newModel The new or augmented model.
|
|
426
|
-
* @param includeTree An include tree describing which foreign keys to join.
|
|
427
|
-
* @returns An error string, or the primary key of the inserted model.
|
|
428
|
-
*/
|
|
429
|
-
upsert<T extends object>(
|
|
430
|
-
ctor: new () => T,
|
|
431
|
-
newModel: DeepPartial<T>,
|
|
432
|
-
includeTree?: IncludeTree<T> | null,
|
|
433
|
-
): Promise<Either<string, any>>;
|
|
434
|
-
/**
|
|
435
|
-
* Returns a select query, creating a CTE view for the model using the provided include tree.
|
|
436
|
-
*
|
|
437
|
-
* @param ctor The model constructor.
|
|
438
|
-
* @param includeTree An include tree describing which related models to join.
|
|
439
|
-
* @param from An optional custom `FROM` clause to use instead of the base table.
|
|
440
|
-
* @param tagCte An optional CTE name to tag the query with. Defaults to "Model.view".
|
|
441
|
-
*
|
|
442
|
-
* ### Example:
|
|
443
|
-
* ```ts
|
|
444
|
-
* // Using a data source
|
|
445
|
-
* const query = Orm.listQuery(Person, "default");
|
|
446
|
-
*
|
|
447
|
-
* // Using a custom from statement
|
|
448
|
-
* const query = Orm.listQuery(Person, null, "SELECT * FROM Person WHERE age > 18");
|
|
449
|
-
* ```
|
|
450
|
-
*
|
|
451
|
-
* ### Example SQL output:
|
|
452
|
-
* ```sql
|
|
453
|
-
* WITH Person_view AS (
|
|
454
|
-
* SELECT
|
|
455
|
-
* "Person"."id" AS "id",
|
|
456
|
-
* ...
|
|
457
|
-
* FROM "Person"
|
|
458
|
-
* LEFT JOIN ...
|
|
459
|
-
* )
|
|
460
|
-
* SELECT * FROM Person_view
|
|
461
|
-
* ```
|
|
462
|
-
*/
|
|
463
|
-
static listQuery<T extends object>(
|
|
464
|
-
ctor: new () => T,
|
|
465
|
-
opts: {
|
|
466
|
-
includeTree?: IncludeTree<T> | null;
|
|
467
|
-
from?: string;
|
|
468
|
-
tagCte?: string;
|
|
469
|
-
},
|
|
470
|
-
): string;
|
|
471
|
-
/**
|
|
472
|
-
* Returns a select query for a single model by primary key, creating a CTE view using the provided include tree.
|
|
473
|
-
*
|
|
474
|
-
* @param ctor The model constructor.
|
|
475
|
-
* @param includeTree An include tree describing which related models to join.
|
|
476
|
-
*
|
|
477
|
-
* ### Example:
|
|
478
|
-
* ```ts
|
|
479
|
-
* // Using a data source
|
|
480
|
-
* const query = Orm.getQuery(Person, "default");
|
|
481
|
-
* ```
|
|
482
|
-
*
|
|
483
|
-
* ### Example SQL output:
|
|
484
|
-
*
|
|
485
|
-
* ```sql
|
|
486
|
-
* WITH Person_view AS (
|
|
487
|
-
* SELECT
|
|
488
|
-
* "Person"."id" AS "id",
|
|
489
|
-
* ...
|
|
490
|
-
* FROM "Person"
|
|
491
|
-
* LEFT JOIN ...
|
|
492
|
-
* )
|
|
493
|
-
* SELECT * FROM Person_view WHERE [Person].[id] = ?
|
|
494
|
-
* ```
|
|
495
|
-
*/
|
|
496
|
-
static getQuery<T extends object>(
|
|
497
|
-
ctor: new () => T,
|
|
498
|
-
includeTree?: IncludeTree<T> | null,
|
|
499
|
-
): string;
|
|
500
|
-
/**
|
|
501
|
-
* Retrieves all instances of a model from the database.
|
|
502
|
-
* @param ctor The model constructor.
|
|
503
|
-
* @param includeTree An include tree describing which related models to join.
|
|
504
|
-
* @param from An optional custom `FROM` clause to use instead of the base table.
|
|
505
|
-
* @returns Either an error string, or an array of model instances.
|
|
506
|
-
*
|
|
507
|
-
* ### Example:
|
|
508
|
-
* ```ts
|
|
509
|
-
* const orm = Orm.fromD1(env.db);
|
|
510
|
-
* const horses = await orm.list(Horse, Horse.default);
|
|
511
|
-
* ```
|
|
512
|
-
*
|
|
513
|
-
* ### Example with custom from:
|
|
514
|
-
* ```ts
|
|
515
|
-
* const orm = Orm.fromD1(env.db);
|
|
516
|
-
* const adultHorses = await orm.list(Horse, Horse.default, "SELECT * FROM Horse ORDER BY age DESC LIMIT 10");
|
|
517
|
-
* ```
|
|
518
|
-
*
|
|
519
|
-
* =>
|
|
520
|
-
*
|
|
521
|
-
* ```sql
|
|
522
|
-
* SELECT
|
|
523
|
-
* "Horse"."id" AS "id",
|
|
524
|
-
* ...
|
|
525
|
-
* FROM (SELECT * FROM Horse ORDER BY age DESC LIMIT 10)
|
|
526
|
-
* LEFT JOIN ...
|
|
527
|
-
* ```
|
|
528
|
-
*
|
|
529
|
-
*/
|
|
530
|
-
list<T extends object>(
|
|
531
|
-
ctor: new () => T,
|
|
532
|
-
opts: {
|
|
533
|
-
includeTree?: IncludeTree<T> | null;
|
|
534
|
-
from?: string;
|
|
535
|
-
},
|
|
536
|
-
): Promise<Either<string, T[]>>;
|
|
537
|
-
/**
|
|
538
|
-
* Retrieves a single model by primary key.
|
|
539
|
-
* @param ctor The model constructor.
|
|
540
|
-
* @param id The primary key value.
|
|
541
|
-
* @param includeTree An include tree describing which related models to join.
|
|
542
|
-
* @returns Either an error string, or the model instance (null if not found).
|
|
543
|
-
*
|
|
544
|
-
* ### Example:
|
|
545
|
-
* ```ts
|
|
546
|
-
* const orm = Orm.fromD1(env.db);
|
|
547
|
-
* const horse = await orm.get(Horse, 1, Horse.default);
|
|
548
|
-
* ```
|
|
549
|
-
*/
|
|
550
|
-
get<T extends object>(
|
|
551
|
-
ctor: new () => T,
|
|
552
|
-
id: any,
|
|
553
|
-
includeTree?: IncludeTree<T> | null,
|
|
554
|
-
): Promise<Either<string, T | null>>;
|
|
555
|
-
}
|
|
556
|
-
//# sourceMappingURL=backend.d.ts.map
|
|
277
|
+
//# sourceMappingURL=backend.d.ts.map
|
package/dist/ui/backend.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/ui/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../../src/ui/backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGhD;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACtE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B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