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,285 @@
|
|
|
1
|
+
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { identifier } from '../resource/define_resource.js';
|
|
4
|
+
import { planResource, quoted } from './generator.js';
|
|
5
|
+
import { MODULE_DIRECTORIES, moduleRegistered } from './source_markers.js';
|
|
6
|
+
/**
|
|
7
|
+
* Names an application (module) may not take: AdulaJS framework areas, URL segments of
|
|
8
|
+
* the generated application, and tables the core and the host application own. An
|
|
9
|
+
* application's example resource and table share its name, so a collision would shadow
|
|
10
|
+
* a framework table or route.
|
|
11
|
+
*/
|
|
12
|
+
export const RESERVED_APP_NAMES = [
|
|
13
|
+
// Framework and application areas
|
|
14
|
+
'adula',
|
|
15
|
+
'adulajs',
|
|
16
|
+
'core',
|
|
17
|
+
'app',
|
|
18
|
+
'apps',
|
|
19
|
+
'module',
|
|
20
|
+
'modules',
|
|
21
|
+
'system',
|
|
22
|
+
'admin',
|
|
23
|
+
'auth',
|
|
24
|
+
'api',
|
|
25
|
+
'account',
|
|
26
|
+
'profile',
|
|
27
|
+
'work',
|
|
28
|
+
'resources',
|
|
29
|
+
'settings',
|
|
30
|
+
'lookups',
|
|
31
|
+
'sequences',
|
|
32
|
+
'notifications',
|
|
33
|
+
'workflows',
|
|
34
|
+
'approvals',
|
|
35
|
+
'my_tasks',
|
|
36
|
+
'imports',
|
|
37
|
+
'attachments',
|
|
38
|
+
'webhooks',
|
|
39
|
+
'health',
|
|
40
|
+
'login',
|
|
41
|
+
'logout',
|
|
42
|
+
'invitations',
|
|
43
|
+
'permissions',
|
|
44
|
+
'reports',
|
|
45
|
+
'jobs',
|
|
46
|
+
'mcp',
|
|
47
|
+
// Core and host-application tables
|
|
48
|
+
'users',
|
|
49
|
+
'roles',
|
|
50
|
+
'role_rules',
|
|
51
|
+
'user_roles',
|
|
52
|
+
'user_org_units',
|
|
53
|
+
'org_units',
|
|
54
|
+
'activities',
|
|
55
|
+
'assignments',
|
|
56
|
+
'auth_access_tokens',
|
|
57
|
+
'authorization_revision',
|
|
58
|
+
'comment_mentions',
|
|
59
|
+
'comments',
|
|
60
|
+
'field_changes',
|
|
61
|
+
'followers',
|
|
62
|
+
'import_batches',
|
|
63
|
+
'inbound_deliveries',
|
|
64
|
+
'inbound_sources',
|
|
65
|
+
'message_templates',
|
|
66
|
+
'outbox',
|
|
67
|
+
'processed_events',
|
|
68
|
+
'saved_views',
|
|
69
|
+
'sessions',
|
|
70
|
+
'taggables',
|
|
71
|
+
'tags',
|
|
72
|
+
'upload_grants',
|
|
73
|
+
'user_invitations',
|
|
74
|
+
'user_sessions',
|
|
75
|
+
'webhook_deliveries',
|
|
76
|
+
'workflow_events',
|
|
77
|
+
'workflow_runs',
|
|
78
|
+
'password_reset_tokens',
|
|
79
|
+
'social_accounts',
|
|
80
|
+
'adonis_schema',
|
|
81
|
+
'adonis_schema_versions',
|
|
82
|
+
];
|
|
83
|
+
/** Longest application name: its table, indexes and role keys must fit PostgreSQL limits. */
|
|
84
|
+
export const APP_NAME_MAX_LENGTH = 40;
|
|
85
|
+
/** Validates an application name: an SQL-safe slug that is neither reserved nor too long. */
|
|
86
|
+
export function appName(value) {
|
|
87
|
+
if (typeof value !== 'string' || !/^[a-z][a-z0-9_]*$/.test(value))
|
|
88
|
+
throw new Error(`Invalid application name "${value}": use lower-case letters, digits and underscores, starting with a letter`);
|
|
89
|
+
identifier(value);
|
|
90
|
+
if (value.length > APP_NAME_MAX_LENGTH)
|
|
91
|
+
throw new Error(`Application name is longer than ${APP_NAME_MAX_LENGTH} characters`);
|
|
92
|
+
if (RESERVED_APP_NAMES.includes(value))
|
|
93
|
+
throw new Error(`"${value}" is reserved by AdulaJS; choose another application name`);
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
/** leave_requests → Leave requests */
|
|
97
|
+
export function defaultEnglishLabel(name) {
|
|
98
|
+
const words = name.replaceAll('_', ' ').trim();
|
|
99
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
100
|
+
}
|
|
101
|
+
/** The default roles an application ships, in the shape module definitions declare. */
|
|
102
|
+
export function appDefaultRoles(name, labelAr) {
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
key: `${name}_manager`,
|
|
106
|
+
name: `مدير ${labelAr}`,
|
|
107
|
+
permissionLevel: 1,
|
|
108
|
+
rules: ['view', 'create', 'update', 'delete'].map((action) => ({
|
|
109
|
+
subject: name,
|
|
110
|
+
action,
|
|
111
|
+
})),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: `${name}_user`,
|
|
115
|
+
name: `مستخدم ${labelAr}`,
|
|
116
|
+
rules: [
|
|
117
|
+
{ subject: name, action: 'view' },
|
|
118
|
+
{ subject: name, action: 'create' },
|
|
119
|
+
{ subject: name, action: 'update', conditions: { createdBy: '$actor.id' } },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
/** The module definition of a new application, in the project's Prettier layout. */
|
|
125
|
+
export function appModuleSource(name, label) {
|
|
126
|
+
const [manager, user] = appDefaultRoles(name, label.ar);
|
|
127
|
+
const rule = (action) => ` { subject: '${name}', action: '${action}' },`;
|
|
128
|
+
return [
|
|
129
|
+
"import { ACTOR_ID, type Module } from 'adula'",
|
|
130
|
+
'// adula:imports',
|
|
131
|
+
'export default {',
|
|
132
|
+
` name: '${name}',`,
|
|
133
|
+
' label: {',
|
|
134
|
+
` ar: ${quoted(label.ar)},`,
|
|
135
|
+
` en: ${quoted(label.en ?? defaultEnglishLabel(name))},`,
|
|
136
|
+
' },',
|
|
137
|
+
' dependsOn: [],',
|
|
138
|
+
' resources: [/* adula:resources */],',
|
|
139
|
+
' // Created by `node ace adula:install` when missing; administrators own them afterwards.',
|
|
140
|
+
' defaultRoles: [',
|
|
141
|
+
' {',
|
|
142
|
+
` key: '${manager.key}',`,
|
|
143
|
+
` name: ${quoted(manager.name)},`,
|
|
144
|
+
' permissionLevel: 1,',
|
|
145
|
+
' rules: [',
|
|
146
|
+
...['view', 'create', 'update', 'delete'].map((action) => rule(action)),
|
|
147
|
+
' ],',
|
|
148
|
+
' },',
|
|
149
|
+
' {',
|
|
150
|
+
` key: '${user.key}',`,
|
|
151
|
+
` name: ${quoted(user.name)},`,
|
|
152
|
+
' rules: [',
|
|
153
|
+
rule('view'),
|
|
154
|
+
rule('create'),
|
|
155
|
+
' // Each user edits only the records they created.',
|
|
156
|
+
' {',
|
|
157
|
+
` subject: '${name}',`,
|
|
158
|
+
" action: 'update',",
|
|
159
|
+
' conditions: { createdBy: ACTOR_ID },',
|
|
160
|
+
' },',
|
|
161
|
+
' ],',
|
|
162
|
+
' },',
|
|
163
|
+
' ],',
|
|
164
|
+
'} satisfies Module',
|
|
165
|
+
'',
|
|
166
|
+
].join('\n');
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A functional smoke test: an administrator opens the example resource list and the
|
|
170
|
+
* navigation carries the application's menu group.
|
|
171
|
+
*/
|
|
172
|
+
export function appSmokeTestSource(name, label) {
|
|
173
|
+
return `import { test } from '@japa/runner'
|
|
174
|
+
import { randomUUID } from 'node:crypto'
|
|
175
|
+
import db from '@adonisjs/lucid/services/db'
|
|
176
|
+
import User from '#models/user'
|
|
177
|
+
|
|
178
|
+
const application = '${name}'
|
|
179
|
+
const label = ${quoted(label.ar)}
|
|
180
|
+
|
|
181
|
+
test.group('${name} application smoke test', () => {
|
|
182
|
+
test('an administrator opens the list and sees the application menu group', async ({
|
|
183
|
+
client,
|
|
184
|
+
assert,
|
|
185
|
+
}) => {
|
|
186
|
+
const knex = db.connection().getWriteClient()
|
|
187
|
+
const unique = randomUUID()
|
|
188
|
+
const admin = await User.create({
|
|
189
|
+
email: \`\${application}-admin-\${unique}@example.test\`,
|
|
190
|
+
password: 'smoke-test-password-123',
|
|
191
|
+
})
|
|
192
|
+
const [role] = await knex('roles')
|
|
193
|
+
.insert({ name: \`\${application}-admin-\${unique}\`, permission_level: 1 })
|
|
194
|
+
.returning('id')
|
|
195
|
+
await knex('role_rules').insert({ role_id: role.id, subject: 'all', action: 'manage' })
|
|
196
|
+
await knex('user_roles').insert({ user_id: admin.id, role_id: role.id })
|
|
197
|
+
const [unit] = await knex('org_units')
|
|
198
|
+
.insert({
|
|
199
|
+
name: 'وحدة الاختبار',
|
|
200
|
+
type: 'root',
|
|
201
|
+
path: \`\${application}_\${unique.replaceAll('-', '_')}\`,
|
|
202
|
+
})
|
|
203
|
+
.returning('id')
|
|
204
|
+
await knex('user_org_units').insert({ user_id: admin.id, org_unit_id: unit.id })
|
|
205
|
+
const page = await client
|
|
206
|
+
.get(\`/resources/\${application}\`)
|
|
207
|
+
.loginAs(admin)
|
|
208
|
+
.header('Accept', 'text/html')
|
|
209
|
+
.withInertia()
|
|
210
|
+
page.assertStatus(200)
|
|
211
|
+
const group = page
|
|
212
|
+
.body()
|
|
213
|
+
.props.navigation.filter((entry: { module: string }) => entry.module === application)
|
|
214
|
+
assert.deepEqual(
|
|
215
|
+
group.map((entry: { name: string }) => entry.name),
|
|
216
|
+
[application]
|
|
217
|
+
)
|
|
218
|
+
assert.equal(group[0].moduleLabel, label)
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
`;
|
|
222
|
+
}
|
|
223
|
+
async function exists(path) {
|
|
224
|
+
try {
|
|
225
|
+
await access(path);
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (error.code !== 'ENOENT')
|
|
230
|
+
throw error;
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Plans a new application (module) without writing: its module definition with bilingual
|
|
236
|
+
* labels and default roles, one example resource from the resource generator, the empty
|
|
237
|
+
* module folders, a smoke test and its registration in start/modules.ts.
|
|
238
|
+
*/
|
|
239
|
+
export async function planApp(root, options) {
|
|
240
|
+
const name = appName(options.name);
|
|
241
|
+
const ar = options.labelAr?.trim();
|
|
242
|
+
if (!ar)
|
|
243
|
+
throw new Error('--label-ar is required: the Arabic label shown in the menu');
|
|
244
|
+
const label = { ar, en: options.labelEn?.trim() || defaultEnglishLabel(name) };
|
|
245
|
+
// eslint-disable-next-line no-control-regex
|
|
246
|
+
if (/[\u0000-\u001f\u007f]/.test(label.ar + label.en))
|
|
247
|
+
throw new Error('Labels must be a single line without control characters');
|
|
248
|
+
if (await exists(join(root, 'app/modules', name)))
|
|
249
|
+
throw new Error(`Application already exists: app/modules/${name}`);
|
|
250
|
+
const modulesPath = join(root, 'start/modules.ts');
|
|
251
|
+
if (moduleRegistered(await readFile(modulesPath, 'utf8'), name))
|
|
252
|
+
throw new Error(`Application ${name} is already registered in start/modules.ts`);
|
|
253
|
+
const resource = await planResource(root, name, name, {
|
|
254
|
+
moduleSource: appModuleSource(name, label),
|
|
255
|
+
label,
|
|
256
|
+
});
|
|
257
|
+
if (!resource.modules)
|
|
258
|
+
throw new Error(`Application ${name} is already registered`);
|
|
259
|
+
const files = {
|
|
260
|
+
[`app/modules/${name}/module.ts`]: resource.module.source,
|
|
261
|
+
...resource.files,
|
|
262
|
+
[`tests/functional/${name}/smoke.spec.ts`]: appSmokeTestSource(name, label),
|
|
263
|
+
};
|
|
264
|
+
for (const file of Object.keys(files))
|
|
265
|
+
if (await exists(join(root, file)))
|
|
266
|
+
throw new Error(`Refusing to overwrite ${file}`);
|
|
267
|
+
return {
|
|
268
|
+
name,
|
|
269
|
+
label,
|
|
270
|
+
files,
|
|
271
|
+
directories: MODULE_DIRECTORIES.map((directory) => `app/modules/${name}/${directory}`),
|
|
272
|
+
modules: resource.modules,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/** Writes a plan; files are created exclusively, start/modules.ts is changed last. */
|
|
276
|
+
export async function writeAppPlan(root, plan) {
|
|
277
|
+
for (const directory of plan.directories)
|
|
278
|
+
await mkdir(join(root, directory), { recursive: true });
|
|
279
|
+
for (const [file, content] of Object.entries(plan.files)) {
|
|
280
|
+
const path = join(root, file);
|
|
281
|
+
await mkdir(dirname(path), { recursive: true });
|
|
282
|
+
await writeFile(path, content, { flag: 'wx' });
|
|
283
|
+
}
|
|
284
|
+
await writeFile(plan.modules.path, plan.modules.source);
|
|
285
|
+
}
|
|
@@ -3,15 +3,23 @@ import { WORKFLOW_NAME_RULE } from '../workflows/define_workflow.js';
|
|
|
3
3
|
import { ACTOR_ID } from '../auth/conditions.js';
|
|
4
4
|
/** Field kinds accepted by defineResource, with their storage. */
|
|
5
5
|
export const FIELD_TYPES = {
|
|
6
|
-
string: 'varchar',
|
|
7
|
-
text: 'text',
|
|
8
|
-
integer: 'integer',
|
|
9
|
-
money: 'bigint minor units, decimal string in JSON',
|
|
6
|
+
string: 'varchar(255); min/max length, pattern, format email/url/phone',
|
|
7
|
+
text: 'text; min/max length, pattern',
|
|
8
|
+
integer: 'integer; min/max',
|
|
9
|
+
money: 'bigint minor units, decimal string in JSON; min/max in minor units',
|
|
10
|
+
decimal: 'numeric(precision 18, scale 2 by default); canonical decimal string ("12.50"); min/max',
|
|
11
|
+
percent: 'numeric(precision 7, scale 2 by default); 12.5 means 12.5 %; min/max',
|
|
12
|
+
email: 'varchar(254), trimmed and lower-cased',
|
|
13
|
+
phone: 'varchar(32), stored as +?digits (7 to 15 digits)',
|
|
14
|
+
url: 'varchar(2048), absolute http(s) URLs only',
|
|
15
|
+
enum: 'varchar; one of options [{ value, label }]',
|
|
16
|
+
multiSelect: 'jsonb array of option values in options order; min/max count; filter contains',
|
|
17
|
+
manyToMany: 'join table <owner>_<key> (or table), array of target ids; targets must be viewable',
|
|
10
18
|
boolean: 'boolean',
|
|
11
19
|
date: 'date (YYYY-MM-DD)',
|
|
12
20
|
datetime: 'timestamptz',
|
|
13
21
|
json: 'jsonb',
|
|
14
|
-
attachment: 'attachments row id; per-
|
|
22
|
+
attachment: 'attachments row id; per-file accept/maxSize; multiple: true (max, default 10) stores an ordered jsonb array of ids; images, PDF and text preview inline',
|
|
15
23
|
belongsTo: 'foreign key, preloaded, restrict on delete',
|
|
16
24
|
user: 'users foreign key, restrict on delete; choices are active members of the record unit or its ancestors; related as { id, fullName }',
|
|
17
25
|
hasMany: 'child resource; inline rows saved with the parent',
|
|
@@ -26,6 +34,14 @@ export const FIELD_OPTIONS = [
|
|
|
26
34
|
'permissionLevel',
|
|
27
35
|
'sequence',
|
|
28
36
|
'column',
|
|
37
|
+
'default (create prefill, server default and column default)',
|
|
38
|
+
'visibleWhen ({ sibling: value | values }; hidden fields are stored empty and not required)',
|
|
39
|
+
'min / max (length, numeric limit or count)',
|
|
40
|
+
'pattern (anchored RegExp source)',
|
|
41
|
+
'format (string: email, url or phone)',
|
|
42
|
+
'precision / scale (decimal, percent)',
|
|
43
|
+
'options (enum, multiSelect)',
|
|
44
|
+
'resource / table (manyToMany)',
|
|
29
45
|
];
|
|
30
46
|
export const RESOURCE_OPTIONS = [
|
|
31
47
|
'scoped (required)',
|
|
@@ -33,10 +49,11 @@ export const RESOURCE_OPTIONS = [
|
|
|
33
49
|
'title (fields that name the record in relations, pickers, tasks and approvals)',
|
|
34
50
|
'submittable (docStatus, submit/cancel/amend-by-copy)',
|
|
35
51
|
'version (optimistic locking, default with submittable)',
|
|
36
|
-
'
|
|
52
|
+
'unique (composite combinations of fields, partial over active rows)',
|
|
37
53
|
'list / form / show / serialize / hidden',
|
|
38
54
|
'actions',
|
|
39
55
|
'hooks.beforeSave / hooks.afterSave',
|
|
56
|
+
'validator / model (optional: without validator a VineJS validator is derived from the fields)',
|
|
40
57
|
];
|
|
41
58
|
export const CONDITION_OPERATORS = ['$eq', '$ne', '$in', '$lt', '$gt', '$like'];
|
|
42
59
|
export const WORKFLOW_STEPS = [
|
|
@@ -71,7 +88,12 @@ export const SERVICES = {
|
|
|
71
88
|
'SavedViews',
|
|
72
89
|
'logActivity',
|
|
73
90
|
],
|
|
74
|
-
'Documents and workflows': [
|
|
91
|
+
'Documents and workflows': [
|
|
92
|
+
'defineWorkflow',
|
|
93
|
+
'WorkflowEngine',
|
|
94
|
+
'workflowListeners',
|
|
95
|
+
'WorkflowDelegations',
|
|
96
|
+
],
|
|
75
97
|
'Notifications and messages': [
|
|
76
98
|
'notify',
|
|
77
99
|
'notifyWithTemplate',
|
|
@@ -85,7 +107,9 @@ export const SERVICES = {
|
|
|
85
107
|
'signWebhook',
|
|
86
108
|
'InboundWebhooks',
|
|
87
109
|
'openApiDocument',
|
|
110
|
+
'apiClientSource',
|
|
88
111
|
'ImportBatches',
|
|
112
|
+
'xlsxImportAdapter',
|
|
89
113
|
'renderPrintHtml',
|
|
90
114
|
'htmlToPdf',
|
|
91
115
|
],
|
|
@@ -111,8 +135,11 @@ export const EXTENSION_POINTS = [
|
|
|
111
135
|
'Create links with defaults: /resources/<resource>/create?defaults[field]=value',
|
|
112
136
|
'Domain events <module>.<resource>.{created,updated,deleted,submitted,cancelled,amended} with idempotent listeners',
|
|
113
137
|
'Module workflows (Module.workflows) with versioned definitions',
|
|
138
|
+
'Approval delegation while out of office (WorkflowDelegations; never widens record access)',
|
|
139
|
+
'Step SLA deadlines (sla: hours, dueSoonHours, escalate overdue | notify | reassign, to a recipient or { manager: roleKey }) evaluated by the sla:evaluate job',
|
|
114
140
|
'Message templates edited per deployment',
|
|
115
141
|
'Outgoing webhooks and the bearer-token /api/v1 API',
|
|
142
|
+
'Typed API client of the bearer-token API: GET /api/v1/client.ts per token, or node ace adula:client into clients/<system>/',
|
|
116
143
|
'Signed inbound webhooks raising inbound.<source>.<event> through the outbox',
|
|
117
144
|
];
|
|
118
145
|
export const OUTSIDE_ADULAJS = [
|
|
@@ -120,14 +147,13 @@ export const OUTSIDE_ADULAJS = [
|
|
|
120
147
|
'Runtime plugins',
|
|
121
148
|
'A visual workflow editor',
|
|
122
149
|
'Multi-tenant SaaS in one database (one deployment per organization)',
|
|
123
|
-
'XLSX import until a maintained parser passes the dependency rule (GAP-006)',
|
|
124
150
|
];
|
|
125
151
|
/** The capability catalog read by idea-review: generated, never hand-edited. */
|
|
126
152
|
export function capabilityCatalog(options = {}) {
|
|
127
153
|
const lines = [
|
|
128
154
|
`# AdulaJS capabilities (${ADULA_VERSION})`,
|
|
129
155
|
'',
|
|
130
|
-
'Generated by `node ace adula:capabilities`. Read this before proposing a module; anything not listed here is not provided by AdulaJS.',
|
|
156
|
+
'Generated by `node ace adula:capabilities`. Read this before proposing an application (a module under app/modules); anything not listed here is not provided by AdulaJS.',
|
|
131
157
|
'',
|
|
132
158
|
'## Resource definition',
|
|
133
159
|
'',
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Settings } from '../services/settings.js';
|
|
2
|
+
import type { Knex } from 'knex';
|
|
2
3
|
import type { Field, Resource } from '../resource/types.js';
|
|
4
|
+
import type { Rule } from '../auth/ability.js';
|
|
3
5
|
import type { WorkflowDefinition } from '../workflows/define_workflow.js';
|
|
4
6
|
import type { RuntimeHealth } from '../core/health.js';
|
|
5
7
|
export type Finding = {
|
|
@@ -12,10 +14,13 @@ export declare function diagnoseUploads(root: string): Promise<Finding>;
|
|
|
12
14
|
export declare function diagnoseUi(root: string): Promise<Finding[]>;
|
|
13
15
|
export declare function diagnoseAgentSkills(root: string): Promise<Finding>;
|
|
14
16
|
export declare function diagnose(root: string, settings: Settings, production: boolean, env: Record<string, string | undefined>, now?: number): Promise<Finding[]>;
|
|
15
|
-
type TableShape = Pick<Resource, 'name' | 'scoped' | 'version' | 'submittable' | '
|
|
16
|
-
fields: Record<string, Pick<Field, 'column' | 'required' | 'sequence' | 'unique' | 'searchable'> & {
|
|
17
|
+
type TableShape = Pick<Resource, 'name' | 'scoped' | 'version' | 'submittable' | 'unique'> & {
|
|
18
|
+
fields: Record<string, Pick<Field, 'column' | 'required' | 'sequence' | 'unique' | 'searchable' | 'default' | 'visibleWhen'> & {
|
|
17
19
|
type: string;
|
|
18
20
|
resource?: string;
|
|
21
|
+
table?: string;
|
|
22
|
+
precision?: number;
|
|
23
|
+
scale?: number;
|
|
19
24
|
}>;
|
|
20
25
|
};
|
|
21
26
|
/**
|
|
@@ -35,8 +40,25 @@ export declare function diagnoseWorkflowRoles(workflows: readonly Pick<WorkflowD
|
|
|
35
40
|
key: string | null;
|
|
36
41
|
name: string;
|
|
37
42
|
})[]): Finding;
|
|
43
|
+
/**
|
|
44
|
+
* A child declared with `scope: { from }` takes its unit from its parent, so creating or
|
|
45
|
+
* updating it needs `view` on the parent (ADR 029). List roles that may write such a child
|
|
46
|
+
* but have no rule that lets them view the parent: every create and update refuses them (#140).
|
|
47
|
+
*/
|
|
48
|
+
export declare function diagnoseScopeParentRoles(resources: readonly Pick<Resource, 'name' | 'fields' | 'scope'>[], roles: readonly {
|
|
49
|
+
name: string;
|
|
50
|
+
rules: readonly Pick<Rule, 'subject' | 'action' | 'inverted'>[];
|
|
51
|
+
}[]): Finding;
|
|
38
52
|
/** Events wait in the outbox until a worker publishes them; a stale backlog means none runs (#50). */
|
|
39
53
|
export declare function diagnoseOutbox(health: Pick<RuntimeHealth, 'outbox'> & {
|
|
40
54
|
heartbeats: Pick<RuntimeHealth['heartbeats'], 'worker'>;
|
|
41
55
|
}): Finding;
|
|
56
|
+
/**
|
|
57
|
+
* Compares every registered resource with its live table (see schemaDrift): missing
|
|
58
|
+
* columns, different types, NOT NULL columns the definition lets be empty, missing unique
|
|
59
|
+
* indexes, unique indexes still counting cancelled documents and missing join tables. Run
|
|
60
|
+
* `node ace adula:resource:migration <name>` to add what is missing and apply the
|
|
61
|
+
* relaxing changes.
|
|
62
|
+
*/
|
|
63
|
+
export declare function diagnoseResourceSchemas(db: Knex, resources: readonly Resource[]): Promise<Finding>;
|
|
42
64
|
export {};
|
|
@@ -2,7 +2,9 @@ import { lstat, readFile, readdir, realpath } from 'node:fs/promises';
|
|
|
2
2
|
import { isAbsolute, join, relative } from 'node:path';
|
|
3
3
|
import { ADULA_VERSION } from '../version.js';
|
|
4
4
|
import { agentAssets, managedRules, digest } from './agent_assets.js';
|
|
5
|
-
import { columnName } from '../resource/define_resource.js';
|
|
5
|
+
import { columnName, joinTable } from '../resource/define_resource.js';
|
|
6
|
+
import { decimalShape } from '../resource/values.js';
|
|
7
|
+
import { describeDrift, inSync, migratable, schemaDrift } from '../database/schema_diff.js';
|
|
6
8
|
// The deployment volume and backup scripts share this application-relative path.
|
|
7
9
|
const UPLOADS_PATH = 'storage/uploads';
|
|
8
10
|
const UPLOADS_WARNING_BYTES = 5_000_000_000;
|
|
@@ -265,21 +267,36 @@ export async function diagnose(root, settings, production, env, now = Date.now()
|
|
|
265
267
|
/** The columns and indexes createResourceTable derives from a definition, one entry each. */
|
|
266
268
|
function tableShape(resource) {
|
|
267
269
|
const shape = new Map();
|
|
268
|
-
for (const flag of ['scoped', 'version', 'submittable'
|
|
270
|
+
for (const flag of ['scoped', 'version', 'submittable'])
|
|
269
271
|
if (resource[flag])
|
|
270
272
|
shape.set(flag, flag);
|
|
271
273
|
for (const [key, field] of Object.entries(resource.fields)) {
|
|
272
274
|
if (field.type === 'hasMany')
|
|
273
275
|
continue;
|
|
274
|
-
const column = field.
|
|
276
|
+
const column = field.type === 'manyToMany'
|
|
277
|
+
? joinTable(resource.name, key, { resource: String(field.resource), table: field.table })
|
|
278
|
+
.table
|
|
279
|
+
: (field.column ?? columnName(key));
|
|
275
280
|
const traits = [
|
|
276
|
-
field.type === 'belongsTo'
|
|
277
|
-
|
|
281
|
+
field.type === 'belongsTo' || field.type === 'manyToMany'
|
|
282
|
+
? `${field.type} ${field.resource}`
|
|
283
|
+
: field.type === 'decimal' || field.type === 'percent'
|
|
284
|
+
? `${field.type}(${Object.values(decimalShape(field)).join(',')})`
|
|
285
|
+
: field.type,
|
|
286
|
+
// The same NOT NULL rule as createResourceTable: visibleWhen may hide (and clear) it.
|
|
287
|
+
...(field.sequence || (field.required && field.visibleWhen === undefined)
|
|
288
|
+
? ['required']
|
|
289
|
+
: []),
|
|
278
290
|
...(field.unique ? ['unique'] : []),
|
|
279
291
|
...(field.searchable ? ['searchable'] : []),
|
|
292
|
+
...(field.default !== undefined && !Array.isArray(field.default)
|
|
293
|
+
? [`default ${JSON.stringify(field.default)}`]
|
|
294
|
+
: []),
|
|
280
295
|
];
|
|
281
296
|
shape.set(column, `${column} (${traits.join(', ')})`);
|
|
282
297
|
}
|
|
298
|
+
for (const keys of resource.unique ?? [])
|
|
299
|
+
shape.set(`unique ${keys.join(',')}`, `unique (${keys.join(', ')})`);
|
|
283
300
|
return shape;
|
|
284
301
|
}
|
|
285
302
|
/**
|
|
@@ -313,7 +330,7 @@ export function diagnoseResourceSnapshots(pending, resource) {
|
|
|
313
330
|
check: 'resources.snapshots',
|
|
314
331
|
status: drift.length ? 'warn' : 'pass',
|
|
315
332
|
message: drift.length
|
|
316
|
-
? `Pending create-migrations differ from their resource definitions; run node ace adula:resource:snapshot <name> (or update the embedded definition) before migration:run: ${drift.join(' | ')}`
|
|
333
|
+
? `Pending create-migrations differ from their resource definitions; run node ace adula:resource:snapshot <name> (or update the embedded definition) before migration:run; a relation to a table created by a later migration is refused, add it afterwards with node ace adula:resource:migration <name>: ${drift.join(' | ')}`
|
|
317
334
|
: 'Pending resource migrations match their definitions',
|
|
318
335
|
};
|
|
319
336
|
}
|
|
@@ -360,6 +377,36 @@ export function diagnoseWorkflowRoles(workflows, roles) {
|
|
|
360
377
|
: 'Every role addressed by a workflow step exists',
|
|
361
378
|
};
|
|
362
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* A child declared with `scope: { from }` takes its unit from its parent, so creating or
|
|
382
|
+
* updating it needs `view` on the parent (ADR 029). List roles that may write such a child
|
|
383
|
+
* but have no rule that lets them view the parent: every create and update refuses them (#140).
|
|
384
|
+
*/
|
|
385
|
+
export function diagnoseScopeParentRoles(resources, roles) {
|
|
386
|
+
const grants = (rules, subject, wanted) => rules.some((rule) => {
|
|
387
|
+
const actions = Array.isArray(rule.action) ? rule.action : [rule.action];
|
|
388
|
+
return (!rule.inverted &&
|
|
389
|
+
(rule.subject === subject || rule.subject === 'all') &&
|
|
390
|
+
actions.some((action) => action === 'manage' || wanted.includes(action)));
|
|
391
|
+
});
|
|
392
|
+
const problems = [];
|
|
393
|
+
for (const child of resources) {
|
|
394
|
+
const field = child.scope ? child.fields[child.scope.from] : undefined;
|
|
395
|
+
if (!child.scope || field?.type !== 'belongsTo')
|
|
396
|
+
continue;
|
|
397
|
+
for (const role of roles)
|
|
398
|
+
if (grants(role.rules, child.name, ['create', 'update']) &&
|
|
399
|
+
!grants(role.rules, field.resource, ['view']))
|
|
400
|
+
problems.push(`role "${role.name}": create/update on ${child.name} needs view on ${field.resource} (scope.from ${child.scope.from})`);
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
check: 'roles.scope_parents',
|
|
404
|
+
status: problems.length ? 'warn' : 'pass',
|
|
405
|
+
message: problems.length
|
|
406
|
+
? `Roles may write scope-inheriting records without viewing their parent; those creates and updates are refused: ${problems.join(', ')}`
|
|
407
|
+
: 'Every role that writes a scope-inheriting record may view its parent',
|
|
408
|
+
};
|
|
409
|
+
}
|
|
363
410
|
/** Events wait in the outbox until a worker publishes them; a stale backlog means none runs (#50). */
|
|
364
411
|
export function diagnoseOutbox(health) {
|
|
365
412
|
const { backlog, oldestAgeMs } = health.outbox;
|
|
@@ -373,3 +420,31 @@ export function diagnoseOutbox(health) {
|
|
|
373
420
|
: `No outbox event is older than ${OUTBOX_STALE_MS / 1000} s; the worker is ${worker}`,
|
|
374
421
|
};
|
|
375
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Compares every registered resource with its live table (see schemaDrift): missing
|
|
425
|
+
* columns, different types, NOT NULL columns the definition lets be empty, missing unique
|
|
426
|
+
* indexes, unique indexes still counting cancelled documents and missing join tables. Run
|
|
427
|
+
* `node ace adula:resource:migration <name>` to add what is missing and apply the
|
|
428
|
+
* relaxing changes.
|
|
429
|
+
*/
|
|
430
|
+
export async function diagnoseResourceSchemas(db, resources) {
|
|
431
|
+
const problems = [];
|
|
432
|
+
const missing = new Set();
|
|
433
|
+
for (const resource of resources) {
|
|
434
|
+
const drift = await schemaDrift(db, resource);
|
|
435
|
+
if (inSync(drift))
|
|
436
|
+
continue;
|
|
437
|
+
if (migratable(drift))
|
|
438
|
+
missing.add(resource.name);
|
|
439
|
+
problems.push(...describeDrift(drift));
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
check: 'resources.schema',
|
|
443
|
+
status: problems.length ? 'warn' : 'pass',
|
|
444
|
+
message: problems.length
|
|
445
|
+
? `The database differs from the resource definitions: ${problems.join('; ')}${missing.size
|
|
446
|
+
? `. Add what is missing with ${[...missing].map((name) => `node ace adula:resource:migration ${name}`).join(', ')}, then migration:run`
|
|
447
|
+
: ''}`
|
|
448
|
+
: 'Every resource table matches its definition',
|
|
449
|
+
};
|
|
450
|
+
}
|
|
@@ -36,7 +36,7 @@ export declare const GAP_FIELDS: readonly [{
|
|
|
36
36
|
readonly id: "workaround";
|
|
37
37
|
readonly required: false;
|
|
38
38
|
}];
|
|
39
|
-
export declare const GAPS_TEMPLATE = "# AdulaJS gaps\n\nRecord each limitation of AdulaJS as one entry. Describe AdulaJS capability, not this\nproject: reproduce it on a new
|
|
39
|
+
export declare const GAPS_TEMPLATE = "# AdulaJS gaps\n\nRecord each limitation of AdulaJS as one entry. Describe AdulaJS capability, not this\nproject: reproduce it on a new system from create-adulajs. Run `node ace adula:gaps report`\nto open AdulaJS's gap form prefilled, then write the issue number in `Issue:`.\n\n<!--\n## GAP-001 \u2014 Short title naming AdulaJS capability\nPackage: adula 1.0.0\nNeeded by: AdulaJS capability that is missing, stated without project details\nTried: AdulaJS extension points tried\nBlocked because: why none of them works\nProposed AdulaJS change: the API, option or fix AdulaJS should offer\nReproduction: steps on a new system from create-adulajs\nAcceptance: the test that proves the gap is closed\nWorkaround: none, or what the project does meanwhile\nIssue:\n-->\n";
|
|
40
40
|
export interface GapEntry {
|
|
41
41
|
title: string;
|
|
42
42
|
fields: Record<string, string>;
|
|
@@ -16,7 +16,7 @@ export const GAP_FIELDS = [
|
|
|
16
16
|
export const GAPS_TEMPLATE = `# AdulaJS gaps
|
|
17
17
|
|
|
18
18
|
Record each limitation of AdulaJS as one entry. Describe AdulaJS capability, not this
|
|
19
|
-
project: reproduce it on a new
|
|
19
|
+
project: reproduce it on a new system from create-adulajs. Run \`node ace adula:gaps report\`
|
|
20
20
|
to open AdulaJS's gap form prefilled, then write the issue number in \`Issue:\`.
|
|
21
21
|
|
|
22
22
|
<!--
|
|
@@ -26,7 +26,7 @@ Needed by: AdulaJS capability that is missing, stated without project details
|
|
|
26
26
|
Tried: AdulaJS extension points tried
|
|
27
27
|
Blocked because: why none of them works
|
|
28
28
|
Proposed AdulaJS change: the API, option or fix AdulaJS should offer
|
|
29
|
-
Reproduction: steps on a new
|
|
29
|
+
Reproduction: steps on a new system from create-adulajs
|
|
30
30
|
Acceptance: the test that proves the gap is closed
|
|
31
31
|
Workaround: none, or what the project does meanwhile
|
|
32
32
|
Issue:
|
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Label } from '../resource/types.js';
|
|
2
|
+
/** Every file a resource generation writes, computed without touching the disk. */
|
|
3
|
+
export type ResourcePlan = {
|
|
4
|
+
/** New files relative to the application root; none may exist yet. */
|
|
5
|
+
files: Record<string, string>;
|
|
6
|
+
/** The module definition after registering the resource (created when missing). */
|
|
7
|
+
module: {
|
|
8
|
+
path: string;
|
|
9
|
+
source: string;
|
|
10
|
+
};
|
|
11
|
+
/** start/modules.ts after registering the module, or null when it is already registered. */
|
|
12
|
+
modules: {
|
|
13
|
+
path: string;
|
|
14
|
+
source: string;
|
|
15
|
+
} | null;
|
|
16
|
+
};
|
|
17
|
+
/** A single-quoted TypeScript string literal. */
|
|
18
|
+
export declare function quoted(value: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Plans a scoped resource with its migration, model, validator, factory and security
|
|
21
|
+
* contract, without writing. `moduleSource` replaces the module definition read from disk
|
|
22
|
+
* (adula:app passes the module it is about to create); `label` sets the resource labels.
|
|
23
|
+
*/
|
|
24
|
+
export declare function planResource(root: string, name: string, module: string, options?: {
|
|
25
|
+
moduleSource?: string;
|
|
26
|
+
label?: Label;
|
|
27
|
+
/** Also write a VineJS validator file; by default the fields are the validator (ADR 045). */
|
|
28
|
+
validator?: boolean;
|
|
29
|
+
/** Also write a Lucid model and its factory; AdulaJS itself never reads a model. */
|
|
30
|
+
model?: boolean;
|
|
31
|
+
}): Promise<ResourcePlan>;
|
|
32
|
+
/** Writes a plan: new files first (never overwriting), then the module and the index. */
|
|
33
|
+
export declare function writeResourcePlan(root: string, plan: ResourcePlan): Promise<void>;
|
|
34
|
+
export declare function generateResource(root: string, name: string, module: string, options?: {
|
|
35
|
+
validator?: boolean;
|
|
36
|
+
model?: boolean;
|
|
37
|
+
}): Promise<string[]>;
|