@datagrok/compute 1.44.6 → 1.45.1

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/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "1.44.6",
4
+ "version": "1.45.1",
5
5
  "author": {
6
6
  "name": "Andrey Sharapov",
7
7
  "email": "andrey.sharapov@softwarecountry.com"
8
8
  },
9
- "description": "Provides additional analytical and UI blocks for [Datagrok scientific computing](https://datagrok.ai/help/compute/).",
9
+ "description": "Legacy modeling UI",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/datagrok-ai/public.git",
13
13
  "directory": "packages/Compute"
14
14
  },
15
15
  "dependencies": {
16
- "@datagrok-libraries/compute-utils": "^1.44.9",
17
- "@datagrok-libraries/utils": "^4.6.5",
16
+ "@datagrok-libraries/compute-api": "^0.7.6",
17
+ "@datagrok-libraries/compute-utils": "^1.46.1",
18
+ "@datagrok-libraries/test": "^1.2.0",
19
+ "@datagrok-libraries/utils": "^4.7.1",
18
20
  "cash-dom": "^8.1.5",
19
- "datagrok-api": "^1.26.0",
20
- "dayjs": "=1.11.10",
21
+ "datagrok-api": "^1.27.0",
22
+ "dayjs": "1.11.19",
21
23
  "exceljs": "^4.3.0",
22
24
  "rxjs": "^6.6.7",
23
25
  "source-map-loader": "^5.0.0",
@@ -29,7 +31,7 @@
29
31
  "@typescript-eslint/eslint-plugin": "^8.8.1",
30
32
  "@typescript-eslint/parser": "^8.8.1",
31
33
  "css-loader": "^7.1.2",
32
- "datagrok-tools": "^4.14.55",
34
+ "datagrok-tools": "^5.0.0",
33
35
  "eslint": "^8.0.1",
34
36
  "eslint-config-google": "^0.14.0",
35
37
  "style-loader": "^4.0.0",
@@ -66,7 +68,9 @@
66
68
  ],
67
69
  "category": "Compute",
68
70
  "meta": {
69
- "url": "/Modelhub",
70
71
  "dartium": false
72
+ },
73
+ "overrides": {
74
+ "datagrok-api": "$datagrok-api"
71
75
  }
72
76
  }
@@ -0,0 +1,13 @@
1
+ //name: complexInputs
2
+ //language: javascript
3
+ //description: RichFunctionView custom input and df input
4
+ //input: dataframe df
5
+ //input: string data { input: Compute:CustomInputMock; inputOptions: { "arg1": 1, "arg2": "test", "arg3": true } }
6
+ //output: dataframe dfout
7
+ //output: string dataout
8
+ //editor: Compute:RichFunctionViewEditor
9
+ //meta.uploadMode: true
10
+ //tags: test
11
+
12
+ dfout=df;
13
+ dataout=data;
@@ -0,0 +1,11 @@
1
+ //name: globalValidationTest
2
+ //description: Global validators test
3
+ //language: javascript
4
+ //tags: simulation, test
5
+ //input: double a {caption: First value; validatorFunc: Compute:GlobalValidatorDemoFactory; validatorFuncOptions: { "max": 100 } }
6
+ //input: double b {caption: Second value; validatorFunc: Compute:GlobalValidatorDemoFactory; validatorFuncOptions: { "max": 100 } }
7
+ //input: double c {caption: Third value; validatorFunc: Compute:GlobalValidatorDemoFactory; validatorFuncOptions: { "max": 100 } }
8
+ //editor: Compute:RichFunctionViewEditor
9
+ //output: double s
10
+
11
+ s = a + b + c;
@@ -7,7 +7,7 @@
7
7
  //input: double x0 = 0 [Initial conditions for rate of convective motion - i.e. how fast the rolls are rotating]
8
8
  //input: double y0 = 1 [Initial conditions for temperature difference between the ascending and descending currents]
9
9
  //input: double z0 = 1.05 [Initial conditions for distortion (from linearity) of the vertical temperature profile]
10
- //output: dataframe df {caption: Lorenz attractor; viewer: 3d Scatter plot())}
10
+ //output: dataframe df {caption: Lorenz attractor; viewer: 3d Scatter plot()}
11
11
  //editor: Compute:RichFunctionViewEditor
12
12
  //meta.runOnOpen: true
13
13
  //meta.runOnInput: true
@@ -0,0 +1,16 @@
1
+ //name: simpleInputs
2
+ //language: javascript
3
+ //description: RichFunctionView simple inputs test
4
+ //input: int a
5
+ //input: double b
6
+ //input: string c
7
+ //output: int aout
8
+ //output: double bout
9
+ //output: string cout
10
+ //editor: Compute:RichFunctionViewEditor
11
+ //meta.uploadMode: true
12
+ //tags: test
13
+
14
+ aout=a;
15
+ bout=b;
16
+ cout=c;
@@ -0,0 +1,15 @@
1
+ //name: simpleInputsDefaultValues
2
+ //language: javascript
3
+ //description: RichFunctionView simple inputs
4
+ //input: int a=1
5
+ //input: double b=2.2
6
+ //input: string c="test"
7
+ //output: int aout
8
+ //output: double bout
9
+ //output: string cout
10
+ //editor: Compute:RichFunctionViewEditor
11
+ //tags: test
12
+
13
+ aout=a;
14
+ bout=b;
15
+ cout=c;
@@ -0,0 +1,11 @@
1
+ //name: validationTest
2
+ //description: Custom validators test
3
+ //language: javascript
4
+ //tags: simulation, test
5
+ //input: double a {caption: First value; validatorFunc: Compute:RangeValidatorFactory; validatorFuncOptions: { "min": 1, "max": 10 } }
6
+ //input: double b {caption: Second value; validatorFunc: Compute:RangeValidatorFactory; validatorFuncOptions: { "min": 20, "max": 100 } }
7
+ //input: double x=0 {caption: Async suggestions; validatorFunc: Compute:AsyncValidatorDemoFactory }
8
+ //editor: Compute:RichFunctionViewEditor
9
+ //output: double c
10
+
11
+ c = a + b;
@@ -28,6 +28,10 @@ export namespace scripts {
28
28
  }
29
29
 
30
30
  export namespace funcs {
31
+ export async function init(): Promise<void> {
32
+ return await grok.functions.call('Compute:Init', {});
33
+ }
34
+
31
35
  export async function openModelFromFuncall(funccall: any ): Promise<void> {
32
36
  return await grok.functions.call('Compute:OpenModelFromFuncall', { funccall });
33
37
  }
@@ -43,26 +47,10 @@ export namespace funcs {
43
47
  return await grok.functions.call('Compute:RichFunctionViewEditor', { call });
44
48
  }
45
49
 
46
- export async function pipelineStepEditor(call: any ): Promise<DG.View> {
50
+ export async function pipelineStepEditor(call: any ): Promise<any> {
47
51
  return await grok.functions.call('Compute:PipelineStepEditor', { call });
48
52
  }
49
53
 
50
- export async function renderPanel(func: any ): Promise<any> {
51
- return await grok.functions.call('Compute:RenderPanel', { func });
52
- }
53
-
54
- export async function init(): Promise<void> {
55
- return await grok.functions.call('Compute:Init', {});
56
- }
57
-
58
- export async function modelCatalog(): Promise<DG.View> {
59
- return await grok.functions.call('Compute:ModelCatalog', {});
60
- }
61
-
62
- export async function modelCatalogTreeBrowser(treeNode: any , browseView: DG.View ): Promise<void> {
63
- return await grok.functions.call('Compute:ModelCatalogTreeBrowser', { treeNode, browseView });
64
- }
65
-
66
54
  export async function customDataUploader(func: any ): Promise<any> {
67
55
  return await grok.functions.call('Compute:CustomDataUploader', { func });
68
56
  }
@@ -103,17 +91,19 @@ export namespace funcs {
103
91
  return await grok.functions.call('Compute:ObjectCoolingSelector', { params });
104
92
  }
105
93
 
106
- /**
107
- Test for optimization: multiple scalars output
108
- */
109
- export async function fitTestFunc(x1: number , x2: number , y: DG.DataFrame , bool: boolean ): Promise<{integer: number, float1: number, float2: number, table1: DG.DataFrame, table2: DG.DataFrame}> {
110
- return await grok.functions.call('Compute:FitTestFunc', { x1, x2, y, bool });
94
+ export async function customInputMock(params: any ): Promise<any> {
95
+ return await grok.functions.call('Compute:CustomInputMock', { params });
111
96
  }
112
97
 
113
- /**
114
- Test for optimization: multiple scalars output
115
- */
116
- export async function testFittingOutputs(): Promise<void> {
117
- return await grok.functions.call('Compute:TestFittingOutputs', {});
98
+ export async function rangeValidatorFactory(params: any ): Promise<any> {
99
+ return await grok.functions.call('Compute:RangeValidatorFactory', { params });
100
+ }
101
+
102
+ export async function asyncValidatorDemoFactory(params: any ): Promise<any> {
103
+ return await grok.functions.call('Compute:AsyncValidatorDemoFactory', { params });
104
+ }
105
+
106
+ export async function globalValidatorDemoFactory(params: any ): Promise<any> {
107
+ return await grok.functions.call('Compute:GlobalValidatorDemoFactory', { params });
118
108
  }
119
109
  }
@@ -1,6 +1,9 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
  import * as grok from 'datagrok-api/grok';
3
- import {runTests, tests, TestContext, initAutoTests as initTests} from '@datagrok-libraries/utils/src/test';
3
+ import {runTests, tests, TestContext, initAutoTests as initTests} from '@datagrok-libraries/test/src/test';
4
+
5
+ import './tests/rich-function-view-tests';
6
+ import './tests/rich-function-view-direct-tests';
4
7
 
5
8
  export const _package = new DG.Package();
6
9
  export {tests};
package/src/package.g.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import {PackageFunctions} from './package';
2
2
  import * as DG from 'datagrok-api/dg';
3
3
 
4
+ //meta.role: init
5
+ export async function init() : Promise<void> {
6
+ await PackageFunctions.init();
7
+ }
8
+
4
9
  //input: funccall funccall
5
10
  export function openModelFromFuncall(funccall: DG.FuncCall) : void {
6
11
  PackageFunctions.openModelFromFuncall(funccall);
@@ -8,54 +13,26 @@ export function openModelFromFuncall(funccall: DG.FuncCall) : void {
8
13
 
9
14
  //name: OutliersSelectionViewer
10
15
  //description: Creates an outliers selection viewer
11
- //tags: viewer
12
16
  //output: viewer result
17
+ //meta.role: viewer
13
18
  export function OutliersSelection() {
14
19
  return PackageFunctions.OutliersSelection();
15
20
  }
16
21
 
17
- //tags: editor
18
22
  //input: funccall call
19
23
  //output: view result
24
+ //meta.role: editor
20
25
  export function RichFunctionViewEditor(call: DG.FuncCall) {
21
26
  return PackageFunctions.RichFunctionViewEditor(call);
22
27
  }
23
28
 
24
- //tags: editor
25
29
  //input: funccall call
26
- //output: view result
30
+ //output: object result
31
+ //meta.role: editor
27
32
  export function PipelineStepEditor(call: DG.FuncCall) {
28
33
  return PackageFunctions.PipelineStepEditor(call);
29
34
  }
30
35
 
31
- //name: renderRestPanel
32
- //input: func func
33
- //output: widget result
34
- export async function renderPanel(func: any) : Promise<any> {
35
- return await PackageFunctions.renderPanel(func);
36
- }
37
-
38
- //tags: init
39
- export function init() : void {
40
- PackageFunctions.init();
41
- }
42
-
43
- //name: Model Hub
44
- //tags: app
45
- //output: view result
46
- //meta.browsePath: Compute
47
- export function modelCatalog() {
48
- return PackageFunctions.modelCatalog();
49
- }
50
-
51
- //input: dynamic treeNode
52
- //input: view browseView
53
- //meta.role:
54
- //meta.app:
55
- export function modelCatalogTreeBrowser(treeNode: any, browseView: DG.ViewBase) : void {
56
- PackageFunctions.modelCatalogTreeBrowser(treeNode, browseView);
57
- }
58
-
59
36
  //input: dynamic func
60
37
  //output: object uploadedCalls
61
38
  export async function CustomDataUploader(func: any) {
@@ -116,25 +93,26 @@ export function ObjectCoolingSelector(params: any) {
116
93
  return PackageFunctions.ObjectCoolingSelector(params);
117
94
  }
118
95
 
119
- //description: Test for optimization: multiple scalars output
120
- //input: double x1 = 1 { caption: param1; min: -3; max: 3 }
121
- //input: double x2 = -1 { caption: param2; min: -3; max: 3 }
122
- //input: dataframe y { caption: table }
123
- //input: bool bool
124
- //output: int integer
125
- //output: double float1
126
- //output: double float2
127
- //output: dataframe table1 { viewer: Line chart(block:60) | Grid(block:40) }
128
- //output: dataframe table2 { viewer: Line chart(block:60) | Grid(block:40) }
129
- //meta.features: {"fitting": true, "sens-analysis": true}
130
- //meta.runOnOpen: true
131
- //meta.runOnInput: true
132
- //editor: Compute:RichFunctionViewEditor
133
- export function fitTestFunc(x1: number, x2: number, y: DG.DataFrame, bool: boolean) {
134
- return PackageFunctions.fitTestFunc(x1, x2, y, bool);
135
- }
136
-
137
- //description: Test for optimization: multiple scalars output
138
- export async function testFittingOutputs() : Promise<void> {
139
- await PackageFunctions.testFittingOutputs();
96
+ //input: object params
97
+ //output: object input
98
+ export async function CustomInputMock(params: any) : Promise<any> {
99
+ return await PackageFunctions.CustomInputMock(params);
100
+ }
101
+
102
+ //input: object params
103
+ //output: object validator
104
+ export function RangeValidatorFactory(params: any) {
105
+ return PackageFunctions.RangeValidatorFactory(params);
106
+ }
107
+
108
+ //input: object params
109
+ //output: object validator
110
+ export function AsyncValidatorDemoFactory(params: any) {
111
+ return PackageFunctions.AsyncValidatorDemoFactory(params);
112
+ }
113
+
114
+ //input: object params
115
+ //output: object validator
116
+ export function GlobalValidatorDemoFactory(params: any) {
117
+ return PackageFunctions.GlobalValidatorDemoFactory(params);
140
118
  }
package/src/package.ts CHANGED
@@ -2,14 +2,15 @@
2
2
  import * as grok from 'datagrok-api/grok';
3
3
  import * as ui from 'datagrok-api/ui';
4
4
  import * as DG from 'datagrok-api/dg';
5
+ import {BehaviorSubject} from 'rxjs';
5
6
  import {filter} from 'rxjs/operators';
6
7
  import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
7
8
  import {
8
9
  ComputationView as ComputationViewInst,
9
10
  RichFunctionView as RichFunctionViewInst,
10
11
  PipelineView as PipelineViewInst,
11
- CustomFunctionView as CustomFunctionViewInst,
12
12
  UiUtils,
13
+ FuncCallInput,
13
14
  } from '@datagrok-libraries/compute-utils';
14
15
  import {
15
16
  ValidationInfo,
@@ -18,13 +19,7 @@ import {
18
19
  makeRevalidation as makeRevalidationInst,
19
20
  mergeValidationResults as mergeValidationResultsInst,
20
21
  } from '@datagrok-libraries/compute-utils';
21
- import {ModelCatalogView,
22
- ModelHandler,
23
- startModelCatalog,
24
- makeModelTreeBrowser,
25
- renderRestPanel,
26
- setModelCatalogEventHandlers,
27
- setModelCatalogHandler} from '@datagrok-libraries/compute-utils/model-catalog';
22
+ import {ModelHandler} from '@datagrok-libraries/compute-utils/model-catalog';
28
23
  import {
29
24
  testPipeline as testPipelineInst,
30
25
  } from '@datagrok-libraries/compute-utils';
@@ -33,16 +28,45 @@ import {
33
28
  } from '@datagrok-libraries/compute-utils';
34
29
 
35
30
 
36
- import {FittingView} from '@datagrok-libraries/compute-utils/function-views/src/fitting-view';
37
31
  export * from './package.g';
38
32
  export const _package = new DG.Package();
39
33
 
34
+ class InputMock implements FuncCallInput {
35
+ _value = new BehaviorSubject<any>(null);
36
+ notify = true;
37
+ enabled = true;
38
+ root = ui.div('', {style: {width: '100%'}});
39
+ input = ui.input.toggle('test', {value: true});
40
+
41
+ constructor() {
42
+ this.root.append(this.input.root);
43
+ }
44
+
45
+ set value(v: any) {
46
+ const nv = v ? JSON.parse(v) : '';
47
+ this._value.next(nv);
48
+ }
49
+
50
+ get value() {
51
+ if (!this._value.value)
52
+ return '';
53
+
54
+ return JSON.stringify(this._value.value);
55
+ }
56
+
57
+ onInput(fn: Function) {
58
+ return this._value.subscribe(() => {
59
+ if (this.notify)
60
+ fn(this.value);
61
+ });
62
+ }
63
+ }
64
+
40
65
  // for compute-api pakage
41
66
  export const testPipeline = testPipelineInst;
42
67
  export const deepCopy = deepCopyInst;
43
68
  export const CompView = ComputationViewInst;
44
69
  export const RFV = RichFunctionViewInst;
45
- export const CFV = CustomFunctionViewInst;
46
70
  export const Pipeline = PipelineViewInst;
47
71
  export const makeValidationResult = makeValidationResultInst;
48
72
  export const makeAdvice = makeAdviceInst;
@@ -53,22 +77,13 @@ export const historyInput = UiUtils.historyInput;
53
77
  export const historyInputJSON = UiUtils.historyInputJSON;
54
78
  export const historyPanel = UiUtils.historyPanel;
55
79
 
56
- let startUriLoaded = false;
57
- let initCompleted = false;
58
-
59
80
 
60
- const options = {
61
- _package,
62
- ViewClass: ModelCatalogView,
63
- segment: 'Modelhub',
64
- viewName: 'Model Hub',
65
- funcName: 'modelCatalog',
66
- setStartUriLoaded: () => startUriLoaded = true,
67
- getStartUriLoaded: () => startUriLoaded,
68
- };
81
+ export class PackageFunctions {
82
+ @grok.decorators.init()
83
+ static async init() {
84
+ }
69
85
 
70
86
 
71
- export class PackageFunctions {
72
87
  @grok.decorators.func()
73
88
  static openModelFromFuncall(funccall: DG.FuncCall) {
74
89
  ModelHandler.openModelFromFunccall(funccall as any);
@@ -76,10 +91,10 @@ export class PackageFunctions {
76
91
 
77
92
 
78
93
  @grok.decorators.func({
79
- tags: ['viewer'],
80
94
  name: 'OutliersSelectionViewer',
81
95
  description: 'Creates an outliers selection viewer',
82
96
  outputs: [{type: 'viewer', name: 'result'}],
97
+ meta: {role: 'viewer'},
83
98
  })
84
99
  static OutliersSelection() {
85
100
  return new OutliersSelectionViewer();
@@ -92,46 +107,11 @@ export class PackageFunctions {
92
107
  }
93
108
 
94
109
 
95
- @grok.decorators.editor({outputs: [{type: 'view', name: 'result'}]})
110
+ @grok.decorators.editor({outputs: [{type: 'object', name: 'result'}]})
96
111
  static PipelineStepEditor(call: DG.FuncCall) {
97
112
  return RichFunctionViewInst.fromFuncCall(call as any, {historyEnabled: false, isTabbed: true});
98
113
  }
99
114
 
100
-
101
- @grok.decorators.func({name: 'renderRestPanel'})
102
- static async renderPanel(@grok.decorators.param({type: 'func'}) func: DG.Func) : Promise<DG.Widget> {
103
- return renderRestPanel(func as any) as any;
104
- }
105
-
106
- @grok.decorators.init()
107
- static init() {
108
- if (initCompleted)
109
- return;
110
-
111
- setModelCatalogHandler();
112
- setModelCatalogEventHandlers(options as any);
113
-
114
- initCompleted = true;
115
- }
116
-
117
-
118
- @grok.decorators.app({
119
- browsePath: 'Compute',
120
- name: 'Model Hub',
121
- outputs: [{type: 'view', name: 'result'}],
122
- })
123
- static modelCatalog() {
124
- return startModelCatalog(options as any);
125
- }
126
-
127
-
128
- @grok.decorators.func({
129
- meta: { role: ' ', app: ' '}
130
- })
131
- static modelCatalogTreeBrowser(treeNode: DG.TreeViewGroup, browseView: DG.ViewBase) {
132
- makeModelTreeBrowser(treeNode as any);
133
- }
134
-
135
115
  //
136
116
  // Testing code
137
117
  //
@@ -304,96 +284,52 @@ export class PackageFunctions {
304
284
  }
305
285
 
306
286
 
307
- @grok.decorators.func({
308
- meta: {
309
- features: '{"fitting": true, "sens-analysis": true}',
310
- runOnOpen: 'true',
311
- runOnInput: 'true',
312
- },
313
- outputs: [
314
- {
315
- name: 'integer',
316
- type: 'int',
317
- },
318
- {
319
- name: 'float1',
320
- type: 'double',
321
- },
322
- {
323
- name: 'float2',
324
- type: 'double',
325
- },
326
- {
327
- name: 'table1',
328
- type: 'dataframe',
329
- options: {viewer: 'Line chart(block:60) | Grid(block:40)'},
330
- },
331
- {
332
- name: 'table2',
333
- type: 'dataframe',
334
- options: {viewer: 'Line chart(block:60) | Grid(block:40)'},
335
- },
336
- ],
337
- description: 'Test for optimization: multiple scalars output',
338
- editor: 'Compute:RichFunctionViewEditor',
339
- })
340
- static fitTestFunc(
341
- @grok.decorators.param({options: {caption: 'param1', min: '-3', max: '3', initialValue: '1'}}) x1: number,
342
- @grok.decorators.param({options: {caption: 'param2', min: '-3', max: '3', initialValue: '-1'}}) x2: number,
343
- @grok.decorators.param({options: {caption: 'table'}}) y: DG.DataFrame,
344
- bool: boolean) {
345
- return {
346
- integer: x1**3 * (x1 - 1) * x2**3 * (x2 - 1),
347
- float1: (x2 - 1)**2 + (x1 - 1)**2,
348
- float2: (x2 - 1)**4 + (x1 - 1)**4,
349
- table1: DG.DataFrame.fromColumns([
350
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
351
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [x1 + x2 + 1, 4, 9, 16, 25]),
352
- ]),
353
- table2: DG.DataFrame.fromColumns([
354
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
355
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [x1 + x2 + 1, 8, 27, 64, 125]),
356
- ]),
287
+ @grok.decorators.func({outputs: [{type: 'object', name: 'input'}]})
288
+ static async CustomInputMock(
289
+ @grok.decorators.param({type: 'object'}) params: any): Promise<FuncCallInput> {
290
+ return new InputMock();
291
+ }
292
+
293
+
294
+ @grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
295
+ static RangeValidatorFactory(
296
+ @grok.decorators.param({type: 'object'}) params: any) {
297
+ const {min, max} = params;
298
+ return (val: number) => {
299
+ if (val < min || val > max)
300
+ return makeValidationResultInst({errors: [`Out of range [${min}, ${max}] value: ${val}`]});
357
301
  };
358
302
  }
359
303
 
360
304
 
361
- @grok.decorators.func({description: 'Test for optimization: multiple scalars output'})
362
- static async testFittingOutputs() {
363
- const func = await grok.functions.find('Compute:fitTestFunc');
364
-
365
- if (func === null) {
366
- grok.shell.error('The function "Compute:fitTestFunc" not found!');
367
- return;
368
- }
369
-
370
- const targetDf1 = DG.DataFrame.fromColumns([
371
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
372
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [1, 4.3, 9.1, 16, 25]),
373
- ]);
374
- targetDf1.name = 'test-df1';
375
-
376
- const targetDf2 = DG.DataFrame.fromColumns([
377
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'arg', [1, 2, 3, 4, 5]),
378
- DG.Column.fromList(DG.COLUMN_TYPE.FLOAT, 'func', [1, 8.5, 27.6, 64.9, 125]),
379
- ]);
380
- targetDf2.name = 'test-df2';
381
-
382
- await FittingView.fromEmpty(func as any, {
383
- targets: {
384
- integer: {default: 123, enabled: true},
385
- float1: {default: 456.789, enabled: true},
386
- table1: {
387
- default: targetDf1,
388
- enabled: true,
389
- argumentCol: 'arg',
390
- },
391
- table2: {
392
- default: targetDf2,
393
- enabled: true,
394
- argumentCol: 'arg',
395
- },
396
- },
397
- });
305
+ @grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
306
+ static AsyncValidatorDemoFactory(
307
+ @grok.decorators.param({type: 'object'}) params: any) {
308
+ return async (val: number) => {
309
+ await new Promise((resolve) => setTimeout(resolve, 100));
310
+ if (val === 0)
311
+ return makeValidationResultInst({warnings: [`Try non-null value`]});
312
+ };
313
+ }
314
+
315
+
316
+ @grok.decorators.func({outputs: [{type: 'object', name: 'validator'}]})
317
+ static GlobalValidatorDemoFactory(
318
+ @grok.decorators.param({type: 'object'}) params: any) {
319
+ const {max} = params;
320
+ return async (_val: number, info: ValidationInfo) => {
321
+ if (info.isRevalidation) {
322
+ if (info.context?.isOk)
323
+ return makeValidationResultInst();
324
+ return makeValidationResultInst({warnings: [`Try lowering a value as well`]});
325
+ }
326
+ await new Promise((resolve) => setTimeout(resolve, 100));
327
+ const {a, b, c} = info.funcCall.inputs;
328
+ const s = a + b + c;
329
+ const isOk = s <= max;
330
+ const valRes = isOk ? makeValidationResultInst() : makeValidationResultInst({warnings: [`Try lowering a value`]});
331
+ const fields = ['a', 'b', 'c'].filter((p) => p !== info.param);
332
+ return makeRevalidationInst(fields, {isOk}, valRes);
333
+ };
398
334
  }
399
335
  }