@akanjs/cli 0.9.56 → 0.9.57
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/cjs/index.js +25 -34
- package/cjs/src/guidelines/databaseModule/databaseModule.instruction.md +7 -1
- package/cjs/src/guidelines/modelSignal/modelSignal.instruction.md +3 -3
- package/cjs/src/guidelines/modelTemplate/modelTemplate.instruction.md +5 -5
- package/cjs/src/guidelines/sharedUiUsage/sharedUiUsage.generate.json +0 -7
- package/cjs/src/guidelines/sharedUiUsage/sharedUiUsage.instruction.md +7 -7
- package/cjs/src/templates/app/lib/option.js +6 -1
- package/cjs/src/templates/app/main.js +2 -2
- package/cjs/src/templates/lib/__lib/lib.dictionary.js +1 -2
- package/cjs/src/templates/lib/dict.js +22 -6
- package/cjs/src/templates/lib/sig.js +5 -2
- package/cjs/src/templates/lib/useClient.js +5 -4
- package/cjs/src/templates/libRoot/lib/option.js +5 -1
- package/cjs/src/templates/module/__Model__.Template.js +2 -2
- package/cjs/src/templates/module/__Model__.Util.js +8 -1
- package/cjs/src/templates/module/__model__.constant.js +3 -8
- package/cjs/src/templates/module/__model__.dictionary.js +21 -59
- package/cjs/src/templates/module/__model__.document.js +1 -1
- package/cjs/src/templates/module/__model__.signal.js +5 -4
- package/cjs/src/templates/server.js +11 -3
- package/esm/index.js +25 -34
- package/esm/src/guidelines/databaseModule/databaseModule.instruction.md +7 -1
- package/esm/src/guidelines/modelSignal/modelSignal.instruction.md +3 -3
- package/esm/src/guidelines/modelTemplate/modelTemplate.instruction.md +5 -5
- package/esm/src/guidelines/sharedUiUsage/sharedUiUsage.generate.json +0 -7
- package/esm/src/guidelines/sharedUiUsage/sharedUiUsage.instruction.md +7 -7
- package/esm/src/templates/app/lib/option.js +6 -1
- package/esm/src/templates/app/main.js +2 -2
- package/esm/src/templates/lib/__lib/lib.dictionary.js +1 -2
- package/esm/src/templates/lib/dict.js +22 -6
- package/esm/src/templates/lib/sig.js +5 -2
- package/esm/src/templates/lib/useClient.js +5 -4
- package/esm/src/templates/libRoot/lib/option.js +5 -1
- package/esm/src/templates/module/__Model__.Template.js +2 -2
- package/esm/src/templates/module/__Model__.Util.js +8 -1
- package/esm/src/templates/module/__model__.constant.js +3 -8
- package/esm/src/templates/module/__model__.dictionary.js +21 -59
- package/esm/src/templates/module/__model__.document.js +1 -1
- package/esm/src/templates/module/__model__.signal.js +5 -4
- package/esm/src/templates/server.js +11 -3
- package/package.json +1 -1
- package/src/guidelines/databaseModule/databaseModule.instruction.md +7 -1
- package/src/guidelines/modelSignal/modelSignal.instruction.md +3 -3
- package/src/guidelines/modelTemplate/modelTemplate.instruction.md +5 -5
- package/src/guidelines/sharedUiUsage/sharedUiUsage.instruction.md +7 -7
- package/src/module/module.command.d.ts +1 -1
- package/src/module/module.runner.d.ts +1 -1
- package/src/module/module.script.d.ts +1 -1
- package/src/scalar/scalar.command.d.ts +1 -1
- package/src/scalar/scalar.script.d.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// pkgs/@akanjs/cli/src/templates/module/__model__.document.ts
|
|
2
2
|
function getContent(scanInfo, dict) {
|
|
3
3
|
return `
|
|
4
|
-
import { beyond, by, into, type SchemaOf } from "@akanjs/document";
|
|
4
|
+
import { beyond, by, from, into, type SchemaOf } from "@akanjs/document";
|
|
5
5
|
|
|
6
6
|
import * as cnst from "../cnst";
|
|
7
7
|
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// pkgs/@akanjs/cli/src/templates/module/__model__.signal.ts
|
|
2
2
|
function getContent(scanInfo, dict) {
|
|
3
3
|
return `
|
|
4
|
+
import { Public } from "@akanjs/nest";
|
|
4
5
|
import { endpoint, internal, slice } from "@akanjs/signal";
|
|
6
|
+
import { Admin } from "@shared/nest";
|
|
5
7
|
|
|
6
8
|
import * as cnst from "../cnst";
|
|
7
9
|
import * as srv from "../srv";
|
|
8
10
|
|
|
9
11
|
export class ${dict.Model}Internal extends internal(srv.${dict.model}, () => ({})) {}
|
|
10
12
|
|
|
11
|
-
export class ${dict.Model}Slice extends slice(srv.${dict.model}, { guards: { get:
|
|
13
|
+
export class ${dict.Model}Slice extends slice(srv.${dict.model}, { guards: { root: Admin, get: Public, cru: Public } }, (init) => ({
|
|
12
14
|
inPublic: init()
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
return this.${dict.model}Service.queryByStatuses(statuses);
|
|
15
|
+
.exec(function () {
|
|
16
|
+
return this.${dict.model}Service.queryAny();
|
|
16
17
|
}),
|
|
17
18
|
})) {}
|
|
18
19
|
|
|
@@ -8,15 +8,15 @@ function getContent(scanInfo, dict = {}) {
|
|
|
8
8
|
const serviceModules = [...scanInfo.service.entries()].filter(([_, files]) => files.has("service"));
|
|
9
9
|
const scalarModules = [...scanInfo.scalar.entries()];
|
|
10
10
|
return `
|
|
11
|
-
import { databaseModuleOf, scalarModulesOf, serviceModuleOf, type Module } from "@akanjs/server";
|
|
12
|
-
${libs.map((lib) => `import { registerModules as register${capitalize(lib)}Modules } from "@${lib}/server";`).join("\n")}
|
|
11
|
+
import { databaseModuleOf, scalarModulesOf, serviceModuleOf, type Module, type Middleware } from "@akanjs/server";
|
|
12
|
+
${libs.map((lib) => `import { registerModules as register${capitalize(lib)}Modules, registerMiddlewares as register${capitalize(lib)}Middlewares } from "@${lib}/server";`).join("\n")}
|
|
13
13
|
|
|
14
14
|
import * as cnst from "./lib/cnst";
|
|
15
15
|
import * as db from "./lib/db";
|
|
16
16
|
import * as srv from "./lib/srv";
|
|
17
17
|
import { allSrvs } from "./lib/srv";
|
|
18
18
|
import * as sig from "./lib/sig";
|
|
19
|
-
import { type ModulesOptions, registerGlobalModule } from "./lib/option";
|
|
19
|
+
import { type ModulesOptions, registerGlobalModule, registerGlobalMiddlewares } from "./lib/option";
|
|
20
20
|
|
|
21
21
|
// database modules
|
|
22
22
|
${databaseModules.map(([model]) => {
|
|
@@ -44,6 +44,14 @@ ${databaseModules.map(([model]) => ` register${capitalize(model)}Module(),`).
|
|
|
44
44
|
return modules;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
export const registerMiddlewares = (options: ModulesOptions, isChild?: boolean) => {
|
|
48
|
+
const middlewares = [
|
|
49
|
+
${libs.map((lib) => ` ...(!isChild ? register${capitalize(lib)}Middlewares(options, true) : []),`).join("\n")}
|
|
50
|
+
...registerGlobalMiddlewares(options),
|
|
51
|
+
] as Middleware[];
|
|
52
|
+
return middlewares;
|
|
53
|
+
};
|
|
54
|
+
|
|
47
55
|
export { env } from "./env/env.server.testing";
|
|
48
56
|
export * as db from "./lib/db";
|
|
49
57
|
export * as srv from "./lib/srv";
|
package/package.json
CHANGED
|
@@ -207,7 +207,7 @@ import * as cnst from "../cnst";
|
|
|
207
207
|
import type * as db from "../db";
|
|
208
208
|
|
|
209
209
|
export class UserSignal extends DbSignal(cnst.userCnst, cnst.Srvs, {
|
|
210
|
-
guards: { get: Query.Public, cru: Mutation.Admin },
|
|
210
|
+
guards: { root: Admin, get: Query.Public, cru: Mutation.Admin },
|
|
211
211
|
}) {
|
|
212
212
|
@Mutation.Public(() => cnst.util.AccessToken)
|
|
213
213
|
async signin(
|
|
@@ -578,30 +578,36 @@ export const Layout = () => (
|
|
|
578
578
|
## Best Practices
|
|
579
579
|
|
|
580
580
|
1. **Naming Conventions**
|
|
581
|
+
|
|
581
582
|
- Use PascalCase for classes and components (e.g., `UserService`, `User.Unit.tsx`)
|
|
582
583
|
- Use camelCase for files (e.g., `user.service.ts`, `user.document.ts`)
|
|
583
584
|
|
|
584
585
|
2. **Security**
|
|
586
|
+
|
|
585
587
|
- Use `@Field.Secret` for sensitive data like passwords
|
|
586
588
|
- Apply proper permission guards to queries and mutations (`@Query.Admin`, `@Mutation.Public`)
|
|
587
589
|
- Validate input data using the `validate` option in `@Field.Prop`
|
|
588
590
|
|
|
589
591
|
3. **Code Organization**
|
|
592
|
+
|
|
590
593
|
- Keep business logic in service files
|
|
591
594
|
- Use signals for API calls only, not for business logic
|
|
592
595
|
- Define reusable utility methods in document models
|
|
593
596
|
|
|
594
597
|
4. **Performance**
|
|
598
|
+
|
|
595
599
|
- Use dataloader pattern (`@Loader.ByField`) for efficient database access
|
|
596
600
|
- Create proper indexes in the middleware
|
|
597
601
|
- Use projections to limit returned fields when appropriate
|
|
598
602
|
|
|
599
603
|
5. **Testing**
|
|
604
|
+
|
|
600
605
|
- Create signal tests for each API endpoint
|
|
601
606
|
- Mock services for unit testing signals
|
|
602
607
|
- Use integration tests for testing complex workflows
|
|
603
608
|
|
|
604
609
|
6. **UI Components**
|
|
610
|
+
|
|
605
611
|
- Follow the separation between Template, Unit, View, and Zone components
|
|
606
612
|
- Make components reusable across different parts of the application
|
|
607
613
|
- Use dictionary files for all UI text to support internationalization
|
|
@@ -27,7 +27,7 @@ import * as cnst from "../cnst";
|
|
|
27
27
|
import type * as db from "../db";
|
|
28
28
|
|
|
29
29
|
export class ModelNameSignal extends DbSignal(cnst.modelNameCnst, cnst.Srvs, {
|
|
30
|
-
guards: { get: Query.Public, cru: Mutation.User },
|
|
30
|
+
guards: { root: Admin, get: Query.Public, cru: Mutation.User },
|
|
31
31
|
}) {
|
|
32
32
|
// Signal methods here...
|
|
33
33
|
}
|
|
@@ -259,7 +259,7 @@ DbSignal creates standard operations that you don't need to implement:
|
|
|
259
259
|
|
|
260
260
|
```typescript
|
|
261
261
|
export class BoardSignal extends DbSignal(cnst.boardCnst, cnst.Srvs, {
|
|
262
|
-
guards: { get: Query.Public, cru: Mutation.Admin },
|
|
262
|
+
guards: { root: Admin, get: Query.Public, cru: Mutation.Admin },
|
|
263
263
|
}) {
|
|
264
264
|
// Custom methods beyond CRUD go here
|
|
265
265
|
}
|
|
@@ -378,7 +378,7 @@ async getProjectDetails(
|
|
|
378
378
|
|
|
379
379
|
```typescript
|
|
380
380
|
export class ProductSignal extends DbSignal(cnst.productCnst, cnst.Srvs, {
|
|
381
|
-
guards: { get: Query.Public, cru: Mutation.Admin },
|
|
381
|
+
guards: { root: Admin, get: Query.Public, cru: Mutation.Admin },
|
|
382
382
|
}) {
|
|
383
383
|
// Custom methods beyond auto-generated CRUD
|
|
384
384
|
@Query.Public(() => [cnst.Product])
|
|
@@ -49,7 +49,7 @@ export const General = ({ id }: { id?: string }) => {
|
|
|
49
49
|
return (
|
|
50
50
|
<div className="grid grid-cols-1 gap-4">
|
|
51
51
|
<Field.Text
|
|
52
|
-
label={l
|
|
52
|
+
label={l("model.fieldName")}
|
|
53
53
|
value={form.fieldName}
|
|
54
54
|
onChange={(v) => st.do.setFieldNameOn[Model](v)}
|
|
55
55
|
/>
|
|
@@ -139,7 +139,7 @@ useEffect(() => {
|
|
|
139
139
|
|
|
140
140
|
```tsx
|
|
141
141
|
<Field.List
|
|
142
|
-
label={l
|
|
142
|
+
label={l("map.spawnPositions")}
|
|
143
143
|
value={form.spawnPositions}
|
|
144
144
|
onAdd={() => st.do.addSpawnPosition(defaultPosition)}
|
|
145
145
|
renderItem={(position, idx) => (
|
|
@@ -201,12 +201,12 @@ useEffect(() => {
|
|
|
201
201
|
const { l } = usePage();
|
|
202
202
|
|
|
203
203
|
// Basic field
|
|
204
|
-
<Field.Text label={l
|
|
204
|
+
<Field.Text label={l("model.name")} />
|
|
205
205
|
|
|
206
206
|
// With description
|
|
207
207
|
<Field.Text
|
|
208
|
-
label={l
|
|
209
|
-
desc={l
|
|
208
|
+
label={l("model.email")}
|
|
209
|
+
desc={l("model.email.desc")}
|
|
210
210
|
/>
|
|
211
211
|
|
|
212
212
|
// Dynamic content
|
|
@@ -64,8 +64,8 @@ const MyComponent = () => {
|
|
|
64
64
|
return (
|
|
65
65
|
<>
|
|
66
66
|
<Field.Text
|
|
67
|
-
label={l
|
|
68
|
-
desc={l
|
|
67
|
+
label={l("myModel.title")}
|
|
68
|
+
desc={l("myModel.title.desc")}
|
|
69
69
|
value={formState.title}
|
|
70
70
|
onChange={(value) => st.do.setTitleOnMyModel(value)}
|
|
71
71
|
nullable={false}
|
|
@@ -73,8 +73,8 @@ const MyComponent = () => {
|
|
|
73
73
|
/>
|
|
74
74
|
|
|
75
75
|
<Field.Number
|
|
76
|
-
label={l
|
|
77
|
-
desc={l
|
|
76
|
+
label={l("myModel.amount")}
|
|
77
|
+
desc={l("myModel.amount.desc")}
|
|
78
78
|
value={formState.amount}
|
|
79
79
|
onChange={(value) => st.do.setAmountOnMyModel(value)}
|
|
80
80
|
min={0}
|
|
@@ -83,8 +83,8 @@ const MyComponent = () => {
|
|
|
83
83
|
/>
|
|
84
84
|
|
|
85
85
|
<Field.ToggleSelect
|
|
86
|
-
label={l
|
|
87
|
-
desc={l
|
|
86
|
+
label={l("myModel.status")}
|
|
87
|
+
desc={l("myModel.status.desc")}
|
|
88
88
|
value={formState.status}
|
|
89
89
|
items={cnst.Status}
|
|
90
90
|
onChange={(status) => st.do.setStatusOnMyModel(status)}
|
|
@@ -266,7 +266,7 @@ Components automatically integrate with the internationalization system:
|
|
|
266
266
|
```tsx
|
|
267
267
|
const { l } = usePage();
|
|
268
268
|
|
|
269
|
-
<Field.Text label={l
|
|
269
|
+
<Field.Text label={l("user.name")} desc={l("user.name.desc")} placeholder={l("user.namePlaceholder")} />;
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
### State Management Integration
|
|
@@ -3,7 +3,7 @@ import { ModuleScript } from "./module.script";
|
|
|
3
3
|
export declare class ModuleCommand {
|
|
4
4
|
moduleScript: ModuleScript;
|
|
5
5
|
createModule(moduleName: string, sys: Sys, page: boolean): Promise<void>;
|
|
6
|
-
removeModule(module: Module): void
|
|
6
|
+
removeModule(module: Module): Promise<void>;
|
|
7
7
|
createView(module: Module): Promise<void>;
|
|
8
8
|
createUnit(module: Module): Promise<void>;
|
|
9
9
|
createTemplate(module: Module): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Module, Workspace } from "@akanjs/devkit";
|
|
2
2
|
export declare class ModuleRunner {
|
|
3
3
|
createModule(workspace: Workspace, sysType: "app" | "lib", sysName: string, moduleName: string, description: string): Promise<void>;
|
|
4
|
-
removeModule(module: Module): void
|
|
4
|
+
removeModule(module: Module): Promise<void>;
|
|
5
5
|
createComponentTemplate(module: Module, type: "unit" | "view" | "template" | "zone" | "util"): Promise<{
|
|
6
6
|
component: {
|
|
7
7
|
filename: string;
|
|
@@ -8,7 +8,7 @@ export declare class ModuleScript {
|
|
|
8
8
|
}): Promise<void>;
|
|
9
9
|
createModule(sys: Sys, name: string, description?: string, schemaDescription?: string): Promise<void>;
|
|
10
10
|
createModule_(sys: Sys, name: string, description: string, schemaDescription: string): Promise<void>;
|
|
11
|
-
removeModule(mod: Module): void
|
|
11
|
+
removeModule(mod: Module): Promise<void>;
|
|
12
12
|
createService(workspace: Workspace, name: string): Promise<void>;
|
|
13
13
|
createTest(workspace: Workspace, name: string): Promise<void>;
|
|
14
14
|
createTemplate(mod: Module): Promise<void>;
|
|
@@ -3,5 +3,5 @@ import { ScalarScript } from "./scalar.script";
|
|
|
3
3
|
export declare class ScalarCommand {
|
|
4
4
|
scalarScript: ScalarScript;
|
|
5
5
|
createScalar(sys: Sys, scalarName: string): Promise<void>;
|
|
6
|
-
removeScalar(sys: Sys, scalarName: string): void
|
|
6
|
+
removeScalar(sys: Sys, scalarName: string): Promise<void>;
|
|
7
7
|
}
|