@milaboratories/pl-model-common 1.3.9
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/index.cjs +170 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +149 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -0
- package/src/block.ts +1 -0
- package/src/block_state.ts +30 -0
- package/src/branding.ts +4 -0
- package/src/common_types.ts +7 -0
- package/src/driver_kit.ts +23 -0
- package/src/drivers/blob.ts +42 -0
- package/src/drivers/index.ts +6 -0
- package/src/drivers/log.ts +79 -0
- package/src/drivers/ls.ts +80 -0
- package/src/drivers/pframe/column_filter.ts +19 -0
- package/src/drivers/pframe/data.ts +67 -0
- package/src/drivers/pframe/driver.ts +110 -0
- package/src/drivers/pframe/find_columns.ts +30 -0
- package/src/drivers/pframe/index.ts +11 -0
- package/src/drivers/pframe/pframe.ts +34 -0
- package/src/drivers/pframe/spec.ts +139 -0
- package/src/drivers/pframe/table.ts +31 -0
- package/src/drivers/pframe/table_calculate.ts +295 -0
- package/src/drivers/pframe/table_common.ts +28 -0
- package/src/drivers/pframe/type_util.ts +15 -0
- package/src/drivers/pframe/unique_values.ts +27 -0
- package/src/drivers/upload.ts +22 -0
- package/src/index.ts +10 -0
- package/src/navigation.ts +31 -0
- package/src/pool/entry.ts +20 -0
- package/src/pool/index.ts +3 -0
- package/src/pool/query.ts +93 -0
- package/src/pool/spec.ts +62 -0
- package/src/ref.ts +33 -0
- package/src/utag.ts +14 -0
- package/src/util.ts +3 -0
- package/src/value_or_error.ts +16 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { PTableColumnId, PTableColumnSpec } from './table_common';
|
|
2
|
+
import { PTableVector } from './data';
|
|
3
|
+
import { assertNever } from '../../util';
|
|
4
|
+
|
|
5
|
+
/** Defines a terminal column node in the join request tree */
|
|
6
|
+
export interface ColumnJoinEntry<Col> {
|
|
7
|
+
/** Node type discriminator */
|
|
8
|
+
readonly type: 'column';
|
|
9
|
+
|
|
10
|
+
/** Local column */
|
|
11
|
+
readonly column: Col;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Defines a join request tree node that will output only records present in
|
|
16
|
+
* all child nodes ({@link entries}).
|
|
17
|
+
* */
|
|
18
|
+
export interface InnerJoin<Col> {
|
|
19
|
+
/** Node type discriminator */
|
|
20
|
+
readonly type: 'inner';
|
|
21
|
+
|
|
22
|
+
/** Child nodes to be inner joined */
|
|
23
|
+
readonly entries: JoinEntry<Col>[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Defines a join request tree node that will output all records present at
|
|
28
|
+
* least in one of the child nodes ({@link entries}), values for those PColumns
|
|
29
|
+
* that lacks corresponding combinations of axis values will be marked as absent,
|
|
30
|
+
* see {@link PTableVector.absent}.
|
|
31
|
+
* */
|
|
32
|
+
export interface FullJoin<Col> {
|
|
33
|
+
/** Node type discriminator */
|
|
34
|
+
readonly type: 'full';
|
|
35
|
+
|
|
36
|
+
/** Child nodes to be fully outer joined */
|
|
37
|
+
readonly entries: JoinEntry<Col>[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Defines a join request tree node that will output all records present in
|
|
42
|
+
* {@link primary} child node, and records from the {@link secondary} nodes will
|
|
43
|
+
* be added to the output only if present, values for those PColumns from the
|
|
44
|
+
* {@link secondary} list, that lacks corresponding combinations of axis values
|
|
45
|
+
* will be marked as absent, see {@link PTableVector.absent}.
|
|
46
|
+
*
|
|
47
|
+
* This node can be thought as a chain of SQL LEFT JOIN operations starting from
|
|
48
|
+
* the {@link primary} node and adding {@link secondary} nodes one by one.
|
|
49
|
+
* */
|
|
50
|
+
export interface OuterJoin<Col> {
|
|
51
|
+
/** Node type discriminator */
|
|
52
|
+
readonly type: 'outer';
|
|
53
|
+
|
|
54
|
+
/** Primes the join operation. Left part of LEFT JOIN. */
|
|
55
|
+
readonly primary: JoinEntry<Col>;
|
|
56
|
+
|
|
57
|
+
/** Driven nodes, giving their values only if primary node have corresponding
|
|
58
|
+
* nodes. Right parts of LEFT JOIN chain. */
|
|
59
|
+
readonly secondary: JoinEntry<Col>[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Base type of all join request tree nodes. Join request tree allows to combine
|
|
64
|
+
* information from multiple PColumns into a PTable. Correlation between records
|
|
65
|
+
* is performed by looking for records with the same values in common axis between
|
|
66
|
+
* the PColumns. Common axis are those axis which have equal {@link AxisId} derived
|
|
67
|
+
* from the columns axes spec.
|
|
68
|
+
* */
|
|
69
|
+
export type JoinEntry<Col> =
|
|
70
|
+
| ColumnJoinEntry<Col>
|
|
71
|
+
| InnerJoin<Col>
|
|
72
|
+
| FullJoin<Col>
|
|
73
|
+
| OuterJoin<Col>;
|
|
74
|
+
|
|
75
|
+
/** Container representing whole data stored in specific PTable column. */
|
|
76
|
+
export interface FullPTableColumnData {
|
|
77
|
+
/** Unified spec */
|
|
78
|
+
readonly spec: PTableColumnSpec;
|
|
79
|
+
|
|
80
|
+
/** Data */
|
|
81
|
+
readonly data: PTableVector;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface SingleValueIsNAPredicate {
|
|
85
|
+
/** Comparison operator */
|
|
86
|
+
readonly operator: 'IsNA';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface SingleValueEqualPredicate {
|
|
90
|
+
/** Comparison operator */
|
|
91
|
+
readonly operator: 'Equal';
|
|
92
|
+
|
|
93
|
+
/** Reference value, NA values will not match */
|
|
94
|
+
readonly reference: string | number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface SingleValueLessPredicate {
|
|
98
|
+
/** Comparison operator */
|
|
99
|
+
readonly operator: 'Less';
|
|
100
|
+
|
|
101
|
+
/** Reference value, NA values will not match */
|
|
102
|
+
readonly reference: string | number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SingleValueLessOrEqualPredicate {
|
|
106
|
+
/** Comparison operator */
|
|
107
|
+
readonly operator: 'LessOrEqual';
|
|
108
|
+
|
|
109
|
+
/** Reference value, NA values will not match */
|
|
110
|
+
readonly reference: string | number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface SingleValueGreaterPredicate {
|
|
114
|
+
/** Comparison operator */
|
|
115
|
+
readonly operator: 'Greater';
|
|
116
|
+
|
|
117
|
+
/** Reference value, NA values will not match */
|
|
118
|
+
readonly reference: string | number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface SingleValueGreaterOrEqualPredicate {
|
|
122
|
+
/** Comparison operator */
|
|
123
|
+
readonly operator: 'GreaterOrEqual';
|
|
124
|
+
|
|
125
|
+
/** Reference value, NA values will not match */
|
|
126
|
+
readonly reference: string | number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface SingleValueStringContainsPredicate {
|
|
130
|
+
/** Comparison operator */
|
|
131
|
+
readonly operator: 'StringContains';
|
|
132
|
+
|
|
133
|
+
/** Reference substring, NA values are skipped */
|
|
134
|
+
readonly substring: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface SingleValueMatchesPredicate {
|
|
138
|
+
/** Comparison operator */
|
|
139
|
+
readonly operator: 'Matches';
|
|
140
|
+
|
|
141
|
+
/** Regular expression, NA values are skipped */
|
|
142
|
+
readonly regex: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface SingleValueStringContainsFuzzyPredicate {
|
|
146
|
+
/** Comparison operator */
|
|
147
|
+
readonly operator: 'StringContainsFuzzy';
|
|
148
|
+
|
|
149
|
+
/** Reference value, NA values are skipped */
|
|
150
|
+
readonly reference: string;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Integer specifying the upper bound of edit distance between
|
|
154
|
+
* reference and actual value.
|
|
155
|
+
* When {@link substitutionsOnly} is not defined or set to false
|
|
156
|
+
* Levenshtein distance is used (substitutions and indels)
|
|
157
|
+
* @see https://en.wikipedia.org/wiki/Levenshtein_distance
|
|
158
|
+
* When {@link substitutionsOnly} is set to true
|
|
159
|
+
* Hamming distance is used (substitutions only)
|
|
160
|
+
* @see https://en.wikipedia.org/wiki/Hamming_distance
|
|
161
|
+
*/
|
|
162
|
+
readonly maxEdits: number;
|
|
163
|
+
|
|
164
|
+
/** Changes the type of edit distance in {@link maxEdits} */
|
|
165
|
+
readonly substitutionsOnly?: boolean;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Some character in {@link reference} that will match any
|
|
169
|
+
* single character in searched text.
|
|
170
|
+
*/
|
|
171
|
+
readonly wildcard?: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface SingleValueNotPredicate {
|
|
175
|
+
/** Comparison operator */
|
|
176
|
+
readonly operator: 'Not';
|
|
177
|
+
|
|
178
|
+
/** Operand to negate */
|
|
179
|
+
readonly operand: SingleValuePredicate;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface SingleValueAndPredicate {
|
|
183
|
+
/** Comparison operator */
|
|
184
|
+
readonly operator: 'And';
|
|
185
|
+
|
|
186
|
+
/** Operands to combine */
|
|
187
|
+
readonly operands: SingleValuePredicate[];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface SingleValueOrPredicate {
|
|
191
|
+
/** Comparison operator */
|
|
192
|
+
readonly operator: 'Or';
|
|
193
|
+
|
|
194
|
+
/** Operands to combine */
|
|
195
|
+
readonly operands: SingleValuePredicate[];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Filtering predicate for a single axis or column value */
|
|
199
|
+
export type SingleValuePredicate =
|
|
200
|
+
| SingleValueIsNAPredicate
|
|
201
|
+
| SingleValueEqualPredicate
|
|
202
|
+
| SingleValueLessPredicate
|
|
203
|
+
| SingleValueLessOrEqualPredicate
|
|
204
|
+
| SingleValueGreaterPredicate
|
|
205
|
+
| SingleValueGreaterOrEqualPredicate
|
|
206
|
+
| SingleValueStringContainsPredicate
|
|
207
|
+
| SingleValueMatchesPredicate
|
|
208
|
+
| SingleValueStringContainsFuzzyPredicate
|
|
209
|
+
| SingleValueNotPredicate
|
|
210
|
+
| SingleValueAndPredicate
|
|
211
|
+
| SingleValueOrPredicate;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Filter PTable records based on specific axis or column value. If this is an
|
|
215
|
+
* axis value filter and the axis is part of a partitioning key in some of the
|
|
216
|
+
* source PColumns, the filter will be pushed down to those columns, so only
|
|
217
|
+
* specific partitions will be retrieved from the remote storage.
|
|
218
|
+
* */
|
|
219
|
+
export interface PTableRecordSingleValueFilter {
|
|
220
|
+
/** Filter type discriminator */
|
|
221
|
+
readonly type: 'bySingleColumn';
|
|
222
|
+
|
|
223
|
+
/** Target axis selector to examine values from */
|
|
224
|
+
readonly column: PTableColumnId;
|
|
225
|
+
|
|
226
|
+
/** Value predicate */
|
|
227
|
+
readonly predicate: SingleValuePredicate;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Generic PTable records filter */
|
|
231
|
+
export type PTableRecordFilter = PTableRecordSingleValueFilter;
|
|
232
|
+
|
|
233
|
+
/** Sorting parameters for a PTable. */
|
|
234
|
+
export type PTableSorting = {
|
|
235
|
+
/** Unified column identifier */
|
|
236
|
+
readonly column: PTableColumnId;
|
|
237
|
+
|
|
238
|
+
/** Sorting order */
|
|
239
|
+
readonly ascending: boolean;
|
|
240
|
+
|
|
241
|
+
/** Sorting in respect to NA and absent values */
|
|
242
|
+
readonly naAndAbsentAreLeastValues: boolean;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/** Information required to instantiate a PTable. */
|
|
246
|
+
export interface PTableDef<Col> {
|
|
247
|
+
/** Join tree to populate the PTable */
|
|
248
|
+
readonly src: JoinEntry<Col>;
|
|
249
|
+
|
|
250
|
+
/** Record filters */
|
|
251
|
+
readonly filters: PTableRecordFilter[];
|
|
252
|
+
|
|
253
|
+
/** Table sorting */
|
|
254
|
+
readonly sorting: PTableSorting[];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Request to create and retrieve entirety of data of PTable. */
|
|
258
|
+
export type CalculateTableDataRequest<Col> = PTableDef<Col>;
|
|
259
|
+
|
|
260
|
+
/** Response for {@link CalculateTableDataRequest} */
|
|
261
|
+
export type CalculateTableDataResponse = FullPTableColumnData[];
|
|
262
|
+
|
|
263
|
+
export function mapPTableDef<C1, C2>(
|
|
264
|
+
def: PTableDef<C1>,
|
|
265
|
+
cb: (c: C1) => C2
|
|
266
|
+
): PTableDef<C2> {
|
|
267
|
+
return { ...def, src: mapJoinEntry(def.src, cb) };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function mapJoinEntry<C1, C2>(
|
|
271
|
+
entry: JoinEntry<C1>,
|
|
272
|
+
cb: (c: C1) => C2
|
|
273
|
+
): JoinEntry<C2> {
|
|
274
|
+
switch (entry.type) {
|
|
275
|
+
case 'column':
|
|
276
|
+
return {
|
|
277
|
+
type: 'column',
|
|
278
|
+
column: cb(entry.column)
|
|
279
|
+
};
|
|
280
|
+
case 'inner':
|
|
281
|
+
case 'full':
|
|
282
|
+
return {
|
|
283
|
+
type: entry.type,
|
|
284
|
+
entries: entry.entries.map((col) => mapJoinEntry(col, cb))
|
|
285
|
+
};
|
|
286
|
+
case 'outer':
|
|
287
|
+
return {
|
|
288
|
+
type: 'outer',
|
|
289
|
+
primary: mapJoinEntry(entry.primary, cb),
|
|
290
|
+
secondary: entry.secondary.map((col) => mapJoinEntry(col, cb))
|
|
291
|
+
};
|
|
292
|
+
default:
|
|
293
|
+
assertNever(entry);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PObjectId } from '../../pool';
|
|
2
|
+
import { AxisId, AxisSpec, PColumnSpec } from './spec';
|
|
3
|
+
|
|
4
|
+
/** Unified spec object for axes and columns */
|
|
5
|
+
export type PTableColumnSpec =
|
|
6
|
+
| {
|
|
7
|
+
type: 'axis';
|
|
8
|
+
id: AxisId;
|
|
9
|
+
spec: AxisSpec;
|
|
10
|
+
}
|
|
11
|
+
| {
|
|
12
|
+
type: 'column';
|
|
13
|
+
id: PObjectId;
|
|
14
|
+
spec: PColumnSpec;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type PTableColumnIdAxis = {
|
|
18
|
+
type: 'axis';
|
|
19
|
+
id: AxisId;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type PTableColumnIdColumn = {
|
|
23
|
+
type: 'column';
|
|
24
|
+
id: PObjectId;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Unified PTable column identifier */
|
|
28
|
+
export type PTableColumnId = PTableColumnIdAxis | PTableColumnIdColumn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type AddParameters<
|
|
2
|
+
TParameters extends [...args: any],
|
|
3
|
+
TFunction extends (...args: any) => any
|
|
4
|
+
> = (
|
|
5
|
+
...args: [...TParameters, ...Parameters<TFunction>]
|
|
6
|
+
) => ReturnType<TFunction>;
|
|
7
|
+
|
|
8
|
+
export type AddParameterToAllMethods<
|
|
9
|
+
Interface,
|
|
10
|
+
TParameters extends [...args: any]
|
|
11
|
+
> = {
|
|
12
|
+
[Field in keyof Interface]: Interface[Field] extends (...args: any) => any
|
|
13
|
+
? AddParameters<TParameters, Interface[Field]>
|
|
14
|
+
: Interface[Field];
|
|
15
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AxisId } from './spec';
|
|
2
|
+
import { PTableRecordFilter } from './table_calculate';
|
|
3
|
+
import { PTableVector } from './data';
|
|
4
|
+
import { PObjectId } from '../../pool';
|
|
5
|
+
|
|
6
|
+
/** Calculate set of unique values for a specific axis for the filtered set of records */
|
|
7
|
+
export interface UniqueValuesRequest {
|
|
8
|
+
/** Target axis id */
|
|
9
|
+
readonly columnId: PObjectId;
|
|
10
|
+
|
|
11
|
+
/** Target axis id, if not specified calculates unique column values */
|
|
12
|
+
readonly axis?: AxisId;
|
|
13
|
+
|
|
14
|
+
/** Filters to apply before calculating unique values */
|
|
15
|
+
readonly filters: PTableRecordFilter[];
|
|
16
|
+
|
|
17
|
+
/** Max number of values to return, if reached response will contain overflow flag */
|
|
18
|
+
readonly limit: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface UniqueValuesResponse {
|
|
22
|
+
/** Unique values */
|
|
23
|
+
readonly values: PTableVector;
|
|
24
|
+
|
|
25
|
+
/** True if limit was reached and response contain non-exhaustive list of values. */
|
|
26
|
+
readonly overflow: boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ImportProgress {
|
|
2
|
+
done: boolean;
|
|
3
|
+
/** Status of indexing/uploading got from platforma gRPC. */
|
|
4
|
+
status?: ImportStatus;
|
|
5
|
+
/** True if BlobUpload, false if BlobIndex. */
|
|
6
|
+
readonly isUpload: boolean;
|
|
7
|
+
/** True if signature matched. */
|
|
8
|
+
isUploadSignMatch?: boolean;
|
|
9
|
+
/** Exists when an upload failed and was restarted,
|
|
10
|
+
* but the error was recoverable.
|
|
11
|
+
* If the error was non-recoverable,
|
|
12
|
+
* the driver's computable will throw an error instead. */
|
|
13
|
+
lastError?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Almost direct mapping from proto struct got from gRPC. */
|
|
17
|
+
export interface ImportStatus {
|
|
18
|
+
/** A float from 0 to 1 and is equal to bytesProcessed / bytesTotal. */
|
|
19
|
+
readonly progress: number;
|
|
20
|
+
readonly bytesProcessed?: number;
|
|
21
|
+
readonly bytesTotal?: number;
|
|
22
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './block';
|
|
2
|
+
export * from './block_state';
|
|
3
|
+
export * from './utag';
|
|
4
|
+
export * from './drivers';
|
|
5
|
+
export * from './driver_kit';
|
|
6
|
+
export * from './navigation';
|
|
7
|
+
export * from './ref';
|
|
8
|
+
export * from './common_types';
|
|
9
|
+
export * from './pool';
|
|
10
|
+
export * from './value_or_error';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Block section visualized as items in left panel block overview */
|
|
2
|
+
export type BlockSection = BlockSectionLink | BlockSectionDelimiter;
|
|
3
|
+
|
|
4
|
+
/** Tells the system that specific section from the main UI of this block should
|
|
5
|
+
* be opened */
|
|
6
|
+
export type BlockSectionLink = {
|
|
7
|
+
/** Potentially there may be multiple section types, i.e. for "+" rows and for
|
|
8
|
+
* sections directly opening html from the outputs. */
|
|
9
|
+
readonly type: 'link';
|
|
10
|
+
|
|
11
|
+
/** Internal block section identifier */
|
|
12
|
+
readonly href: `/${string}`;
|
|
13
|
+
|
|
14
|
+
/** Visible section title, can also be used in the window header. */
|
|
15
|
+
readonly label: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Create a horisontal line between sections */
|
|
19
|
+
export type BlockSectionDelimiter = {
|
|
20
|
+
readonly type: 'delimiter';
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Part of the block state, representing current navigation information
|
|
25
|
+
* (i.e. currently selected section)
|
|
26
|
+
* */
|
|
27
|
+
export type NavigationState<Href extends `/${string}` = `/${string}`> = {
|
|
28
|
+
readonly href: Href;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const DefaultNavigationState: NavigationState = { href: '/' };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Ref } from '../ref';
|
|
2
|
+
import { PObject } from './spec';
|
|
3
|
+
|
|
4
|
+
/** Result pool entry */
|
|
5
|
+
export type ResultPoolEntry<O> = {
|
|
6
|
+
/** Reference that can be passed to args to import the object in workflow */
|
|
7
|
+
readonly ref: Ref;
|
|
8
|
+
|
|
9
|
+
/** Object. Normally spec or PObject. */
|
|
10
|
+
readonly obj: O;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Collection of results from the result pool */
|
|
14
|
+
export type ResultCollection<O> = {
|
|
15
|
+
/** List of results from the pool */
|
|
16
|
+
readonly entries: ResultPoolEntry<O>[];
|
|
17
|
+
|
|
18
|
+
/** False means that current collection is not fully loaded due to some computations still taking place */
|
|
19
|
+
readonly isComplete: boolean;
|
|
20
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { AxisId } from '../drivers';
|
|
2
|
+
import { PObjectSpec, isPColumnSpec } from './spec';
|
|
3
|
+
|
|
4
|
+
export type PSpecPredicate =
|
|
5
|
+
| {
|
|
6
|
+
type: 'and' | 'or';
|
|
7
|
+
operands: PSpecPredicate[];
|
|
8
|
+
}
|
|
9
|
+
| {
|
|
10
|
+
type: 'not';
|
|
11
|
+
operand: PSpecPredicate;
|
|
12
|
+
}
|
|
13
|
+
| {
|
|
14
|
+
type: 'name';
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
17
|
+
| {
|
|
18
|
+
type: 'name_pattern';
|
|
19
|
+
pattern: string;
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
type: 'annotation';
|
|
23
|
+
annotation: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
type: 'annotation_pattern';
|
|
28
|
+
annotation: string;
|
|
29
|
+
pattern: string;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
type: 'has_axes';
|
|
33
|
+
axes: Partial<AxisId>[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function assertNever(x: never): never {
|
|
37
|
+
throw new Error('Unexpected object: ' + x);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function executePSpecPredicate(
|
|
41
|
+
predicate: PSpecPredicate,
|
|
42
|
+
spec: PObjectSpec
|
|
43
|
+
): boolean {
|
|
44
|
+
switch (predicate.type) {
|
|
45
|
+
case 'and':
|
|
46
|
+
for (const operator of predicate.operands)
|
|
47
|
+
if (!executePSpecPredicate(operator, spec)) return false;
|
|
48
|
+
return true;
|
|
49
|
+
case 'or':
|
|
50
|
+
for (const operator of predicate.operands)
|
|
51
|
+
if (executePSpecPredicate(operator, spec)) return true;
|
|
52
|
+
return false;
|
|
53
|
+
case 'not':
|
|
54
|
+
return !executePSpecPredicate(predicate.operand, spec);
|
|
55
|
+
case 'name':
|
|
56
|
+
return isPColumnSpec(spec) && spec.name === predicate.name;
|
|
57
|
+
case 'name_pattern':
|
|
58
|
+
return isPColumnSpec(spec) && Boolean(spec.name.match(predicate.pattern));
|
|
59
|
+
case 'annotation':
|
|
60
|
+
return (
|
|
61
|
+
isPColumnSpec(spec) &&
|
|
62
|
+
spec.annotations !== undefined &&
|
|
63
|
+
spec.annotations[predicate.annotation] === predicate.value
|
|
64
|
+
);
|
|
65
|
+
case 'annotation_pattern':
|
|
66
|
+
return (
|
|
67
|
+
isPColumnSpec(spec) &&
|
|
68
|
+
spec.annotations !== undefined &&
|
|
69
|
+
spec.annotations[predicate.annotation] !== undefined &&
|
|
70
|
+
Boolean(spec.annotations[predicate.annotation].match(predicate.pattern))
|
|
71
|
+
);
|
|
72
|
+
case 'has_axes':
|
|
73
|
+
return (
|
|
74
|
+
isPColumnSpec(spec) &&
|
|
75
|
+
predicate.axes.every((matcher) =>
|
|
76
|
+
spec.axesSpec.some(
|
|
77
|
+
(axisSpec) =>
|
|
78
|
+
(matcher.type === undefined || matcher.type === axisSpec.type) &&
|
|
79
|
+
(matcher.name === undefined || matcher.name === axisSpec.name) &&
|
|
80
|
+
(matcher.domain === undefined ||
|
|
81
|
+
Object.keys(matcher.domain).length === 0 ||
|
|
82
|
+
(axisSpec.domain !== undefined &&
|
|
83
|
+
Object.entries(matcher.domain).every(
|
|
84
|
+
([domain, domainValue]) =>
|
|
85
|
+
axisSpec.domain![domain] === domainValue
|
|
86
|
+
)))
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
default:
|
|
91
|
+
assertNever(predicate);
|
|
92
|
+
}
|
|
93
|
+
}
|
package/src/pool/spec.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Branded } from '../branding';
|
|
2
|
+
import { PColumn, PColumnSpec } from '../drivers';
|
|
3
|
+
|
|
4
|
+
/** Any object exported into the result pool by the block always have spec attached to it */
|
|
5
|
+
export interface PObjectSpec {
|
|
6
|
+
/** PObject kind discriminator */
|
|
7
|
+
readonly kind: string;
|
|
8
|
+
|
|
9
|
+
/** Additional information attached to the object */
|
|
10
|
+
readonly annotations?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Stable PObject id */
|
|
14
|
+
export type PObjectId = Branded<string, 'PColumnId'>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Full PObject representation.
|
|
18
|
+
*
|
|
19
|
+
* @template Data type of the object referencing or describing the "data" part of the PObject
|
|
20
|
+
* */
|
|
21
|
+
export interface PObject<Data> {
|
|
22
|
+
/** Fully rendered PObjects are assigned a stable identifier. */
|
|
23
|
+
readonly id: PObjectId;
|
|
24
|
+
|
|
25
|
+
/** PObject spec, allowing it to be found among other PObjects */
|
|
26
|
+
readonly spec: PObjectSpec;
|
|
27
|
+
|
|
28
|
+
/** A handle to data object */
|
|
29
|
+
readonly data: Data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isPColumnSpec(spec: PObjectSpec): spec is PColumnSpec {
|
|
33
|
+
return spec.kind === 'PColumn';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isPColumn<T>(obj: PObject<T>): obj is PColumn<T> {
|
|
37
|
+
return isPColumnSpec(obj.spec);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function ensurePColumn<T>(obj: PObject<T>): PColumn<T> {
|
|
41
|
+
if (!isPColumn(obj))
|
|
42
|
+
throw new Error(`not a PColumn (kind = ${obj.spec.kind})`);
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function mapPObjectData<D1, D2>(
|
|
47
|
+
pObj: PColumn<D1>,
|
|
48
|
+
cb: (d: D1) => D2
|
|
49
|
+
): PColumn<D2>;
|
|
50
|
+
export function mapPObjectData<D1, D2>(
|
|
51
|
+
pObj: PObject<D1>,
|
|
52
|
+
cb: (d: D1) => D2
|
|
53
|
+
): PObject<D2>;
|
|
54
|
+
export function mapPObjectData<D1, D2>(
|
|
55
|
+
pObj: PObject<D1>,
|
|
56
|
+
cb: (d: D1) => D2
|
|
57
|
+
): PObject<D2> {
|
|
58
|
+
return {
|
|
59
|
+
...pObj,
|
|
60
|
+
data: cb(pObj.data)
|
|
61
|
+
};
|
|
62
|
+
}
|
package/src/ref.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export const Ref = z
|
|
4
|
+
.object({
|
|
5
|
+
__isRef: z
|
|
6
|
+
.literal(true)
|
|
7
|
+
.describe('Crucial marker for the block dependency tree reconstruction'),
|
|
8
|
+
blockId: z.string().describe('Upstream block id'),
|
|
9
|
+
name: z
|
|
10
|
+
.string()
|
|
11
|
+
.describe(
|
|
12
|
+
"Name of the output provided to the upstream block's output context"
|
|
13
|
+
)
|
|
14
|
+
})
|
|
15
|
+
.describe(
|
|
16
|
+
'Universal reference type, allowing to set block connections. It is crucial that ' +
|
|
17
|
+
'{@link __isRef} is present and equal to true, internal logic relies on this marker ' +
|
|
18
|
+
'to build block dependency trees.'
|
|
19
|
+
)
|
|
20
|
+
.strict()
|
|
21
|
+
.readonly();
|
|
22
|
+
export type Ref = z.infer<typeof Ref>;
|
|
23
|
+
|
|
24
|
+
/** Standard way how to communicate possible connections given specific
|
|
25
|
+
* requirements for incoming data. */
|
|
26
|
+
export type Option = {
|
|
27
|
+
/** Fully rendered reference to be assigned for the intended field in block's
|
|
28
|
+
* args */
|
|
29
|
+
readonly ref: Ref;
|
|
30
|
+
|
|
31
|
+
/** Label to be present for the user in i.e. drop-down list */
|
|
32
|
+
readonly label: string;
|
|
33
|
+
};
|
package/src/utag.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Value returned for changing states supporting reactive listening for changes */
|
|
2
|
+
export interface ValueWithUTag<V> {
|
|
3
|
+
/** Value snapshot. */
|
|
4
|
+
readonly value: V;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Unique tag for the value snapshot.
|
|
8
|
+
*
|
|
9
|
+
* It can be used to synchronously detect if changes happened after current
|
|
10
|
+
* snapshot was retrieved, or asynchronously await next value snapshot,
|
|
11
|
+
* generated on underlying data changes.
|
|
12
|
+
* */
|
|
13
|
+
readonly uTag: string;
|
|
14
|
+
}
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ValueOrError<V, E> =
|
|
2
|
+
| {
|
|
3
|
+
ok: true;
|
|
4
|
+
value: V;
|
|
5
|
+
}
|
|
6
|
+
| {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: E;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function mapValueInVOE<V1, V2, E>(
|
|
12
|
+
voe: ValueOrError<V1, E>,
|
|
13
|
+
cb: (value: V1) => V2
|
|
14
|
+
): ValueOrError<V2, E> {
|
|
15
|
+
return voe.ok ? { ok: true, value: cb(voe.value) } : voe;
|
|
16
|
+
}
|