@openinc/parse-server-opendash 4.19.0 → 4.20.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.
@@ -83,7 +83,85 @@ async function applyLinkedObjectTenant(request) {
83
83
  console.error("[@openinc/parse-server-opendash][Meta_Entry] Failed to resolve the linked object's tenant", className, objectId, error);
84
84
  }
85
85
  }
86
+ /**
87
+ * The classes a meta entry can be *about*, i.e. every class some context
88
+ * addresses by `entryClassName`. Kept here rather than spread over the ten
89
+ * classes' own hook modules: the list is the answer to "who carries meta
90
+ * entries", it belongs next to the class that holds them, and ten copies of the
91
+ * same three lines is how the eleventh context gets forgotten.
92
+ *
93
+ * Derived from the frontend's context constants — `MetaContext` (bde),
94
+ * `metaContext()` / `TICKET_VIEWS_META_CONTEXT` /
95
+ * `SCHEDULE_VIEWS_META_CONTEXT` (openservice v2), `stepMetaContext()`, and the
96
+ * literals the v1 openservice plugin still uses. Adding a context for a class
97
+ * that is not in here leaves its entries behind on delete.
98
+ */
99
+ const META_SUBJECT_CLASSES = [
100
+ node_1.default.User,
101
+ index_js_3.Source,
102
+ index_js_3.BDE_Article,
103
+ index_js_3.Service_Ticket,
104
+ index_js_3.Service_Equipment,
105
+ index_js_3.Service_Schedule_Execution,
106
+ index_js_3.Tenant,
107
+ index_js_3.Maintenance_Ticket,
108
+ index_js_3.Maintenance_Schedule,
109
+ index_js_3.Maintenance_Schedule_Execution_Step,
110
+ ];
111
+ /**
112
+ * Drop the meta entries of an object that was deleted.
113
+ *
114
+ * Nothing did this before: an entry addresses its subject by the two strings
115
+ * `entryClassName` + `entryObjectId` and not by a pointer, so Parse has no idea
116
+ * the two belong together and deleting the subject left the entry sitting there
117
+ * forever. The index this query runs on was already declared for exactly this
118
+ * case — see `od_entryObjectId_entryClassName_context` in `indexes.ts`, whose
119
+ * comment names "cleanup on delete (without `context`)".
120
+ *
121
+ * **`afterDelete`, deliberately not `beforeDelete`.** A throw in `beforeDelete`
122
+ * aborts the delete, which would make a failed bit of housekeeping enough to
123
+ * stop anyone from deleting a ticket. Here the object is already gone and a
124
+ * failure leaves exactly what the situation was before this existed — an
125
+ * orphaned entry — so it is logged and swallowed.
126
+ *
127
+ * Soft delete is unaffected and should be: the archive action stamps a marker
128
+ * column instead of destroying the row, no delete trigger fires, and the
129
+ * entries of an archived object stay with it until it is really deleted.
130
+ *
131
+ * One case this cannot reach: the schedule step contexts carry the step id
132
+ * *inside the context* (`["openservice", "schedule", "step", <stepId>]`) while
133
+ * the entry hangs off the execution. Removing a step from a plan therefore
134
+ * leaves an entry whose subject is still alive, which no `entryObjectId` lookup
135
+ * can find.
136
+ */
137
+ async function removeEntriesOfDeletedObject(className, objectId) {
138
+ try {
139
+ // No `context` constraint: every context's entries for this object go.
140
+ const orphans = await new node_1.default.Query(index_js_3.Meta_Entry)
141
+ .equalTo("entryClassName", className)
142
+ .equalTo("entryObjectId", objectId)
143
+ .find({ useMasterKey: true });
144
+ if (orphans.length === 0)
145
+ return;
146
+ await node_1.default.Object.destroyAll(orphans, { useMasterKey: true });
147
+ }
148
+ catch (error) {
149
+ console.error("[@openinc/parse-server-opendash][Meta_Entry] Failed to remove the meta entries of a deleted object", className, objectId, error);
150
+ }
151
+ }
86
152
  async function init() {
153
+ for (const subjectClass of META_SUBJECT_CLASSES) {
154
+ // `.className` and not a literal: a query on a class name that does not
155
+ // exist returns nothing instead of throwing, so a typo here would be a
156
+ // cleanup that silently never cleans anything up.
157
+ const className = subjectClass
158
+ .className;
159
+ (0, index_js_2.afterDeleteHook)(subjectClass, async ({ object }) => {
160
+ if (!object?.id)
161
+ return;
162
+ await removeEntriesOfDeletedObject(className, object.id);
163
+ });
164
+ }
87
165
  (0, index_js_2.beforeSaveHook)(index_js_3.Meta_Entry, async (request) => {
88
166
  await (0, index_js_2.defaultHandler)(request);
89
167
  // Before the ACL handler: it derives every grant from `tenant`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.19.0",
3
+ "version": "4.20.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.8.1",
6
6
  "keywords": [