@memberjunction/core-entities-server 5.13.0 → 5.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/custom/MJQueryEntityServer.server.d.ts +22 -1
- package/dist/custom/MJQueryEntityServer.server.d.ts.map +1 -1
- package/dist/custom/MJQueryEntityServer.server.js +120 -86
- package/dist/custom/MJQueryEntityServer.server.js.map +1 -1
- package/dist/engines/QueryEngineServer.d.ts +117 -0
- package/dist/engines/QueryEngineServer.d.ts.map +1 -0
- package/dist/engines/QueryEngineServer.js +251 -0
- package/dist/engines/QueryEngineServer.js.map +1 -0
- package/dist/engines/QueryMatchResult.d.ts +55 -0
- package/dist/engines/QueryMatchResult.d.ts.map +1 -0
- package/dist/engines/QueryMatchResult.js +2 -0
- package/dist/engines/QueryMatchResult.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +20 -18
- package/dist/custom/sql-parser.d.ts +0 -95
- package/dist/custom/sql-parser.d.ts.map +0 -1
- package/dist/custom/sql-parser.js +0 -313
- package/dist/custom/sql-parser.js.map +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { BaseSingleton } from '@memberjunction/global';
|
|
2
|
+
import { UserInfo, IMetadataProvider } from '@memberjunction/core';
|
|
3
|
+
import { QueryEngine } from '@memberjunction/core-entities';
|
|
4
|
+
import { SimpleVectorService } from '@memberjunction/ai-vectors-memory';
|
|
5
|
+
import { EmbedTextResult } from '@memberjunction/ai';
|
|
6
|
+
import { MJAIModelEntityExtended } from '@memberjunction/ai-core-plus';
|
|
7
|
+
import { MJQueryEntity, MJQueryCategoryEntity, MJQueryFieldEntity, MJQueryParameterEntity, MJQueryEntityEntity, MJQueryPermissionEntity } from '@memberjunction/core-entities';
|
|
8
|
+
import { QueryEmbeddingMetadata, QueryMatchResult } from './QueryMatchResult.js';
|
|
9
|
+
/**
|
|
10
|
+
* Server-side Query Engine that wraps QueryEngine and adds server-only capabilities.
|
|
11
|
+
*
|
|
12
|
+
* Uses composition (containment) rather than inheritance to avoid duplicate
|
|
13
|
+
* data loading. Delegates all base functionality to QueryEngine.Instance while
|
|
14
|
+
* adding server-specific features like embedding-based semantic search.
|
|
15
|
+
*
|
|
16
|
+
* Follows the same pattern as AIEngine containing AIEngineBase.
|
|
17
|
+
*
|
|
18
|
+
* @description ONLY USE ON SERVER-SIDE. For metadata only, use the QueryEngine class which can be used anywhere.
|
|
19
|
+
*/
|
|
20
|
+
export declare class QueryEngineServer extends BaseSingleton<QueryEngineServer> {
|
|
21
|
+
protected constructor();
|
|
22
|
+
static get Instance(): QueryEngineServer;
|
|
23
|
+
protected get Base(): QueryEngine;
|
|
24
|
+
private _queryVectorService;
|
|
25
|
+
private _loaded;
|
|
26
|
+
private _loading;
|
|
27
|
+
private _loadingPromise;
|
|
28
|
+
private _contextUser;
|
|
29
|
+
private _dataChangeSubscription;
|
|
30
|
+
/** All queries in the system */
|
|
31
|
+
get Queries(): MJQueryEntity[];
|
|
32
|
+
/** All query categories */
|
|
33
|
+
get Categories(): MJQueryCategoryEntity[];
|
|
34
|
+
/** All query field definitions */
|
|
35
|
+
get Fields(): MJQueryFieldEntity[];
|
|
36
|
+
/** All query parameter definitions */
|
|
37
|
+
get Parameters(): MJQueryParameterEntity[];
|
|
38
|
+
/** All query-to-entity relationship mappings */
|
|
39
|
+
get QueryEntities(): MJQueryEntityEntity[];
|
|
40
|
+
/** All query permission records */
|
|
41
|
+
get Permissions(): MJQueryPermissionEntity[];
|
|
42
|
+
/** Returns only queries with Status === 'Approved' */
|
|
43
|
+
get ApprovedQueries(): MJQueryEntity[];
|
|
44
|
+
/** Find a query by its ID */
|
|
45
|
+
FindQueryByID(id: string): MJQueryEntity | undefined;
|
|
46
|
+
/** Find a query by name, optionally scoped to a category */
|
|
47
|
+
FindQueryByName(name: string, categoryId?: string): MJQueryEntity | undefined;
|
|
48
|
+
/** Get all field definitions for a specific query */
|
|
49
|
+
GetQueryFields(queryId: string): MJQueryFieldEntity[];
|
|
50
|
+
/** Get all parameter definitions for a specific query */
|
|
51
|
+
GetQueryParameters(queryId: string): MJQueryParameterEntity[];
|
|
52
|
+
/** Get all permission records for a specific query */
|
|
53
|
+
GetQueryPermissions(queryId: string): MJQueryPermissionEntity[];
|
|
54
|
+
/** Get all queries belonging to a specific category */
|
|
55
|
+
GetQueriesByCategory(categoryId: string): MJQueryEntity[];
|
|
56
|
+
/** Find a category by name (case-insensitive) */
|
|
57
|
+
FindCategory(name: string): MJQueryCategoryEntity | undefined;
|
|
58
|
+
/** Returns true if both the base engine and server capabilities are loaded */
|
|
59
|
+
get Loaded(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Get the query vector service for semantic search.
|
|
62
|
+
* Initialized during Config — will be null before Config() completes.
|
|
63
|
+
*/
|
|
64
|
+
get QueryVectorService(): SimpleVectorService<QueryEmbeddingMetadata> | null;
|
|
65
|
+
/**
|
|
66
|
+
* Configures the QueryEngineServer by first ensuring QueryEngine is configured,
|
|
67
|
+
* then building the in-memory vector index from cached query embeddings.
|
|
68
|
+
*
|
|
69
|
+
* Safe to call from multiple places concurrently — returns the same promise
|
|
70
|
+
* to all callers during loading.
|
|
71
|
+
*
|
|
72
|
+
* @param forceRefresh - If true, forces a full reload even if already loaded
|
|
73
|
+
* @param contextUser - User context for server-side operations
|
|
74
|
+
* @param provider - Optional metadata provider override
|
|
75
|
+
*/
|
|
76
|
+
Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
|
|
77
|
+
private InnerLoad;
|
|
78
|
+
/**
|
|
79
|
+
* Rebuilds the in-memory vector index from QueryEngine's cached queries.
|
|
80
|
+
* This is a synchronous, in-memory-only operation — no database call.
|
|
81
|
+
*
|
|
82
|
+
* Called automatically on Config() and whenever QueryEngine emits a
|
|
83
|
+
* DataChange$ event for the 'MJ: Queries' entity.
|
|
84
|
+
*/
|
|
85
|
+
RefreshQueryEmbeddings(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Packages a query entity into the metadata shape stored in the vector service.
|
|
88
|
+
*/
|
|
89
|
+
protected PackageQueryMetadata(query: MJQueryEntity): QueryEmbeddingMetadata;
|
|
90
|
+
/**
|
|
91
|
+
* Subscribes (once) to QueryEngine.DataChange$ so the vector index stays
|
|
92
|
+
* in sync whenever queries are added, updated, or deleted.
|
|
93
|
+
*
|
|
94
|
+
* BaseEngine's auto-refresh already debounces entity events (default 5000ms).
|
|
95
|
+
* By the time DataChange$ fires, this.Base.Queries is already updated.
|
|
96
|
+
*/
|
|
97
|
+
private SubscribeToDataChanges;
|
|
98
|
+
/**
|
|
99
|
+
* Find queries semantically similar to a natural language search text.
|
|
100
|
+
*
|
|
101
|
+
* Uses the persistent in-memory vector index built from QueryEngine's
|
|
102
|
+
* cached query data. Supports an optional metadata filter callback for
|
|
103
|
+
* filtering by status, reusable flag, etc. at search time.
|
|
104
|
+
*
|
|
105
|
+
* @param searchText - Natural language description of what data is needed
|
|
106
|
+
* @param embedFunction - Function to generate embeddings (typically from AIEngine.EmbedTextLocal)
|
|
107
|
+
* @param topK - Maximum number of results to return (default: 10)
|
|
108
|
+
* @param minSimilarity - Minimum similarity score 0-1 (default: 0.3)
|
|
109
|
+
* @param filter - Optional filter callback applied to metadata before similarity scoring
|
|
110
|
+
* @returns Array of matching queries sorted by similarity score (highest first)
|
|
111
|
+
*/
|
|
112
|
+
FindSimilarQueries(searchText: string, embedFunction: (text: string) => Promise<{
|
|
113
|
+
result: EmbedTextResult;
|
|
114
|
+
model: MJAIModelEntityExtended;
|
|
115
|
+
} | null>, topK?: number, minSimilarity?: number, filter?: (metadata: QueryEmbeddingMetadata) => boolean): Promise<QueryMatchResult[]>;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=QueryEngineServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryEngineServer.d.ts","sourceR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AAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,uBAAuB,CAAA;KAAE,GAAG,IAAI,CAAC,EAC5G,IAAI,GAAE,MAAW,EACjB,aAAa,GAAE,MAAY,EAC3B,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,OAAO,GACvD,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAiCjC"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { BaseSingleton } from '@memberjunction/global';
|
|
2
|
+
import { LogError, LogStatus } from '@memberjunction/core';
|
|
3
|
+
import { QueryEngine } from '@memberjunction/core-entities';
|
|
4
|
+
import { SimpleVectorService } from '@memberjunction/ai-vectors-memory';
|
|
5
|
+
/**
|
|
6
|
+
* Server-side Query Engine that wraps QueryEngine and adds server-only capabilities.
|
|
7
|
+
*
|
|
8
|
+
* Uses composition (containment) rather than inheritance to avoid duplicate
|
|
9
|
+
* data loading. Delegates all base functionality to QueryEngine.Instance while
|
|
10
|
+
* adding server-specific features like embedding-based semantic search.
|
|
11
|
+
*
|
|
12
|
+
* Follows the same pattern as AIEngine containing AIEngineBase.
|
|
13
|
+
*
|
|
14
|
+
* @description ONLY USE ON SERVER-SIDE. For metadata only, use the QueryEngine class which can be used anywhere.
|
|
15
|
+
*/
|
|
16
|
+
export class QueryEngineServer extends BaseSingleton {
|
|
17
|
+
// --- Singleton ---
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
// --- Server-specific state ---
|
|
21
|
+
this._queryVectorService = null;
|
|
22
|
+
this._loaded = false;
|
|
23
|
+
this._loading = false;
|
|
24
|
+
this._loadingPromise = null;
|
|
25
|
+
this._dataChangeSubscription = null;
|
|
26
|
+
}
|
|
27
|
+
static get Instance() {
|
|
28
|
+
return super.getInstance();
|
|
29
|
+
}
|
|
30
|
+
// --- Containment ---
|
|
31
|
+
get Base() {
|
|
32
|
+
return QueryEngine.Instance;
|
|
33
|
+
}
|
|
34
|
+
// ========================================================================
|
|
35
|
+
// Delegated Properties from QueryEngine
|
|
36
|
+
// ========================================================================
|
|
37
|
+
/** All queries in the system */
|
|
38
|
+
get Queries() { return this.Base.Queries; }
|
|
39
|
+
/** All query categories */
|
|
40
|
+
get Categories() { return this.Base.Categories; }
|
|
41
|
+
/** All query field definitions */
|
|
42
|
+
get Fields() { return this.Base.Fields; }
|
|
43
|
+
/** All query parameter definitions */
|
|
44
|
+
get Parameters() { return this.Base.Parameters; }
|
|
45
|
+
/** All query-to-entity relationship mappings */
|
|
46
|
+
get QueryEntities() { return this.Base.QueryEntities; }
|
|
47
|
+
/** All query permission records */
|
|
48
|
+
get Permissions() { return this.Base.Permissions; }
|
|
49
|
+
/** Returns only queries with Status === 'Approved' */
|
|
50
|
+
get ApprovedQueries() { return this.Base.ApprovedQueries; }
|
|
51
|
+
// --- Delegated methods ---
|
|
52
|
+
/** Find a query by its ID */
|
|
53
|
+
FindQueryByID(id) {
|
|
54
|
+
return this.Base.FindQueryByID(id);
|
|
55
|
+
}
|
|
56
|
+
/** Find a query by name, optionally scoped to a category */
|
|
57
|
+
FindQueryByName(name, categoryId) {
|
|
58
|
+
return this.Base.FindQueryByName(name, categoryId);
|
|
59
|
+
}
|
|
60
|
+
/** Get all field definitions for a specific query */
|
|
61
|
+
GetQueryFields(queryId) {
|
|
62
|
+
return this.Base.GetQueryFields(queryId);
|
|
63
|
+
}
|
|
64
|
+
/** Get all parameter definitions for a specific query */
|
|
65
|
+
GetQueryParameters(queryId) {
|
|
66
|
+
return this.Base.GetQueryParameters(queryId);
|
|
67
|
+
}
|
|
68
|
+
/** Get all permission records for a specific query */
|
|
69
|
+
GetQueryPermissions(queryId) {
|
|
70
|
+
return this.Base.GetQueryPermissions(queryId);
|
|
71
|
+
}
|
|
72
|
+
/** Get all queries belonging to a specific category */
|
|
73
|
+
GetQueriesByCategory(categoryId) {
|
|
74
|
+
return this.Base.GetQueriesByCategory(categoryId);
|
|
75
|
+
}
|
|
76
|
+
/** Find a category by name (case-insensitive) */
|
|
77
|
+
FindCategory(name) {
|
|
78
|
+
return this.Base.FindCategory(name);
|
|
79
|
+
}
|
|
80
|
+
// ========================================================================
|
|
81
|
+
// Server-Only Properties
|
|
82
|
+
// ========================================================================
|
|
83
|
+
/** Returns true if both the base engine and server capabilities are loaded */
|
|
84
|
+
get Loaded() {
|
|
85
|
+
return this._loaded;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the query vector service for semantic search.
|
|
89
|
+
* Initialized during Config — will be null before Config() completes.
|
|
90
|
+
*/
|
|
91
|
+
get QueryVectorService() {
|
|
92
|
+
return this._queryVectorService;
|
|
93
|
+
}
|
|
94
|
+
// ========================================================================
|
|
95
|
+
// Config — Main Entry Point
|
|
96
|
+
// ========================================================================
|
|
97
|
+
/**
|
|
98
|
+
* Configures the QueryEngineServer by first ensuring QueryEngine is configured,
|
|
99
|
+
* then building the in-memory vector index from cached query embeddings.
|
|
100
|
+
*
|
|
101
|
+
* Safe to call from multiple places concurrently — returns the same promise
|
|
102
|
+
* to all callers during loading.
|
|
103
|
+
*
|
|
104
|
+
* @param forceRefresh - If true, forces a full reload even if already loaded
|
|
105
|
+
* @param contextUser - User context for server-side operations
|
|
106
|
+
* @param provider - Optional metadata provider override
|
|
107
|
+
*/
|
|
108
|
+
async Config(forceRefresh, contextUser, provider) {
|
|
109
|
+
if (this._loaded && !forceRefresh)
|
|
110
|
+
return;
|
|
111
|
+
if (this._loading && this._loadingPromise)
|
|
112
|
+
return this._loadingPromise;
|
|
113
|
+
this._loading = true;
|
|
114
|
+
this._loadingPromise = this.InnerLoad(forceRefresh, contextUser, provider);
|
|
115
|
+
try {
|
|
116
|
+
await this._loadingPromise;
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
this._loading = false;
|
|
120
|
+
this._loadingPromise = null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async InnerLoad(forceRefresh, contextUser, provider) {
|
|
124
|
+
try {
|
|
125
|
+
this._contextUser = contextUser;
|
|
126
|
+
// 1. Ensure QueryEngine (the base) is configured first
|
|
127
|
+
await QueryEngine.Instance.Config(forceRefresh, contextUser, provider);
|
|
128
|
+
// 2. Build vector index from already-loaded queries (NO RunView)
|
|
129
|
+
this.RefreshQueryEmbeddings();
|
|
130
|
+
// 3. Subscribe to DataChange$ for ongoing updates (only once)
|
|
131
|
+
this.SubscribeToDataChanges();
|
|
132
|
+
this._loaded = true;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
LogError(error);
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// ========================================================================
|
|
140
|
+
// Embedding Management
|
|
141
|
+
// ========================================================================
|
|
142
|
+
/**
|
|
143
|
+
* Rebuilds the in-memory vector index from QueryEngine's cached queries.
|
|
144
|
+
* This is a synchronous, in-memory-only operation — no database call.
|
|
145
|
+
*
|
|
146
|
+
* Called automatically on Config() and whenever QueryEngine emits a
|
|
147
|
+
* DataChange$ event for the 'MJ: Queries' entity.
|
|
148
|
+
*/
|
|
149
|
+
RefreshQueryEmbeddings() {
|
|
150
|
+
const queries = this.Base.Queries;
|
|
151
|
+
const entries = [];
|
|
152
|
+
for (const query of queries) {
|
|
153
|
+
if (!query.EmbeddingVector)
|
|
154
|
+
continue;
|
|
155
|
+
try {
|
|
156
|
+
const vector = JSON.parse(query.EmbeddingVector);
|
|
157
|
+
if (!Array.isArray(vector) || vector.length === 0)
|
|
158
|
+
continue;
|
|
159
|
+
entries.push({
|
|
160
|
+
key: query.ID,
|
|
161
|
+
vector,
|
|
162
|
+
metadata: this.PackageQueryMetadata(query)
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
LogError(`QueryEngineServer: Failed to parse embedding for query ${query.Name}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
this._queryVectorService = new SimpleVectorService();
|
|
170
|
+
if (entries.length > 0) {
|
|
171
|
+
this._queryVectorService.LoadVectors(entries);
|
|
172
|
+
}
|
|
173
|
+
LogStatus(`QueryEngineServer: Loaded ${entries.length} query embeddings from cached queries`);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Packages a query entity into the metadata shape stored in the vector service.
|
|
177
|
+
*/
|
|
178
|
+
PackageQueryMetadata(query) {
|
|
179
|
+
return {
|
|
180
|
+
id: query.ID,
|
|
181
|
+
name: query.Name,
|
|
182
|
+
description: query.Description || '',
|
|
183
|
+
category: query.Category || '',
|
|
184
|
+
status: query.Status || '',
|
|
185
|
+
reusable: query.Reusable ?? false,
|
|
186
|
+
sql: query.SQL || '',
|
|
187
|
+
userQuestion: query.UserQuestion || ''
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// ========================================================================
|
|
191
|
+
// DataChange$ Subscription
|
|
192
|
+
// ========================================================================
|
|
193
|
+
/**
|
|
194
|
+
* Subscribes (once) to QueryEngine.DataChange$ so the vector index stays
|
|
195
|
+
* in sync whenever queries are added, updated, or deleted.
|
|
196
|
+
*
|
|
197
|
+
* BaseEngine's auto-refresh already debounces entity events (default 5000ms).
|
|
198
|
+
* By the time DataChange$ fires, this.Base.Queries is already updated.
|
|
199
|
+
*/
|
|
200
|
+
SubscribeToDataChanges() {
|
|
201
|
+
if (this._dataChangeSubscription)
|
|
202
|
+
return;
|
|
203
|
+
this._dataChangeSubscription = this.Base.DataChange$.subscribe(event => {
|
|
204
|
+
if (event.config.EntityName === 'MJ: Queries') {
|
|
205
|
+
this.RefreshQueryEmbeddings();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// ========================================================================
|
|
210
|
+
// Semantic Search
|
|
211
|
+
// ========================================================================
|
|
212
|
+
/**
|
|
213
|
+
* Find queries semantically similar to a natural language search text.
|
|
214
|
+
*
|
|
215
|
+
* Uses the persistent in-memory vector index built from QueryEngine's
|
|
216
|
+
* cached query data. Supports an optional metadata filter callback for
|
|
217
|
+
* filtering by status, reusable flag, etc. at search time.
|
|
218
|
+
*
|
|
219
|
+
* @param searchText - Natural language description of what data is needed
|
|
220
|
+
* @param embedFunction - Function to generate embeddings (typically from AIEngine.EmbedTextLocal)
|
|
221
|
+
* @param topK - Maximum number of results to return (default: 10)
|
|
222
|
+
* @param minSimilarity - Minimum similarity score 0-1 (default: 0.3)
|
|
223
|
+
* @param filter - Optional filter callback applied to metadata before similarity scoring
|
|
224
|
+
* @returns Array of matching queries sorted by similarity score (highest first)
|
|
225
|
+
*/
|
|
226
|
+
async FindSimilarQueries(searchText, embedFunction, topK = 10, minSimilarity = 0.3, filter) {
|
|
227
|
+
if (!searchText || searchText.trim().length === 0) {
|
|
228
|
+
throw new Error('searchText cannot be empty');
|
|
229
|
+
}
|
|
230
|
+
if (!this._queryVectorService) {
|
|
231
|
+
throw new Error('QueryEngineServer not configured. Call Config() first.');
|
|
232
|
+
}
|
|
233
|
+
const embedding = await embedFunction(searchText);
|
|
234
|
+
if (!embedding?.result?.vector?.length) {
|
|
235
|
+
throw new Error('Failed to generate embedding for search text');
|
|
236
|
+
}
|
|
237
|
+
const results = this._queryVectorService.FindNearest(embedding.result.vector, topK, minSimilarity, 'cosine', filter);
|
|
238
|
+
return results.map(r => ({
|
|
239
|
+
queryId: r.key,
|
|
240
|
+
queryName: r.metadata?.name || 'Unknown',
|
|
241
|
+
description: r.metadata?.description || '',
|
|
242
|
+
category: r.metadata?.category || '',
|
|
243
|
+
similarityScore: r.score,
|
|
244
|
+
status: r.metadata?.status || '',
|
|
245
|
+
reusable: r.metadata?.reusable ?? false,
|
|
246
|
+
sql: r.metadata?.sql,
|
|
247
|
+
userQuestion: r.metadata?.userQuestion
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=QueryEngineServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryEngineServer.js","sourceRoot":"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AAW,CAChD,SAAS,CAAC,MAAM,CAAC,MAAM,EACvB,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,MAAM,CACT,CAAC;QAEF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACrB,OAAO,EAAE,CAAC,CAAC,GAAG;YACd,SAAS,EAAE,CAAC,CAAC,QAAQ,EAAE,IAAI,IAAI,SAAS;YACxC,WAAW,EAAE,CAAC,CAAC,QAAQ,EAAE,WAAW,IAAI,EAAE;YAC1C,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE;YACpC,eAAe,EAAE,CAAC,CAAC,KAAK;YACxB,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE;YAChC,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,QAAQ,IAAI,KAAK;YACvC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,GAAG;YACpB,YAAY,EAAE,CAAC,CAAC,QAAQ,EAAE,YAAY;SACzC,CAAC,CAAC,CAAC;IACR,CAAC;CACJ"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata about a query for embedding purposes
|
|
3
|
+
*/
|
|
4
|
+
export interface QueryEmbeddingMetadata {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
category: string;
|
|
9
|
+
status: string;
|
|
10
|
+
reusable: boolean;
|
|
11
|
+
sql: string;
|
|
12
|
+
userQuestion: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result from query similarity matching
|
|
16
|
+
*/
|
|
17
|
+
export interface QueryMatchResult {
|
|
18
|
+
/**
|
|
19
|
+
* The query's unique ID
|
|
20
|
+
*/
|
|
21
|
+
queryId: string;
|
|
22
|
+
/**
|
|
23
|
+
* The query's name
|
|
24
|
+
*/
|
|
25
|
+
queryName: string;
|
|
26
|
+
/**
|
|
27
|
+
* The query's description
|
|
28
|
+
*/
|
|
29
|
+
description: string;
|
|
30
|
+
/**
|
|
31
|
+
* The query's category name
|
|
32
|
+
*/
|
|
33
|
+
category: string;
|
|
34
|
+
/**
|
|
35
|
+
* Cosine similarity score (0-1, where 1 = perfect match)
|
|
36
|
+
*/
|
|
37
|
+
similarityScore: number;
|
|
38
|
+
/**
|
|
39
|
+
* Query status (Approved, Pending, etc.)
|
|
40
|
+
*/
|
|
41
|
+
status: string;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the query is marked as reusable for composition
|
|
44
|
+
*/
|
|
45
|
+
reusable: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The query's SQL (only populated when requested)
|
|
48
|
+
*/
|
|
49
|
+
sql?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The natural language question this query answers
|
|
52
|
+
*/
|
|
53
|
+
userQuestion?: string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=QueryMatchResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryMatchResult.d.ts","sourceRoot":"","sources":["../../src/engines/QueryMatchResult.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryMatchResult.js","sourceRoot":"","sources":["../../src/engines/QueryMatchResult.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ export * from './custom/MJArtifactVersionEntityServer.server.js';
|
|
|
13
13
|
export * from './custom/MJAIAgentNoteEntityServer.server.js';
|
|
14
14
|
export * from './custom/MJAIAgentExampleEntityServer.server.js';
|
|
15
15
|
export * from './custom/util.js';
|
|
16
|
-
export * from './
|
|
16
|
+
export * from './engines/QueryEngineServer.js';
|
|
17
|
+
export * from './engines/QueryMatchResult.js';
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,eAAe,CAAC;AAE9B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,5 +13,6 @@ export * from './custom/MJArtifactVersionEntityServer.server.js';
|
|
|
13
13
|
export * from './custom/MJAIAgentNoteEntityServer.server.js';
|
|
14
14
|
export * from './custom/MJAIAgentExampleEntityServer.server.js';
|
|
15
15
|
export * from './custom/util.js';
|
|
16
|
-
export * from './
|
|
16
|
+
export * from './engines/QueryEngineServer.js';
|
|
17
|
+
export * from './engines/QueryMatchResult.js';
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,eAAe,CAAC;AAE9B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/core-entities-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.15.0",
|
|
5
5
|
"description": "Entity subclasses for the metadata layer of MemberJunction that are only used on server side applications like MJAPI, distributed as part of each release of MemberJunction",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -21,23 +21,25 @@
|
|
|
21
21
|
"typescript": "^5.9.3"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@memberjunction/actions-base": "5.
|
|
25
|
-
"@memberjunction/ai": "5.
|
|
26
|
-
"@memberjunction/ai-core-plus": "5.
|
|
27
|
-
"@memberjunction/ai-engine-base": "5.
|
|
28
|
-
"@memberjunction/ai-prompts": "5.
|
|
29
|
-
"@memberjunction/ai-provider-bundle": "5.
|
|
30
|
-
"@memberjunction/ai-vector-dupe": "5.
|
|
31
|
-
"@memberjunction/
|
|
32
|
-
"@memberjunction/
|
|
33
|
-
"@memberjunction/core
|
|
34
|
-
"@memberjunction/
|
|
35
|
-
"@memberjunction/
|
|
36
|
-
"@memberjunction/
|
|
37
|
-
"@memberjunction/
|
|
38
|
-
"@memberjunction/
|
|
39
|
-
"
|
|
40
|
-
"
|
|
24
|
+
"@memberjunction/actions-base": "5.15.0",
|
|
25
|
+
"@memberjunction/ai": "5.15.0",
|
|
26
|
+
"@memberjunction/ai-core-plus": "5.15.0",
|
|
27
|
+
"@memberjunction/ai-engine-base": "5.15.0",
|
|
28
|
+
"@memberjunction/ai-prompts": "5.15.0",
|
|
29
|
+
"@memberjunction/ai-provider-bundle": "5.15.0",
|
|
30
|
+
"@memberjunction/ai-vector-dupe": "5.15.0",
|
|
31
|
+
"@memberjunction/ai-vectors-memory": "5.15.0",
|
|
32
|
+
"@memberjunction/aiengine": "5.15.0",
|
|
33
|
+
"@memberjunction/core": "5.15.0",
|
|
34
|
+
"@memberjunction/core-entities": "5.15.0",
|
|
35
|
+
"@memberjunction/generic-database-provider": "5.15.0",
|
|
36
|
+
"@memberjunction/doc-utils": "5.15.0",
|
|
37
|
+
"@memberjunction/global": "5.15.0",
|
|
38
|
+
"@memberjunction/skip-types": "5.15.0",
|
|
39
|
+
"@memberjunction/sql-converter": "5.15.0",
|
|
40
|
+
"@memberjunction/sql-parser": "5.15.0",
|
|
41
|
+
"@memberjunction/sqlserver-dataprovider": "5.15.0",
|
|
42
|
+
"rxjs": "~7.8.1",
|
|
41
43
|
"zod": "~3.24.4"
|
|
42
44
|
},
|
|
43
45
|
"repository": {
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A single table/view reference extracted from SQL.
|
|
3
|
-
*/
|
|
4
|
-
export interface SQLTableReference {
|
|
5
|
-
/** The table or view name as it appears in SQL */
|
|
6
|
-
TableName: string;
|
|
7
|
-
/** The schema name, defaults to 'dbo' if unspecified */
|
|
8
|
-
SchemaName: string;
|
|
9
|
-
/** The alias used in the query, or the table name if no alias */
|
|
10
|
-
Alias: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A column reference extracted from SQL expressions.
|
|
14
|
-
*/
|
|
15
|
-
export interface SQLColumnReference {
|
|
16
|
-
/** Column name */
|
|
17
|
-
ColumnName: string;
|
|
18
|
-
/** Table alias or name prefix, if qualified (e.g. "t" in "t.Name") */
|
|
19
|
-
TableQualifier: string | null;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Complete result of parsing a SQL statement for table and column references.
|
|
23
|
-
*/
|
|
24
|
-
export interface SQLParseResult {
|
|
25
|
-
/** All table/view references found (FROM, JOIN, subqueries, CTEs) */
|
|
26
|
-
Tables: SQLTableReference[];
|
|
27
|
-
/** All column references found (SELECT, WHERE, JOIN ON, GROUP BY, ORDER BY) */
|
|
28
|
-
Columns: SQLColumnReference[];
|
|
29
|
-
/** Whether parsing succeeded via AST (true) or fell back to regex (false) */
|
|
30
|
-
UsedASTParsing: boolean;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Reusable SQL parsing utility that extracts table/view references and column references
|
|
34
|
-
* from SQL statements using node-sql-parser with a regex fallback.
|
|
35
|
-
*
|
|
36
|
-
* This class has no dependency on MJ Metadata — it returns raw parse results.
|
|
37
|
-
* Callers are responsible for cross-referencing against entity metadata.
|
|
38
|
-
*/
|
|
39
|
-
export declare class SQLParser {
|
|
40
|
-
/**
|
|
41
|
-
* Parse a plain SQL statement and extract all table and column references.
|
|
42
|
-
* Uses AST parsing with TransactSQL dialect, falls back to regex on failure.
|
|
43
|
-
*/
|
|
44
|
-
static Parse(sql: string): SQLParseResult;
|
|
45
|
-
/**
|
|
46
|
-
* Parse a SQL statement that may contain Nunjucks template syntax.
|
|
47
|
-
* Pre-processes templates into valid SQL before parsing.
|
|
48
|
-
*/
|
|
49
|
-
static ParseWithTemplatePreprocessing(sql: string): SQLParseResult;
|
|
50
|
-
/**
|
|
51
|
-
* Attempt to parse SQL via node-sql-parser AST.
|
|
52
|
-
* Returns null if parsing fails (caller should fall back to regex).
|
|
53
|
-
*/
|
|
54
|
-
private static ParseViaAST;
|
|
55
|
-
/**
|
|
56
|
-
* Regex-based fallback for extracting table references from SQL.
|
|
57
|
-
* Less accurate than AST but handles edge cases where the parser fails.
|
|
58
|
-
*/
|
|
59
|
-
private static ParseViaRegex;
|
|
60
|
-
/**
|
|
61
|
-
* Converts internal maps into the public SQLParseResult shape.
|
|
62
|
-
*/
|
|
63
|
-
private static BuildResult;
|
|
64
|
-
/**
|
|
65
|
-
* Deduplicates table references by schema.table key, keeping distinct entries.
|
|
66
|
-
*/
|
|
67
|
-
private static DeduplicateTables;
|
|
68
|
-
/**
|
|
69
|
-
* Converts raw column reference strings into structured SQLColumnReference objects.
|
|
70
|
-
*/
|
|
71
|
-
private static ParseColumnRefs;
|
|
72
|
-
/**
|
|
73
|
-
* Recursively extracts table references and column references from SQL AST.
|
|
74
|
-
*/
|
|
75
|
-
private static ExtractFromAST;
|
|
76
|
-
/**
|
|
77
|
-
* Extracts table information from a FROM clause item, handling tables and JOINs.
|
|
78
|
-
*/
|
|
79
|
-
private static ExtractTableFromItem;
|
|
80
|
-
/**
|
|
81
|
-
* Extracts column references from an expression node.
|
|
82
|
-
* Also extracts tables from subqueries found in expressions (e.g., EXISTS, IN).
|
|
83
|
-
*/
|
|
84
|
-
private static ExtractColumnReferences;
|
|
85
|
-
/**
|
|
86
|
-
* Pre-processes Nunjucks templates in SQL to create valid SQL for parsing.
|
|
87
|
-
* Replaces Nunjucks syntax with placeholder values.
|
|
88
|
-
*/
|
|
89
|
-
private static PreProcessNunjucksForParsing;
|
|
90
|
-
/**
|
|
91
|
-
* Regex fallback for Nunjucks preprocessing when rendering fails.
|
|
92
|
-
*/
|
|
93
|
-
private static PreProcessNunjucksViaRegex;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=sql-parser.d.ts.map
|
|
@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