@warlock.js/core 4.2.0 → 4.2.2
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/CHANGELOG.md +6 -0
- package/bin/warlock.js +3 -0
- package/esm/_virtual/_rolldown/runtime.mjs +7 -0
- package/esm/cli/cli-commands.manager.mjs +290 -0
- package/esm/cli/cli-commands.manager.mjs.map +1 -0
- package/esm/cli/cli-commands.utils.mjs +217 -0
- package/esm/cli/cli-commands.utils.mjs.map +1 -0
- package/esm/cli/commands/add.command.mjs +27 -0
- package/esm/cli/commands/add.command.mjs.map +1 -0
- package/esm/cli/commands/build.command.mjs +14 -0
- package/esm/cli/commands/build.command.mjs.map +1 -0
- package/esm/cli/commands/create-database.command.mjs +24 -0
- package/esm/cli/commands/create-database.command.mjs.map +1 -0
- package/esm/cli/commands/dev-server.command.mjs +48 -0
- package/esm/cli/commands/dev-server.command.mjs.map +1 -0
- package/esm/cli/commands/drop-tables.command.mjs +23 -0
- package/esm/cli/commands/drop-tables.command.mjs.map +1 -0
- package/esm/cli/commands/generate/generate.command.mjs +201 -0
- package/esm/cli/commands/generate/generate.command.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/column-dsl-parser.mjs +49 -0
- package/esm/cli/commands/generate/generators/column-dsl-parser.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/controller.generator.mjs +48 -0
- package/esm/cli/commands/generate/generators/controller.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/migration.generator.mjs +81 -0
- package/esm/cli/commands/generate/generators/migration.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/model.generator.mjs +60 -0
- package/esm/cli/commands/generate/generators/model.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/module.generator.mjs +113 -0
- package/esm/cli/commands/generate/generators/module.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/repository.generator.mjs +42 -0
- package/esm/cli/commands/generate/generators/repository.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/resource.generator.mjs +42 -0
- package/esm/cli/commands/generate/generators/resource.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/service.generator.mjs +42 -0
- package/esm/cli/commands/generate/generators/service.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/templates/stubs.mjs +514 -0
- package/esm/cli/commands/generate/templates/stubs.mjs.map +1 -0
- package/esm/cli/commands/generate/utils/name-parser.mjs +69 -0
- package/esm/cli/commands/generate/utils/name-parser.mjs.map +1 -0
- package/esm/cli/commands/generate/utils/path-resolver.mjs +56 -0
- package/esm/cli/commands/generate/utils/path-resolver.mjs.map +1 -0
- package/esm/cli/commands/generate/utils/prompt.mjs +28 -0
- package/esm/cli/commands/generate/utils/prompt.mjs.map +1 -0
- package/esm/cli/commands/generate/utils/writer.mjs +60 -0
- package/esm/cli/commands/generate/utils/writer.mjs.map +1 -0
- package/esm/cli/commands/migrate.command.mjs +60 -0
- package/esm/cli/commands/migrate.command.mjs.map +1 -0
- package/esm/cli/commands/seed.command.mjs +41 -0
- package/esm/cli/commands/seed.command.mjs.map +1 -0
- package/esm/cli/commands/start-production.command.mjs +50 -0
- package/esm/cli/commands/start-production.command.mjs.map +1 -0
- package/esm/cli/commands/storage-put.action.mjs +75 -0
- package/esm/cli/commands/storage-put.action.mjs.map +1 -0
- package/esm/cli/commands/storage-put.command.mjs +46 -0
- package/esm/cli/commands/storage-put.command.mjs.map +1 -0
- package/esm/cli/commands/typings-generator.command.mjs +38 -0
- package/esm/cli/commands/typings-generator.command.mjs.map +1 -0
- package/esm/cli/commands-loader.mjs +50 -0
- package/esm/cli/commands-loader.mjs.map +1 -0
- package/esm/cli/framework-cli-commands.mjs +37 -0
- package/esm/cli/framework-cli-commands.mjs.map +1 -0
- package/esm/cli/parse-cli-args.mjs +62 -0
- package/esm/cli/parse-cli-args.mjs.map +1 -0
- package/esm/cli/start.d.mts +1 -0
- package/esm/cli/start.mjs +8 -0
- package/esm/cli/start.mjs.map +1 -0
- package/esm/cli/string-similarity.mjs +56 -0
- package/esm/cli/string-similarity.mjs.map +1 -0
- package/esm/database/create-database-action.mjs +32 -0
- package/esm/database/create-database-action.mjs.map +1 -0
- package/esm/database/drop-tables-action.mjs +35 -0
- package/esm/database/drop-tables-action.mjs.map +1 -0
- package/esm/database/migrate-action.mjs +99 -0
- package/esm/database/migrate-action.mjs.map +1 -0
- package/esm/database/seed-command-action.mjs +74 -0
- package/esm/database/seed-command-action.mjs.map +1 -0
- package/esm/database/seeds/seeders.manager.mjs +129 -0
- package/esm/database/seeds/seeders.manager.mjs.map +1 -0
- package/esm/database/seeds/seeds-table-migration.mjs +31 -0
- package/esm/database/seeds/seeds-table-migration.mjs.map +1 -0
- package/esm/database/seeds/utils.mjs +6 -0
- package/esm/database/seeds/utils.mjs.map +1 -0
- package/esm/dev-server/dev-logger.mjs +12 -1
- package/esm/dev-server/dev-logger.mjs.map +1 -1
- package/esm/dev-server/development-server.mjs +115 -0
- package/esm/dev-server/development-server.mjs.map +1 -0
- package/esm/dev-server/layer-executor.mjs +114 -0
- package/esm/dev-server/layer-executor.mjs.map +1 -0
- package/esm/dev-server/start-development-server.mjs +63 -0
- package/esm/dev-server/start-development-server.mjs.map +1 -0
- package/esm/dev-server/type-generator.mjs +453 -0
- package/esm/dev-server/type-generator.mjs.map +1 -0
- package/esm/generations/add-command.action.mjs +480 -0
- package/esm/generations/add-command.action.mjs.map +1 -0
- package/esm/generations/stubs.mjs +436 -0
- package/esm/generations/stubs.mjs.map +1 -0
- package/esm/manifest/manifest-manager.mjs +79 -0
- package/esm/manifest/manifest-manager.mjs.map +1 -0
- package/esm/production/build-app-production.mjs +14 -0
- package/esm/production/build-app-production.mjs.map +1 -0
- package/esm/production/esbuild-plugins.mjs +37 -0
- package/esm/production/esbuild-plugins.mjs.map +1 -0
- package/esm/production/production-builder.mjs +264 -0
- package/esm/production/production-builder.mjs.map +1 -0
- package/esm/production/resolve-build-config.mjs +28 -0
- package/esm/production/resolve-build-config.mjs.map +1 -0
- package/esm/utils/framework-vesion.mjs +10 -1
- package/esm/utils/framework-vesion.mjs.map +1 -1
- package/package.json +15 -9
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { appPath } from "../../../../utils/paths.mjs";
|
|
2
|
+
import "../../../../utils/index.mjs";
|
|
3
|
+
import { crudCreateControllerStub, crudCreateSchemaStub, crudCreateServiceStub, crudDeleteControllerStub, crudDeleteServiceStub, crudGetServiceStub, crudListControllerStub, crudListServiceStub, crudModelStub, crudRepositoryStub, crudResourceStub, crudRoutesStub, crudSeedStub, crudShowControllerStub, crudUpdateControllerStub, crudUpdateSchemaStub, crudUpdateServiceStub } from "../templates/stubs.mjs";
|
|
4
|
+
import { pluralName, singularName } from "../utils/name-parser.mjs";
|
|
5
|
+
import { ensureDirectoryAsync, putFileAsync, setDryRun } from "../utils/writer.mjs";
|
|
6
|
+
import { moduleExists } from "../utils/path-resolver.mjs";
|
|
7
|
+
import { createMigrationFile } from "./migration.generator.mjs";
|
|
8
|
+
import { colors } from "@mongez/copper";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
//#region ../@warlock.js/core/src/cli/commands/generate/generators/module.generator.ts
|
|
12
|
+
async function generateModule(data) {
|
|
13
|
+
const moduleName = data.args[0];
|
|
14
|
+
if (!moduleName) {
|
|
15
|
+
console.log(colors.red("Error: Module name is required"));
|
|
16
|
+
console.log(colors.yellow("Usage: warlock generate.module <name> [options]"));
|
|
17
|
+
console.log(colors.yellow("Example: warlock generate.module products"));
|
|
18
|
+
console.log(colors.yellow(" warlock generate.module products --minimal"));
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
const name = pluralName(moduleName);
|
|
22
|
+
const force = data.options.force || data.options.f;
|
|
23
|
+
setDryRun(Boolean(data.options.dryRun));
|
|
24
|
+
const withCrud = !(data.options.minimal || data.options.m);
|
|
25
|
+
if (await moduleExists(name.kebab) && !force) {
|
|
26
|
+
console.log(colors.red(`Error: Module "${name.kebab}" already exists`));
|
|
27
|
+
console.log(colors.yellow("Use --force to overwrite"));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const modulePath = appPath(name.kebab);
|
|
31
|
+
for (const dir of [
|
|
32
|
+
"controllers",
|
|
33
|
+
"services",
|
|
34
|
+
"models",
|
|
35
|
+
"repositories",
|
|
36
|
+
"schema",
|
|
37
|
+
"resources",
|
|
38
|
+
"events",
|
|
39
|
+
"types",
|
|
40
|
+
"utils"
|
|
41
|
+
]) await ensureDirectoryAsync(path.join(modulePath, dir));
|
|
42
|
+
await putFileAsync(path.join(modulePath, "main.ts"), `// You may use this file as a custom entry point to be executed when the app starts.
|
|
43
|
+
// it runs only once, and you don't need to import the routes.ts file, it will be imported automatically.
|
|
44
|
+
// Use it to regsiter or boot up any custom logic for this module.
|
|
45
|
+
`);
|
|
46
|
+
const routesContent = withCrud ? crudRoutesStub(name) : `import { router } from "@warlock.js/core";
|
|
47
|
+
import { guarded } from "app/shared/utils/router";
|
|
48
|
+
|
|
49
|
+
// Define your routes here
|
|
50
|
+
// Example:
|
|
51
|
+
// router.get("/${name.kebab}", listController);
|
|
52
|
+
`;
|
|
53
|
+
await putFileAsync(path.join(modulePath, "routes.ts"), routesContent);
|
|
54
|
+
const localesContent = `import { groupedTranslations } from "@mongez/localization";
|
|
55
|
+
|
|
56
|
+
groupedTranslations("${name.camel}", {
|
|
57
|
+
// Add your translations here
|
|
58
|
+
// Example:
|
|
59
|
+
// welcome: {
|
|
60
|
+
// en: "Welcome",
|
|
61
|
+
// ar: "Ù…Ø±ØØ¨Ø§",
|
|
62
|
+
// },
|
|
63
|
+
});
|
|
64
|
+
`;
|
|
65
|
+
await putFileAsync(path.join(modulePath, "utils", "locales.ts"), localesContent);
|
|
66
|
+
if (withCrud) {
|
|
67
|
+
const entity = singularName(moduleName);
|
|
68
|
+
await putFileAsync(path.join(modulePath, "controllers", `create-${entity.kebab}.controller.ts`), crudCreateControllerStub(entity));
|
|
69
|
+
await putFileAsync(path.join(modulePath, "controllers", `update-${entity.kebab}.controller.ts`), crudUpdateControllerStub(entity));
|
|
70
|
+
await putFileAsync(path.join(modulePath, "controllers", `list-${name.kebab}.controller.ts`), crudListControllerStub(name));
|
|
71
|
+
await putFileAsync(path.join(modulePath, "controllers", `get-${entity.kebab}.controller.ts`), crudShowControllerStub(entity));
|
|
72
|
+
await putFileAsync(path.join(modulePath, "controllers", `delete-${entity.kebab}.controller.ts`), crudDeleteControllerStub(entity));
|
|
73
|
+
await putFileAsync(path.join(modulePath, "schema", `create-${entity.kebab}.schema.ts`), crudCreateSchemaStub(entity));
|
|
74
|
+
await putFileAsync(path.join(modulePath, "schema", `update-${entity.kebab}.schema.ts`), crudUpdateSchemaStub(entity));
|
|
75
|
+
await ensureDirectoryAsync(path.join(modulePath, "models", entity.kebab));
|
|
76
|
+
await putFileAsync(path.join(modulePath, "models", entity.kebab, `${entity.kebab}.model.ts`), crudModelStub(entity));
|
|
77
|
+
await putFileAsync(path.join(modulePath, "models", entity.kebab, "index.ts"), `export * from "./${entity.kebab}.model";\n`);
|
|
78
|
+
await ensureDirectoryAsync(path.join(modulePath, "models", entity.kebab, "migrations"));
|
|
79
|
+
await putFileAsync(path.join(modulePath, "resources", `${entity.kebab}.resource.ts`), crudResourceStub(name));
|
|
80
|
+
await putFileAsync(path.join(modulePath, "repositories", `${name.kebab}.repository.ts`), crudRepositoryStub(name));
|
|
81
|
+
await putFileAsync(path.join(modulePath, "services", `create-${entity.kebab}.service.ts`), crudCreateServiceStub(entity));
|
|
82
|
+
await putFileAsync(path.join(modulePath, "services", `update-${entity.kebab}.service.ts`), crudUpdateServiceStub(entity));
|
|
83
|
+
await putFileAsync(path.join(modulePath, "services", `list-${name.kebab}.service.ts`), crudListServiceStub(name));
|
|
84
|
+
await putFileAsync(path.join(modulePath, "services", `get-${entity.kebab}.service.ts`), crudGetServiceStub(entity));
|
|
85
|
+
await putFileAsync(path.join(modulePath, "services", `delete-${entity.kebab}.service.ts`), crudDeleteServiceStub(entity));
|
|
86
|
+
await ensureDirectoryAsync(path.join(modulePath, "seeds"));
|
|
87
|
+
await putFileAsync(path.join(modulePath, "seeds", `${name.kebab}.seed.ts`), crudSeedStub(name));
|
|
88
|
+
await createMigrationFile(name.kebab, entity.kebab);
|
|
89
|
+
}
|
|
90
|
+
console.log(colors.cyan(`\n✨ Module "${name.kebab}" generated successfully!`));
|
|
91
|
+
if (withCrud) {
|
|
92
|
+
console.log(colors.gray(`\n📦 CRUD scaffold created with:`));
|
|
93
|
+
console.log(colors.gray(` - List, Get, Create, Update & Delete controllers`));
|
|
94
|
+
console.log(colors.gray(` - Repository`));
|
|
95
|
+
console.log(colors.gray(` - Validation schemas in schema/`));
|
|
96
|
+
console.log(colors.gray(` - Model with resource`));
|
|
97
|
+
console.log(colors.gray(` - Routes configured`));
|
|
98
|
+
console.log(colors.gray(`\nNext steps:`));
|
|
99
|
+
console.log(colors.gray(` 1. Update model schema in models/${name.kebab}/${name.kebab}.model.ts`));
|
|
100
|
+
console.log(colors.gray(` 2. Update schema rules in schema/*.schema.ts`));
|
|
101
|
+
console.log(colors.gray(` 3. Create migration: warlock generate.model ${name.kebab}/${name.kebab}`));
|
|
102
|
+
} else {
|
|
103
|
+
console.log(colors.gray(`\nNext steps:`));
|
|
104
|
+
console.log(colors.gray(` 1. Define routes in ${name.kebab}/routes.ts`));
|
|
105
|
+
console.log(colors.gray(` 2. Create controllers: warlock generate.controller ${name.kebab}/<name>`));
|
|
106
|
+
console.log(colors.gray(` 3. Create models: warlock generate.model ${name.kebab}/<name>`));
|
|
107
|
+
console.log(colors.gray(`\nTip: omit --minimal to generate a full CRUD scaffold`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
export { generateModule };
|
|
113
|
+
//# sourceMappingURL=module.generator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.generator.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/core/src/cli/commands/generate/generators/module.generator.ts"],"sourcesContent":["import { colors } from \"@mongez/copper\";\r\nimport path from \"node:path\";\r\nimport { appPath } from \"../../../../utils\";\r\nimport type { CommandActionData } from \"../../../types\";\r\nimport {\r\n crudCreateControllerStub,\r\n crudCreateSchemaStub,\r\n crudCreateServiceStub,\r\n crudDeleteControllerStub,\r\n crudDeleteServiceStub,\r\n crudGetServiceStub,\r\n crudListControllerStub,\r\n crudListServiceStub,\r\n crudModelStub,\r\n crudRepositoryStub,\r\n crudResourceStub,\r\n crudRoutesStub,\r\n crudSeedStub,\r\n crudShowControllerStub,\r\n crudUpdateControllerStub,\r\n crudUpdateSchemaStub,\r\n crudUpdateServiceStub,\r\n} from \"../templates/stubs\";\r\nimport { pluralName, singularName } from \"../utils/name-parser\";\r\nimport { moduleExists } from \"../utils/path-resolver\";\r\nimport { ensureDirectoryAsync, putFileAsync, setDryRun } from \"../utils/writer\";\r\nimport { createMigrationFile } from \"./migration.generator\";\r\n\r\nexport async function generateModule(data: CommandActionData): Promise<void> {\r\n const moduleName = data.args[0];\r\n\r\n if (!moduleName) {\r\n console.log(colors.red(\"Error: Module name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock generate.module <name> [options]\"));\r\n console.log(colors.yellow(\"Example: warlock generate.module products\"));\r\n console.log(colors.yellow(\" warlock generate.module products --minimal\"));\r\n process.exit(1);\r\n }\r\n\r\n const name = pluralName(moduleName);\r\n const force = data.options.force || data.options.f;\r\n setDryRun(Boolean(data.options.dryRun));\r\n\r\n // Full CRUD is the default; --minimal (-m) opts down to a bare skeleton.\r\n const minimal = data.options.minimal || data.options.m;\r\n const withCrud = !minimal;\r\n\r\n // Check if module already exists\r\n if ((await moduleExists(name.kebab)) && !force) {\r\n console.log(colors.red(`Error: Module \"${name.kebab}\" already exists`));\r\n console.log(colors.yellow(\"Use --force to overwrite\"));\r\n process.exit(1);\r\n }\r\n\r\n const modulePath = appPath(name.kebab);\r\n\r\n // Create module directory structure\r\n const directories = [\r\n \"controllers\",\r\n \"services\",\r\n \"models\",\r\n \"repositories\",\r\n \"schema\",\r\n \"resources\",\r\n \"events\",\r\n \"types\",\r\n \"utils\",\r\n ];\r\n\r\n for (const dir of directories) {\r\n await ensureDirectoryAsync(path.join(modulePath, dir));\r\n }\r\n\r\n // Create main.ts\r\n const mainContent = `// You may use this file as a custom entry point to be executed when the app starts.\r\n// it runs only once, and you don't need to import the routes.ts file, it will be imported automatically.\r\n// Use it to regsiter or boot up any custom logic for this module.\r\n`;\r\n await putFileAsync(path.join(modulePath, \"main.ts\"), mainContent);\r\n\r\n // Create routes.ts\r\n const routesContent = withCrud\r\n ? crudRoutesStub(name)\r\n : `import { router } from \"@warlock.js/core\";\r\nimport { guarded } from \"app/shared/utils/router\";\r\n\r\n// Define your routes here\r\n// Example:\r\n// router.get(\"/${name.kebab}\", listController);\r\n`;\r\n await putFileAsync(path.join(modulePath, \"routes.ts\"), routesContent);\r\n\r\n // Create utils/locales.ts\r\n const localesContent = `import { groupedTranslations } from \"@mongez/localization\";\r\n\r\ngroupedTranslations(\"${name.camel}\", {\r\n // Add your translations here\r\n // Example:\r\n // welcome: {\r\n // en: \"Welcome\",\r\n // ar: \"Ù…Ø±ØØ¨Ø§\",\r\n // },\r\n});\r\n`;\r\n await putFileAsync(path.join(modulePath, \"utils\", \"locales.ts\"), localesContent);\r\n\r\n // Full CRUD scaffold (the default) unless --minimal was passed\r\n if (withCrud) {\r\n const entity = singularName(moduleName);\r\n\r\n // Create controllers\r\n await putFileAsync(\r\n path.join(modulePath, \"controllers\", `create-${entity.kebab}.controller.ts`),\r\n crudCreateControllerStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"controllers\", `update-${entity.kebab}.controller.ts`),\r\n crudUpdateControllerStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"controllers\", `list-${name.kebab}.controller.ts`),\r\n crudListControllerStub(name),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"controllers\", `get-${entity.kebab}.controller.ts`),\r\n crudShowControllerStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"controllers\", `delete-${entity.kebab}.controller.ts`),\r\n crudDeleteControllerStub(entity),\r\n );\r\n\r\n // Create schema files — each exports both the schema value and its\r\n // inferred type; controllers import them directly (no requests/ alias).\r\n await putFileAsync(\r\n path.join(modulePath, \"schema\", `create-${entity.kebab}.schema.ts`),\r\n crudCreateSchemaStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"schema\", `update-${entity.kebab}.schema.ts`),\r\n crudUpdateSchemaStub(entity),\r\n );\r\n\r\n // Create model\r\n await ensureDirectoryAsync(path.join(modulePath, \"models\", entity.kebab));\r\n await putFileAsync(\r\n path.join(modulePath, \"models\", entity.kebab, `${entity.kebab}.model.ts`),\r\n crudModelStub(entity),\r\n );\r\n\r\n // Create model index\r\n await putFileAsync(\r\n path.join(modulePath, \"models\", entity.kebab, \"index.ts\"),\r\n `export * from \"./${entity.kebab}.model\";\\n`,\r\n );\r\n\r\n // Create migrations folder\r\n await ensureDirectoryAsync(path.join(modulePath, \"models\", entity.kebab, \"migrations\"));\r\n\r\n // Create resource\r\n await putFileAsync(\r\n path.join(modulePath, \"resources\", `${entity.kebab}.resource.ts`),\r\n crudResourceStub(name),\r\n );\r\n\r\n // Create repository\r\n await putFileAsync(\r\n path.join(modulePath, \"repositories\", `${name.kebab}.repository.ts`),\r\n crudRepositoryStub(name),\r\n );\r\n\r\n // Create services\r\n await putFileAsync(\r\n path.join(modulePath, \"services\", `create-${entity.kebab}.service.ts`),\r\n crudCreateServiceStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"services\", `update-${entity.kebab}.service.ts`),\r\n crudUpdateServiceStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"services\", `list-${name.kebab}.service.ts`),\r\n crudListServiceStub(name),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"services\", `get-${entity.kebab}.service.ts`),\r\n crudGetServiceStub(entity),\r\n );\r\n\r\n await putFileAsync(\r\n path.join(modulePath, \"services\", `delete-${entity.kebab}.service.ts`),\r\n crudDeleteServiceStub(entity),\r\n );\r\n\r\n // Create seeds\r\n await ensureDirectoryAsync(path.join(modulePath, \"seeds\"));\r\n await putFileAsync(path.join(modulePath, \"seeds\", `${name.kebab}.seed.ts`), crudSeedStub(name));\r\n\r\n // Create migration\r\n await createMigrationFile(name.kebab, entity.kebab);\r\n }\r\n\r\n console.log(colors.cyan(`\\n✨ Module \"${name.kebab}\" generated successfully!`));\r\n\r\n if (withCrud) {\r\n console.log(colors.gray(`\\n📦 CRUD scaffold created with:`));\r\n console.log(colors.gray(` - List, Get, Create, Update & Delete controllers`));\r\n console.log(colors.gray(` - Repository`));\r\n console.log(colors.gray(` - Validation schemas in schema/`));\r\n console.log(colors.gray(` - Model with resource`));\r\n console.log(colors.gray(` - Routes configured`));\r\n console.log(colors.gray(`\\nNext steps:`));\r\n console.log(\r\n colors.gray(` 1. Update model schema in models/${name.kebab}/${name.kebab}.model.ts`),\r\n );\r\n console.log(colors.gray(` 2. Update schema rules in schema/*.schema.ts`));\r\n console.log(\r\n colors.gray(` 3. Create migration: warlock generate.model ${name.kebab}/${name.kebab}`),\r\n );\r\n } else {\r\n console.log(colors.gray(`\\nNext steps:`));\r\n console.log(colors.gray(` 1. Define routes in ${name.kebab}/routes.ts`));\r\n console.log(\r\n colors.gray(` 2. Create controllers: warlock generate.controller ${name.kebab}/<name>`),\r\n );\r\n console.log(colors.gray(` 3. Create models: warlock generate.model ${name.kebab}/<name>`));\r\n console.log(colors.gray(`\\nTip: omit --minimal to generate a full CRUD scaffold`));\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;AA4BA,eAAsB,eAAe,MAAwC;CAC3E,MAAM,aAAa,KAAK,KAAK;CAE7B,IAAI,CAAC,YAAY;EACf,QAAQ,IAAI,OAAO,IAAI,gCAAgC,CAAC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Q,IAAI,OAAO,KAAK,8CAA8C,KAAK,MAAM,QAAQ,CAAC;EAC1F,QAAQ,IAAI,OAAO,KAAK,wDAAwD,CAAC;CACnF;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { repositoryStub } from "../templates/stubs.mjs";
|
|
2
|
+
import { parseModulePath, parseName } from "../utils/name-parser.mjs";
|
|
3
|
+
import { putFileAsync, setDryRun } from "../utils/writer.mjs";
|
|
4
|
+
import { componentExists, ensureComponentDirectory, moduleExists, resolveComponentPath } from "../utils/path-resolver.mjs";
|
|
5
|
+
import { colors } from "@mongez/copper";
|
|
6
|
+
|
|
7
|
+
//#region ../@warlock.js/core/src/cli/commands/generate/generators/repository.generator.ts
|
|
8
|
+
async function generateRepository(data) {
|
|
9
|
+
const input = data.args[0];
|
|
10
|
+
if (!input) {
|
|
11
|
+
console.log(colors.red("Error: Repository name is required"));
|
|
12
|
+
console.log(colors.yellow("Usage: warlock create.repository <module>/<name>"));
|
|
13
|
+
console.log(colors.yellow("Example: warlock create.repository users/user"));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const { module, name: componentName } = parseModulePath(input);
|
|
17
|
+
if (!module) {
|
|
18
|
+
console.log(colors.red("Error: Module name is required"));
|
|
19
|
+
console.log(colors.yellow("Usage: warlock create.repository <module>/<name>"));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (!await moduleExists(module)) {
|
|
23
|
+
console.log(colors.red(`Error: Module "${module}" does not exist`));
|
|
24
|
+
console.log(colors.yellow(`Run: warlock create.module ${module}`));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const name = parseName(componentName);
|
|
28
|
+
const force = data.options.force || data.options.f;
|
|
29
|
+
setDryRun(Boolean(data.options.dryRun));
|
|
30
|
+
if (await componentExists(module, "repositories", `${name.kebab}.repository`) && !force) {
|
|
31
|
+
console.log(colors.red(`Error: Repository "${name.kebab}.repository.ts" already exists`));
|
|
32
|
+
console.log(colors.yellow("Use --force to overwrite"));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
await ensureComponentDirectory(module, "repositories");
|
|
36
|
+
await putFileAsync(resolveComponentPath(module, "repositories", `${name.kebab}.repository`), repositoryStub(name));
|
|
37
|
+
console.log(colors.cyan(`\n✨ Repository "${name.pascal}Repository" generated successfully!`));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { generateRepository };
|
|
42
|
+
//# sourceMappingURL=repository.generator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repository.generator.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/core/src/cli/commands/generate/generators/repository.generator.ts"],"sourcesContent":["import { colors } from \"@mongez/copper\";\r\nimport type { CommandActionData } from \"../../../types\";\r\nimport { repositoryStub } from \"../templates/stubs\";\r\nimport { putFileAsync, setDryRun } from \"../utils/writer\";\r\nimport { parseModulePath, parseName } from \"../utils/name-parser\";\r\nimport {\r\n componentExists,\r\n ensureComponentDirectory,\r\n moduleExists,\r\n resolveComponentPath,\r\n} from \"../utils/path-resolver\";\r\n\r\nexport async function generateRepository(data: CommandActionData): Promise<void> {\r\n const input = data.args[0];\r\n\r\n if (!input) {\r\n console.log(colors.red(\"Error: Repository name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock create.repository <module>/<name>\"));\r\n console.log(colors.yellow(\"Example: warlock create.repository users/user\"));\r\n process.exit(1);\r\n }\r\n\r\n const { module, name: componentName } = parseModulePath(input);\r\n\r\n if (!module) {\r\n console.log(colors.red(\"Error: Module name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock create.repository <module>/<name>\"));\r\n process.exit(1);\r\n }\r\n\r\n // Check if module exists\r\n if (!(await moduleExists(module))) {\r\n console.log(colors.red(`Error: Module \"${module}\" does not exist`));\r\n console.log(colors.yellow(`Run: warlock create.module ${module}`));\r\n process.exit(1);\r\n }\r\n\r\n const name = parseName(componentName);\r\n const force = data.options.force || data.options.f;\r\n setDryRun(Boolean(data.options.dryRun));\r\n\r\n // Check if repository already exists\r\n if ((await componentExists(module, \"repositories\", `${name.kebab}.repository`)) && !force) {\r\n console.log(colors.red(`Error: Repository \"${name.kebab}.repository.ts\" already exists`));\r\n console.log(colors.yellow(\"Use --force to overwrite\"));\r\n process.exit(1);\r\n }\r\n\r\n // Ensure directories exist\r\n await ensureComponentDirectory(module, \"repositories\");\r\n\r\n // Generate repository\r\n const repositoryPath = resolveComponentPath(module, \"repositories\", `${name.kebab}.repository`);\r\n const repositoryContent = repositoryStub(name);\r\n\r\n await putFileAsync(repositoryPath, repositoryContent);\r\n\r\n console.log(colors.cyan(`\\n✨ Repository \"${name.pascal}Repository\" generated successfully!`));\r\n}\r\n"],"mappings":";;;;;;;AAYA,eAAsB,mBAAmB,MAAwC;CAC/E,MAAM,QAAQ,KAAK,KAAK;CAExB,IAAI,CAAC,OAAO;EACV,QAAQ,IAAI,OAAO,IAAI,oCAAoC,CAAC;EAC5D,QAAQ,IAAI,OAAO,OAAO,kDAAkD,CAAC;EAC7E,QAAQ,IAAI,OAAO,OAAO,+CAA+C,CAAC;EAC1E,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,EAAE,QAAQ,MAAM,kBAAkB,gBAAgB,KAAK;CAE7D,IAAI,CAAC,QAAQ;EACX,QAAQ,IAAI,OAAO,IAAI,gCAAgC,CAAC;EACxD,QAAQ,IAAI,OAAO,OAAO,kDAAkD,CAAC;EAC7E,QAAQ,KAAK,CAAC;CAChB;CAGA,IAAI,CAAE,MAAM,aAAa,MAAM,GAAI;EACjC,QAAQ,IAAI,OAAO,IAAI,kBAAkB,OAAO,iBAAiB,CAAC;EAClE,QAAQ,IAAI,OAAO,OAAO,8BAA8B,QAAQ,CAAC;EACjE,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,OAAO,UAAU,aAAa;CACpC,MAAM,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ;CACjD,UAAU,QAAQ,KAAK,QAAQ,MAAM,CAAC;CAGtC,IAAK,MAAM,gBAAgB,QAAQ,gBAAgB,GAAG,KAAK,MAAM,YAAY,KAAM,CAAC,OAAO;EACzF,QAAQ,IAAI,OAAO,IAAI,sBAAsB,KAAK,MAAM,+BAA+B,CAAC;EACxF,QAAQ,IAAI,OAAO,OAAO,0BAA0B,CAAC;EACrD,QAAQ,KAAK,CAAC;CAChB;CAGA,MAAM,yBAAyB,QAAQ,cAAc;CAMrD,MAAM,aAHiB,qBAAqB,QAAQ,gBAAgB,GAAG,KAAK,MAAM,YAGlD,GAFN,eAAe,IAEU,CAAC;CAEpD,QAAQ,IAAI,OAAO,KAAK,qBAAqB,KAAK,OAAO,oCAAoC,CAAC;AAChG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { resourceStub } from "../templates/stubs.mjs";
|
|
2
|
+
import { parseModulePath, parseName } from "../utils/name-parser.mjs";
|
|
3
|
+
import { putFileAsync, setDryRun } from "../utils/writer.mjs";
|
|
4
|
+
import { componentExists, ensureComponentDirectory, moduleExists, resolveComponentPath } from "../utils/path-resolver.mjs";
|
|
5
|
+
import { colors } from "@mongez/copper";
|
|
6
|
+
|
|
7
|
+
//#region ../@warlock.js/core/src/cli/commands/generate/generators/resource.generator.ts
|
|
8
|
+
async function generateResource(data) {
|
|
9
|
+
const input = data.args[0];
|
|
10
|
+
if (!input) {
|
|
11
|
+
console.log(colors.red("Error: Resource name is required"));
|
|
12
|
+
console.log(colors.yellow("Usage: warlock create.resource <module>/<name>"));
|
|
13
|
+
console.log(colors.yellow("Example: warlock create.resource users/user"));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const { module, name: componentName } = parseModulePath(input);
|
|
17
|
+
if (!module) {
|
|
18
|
+
console.log(colors.red("Error: Module name is required"));
|
|
19
|
+
console.log(colors.yellow("Usage: warlock create.resource <module>/<name>"));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (!await moduleExists(module)) {
|
|
23
|
+
console.log(colors.red(`Error: Module "${module}" does not exist`));
|
|
24
|
+
console.log(colors.yellow(`Run: warlock create.module ${module}`));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const name = parseName(componentName);
|
|
28
|
+
const force = data.options.force || data.options.f;
|
|
29
|
+
setDryRun(Boolean(data.options.dryRun));
|
|
30
|
+
if (await componentExists(module, "resources", `${name.kebab}.resource`) && !force) {
|
|
31
|
+
console.log(colors.red(`Error: Resource "${name.kebab}.resource.ts" already exists`));
|
|
32
|
+
console.log(colors.yellow("Use --force to overwrite"));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
await ensureComponentDirectory(module, "resources");
|
|
36
|
+
await putFileAsync(resolveComponentPath(module, "resources", `${name.kebab}.resource`), resourceStub(name));
|
|
37
|
+
console.log(colors.cyan(`\n✨ Resource "${name.pascal}Resource" generated successfully!`));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { generateResource };
|
|
42
|
+
//# sourceMappingURL=resource.generator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.generator.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/core/src/cli/commands/generate/generators/resource.generator.ts"],"sourcesContent":["import { colors } from \"@mongez/copper\";\r\nimport type { CommandActionData } from \"../../../types\";\r\nimport { resourceStub } from \"../templates/stubs\";\r\nimport { putFileAsync, setDryRun } from \"../utils/writer\";\r\nimport { parseModulePath, parseName } from \"../utils/name-parser\";\r\nimport {\r\n componentExists,\r\n ensureComponentDirectory,\r\n moduleExists,\r\n resolveComponentPath,\r\n} from \"../utils/path-resolver\";\r\n\r\nexport async function generateResource(data: CommandActionData): Promise<void> {\r\n const input = data.args[0];\r\n\r\n if (!input) {\r\n console.log(colors.red(\"Error: Resource name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock create.resource <module>/<name>\"));\r\n console.log(colors.yellow(\"Example: warlock create.resource users/user\"));\r\n process.exit(1);\r\n }\r\n\r\n const { module, name: componentName } = parseModulePath(input);\r\n\r\n if (!module) {\r\n console.log(colors.red(\"Error: Module name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock create.resource <module>/<name>\"));\r\n process.exit(1);\r\n }\r\n\r\n // Check if module exists\r\n if (!(await moduleExists(module))) {\r\n console.log(colors.red(`Error: Module \"${module}\" does not exist`));\r\n console.log(colors.yellow(`Run: warlock create.module ${module}`));\r\n process.exit(1);\r\n }\r\n\r\n const name = parseName(componentName);\r\n const force = data.options.force || data.options.f;\r\n setDryRun(Boolean(data.options.dryRun));\r\n\r\n // Check if resource already exists\r\n if ((await componentExists(module, \"resources\", `${name.kebab}.resource`)) && !force) {\r\n console.log(colors.red(`Error: Resource \"${name.kebab}.resource.ts\" already exists`));\r\n console.log(colors.yellow(\"Use --force to overwrite\"));\r\n process.exit(1);\r\n }\r\n\r\n // Ensure directories exist\r\n await ensureComponentDirectory(module, \"resources\");\r\n\r\n // Generate resource\r\n const resourcePath = resolveComponentPath(module, \"resources\", `${name.kebab}.resource`);\r\n const resourceContent = resourceStub(name);\r\n\r\n await putFileAsync(resourcePath, resourceContent);\r\n\r\n console.log(colors.cyan(`\\n✨ Resource \"${name.pascal}Resource\" generated successfully!`));\r\n}\r\n"],"mappings":";;;;;;;AAYA,eAAsB,iBAAiB,MAAwC;CAC7E,MAAM,QAAQ,KAAK,KAAK;CAExB,IAAI,CAAC,OAAO;EACV,QAAQ,IAAI,OAAO,IAAI,kCAAkC,CAAC;EAC1D,QAAQ,IAAI,OAAO,OAAO,gDAAgD,CAAC;EAC3E,QAAQ,IAAI,OAAO,OAAO,6CAA6C,CAAC;EACxE,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,EAAE,QAAQ,MAAM,kBAAkB,gBAAgB,KAAK;CAE7D,IAAI,CAAC,QAAQ;EACX,QAAQ,IAAI,OAAO,IAAI,gCAAgC,CAAC;EACxD,QAAQ,IAAI,OAAO,OAAO,gDAAgD,CAAC;EAC3E,QAAQ,KAAK,CAAC;CAChB;CAGA,IAAI,CAAE,MAAM,aAAa,MAAM,GAAI;EACjC,QAAQ,IAAI,OAAO,IAAI,kBAAkB,OAAO,iBAAiB,CAAC;EAClE,QAAQ,IAAI,OAAO,OAAO,8BAA8B,QAAQ,CAAC;EACjE,QAAQ,KAAK,CAAC;CAChB;CAEA,MAAM,OAAO,UAAU,aAAa;CACpC,MAAM,QAAQ,KAAK,QAAQ,SAAS,KAAK,QAAQ;CACjD,UAAU,QAAQ,KAAK,QAAQ,MAAM,CAAC;CAGtC,IAAK,MAAM,gBAAgB,QAAQ,aAAa,GAAG,KAAK,MAAM,UAAU,KAAM,CAAC,OAAO;EACpF,QAAQ,IAAI,OAAO,IAAI,oBAAoB,KAAK,MAAM,6BAA6B,CAAC;EACpF,QAAQ,IAAI,OAAO,OAAO,0BAA0B,CAAC;EACrD,QAAQ,KAAK,CAAC;CAChB;CAGA,MAAM,yBAAyB,QAAQ,WAAW;CAMlD,MAAM,aAHe,qBAAqB,QAAQ,aAAa,GAAG,KAAK,MAAM,UAG/C,GAFN,aAAa,IAEU,CAAC;CAEhD,QAAQ,IAAI,OAAO,KAAK,mBAAmB,KAAK,OAAO,kCAAkC,CAAC;AAC5F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { serviceStub } from "../templates/stubs.mjs";
|
|
2
|
+
import { parseModulePath, parseName } from "../utils/name-parser.mjs";
|
|
3
|
+
import { putFileAsync, setDryRun } from "../utils/writer.mjs";
|
|
4
|
+
import { componentExists, ensureComponentDirectory, moduleExists, resolveComponentPath } from "../utils/path-resolver.mjs";
|
|
5
|
+
import { colors } from "@mongez/copper";
|
|
6
|
+
|
|
7
|
+
//#region ../@warlock.js/core/src/cli/commands/generate/generators/service.generator.ts
|
|
8
|
+
async function generateService(data) {
|
|
9
|
+
const input = data.args[0];
|
|
10
|
+
if (!input) {
|
|
11
|
+
console.log(colors.red("Error: Service name is required"));
|
|
12
|
+
console.log(colors.yellow("Usage: warlock create.service <module>/<name>"));
|
|
13
|
+
console.log(colors.yellow("Example: warlock create.service users/create-user"));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const { module, name: componentName } = parseModulePath(input);
|
|
17
|
+
if (!module) {
|
|
18
|
+
console.log(colors.red("Error: Module name is required"));
|
|
19
|
+
console.log(colors.yellow("Usage: warlock create.service <module>/<name>"));
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (!await moduleExists(module)) {
|
|
23
|
+
console.log(colors.red(`Error: Module "${module}" does not exist`));
|
|
24
|
+
console.log(colors.yellow(`Run: warlock create.module ${module}`));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const name = parseName(componentName);
|
|
28
|
+
const force = data.options.force || data.options.f;
|
|
29
|
+
setDryRun(Boolean(data.options.dryRun));
|
|
30
|
+
if (await componentExists(module, "services", `${name.kebab}.service`) && !force) {
|
|
31
|
+
console.log(colors.red(`Error: Service "${name.kebab}.service.ts" already exists`));
|
|
32
|
+
console.log(colors.yellow("Use --force to overwrite"));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
await ensureComponentDirectory(module, "services");
|
|
36
|
+
await putFileAsync(resolveComponentPath(module, "services", `${name.kebab}.service`), serviceStub(name));
|
|
37
|
+
console.log(colors.cyan(`\n✨ Service "${name.camel}" generated successfully!`));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { generateService };
|
|
42
|
+
//# sourceMappingURL=service.generator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.generator.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/core/src/cli/commands/generate/generators/service.generator.ts"],"sourcesContent":["import { colors } from \"@mongez/copper\";\r\nimport type { CommandActionData } from \"../../../types\";\r\nimport { serviceStub } from \"../templates/stubs\";\r\nimport { putFileAsync, setDryRun } from \"../utils/writer\";\r\nimport { parseModulePath, parseName } from \"../utils/name-parser\";\r\nimport {\r\n componentExists,\r\n ensureComponentDirectory,\r\n moduleExists,\r\n resolveComponentPath,\r\n} from \"../utils/path-resolver\";\r\n\r\nexport async function generateService(data: CommandActionData): Promise<void> {\r\n const input = data.args[0];\r\n\r\n if (!input) {\r\n console.log(colors.red(\"Error: Service name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock create.service <module>/<name>\"));\r\n console.log(colors.yellow(\"Example: warlock create.service users/create-user\"));\r\n process.exit(1);\r\n }\r\n\r\n const { module, name: componentName } = parseModulePath(input);\r\n\r\n if (!module) {\r\n console.log(colors.red(\"Error: Module name is required\"));\r\n console.log(colors.yellow(\"Usage: warlock create.service <module>/<name>\"));\r\n process.exit(1);\r\n }\r\n\r\n // Check if module exists\r\n if (!(await moduleExists(module))) {\r\n console.log(colors.red(`Error: Module \"${module}\" does not exist`));\r\n console.log(colors.yellow(`Run: warlock create.module ${module}`));\r\n process.exit(1);\r\n }\r\n\r\n const name = parseName(componentName);\r\n const force = data.options.force || data.options.f;\r\n setDryRun(Boolean(data.options.dryRun));\r\n\r\n // Check if service already exists\r\n if ((await componentExists(module, \"services\", `${name.kebab}.service`)) && !force) {\r\n console.log(colors.red(`Error: Service \"${name.kebab}.service.ts\" already exists`));\r\n console.log(colors.yellow(\"Use --force to overwrite\"));\r\n process.exit(1);\r\n }\r\n\r\n // Ensure directories exist\r\n await ensureComponentDirectory(module, \"services\");\r\n\r\n // Generate service\r\n const servicePath = resolveComponentPath(module, \"services\", `${name.kebab}.service`);\r\n const serviceContent = serviceStub(name);\r\n\r\n await putFileAsync(servicePath, serviceContent);\r\n\r\n console.log(colors.cyan(`\\n✨ Service \"${name.camel}\" generated successfully!`));\r\n}\r\n"],"mappings":";;;;;;;AAYA,eAAsB,gBAAgB,MAAwC;CAC5E,MAAM,QAAQ,KAAK,KAAK;CAExB,IAAI,CAAC,OAAO;EACV,QAAQ,IA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