adula 0.0.0-stage → 2.0.0

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 (210) hide show
  1. package/LICENSE.md +10 -0
  2. package/README.md +40 -2
  3. package/build/agent/AGENTS.template.md +28 -0
  4. package/build/agent/capabilities.md +60 -0
  5. package/build/agent/skills/adula-frontend-design/SKILL.md +59 -0
  6. package/build/agent/skills/idea-review/SKILL.md +31 -0
  7. package/build/agent/skills/module-review/SKILL.md +22 -0
  8. package/build/agent/skills/perf-review/SKILL.md +24 -0
  9. package/build/agent/skills/schema-review/SKILL.md +22 -0
  10. package/build/agent/skills/security-review/SKILL.md +24 -0
  11. package/build/agent/skills/ui-review/SKILL.md +22 -0
  12. package/build/commands/capabilities.d.ts +10 -0
  13. package/build/commands/capabilities.js +40 -0
  14. package/build/commands/doctor.d.ts +9 -0
  15. package/build/commands/doctor.js +72 -0
  16. package/build/commands/gaps.d.ts +12 -0
  17. package/build/commands/gaps.js +62 -0
  18. package/build/commands/install.d.ts +9 -0
  19. package/build/commands/install.js +105 -0
  20. package/build/commands/main.d.ts +8 -0
  21. package/build/commands/main.js +33 -0
  22. package/build/commands/module_add.d.ts +8 -0
  23. package/build/commands/module_add.js +57 -0
  24. package/build/commands/module_remove.d.ts +10 -0
  25. package/build/commands/module_remove.js +94 -0
  26. package/build/commands/resource.d.ts +8 -0
  27. package/build/commands/resource.js +29 -0
  28. package/build/commands/resource_snapshot.d.ts +15 -0
  29. package/build/commands/resource_snapshot.js +61 -0
  30. package/build/commands/storage_migrate.d.ts +12 -0
  31. package/build/commands/storage_migrate.js +39 -0
  32. package/build/commands/ui.d.ts +11 -0
  33. package/build/commands/ui.js +210 -0
  34. package/build/commands/upgrade.d.ts +15 -0
  35. package/build/commands/upgrade.js +34 -0
  36. package/build/configure.d.ts +2 -0
  37. package/build/configure.js +79 -0
  38. package/build/database/migrations/1770000000000_core.d.ts +5 -0
  39. package/build/database/migrations/1770000000000_core.js +10 -0
  40. package/build/database/migrations/1770000000001_attachments.d.ts +5 -0
  41. package/build/database/migrations/1770000000001_attachments.js +10 -0
  42. package/build/database/migrations/1770000000002_saved_views.d.ts +5 -0
  43. package/build/database/migrations/1770000000002_saved_views.js +10 -0
  44. package/build/database/migrations/1770000000003_user_invitations.d.ts +5 -0
  45. package/build/database/migrations/1770000000003_user_invitations.js +18 -0
  46. package/build/database/migrations/1770000000004_collaboration.d.ts +5 -0
  47. package/build/database/migrations/1770000000004_collaboration.js +10 -0
  48. package/build/database/migrations/1770000000005_assignments.d.ts +5 -0
  49. package/build/database/migrations/1770000000005_assignments.js +10 -0
  50. package/build/database/migrations/1770000000006_messaging.d.ts +5 -0
  51. package/build/database/migrations/1770000000006_messaging.js +10 -0
  52. package/build/database/migrations/1770000000007_webhooks.d.ts +5 -0
  53. package/build/database/migrations/1770000000007_webhooks.js +10 -0
  54. package/build/database/migrations/1770000000008_imports.d.ts +5 -0
  55. package/build/database/migrations/1770000000008_imports.js +10 -0
  56. package/build/database/migrations/1770000000010_workflows.d.ts +5 -0
  57. package/build/database/migrations/1770000000010_workflows.js +10 -0
  58. package/build/database/migrations/1770000000011_managed_assignments.d.ts +5 -0
  59. package/build/database/migrations/1770000000011_managed_assignments.js +10 -0
  60. package/build/database/migrations/1770000000012_role_keys.d.ts +5 -0
  61. package/build/database/migrations/1770000000012_role_keys.js +10 -0
  62. package/build/database/migrations/1770000000013_notification_targets.d.ts +5 -0
  63. package/build/database/migrations/1770000000013_notification_targets.js +10 -0
  64. package/build/database/migrations/1770000000014_upload_grants.d.ts +5 -0
  65. package/build/database/migrations/1770000000014_upload_grants.js +10 -0
  66. package/build/database/migrations/1770000000015_inbound_webhooks.d.ts +5 -0
  67. package/build/database/migrations/1770000000015_inbound_webhooks.js +10 -0
  68. package/build/database/migrations/1770000000016_adulajs_names.d.ts +6 -0
  69. package/build/database/migrations/1770000000016_adulajs_names.js +11 -0
  70. package/build/index.d.ts +80 -0
  71. package/build/index.js +49 -0
  72. package/build/providers/adula_provider.d.ts +6 -0
  73. package/build/providers/adula_provider.js +10 -0
  74. package/build/src/admin/contracts.d.ts +19 -0
  75. package/build/src/admin/contracts.js +115 -0
  76. package/build/src/admin/controller.d.ts +32 -0
  77. package/build/src/admin/controller.js +167 -0
  78. package/build/src/admin/errors.d.ts +5 -0
  79. package/build/src/admin/errors.js +9 -0
  80. package/build/src/admin/presentation.d.ts +28 -0
  81. package/build/src/admin/presentation.js +1 -0
  82. package/build/src/admin/record_title.d.ts +14 -0
  83. package/build/src/admin/record_title.js +50 -0
  84. package/build/src/admin/resource_service.d.ts +376 -0
  85. package/build/src/admin/resource_service.js +1448 -0
  86. package/build/src/attachments/attachment_service.d.ts +100 -0
  87. package/build/src/attachments/attachment_service.js +270 -0
  88. package/build/src/attachments/doctor.d.ts +4 -0
  89. package/build/src/attachments/doctor.js +28 -0
  90. package/build/src/attachments/storage_migrate.d.ts +39 -0
  91. package/build/src/attachments/storage_migrate.js +64 -0
  92. package/build/src/attachments/upload_grants.d.ts +44 -0
  93. package/build/src/attachments/upload_grants.js +105 -0
  94. package/build/src/auth/ability.d.ts +24 -0
  95. package/build/src/auth/ability.js +34 -0
  96. package/build/src/auth/actor_store.d.ts +14 -0
  97. package/build/src/auth/actor_store.js +70 -0
  98. package/build/src/auth/conditions.d.ts +26 -0
  99. package/build/src/auth/conditions.js +117 -0
  100. package/build/src/auth/packed_rules.d.ts +4 -0
  101. package/build/src/auth/packed_rules.js +13 -0
  102. package/build/src/auth/sql.d.ts +11 -0
  103. package/build/src/auth/sql.js +118 -0
  104. package/build/src/collaboration/assignments.d.ts +129 -0
  105. package/build/src/collaboration/assignments.js +333 -0
  106. package/build/src/collaboration/record_collaboration.d.ts +86 -0
  107. package/build/src/collaboration/record_collaboration.js +348 -0
  108. package/build/src/commands/agent_assets.d.ts +7 -0
  109. package/build/src/commands/agent_assets.js +66 -0
  110. package/build/src/commands/capabilities.d.ts +19 -0
  111. package/build/src/commands/capabilities.js +179 -0
  112. package/build/src/commands/doctor.d.ts +42 -0
  113. package/build/src/commands/doctor.js +375 -0
  114. package/build/src/commands/gap_report.d.ts +56 -0
  115. package/build/src/commands/gap_report.js +110 -0
  116. package/build/src/commands/generator.d.ts +1 -0
  117. package/build/src/commands/generator.js +70 -0
  118. package/build/src/commands/snapshot.d.ts +28 -0
  119. package/build/src/commands/snapshot.js +48 -0
  120. package/build/src/commands/source_markers.d.ts +11 -0
  121. package/build/src/commands/source_markers.js +41 -0
  122. package/build/src/core/activity.d.ts +43 -0
  123. package/build/src/core/activity.js +77 -0
  124. package/build/src/core/administration_guard.d.ts +3 -0
  125. package/build/src/core/administration_guard.js +39 -0
  126. package/build/src/core/health.d.ts +42 -0
  127. package/build/src/core/health.js +44 -0
  128. package/build/src/core/mail_test.d.ts +18 -0
  129. package/build/src/core/mail_test.js +88 -0
  130. package/build/src/core/message_templates.d.ts +83 -0
  131. package/build/src/core/message_templates.js +293 -0
  132. package/build/src/core/module_seed.d.ts +15 -0
  133. package/build/src/core/module_seed.js +31 -0
  134. package/build/src/core/notifications.d.ts +42 -0
  135. package/build/src/core/notifications.js +91 -0
  136. package/build/src/core/org_units.d.ts +30 -0
  137. package/build/src/core/org_units.js +123 -0
  138. package/build/src/core/roles.d.ts +98 -0
  139. package/build/src/core/roles.js +447 -0
  140. package/build/src/core/saved_views.d.ts +37 -0
  141. package/build/src/core/saved_views.js +164 -0
  142. package/build/src/core/settings.d.ts +29 -0
  143. package/build/src/core/settings.js +113 -0
  144. package/build/src/core/setup.d.ts +14 -0
  145. package/build/src/core/setup.js +89 -0
  146. package/build/src/core/ui_preferences.d.ts +12 -0
  147. package/build/src/core/ui_preferences.js +30 -0
  148. package/build/src/core/user_invitations.d.ts +23 -0
  149. package/build/src/core/user_invitations.js +144 -0
  150. package/build/src/core/users.d.ts +44 -0
  151. package/build/src/core/users.js +182 -0
  152. package/build/src/database/configure.d.ts +3 -0
  153. package/build/src/database/configure.js +41 -0
  154. package/build/src/database/schema.d.ts +52 -0
  155. package/build/src/database/schema.js +538 -0
  156. package/build/src/eslint/index.d.ts +3 -0
  157. package/build/src/eslint/index.js +90 -0
  158. package/build/src/events/adonis_jobs.d.ts +9 -0
  159. package/build/src/events/adonis_jobs.js +13 -0
  160. package/build/src/events/outbox.d.ts +19 -0
  161. package/build/src/events/outbox.js +33 -0
  162. package/build/src/events/record_mutation.d.ts +24 -0
  163. package/build/src/events/record_mutation.js +62 -0
  164. package/build/src/integrations/imports.d.ts +74 -0
  165. package/build/src/integrations/imports.js +333 -0
  166. package/build/src/integrations/inbound_webhooks.d.ts +94 -0
  167. package/build/src/integrations/inbound_webhooks.js +276 -0
  168. package/build/src/integrations/openapi.d.ts +39 -0
  169. package/build/src/integrations/openapi.js +323 -0
  170. package/build/src/integrations/print.d.ts +37 -0
  171. package/build/src/integrations/print.js +124 -0
  172. package/build/src/integrations/webhooks.d.ts +98 -0
  173. package/build/src/integrations/webhooks.js +298 -0
  174. package/build/src/mcp/tools.d.ts +8 -0
  175. package/build/src/mcp/tools.js +156 -0
  176. package/build/src/org/org_service.d.ts +2 -0
  177. package/build/src/org/org_service.js +16 -0
  178. package/build/src/resource/define_resource.d.ts +5 -0
  179. package/build/src/resource/define_resource.js +68 -0
  180. package/build/src/resource/registry.d.ts +12 -0
  181. package/build/src/resource/registry.js +101 -0
  182. package/build/src/resource/types.d.ts +155 -0
  183. package/build/src/resource/types.js +1 -0
  184. package/build/src/resource/values.d.ts +5 -0
  185. package/build/src/resource/values.js +88 -0
  186. package/build/src/services/backup.d.ts +14 -0
  187. package/build/src/services/backup.js +59 -0
  188. package/build/src/services/settings.d.ts +21 -0
  189. package/build/src/services/settings.js +30 -0
  190. package/build/src/upgrade/legacy.d.ts +27 -0
  191. package/build/src/upgrade/legacy.js +58 -0
  192. package/build/src/upgrade/rename.d.ts +17 -0
  193. package/build/src/upgrade/rename.js +94 -0
  194. package/build/src/version.d.ts +1 -0
  195. package/build/src/version.js +2 -0
  196. package/build/src/workflows/define_workflow.d.ts +124 -0
  197. package/build/src/workflows/define_workflow.js +123 -0
  198. package/build/src/workflows/engine.d.ts +141 -0
  199. package/build/src/workflows/engine.js +752 -0
  200. package/build/stubs/README.md +6 -0
  201. package/build/stubs/controller.stub +8 -0
  202. package/build/stubs/main.d.ts +5 -0
  203. package/build/stubs/main.js +5 -0
  204. package/build/stubs/main.ts +5 -0
  205. package/build/stubs/modules.stub +6 -0
  206. package/build/stubs/resource_contract.stub +1 -0
  207. package/build/stubs/resource_contract.txt +452 -0
  208. package/build/stubs/routes.stub +16 -0
  209. package/build/stubs/service.stub +9 -0
  210. package/package.json +95 -3
@@ -0,0 +1,105 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ import { readFile, writeFile, access } from 'node:fs/promises';
3
+ import { Settings } from '../src/services/settings.js';
4
+ import { seedModules } from '../src/core/module_seed.js';
5
+ import { syncAgentAssets } from '../src/commands/agent_assets.js';
6
+ import { GAPS_TEMPLATE } from '../src/commands/gap_report.js';
7
+ import { ADULA_VERSION } from '../src/version.js';
8
+ import { fileURLToPath } from 'node:url';
9
+ export default class Install extends BaseCommand {
10
+ static commandName = 'adula:install';
11
+ static description = 'Install core organization, administrator role and managed agent instructions after migrations';
12
+ static options = { startApp: true };
13
+ async run() {
14
+ const { default: db } = await import('@adonisjs/lucid/services/db');
15
+ const knex = db.connection().getWriteClient();
16
+ const email = process.env.ADULA_ADMIN_EMAIL;
17
+ if (!email)
18
+ throw new Error('Set ADULA_ADMIN_EMAIL to an existing user email. Create the user through the official auth flow first.');
19
+ const user = await knex('users').where({ email }).first('id');
20
+ if (!user)
21
+ throw new Error('Administrator user does not exist. Create it using the official signup flow first.');
22
+ await knex.transaction(async (trx) => {
23
+ await trx.raw('SELECT pg_advisory_xact_lock(717011)');
24
+ let root = await trx('org_units').whereNull('parent_id').first();
25
+ if (!root) {
26
+ const [created] = await trx('org_units')
27
+ .insert({ name: 'الجهة', type: 'root', path: 'root' })
28
+ .returning('*');
29
+ await trx('org_units')
30
+ .where('id', created.id)
31
+ .update({ path: String(created.id) });
32
+ root = created;
33
+ }
34
+ let role = await trx('roles').where('name', 'administrator').first();
35
+ if (!role) {
36
+ const [created] = await trx('roles')
37
+ .insert({ name: 'administrator', key: 'administrator', permission_level: 1 })
38
+ .returning('*');
39
+ role = created;
40
+ }
41
+ else if (!role.key && !(await trx('roles').where('key', 'administrator').first()))
42
+ await trx('roles').where('id', role.id).update({ key: 'administrator' });
43
+ // Repair a missing bootstrap grant even when the role already exists.
44
+ // The transaction lock makes repeated/concurrent installation idempotent.
45
+ if (!(await trx('role_rules')
46
+ .where({ role_id: role.id, subject: 'all', action: 'manage', inverted: false })
47
+ .whereNull('conditions')
48
+ .whereNull('fields')
49
+ .first()))
50
+ await trx('role_rules').insert({ role_id: role.id, subject: 'all', action: 'manage' });
51
+ if (!(await trx('user_roles')
52
+ .where({ user_id: user.id, role_id: role.id })
53
+ .whereNull('org_unit_id')
54
+ .first()))
55
+ await trx('user_roles').insert({ user_id: user.id, role_id: role.id });
56
+ await trx('user_org_units')
57
+ .insert({ user_id: user.id, org_unit_id: root.id })
58
+ .onConflict(['user_id', 'org_unit_id'])
59
+ .ignore();
60
+ await new Settings(trx).set('adula.version', ADULA_VERSION);
61
+ });
62
+ // Module lookups and default roles: added when missing, never overwritten.
63
+ let registry;
64
+ try {
65
+ ;
66
+ ({ registry } = await this.app.import('#start/modules'));
67
+ }
68
+ catch (error) {
69
+ this.logger.warning(`Module defaults skipped: ${error.message}`);
70
+ }
71
+ if (registry) {
72
+ const seeded = await seedModules(knex, registry, user.id);
73
+ this.logger.info(`Module defaults: ${seeded.lookups} lookup rows added; roles created: ${seeded.created.join(', ') || 'none'}; adopted by name: ${seeded.adopted.join(', ') || 'none'}`);
74
+ }
75
+ for (const [name, content] of [
76
+ ['CLAUDE.md', 'Read and follow AGENTS.md.\nThe project rules are maintained there.\n'],
77
+ ['GAPS.md', GAPS_TEMPLATE],
78
+ ]) {
79
+ const path = this.app.makePath(name);
80
+ try {
81
+ await access(path);
82
+ }
83
+ catch {
84
+ await writeFile(path, content, { flag: 'wx' });
85
+ }
86
+ }
87
+ await syncAgentAssets(fileURLToPath(this.app.appRoot));
88
+ const pkg = JSON.parse(await readFile(this.app.makePath('package.json'), 'utf8'));
89
+ let uiInstalled = false;
90
+ try {
91
+ await access(this.app.makePath('ui.lock.json'));
92
+ uiInstalled = true;
93
+ }
94
+ catch (error) {
95
+ if (error.code !== 'ENOENT')
96
+ throw error;
97
+ }
98
+ if (pkg.dependencies?.['@adula/ui'] && !uiInstalled) {
99
+ const ui = await this.kernel.exec('adula:ui', ['add', 'all']);
100
+ if (ui.exitCode)
101
+ throw new Error('UI installation failed; existing project customizations require review');
102
+ }
103
+ this.logger.success('Core installation complete. Run adula:doctor.');
104
+ }
105
+ }
@@ -0,0 +1,8 @@
1
+ import Resource from './resource.js';
2
+ import Doctor from './doctor.js';
3
+ import ModuleAdd from './module_add.js';
4
+ import Ui from './ui.js';
5
+ export declare function getMetaData(): Promise<import("@adonisjs/core/types/ace").CommandMetaData[]>;
6
+ export declare function getCommand(meta: {
7
+ commandName: string;
8
+ }): Promise<typeof Resource | typeof Doctor | typeof ModuleAdd | typeof Ui | null>;
@@ -0,0 +1,33 @@
1
+ import Resource from './resource.js';
2
+ import ResourceSnapshot from './resource_snapshot.js';
3
+ import Doctor from './doctor.js';
4
+ import Install from './install.js';
5
+ import Capabilities from './capabilities.js';
6
+ import ModuleAdd from './module_add.js';
7
+ import ModuleRemove from './module_remove.js';
8
+ import Ui from './ui.js';
9
+ import StorageMigrate from './storage_migrate.js';
10
+ import Gaps from './gaps.js';
11
+ import Upgrade from './upgrade.js';
12
+ const commands = [
13
+ Resource,
14
+ ResourceSnapshot,
15
+ Doctor,
16
+ Install,
17
+ Capabilities,
18
+ ModuleAdd,
19
+ ModuleRemove,
20
+ Ui,
21
+ StorageMigrate,
22
+ Gaps,
23
+ Upgrade,
24
+ ];
25
+ export async function getMetaData() {
26
+ return commands.map((command) => {
27
+ command.boot();
28
+ return command.serialize();
29
+ });
30
+ }
31
+ export async function getCommand(meta) {
32
+ return commands.find((command) => command.commandName === meta.commandName) ?? null;
33
+ }
@@ -0,0 +1,8 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ export default class ModuleAdd extends BaseCommand {
3
+ static commandName: string;
4
+ static description: string;
5
+ name: string;
6
+ reference: boolean;
7
+ run(): Promise<void>;
8
+ }
@@ -0,0 +1,57 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, args, flags } from '@adonisjs/core/ace';
8
+ import { mkdir, readFile, writeFile, access } from 'node:fs/promises';
9
+ import { identifier } from '../src/resource/define_resource.js';
10
+ import { appendMarkedItem, moduleSource } from '../src/commands/source_markers.js';
11
+ export default class ModuleAdd extends BaseCommand {
12
+ static commandName = 'adula:module:add';
13
+ static description = 'Create and register an application-owned module';
14
+ async run() {
15
+ identifier(this.name);
16
+ if (this.app.inProduction)
17
+ throw new Error('Generate modules in the source checkout, not in production');
18
+ const path = this.app.makePath('app/modules', this.name);
19
+ try {
20
+ await access(path);
21
+ throw new Error(`Module directory already exists: ${this.name}`);
22
+ }
23
+ catch (error) {
24
+ if (error.code !== 'ENOENT')
25
+ throw error;
26
+ }
27
+ const indexPath = this.app.makePath('start/modules.ts');
28
+ const source = await readFile(indexPath, 'utf8');
29
+ if (!source.includes('// adula:imports'))
30
+ throw new Error('Module index registration markers are missing');
31
+ const alias = `module_${this.name}`;
32
+ const next = appendMarkedItem(source.replace('// adula:imports', `import ${alias} from '#modules/${this.name}/module'\n// adula:imports`), '/* adula:modules */', alias);
33
+ for (const directory of [
34
+ 'models',
35
+ 'resources',
36
+ 'validators',
37
+ 'migrations',
38
+ 'factories',
39
+ 'listeners',
40
+ 'jobs',
41
+ 'workflows',
42
+ 'reports',
43
+ 'pages',
44
+ 'tests',
45
+ ])
46
+ await mkdir(this.app.makePath('app/modules', this.name, directory), { recursive: true });
47
+ await writeFile(this.app.makePath('app/modules', this.name, 'module.ts'), moduleSource(this.name, { reference: Boolean(this.reference), typed: true }), { flag: 'wx' });
48
+ await writeFile(indexPath, next);
49
+ this.logger.success(`Created ${this.name}. Fill bilingual labels and declare dependencies before adding resources.`);
50
+ }
51
+ }
52
+ __decorate([
53
+ args.string()
54
+ ], ModuleAdd.prototype, "name", void 0);
55
+ __decorate([
56
+ flags.boolean({ description: 'Mark a disposable reference module' })
57
+ ], ModuleAdd.prototype, "reference", void 0);
@@ -0,0 +1,10 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ export default class ModuleRemove extends BaseCommand {
3
+ static commandName: string;
4
+ static description: string;
5
+ static options: {
6
+ startApp: boolean;
7
+ };
8
+ name: string;
9
+ run(): Promise<void>;
10
+ }
@@ -0,0 +1,94 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, args } from '@adonisjs/core/ace';
8
+ import { mkdir, rename, realpath, lstat, readdir } from 'node:fs/promises';
9
+ import { dirname, join, relative, isAbsolute } from 'node:path';
10
+ import { identifier } from '../src/resource/define_resource.js';
11
+ export default class ModuleRemove extends BaseCommand {
12
+ static commandName = 'adula:module:remove';
13
+ static description = 'Unregister and archive a reference module; preserve its database tables';
14
+ static options = { startApp: true };
15
+ async run() {
16
+ identifier(this.name);
17
+ if (this.app.inProduction)
18
+ throw new Error('Remove reference modules in the source checkout, not in production');
19
+ const { modules } = await this.app.import('#start/modules');
20
+ const module = modules.find((entry) => entry.name === this.name);
21
+ if (!module?.reference)
22
+ throw new Error('Only modules explicitly marked reference: true can be removed');
23
+ const dependents = modules.filter((entry) => entry.dependsOn.includes(this.name));
24
+ if (dependents.length)
25
+ throw new Error(`Remove dependent reference modules first: ${dependents.map((entry) => entry.name).join(', ')}`);
26
+ const root = await realpath(this.app.makePath());
27
+ const path = this.app.makePath('app/modules', this.name);
28
+ const actual = await realpath(path);
29
+ const inside = relative(root, actual);
30
+ const directoryInfo = await lstat(path);
31
+ if (directoryInfo.isSymbolicLink() || inside.startsWith('..') || isAbsolute(inside))
32
+ throw new Error('Refusing to move a module outside the application');
33
+ const codemods = await this.createCodemods();
34
+ const project = await codemods.getTsMorphProject();
35
+ if (!project)
36
+ throw new Error('Module removal requires @adonisjs/assembler');
37
+ const source = project.addSourceFileAtPathIfExists(this.app.makePath('start/modules.ts'));
38
+ const imported = source.getImportDeclaration(`#modules/${this.name}/module`);
39
+ const alias = imported?.getDefaultImport()?.getText();
40
+ const declaration = source.getVariableDeclaration('modules')?.getInitializer();
41
+ if (!alias || !declaration || !('getElements' in declaration))
42
+ throw new Error('Expected a literal module registry; no files were changed');
43
+ const array = declaration;
44
+ const index = array.getElements().findIndex((element) => element.getText() === alias);
45
+ if (index < 0)
46
+ throw new Error('Module import is not a literal registry item; no files were changed');
47
+ array.removeElement(index);
48
+ imported.remove();
49
+ const archive = this.app.tmpPath('adula-removed', `${this.name}-${Date.now()}`);
50
+ await mkdir(dirname(archive), { recursive: true });
51
+ const archiveParent = relative(root, await realpath(dirname(archive)));
52
+ if (archiveParent.startsWith('..') || isAbsolute(archiveParent))
53
+ throw new Error('Archive must stay inside the application');
54
+ const moves = [];
55
+ const move = async (from, to) => {
56
+ await rename(from, to);
57
+ moves.push([from, to]);
58
+ };
59
+ // No delete and no database mutation. Archived source receives .bak suffixes so it is not compiled.
60
+ const preserve = async (directory) => {
61
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
62
+ const file = join(directory, entry.name);
63
+ if (entry.isDirectory())
64
+ await preserve(file);
65
+ else if (entry.isFile() && /\.(ts|tsx|js|jsx)$/.test(entry.name))
66
+ await move(file, `${file}.bak`);
67
+ }
68
+ };
69
+ try {
70
+ await move(path, archive);
71
+ await preserve(archive);
72
+ for (const resource of module.resources) {
73
+ const testPath = this.app.makePath('tests/functional', `${identifier(resource.name)}.spec.ts`);
74
+ try {
75
+ await move(testPath, join(archive, `${resource.name}.spec.ts.bak`));
76
+ }
77
+ catch (error) {
78
+ if (error.code !== 'ENOENT')
79
+ throw error;
80
+ }
81
+ }
82
+ await source.save();
83
+ }
84
+ catch (error) {
85
+ for (const [from, to] of moves.reverse())
86
+ await rename(to, from);
87
+ throw error;
88
+ }
89
+ this.logger.success(`Unregistered ${this.name}; source archived at ${archive}. Database tables and migration history were preserved.`);
90
+ }
91
+ }
92
+ __decorate([
93
+ args.string()
94
+ ], ModuleRemove.prototype, "name", void 0);
@@ -0,0 +1,8 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ export default class Resource extends BaseCommand {
3
+ static commandName: string;
4
+ static description: string;
5
+ name: string;
6
+ module: string;
7
+ run(): Promise<void>;
8
+ }
@@ -0,0 +1,29 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, args, flags } from '@adonisjs/core/ace';
8
+ import { generateResource } from '../src/commands/generator.js';
9
+ import { fileURLToPath } from 'node:url';
10
+ export default class Resource extends BaseCommand {
11
+ static commandName = 'adula:resource';
12
+ static description = 'Generate a scoped resource, migration, model, validator, factory and security contract';
13
+ async run() {
14
+ if (!this.module) {
15
+ this.logger.error('--module is required');
16
+ this.exitCode = 1;
17
+ return;
18
+ }
19
+ const files = await generateResource(fileURLToPath(this.app.appRoot), this.name, this.module);
20
+ files.forEach((file) => this.logger.success(file));
21
+ this.logger.info('Set bilingual labels (label: the plural list heading; recordLabel: the singular record noun) and fill the resource definition. The generated migration embeds the definition as scaffolded: after filling the definition, run `node ace adula:resource:snapshot <name>` to refresh the pending migration, and update the model, factory and contract fixture, before migration:run. adula:doctor reports a pending migration that differs. Then run the generated security contract.');
22
+ }
23
+ }
24
+ __decorate([
25
+ args.string()
26
+ ], Resource.prototype, "name", void 0);
27
+ __decorate([
28
+ flags.string()
29
+ ], Resource.prototype, "module", void 0);
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ /**
3
+ * Rewrites the definition embedded in a resource's generated create-migration from the
4
+ * current resource, while that migration has not run yet (#20). A migration that already
5
+ * ran is never edited: change the table with a new expand migration instead.
6
+ */
7
+ export default class ResourceSnapshot extends BaseCommand {
8
+ static commandName: string;
9
+ static description: string;
10
+ static options: {
11
+ startApp: boolean;
12
+ };
13
+ name: string;
14
+ run(): Promise<void>;
15
+ }
@@ -0,0 +1,61 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, args } from '@adonisjs/core/ace';
8
+ import { readFile, writeFile } from 'node:fs/promises';
9
+ import { MigrationRunner } from '@adonisjs/lucid/migration';
10
+ import { embeddedResource, resourceSnapshot, rewriteResourceSnapshot, } from '../src/commands/snapshot.js';
11
+ /**
12
+ * Rewrites the definition embedded in a resource's generated create-migration from the
13
+ * current resource, while that migration has not run yet (#20). A migration that already
14
+ * ran is never edited: change the table with a new expand migration instead.
15
+ */
16
+ export default class ResourceSnapshot extends BaseCommand {
17
+ static commandName = 'adula:resource:snapshot';
18
+ static description = "Refresh a pending generated create-migration from the resource's current definition";
19
+ static options = { startApp: true };
20
+ async run() {
21
+ const { default: db } = await import('@adonisjs/lucid/services/db');
22
+ const { registry } = (await this.app.import('#start/modules'));
23
+ let resource;
24
+ try {
25
+ resource = registry.get(this.name);
26
+ }
27
+ catch {
28
+ this.logger.error(`Unknown resource: ${this.name}. Register it in its module first.`);
29
+ this.exitCode = 1;
30
+ return;
31
+ }
32
+ const migrations = await new MigrationRunner(db, this.app, { direction: 'up' }).getList();
33
+ const matches = [];
34
+ for (const entry of migrations)
35
+ for (const extension of ['.ts', '.js'])
36
+ try {
37
+ const file = `${entry.name}${extension}`;
38
+ const source = await readFile(this.app.makePath(file), 'utf8');
39
+ if (embeddedResource(source) === this.name)
40
+ matches.push({ file, source, pending: entry.status === 'pending' });
41
+ break;
42
+ }
43
+ catch { }
44
+ const pending = matches.filter((match) => match.pending);
45
+ if (!pending.length) {
46
+ this.logger.error(matches.length
47
+ ? `${matches[0].file} already ran; never edit it. Add an expand migration for the new columns instead.`
48
+ : `No generated create-migration embeds ${this.name}.`);
49
+ this.exitCode = 1;
50
+ return;
51
+ }
52
+ for (const match of pending) {
53
+ await writeFile(this.app.makePath(match.file), rewriteResourceSnapshot(match.source, resourceSnapshot(resource)));
54
+ this.logger.success(match.file);
55
+ }
56
+ this.logger.info('Update the model, factory and contract fixture to the same fields, then run migration:run.');
57
+ }
58
+ }
59
+ __decorate([
60
+ args.string({ description: 'Resource name' })
61
+ ], ResourceSnapshot.prototype, "name", void 0);
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ export default class StorageMigrate extends BaseCommand {
3
+ static commandName: string;
4
+ static description: string;
5
+ static options: {
6
+ startApp: boolean;
7
+ };
8
+ from: string;
9
+ to: string;
10
+ dryRun: boolean;
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,39 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, args, flags } from '@adonisjs/core/ace';
8
+ import { migrateStorage } from '../src/attachments/storage_migrate.js';
9
+ export default class StorageMigrate extends BaseCommand {
10
+ static commandName = 'adula:storage:migrate';
11
+ static description = 'Copy attachment files from one Drive disk to another and repoint their rows';
12
+ static options = { startApp: true };
13
+ async run() {
14
+ const { default: db } = await import('@adonisjs/lucid/services/db');
15
+ const { default: drive } = await import('@adonisjs/drive/services/main');
16
+ const { configProvider } = await import('@adonisjs/core');
17
+ const resolved = await configProvider.resolve(this.app, this.app.config.get('drive'));
18
+ const result = await migrateStorage(db.connection().getWriteClient(), {
19
+ from: this.from,
20
+ to: this.to,
21
+ disks: Object.keys(resolved?.config.services ?? {}),
22
+ dryRun: Boolean(this.dryRun),
23
+ use: (name) => drive.use(name),
24
+ report: (line) => this.logger.info(line),
25
+ });
26
+ this.logger.log(JSON.stringify(result));
27
+ if (result.failed.length)
28
+ this.exitCode = 1;
29
+ }
30
+ }
31
+ __decorate([
32
+ args.string({ description: 'Source disk name' })
33
+ ], StorageMigrate.prototype, "from", void 0);
34
+ __decorate([
35
+ args.string({ description: 'Target disk name' })
36
+ ], StorageMigrate.prototype, "to", void 0);
37
+ __decorate([
38
+ flags.boolean({ description: 'List the files that would move without copying anything' })
39
+ ], StorageMigrate.prototype, "dryRun", void 0);
@@ -0,0 +1,11 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ export default class Ui extends BaseCommand {
3
+ static commandName: string;
4
+ static description: string;
5
+ action: string;
6
+ component: string;
7
+ preview: boolean;
8
+ accept: boolean;
9
+ run(): Promise<void>;
10
+ private initialize;
11
+ }