@platforma-sdk/model 1.29.2 → 1.29.12
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/components/PlDataTable.d.ts +40 -4
- package/dist/components/PlDataTable.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +563 -473
- package/dist/index.mjs.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/PlDataTable.ts +243 -67
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PlatformaSDKVersion = "1.29.
|
|
1
|
+
export declare const PlatformaSDKVersion = "1.29.12";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.12",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"utility-types": "^3.11.0",
|
|
22
22
|
"canonicalize": "~2.1.0",
|
|
23
23
|
"zod": "~3.23.8",
|
|
24
|
-
"@milaboratories/pl-
|
|
25
|
-
"@milaboratories/pl-
|
|
24
|
+
"@milaboratories/pl-error-like": "^1.12.0",
|
|
25
|
+
"@milaboratories/pl-model-common": "^1.13.6"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"typescript": "~5.5.4",
|
|
@@ -7,17 +7,33 @@ import type {
|
|
|
7
7
|
PColumnSpec,
|
|
8
8
|
PColumnValues,
|
|
9
9
|
PObjectId,
|
|
10
|
+
PTableColumnIdColumn,
|
|
11
|
+
PTableColumnSpec,
|
|
12
|
+
PTableDef,
|
|
10
13
|
PTableHandle,
|
|
11
14
|
PTableRecordFilter,
|
|
15
|
+
PTableRecordSingleValueFilterV2,
|
|
12
16
|
PTableSorting,
|
|
13
17
|
} from '@milaboratories/pl-model-common';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
import { getAxisId, getColumnIdAndSpec, matchAxisId } from '@milaboratories/pl-model-common';
|
|
19
|
+
import type { AxisLabelProvider, ColumnProvider, RenderCtx } from '../render';
|
|
20
|
+
import { PColumnCollection, TreeNodeAccessor } from '../render';
|
|
21
|
+
import canonicalize from 'canonicalize';
|
|
22
|
+
|
|
23
|
+
/** Canonicalized PTableColumnSpec JSON string */
|
|
24
|
+
export type PTableColumnSpecJson = string & {
|
|
25
|
+
__json_canonicalized: PTableColumnSpec;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Encode `PTableColumnId` as canonicalized JSON string */
|
|
29
|
+
export function strinfigyPTableColumnId(spec: PTableColumnSpec): PTableColumnSpecJson {
|
|
30
|
+
return canonicalize(spec)! as PTableColumnSpecJson;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Parse `PTableColumnId` from JSON string */
|
|
34
|
+
export function parsePTableColumnId(str: PTableColumnSpecJson): PTableColumnSpec {
|
|
35
|
+
return JSON.parse(str) as PTableColumnSpec;
|
|
36
|
+
}
|
|
21
37
|
|
|
22
38
|
/** Data table state */
|
|
23
39
|
export type PlDataTableGridState = {
|
|
@@ -44,7 +60,7 @@ export type PlDataTableGridState = {
|
|
|
44
60
|
/** Includes column visibility */
|
|
45
61
|
columnVisibility?: {
|
|
46
62
|
/** All colIds which were hidden */
|
|
47
|
-
hiddenColIds:
|
|
63
|
+
hiddenColIds: PTableColumnSpecJson[];
|
|
48
64
|
};
|
|
49
65
|
/** current sheet selections */
|
|
50
66
|
sheets?: Record<string, string | number>;
|
|
@@ -319,49 +335,29 @@ export type CreatePlDataTableOps = {
|
|
|
319
335
|
coreJoinType?: 'inner' | 'full';
|
|
320
336
|
};
|
|
321
337
|
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
* @param columns column list
|
|
327
|
-
* @param tableState table ui state
|
|
328
|
-
* @returns
|
|
329
|
-
*/
|
|
330
|
-
export function createPlDataTable<A, U>(
|
|
331
|
-
ctx: RenderCtx<A, U>,
|
|
332
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
333
|
-
tableState: PlDataTableState | undefined
|
|
334
|
-
): PTableHandle | undefined;
|
|
335
|
-
export function createPlDataTable<A, U>(
|
|
336
|
-
ctx: RenderCtx<A, U>,
|
|
337
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
338
|
-
tableState: PlDataTableState | undefined,
|
|
339
|
-
ops: CreatePlDataTableOps
|
|
340
|
-
): PTableHandle | undefined;
|
|
341
|
-
/** @deprecated use method with extended ops as the last argument */
|
|
342
|
-
export function createPlDataTable<A, U>(
|
|
343
|
-
ctx: RenderCtx<A, U>,
|
|
344
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
345
|
-
tableState: PlDataTableState | undefined,
|
|
346
|
-
filters: PTableRecordFilter[]
|
|
347
|
-
): PTableHandle | undefined;
|
|
348
|
-
export function createPlDataTable<A, U>(
|
|
349
|
-
ctx: RenderCtx<A, U>,
|
|
350
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
351
|
-
tableState: PlDataTableState | undefined,
|
|
352
|
-
ops?: PTableRecordFilter[] | CreatePlDataTableOps,
|
|
353
|
-
): PTableHandle | undefined {
|
|
354
|
-
// ops migration for backward compatibility with previous deprecated API
|
|
355
|
-
if (Array.isArray(ops)) {
|
|
356
|
-
ops = { filters: ops };
|
|
357
|
-
}
|
|
338
|
+
/** Check if column is a label column */
|
|
339
|
+
export function isLabelColumn(column: PColumnSpec) {
|
|
340
|
+
return column.axesSpec.length === 1 && column.name === 'pl7.app/label';
|
|
341
|
+
}
|
|
358
342
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
343
|
+
/** Get all label columns from the result pool */
|
|
344
|
+
export function getAllLabelColumns(
|
|
345
|
+
resultPool: AxisLabelProvider & ColumnProvider,
|
|
346
|
+
): PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[] | undefined {
|
|
347
|
+
return new PColumnCollection()
|
|
348
|
+
.addAxisLabelProvider(resultPool)
|
|
349
|
+
.addColumnProvider(resultPool)
|
|
350
|
+
.getColumns({
|
|
351
|
+
name: 'pl7.app/label',
|
|
352
|
+
axes: [{}], // exactly one axis
|
|
353
|
+
}, { dontWaitAllData: true });
|
|
354
|
+
}
|
|
364
355
|
|
|
356
|
+
/** Get label columns matching the provided columns from the result pool */
|
|
357
|
+
export function getMatchingLabelColumns(
|
|
358
|
+
columns: PColumnIdAndSpec[],
|
|
359
|
+
allLabelColumns: PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[],
|
|
360
|
+
): PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[] {
|
|
365
361
|
const colId = (id: PObjectId, domain?: Record<string, string>) => {
|
|
366
362
|
let wid = id.toString();
|
|
367
363
|
if (domain) {
|
|
@@ -373,12 +369,11 @@ export function createPlDataTable<A, U>(
|
|
|
373
369
|
return wid;
|
|
374
370
|
};
|
|
375
371
|
|
|
376
|
-
const labelColumns = new Map<string,
|
|
377
|
-
|
|
372
|
+
const labelColumns = new Map<string, typeof allLabelColumns[number]>();
|
|
378
373
|
for (const col of columns) {
|
|
379
374
|
for (const axis of col.spec.axesSpec) {
|
|
380
375
|
const axisId = getAxisId(axis);
|
|
381
|
-
for (const labelColumn of
|
|
376
|
+
for (const labelColumn of allLabelColumns) {
|
|
382
377
|
const labelAxis = labelColumn.spec.axesSpec[0];
|
|
383
378
|
const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);
|
|
384
379
|
if (matchAxisId(axisId, labelAxisId)) {
|
|
@@ -403,38 +398,219 @@ export function createPlDataTable<A, U>(
|
|
|
403
398
|
}
|
|
404
399
|
}
|
|
405
400
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
401
|
+
return [...labelColumns.values()];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Check if all columns are computed */
|
|
405
|
+
export function allColumnsComputed(
|
|
406
|
+
columns: PColumn<PColumnValues | TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[],
|
|
407
|
+
): boolean {
|
|
408
|
+
type Data = typeof columns[number]['data'];
|
|
409
|
+
const isValues = (d: Data): d is PColumnValues => Array.isArray(d);
|
|
410
|
+
const isAccessor = (d: Data): d is TreeNodeAccessor => d instanceof TreeNodeAccessor;
|
|
411
|
+
const isDataInfo = (d: Data): d is DataInfo<TreeNodeAccessor> =>
|
|
412
|
+
typeof d === 'object' && 'type' in d;
|
|
413
|
+
|
|
414
|
+
return columns
|
|
415
|
+
.map((c) => c.data)
|
|
416
|
+
.every((d): boolean => {
|
|
417
|
+
if (isValues(d)) {
|
|
418
|
+
return true;
|
|
419
|
+
} else if (isAccessor(d)) {
|
|
420
|
+
return d.getIsReadyOrError();
|
|
421
|
+
} else if (isDataInfo(d)) {
|
|
422
|
+
const type = d.type;
|
|
423
|
+
switch (type) {
|
|
424
|
+
case 'Json':
|
|
425
|
+
return true;
|
|
426
|
+
case 'JsonPartitioned':
|
|
427
|
+
return Object.values(d.parts).every((p) => p.getIsReadyOrError());
|
|
428
|
+
case 'BinaryPartitioned':
|
|
429
|
+
return Object.values(d.parts)
|
|
430
|
+
.every((p) => p.index.getIsReadyOrError() && p.values.getIsReadyOrError());
|
|
431
|
+
}
|
|
432
|
+
} else {
|
|
433
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
434
|
+
throw Error(`unsupported column data type: ${d satisfies never}`);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
}
|
|
413
438
|
|
|
439
|
+
function createPTableDef(
|
|
440
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
441
|
+
labelColumns: PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[],
|
|
442
|
+
coreJoinType: 'inner' | 'full',
|
|
443
|
+
filters: PTableRecordSingleValueFilterV2[],
|
|
444
|
+
sorting: PTableSorting[],
|
|
445
|
+
coreColumnPredicate?: ((spec: PColumnSpec) => boolean),
|
|
446
|
+
): PTableDef<PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>> {
|
|
414
447
|
let coreColumns = columns;
|
|
415
448
|
const secondaryColumns: typeof columns = [];
|
|
416
449
|
|
|
417
|
-
if (
|
|
450
|
+
if (coreColumnPredicate) {
|
|
418
451
|
coreColumns = [];
|
|
419
452
|
for (const c of columns)
|
|
420
|
-
if (
|
|
453
|
+
if (coreColumnPredicate(c.spec)) coreColumns.push(c);
|
|
421
454
|
else secondaryColumns.push(c);
|
|
422
455
|
}
|
|
423
456
|
|
|
424
|
-
secondaryColumns.push(...labelColumns
|
|
457
|
+
secondaryColumns.push(...labelColumns);
|
|
425
458
|
|
|
426
|
-
return
|
|
459
|
+
return {
|
|
427
460
|
src: {
|
|
428
461
|
type: 'outer',
|
|
429
462
|
primary: {
|
|
430
|
-
type:
|
|
463
|
+
type: coreJoinType,
|
|
431
464
|
entries: coreColumns.map((c) => ({ type: 'column', column: c })),
|
|
432
465
|
},
|
|
433
466
|
secondary: secondaryColumns.map((c) => ({ type: 'column', column: c })),
|
|
434
467
|
},
|
|
435
|
-
filters
|
|
436
|
-
sorting
|
|
437
|
-
}
|
|
468
|
+
filters,
|
|
469
|
+
sorting,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Create p-table handle given ui table state
|
|
475
|
+
*
|
|
476
|
+
* @param ctx context
|
|
477
|
+
* @param columns column list
|
|
478
|
+
* @param tableState table ui state
|
|
479
|
+
* @returns PlAgDataTable table source
|
|
480
|
+
*/
|
|
481
|
+
export function createPlDataTable<A, U>(
|
|
482
|
+
ctx: RenderCtx<A, U>,
|
|
483
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
484
|
+
tableState: PlDataTableState | undefined
|
|
485
|
+
): PTableHandle | undefined;
|
|
486
|
+
export function createPlDataTable<A, U>(
|
|
487
|
+
ctx: RenderCtx<A, U>,
|
|
488
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
489
|
+
tableState: PlDataTableState | undefined,
|
|
490
|
+
ops: CreatePlDataTableOps
|
|
491
|
+
): PTableHandle | undefined;
|
|
492
|
+
/** @deprecated use method with extended ops as the last argument */
|
|
493
|
+
export function createPlDataTable<A, U>(
|
|
494
|
+
ctx: RenderCtx<A, U>,
|
|
495
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
496
|
+
tableState: PlDataTableState | undefined,
|
|
497
|
+
filters: PTableRecordFilter[]
|
|
498
|
+
): PTableHandle | undefined;
|
|
499
|
+
export function createPlDataTable<A, U>(
|
|
500
|
+
ctx: RenderCtx<A, U>,
|
|
501
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
502
|
+
tableState: PlDataTableState | undefined,
|
|
503
|
+
ops?: PTableRecordFilter[] | CreatePlDataTableOps,
|
|
504
|
+
): PTableHandle | undefined {
|
|
505
|
+
// ops migration for backward compatibility with previous deprecated API
|
|
506
|
+
if (Array.isArray(ops)) {
|
|
507
|
+
ops = { filters: ops };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const coreJoinType = ops?.coreJoinType ?? 'full';
|
|
511
|
+
const filters: PTableRecordSingleValueFilterV2[]
|
|
512
|
+
= [...(ops?.filters ?? []), ...(tableState?.pTableParams?.filters ?? [])];
|
|
513
|
+
const sorting: PTableSorting[] = tableState?.pTableParams?.sorting ?? [];
|
|
514
|
+
|
|
515
|
+
const allLabelColumns = getAllLabelColumns(ctx.resultPool);
|
|
516
|
+
if (!allLabelColumns) return undefined;
|
|
517
|
+
|
|
518
|
+
const labelColumns = getMatchingLabelColumns(columns.map(getColumnIdAndSpec), allLabelColumns);
|
|
519
|
+
|
|
520
|
+
// if at least one column is not yet computed, we can't show the table
|
|
521
|
+
if (!allColumnsComputed([...columns, ...labelColumns])) return undefined;
|
|
522
|
+
|
|
523
|
+
return ctx.createPTable(
|
|
524
|
+
createPTableDef(columns, labelColumns, coreJoinType, filters, sorting, ops?.coreColumnPredicate));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** PlAgDataTable model */
|
|
528
|
+
export type PlDataTableModel = {
|
|
529
|
+
/** p-table specification (full, including hidden columns) */
|
|
530
|
+
tableSpec: PTableColumnSpec[];
|
|
531
|
+
/** p-table handle (integration of visible columns data) */
|
|
532
|
+
tableHandle: PTableHandle;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
/** Check if column is hidden by default */
|
|
536
|
+
export function isColumnOptional(spec: { annotations?: Record<string, string> }): boolean {
|
|
537
|
+
return spec.annotations?.['pl7.app/table/visibility'] === 'optional';
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Create p-table spec and handle given ui table state
|
|
542
|
+
*
|
|
543
|
+
* @param ctx context
|
|
544
|
+
* @param columns column list
|
|
545
|
+
* @param tableState table ui state
|
|
546
|
+
* @returns PlAgDataTableV2 table source
|
|
547
|
+
*/
|
|
548
|
+
export function createPlDataTableV2<A, U>(
|
|
549
|
+
ctx: RenderCtx<A, U>,
|
|
550
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
551
|
+
mainColumnPredicate: (spec: PColumnSpec) => boolean,
|
|
552
|
+
tableState: PlDataTableState | undefined,
|
|
553
|
+
ops?: CreatePlDataTableOps,
|
|
554
|
+
): PlDataTableModel | undefined {
|
|
555
|
+
const coreJoinType = ops?.coreJoinType ?? 'full';
|
|
556
|
+
const filters: PTableRecordSingleValueFilterV2[]
|
|
557
|
+
= [...(ops?.filters ?? []), ...(tableState?.pTableParams?.filters ?? [])];
|
|
558
|
+
const sorting: PTableSorting[] = tableState?.pTableParams?.sorting ?? [];
|
|
559
|
+
|
|
560
|
+
const mainColumn = columns.find((c) => mainColumnPredicate(c.spec));
|
|
561
|
+
if (!mainColumn) return undefined;
|
|
562
|
+
|
|
563
|
+
const allLabelColumns = getAllLabelColumns(ctx.resultPool);
|
|
564
|
+
if (!allLabelColumns) return undefined;
|
|
565
|
+
|
|
566
|
+
const spec: PTableColumnSpec[] = [
|
|
567
|
+
...mainColumn.spec.axesSpec.map((axis) => ({
|
|
568
|
+
type: 'axis',
|
|
569
|
+
id: getAxisId(axis),
|
|
570
|
+
spec: axis,
|
|
571
|
+
} satisfies PTableColumnSpec)),
|
|
572
|
+
...[...columns, ...allLabelColumns].map((c) => ({
|
|
573
|
+
type: 'column',
|
|
574
|
+
id: c.id,
|
|
575
|
+
spec: c.spec,
|
|
576
|
+
} satisfies PTableColumnSpec)),
|
|
577
|
+
];
|
|
578
|
+
|
|
579
|
+
const hiddenColumns = new Set<PObjectId>(((): PObjectId[] => {
|
|
580
|
+
// Inner join works as a filter - all columns must be present
|
|
581
|
+
if (coreJoinType === 'inner') return [];
|
|
582
|
+
|
|
583
|
+
const hiddenColIds = tableState?.gridState.columnVisibility?.hiddenColIds
|
|
584
|
+
?.map(parsePTableColumnId)
|
|
585
|
+
.filter((c) => c.type === 'column')
|
|
586
|
+
.map((c) => c.id);
|
|
587
|
+
if (hiddenColIds) return hiddenColIds;
|
|
588
|
+
|
|
589
|
+
return columns
|
|
590
|
+
.filter((c) => isColumnOptional(c.spec))
|
|
591
|
+
.map((c) => c.id);
|
|
592
|
+
})());
|
|
593
|
+
|
|
594
|
+
// Main column must always be included in join to integrate all other columns
|
|
595
|
+
hiddenColumns.delete(mainColumn.id);
|
|
596
|
+
// Filters decrease the number of result rows, sorting changes the order of result rows
|
|
597
|
+
[...filters.map((f) => f.column), ...sorting.map((s) => s.column)]
|
|
598
|
+
.filter((c): c is PTableColumnIdColumn => c.type === 'column')
|
|
599
|
+
.map((c) => hiddenColumns.delete(c.id));
|
|
600
|
+
|
|
601
|
+
const visibleColumns = columns.filter((c) => !hiddenColumns.has(c.id));
|
|
602
|
+
const labelColumns = getMatchingLabelColumns(visibleColumns.map(getColumnIdAndSpec), allLabelColumns);
|
|
603
|
+
|
|
604
|
+
// if at least one column is not yet computed, we can't show the table
|
|
605
|
+
if (!allColumnsComputed([...visibleColumns, ...labelColumns])) return undefined;
|
|
606
|
+
|
|
607
|
+
const handle = ctx.createPTable(
|
|
608
|
+
createPTableDef(columns, labelColumns, coreJoinType, filters, sorting, ops?.coreColumnPredicate));
|
|
609
|
+
|
|
610
|
+
return {
|
|
611
|
+
tableSpec: spec,
|
|
612
|
+
tableHandle: handle,
|
|
613
|
+
} satisfies PlDataTableModel;
|
|
438
614
|
}
|
|
439
615
|
|
|
440
616
|
/** Create sheet entries for PlDataTable */
|