@datagrok/compute 1.45.4 → 1.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "1.45.4",
4
+ "version": "1.46.0",
5
5
  "author": {
6
6
  "name": "Andrey Sharapov",
7
7
  "email": "andrey.sharapov@softwarecountry.com"
@@ -13,15 +13,18 @@
13
13
  "directory": "packages/Compute"
14
14
  },
15
15
  "dependencies": {
16
- "@datagrok-libraries/test": "1.4.1",
17
16
  "cash-dom": "8.1.5",
18
17
  "dayjs": "1.11.23",
19
18
  "exceljs": "4.4.0",
20
19
  "rxjs": "6.6.7",
21
20
  "@datagrok-libraries/compute-api": "^0.8.0",
22
- "@datagrok-libraries/compute-utils": "^1.47.0",
23
- "@datagrok-libraries/utils": "^4.7.9",
24
- "datagrok-api": "^1.27.11"
21
+ "@datagrok-libraries/test": "^1.6.0",
22
+ "datagrok-api": "^1.28.1",
23
+ "@datagrok-libraries/compute-utils": "^1.48.0",
24
+ "@datagrok-libraries/utils": "^4.8.0"
25
+ },
26
+ "overrides": {
27
+ "uuid": "^11.1.1"
25
28
  },
26
29
  "devDependencies": {
27
30
  "@types/lodash.clonedeepwith": "^4.5.9",
@@ -35,9 +38,6 @@
35
38
  "All users"
36
39
  ],
37
40
  "category": "Compute",
38
- "meta": {
39
- "dartium": false
40
- },
41
41
  "scripts": {
42
42
  "build": "grok build",
43
43
  "typecheck": "grok tsc --noEmit -p tsconfig.json",
@@ -1,9 +1,9 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
- import {category, test, before, delay} from '@datagrok-libraries/test/src/test';
2
+ import {category, test, before} from '@datagrok-libraries/test/src/test';
3
3
  import {RichFunctionView} from '@datagrok-libraries/compute-utils';
4
4
  import {take, filter} from 'rxjs/operators';
5
5
  import {applyTransformations} from '@datagrok-libraries/utils/src/json-serialization';
6
- import {getFuncCallIO} from './utils';
6
+ import {getFuncCallIO, inputsRendered, inputsApplied, eventually} from './utils';
7
7
  import {expectDeepEqual} from '@datagrok-libraries/utils/src/expect';
8
8
  import {InputVariants} from '@datagrok-libraries/compute-utils/old-views/src/rich-function-view';
9
9
  import fc1 from './snapshots/fc1.json';
@@ -58,13 +58,13 @@ category('Compute: RichFunctionView Inputs', async () => {
58
58
  inputsMap[prop.name] = input;
59
59
  });
60
60
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
61
- await delay(100);
61
+ await inputsRendered(view, inputsMap);
62
62
  for (const [name, input] of Object.entries(inputsMap)) {
63
63
  input.value = inputValues[name];
64
64
  const element = (input as any).input;
65
65
  element.dispatchEvent(new Event('input', {bubbles: true}));
66
66
  }
67
- await delay(300);
67
+ await inputsApplied(view, inputValues);
68
68
  await view.doRun();
69
69
  const expected = {
70
70
  'inputs': [
@@ -95,7 +95,7 @@ category('Compute: RichFunctionView Inputs', async () => {
95
95
  });
96
96
 
97
97
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
98
- await delay(100);
98
+ await inputsRendered(view, inputsMap);
99
99
  await view.doRun();
100
100
  view.funcCall.setParamValue('a', 2);
101
101
  view.funcCall.setParamValue('b', 3.2);
@@ -131,15 +131,14 @@ category('Compute: RichFunctionView Inputs', async () => {
131
131
  inputsMap[prop.name] = input;
132
132
  });
133
133
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
134
- await delay(100);
134
+ await inputsRendered(view, inputsMap);
135
135
  await view.doRun();
136
- await delay(100);
137
136
  for (const [name, input] of Object.entries(inputsMap)) {
138
137
  input.value = inputValues[name];
139
138
  const element = (input as any).input;
140
139
  element.dispatchEvent(new Event('input', {bubbles: true}));
141
140
  }
142
- await delay(300);
141
+ await inputsApplied(view, inputValues);
143
142
  await view.doRun();
144
143
  const expected = {
145
144
  'inputs': [
@@ -161,7 +160,6 @@ category('Compute: RichFunctionView Inputs', async () => {
161
160
  const view = new RichFunctionView('Compute:simpleInputsDefaultValues', {historyEnabled: false, isTabbed: false});
162
161
 
163
162
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
164
- await delay(100);
165
163
  const expected = {
166
164
  'inputs': [
167
165
  ['a', 1],
@@ -169,7 +167,7 @@ category('Compute: RichFunctionView Inputs', async () => {
169
167
  ['c', 'test'],
170
168
  ],
171
169
  };
172
- expectDeepEqual(getFuncCallIO(view.funcCall).inputs, expected.inputs);
170
+ await eventually(() => expectDeepEqual(getFuncCallIO(view.funcCall).inputs, expected.inputs));
173
171
  });
174
172
 
175
173
  test('Complex inputs setParamValue', async () => {
@@ -205,10 +203,10 @@ category('Compute: RichFunctionView Inputs', async () => {
205
203
  inputsMap[prop.name] = input;
206
204
  });
207
205
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
208
- await delay(100);
206
+ await inputsRendered(view, inputsMap);
209
207
  inputsMap['data'].value = inputValues['data'];
210
208
  view.funcCall.setParamValue('df', inputValues['df']);
211
- await delay(300);
209
+ await inputsApplied(view, inputValues);
212
210
  await view.doRun();
213
211
  expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
214
212
  expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
@@ -258,10 +256,10 @@ category('Compute: RichFunctionView Inputs', async () => {
258
256
  inputsMap[prop.name] = input;
259
257
  });
260
258
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
261
- await delay(100);
259
+ await inputsRendered(view, inputsMap);
262
260
  inputsMap['data'].value = inputValuesPre['data'];
263
261
  view.funcCall.setParamValue('df', inputValuesPre['df']);
264
- await delay(300);
262
+ await inputsApplied(view, inputValuesPre);
265
263
  await view.doRun();
266
264
  const inputValues: Record<string, any> = {
267
265
  df: DG.DataFrame.fromColumns([
@@ -271,7 +269,7 @@ category('Compute: RichFunctionView Inputs', async () => {
271
269
  };
272
270
  inputsMap['data'].value = inputValues['data'];
273
271
  view.funcCall.setParamValue('df', inputValues['df']);
274
- await delay(300);
272
+ await inputsApplied(view, inputValues);
275
273
  await view.doRun();
276
274
  expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
277
275
  expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
@@ -286,10 +284,8 @@ category('Compute: RichFunctionView Validation', async () => {
286
284
  test('Validate on start', async () => {
287
285
  const view = new RichFunctionView('Compute:validationTest', {historyEnabled: false, isTabbed: false});
288
286
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
289
- await delay(1500);
290
- const results = view.getValidationState();
291
- expectDeepEqual(
292
- results,
287
+ await eventually(() => expectDeepEqual(
288
+ view.getValidationState(),
293
289
  {
294
290
  'a': {
295
291
  'errors': [
@@ -321,7 +317,7 @@ category('Compute: RichFunctionView Validation', async () => {
321
317
  'context': {},
322
318
  },
323
319
  },
324
- );
320
+ ));
325
321
  });
326
322
 
327
323
  test('Validate on input', async () => {
@@ -336,17 +332,14 @@ category('Compute: RichFunctionView Validation', async () => {
336
332
  inputsMap[prop.name] = input;
337
333
  });
338
334
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
339
- await delay(1500);
335
+ await inputsRendered(view, inputsMap);
340
336
  for (const [name, input] of Object.entries(inputsMap)) {
341
337
  input.value = inputValues[name];
342
338
  const element = (input as any).input;
343
339
  element.dispatchEvent(new Event('input', {bubbles: true}));
344
340
  }
345
- await delay(400);
346
-
347
- const results = view.getValidationState();
348
- expectDeepEqual(
349
- results,
341
+ await eventually(() => expectDeepEqual(
342
+ view.getValidationState(),
350
343
  {
351
344
  'b': {
352
345
  'errors': [
@@ -354,7 +347,7 @@ category('Compute: RichFunctionView Validation', async () => {
354
347
  ],
355
348
  },
356
349
  },
357
- );
350
+ ));
358
351
  });
359
352
 
360
353
  test('Revalidation sequence', async () => {
@@ -369,16 +362,14 @@ category('Compute: RichFunctionView Validation', async () => {
369
362
  inputsMap[prop.name] = input;
370
363
  });
371
364
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
372
- await delay(1500);
365
+ await inputsRendered(view, inputsMap);
373
366
  for (const [name, input] of Object.entries(inputsMap)) {
374
367
  input.value = inputValues[name];
375
368
  const element = (input as any).input;
376
369
  element.dispatchEvent(new Event('input', {bubbles: true}));
377
370
  }
378
- await delay(1000);
379
- const results = view.getValidationState();
380
- expectDeepEqual(
381
- results,
371
+ await eventually(() => expectDeepEqual(
372
+ view.getValidationState(),
382
373
  {
383
374
  'a': {
384
375
  'revalidate': ['b', 'c'],
@@ -398,6 +389,6 @@ category('Compute: RichFunctionView Validation', async () => {
398
389
  ],
399
390
  },
400
391
  },
401
- );
392
+ ));
402
393
  });
403
394
  });
@@ -1,9 +1,9 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
- import {category, test, before, delay} from '@datagrok-libraries/test/src/test';
2
+ import {category, test, before} from '@datagrok-libraries/test/src/test';
3
3
  import {createRFV, initComputeApi} from '@datagrok-libraries/compute-api';
4
4
  import {take, filter} from 'rxjs/operators';
5
5
  import {applyTransformations} from '@datagrok-libraries/utils/src/json-serialization';
6
- import {getFuncCallIO} from './utils';
6
+ import {getFuncCallIO, inputsRendered, inputsApplied, eventually} from './utils';
7
7
  import {expectDeepEqual} from '@datagrok-libraries/utils/src/expect';
8
8
  import fc1 from './snapshots/fc1.json';
9
9
  import {InputVariants} from '@datagrok-libraries/compute-utils/old-views/src/rich-function-view';
@@ -77,13 +77,13 @@ category('Compute API: RFV Inputs', async () => {
77
77
  inputsMap[prop.name] = input;
78
78
  });
79
79
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
80
- await delay(100);
80
+ await inputsRendered(view, inputsMap);
81
81
  for (const [name, input] of Object.entries(inputsMap)) {
82
82
  input.value = inputValues[name];
83
83
  const element = (input as any).input;
84
84
  element.dispatchEvent(new Event('input', {bubbles: true}));
85
85
  }
86
- await delay(300);
86
+ await inputsApplied(view, inputValues);
87
87
  await view.doRun();
88
88
  const expected = {
89
89
  'inputs': [
@@ -132,7 +132,7 @@ category('Compute API: RFV Inputs', async () => {
132
132
  });
133
133
 
134
134
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
135
- await delay(100);
135
+ await inputsRendered(view, inputsMap);
136
136
  await view.doRun();
137
137
  view.funcCall.setParamValue('a', 2);
138
138
  view.funcCall.setParamValue('b', 3.2);
@@ -186,15 +186,14 @@ category('Compute API: RFV Inputs', async () => {
186
186
  inputsMap[prop.name] = input;
187
187
  });
188
188
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
189
- await delay(100);
189
+ await inputsRendered(view, inputsMap);
190
190
  await view.doRun();
191
- await delay(100);
192
191
  for (const [name, input] of Object.entries(inputsMap)) {
193
192
  input.value = inputValues[name];
194
193
  const element = (input as any).input;
195
194
  element.dispatchEvent(new Event('input', {bubbles: true}));
196
195
  }
197
- await delay(300);
196
+ await inputsApplied(view, inputValues);
198
197
  await view.doRun();
199
198
  const expected = {
200
199
  'inputs': [
@@ -234,7 +233,6 @@ category('Compute API: RFV Inputs', async () => {
234
233
  const view = createRFV('Compute:simpleInputsDefaultValues', {historyEnabled: false, isTabbed: false});
235
234
 
236
235
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
237
- await delay(100);
238
236
  const expected = {
239
237
  'inputs': [
240
238
  [
@@ -251,7 +249,7 @@ category('Compute API: RFV Inputs', async () => {
251
249
  ],
252
250
  ],
253
251
  };
254
- expectDeepEqual(getFuncCallIO(view.funcCall).inputs, expected.inputs);
252
+ await eventually(() => expectDeepEqual(getFuncCallIO(view.funcCall).inputs, expected.inputs));
255
253
  });
256
254
 
257
255
  test('Complex inputs setParamValue', async () => {
@@ -287,11 +285,11 @@ category('Compute API: RFV Inputs', async () => {
287
285
  inputsMap[prop.name] = input;
288
286
  });
289
287
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
290
- await delay(100);
288
+ await inputsRendered(view, inputsMap);
291
289
  inputsMap['data'].value = inputValues['data'];
292
290
  // TODO: test df input, not rly used rn
293
291
  view.funcCall.setParamValue('df', inputValues['df']);
294
- await delay(300);
292
+ await inputsApplied(view, inputValues);
295
293
  await view.doRun();
296
294
  expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
297
295
  expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
@@ -341,11 +339,11 @@ category('Compute API: RFV Inputs', async () => {
341
339
  inputsMap[prop.name] = input;
342
340
  });
343
341
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
344
- await delay(100);
342
+ await inputsRendered(view, inputsMap);
345
343
  inputsMap['data'].value = inputValuesPre['data'];
346
344
  // TODO: test df input, not rly used rn
347
345
  view.funcCall.setParamValue('df', inputValuesPre['df']);
348
- await delay(300);
346
+ await inputsApplied(view, inputValuesPre);
349
347
  await view.doRun();
350
348
  const inputValues: Record<string, any> = {
351
349
  df: DG.DataFrame.fromColumns([
@@ -356,7 +354,7 @@ category('Compute API: RFV Inputs', async () => {
356
354
  inputsMap['data'].value = inputValues['data'];
357
355
  // TODO: test df input, not rly used rn
358
356
  view.funcCall.setParamValue('df', inputValues['df']);
359
- await delay(300);
357
+ await inputsApplied(view, inputValues);
360
358
  await view.doRun();
361
359
  expectDeepEqual(getFuncCallIO(view.funcCall), applyTransformations(fc1), {prefix: 'funcCall'});
362
360
  expectDeepEqual(getFuncCallIO(view.lastCall!), applyTransformations(fc1), {prefix: 'lastCall'});
@@ -372,10 +370,8 @@ category('Compute API: RFV Validation', async () => {
372
370
  test('Validate on start', async () => {
373
371
  const view = createRFV('Compute:validationTest', {historyEnabled: false, isTabbed: false});
374
372
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
375
- await delay(1500);
376
- const results = view.getValidationState();
377
- expectDeepEqual(
378
- results,
373
+ await eventually(() => expectDeepEqual(
374
+ view.getValidationState(),
379
375
  {
380
376
  'a': {
381
377
  'errors': [
@@ -417,7 +413,7 @@ category('Compute API: RFV Validation', async () => {
417
413
  'context': {},
418
414
  },
419
415
  },
420
- );
416
+ ));
421
417
  });
422
418
 
423
419
  test('Validate on input', async () => {
@@ -432,17 +428,14 @@ category('Compute API: RFV Validation', async () => {
432
428
  inputsMap[prop.name] = input;
433
429
  });
434
430
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
435
- await delay(1500);
431
+ await inputsRendered(view, inputsMap);
436
432
  for (const [name, input] of Object.entries(inputsMap)) {
437
433
  input.value = inputValues[name];
438
434
  const element = (input as any).input;
439
435
  element.dispatchEvent(new Event('input', {bubbles: true}));
440
436
  }
441
- await delay(400);
442
-
443
- const results = view.getValidationState();
444
- expectDeepEqual(
445
- results,
437
+ await eventually(() => expectDeepEqual(
438
+ view.getValidationState(),
446
439
  {
447
440
  'b': {
448
441
  'errors': [
@@ -452,7 +445,7 @@ category('Compute API: RFV Validation', async () => {
452
445
  ],
453
446
  },
454
447
  },
455
- );
448
+ ));
456
449
  });
457
450
 
458
451
  test('Revalidation sequence', async () => {
@@ -467,16 +460,14 @@ category('Compute API: RFV Validation', async () => {
467
460
  inputsMap[prop.name] = input;
468
461
  });
469
462
  await view.isReady.pipe(filter((x) => x), take(1)).toPromise();
470
- await delay(1500);
463
+ await inputsRendered(view, inputsMap);
471
464
  for (const [name, input] of Object.entries(inputsMap)) {
472
465
  input.value = inputValues[name];
473
466
  const element = (input as any).input;
474
467
  element.dispatchEvent(new Event('input', {bubbles: true}));
475
468
  }
476
- await delay(1000);
477
- const results = view.getValidationState();
478
- expectDeepEqual(
479
- results,
469
+ await eventually(() => expectDeepEqual(
470
+ view.getValidationState(),
480
471
  {
481
472
  'a': {
482
473
  'revalidate': [
@@ -507,6 +498,6 @@ category('Compute API: RFV Validation', async () => {
507
498
  ],
508
499
  },
509
500
  },
510
- );
501
+ ));
511
502
  });
512
503
  });
@@ -1,4 +1,5 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
+ import {waitUntil} from '@datagrok-libraries/test/src/test';
2
3
 
3
4
  export function getFuncCallIO(fc: DG.FuncCall) {
4
5
  return {
@@ -6,3 +7,35 @@ export function getFuncCallIO(fc: DG.FuncCall) {
6
7
  outputs: [...fc.outputs.entries()],
7
8
  };
8
9
  }
10
+
11
+ /** Resolves once the view has rendered an input for each input of its function. */
12
+ export async function inputsRendered(view: {funcCall: DG.FuncCall}, inputsMap: Record<string, unknown>): Promise<void> {
13
+ await waitUntil(() => view.funcCall.func.inputs.every((p) => inputsMap[p.name] != null),
14
+ () => `inputs not rendered: ${view.funcCall.func.inputs.map((p) => p.name).filter((n) => inputsMap[n] == null)}`);
15
+ }
16
+
17
+ /** Resolves once the view's call holds [values]: an input passes its value on after a validation debounce. */
18
+ export async function inputsApplied(view: {funcCall: DG.FuncCall}, values: Record<string, any>): Promise<void> {
19
+ // a dataframe comes back in a new wrapper on every read
20
+ const holds = (name: string) => values[name] instanceof DG.DataFrame ?
21
+ view.funcCall.inputs[name]?.dart === values[name].dart : view.funcCall.inputs[name] === values[name];
22
+ await waitUntil(() => Object.keys(values).every(holds),
23
+ () => `the call did not take the inputs: ${JSON.stringify(Object.keys(values).filter((name) => !holds(name)))}`);
24
+ }
25
+
26
+ /** Retries [assertion] until it passes; after [timeout] ms throws what it threw last. */
27
+ export async function eventually(assertion: () => void, timeout: number = 10000): Promise<void> {
28
+ let last: unknown = null;
29
+ const passes = () => {
30
+ try {
31
+ assertion();
32
+ return true;
33
+ } catch (e) {
34
+ last = e;
35
+ return false;
36
+ }
37
+ };
38
+ await waitUntil(passes, 'unreached', timeout).catch(() => {
39
+ throw last;
40
+ });
41
+ }