@solid-stack/mason 1.0.27 → 1.0.30

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.
Files changed (36) hide show
  1. package/dist/bin.cjs +36 -0
  2. package/dist/bin.cjs.map +1 -1
  3. package/dist/bin.js +36 -0
  4. package/dist/bin.js.map +1 -1
  5. package/dist/core/lintEngine.d.ts.map +1 -1
  6. package/dist/index.cjs +36 -0
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.js +36 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/templates/domain/class.hbs +5 -5
  11. package/dist/templates/domain/interface.hbs +1 -1
  12. package/dist/templates/domain/valueObject.hbs +11 -11
  13. package/dist/templates/httpHandler/handler.hbs +34 -34
  14. package/dist/templates/infra/concrete.hbs +8 -8
  15. package/dist/templates/infra/stub.hbs +76 -76
  16. package/dist/templates/injectable/injectable.hbs +11 -11
  17. package/dist/templates/injectable/interface.hbs +1 -1
  18. package/dist/templates/interface/interface.hbs +7 -7
  19. package/dist/templates/provider/provider.hbs +1 -1
  20. package/dist/templates/useCase/useCase.hbs +13 -13
  21. package/dist/templates/useCase/useCaseTest.hbs +10 -10
  22. package/dist/types/lint.d.ts +1 -1
  23. package/dist/types/lint.d.ts.map +1 -1
  24. package/package.json +6 -2
  25. package/templates/domain/class.hbs +5 -5
  26. package/templates/domain/interface.hbs +1 -1
  27. package/templates/domain/valueObject.hbs +11 -11
  28. package/templates/httpHandler/handler.hbs +34 -34
  29. package/templates/infra/concrete.hbs +8 -8
  30. package/templates/infra/stub.hbs +76 -76
  31. package/templates/injectable/injectable.hbs +11 -11
  32. package/templates/injectable/interface.hbs +1 -1
  33. package/templates/interface/interface.hbs +7 -7
  34. package/templates/provider/provider.hbs +1 -1
  35. package/templates/useCase/useCase.hbs +13 -13
  36. package/templates/useCase/useCaseTest.hbs +10 -10
@@ -11,61 +11,61 @@ import { {{ucName}} } from "../../useCases/{{ucName}}.js";
11
11
  export type HttpResponseStatus = "info" | "success" | "redirect" | "fail" | "error";
12
12
 
13
13
  export interface HttpResponse<T = object> {
14
- status: HttpResponseStatus;
15
- message: string;
16
- data?: T;
14
+ status: HttpResponseStatus;
15
+ message: string;
16
+ data?: T;
17
17
  }
18
18
 
19
19
  {{#if includeValidation}}
20
20
  const {{schemaName}} = z.object({
21
21
  {{#if hasValidationFields}}
22
22
  {{#each validationFields}}
23
- {{name}}: {{{zodType}}},
23
+ {{name}}: {{{zodType}}},
24
24
  {{/each}}
25
25
  {{else}}
26
- // TODO: define schema properties
27
- example: z.string().optional(),
26
+ // TODO: define schema properties
27
+ example: z.string().optional(),
28
28
  {{/if}}
29
29
  });
30
30
 
31
31
  {{/if}}
32
32
  @MakeInjectable
33
33
  export default class {{className}} extends ExpressRoute {
34
- public static deps = {
34
+ public static deps = {
35
35
  {{#if ucName}}
36
- {{ucDepKey}}: {{ucName}},
36
+ {{ucDepKey}}: {{ucName}},
37
37
  {{/if}}
38
- };
38
+ };
39
39
 
40
- constructor(public deps: DepsType<typeof {{className}}.deps>) {
41
- super();
42
- }
40
+ constructor(public deps: DepsType<typeof {{className}}.deps>) {
41
+ super();
42
+ }
43
43
 
44
- public method = "{{method}}" as const;
45
- public path = "{{routeSubPath}}";
46
- public handler = async (req: Request, res: Response) => {
44
+ public method = "{{method}}" as const;
45
+ public path = "{{routeSubPath}}";
46
+ public handler = async (req: Request, res: Response) => {
47
47
  {{#if includeValidation}}
48
- const parsed = {{schemaName}}.safeParse(req.{{validationSource}});
49
- if (!parsed.success) {
50
- return res.status(400).json({
51
- status: "error",
52
- message: "Validation failed",
53
- data: parsed.error.format(),
54
- });
55
- }
48
+ const parsed = {{schemaName}}.safeParse(req.{{validationSource}});
49
+ if (!parsed.success) {
50
+ return res.status(400).json({
51
+ status: "error",
52
+ message: "Validation failed",
53
+ data: parsed.error.format(),
54
+ });
55
+ }
56
56
  {{/if}}
57
57
  {{#if ucName}}
58
- const result = await this.deps.{{ucDepKey}}.execute({{callArg}});
59
- return res.status({{statusCode}}).json({
60
- status: "success",
61
- message: "{{successMessage}}",
62
- data: result,
63
- });
58
+ const result = await this.deps.{{ucDepKey}}.execute({{callArg}});
59
+ return res.status({{statusCode}}).json({
60
+ status: "success",
61
+ message: "{{successMessage}}",
62
+ data: result,
63
+ });
64
64
  {{else}}
65
- return res.status(200).json({
66
- status: "success",
67
- message: "{{successMessage}}",
68
- });
65
+ return res.status(200).json({
66
+ status: "success",
67
+ message: "{{successMessage}}",
68
+ });
69
69
  {{/if}}
70
- };
70
+ };
71
71
  }
@@ -8,22 +8,22 @@ import {{#if isTypeOnly}}type {{/if}}{ {{names}} } from "{{from}}";
8
8
 
9
9
  @MakeInjectable
10
10
  export class {{className}}{{#if ifaceName}} implements {{ifaceName}}{{/if}} {
11
- public static deps = {
11
+ public static deps = {
12
12
  {{#each dependencies}}
13
- {{key}}: {{name}},
13
+ {{key}}: {{name}},
14
14
  {{/each}}
15
- };
15
+ };
16
16
 
17
- constructor(public deps: DepsType<typeof {{className}}.deps>) {}
17
+ constructor(public deps: DepsType<typeof {{className}}.deps>) {}
18
18
  {{#if hasMethods}}
19
19
  {{#each methods}}
20
20
 
21
- {{#if isAsync}}async {{/if}}{{name}}{{{typeParams}}}({{{params}}}): {{{returnType}}} {
22
- throw new Error("not implemented");
23
- }
21
+ {{#if isAsync}}async {{/if}}{{name}}{{{typeParams}}}({{{params}}}): {{{returnType}}} {
22
+ throw new Error("not implemented");
23
+ }
24
24
  {{/each}}
25
25
  {{else}}
26
26
 
27
- // Implement your infrastructure methods here
27
+ // Implement your infrastructure methods here
28
28
  {{/if}}
29
29
  }
@@ -9,95 +9,95 @@ import {{#if isTypeOnly}}type {{/if}}{ {{names}} } from "{{from}}";
9
9
 
10
10
  @MakeInjectable
11
11
  export class {{stubClassName}} implements {{ifaceName}} {
12
- public static deps = {};
12
+ public static deps = {};
13
13
  {{#if baseEntity}}
14
14
 
15
- private {{entitiesVar}}: Map<string, {{baseEntity}}> = new Map();
16
- private errorToThrow: Error | null = null;
17
-
18
- constructor(public deps: DepsType<typeof {{stubClassName}}.deps>) {}
19
-
20
- // --- Test Helpers ---
21
- public clear(): void {
22
- this.{{entitiesVar}}.clear();
23
- this.errorToThrow = null;
24
- }
25
-
26
- public add{{baseEntity}}({{entityVar}}: {{baseEntity}}): void {
27
- this.{{entitiesVar}}.set({{entityVar}}.id, { ...{{entityVar}} });
28
- }
29
-
30
- public get{{baseEntity}}s(): {{baseEntity}}[] {
31
- return Array.from(this.{{entitiesVar}}.values()).map((e) => ({ ...e }));
32
- }
33
-
34
- public setError(error: Error | null): void {
35
- this.errorToThrow = error;
36
- }
37
-
38
- // --- {{ifaceName}} Methods ---
39
- async Get{{baseEntity}}ById(input: { {{idKey}}: string }): Promise<{ {{entityVar}}: {{baseEntity}} }> {
40
- if (this.errorToThrow) throw this.errorToThrow;
41
- const found = this.{{entitiesVar}}.get(input.{{idKey}});
42
- if (!found) throw new Error("{{baseEntity}} with ID " + input.{{idKey}} + " not found");
43
- return { {{entityVar}}: { ...found } };
44
- }
45
-
46
- async List{{baseEntity}}s(input?: { page?: number | undefined; limit?: number | undefined }): Promise<{ {{entitiesVar}}: {{baseEntity}}[]; total?: number | undefined; page?: number | undefined; limit?: number | undefined }> {
47
- if (this.errorToThrow) throw this.errorToThrow;
48
- let all = this.get{{baseEntity}}s();
49
- const total = all.length;
50
- if (input?.page && input?.limit) {
51
- const start = (input.page - 1) * input.limit;
52
- all = all.slice(start, start + input.limit);
53
- return { {{entitiesVar}}: all, total, page: input.page, limit: input.limit };
54
- }
55
- return { {{entitiesVar}}: all, total };
56
- }
57
-
58
- async Create{{baseEntity}}(input: { {{entityVar}}: {{baseEntity}} }): Promise<{ {{entityVar}}: {{baseEntity}} }> {
59
- if (this.errorToThrow) throw this.errorToThrow;
60
- const entity = { ...input.{{entityVar}} };
61
- this.{{entitiesVar}}.set(entity.id, entity);
62
- return { {{entityVar}}: { ...entity } };
63
- }
64
-
65
- async Update{{baseEntity}}(input: { {{entityVar}}: {{baseEntity}} }): Promise<{ {{entityVar}}: {{baseEntity}} }> {
66
- if (this.errorToThrow) throw this.errorToThrow;
67
- if (!this.{{entitiesVar}}.has(input.{{entityVar}}.id)) {
68
- throw new Error("{{baseEntity}} with ID " + input.{{entityVar}}.id + " not found");
69
- }
70
- const entity = { ...input.{{entityVar}} };
71
- this.{{entitiesVar}}.set(entity.id, entity);
72
- return { {{entityVar}}: { ...entity } };
73
- }
74
-
75
- async Delete{{baseEntity}}(input: { {{idKey}}: string }): Promise<{ success: boolean }> {
76
- if (this.errorToThrow) throw this.errorToThrow;
77
- this.{{entitiesVar}}.delete(input.{{idKey}});
78
- return { success: true };
79
- }
15
+ private {{entitiesVar}}: Map<string, {{baseEntity}}> = new Map();
16
+ private errorToThrow: Error | null = null;
17
+
18
+ constructor(public deps: DepsType<typeof {{stubClassName}}.deps>) {}
19
+
20
+ // --- Test Helpers ---
21
+ public clear(): void {
22
+ this.{{entitiesVar}}.clear();
23
+ this.errorToThrow = null;
24
+ }
25
+
26
+ public add{{baseEntity}}({{entityVar}}: {{baseEntity}}): void {
27
+ this.{{entitiesVar}}.set({{entityVar}}.id, { ...{{entityVar}} });
28
+ }
29
+
30
+ public get{{baseEntity}}s(): {{baseEntity}}[] {
31
+ return Array.from(this.{{entitiesVar}}.values()).map((e) => ({ ...e }));
32
+ }
33
+
34
+ public setError(error: Error | null): void {
35
+ this.errorToThrow = error;
36
+ }
37
+
38
+ // --- {{ifaceName}} Methods ---
39
+ async Get{{baseEntity}}ById(input: { {{idKey}}: string }): Promise<{ {{entityVar}}: {{baseEntity}} }> {
40
+ if (this.errorToThrow) throw this.errorToThrow;
41
+ const found = this.{{entitiesVar}}.get(input.{{idKey}});
42
+ if (!found) throw new Error("{{baseEntity}} with ID " + input.{{idKey}} + " not found");
43
+ return { {{entityVar}}: { ...found } };
44
+ }
45
+
46
+ async List{{baseEntity}}s(input?: { page?: number | undefined; limit?: number | undefined }): Promise<{ {{entitiesVar}}: {{baseEntity}}[]; total?: number | undefined; page?: number | undefined; limit?: number | undefined }> {
47
+ if (this.errorToThrow) throw this.errorToThrow;
48
+ let all = this.get{{baseEntity}}s();
49
+ const total = all.length;
50
+ if (input?.page && input?.limit) {
51
+ const start = (input.page - 1) * input.limit;
52
+ all = all.slice(start, start + input.limit);
53
+ return { {{entitiesVar}}: all, total, page: input.page, limit: input.limit };
54
+ }
55
+ return { {{entitiesVar}}: all, total };
56
+ }
57
+
58
+ async Create{{baseEntity}}(input: { {{entityVar}}: {{baseEntity}} }): Promise<{ {{entityVar}}: {{baseEntity}} }> {
59
+ if (this.errorToThrow) throw this.errorToThrow;
60
+ const entity = { ...input.{{entityVar}} };
61
+ this.{{entitiesVar}}.set(entity.id, entity);
62
+ return { {{entityVar}}: { ...entity } };
63
+ }
64
+
65
+ async Update{{baseEntity}}(input: { {{entityVar}}: {{baseEntity}} }): Promise<{ {{entityVar}}: {{baseEntity}} }> {
66
+ if (this.errorToThrow) throw this.errorToThrow;
67
+ if (!this.{{entitiesVar}}.has(input.{{entityVar}}.id)) {
68
+ throw new Error("{{baseEntity}} with ID " + input.{{entityVar}}.id + " not found");
69
+ }
70
+ const entity = { ...input.{{entityVar}} };
71
+ this.{{entitiesVar}}.set(entity.id, entity);
72
+ return { {{entityVar}}: { ...entity } };
73
+ }
74
+
75
+ async Delete{{baseEntity}}(input: { {{idKey}}: string }): Promise<{ success: boolean }> {
76
+ if (this.errorToThrow) throw this.errorToThrow;
77
+ this.{{entitiesVar}}.delete(input.{{idKey}});
78
+ return { success: true };
79
+ }
80
80
  {{#each extraMethods}}
81
81
 
82
- {{#if isAsync}}async {{/if}}{{name}}{{{typeParams}}}({{{params}}}): {{{returnType}}} {
83
- throw new Error("not implemented");
84
- }
82
+ {{#if isAsync}}async {{/if}}{{name}}{{{typeParams}}}({{{params}}}): {{{returnType}}} {
83
+ throw new Error("not implemented");
84
+ }
85
85
  {{/each}}
86
86
  {{else}}
87
87
 
88
- constructor(public deps: DepsType<typeof {{stubClassName}}.deps>) {}
88
+ constructor(public deps: DepsType<typeof {{stubClassName}}.deps>) {}
89
89
  {{#if hasMethods}}
90
90
  {{#each methods}}
91
91
 
92
- {{#if isAsync}}async {{/if}}{{name}}{{{typeParams}}}({{{params}}}): {{{returnType}}} {
93
- throw new Error("not implemented");
94
- }
92
+ {{#if isAsync}}async {{/if}}{{name}}{{{typeParams}}}({{{params}}}): {{{returnType}}} {
93
+ throw new Error("not implemented");
94
+ }
95
95
  {{/each}}
96
96
  {{else}}
97
97
 
98
- async execute(input?: unknown): Promise<unknown> {
99
- throw new Error("{{stubClassName}}.execute not implemented");
100
- }
98
+ async execute(input?: unknown): Promise<unknown> {
99
+ throw new Error("{{stubClassName}}.execute not implemented");
100
+ }
101
101
  {{/if}}
102
102
  {{/if}}
103
103
  }
@@ -5,28 +5,28 @@ import { {{implementsInterface}} } from "./{{implementsInterface}}.js";
5
5
 
6
6
  @MakeInjectable
7
7
  export class {{className}}{{#if implementsInterface}} implements {{implementsInterface}}{{/if}} {
8
- public static deps = {
8
+ public static deps = {
9
9
  {{#each dependencies}}
10
- {{key}}: {{name}},
10
+ {{key}}: {{name}},
11
11
  {{/each}}
12
- };
12
+ };
13
13
 
14
14
  {{#if hasDependencies}}
15
- constructor(public deps: DepsType<typeof {{className}}.deps>) {}
15
+ constructor(public deps: DepsType<typeof {{className}}.deps>) {}
16
16
  {{else}}
17
- constructor() {}
17
+ constructor() {}
18
18
  {{/if}}
19
19
 
20
20
  {{#if hasMethods}}
21
21
  {{#each methods}}
22
- public {{#if isAsync}}async {{/if}}{{name}}({{{params}}}): {{{returnType}}} {
23
- // TODO: implement method logic
24
- }
22
+ public {{#if isAsync}}async {{/if}}{{name}}({{{params}}}): {{{returnType}}} {
23
+ // TODO: implement method logic
24
+ }
25
25
 
26
26
  {{/each}}
27
27
  {{else}}
28
- public execute(): void {
29
- // TODO: implement logic
30
- }
28
+ public execute(): void {
29
+ // TODO: implement logic
30
+ }
31
31
  {{/if}}
32
32
  }
@@ -1,3 +1,3 @@
1
1
  export abstract class {{ifaceName}} {
2
- abstract execute(): void;
2
+ abstract execute(): void;
3
3
  }
@@ -4,16 +4,16 @@ import type { {{domainImport}} } from "./{{domainImport}}.js";
4
4
  {{/if}}
5
5
  export {{#if isAbstractClass}}abstract class{{else}}interface{{/if}} {{ifaceName}} {
6
6
  {{#if isCrud}}
7
- {{methodPrefix}}Get{{baseEntity}}ById(input: { {{idKey}}: string }): Promise<{ {{entityKey}}: {{baseEntity}} }>;
8
- {{methodPrefix}}List{{baseEntity}}s(input?: { page?: number | undefined; limit?: number | undefined }): Promise<{ {{listKey}}: {{baseEntity}}[]; total?: number | undefined; page?: number | undefined; limit?: number | undefined }>;
9
- {{methodPrefix}}Create{{baseEntity}}(input: { {{entityKey}}: {{baseEntity}} }): Promise<{ {{entityKey}}: {{baseEntity}} }>;
10
- {{methodPrefix}}Update{{baseEntity}}(input: { {{entityKey}}: {{baseEntity}} }): Promise<{ {{entityKey}}: {{baseEntity}} }>;
11
- {{methodPrefix}}Delete{{baseEntity}}(input: { {{idKey}}: string }): Promise<{ success: boolean }>;
7
+ {{methodPrefix}}Get{{baseEntity}}ById(input: { {{idKey}}: string }): Promise<{ {{entityKey}}: {{baseEntity}} }>;
8
+ {{methodPrefix}}List{{baseEntity}}s(input?: { page?: number | undefined; limit?: number | undefined }): Promise<{ {{listKey}}: {{baseEntity}}[]; total?: number | undefined; page?: number | undefined; limit?: number | undefined }>;
9
+ {{methodPrefix}}Create{{baseEntity}}(input: { {{entityKey}}: {{baseEntity}} }): Promise<{ {{entityKey}}: {{baseEntity}} }>;
10
+ {{methodPrefix}}Update{{baseEntity}}(input: { {{entityKey}}: {{baseEntity}} }): Promise<{ {{entityKey}}: {{baseEntity}} }>;
11
+ {{methodPrefix}}Delete{{baseEntity}}(input: { {{idKey}}: string }): Promise<{ success: boolean }>;
12
12
  {{else if isCustom}}
13
13
  {{#each customMethods}}
14
- {{../methodPrefix}}{{name}}({{#if params}}input: { {{params}} }{{/if}}): {{returnType}};
14
+ {{../methodPrefix}}{{name}}({{#if params}}input: { {{params}} }{{/if}}): {{returnType}};
15
15
  {{/each}}
16
16
  {{else}}
17
- {{methodPrefix}}execute(input?: unknown): Promise<unknown>;
17
+ {{methodPrefix}}execute(input?: unknown): Promise<unknown>;
18
18
  {{/if}}
19
19
  }
@@ -6,7 +6,7 @@ import { {{implName}} } from "{{implImportPath}}";
6
6
 
7
7
  export const {{providerModuleName}}: DIModule = (c: Container) => {
8
8
  {{#each bindings}}
9
- c.provide({{ifaceName}}, {{implName}});
9
+ c.provide({{ifaceName}}, {{implName}});
10
10
  {{/each}}
11
11
  };
12
12
 
@@ -9,7 +9,7 @@ import type { {{this}} } from "../domain/{{this}}.js";
9
9
  {{#if hasInputProps}}
10
10
  export type {{inputTypeName}} = {
11
11
  {{#each inputProperties}}
12
- {{name}}{{#if optional}}?{{/if}}: {{type}};
12
+ {{name}}{{#if optional}}?{{/if}}: {{type}};
13
13
  {{/each}}
14
14
  };
15
15
  {{else}}
@@ -19,39 +19,39 @@ export type {{inputTypeName}} = Record<string, never>;
19
19
  {{#if hasOutputProps}}
20
20
  export type {{outputTypeName}} = {
21
21
  {{#each outputProperties}}
22
- {{name}}{{#if optional}}?{{/if}}: {{type}};
22
+ {{name}}{{#if optional}}?{{/if}}: {{type}};
23
23
  {{/each}}
24
24
  };
25
25
  {{else}}
26
26
  export type {{outputTypeName}} = {
27
- success: boolean;
27
+ success: boolean;
28
28
  };
29
29
  {{/if}}
30
30
 
31
31
  @MakeInjectable
32
32
  export class {{ucName}} {
33
- public static deps = {
33
+ public static deps = {
34
34
  {{#each dependencies}}
35
- {{key}}: {{name}},
35
+ {{key}}: {{name}},
36
36
  {{/each}}
37
- };
37
+ };
38
38
 
39
39
  {{#if hasDependencies}}
40
- constructor(public deps: DepsType<typeof {{ucName}}.deps>) {}
40
+ constructor(public deps: DepsType<typeof {{ucName}}.deps>) {}
41
41
  {{else}}
42
- constructor() {}
42
+ constructor() {}
43
43
  {{/if}}
44
44
 
45
- async execute({{paramStr}}): Promise<{{outputTypeName}}> {
45
+ async execute({{paramStr}}): Promise<{{outputTypeName}}> {
46
46
  {{#if callWired}}
47
47
  {{{callWired}}}
48
48
  {{else}}
49
- // TODO: Implement use case business logic
49
+ // TODO: Implement use case business logic
50
50
  {{#if hasOutputProps}}
51
- throw new Error("{{ucName}} not implemented");
51
+ throw new Error("{{ucName}} not implemented");
52
52
  {{else}}
53
- return { success: true };
53
+ return { success: true };
54
54
  {{/if}}
55
55
  {{/if}}
56
- }
56
+ }
57
57
  }
@@ -7,18 +7,18 @@ import { {{stub}} } from "../infrastructure/{{stub}}.js";
7
7
  {{/each}}
8
8
 
9
9
  describe("{{ucName}} Use Case", () => {
10
- let container: Container;
11
- let useCase: {{ucName}};
10
+ let container: Container;
11
+ let useCase: {{ucName}};
12
12
 
13
- beforeEach(() => {
14
- container = new Container();
13
+ beforeEach(() => {
14
+ container = new Container();
15
15
  {{#each stubBindings}}
16
- container.provide({{iface}}, {{stub}});
16
+ container.provide({{iface}}, {{stub}});
17
17
  {{/each}}
18
- useCase = container.resolve({{ucName}});
19
- });
18
+ useCase = container.resolve({{ucName}});
19
+ });
20
20
 
21
- it("should be successfully resolved from DI container", () => {
22
- expect(useCase).toBeDefined();
23
- });
21
+ it("should be successfully resolved from DI container", () => {
22
+ expect(useCase).toBeDefined();
23
+ });
24
24
  });