cloesce 0.0.3-fix.6 → 0.0.4-unstable.0

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.
@@ -1,112 +0,0 @@
1
- import { HttpResult, Either, ModelMethod, CloesceAst, Model } from "../common.js";
2
- import { IncludeTree } from "../index/backend.js";
3
- /**
4
- * Map of model names to their respective constructor.
5
- *
6
- * The value accepted into the `cloesce` function is generated by the Cloesce compiler, and
7
- * is guaranteed to contain all model definitions.
8
- */
9
- type ModelConstructorRegistry = Record<string, new () => UserDefinedModel>;
10
- /**
11
- * Dependency injection container, mapping an object type name to an instance of that object.
12
- *
13
- * The value accepted into the `cloesce` function is generated by the Cloesce compiler, and is
14
- * guaranteed to contain all injected model method parameters.
15
- */
16
- type InstanceRegistry = Map<string, any>;
17
- /**
18
- * Users will create Cloesce models, which have metadata for them in the ast.
19
- * For TypeScript's purposes, these models can be anything. We can assume any
20
- * `UserDefinedModel` has been verified by the compiler.
21
- */
22
- type UserDefinedModel = any;
23
- /**
24
- * Given a request, this represents a map of each body / url param name to
25
- * its actual value. Unknown, as the a request can be anything.
26
- */
27
- type RequestParamMap = Record<string, unknown>;
28
- /**
29
- * Meta information on the wrangler env and db bindings
30
- */
31
- interface MetaWranglerEnv {
32
- envName: string;
33
- dbName: string;
34
- }
35
- /**
36
- * WASM ABI
37
- */
38
- interface RuntimeWasmExports {
39
- memory: WebAssembly.Memory;
40
- get_return_len(): number;
41
- set_meta_ptr(ptr: number, len: number): number;
42
- alloc(len: number): number;
43
- dealloc(ptr: number, len: number): void;
44
- object_relational_mapping(model_name_ptr: number, model_name_len: number, sql_rows_ptr: number, sql_rows_len: number, include_tree_ptr: number, include_tree_len: number): number;
45
- }
46
- /**
47
- * Singleton instances of the cidl, constructor registry, and wasm binary.
48
- * These values are guaranteed to never change throughout a program lifetime.
49
- */
50
- declare class RuntimeContainer {
51
- readonly ast: CloesceAst;
52
- readonly constructorRegistry: ModelConstructorRegistry;
53
- readonly wasm: RuntimeWasmExports;
54
- private static instance;
55
- private constructor();
56
- static init(ast: CloesceAst, constructorRegistry: ModelConstructorRegistry, wasm?: WebAssembly.Instance): Promise<void>;
57
- static get(): RuntimeContainer;
58
- }
59
- /**
60
- * Runtime entry point. Given a request, undergoes: routing, validating,
61
- * hydrating, and method dispatch.
62
- *
63
- * @returns A Response with an `HttpResult` JSON body.
64
- */
65
- export declare function cloesce(request: Request, ast: CloesceAst, constructorRegistry: ModelConstructorRegistry, instanceRegistry: InstanceRegistry, envMeta: MetaWranglerEnv, api_route: string): Promise<Response>;
66
- /**
67
- * Matches a request to a method on a model.
68
- * @param api_route The route from the domain to the actual API, ie https://foo.com/route/to/api => route/to/api/
69
- * @returns 404 or a `MatchedRoute`
70
- */
71
- declare function matchRoute(request: Request, ast: CloesceAst, api_route: string): Either<HttpResult, {
72
- model: Model;
73
- method: ModelMethod;
74
- id: string | null;
75
- }>;
76
- /**
77
- * Validates the request's body/search params against a ModelMethod
78
- * @returns 400 or a `RequestParamMap` consisting of each parameters name mapped to its value, and
79
- * a data source
80
- */
81
- declare function validateRequest(request: Request, ast: CloesceAst, model: Model, method: ModelMethod, id: string | null): Promise<Either<HttpResult, {
82
- params: RequestParamMap;
83
- dataSource: string | null;
84
- }>>;
85
- /**
86
- * Calls a method on a model given a list of parameters.
87
- * @returns 500 on an uncaught client error, 200 with a result body on success
88
- */
89
- declare function methodDispatch(instance: object, instanceRegistry: InstanceRegistry, envMeta: MetaWranglerEnv, method: ModelMethod, params: Record<string, unknown>): Promise<HttpResult<unknown>>;
90
- /**
91
- * Creates model instances given a properly formatted SQL record, being either:
92
- *
93
- * 1. Flat, relationship-less (ex: id, name, location, ...)
94
- * 2. `DataSource` formatted (ex: Horse.id, Horse.name, Horse.rider, ...)
95
- *
96
- * @param ctor The type of the model
97
- * @param records SQL records
98
- * @param includeTree The include tree to use when parsing the records
99
- * @returns An instantiated array of `T`, containing one or more objects.
100
- */
101
- export declare function modelsFromSql<T extends object>(ctor: new () => T, records: Record<string, any>[], includeTree: IncludeTree<T> | null): T[];
102
- /**
103
- * For testing purposes
104
- */
105
- export declare const _cloesceInternal: {
106
- matchRoute: typeof matchRoute;
107
- validateRequest: typeof validateRequest;
108
- methodDispatch: typeof methodDispatch;
109
- RuntimeContainer: typeof RuntimeContainer;
110
- };
111
- export {};
112
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,MAAM,EACN,WAAW,EAIX,UAAU,EAEV,KAAK,EAGN,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKlD;;;;;GAKG;AACH,KAAK,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,gBAAgB,CAAC,CAAC;AAE3E;;;;;GAKG;AACH,KAAK,gBAAgB,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEzC;;;;GAIG;AACH,KAAK,gBAAgB,GAAG,GAAG,CAAC;AAE5B;;;GAGG;AACH,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C;;GAEG;AACH,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,UAAU,kBAAkB;IAC1B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;IAC3B,cAAc,IAAI,MAAM,CAAC;IACzB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,yBAAyB,CACvB,cAAc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