@memberjunction/core 6.3.0-edge.1 → 6.3.0-edge.2

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.
Files changed (41) hide show
  1. package/dist/generic/QueryCache.d.ts +2 -2
  2. package/dist/generic/QueryCache.d.ts.map +1 -1
  3. package/dist/generic/QueryCache.js +12 -7
  4. package/dist/generic/QueryCache.js.map +1 -1
  5. package/dist/generic/baseEntity.d.ts +61 -3
  6. package/dist/generic/baseEntity.d.ts.map +1 -1
  7. package/dist/generic/baseEntity.js +54 -0
  8. package/dist/generic/baseEntity.js.map +1 -1
  9. package/dist/generic/databaseProviderBase.d.ts +11 -7
  10. package/dist/generic/databaseProviderBase.d.ts.map +1 -1
  11. package/dist/generic/databaseProviderBase.js +30 -12
  12. package/dist/generic/databaseProviderBase.js.map +1 -1
  13. package/dist/generic/entityInfo.d.ts +9 -2
  14. package/dist/generic/entityInfo.d.ts.map +1 -1
  15. package/dist/generic/entityInfo.js +30 -12
  16. package/dist/generic/entityInfo.js.map +1 -1
  17. package/dist/generic/entityValueFieldSecurity.d.ts.map +1 -1
  18. package/dist/generic/entityValueFieldSecurity.js +1 -0
  19. package/dist/generic/entityValueFieldSecurity.js.map +1 -1
  20. package/dist/generic/limitsConfig.d.ts +577 -0
  21. package/dist/generic/limitsConfig.d.ts.map +1 -0
  22. package/dist/generic/limitsConfig.js +1126 -0
  23. package/dist/generic/limitsConfig.js.map +1 -0
  24. package/dist/generic/providerBase.d.ts +49 -0
  25. package/dist/generic/providerBase.d.ts.map +1 -1
  26. package/dist/generic/providerBase.js +173 -11
  27. package/dist/generic/providerBase.js.map +1 -1
  28. package/dist/generic/securityInfo.d.ts +7 -0
  29. package/dist/generic/securityInfo.d.ts.map +1 -1
  30. package/dist/generic/securityInfo.js +6 -4
  31. package/dist/generic/securityInfo.js.map +1 -1
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +2 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/dist/views/decisionReadGuard.d.ts +143 -0
  38. package/dist/views/decisionReadGuard.d.ts.map +1 -0
  39. package/dist/views/decisionReadGuard.js +220 -0
  40. package/dist/views/decisionReadGuard.js.map +1 -0
  41. package/package.json +3 -3
@@ -0,0 +1,143 @@
1
+ /**
2
+ * @fileoverview Zero silent row-cap truncation guards for decision-critical `RunView` reads.
3
+ *
4
+ * Decision-critical queries (budget ledgers, task-graph scheduling & dependency loading,
5
+ * open-request / consult resolution, name-to-ID metadata resolution) must never silently drop
6
+ * matching rows when `MaxRows` or an entity's `UserViewMaxRows` caps a result set.
7
+ *
8
+ * Uses a single-query sentinel `MaxRows + 1` probe (with `ResultType: 'simple'` by default)
9
+ * or inspects `TotalRowCount` when returned by the provider so overflow is detected in one
10
+ * round-trip without doubling database query quota.
11
+ *
12
+ * @module @memberjunction/core
13
+ */
14
+ import type { RunViewResult } from '../generic/interfaces.js';
15
+ import type { UserInfo } from '../generic/securityInfo.js';
16
+ import { RunView, RunViewParams } from './runView.js';
17
+ /**
18
+ * Strongly-typed scalar union for default `'simple'` decision-read rows without `any` or `unknown`.
19
+ */
20
+ export type DecisionReadScalar = string | number | boolean | Date | null | undefined;
21
+ /**
22
+ * Default plain-object row shape returned when `ExecuteDecisionRead` is called without an
23
+ * explicit row projection interface.
24
+ */
25
+ export type DecisionReadDefaultRow = Record<string, DecisionReadScalar>;
26
+ /**
27
+ * Machine-readable reason explaining how silent row-cap truncation was detected.
28
+ */
29
+ export type DecisionReadTruncationReason = 'SentinelOverflow' | 'TotalRowCountExceedsReturned' | 'AmbiguousMaxRowsBoundary';
30
+ /**
31
+ * Structured truncation metadata attached to {@link RunViewDecisionReadTruncatedError} and
32
+ * failed {@link DecisionReadValidationOutcome} results.
33
+ */
34
+ export interface DecisionReadTruncationDetail {
35
+ EntityName: string;
36
+ OperationName?: string;
37
+ ReturnedRowCount: number;
38
+ MaxRows: number | null;
39
+ TotalRowCount: number | null;
40
+ Reason: DecisionReadTruncationReason;
41
+ Message: string;
42
+ }
43
+ /**
44
+ * Error thrown when a decision-critical `RunView` read encounters row-cap truncation instead
45
+ * of silently operating on an incomplete result set.
46
+ */
47
+ export declare class RunViewDecisionReadTruncatedError extends Error {
48
+ readonly Detail: DecisionReadTruncationDetail;
49
+ constructor(detail: DecisionReadTruncationDetail);
50
+ get EntityName(): string;
51
+ get OperationName(): string | undefined;
52
+ get ReturnedRowCount(): number;
53
+ get MaxRows(): number | null;
54
+ get TotalRowCount(): number | null;
55
+ get Reason(): DecisionReadTruncationReason;
56
+ }
57
+ /**
58
+ * Guard options for validating a `RunViewResult` against silent row-cap truncation.
59
+ */
60
+ export interface DecisionReadGuardOptions {
61
+ /** Target entity name (used in structured diagnostics). */
62
+ EntityName?: string;
63
+ /** Logical caller operation name (used in structured diagnostics). */
64
+ OperationName?: string;
65
+ /** Logical row ceiling expected by the caller. */
66
+ MaxRows?: number | null;
67
+ /** True when the executed query requested `MaxRows + 1` rows as a single-query sentinel probe. */
68
+ UsedSentinelProbe?: boolean;
69
+ }
70
+ /**
71
+ * Options for {@link ExecuteDecisionRead} and {@link ExecuteDecisionReadOrThrow}.
72
+ */
73
+ export interface DecisionReadExecuteOptions extends DecisionReadGuardOptions {
74
+ /**
75
+ * When `true` (the default whenever `MaxRows > 0`), rewrites `MaxRows` to `MaxRows + 1` with
76
+ * `SkipTotalRowCount: true` so truncation is detected in a single SQL query without paying a
77
+ * second `COUNT(*)` query.
78
+ */
79
+ UseSentinelProbe?: boolean;
80
+ }
81
+ /**
82
+ * Parameters accepted by {@link ExecuteDecisionRead}, defaulting `ResultType` to `'simple'`.
83
+ */
84
+ export type DecisionReadParams = Omit<RunViewParams, 'ResultType'> & {
85
+ ResultType?: 'simple' | 'entity_object';
86
+ };
87
+ /**
88
+ * Non-throwing validation outcome returned by {@link ValidateDecisionReadResult} and
89
+ * {@link ExecuteDecisionRead}.
90
+ */
91
+ export type DecisionReadValidationOutcome<T> = {
92
+ Success: true;
93
+ Truncated: false;
94
+ Results: T[];
95
+ RowCount: number;
96
+ TotalRowCount?: number;
97
+ } | {
98
+ Success: false;
99
+ Truncated: boolean;
100
+ ErrorMessage: string;
101
+ TruncationDetail?: DecisionReadTruncationDetail;
102
+ Error: Error;
103
+ };
104
+ /**
105
+ * Builds {@link RunViewParams} configured for decision-read truncation detection using
106
+ * `ResultType: 'simple'` by default and a single-query `MaxRows + 1` sentinel probe when a
107
+ * positive `MaxRows` cap is supplied.
108
+ */
109
+ export declare function BuildDecisionReadParams(params: DecisionReadParams, options?: Pick<DecisionReadExecuteOptions, 'MaxRows' | 'UseSentinelProbe'>): {
110
+ Params: RunViewParams;
111
+ EffectiveMaxRows: number | null;
112
+ UsedSentinelProbe: boolean;
113
+ };
114
+ /**
115
+ * Inspects a completed {@link RunViewResult} for query failure or silent row-cap truncation.
116
+ *
117
+ * Truncation is flagged when:
118
+ * 1. `result.TotalRowCount > result.Results.length` (provider reported more matching rows than returned),
119
+ * 2. `result.Results.length > MaxRows` (single-query `MaxRows + 1` sentinel overflow), or
120
+ * 3. `result.Results.length === MaxRows` without sentinel probing and without `TotalRowCount`
121
+ * (ambiguous boundary where overflow cannot be disproved).
122
+ */
123
+ export declare function ValidateDecisionReadResult<T>(result: RunViewResult<T> | null | undefined, options?: DecisionReadGuardOptions): DecisionReadValidationOutcome<T>;
124
+ /**
125
+ * Asserts that a {@link RunViewResult} succeeded with zero silent row-cap truncation and returns
126
+ * its rows, throwing {@link RunViewDecisionReadTruncatedError} on overflow.
127
+ */
128
+ export declare function AssertRunViewNotTruncated<T>(result: RunViewResult<T> | null | undefined, options?: DecisionReadGuardOptions): T[];
129
+ /**
130
+ * Executes a decision-critical `RunView` read (defaulting to `ResultType: 'simple'`) with
131
+ * automatic single-query sentinel probing when `MaxRows` is set, returning a structured outcome.
132
+ */
133
+ export declare function ExecuteDecisionRead<T extends object = DecisionReadDefaultRow>(rv: RunView, params: DecisionReadParams, contextUser?: UserInfo, options?: DecisionReadExecuteOptions): Promise<DecisionReadValidationOutcome<T>>;
134
+ /**
135
+ * Executes a decision-critical `RunView` read (defaulting to `ResultType: 'simple'`) and throws
136
+ * {@link RunViewDecisionReadTruncatedError} if rows were truncated or `Error` if the query failed.
137
+ */
138
+ export declare function ExecuteDecisionReadOrThrow<T extends object = DecisionReadDefaultRow>(rv: RunView, params: DecisionReadParams, contextUser?: UserInfo, options?: DecisionReadExecuteOptions): Promise<T[]>;
139
+ /**
140
+ * Validates a batch of `RunViews` results against matching {@link DecisionReadGuardOptions}.
141
+ */
142
+ export declare function ValidateDecisionReadBatch<T>(results: ReadonlyArray<RunViewResult<T> | null | undefined>, optionsList: ReadonlyArray<DecisionReadGuardOptions>): DecisionReadValidationOutcome<T>[];
143
+ //# sourceMappingURL=decisionReadGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisionReadGuard.d.ts","sourceRoot":"","sources":["../../src/views/decisionReadGuard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;AAErF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAClC,kBAAkB,GAClB,8BAA8B,GAC9B,0BAA0B,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM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AM,EAAE,kBAAkB,EAC1B,WAAW,CAAC,EAAE,QAAQ,EACtB,OAAO,GAAE,0BAA+B,GACzC,OAAO,CAAC,CAAC,EAAE,CAAC,CAMd;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,EACvC,OAAO,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAC3D,WAAW,EAAE,aAAa,CAAC,wBAAwB,CAAC,GACrD,6BAA6B,CAAC,CAAC,CAAC,EAAE,CAEpC"}
@@ -0,0 +1,220 @@
1
+ /**
2
+ * @fileoverview Zero silent row-cap truncation guards for decision-critical `RunView` reads.
3
+ *
4
+ * Decision-critical queries (budget ledgers, task-graph scheduling & dependency loading,
5
+ * open-request / consult resolution, name-to-ID metadata resolution) must never silently drop
6
+ * matching rows when `MaxRows` or an entity's `UserViewMaxRows` caps a result set.
7
+ *
8
+ * Uses a single-query sentinel `MaxRows + 1` probe (with `ResultType: 'simple'` by default)
9
+ * or inspects `TotalRowCount` when returned by the provider so overflow is detected in one
10
+ * round-trip without doubling database query quota.
11
+ *
12
+ * @module @memberjunction/core
13
+ */
14
+ /**
15
+ * Error thrown when a decision-critical `RunView` read encounters row-cap truncation instead
16
+ * of silently operating on an incomplete result set.
17
+ */
18
+ export class RunViewDecisionReadTruncatedError extends Error {
19
+ constructor(detail) {
20
+ super(detail.Message);
21
+ this.name = 'RunViewDecisionReadTruncatedError';
22
+ this.Detail = detail;
23
+ }
24
+ get EntityName() {
25
+ return this.Detail.EntityName;
26
+ }
27
+ get OperationName() {
28
+ return this.Detail.OperationName;
29
+ }
30
+ get ReturnedRowCount() {
31
+ return this.Detail.ReturnedRowCount;
32
+ }
33
+ get MaxRows() {
34
+ return this.Detail.MaxRows;
35
+ }
36
+ get TotalRowCount() {
37
+ return this.Detail.TotalRowCount;
38
+ }
39
+ get Reason() {
40
+ return this.Detail.Reason;
41
+ }
42
+ }
43
+ function formatDecisionReadLabel(entityName, operationName) {
44
+ return operationName ? `${operationName} (${entityName})` : entityName;
45
+ }
46
+ function buildTruncationDetail(entityName, operationName, returnedRowCount, maxRows, totalRowCount, reason) {
47
+ const label = formatDecisionReadLabel(entityName, operationName);
48
+ let reasonDetail;
49
+ switch (reason) {
50
+ case 'TotalRowCountExceedsReturned':
51
+ reasonDetail = `TotalRowCount (${totalRowCount}) exceeds returned rows (${returnedRowCount})`;
52
+ break;
53
+ case 'SentinelOverflow':
54
+ reasonDetail = `sentinel fetch returned ${returnedRowCount} rows, exceeding MaxRows cap (${maxRows})`;
55
+ break;
56
+ case 'AmbiguousMaxRowsBoundary':
57
+ reasonDetail = `returned ${returnedRowCount} rows matching MaxRows (${maxRows}) without TotalRowCount or sentinel probe`;
58
+ break;
59
+ }
60
+ return {
61
+ EntityName: entityName,
62
+ ...(operationName ? { OperationName: operationName } : {}),
63
+ ReturnedRowCount: returnedRowCount,
64
+ MaxRows: maxRows,
65
+ TotalRowCount: totalRowCount,
66
+ Reason: reason,
67
+ Message: `Decision-critical RunView truncation detected on ${label}: ${reasonDetail}.`,
68
+ };
69
+ }
70
+ function normalizePositiveCap(cap) {
71
+ if (typeof cap !== 'number' || !Number.isFinite(cap) || cap <= 0) {
72
+ return null;
73
+ }
74
+ return Math.trunc(cap);
75
+ }
76
+ /**
77
+ * Builds {@link RunViewParams} configured for decision-read truncation detection using
78
+ * `ResultType: 'simple'` by default and a single-query `MaxRows + 1` sentinel probe when a
79
+ * positive `MaxRows` cap is supplied.
80
+ */
81
+ export function BuildDecisionReadParams(params, options) {
82
+ const effectiveCap = normalizePositiveCap(options?.MaxRows ?? params.MaxRows);
83
+ const useSentinel = effectiveCap !== null && options?.UseSentinelProbe !== false;
84
+ const baseParams = {
85
+ ...params,
86
+ ResultType: params.ResultType ?? 'simple',
87
+ };
88
+ if (useSentinel && effectiveCap !== null) {
89
+ baseParams.MaxRows = effectiveCap + 1;
90
+ baseParams.SkipTotalRowCount = true;
91
+ }
92
+ else if (effectiveCap !== null) {
93
+ baseParams.MaxRows = effectiveCap;
94
+ }
95
+ return {
96
+ Params: baseParams,
97
+ EffectiveMaxRows: effectiveCap,
98
+ UsedSentinelProbe: useSentinel,
99
+ };
100
+ }
101
+ /**
102
+ * Inspects a completed {@link RunViewResult} for query failure or silent row-cap truncation.
103
+ *
104
+ * Truncation is flagged when:
105
+ * 1. `result.TotalRowCount > result.Results.length` (provider reported more matching rows than returned),
106
+ * 2. `result.Results.length > MaxRows` (single-query `MaxRows + 1` sentinel overflow), or
107
+ * 3. `result.Results.length === MaxRows` without sentinel probing and without `TotalRowCount`
108
+ * (ambiguous boundary where overflow cannot be disproved).
109
+ */
110
+ export function ValidateDecisionReadResult(result, options = {}) {
111
+ const entityName = options.EntityName?.trim() || 'UnknownEntity';
112
+ const operationName = options.OperationName?.trim() || undefined;
113
+ const cap = normalizePositiveCap(options.MaxRows);
114
+ const usedSentinelProbe = options.UsedSentinelProbe === true;
115
+ if (!result) {
116
+ const msg = `Decision-critical RunView failed on ${formatDecisionReadLabel(entityName, operationName)}: null or undefined result.`;
117
+ return {
118
+ Success: false,
119
+ Truncated: false,
120
+ ErrorMessage: msg,
121
+ Error: new Error(msg),
122
+ };
123
+ }
124
+ if (!result.Success) {
125
+ const msg = result.ErrorMessage?.trim() ||
126
+ `Decision-critical RunView failed on ${formatDecisionReadLabel(entityName, operationName)}.`;
127
+ return {
128
+ Success: false,
129
+ Truncated: false,
130
+ ErrorMessage: msg,
131
+ Error: new Error(msg),
132
+ };
133
+ }
134
+ const rows = Array.isArray(result.Results) ? result.Results : [];
135
+ const totalRowCount = typeof result.TotalRowCount === 'number' && Number.isFinite(result.TotalRowCount)
136
+ ? result.TotalRowCount
137
+ : null;
138
+ if (totalRowCount !== null && totalRowCount > rows.length) {
139
+ const detail = buildTruncationDetail(entityName, operationName, rows.length, cap, totalRowCount, 'TotalRowCountExceedsReturned');
140
+ return {
141
+ Success: false,
142
+ Truncated: true,
143
+ ErrorMessage: detail.Message,
144
+ TruncationDetail: detail,
145
+ Error: new RunViewDecisionReadTruncatedError(detail),
146
+ };
147
+ }
148
+ if (cap !== null) {
149
+ if (rows.length > cap) {
150
+ const detail = buildTruncationDetail(entityName, operationName, rows.length, cap, totalRowCount, 'SentinelOverflow');
151
+ return {
152
+ Success: false,
153
+ Truncated: true,
154
+ ErrorMessage: detail.Message,
155
+ TruncationDetail: detail,
156
+ Error: new RunViewDecisionReadTruncatedError(detail),
157
+ };
158
+ }
159
+ if (!usedSentinelProbe && rows.length === cap && totalRowCount === null) {
160
+ const detail = buildTruncationDetail(entityName, operationName, rows.length, cap, null, 'AmbiguousMaxRowsBoundary');
161
+ return {
162
+ Success: false,
163
+ Truncated: true,
164
+ ErrorMessage: detail.Message,
165
+ TruncationDetail: detail,
166
+ Error: new RunViewDecisionReadTruncatedError(detail),
167
+ };
168
+ }
169
+ }
170
+ return {
171
+ Success: true,
172
+ Truncated: false,
173
+ Results: rows,
174
+ RowCount: rows.length,
175
+ ...(totalRowCount !== null ? { TotalRowCount: totalRowCount } : {}),
176
+ };
177
+ }
178
+ /**
179
+ * Asserts that a {@link RunViewResult} succeeded with zero silent row-cap truncation and returns
180
+ * its rows, throwing {@link RunViewDecisionReadTruncatedError} on overflow.
181
+ */
182
+ export function AssertRunViewNotTruncated(result, options = {}) {
183
+ const validated = ValidateDecisionReadResult(result, options);
184
+ if ('Error' in validated) {
185
+ throw validated.Error;
186
+ }
187
+ return validated.Results;
188
+ }
189
+ /**
190
+ * Executes a decision-critical `RunView` read (defaulting to `ResultType: 'simple'`) with
191
+ * automatic single-query sentinel probing when `MaxRows` is set, returning a structured outcome.
192
+ */
193
+ export async function ExecuteDecisionRead(rv, params, contextUser, options = {}) {
194
+ const built = BuildDecisionReadParams(params, options);
195
+ const result = await rv.RunView(built.Params, contextUser);
196
+ return ValidateDecisionReadResult(result, {
197
+ EntityName: options.EntityName ?? params.EntityName ?? params.ViewName ?? 'View',
198
+ OperationName: options.OperationName,
199
+ MaxRows: built.EffectiveMaxRows,
200
+ UsedSentinelProbe: built.UsedSentinelProbe,
201
+ });
202
+ }
203
+ /**
204
+ * Executes a decision-critical `RunView` read (defaulting to `ResultType: 'simple'`) and throws
205
+ * {@link RunViewDecisionReadTruncatedError} if rows were truncated or `Error` if the query failed.
206
+ */
207
+ export async function ExecuteDecisionReadOrThrow(rv, params, contextUser, options = {}) {
208
+ const outcome = await ExecuteDecisionRead(rv, params, contextUser, options);
209
+ if ('Error' in outcome) {
210
+ throw outcome.Error;
211
+ }
212
+ return outcome.Results;
213
+ }
214
+ /**
215
+ * Validates a batch of `RunViews` results against matching {@link DecisionReadGuardOptions}.
216
+ */
217
+ export function ValidateDecisionReadBatch(results, optionsList) {
218
+ return optionsList.map((opts, index) => ValidateDecisionReadResult(results[index], opts));
219
+ }
220
+ //# sourceMappingURL=decisionReadGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decisionReadGuard.js","sourceRoot":"","sources":["../../src/views/decisionReadGuard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAuCH;;;GAGG;AACH,MAAM,OAAO,iCAAkC,SAAQ,KAAK;IAGxD,YAAY,MAAoC;QAC5C,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,mCAAmC,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;IAClC,CAAC;IAED,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;IACrC,CAAC;IAED,IAAW,gBAAgB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;IACxC,CAAC;IAED,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,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C,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AAC9F,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/core",
3
3
  "type": "module",
4
- "version": "6.3.0-edge.1",
4
+ "version": "6.3.0-edge.2",
5
5
  "description": "MemberJunction: Core Library including Metadata, Application, Entity Retrieval and Manipulation, and Utilities",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -17,8 +17,8 @@
17
17
  "vitest": "^3.1.1"
18
18
  },
19
19
  "dependencies": {
20
- "@memberjunction/global": "6.3.0-edge.1",
21
- "@memberjunction/sql-dialect": "6.3.0-edge.1",
20
+ "@memberjunction/global": "6.3.0-edge.2",
21
+ "@memberjunction/sql-dialect": "6.3.0-edge.2",
22
22
  "rxjs": "^7.8.2",
23
23
  "zod": "^3.25.0",
24
24
  "debug": "^4.4.3"