adula 0.0.0 → 2.1.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/LICENSE.md +10 -0
- package/README.md +38 -2
- package/build/agent/AGENTS.template.md +28 -0
- package/build/agent/capabilities.md +60 -0
- package/build/agent/skills/adula-frontend-design/SKILL.md +59 -0
- package/build/agent/skills/idea-review/SKILL.md +31 -0
- package/build/agent/skills/module-review/SKILL.md +22 -0
- package/build/agent/skills/perf-review/SKILL.md +24 -0
- package/build/agent/skills/schema-review/SKILL.md +22 -0
- package/build/agent/skills/security-review/SKILL.md +24 -0
- package/build/agent/skills/ui-review/SKILL.md +22 -0
- package/build/commands/capabilities.d.ts +10 -0
- package/build/commands/capabilities.js +40 -0
- package/build/commands/doctor.d.ts +9 -0
- package/build/commands/doctor.js +72 -0
- package/build/commands/gaps.d.ts +12 -0
- package/build/commands/gaps.js +62 -0
- package/build/commands/install.d.ts +9 -0
- package/build/commands/install.js +105 -0
- package/build/commands/main.d.ts +8 -0
- package/build/commands/main.js +33 -0
- package/build/commands/module_add.d.ts +8 -0
- package/build/commands/module_add.js +57 -0
- package/build/commands/module_remove.d.ts +10 -0
- package/build/commands/module_remove.js +94 -0
- package/build/commands/resource.d.ts +8 -0
- package/build/commands/resource.js +29 -0
- package/build/commands/resource_snapshot.d.ts +15 -0
- package/build/commands/resource_snapshot.js +61 -0
- package/build/commands/storage_migrate.d.ts +12 -0
- package/build/commands/storage_migrate.js +39 -0
- package/build/commands/ui.d.ts +11 -0
- package/build/commands/ui.js +210 -0
- package/build/commands/upgrade.d.ts +15 -0
- package/build/commands/upgrade.js +34 -0
- package/build/configure.d.ts +2 -0
- package/build/configure.js +79 -0
- package/build/database/migrations/1770000000000_core.d.ts +5 -0
- package/build/database/migrations/1770000000000_core.js +10 -0
- package/build/database/migrations/1770000000001_attachments.d.ts +5 -0
- package/build/database/migrations/1770000000001_attachments.js +10 -0
- package/build/database/migrations/1770000000002_saved_views.d.ts +5 -0
- package/build/database/migrations/1770000000002_saved_views.js +10 -0
- package/build/database/migrations/1770000000003_user_invitations.d.ts +5 -0
- package/build/database/migrations/1770000000003_user_invitations.js +18 -0
- package/build/database/migrations/1770000000004_collaboration.d.ts +5 -0
- package/build/database/migrations/1770000000004_collaboration.js +10 -0
- package/build/database/migrations/1770000000005_assignments.d.ts +5 -0
- package/build/database/migrations/1770000000005_assignments.js +10 -0
- package/build/database/migrations/1770000000006_messaging.d.ts +5 -0
- package/build/database/migrations/1770000000006_messaging.js +10 -0
- package/build/database/migrations/1770000000007_webhooks.d.ts +5 -0
- package/build/database/migrations/1770000000007_webhooks.js +10 -0
- package/build/database/migrations/1770000000008_imports.d.ts +5 -0
- package/build/database/migrations/1770000000008_imports.js +10 -0
- package/build/database/migrations/1770000000010_workflows.d.ts +5 -0
- package/build/database/migrations/1770000000010_workflows.js +10 -0
- package/build/database/migrations/1770000000011_managed_assignments.d.ts +5 -0
- package/build/database/migrations/1770000000011_managed_assignments.js +10 -0
- package/build/database/migrations/1770000000012_role_keys.d.ts +5 -0
- package/build/database/migrations/1770000000012_role_keys.js +10 -0
- package/build/database/migrations/1770000000013_notification_targets.d.ts +5 -0
- package/build/database/migrations/1770000000013_notification_targets.js +10 -0
- package/build/database/migrations/1770000000014_upload_grants.d.ts +5 -0
- package/build/database/migrations/1770000000014_upload_grants.js +10 -0
- package/build/database/migrations/1770000000015_inbound_webhooks.d.ts +5 -0
- package/build/database/migrations/1770000000015_inbound_webhooks.js +10 -0
- package/build/database/migrations/1770000000016_adulajs_names.d.ts +6 -0
- package/build/database/migrations/1770000000016_adulajs_names.js +11 -0
- package/build/index.d.ts +80 -0
- package/build/index.js +49 -0
- package/build/providers/adula_provider.d.ts +6 -0
- package/build/providers/adula_provider.js +10 -0
- package/build/src/admin/contracts.d.ts +19 -0
- package/build/src/admin/contracts.js +115 -0
- package/build/src/admin/controller.d.ts +32 -0
- package/build/src/admin/controller.js +167 -0
- package/build/src/admin/errors.d.ts +5 -0
- package/build/src/admin/errors.js +9 -0
- package/build/src/admin/presentation.d.ts +28 -0
- package/build/src/admin/presentation.js +1 -0
- package/build/src/admin/record_title.d.ts +14 -0
- package/build/src/admin/record_title.js +50 -0
- package/build/src/admin/resource_service.d.ts +376 -0
- package/build/src/admin/resource_service.js +1448 -0
- package/build/src/attachments/attachment_service.d.ts +100 -0
- package/build/src/attachments/attachment_service.js +270 -0
- package/build/src/attachments/doctor.d.ts +4 -0
- package/build/src/attachments/doctor.js +28 -0
- package/build/src/attachments/storage_migrate.d.ts +39 -0
- package/build/src/attachments/storage_migrate.js +64 -0
- package/build/src/attachments/upload_grants.d.ts +44 -0
- package/build/src/attachments/upload_grants.js +105 -0
- package/build/src/auth/ability.d.ts +24 -0
- package/build/src/auth/ability.js +34 -0
- package/build/src/auth/actor_store.d.ts +14 -0
- package/build/src/auth/actor_store.js +70 -0
- package/build/src/auth/conditions.d.ts +26 -0
- package/build/src/auth/conditions.js +117 -0
- package/build/src/auth/packed_rules.d.ts +4 -0
- package/build/src/auth/packed_rules.js +13 -0
- package/build/src/auth/sql.d.ts +11 -0
- package/build/src/auth/sql.js +118 -0
- package/build/src/collaboration/assignments.d.ts +129 -0
- package/build/src/collaboration/assignments.js +333 -0
- package/build/src/collaboration/record_collaboration.d.ts +86 -0
- package/build/src/collaboration/record_collaboration.js +348 -0
- package/build/src/commands/agent_assets.d.ts +7 -0
- package/build/src/commands/agent_assets.js +66 -0
- package/build/src/commands/capabilities.d.ts +19 -0
- package/build/src/commands/capabilities.js +179 -0
- package/build/src/commands/doctor.d.ts +42 -0
- package/build/src/commands/doctor.js +375 -0
- package/build/src/commands/gap_report.d.ts +56 -0
- package/build/src/commands/gap_report.js +110 -0
- package/build/src/commands/generator.d.ts +1 -0
- package/build/src/commands/generator.js +70 -0
- package/build/src/commands/snapshot.d.ts +28 -0
- package/build/src/commands/snapshot.js +48 -0
- package/build/src/commands/source_markers.d.ts +11 -0
- package/build/src/commands/source_markers.js +41 -0
- package/build/src/core/activity.d.ts +43 -0
- package/build/src/core/activity.js +77 -0
- package/build/src/core/administration_guard.d.ts +3 -0
- package/build/src/core/administration_guard.js +39 -0
- package/build/src/core/health.d.ts +42 -0
- package/build/src/core/health.js +44 -0
- package/build/src/core/mail_test.d.ts +18 -0
- package/build/src/core/mail_test.js +88 -0
- package/build/src/core/message_templates.d.ts +83 -0
- package/build/src/core/message_templates.js +293 -0
- package/build/src/core/module_seed.d.ts +15 -0
- package/build/src/core/module_seed.js +31 -0
- package/build/src/core/notifications.d.ts +42 -0
- package/build/src/core/notifications.js +91 -0
- package/build/src/core/org_units.d.ts +30 -0
- package/build/src/core/org_units.js +123 -0
- package/build/src/core/roles.d.ts +98 -0
- package/build/src/core/roles.js +447 -0
- package/build/src/core/saved_views.d.ts +37 -0
- package/build/src/core/saved_views.js +164 -0
- package/build/src/core/settings.d.ts +29 -0
- package/build/src/core/settings.js +113 -0
- package/build/src/core/setup.d.ts +14 -0
- package/build/src/core/setup.js +89 -0
- package/build/src/core/ui_preferences.d.ts +12 -0
- package/build/src/core/ui_preferences.js +30 -0
- package/build/src/core/user_invitations.d.ts +23 -0
- package/build/src/core/user_invitations.js +144 -0
- package/build/src/core/users.d.ts +44 -0
- package/build/src/core/users.js +182 -0
- package/build/src/database/configure.d.ts +3 -0
- package/build/src/database/configure.js +41 -0
- package/build/src/database/schema.d.ts +52 -0
- package/build/src/database/schema.js +538 -0
- package/build/src/eslint/index.d.ts +3 -0
- package/build/src/eslint/index.js +90 -0
- package/build/src/events/adonis_jobs.d.ts +9 -0
- package/build/src/events/adonis_jobs.js +13 -0
- package/build/src/events/outbox.d.ts +19 -0
- package/build/src/events/outbox.js +33 -0
- package/build/src/events/record_mutation.d.ts +24 -0
- package/build/src/events/record_mutation.js +62 -0
- package/build/src/integrations/imports.d.ts +74 -0
- package/build/src/integrations/imports.js +333 -0
- package/build/src/integrations/inbound_webhooks.d.ts +94 -0
- package/build/src/integrations/inbound_webhooks.js +276 -0
- package/build/src/integrations/openapi.d.ts +39 -0
- package/build/src/integrations/openapi.js +323 -0
- package/build/src/integrations/print.d.ts +37 -0
- package/build/src/integrations/print.js +124 -0
- package/build/src/integrations/webhooks.d.ts +98 -0
- package/build/src/integrations/webhooks.js +298 -0
- package/build/src/mcp/tools.d.ts +8 -0
- package/build/src/mcp/tools.js +156 -0
- package/build/src/org/org_service.d.ts +2 -0
- package/build/src/org/org_service.js +16 -0
- package/build/src/resource/define_resource.d.ts +5 -0
- package/build/src/resource/define_resource.js +68 -0
- package/build/src/resource/registry.d.ts +12 -0
- package/build/src/resource/registry.js +101 -0
- package/build/src/resource/types.d.ts +155 -0
- package/build/src/resource/types.js +1 -0
- package/build/src/resource/values.d.ts +5 -0
- package/build/src/resource/values.js +88 -0
- package/build/src/services/backup.d.ts +14 -0
- package/build/src/services/backup.js +59 -0
- package/build/src/services/settings.d.ts +21 -0
- package/build/src/services/settings.js +30 -0
- package/build/src/upgrade/legacy.d.ts +27 -0
- package/build/src/upgrade/legacy.js +58 -0
- package/build/src/upgrade/rename.d.ts +17 -0
- package/build/src/upgrade/rename.js +94 -0
- package/build/src/version.d.ts +1 -0
- package/build/src/version.js +2 -0
- package/build/src/workflows/define_workflow.d.ts +124 -0
- package/build/src/workflows/define_workflow.js +123 -0
- package/build/src/workflows/engine.d.ts +141 -0
- package/build/src/workflows/engine.js +752 -0
- package/build/stubs/README.md +6 -0
- package/build/stubs/controller.stub +8 -0
- package/build/stubs/main.d.ts +5 -0
- package/build/stubs/main.js +5 -0
- package/build/stubs/main.ts +5 -0
- package/build/stubs/modules.stub +6 -0
- package/build/stubs/resource_contract.stub +1 -0
- package/build/stubs/resource_contract.txt +452 -0
- package/build/stubs/routes.stub +16 -0
- package/build/stubs/service.stub +9 -0
- package/package.json +95 -6
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BaseSchema } from '@adonisjs/lucid/schema';
|
|
2
|
+
/** 2.0.0: database objects, the version setting and listener names created by 1.x get their AdulaJS names. */
|
|
3
|
+
export default class AdulaJsNames extends BaseSchema {
|
|
4
|
+
up(): Promise<void>;
|
|
5
|
+
down(): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseSchema } from '@adonisjs/lucid/schema';
|
|
2
|
+
import { renameLegacyDatabaseObjects } from '../../src/upgrade/rename.js';
|
|
3
|
+
/** 2.0.0: database objects, the version setting and listener names created by 1.x get their AdulaJS names. */
|
|
4
|
+
export default class AdulaJsNames extends BaseSchema {
|
|
5
|
+
async up() {
|
|
6
|
+
await renameLegacyDatabaseObjects(this.db.getWriteClient());
|
|
7
|
+
}
|
|
8
|
+
async down() {
|
|
9
|
+
throw new Error('AdulaJS migrations are additive. Restore a tested backup instead of rolling back.');
|
|
10
|
+
}
|
|
11
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export { defineResource, columnName } from './src/resource/define_resource.js';
|
|
2
|
+
export { configure } from './configure.js';
|
|
3
|
+
export { withAdulaDatabase } from './src/database/configure.js';
|
|
4
|
+
export { createResourceController } from './src/admin/controller.js';
|
|
5
|
+
export type { ResourceRuntime, ResourceList, ResourceEditor, ResourceShow, ResourceChildren, ResourceLookups, ResourceActivity, } from './src/admin/controller.js';
|
|
6
|
+
export type * from './src/admin/presentation.js';
|
|
7
|
+
export { ResourceRegistry } from './src/resource/registry.js';
|
|
8
|
+
export type * from './src/resource/types.js';
|
|
9
|
+
export { buildAbility, canRecord, inOrgScope } from './src/auth/ability.js';
|
|
10
|
+
export { packedResourceRules } from './src/auth/packed_rules.js';
|
|
11
|
+
export type { Actor, Rule, AdulaAbility } from './src/auth/ability.js';
|
|
12
|
+
export { ActorStore } from './src/auth/actor_store.js';
|
|
13
|
+
export { accessibleBy, authorizationSql, conditionSql } from './src/auth/sql.js';
|
|
14
|
+
export { ACTOR_ID, resolveActorConditions } from './src/auth/conditions.js';
|
|
15
|
+
export { ResourceService, canQueryField } from './src/admin/resource_service.js';
|
|
16
|
+
export type { AggregateOptions, AggregateRow, ListOptions } from './src/admin/resource_service.js';
|
|
17
|
+
export { serialize, writableInput, selectedFields } from './src/admin/contracts.js';
|
|
18
|
+
export { AdulaError } from './src/admin/errors.js';
|
|
19
|
+
export { createCoreSchema, createResourceTable, createAttachmentsSchema, createSavedViewsSchema, createCollaborationSchema, createAssignmentsSchema, createMessagingSchema, createWebhooksSchema, createImportsSchema, createWorkflowSchema, createManagedAssignmentsSchema, createRoleKeysSchema, createNotificationTargetsSchema, createUploadGrantsSchema, createInboundWebhooksSchema, } from './src/database/schema.js';
|
|
20
|
+
export { defineWorkflow, nextStep } from './src/workflows/define_workflow.js';
|
|
21
|
+
export type { WorkflowDefinition, WorkflowInput, WorkflowStep, WorkflowEvent, StepContext, Recipients, DecisionOutcome, } from './src/workflows/define_workflow.js';
|
|
22
|
+
export { WorkflowEngine, workflowListeners } from './src/workflows/engine.js';
|
|
23
|
+
export type { WorkflowRun, WorkflowRunStatus, WorkflowOptions, WorkflowDecisionForm, } from './src/workflows/engine.js';
|
|
24
|
+
export { ImportBatches, importCell, IMPORT_ROW_LIMIT } from './src/integrations/imports.js';
|
|
25
|
+
export type { ImportBatch, ImportStatus, ImportTarget, ActorSource, } from './src/integrations/imports.js';
|
|
26
|
+
export { openApiDocument } from './src/integrations/openapi.js';
|
|
27
|
+
export { renderPrintHtml, htmlToPdf } from './src/integrations/print.js';
|
|
28
|
+
export type { PrintIdentity, PrintInput } from './src/integrations/print.js';
|
|
29
|
+
export { Webhooks, signWebhook, WEBHOOK_MAX_ATTEMPTS } from './src/integrations/webhooks.js';
|
|
30
|
+
export { InboundWebhooks, inboundEventName, INBOUND_BODY_LIMIT, INBOUND_RETENTION_DAYS, } from './src/integrations/inbound_webhooks.js';
|
|
31
|
+
export type { InboundSource, InboundSourceInput, InboundDelivery, InboundReceipt, } from './src/integrations/inbound_webhooks.js';
|
|
32
|
+
export type { SecretBox, Webhook, WebhookDelivery, WebhookOptions, HttpPoster, } from './src/integrations/webhooks.js';
|
|
33
|
+
export { MessageTemplates, DEFAULT_TEMPLATES, renderTemplate, notifyWithTemplate, deliverNotificationMail, listenForNotifications, } from './src/core/message_templates.js';
|
|
34
|
+
export type { TemplateDefinition, MessageTemplate, RenderedMessage, MailSender, NotificationSignal, } from './src/core/message_templates.js';
|
|
35
|
+
export { Assignments } from './src/collaboration/assignments.js';
|
|
36
|
+
export type { Assignment, AssignmentPage, AssignmentOptions, CloseNotePolicy, AssignmentStatus, } from './src/collaboration/assignments.js';
|
|
37
|
+
export { RecordCollaboration, followerListeners } from './src/collaboration/record_collaboration.js';
|
|
38
|
+
export type { ActorLoader, CommentEntry, FieldChangeEntry, RecordCollaborationState, MentionCandidate, } from './src/collaboration/record_collaboration.js';
|
|
39
|
+
export type { FieldChange } from './src/events/record_mutation.js';
|
|
40
|
+
export { registerUpload, findAttachment, loadAttachments, claimAttachment, releaseAttachment, summarizeAttachment, attachmentUrl, isAttachmentId, isRelativeDiskPath, attachmentPolicy, pendingUploadCount, staleUploads, forgetUpload, DEFAULT_ATTACHMENT_EXTENSIONS, PENDING_UPLOAD_LIMIT, UNBOUND_UPLOAD_TTL_MS, } from './src/attachments/attachment_service.js';
|
|
41
|
+
export type { AttachmentRecord, AttachmentSummary, UploadInput, ClaimInput, } from './src/attachments/attachment_service.js';
|
|
42
|
+
export { grantUpload, redeemUploadGrant, pruneUploadGrants, UPLOAD_GRANT_MAX_TTL_MS, } from './src/attachments/upload_grants.js';
|
|
43
|
+
export type { UploadGrantInput, UploadGrant, RedeemedUploadGrant, } from './src/attachments/upload_grants.js';
|
|
44
|
+
export { migrateStorage } from './src/attachments/storage_migrate.js';
|
|
45
|
+
export type { StorageDisk, StorageMigrationOptions, StorageMigrationResult, } from './src/attachments/storage_migrate.js';
|
|
46
|
+
export { diagnoseAttachments } from './src/attachments/doctor.js';
|
|
47
|
+
export { Settings, sequence, notify } from './src/services/settings.js';
|
|
48
|
+
export type { NotificationTarget } from './src/services/settings.js';
|
|
49
|
+
export { uiPreferences, validateUiPreferences, UI_PREFERENCES_KEY, DEFAULT_UI_PREFERENCES, } from './src/core/ui_preferences.js';
|
|
50
|
+
export type { UiPreferences, CalendarSystem, CalendarPreference, } from './src/core/ui_preferences.js';
|
|
51
|
+
export { moveOrgUnit } from './src/org/org_service.js';
|
|
52
|
+
export { publishOutbox, consumeEvent } from './src/events/outbox.js';
|
|
53
|
+
export type { Jobs, DomainEvent, Listener } from './src/events/outbox.js';
|
|
54
|
+
export { AdonisJobs } from './src/events/adonis_jobs.js';
|
|
55
|
+
export { recordMutation } from './src/events/record_mutation.js';
|
|
56
|
+
export { assessBackup, verifyBackup } from './src/services/backup.js';
|
|
57
|
+
export type { BackupObject, BackupStatus } from './src/services/backup.js';
|
|
58
|
+
export { ActivityAdmin, logActivity } from './src/core/activity.js';
|
|
59
|
+
export type { ActivityEntry, ActivityFilters, ActivityPage, ActivityRow, } from './src/core/activity.js';
|
|
60
|
+
export { RolesAdmin, ALL_SUBJECT_LABEL } from './src/core/roles.js';
|
|
61
|
+
export { seedModules } from './src/core/module_seed.js';
|
|
62
|
+
export type { ModuleSeedResult } from './src/core/module_seed.js';
|
|
63
|
+
export type { RoleSummary, RoleDetail, RoleRule, RuleInput, RoleMatrix, MatrixSubject, MatrixField, } from './src/core/roles.js';
|
|
64
|
+
export { UsersAdmin } from './src/core/users.js';
|
|
65
|
+
export { UserInvitations, type InvitationDelivery } from './src/core/user_invitations.js';
|
|
66
|
+
export type { UserSummary, UserPage, UserRoleAssignment, UserOrgUnit } from './src/core/users.js';
|
|
67
|
+
export { OrgUnitsAdmin } from './src/core/org_units.js';
|
|
68
|
+
export type { OrgUnitNode } from './src/core/org_units.js';
|
|
69
|
+
export { SavedViews } from './src/core/saved_views.js';
|
|
70
|
+
export type { SavedView, SavedViewQuery } from './src/core/saved_views.js';
|
|
71
|
+
export { NotificationsAdmin } from './src/core/notifications.js';
|
|
72
|
+
export type { Notification, NotificationPage } from './src/core/notifications.js';
|
|
73
|
+
export { SettingsAdmin, isProtectedSetting, parseSettingValue, SETTING_SCOPES, PROTECTED_SETTING_KEYS, } from './src/core/settings.js';
|
|
74
|
+
export type { SettingScope, SettingRow, SettingInput } from './src/core/settings.js';
|
|
75
|
+
export { runtimeHealth, isBackupStale, backupStale, heartbeat, HEARTBEAT_MAX_AGE_MS, BACKUP_MAX_AGE_MS, } from './src/core/health.js';
|
|
76
|
+
export type { RuntimeHealth, HeartbeatStatus, QueueSnapshot, QueueCounts, FailedJob, } from './src/core/health.js';
|
|
77
|
+
export { MailDeliveryTest, MAIL_TEST_KEY, type MailTestState } from './src/core/mail_test.js';
|
|
78
|
+
export { InitialSetup, type SetupCheck } from './src/core/setup.js';
|
|
79
|
+
export { ADULA_VERSION } from './src/version.js';
|
|
80
|
+
export { capabilityCatalog, SERVICES as CAPABILITY_SERVICES, FIELD_TYPES, WORKFLOW_STEPS, } from './src/commands/capabilities.js';
|
package/build/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export { defineResource, columnName } from './src/resource/define_resource.js';
|
|
2
|
+
export { configure } from './configure.js';
|
|
3
|
+
export { withAdulaDatabase } from './src/database/configure.js';
|
|
4
|
+
export { createResourceController } from './src/admin/controller.js';
|
|
5
|
+
export { ResourceRegistry } from './src/resource/registry.js';
|
|
6
|
+
export { buildAbility, canRecord, inOrgScope } from './src/auth/ability.js';
|
|
7
|
+
export { packedResourceRules } from './src/auth/packed_rules.js';
|
|
8
|
+
export { ActorStore } from './src/auth/actor_store.js';
|
|
9
|
+
export { accessibleBy, authorizationSql, conditionSql } from './src/auth/sql.js';
|
|
10
|
+
export { ACTOR_ID, resolveActorConditions } from './src/auth/conditions.js';
|
|
11
|
+
export { ResourceService, canQueryField } from './src/admin/resource_service.js';
|
|
12
|
+
export { serialize, writableInput, selectedFields } from './src/admin/contracts.js';
|
|
13
|
+
export { AdulaError } from './src/admin/errors.js';
|
|
14
|
+
export { createCoreSchema, createResourceTable, createAttachmentsSchema, createSavedViewsSchema, createCollaborationSchema, createAssignmentsSchema, createMessagingSchema, createWebhooksSchema, createImportsSchema, createWorkflowSchema, createManagedAssignmentsSchema, createRoleKeysSchema, createNotificationTargetsSchema, createUploadGrantsSchema, createInboundWebhooksSchema, } from './src/database/schema.js';
|
|
15
|
+
export { defineWorkflow, nextStep } from './src/workflows/define_workflow.js';
|
|
16
|
+
export { WorkflowEngine, workflowListeners } from './src/workflows/engine.js';
|
|
17
|
+
export { ImportBatches, importCell, IMPORT_ROW_LIMIT } from './src/integrations/imports.js';
|
|
18
|
+
export { openApiDocument } from './src/integrations/openapi.js';
|
|
19
|
+
export { renderPrintHtml, htmlToPdf } from './src/integrations/print.js';
|
|
20
|
+
export { Webhooks, signWebhook, WEBHOOK_MAX_ATTEMPTS } from './src/integrations/webhooks.js';
|
|
21
|
+
export { InboundWebhooks, inboundEventName, INBOUND_BODY_LIMIT, INBOUND_RETENTION_DAYS, } from './src/integrations/inbound_webhooks.js';
|
|
22
|
+
export { MessageTemplates, DEFAULT_TEMPLATES, renderTemplate, notifyWithTemplate, deliverNotificationMail, listenForNotifications, } from './src/core/message_templates.js';
|
|
23
|
+
export { Assignments } from './src/collaboration/assignments.js';
|
|
24
|
+
export { RecordCollaboration, followerListeners } from './src/collaboration/record_collaboration.js';
|
|
25
|
+
export { registerUpload, findAttachment, loadAttachments, claimAttachment, releaseAttachment, summarizeAttachment, attachmentUrl, isAttachmentId, isRelativeDiskPath, attachmentPolicy, pendingUploadCount, staleUploads, forgetUpload, DEFAULT_ATTACHMENT_EXTENSIONS, PENDING_UPLOAD_LIMIT, UNBOUND_UPLOAD_TTL_MS, } from './src/attachments/attachment_service.js';
|
|
26
|
+
export { grantUpload, redeemUploadGrant, pruneUploadGrants, UPLOAD_GRANT_MAX_TTL_MS, } from './src/attachments/upload_grants.js';
|
|
27
|
+
export { migrateStorage } from './src/attachments/storage_migrate.js';
|
|
28
|
+
export { diagnoseAttachments } from './src/attachments/doctor.js';
|
|
29
|
+
export { Settings, sequence, notify } from './src/services/settings.js';
|
|
30
|
+
export { uiPreferences, validateUiPreferences, UI_PREFERENCES_KEY, DEFAULT_UI_PREFERENCES, } from './src/core/ui_preferences.js';
|
|
31
|
+
export { moveOrgUnit } from './src/org/org_service.js';
|
|
32
|
+
export { publishOutbox, consumeEvent } from './src/events/outbox.js';
|
|
33
|
+
export { AdonisJobs } from './src/events/adonis_jobs.js';
|
|
34
|
+
export { recordMutation } from './src/events/record_mutation.js';
|
|
35
|
+
export { assessBackup, verifyBackup } from './src/services/backup.js';
|
|
36
|
+
export { ActivityAdmin, logActivity } from './src/core/activity.js';
|
|
37
|
+
export { RolesAdmin, ALL_SUBJECT_LABEL } from './src/core/roles.js';
|
|
38
|
+
export { seedModules } from './src/core/module_seed.js';
|
|
39
|
+
export { UsersAdmin } from './src/core/users.js';
|
|
40
|
+
export { UserInvitations } from './src/core/user_invitations.js';
|
|
41
|
+
export { OrgUnitsAdmin } from './src/core/org_units.js';
|
|
42
|
+
export { SavedViews } from './src/core/saved_views.js';
|
|
43
|
+
export { NotificationsAdmin } from './src/core/notifications.js';
|
|
44
|
+
export { SettingsAdmin, isProtectedSetting, parseSettingValue, SETTING_SCOPES, PROTECTED_SETTING_KEYS, } from './src/core/settings.js';
|
|
45
|
+
export { runtimeHealth, isBackupStale, backupStale, heartbeat, HEARTBEAT_MAX_AGE_MS, BACKUP_MAX_AGE_MS, } from './src/core/health.js';
|
|
46
|
+
export { MailDeliveryTest, MAIL_TEST_KEY } from './src/core/mail_test.js';
|
|
47
|
+
export { InitialSetup } from './src/core/setup.js';
|
|
48
|
+
export { ADULA_VERSION } from './src/version.js';
|
|
49
|
+
export { capabilityCatalog, SERVICES as CAPABILITY_SERVICES, FIELD_TYPES, WORKFLOW_STEPS, } from './src/commands/capabilities.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AdulaAbility, Actor } from '../auth/ability.js';
|
|
2
|
+
import type { RecordData, Resource, JsonValue, SerializedRecord } from '../resource/types.js';
|
|
3
|
+
export declare function selectedFields(resource: Resource, ability: AdulaAbility, options?: {
|
|
4
|
+
write?: boolean;
|
|
5
|
+
extra?: string[];
|
|
6
|
+
}): string[];
|
|
7
|
+
export declare function fromRow(row: RecordData, resource: Resource): RecordData;
|
|
8
|
+
export declare function jsonValue(value: unknown): JsonValue;
|
|
9
|
+
export declare function serialize(resource: Resource, record: RecordData, ability: AdulaAbility, actor: Actor): SerializedRecord;
|
|
10
|
+
export declare function writableInput(resource: Resource, input: RecordData): {
|
|
11
|
+
[k: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Values module code may write through ResourceService.systemSave: every stored field
|
|
15
|
+
* except sequences and inline children, plus the organization unit when it is not inherited.
|
|
16
|
+
*/
|
|
17
|
+
export declare function systemInput(resource: Resource, input: RecordData): {
|
|
18
|
+
[k: string]: unknown;
|
|
19
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { subject } from '@casl/ability';
|
|
2
|
+
import { conditionFields } from '../auth/ability.js';
|
|
3
|
+
import { columnName } from '../resource/define_resource.js';
|
|
4
|
+
import { AdulaError } from './errors.js';
|
|
5
|
+
const standard = ['id', 'createdBy', 'updatedBy', 'createdAt', 'updatedAt', 'deletedAt'];
|
|
6
|
+
export function selectedFields(resource, ability, options = {}) {
|
|
7
|
+
return [
|
|
8
|
+
...new Set([
|
|
9
|
+
...standard,
|
|
10
|
+
...(resource.scoped ? ['orgUnitId'] : []),
|
|
11
|
+
...(resource.version ? ['version'] : []),
|
|
12
|
+
...(resource.submittable ? ['docStatus', 'amendedFromId'] : []),
|
|
13
|
+
...(options.write
|
|
14
|
+
? Object.keys(resource.fields)
|
|
15
|
+
: (resource.serialize ?? [...resource.list, ...resource.show])),
|
|
16
|
+
...Object.keys(resource.fields).filter((k) => ['belongsTo', 'user'].includes(resource.fields[k].type)),
|
|
17
|
+
...(options.extra ?? []),
|
|
18
|
+
...conditionFields(ability, resource),
|
|
19
|
+
]),
|
|
20
|
+
].filter((key) => key !== 'orgPath' && resource.fields[key]?.type !== 'hasMany');
|
|
21
|
+
}
|
|
22
|
+
const rowKeys = new WeakMap();
|
|
23
|
+
/** Record keys and their columns for a resource, computed once per definition. */
|
|
24
|
+
function keysOf(resource) {
|
|
25
|
+
let keys = rowKeys.get(resource);
|
|
26
|
+
if (!keys) {
|
|
27
|
+
keys = [
|
|
28
|
+
...standard,
|
|
29
|
+
'orgUnitId',
|
|
30
|
+
'version',
|
|
31
|
+
'docStatus',
|
|
32
|
+
'amendedFromId',
|
|
33
|
+
'orgPath',
|
|
34
|
+
...Object.keys(resource.fields),
|
|
35
|
+
].map((key) => [key, resource.fields[key]?.column ?? columnName(key)]);
|
|
36
|
+
rowKeys.set(resource, keys);
|
|
37
|
+
}
|
|
38
|
+
return keys;
|
|
39
|
+
}
|
|
40
|
+
export function fromRow(row, resource) {
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, column] of keysOf(resource)) {
|
|
43
|
+
if (column in row) {
|
|
44
|
+
const value = row[column];
|
|
45
|
+
result[key] =
|
|
46
|
+
value instanceof Date
|
|
47
|
+
? resource.fields[key]?.type === 'date'
|
|
48
|
+
? // pg parses DATE as local midnight. Preserve its calendar day;
|
|
49
|
+
// converting to UTC first shifts it in positive-offset time zones.
|
|
50
|
+
`${String(value.getFullYear()).padStart(4, '0')}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
|
|
51
|
+
: value.toISOString()
|
|
52
|
+
: value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
export function jsonValue(value) {
|
|
58
|
+
if (value === null || value === undefined)
|
|
59
|
+
return null;
|
|
60
|
+
if (typeof value === 'string' || typeof value === 'boolean')
|
|
61
|
+
return value;
|
|
62
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
63
|
+
return value;
|
|
64
|
+
if (typeof value === 'bigint')
|
|
65
|
+
return value.toString();
|
|
66
|
+
if (value instanceof Date)
|
|
67
|
+
return value.toISOString();
|
|
68
|
+
if (Array.isArray(value))
|
|
69
|
+
return value.map(jsonValue);
|
|
70
|
+
if (typeof value === 'object')
|
|
71
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, jsonValue(entry)]));
|
|
72
|
+
throw new Error('Non-serializable resource value');
|
|
73
|
+
}
|
|
74
|
+
export function serialize(resource, record, ability, actor) {
|
|
75
|
+
const result = { id: jsonValue(record.id) };
|
|
76
|
+
const fields = resource.serialize ?? [...new Set([...resource.list, ...resource.show])];
|
|
77
|
+
for (const key of fields) {
|
|
78
|
+
const minimum = Math.max(resource.fields[key]?.permissionLevel ?? 0, resource.hidden?.includes(key) ? 1 : 0);
|
|
79
|
+
if (actor.permissionLevel >= minimum &&
|
|
80
|
+
ability.can('view', subject(resource.name, record), key) &&
|
|
81
|
+
key in record)
|
|
82
|
+
result[key] = jsonValue(record[key]);
|
|
83
|
+
}
|
|
84
|
+
if (resource.version)
|
|
85
|
+
result.version = jsonValue(record.version);
|
|
86
|
+
if (resource.submittable)
|
|
87
|
+
result.docStatus = jsonValue(record.docStatus);
|
|
88
|
+
if (resource.scoped)
|
|
89
|
+
result.orgUnitId = jsonValue(record.orgUnitId);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
export function writableInput(resource, input) {
|
|
93
|
+
const allowed = new Set([
|
|
94
|
+
...resource.form,
|
|
95
|
+
...(resource.scoped && !resource.scope ? ['orgUnitId'] : []),
|
|
96
|
+
...(resource.version ? ['version'] : []),
|
|
97
|
+
]);
|
|
98
|
+
for (const key of Object.keys(input))
|
|
99
|
+
if (!allowed.has(key))
|
|
100
|
+
throw new AdulaError(422, 'E_FIELD_NOT_WRITABLE', `Field is not writable: ${key}`);
|
|
101
|
+
return Object.fromEntries(Object.entries(input).filter(([key]) => resource.form.includes(key)));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Values module code may write through ResourceService.systemSave: every stored field
|
|
105
|
+
* except sequences and inline children, plus the organization unit when it is not inherited.
|
|
106
|
+
*/
|
|
107
|
+
export function systemInput(resource, input) {
|
|
108
|
+
for (const key of Object.keys(input)) {
|
|
109
|
+
const field = resource.fields[key];
|
|
110
|
+
const unit = key === 'orgUnitId' && resource.scoped && !resource.scope;
|
|
111
|
+
if (!unit && (!field || field.type === 'hasMany' || field.sequence))
|
|
112
|
+
throw new AdulaError(422, 'E_FIELD_NOT_WRITABLE', `Field is not writable: ${key}`);
|
|
113
|
+
}
|
|
114
|
+
return Object.fromEntries(Object.entries(input).filter(([key]) => key in resource.fields));
|
|
115
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
2
|
+
import type { Actor } from '../auth/ability.js';
|
|
3
|
+
import type { ResourceRegistry } from '../resource/registry.js';
|
|
4
|
+
import type { Resource } from '../resource/types.js';
|
|
5
|
+
import type { ResourceService } from './resource_service.js';
|
|
6
|
+
export type ResourceRuntime = {
|
|
7
|
+
registry: ResourceRegistry;
|
|
8
|
+
resources: ResourceService;
|
|
9
|
+
actor: Actor;
|
|
10
|
+
};
|
|
11
|
+
export type ResourceList = Awaited<ReturnType<ResourceService['list']>>;
|
|
12
|
+
export type ResourceEditor = Awaited<ReturnType<ResourceService['editor']>>;
|
|
13
|
+
export type ResourceShow = Awaited<ReturnType<ResourceService['show']>>;
|
|
14
|
+
export type ResourceChildren = Awaited<ReturnType<ResourceService['children']>>;
|
|
15
|
+
export type ResourceLookups = Awaited<ReturnType<ResourceService['lookups']>>;
|
|
16
|
+
export type ResourceActivity = Awaited<ReturnType<ResourceService['activity']>>;
|
|
17
|
+
export interface ResourceController {
|
|
18
|
+
index(ctx: HttpContext): Promise<unknown>;
|
|
19
|
+
show(ctx: HttpContext): Promise<unknown>;
|
|
20
|
+
store(ctx: HttpContext): Promise<unknown>;
|
|
21
|
+
update(ctx: HttpContext): Promise<unknown>;
|
|
22
|
+
destroy(ctx: HttpContext): Promise<unknown>;
|
|
23
|
+
submit(ctx: HttpContext): Promise<unknown>;
|
|
24
|
+
cancel(ctx: HttpContext): Promise<unknown>;
|
|
25
|
+
amend(ctx: HttpContext): Promise<unknown>;
|
|
26
|
+
create(ctx: HttpContext): Promise<unknown>;
|
|
27
|
+
edit(ctx: HttpContext): Promise<unknown>;
|
|
28
|
+
options(ctx: HttpContext): Promise<unknown>;
|
|
29
|
+
aggregate(ctx: HttpContext): Promise<unknown>;
|
|
30
|
+
}
|
|
31
|
+
/** The host supplies its authenticated actor; ResourceService authorizes every action. */
|
|
32
|
+
export declare function createResourceController(resolveRuntime: (ctx: HttpContext) => Promise<ResourceRuntime>, renderList?: (ctx: HttpContext, resource: Resource, result: ResourceList) => unknown, renderForm?: (ctx: HttpContext, resource: Resource, editor: ResourceEditor) => unknown, renderShow?: (ctx: HttpContext, resource: Resource, result: ResourceShow) => unknown): new () => ResourceController;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { AdulaError } from './errors.js';
|
|
2
|
+
/** The host supplies its authenticated actor; ResourceService authorizes every action. */
|
|
3
|
+
export function createResourceController(resolveRuntime, renderList, renderForm, renderShow) {
|
|
4
|
+
return class ResourcesController {
|
|
5
|
+
async create(ctx) {
|
|
6
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => {
|
|
7
|
+
// `?defaults[field]=value` pre-fills the form; the service authorizes each value.
|
|
8
|
+
const defaults = ctx.request.qs().defaults;
|
|
9
|
+
const editor = await resources.editor(resource.name, actor, undefined, {
|
|
10
|
+
defaults: defaults && typeof defaults === 'object' && !Array.isArray(defaults)
|
|
11
|
+
? defaults
|
|
12
|
+
: undefined,
|
|
13
|
+
});
|
|
14
|
+
return renderForm && ctx.request.accepts(['html', 'json']) === 'html'
|
|
15
|
+
? renderForm(ctx, resource, editor)
|
|
16
|
+
: editor;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async edit(ctx) {
|
|
20
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => {
|
|
21
|
+
const editor = await resources.editor(resource.name, actor, this.#id(ctx));
|
|
22
|
+
return renderForm && ctx.request.accepts(['html', 'json']) === 'html'
|
|
23
|
+
? renderForm(ctx, resource, editor)
|
|
24
|
+
: editor;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async index(ctx) {
|
|
28
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => {
|
|
29
|
+
const result = await resources.list(resource.name, actor, {
|
|
30
|
+
limit: ctx.request.input('limit'),
|
|
31
|
+
cursor: ctx.request.input('cursor'),
|
|
32
|
+
search: ctx.request.input('search'),
|
|
33
|
+
sort: ctx.request.input('sort'),
|
|
34
|
+
direction: ctx.request.input('direction'),
|
|
35
|
+
filters: ctx.request.input('filters'),
|
|
36
|
+
tag: ctx.request.input('tag'),
|
|
37
|
+
estimate: ctx.request.input('estimate') !== 'false' && ctx.request.input('estimate') !== false,
|
|
38
|
+
});
|
|
39
|
+
return renderList && ctx.request.accepts(['html', 'json']) === 'html'
|
|
40
|
+
? renderList(ctx, resource, result)
|
|
41
|
+
: result;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async show(ctx) {
|
|
45
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => {
|
|
46
|
+
const result = await resources.show(resource.name, this.#id(ctx), actor);
|
|
47
|
+
return renderShow && ctx.request.accepts(['html', 'json']) === 'html'
|
|
48
|
+
? renderShow(ctx, resource, result)
|
|
49
|
+
: result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async options(ctx) {
|
|
53
|
+
return this.#execute(ctx, ({ resources, actor }, resource) => resources.relationOptions(resource.name, ctx.params.field, actor, {
|
|
54
|
+
id: ctx.request.input('id') === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: this.#positiveId(ctx.request.input('id')),
|
|
57
|
+
search: ctx.request.input('search'),
|
|
58
|
+
cursor: ctx.request.input('cursor'),
|
|
59
|
+
orgUnitId: ctx.request.input('orgUnitId') === undefined || ctx.request.input('orgUnitId') === ''
|
|
60
|
+
? undefined
|
|
61
|
+
: this.#positiveId(ctx.request.input('orgUnitId')),
|
|
62
|
+
purpose: ctx.request.input('purpose') === 'filter' ? 'filter' : 'form',
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* GET …/aggregate?groupBy=status,priority&sum=total&filters[x]=…&where={json}
|
|
67
|
+
* Counts and totals over the records the actor may view (ResourceService.aggregate).
|
|
68
|
+
*/
|
|
69
|
+
async aggregate(ctx) {
|
|
70
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => {
|
|
71
|
+
const list = (value) => value === undefined || value === ''
|
|
72
|
+
? []
|
|
73
|
+
: Array.isArray(value)
|
|
74
|
+
? value.map(String)
|
|
75
|
+
: String(value).split(',').filter(Boolean);
|
|
76
|
+
let where;
|
|
77
|
+
const raw = ctx.request.input('where');
|
|
78
|
+
if (typeof raw === 'string' && raw) {
|
|
79
|
+
try {
|
|
80
|
+
where = JSON.parse(raw);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
throw new AdulaError(422, 'E_FILTER', 'where must be a JSON object');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if (raw && typeof raw === 'object')
|
|
87
|
+
where = raw;
|
|
88
|
+
return {
|
|
89
|
+
data: await resources.aggregate(resource.name, actor, {
|
|
90
|
+
groupBy: list(ctx.request.input('groupBy')),
|
|
91
|
+
sum: list(ctx.request.input('sum')),
|
|
92
|
+
count: ctx.request.input('count') !== 'false',
|
|
93
|
+
filters: ctx.request.input('filters'),
|
|
94
|
+
where: where,
|
|
95
|
+
search: ctx.request.input('search'),
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async store(ctx) {
|
|
101
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => ctx.response.created({
|
|
102
|
+
data: await resources.save(resource.name, actor, ctx.request.body()),
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
async update(ctx) {
|
|
106
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => ({
|
|
107
|
+
data: await resources.save(resource.name, actor, ctx.request.body(), this.#id(ctx)),
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
async destroy(ctx) {
|
|
111
|
+
return this.#transition(ctx, 'delete');
|
|
112
|
+
}
|
|
113
|
+
async submit(ctx) {
|
|
114
|
+
return this.#transition(ctx, 'submit');
|
|
115
|
+
}
|
|
116
|
+
async cancel(ctx) {
|
|
117
|
+
return this.#transition(ctx, 'cancel');
|
|
118
|
+
}
|
|
119
|
+
async amend(ctx) {
|
|
120
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => ctx.response.created({
|
|
121
|
+
data: await resources.amend(resource.name, this.#id(ctx), actor),
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
#id(ctx) {
|
|
125
|
+
return this.#positiveId(ctx.params.id);
|
|
126
|
+
}
|
|
127
|
+
#positiveId(value) {
|
|
128
|
+
const id = Number(value);
|
|
129
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
130
|
+
throw new AdulaError(404, 'E_NOT_FOUND', 'السجل غير موجود');
|
|
131
|
+
return id;
|
|
132
|
+
}
|
|
133
|
+
async #transition(ctx, action) {
|
|
134
|
+
return this.#execute(ctx, async ({ resources, actor }, resource) => ({
|
|
135
|
+
data: await resources.transition(resource.name, this.#id(ctx), actor, action, ctx.request.input('version')),
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
async #execute(ctx, action) {
|
|
139
|
+
try {
|
|
140
|
+
const runtime = await resolveRuntime(ctx);
|
|
141
|
+
let resource;
|
|
142
|
+
try {
|
|
143
|
+
resource = runtime.registry.get(ctx.params.resource);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
throw new AdulaError(404, 'E_NOT_FOUND', 'الكيان غير موجود');
|
|
147
|
+
}
|
|
148
|
+
return await action(runtime, resource);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
if (error instanceof AdulaError)
|
|
152
|
+
return ctx.response
|
|
153
|
+
.status(error.status)
|
|
154
|
+
.send({ error: { code: error.code, message: error.message } });
|
|
155
|
+
if (error?.code === '23505')
|
|
156
|
+
return ctx.response.conflict({
|
|
157
|
+
error: { code: 'E_DUPLICATE', message: 'هذه القيمة مستخدمة في سجل آخر' },
|
|
158
|
+
});
|
|
159
|
+
if (error?.code === '23503')
|
|
160
|
+
return ctx.response.unprocessableEntity({
|
|
161
|
+
error: { code: 'E_RELATION', message: 'تحقق من السجلات المرتبطة' },
|
|
162
|
+
});
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Action, Field } from '../resource/types.js';
|
|
2
|
+
export type ResourceField = Field & {
|
|
3
|
+
key: string;
|
|
4
|
+
};
|
|
5
|
+
export type RecordPermissions = Partial<Record<Action, boolean>>;
|
|
6
|
+
export type ResourceDescription = {
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
/** Singular record noun in Arabic, or null when the resource does not declare one. */
|
|
10
|
+
recordLabel: string | null;
|
|
11
|
+
/** Arabic create-button text, or null to derive «إضافة <recordLabel>» (or «إضافة سجل»). */
|
|
12
|
+
createLabel: string | null;
|
|
13
|
+
fields: ResourceField[];
|
|
14
|
+
list: string[];
|
|
15
|
+
show: string[];
|
|
16
|
+
searchable: boolean;
|
|
17
|
+
canCreate: boolean;
|
|
18
|
+
scoped: boolean;
|
|
19
|
+
submittable: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type ResourceNavigation = {
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
href: string;
|
|
25
|
+
module: string;
|
|
26
|
+
/** Arabic module label, for grouping the navigation by module (1.2; optional for compatibility). */
|
|
27
|
+
moduleLabel?: string;
|
|
28
|
+
}[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Resource, SerializedRecord } from '../resource/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The fields that name a record wherever it is referenced (#47, #32): the resource's
|
|
4
|
+
* `title`, or else its first sequence field and its first text field in `list`. Lookup
|
|
5
|
+
* keys are never shown raw; declared lookup fields are shown by their Arabic label.
|
|
6
|
+
*/
|
|
7
|
+
export declare function titleFields(resource: Pick<Resource, 'fields' | 'list' | 'title'>): string[];
|
|
8
|
+
/** Definition check: title fields exist, are readable and have a displayable type. */
|
|
9
|
+
export declare function assertTitle(resource: Pick<Resource, 'name' | 'fields' | 'list' | 'show' | 'serialize' | 'title'>): void;
|
|
10
|
+
/**
|
|
11
|
+
* The title of one serialized record, read after field-level filtering so it never shows
|
|
12
|
+
* a value the viewer may not read. Returns null when no title field has a value.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatTitle(resource: Pick<Resource, 'fields' | 'list' | 'title'>, record: SerializedRecord, lookupLabel: (group: string, key: string) => string | undefined): string | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const TITLE_TYPES = new Set(['string', 'text', 'integer', 'money', 'date', 'datetime', 'lookup']);
|
|
2
|
+
/**
|
|
3
|
+
* The fields that name a record wherever it is referenced (#47, #32): the resource's
|
|
4
|
+
* `title`, or else its first sequence field and its first text field in `list`. Lookup
|
|
5
|
+
* keys are never shown raw; declared lookup fields are shown by their Arabic label.
|
|
6
|
+
*/
|
|
7
|
+
export function titleFields(resource) {
|
|
8
|
+
if (resource.title)
|
|
9
|
+
return [...resource.title];
|
|
10
|
+
const sequence = Object.keys(resource.fields).find((key) => resource.fields[key].sequence);
|
|
11
|
+
const text = resource.list.find((key) => {
|
|
12
|
+
const field = resource.fields[key];
|
|
13
|
+
return (field.type === 'string' || field.type === 'text') && !field.sequence;
|
|
14
|
+
});
|
|
15
|
+
return [sequence, text].filter((key) => key !== undefined);
|
|
16
|
+
}
|
|
17
|
+
/** Definition check: title fields exist, are readable and have a displayable type. */
|
|
18
|
+
export function assertTitle(resource) {
|
|
19
|
+
if (!resource.title)
|
|
20
|
+
return;
|
|
21
|
+
if (!resource.title.length)
|
|
22
|
+
throw new Error(`${resource.name}: title needs at least one field`);
|
|
23
|
+
const readable = new Set(resource.serialize ?? [...resource.list, ...resource.show]);
|
|
24
|
+
for (const key of resource.title) {
|
|
25
|
+
const field = resource.fields[key];
|
|
26
|
+
if (!field)
|
|
27
|
+
throw new Error(`Unknown field: ${key}`);
|
|
28
|
+
if (!TITLE_TYPES.has(field.type))
|
|
29
|
+
throw new Error(`${resource.name}: title field ${key} cannot be a ${field.type}`);
|
|
30
|
+
if (!readable.has(key))
|
|
31
|
+
throw new Error(`${resource.name}: title field ${key} must be serialized`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The title of one serialized record, read after field-level filtering so it never shows
|
|
36
|
+
* a value the viewer may not read. Returns null when no title field has a value.
|
|
37
|
+
*/
|
|
38
|
+
export function formatTitle(resource, record, lookupLabel) {
|
|
39
|
+
const parts = [];
|
|
40
|
+
for (const key of titleFields(resource)) {
|
|
41
|
+
const value = record[key];
|
|
42
|
+
if (value === null || value === undefined || value === '')
|
|
43
|
+
continue;
|
|
44
|
+
const field = resource.fields[key];
|
|
45
|
+
parts.push(field.type === 'lookup'
|
|
46
|
+
? (lookupLabel(field.group, String(value)) ?? String(value))
|
|
47
|
+
: String(value));
|
|
48
|
+
}
|
|
49
|
+
return parts.length ? parts.join(' · ') : null;
|
|
50
|
+
}
|