@memberjunction/generic-database-provider 6.2.0-edge.5 → 6.2.0-edge.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/dist/GenericDatabaseProvider.d.ts +362 -37
- package/dist/GenericDatabaseProvider.d.ts.map +1 -1
- package/dist/GenericDatabaseProvider.js +1425 -216
- package/dist/GenericDatabaseProvider.js.map +1 -1
- package/dist/SqlLogger.d.ts +26 -0
- package/dist/SqlLogger.d.ts.map +1 -1
- package/dist/SqlLogger.js +77 -20
- package/dist/SqlLogger.js.map +1 -1
- package/dist/clientClauseScreen.d.ts +28 -3
- package/dist/clientClauseScreen.d.ts.map +1 -1
- package/dist/clientClauseScreen.js +112 -6
- package/dist/clientClauseScreen.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/recordChangeSnapshot.d.ts +43 -0
- package/dist/recordChangeSnapshot.d.ts.map +1 -0
- package/dist/recordChangeSnapshot.js +85 -0
- package/dist/recordChangeSnapshot.js.map +1 -0
- package/dist/renderPipeline.d.ts +27 -0
- package/dist/renderPipeline.d.ts.map +1 -1
- package/dist/renderPipeline.js +45 -3
- package/dist/renderPipeline.js.map +1 -1
- package/dist/systemUserFieldAccess.d.ts +16 -1
- package/dist/systemUserFieldAccess.d.ts.map +1 -1
- package/dist/systemUserFieldAccess.js +39 -8
- package/dist/systemUserFieldAccess.js.map +1 -1
- package/dist/types.d.ts +47 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export { ClientClauseScreen, IsClientClauseScreeningProvider } from './clientCla
|
|
|
9
9
|
export type { ClientClauseText, ClientViewClauseSet, EntityBaseViewAllowList, ClientClauseScreeningProvider, StatementReads, StatementRelation } from './clientClauseScreen.js';
|
|
10
10
|
export { SystemUserFieldAccessLossReason, FindSystemUserFieldAccessViolations, SystemUserFieldAccessViolation, SystemUserHoldsRole, SystemUserFieldAccessSweepOptions, } from './systemUserFieldAccess.js';
|
|
11
11
|
export { SystemUserFieldAccessCheck, LoadSystemUserFieldAccessCheck } from './SystemUserFieldAccessCheck.js';
|
|
12
|
-
export { SqlLoggingOptions, SqlLoggingSession } from './types.js';
|
|
13
|
-
export { SqlLoggingSessionImpl } from './SqlLogger.js';
|
|
12
|
+
export { SqlLoggingOptions, SqlLoggingSession, SqlSchemaPlaceholder } from './types.js';
|
|
13
|
+
export { SqlLoggingSessionImpl, SCHEMA_PLACEHOLDER_LOOKBEHIND } from './SqlLogger.js';
|
|
14
14
|
export { QueryCompositionEngine, CompositionCTEInfo, CompositionResult } from './queryCompositionEngine.js';
|
|
15
15
|
export { CountOnlyBatchCoalescer, IsCoalescibleCountBatch } from './countOnlyBatch.js';
|
|
16
16
|
export type { CountOnlyRow, CountSQLExecutor } from './countOnlyBatch.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAGvH,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EACR,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,aAAa,EACb,0BAA0B,EAAE,0BAA0B,EACtD,4BAA4B,EAAE,4BAA4B,EAC1D,mBAAmB,EAAE,mBAAmB,EACxC,eAAe,EAAE,eAAe,GACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB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ED
|
@@ -11,7 +11,7 @@ export { SystemUserFieldAccessLossReason, FindSystemUserFieldAccessViolations, S
|
|
|
11
11
|
// Side-effect import: registers the startup sweep that reports a system user which has lost
|
|
12
12
|
// field-level access on an FLS-enabled entity.
|
|
13
13
|
export { SystemUserFieldAccessCheck, LoadSystemUserFieldAccessCheck } from './SystemUserFieldAccessCheck.js';
|
|
14
|
-
export { SqlLoggingSessionImpl } from './SqlLogger.js';
|
|
14
|
+
export { SqlLoggingSessionImpl, SCHEMA_PLACEHOLDER_LOOKBEHIND } from './SqlLogger.js';
|
|
15
15
|
export { QueryCompositionEngine } from './queryCompositionEngine.js';
|
|
16
16
|
export { CountOnlyBatchCoalescer, IsCoalescibleCountBatch } from './countOnlyBatch.js';
|
|
17
17
|
export { QueryPagingEngine } from './queryPagingEngine.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAA0B,MAAM,8BAA8B,CAAC;AACvH,0FAA0F;AAC1F,0EAA0E;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,OAAO,EAEH,0BAA0B,EAAE,0BAA0B,EACtD,4BAA4B,EAAE,4BAA4B,EAC1D,mBAAmB,EAAE,mBAAmB,EACxC,eAAe,EAAE,eAAe,GACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE9F,OAAO,EACH,+BAA+B,EAC/B,mCAAmC,EAEnC,mBAAmB,GAEtB,MAAM,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AAc,EAAmE,MAAM,qBAAqB,CAAC;AACtH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,uEAAuE;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BaseEntity, UserInfo } from '@memberjunction/core';
|
|
2
|
+
/**
|
|
3
|
+
* The old and new record snapshots a save hands to `BuildRecordChangePayload`. `OldData` is
|
|
4
|
+
* null for a create.
|
|
5
|
+
*/
|
|
6
|
+
export interface RecordChangeSnapshots {
|
|
7
|
+
NewData: Record<string, unknown>;
|
|
8
|
+
OldData: Record<string, unknown> | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The names of the fields `user` may not read whose stored value the saving object does not
|
|
12
|
+
* hold — the columns a restricted user's object leaves out of a snapshot. Empty for every user
|
|
13
|
+
* denied nothing, which is what lets those saves skip the stored-row read: a field such a user's
|
|
14
|
+
* object lacks only because its load left the column out (a list load skips binary columns)
|
|
15
|
+
* stays out of the snapshot, as it always has.
|
|
16
|
+
*/
|
|
17
|
+
export declare function FieldsLackingStoredValue(entity: BaseEntity, user: UserInfo | null | undefined): Set<string>;
|
|
18
|
+
/**
|
|
19
|
+
* The snapshots for a create. A field the INSERT omits because the user may not supply it
|
|
20
|
+
* (`CreateSuppressed`) is left out of the new-values snapshot: the value the object holds is one
|
|
21
|
+
* the record never received, and the column's database default is not known until the insert
|
|
22
|
+
* runs. The next change to the record snapshots the stored value.
|
|
23
|
+
*/
|
|
24
|
+
export declare function CreateSnapshots(entity: BaseEntity): RecordChangeSnapshots;
|
|
25
|
+
/**
|
|
26
|
+
* Widens an update's snapshots to the whole record using the stored row, in entity field order.
|
|
27
|
+
*
|
|
28
|
+
* - **New values**: the saving object's values, and the stored value for each field it never held.
|
|
29
|
+
* - **Old values**: the saving object's old values, and the stored value for each field it never
|
|
30
|
+
* held — including one it then wrote blind, whose in-memory old value is not the stored one.
|
|
31
|
+
*
|
|
32
|
+
* A field the object never held has the same stored value on both sides, so it never appears as
|
|
33
|
+
* a change: the diff still lists only what the save changed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function WidenUpdateSnapshots(entity: BaseEntity, narrow: RecordChangeSnapshots, storedRow: Record<string, unknown>, lacking: ReadonlySet<string>): RecordChangeSnapshots;
|
|
36
|
+
/**
|
|
37
|
+
* Widens a delete's record snapshot to the whole record using the stored row, in entity field
|
|
38
|
+
* order: the deleting object's values, and the stored value for each field it never held. A
|
|
39
|
+
* deleted record is restored from this snapshot, so a narrowed one would bring the record back
|
|
40
|
+
* without the columns its deleter could not read.
|
|
41
|
+
*/
|
|
42
|
+
export declare function WidenDeleteSnapshot(entity: BaseEntity, narrow: Record<string, unknown>, storedRow: Record<string, unknown>, lacking: ReadonlySet<string>): Record<string, unknown>;
|
|
43
|
+
//# sourceMappingURL=recordChangeSnapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recordChangeSnapshot.d.ts","sourceRoot":"","sources":["../src/recordChangeSnapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAe,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC3C;AAWD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAgB3G;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,qBAAqB,CAQzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAChC,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,qBAAqB,EAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAC7B,qBAAqB,CAcvB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when the field's stored value is not in the saving object: either the hydration source
|
|
3
|
+
* omitted it ({@link EntityField.NotLoaded}), or it was written after being omitted, so its old
|
|
4
|
+
* value is a construction artifact rather than the stored value.
|
|
5
|
+
*/
|
|
6
|
+
function lacksStoredValue(field) {
|
|
7
|
+
return field.NotLoaded || field.GetState().WrittenAfterNotLoaded === true;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The names of the fields `user` may not read whose stored value the saving object does not
|
|
11
|
+
* hold — the columns a restricted user's object leaves out of a snapshot. Empty for every user
|
|
12
|
+
* denied nothing, which is what lets those saves skip the stored-row read: a field such a user's
|
|
13
|
+
* object lacks only because its load left the column out (a list load skips binary columns)
|
|
14
|
+
* stays out of the snapshot, as it always has.
|
|
15
|
+
*/
|
|
16
|
+
export function FieldsLackingStoredValue(entity, user) {
|
|
17
|
+
const names = new Set();
|
|
18
|
+
const denied = user && entity.EntityInfo.FieldLevelSecurityApplies ? entity.EntityInfo.GetDeniedReadFields(user) : null;
|
|
19
|
+
if (!denied || denied.size === 0) {
|
|
20
|
+
return names;
|
|
21
|
+
}
|
|
22
|
+
for (const fieldInfo of entity.EntityInfo.Fields) {
|
|
23
|
+
if (!denied.has(fieldInfo.Name.trim().toLowerCase())) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const field = entity.GetFieldByName(fieldInfo.Name);
|
|
27
|
+
if (field && lacksStoredValue(field)) {
|
|
28
|
+
names.add(fieldInfo.Name);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return names;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The snapshots for a create. A field the INSERT omits because the user may not supply it
|
|
35
|
+
* (`CreateSuppressed`) is left out of the new-values snapshot: the value the object holds is one
|
|
36
|
+
* the record never received, and the column's database default is not known until the insert
|
|
37
|
+
* runs. The next change to the record snapshots the stored value.
|
|
38
|
+
*/
|
|
39
|
+
export function CreateSnapshots(entity) {
|
|
40
|
+
const newData = entity.GetAll(false);
|
|
41
|
+
for (const field of entity.Fields) {
|
|
42
|
+
if (field.CreateSuppressed) {
|
|
43
|
+
delete newData[field.Name];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { NewData: newData, OldData: null };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Widens an update's snapshots to the whole record using the stored row, in entity field order.
|
|
50
|
+
*
|
|
51
|
+
* - **New values**: the saving object's values, and the stored value for each field it never held.
|
|
52
|
+
* - **Old values**: the saving object's old values, and the stored value for each field it never
|
|
53
|
+
* held — including one it then wrote blind, whose in-memory old value is not the stored one.
|
|
54
|
+
*
|
|
55
|
+
* A field the object never held has the same stored value on both sides, so it never appears as
|
|
56
|
+
* a change: the diff still lists only what the save changed.
|
|
57
|
+
*/
|
|
58
|
+
export function WidenUpdateSnapshots(entity, narrow, storedRow, lacking) {
|
|
59
|
+
const newData = {};
|
|
60
|
+
const oldData = {};
|
|
61
|
+
const narrowOld = narrow.OldData ?? {};
|
|
62
|
+
for (const fieldInfo of entity.EntityInfo.Fields) {
|
|
63
|
+
const name = fieldInfo.Name;
|
|
64
|
+
const stored = name in storedRow;
|
|
65
|
+
if (name in narrow.NewData)
|
|
66
|
+
newData[name] = narrow.NewData[name];
|
|
67
|
+
else if (stored)
|
|
68
|
+
newData[name] = storedRow[name];
|
|
69
|
+
if (lacking.has(name) && stored)
|
|
70
|
+
oldData[name] = storedRow[name];
|
|
71
|
+
else if (name in narrowOld)
|
|
72
|
+
oldData[name] = narrowOld[name];
|
|
73
|
+
}
|
|
74
|
+
return { NewData: newData, OldData: oldData };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Widens a delete's record snapshot to the whole record using the stored row, in entity field
|
|
78
|
+
* order: the deleting object's values, and the stored value for each field it never held. A
|
|
79
|
+
* deleted record is restored from this snapshot, so a narrowed one would bring the record back
|
|
80
|
+
* without the columns its deleter could not read.
|
|
81
|
+
*/
|
|
82
|
+
export function WidenDeleteSnapshot(entity, narrow, storedRow, lacking) {
|
|
83
|
+
return WidenUpdateSnapshots(entity, { NewData: narrow, OldData: narrow }, storedRow, lacking).OldData ?? narrow;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=recordChangeSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recordChangeSnapshot.js","sourceRoot":"","sources":["../src/recordChangeSnapshot.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,KAAkB;IACxC,OAAO,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,qBAAqB,KAAK,IAAI,CAAC;AAC9E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAkB,EAAE,IAAiC;IAC1F,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,IAAI,MAAM,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACxH,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CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAI,IAAI,SAAS,CAAC;QACjC,IAAI,IAAI,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aAC5D,IAAI,MAAM;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAEjD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,MAAM;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;aAC5D,IAAI,IAAI,IAAI,SAAS;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAC/B,MAAkB,EAClB,MAA+B,EAC/B,SAAkC,EAClC,OAA4B;IAE5B,OAAO,oBAAoB,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;AACpH,CAAC"}
|
package/dist/renderPipeline.d.ts
CHANGED
|
@@ -44,6 +44,15 @@ export interface RenderContext {
|
|
|
44
44
|
ContextUser?: UserInfo;
|
|
45
45
|
/** Parameter values from the caller */
|
|
46
46
|
Parameters?: Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Values only server code sets (`RunQueryParams.ServerParameters`). A caller value for a
|
|
49
|
+
* server-set parameter, here or in a composed query, is refused.
|
|
50
|
+
*/
|
|
51
|
+
ServerParameters?: Record<string, unknown>;
|
|
52
|
+
/** IANA time zone the template's `Context` dates are worked out in. UTC when unset. */
|
|
53
|
+
TimeZone?: string;
|
|
54
|
+
/** The clock the template's `Context` reads. Defaults to now. */
|
|
55
|
+
Now?: Date;
|
|
47
56
|
/** Formal parameter definitions (for validation). Null = skip validation. */
|
|
48
57
|
ParameterDefinitions?: MJQueryParameterEntity[];
|
|
49
58
|
/** Whether the outer query uses Nunjucks templates */
|
|
@@ -80,6 +89,11 @@ export interface RenderResult {
|
|
|
80
89
|
FinalSQL: string;
|
|
81
90
|
/** Parameters that were applied during template processing */
|
|
82
91
|
AppliedParameters: Record<string, string>;
|
|
92
|
+
/**
|
|
93
|
+
* The `Context` members the template read, with their values. Empty when it read none. A
|
|
94
|
+
* cached result depends on exactly these.
|
|
95
|
+
*/
|
|
96
|
+
ContextValues: Record<string, string>;
|
|
83
97
|
/** Whether composition tokens were found and resolved */
|
|
84
98
|
HasCompositions: boolean;
|
|
85
99
|
/** Metadata about each CTE generated during composition */
|
|
@@ -175,5 +189,18 @@ export declare class RenderPipeline {
|
|
|
175
189
|
static HasCompositionTokens(sql: string): boolean;
|
|
176
190
|
private static runComposition;
|
|
177
191
|
private static runTemplates;
|
|
192
|
+
/**
|
|
193
|
+
* What the server sets on this render: its `ServerParameters`, the names that reach a
|
|
194
|
+
* server-set parameter of a composed query, and the `Context` object, worked out from the
|
|
195
|
+
* context user and the run's time zone. Context members resolve only when the template reads them.
|
|
196
|
+
*/
|
|
197
|
+
private static buildServerValues;
|
|
198
|
+
/**
|
|
199
|
+
* The names a caller value may not use because they reach a server-set parameter of a composed
|
|
200
|
+
* query: the parameter's own name when the composition token leaves it unmapped (it then reads
|
|
201
|
+
* the outer render context), or the outer name it is passed through from. A static value in the
|
|
202
|
+
* token is the query author's and protects nothing.
|
|
203
|
+
*/
|
|
204
|
+
private static composedServerSetNames;
|
|
178
205
|
}
|
|
179
206
|
//# sourceMappingURL=renderPipeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPipeline.d.ts","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"renderPipeline.d.ts","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAa,MAAM,sBAAsB,CAAC;AAC7H,OAAO,EAAyB,sBAAsB,EAAe,MAAM,+BAA+B,CAAC;AAI3G,OAAO,EAA0B,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC5G,OAAO,EAAqB,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAmD,KAAK,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAM3H;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,eAAe,EAAE,OAAO,CAAC;IACzB,iDAAiD;IACjD,gBAAgB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IACxB,+DAA+D;IAC/D,gBAAgB,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,sBAAsB,EAAE,qBAAqB,EAAE,CAAC;IAChD,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,+BAA+B;IAC/B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,+DAA+D;IAC/D,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAA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;GAiBG;AACH,qBAAa,cAAc;IAEvB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY;IAoFzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IA8BlC;;;;;;OAMG;IACH,MAAM,CAAC,sBAAsB,CACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,gBAAgB,EAC1B,WAAW,EAAE,QAAQ,EACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,kBAAkB,CAAC,EAAE,mBAAmB,EAAE,GAC3C,iBAAiB;IAMpB;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQjD,OAAO,CAAC,MAAM,CAAC,cAAc;IAkB7B,OAAO,CAAC,MAAM,CAAC,YAAY;IAyC3B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAqBxC"}
|
package/dist/renderPipeline.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { LogStatus } from '@memberjunction/core';
|
|
1
|
+
import { BuildQueryTemplateContext, LogStatus } from '@memberjunction/core';
|
|
2
|
+
import { QueryEngine } from '@memberjunction/core-entities';
|
|
3
|
+
import { UUIDMap, UUIDSet } from '@memberjunction/global';
|
|
2
4
|
import { GetDialect } from '@memberjunction/sql-dialect';
|
|
3
5
|
import { SQLParser, IsReadOnlyQuery, FindForbiddenFunctionCalls } from '@memberjunction/sql-parser';
|
|
4
6
|
import { QueryCompositionEngine } from './queryCompositionEngine.js';
|
|
@@ -43,6 +45,7 @@ export class RenderPipeline {
|
|
|
43
45
|
}
|
|
44
46
|
let currentSQL = sql;
|
|
45
47
|
let appliedParameters = {};
|
|
48
|
+
let contextValues = {};
|
|
46
49
|
// ── Step 1: Composition ──────────────────────────────────────
|
|
47
50
|
const compositionResult = RenderPipeline.runComposition(currentSQL, ctx);
|
|
48
51
|
currentSQL = compositionResult.ResolvedSQL;
|
|
@@ -59,6 +62,7 @@ export class RenderPipeline {
|
|
|
59
62
|
const templateResult = RenderPipeline.runTemplates(currentSQL, sql, ctx, compositionResult);
|
|
60
63
|
currentSQL = templateResult.processedSQL;
|
|
61
64
|
appliedParameters = templateResult.appliedParameters;
|
|
65
|
+
contextValues = templateResult.contextValues;
|
|
62
66
|
const afterTemplates = currentSQL;
|
|
63
67
|
// ── Step 2.5: Safety validation (mutation + injection guard) ──
|
|
64
68
|
// The fully-resolved query is the point where composition and parameter
|
|
@@ -88,6 +92,7 @@ export class RenderPipeline {
|
|
|
88
92
|
return {
|
|
89
93
|
FinalSQL: currentSQL,
|
|
90
94
|
AppliedParameters: appliedParameters,
|
|
95
|
+
ContextValues: contextValues,
|
|
91
96
|
HasCompositions: compositionResult.HasCompositions,
|
|
92
97
|
CTEs: compositionResult.CTEs,
|
|
93
98
|
Trace: {
|
|
@@ -197,7 +202,7 @@ export class RenderPipeline {
|
|
|
197
202
|
static runTemplates(composedSQL, originalSQL, ctx, compositionResult) {
|
|
198
203
|
const needsTemplateProcessing = ctx.UsesTemplate || compositionResult.AnyDependencyUsesTemplates;
|
|
199
204
|
if (!needsTemplateProcessing) {
|
|
200
|
-
return { processedSQL: composedSQL, appliedParameters: {} };
|
|
205
|
+
return { processedSQL: composedSQL, appliedParameters: {}, contextValues: {} };
|
|
201
206
|
}
|
|
202
207
|
// Build the template input. When a QueryInfo object is provided (saved
|
|
203
208
|
// query path), pass it directly so processQueryTemplate gets the real
|
|
@@ -208,15 +213,52 @@ export class RenderPipeline {
|
|
|
208
213
|
Parameters: ctx.ParameterDefinitions ?? [],
|
|
209
214
|
};
|
|
210
215
|
const skipUnknownParamCheck = compositionResult.AnyDependencyUsesTemplates || !ctx.ParameterDefinitions;
|
|
211
|
-
const result = QueryParameterProcessor.
|
|
216
|
+
const result = QueryParameterProcessor.ProcessQueryTemplate(templateInput, ctx.Parameters, composedSQL, skipUnknownParamCheck, RenderPipeline.buildServerValues(ctx, compositionResult));
|
|
212
217
|
if (!result.success) {
|
|
213
218
|
throw new Error(result.error);
|
|
214
219
|
}
|
|
215
220
|
return {
|
|
216
221
|
processedSQL: result.processedSQL,
|
|
217
222
|
appliedParameters: (result.appliedParameters || {}),
|
|
223
|
+
contextValues: result.contextValues ?? {},
|
|
218
224
|
};
|
|
219
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* What the server sets on this render: its `ServerParameters`, the names that reach a
|
|
228
|
+
* server-set parameter of a composed query, and the `Context` object, worked out from the
|
|
229
|
+
* context user and the run's time zone. Context members resolve only when the template reads them.
|
|
230
|
+
*/
|
|
231
|
+
static buildServerValues(ctx, compositionResult) {
|
|
232
|
+
return {
|
|
233
|
+
ServerParameters: ctx.ServerParameters,
|
|
234
|
+
ProtectedNames: RenderPipeline.composedServerSetNames(compositionResult),
|
|
235
|
+
Context: BuildQueryTemplateContext({ User: ctx.ContextUser, TimeZone: ctx.TimeZone, Now: ctx.Now }),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The names a caller value may not use because they reach a server-set parameter of a composed
|
|
240
|
+
* query: the parameter's own name when the composition token leaves it unmapped (it then reads
|
|
241
|
+
* the outer render context), or the outer name it is passed through from. A static value in the
|
|
242
|
+
* token is the query author's and protects nothing.
|
|
243
|
+
*/
|
|
244
|
+
static composedServerSetNames(compositionResult) {
|
|
245
|
+
if (compositionResult.CTEs.length === 0) {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
const composedIDs = new UUIDSet(compositionResult.CTEs.map(c => c.QueryID));
|
|
249
|
+
const composed = new UUIDMap(QueryEngine.Instance.Queries.filter(q => composedIDs.Has(q.ID)).map((q) => [q.ID, q]));
|
|
250
|
+
const names = new Set();
|
|
251
|
+
for (const cte of compositionResult.CTEs) {
|
|
252
|
+
for (const param of composed.Get(cte.QueryID)?.QueryParameters.filter(p => p.IsServerSet) ?? []) {
|
|
253
|
+
const mapped = cte.Parameters[param.Name];
|
|
254
|
+
const passThrough = mapped === undefined ? param.Name : /^\{\{\s*([A-Za-z_]\w*)\s*\}\}$/.exec(mapped)?.[1];
|
|
255
|
+
if (passThrough) {
|
|
256
|
+
names.add(passThrough);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return [...names];
|
|
261
|
+
}
|
|
220
262
|
}
|
|
221
263
|
// ════════════════════════════════════════════════════════════════════
|
|
222
264
|
// Helpers
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderPipeline.js","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"renderPipeline.js","sourceRoot":"","sources":["../src/renderPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAmD,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC7H,OAAO,EAAiD,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC3G,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,EAAE,sBAAsB,EAAyC,MAAM,6BAA6B,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAmC,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAmD,MAAM,iCAAiC,CAAC;AAgH3H,uEAAuE;AACvE,WAAW;AACX,uEAAuE;AAEvE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IAEv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;oBACd,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAC3B,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;IACtB,CAAC;CAEJ;AAED,uEAAuE;AACvE,UAAU;AACV,uEAAuE;AAEvE,SAAS,2BAA2B,CAAC,MAAyB;IAC1D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3B,OAAO,EAAE,GAAG,CAAC,SAAS;QACtB,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,kEAAkE;QAClE,mEAAmE;QACnE,8DAA8D;QAC9D,eAAe,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAChG,gBAAgB,EAAE,CAAC,EAAE,oCAAoC;KAC5D,CAAC,CAAC,CAAC;AACR,CAAC"}
|
|
@@ -72,8 +72,10 @@ export type SystemUserFieldAccessViolation = {
|
|
|
72
72
|
* @param entity the entity the field belongs to
|
|
73
73
|
* @param field the field whose rules are changing
|
|
74
74
|
* @param projectedRules every rule that would bind to this field after the change
|
|
75
|
+
* @param systemUser the account to check, for callers that read its role set from the database;
|
|
76
|
+
* defaults to the user cache's system user
|
|
75
77
|
*/
|
|
76
|
-
export declare function SystemUserFieldAccessLossReason(entity: EntityInfo | null | undefined, field: EntityFieldInfo | null | undefined, projectedRules: readonly FieldPermissionRuleForRole[]): string | null;
|
|
78
|
+
export declare function SystemUserFieldAccessLossReason(entity: EntityInfo | null | undefined, field: EntityFieldInfo | null | undefined, projectedRules: readonly FieldPermissionRuleForRole[], systemUser?: UserInfo | null): string | null;
|
|
77
79
|
/** Narrowing for {@link FindSystemUserFieldAccessViolations}. */
|
|
78
80
|
export type SystemUserFieldAccessSweepOptions = {
|
|
79
81
|
/**
|
|
@@ -86,6 +88,13 @@ export type SystemUserFieldAccessSweepOptions = {
|
|
|
86
88
|
* up, and field rules decide nothing.
|
|
87
89
|
*/
|
|
88
90
|
WithoutRoleID?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The rules to judge each field by, keyed by lower-case `EntityFieldID`, in place of the rules
|
|
93
|
+
* on loaded metadata. For callers that read the rules from the database because loaded
|
|
94
|
+
* metadata may lag a write made a moment ago. A field absent from the map has no rule for any
|
|
95
|
+
* role the system user holds, so only rules bound to those roles need to be in it.
|
|
96
|
+
*/
|
|
97
|
+
RulesByFieldID?: ReadonlyMap<string, readonly FieldPermissionRuleForRole[]>;
|
|
89
98
|
};
|
|
90
99
|
/**
|
|
91
100
|
* Every field on an FLS-enabled entity that the system user cannot fully use.
|
|
@@ -94,6 +103,12 @@ export type SystemUserFieldAccessSweepOptions = {
|
|
|
94
103
|
* while the user cache was cold. Walks loaded metadata only — no queries — and skips entities with
|
|
95
104
|
* field security switched off, which is nearly all of them.
|
|
96
105
|
*
|
|
106
|
+
* With `WithoutRoleID` (the role-removal guard) an entity with field security switched off is
|
|
107
|
+
* judged too, on the fields that carry rules: those rules are dormant, not gone, and apply again
|
|
108
|
+
* the moment field security is re-enabled, so skipping them would let "disable, remove the role,
|
|
109
|
+
* re-enable" strip the system user's access with no refusal anywhere. Such a field is reported
|
|
110
|
+
* only when the removal itself costs the access, never for a shortfall that already existed.
|
|
111
|
+
*
|
|
97
112
|
* @param provider the provider whose metadata to walk
|
|
98
113
|
* @param systemUser the account to check; defaults to the user cache's system user
|
|
99
114
|
* @param options optional projection — see {@link SystemUserFieldAccessSweepOptions}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemUserFieldAccess.d.ts","sourceRoot":"","sources":["../src/systemUserFieldAccess.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EACH,eAAe,EACf,UAAU,EACV,0BAA0B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mC,CAC/C,QAAQ,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EAC9C,UAAU,CAAC,EAAE,QAAQ,GAAG,IAAI,EAC5B,OAAO,GAAE,iCAAsC,GAChD,8BAA8B,EAAE,CAqBlC;AA4ED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAM9E"}
|
|
@@ -65,12 +65,14 @@ import { UserCache } from './UserCache.js';
|
|
|
65
65
|
* @param entity the entity the field belongs to
|
|
66
66
|
* @param field the field whose rules are changing
|
|
67
67
|
* @param projectedRules every rule that would bind to this field after the change
|
|
68
|
+
* @param systemUser the account to check, for callers that read its role set from the database;
|
|
69
|
+
* defaults to the user cache's system user
|
|
68
70
|
*/
|
|
69
|
-
export function SystemUserFieldAccessLossReason(entity, field, projectedRules) {
|
|
71
|
+
export function SystemUserFieldAccessLossReason(entity, field, projectedRules, systemUser) {
|
|
70
72
|
if (!entity || !field) {
|
|
71
73
|
return null;
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
systemUser = systemUser ?? resolveSystemUser();
|
|
74
76
|
if (!systemUser) {
|
|
75
77
|
return null;
|
|
76
78
|
}
|
|
@@ -95,6 +97,12 @@ export function SystemUserFieldAccessLossReason(entity, field, projectedRules) {
|
|
|
95
97
|
* while the user cache was cold. Walks loaded metadata only — no queries — and skips entities with
|
|
96
98
|
* field security switched off, which is nearly all of them.
|
|
97
99
|
*
|
|
100
|
+
* With `WithoutRoleID` (the role-removal guard) an entity with field security switched off is
|
|
101
|
+
* judged too, on the fields that carry rules: those rules are dormant, not gone, and apply again
|
|
102
|
+
* the moment field security is re-enabled, so skipping them would let "disable, remove the role,
|
|
103
|
+
* re-enable" strip the system user's access with no refusal anywhere. Such a field is reported
|
|
104
|
+
* only when the removal itself costs the access, never for a shortfall that already existed.
|
|
105
|
+
*
|
|
98
106
|
* @param provider the provider whose metadata to walk
|
|
99
107
|
* @param systemUser the account to check; defaults to the user cache's system user
|
|
100
108
|
* @param options optional projection — see {@link SystemUserFieldAccessSweepOptions}
|
|
@@ -107,14 +115,12 @@ export function FindSystemUserFieldAccessViolations(provider, systemUser, option
|
|
|
107
115
|
const user = options.WithoutRoleID ? projectUserWithoutRole(resolved, options.WithoutRoleID) : resolved;
|
|
108
116
|
const violations = [];
|
|
109
117
|
for (const entity of provider.Entities ?? []) {
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
const dormant = !entity.EnableFieldLevelSecurity;
|
|
119
|
+
if (dormant && !options.WithoutRoleID) {
|
|
120
|
+
continue; // dormant rules restrict nothing until field security is re-enabled
|
|
112
121
|
}
|
|
113
122
|
for (const field of entity.Fields) {
|
|
114
|
-
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
const lost = lostVerb(entity, field, field.FieldPermissions, user);
|
|
123
|
+
const lost = fieldViolation(entity, field, rulesForField(field, options), user, dormant ? resolved : null);
|
|
118
124
|
if (lost) {
|
|
119
125
|
violations.push({ EntityName: entity.Name, FieldName: field.Name, Verb: lost });
|
|
120
126
|
}
|
|
@@ -122,6 +128,31 @@ export function FindSystemUserFieldAccessViolations(provider, systemUser, option
|
|
|
122
128
|
}
|
|
123
129
|
return violations;
|
|
124
130
|
}
|
|
131
|
+
/** The rules to judge a field by: the caller's stored rules when supplied, else loaded metadata. */
|
|
132
|
+
function rulesForField(field, options) {
|
|
133
|
+
if (!options.RulesByFieldID) {
|
|
134
|
+
return field.FieldPermissions;
|
|
135
|
+
}
|
|
136
|
+
return options.RulesByFieldID.get(String(field.ID ?? '').trim().toLowerCase()) ?? [];
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The verb `user` lacks on one field, or null. For a dormant field (`before` is the user as it is
|
|
140
|
+
* now, before the change being judged) only a field with rules counts, and only when `before`
|
|
141
|
+
* still has that verb, so the change is what costs it.
|
|
142
|
+
*/
|
|
143
|
+
function fieldViolation(entity, field, rules, user, before) {
|
|
144
|
+
if (field.IsUnrestrictableField || field.IsOnUnrestrictableEntity) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
if (before && rules.length === 0) {
|
|
148
|
+
return null; // no dormant rule: re-enabling seeds this field afresh
|
|
149
|
+
}
|
|
150
|
+
const lost = lostVerb(entity, field, rules, user);
|
|
151
|
+
if (!lost || (before && lostVerb(entity, field, rules, before))) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
return lost;
|
|
155
|
+
}
|
|
125
156
|
/**
|
|
126
157
|
* Which verb the system user would lose relative to its ENTITY-level access, or null.
|
|
127
158
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemUserFieldAccess.js","sourceRoot":"","sources":["../src/systemUserFieldAccess.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EACH,eAAe,EAIf,QAAQ,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAY3C
|
|
1
|
+
{"version":3,"file":"systemUserFieldAccess.js","sourceRoot":"","sources":["../src/systemUserFieldAccess.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EACH,eAAe,EAIf,QAAQ,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAY3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,+BAA+B,CAC3C,MAAqC,EACrC,KAAyC,EACzC,cAAqD,EACrD,UAA4B;IAE5B,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,OAAO,IAAI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AO,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAAC,IAAc,EAAE,MAAc;IAC1D,6FAA6F;IAC7F,6CAA6C;IAC7C,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE;QAC3B,GAAG,IAAI;QACP,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjF,CAAC,CAAC;AACP,CAAC;AAED,qEAAqE;AACrE,SAAS,iBAAiB;IACtB,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE,CAAC;IACnD,OAAO,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACjD,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,19 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module @memberjunction/generic-database-provider/types
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* One schema-name to Flyway-placeholder rule for a migration-formatted SQL log. Same shape as
|
|
11
|
+
* `SQLOutput.schemaPlaceholders` in `mj.config.cjs`, so a repo declares the mapping once and
|
|
12
|
+
* CodeGen and the SQL logger read the same array. They apply it differently: CodeGen goes in
|
|
13
|
+
* declared order and needs no `.` after the schema name; the SQL logger needs the `.` and skips a
|
|
14
|
+
* name preceded by a word character, `$`, `@` or `#`.
|
|
15
|
+
*/
|
|
16
|
+
export interface SqlSchemaPlaceholder {
|
|
17
|
+
/** The schema name as it appears in captured SQL, e.g. `__mj_BizAppsAccounting` */
|
|
18
|
+
schema: string;
|
|
19
|
+
/** The placeholder written in its place, e.g. `${flyway:defaultSchema}` or `${mjSchema}` */
|
|
20
|
+
placeholder: string;
|
|
21
|
+
}
|
|
9
22
|
/**
|
|
10
23
|
* Configuration options for SQL logging sessions
|
|
11
24
|
*/
|
|
@@ -15,8 +28,39 @@ export interface SqlLoggingOptions {
|
|
|
15
28
|
/**
|
|
16
29
|
* Optional default schema name to use for Flyway migrations for replacing schema names with
|
|
17
30
|
* the placeholder ${flyway:defaultSchema}
|
|
31
|
+
*
|
|
32
|
+
* Used only when `schemaPlaceholders` is absent or empty.
|
|
18
33
|
*/
|
|
19
34
|
defaultSchemaName?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Schema-to-placeholder rules for migration formatting (#3618). When set, they replace the
|
|
37
|
+
* single `defaultSchemaName` -> `${flyway:defaultSchema}` rewrite.
|
|
38
|
+
*
|
|
39
|
+
* `${flyway:defaultSchema}` is the core schema in MJ's own repo, but in an Open App repo Skyway
|
|
40
|
+
* binds it to the app schema and `${mjSchema}` to core. An Open App therefore supplies both:
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* schemaPlaceholders: [
|
|
44
|
+
* { schema: '__mj_BizAppsAccounting', placeholder: '${flyway:defaultSchema}' },
|
|
45
|
+
* { schema: '__mj', placeholder: '${mjSchema}' },
|
|
46
|
+
* ]
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* The rules run in one pass, so an emitted placeholder is never rewritten again. A schema name
|
|
50
|
+
* is rewritten only when a `.` follows it (optionally after a closing `]`), which also keeps a
|
|
51
|
+
* short rule off the prefix of a longer schema name, and no word character, `$`, `@` or `#`
|
|
52
|
+
* precedes it. Code and string data are treated alike: `__mj.` inside a quoted literal is
|
|
53
|
+
* rewritten; a bare name with no `.` after it is left alone.
|
|
54
|
+
*
|
|
55
|
+
* Ignored unless `formatAsMigration` is true.
|
|
56
|
+
*/
|
|
57
|
+
schemaPlaceholders?: SqlSchemaPlaceholder[];
|
|
58
|
+
/**
|
|
59
|
+
* Escape `${...}` inside SQL string literals so Flyway/Skyway does not read captured data
|
|
60
|
+
* (template text, prompt bodies) as a placeholder. Always on when `formatAsMigration` is true;
|
|
61
|
+
* set it to get the escaping without migration formatting.
|
|
62
|
+
*/
|
|
63
|
+
escapeFlywaySyntax?: boolean;
|
|
20
64
|
/** Optional description to include as a comment at the start of the log */
|
|
21
65
|
description?: string;
|
|
22
66
|
/** Which types of statements to log: 'queries' (all), 'mutations' (only data changes), 'both' (default) */
|
|
@@ -74,8 +118,9 @@ export interface SqlLoggingOptions {
|
|
|
74
118
|
/**
|
|
75
119
|
* Optional rewrite of each logged text before the session reads it: the statement, its simple-SQL
|
|
76
120
|
* fallback, the description and the `-- Parameters:` line. It runs before the verbose prints, the
|
|
77
|
-
* filters, the Flyway escape and the pretty-print, so text it
|
|
78
|
-
* or the console
|
|
121
|
+
* filters, the Flyway escape, the schema-placeholder rewrite and the pretty-print, so text it
|
|
122
|
+
* removes never reaches the log file or the console, and SQL it adds that names a real schema
|
|
123
|
+
* (`[__mj].Entity`) is rewritten to that schema's placeholder like the rest of the statement.
|
|
79
124
|
*
|
|
80
125
|
* It covers only this session's file and verbose prints, plus the provider's shared verbose
|
|
81
126
|
* `Query to log:` print. Other sessions and other output paths do not use it.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5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