@memberjunction/server 2.45.0 → 2.46.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.
Files changed (28) hide show
  1. package/dist/entitySubclasses/entityPermissions.server.d.ts.map +1 -1
  2. package/dist/entitySubclasses/entityPermissions.server.js.map +1 -1
  3. package/dist/index.d.ts +0 -3
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/resolvers/AskSkipResolver.d.ts.map +1 -1
  8. package/dist/resolvers/AskSkipResolver.js +5 -2
  9. package/dist/resolvers/AskSkipResolver.js.map +1 -1
  10. package/package.json +24 -23
  11. package/src/entitySubclasses/entityPermissions.server.ts +3 -0
  12. package/src/index.ts +3 -3
  13. package/src/resolvers/AskSkipResolver.ts +5 -2
  14. package/dist/entitySubclasses/DuplicateRunEntity.server.d.ts +0 -6
  15. package/dist/entitySubclasses/DuplicateRunEntity.server.d.ts.map +0 -1
  16. package/dist/entitySubclasses/DuplicateRunEntity.server.js +0 -32
  17. package/dist/entitySubclasses/DuplicateRunEntity.server.js.map +0 -1
  18. package/dist/entitySubclasses/reportEntity.server.d.ts +0 -6
  19. package/dist/entitySubclasses/reportEntity.server.d.ts.map +0 -1
  20. package/dist/entitySubclasses/reportEntity.server.js +0 -103
  21. package/dist/entitySubclasses/reportEntity.server.js.map +0 -1
  22. package/dist/entitySubclasses/userViewEntity.server.d.ts +0 -13
  23. package/dist/entitySubclasses/userViewEntity.server.d.ts.map +0 -1
  24. package/dist/entitySubclasses/userViewEntity.server.js +0 -205
  25. package/dist/entitySubclasses/userViewEntity.server.js.map +0 -1
  26. package/src/entitySubclasses/DuplicateRunEntity.server.ts +0 -27
  27. package/src/entitySubclasses/reportEntity.server.ts +0 -130
  28. package/src/entitySubclasses/userViewEntity.server.ts +0 -231
@@ -2044,8 +2044,10 @@ cycle.`);
2044
2044
  responsePhase: SkipResponsePhase.AnalysisComplete,
2045
2045
  techExplanation: analysisDetail.techExplanation,
2046
2046
  userExplanation: analysisDetail.userExplanation,
2047
- scriptText: analysisDetail.scriptText,
2047
+ executionResults: analysisDetail.executionResults,
2048
2048
  tableDataColumns: analysisDetail.tableDataColumns,
2049
+ componentOptions: analysisDetail.componentOptions,
2050
+ artifactRequest: analysisDetail.artifactRequest
2049
2051
  });
2050
2052
  } else if (detail?.responsePhase === SkipResponsePhase.ClarifyingQuestion) {
2051
2053
  const clarifyingQuestionDetail = <SkipAPIClarifyingQuestionResponse>detail;
@@ -2567,6 +2569,7 @@ cycle.`);
2567
2569
  item.Type = 'sql';
2568
2570
  item.SQL = dr.text;
2569
2571
  item.AdditionalDescription = dr.description;
2572
+ item.CodeName = dr.codeName;
2570
2573
  if (!(await item.LoadData(dataSource, false, false, 0, user)))
2571
2574
  throw new Error(`SQL data request failed: ${item.DataLoadingError}`);
2572
2575
  break;
@@ -2681,7 +2684,7 @@ cycle.`);
2681
2684
  dataSource: DataSource,
2682
2685
  startTime: Date
2683
2686
  ): Promise<{ AIMessageConversationDetailID: string }> {
2684
- const sTitle = apiResponse.title;
2687
+ const sTitle = apiResponse.title || apiResponse.reportTitle;
2685
2688
  const sResult = JSON.stringify(apiResponse);
2686
2689
 
2687
2690
  // first up, let's see if Skip asked us to create an artifact or add a new version to an existing artifact, or NOT
@@ -1,6 +0,0 @@
1
- import { DuplicateRunEntity } from "@memberjunction/core-entities";
2
- export declare class DuplicateRunEntity_Server extends DuplicateRunEntity {
3
- Save(): Promise<boolean>;
4
- }
5
- export declare function LoadDuplicateRunEntityServerSubClass(): void;
6
- //# sourceMappingURL=DuplicateRunEntity.server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DuplicateRunEntity.server.d.ts","sourceRoot":"","sources":["../../src/entitySubclasses/DuplicateRunEntity.server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,qBACa,yBAA0B,SAAQ,kBAAkB;IAChD,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;CAiBxC;AAED,wBAAgB,oCAAoC,SAAK"}
@@ -1,32 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { BaseEntity, PotentialDuplicateRequest } from "@memberjunction/core";
8
- import { RegisterClass } from "@memberjunction/global";
9
- import { DuplicateRunEntity } from "@memberjunction/core-entities";
10
- import { DuplicateRecordDetector } from "@memberjunction/ai-vector-dupe";
11
- let DuplicateRunEntity_Server = class DuplicateRunEntity_Server extends DuplicateRunEntity {
12
- async Save() {
13
- const saveResult = await super.Save();
14
- if (saveResult && this.EndedAt === null) {
15
- const duplicateRecordDetector = new DuplicateRecordDetector();
16
- let request = new PotentialDuplicateRequest();
17
- request.EntityID = this.EntityID;
18
- request.ListID = this.SourceListID;
19
- request.Options = {
20
- DuplicateRunID: this.ID,
21
- };
22
- const response = await duplicateRecordDetector.getDuplicateRecords(request, this.ContextCurrentUser);
23
- }
24
- return saveResult;
25
- }
26
- };
27
- DuplicateRunEntity_Server = __decorate([
28
- RegisterClass(BaseEntity, 'Duplicate Runs')
29
- ], DuplicateRunEntity_Server);
30
- export { DuplicateRunEntity_Server };
31
- export function LoadDuplicateRunEntityServerSubClass() { }
32
- //# sourceMappingURL=DuplicateRunEntity.server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DuplicateRunEntity.server.js","sourceRoot":"","sources":["../../src/entitySubclasses/DuplicateRunEntity.server.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,kBAAkB;IACtD,KAAK,CAAC,IAAI;QACb,MAAM,UAAU,GAAY,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QAC/C,IAAI,UAAU,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAEtC,MAAM,uBAAuB,GAA4B,IAAI,uBAAuB,EAAE,CAAC;YACvF,IAAI,OAAO,GAA8B,IAAI,yBAAyB,EAAE,CAAC;YACzE,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;YACjC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;YACnC,OAAO,CAAC,OAAO,GAAG;gBACd,cAAc,EAAE,IAAI,CAAC,EAAE;aAC1B,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,uBAAuB,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACzG,CAAC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ,CAAA;AAlBY,yBAAyB;IADrC,aAAa,CAAC,UAAU,EAAE,gBAAgB,CAAC;GAC/B,yBAAyB,CAkBrC;;AAED,MAAM,UAAU,oCAAoC,KAAI,CAAC"}
@@ -1,6 +0,0 @@
1
- import { ReportEntity } from "@memberjunction/core-entities";
2
- export declare class ReportEntity_Server extends ReportEntity {
3
- Save(): Promise<boolean>;
4
- }
5
- export declare function LoadReportEntityServerSubClass(): void;
6
- //# sourceMappingURL=reportEntity.server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reportEntity.server.d.ts","sourceRoot":"","sources":["../../src/entitySubclasses/reportEntity.server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA6C,MAAM,+BAA+B,CAAC;AAGxG,qBACa,mBAAoB,SAAQ,YAAY;IAMpC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;CAmHxC;AAED,wBAAgB,8BAA8B,SAAK"}
@@ -1,103 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { BaseEntity, Metadata, RunView } from "@memberjunction/core";
8
- import { RegisterClass, SafeJSONParse } from "@memberjunction/global";
9
- import { ReportEntity } from "@memberjunction/core-entities";
10
- let ReportEntity_Server = class ReportEntity_Server extends ReportEntity {
11
- async Save() {
12
- try {
13
- const config = this.Configuration && this.Configuration.length > 0 ? SafeJSONParse(this.Configuration) : null;
14
- const oldTextConfig = this.GetFieldByName('Configuration')?.OldValue;
15
- const oldConfig = oldTextConfig && oldTextConfig.length > 0 ? SafeJSONParse(oldTextConfig) : null;
16
- if ((config && oldConfig) || (config && !this.IsSaved)) {
17
- let createSnapshot = false;
18
- let createReportVersion = false;
19
- if (this.IsSaved) {
20
- const castedConfig = config;
21
- const castedOldConfig = oldConfig;
22
- const dataContextChanged = Object.keys(castedConfig.dataContext || {})?.length !== Object.keys(castedOldConfig.dataContext || {})?.length;
23
- const executionResultsChanged = JSON.stringify(castedConfig.executionResults) !== JSON.stringify(castedOldConfig.executionResults);
24
- const analysisChanged = castedConfig.analysis !== castedOldConfig.analysis;
25
- delete castedConfig.dataContext;
26
- delete castedConfig.analysis;
27
- delete castedConfig.executionResults;
28
- delete castedOldConfig.dataContext;
29
- delete castedOldConfig.executionResults;
30
- delete castedOldConfig.analysis;
31
- const configChanged = JSON.stringify(castedConfig) !== JSON.stringify(castedOldConfig);
32
- createSnapshot = dataContextChanged || executionResultsChanged || analysisChanged;
33
- createReportVersion = configChanged;
34
- }
35
- else {
36
- createSnapshot = true;
37
- createReportVersion = true;
38
- }
39
- const wasNewRecord = !this.IsSaved;
40
- const saveResult = await super.Save();
41
- if (saveResult && (createSnapshot || createReportVersion)) {
42
- let success = true;
43
- const md = new Metadata();
44
- if (createReportVersion) {
45
- const reportVersion = await md.GetEntityObject('MJ: Report Versions', this.ContextCurrentUser);
46
- reportVersion.ReportID = this.ID;
47
- let newVersionNumber = 1;
48
- if (!wasNewRecord) {
49
- const rv = new RunView();
50
- const rvResult = await rv.RunView({
51
- Fields: ['VersionNumber'],
52
- EntityName: 'MJ: Report Versions',
53
- ExtraFilter: `ReportID = '${this.ID}'`,
54
- MaxRows: 1,
55
- OrderBy: 'VersionNumber DESC',
56
- }, this.ContextCurrentUser);
57
- if (rvResult.Success && rvResult.Results.length > 0) {
58
- newVersionNumber = parseInt(rvResult.Results[0].VersionNumber) + 1;
59
- }
60
- else {
61
- newVersionNumber = 1;
62
- console.warn('ReportEntity_Server.Save(): No report versions found for report ID:', this.ID);
63
- console.warn('ReportEntity_Server.Save(): Using version number 1 for new report version');
64
- }
65
- }
66
- reportVersion.Name = this.Name;
67
- reportVersion.Description = this.Description;
68
- reportVersion.VersionNumber = newVersionNumber;
69
- reportVersion.Configuration = JSON.stringify(this.Configuration);
70
- success = success && await reportVersion.Save();
71
- if (!success) {
72
- console.error('ReportEntity_Server.Save(): Error saving report version\n' + reportVersion.LatestResult.Message);
73
- }
74
- }
75
- if (createSnapshot) {
76
- const snapshot = await md.GetEntityObject('Report Snapshots', this.ContextCurrentUser);
77
- snapshot.ReportID = this.ID;
78
- snapshot.UserID = this.ContextCurrentUser.ID;
79
- snapshot.ResultSet = JSON.stringify(this.Configuration);
80
- success = success && await snapshot.Save();
81
- }
82
- return success;
83
- }
84
- else {
85
- return saveResult;
86
- }
87
- }
88
- else {
89
- return super.Save();
90
- }
91
- }
92
- catch (e) {
93
- console.error('Error in ReportEntity_Server.Save():', e);
94
- return false;
95
- }
96
- }
97
- };
98
- ReportEntity_Server = __decorate([
99
- RegisterClass(BaseEntity, 'Reports')
100
- ], ReportEntity_Server);
101
- export { ReportEntity_Server };
102
- export function LoadReportEntityServerSubClass() { }
103
- //# sourceMappingURL=reportEntity.server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reportEntity.server.js","sourceRoot":"","sources":["../../src/entitySubclasses/reportEntity.server.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,YAAY,EAA6C,MAAM,+BAA+B,CAAC;AAIjG,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,YAAY;IAM1C,KAAK,CAAC,IAAI;QACb,IAAI,CAAC;YAED,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC9G,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC;YACrE,MAAM,SAAS,GAAG,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAElG,IAAK,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO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,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC;GACxB,mBAAmB,CAyH/B;;AAED,MAAM,UAAU,8BAA8B,KAAI,CAAC"}
@@ -1,13 +0,0 @@
1
- import { EntityInfo } from "@memberjunction/core";
2
- import { AIModelEntityExtended, UserViewEntityExtended } from '@memberjunction/core-entities';
3
- export declare class UserViewEntity_Server extends UserViewEntityExtended {
4
- protected get SmartFilterImplemented(): boolean;
5
- protected get AIVendorName(): string;
6
- protected GetAIModel(): Promise<AIModelEntityExtended>;
7
- GenerateSmartFilterWhereClause(prompt: string, entityInfo: EntityInfo): Promise<{
8
- whereClause: string;
9
- userExplanation: string;
10
- }>;
11
- GenerateSysPrompt(entityInfo: EntityInfo): string;
12
- }
13
- //# sourceMappingURL=userViewEntity.server.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userViewEntity.server.d.ts","sourceRoot":"","sources":["../../src/entitySubclasses/userViewEntity.server.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,UAAU,EAAsB,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAiB,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAM5G,qBACa,qBAAsB,SAAQ,sBAAsB;IAI7D,cAAuB,sBAAsB,IAAI,OAAO,CAEvD;IAMD,SAAS,KAAK,YAAY,IAAI,MAAM,CAEnC;cAMe,UAAU,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAc/C,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAC,CAAC;IAuErI,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM;CAoH3D"}
@@ -1,205 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { CleanJSON, MJGlobal, RegisterClass } from "@memberjunction/global";
8
- import { BaseEntity, LogError, Metadata } from "@memberjunction/core";
9
- import { UserViewEntityExtended } from '@memberjunction/core-entities';
10
- import { BaseLLM, GetAIAPIKey } from "@memberjunction/ai";
11
- import { AIEngine } from "@memberjunction/aiengine";
12
- import { LoadOpenAILLM } from "@memberjunction/ai-openai";
13
- LoadOpenAILLM();
14
- let UserViewEntity_Server = class UserViewEntity_Server extends UserViewEntityExtended {
15
- get SmartFilterImplemented() {
16
- return true;
17
- }
18
- get AIVendorName() {
19
- return 'OpenAI';
20
- }
21
- async GetAIModel() {
22
- await AIEngine.Instance.Config(false, this.ContextCurrentUser);
23
- const models = AIEngine.Instance.Models.filter(m => m.AIModelType.trim().toLowerCase() === 'llm' &&
24
- m.Vendor.trim().toLowerCase() === this.AIVendorName.trim().toLowerCase());
25
- models.sort((a, b) => b.PowerRank - a.PowerRank);
26
- return models[0];
27
- }
28
- async GenerateSmartFilterWhereClause(prompt, entityInfo) {
29
- try {
30
- const model = await this.GetAIModel();
31
- const llm = MJGlobal.Instance.ClassFactory.CreateInstance(BaseLLM, model.DriverClass, GetAIAPIKey(model.DriverClass));
32
- const chatParams = {
33
- model: model.APINameOrName,
34
- messages: [
35
- {
36
- role: 'system',
37
- content: this.GenerateSysPrompt(entityInfo)
38
- },
39
- {
40
- role: 'user',
41
- content: `${prompt}`,
42
- },
43
- ],
44
- };
45
- const result = await llm.ChatCompletion(chatParams);
46
- if (result && result.data) {
47
- const llmResponse = result.data.choices[0].message.content;
48
- if (llmResponse) {
49
- try {
50
- const cleansed = CleanJSON(llmResponse);
51
- if (!cleansed)
52
- throw new Error('Invalid JSON response from AI: ' + llmResponse);
53
- const parsed = JSON.parse(cleansed);
54
- if (parsed.whereClause && parsed.whereClause.length > 0) {
55
- const trimmed = parsed.whereClause.trim();
56
- let ret = '';
57
- if (trimmed.toLowerCase().startsWith('where '))
58
- ret = trimmed.substring(6);
59
- else
60
- ret = parsed.whereClause;
61
- return {
62
- whereClause: ret,
63
- userExplanation: parsed.userExplanationMessage
64
- };
65
- }
66
- else if (parsed.whereClause !== undefined && parsed.whereClause !== null) {
67
- return {
68
- whereClause: '',
69
- userExplanation: parsed.userExplanationMessage
70
- };
71
- }
72
- else {
73
- throw new Error('Invalid response from AI, no whereClause property found in response: ' + llmResponse);
74
- }
75
- }
76
- catch (e) {
77
- LogError(e);
78
- throw new Error('Error parsing JSON response from AI: ' + llmResponse);
79
- }
80
- }
81
- else
82
- throw new Error('Null response from AI');
83
- }
84
- else
85
- throw new Error('No result returned from AI');
86
- }
87
- catch (e) {
88
- LogError(e);
89
- throw e;
90
- }
91
- }
92
- GenerateSysPrompt(entityInfo) {
93
- const processedViews = [entityInfo.BaseView];
94
- const md = new Metadata();
95
- const listsEntity = md.EntityByName("Lists");
96
- const listDetailsEntity = md.EntityByName("List Details");
97
- const gptSysPrompt = `You are an expert in SQL and Microsoft SQL Server.
98
- You will be provided a user prompt representing how they want to filter the data.
99
- You may *NOT* use JOINS, only sub-queries for related tables.
100
-
101
- I am a bot and can only understand JSON. Your response must be parsable into this type:
102
- const returnType = {
103
- whereClause: string,
104
- orderByClause: string
105
- userExplanationMessage: string
106
- };
107
-
108
- In MemberJunction, we have a concept called "Entities" and these are metadata constructs that wrap SQL tables and views. The entity that we are currently
109
- building a filter for is called "${entityInfo.Name}" and has an ID of "${entityInfo.ID}"
110
-
111
- You won't be using this Entity name or ID in your SQL, unless you need to use it for List filtering (more on that below).
112
-
113
- The view that the user is querying is called ${entityInfo.BaseView} and has these fields:
114
- ${entityInfo.Fields.map(f => {
115
- let ret = `${f.Name} (${f.Type})`;
116
- if (f.RelatedEntity) {
117
- ret += ` (fkey to ${f.RelatedEntityBaseView})`;
118
- }
119
- return ret;
120
- }).join(',')}`;
121
- const fkeyFields = entityInfo.Fields.filter(f => f.RelatedEntity && f.RelatedEntity.length > 0);
122
- const fkeyBaseViewsDistinct = fkeyFields.map(f => f.RelatedEntityBaseView).filter((v, i, a) => a.indexOf(v) === i);
123
- const relationships = `
124
- In addition, ${entityInfo.BaseView} has links to other views, as shown here, you can use these views in sub-queries to achieve the request from the user.
125
- If there are multiple filters related to a single related view, attempt to combine them into a single sub-query for efficiency.
126
- ${fkeyBaseViewsDistinct.map(v => {
127
- if (processedViews.indexOf(v) === -1) {
128
- const e = md.Entities.find(e => e.BaseView === v);
129
- if (e) {
130
- processedViews.push(v);
131
- return `* ${e.SchemaName}.${e.BaseView}: ${e.Fields.map(ef => {
132
- return ef.Name + ' (' + ef.Type + ')';
133
- }).join(',')}`;
134
- }
135
- else
136
- return '';
137
- }
138
- else
139
- return '';
140
- }).join('\n')}
141
- ${entityInfo.RelatedEntities.map(r => {
142
- const e = md.Entities.find(e => e.Name === r.RelatedEntity);
143
- if (e) {
144
- if (processedViews.indexOf(e.BaseView) === -1) {
145
- processedViews.push(e.BaseView);
146
- return `* ${e.SchemaName}.${e.BaseView}: ${e.Fields.map(ef => {
147
- let ret = `${ef.Name} (${ef.Type})`;
148
- if (ef.RelatedEntity) {
149
- ret += ` (fkey to ${ef.RelatedEntityBaseView})`;
150
- }
151
- return ret;
152
- }).join(',')}`;
153
- }
154
- else
155
- return '';
156
- }
157
- else
158
- return '';
159
- }).join('\n')}
160
-
161
- <IMPORTANT - LISTS FEATURE>
162
- In addition to the above related views, a user may talk about "Lists" in their request. A List is a static set of records modeled in our database with the ${listsEntity.SchemaName}.vwLists view and
163
- the ${listsEntity.SchemaName}.vwListDetails view. ${listsEntity.SchemaName}.vwLists contains the list "header" information with these columns:
164
- ${listsEntity.Fields.map(f => {
165
- return f.Name + ' (' + f.SQLFullType + ')';
166
- }).join(', ')}
167
- The vwListDetails view contains the list "detail" information with these columns which is basically the records that are part of the list. ${listsEntity.SchemaName}.vwListDetails contains these columns:
168
- ${listDetailsEntity.Fields.map(f => {
169
- return f.Name + ' (' + f.SQLFullType + ')';
170
- }).join(', ')}.
171
-
172
- If a user is asking to use a list in creating a view, you need to use a sub-query along these lines:
173
-
174
- ID IN (SELECT RecordID FROM ${listsEntity.SchemaName}.vwListDetails WHERE ListID='My List ID')
175
-
176
- In this example we're assuming the user has asked us to filter to include only records that are part of the list with the ID of 'My List ID'. In reality the prompt you will have will have a UUID/GUID type ID not a text string like this.
177
- You can use any fields at the detail level filter the records and of course combine this type of list-oriented sub-query with other filters as appropriate to satisfy the user's request.
178
-
179
- It is also possible that a user will provide ONLY the name of the list they want to filter on. If they provide the List ID, use it with a query like the above. However, if ONLY a List name is provided, you can do as follows: use this style of query with a join to the vwLists view (the list "header") to filter on the name
180
- of the view or other header information if they want to filter on other list header attributes you can do this. Here is an example:
181
-
182
- ID IN (SELECT ld.RecordID FROM ${listsEntity.SchemaName}.vwListDetails ld INNER JOIN ${listsEntity.SchemaName}.vwLists l ON ld.ListID=l.ID WHERE l.Name='My List Name')
183
-
184
- No need to use table aliasing if you're just using the vwListDetails view, in that simple subquery it is automatic and unnecessary. If you need to join to the vwLists view, you can use the aliases "l" and "ld", as shown in the example above.
185
-
186
- </IMPORTANT - LISTS FEATURE>
187
- <IMPORTANT - OTHER VIEWS>
188
- The user might reference other "views" in their request. In the user's terminology a view is what we call a "User View" in MemberJunction system-speak. The idea is a user might ask for a filter that includes or excludes
189
- records from another view. Unlike Lists, which are STATIC sets of records, User Views are dynamic and can change based on the underlying data. So, what we need to do is use a sub-query that pulls in the SQL for the other view
190
- The user will be referring to the other view by name, so what you need to do when generating SQL for this scenario is to simply embed a sub-query along the lines of this example, updated of course in the context of the user's request and the rest of any filters you are building:
191
- ID IN ({%UserView "ViewID"%}) -- this is for filtering the primary key using other User Views for this entity: "${entityInfo.Name}"
192
- AccountID IN ({%UserView "ViewID"%}) -- this is an example where the foreign key relationship for the AccountID field in this entity (${entityInfo.Name}) links to another entity hypothetically called "Accounts" and we want to use an Accounts view for filtering in some way
193
- By including this sub-query in your generated WHERE clause, it will give me what I need to dynamically replace the {%UserView "View Name"%} with the actual SQL for the view that the user is referring to. Since that actual SQL
194
- can change over time, I don't want to embed it directly here but rather have it templatized and each time it is run, I will pre-process the SQL to replace the template with the actual SQL for the view.
195
- </IMPORTANT - OTHER VIEWS>
196
- `;
197
- return gptSysPrompt + (processedViews.length > 1 ? relationships : '') + `
198
- **** REMEMBER **** I am a BOT, do not return anything other than JSON to me or I will choke on your response!`;
199
- }
200
- };
201
- UserViewEntity_Server = __decorate([
202
- RegisterClass(BaseEntity, 'User Views')
203
- ], UserViewEntity_Server);
204
- export { UserViewEntity_Server };
205
- //# sourceMappingURL=userViewEntity.server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"userViewEntity.server.js","sourceRoot":"","sources":["../../src/entitySubclasses/userViewEntity.server.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAc,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAwC,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAC5G,OAAO,EAAE,OAAO,EAAc,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,aAAa,EAAE,CAAC;AAGT,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,sBAAsB;IAI7D,IAAuB,sBAAsB;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IAMD,IAAc,YAAY;QACtB,OAAO,QAAQ,CAAC;IACpB,CAAC;IAMS,KAAK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AC;;;;8BAIiB,WAAW,CAAC,UAAU;;;;;;;;iCAQnB,WAAW,CAAC,UAAU,gCAAgC,WAAW,CAAC,UAAU;;;;;;;;;sHASS,UAAU,CAAC,IAAI;4IACO,UAAU,CAAC,IAAI;;;;CAI1J,CAAA;QAEO,OAAO,YAAY,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAgD,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG;sHACV,CAAC;IACnH,CAAC;CACJ,CAAA;AA7NY,qBAAqB;IADjC,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC;GAC3B,qBAAqB,CA6NjC"}
@@ -1,27 +0,0 @@
1
- import { BaseEntity, PotentialDuplicateRequest } from "@memberjunction/core";
2
- import { RegisterClass } from "@memberjunction/global";
3
- import { DuplicateRunEntity } from "@memberjunction/core-entities";
4
- import { DuplicateRecordDetector } from "@memberjunction/ai-vector-dupe";
5
-
6
- @RegisterClass(BaseEntity, 'Duplicate Runs')
7
- export class DuplicateRunEntity_Server extends DuplicateRunEntity {
8
- public async Save(): Promise<boolean> {
9
- const saveResult: boolean = await super.Save();
10
- if (saveResult && this.EndedAt === null) {
11
- // do something
12
- const duplicateRecordDetector: DuplicateRecordDetector = new DuplicateRecordDetector();
13
- let request: PotentialDuplicateRequest = new PotentialDuplicateRequest();
14
- request.EntityID = this.EntityID;
15
- request.ListID = this.SourceListID;
16
- request.Options = {
17
- DuplicateRunID: this.ID,
18
- };
19
-
20
- const response = await duplicateRecordDetector.getDuplicateRecords(request, this.ContextCurrentUser);
21
- }
22
-
23
- return saveResult;
24
- }
25
- }
26
-
27
- export function LoadDuplicateRunEntityServerSubClass() {}
@@ -1,130 +0,0 @@
1
- import { BaseEntity, Metadata, RunView } from "@memberjunction/core";
2
- import { RegisterClass, SafeJSONParse } from "@memberjunction/global";
3
- import { ReportEntity, ReportSnapshotEntity, ReportVersionEntity } from "@memberjunction/core-entities";
4
- import { SkipAPIAnalysisCompleteResponse } from "@memberjunction/skip-types";
5
-
6
- @RegisterClass(BaseEntity, 'Reports')
7
- export class ReportEntity_Server extends ReportEntity {
8
- /**
9
- * The server side Report Entity sub-class has a simple logic that will create a snapshot of the report when it is first created and each time it is modified, but only
10
- * if it is either newly created or if the Configuration field has changed.
11
- * @returns
12
- */
13
- public async Save(): Promise<boolean> {
14
- try {
15
- // first let's get the actual parsed object for the Configuration field
16
- const config = this.Configuration && this.Configuration.length > 0 ? SafeJSONParse(this.Configuration) : null;
17
- const oldTextConfig = this.GetFieldByName('Configuration')?.OldValue;
18
- const oldConfig = oldTextConfig && oldTextConfig.length > 0 ? SafeJSONParse(oldTextConfig) : null;
19
-
20
- if ( (config && oldConfig) || (config && !this.IsSaved) ) {
21
- let createSnapshot = false;
22
- let createReportVersion = false;
23
- if (this.IsSaved) {
24
- // existing record
25
- // we nave a configuration and an old configuration, so we can compare them, cast them to their strong types first
26
- const castedConfig = config as SkipAPIAnalysisCompleteResponse;
27
- const castedOldConfig = oldConfig as SkipAPIAnalysisCompleteResponse;
28
-
29
- // Next, we need to see if the data context has changed at all. We do this by comparing the # of items in the data context. a Data context's items are immutable and we only add new Data Context Items
30
- // so we can simply check to see if we have new data context items or not
31
- const dataContextChanged = Object.keys(castedConfig.dataContext || {})?.length !== Object.keys(castedOldConfig.dataContext || {})?.length;
32
-
33
- // next up, we check to see if anything in the execution results changed. The simple way to do that is convert the execution results back to a string and compare those strings
34
- const executionResultsChanged = JSON.stringify(castedConfig.executionResults) !== JSON.stringify(castedOldConfig.executionResults);
35
-
36
- // next up we check to see if the analysis changed, which would also represent a "data" change
37
- const analysisChanged = castedConfig.analysis !== castedOldConfig.analysis;
38
-
39
- // finally, we check to see if the configuration itself has OUTSIDE of the data elements we just checked. We do that by deleting those properties from those objects, converting to strings
40
- // and comparing them
41
- delete castedConfig.dataContext;
42
- delete castedConfig.analysis;
43
- delete castedConfig.executionResults;
44
-
45
- delete castedOldConfig.dataContext;
46
- delete castedOldConfig.executionResults;
47
- delete castedOldConfig.analysis;
48
-
49
- // we can now compare the two objects
50
- const configChanged = JSON.stringify(castedConfig) !== JSON.stringify(castedOldConfig);
51
-
52
- // now our logic is this - if the DATA changed, but the configuration did NOT change, that means we want to create a new SNAPSHOT of the report - which is the data changing side
53
- // if the configuration changed at all we wnat to create a new Report Version. Sometimes both changd and we do both
54
- createSnapshot = dataContextChanged || executionResultsChanged || analysisChanged;
55
- createReportVersion = configChanged;
56
- }
57
- else {
58
- // we have a new record set createSnapshot to true and createReportVersion to true
59
- createSnapshot = true;
60
- createReportVersion = true;
61
- }
62
-
63
- const wasNewRecord: boolean = !this.IsSaved;
64
- const saveResult: boolean = await super.Save();
65
- if (saveResult && (createSnapshot || createReportVersion)) {
66
- // here we either have a new record or the configuration has changed, so we need to create a snapshot of the report
67
- let success: boolean = true;
68
- const md = new Metadata();
69
-
70
- if (createReportVersion) {
71
- const reportVersion = await md.GetEntityObject<ReportVersionEntity>('MJ: Report Versions', this.ContextCurrentUser);
72
- reportVersion.ReportID = this.ID;
73
- // const get highest new version number already in DB
74
- let newVersionNumber: number = 1;
75
- if (!wasNewRecord) {
76
- const rv = new RunView();
77
- const rvResult = await rv.RunView({
78
- Fields: ['VersionNumber'],
79
- EntityName: 'MJ: Report Versions',
80
- ExtraFilter: `ReportID = '${this.ID}'`,
81
- MaxRows: 1,
82
- OrderBy: 'VersionNumber DESC',
83
- }, this.ContextCurrentUser);
84
- if (rvResult.Success && rvResult.Results.length > 0) {
85
- newVersionNumber = parseInt(rvResult.Results[0].VersionNumber) + 1;
86
- }
87
- else {
88
- newVersionNumber = 1; // this is an error state as we previously had a saved report, BUT there were no saved versions for the report, so we are going to use 1 here, but let's log a warning
89
- console.warn('ReportEntity_Server.Save(): No report versions found for report ID:', this.ID);
90
- console.warn('ReportEntity_Server.Save(): Using version number 1 for new report version');
91
- }
92
- }
93
- reportVersion.Name = this.Name; // copy current name to the new version
94
- reportVersion.Description = this.Description; // copy current description to the new version
95
- reportVersion.VersionNumber = newVersionNumber;
96
- reportVersion.Configuration = JSON.stringify(this.Configuration);
97
- success = success && await reportVersion.Save();
98
- if (!success) {
99
- console.error('ReportEntity_Server.Save(): Error saving report version\n' + reportVersion.LatestResult.Message);
100
- }
101
- }
102
-
103
- if (createSnapshot) {
104
- const snapshot = await md.GetEntityObject<ReportSnapshotEntity>('Report Snapshots', this.ContextCurrentUser);
105
- snapshot.ReportID = this.ID;
106
- snapshot.UserID = this.ContextCurrentUser.ID;
107
- // in the snapshot entity the ResultSet column is the Configuration column from the Report entity
108
- snapshot.ResultSet = JSON.stringify(this.Configuration);
109
- success = success && await snapshot.Save();
110
- }
111
-
112
- return success;
113
- }
114
- else {
115
- return saveResult;
116
- }
117
- }
118
- else {
119
- // no configuration or no parseable configuration, so we just call super.Save();
120
- return super.Save();
121
- }
122
- }
123
- catch (e) {
124
- console.error('Error in ReportEntity_Server.Save():', e);
125
- return false;
126
- }
127
- }
128
- }
129
-
130
- export function LoadReportEntityServerSubClass() {}