adminizer 5.0.0-build.9 → 5.1.0-build.24
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/assets/abnfDiagram-VCTEODGH-DFY3Pztx.js +1 -0
- package/assets/add-31tS-g4V.js +1 -0
- package/assets/add-group-Cf3zT7WE.js +1 -0
- package/assets/add-user-C62wOna-.js +1 -0
- package/assets/ai-assistant/agent.es.js +28464 -0
- package/assets/app-DPmI-MvN.css +1 -0
- package/assets/app-vdHbjOQX.js +138 -0
- package/assets/arc-DP4o1zz3.js +1 -0
- package/assets/architectureDiagram-5GKGNRK7-BjXW5Zu0.js +36 -0
- package/assets/asmcrypto-DZeQH0LC.js +1 -0
- package/assets/blockDiagram-I7D4REHJ-BUPnDwN0.js +129 -0
- package/assets/c4Diagram-7LVT6UL2-Cmb_dAhd.js +38 -0
- package/assets/{catalog-dk6a0I1u.js → catalog-C-y5rMaG.js} +3 -3
- package/assets/channel-CkJRUsq_.js +1 -0
- package/assets/chunk-2Q5K7J3B-CmS-dWwQ.js +1 -0
- package/assets/chunk-5VM5RSS4-Cqs2Ow64.js +15 -0
- package/assets/chunk-F27PBJKO-BoMCpJA1.js +1 -0
- package/assets/chunk-IMKFNOWR-DlDcPk1x.js +231 -0
- package/assets/chunk-JWPE2WC7-DzL_SU8s.js +1 -0
- package/assets/chunk-POPQ4Y6H-Cwq2-Vb8.js +1 -0
- package/assets/chunk-SVP7TREG-BfRHY5FU.js +88 -0
- package/assets/chunk-TICWLB2K-CRP7rHkW.js +206 -0
- package/assets/chunk-XXDRQBXY-Bg2jg-98.js +1 -0
- package/assets/classDiagram-ZZMXUADV-D4EF3HGj.js +1 -0
- package/assets/classDiagram-v2-VYDZK3BY-D4EF3HGj.js +1 -0
- package/assets/controls/ckeditor.es.js +9382 -9320
- package/assets/controls/handsontable.es.js +11971 -11938
- package/assets/controls/jsoneditor.es.js +10442 -10233
- package/assets/controls/toast-ui.es.js +1308 -1279
- package/assets/cose-bilkent-JH36ORCC-CCJ0SGyO.js +1 -0
- package/assets/cynefin-OW5HDTMX-B2Jx5fw3.js +166 -0
- package/assets/cynefinDiagram-5FMLGOSQ-DuK0Lb62.js +62 -0
- package/assets/cytoscape.esm-DzSz-X2X.js +321 -0
- package/assets/dagre-GXQ25YYZ-DnOYexET.js +4 -0
- package/assets/dashboard-X8k4X6Sw.js +3 -0
- package/assets/debounce-B3mXI_sx.js +1 -0
- package/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/assets/diagram-S7CK7UJ4-DDgPBHsK.js +30 -0
- package/assets/diagram-UQ7AKVKN-qlL0GZs8.js +41 -0
- package/assets/diagram-VSXAHHWV-CQbiU1_c.js +3 -0
- package/assets/diagram-VX7I27RA-DFDI9_au.js +24 -0
- package/assets/diagram-Z3DM3KII-B5C9dtmJ.js +24 -0
- package/assets/docs-BiZOD7PP.js +1 -0
- package/assets/ebnfDiagram-PWID7BFC-CLMUsXEI.js +1 -0
- package/assets/erDiagram-RLTQ6QDP-ax9Xol5-.js +99 -0
- package/assets/flowDiagram-HODETNUW-CvaH7l3S.js +168 -0
- package/assets/ganttDiagram-EL5Y4UJY-Cga5U19j.js +292 -0
- package/assets/gitGraphDiagram-WWUBYQGX-B6o1T3-d.js +106 -0
- package/assets/history-CVBJUNSQ.js +1 -0
- package/assets/infoDiagram-27XIBGKW-BpWxgBCE.js +2 -0
- package/assets/init-Gi6I4Gst.js +1 -0
- package/assets/init-user-xSvnFTF0.js +1 -0
- package/assets/isObject-DL-BuaBl.js +1 -0
- package/assets/ishikawaDiagram-5VMMS53U-zE83db4H.js +70 -0
- package/assets/journeyDiagram-3NMN7TZE-DZNVFqrX.js +139 -0
- package/assets/kanban-definition-UXKFOSKX-CqxNgk27.js +89 -0
- package/assets/katex-HP8lGamR.js +257 -0
- package/assets/layout-CN3kt_jt.js +1 -0
- package/assets/linear-nvkaQ6BA.js +1 -0
- package/assets/{list-CcMtS4hD.js → list-CrIU2eZz.js} +2 -2
- package/assets/login-CX9xVjCn.js +1 -0
- package/assets/manifest.json +834 -58
- package/assets/media-manager-BfYftLIH.js +6 -0
- package/assets/mermaid.core-C0V1NaVJ.js +310 -0
- package/assets/mindmap-definition-YA3MSWOX-Bh7_d9f1.js +96 -0
- package/assets/module-DPEvnad3.js +1 -0
- package/assets/notification-Dqpt5AIZ.js +20 -0
- package/assets/ordinal-Cboi1Yqb.js +1 -0
- package/assets/pegDiagram-XKGWAZYB-DMnjm6Z1.js +1 -0
- package/assets/pieDiagram-E7YTZNPT-D-RWCgYb.js +39 -0
- package/assets/quadrantDiagram-AXDQQJYC-BNBGP7RM.js +7 -0
- package/assets/railroadDiagram-O6MQD6OU-BIjVPT01.js +1 -0
- package/assets/register-CF4KQ97e.js +1 -0
- package/assets/requirementDiagram-BXWQKSXE-VPrtGdjM.js +84 -0
- package/assets/ru-CFJ4fysR.js +1 -0
- package/assets/sankeyDiagram-P5KCCOFB-ct9mLF3U.js +40 -0
- package/assets/sequenceDiagram-WJ2MYXX4-TC06Mbmw.js +162 -0
- package/assets/sizeCapture-INFHLROL-BMMwriCf.js +1 -0
- package/assets/stateDiagram-D77RDMKH-DtwYRPCX.js +1 -0
- package/assets/stateDiagram-v2-MP3YSRHH-C1yB0O5U.js +1 -0
- package/assets/swimlanes-42K2YHIH-DE3hRbbr.js +1 -0
- package/assets/swimlanesDiagram-VR7AAH4N-Ce4l1sQD.js +8 -0
- package/assets/timeline-definition-24CTP7MA-N7s_hfjj.js +120 -0
- package/assets/toNumber-DZb-r9sy.js +1 -0
- package/assets/use-appearance-DYTIKpT2.js +1 -0
- package/assets/user-filters-list-fR0YNJ3l.js +1 -0
- package/assets/vennDiagram-4TSXK5OY-Dj5bFQkR.js +34 -0
- package/assets/wardleyDiagram-VM6X3IG4-83ax25Z6.js +78 -0
- package/assets/welcome-v11MTsRK.js +1 -0
- package/assets/with-app-layout-CH6RIib1.js +31 -0
- package/assets/xychartDiagram-S5SC5T6Z-CW9Br5Xp.js +7 -0
- package/controllers/access-rights/permissionOptions.d.ts +2 -0
- package/controllers/access-rights/permissionOptions.js +23 -0
- package/controllers/add.js +2 -2
- package/controllers/addGroup.js +15 -6
- package/controllers/ai/AiAgentController.d.ts +66 -0
- package/controllers/ai/AiAgentController.js +435 -0
- package/controllers/ai/AiAssistantController.d.ts +0 -4
- package/controllers/ai/AiAssistantController.js +4 -78
- package/controllers/catalog/FrontendCatalogAdapter.js +7 -8
- package/controllers/docs/index.d.ts +22 -0
- package/controllers/docs/index.js +126 -0
- package/controllers/edit.js +2 -2
- package/controllers/editGroup.js +15 -6
- package/controllers/filter-fields/savedFilters.js +1 -1
- package/controllers/history-actions/HistoryController.js +7 -7
- package/controllers/inlineUpdate.js +10 -3
- package/controllers/list.js +1 -1
- package/controllers/login.js +1 -1
- package/controllers/notifications/NotificationController.js +14 -8
- package/controllers/view.js +3 -3
- package/controllers/widgets/filterInfo.js +1 -1
- package/helpers/accessRightsHelper.d.ts +30 -3
- package/helpers/accessRightsHelper.js +140 -12
- package/helpers/assetVersionHelper.d.ts +14 -0
- package/helpers/assetVersionHelper.js +42 -0
- package/helpers/configHelper.js +19 -18
- package/helpers/controllerHelper.d.ts +1 -0
- package/helpers/controllerHelper.js +25 -15
- package/helpers/fieldsHelper.d.ts +2 -1
- package/helpers/fieldsHelper.js +11 -5
- package/helpers/inertiaActionsHelper.d.ts +1 -1
- package/helpers/inertiaActionsHelper.js +4 -5
- package/helpers/inertiaAddHelper.d.ts +1 -1
- package/helpers/inertiaAddHelper.js +7 -6
- package/helpers/inertiaGroupHelper.js +10 -2
- package/helpers/inertiaListHelper.d.ts +1 -1
- package/helpers/inertiaListHelper.js +7 -8
- package/helpers/inertiaMenuHelper.d.ts +7 -2
- package/helpers/inertiaMenuHelper.js +12 -27
- package/helpers/menuHelper.d.ts +11 -1
- package/helpers/menuHelper.js +12 -0
- package/helpers/modelResourceHelper.d.ts +9 -0
- package/helpers/modelResourceHelper.js +43 -0
- package/helpers/navigationAccessHelper.d.ts +13 -0
- package/helpers/navigationAccessHelper.js +45 -0
- package/index.d.ts +11 -0
- package/index.js +11 -0
- package/interfaces/adminpanelConfig.d.ts +160 -2
- package/interfaces/queryCriteria.d.ts +13 -0
- package/interfaces/types.d.ts +169 -0
- package/lib/Adminizer.d.ts +8 -0
- package/lib/Adminizer.js +29 -2
- package/lib/DataAccessor.d.ts +100 -3
- package/lib/DataAccessor.js +454 -245
- package/lib/access-graph/AccessGraphResolver.d.ts +136 -0
- package/lib/access-graph/AccessGraphResolver.js +605 -0
- package/lib/access-graph/RecordAccessCache.d.ts +23 -0
- package/lib/access-graph/RecordAccessCache.js +30 -0
- package/lib/access-graph/RecordAccessResolver.d.ts +83 -0
- package/lib/access-graph/RecordAccessResolver.js +295 -0
- package/lib/access-graph/shared.d.ts +60 -0
- package/lib/access-graph/shared.js +121 -0
- package/lib/admin-links/AdminLinkHandler.d.ts +72 -0
- package/lib/admin-links/AdminLinkHandler.js +183 -0
- package/lib/ai-assistant/AbstractAiConversationHistoryService.d.ts +39 -0
- package/lib/ai-assistant/AbstractAiConversationHistoryService.js +98 -0
- package/lib/ai-assistant/AbstractAiModelService.d.ts +139 -2
- package/lib/ai-assistant/AbstractAiModelService.js +154 -1
- package/lib/ai-assistant/AiAgentRunManager.d.ts +35 -0
- package/lib/ai-assistant/AiAgentRunManager.js +109 -0
- package/lib/ai-assistant/AiAssistantAgentSkillHandler.d.ts +61 -0
- package/lib/ai-assistant/AiAssistantAgentSkillHandler.js +90 -0
- package/lib/ai-assistant/AiAssistantHandler.d.ts +1 -0
- package/lib/ai-assistant/AiAssistantHandler.js +4 -0
- package/lib/ai-assistant/AiAssistantUiMethodHandler.d.ts +60 -0
- package/lib/ai-assistant/AiAssistantUiMethodHandler.js +144 -0
- package/lib/ai-assistant/builtinAgentSkills.d.ts +9 -0
- package/lib/ai-assistant/builtinAgentSkills.js +259 -0
- package/lib/ai-assistant/jsonSafe.d.ts +13 -0
- package/lib/ai-assistant/jsonSafe.js +81 -0
- package/lib/app-manager/AdminizerApp.d.ts +31 -2
- package/lib/app-manager/AppManager.js +43 -42
- package/lib/app-manager/ConfigLayerHandler.js +4 -0
- package/lib/docs/AbstractDocumentation.d.ts +100 -0
- package/lib/docs/AbstractDocumentation.js +108 -0
- package/lib/docs/DocumentationHandler.d.ts +100 -0
- package/lib/docs/DocumentationHandler.js +198 -0
- package/lib/docs/FileDocumentation.d.ts +47 -0
- package/lib/docs/FileDocumentation.js +189 -0
- package/lib/docs/docsAgentSkills.d.ts +10 -0
- package/lib/docs/docsAgentSkills.js +93 -0
- package/lib/filters/FilterService.js +4 -3
- package/lib/history-actions/AbstractHistoryAdapter.d.ts +26 -1
- package/lib/history-actions/AbstractHistoryAdapter.js +155 -25
- package/lib/media-manager/helpers/MediaManagerHelper.js +9 -7
- package/lib/model/AbstractModel.d.ts +48 -0
- package/lib/model/AbstractModel.js +14 -4
- package/lib/model/ModelHandler.d.ts +50 -2
- package/lib/model/ModelHandler.js +117 -8
- package/lib/model/adapter/sequelize.d.ts +40 -1
- package/lib/model/adapter/sequelize.js +243 -77
- package/lib/model/adapter/typeorm.d.ts +16 -0
- package/lib/model/adapter/typeorm.js +136 -9
- package/lib/notifications/GeneralNotificationService.js +6 -5
- package/lib/notifications/SystemNotificationService.js +1 -1
- package/lib/ui-i18n/uiTranslationKeys.d.ts +2 -1
- package/lib/ui-i18n/uiTranslationKeys.js +42 -1
- package/lib/widgets/widgetHandler.js +10 -6
- package/models/Group.d.ts +2 -1
- package/package.json +35 -23
- package/policies/authPolicies.js +6 -6
- package/policies/permissionResolvers.d.ts +1 -0
- package/policies/permissionResolvers.js +3 -0
- package/system/Router.js +21 -3
- package/system/bindAccessRights.js +13 -3
- package/system/bindDocs.d.ts +13 -0
- package/system/bindDocs.js +77 -0
- package/system/bindInertia.js +30 -7
- package/system/buildInternalModelAccess.d.ts +8 -0
- package/system/buildInternalModelAccess.js +36 -4
- package/system/defaults.js +7 -1
- package/system/validateSystemModels.js +29 -9
- package/assets/add-CBlLpLr0.js +0 -1
- package/assets/add-group-H0IKIsNm.js +0 -1
- package/assets/add-user-CoTLmxtF.js +0 -1
- package/assets/app-DNXiApCk.css +0 -1
- package/assets/app-layout-xxJpLAvb.js +0 -1
- package/assets/app.js +0 -138
- package/assets/dashboard-DVJS5EPP.js +0 -3
- package/assets/debounce-BMmXVQ06.js +0 -1
- package/assets/history-bWRuzbye.js +0 -1
- package/assets/init-user-8aUohVDq.js +0 -1
- package/assets/login-CO4laf6m.js +0 -1
- package/assets/media-manager-BDbpSSjH.js +0 -6
- package/assets/module-CqO_BKsH.js +0 -1
- package/assets/notification-B5l2wwmi.js +0 -20
- package/assets/register-DBYIMXGQ.js +0 -1
- package/assets/ru-rYKdQbWF.js +0 -1
- package/assets/use-appearance-_EbbjHTh.js +0 -1
- package/assets/user-filters-list-C7kMKN5f.js +0 -1
- package/assets/welcome-6z-7sXnQ.js +0 -1
|
@@ -130,14 +130,16 @@ export async function populateVariants(host, variants, model) {
|
|
|
130
130
|
const mediaModel = "models" in host
|
|
131
131
|
? host.models.get(model)
|
|
132
132
|
: host.modelHandler.internal("media-manager").get(model);
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (populated) {
|
|
137
|
-
items.push(populated);
|
|
138
|
-
}
|
|
133
|
+
const ids = (variants ?? []).map((variant) => variant.id).filter((id) => id !== null && id !== undefined);
|
|
134
|
+
if (!ids.length) {
|
|
135
|
+
return [];
|
|
139
136
|
}
|
|
140
|
-
|
|
137
|
+
// One query for the whole set; the input order is preserved and gaps are dropped
|
|
138
|
+
const populated = await mediaModel.find({ where: { id: { in: ids } } });
|
|
139
|
+
const byId = new Map((populated ?? []).map((item) => [String(item.id), item]));
|
|
140
|
+
return (variants ?? [])
|
|
141
|
+
.map((variant) => byId.get(String(variant.id)))
|
|
142
|
+
.filter((item) => Boolean(item));
|
|
141
143
|
}
|
|
142
144
|
export function getAssociationFieldName(model, associationName) {
|
|
143
145
|
const attributes = model.attributes || {};
|
|
@@ -14,6 +14,8 @@ export interface Attribute {
|
|
|
14
14
|
columnName?: string;
|
|
15
15
|
model?: string;
|
|
16
16
|
collection?: string;
|
|
17
|
+
/** Canonical Adminizer resource target for a system-model association. */
|
|
18
|
+
resourceName?: string;
|
|
17
19
|
via?: string;
|
|
18
20
|
allowNull?: boolean;
|
|
19
21
|
/**
|
|
@@ -30,6 +32,24 @@ export type ModelAnyField = number | string | boolean | Date | Array<number | st
|
|
|
30
32
|
export type ModelAnyInstance = {
|
|
31
33
|
[key: string]: ModelAnyField;
|
|
32
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* One level of an accessGraph pushdown subquery, innermost first: the level SELECTs
|
|
37
|
+
* `select` from `model`, filtered either by the previous (inner) level's subquery on
|
|
38
|
+
* `parentAttribute` or by literal `conditions`. Attribute names are Adminizer attributes
|
|
39
|
+
* (association aliases or plain columns) — the adapter maps them to physical columns.
|
|
40
|
+
*/
|
|
41
|
+
export interface GraphSubqueryLevel {
|
|
42
|
+
model: AbstractModel<any>;
|
|
43
|
+
/** Attribute whose values the level yields. */
|
|
44
|
+
select: string;
|
|
45
|
+
/** Attribute filtered by the previous (inner) level's subquery. */
|
|
46
|
+
parentAttribute?: string;
|
|
47
|
+
/** IN-conditions on this level's own attributes (an empty values list matches nothing). */
|
|
48
|
+
conditions?: Array<{
|
|
49
|
+
attribute: string;
|
|
50
|
+
values: unknown[];
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
33
53
|
export declare abstract class AbstractModel<T> {
|
|
34
54
|
readonly modelname: string;
|
|
35
55
|
readonly attributes: ModelAttributes;
|
|
@@ -44,6 +64,34 @@ export declare abstract class AbstractModel<T> {
|
|
|
44
64
|
protected abstract _destroyOne(criteria: QueryCriteria<T>): Promise<T | null>;
|
|
45
65
|
protected abstract _destroy(criteria: QueryCriteria<T>): Promise<T[]>;
|
|
46
66
|
protected abstract _count(criteria: QueryCriteria<T>): Promise<number>;
|
|
67
|
+
/**
|
|
68
|
+
* accessGraph pushdown hook (stage 3): compiles the level chain into an opaque operand
|
|
69
|
+
* for an `{in: ...}` criteria on this model — one nested subquery instead of
|
|
70
|
+
* materialized id lists. Returns `undefined` when the chain cannot be pushed down
|
|
71
|
+
* (foreign adapter or connection, unknown attribute); the caller then falls back to
|
|
72
|
+
* per-level materialization. Adapters without pushdown support simply don't implement it.
|
|
73
|
+
*
|
|
74
|
+
* What it buys: the fallback issues one query per level and inlines every intermediate id
|
|
75
|
+
* the user can reach into the final `IN (...)`, so a read costs whatever the user's account
|
|
76
|
+
* holds — a member of 500 projects drags ~25 000 task ids through the app to render one page.
|
|
77
|
+
* A chain compiled here is a single statement of constant size at any account size, which is
|
|
78
|
+
* why implementing it is worth the raw-SQL surface. Because the fallback is silent, an
|
|
79
|
+
* implementation that quietly declines is a performance regression nobody is told about —
|
|
80
|
+
* decline only where correctness demands it (see the Sequelize adapter's `defaultScope` and
|
|
81
|
+
* `paranoid` handling), and keep it equivalent to the materialized walk row for row.
|
|
82
|
+
*
|
|
83
|
+
* @param decline call it with a human-readable reason before returning `undefined`. The
|
|
84
|
+
* resolver logs that reason once per model, which is the only signal an operator gets that a
|
|
85
|
+
* configured `pushdown: true` is not doing anything for this chain.
|
|
86
|
+
*/
|
|
87
|
+
compileGraphInSubquery?(levels: GraphSubqueryLevel[], decline?: (reason: string) => void): Promise<unknown | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Whether `criteria.populateOn` works for `association` on this model: the adapter
|
|
90
|
+
* can AND the condition into that populate JOIN and hand a filtered-out record back
|
|
91
|
+
* as its bare foreign-key value. Emitters must check this before setting the key —
|
|
92
|
+
* an unsupported association has to keep the post-read verification instead.
|
|
93
|
+
*/
|
|
94
|
+
canPushdownPopulateAccess?(association: string): boolean;
|
|
47
95
|
protected createInternalRepository(accessToken: symbol, modelName?: string): InternalModelRepository<T>;
|
|
48
96
|
/**
|
|
49
97
|
* Generate diff between old and new records
|
|
@@ -127,13 +127,21 @@ export class AbstractModel {
|
|
|
127
127
|
}
|
|
128
128
|
async findOne(criteria, dataAccessor) {
|
|
129
129
|
criteria = await dataAccessor.sanitizeUserRelationAccess(criteria);
|
|
130
|
+
criteria = await dataAccessor.pushDownPopulateAccess(criteria);
|
|
130
131
|
let record = await this._findOne(criteria);
|
|
131
|
-
|
|
132
|
+
if (!record) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
// Populated associations are not covered by the criteria above — see processManyWithAccess
|
|
136
|
+
const [processed] = await dataAccessor.processManyWithAccess([record], criteria);
|
|
137
|
+
return processed;
|
|
132
138
|
}
|
|
133
139
|
async find(criteria, dataAccessor) {
|
|
134
140
|
criteria = await dataAccessor.sanitizeUserRelationAccess(criteria);
|
|
141
|
+
criteria = await dataAccessor.pushDownPopulateAccess(criteria);
|
|
135
142
|
let records = await this._find(criteria);
|
|
136
|
-
|
|
143
|
+
// Populated associations are not covered by the criteria above — see processManyWithAccess
|
|
144
|
+
return dataAccessor.processManyWithAccess(records, criteria);
|
|
137
145
|
}
|
|
138
146
|
/**
|
|
139
147
|
* Find with raw SQL where clause (Sequelize.literal support)
|
|
@@ -152,7 +160,8 @@ export class AbstractModel {
|
|
|
152
160
|
throw new Error('countWithRawWhere is only supported in Sequelize adapter');
|
|
153
161
|
}
|
|
154
162
|
async updateOne(criteria, data, dataAccessor) {
|
|
155
|
-
|
|
163
|
+
// Write rules apply on update too: the record may not move out of the user's reach
|
|
164
|
+
let _data = await dataAccessor.setUserRelationAccess(dataAccessor.process(data));
|
|
156
165
|
// Get the old record first for diff
|
|
157
166
|
criteria = await dataAccessor.sanitizeUserRelationAccess(criteria);
|
|
158
167
|
const oldRecord = await this._findOne(criteria);
|
|
@@ -168,7 +177,8 @@ export class AbstractModel {
|
|
|
168
177
|
return dataAccessor.process(record, criteria);
|
|
169
178
|
}
|
|
170
179
|
async update(criteria, data, dataAccessor) {
|
|
171
|
-
|
|
180
|
+
// Write rules apply on update too: the record may not move out of the user's reach
|
|
181
|
+
let _data = await dataAccessor.setUserRelationAccess(dataAccessor.process(data));
|
|
172
182
|
criteria = await dataAccessor.sanitizeUserRelationAccess(criteria);
|
|
173
183
|
// Get old records automatically
|
|
174
184
|
const oldRecords = await this._find(criteria);
|
|
@@ -9,10 +9,26 @@ export interface AppModelAccessRecord {
|
|
|
9
9
|
export interface ModelRecord {
|
|
10
10
|
id: string;
|
|
11
11
|
name: string;
|
|
12
|
+
hostModelName: string;
|
|
13
|
+
primaryHostModel: boolean;
|
|
12
14
|
model: AbstractModel<any>;
|
|
13
15
|
ownerApp?: string;
|
|
14
16
|
enabled: boolean;
|
|
15
17
|
}
|
|
18
|
+
export interface ModelRegistrationOptions {
|
|
19
|
+
/** Physical ORM model name. It is intentionally independent from the Adminizer resource name. */
|
|
20
|
+
hostModelName?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Selects this resource as the association target when multiple resources use the same host model.
|
|
23
|
+
* Exactly one resource must be primary for every shared host model.
|
|
24
|
+
*/
|
|
25
|
+
primary?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Register and use the canonical Adminizer resource name instead.
|
|
28
|
+
* Kept only for compatibility with existing integrations. Host model names must not be used as aliases.
|
|
29
|
+
*/
|
|
30
|
+
aliases?: string[];
|
|
31
|
+
}
|
|
16
32
|
export declare class AppModelAccess {
|
|
17
33
|
private readonly getModel;
|
|
18
34
|
private readonly appName;
|
|
@@ -33,9 +49,15 @@ export declare class AppModelAccess {
|
|
|
33
49
|
export declare class ModelHandler {
|
|
34
50
|
private models;
|
|
35
51
|
private modelAliases;
|
|
52
|
+
private hostModelResources;
|
|
36
53
|
private internalAccess?;
|
|
37
54
|
private appAccessRecords;
|
|
38
|
-
|
|
55
|
+
private registryEpoch;
|
|
56
|
+
/** Bumped on every registry mutation; consumers key their caches on it. */
|
|
57
|
+
get registryVersion(): number;
|
|
58
|
+
add<T>(resourceName: string, modelInstance: AbstractModel<T>, options?: ModelRegistrationOptions): void;
|
|
59
|
+
/** @deprecated Pass `{ aliases }` in ModelRegistrationOptions, or preferably use the canonical resource name. */
|
|
60
|
+
add<T>(resourceName: string, modelInstance: AbstractModel<T>, aliases?: string[]): void;
|
|
39
61
|
register<T>(appName: string, modelName: string, modelInstance: AbstractModel<T>): string;
|
|
40
62
|
unregister(id: string): void;
|
|
41
63
|
disable(id: string): void;
|
|
@@ -45,7 +67,10 @@ export declare class ModelHandler {
|
|
|
45
67
|
unregisterAppAccess(id: string): void;
|
|
46
68
|
getAppAccessRecords(appName: string): AppModelAccessRecord[];
|
|
47
69
|
createAppAccess(appName: string): AppModelAccess;
|
|
48
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Improved model getter with case-insensitive lookup and configured alias support.
|
|
72
|
+
* @deprecated New code should use getResource() and getByHostModel() explicitly.
|
|
73
|
+
*/
|
|
49
74
|
get model(): {
|
|
50
75
|
get: (modelName: string) => AbstractModel<any>;
|
|
51
76
|
has: (modelName: string) => boolean;
|
|
@@ -53,6 +78,26 @@ export declare class ModelHandler {
|
|
|
53
78
|
keys: () => IterableIterator<string>;
|
|
54
79
|
values: () => IterableIterator<AbstractModel<any>>;
|
|
55
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Returns a model by its Adminizer resource name or an explicit deprecated compatibility alias.
|
|
83
|
+
* New code must use canonical resource names.
|
|
84
|
+
*/
|
|
85
|
+
getResource(resourceName: string): AbstractModel<any> | undefined;
|
|
86
|
+
getResourceRecord(resourceName: string): ModelRecord | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Resolves a physical ORM model name to its Adminizer resource.
|
|
89
|
+
* This lookup is deliberately separate from getResource(): a host model may have the
|
|
90
|
+
* same name as a system resource while being exposed under a project resource alias.
|
|
91
|
+
*/
|
|
92
|
+
resolveResourceByHostModel(hostModelName: string): string | undefined;
|
|
93
|
+
getByHostModel(hostModelName: string): AbstractModel<any> | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Resolves an ORM association target. Adapter-provided host model names take precedence;
|
|
96
|
+
* system-model relations may pass their explicit canonical resource name instead.
|
|
97
|
+
*/
|
|
98
|
+
resolveAssociationResource(targetName: string, resourceName?: string): string | undefined;
|
|
99
|
+
/** Validates that every host ORM model used by multiple resources has one primary resource. */
|
|
100
|
+
validateHostModelMappings(): void;
|
|
56
101
|
resolveModelName(modelName: string): string;
|
|
57
102
|
configureInternalAccess(accessMap?: InternalModelAccessMap): void;
|
|
58
103
|
internal(scopeName: string): InternalModelScope;
|
|
@@ -63,6 +108,9 @@ export declare class ModelHandler {
|
|
|
63
108
|
get all(): AbstractModel<any>[];
|
|
64
109
|
private getAllowedAppModels;
|
|
65
110
|
private registerAliases;
|
|
111
|
+
private registerHostModel;
|
|
112
|
+
private unregisterHostModel;
|
|
113
|
+
private getSharedHostModelError;
|
|
66
114
|
private resolveName;
|
|
67
115
|
private enabledModelEntries;
|
|
68
116
|
private enabledModelKeys;
|
|
@@ -40,18 +40,33 @@ export class AppModelAccess {
|
|
|
40
40
|
export class ModelHandler {
|
|
41
41
|
models = new Map();
|
|
42
42
|
modelAliases = new Map();
|
|
43
|
+
hostModelResources = new Map();
|
|
43
44
|
internalAccess;
|
|
44
45
|
appAccessRecords = new Map();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
registryEpoch = 0;
|
|
47
|
+
/** Bumped on every registry mutation; consumers key their caches on it. */
|
|
48
|
+
get registryVersion() {
|
|
49
|
+
return this.registryEpoch;
|
|
50
|
+
}
|
|
51
|
+
add(resourceName, modelInstance, options = {}) {
|
|
52
|
+
const resourceId = normalizeName(resourceName);
|
|
53
|
+
if (this.models.has(resourceId)) {
|
|
54
|
+
throw new Error(`Model resource "${resourceName}" is already registered`);
|
|
55
|
+
}
|
|
56
|
+
const normalizedOptions = Array.isArray(options) ? { aliases: options } : options;
|
|
57
|
+
const hostModelName = normalizedOptions.hostModelName ?? resourceName;
|
|
58
|
+
this.registerHostModel(resourceName, hostModelName, true);
|
|
59
|
+
this.models.set(resourceId, {
|
|
60
|
+
id: resourceId,
|
|
61
|
+
name: resourceName,
|
|
62
|
+
hostModelName,
|
|
63
|
+
primaryHostModel: normalizedOptions.primary === true,
|
|
50
64
|
model: modelInstance,
|
|
51
65
|
enabled: true,
|
|
52
66
|
});
|
|
53
|
-
this.registerAliases(
|
|
54
|
-
|
|
67
|
+
this.registerAliases(resourceName, normalizedOptions.aliases ?? []);
|
|
68
|
+
this.registryEpoch++;
|
|
69
|
+
Adminizer.log.debug(`Model resource [${resourceName}] was registered for host model [${hostModelName}]`);
|
|
55
70
|
}
|
|
56
71
|
register(appName, modelName, modelInstance) {
|
|
57
72
|
const normalizedModelName = normalizeName(modelName);
|
|
@@ -61,10 +76,14 @@ export class ModelHandler {
|
|
|
61
76
|
this.models.set(normalizedModelName, {
|
|
62
77
|
id: normalizedModelName,
|
|
63
78
|
name: modelName,
|
|
79
|
+
hostModelName: modelName,
|
|
80
|
+
primaryHostModel: true,
|
|
64
81
|
model: modelInstance,
|
|
65
82
|
ownerApp: appName,
|
|
66
83
|
enabled: true,
|
|
67
84
|
});
|
|
85
|
+
this.registerHostModel(modelName, modelName, false);
|
|
86
|
+
this.registryEpoch++;
|
|
68
87
|
Adminizer.log.debug(`Model with name [${normalizedModelName}] was registered by app [${appName}]`);
|
|
69
88
|
return normalizedModelName;
|
|
70
89
|
}
|
|
@@ -74,6 +93,8 @@ export class ModelHandler {
|
|
|
74
93
|
return;
|
|
75
94
|
}
|
|
76
95
|
this.models.delete(normalizeName(id));
|
|
96
|
+
this.unregisterHostModel(record.hostModelName, record.name);
|
|
97
|
+
this.registryEpoch++;
|
|
77
98
|
}
|
|
78
99
|
disable(id) {
|
|
79
100
|
const record = this.models.get(normalizeName(id));
|
|
@@ -81,6 +102,7 @@ export class ModelHandler {
|
|
|
81
102
|
return;
|
|
82
103
|
}
|
|
83
104
|
record.enabled = false;
|
|
105
|
+
this.registryEpoch++;
|
|
84
106
|
}
|
|
85
107
|
enable(id) {
|
|
86
108
|
const record = this.models.get(normalizeName(id));
|
|
@@ -88,6 +110,7 @@ export class ModelHandler {
|
|
|
88
110
|
return;
|
|
89
111
|
}
|
|
90
112
|
record.enabled = true;
|
|
113
|
+
this.registryEpoch++;
|
|
91
114
|
}
|
|
92
115
|
getByApp(appName) {
|
|
93
116
|
return Array.from(this.models.values()).filter((record) => record.ownerApp === appName);
|
|
@@ -118,7 +141,10 @@ export class ModelHandler {
|
|
|
118
141
|
return new AppModelAccess((modelName) => this.model.get(modelName), appName, () => this.getAllowedAppModels(appName));
|
|
119
142
|
}
|
|
120
143
|
// TODO: 'hot reload' need add method for delete model & unbind
|
|
121
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* Improved model getter with case-insensitive lookup and configured alias support.
|
|
146
|
+
* @deprecated New code should use getResource() and getByHostModel() explicitly.
|
|
147
|
+
*/
|
|
122
148
|
get model() {
|
|
123
149
|
return {
|
|
124
150
|
get: (modelName) => this.models.get(this.resolveName(modelName))?.enabled
|
|
@@ -130,6 +156,65 @@ export class ModelHandler {
|
|
|
130
156
|
values: () => this.enabledModelValues(),
|
|
131
157
|
};
|
|
132
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns a model by its Adminizer resource name or an explicit deprecated compatibility alias.
|
|
161
|
+
* New code must use canonical resource names.
|
|
162
|
+
*/
|
|
163
|
+
getResource(resourceName) {
|
|
164
|
+
return this.model.get(resourceName);
|
|
165
|
+
}
|
|
166
|
+
getResourceRecord(resourceName) {
|
|
167
|
+
const record = this.models.get(this.resolveName(resourceName));
|
|
168
|
+
return record?.enabled ? record : undefined;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Resolves a physical ORM model name to its Adminizer resource.
|
|
172
|
+
* This lookup is deliberately separate from getResource(): a host model may have the
|
|
173
|
+
* same name as a system resource while being exposed under a project resource alias.
|
|
174
|
+
*/
|
|
175
|
+
resolveResourceByHostModel(hostModelName) {
|
|
176
|
+
const resourceIds = this.hostModelResources.get(normalizeName(hostModelName));
|
|
177
|
+
const records = Array.from(resourceIds ?? [])
|
|
178
|
+
.map((resourceId) => this.models.get(resourceId))
|
|
179
|
+
.filter((record) => Boolean(record?.enabled));
|
|
180
|
+
if (records.length === 1) {
|
|
181
|
+
return records[0].name;
|
|
182
|
+
}
|
|
183
|
+
const primaryRecords = records.filter((record) => record.primaryHostModel);
|
|
184
|
+
if (primaryRecords.length === 1) {
|
|
185
|
+
return primaryRecords[0].name;
|
|
186
|
+
}
|
|
187
|
+
if (records.length > 1) {
|
|
188
|
+
throw new Error(this.getSharedHostModelError(hostModelName, records));
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
getByHostModel(hostModelName) {
|
|
193
|
+
const resourceName = this.resolveResourceByHostModel(hostModelName);
|
|
194
|
+
return resourceName ? this.getResource(resourceName) : undefined;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Resolves an ORM association target. Adapter-provided host model names take precedence;
|
|
198
|
+
* system-model relations may pass their explicit canonical resource name instead.
|
|
199
|
+
*/
|
|
200
|
+
resolveAssociationResource(targetName, resourceName) {
|
|
201
|
+
if (resourceName) {
|
|
202
|
+
return this.getResourceRecord(resourceName)?.name;
|
|
203
|
+
}
|
|
204
|
+
return this.resolveResourceByHostModel(targetName)
|
|
205
|
+
?? this.getResourceRecord(targetName)?.name;
|
|
206
|
+
}
|
|
207
|
+
/** Validates that every host ORM model used by multiple resources has one primary resource. */
|
|
208
|
+
validateHostModelMappings() {
|
|
209
|
+
for (const [normalizedHostModelName, resourceIds] of this.hostModelResources) {
|
|
210
|
+
const records = Array.from(resourceIds)
|
|
211
|
+
.map((resourceId) => this.models.get(resourceId))
|
|
212
|
+
.filter((record) => Boolean(record?.enabled));
|
|
213
|
+
if (records.length > 1 && records.filter((record) => record.primaryHostModel).length !== 1) {
|
|
214
|
+
throw new Error(this.getSharedHostModelError(records[0]?.hostModelName ?? normalizedHostModelName, records));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
133
218
|
resolveModelName(modelName) {
|
|
134
219
|
const resolvedName = this.resolveName(modelName);
|
|
135
220
|
return this.models.get(resolvedName)?.name ?? modelName;
|
|
@@ -184,6 +269,30 @@ export class ModelHandler {
|
|
|
184
269
|
this.modelAliases.set(normalizedAlias, normalizedModelName);
|
|
185
270
|
}
|
|
186
271
|
}
|
|
272
|
+
registerHostModel(resourceName, hostModelName, allowMultipleResources) {
|
|
273
|
+
const normalizedHostModelName = normalizeName(hostModelName);
|
|
274
|
+
const resourceId = normalizeName(resourceName);
|
|
275
|
+
const resourceIds = this.hostModelResources.get(normalizedHostModelName) ?? new Set();
|
|
276
|
+
if (!allowMultipleResources && resourceIds.size && !resourceIds.has(resourceId)) {
|
|
277
|
+
const existingResourceId = resourceIds.values().next().value;
|
|
278
|
+
const existingResource = this.models.get(existingResourceId)?.name ?? existingResourceId;
|
|
279
|
+
throw new Error(`Host model "${hostModelName}" is already registered for Adminizer resource "${existingResource}"`);
|
|
280
|
+
}
|
|
281
|
+
resourceIds.add(resourceId);
|
|
282
|
+
this.hostModelResources.set(normalizedHostModelName, resourceIds);
|
|
283
|
+
}
|
|
284
|
+
unregisterHostModel(hostModelName, resourceName) {
|
|
285
|
+
const normalizedHostModelName = normalizeName(hostModelName);
|
|
286
|
+
const resourceIds = this.hostModelResources.get(normalizedHostModelName);
|
|
287
|
+
resourceIds?.delete(normalizeName(resourceName));
|
|
288
|
+
if (!resourceIds?.size) {
|
|
289
|
+
this.hostModelResources.delete(normalizedHostModelName);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
getSharedHostModelError(hostModelName, records) {
|
|
293
|
+
return (`Host model "${hostModelName}" is mapped to multiple Adminizer resources: ` +
|
|
294
|
+
`${records.map((record) => record.name).join(", ")}. Configure exactly one with primary: true.`);
|
|
295
|
+
}
|
|
187
296
|
resolveName(modelName) {
|
|
188
297
|
const normalizedModelName = normalizeName(modelName);
|
|
189
298
|
return this.modelAliases.get(normalizedModelName) ?? normalizedModelName;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelStatic, Sequelize as SequelizeType } from "sequelize";
|
|
2
|
-
import { AbstractAdapter, AbstractAdapterOptions, AbstractModel, Attribute } from "../AbstractModel.js";
|
|
2
|
+
import { AbstractAdapter, AbstractAdapterOptions, AbstractModel, Attribute, GraphSubqueryLevel } from "../AbstractModel.js";
|
|
3
3
|
import { QueryCriteria } from "../../../interfaces/queryCriteria.js";
|
|
4
4
|
export declare function mapSequelizeToAdminizerAttributes(model: ModelStatic<any>): Record<string, Attribute>;
|
|
5
5
|
export declare class SequelizeModel<T> extends AbstractModel<T> {
|
|
@@ -7,6 +7,22 @@ export declare class SequelizeModel<T> extends AbstractModel<T> {
|
|
|
7
7
|
private _init;
|
|
8
8
|
private _ensure;
|
|
9
9
|
constructor(modelName: string, model: ModelStatic<any>);
|
|
10
|
+
/**
|
|
11
|
+
* accessGraph pushdown: compiles the level chain into one nested-subquery literal for
|
|
12
|
+
* an `{in: ...}` criteria, so the DB planner optimizes the whole walk instead of the
|
|
13
|
+
* app materializing id lists. Returns undefined — falling back to materialization —
|
|
14
|
+
* when any level lives on another adapter or connection, an attribute is unknown, or a
|
|
15
|
+
* level carries a defaultScope we cannot reproduce.
|
|
16
|
+
*
|
|
17
|
+
* The materialized path queries through `model.find()`, so it inherits paranoid and
|
|
18
|
+
* defaultScope filtering; this raw SQL must match it exactly or the same config would
|
|
19
|
+
* yield two different record sets depending on `pushdown`.
|
|
20
|
+
*
|
|
21
|
+
* Every bail-out reports through `decline` before returning: a fallback is invisible in the
|
|
22
|
+
* result (the records are the same, only slower), so the reason is the only thing that tells
|
|
23
|
+
* an operator why `pushdown: true` changed nothing.
|
|
24
|
+
*/
|
|
25
|
+
compileGraphInSubquery(levels: GraphSubqueryLevel[], decline?: (reason: string) => void): Promise<unknown | undefined>;
|
|
10
26
|
private _buildJsonContainsCondition;
|
|
11
27
|
_convertCriteriaToSequelize(criteria: any): any;
|
|
12
28
|
_convertAdminizerCriteriaToSequelizeOptions(criteria: any): {
|
|
@@ -36,6 +52,18 @@ export declare class SequelizeModel<T> extends AbstractModel<T> {
|
|
|
36
52
|
countWithRawWhere(where: any): Promise<number>;
|
|
37
53
|
protected _updateOne(criteria: QueryCriteria, data: Partial<T>): Promise<T | null>;
|
|
38
54
|
protected _update(criteria: QueryCriteria, data: Partial<T>): Promise<T[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Application-level cascade for the records `ids` identifies, one statement per
|
|
57
|
+
* association instead of a getter plus a delete per related row:
|
|
58
|
+
*
|
|
59
|
+
* - `belongsTo` — the parent is never touched; deleting a task must not delete its project;
|
|
60
|
+
* - `belongsToMany` — only the link rows go, never the far side: those rows are shared
|
|
61
|
+
* (deleting one post must not delete a tag another post still uses);
|
|
62
|
+
* - `hasOne` / `hasMany` — the children are deleted, which is the actual cascade.
|
|
63
|
+
*
|
|
64
|
+
* Row-level destroy hooks are preserved for targets that declare them.
|
|
65
|
+
*/
|
|
66
|
+
private _cascadeDelete;
|
|
39
67
|
protected _destroyOne(criteria: QueryCriteria): Promise<T | null>;
|
|
40
68
|
protected _destroy(criteria: QueryCriteria): Promise<T[]>;
|
|
41
69
|
protected _count(criteria?: QueryCriteria): Promise<number>;
|
|
@@ -43,6 +71,17 @@ export declare class SequelizeModel<T> extends AbstractModel<T> {
|
|
|
43
71
|
private _extractRelationAliasesFromWhere;
|
|
44
72
|
private _buildListInclude;
|
|
45
73
|
private _buildIncludes;
|
|
74
|
+
/**
|
|
75
|
+
* `criteria.populateOn` support: BelongsTo only — the owning row keeps its FK
|
|
76
|
+
* column, so a record filtered out of the JOIN can be handed back as that bare value.
|
|
77
|
+
*/
|
|
78
|
+
canPushdownPopulateAccess(association: string): boolean;
|
|
79
|
+
/** ANDs `criteria.populateOn` into the matching includes' ON clause (LEFT JOIN — owning rows stay). */
|
|
80
|
+
private _applyPopulateOn;
|
|
81
|
+
/** A record filtered out of a `populateOn` JOIN comes back as its bare foreign key. */
|
|
82
|
+
private _collapsePopulateOn;
|
|
83
|
+
/** The collapse above reads the FK columns — keep them selected under an explicit `select`. */
|
|
84
|
+
private _ensureForeignKeysSelected;
|
|
46
85
|
private _buildAttributes;
|
|
47
86
|
private _buildCriteriaIncludes;
|
|
48
87
|
}
|