cloesce 0.0.4-unstable.9 → 0.0.5-unstable.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.
@@ -0,0 +1,32 @@
1
+ export declare enum ExtractorErrorCode {
2
+ MissingExport = 0,
3
+ AppMissingDefaultExport = 1,
4
+ UnknownType = 2,
5
+ MultipleGenericType = 3,
6
+ InvalidDataSourceDefinition = 4,
7
+ InvalidPartialType = 5,
8
+ InvalidIncludeTree = 6,
9
+ InvalidAttributeModifier = 7,
10
+ InvalidApiMethodModifier = 8,
11
+ UnknownNavigationPropertyReference = 9,
12
+ InvalidNavigationPropertyReference = 10,
13
+ MissingNavigationPropertyReference = 11,
14
+ MissingManyToManyUniqueId = 12,
15
+ MissingPrimaryKey = 13,
16
+ MissingDatabaseBinding = 14,
17
+ TooManyWranglerEnvs = 15,
18
+ MissingFile = 16,
19
+ InvalidServiceAttribute = 17,
20
+ }
21
+ export declare function getErrorInfo(code: ExtractorErrorCode): {
22
+ description: string;
23
+ suggestion: string;
24
+ };
25
+ export declare class ExtractorError {
26
+ code: ExtractorErrorCode;
27
+ context?: string;
28
+ snippet?: string;
29
+ constructor(code: ExtractorErrorCode);
30
+ addContext(fn: (val: string | undefined) => string | undefined): void;
31
+ }
32
+ //# sourceMappingURL=err.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../src/extractor/err.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,yBAAyB,KAAA;IACzB,iBAAiB,KAAA;IACjB,sBAAsB,KAAA;IACtB,mBAAmB,KAAA;IACnB,WAAW,KAAA;IACX,uBAAuB,KAAA;CACxB;AA0FD,wBAAgB,YAAY,CAAC,IAAI,EAAE,kBAAkB;iBAtFpC,MAAM;gBAAc,MAAM;EAwF1C;AAED,qBAAa,cAAc;IAIN,IAAI,EAAE,kBAAkB;IAH3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;gBAEE,IAAI,EAAE,kBAAkB;IAE3C,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,GAAG,SAAS;CAG/D"}
@@ -0,0 +1,138 @@
1
+ export var ExtractorErrorCode;
2
+ (function (ExtractorErrorCode) {
3
+ ExtractorErrorCode[(ExtractorErrorCode["MissingExport"] = 0)] =
4
+ "MissingExport";
5
+ ExtractorErrorCode[(ExtractorErrorCode["AppMissingDefaultExport"] = 1)] =
6
+ "AppMissingDefaultExport";
7
+ ExtractorErrorCode[(ExtractorErrorCode["UnknownType"] = 2)] = "UnknownType";
8
+ ExtractorErrorCode[(ExtractorErrorCode["MultipleGenericType"] = 3)] =
9
+ "MultipleGenericType";
10
+ ExtractorErrorCode[(ExtractorErrorCode["InvalidDataSourceDefinition"] = 4)] =
11
+ "InvalidDataSourceDefinition";
12
+ ExtractorErrorCode[(ExtractorErrorCode["InvalidPartialType"] = 5)] =
13
+ "InvalidPartialType";
14
+ ExtractorErrorCode[(ExtractorErrorCode["InvalidIncludeTree"] = 6)] =
15
+ "InvalidIncludeTree";
16
+ ExtractorErrorCode[(ExtractorErrorCode["InvalidAttributeModifier"] = 7)] =
17
+ "InvalidAttributeModifier";
18
+ ExtractorErrorCode[(ExtractorErrorCode["InvalidApiMethodModifier"] = 8)] =
19
+ "InvalidApiMethodModifier";
20
+ ExtractorErrorCode[
21
+ (ExtractorErrorCode["UnknownNavigationPropertyReference"] = 9)
22
+ ] = "UnknownNavigationPropertyReference";
23
+ ExtractorErrorCode[
24
+ (ExtractorErrorCode["InvalidNavigationPropertyReference"] = 10)
25
+ ] = "InvalidNavigationPropertyReference";
26
+ ExtractorErrorCode[
27
+ (ExtractorErrorCode["MissingNavigationPropertyReference"] = 11)
28
+ ] = "MissingNavigationPropertyReference";
29
+ ExtractorErrorCode[(ExtractorErrorCode["MissingManyToManyUniqueId"] = 12)] =
30
+ "MissingManyToManyUniqueId";
31
+ ExtractorErrorCode[(ExtractorErrorCode["MissingPrimaryKey"] = 13)] =
32
+ "MissingPrimaryKey";
33
+ ExtractorErrorCode[(ExtractorErrorCode["MissingDatabaseBinding"] = 14)] =
34
+ "MissingDatabaseBinding";
35
+ ExtractorErrorCode[(ExtractorErrorCode["TooManyWranglerEnvs"] = 15)] =
36
+ "TooManyWranglerEnvs";
37
+ ExtractorErrorCode[(ExtractorErrorCode["MissingFile"] = 16)] = "MissingFile";
38
+ ExtractorErrorCode[(ExtractorErrorCode["InvalidServiceAttribute"] = 17)] =
39
+ "InvalidServiceAttribute";
40
+ })(ExtractorErrorCode || (ExtractorErrorCode = {}));
41
+ const errorInfoMap = {
42
+ [ExtractorErrorCode.MissingExport]: {
43
+ description: "All Cloesce types must be exported.",
44
+ suggestion: "Add `export` to the class definition.",
45
+ },
46
+ [ExtractorErrorCode.AppMissingDefaultExport]: {
47
+ description: "app.cloesce.ts does not export a CloesceApp by default",
48
+ suggestion: "Export an instantiated CloesceApp in app.cloesce.ts",
49
+ },
50
+ [ExtractorErrorCode.UnknownType]: {
51
+ description: "Encountered an unknown or unsupported type",
52
+ suggestion: "Refer to the documentation on valid Cloesce TS types",
53
+ },
54
+ [ExtractorErrorCode.InvalidPartialType]: {
55
+ description: "Partial types must only contain a model or plain old object",
56
+ suggestion: "Refer to the documentation on valid Cloesce TS types",
57
+ },
58
+ [ExtractorErrorCode.MultipleGenericType]: {
59
+ description: "Cloesce does not yet support types with multiple generics",
60
+ suggestion:
61
+ "Simplify your type to use only a single generic parameter, ie Foo<T>",
62
+ },
63
+ [ExtractorErrorCode.InvalidDataSourceDefinition]: {
64
+ description:
65
+ "Data Sources must be explicitly typed as a static Include Tree",
66
+ suggestion:
67
+ "Declare your data source as `static readonly _: IncludeTree<Model>`",
68
+ },
69
+ [ExtractorErrorCode.InvalidIncludeTree]: {
70
+ description: "Invalid Include Tree",
71
+ suggestion:
72
+ "Include trees must only contain references to a model's navigation properties.",
73
+ },
74
+ [ExtractorErrorCode.InvalidAttributeModifier]: {
75
+ description:
76
+ "Attributes can only be public on a Model, Plain Old Object or Wrangler Environment",
77
+ suggestion: "Change the attribute modifier to just `public`",
78
+ },
79
+ [ExtractorErrorCode.InvalidApiMethodModifier]: {
80
+ description:
81
+ "Model methods must be public if they are decorated as GET, POST, PUT, PATCH",
82
+ suggestion: "Change the method modifier to just `public`",
83
+ },
84
+ [ExtractorErrorCode.UnknownNavigationPropertyReference]: {
85
+ description: "Unknown Navigation Property Reference",
86
+ suggestion:
87
+ "Verify that the navigation property reference model exists, or create a model.",
88
+ },
89
+ [ExtractorErrorCode.InvalidNavigationPropertyReference]: {
90
+ description: "Invalid Navigation Property Reference",
91
+ suggestion: "Ensure the navigation property points to a valid model field",
92
+ },
93
+ [ExtractorErrorCode.MissingNavigationPropertyReference]: {
94
+ description: "Missing Navigation Property Reference",
95
+ suggestion:
96
+ "Navigation properties require a foreign key model attribute reference",
97
+ },
98
+ [ExtractorErrorCode.MissingManyToManyUniqueId]: {
99
+ description: "Missing unique id on Many to Many navigation property",
100
+ suggestion:
101
+ "Define a unique identifier field for the Many-to-Many relationship",
102
+ },
103
+ [ExtractorErrorCode.MissingPrimaryKey]: {
104
+ description: "Missing primary key on a model",
105
+ suggestion: "Add a primary key field to your model (e.g., `id: number`)",
106
+ },
107
+ [ExtractorErrorCode.MissingDatabaseBinding]: {
108
+ description: "Missing a database binding in the WranglerEnv definition",
109
+ suggestion: "Add a `D1Database` to your WranglerEnv",
110
+ },
111
+ [ExtractorErrorCode.TooManyWranglerEnvs]: {
112
+ description: "Too many wrangler environments defined in the project",
113
+ suggestion: "Consolidate or remove unused @WranglerEnv's",
114
+ },
115
+ [ExtractorErrorCode.MissingFile]: {
116
+ description: "A specified input file could not be found",
117
+ suggestion: "Verify the input file path is correct",
118
+ },
119
+ [ExtractorErrorCode.InvalidServiceAttribute]: {
120
+ description:
121
+ "Services must contain only dependency injected instances as attributes.",
122
+ suggestion: "Remove the attribute.",
123
+ },
124
+ };
125
+ export function getErrorInfo(code) {
126
+ return errorInfoMap[code];
127
+ }
128
+ export class ExtractorError {
129
+ code;
130
+ context;
131
+ snippet;
132
+ constructor(code) {
133
+ this.code = code;
134
+ }
135
+ addContext(fn) {
136
+ this.context = fn(this.context ?? "");
137
+ }
138
+ }
@@ -1,17 +1,64 @@
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";
1
+ import {
2
+ Project,
3
+ Type,
4
+ SourceFile,
5
+ MethodDeclaration,
6
+ ClassDeclaration,
7
+ Expression,
8
+ } from "ts-morph";
9
+ import {
10
+ CidlIncludeTree,
11
+ CloesceAst,
12
+ CidlType,
13
+ HttpVerb,
14
+ Model,
15
+ ApiMethod,
16
+ WranglerEnv,
17
+ PlainOldObject,
18
+ Service,
19
+ } from "../ast.js";
20
+ import { ExtractorError } from "./err.js";
21
+ import { Either } from "../ui/common.js";
3
22
  export declare class CidlExtractor {
4
- projectName: string;
5
- version: string;
6
- constructor(projectName: string, version: string);
7
- extract(project: Project): Either<ExtractorError, CloesceAst>;
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>;
12
- private static readonly primTypeMap;
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>;
23
+ projectName: string;
24
+ version: string;
25
+ constructor(projectName: string, version: string);
26
+ extract(project: Project): Either<ExtractorError, CloesceAst>;
27
+ static app(sourceFile: SourceFile): Either<ExtractorError, string>;
28
+ static model(
29
+ classDecl: ClassDeclaration,
30
+ sourceFile: SourceFile,
31
+ ): Either<ExtractorError, Model>;
32
+ static modelMethod(
33
+ modelName: string,
34
+ method: MethodDeclaration,
35
+ verb: HttpVerb,
36
+ ): Either<ExtractorError, ApiMethod>;
37
+ static service(
38
+ classDecl: ClassDeclaration,
39
+ sourceFile: SourceFile,
40
+ ): Either<ExtractorError, Service>;
41
+ static serviceMethod(
42
+ method: MethodDeclaration,
43
+ verb: HttpVerb,
44
+ ): Either<ExtractorError, ApiMethod>;
45
+ static poo(
46
+ classDecl: ClassDeclaration,
47
+ sourceFile: SourceFile,
48
+ ): Either<ExtractorError, PlainOldObject>;
49
+ static env(
50
+ classDecl: ClassDeclaration,
51
+ sourceFile: SourceFile,
52
+ ): Either<ExtractorError, WranglerEnv>;
53
+ private static readonly primTypeMap;
54
+ static cidlType(
55
+ type: Type,
56
+ inject?: boolean,
57
+ ): Either<ExtractorError, CidlType>;
58
+ static includeTree(
59
+ expr: Expression | undefined,
60
+ currentClass: ClassDeclaration,
61
+ sf: SourceFile,
62
+ ): Either<ExtractorError, CidlIncludeTree>;
16
63
  }
17
- //# sourceMappingURL=extract.d.ts.map
64
+ //# 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,EACP,IAAI,EACJ,UAAU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