cloesce 0.0.3-fix.1
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/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +352 -0
- package/dist/cli.wasm +0 -0
- package/dist/cloesce.d.ts +108 -0
- package/dist/cloesce.d.ts.map +1 -0
- package/dist/cloesce.js +453 -0
- package/dist/common.d.ts +96 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +96 -0
- package/dist/decorators.d.ts +13 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +13 -0
- package/dist/dog.cloesce.js +111 -0
- package/dist/extract.d.ts +14 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +517 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +60 -0
package/dist/common.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export function left(value) {
|
|
2
|
+
return { ok: false, value };
|
|
3
|
+
}
|
|
4
|
+
export function right(value) {
|
|
5
|
+
return { ok: true, value };
|
|
6
|
+
}
|
|
7
|
+
export var ExtractorErrorCode;
|
|
8
|
+
(function (ExtractorErrorCode) {
|
|
9
|
+
ExtractorErrorCode[ExtractorErrorCode["UnknownType"] = 0] = "UnknownType";
|
|
10
|
+
ExtractorErrorCode[ExtractorErrorCode["MultipleGenericType"] = 1] = "MultipleGenericType";
|
|
11
|
+
ExtractorErrorCode[ExtractorErrorCode["InvalidIncludeTree"] = 2] = "InvalidIncludeTree";
|
|
12
|
+
ExtractorErrorCode[ExtractorErrorCode["UnknownNavigationPropertyReference"] = 3] = "UnknownNavigationPropertyReference";
|
|
13
|
+
ExtractorErrorCode[ExtractorErrorCode["InvalidNavigationPropertyReference"] = 4] = "InvalidNavigationPropertyReference";
|
|
14
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingNavigationPropertyReference"] = 5] = "MissingNavigationPropertyReference";
|
|
15
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingManyToManyUniqueId"] = 6] = "MissingManyToManyUniqueId";
|
|
16
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingPrimaryKey"] = 7] = "MissingPrimaryKey";
|
|
17
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingWranglerEnv"] = 8] = "MissingWranglerEnv";
|
|
18
|
+
ExtractorErrorCode[ExtractorErrorCode["TooManyWranglerEnvs"] = 9] = "TooManyWranglerEnvs";
|
|
19
|
+
ExtractorErrorCode[ExtractorErrorCode["MissingFile"] = 10] = "MissingFile";
|
|
20
|
+
})(ExtractorErrorCode || (ExtractorErrorCode = {}));
|
|
21
|
+
const errorInfoMap = {
|
|
22
|
+
[ExtractorErrorCode.UnknownType]: {
|
|
23
|
+
description: "Encountered an unknown or unsupported type",
|
|
24
|
+
suggestion: "Refer to the documentation on valid Cloesce TS types",
|
|
25
|
+
},
|
|
26
|
+
[ExtractorErrorCode.MultipleGenericType]: {
|
|
27
|
+
description: "Cloesce does not yet support types with multiple generics",
|
|
28
|
+
suggestion: "Simplify your type to use only a single generic parameter, ie Foo<T>",
|
|
29
|
+
},
|
|
30
|
+
[ExtractorErrorCode.InvalidIncludeTree]: {
|
|
31
|
+
description: "Invalid Include Tree",
|
|
32
|
+
suggestion: "Include trees must only contain references to a model's navigation properties.",
|
|
33
|
+
},
|
|
34
|
+
[ExtractorErrorCode.UnknownNavigationPropertyReference]: {
|
|
35
|
+
description: "Unknown Navigation Property Reference",
|
|
36
|
+
suggestion: "Verify that the navigation property reference model exists, or create a model.",
|
|
37
|
+
},
|
|
38
|
+
[ExtractorErrorCode.InvalidNavigationPropertyReference]: {
|
|
39
|
+
description: "Invalid Navigation Property Reference",
|
|
40
|
+
suggestion: "Ensure the navigation property points to a valid model field",
|
|
41
|
+
},
|
|
42
|
+
[ExtractorErrorCode.MissingNavigationPropertyReference]: {
|
|
43
|
+
description: "Missing Navigation Property Reference",
|
|
44
|
+
suggestion: "Navigation properties require a foreign key model attribute reference",
|
|
45
|
+
},
|
|
46
|
+
[ExtractorErrorCode.MissingManyToManyUniqueId]: {
|
|
47
|
+
description: "Missing unique id on Many to Many navigation property",
|
|
48
|
+
suggestion: "Define a unique identifier field for the Many-to-Many relationship",
|
|
49
|
+
},
|
|
50
|
+
[ExtractorErrorCode.MissingPrimaryKey]: {
|
|
51
|
+
description: "Missing primary key on a model",
|
|
52
|
+
suggestion: "Add a primary key field to your model (e.g., `id: number`)",
|
|
53
|
+
},
|
|
54
|
+
[ExtractorErrorCode.MissingWranglerEnv]: {
|
|
55
|
+
description: "Missing a wrangler environment definition in the project",
|
|
56
|
+
suggestion: "Add a @WranglerEnv class in your project.",
|
|
57
|
+
},
|
|
58
|
+
[ExtractorErrorCode.TooManyWranglerEnvs]: {
|
|
59
|
+
description: "Too many wrangler environments defined in the project",
|
|
60
|
+
suggestion: "Consolidate or remove unused @WranglerEnv's",
|
|
61
|
+
},
|
|
62
|
+
[ExtractorErrorCode.MissingFile]: {
|
|
63
|
+
description: "A specified input file could not be found",
|
|
64
|
+
suggestion: "Verify the input file path is correct",
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export function getErrorInfo(code) {
|
|
68
|
+
return errorInfoMap[code];
|
|
69
|
+
}
|
|
70
|
+
export class ExtractorError {
|
|
71
|
+
code;
|
|
72
|
+
context;
|
|
73
|
+
snippet;
|
|
74
|
+
constructor(code) {
|
|
75
|
+
this.code = code;
|
|
76
|
+
}
|
|
77
|
+
addContext(fn) {
|
|
78
|
+
this.context = fn(this.context ?? "");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function isNullableType(ty) {
|
|
82
|
+
return typeof ty === "object" && ty !== null && "Nullable" in ty;
|
|
83
|
+
}
|
|
84
|
+
export var HttpVerb;
|
|
85
|
+
(function (HttpVerb) {
|
|
86
|
+
HttpVerb["GET"] = "GET";
|
|
87
|
+
HttpVerb["POST"] = "POST";
|
|
88
|
+
HttpVerb["PUT"] = "PUT";
|
|
89
|
+
HttpVerb["PATCH"] = "PATCH";
|
|
90
|
+
HttpVerb["DELETE"] = "DELETE";
|
|
91
|
+
})(HttpVerb || (HttpVerb = {}));
|
|
92
|
+
export function getNavigationPropertyCidlType(nav) {
|
|
93
|
+
return "OneToOne" in nav.kind
|
|
94
|
+
? { Object: nav.model_name }
|
|
95
|
+
: { Array: { Object: nav.model_name } };
|
|
96
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Handler } from "./types.js";
|
|
2
|
+
/** Use as @GET (no parentheses) */
|
|
3
|
+
export declare function GET(_value: Handler, _ctx: ClassMethodDecoratorContext): void;
|
|
4
|
+
/** Use as @POST (no parentheses) */
|
|
5
|
+
export declare function POST(_value: Handler, _ctx: ClassMethodDecoratorContext): void;
|
|
6
|
+
export declare function PUT(_value: Handler, _ctx: ClassMethodDecoratorContext): void;
|
|
7
|
+
export declare function PATCH(_value: Handler, _ctx: ClassMethodDecoratorContext): void;
|
|
8
|
+
export declare function DELETE(_value: Handler, _ctx: ClassMethodDecoratorContext): void;
|
|
9
|
+
/** Class decorator (no-op) */
|
|
10
|
+
export declare function D1<T extends new (...a: any[]) => object>(value: T, _ctx: ClassDecoratorContext<T>): T;
|
|
11
|
+
/** Field decorator (no-op) */
|
|
12
|
+
export declare function PrimaryKey(_v: undefined, _ctx: ClassFieldDecoratorContext): void;
|
|
13
|
+
//# sourceMappingURL=decorators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,mCAAmC;AACnC,wBAAgB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,QAAI;AAE1E,oCAAoC;AACpC,wBAAgB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,QAAI;AAE3E,wBAAgB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,QAAI;AAE1E,wBAAgB,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,QAAI;AAE5E,wBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,QAAI;AAE7E,8BAA8B;AAC9B,wBAAgB,EAAE,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,MAAM,EACtD,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAG/B;AAED,8BAA8B;AAC9B,wBAAgB,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,0BAA0B,QAAI"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Use as @GET (no parentheses) */
|
|
2
|
+
export function GET(_value, _ctx) { }
|
|
3
|
+
/** Use as @POST (no parentheses) */
|
|
4
|
+
export function POST(_value, _ctx) { }
|
|
5
|
+
export function PUT(_value, _ctx) { }
|
|
6
|
+
export function PATCH(_value, _ctx) { }
|
|
7
|
+
export function DELETE(_value, _ctx) { }
|
|
8
|
+
/** Class decorator (no-op) */
|
|
9
|
+
export function D1(value, _ctx) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
/** Field decorator (no-op) */
|
|
13
|
+
export function PrimaryKey(_v, _ctx) { }
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import { WranglerEnv } from './cloesce.js'; // adjust import path
|
|
36
|
+
let MyEnvironment = (() => {
|
|
37
|
+
let _classDecorators = [WranglerEnv({
|
|
38
|
+
name: "my-worker",
|
|
39
|
+
compatibility_date: "2024-01-01"
|
|
40
|
+
})];
|
|
41
|
+
let _classDescriptor;
|
|
42
|
+
let _classExtraInitializers = [];
|
|
43
|
+
let _classThis;
|
|
44
|
+
var MyEnvironment = class {
|
|
45
|
+
static { _classThis = this; }
|
|
46
|
+
static {
|
|
47
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
48
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
49
|
+
MyEnvironment = _classThis = _classDescriptor.value;
|
|
50
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
51
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return MyEnvironment = _classThis;
|
|
55
|
+
})();
|
|
56
|
+
let Dog = (() => {
|
|
57
|
+
let _classDecorators = [D1];
|
|
58
|
+
let _classDescriptor;
|
|
59
|
+
let _classExtraInitializers = [];
|
|
60
|
+
let _classThis;
|
|
61
|
+
let _staticExtraInitializers = [];
|
|
62
|
+
let _instanceExtraInitializers = [];
|
|
63
|
+
let _static_woof_decorators;
|
|
64
|
+
let _id_decorators;
|
|
65
|
+
let _id_initializers = [];
|
|
66
|
+
let _id_extraInitializers = [];
|
|
67
|
+
let _get_name_decorators;
|
|
68
|
+
let _get_breed_decorators;
|
|
69
|
+
var Dog = class {
|
|
70
|
+
static { _classThis = this; }
|
|
71
|
+
static {
|
|
72
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
73
|
+
_id_decorators = [PrimaryKey];
|
|
74
|
+
_get_name_decorators = [GET];
|
|
75
|
+
_get_breed_decorators = [GET];
|
|
76
|
+
_static_woof_decorators = [POST];
|
|
77
|
+
__esDecorate(this, null, _static_woof_decorators, { kind: "method", name: "woof", static: true, private: false, access: { has: obj => "woof" in obj, get: obj => obj.woof }, metadata: _metadata }, null, _staticExtraInitializers);
|
|
78
|
+
__esDecorate(this, null, _get_name_decorators, { kind: "method", name: "get_name", static: false, private: false, access: { has: obj => "get_name" in obj, get: obj => obj.get_name }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
79
|
+
__esDecorate(this, null, _get_breed_decorators, { kind: "method", name: "get_breed", static: false, private: false, access: { has: obj => "get_breed" in obj, get: obj => obj.get_breed }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
80
|
+
__esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
|
|
81
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
82
|
+
Dog = _classThis = _classDescriptor.value;
|
|
83
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
84
|
+
__runInitializers(_classThis, _staticExtraInitializers);
|
|
85
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
86
|
+
}
|
|
87
|
+
id = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _id_initializers, void 0));
|
|
88
|
+
name = __runInitializers(this, _id_extraInitializers);
|
|
89
|
+
breed;
|
|
90
|
+
preferred_treat;
|
|
91
|
+
async get_name(db, req) {
|
|
92
|
+
const who = new URL(req.url).searchParams.get("name");
|
|
93
|
+
return new Response(JSON.stringify({ hello: who }), {
|
|
94
|
+
headers: { "content-type": "application/json" },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async get_breed(db, req) {
|
|
98
|
+
const breed = new URL(req.url).searchParams.get("breed");
|
|
99
|
+
return new Response(JSON.stringify({ hello: breed }), {
|
|
100
|
+
headers: { "content-type": "application/json" },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static async woof(db, req, phrase) {
|
|
104
|
+
return new Response(JSON.stringify({ phrase }), {
|
|
105
|
+
status: 201,
|
|
106
|
+
headers: { "content-type": "application/json" },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return Dog = _classThis;
|
|
111
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import { CloesceAst, Either } from "./common.js";
|
|
3
|
+
export declare class CidlExtractor {
|
|
4
|
+
projectName: string;
|
|
5
|
+
version: string;
|
|
6
|
+
constructor(projectName: string, version: string);
|
|
7
|
+
extract(project: Project): Either<string, CloesceAst>;
|
|
8
|
+
private static model;
|
|
9
|
+
private static readonly primTypeMap;
|
|
10
|
+
private static cidlType;
|
|
11
|
+
private static includeTree;
|
|
12
|
+
private static method;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EASR,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,UAAU,EAGV,MAAM,EAUP,MAAM,aAAa,CAAC;AAqBrB,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,MAAM,EAAE,UAAU,CAAC;IA8CrD,OAAO,CAAC,MAAM,CAAC,KAAK;IA+KpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAQjC;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ;IAgGvB,OAAO,CAAC,MAAM,CAAC,WAAW;IA8D1B,OAAO,CAAC,MAAM,CAAC,MAAM;CAqDtB"}
|