adula 2.1.0 → 2.3.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.
- package/README.md +149 -18
- package/build/agent/AGENTS.template.md +4 -4
- package/build/agent/capabilities.md +22 -12
- package/build/agent/skills/adula-frontend-design/SKILL.md +6 -4
- package/build/agent/skills/idea-review/SKILL.md +2 -2
- package/build/commands/adula_assistant_prune.d.ts +10 -0
- package/build/commands/adula_assistant_prune.js +12 -0
- package/build/commands/adula_outbox.d.ts +10 -0
- package/build/commands/adula_outbox.js +11 -0
- package/build/commands/adula_restore_reconcile.d.ts +10 -0
- package/build/commands/adula_restore_reconcile.js +34 -0
- package/build/commands/adula_runtime_health.d.ts +10 -0
- package/build/commands/adula_runtime_health.js +27 -0
- package/build/commands/adula_uploads_prune.d.ts +10 -0
- package/build/commands/adula_uploads_prune.js +16 -0
- package/build/commands/app.d.ts +10 -0
- package/build/commands/app.js +64 -0
- package/build/commands/backup_create.d.ts +11 -0
- package/build/commands/backup_create.js +99 -0
- package/build/commands/backup_open.d.ts +16 -0
- package/build/commands/backup_open.js +48 -0
- package/build/commands/backup_restore_files.d.ts +11 -0
- package/build/commands/backup_restore_files.js +44 -0
- package/build/commands/backup_restore_test.d.ts +12 -0
- package/build/commands/backup_restore_test.js +188 -0
- package/build/commands/backup_seal.d.ts +12 -0
- package/build/commands/backup_seal.js +36 -0
- package/build/commands/backup_services.d.ts +33 -0
- package/build/commands/backup_services.js +6 -0
- package/build/commands/backup_verify.d.ts +9 -0
- package/build/commands/backup_verify.js +59 -0
- package/build/commands/backup_verify_snapshot.d.ts +10 -0
- package/build/commands/backup_verify_snapshot.js +37 -0
- package/build/commands/client.d.ts +16 -0
- package/build/commands/client.js +71 -0
- package/build/commands/doctor.js +21 -1
- package/build/commands/install.d.ts +8 -0
- package/build/commands/install.js +69 -45
- package/build/commands/main.d.ts +3 -2
- package/build/commands/main.js +32 -0
- package/build/commands/module_add.js +4 -20
- package/build/commands/resource.d.ts +2 -0
- package/build/commands/resource.js +12 -3
- package/build/commands/resource_migration.d.ts +15 -0
- package/build/commands/resource_migration.js +81 -0
- package/build/commands/resource_snapshot.d.ts +2 -0
- package/build/commands/resource_snapshot.js +21 -4
- package/build/commands/sla_evaluate.d.ts +14 -0
- package/build/commands/sla_evaluate.js +16 -0
- package/build/commands/ui.js +4 -2
- package/build/commands/ui_css.d.ts +9 -0
- package/build/commands/ui_css.js +19 -0
- package/build/commands/upgrade.d.ts +1 -1
- package/build/commands/upgrade.js +1 -1
- package/build/configure.js +1 -1
- package/build/database/migrations/1770000000020_two_factor.d.ts +5 -0
- package/build/database/migrations/1770000000020_two_factor.js +10 -0
- package/build/database/migrations/1770000000041_import_modes.d.ts +5 -0
- package/build/database/migrations/1770000000041_import_modes.js +10 -0
- package/build/database/migrations/1770000000042_sync_jobs.d.ts +5 -0
- package/build/database/migrations/1770000000042_sync_jobs.js +10 -0
- package/build/database/migrations/1770000000043_notification_channels.d.ts +5 -0
- package/build/database/migrations/1770000000043_notification_channels.js +10 -0
- package/build/database/migrations/1770000000044_channel_confirmations.d.ts +5 -0
- package/build/database/migrations/1770000000044_channel_confirmations.js +10 -0
- package/build/database/migrations/1770000000045_import_leases.d.ts +5 -0
- package/build/database/migrations/1770000000045_import_leases.js +10 -0
- package/build/database/migrations/1770000000046_workflow_delegation_sla.d.ts +5 -0
- package/build/database/migrations/1770000000046_workflow_delegation_sla.js +10 -0
- package/build/database/migrations/1770000000049_print_templates.d.ts +5 -0
- package/build/database/migrations/1770000000049_print_templates.js +10 -0
- package/build/database/migrations/1770000000051_comment_notifications.d.ts +5 -0
- package/build/database/migrations/1770000000051_comment_notifications.js +10 -0
- package/build/database/migrations/1770000000054_cloud_backups.d.ts +5 -0
- package/build/database/migrations/1770000000054_cloud_backups.js +10 -0
- package/build/database/migrations/1770000000055_ai_assistant.d.ts +5 -0
- package/build/database/migrations/1770000000055_ai_assistant.js +10 -0
- package/build/database/migrations/1770000000056_appearance.d.ts +5 -0
- package/build/database/migrations/1770000000056_appearance.js +10 -0
- package/build/index.d.ts +87 -11
- package/build/index.js +50 -7
- package/build/providers/adula_provider.d.ts +2 -0
- package/build/providers/adula_provider.js +7 -0
- package/build/src/admin/contracts.js +1 -1
- package/build/src/admin/controller.d.ts +14 -1
- package/build/src/admin/controller.js +91 -13
- package/build/src/admin/errors.d.ts +32 -0
- package/build/src/admin/errors.js +63 -1
- package/build/src/admin/presentation.d.ts +21 -2
- package/build/src/admin/resource/editor.d.ts +60 -0
- package/build/src/admin/resource/editor.js +345 -0
- package/build/src/admin/resource/export.d.ts +54 -0
- package/build/src/admin/resource/export.js +262 -0
- package/build/src/admin/resource/lifecycle.d.ts +23 -0
- package/build/src/admin/resource/lifecycle.js +91 -0
- package/build/src/admin/resource/query.d.ts +111 -0
- package/build/src/admin/resource/query.js +595 -0
- package/build/src/admin/resource/read.d.ts +109 -0
- package/build/src/admin/resource/read.js +388 -0
- package/build/src/admin/resource/shared.d.ts +93 -0
- package/build/src/admin/resource/shared.js +265 -0
- package/build/src/admin/resource/trash.d.ts +10 -0
- package/build/src/admin/resource/trash.js +56 -0
- package/build/src/admin/resource/write.d.ts +57 -0
- package/build/src/admin/resource/write.js +603 -0
- package/build/src/admin/resource_service.d.ts +80 -193
- package/build/src/admin/resource_service.js +81 -1343
- package/build/src/admin/resource_tools.d.ts +111 -0
- package/build/src/admin/resource_tools.js +139 -0
- package/build/src/ai/assistant.d.ts +100 -0
- package/build/src/ai/assistant.js +487 -0
- package/build/src/ai/client.d.ts +49 -0
- package/build/src/ai/client.js +85 -0
- package/build/src/ai/prompt.d.ts +23 -0
- package/build/src/ai/prompt.js +83 -0
- package/build/src/ai/settings.d.ts +56 -0
- package/build/src/ai/settings.js +214 -0
- package/build/src/ai/usage.d.ts +16 -0
- package/build/src/ai/usage.js +33 -0
- package/build/src/appearance/appearance.d.ts +134 -0
- package/build/src/appearance/appearance.js +461 -0
- package/build/src/appearance/colors.d.ts +43 -0
- package/build/src/appearance/colors.js +99 -0
- package/build/src/appearance/logo.d.ts +32 -0
- package/build/src/appearance/logo.js +112 -0
- package/build/src/attachments/attachment_service.d.ts +46 -2
- package/build/src/attachments/attachment_service.js +96 -4
- package/build/src/auth/actor_store.d.ts +5 -1
- package/build/src/auth/actor_store.js +8 -4
- package/build/src/auth/conditions.d.ts +5 -0
- package/build/src/auth/conditions.js +26 -3
- package/build/src/auth/sql.js +17 -5
- package/build/src/auth/two_factor.d.ts +96 -0
- package/build/src/auth/two_factor.js +259 -0
- package/build/src/backups/archive.d.ts +52 -0
- package/build/src/backups/archive.js +362 -0
- package/build/src/backups/cloud_backups.d.ts +133 -0
- package/build/src/backups/cloud_backups.js +650 -0
- package/build/src/backups/doctor.d.ts +7 -0
- package/build/src/backups/doctor.js +55 -0
- package/build/src/backups/providers.d.ts +81 -0
- package/build/src/backups/providers.js +470 -0
- package/build/src/collaboration/assignments.d.ts +59 -2
- package/build/src/collaboration/assignments.js +196 -74
- package/build/src/collaboration/record_collaboration.d.ts +21 -4
- package/build/src/collaboration/record_collaboration.js +126 -51
- package/build/src/collaboration/shared.d.ts +24 -0
- package/build/src/collaboration/shared.js +34 -0
- package/build/src/commands/app_scaffold.d.ts +72 -0
- package/build/src/commands/app_scaffold.js +285 -0
- package/build/src/commands/capabilities.js +35 -9
- package/build/src/commands/doctor.d.ts +24 -2
- package/build/src/commands/doctor.js +81 -6
- package/build/src/commands/gap_report.d.ts +1 -1
- package/build/src/commands/gap_report.js +2 -2
- package/build/src/commands/generator.d.ts +37 -1
- package/build/src/commands/generator.js +61 -18
- package/build/src/commands/snapshot.d.ts +24 -13
- package/build/src/commands/snapshot.js +54 -14
- package/build/src/commands/source_markers.d.ts +10 -0
- package/build/src/commands/source_markers.js +29 -0
- package/build/src/core/activity.d.ts +2 -0
- package/build/src/core/activity.js +7 -1
- package/build/src/core/administrators.d.ts +38 -0
- package/build/src/core/administrators.js +145 -0
- package/build/src/core/avatar_image.d.ts +33 -0
- package/build/src/core/avatar_image.js +278 -0
- package/build/src/core/html_sanitizer.d.ts +20 -0
- package/build/src/core/html_sanitizer.js +261 -0
- package/build/src/core/like.d.ts +5 -0
- package/build/src/core/like.js +5 -0
- package/build/src/core/lookups.d.ts +80 -0
- package/build/src/core/lookups.js +319 -0
- package/build/src/core/mail_settings.d.ts +83 -0
- package/build/src/core/mail_settings.js +274 -0
- package/build/src/core/mail_test.d.ts +16 -0
- package/build/src/core/mail_test.js +81 -6
- package/build/src/core/message_templates.d.ts +15 -2
- package/build/src/core/message_templates.js +81 -11
- package/build/src/core/module_seed.js +2 -1
- package/build/src/core/notification_channels.d.ts +235 -0
- package/build/src/core/notification_channels.js +660 -0
- package/build/src/core/roles.js +26 -9
- package/build/src/core/saved_views.d.ts +8 -1
- package/build/src/core/saved_views.js +91 -26
- package/build/src/core/sequences.d.ts +32 -0
- package/build/src/core/sequences.js +97 -0
- package/build/src/core/settings.d.ts +5 -0
- package/build/src/core/settings.js +31 -3
- package/build/src/core/template_language.d.ts +61 -0
- package/build/src/core/template_language.js +141 -0
- package/build/src/core/ui_preferences.d.ts +10 -0
- package/build/src/core/ui_preferences.js +15 -1
- package/build/src/core/user_avatars.d.ts +79 -0
- package/build/src/core/user_avatars.js +186 -0
- package/build/src/core/user_invitations.d.ts +5 -1
- package/build/src/core/user_invitations.js +7 -1
- package/build/src/core/user_preferences.d.ts +36 -0
- package/build/src/core/user_preferences.js +125 -0
- package/build/src/core/users.d.ts +2 -0
- package/build/src/core/users.js +5 -3
- package/build/src/database/calendar_days.d.ts +19 -0
- package/build/src/database/calendar_days.js +36 -0
- package/build/src/database/schema.d.ts +201 -2
- package/build/src/database/schema.js +713 -59
- package/build/src/database/schema_diff.d.ts +70 -0
- package/build/src/database/schema_diff.js +190 -0
- package/build/src/events/record_mutation.d.ts +2 -1
- package/build/src/events/record_mutation.js +1 -0
- package/build/src/integrations/api_client.d.ts +37 -0
- package/build/src/integrations/api_client.js +567 -0
- package/build/src/integrations/import_adapters.d.ts +37 -0
- package/build/src/integrations/import_adapters.js +35 -0
- package/build/src/integrations/imports.d.ts +130 -16
- package/build/src/integrations/imports.js +434 -73
- package/build/src/integrations/openapi.d.ts +3 -1
- package/build/src/integrations/openapi.js +465 -31
- package/build/src/integrations/outbound.d.ts +94 -0
- package/build/src/integrations/outbound.js +276 -0
- package/build/src/integrations/print.d.ts +22 -1
- package/build/src/integrations/print.js +68 -22
- package/build/src/integrations/print_templates.d.ts +216 -0
- package/build/src/integrations/print_templates.js +1017 -0
- package/build/src/integrations/sync_jobs.d.ts +139 -0
- package/build/src/integrations/sync_jobs.js +416 -0
- package/build/src/integrations/webhooks.d.ts +12 -12
- package/build/src/integrations/webhooks.js +34 -43
- package/build/src/integrations/xlsx.d.ts +41 -0
- package/build/src/integrations/xlsx.js +519 -0
- package/build/src/languages/ar.d.ts +11 -0
- package/build/src/languages/ar.js +358 -0
- package/build/src/languages/ar_ui.d.ts +461 -0
- package/build/src/languages/ar_ui.js +464 -0
- package/build/src/languages/catalog.d.ts +66 -0
- package/build/src/languages/catalog.js +152 -0
- package/build/src/languages/en.d.ts +7 -0
- package/build/src/languages/en.js +352 -0
- package/build/src/languages/en_ui.d.ts +3 -0
- package/build/src/languages/en_ui.js +458 -0
- package/build/src/languages/validation.d.ts +26 -0
- package/build/src/languages/validation.js +60 -0
- package/build/src/lists/bulk_actions.d.ts +89 -0
- package/build/src/lists/bulk_actions.js +268 -0
- package/build/src/lists/dashboards.d.ts +138 -0
- package/build/src/lists/dashboards.js +290 -0
- package/build/src/mcp/tools.js +9 -104
- package/build/src/resource/define_resource.d.ts +18 -1
- package/build/src/resource/define_resource.js +212 -18
- package/build/src/resource/definition.d.ts +44 -0
- package/build/src/resource/definition.js +171 -0
- package/build/src/resource/registry.js +15 -4
- package/build/src/resource/types.d.ts +313 -16
- package/build/src/resource/values.d.ts +56 -1
- package/build/src/resource/values.js +237 -5
- package/build/src/services/settings.d.ts +2 -0
- package/build/src/services/settings.js +5 -1
- package/build/src/upgrade/legacy.js +2 -2
- package/build/src/workflows/calendar.d.ts +9 -0
- package/build/src/workflows/calendar.js +44 -0
- package/build/src/workflows/define_workflow.d.ts +48 -3
- package/build/src/workflows/define_workflow.js +57 -13
- package/build/src/workflows/delegations.d.ts +107 -0
- package/build/src/workflows/delegations.js +326 -0
- package/build/src/workflows/engine.d.ts +80 -4
- package/build/src/workflows/engine.js +466 -86
- package/build/src/workflows/sla.d.ts +15 -0
- package/build/src/workflows/sla.js +8 -0
- package/build/stubs/resource_contract.txt +12 -1
- package/package.json +9 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
/**
|
|
3
|
+
* Writes clients/<system>/index.ts, a typed API client of every registered resource
|
|
4
|
+
* (or of what one user may use), and its README with token usage.
|
|
5
|
+
*/
|
|
6
|
+
export default class Client extends BaseCommand {
|
|
7
|
+
static commandName: string;
|
|
8
|
+
static description: string;
|
|
9
|
+
static options: {
|
|
10
|
+
startApp: boolean;
|
|
11
|
+
};
|
|
12
|
+
asUser: number | undefined;
|
|
13
|
+
url: string | undefined;
|
|
14
|
+
output: string | undefined;
|
|
15
|
+
run(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { isAbsolute } from 'node:path';
|
|
10
|
+
import { ActorStore } from '../src/auth/actor_store.js';
|
|
11
|
+
import { openApiDocument } from '../src/integrations/openapi.js';
|
|
12
|
+
import { apiClientName, apiClientReadme, apiClientSource } from '../src/integrations/api_client.js';
|
|
13
|
+
import { ADULA_VERSION } from '../src/version.js';
|
|
14
|
+
/**
|
|
15
|
+
* Writes clients/<system>/index.ts, a typed API client of every registered resource
|
|
16
|
+
* (or of what one user may use), and its README with token usage.
|
|
17
|
+
*/
|
|
18
|
+
export default class Client extends BaseCommand {
|
|
19
|
+
static commandName = 'adula:client';
|
|
20
|
+
static description = 'Generate a typed TypeScript client of the bearer-token resource API in clients/<system>/';
|
|
21
|
+
static options = { startApp: true };
|
|
22
|
+
async run() {
|
|
23
|
+
const { registry } = (await this.app.import('#start/modules'));
|
|
24
|
+
let actor;
|
|
25
|
+
if (this.asUser !== undefined) {
|
|
26
|
+
if (!Number.isSafeInteger(this.asUser) || this.asUser <= 0) {
|
|
27
|
+
this.logger.error('--as-user must be a user id');
|
|
28
|
+
this.exitCode = 1;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
32
|
+
const knex = db.connection().getWriteClient();
|
|
33
|
+
if (!(await knex('users').where('id', this.asUser).first('id'))) {
|
|
34
|
+
this.logger.error(`No user with id ${this.asUser}`);
|
|
35
|
+
this.exitCode = 1;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
actor = await new ActorStore(knex, registry).load(this.asUser);
|
|
39
|
+
}
|
|
40
|
+
let name = 'app';
|
|
41
|
+
try {
|
|
42
|
+
name = apiClientName(JSON.parse(await readFile(this.app.makePath('package.json'), 'utf8')).name);
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
const document = openApiDocument(registry, {
|
|
46
|
+
title: name,
|
|
47
|
+
version: ADULA_VERSION,
|
|
48
|
+
serverUrl: this.url ?? process.env.APP_URL ?? 'http://localhost:3333',
|
|
49
|
+
actor,
|
|
50
|
+
});
|
|
51
|
+
const output = this.output ?? `clients/${name}`;
|
|
52
|
+
const directory = isAbsolute(output) ? output : this.app.makePath(output);
|
|
53
|
+
await mkdir(directory, { recursive: true });
|
|
54
|
+
await writeFile(`${directory}/index.ts`, apiClientSource(document));
|
|
55
|
+
await writeFile(`${directory}/README.md`, apiClientReadme(name, document));
|
|
56
|
+
this.logger.success(`${directory}/index.ts`);
|
|
57
|
+
this.logger.success(`${directory}/README.md`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
__decorate([
|
|
61
|
+
flags.number({
|
|
62
|
+
flagName: 'as-user',
|
|
63
|
+
description: 'Describe only what this user id may use (default: the full registry)',
|
|
64
|
+
})
|
|
65
|
+
], Client.prototype, "asUser", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
flags.string({ description: 'Default server URL in the client (default: APP_URL)' })
|
|
68
|
+
], Client.prototype, "url", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
flags.string({ description: 'Output directory (default: clients/<system name>)' })
|
|
71
|
+
], Client.prototype, "output", void 0);
|
package/build/commands/doctor.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { diagnose, diagnoseResourceSnapshots, diagnoseOutbox, diagnoseWorkflowRoles, } from '../src/commands/doctor.js';
|
|
3
|
+
import { diagnose, diagnoseResourceSnapshots, diagnoseResourceSchemas, diagnoseOutbox, diagnoseWorkflowRoles, diagnoseScopeParentRoles, } from '../src/commands/doctor.js';
|
|
4
4
|
import { runtimeHealth } from '../src/core/health.js';
|
|
5
5
|
import { diagnoseAttachments } from '../src/attachments/doctor.js';
|
|
6
|
+
import { diagnoseCloudBackups } from '../src/backups/doctor.js';
|
|
6
7
|
import { Settings } from '../src/services/settings.js';
|
|
7
8
|
import { MigrationRunner } from '@adonisjs/lucid/migration';
|
|
8
9
|
import { readFile } from 'node:fs/promises';
|
|
@@ -16,6 +17,7 @@ export default class Doctor extends BaseCommand {
|
|
|
16
17
|
const findings = await diagnose(fileURLToPath(this.app.appRoot), new Settings(db.connection().getWriteClient()), this.app.inProduction, process.env);
|
|
17
18
|
findings.push(await diagnoseAttachments(db.connection().getWriteClient()));
|
|
18
19
|
findings.push(diagnoseOutbox(await runtimeHealth(db.connection().getWriteClient())));
|
|
20
|
+
findings.push(...diagnoseCloudBackups(process.env));
|
|
19
21
|
const migrations = await new MigrationRunner(db, this.app, { direction: 'up' }).getList();
|
|
20
22
|
const missing = migrations.filter((entry) => entry.status === 'corrupt');
|
|
21
23
|
const pending = migrations.filter((entry) => entry.status === 'pending');
|
|
@@ -54,6 +56,21 @@ export default class Doctor extends BaseCommand {
|
|
|
54
56
|
key: role.key ? String(role.key) : null,
|
|
55
57
|
name: String(role.name),
|
|
56
58
|
}))));
|
|
59
|
+
const rules = await db
|
|
60
|
+
.from('role_rules as rr')
|
|
61
|
+
.join('roles as r', 'r.id', 'rr.role_id')
|
|
62
|
+
.select('r.name', 'rr.subject', 'rr.action', 'rr.inverted');
|
|
63
|
+
const byRole = new Map();
|
|
64
|
+
for (const rule of rules)
|
|
65
|
+
byRole.set(String(rule.name), [
|
|
66
|
+
...(byRole.get(String(rule.name)) ?? []),
|
|
67
|
+
{
|
|
68
|
+
subject: String(rule.subject),
|
|
69
|
+
action: String(rule.action),
|
|
70
|
+
inverted: Boolean(rule.inverted),
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
findings.push(diagnoseScopeParentRoles(registry.all(), [...byRole].map(([name, roleRules]) => ({ name, rules: roleRules }))));
|
|
57
74
|
}
|
|
58
75
|
if (registry)
|
|
59
76
|
findings.push(diagnoseResourceSnapshots(sources, (name) => {
|
|
@@ -64,6 +81,9 @@ export default class Doctor extends BaseCommand {
|
|
|
64
81
|
return undefined;
|
|
65
82
|
}
|
|
66
83
|
}));
|
|
84
|
+
// Tables of resources whose create-migration is still pending are reported missing.
|
|
85
|
+
if (registry)
|
|
86
|
+
findings.push(await diagnoseResourceSchemas(db.connection().getWriteClient(), registry.all()));
|
|
67
87
|
for (const finding of findings)
|
|
68
88
|
this.logger.log(`${finding.status.toUpperCase()} ${finding.check}: ${finding.message}`);
|
|
69
89
|
if (findings.some((finding) => finding.status === 'fail'))
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
/**
|
|
3
|
+
* Installs the core organization, administrator role and managed agent instructions.
|
|
4
|
+
* Creating or re-securing the first administrator requires the application's `#models/user`
|
|
5
|
+
* Lucid model (with `email`, `fullName` and a hashed `password`); it is loaded only then.
|
|
6
|
+
*/
|
|
2
7
|
export default class Install extends BaseCommand {
|
|
3
8
|
static commandName: string;
|
|
4
9
|
static description: string;
|
|
5
10
|
static options: {
|
|
6
11
|
startApp: boolean;
|
|
7
12
|
};
|
|
13
|
+
adminEmail?: string;
|
|
14
|
+
adminName?: string;
|
|
15
|
+
keepPassword?: boolean;
|
|
8
16
|
run(): Promise<void>;
|
|
9
17
|
}
|
|
@@ -1,64 +1,72 @@
|
|
|
1
|
-
|
|
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, flags } from '@adonisjs/core/ace';
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
2
9
|
import { readFile, writeFile, access } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
10
|
+
import { grantInstallAdministrator, resolveInstallAdministrator, } from '../src/core/administrators.js';
|
|
4
11
|
import { seedModules } from '../src/core/module_seed.js';
|
|
5
12
|
import { syncAgentAssets } from '../src/commands/agent_assets.js';
|
|
13
|
+
import { diagnoseScopeParentRoles } from '../src/commands/doctor.js';
|
|
6
14
|
import { GAPS_TEMPLATE } from '../src/commands/gap_report.js';
|
|
7
15
|
import { ADULA_VERSION } from '../src/version.js';
|
|
8
16
|
import { fileURLToPath } from 'node:url';
|
|
17
|
+
/**
|
|
18
|
+
* Installs the core organization, administrator role and managed agent instructions.
|
|
19
|
+
* Creating or re-securing the first administrator requires the application's `#models/user`
|
|
20
|
+
* Lucid model (with `email`, `fullName` and a hashed `password`); it is loaded only then.
|
|
21
|
+
*/
|
|
9
22
|
export default class Install extends BaseCommand {
|
|
10
23
|
static commandName = 'adula:install';
|
|
11
|
-
static description = 'Install core organization, administrator role and managed agent instructions after migrations';
|
|
24
|
+
static description = 'Install core organization, administrator role (creating the first administrator when missing) and managed agent instructions after migrations';
|
|
12
25
|
static options = { startApp: true };
|
|
13
26
|
async run() {
|
|
14
27
|
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
15
28
|
const knex = db.connection().getWriteClient();
|
|
16
|
-
const email = process.env.ADULA_ADMIN_EMAIL;
|
|
29
|
+
const email = (this.adminEmail ?? process.env.ADULA_ADMIN_EMAIL)?.trim().toLowerCase();
|
|
17
30
|
if (!email)
|
|
18
|
-
throw new Error('Set ADULA_ADMIN_EMAIL
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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;
|
|
31
|
+
throw new Error('Set ADULA_ADMIN_EMAIL (or pass --admin-email) to the administrator e-mail address.');
|
|
32
|
+
let password;
|
|
33
|
+
const userModel = async () => {
|
|
34
|
+
try {
|
|
35
|
+
const module = await this.app.import('#models/user');
|
|
36
|
+
return module.default;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const [created] = await trx('roles')
|
|
37
|
-
.insert({ name: 'administrator', key: 'administrator', permission_level: 1 })
|
|
38
|
-
.returning('*');
|
|
39
|
-
role = created;
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new Error("adula:install creates the first administrator through the application's #models/user model; it was not found", { cause: error });
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
};
|
|
42
|
+
const user = await resolveInstallAdministrator(knex, email, async () => {
|
|
43
|
+
// The first administrator is created here so self-signup is never the bootstrap path.
|
|
44
|
+
password = randomBytes(18).toString('base64url');
|
|
45
|
+
const User = await userModel();
|
|
46
|
+
const created = await User.create({
|
|
47
|
+
email,
|
|
48
|
+
fullName: this.adminName?.trim() || 'مدير النظام',
|
|
49
|
+
password,
|
|
50
|
+
});
|
|
51
|
+
return Number(created.id);
|
|
52
|
+
}, {
|
|
53
|
+
// Anyone may have self-registered this address before the first administrator existed.
|
|
54
|
+
rotatePassword: this.keepPassword
|
|
55
|
+
? undefined
|
|
56
|
+
: async (id) => {
|
|
57
|
+
password = randomBytes(18).toString('base64url');
|
|
58
|
+
const User = await userModel();
|
|
59
|
+
const account = await User.findOrFail(id);
|
|
60
|
+
account.password = password;
|
|
61
|
+
await account.save();
|
|
62
|
+
},
|
|
61
63
|
});
|
|
64
|
+
await grantInstallAdministrator(knex, user.id, ADULA_VERSION);
|
|
65
|
+
// Shown once on the terminal and never written to a file; change it after signing in.
|
|
66
|
+
if (user.created && password)
|
|
67
|
+
this.logger.warning(`First administrator ${email} created. One-time password (change it after signing in): ${password}`);
|
|
68
|
+
if (user.rotated && password)
|
|
69
|
+
this.logger.warning(`Existing account ${email} promoted to first administrator: its password was replaced and ${user.rotated.sessions} session(s), ${user.rotated.tokens} API token(s), ${user.rotated.resetTokens} recovery link(s) and ${user.rotated.invitations} invitation(s) were ended. One-time password (change it after signing in): ${password}. Pass --keep-password only for an account you created yourself.`);
|
|
62
70
|
// Module lookups and default roles: added when missing, never overwritten.
|
|
63
71
|
let registry;
|
|
64
72
|
try {
|
|
@@ -71,6 +79,11 @@ export default class Install extends BaseCommand {
|
|
|
71
79
|
if (registry) {
|
|
72
80
|
const seeded = await seedModules(knex, registry, user.id);
|
|
73
81
|
this.logger.info(`Module defaults: ${seeded.lookups} lookup rows added; roles created: ${seeded.created.join(', ') || 'none'}; adopted by name: ${seeded.adopted.join(', ') || 'none'}`);
|
|
82
|
+
const parents = diagnoseScopeParentRoles(registry.all(), registry
|
|
83
|
+
.modules()
|
|
84
|
+
.flatMap((module) => (module.defaultRoles ?? []).map((role) => ({ name: role.key, rules: role.rules }))));
|
|
85
|
+
if (parents.status === 'warn')
|
|
86
|
+
this.logger.warning(parents.message);
|
|
74
87
|
}
|
|
75
88
|
for (const [name, content] of [
|
|
76
89
|
['CLAUDE.md', 'Read and follow AGENTS.md.\nThe project rules are maintained there.\n'],
|
|
@@ -103,3 +116,14 @@ export default class Install extends BaseCommand {
|
|
|
103
116
|
this.logger.success('Core installation complete. Run adula:doctor.');
|
|
104
117
|
}
|
|
105
118
|
}
|
|
119
|
+
__decorate([
|
|
120
|
+
flags.string({ description: 'Administrator e-mail (defaults to ADULA_ADMIN_EMAIL)' })
|
|
121
|
+
], Install.prototype, "adminEmail", void 0);
|
|
122
|
+
__decorate([
|
|
123
|
+
flags.string({ description: 'Full name used when the first administrator is created' })
|
|
124
|
+
], Install.prototype, "adminName", void 0);
|
|
125
|
+
__decorate([
|
|
126
|
+
flags.boolean({
|
|
127
|
+
description: 'Keep the password of an existing account promoted as the first administrator (only when you created it yourself)',
|
|
128
|
+
})
|
|
129
|
+
], Install.prototype, "keepPassword", void 0);
|
package/build/commands/main.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import Resource from './resource.js';
|
|
2
|
-
import Doctor from './doctor.js';
|
|
3
2
|
import ModuleAdd from './module_add.js';
|
|
4
3
|
import Ui from './ui.js';
|
|
4
|
+
import AdulaAssistantPrune from './adula_assistant_prune.js';
|
|
5
|
+
import App from './app.js';
|
|
5
6
|
export declare function getMetaData(): Promise<import("@adonisjs/core/types/ace").CommandMetaData[]>;
|
|
6
7
|
export declare function getCommand(meta: {
|
|
7
8
|
commandName: string;
|
|
8
|
-
}): Promise<typeof
|
|
9
|
+
}): Promise<typeof AdulaAssistantPrune | typeof App | typeof Resource | typeof ModuleAdd | typeof Ui | null>;
|
package/build/commands/main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Resource from './resource.js';
|
|
2
2
|
import ResourceSnapshot from './resource_snapshot.js';
|
|
3
|
+
import ResourceMigration from './resource_migration.js';
|
|
3
4
|
import Doctor from './doctor.js';
|
|
4
5
|
import Install from './install.js';
|
|
5
6
|
import Capabilities from './capabilities.js';
|
|
@@ -9,9 +10,25 @@ import Ui from './ui.js';
|
|
|
9
10
|
import StorageMigrate from './storage_migrate.js';
|
|
10
11
|
import Gaps from './gaps.js';
|
|
11
12
|
import Upgrade from './upgrade.js';
|
|
13
|
+
import AdulaOutbox from './adula_outbox.js';
|
|
14
|
+
import AdulaRuntimeHealth from './adula_runtime_health.js';
|
|
15
|
+
import AdulaUploadsPrune from './adula_uploads_prune.js';
|
|
16
|
+
import AdulaAssistantPrune from './adula_assistant_prune.js';
|
|
17
|
+
import AdulaRestoreReconcile from './adula_restore_reconcile.js';
|
|
18
|
+
import BackupCreate from './backup_create.js';
|
|
19
|
+
import BackupRestoreFiles from './backup_restore_files.js';
|
|
20
|
+
import BackupRestoreTest from './backup_restore_test.js';
|
|
21
|
+
import BackupVerify from './backup_verify.js';
|
|
22
|
+
import BackupVerifySnapshot from './backup_verify_snapshot.js';
|
|
23
|
+
import BackupSeal from './backup_seal.js';
|
|
24
|
+
import BackupOpen from './backup_open.js';
|
|
25
|
+
import App from './app.js';
|
|
26
|
+
import Client from './client.js';
|
|
27
|
+
import SlaEvaluate from './sla_evaluate.js';
|
|
12
28
|
const commands = [
|
|
13
29
|
Resource,
|
|
14
30
|
ResourceSnapshot,
|
|
31
|
+
ResourceMigration,
|
|
15
32
|
Doctor,
|
|
16
33
|
Install,
|
|
17
34
|
Capabilities,
|
|
@@ -21,6 +38,21 @@ const commands = [
|
|
|
21
38
|
StorageMigrate,
|
|
22
39
|
Gaps,
|
|
23
40
|
Upgrade,
|
|
41
|
+
AdulaOutbox,
|
|
42
|
+
AdulaRuntimeHealth,
|
|
43
|
+
AdulaUploadsPrune,
|
|
44
|
+
AdulaAssistantPrune,
|
|
45
|
+
AdulaRestoreReconcile,
|
|
46
|
+
BackupCreate,
|
|
47
|
+
BackupRestoreFiles,
|
|
48
|
+
BackupRestoreTest,
|
|
49
|
+
BackupVerify,
|
|
50
|
+
BackupVerifySnapshot,
|
|
51
|
+
BackupSeal,
|
|
52
|
+
BackupOpen,
|
|
53
|
+
App,
|
|
54
|
+
Client,
|
|
55
|
+
SlaEvaluate,
|
|
24
56
|
];
|
|
25
57
|
export async function getMetaData() {
|
|
26
58
|
return commands.map((command) => {
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { BaseCommand, args, flags } from '@adonisjs/core/ace';
|
|
8
8
|
import { mkdir, readFile, writeFile, access } from 'node:fs/promises';
|
|
9
9
|
import { identifier } from '../src/resource/define_resource.js';
|
|
10
|
-
import {
|
|
10
|
+
import { MODULE_DIRECTORIES, moduleSource, registerModuleSource, } from '../src/commands/source_markers.js';
|
|
11
11
|
export default class ModuleAdd extends BaseCommand {
|
|
12
12
|
static commandName = 'adula:module:add';
|
|
13
13
|
static description = 'Create and register an application-owned module';
|
|
@@ -25,28 +25,12 @@ export default class ModuleAdd extends BaseCommand {
|
|
|
25
25
|
throw error;
|
|
26
26
|
}
|
|
27
27
|
const indexPath = this.app.makePath('start/modules.ts');
|
|
28
|
-
const
|
|
29
|
-
|
|
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
|
-
])
|
|
28
|
+
const next = registerModuleSource(await readFile(indexPath, 'utf8'), this.name);
|
|
29
|
+
for (const directory of MODULE_DIRECTORIES)
|
|
46
30
|
await mkdir(this.app.makePath('app/modules', this.name, directory), { recursive: true });
|
|
47
31
|
await writeFile(this.app.makePath('app/modules', this.name, 'module.ts'), moduleSource(this.name, { reference: Boolean(this.reference), typed: true }), { flag: 'wx' });
|
|
48
32
|
await writeFile(indexPath, next);
|
|
49
|
-
this.logger.success(`Created ${this.name}. Fill
|
|
33
|
+
this.logger.success(`Created ${this.name}. Fill the Arabic labels (other languages are optional) and declare dependencies before adding resources.`);
|
|
50
34
|
}
|
|
51
35
|
}
|
|
52
36
|
__decorate([
|
|
@@ -9,16 +9,19 @@ import { generateResource } from '../src/commands/generator.js';
|
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
10
|
export default class Resource extends BaseCommand {
|
|
11
11
|
static commandName = 'adula:resource';
|
|
12
|
-
static description = 'Generate a scoped resource, migration
|
|
12
|
+
static description = 'Generate a scoped resource, its create-migration and security contract (validator and model are derived; opt in with --validator / --model)';
|
|
13
13
|
async run() {
|
|
14
14
|
if (!this.module) {
|
|
15
15
|
this.logger.error('--module is required');
|
|
16
16
|
this.exitCode = 1;
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
const files = await generateResource(fileURLToPath(this.app.appRoot), this.name, this.module
|
|
19
|
+
const files = await generateResource(fileURLToPath(this.app.appRoot), this.name, this.module, {
|
|
20
|
+
validator: Boolean(this.validator),
|
|
21
|
+
model: Boolean(this.model),
|
|
22
|
+
});
|
|
20
23
|
files.forEach((file) => this.logger.success(file));
|
|
21
|
-
this.logger.info('Set
|
|
24
|
+
this.logger.info('Set the Arabic labels (label: the plural list heading; recordLabel: the singular record noun; label.en and other languages are optional) and fill the resource definition: its fields decide validation, columns and forms. The generated migration embeds the definition as scaffolded: run migration:run, then after adding fields run `node ace adula:resource:migration <name>` for an additive migration of what the table lacks. adula:doctor reports tables that differ from their definitions. Then run the generated security contract.');
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
__decorate([
|
|
@@ -27,3 +30,9 @@ __decorate([
|
|
|
27
30
|
__decorate([
|
|
28
31
|
flags.string()
|
|
29
32
|
], Resource.prototype, "module", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
flags.boolean({ description: 'Also write a VineJS validator file instead of the derived one' })
|
|
35
|
+
], Resource.prototype, "validator", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
flags.boolean({ description: 'Also write a Lucid model and factory for your own code' })
|
|
38
|
+
], Resource.prototype, "model", void 0);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
/**
|
|
3
|
+
* Writes an additive migration with what the database lacks for a resource: new
|
|
4
|
+
* columns, join tables and unique indexes (see alterResourceTable). Only the new pieces
|
|
5
|
+
* are embedded, so migrations that already ran stay unchanged.
|
|
6
|
+
*/
|
|
7
|
+
export default class ResourceMigration 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,81 @@
|
|
|
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, readFile, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { dirname } from 'node:path';
|
|
10
|
+
import { MigrationRunner } from '@adonisjs/lucid/migration';
|
|
11
|
+
import { embeddedResource } from '../src/commands/snapshot.js';
|
|
12
|
+
import { additionMigrationSource, describeDrift, missingStandardColumns, resourceAddition, schemaDrift, } from '../src/database/schema_diff.js';
|
|
13
|
+
/**
|
|
14
|
+
* Writes an additive migration with what the database lacks for a resource: new
|
|
15
|
+
* columns, join tables and unique indexes (see alterResourceTable). Only the new pieces
|
|
16
|
+
* are embedded, so migrations that already ran stay unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export default class ResourceMigration extends BaseCommand {
|
|
19
|
+
static commandName = 'adula:resource:migration';
|
|
20
|
+
static description = 'Write an additive migration for the columns, join tables and unique indexes a resource table lacks';
|
|
21
|
+
static options = { startApp: true };
|
|
22
|
+
async run() {
|
|
23
|
+
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
24
|
+
const { registry } = (await this.app.import('#start/modules'));
|
|
25
|
+
let resource;
|
|
26
|
+
try {
|
|
27
|
+
resource = registry.get(this.name);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
this.logger.error(`Unknown resource: ${this.name}. Register it in its module first.`);
|
|
31
|
+
this.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const drift = await schemaDrift(db.connection().getWriteClient(), resource);
|
|
35
|
+
if (drift.missingTable) {
|
|
36
|
+
this.logger.error(`${this.name} has no table yet: run its create-migration with migration:run first.`);
|
|
37
|
+
this.exitCode = 1;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const entry of drift.wrongTypes)
|
|
41
|
+
this.logger.warning(`${this.name}.${entry.column} is ${entry.actual}, the definition expects ${entry.expected}; types are never changed automatically (write an expand/contract migration).`);
|
|
42
|
+
const addition = resourceAddition(resource, drift);
|
|
43
|
+
// Standard columns are not fields: the version column is added by a fixed statement
|
|
44
|
+
// (#138); the others need a hand-written expand migration and fail the command.
|
|
45
|
+
const standard = missingStandardColumns(drift);
|
|
46
|
+
for (const column of standard.unsupported) {
|
|
47
|
+
this.logger.error(`${this.name}.${column} is missing and cannot be generated: write an expand migration by hand.`);
|
|
48
|
+
this.exitCode = 1;
|
|
49
|
+
}
|
|
50
|
+
if (!Object.keys(addition).length && !standard.statements.length) {
|
|
51
|
+
if (standard.unsupported.length)
|
|
52
|
+
return;
|
|
53
|
+
this.logger.info(`${this.name}: the database already has every column, join table and unique index.`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Next to the resource's create-migration, or in its module's migrations folder.
|
|
57
|
+
let folder = `app/modules/${registry.owner(this.name)}/migrations`;
|
|
58
|
+
const migrations = await new MigrationRunner(db, this.app, { direction: 'up' }).getList();
|
|
59
|
+
for (const entry of migrations)
|
|
60
|
+
for (const extension of ['.ts', '.js'])
|
|
61
|
+
try {
|
|
62
|
+
const source = await readFile(this.app.makePath(`${entry.name}${extension}`), 'utf8');
|
|
63
|
+
if (embeddedResource(source) === this.name)
|
|
64
|
+
folder = dirname(entry.name);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
catch { }
|
|
68
|
+
const file = `${folder}/${Date.now()}_alter_${this.name}.ts`;
|
|
69
|
+
await mkdir(this.app.makePath(folder), { recursive: true });
|
|
70
|
+
await writeFile(this.app.makePath(file), additionMigrationSource(this.name, addition, standard.statements), {
|
|
71
|
+
flag: 'wx',
|
|
72
|
+
});
|
|
73
|
+
for (const line of describeDrift(drift))
|
|
74
|
+
this.logger.info(line);
|
|
75
|
+
this.logger.success(file);
|
|
76
|
+
this.logger.info('Review the migration, then run migration:run after the deployment backup.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
__decorate([
|
|
80
|
+
args.string({ description: 'Resource name' })
|
|
81
|
+
], ResourceMigration.prototype, "name", void 0);
|
|
@@ -3,6 +3,8 @@ import { BaseCommand } from '@adonisjs/core/ace';
|
|
|
3
3
|
* Rewrites the definition embedded in a resource's generated create-migration from the
|
|
4
4
|
* current resource, while that migration has not run yet (#20). A migration that already
|
|
5
5
|
* ran is never edited: change the table with a new expand migration instead.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use adula:resource:migration after the create-migration ran (ADR 045).
|
|
6
8
|
*/
|
|
7
9
|
export default class ResourceSnapshot extends BaseCommand {
|
|
8
10
|
static commandName: string;
|
|
@@ -7,17 +7,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { BaseCommand, args } from '@adonisjs/core/ace';
|
|
8
8
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
9
9
|
import { MigrationRunner } from '@adonisjs/lucid/migration';
|
|
10
|
-
import { embeddedResource, resourceSnapshot, rewriteResourceSnapshot, } from '../src/commands/snapshot.js';
|
|
10
|
+
import { embeddedResource, laterRelationTargets, resourceSnapshot, rewriteResourceSnapshot, } from '../src/commands/snapshot.js';
|
|
11
11
|
/**
|
|
12
12
|
* Rewrites the definition embedded in a resource's generated create-migration from the
|
|
13
13
|
* current resource, while that migration has not run yet (#20). A migration that already
|
|
14
14
|
* ran is never edited: change the table with a new expand migration instead.
|
|
15
|
+
*
|
|
16
|
+
* @deprecated Use adula:resource:migration after the create-migration ran (ADR 045).
|
|
15
17
|
*/
|
|
16
18
|
export default class ResourceSnapshot extends BaseCommand {
|
|
17
19
|
static commandName = 'adula:resource:snapshot';
|
|
18
20
|
static description = "Refresh a pending generated create-migration from the resource's current definition";
|
|
19
21
|
static options = { startApp: true };
|
|
20
22
|
async run() {
|
|
23
|
+
this.logger.warning('adula:resource:snapshot is deprecated (ADR 045): run the create-migration as scaffolded, then add later fields with node ace adula:resource:migration <name>.');
|
|
21
24
|
const { default: db } = await import('@adonisjs/lucid/services/db');
|
|
22
25
|
const { registry } = (await this.app.import('#start/modules'));
|
|
23
26
|
let resource;
|
|
@@ -31,16 +34,20 @@ export default class ResourceSnapshot extends BaseCommand {
|
|
|
31
34
|
}
|
|
32
35
|
const migrations = await new MigrationRunner(db, this.app, { direction: 'up' }).getList();
|
|
33
36
|
const matches = [];
|
|
34
|
-
|
|
37
|
+
const embedded = [];
|
|
38
|
+
for (const entry of migrations) {
|
|
39
|
+
embedded.push({ name: entry.name });
|
|
35
40
|
for (const extension of ['.ts', '.js'])
|
|
36
41
|
try {
|
|
37
42
|
const file = `${entry.name}${extension}`;
|
|
38
43
|
const source = await readFile(this.app.makePath(file), 'utf8');
|
|
44
|
+
embedded[embedded.length - 1].resource = embeddedResource(source);
|
|
39
45
|
if (embeddedResource(source) === this.name)
|
|
40
|
-
matches.push({ file, source, pending: entry.status === 'pending' });
|
|
46
|
+
matches.push({ name: entry.name, file, source, pending: entry.status === 'pending' });
|
|
41
47
|
break;
|
|
42
48
|
}
|
|
43
49
|
catch { }
|
|
50
|
+
}
|
|
44
51
|
const pending = matches.filter((match) => match.pending);
|
|
45
52
|
if (!pending.length) {
|
|
46
53
|
this.logger.error(matches.length
|
|
@@ -49,8 +56,18 @@ export default class ResourceSnapshot extends BaseCommand {
|
|
|
49
56
|
this.exitCode = 1;
|
|
50
57
|
return;
|
|
51
58
|
}
|
|
59
|
+
// A relation to a table created by a later migration would fail its foreign key on a
|
|
60
|
+
// fresh database (#99): refuse before writing anything.
|
|
61
|
+
const snapshot = resourceSnapshot(resource);
|
|
62
|
+
const later = pending.flatMap((match) => laterRelationTargets(snapshot, match.name, embedded).map((entry) => ({ ...entry, match })));
|
|
63
|
+
if (later.length) {
|
|
64
|
+
for (const entry of later)
|
|
65
|
+
this.logger.error(`${entry.match.file}: ${entry.field} links ${entry.target}, whose create-migration ${entry.migration} runs later, so its foreign key would fail. Keep ${entry.field} out of this create-migration and add it with node ace adula:resource:migration ${this.name} once both tables exist.`);
|
|
66
|
+
this.exitCode = 1;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
52
69
|
for (const match of pending) {
|
|
53
|
-
await writeFile(this.app.makePath(match.file), rewriteResourceSnapshot(match.source,
|
|
70
|
+
await writeFile(this.app.makePath(match.file), rewriteResourceSnapshot(match.source, snapshot));
|
|
54
71
|
this.logger.success(match.file);
|
|
55
72
|
}
|
|
56
73
|
this.logger.info('Update the model, factory and contract fixture to the same fields, then run migration:run.');
|