@milaboratories/pl-model-middle-layer 1.30.0 → 1.30.2

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.
@@ -59,52 +59,31 @@ export type PColumnValueTypeSpec = {
59
59
  *
60
60
  * @template Blob - Type parameter representing the storage reference type (could be ResourceInfo, PFrameBlobId, etc.)
61
61
  */
62
- export type DataInfo<Blob> =
62
+ export type DataInfo<Blob> = (
63
63
  | JsonDataInfo
64
64
  | JsonPartitionedDataInfo<Blob>
65
65
  | BinaryPartitionedDataInfo<Blob>
66
- | ParquetPartitionedDataInfo<ParquetChunk<Blob>>;
66
+ | ParquetPartitionedDataInfo<ParquetChunk<Blob>>
67
+ ) & {
68
+ /**
69
+ * Self-contained structural type info. Present in data info produced by the
70
+ * new converter, absent in data info produced by the old one.
71
+ */
72
+ readonly typeSpec?: PColumnValueTypeSpec;
73
+ };
67
74
 
68
75
  /**
69
- * Self-contained data info: a PColumn data storage format with an embedded
76
+ * Self-contained data info: {@link DataInfo} with a required
70
77
  * {@link PColumnValueTypeSpec}, so the data layer can interpret the values
71
78
  * without a separate spec. This is the on-disk `.datainfo` shape and the
72
79
  * payload accepted by {@link PFrameFactoryAPIV6.addColumns}.
73
80
  *
74
- * Declared independently of {@link DataInfo} (not as an intersection) so the
75
- * legacy v1 type can be removed without affecting this one.
76
- *
77
81
  * @template Blob - Type parameter representing the storage reference type (could be ResourceInfo, PFrameBlobId, etc.)
78
82
  */
79
- export type DataInfoV2<Blob> = (
80
- | JsonDataInfo
81
- | JsonPartitionedDataInfo<Blob>
82
- | BinaryPartitionedDataInfo<Blob>
83
- | ParquetPartitionedDataInfo<ParquetChunk<Blob>>
84
- ) & {
83
+ export type DataInfoV2<Blob> = DataInfo<Blob> & {
85
84
  readonly typeSpec: PColumnValueTypeSpec;
86
85
  };
87
86
 
88
- /**
89
- * Structural type information needed by the data side: axis value
90
- * types and column value types, in their canonical order. Mirrors
91
- * the bridge-side `TypeSpec`.
92
- */
93
- export interface ValueTypeSpec {
94
- readonly axes: AxisValueType[];
95
- readonly columns: ColumnValueType[];
96
- }
97
-
98
- /** Single column entry for {@link PFrameFactoryAPIV5.addColumns}. */
99
- export interface AddColumnEntry {
100
- /** Unique column identifier within the PFrame. */
101
- readonly id: PObjectId;
102
- /** Structural type info (axes / column value types). */
103
- readonly typeSpec: ValueTypeSpec;
104
- /** Data info for the column. */
105
- readonly data: DataInfo<PFrameBlobId>;
106
- }
107
-
108
87
  /**
109
88
  * Single column entry for {@link PFrameFactoryAPIV6.addColumns}. The structural
110
89
  * type info is carried inside {@link DataInfoV2.typeSpec} rather than as a
@@ -117,32 +96,10 @@ export interface AddColumnEntryV2 {
117
96
  readonly data: DataInfoV2<PFrameBlobId>;
118
97
  }
119
98
 
120
- /** API for populating a PFrame with columns and a data source. */
121
- export interface PFrameFactoryAPIV5 extends Disposable {
122
- /** Associates data source with this PFrame. */
123
- setDataSource(dataSource: PFrameDataSourceV2): void;
124
-
125
- /**
126
- * Registers all PColumns at once: specs are recorded and data info
127
- * is attached atomically. For parquet data info, schema resolution
128
- * via network is performed during this call.
129
- */
130
- addColumns(
131
- columns: AddColumnEntry[],
132
- options?: {
133
- signal?: AbortSignal;
134
- },
135
- ): Promise<void>;
136
-
137
- /** Releases all the data previously added to PFrame using methods above,
138
- * any interactions with disposed PFrame will result in exception */
139
- dispose(): void;
140
- }
141
-
142
99
  /**
143
- * API for populating a PFrame with columns and a data source. Unlike
144
- * {@link PFrameFactoryAPIV5}, each column's structural type info is embedded in
145
- * its self-contained {@link AddColumnEntryV2.data} instead of a separate field.
100
+ * API for populating a PFrame with columns and a data source. Each column's
101
+ * structural type info is embedded in its self-contained
102
+ * {@link AddColumnEntryV2.data} instead of a separate field.
146
103
  */
147
104
  export interface PFrameFactoryAPIV6 extends Disposable {
148
105
  /** Associates data source with this PFrame. */
@@ -4,7 +4,7 @@ import type {
4
4
  DataQuery,
5
5
  DataQueryBooleanExpression,
6
6
  } from "@milaboratories/pl-model-common";
7
- import type { PTableV11 } from "./table";
7
+ import type { PTableV11, PTableV12 } from "./table";
8
8
  import type { PTableId } from "./common";
9
9
 
10
10
  /**
@@ -30,6 +30,39 @@ export interface UniqueValuesRequestV2 {
30
30
  readonly limit: number;
31
31
  }
32
32
 
33
+ /**
34
+ * Read interface exposed by PFrames library. Returns the {@link PTableV12}
35
+ * table view, whose `export` takes an `ops.headers` list of
36
+ * `[column index, header name]` pairs.
37
+ *
38
+ * Self-contained: does not extend any earlier read interface. Once this
39
+ * version is adopted, every earlier `PFrameReadAPIV*` and per-table
40
+ * `PTableV*` interface is dropped, so this declaration repeats the full
41
+ * method surface rather than referencing the predecessors.
42
+ *
43
+ * Same surface as {@link PFrameReadAPIV14}; the only change is that
44
+ * {@link PFrameReadAPIV15.createTable} returns {@link PTableV12}.
45
+ *
46
+ * Spec-side operations (finding columns, listing columns, retrieving
47
+ * column specs, computing axis integrations) are not part of this
48
+ * surface — callers cache column specs themselves or route through
49
+ * WASM-spec. The data-side `createTable` accepts a pre-lowered
50
+ * `DataQuery`; `getUniqueValues` takes pre-resolved indices via
51
+ * {@link UniqueValuesRequestV2}.
52
+ */
53
+ export interface PFrameReadAPIV15 {
54
+ /** Creates table from a pre-lowered data query. */
55
+ createTable(tableId: PTableId, dataQuery: DataQuery): PTableV12;
56
+
57
+ /** Calculate set of unique values for a specific axis for the filtered set of records. */
58
+ getUniqueValues(
59
+ request: UniqueValuesRequestV2,
60
+ ops?: {
61
+ signal?: AbortSignal;
62
+ },
63
+ ): Promise<UniqueValuesResponse>;
64
+ }
65
+
33
66
  /**
34
67
  * Read interface exposed by PFrames library. Returns the {@link PTableV11}
35
68
  * table view, whose `export` takes a column-index → header map.
@@ -3,7 +3,7 @@ import type {
3
3
  AxesSpec,
4
4
  BuildQueryInput,
5
5
  JoinEntry,
6
- PColumnInfo,
6
+ PColumnIdAndSpec,
7
7
  PColumnSpec,
8
8
  PObjectId,
9
9
  PTableColumnId,
@@ -23,6 +23,116 @@ import type {
23
23
  import type { DiscoverColumnsRequestV2, DiscoverColumnsResponse } from "./discover_columns";
24
24
  import type { FindColumnsRequest, FindColumnsResponse } from "./find_columns";
25
25
 
26
+ /**
27
+ * V5 PFrame API factory — pure spec-layer operations plus frame construction.
28
+ *
29
+ * Self-contained: does not extend any earlier factory interface. Once this
30
+ * version is adopted, every earlier `PFrameWasmAPIV*` and per-frame
31
+ * `PFrameWasmV*` interface is dropped, so this declaration repeats the full
32
+ * method surface rather than referencing the predecessors.
33
+ */
34
+ export interface PFrameWasmAPIV5 {
35
+ /**
36
+ * Creates a new PFrame from a map of column IDs to column specifications.
37
+ */
38
+ createPFrame(spec: Record<string, PColumnSpec>): PFrameWasmV4;
39
+
40
+ /**
41
+ * Expands an {@link AxesSpec} into {@link AxesId}s with parent information
42
+ * resolved.
43
+ */
44
+ expandAxes(spec: AxesSpec): AxesId;
45
+
46
+ /**
47
+ * Collapses {@link AxesId} into {@link AxesSpec}.
48
+ */
49
+ collapseAxes(ids: AxesId): AxesSpec;
50
+
51
+ /**
52
+ * Finds the index of an axis matching the given selector.
53
+ * Returns -1 if no matching axis is found.
54
+ */
55
+ findAxis(spec: AxesSpec, selector: SingleAxisSelector): number;
56
+
57
+ /**
58
+ * Finds the flat index of a table column matching the given
59
+ * selector within a table spec. Returns -1 if not found.
60
+ */
61
+ findTableColumn(tableSpec: PTableColumnSpec[], selector: PTableColumnId): number;
62
+
63
+ /**
64
+ * Assembles a {@link SpecQueryJoinEntry} from a terminal column plus an
65
+ * ordered path of wrapping steps (linker hops, filter joins).
66
+ *
67
+ * Right-fold over `path` starting from `Column(column)`: each `linker` step
68
+ * wraps the current subquery as `linkerJoin`, each `filter` step as
69
+ * `innerJoin` with the filter column. `qualifications` annotate the
70
+ * outermost entry only.
71
+ */
72
+ buildQuery(input: BuildQueryInput): SpecQueryJoinEntry;
73
+
74
+ /**
75
+ * Upgrades selector-based legacy record filters into index-based data-layer
76
+ * boolean expressions, resolved against the provided unified table spec
77
+ * (axes first, then columns).
78
+ */
79
+ rewriteLegacyFilters(request: {
80
+ tableSpec: PTableColumnSpec[];
81
+ filters: PTableRecordFilter[];
82
+ }): DataQueryBooleanExpression[];
83
+ }
84
+
85
+ /**
86
+ * V4 PFrame interface — per-frame instance operations.
87
+ *
88
+ * Self-contained: does not extend any earlier per-frame interface. Once this
89
+ * version is adopted, every earlier `PFrameWasmV*` interface is dropped, so
90
+ * this declaration repeats the full method surface rather than referencing
91
+ * the predecessors.
92
+ */
93
+ export interface PFrameWasmV4 extends Disposable {
94
+ /**
95
+ * Deletes columns from a columns specification.
96
+ */
97
+ deleteColumns(request: DeleteColumnFromColumnsRequest): DeleteColumnFromColumnsResponse;
98
+
99
+ /**
100
+ * Returns the id and spec of the single column registered under `columnId`
101
+ * in this PFrame, or `null` if no such column is registered. Same shape as
102
+ * the entries of {@link PFrameWasmV4.listColumns}.
103
+ */
104
+ getColumn(columnId: PObjectId): PColumnIdAndSpec | null;
105
+
106
+ /**
107
+ * Lists all columns currently registered in this PFrame, with their ids and specs.
108
+ */
109
+ listColumns(): PColumnIdAndSpec[];
110
+
111
+ /**
112
+ * Discovers columns compatible with a given axes integration. Include and
113
+ * exclude filters are applied in order (exclude removes matches from the
114
+ * include set). Each hit carries its traversal `path`; feed the hit's
115
+ * column id and `path` into {@link PFrameWasmAPIV5.buildQuery} to
116
+ * materialize it as a {@link SpecQueryJoinEntry}.
117
+ */
118
+ discoverColumns(request: DiscoverColumnsRequestV2): DiscoverColumnsResponse;
119
+
120
+ /**
121
+ * Finds columns in the PFrame matching the given filter criteria.
122
+ */
123
+ findColumns(request: FindColumnsRequest): FindColumnsResponse;
124
+
125
+ /**
126
+ * Evaluates a query specification against this PFrame.
127
+ */
128
+ evaluateQuery(request: SpecQuery): EvaluateQueryResponse;
129
+
130
+ /**
131
+ * Rewrites a legacy query format (V4) to the current SpecQuery format.
132
+ */
133
+ rewriteLegacyQuery(request: LegacyQuery): SpecQuery;
134
+ }
135
+
26
136
  /**
27
137
  * V4 PFrame API factory — pure spec-layer operations plus frame construction.
28
138
  *
@@ -109,7 +219,7 @@ export interface PFrameWasmV3 extends Disposable {
109
219
  /**
110
220
  * Lists all columns currently registered in this PFrame, with their ids and specs.
111
221
  */
112
- listColumns(): PColumnInfo[];
222
+ listColumns(): PColumnIdAndSpec[];
113
223
 
114
224
  /**
115
225
  * Discovers columns compatible with a given axes integration. Include and
@@ -1,19 +1,13 @@
1
- import type { PFrameFactoryAPIV5, PFrameFactoryAPIV6 } from "./api_factory";
1
+ import type { PFrameFactoryAPIV6 } from "./api_factory";
2
2
  import type { PFrameReadAPIV14 } from "./api_read";
3
3
  import type { Logger } from "./common";
4
4
  import type { PFrameId } from "./common";
5
5
 
6
6
  /**
7
7
  * Full PFrame surface — factory operations plus data-side reads. Exposes
8
- * {@link PFrameReadAPIV14}, whose tables' `export` takes a column-index →
9
- * header map.
10
- */
11
- export interface PFrameV16 extends PFrameFactoryAPIV5, PFrameReadAPIV14 {}
12
-
13
- /**
14
- * Full PFrame surface — factory operations plus data-side reads. Like
15
- * {@link PFrameV16} but with self-contained {@link PFrameFactoryAPIV6}
16
- * (column `typeSpec` embedded in `data`).
8
+ * the self-contained {@link PFrameFactoryAPIV6} (column `typeSpec` embedded in
9
+ * `data`) plus {@link PFrameReadAPIV14}, whose tables' `export` takes a
10
+ * column-index → header map.
17
11
  */
18
12
  export interface PFrameV17 extends PFrameFactoryAPIV6, PFrameReadAPIV14 {}
19
13
 
@@ -26,28 +20,6 @@ export type PFrameOptionsV2 = {
26
20
  logger?: Logger;
27
21
  };
28
22
 
29
- /**
30
- * PFrame management functions exposed by the PFrame module. Creates
31
- * {@link PFrameV16} instances, whose tables' `export` takes a
32
- * column-index → header map.
33
- */
34
- export interface PFrameFactoryV7 {
35
- /**
36
- * Create a new PFrame instance.
37
- * @warning Use concurrency limiting to avoid OOM crashes when multiple instances are simultaneously in use.
38
- */
39
- createPFrame(options: PFrameOptionsV2): PFrameV16;
40
-
41
- /**
42
- * Dump active allocations from all PFrames instances in pprof format.
43
- * The result of this function should be saved as `profile.pb.gz`.
44
- * Use {@link https://pprof.me/} or {@link https://www.speedscope.app/}
45
- * to view the allocation flamechart.
46
- * @warning This method will always reject on Windows!
47
- */
48
- pprofDump: () => Promise<Uint8Array>;
49
- }
50
-
51
23
  /**
52
24
  * PFrame management functions exposed by the PFrame module. Creates
53
25
  * {@link PFrameV17} instances (self-contained column data info).
@@ -74,3 +74,85 @@ export interface PTableV11 extends Disposable {
74
74
  /** Deallocates all underlying resources */
75
75
  dispose(): void;
76
76
  }
77
+
78
+ /**
79
+ * Table view returned by `createTable`.
80
+ *
81
+ * Self-contained: does not extend any earlier per-table interface. Once this
82
+ * version is adopted, every earlier `PTableV*` interface is dropped, so this
83
+ * declaration repeats the full method surface rather than referencing the
84
+ * predecessors.
85
+ *
86
+ * Same surface as {@link PTableV11} except {@link PTableV12.export} moves
87
+ * `headers` into `ops` and passes them as an ordered list of
88
+ * `[unified column index, header name]` pairs instead of a
89
+ * `Record<number, string>` map.
90
+ *
91
+ * PTable can be thought as having a composite primary key, consisting
92
+ * of axes, and a set of data columns derived from PColumn values.
93
+ * The table's column spec is owned by the caller — selector → index
94
+ * resolution runs on the caller side via WASM-spec.
95
+ */
96
+ export interface PTableV12 extends Disposable {
97
+ /**
98
+ * Get PTable disk footprint in bytes.
99
+ *
100
+ * @param ops.withPredecessors When true, the footprint includes
101
+ * every registered predecessor table reachable through the
102
+ * query lineage. When false or omitted, only this table's own
103
+ * materialised data is counted.
104
+ *
105
+ * Warning: This call materializes the join.
106
+ */
107
+ getFootprint(ops?: { withPredecessors?: boolean; signal?: AbortSignal }): Promise<number>;
108
+
109
+ /**
110
+ * Unified table shape
111
+ * Warning: This call materializes the join.
112
+ */
113
+ getShape(ops?: { signal?: AbortSignal }): Promise<PTableShape>;
114
+
115
+ /**
116
+ * Retrieve the data from the table. To retrieve only data required, it can be
117
+ * sliced both horizontally ({@link columnIndices}) and vertically
118
+ * ({@link range}).
119
+ * This call materializes the join.
120
+ *
121
+ * @param columnIndices unified indices of columns to be retrieved
122
+ * @param range optionally limit the range of records to retrieve
123
+ * */
124
+ getData(
125
+ columnIndices: number[],
126
+ ops?: {
127
+ range?: TableRange;
128
+ signal?: AbortSignal;
129
+ },
130
+ ): Promise<PTableVector[]>;
131
+
132
+ /**
133
+ * Stream the sorted table to a file at `path`. The output format is
134
+ * selected from the file extension: `csv`, `tsv`, `parquet`, or `xlsx`.
135
+ * Writing is bounded-memory.
136
+ * This call materializes the join.
137
+ *
138
+ * @param path destination file path; its extension selects the format
139
+ * @param ops.headers list of `[unified column index, header name]` pairs
140
+ * (unified index: axes first, then data columns). Only the columns listed
141
+ * are exported, in ascending index order — the list both selects the
142
+ * columns and names them (the data layer is name-independent, so names
143
+ * are supplied by the caller).
144
+ *
145
+ * @remarks For `xlsx` the caller must ensure the row count is below Excel's
146
+ * 1,048,576-row per-sheet limit.
147
+ */
148
+ export(
149
+ path: string,
150
+ ops?: {
151
+ headers: [number, string][];
152
+ signal?: AbortSignal;
153
+ },
154
+ ): Promise<void>;
155
+
156
+ /** Deallocates all underlying resources */
157
+ dispose(): void;
158
+ }