@memberjunction/core 6.3.0-edge.0 → 6.3.0-edge.1
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/dist/generic/baseEngine.d.ts +9 -0
- package/dist/generic/baseEngine.d.ts.map +1 -1
- package/dist/generic/baseEngine.js +23 -1
- package/dist/generic/baseEngine.js.map +1 -1
- package/dist/generic/baseEngineRegistry.d.ts +8 -0
- package/dist/generic/baseEngineRegistry.d.ts.map +1 -1
- package/dist/generic/baseEngineRegistry.js +28 -10
- package/dist/generic/baseEngineRegistry.js.map +1 -1
- package/dist/generic/baseEntity.d.ts +8 -0
- package/dist/generic/baseEntity.d.ts.map +1 -1
- package/dist/generic/baseEntity.js +87 -53
- package/dist/generic/baseEntity.js.map +1 -1
- package/dist/generic/baseRemotableOperation.d.ts +17 -0
- package/dist/generic/baseRemotableOperation.d.ts.map +1 -1
- package/dist/generic/baseRemotableOperation.js +18 -0
- package/dist/generic/baseRemotableOperation.js.map +1 -1
- package/dist/generic/constraintErrorRedaction.d.ts +26 -0
- package/dist/generic/constraintErrorRedaction.d.ts.map +1 -0
- package/dist/generic/constraintErrorRedaction.js +166 -0
- package/dist/generic/constraintErrorRedaction.js.map +1 -0
- package/dist/generic/dataHooks.d.ts +27 -3
- package/dist/generic/dataHooks.d.ts.map +1 -1
- package/dist/generic/dataHooks.js +82 -0
- package/dist/generic/dataHooks.js.map +1 -1
- package/dist/generic/databaseProviderBase.d.ts +59 -1
- package/dist/generic/databaseProviderBase.d.ts.map +1 -1
- package/dist/generic/databaseProviderBase.js +201 -27
- package/dist/generic/databaseProviderBase.js.map +1 -1
- package/dist/generic/entityInfo.d.ts +48 -5
- package/dist/generic/entityInfo.d.ts.map +1 -1
- package/dist/generic/entityInfo.js +181 -49
- package/dist/generic/entityInfo.js.map +1 -1
- package/dist/generic/entitySavePlan.d.ts +6 -0
- package/dist/generic/entitySavePlan.d.ts.map +1 -1
- package/dist/generic/entitySavePlan.js +145 -1
- package/dist/generic/entitySavePlan.js.map +1 -1
- package/dist/generic/interfaces.d.ts +69 -18
- package/dist/generic/interfaces.d.ts.map +1 -1
- package/dist/generic/interfaces.js +9 -9
- package/dist/generic/interfaces.js.map +1 -1
- package/dist/generic/localCacheManager.d.ts +10 -13
- package/dist/generic/localCacheManager.d.ts.map +1 -1
- package/dist/generic/localCacheManager.js +189 -67
- package/dist/generic/localCacheManager.js.map +1 -1
- package/dist/generic/metadata.d.ts +4 -4
- package/dist/generic/metadata.d.ts.map +1 -1
- package/dist/generic/metadata.js +4 -4
- package/dist/generic/metadata.js.map +1 -1
- package/dist/generic/providerBase.d.ts +193 -12
- package/dist/generic/providerBase.d.ts.map +1 -1
- package/dist/generic/providerBase.js +571 -90
- package/dist/generic/providerBase.js.map +1 -1
- package/dist/generic/queryResultEnricher.d.ts +4 -1
- package/dist/generic/queryResultEnricher.d.ts.map +1 -1
- package/dist/generic/queryResultEnricher.js.map +1 -1
- package/dist/generic/queryTemplateContext.d.ts.map +1 -1
- package/dist/generic/queryTemplateContext.js +38 -3
- package/dist/generic/queryTemplateContext.js.map +1 -1
- package/dist/generic/relatedRecordCollection.d.ts +20 -0
- package/dist/generic/relatedRecordCollection.d.ts.map +1 -1
- package/dist/generic/relatedRecordCollection.js +257 -22
- package/dist/generic/relatedRecordCollection.js.map +1 -1
- package/dist/generic/securityInfo.d.ts +49 -2
- package/dist/generic/securityInfo.d.ts.map +1 -1
- package/dist/generic/securityInfo.js +139 -12
- package/dist/generic/securityInfo.js.map +1 -1
- package/dist/generic/telemetryManager.d.ts +40 -4
- package/dist/generic/telemetryManager.d.ts.map +1 -1
- package/dist/generic/telemetryManager.js +68 -15
- package/dist/generic/telemetryManager.js.map +1 -1
- package/dist/generic/transactionGroup.d.ts +41 -23
- package/dist/generic/transactionGroup.d.ts.map +1 -1
- package/dist/generic/transactionGroup.js +133 -70
- package/dist/generic/transactionGroup.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/views/runView.d.ts +8 -0
- package/dist/views/runView.d.ts.map +1 -1
- package/dist/views/runView.js +20 -3
- package/dist/views/runView.js.map +1 -1
- package/package.json +3 -3
- package/readme.md +6 -5
- package/dist/generic/typedQuery.d.ts +0 -151
- package/dist/generic/typedQuery.d.ts.map +0 -1
- package/dist/generic/typedQuery.js +0 -286
- package/dist/generic/typedQuery.js.map +0 -1
|
@@ -19,7 +19,7 @@ import { ExplorerNavigationItem } from "./explorerNavigationItem.js";
|
|
|
19
19
|
import { Metadata } from "./metadata.js";
|
|
20
20
|
import { RunView, IsMaterializedDataSource, ExtractRunViewParameterNames } from "../views/runView.js";
|
|
21
21
|
import { IsPlatformSQL } from "./platformSQL.js";
|
|
22
|
-
import { GetDataHooks } from "./dataHooks.js";
|
|
22
|
+
import { GetDataHooks, IsPostRunViewProtectedEntity } from "./dataHooks.js";
|
|
23
23
|
import { TransformSimpleObjectToEntityObject } from "./util.js";
|
|
24
24
|
import { LoadRelatedRecordsBatched } from "./relatedRecordBatchLoader.js";
|
|
25
25
|
import { GetLocalTimeZone } from "./contextTokens.js";
|
|
@@ -115,6 +115,39 @@ export const AllMetadataArrays = [
|
|
|
115
115
|
{ key: 'AllLibraries', class: LibraryInfo },
|
|
116
116
|
{ key: 'AllExplorerNavigationItems', class: ExplorerNavigationItem }
|
|
117
117
|
];
|
|
118
|
+
/**
|
|
119
|
+
* Produces a canonical, order- and case-insensitive key for a requested `Fields` list, suitable
|
|
120
|
+
* for keying memoized row projections and wire-serialization caches. Returns `''` when no field
|
|
121
|
+
* list is provided.
|
|
122
|
+
*/
|
|
123
|
+
export function CanonicalFieldsKey(fields) {
|
|
124
|
+
if (!fields || fields.length === 0) {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
const unique = new Set();
|
|
128
|
+
for (const f of fields) {
|
|
129
|
+
const normalized = f.trim().toLowerCase();
|
|
130
|
+
if (normalized.length > 0) {
|
|
131
|
+
unique.add(normalized);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (unique.size === 0) {
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
return Array.from(unique).sort().join(',');
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Memoizes frozen subset-projected row objects per `(sourceRow, canonicalFieldsKey)` when
|
|
141
|
+
* `ProjectRowsToFields` runs with `{ PreserveFrozen: true }` on frozen L1/cache rows. Weakly
|
|
142
|
+
* keyed on the source row so entries are automatically garbage-collected when cache slots evict.
|
|
143
|
+
*/
|
|
144
|
+
const FrozenProjectedRowCache = new WeakMap();
|
|
145
|
+
/**
|
|
146
|
+
* Memoizes the entire frozen projected result array per `(frozenSourceArray, canonicalFieldsKey)`
|
|
147
|
+
* when `ProjectRowsToFields` runs with `{ PreserveFrozen: true }` on a frozen cached array.
|
|
148
|
+
* Turns repeat N-row subset projections into a single O(1) WeakMap lookup.
|
|
149
|
+
*/
|
|
150
|
+
const FrozenProjectedArrayCache = new WeakMap();
|
|
118
151
|
/**
|
|
119
152
|
* Projects plain-object rows down to a caller-requested field subset, matching
|
|
120
153
|
* field names case-insensitively (and ignoring surrounding whitespace).
|
|
@@ -131,11 +164,22 @@ export const AllMetadataArrays = [
|
|
|
131
164
|
*
|
|
132
165
|
* @param rows - Plain-object result rows (NOT BaseEntity objects)
|
|
133
166
|
* @param requestedFields - The caller's original Fields list, or null for "all fields"
|
|
167
|
+
* @param options - Optional mutability/freeze preservation controls
|
|
134
168
|
*/
|
|
135
|
-
export function ProjectRowsToFields(rows, requestedFields) {
|
|
169
|
+
export function ProjectRowsToFields(rows, requestedFields, options) {
|
|
136
170
|
if (!requestedFields || requestedFields.length === 0 || !rows || rows.length === 0) {
|
|
137
171
|
return rows;
|
|
138
172
|
}
|
|
173
|
+
const preserveFrozen = Boolean(options?.PreserveFrozen);
|
|
174
|
+
const rowsAreFrozen = Object.isFrozen(rows);
|
|
175
|
+
const canonicalKey = preserveFrozen ? CanonicalFieldsKey(requestedFields) : '';
|
|
176
|
+
// O(1) array-level hit for repeat subset projections over the same frozen cached array.
|
|
177
|
+
if (preserveFrozen && rowsAreFrozen && canonicalKey.length > 0) {
|
|
178
|
+
const cachedArray = FrozenProjectedArrayCache.get(rows)?.get(canonicalKey);
|
|
179
|
+
if (cachedArray) {
|
|
180
|
+
return cachedArray;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
139
183
|
const requestedFieldSet = new Set(requestedFields.map(f => f.trim().toLowerCase()));
|
|
140
184
|
// No-op probe: SQL result rows are uniform (same SELECT list), so if every key of
|
|
141
185
|
// the first row is requested, the projection would copy every row unchanged —
|
|
@@ -155,18 +199,28 @@ export function ProjectRowsToFields(rows, requestedFields) {
|
|
|
155
199
|
// to yield a per-caller row set the caller may mutate, and full coverage is not a
|
|
156
200
|
// narrower promise than partial coverage — it just happens to project to the same
|
|
157
201
|
// shape. Frozen input means `rows` is the cache's shared array, so returning it here
|
|
158
|
-
// would quietly hand a Fields caller immutable rows and break that contract
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
if (!Object.isFrozen(rows)) {
|
|
202
|
+
// would quietly hand a Fields caller immutable rows and break that contract unless
|
|
203
|
+
// the caller explicitly opts into `PreserveFrozen: true` (read-only wire transport).
|
|
204
|
+
if (preserveFrozen || !rowsAreFrozen) {
|
|
162
205
|
return rows;
|
|
163
206
|
}
|
|
164
207
|
}
|
|
165
208
|
}
|
|
166
209
|
// Cache lowercase key→keep decisions across rows to avoid repeated allocations
|
|
167
210
|
const keyCache = new Map();
|
|
168
|
-
|
|
211
|
+
const projected = rows.map((row) => {
|
|
169
212
|
const source = row;
|
|
213
|
+
const canMemoizeFrozen = preserveFrozen &&
|
|
214
|
+
canonicalKey.length > 0 &&
|
|
215
|
+
source !== null &&
|
|
216
|
+
typeof source === 'object' &&
|
|
217
|
+
Object.isFrozen(source);
|
|
218
|
+
if (canMemoizeFrozen) {
|
|
219
|
+
const cachedProjected = FrozenProjectedRowCache.get(source)?.get(canonicalKey);
|
|
220
|
+
if (cachedProjected) {
|
|
221
|
+
return cachedProjected;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
170
224
|
const filtered = {};
|
|
171
225
|
for (const key of Object.keys(source)) {
|
|
172
226
|
let keep = keyCache.get(key);
|
|
@@ -178,8 +232,27 @@ export function ProjectRowsToFields(rows, requestedFields) {
|
|
|
178
232
|
filtered[key] = source[key];
|
|
179
233
|
}
|
|
180
234
|
}
|
|
235
|
+
if (canMemoizeFrozen) {
|
|
236
|
+
Object.freeze(filtered);
|
|
237
|
+
let fieldMap = FrozenProjectedRowCache.get(source);
|
|
238
|
+
if (!fieldMap) {
|
|
239
|
+
fieldMap = new Map();
|
|
240
|
+
FrozenProjectedRowCache.set(source, fieldMap);
|
|
241
|
+
}
|
|
242
|
+
fieldMap.set(canonicalKey, filtered);
|
|
243
|
+
}
|
|
181
244
|
return filtered;
|
|
182
245
|
});
|
|
246
|
+
if (preserveFrozen && rowsAreFrozen && canonicalKey.length > 0) {
|
|
247
|
+
Object.freeze(projected);
|
|
248
|
+
let arrayMap = FrozenProjectedArrayCache.get(rows);
|
|
249
|
+
if (!arrayMap) {
|
|
250
|
+
arrayMap = new Map();
|
|
251
|
+
FrozenProjectedArrayCache.set(rows, arrayMap);
|
|
252
|
+
}
|
|
253
|
+
arrayMap.set(canonicalKey, projected);
|
|
254
|
+
}
|
|
255
|
+
return projected;
|
|
183
256
|
}
|
|
184
257
|
/**
|
|
185
258
|
* Base class for all metadata providers in MemberJunction.
|
|
@@ -249,6 +322,14 @@ export class ProviderBase {
|
|
|
249
322
|
*/
|
|
250
323
|
this._inflightViews = new Map();
|
|
251
324
|
this._lingerInvalidationWired = false;
|
|
325
|
+
/**
|
|
326
|
+
* Lazily registers this instance (once per provider instance) for write-invalidation
|
|
327
|
+
* of in-flight/lingered RunView entries touching a written entity. Deleting an IN-FLIGHT
|
|
328
|
+
* entry is deliberate: late joiners must not share a query that may have read pre-commit
|
|
329
|
+
* data; the original caller still gets its own result, and the orphaned promise's stash
|
|
330
|
+
* step no-ops safely.
|
|
331
|
+
*/
|
|
332
|
+
this._invalidationTargetRef = null;
|
|
252
333
|
/**
|
|
253
334
|
* Per-entity monotonic mutation counter incremented whenever an entity receives a
|
|
254
335
|
* BaseEntity save/delete/remote-invalidate or an explicit {@link InvalidateRunViewDedupCache}
|
|
@@ -325,6 +406,9 @@ export class ProviderBase {
|
|
|
325
406
|
this._lastRemoteTimestampReadReached = true;
|
|
326
407
|
/** Guard for {@link logMetadataSnapshotDisabledOnce}. */
|
|
327
408
|
this._metadataSnapshotSkipLogged = false;
|
|
409
|
+
this._metadataSaveTimer = null;
|
|
410
|
+
this._inFlightMetadataSave = null;
|
|
411
|
+
this._hasPendingMetadataSaveWhileInFlight = false;
|
|
328
412
|
}
|
|
329
413
|
/**
|
|
330
414
|
* Whether this provider can execute a multi-record unit of work atomically, in-process.
|
|
@@ -552,12 +636,26 @@ export class ProviderBase {
|
|
|
552
636
|
return results;
|
|
553
637
|
}
|
|
554
638
|
/**
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* entry is deliberate: late joiners must not share a query that may have read pre-commit
|
|
558
|
-
* data; the original caller still gets its own result, and the orphaned promise's stash
|
|
559
|
-
* step no-ops safely.
|
|
639
|
+
* Number of live/uncollected `ProviderBase` instances currently registered for in-flight
|
|
640
|
+
* view invalidation callbacks.
|
|
560
641
|
*/
|
|
642
|
+
static get ActiveInvalidationTargetCount() {
|
|
643
|
+
return ProviderBase._invalidationTargets.size;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Immediately removes this provider instance from the global in-flight invalidation target set
|
|
647
|
+
* and clears per-instance mutation state. Call on short-lived per-request server providers
|
|
648
|
+
* when the HTTP response closes so `_invalidationTargets` does not accumulate thousands of
|
|
649
|
+
* `WeakRef`s between major garbage collections.
|
|
650
|
+
*/
|
|
651
|
+
DetachInvalidationListeners() {
|
|
652
|
+
if (this._invalidationTargetRef) {
|
|
653
|
+
ProviderBase._invalidationTargets.delete(this._invalidationTargetRef);
|
|
654
|
+
this._invalidationTargetRef = null;
|
|
655
|
+
}
|
|
656
|
+
this._lingerInvalidationWired = false;
|
|
657
|
+
this._entityMutationVersions.clear();
|
|
658
|
+
}
|
|
561
659
|
ensureInflightViewInvalidation() {
|
|
562
660
|
// Deliberately ABOVE the per-instance guard: the static wiring is re-checked on every call,
|
|
563
661
|
// not just the first. A long-lived provider (Explorer's client provider, MJServer's system
|
|
@@ -569,7 +667,9 @@ export class ProviderBase {
|
|
|
569
667
|
return;
|
|
570
668
|
}
|
|
571
669
|
this._lingerInvalidationWired = true;
|
|
572
|
-
|
|
670
|
+
const ref = new WeakRef(this);
|
|
671
|
+
this._invalidationTargetRef = ref;
|
|
672
|
+
ProviderBase._invalidationTargets.add(ref);
|
|
573
673
|
}
|
|
574
674
|
/**
|
|
575
675
|
* Returns the current monotonic mutation version for `entityName` (case-insensitive).
|
|
@@ -717,6 +817,9 @@ export class ProviderBase {
|
|
|
717
817
|
names.add(n);
|
|
718
818
|
}
|
|
719
819
|
}
|
|
820
|
+
for (const skipped of this.skippedMetadataEntityNames(dataset.Results ?? [])) {
|
|
821
|
+
names.delete(skipped);
|
|
822
|
+
}
|
|
720
823
|
if (names.size === 0) {
|
|
721
824
|
return; // a failed/empty load must not erase a previously recorded set
|
|
722
825
|
}
|
|
@@ -732,6 +835,93 @@ export class ProviderBase {
|
|
|
732
835
|
}));
|
|
733
836
|
this.ensureInflightViewInvalidation();
|
|
734
837
|
}
|
|
838
|
+
/**
|
|
839
|
+
* The MJ_Metadata item codes that hold the saved-query metadata: the saved-query family (see
|
|
840
|
+
* {@link PartialRefreshMetadataItemCodes}) and the SQL dialects. They are read only when the
|
|
841
|
+
* provider is configured with {@link ProviderConfigDataBase.LoadQueryMetadata}.
|
|
842
|
+
*/
|
|
843
|
+
static get QueryMetadataItemCodes() {
|
|
844
|
+
return [...ProviderBase._queryFamilyItemCodes, 'SQLDialects'];
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Whether this provider loads the saved-query metadata into its metadata object (see
|
|
848
|
+
* {@link ProviderConfigDataBase.LoadQueryMetadata}). False unless the configuration says true.
|
|
849
|
+
* A provider that adopted the global provider's metadata reports the global provider's
|
|
850
|
+
* setting instead, since that is what decided whether the adopted metadata holds queries.
|
|
851
|
+
*/
|
|
852
|
+
get LoadsQueryMetadata() {
|
|
853
|
+
return this._adoptedLoadsQueryMetadata ?? this._ConfigData?.LoadQueryMetadata === true;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* The item filters every read of the MJ_Metadata dataset uses — the data, its status, and the
|
|
857
|
+
* local dataset cache — so all of them describe the same row set. Null when every item is read.
|
|
858
|
+
* Otherwise each item this provider does not load gets a `1=0` filter: the server runs no SQL
|
|
859
|
+
* for it, and its status is constant, so writes to it never make the metadata look stale.
|
|
860
|
+
*/
|
|
861
|
+
get MetadataDatasetItemFilters() {
|
|
862
|
+
if (this.LoadsQueryMetadata) {
|
|
863
|
+
return null;
|
|
864
|
+
}
|
|
865
|
+
return ProviderBase.QueryMetadataItemCodes.map(code => ({ ItemCode: code, Filter: '1=0' }));
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* The MJ_Metadata item codes THIS provider builds its metadata from: {@link MetadataBuildItemCodes}
|
|
869
|
+
* without the items it does not read (see {@link MetadataDatasetItemFilters}). A change only to
|
|
870
|
+
* the others needs no reload, as for any item the build never reads.
|
|
871
|
+
*/
|
|
872
|
+
get BuiltMetadataItemCodes() {
|
|
873
|
+
if (this.LoadsQueryMetadata) {
|
|
874
|
+
return ProviderBase.MetadataBuildItemCodes;
|
|
875
|
+
}
|
|
876
|
+
const built = new Set(ProviderBase.MetadataBuildItemCodes);
|
|
877
|
+
for (const code of ProviderBase.QueryMetadataItemCodes) {
|
|
878
|
+
built.delete(code);
|
|
879
|
+
}
|
|
880
|
+
return built;
|
|
881
|
+
}
|
|
882
|
+
/**
|
|
883
|
+
* Empties the query-metadata arrays of `metadata` when this provider does not load them. A stored
|
|
884
|
+
* snapshot written by a process that did load them would otherwise hold those rows in memory for
|
|
885
|
+
* the life of this process, behind getters that return nothing.
|
|
886
|
+
*/
|
|
887
|
+
dropUnloadedQueryMetadata(metadata) {
|
|
888
|
+
if (this.LoadsQueryMetadata) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
metadata.AllQueryCategories = [];
|
|
892
|
+
metadata.AllQueries = [];
|
|
893
|
+
metadata.AllQueryFields = [];
|
|
894
|
+
metadata.AllQueryPermissions = [];
|
|
895
|
+
metadata.AllQueryEntities = [];
|
|
896
|
+
metadata.AllQueryParameters = [];
|
|
897
|
+
metadata.AllQueryDependencies = [];
|
|
898
|
+
metadata.AllSQLDialects = [];
|
|
899
|
+
metadata.AllQuerySQLs = [];
|
|
900
|
+
}
|
|
901
|
+
/** Whether `code` is an MJ_Metadata item this provider does not read (see {@link MetadataDatasetItemFilters}). */
|
|
902
|
+
isSkippedMetadataItem(code) {
|
|
903
|
+
return !!code && !this.LoadsQueryMetadata && ProviderBase.QueryMetadataItemCodes.includes(code);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Lowercased names of the entities that back only items this provider does not read. A write to
|
|
907
|
+
* one of them cannot change this provider's metadata, so they are left out of the membership set
|
|
908
|
+
* — otherwise each such write would schedule a refresh that finds no timestamp moved and falls
|
|
909
|
+
* back to a full reload.
|
|
910
|
+
*/
|
|
911
|
+
skippedMetadataEntityNames(items) {
|
|
912
|
+
const skipped = new Set();
|
|
913
|
+
const read = new Set();
|
|
914
|
+
for (const item of items) {
|
|
915
|
+
const name = item.EntityName?.trim().toLowerCase();
|
|
916
|
+
if (name) {
|
|
917
|
+
(this.isSkippedMetadataItem(item.Code) ? skipped : read).add(name);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
for (const name of read) {
|
|
921
|
+
skipped.delete(name);
|
|
922
|
+
}
|
|
923
|
+
return skipped;
|
|
924
|
+
}
|
|
735
925
|
/**
|
|
736
926
|
* Result of {@link SweepMetadataAgainstDatabase}.
|
|
737
927
|
*/
|
|
@@ -1333,29 +1523,30 @@ export class ProviderBase {
|
|
|
1333
1523
|
// BypassCache skips this entirely — used by maintenance actions that need
|
|
1334
1524
|
// to see the true DB state after direct SQL inserts.
|
|
1335
1525
|
const preResult = await this.PreRunView(params, contextUser);
|
|
1526
|
+
const effectiveParams = preResult.effectiveParams ?? params;
|
|
1336
1527
|
if (preResult.cachedResult) {
|
|
1337
1528
|
// Cache hit — transform and return directly
|
|
1338
|
-
LogStatusEx({ message: ` ✅ [Cache HIT] RunView "${
|
|
1339
|
-
await this.TransformSimpleObjectToEntityObject(
|
|
1340
|
-
await this.ApplyPostRunViewHooksToCacheHit(
|
|
1529
|
+
LogStatusEx({ message: ` ✅ [Cache HIT] RunView "${effectiveParams.EntityName || effectiveParams.ViewName || 'unknown'}" — ${preResult.cachedResult.Results?.length ?? 0} rows from cache, no DB query`, verboseOnly: true });
|
|
1530
|
+
await this.TransformSimpleObjectToEntityObject(effectiveParams, preResult.cachedResult, contextUser);
|
|
1531
|
+
await this.ApplyPostRunViewHooksToCacheHit(effectiveParams, preResult.cachedResult, contextUser);
|
|
1341
1532
|
TelemetryManager.Instance.EndEvent(preResult.telemetryEventId, {
|
|
1342
1533
|
cacheHit: true,
|
|
1343
1534
|
cacheStatus: preResult.cacheStatus,
|
|
1344
1535
|
resultCount: preResult.cachedResult.Results?.length ?? 0
|
|
1345
1536
|
});
|
|
1346
|
-
if (
|
|
1347
|
-
preResult.cachedResult.Unsubscribe = LocalCacheManager.Instance.RegisterChangeCallback(preResult.fingerprint,
|
|
1537
|
+
if (effectiveParams.OnDataChanged && preResult.fingerprint) {
|
|
1538
|
+
preResult.cachedResult.Unsubscribe = LocalCacheManager.Instance.RegisterChangeCallback(preResult.fingerprint, effectiveParams.OnDataChanged);
|
|
1348
1539
|
}
|
|
1349
|
-
ProviderBase.clearSkippedTotalRowCount(
|
|
1540
|
+
ProviderBase.clearSkippedTotalRowCount(effectiveParams, preResult.cachedResult);
|
|
1350
1541
|
return preResult.cachedResult;
|
|
1351
1542
|
}
|
|
1352
1543
|
// Cache miss — execute query, then post-process (stores in cache)
|
|
1353
|
-
LogStatusEx({ message: ` 🔍 [Cache MISS] RunView "${
|
|
1354
|
-
const result = await this.InternalRunView(
|
|
1544
|
+
LogStatusEx({ message: ` 🔍 [Cache MISS] RunView "${effectiveParams.EntityName || effectiveParams.ViewName || 'unknown'}" — querying database`, verboseOnly: true });
|
|
1545
|
+
const result = await this.InternalRunView(effectiveParams, contextUser);
|
|
1355
1546
|
// PostRunView copies any hook-supplied replacement onto `result` in place, so this
|
|
1356
1547
|
// reference reflects the hook chain's output.
|
|
1357
|
-
await this.PostRunView(result,
|
|
1358
|
-
ProviderBase.clearSkippedTotalRowCount(
|
|
1548
|
+
await this.PostRunView(result, effectiveParams, preResult, contextUser);
|
|
1549
|
+
ProviderBase.clearSkippedTotalRowCount(effectiveParams, result);
|
|
1359
1550
|
return result;
|
|
1360
1551
|
}
|
|
1361
1552
|
// Delegate to RunViews, which uses the smart cache check (lightweight maxUpdatedAt +
|
|
@@ -2507,7 +2698,10 @@ export class ProviderBase {
|
|
|
2507
2698
|
* `resolvable` is true.
|
|
2508
2699
|
*
|
|
2509
2700
|
* The BASE implementation resolves from the metadata `Queries` cache and enforces the
|
|
2510
|
-
* ROLES-ONLY `QueryInfo.UserCanRun` — the strongest check available at this layer.
|
|
2701
|
+
* ROLES-ONLY `QueryInfo.UserCanRun` — the strongest check available at this layer. That cache
|
|
2702
|
+
* is loaded only when the provider is configured with `LoadQueryMetadata`; otherwise every
|
|
2703
|
+
* request is unresolvable here, so a provider that executes or caches saved queries overrides
|
|
2704
|
+
* this to resolve from `QueryEngine`.
|
|
2511
2705
|
* Providers with richer query metadata MUST override this to enforce the SAME authorization
|
|
2512
2706
|
* their miss path enforces (`GenericDatabaseProvider` overrides with
|
|
2513
2707
|
* `MJQueryEntityExtended.UserCanRun`, which adds entity CanRead + recursive composition
|
|
@@ -2517,6 +2711,9 @@ export class ProviderBase {
|
|
|
2517
2711
|
* the miss path also checked entity read permissions).
|
|
2518
2712
|
*/
|
|
2519
2713
|
ResolveQueryCacheAuthorization(params, user) {
|
|
2714
|
+
if (!this.LoadsQueryMetadata) {
|
|
2715
|
+
return { resolvable: false, authorized: false };
|
|
2716
|
+
}
|
|
2520
2717
|
const requestedPath = params.CategoryPath?.trim().toLowerCase();
|
|
2521
2718
|
const qInfo = this.Queries.find(q => (params.QueryID && UUIDsEqual(q.ID, params.QueryID))
|
|
2522
2719
|
|| (!params.QueryID && params.QueryName
|
|
@@ -3541,6 +3738,7 @@ export class ProviderBase {
|
|
|
3541
3738
|
// PostRunView to project cache-miss DB results back to the caller's shape
|
|
3542
3739
|
callerRequestedFields: callerRequestedFieldsForPost,
|
|
3543
3740
|
populateCache: willPopulateCache,
|
|
3741
|
+
effectiveParams: params,
|
|
3544
3742
|
};
|
|
3545
3743
|
}
|
|
3546
3744
|
/**
|
|
@@ -4373,7 +4571,7 @@ export class ProviderBase {
|
|
|
4373
4571
|
async RunPreRunViewHooks(params, contextUser) {
|
|
4374
4572
|
const hooks = GetDataHooks('PreRunView');
|
|
4375
4573
|
for (const hook of hooks) {
|
|
4376
|
-
params = await hook(params, contextUser);
|
|
4574
|
+
params = await hook(params, contextUser, this);
|
|
4377
4575
|
}
|
|
4378
4576
|
return params;
|
|
4379
4577
|
}
|
|
@@ -4391,7 +4589,7 @@ export class ProviderBase {
|
|
|
4391
4589
|
async RunPostRunViewHooks(params, result, contextUser) {
|
|
4392
4590
|
const hooks = GetDataHooks('PostRunView');
|
|
4393
4591
|
for (const hook of hooks) {
|
|
4394
|
-
result = await hook(params, result, contextUser);
|
|
4592
|
+
result = await hook(params, result, contextUser, this);
|
|
4395
4593
|
}
|
|
4396
4594
|
return result;
|
|
4397
4595
|
}
|
|
@@ -4539,6 +4737,10 @@ export class ProviderBase {
|
|
|
4539
4737
|
// wasted `Fields` widening and futile cache lookups.
|
|
4540
4738
|
if (entity.ExternalDataSourceID)
|
|
4541
4739
|
return false;
|
|
4740
|
+
// PostRunView-protected entities enforce per-caller ACL filtering inside PostRunView hooks
|
|
4741
|
+
// from sibling permission tables whose mutations never change this entity's table timestamps.
|
|
4742
|
+
if (IsPostRunViewProtectedEntity(entity.Name))
|
|
4743
|
+
return false;
|
|
4542
4744
|
return entity.TrustServerCacheCompletely !== false;
|
|
4543
4745
|
}
|
|
4544
4746
|
shouldAutoCache(params, result, contextUser) {
|
|
@@ -5054,8 +5256,23 @@ export class ProviderBase {
|
|
|
5054
5256
|
* @param data - Configuration including schema filters and connection info
|
|
5055
5257
|
* @returns True if configuration was successful
|
|
5056
5258
|
*/
|
|
5259
|
+
/**
|
|
5260
|
+
* Synchronously configures this provider from an already-initialized global `Metadata.Provider`
|
|
5261
|
+
* without allocating promises or awaiting async cache initialization. Returns `false` if global
|
|
5262
|
+
* metadata or `LocalCacheManager` has not finished initializing yet.
|
|
5263
|
+
*/
|
|
5264
|
+
ConfigureFromGlobalMetadataSync(data) {
|
|
5265
|
+
if (!Metadata.Provider || data.IgnoreExistingMetadata || this._refresh || !LocalCacheManager.Instance.IsInitialized) { // global-provider-ok: bootstrap checks for an existing global registration
|
|
5266
|
+
return false;
|
|
5267
|
+
}
|
|
5268
|
+
this._ConfigData = data;
|
|
5269
|
+
this._adoptedLoadsQueryMetadata = undefined;
|
|
5270
|
+
this._configLoadedFromServer = false;
|
|
5271
|
+
return this.CopyMetadataFromGlobalProvider();
|
|
5272
|
+
}
|
|
5057
5273
|
async Config(data, providerToUse) {
|
|
5058
5274
|
this._ConfigData = data;
|
|
5275
|
+
this._adoptedLoadsQueryMetadata = undefined;
|
|
5059
5276
|
// Describes THIS Config only: a flag left by an earlier Refresh() must not make the
|
|
5060
5277
|
// pre-validation that follows a Config which loaded nothing skip its check.
|
|
5061
5278
|
this._configLoadedFromServer = false;
|
|
@@ -5311,7 +5528,7 @@ export class ProviderBase {
|
|
|
5311
5528
|
const rollup = norm(ProviderBase._allMetadataTypeName);
|
|
5312
5529
|
const prevLocal = this._latestLocalMetadataTimestamps ?? [];
|
|
5313
5530
|
const datasetItems = this._metadataDatasetItems;
|
|
5314
|
-
const built =
|
|
5531
|
+
const built = this.BuiltMetadataItemCodes;
|
|
5315
5532
|
const resRecord = res;
|
|
5316
5533
|
let hasMismatch = false;
|
|
5317
5534
|
const reconciled = [];
|
|
@@ -5396,7 +5613,7 @@ export class ProviderBase {
|
|
|
5396
5613
|
if (!hasMismatch) {
|
|
5397
5614
|
return remote;
|
|
5398
5615
|
}
|
|
5399
|
-
this.ClearDatasetCache(ProviderBase._mjMetadataDatasetName).catch(() => { });
|
|
5616
|
+
this.ClearDatasetCache(ProviderBase._mjMetadataDatasetName, this.MetadataDatasetItemFilters).catch(() => { });
|
|
5400
5617
|
const remoteRollup = remote.find(r => norm(r.Type) === rollup);
|
|
5401
5618
|
if (remoteRollup) {
|
|
5402
5619
|
const priorRollup = prevLocal.find(m => norm(m.Type) === rollup);
|
|
@@ -5437,7 +5654,7 @@ export class ProviderBase {
|
|
|
5437
5654
|
return { Kind: 'full', Reason: 'the metadata timestamps are not known' };
|
|
5438
5655
|
}
|
|
5439
5656
|
const family = new Set(ProviderBase.PartialRefreshMetadataItemCodes);
|
|
5440
|
-
const built =
|
|
5657
|
+
const built = this.BuiltMetadataItemCodes;
|
|
5441
5658
|
const norm = (v) => (v ?? '').trim().toLowerCase();
|
|
5442
5659
|
const rollup = norm(ProviderBase._allMetadataTypeName);
|
|
5443
5660
|
let anyItemChanged = false;
|
|
@@ -5520,8 +5737,9 @@ export class ProviderBase {
|
|
|
5520
5737
|
}
|
|
5521
5738
|
try {
|
|
5522
5739
|
const keep = new Set(codes);
|
|
5740
|
+
// Items this provider does not load stay unread even when they are in the family.
|
|
5523
5741
|
const skipOthers = items
|
|
5524
|
-
.filter(item => !keep.has(item.Code))
|
|
5742
|
+
.filter(item => !keep.has(item.Code) || this.isSkippedMetadataItem(item.Code))
|
|
5525
5743
|
.map(item => ({ ItemCode: item.Code, Filter: '1=0' }));
|
|
5526
5744
|
const start = Date.now();
|
|
5527
5745
|
const d = await this.GetDatasetByName(ProviderBase._mjMetadataDatasetName, skipOthers, this.CurrentUser, providerToUse, true);
|
|
@@ -5785,6 +6003,9 @@ export class ProviderBase {
|
|
|
5785
6003
|
else {
|
|
5786
6004
|
this.UpdateLocalMetadata(adopted);
|
|
5787
6005
|
}
|
|
6006
|
+
if (globalProvider instanceof ProviderBase) {
|
|
6007
|
+
this._adoptedLoadsQueryMetadata = globalProvider.LoadsQueryMetadata;
|
|
6008
|
+
}
|
|
5788
6009
|
return true;
|
|
5789
6010
|
}
|
|
5790
6011
|
return false;
|
|
@@ -5882,9 +6103,10 @@ export class ProviderBase {
|
|
|
5882
6103
|
// NOTE: Schema filters (IncludeSchemas/ExcludeSchemas) are for CodeGen only, not for runtime
|
|
5883
6104
|
// metadata loading. We always load all schemas — there are no sys/staging entities in metadata anyway.
|
|
5884
6105
|
const mutationSeqAtStart = this._metadataMemberMutationSeq;
|
|
6106
|
+
const itemFilters = this.MetadataDatasetItemFilters;
|
|
5885
6107
|
// Get the dataset and cache it for anyone else who wants to use it
|
|
5886
6108
|
// When forceRefresh is true (from a hard Refresh() call), bypass LocalCacheManager
|
|
5887
|
-
const d = await this.GetDatasetByName(ProviderBase._mjMetadataDatasetName,
|
|
6109
|
+
const d = await this.GetDatasetByName(ProviderBase._mjMetadataDatasetName, itemFilters, this.CurrentUser, providerToUse, forceRefresh);
|
|
5888
6110
|
// A dataset with no entities is a failed read, whatever its Success flag says: there
|
|
5889
6111
|
// is no deployment in which MJ_Metadata legitimately holds zero entities. Returning
|
|
5890
6112
|
// undefined here keeps the metadata already loaded (Config() treats undefined as
|
|
@@ -5909,16 +6131,15 @@ export class ProviderBase {
|
|
|
5909
6131
|
this._metadataMemberMutationSeq !== mutationSeqAtStart ||
|
|
5910
6132
|
this.hasDatasetRemoteRowCountMismatch(d);
|
|
5911
6133
|
if (!mutatedDuringLoad) {
|
|
5912
|
-
await this.CacheDataset(ProviderBase._mjMetadataDatasetName,
|
|
6134
|
+
await this.CacheDataset(ProviderBase._mjMetadataDatasetName, itemFilters, d);
|
|
5913
6135
|
}
|
|
5914
6136
|
else {
|
|
5915
|
-
await this.ClearDatasetCache(ProviderBase._mjMetadataDatasetName);
|
|
5916
|
-
}
|
|
5917
|
-
// got the results, let's build our response in the format we need
|
|
5918
|
-
const simpleMetadata = {};
|
|
5919
|
-
for (let r of d.Results) {
|
|
5920
|
-
simpleMetadata[r.Code] = r.Results;
|
|
6137
|
+
await this.ClearDatasetCache(ProviderBase._mjMetadataDatasetName, itemFilters);
|
|
5921
6138
|
}
|
|
6139
|
+
// got the results, let's build our response in the format we need. The assembly
|
|
6140
|
+
// below attaches child collections to rows, so it works on copies of those rows:
|
|
6141
|
+
// the dataset's own rows stay exactly as read (see metadataAssemblyInput).
|
|
6142
|
+
const simpleMetadata = ProviderBase.metadataAssemblyInput(d);
|
|
5922
6143
|
// Post Process Entities because there's some special handling of the sub-objects
|
|
5923
6144
|
simpleMetadata.AllEntities = this.PostProcessEntityMetadata(simpleMetadata.Entities, simpleMetadata.EntityFields, simpleMetadata.EntityFieldValues, simpleMetadata.EntityPermissions, simpleMetadata.EntityRelationships, simpleMetadata.EntitySettings, simpleMetadata.EntityOrganicKeys, simpleMetadata.EntityOrganicKeyRelatedEntities, simpleMetadata.EntityFieldPermissions, simpleMetadata.EntityAlternateBaseViews, simpleMetadata.EntityUniqueKeys);
|
|
5924
6145
|
// Post Process the Applications, because we want to handle the sub-objects properly.
|
|
@@ -5945,6 +6166,31 @@ export class ProviderBase {
|
|
|
5945
6166
|
this._lastMetadataLoadError = e instanceof Error ? e : new Error(String(e));
|
|
5946
6167
|
}
|
|
5947
6168
|
}
|
|
6169
|
+
/**
|
|
6170
|
+
* The MJ_Metadata item codes whose rows the metadata assembly writes to: entity rows get their
|
|
6171
|
+
* fields, permissions, relationships, settings, organic keys, alternate views and unique keys;
|
|
6172
|
+
* field rows their values and field permissions; organic keys their related entities;
|
|
6173
|
+
* applications their entities and settings. The entity array is also sorted.
|
|
6174
|
+
*/
|
|
6175
|
+
static { this._assemblyWrittenItemCodes = new Set(['Entities', 'EntityFields', 'EntityOrganicKeys', 'Applications']); }
|
|
6176
|
+
/**
|
|
6177
|
+
* The MJ_Metadata rows keyed by item code, as {@link GetAllMetadata} assembles them: the items
|
|
6178
|
+
* the assembly writes to are shallow copies (a new array of new row objects), the rest are the
|
|
6179
|
+
* dataset's own arrays. The dataset's rows are the ones the dataset cache holds and serves to
|
|
6180
|
+
* every later reader — on a server, every client's metadata request — so writing child
|
|
6181
|
+
* collections onto them would send each entity's fields, permissions and relationships a second
|
|
6182
|
+
* time, nested inside the entity rows, with every response.
|
|
6183
|
+
*/
|
|
6184
|
+
static metadataAssemblyInput(dataset) {
|
|
6185
|
+
const input = {};
|
|
6186
|
+
for (const item of dataset.Results ?? []) {
|
|
6187
|
+
const rows = Array.isArray(item.Results) ? item.Results : [];
|
|
6188
|
+
input[item.Code] = ProviderBase._assemblyWrittenItemCodes.has(item.Code)
|
|
6189
|
+
? rows.map(row => ({ ...row }))
|
|
6190
|
+
: rows;
|
|
6191
|
+
}
|
|
6192
|
+
return input;
|
|
6193
|
+
}
|
|
5948
6194
|
/** Logs a failed metadata download and keeps it for {@link LastMetadataLoadError}. */
|
|
5949
6195
|
recordMetadataLoadFailure(error) {
|
|
5950
6196
|
LogError(error.message);
|
|
@@ -5968,7 +6214,12 @@ export class ProviderBase {
|
|
|
5968
6214
|
// SaveLocalMetadataToStorage avoids a multi-MB JSON.stringify + gzip + IDB
|
|
5969
6215
|
// write pass on the main thread during startup.
|
|
5970
6216
|
if (previousUserJson !== JSON.stringify(user)) {
|
|
5971
|
-
|
|
6217
|
+
if (Object.prototype.hasOwnProperty.call(this, 'SaveLocalMetadataToStorage')) {
|
|
6218
|
+
void this.SaveLocalMetadataToStorage();
|
|
6219
|
+
}
|
|
6220
|
+
else {
|
|
6221
|
+
this.ScheduleSaveLocalMetadataToStorage();
|
|
6222
|
+
}
|
|
5972
6223
|
}
|
|
5973
6224
|
return user;
|
|
5974
6225
|
}
|
|
@@ -6169,41 +6420,87 @@ export class ProviderBase {
|
|
|
6169
6420
|
get AuthorizationRoles() {
|
|
6170
6421
|
return this._localMetadata.AllAuthorizationRoles;
|
|
6171
6422
|
}
|
|
6172
|
-
/** @
|
|
6423
|
+
/** Whether {@link deprecatedQueryMetadata} has logged its warning in this process. */
|
|
6424
|
+
static { this._queryMetadataWarningLogged = false; }
|
|
6425
|
+
/**
|
|
6426
|
+
* What a deprecated query-metadata getter returns: the loaded array when the provider loads query
|
|
6427
|
+
* metadata, otherwise an empty array and a warning, logged once per process, naming the
|
|
6428
|
+
* replacement.
|
|
6429
|
+
*/
|
|
6430
|
+
deprecatedQueryMetadata(items, getterName) {
|
|
6431
|
+
if (this.LoadsQueryMetadata) {
|
|
6432
|
+
return items;
|
|
6433
|
+
}
|
|
6434
|
+
if (!ProviderBase._queryMetadataWarningLogged) {
|
|
6435
|
+
ProviderBase._queryMetadataWarningLogged = true;
|
|
6436
|
+
LogWarning(`Metadata.${getterName} and the other query-metadata getters are empty: query metadata is not loaded into the ` +
|
|
6437
|
+
`metadata object. Use QueryEngine from @memberjunction/core-entities, or set LoadQueryMetadata ` +
|
|
6438
|
+
`(databaseSettings.loadQueryMetadata on MJAPI) until the code is migrated.`, 'Metadata');
|
|
6439
|
+
}
|
|
6440
|
+
return [];
|
|
6441
|
+
}
|
|
6442
|
+
/**
|
|
6443
|
+
* @deprecated Use `QueryEngine.Instance.Queries` from `@memberjunction/core-entities`. Empty unless the
|
|
6444
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6445
|
+
*/
|
|
6173
6446
|
get Queries() {
|
|
6174
|
-
return this._localMetadata.AllQueries;
|
|
6447
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueries, 'Queries');
|
|
6175
6448
|
}
|
|
6176
|
-
/**
|
|
6449
|
+
/**
|
|
6450
|
+
* @deprecated Use `QueryEngine.Instance.Categories` from `@memberjunction/core-entities`. Empty unless the
|
|
6451
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6452
|
+
*/
|
|
6177
6453
|
get QueryCategories() {
|
|
6178
|
-
return this._localMetadata.AllQueryCategories;
|
|
6454
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueryCategories, 'QueryCategories');
|
|
6179
6455
|
}
|
|
6180
|
-
/**
|
|
6456
|
+
/**
|
|
6457
|
+
* @deprecated Use `QueryEngine.Instance.Fields` from `@memberjunction/core-entities`. Empty unless the
|
|
6458
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6459
|
+
*/
|
|
6181
6460
|
get QueryFields() {
|
|
6182
|
-
return this._localMetadata.AllQueryFields;
|
|
6461
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueryFields, 'QueryFields');
|
|
6183
6462
|
}
|
|
6184
|
-
/**
|
|
6463
|
+
/**
|
|
6464
|
+
* @deprecated Use `QueryEngine.Instance.Permissions` from `@memberjunction/core-entities`. Empty unless the
|
|
6465
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6466
|
+
*/
|
|
6185
6467
|
get QueryPermissions() {
|
|
6186
|
-
return this._localMetadata.AllQueryPermissions;
|
|
6468
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueryPermissions, 'QueryPermissions');
|
|
6187
6469
|
}
|
|
6188
|
-
/**
|
|
6470
|
+
/**
|
|
6471
|
+
* @deprecated Use `QueryEngine.Instance.QueryEntities` from `@memberjunction/core-entities`. Empty unless the
|
|
6472
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6473
|
+
*/
|
|
6189
6474
|
get QueryEntities() {
|
|
6190
|
-
return this._localMetadata.AllQueryEntities;
|
|
6475
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueryEntities, 'QueryEntities');
|
|
6191
6476
|
}
|
|
6192
|
-
/**
|
|
6477
|
+
/**
|
|
6478
|
+
* @deprecated Use `QueryEngine.Instance.Parameters` from `@memberjunction/core-entities`. Empty unless the
|
|
6479
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6480
|
+
*/
|
|
6193
6481
|
get QueryParameters() {
|
|
6194
|
-
return this._localMetadata.AllQueryParameters;
|
|
6482
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueryParameters, 'QueryParameters');
|
|
6195
6483
|
}
|
|
6196
|
-
/**
|
|
6484
|
+
/**
|
|
6485
|
+
* @deprecated Use `QueryEngine.Instance.Dependencies` from `@memberjunction/core-entities`. Empty unless the
|
|
6486
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6487
|
+
*/
|
|
6197
6488
|
get QueryDependencies() {
|
|
6198
|
-
return this._localMetadata.AllQueryDependencies;
|
|
6489
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQueryDependencies, 'QueryDependencies');
|
|
6199
6490
|
}
|
|
6200
|
-
/**
|
|
6491
|
+
/**
|
|
6492
|
+
* @deprecated Use `QueryEngine.Instance.SQLDialects` from `@memberjunction/core-entities`. Empty unless the
|
|
6493
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6494
|
+
*/
|
|
6201
6495
|
get SQLDialects() {
|
|
6202
|
-
return this._localMetadata.AllSQLDialects;
|
|
6496
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllSQLDialects, 'SQLDialects');
|
|
6203
6497
|
}
|
|
6204
|
-
/**
|
|
6498
|
+
/**
|
|
6499
|
+
* @deprecated Use `QueryEngine.Instance.QuerySQLs` from `@memberjunction/core-entities`. Empty unless the
|
|
6500
|
+
* provider is configured with `LoadQueryMetadata`; removed in 7.0.
|
|
6501
|
+
*/
|
|
6205
6502
|
get QuerySQLs() {
|
|
6206
|
-
return this._localMetadata.AllQuerySQLs;
|
|
6503
|
+
return this.deprecatedQueryMetadata(this._localMetadata.AllQuerySQLs, 'QuerySQLs');
|
|
6207
6504
|
}
|
|
6208
6505
|
/**
|
|
6209
6506
|
* Gets all library definitions in the system.
|
|
@@ -6918,7 +7215,7 @@ export class ProviderBase {
|
|
|
6918
7215
|
let d;
|
|
6919
7216
|
try {
|
|
6920
7217
|
// No schema filters for metadata — see comment in GetAllMetadata
|
|
6921
|
-
d = await this.GetDatasetStatusByName(ProviderBase._mjMetadataDatasetName,
|
|
7218
|
+
d = await this.GetDatasetStatusByName(ProviderBase._mjMetadataDatasetName, this.MetadataDatasetItemFilters, this.CurrentUser, providerToUse);
|
|
6922
7219
|
}
|
|
6923
7220
|
catch (e) {
|
|
6924
7221
|
if (!IsTransportError(e)) {
|
|
@@ -7084,13 +7381,53 @@ export class ProviderBase {
|
|
|
7084
7381
|
const membershipKey = this.LocalStoragePrefix + ProviderBase.localStorageDatasetMembershipKey;
|
|
7085
7382
|
const itemsKey = this.LocalStoragePrefix + ProviderBase.localStorageDatasetItemsKey;
|
|
7086
7383
|
const readStart = Date.now();
|
|
7087
|
-
|
|
7384
|
+
let raw = null;
|
|
7385
|
+
let tsRaw = null;
|
|
7386
|
+
let format = null;
|
|
7387
|
+
let membershipRaw = null;
|
|
7388
|
+
let itemsRaw = null;
|
|
7389
|
+
if (typeof ls.GetObject === 'function') {
|
|
7390
|
+
const otherKeys = [tsKey, fmtKey, membershipKey, itemsKey];
|
|
7391
|
+
const [metadataObj, otherItems] = await Promise.all([
|
|
7392
|
+
ls.GetObject(dataKey),
|
|
7393
|
+
typeof ls.GetItems === 'function' ? ls.GetItems(otherKeys) : null
|
|
7394
|
+
]);
|
|
7395
|
+
raw = metadataObj !== null && metadataObj !== undefined
|
|
7396
|
+
? metadataObj
|
|
7397
|
+
: await ls.GetItem(dataKey);
|
|
7398
|
+
if (otherItems) {
|
|
7399
|
+
tsRaw = otherItems.get(tsKey) ?? null;
|
|
7400
|
+
format = otherItems.get(fmtKey) ?? null;
|
|
7401
|
+
membershipRaw = otherItems.get(membershipKey) ?? null;
|
|
7402
|
+
itemsRaw = otherItems.get(itemsKey) ?? null;
|
|
7403
|
+
}
|
|
7404
|
+
else {
|
|
7405
|
+
tsRaw = await ls.GetItem(tsKey);
|
|
7406
|
+
format = await ls.GetItem(fmtKey);
|
|
7407
|
+
membershipRaw = await ls.GetItem(membershipKey);
|
|
7408
|
+
itemsRaw = await ls.GetItem(itemsKey);
|
|
7409
|
+
}
|
|
7410
|
+
}
|
|
7411
|
+
else {
|
|
7412
|
+
const all = typeof ls.GetItems === 'function'
|
|
7413
|
+
? await ls.GetItems([tsKey, fmtKey, dataKey, membershipKey, itemsKey])
|
|
7414
|
+
: null;
|
|
7415
|
+
if (all) {
|
|
7416
|
+
tsRaw = all.get(tsKey) ?? null;
|
|
7417
|
+
format = all.get(fmtKey) ?? null;
|
|
7418
|
+
raw = all.get(dataKey) ?? null;
|
|
7419
|
+
membershipRaw = all.get(membershipKey) ?? null;
|
|
7420
|
+
itemsRaw = all.get(itemsKey) ?? null;
|
|
7421
|
+
}
|
|
7422
|
+
else {
|
|
7423
|
+
tsRaw = await ls.GetItem(tsKey);
|
|
7424
|
+
format = await ls.GetItem(fmtKey);
|
|
7425
|
+
raw = await ls.GetItem(dataKey);
|
|
7426
|
+
membershipRaw = await ls.GetItem(membershipKey);
|
|
7427
|
+
itemsRaw = await ls.GetItem(itemsKey);
|
|
7428
|
+
}
|
|
7429
|
+
}
|
|
7088
7430
|
const readMs = Date.now() - readStart;
|
|
7089
|
-
const tsRaw = all.get(tsKey) ?? null;
|
|
7090
|
-
const format = all.get(fmtKey) ?? null;
|
|
7091
|
-
const raw = all.get(dataKey) ?? null;
|
|
7092
|
-
const membershipRaw = all.get(membershipKey) ?? null;
|
|
7093
|
-
const itemsRaw = all.get(itemsKey) ?? null;
|
|
7094
7431
|
// The timestamps are a freshness claim FOR THE PAYLOAD, so they are only adopted when the
|
|
7095
7432
|
// payload is there to adopt with them. Timestamps without a payload happen whenever the
|
|
7096
7433
|
// two keys do not disappear together: the timestamps key is written last (and removed
|
|
@@ -7116,27 +7453,19 @@ export class ProviderBase {
|
|
|
7116
7453
|
// boot that never calls GetAllMetadata (the stale-while-revalidate fast start). The
|
|
7117
7454
|
// set is only stored after a successful dataset load, so restoring it is exactly as
|
|
7118
7455
|
// trustworthy as restoring the metadata itself.
|
|
7119
|
-
if (membershipRaw) {
|
|
7120
|
-
try {
|
|
7121
|
-
const names = JSON.parse(membershipRaw);
|
|
7122
|
-
if (Array.isArray(names) && names.length > 0) {
|
|
7123
|
-
this._metadataDatasetEntityNames = new Set(names);
|
|
7124
|
-
this.ensureInflightViewInvalidation();
|
|
7125
|
-
}
|
|
7126
|
-
}
|
|
7127
|
-
catch (membershipErr) {
|
|
7128
|
-
LogError(`[Metadata Cache] Failed to restore dataset membership: ${membershipErr instanceof Error ? membershipErr.message : String(membershipErr)}`);
|
|
7129
|
-
}
|
|
7130
|
-
}
|
|
7131
7456
|
// Restore the dataset item list the same way, so a warm boot can attribute a change to
|
|
7132
7457
|
// its item and reload only what changed (see MetadataRefreshScope). Without it, every
|
|
7133
|
-
// change seen by a process that started from the snapshot was a full reload.
|
|
7458
|
+
// change seen by a process that started from the snapshot was a full reload. Restored
|
|
7459
|
+
// first: the membership below is narrowed by it.
|
|
7134
7460
|
if (itemsRaw) {
|
|
7135
7461
|
this.restoreMetadataDatasetItems(itemsRaw);
|
|
7136
7462
|
}
|
|
7463
|
+
if (membershipRaw) {
|
|
7464
|
+
this.restoreMetadataDatasetMembership(membershipRaw);
|
|
7465
|
+
}
|
|
7137
7466
|
if (!raw)
|
|
7138
7467
|
return;
|
|
7139
|
-
// Decompress if stored in compressed format, otherwise parse directly
|
|
7468
|
+
// Decompress if stored in compressed format, otherwise parse directly or adopt object directly
|
|
7140
7469
|
const parseStart = Date.now();
|
|
7141
7470
|
let temp;
|
|
7142
7471
|
if (format === 'gzip' && typeof raw === 'string') {
|
|
@@ -7148,9 +7477,13 @@ export class ProviderBase {
|
|
|
7148
7477
|
const jsonString = await new Response(decompressedStream).text();
|
|
7149
7478
|
temp = JSON.parse(jsonString);
|
|
7150
7479
|
}
|
|
7151
|
-
else {
|
|
7152
|
-
// Legacy uncompressed path
|
|
7153
|
-
temp =
|
|
7480
|
+
else if (typeof raw === 'string') {
|
|
7481
|
+
// Legacy uncompressed string path
|
|
7482
|
+
temp = JSON.parse(raw);
|
|
7483
|
+
}
|
|
7484
|
+
else if (typeof raw === 'object' && raw !== null) {
|
|
7485
|
+
// Structured clone object path: directly adopt the cloned object
|
|
7486
|
+
temp = raw;
|
|
7154
7487
|
}
|
|
7155
7488
|
const parseMs = Date.now() - parseStart;
|
|
7156
7489
|
if (!temp)
|
|
@@ -7160,6 +7493,7 @@ export class ProviderBase {
|
|
|
7160
7493
|
const metadata = MetadataFromSimpleObject(temp, this);
|
|
7161
7494
|
const deserializeMs = Date.now() - deserializeStart;
|
|
7162
7495
|
if (metadata) {
|
|
7496
|
+
this.dropUnloadedQueryMetadata(metadata);
|
|
7163
7497
|
this.UpdateLocalMetadata(metadata);
|
|
7164
7498
|
const totalMs = Date.now() - overallStart;
|
|
7165
7499
|
LogStatusEx({
|
|
@@ -7189,6 +7523,30 @@ export class ProviderBase {
|
|
|
7189
7523
|
ProviderBase.localStorageDatasetMembershipKey,
|
|
7190
7524
|
ProviderBase.localStorageDatasetItemsKey,
|
|
7191
7525
|
]; }
|
|
7526
|
+
/**
|
|
7527
|
+
* Adopts a stored metadata-member entity set. The entities that back only items this provider
|
|
7528
|
+
* does not read are removed, so a snapshot saved by a process configured to read them cannot
|
|
7529
|
+
* make writes to them schedule refreshes here.
|
|
7530
|
+
*/
|
|
7531
|
+
restoreMetadataDatasetMembership(membershipRaw) {
|
|
7532
|
+
try {
|
|
7533
|
+
const names = JSON.parse(membershipRaw);
|
|
7534
|
+
if (!Array.isArray(names) || names.length === 0) {
|
|
7535
|
+
return;
|
|
7536
|
+
}
|
|
7537
|
+
const restored = new Set(names.filter((n) => typeof n === 'string'));
|
|
7538
|
+
for (const skipped of this.skippedMetadataEntityNames(this._metadataDatasetItems ?? [])) {
|
|
7539
|
+
restored.delete(skipped);
|
|
7540
|
+
}
|
|
7541
|
+
if (restored.size > 0) {
|
|
7542
|
+
this._metadataDatasetEntityNames = restored;
|
|
7543
|
+
this.ensureInflightViewInvalidation();
|
|
7544
|
+
}
|
|
7545
|
+
}
|
|
7546
|
+
catch (membershipErr) {
|
|
7547
|
+
LogError(`[Metadata Cache] Failed to restore dataset membership: ${membershipErr instanceof Error ? membershipErr.message : String(membershipErr)}`);
|
|
7548
|
+
}
|
|
7549
|
+
}
|
|
7192
7550
|
/**
|
|
7193
7551
|
* Adopts a stored dataset item list. Only a well-formed list replaces the one held: a damaged or
|
|
7194
7552
|
* empty value must not erase the list a load already recorded.
|
|
@@ -7305,6 +7663,115 @@ export class ProviderBase {
|
|
|
7305
7663
|
verboseOnly: false
|
|
7306
7664
|
});
|
|
7307
7665
|
}
|
|
7666
|
+
/** Default debounce duration in milliseconds for coalesced metadata snapshot writes to local storage. */
|
|
7667
|
+
static { this.MetadataSnapshotSaveDebounceMs = 250; }
|
|
7668
|
+
/**
|
|
7669
|
+
* Schedules a trailing-edge coalesced background call to `SaveLocalMetadataToStorage()`,
|
|
7670
|
+
* deduplicating rapid back-to-back calls within the window and serializing execution if an
|
|
7671
|
+
* in-flight save is already running.
|
|
7672
|
+
*
|
|
7673
|
+
* @param delayMs - Debounce window duration in milliseconds (defaults to `ProviderBase.MetadataSnapshotSaveDebounceMs`)
|
|
7674
|
+
*/
|
|
7675
|
+
ScheduleSaveLocalMetadataToStorage(delayMs = ProviderBase.MetadataSnapshotSaveDebounceMs) {
|
|
7676
|
+
if (!this.LocalStorageProvider)
|
|
7677
|
+
return;
|
|
7678
|
+
if (!this.MetadataSnapshotPersistenceEnabled) {
|
|
7679
|
+
this.logMetadataSnapshotDisabledOnce();
|
|
7680
|
+
return;
|
|
7681
|
+
}
|
|
7682
|
+
if (this._inFlightMetadataSave) {
|
|
7683
|
+
this._hasPendingMetadataSaveWhileInFlight = true;
|
|
7684
|
+
return;
|
|
7685
|
+
}
|
|
7686
|
+
if (this._metadataSaveTimer) {
|
|
7687
|
+
clearTimeout(this._metadataSaveTimer);
|
|
7688
|
+
}
|
|
7689
|
+
this._metadataSaveTimer = setTimeout(() => {
|
|
7690
|
+
this._metadataSaveTimer = null;
|
|
7691
|
+
void this.triggerSerializedMetadataSave();
|
|
7692
|
+
}, delayMs);
|
|
7693
|
+
if (typeof this._metadataSaveTimer?.unref === 'function') {
|
|
7694
|
+
this._metadataSaveTimer.unref();
|
|
7695
|
+
}
|
|
7696
|
+
}
|
|
7697
|
+
/**
|
|
7698
|
+
* Cancels any pending debounce timer and awaits `SaveLocalMetadataToStorage()` immediately
|
|
7699
|
+
* (or awaits any in-flight save plus trailing save), so tests and shutdown hooks can
|
|
7700
|
+
* deterministically flush pending writes.
|
|
7701
|
+
*/
|
|
7702
|
+
async FlushPendingMetadataStorageSave() {
|
|
7703
|
+
if (this._metadataSaveTimer) {
|
|
7704
|
+
clearTimeout(this._metadataSaveTimer);
|
|
7705
|
+
this._metadataSaveTimer = null;
|
|
7706
|
+
this._hasPendingMetadataSaveWhileInFlight = true;
|
|
7707
|
+
}
|
|
7708
|
+
if (this._inFlightMetadataSave) {
|
|
7709
|
+
await this._inFlightMetadataSave;
|
|
7710
|
+
return;
|
|
7711
|
+
}
|
|
7712
|
+
if (this._hasPendingMetadataSaveWhileInFlight) {
|
|
7713
|
+
await this.triggerSerializedMetadataSave();
|
|
7714
|
+
}
|
|
7715
|
+
}
|
|
7716
|
+
/**
|
|
7717
|
+
* Clears any pending metadata snapshot save timer without saving.
|
|
7718
|
+
*/
|
|
7719
|
+
CancelPendingMetadataStorageSave() {
|
|
7720
|
+
if (this._metadataSaveTimer) {
|
|
7721
|
+
clearTimeout(this._metadataSaveTimer);
|
|
7722
|
+
this._metadataSaveTimer = null;
|
|
7723
|
+
}
|
|
7724
|
+
this._hasPendingMetadataSaveWhileInFlight = false;
|
|
7725
|
+
}
|
|
7726
|
+
triggerSerializedMetadataSave() {
|
|
7727
|
+
if (!this._inFlightMetadataSave) {
|
|
7728
|
+
this._inFlightMetadataSave = this.executeSerializedMetadataSave().finally(() => {
|
|
7729
|
+
this._inFlightMetadataSave = null;
|
|
7730
|
+
});
|
|
7731
|
+
}
|
|
7732
|
+
return this._inFlightMetadataSave;
|
|
7733
|
+
}
|
|
7734
|
+
async executeSerializedMetadataSave() {
|
|
7735
|
+
do {
|
|
7736
|
+
this._hasPendingMetadataSaveWhileInFlight = false;
|
|
7737
|
+
try {
|
|
7738
|
+
await this.SaveLocalMetadataToStorage();
|
|
7739
|
+
}
|
|
7740
|
+
catch {
|
|
7741
|
+
// SaveLocalMetadataToStorage catches its own errors; guard here as well
|
|
7742
|
+
}
|
|
7743
|
+
} while (this._hasPendingMetadataSaveWhileInFlight);
|
|
7744
|
+
}
|
|
7745
|
+
/**
|
|
7746
|
+
* Converts BaseInfo instances and nested objects into plain structured-cloneable
|
|
7747
|
+
* objects without JSON.stringify/JSON.parse, stripping functions and WeakRefs.
|
|
7748
|
+
*/
|
|
7749
|
+
static toCloneableValue(val) {
|
|
7750
|
+
if (val == null || typeof val !== 'object') {
|
|
7751
|
+
return val;
|
|
7752
|
+
}
|
|
7753
|
+
if (val instanceof Date || val instanceof RegExp || val instanceof ArrayBuffer || ArrayBuffer.isView(val)) {
|
|
7754
|
+
return val;
|
|
7755
|
+
}
|
|
7756
|
+
if (Array.isArray(val)) {
|
|
7757
|
+
const out = new Array(val.length);
|
|
7758
|
+
for (let i = 0; i < val.length; i++) {
|
|
7759
|
+
out[i] = ProviderBase.toCloneableValue(val[i]);
|
|
7760
|
+
}
|
|
7761
|
+
return out;
|
|
7762
|
+
}
|
|
7763
|
+
const maybeToJson = val;
|
|
7764
|
+
if (typeof maybeToJson.toJSON === 'function') {
|
|
7765
|
+
return ProviderBase.toCloneableValue(maybeToJson.toJSON());
|
|
7766
|
+
}
|
|
7767
|
+
const out = {};
|
|
7768
|
+
for (const [k, v] of Object.entries(val)) {
|
|
7769
|
+
if (typeof v !== 'function' && !(typeof WeakRef !== 'undefined' && v instanceof WeakRef)) {
|
|
7770
|
+
out[k] = ProviderBase.toCloneableValue(v);
|
|
7771
|
+
}
|
|
7772
|
+
}
|
|
7773
|
+
return out;
|
|
7774
|
+
}
|
|
7308
7775
|
/**
|
|
7309
7776
|
* Saves current metadata to local storage for caching.
|
|
7310
7777
|
* Serializes both timestamps and full metadata collections.
|
|
@@ -7321,14 +7788,22 @@ export class ProviderBase {
|
|
|
7321
7788
|
return;
|
|
7322
7789
|
}
|
|
7323
7790
|
const start = Date.now();
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7791
|
+
const dataKey = this.LocalStoragePrefix + ProviderBase.localStorageAllMetadataKey;
|
|
7792
|
+
const formatKey = this.LocalStoragePrefix + ProviderBase.localStorageFormatKey;
|
|
7793
|
+
let snapshot;
|
|
7794
|
+
if (typeof ls.SetObject === 'function') {
|
|
7795
|
+
// Structured-clone path: convert BaseInfo instances to plain cloneable objects (stripping
|
|
7796
|
+
// WeakRef/provider back-references without JSON.stringify/gzip/JSON.parse or lazy field hydration)
|
|
7797
|
+
const cloneableMetadata = ProviderBase.toCloneableValue(this._localMetadata);
|
|
7798
|
+
await ls.SetObject(dataKey, cloneableMetadata);
|
|
7799
|
+
await ls.SetItem(formatKey, 'structured-clone');
|
|
7800
|
+
snapshot = { compressed: false, storedLength: 0 };
|
|
7801
|
+
}
|
|
7802
|
+
else {
|
|
7803
|
+
// Serialized string path (JSON.stringify + gzip/base64 when CompressionStream is available)
|
|
7804
|
+
const jsonString = JSON.stringify(this._localMetadata);
|
|
7805
|
+
snapshot = await this.writeMetadataSnapshot(ls, jsonString);
|
|
7806
|
+
}
|
|
7332
7807
|
// Persist the metadata-member entity set beside the snapshot it belongs to, so the
|
|
7333
7808
|
// event-driven refresh survives a warm boot (see LoadLocalMetadataFromStorage).
|
|
7334
7809
|
if (this._metadataDatasetEntityNames?.size) {
|
|
@@ -7343,7 +7818,7 @@ export class ProviderBase {
|
|
|
7343
7818
|
const timestampsRaw = JSON.stringify(this._latestLocalMetadataTimestamps);
|
|
7344
7819
|
await ls.SetItem(this.LocalStoragePrefix + ProviderBase.localStorageTimestampsKey, timestampsRaw);
|
|
7345
7820
|
this._storedTimestampsRaw = timestampsRaw;
|
|
7346
|
-
this.logMetadataSaveComplete(Date.now() - start,
|
|
7821
|
+
this.logMetadataSaveComplete(Date.now() - start, snapshot.storedLength, snapshot);
|
|
7347
7822
|
}
|
|
7348
7823
|
catch (e) {
|
|
7349
7824
|
LogError(`[Metadata Cache] SaveLocalMetadataToStorage failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
@@ -7390,6 +7865,12 @@ export class ProviderBase {
|
|
|
7390
7865
|
verboseOnly: true
|
|
7391
7866
|
});
|
|
7392
7867
|
}
|
|
7868
|
+
else if (snapshot.storedLength === 0) {
|
|
7869
|
+
LogStatusEx({
|
|
7870
|
+
message: `[Metadata Cache] Save complete (structured-clone): ${elapsedMs}ms`,
|
|
7871
|
+
verboseOnly: true
|
|
7872
|
+
});
|
|
7873
|
+
}
|
|
7393
7874
|
else {
|
|
7394
7875
|
LogStatusEx({
|
|
7395
7876
|
message: `[Metadata Cache] Save complete (uncompressed): ${elapsedMs}ms, size=${mb(rawLength)}MB`,
|