@finos/legend-application-repl 1.0.35 → 1.0.37

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.
@@ -40,13 +40,13 @@ import {
40
40
  } from '@finos/legend-graph';
41
41
  import {
42
42
  assertErrorThrown,
43
- type DocumentationEntry,
44
43
  guaranteeType,
45
44
  HttpStatus,
46
45
  isNonNullable,
47
46
  LogEvent,
48
47
  NetworkClientError,
49
48
  type PlainObject,
49
+ UnsupportedOperationError,
50
50
  } from '@finos/legend-shared';
51
51
  import {
52
52
  LegendREPLDataCubeSource,
@@ -54,50 +54,61 @@ import {
54
54
  REPL_DATA_CUBE_SOURCE_TYPE,
55
55
  } from './LegendREPLDataCubeSource.js';
56
56
  import type { LegendREPLApplicationStore } from '../application/LegendREPLApplicationStore.js';
57
- import {
58
- APPLICATION_EVENT,
59
- shouldDisplayVirtualAssistantDocumentationEntry,
60
- } from '@finos/legend-application';
61
- import type { LegendREPLBaseStore } from './LegendREPLBaseStore.js';
57
+ import { APPLICATION_EVENT } from '@finos/legend-application';
62
58
  import { deserialize } from 'serializr';
63
59
 
64
60
  export class LegendREPLDataCubeEngine extends DataCubeEngine {
65
- readonly application: LegendREPLApplicationStore;
66
- readonly baseStore: LegendREPLBaseStore;
67
- readonly client: LegendREPLServerClient;
61
+ private readonly _application: LegendREPLApplicationStore;
62
+ private readonly _client: LegendREPLServerClient;
68
63
 
69
- constructor(baseStore: LegendREPLBaseStore) {
64
+ constructor(
65
+ application: LegendREPLApplicationStore,
66
+ client: LegendREPLServerClient,
67
+ ) {
70
68
  super();
71
69
 
72
- this.application = baseStore.application;
73
- this.baseStore = baseStore;
74
- this.client = baseStore.client;
70
+ this._application = application;
71
+ this._client = client;
75
72
  }
76
73
 
77
74
  // ---------------------------------- IMPLEMENTATION ----------------------------------
78
75
 
79
76
  override async processQuerySource(value: PlainObject) {
80
- if (value._type !== REPL_DATA_CUBE_SOURCE_TYPE) {
81
- throw new Error(
82
- `Can't deserialize query source of type '${value._type}'. Only type(s) '${REPL_DATA_CUBE_SOURCE_TYPE}' are supported.`,
83
- );
84
- }
85
- const rawSource = RawLegendREPLDataCubeSource.serialization.fromJson(value);
86
- this.baseStore.sourceQuery = rawSource.query;
87
- const source = new LegendREPLDataCubeSource();
88
- source.query = await this.parseValueSpecification(rawSource.query, false);
89
- source.columns = (
90
- await this.getQueryRelationType(_lambda([], [source.query]), source)
91
- ).columns;
92
- source.runtime = rawSource.runtime;
77
+ switch (value._type) {
78
+ case REPL_DATA_CUBE_SOURCE_TYPE: {
79
+ const rawSource =
80
+ RawLegendREPLDataCubeSource.serialization.fromJson(value);
81
+ const source = new LegendREPLDataCubeSource();
82
+ source.query = await this.parseValueSpecification(
83
+ rawSource.query,
84
+ false,
85
+ );
86
+ try {
87
+ source.columns = (
88
+ await this._getQueryRelationType(_lambda([], [source.query]))
89
+ ).columns;
90
+ } catch (error) {
91
+ assertErrorThrown(error);
92
+ throw new Error(
93
+ `Can't get query result columns. Make sure the source query return a relation (i.e. typed TDS). Error: ${error.message}`,
94
+ );
95
+ }
96
+ source.runtime = rawSource.runtime;
93
97
 
94
- source.mapping = rawSource.mapping;
95
- source.timestamp = rawSource.timestamp;
96
- source.model = rawSource.model;
97
- source.isLocal = rawSource.isLocal;
98
- source.isPersistenceSupported = rawSource.isPersistenceSupported;
98
+ source.mapping = rawSource.mapping;
99
+ source.timestamp = rawSource.timestamp;
100
+ source.model = rawSource.model;
101
+ source.isLocal = rawSource.isLocal;
102
+ source.isPersistenceSupported = rawSource.isPersistenceSupported;
99
103
 
100
- return source;
104
+ return source;
105
+ }
106
+ default: {
107
+ throw new UnsupportedOperationError(
108
+ `Can't process query source of type '${value._type}'.`,
109
+ );
110
+ }
111
+ }
101
112
  }
102
113
 
103
114
  override async parseValueSpecification(
@@ -105,7 +116,7 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
105
116
  returnSourceInformation?: boolean,
106
117
  ) {
107
118
  return _deserializeValueSpecification(
108
- await this.client.parseValueSpecification({
119
+ await this._client.parseValueSpecification({
109
120
  code,
110
121
  returnSourceInformation,
111
122
  }),
@@ -116,7 +127,7 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
116
127
  value: V1_ValueSpecification,
117
128
  pretty?: boolean,
118
129
  ) {
119
- return this.client.getValueSpecificationCode({
130
+ return this._client.getValueSpecificationCode({
120
131
  value: _serializeValueSpecification(value),
121
132
  pretty,
122
133
  });
@@ -127,30 +138,12 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
127
138
  baseQuery: V1_Lambda,
128
139
  source: DataCubeSource,
129
140
  ) {
130
- return this.client.getQueryTypeahead({
141
+ return this._client.getQueryTypeahead({
131
142
  code,
132
143
  baseQuery: _serializeValueSpecification(baseQuery),
133
144
  });
134
145
  }
135
146
 
136
- override async getQueryRelationType(
137
- query: V1_Lambda,
138
- source: DataCubeSource,
139
- ) {
140
- const relationType = deserialize(
141
- V1_relationTypeModelSchema,
142
- await this.client.getQueryRelationReturnType({
143
- query: _serializeValueSpecification(query),
144
- }),
145
- );
146
- return {
147
- columns: relationType.columns.map((column) => ({
148
- name: column.name,
149
- type: V1_getGenericTypeFullPath(column.genericType),
150
- })),
151
- };
152
- }
153
-
154
147
  override async getQueryCodeRelationReturnType(
155
148
  code: string,
156
149
  baseQuery: V1_ValueSpecification,
@@ -159,7 +152,7 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
159
152
  try {
160
153
  const relationType = deserialize(
161
154
  V1_relationTypeModelSchema,
162
- await this.client.getQueryCodeRelationReturnType({
155
+ await this._client.getQueryCodeRelationReturnType({
163
156
  code,
164
157
  baseQuery: _serializeValueSpecification(baseQuery),
165
158
  }),
@@ -191,7 +184,7 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
191
184
  source: DataCubeSource,
192
185
  options?: DataCubeExecutionOptions | undefined,
193
186
  ) {
194
- const result = await this.client.executeQuery({
187
+ const result = await this._client.executeQuery({
195
188
  query: _serializeValueSpecification(query),
196
189
  debug: options?.debug,
197
190
  });
@@ -222,30 +215,27 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
222
215
  return undefined;
223
216
  }
224
217
 
225
- // ---------------------------------- APPLICATION ----------------------------------
218
+ // ---------------------------------- UTILITIES ----------------------------------
226
219
 
227
- override getDocumentationURL(): string | undefined {
228
- return this.application.documentationService.url;
229
- }
230
-
231
- override getDocumentationEntry(key: string) {
232
- return this.application.documentationService.getDocEntry(key);
233
- }
234
-
235
- override shouldDisplayDocumentationEntry(entry: DocumentationEntry) {
236
- return shouldDisplayVirtualAssistantDocumentationEntry(entry);
237
- }
238
-
239
- override openLink(url: string) {
240
- this.application.navigationService.navigator.visitAddress(url);
220
+ private async _getQueryRelationType(query: V1_Lambda) {
221
+ const relationType = deserialize(
222
+ V1_relationTypeModelSchema,
223
+ await this._client.getQueryRelationReturnType({
224
+ query: _serializeValueSpecification(query),
225
+ }),
226
+ );
227
+ return {
228
+ columns: relationType.columns.map((column) => ({
229
+ name: column.name,
230
+ type: V1_getGenericTypeFullPath(column.genericType),
231
+ })),
232
+ };
241
233
  }
242
234
 
243
- override sendTelemetry(event: string, data: PlainObject) {
244
- this.application.telemetryService.logEvent(event, data);
245
- }
235
+ // ---------------------------------- APPLICATION ----------------------------------
246
236
 
247
237
  override logDebug(message: string, ...data: unknown[]) {
248
- this.application.logService.debug(
238
+ this._application.logService.debug(
249
239
  LogEvent.create(APPLICATION_EVENT.DEBUG),
250
240
  message,
251
241
  ...data,
@@ -255,14 +245,14 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
255
245
  override debugProcess(processName: string, ...data: [string, unknown][]) {
256
246
  // eslint-disable-next-line no-process-env
257
247
  if (process.env.NODE_ENV === 'development') {
258
- this.application.logService.info(
248
+ this._application.logService.info(
259
249
  LogEvent.create(APPLICATION_EVENT.DEBUG),
260
250
  `\n------ START DEBUG PROCESS: ${processName} ------`,
261
251
  ...data.flatMap(([key, value]) => [`\n[${key.toUpperCase()}]:`, value]),
262
252
  `\n------- END DEBUG PROCESS: ${processName} -------\n\n`,
263
253
  );
264
254
  } else {
265
- this.application.logService.debug(
255
+ this._application.logService.debug(
266
256
  LogEvent.create(APPLICATION_EVENT.DEBUG),
267
257
  `\n------ START DEBUG PROCESS: ${processName} ------`,
268
258
  ...data.flatMap(([key, value]) => [`\n[${key.toUpperCase()}]:`, value]),
@@ -272,19 +262,19 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
272
262
  }
273
263
 
274
264
  override logInfo(event: LogEvent, ...data: unknown[]) {
275
- this.application.logService.info(event, ...data);
265
+ this._application.logService.info(event, ...data);
276
266
  }
277
267
 
278
268
  override logWarning(event: LogEvent, ...data: unknown[]) {
279
- this.application.logService.warn(event, ...data);
269
+ this._application.logService.warn(event, ...data);
280
270
  }
281
271
 
282
272
  override logError(event: LogEvent, ...data: unknown[]) {
283
- this.application.logService.error(event, ...data);
273
+ this._application.logService.error(event, ...data);
284
274
  }
285
275
 
286
276
  override logUnhandledError(error: Error) {
287
- this.application.logUnhandledError(error);
277
+ this._application.logUnhandledError(error);
288
278
  }
289
279
 
290
280
  override logIllegalStateError(message: string, error?: Error) {
@@ -294,4 +284,16 @@ export class LegendREPLDataCubeEngine extends DataCubeEngine {
294
284
  error,
295
285
  );
296
286
  }
287
+
288
+ override getDocumentationEntry(key: string) {
289
+ return this._application.documentationService.getDocEntry(key);
290
+ }
291
+
292
+ override openLink(url: string) {
293
+ this._application.navigationService.navigator.visitAddress(url);
294
+ }
295
+
296
+ override sendTelemetry(event: string, data: PlainObject) {
297
+ this._application.telemetryService.logEvent(event, data);
298
+ }
297
299
  }