adula 2.0.0 → 2.2.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 -11
- package/build/agent/skills/adula-frontend-design/SKILL.md +1 -1
- package/build/agent/skills/idea-review/SKILL.md +2 -2
- 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_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 +185 -0
- package/build/commands/backup_services.d.ts +31 -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 +4 -1
- package/build/commands/install.d.ts +8 -0
- package/build/commands/install.js +63 -45
- package/build/commands/main.d.ts +3 -2
- package/build/commands/main.js +26 -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 +72 -0
- package/build/commands/resource_snapshot.d.ts +2 -0
- package/build/commands/resource_snapshot.js +3 -0
- package/build/commands/sla_evaluate.d.ts +14 -0
- package/build/commands/sla_evaluate.js +16 -0
- package/build/commands/ui.js +5 -3
- 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/index.d.ts +56 -10
- package/build/index.js +34 -6
- 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 +77 -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 +59 -0
- package/build/src/admin/resource/editor.js +323 -0
- package/build/src/admin/resource/export.d.ts +37 -0
- package/build/src/admin/resource/export.js +181 -0
- package/build/src/admin/resource/lifecycle.d.ts +21 -0
- package/build/src/admin/resource/lifecycle.js +91 -0
- package/build/src/admin/resource/query.d.ts +100 -0
- package/build/src/admin/resource/query.js +508 -0
- package/build/src/admin/resource/read.d.ts +106 -0
- package/build/src/admin/resource/read.js +327 -0
- package/build/src/admin/resource/shared.d.ts +77 -0
- package/build/src/admin/resource/shared.js +222 -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 +574 -0
- package/build/src/admin/resource_service.d.ts +66 -193
- package/build/src/admin/resource_service.js +69 -1345
- package/build/src/attachments/attachment_service.d.ts +46 -2
- package/build/src/attachments/attachment_service.js +96 -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/collaboration/assignments.d.ts +36 -1
- package/build/src/collaboration/assignments.js +132 -66
- package/build/src/collaboration/record_collaboration.d.ts +2 -3
- package/build/src/collaboration/record_collaboration.js +19 -16
- package/build/src/collaboration/shared.d.ts +16 -0
- package/build/src/collaboration/shared.js +21 -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 +34 -8
- package/build/src/commands/doctor.d.ts +14 -2
- package/build/src/commands/doctor.js +50 -5
- 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 +10 -13
- package/build/src/commands/snapshot.js +31 -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 +129 -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/message_templates.d.ts +7 -2
- package/build/src/core/message_templates.js +72 -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 +2 -2
- package/build/src/core/saved_views.d.ts +8 -1
- package/build/src/core/saved_views.js +36 -2
- 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 +19 -2
- 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 +4 -0
- package/build/src/core/ui_preferences.js +4 -1
- package/build/src/core/user_invitations.d.ts +5 -1
- package/build/src/core/user_invitations.js +7 -1
- package/build/src/core/users.js +1 -1
- 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 +155 -2
- package/build/src/database/schema.js +531 -59
- package/build/src/database/schema_diff.d.ts +56 -0
- package/build/src/database/schema_diff.js +157 -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 +552 -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 +118 -16
- package/build/src/integrations/imports.js +406 -73
- package/build/src/integrations/openapi.d.ts +3 -1
- package/build/src/integrations/openapi.js +454 -31
- package/build/src/integrations/outbound.d.ts +51 -0
- package/build/src/integrations/outbound.js +195 -0
- package/build/src/integrations/print.d.ts +21 -1
- package/build/src/integrations/print.js +63 -21
- package/build/src/integrations/print_templates.d.ts +216 -0
- package/build/src/integrations/print_templates.js +1015 -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/languages/ar.d.ts +11 -0
- package/build/src/languages/ar.js +336 -0
- package/build/src/languages/ar_ui.d.ts +332 -0
- package/build/src/languages/ar_ui.js +333 -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 +330 -0
- package/build/src/languages/en_ui.d.ts +3 -0
- package/build/src/languages/en_ui.js +328 -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 +96 -0
- package/build/src/lists/dashboards.js +241 -0
- package/build/src/mcp/tools.js +1 -1
- package/build/src/resource/define_resource.d.ts +18 -1
- package/build/src/resource/define_resource.js +205 -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 +304 -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 +93 -0
- package/build/src/workflows/delegations.js +287 -0
- package/build/src/workflows/engine.d.ts +69 -4
- package/build/src/workflows/engine.js +441 -83
- 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 +5 -2
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
import type { ResourceRegistry } from '../resource/registry.js';
|
|
3
3
|
import { type Actor } from '../auth/ability.js';
|
|
4
|
+
import { type ListFilterValue } from '../admin/resource/query.js';
|
|
4
5
|
export type SavedViewQuery = {
|
|
5
6
|
search?: string;
|
|
6
7
|
sort?: string;
|
|
7
8
|
direction?: 'asc' | 'desc';
|
|
8
|
-
|
|
9
|
+
/** Equality values or the operator objects of ADR 046 ({ in }, { gte, lte }, { empty }). */
|
|
10
|
+
filters?: Record<string, ListFilterValue>;
|
|
9
11
|
};
|
|
10
12
|
export type SavedView = {
|
|
11
13
|
id: number;
|
|
@@ -31,6 +33,11 @@ export declare class SavedViews {
|
|
|
31
33
|
shared?: boolean;
|
|
32
34
|
}): Promise<SavedView>;
|
|
33
35
|
remove(name: string, actor: Actor, id: number): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Saved views are personal preferences and are not audited for their owner; a change
|
|
38
|
+
* made by an administrator impersonating the owner is recorded with both identities.
|
|
39
|
+
*/
|
|
40
|
+
private auditImpersonation;
|
|
34
41
|
private authorize;
|
|
35
42
|
/** Returns null for a stored view the resource no longer supports; throws on user input. */
|
|
36
43
|
private sanitize;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { buildAbility } from '../auth/ability.js';
|
|
2
2
|
import { AdulaError } from '../admin/errors.js';
|
|
3
3
|
import { canQueryField } from '../admin/resource_service.js';
|
|
4
|
+
import { logActivity } from './activity.js';
|
|
5
|
+
import { filterCondition } from '../admin/resource/query.js';
|
|
4
6
|
const NAME_LIMIT = 60;
|
|
5
7
|
const VIEW_LIMIT = 50;
|
|
6
8
|
/** Shared views are visible to every viewer of a resource; cap them per resource. */
|
|
7
9
|
const SHARED_LIMIT = 100;
|
|
10
|
+
const ACTIVITY_RESOURCE = 'core.saved_views';
|
|
8
11
|
/**
|
|
9
12
|
* A saved view is stored user input that later drives a list query, so every key
|
|
10
13
|
* is validated against the resource definition before it is written and again
|
|
@@ -90,6 +93,11 @@ export class SavedViews {
|
|
|
90
93
|
const [row] = existing
|
|
91
94
|
? await this.db('saved_views').where('id', existing.id).update(values).returning('*')
|
|
92
95
|
: await this.db('saved_views').insert(values).returning('*');
|
|
96
|
+
await this.auditImpersonation(actor, Number(row.id), 'saved_view_saved', {
|
|
97
|
+
resource: resource.name,
|
|
98
|
+
name: label,
|
|
99
|
+
shared,
|
|
100
|
+
});
|
|
93
101
|
return { id: Number(row.id), name: label, query, shared, own: true };
|
|
94
102
|
}
|
|
95
103
|
async remove(name, actor, id) {
|
|
@@ -99,6 +107,23 @@ export class SavedViews {
|
|
|
99
107
|
.del();
|
|
100
108
|
if (!removed)
|
|
101
109
|
throw new AdulaError(404, 'E_VIEW_NOT_FOUND', 'العرض المحفوظ غير موجود');
|
|
110
|
+
await this.auditImpersonation(actor, id, 'saved_view_removed', { resource: resource.name });
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Saved views are personal preferences and are not audited for their owner; a change
|
|
114
|
+
* made by an administrator impersonating the owner is recorded with both identities.
|
|
115
|
+
*/
|
|
116
|
+
async auditImpersonation(actor, viewId, action, changes) {
|
|
117
|
+
if (!actor.impersonatorId)
|
|
118
|
+
return;
|
|
119
|
+
await logActivity(this.db, {
|
|
120
|
+
resource: ACTIVITY_RESOURCE,
|
|
121
|
+
recordId: viewId,
|
|
122
|
+
actorId: actor.id,
|
|
123
|
+
impersonatorId: actor.impersonatorId,
|
|
124
|
+
action,
|
|
125
|
+
changes,
|
|
126
|
+
});
|
|
102
127
|
}
|
|
103
128
|
authorize(name, actor) {
|
|
104
129
|
const resource = this.registry.get(name);
|
|
@@ -152,8 +177,17 @@ export class SavedViews {
|
|
|
152
177
|
if (entry !== null &&
|
|
153
178
|
typeof entry !== 'string' &&
|
|
154
179
|
typeof entry !== 'number' &&
|
|
155
|
-
typeof entry !== 'boolean')
|
|
156
|
-
|
|
180
|
+
typeof entry !== 'boolean') {
|
|
181
|
+
// An operator object is checked exactly as the list will check it.
|
|
182
|
+
try {
|
|
183
|
+
filterCondition(key, resource.fields[key], entry);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return reject('E_VIEW_QUERY', `قيمة التصفية غير صالحة: ${key}`);
|
|
187
|
+
}
|
|
188
|
+
filters[key] = JSON.parse(JSON.stringify(entry));
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
157
191
|
filters[key] = entry;
|
|
158
192
|
}
|
|
159
193
|
if (Object.keys(filters).length)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { ResourceRegistry } from '../resource/registry.js';
|
|
3
|
+
export type SequenceRow = {
|
|
4
|
+
key: string;
|
|
5
|
+
/** The last issued value (0 before the first number); digits, since the column is bigint. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** The number the next record receives, formatted exactly like `sequence()`. */
|
|
8
|
+
next: string;
|
|
9
|
+
/** Registered resource fields numbered by this sequence. */
|
|
10
|
+
fields: {
|
|
11
|
+
resource: string;
|
|
12
|
+
field: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Administration of document numbering (sequences table). A sequence can only move forward:
|
|
18
|
+
* moving it back would issue numbers that records already carry. The key and its format are
|
|
19
|
+
* fixed by the resource field (`sequence: 'ORD'` issues ORD-000001), so only the next value
|
|
20
|
+
* changes. Changes are audited as core.sequences with record id 0 and the key in the changes.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SequencesAdmin {
|
|
23
|
+
private db;
|
|
24
|
+
private registry?;
|
|
25
|
+
constructor(db: Knex, registry?: ResourceRegistry | undefined);
|
|
26
|
+
private fields;
|
|
27
|
+
/** Stored sequences and those declared by registered fields that have not issued a number yet. */
|
|
28
|
+
list(): Promise<SequenceRow[]>;
|
|
29
|
+
/** Sets the value the next record receives; it must be ahead of the last issued value. */
|
|
30
|
+
setNext(actorId: number, key: unknown, next: unknown): Promise<SequenceRow>;
|
|
31
|
+
private toRow;
|
|
32
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { AdulaError } from '../admin/errors.js';
|
|
2
|
+
import { formatSequence } from '../services/settings.js';
|
|
3
|
+
import { logActivity } from './activity.js';
|
|
4
|
+
const RESOURCE = 'core.sequences';
|
|
5
|
+
const KEY = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/;
|
|
6
|
+
function sequenceKey(value) {
|
|
7
|
+
if (typeof value !== 'string' || !KEY.test(value))
|
|
8
|
+
throw new AdulaError(404, 'E_SEQUENCE_NOT_FOUND', 'التسلسل غير موجود');
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function nextValue(value) {
|
|
12
|
+
const text = typeof value === 'number' ? String(value) : value;
|
|
13
|
+
if (typeof text !== 'string' || !/^\d{1,18}$/.test(text.trim()) || BigInt(text.trim()) < 1n)
|
|
14
|
+
throw new AdulaError(422, 'E_SEQUENCE_VALUE', 'الرقم التالي يجب أن يكون عدداً صحيحاً موجباً');
|
|
15
|
+
return BigInt(text.trim());
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Administration of document numbering (sequences table). A sequence can only move forward:
|
|
19
|
+
* moving it back would issue numbers that records already carry. The key and its format are
|
|
20
|
+
* fixed by the resource field (`sequence: 'ORD'` issues ORD-000001), so only the next value
|
|
21
|
+
* changes. Changes are audited as core.sequences with record id 0 and the key in the changes.
|
|
22
|
+
*/
|
|
23
|
+
export class SequencesAdmin {
|
|
24
|
+
db;
|
|
25
|
+
registry;
|
|
26
|
+
constructor(db, registry) {
|
|
27
|
+
this.db = db;
|
|
28
|
+
this.registry = registry;
|
|
29
|
+
}
|
|
30
|
+
fields() {
|
|
31
|
+
return (this.registry?.all() ?? []).flatMap((resource) => Object.entries(resource.fields).flatMap(([field, definition]) => definition.sequence
|
|
32
|
+
? [
|
|
33
|
+
{
|
|
34
|
+
key: definition.sequence,
|
|
35
|
+
resource: resource.name,
|
|
36
|
+
field,
|
|
37
|
+
label: definition.label.ar,
|
|
38
|
+
},
|
|
39
|
+
]
|
|
40
|
+
: []));
|
|
41
|
+
}
|
|
42
|
+
/** Stored sequences and those declared by registered fields that have not issued a number yet. */
|
|
43
|
+
async list() {
|
|
44
|
+
const rows = await this.db('sequences').select('key', 'value');
|
|
45
|
+
const values = new Map(rows.map((row) => [String(row.key), BigInt(row.value)]));
|
|
46
|
+
const fields = this.fields();
|
|
47
|
+
for (const field of fields)
|
|
48
|
+
if (!values.has(field.key))
|
|
49
|
+
values.set(field.key, 0n);
|
|
50
|
+
return [...values.keys()].sort().map((key) => this.toRow(key, values.get(key), fields));
|
|
51
|
+
}
|
|
52
|
+
/** Sets the value the next record receives; it must be ahead of the last issued value. */
|
|
53
|
+
async setNext(actorId, key, next) {
|
|
54
|
+
const name = sequenceKey(key);
|
|
55
|
+
const target = nextValue(next);
|
|
56
|
+
const fields = this.fields();
|
|
57
|
+
return this.db.transaction(async (trx) => {
|
|
58
|
+
let row = await trx('sequences').where('key', name).forUpdate().first('value');
|
|
59
|
+
if (!row) {
|
|
60
|
+
if (!fields.some((field) => field.key === name))
|
|
61
|
+
throw new AdulaError(404, 'E_SEQUENCE_NOT_FOUND', 'التسلسل غير موجود');
|
|
62
|
+
await trx('sequences').insert({ key: name, value: 0 }).onConflict('key').ignore();
|
|
63
|
+
row = await trx('sequences').where('key', name).forUpdate().first('value');
|
|
64
|
+
}
|
|
65
|
+
const current = BigInt(row.value);
|
|
66
|
+
if (target <= current)
|
|
67
|
+
throw new AdulaError(422, 'E_SEQUENCE_BACKWARD', `لا يمكن إرجاع الترقيم: آخر رقم صدر هو ${formatSequence(name, current)}، والرجوع يكرر أرقاماً تحملها سجلات قائمة. اختر رقماً أكبر من ${current}.`);
|
|
68
|
+
if (target === current + 1n)
|
|
69
|
+
return this.toRow(name, current, fields);
|
|
70
|
+
await trx('sequences')
|
|
71
|
+
.where('key', name)
|
|
72
|
+
.update({ value: (target - 1n).toString() });
|
|
73
|
+
await logActivity(trx, {
|
|
74
|
+
resource: RESOURCE,
|
|
75
|
+
recordId: 0,
|
|
76
|
+
actorId,
|
|
77
|
+
action: 'adjust',
|
|
78
|
+
changes: {
|
|
79
|
+
key: name,
|
|
80
|
+
from: formatSequence(name, current + 1n),
|
|
81
|
+
to: formatSequence(name, target),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
return this.toRow(name, target - 1n, fields);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
toRow(key, value, fields) {
|
|
88
|
+
return {
|
|
89
|
+
key,
|
|
90
|
+
value: value.toString(),
|
|
91
|
+
next: formatSequence(key, value + 1n),
|
|
92
|
+
fields: fields
|
|
93
|
+
.filter((field) => field.key === key)
|
|
94
|
+
.map(({ resource, field, label }) => ({ resource, field, label })),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -18,6 +18,11 @@ export type SettingInput = {
|
|
|
18
18
|
export declare const SETTING_SCOPES: SettingScope[];
|
|
19
19
|
export declare const PROTECTED_SETTING_KEYS: string[];
|
|
20
20
|
export declare function isProtectedSetting(key: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Settings that hold a sealed secret (`channels.*`, written by their own section). The
|
|
23
|
+
* settings screen lists them read-only and never returns the sealed value.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isSealedSetting(key: string): boolean;
|
|
21
26
|
export declare function parseSettingValue(text: string): unknown;
|
|
22
27
|
export declare class SettingsAdmin {
|
|
23
28
|
private db;
|
|
@@ -11,7 +11,24 @@ export const PROTECTED_SETTING_KEYS = [
|
|
|
11
11
|
];
|
|
12
12
|
const RESOURCE = 'core.settings';
|
|
13
13
|
export function isProtectedSetting(key) {
|
|
14
|
-
return (PROTECTED_SETTING_KEYS.includes(key) ||
|
|
14
|
+
return (PROTECTED_SETTING_KEYS.includes(key) ||
|
|
15
|
+
key.startsWith('backup.') ||
|
|
16
|
+
key.startsWith('setup.') ||
|
|
17
|
+
isSealedSetting(key));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Settings that hold a sealed secret (`channels.*`, written by their own section). The
|
|
21
|
+
* settings screen lists them read-only and never returns the sealed value.
|
|
22
|
+
*/
|
|
23
|
+
export function isSealedSetting(key) {
|
|
24
|
+
return key.startsWith('channels.');
|
|
25
|
+
}
|
|
26
|
+
function presentValue(key, value) {
|
|
27
|
+
if (!isSealedSetting(key) || !value || typeof value !== 'object' || Array.isArray(value))
|
|
28
|
+
return value;
|
|
29
|
+
const rest = { ...value };
|
|
30
|
+
delete rest.secret;
|
|
31
|
+
return rest;
|
|
15
32
|
}
|
|
16
33
|
export function parseSettingValue(text) {
|
|
17
34
|
try {
|
|
@@ -37,7 +54,7 @@ function toRow(row) {
|
|
|
37
54
|
key: String(row.key),
|
|
38
55
|
scope: row.scope,
|
|
39
56
|
scopeId: String(row.scope_id),
|
|
40
|
-
value: row.value,
|
|
57
|
+
value: presentValue(String(row.key), row.value),
|
|
41
58
|
readOnly: isProtectedSetting(String(row.key)),
|
|
42
59
|
};
|
|
43
60
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `{{name}}` placeholder of message templates (core/message_templates.ts). Print
|
|
3
|
+
* templates use the same delimiters with a small block grammar on top (see parseTemplate).
|
|
4
|
+
*/
|
|
5
|
+
export declare const PLACEHOLDER: RegExp;
|
|
6
|
+
/** Longest template accepted, in characters. */
|
|
7
|
+
export declare const TEMPLATE_SOURCE_LIMIT = 20000;
|
|
8
|
+
/** A value a template tag names. Nothing else is addressable: no expressions, no paths. */
|
|
9
|
+
export type TemplateRef = {
|
|
10
|
+
kind: 'field';
|
|
11
|
+
key: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'row';
|
|
14
|
+
key: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'lines';
|
|
17
|
+
key: string;
|
|
18
|
+
column?: string;
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'meta';
|
|
21
|
+
key: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'string';
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
26
|
+
export type TemplateNode = {
|
|
27
|
+
type: 'text';
|
|
28
|
+
value: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'output';
|
|
31
|
+
helper: string | null;
|
|
32
|
+
arg: TemplateRef;
|
|
33
|
+
source: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: 'if';
|
|
36
|
+
test: TemplateRef;
|
|
37
|
+
then: TemplateNode[];
|
|
38
|
+
else: TemplateNode[];
|
|
39
|
+
source: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'each';
|
|
42
|
+
group: string;
|
|
43
|
+
body: TemplateNode[];
|
|
44
|
+
source: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function templateError(message: string): never;
|
|
47
|
+
/**
|
|
48
|
+
* Parses the template language shared by print templates:
|
|
49
|
+
*
|
|
50
|
+
* - `{{field.key}}`, `{{row.key}}` (inside each), `{{name}}` (document values such as id)
|
|
51
|
+
* - `{{helper arg}}` where arg is one of the above, `lines.group.column` or `"text"`
|
|
52
|
+
* - `{{#if ref}}…{{else}}…{{/if}}` and `{{#each lines.group}}…{{/each}}` (not nested)
|
|
53
|
+
*
|
|
54
|
+
* There are no expressions, no property paths beyond these and no raw output: `{{{`
|
|
55
|
+
* is refused. Which names exist is checked by the caller against its own schema.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseTemplate(source: string): TemplateNode[];
|
|
58
|
+
/** Visits every tag of a parsed template, with the line group of the enclosing each. */
|
|
59
|
+
export declare function walkTemplate(nodes: TemplateNode[], visit: (node: Exclude<TemplateNode, {
|
|
60
|
+
type: 'text';
|
|
61
|
+
}>, group: string | null) => void, group?: string | null): void;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { AdulaError } from '../admin/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `{{name}}` placeholder of message templates (core/message_templates.ts). Print
|
|
4
|
+
* templates use the same delimiters with a small block grammar on top (see parseTemplate).
|
|
5
|
+
*/
|
|
6
|
+
export const PLACEHOLDER = /\{\{\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\}\}/g;
|
|
7
|
+
const NAME = '[a-zA-Z][a-zA-Z0-9_]*';
|
|
8
|
+
const SCOPED = new RegExp(`^(field|row)\\.(${NAME})$`);
|
|
9
|
+
const LINES = new RegExp(`^lines\\.(${NAME})(?:\\.(${NAME}))?$`);
|
|
10
|
+
const META = new RegExp(`^(${NAME})$`);
|
|
11
|
+
const STRING = /^"([^"\\{}<>]{1,100})"$/;
|
|
12
|
+
const HELPER = new RegExp(`^(${NAME})\\s+(\\S.*)$`);
|
|
13
|
+
/** Longest template accepted, in characters. */
|
|
14
|
+
export const TEMPLATE_SOURCE_LIMIT = 20000;
|
|
15
|
+
const TAG_LIMIT = 2000;
|
|
16
|
+
export function templateError(message) {
|
|
17
|
+
throw new AdulaError(422, 'E_PRINT_TEMPLATE', message);
|
|
18
|
+
}
|
|
19
|
+
function reference(source, tag) {
|
|
20
|
+
const scoped = SCOPED.exec(source);
|
|
21
|
+
if (scoped)
|
|
22
|
+
return { kind: scoped[1], key: scoped[2] };
|
|
23
|
+
const lines = LINES.exec(source);
|
|
24
|
+
if (lines)
|
|
25
|
+
return { kind: 'lines', key: lines[1], ...(lines[2] ? { column: lines[2] } : {}) };
|
|
26
|
+
const string = STRING.exec(source);
|
|
27
|
+
if (string)
|
|
28
|
+
return { kind: 'string', value: string[1] };
|
|
29
|
+
if (META.test(source))
|
|
30
|
+
return { kind: 'meta', key: source };
|
|
31
|
+
return templateError(`تعبير غير مسموح في القالب: {{${tag}}}`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parses the template language shared by print templates:
|
|
35
|
+
*
|
|
36
|
+
* - `{{field.key}}`, `{{row.key}}` (inside each), `{{name}}` (document values such as id)
|
|
37
|
+
* - `{{helper arg}}` where arg is one of the above, `lines.group.column` or `"text"`
|
|
38
|
+
* - `{{#if ref}}…{{else}}…{{/if}}` and `{{#each lines.group}}…{{/each}}` (not nested)
|
|
39
|
+
*
|
|
40
|
+
* There are no expressions, no property paths beyond these and no raw output: `{{{`
|
|
41
|
+
* is refused. Which names exist is checked by the caller against its own schema.
|
|
42
|
+
*/
|
|
43
|
+
export function parseTemplate(source) {
|
|
44
|
+
if (source.length > TEMPLATE_SOURCE_LIMIT)
|
|
45
|
+
templateError(`القالب أطول من ${TEMPLATE_SOURCE_LIMIT} حرف`);
|
|
46
|
+
if (source.includes('{{{') || source.includes('}}}'))
|
|
47
|
+
templateError('الصيغة {{{ }}} غير مسموحة؛ تُعرض كل القيم بعد تهريبها');
|
|
48
|
+
const root = [];
|
|
49
|
+
const stack = [];
|
|
50
|
+
const target = () => {
|
|
51
|
+
const top = stack.at(-1);
|
|
52
|
+
if (!top)
|
|
53
|
+
return root;
|
|
54
|
+
if (top.node.type === 'each')
|
|
55
|
+
return top.node.body;
|
|
56
|
+
return top.inElse ? top.node.else : top.node.then;
|
|
57
|
+
};
|
|
58
|
+
let index = 0;
|
|
59
|
+
while (index < source.length) {
|
|
60
|
+
const open = source.indexOf('{{', index);
|
|
61
|
+
if (open === -1) {
|
|
62
|
+
target().push({ type: 'text', value: source.slice(index) });
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (open > index)
|
|
66
|
+
target().push({ type: 'text', value: source.slice(index, open) });
|
|
67
|
+
const close = source.indexOf('}}', open + 2);
|
|
68
|
+
if (close === -1)
|
|
69
|
+
templateError('وسم غير مكتمل في القالب: {{ بلا }}');
|
|
70
|
+
const raw = source.slice(open + 2, close);
|
|
71
|
+
if (raw.length > TAG_LIMIT || raw.includes('{{'))
|
|
72
|
+
templateError('وسم غير صالح في القالب');
|
|
73
|
+
const tag = raw.trim().replace(/\s+/g, ' ');
|
|
74
|
+
index = close + 2;
|
|
75
|
+
if (tag.startsWith('#if ')) {
|
|
76
|
+
const node = {
|
|
77
|
+
type: 'if',
|
|
78
|
+
test: reference(tag.slice(4).trim(), tag),
|
|
79
|
+
then: [],
|
|
80
|
+
else: [],
|
|
81
|
+
source: tag,
|
|
82
|
+
};
|
|
83
|
+
target().push(node);
|
|
84
|
+
stack.push({ node, inElse: false });
|
|
85
|
+
}
|
|
86
|
+
else if (tag.startsWith('#each ')) {
|
|
87
|
+
if (stack.some((entry) => entry.node.type === 'each'))
|
|
88
|
+
templateError('لا يمكن تداخل {{#each}} داخل {{#each}}');
|
|
89
|
+
const group = reference(tag.slice(6).trim(), tag);
|
|
90
|
+
if (group.kind !== 'lines' || group.column)
|
|
91
|
+
templateError(`{{#each}} يقبل مجموعة بنود فقط مثل lines.items: {{${tag}}}`);
|
|
92
|
+
const node = { type: 'each', group: group.key, body: [], source: tag };
|
|
93
|
+
target().push(node);
|
|
94
|
+
stack.push({ node, inElse: false });
|
|
95
|
+
}
|
|
96
|
+
else if (tag === 'else') {
|
|
97
|
+
const top = stack.at(-1);
|
|
98
|
+
if (!top || top.node.type !== 'if' || top.inElse)
|
|
99
|
+
templateError('{{else}} بلا {{#if}}');
|
|
100
|
+
top.inElse = true;
|
|
101
|
+
}
|
|
102
|
+
else if (tag === '/if' || tag === '/each') {
|
|
103
|
+
const top = stack.pop();
|
|
104
|
+
if (!top || `/${top.node.type}` !== tag)
|
|
105
|
+
templateError(`{{${tag}}} بلا بداية مطابقة`);
|
|
106
|
+
}
|
|
107
|
+
else if (tag.startsWith('#') || tag.startsWith('/') || tag.startsWith('>')) {
|
|
108
|
+
templateError(`وسم غير مسموح في القالب: {{${tag}}}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const helper = HELPER.exec(tag);
|
|
112
|
+
if (helper)
|
|
113
|
+
target().push({
|
|
114
|
+
type: 'output',
|
|
115
|
+
helper: helper[1],
|
|
116
|
+
arg: reference(helper[2].trim(), tag),
|
|
117
|
+
source: tag,
|
|
118
|
+
});
|
|
119
|
+
else
|
|
120
|
+
target().push({ type: 'output', helper: null, arg: reference(tag, tag), source: tag });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const open = stack.at(-1);
|
|
124
|
+
if (open)
|
|
125
|
+
templateError(`{{#${open.node.type}}} بلا {{/${open.node.type}}}`);
|
|
126
|
+
return root;
|
|
127
|
+
}
|
|
128
|
+
/** Visits every tag of a parsed template, with the line group of the enclosing each. */
|
|
129
|
+
export function walkTemplate(nodes, visit, group = null) {
|
|
130
|
+
for (const node of nodes) {
|
|
131
|
+
if (node.type === 'text')
|
|
132
|
+
continue;
|
|
133
|
+
visit(node, group);
|
|
134
|
+
if (node.type === 'if') {
|
|
135
|
+
walkTemplate(node.then, visit, group);
|
|
136
|
+
walkTemplate(node.else, visit, group);
|
|
137
|
+
}
|
|
138
|
+
else if (node.type === 'each')
|
|
139
|
+
walkTemplate(node.body, visit, node.group);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { Knex } from 'knex';
|
|
2
2
|
export type CalendarSystem = 'gregory' | 'islamic-umalqura';
|
|
3
3
|
export type CalendarPreference = CalendarSystem | 'both';
|
|
4
|
+
/** Latin (0-9) or Arabic-Indic (٠-٩) digits in printed documents. */
|
|
5
|
+
export type DigitsPreference = 'latn' | 'arab';
|
|
4
6
|
export type UiPreferences = {
|
|
5
7
|
calendar: CalendarPreference;
|
|
6
8
|
confirmDialogClose: boolean;
|
|
7
9
|
pageTransitions: boolean;
|
|
10
|
+
/** Optional for values stored before it existed; absent means 'latn'. */
|
|
11
|
+
digits?: DigitsPreference;
|
|
8
12
|
};
|
|
9
13
|
export declare const UI_PREFERENCES_KEY = "ui.preferences";
|
|
10
14
|
export declare const DEFAULT_UI_PREFERENCES: UiPreferences;
|
|
@@ -6,6 +6,7 @@ export const DEFAULT_UI_PREFERENCES = {
|
|
|
6
6
|
confirmDialogClose: true,
|
|
7
7
|
pageTransitions: true,
|
|
8
8
|
};
|
|
9
|
+
const PREFERENCE_KEYS = ['calendar', 'confirmDialogClose', 'pageTransitions', 'digits'];
|
|
9
10
|
export function validateUiPreferences(value) {
|
|
10
11
|
const input = value;
|
|
11
12
|
if (!input ||
|
|
@@ -14,12 +15,14 @@ export function validateUiPreferences(value) {
|
|
|
14
15
|
!['gregory', 'islamic-umalqura', 'both'].includes(input.calendar) ||
|
|
15
16
|
typeof input.confirmDialogClose !== 'boolean' ||
|
|
16
17
|
typeof input.pageTransitions !== 'boolean' ||
|
|
17
|
-
|
|
18
|
+
(input.digits !== undefined && !['latn', 'arab'].includes(input.digits)) ||
|
|
19
|
+
Object.keys(input).some((key) => !PREFERENCE_KEYS.includes(key)))
|
|
18
20
|
throw new AdulaError(422, 'E_UI_PREFERENCES', 'اختر تقويمًا صالحًا وحدد خيارات تأكيد الإغلاق والانتقالات');
|
|
19
21
|
return {
|
|
20
22
|
calendar: input.calendar,
|
|
21
23
|
confirmDialogClose: input.confirmDialogClose,
|
|
22
24
|
pageTransitions: input.pageTransitions,
|
|
25
|
+
...(input.digits === undefined ? {} : { digits: input.digits }),
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
export async function uiPreferences(db) {
|
|
@@ -12,7 +12,11 @@ export declare class UserInvitations {
|
|
|
12
12
|
invite(actorId: number, input: {
|
|
13
13
|
email: string;
|
|
14
14
|
fullName: string;
|
|
15
|
-
}, send: (invitation: InvitationDelivery) => Promise<void
|
|
15
|
+
}, send: (invitation: InvitationDelivery) => Promise<void>,
|
|
16
|
+
/** The administrator impersonating actorId; recorded in each activity entry. */
|
|
17
|
+
context?: {
|
|
18
|
+
impersonatorId?: number | null;
|
|
19
|
+
}): Promise<{
|
|
16
20
|
id: number;
|
|
17
21
|
email: string;
|
|
18
22
|
}>;
|
|
@@ -22,7 +22,10 @@ export class UserInvitations {
|
|
|
22
22
|
const actor = await new ActorStore(this.db, new ResourceRegistry()).load(actorId);
|
|
23
23
|
return buildAbility(actor.rules).can('invite', subject(RESOURCE, {}));
|
|
24
24
|
}
|
|
25
|
-
async invite(actorId, input, send
|
|
25
|
+
async invite(actorId, input, send,
|
|
26
|
+
/** The administrator impersonating actorId; recorded in each activity entry. */
|
|
27
|
+
context = {}) {
|
|
28
|
+
const impersonatorId = context.impersonatorId ?? null;
|
|
26
29
|
const email = typeof input.email === 'string' ? input.email.trim().toLowerCase() : '';
|
|
27
30
|
const fullName = typeof input.fullName === 'string' ? input.fullName.trim() : '';
|
|
28
31
|
if (!email ||
|
|
@@ -60,6 +63,7 @@ export class UserInvitations {
|
|
|
60
63
|
resource: INVITATIONS,
|
|
61
64
|
recordId: row.id,
|
|
62
65
|
actorId,
|
|
66
|
+
impersonatorId,
|
|
63
67
|
action: 'invitation_created',
|
|
64
68
|
changes: { email },
|
|
65
69
|
});
|
|
@@ -78,6 +82,7 @@ export class UserInvitations {
|
|
|
78
82
|
resource: INVITATIONS,
|
|
79
83
|
recordId: id,
|
|
80
84
|
actorId,
|
|
85
|
+
impersonatorId,
|
|
81
86
|
action: 'invitation_delivery_failed',
|
|
82
87
|
changes: { email },
|
|
83
88
|
});
|
|
@@ -87,6 +92,7 @@ export class UserInvitations {
|
|
|
87
92
|
resource: INVITATIONS,
|
|
88
93
|
recordId: id,
|
|
89
94
|
actorId,
|
|
95
|
+
impersonatorId,
|
|
90
96
|
action: 'invitation_sent',
|
|
91
97
|
changes: { email },
|
|
92
98
|
});
|
package/build/src/core/users.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AdulaError } from '../admin/errors.js';
|
|
2
2
|
import { logActivity, pageLimit } from './activity.js';
|
|
3
3
|
import { administrationGuard } from './administration_guard.js';
|
|
4
|
+
import { escapeLike } from './like.js';
|
|
4
5
|
const RESOURCE = 'core.users';
|
|
5
|
-
const escapeLike = (value) => value.replace(/[\\%_]/g, '\\$&');
|
|
6
6
|
/** Host applications own the users table; AdulaJS expects id, email, full_name and disabled_at. */
|
|
7
7
|
export class UsersAdmin {
|
|
8
8
|
db;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Database } from '@adonisjs/lucid/database';
|
|
2
|
+
/** PostgreSQL's type OID for DATE (a calendar day without a time or zone). */
|
|
3
|
+
export declare const POSTGRES_DATE_OID = 1082;
|
|
4
|
+
/** PostgreSQL's type OID for DATE[] (for example `array_agg(day)`). */
|
|
5
|
+
export declare const POSTGRES_DATE_ARRAY_OID = 1182;
|
|
6
|
+
/**
|
|
7
|
+
* node-postgres turns a DATE into a JavaScript Date at local midnight, so in any time zone
|
|
8
|
+
* east of UTC `toISOString()` reports the previous day. A calendar day never passes
|
|
9
|
+
* through local time in AdulaJS: every PostgreSQL connection returns DATE as the
|
|
10
|
+
* 'YYYY-MM-DD' text the server sent, and DATE[] as an array of those strings (null
|
|
11
|
+
* elements stay null). node-postgres keeps one parser registry per driver, so this
|
|
12
|
+
* covers every query: resources, module code and raw Lucid queries alike.
|
|
13
|
+
*
|
|
14
|
+
* `manager.connect(name)` only builds the connection's Knex client (the pool opens no
|
|
15
|
+
* socket until the first query); it is needed because the driver whose registry must be
|
|
16
|
+
* changed is reachable only through that client, and the change has to be in place
|
|
17
|
+
* before any query parses a DATE. Connecting an already connected name is a no-op.
|
|
18
|
+
*/
|
|
19
|
+
export declare function keepCalendarDays(db: Pick<Database, 'config' | 'manager' | 'getRawConnection'>): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** PostgreSQL's type OID for DATE (a calendar day without a time or zone). */
|
|
2
|
+
export const POSTGRES_DATE_OID = 1082;
|
|
3
|
+
/** PostgreSQL's type OID for DATE[] (for example `array_agg(day)`). */
|
|
4
|
+
export const POSTGRES_DATE_ARRAY_OID = 1182;
|
|
5
|
+
/** PostgreSQL's type OID for TEXT[]; its parser returns the elements as strings. */
|
|
6
|
+
const POSTGRES_TEXT_ARRAY_OID = 1009;
|
|
7
|
+
/**
|
|
8
|
+
* node-postgres turns a DATE into a JavaScript Date at local midnight, so in any time zone
|
|
9
|
+
* east of UTC `toISOString()` reports the previous day. A calendar day never passes
|
|
10
|
+
* through local time in AdulaJS: every PostgreSQL connection returns DATE as the
|
|
11
|
+
* 'YYYY-MM-DD' text the server sent, and DATE[] as an array of those strings (null
|
|
12
|
+
* elements stay null). node-postgres keeps one parser registry per driver, so this
|
|
13
|
+
* covers every query: resources, module code and raw Lucid queries alike.
|
|
14
|
+
*
|
|
15
|
+
* `manager.connect(name)` only builds the connection's Knex client (the pool opens no
|
|
16
|
+
* socket until the first query); it is needed because the driver whose registry must be
|
|
17
|
+
* changed is reachable only through that client, and the change has to be in place
|
|
18
|
+
* before any query parses a DATE. Connecting an already connected name is a no-op.
|
|
19
|
+
*/
|
|
20
|
+
export function keepCalendarDays(db) {
|
|
21
|
+
for (const [name, config] of Object.entries(db.config.connections)) {
|
|
22
|
+
if (!['pg', 'postgres', 'postgresql'].includes(config.client))
|
|
23
|
+
continue;
|
|
24
|
+
db.manager.connect(name);
|
|
25
|
+
const connection = db.getRawConnection(name)?.connection;
|
|
26
|
+
for (const client of [connection?.client, connection?.readClient]) {
|
|
27
|
+
const types = client?.client?.driver?.types;
|
|
28
|
+
if (!types)
|
|
29
|
+
continue;
|
|
30
|
+
types.setTypeParser(POSTGRES_DATE_OID, (value) => value);
|
|
31
|
+
const textArray = types.getTypeParser?.(POSTGRES_TEXT_ARRAY_OID, 'text');
|
|
32
|
+
if (textArray)
|
|
33
|
+
types.setTypeParser(POSTGRES_DATE_ARRAY_OID, textArray);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|