@milaboratories/pframes-rs-node 1.0.50 → 1.0.52

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/export/wrapper.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import humanizeDuration from 'humanize-duration';
2
2
  import { ulid } from 'ulid';
3
3
  import {
4
+ AbortError,
4
5
  DataInfo,
5
6
  PColumnInfo,
6
7
  PColumnSpec,
8
+ PFrameError,
7
9
  PObjectId,
8
10
  PTableColumnId,
9
11
  PTableColumnSpec,
@@ -13,7 +15,9 @@ import {
13
15
  PTableVector,
14
16
  TableRange,
15
17
  UniqueValuesRequest,
16
- UniqueValuesResponse
18
+ UniqueValuesResponse,
19
+ ensureError,
20
+ isAbortError
17
21
  } from '@milaboratories/pl-model-common';
18
22
  import type { PFrameInternal } from '@milaboratories/pl-model-middle-layer';
19
23
  import type {
@@ -24,8 +28,8 @@ import type {
24
28
  } from './addon-def';
25
29
  import { AddonSymbol } from './addon';
26
30
  import {
27
- hashColumnId,
28
31
  dump,
32
+ hashColumnId,
29
33
  hashTableColumnId,
30
34
  hashFilterColumnId,
31
35
  hashUniqueValuesRequestColumnId,
@@ -38,7 +42,13 @@ export class PFrame implements PFrameInternal.PFrameV8 {
38
42
  private readonly frame: NodeFrameSymbol;
39
43
 
40
44
  static async pprofDump(): Promise<Uint8Array> {
41
- return AddonSymbol.pprofDump();
45
+ try {
46
+ return await AddonSymbol.pprofDump();
47
+ } catch (err: unknown) {
48
+ throw new PFrameError(
49
+ `PFrame pprofDump failed, ` + `error:\n` + `${ensureError(err).message}`
50
+ );
51
+ }
42
52
  }
43
53
 
44
54
  constructor(
@@ -58,11 +68,11 @@ export class PFrame implements PFrameInternal.PFrameV8 {
58
68
  this.frame = AddonSymbol.pFrameCreate(spillPath, logger);
59
69
  this.logger?.('info', `PFrame ${this.id} created`);
60
70
  } catch (err: unknown) {
61
- throw new Error(
71
+ throw new PFrameError(
62
72
  `PFrame ${this.id} creation failed, ` +
63
73
  `logger: ${logger?.toString()}, ` +
64
74
  `error:\n` +
65
- `${(err as Error).toString()}`
75
+ `${ensureError(err).message}`
66
76
  );
67
77
  }
68
78
  }
@@ -93,12 +103,12 @@ export class PFrame implements PFrameInternal.PFrameV8 {
93
103
  try {
94
104
  return AddonSymbol.pFrameAddColumnSpec(this.frame, columnId, columnSpec);
95
105
  } catch (err: unknown) {
96
- throw new Error(
106
+ throw new PFrameError(
97
107
  `PFrame ${this.id} addColumnSpec request ${requestId} failed, ` +
98
108
  `columnId: ${JSON.stringify(columnId)}, ` +
99
109
  `columnSpec: ${JSON.stringify(columnSpec)}, ` +
100
110
  `error:\n` +
101
- `${(err as Error).toString()}`
111
+ `${ensureError(err).message}`
102
112
  );
103
113
  }
104
114
  }
@@ -173,11 +183,11 @@ export class PFrame implements PFrameInternal.PFrameV8 {
173
183
  try {
174
184
  return AddonSymbol.pFrameSetDataSource(this.frame, wrappedDataSource);
175
185
  } catch (err: unknown) {
176
- throw new Error(
186
+ throw new PFrameError(
177
187
  `PFrame ${this.id} setDataSource request ${requestId} failed, ` +
178
188
  `dataSource: ${dataSource.toString()}, ` +
179
189
  `error:\n` +
180
- `${(err as Error).toString()}`
190
+ `${ensureError(err).message}`
181
191
  );
182
192
  }
183
193
  }
@@ -211,12 +221,12 @@ export class PFrame implements PFrameInternal.PFrameV8 {
211
221
  try {
212
222
  return AddonSymbol.pFrameSetColumnData(this.frame, columnId, dataInfo);
213
223
  } catch (err: unknown) {
214
- throw new Error(
224
+ throw new PFrameError(
215
225
  `PFrame ${this.id} setColumnData request ${requestId} failed, ` +
216
226
  `columnId: ${JSON.stringify(columnId)}, ` +
217
227
  `dataInfo: ${JSON.stringify(dataInfo)}, ` +
218
228
  `error:\n` +
219
- `${(err as Error).toString()}`
229
+ `${ensureError(err).message}`
220
230
  );
221
231
  }
222
232
  }
@@ -236,10 +246,10 @@ export class PFrame implements PFrameInternal.PFrameV8 {
236
246
  AddonSymbol.pFrameDispose(this.frame);
237
247
  this.logger?.('info', `PFrame ${this.id} disposed`);
238
248
  } catch (err: unknown) {
239
- throw new Error(
249
+ throw new PFrameError(
240
250
  `PFrame ${this.id} dispose request ${requestId} failed, ` +
241
251
  `error:\n` +
242
- `${(err as Error).toString()}`
252
+ `${ensureError(err).message}`
243
253
  );
244
254
  }
245
255
  }
@@ -266,11 +276,11 @@ export class PFrame implements PFrameInternal.PFrameV8 {
266
276
  try {
267
277
  return await AddonSymbol.pFrameFindColumns(this.frame, request);
268
278
  } catch (err: unknown) {
269
- throw new Error(
279
+ throw new PFrameError(
270
280
  `PFrame ${this.id} findColumns request ${requestId} failed, ` +
271
281
  `request: ${JSON.stringify(request)}, ` +
272
282
  `error:\n` +
273
- `${(err as Error).toString()}`
283
+ `${ensureError(err).message}`
274
284
  );
275
285
  } finally {
276
286
  const t1 = performance.now();
@@ -299,11 +309,11 @@ export class PFrame implements PFrameInternal.PFrameV8 {
299
309
  try {
300
310
  return await AddonSymbol.pFrameDeleteColumn(this.frame, request);
301
311
  } catch (err: unknown) {
302
- throw new Error(
312
+ throw new PFrameError(
303
313
  `PFrame ${this.id} deleteColumn request ${requestId} failed, ` +
304
314
  `request: ${JSON.stringify(request)}, ` +
305
315
  `error:\n` +
306
- `${(err as Error).toString()}`
316
+ `${ensureError(err).message}`
307
317
  );
308
318
  } finally {
309
319
  const t1 = performance.now();
@@ -332,11 +342,11 @@ export class PFrame implements PFrameInternal.PFrameV8 {
332
342
  try {
333
343
  return await AddonSymbol.pFrameGetColumnSpec(this.frame, columnId);
334
344
  } catch (err: unknown) {
335
- throw new Error(
345
+ throw new PFrameError(
336
346
  `PFrame ${this.id} getColumnSpec request ${requestId} failed, ` +
337
347
  `columnId: ${JSON.stringify(columnId)}, ` +
338
348
  `error:\n` +
339
- `${(err as Error).toString()}`
349
+ `${ensureError(err).message}`
340
350
  );
341
351
  } finally {
342
352
  const t1 = performance.now();
@@ -362,10 +372,10 @@ export class PFrame implements PFrameInternal.PFrameV8 {
362
372
  try {
363
373
  return await AddonSymbol.pFrameListColumns(this.frame);
364
374
  } catch (err: unknown) {
365
- throw new Error(
375
+ throw new PFrameError(
366
376
  `PFrame ${this.id} listColumns request ${requestId} failed, ` +
367
377
  `error:\n` +
368
- `${(err as Error).toString()}`
378
+ `${ensureError(err).message}`
369
379
  );
370
380
  } finally {
371
381
  const t1 = performance.now();
@@ -401,11 +411,11 @@ export class PFrame implements PFrameInternal.PFrameV8 {
401
411
  );
402
412
  return new PTable(this, requestId, boxed);
403
413
  } catch (err: unknown) {
404
- throw new Error(
414
+ throw new PFrameError(
405
415
  `PFrame ${this.id} createTable request ${requestId} failed, ` +
406
416
  `request: ${JSON.stringify(request)}, ` +
407
417
  `error:\n` +
408
- `${(err as Error).toString()}`
418
+ `${ensureError(err).message}`
409
419
  );
410
420
  } finally {
411
421
  const t1 = performance.now();
@@ -447,11 +457,16 @@ export class PFrame implements PFrameInternal.PFrameV8 {
447
457
  ops?.signal
448
458
  );
449
459
  } catch (err: unknown) {
450
- throw new Error(
460
+ if (isAbortError(err)) {
461
+ throw new AbortError(
462
+ `PFrame ${this.id} getUniqueValues request ${requestId} cancelled`
463
+ );
464
+ }
465
+ throw new PFrameError(
451
466
  `PFrame ${this.id} getUniqueValues request ${requestId} failed, ` +
452
467
  `request: ${JSON.stringify(request)}, ` +
453
468
  `error:\n` +
454
- `${(err as Error).toString()}`
469
+ `${ensureError(err).message}`
455
470
  );
456
471
  } finally {
457
472
  const t1 = performance.now();
@@ -486,10 +501,10 @@ class PTable implements PFrameInternal.PTableV6 {
486
501
  try {
487
502
  return AddonSymbol.pTableGetSpec(this.table);
488
503
  } catch (err: unknown) {
489
- throw new Error(
504
+ throw new PFrameError(
490
505
  `PTable ${this.id} getSpec request ${requestId} failed, ` +
491
506
  `error:\n` +
492
- `${(err as Error).toString()}`
507
+ `${ensureError(err).message}`
493
508
  );
494
509
  }
495
510
  }
@@ -511,11 +526,11 @@ class PTable implements PFrameInternal.PTableV6 {
511
526
  try {
512
527
  return AddonSymbol.pTableGetColumnIndices(this.table, columnIds);
513
528
  } catch (err: unknown) {
514
- throw new Error(
529
+ throw new PFrameError(
515
530
  `PTable ${this.id} getColumnIndices request ${requestId} failed, ` +
516
531
  `columnIds: ${JSON.stringify(columnIds)}, ` +
517
532
  `error:\n` +
518
- `${(err as Error).toString()}`
533
+ `${ensureError(err).message}`
519
534
  );
520
535
  }
521
536
  }
@@ -547,10 +562,15 @@ class PTable implements PFrameInternal.PTableV6 {
547
562
  ops?.signal
548
563
  );
549
564
  } catch (err: unknown) {
550
- throw new Error(
565
+ if (isAbortError(err)) {
566
+ throw new AbortError(
567
+ `PTable ${this.id} getFootprint request ${requestId} cancelled`
568
+ );
569
+ }
570
+ throw new PFrameError(
551
571
  `PTable ${this.id} getFootprint request ${requestId} failed, ` +
552
572
  `error:\n` +
553
- `${(err as Error).toString()}`
573
+ `${ensureError(err).message}`
554
574
  );
555
575
  } finally {
556
576
  const t1 = performance.now();
@@ -581,10 +601,15 @@ class PTable implements PFrameInternal.PTableV6 {
581
601
  ops?.signal?.throwIfAborted();
582
602
  return await AddonSymbol.pTableGetShape(this.table, ops?.signal);
583
603
  } catch (err: unknown) {
584
- throw new Error(
604
+ if (isAbortError(err)) {
605
+ throw new AbortError(
606
+ `PTable ${this.id} getShape request ${requestId} cancelled`
607
+ );
608
+ }
609
+ throw new PFrameError(
585
610
  `PTable ${this.id} getShape request ${requestId} failed, ` +
586
611
  `error:\n` +
587
- `${(err as Error).toString()}`
612
+ `${ensureError(err).message}`
588
613
  );
589
614
  } finally {
590
615
  const t1 = performance.now();
@@ -634,12 +659,17 @@ class PTable implements PFrameInternal.PTableV6 {
634
659
  rowCount = result[0].data.length;
635
660
  return result;
636
661
  } catch (err: unknown) {
637
- throw new Error(
662
+ if (isAbortError(err)) {
663
+ throw new AbortError(
664
+ `PTable ${this.id} getData request ${requestId} cancelled`
665
+ );
666
+ }
667
+ throw new PFrameError(
638
668
  `PTable ${this.id} getData request ${requestId} failed, ` +
639
669
  `columnIndices: ${JSON.stringify(columnIndices)}, ` +
640
670
  `range: ${ops?.range ? JSON.stringify(ops.range) : undefined}, ` +
641
671
  `error:\n` +
642
- `${(err as Error).toString()}`
672
+ `${ensureError(err).message}`
643
673
  );
644
674
  } finally {
645
675
  const t1 = performance.now();
@@ -676,11 +706,11 @@ class PTable implements PFrameInternal.PTableV6 {
676
706
  const boxed = AddonSymbol.pTableFilter(this.table, requestId, request);
677
707
  return new PTable(this.frame, requestId, boxed);
678
708
  } catch (err: unknown) {
679
- throw new Error(
709
+ throw new PFrameError(
680
710
  `PTable ${this.id} filter request ${requestId} failed, ` +
681
711
  `request: ${JSON.stringify(request)}, ` +
682
712
  `error:\n` +
683
- `${(err as Error).toString()}`
713
+ `${ensureError(err).message}`
684
714
  );
685
715
  } finally {
686
716
  const t1 = performance.now();
@@ -715,11 +745,11 @@ class PTable implements PFrameInternal.PTableV6 {
715
745
  const boxed = AddonSymbol.pTableSort(this.table, requestId, request);
716
746
  return new PTable(this.frame, requestId, boxed);
717
747
  } catch (err: unknown) {
718
- throw new Error(
748
+ throw new PFrameError(
719
749
  `PTable ${this.id} sort request ${requestId} failed, ` +
720
750
  `request: ${JSON.stringify(request)}, ` +
721
751
  `error:\n` +
722
- `${(err as Error).toString()}`
752
+ `${ensureError(err).message}`
723
753
  );
724
754
  } finally {
725
755
  const t1 = performance.now();
@@ -745,10 +775,10 @@ class PTable implements PFrameInternal.PTableV6 {
745
775
  AddonSymbol.pTableDispose(this.table);
746
776
  this.frame.logger?.('info', `PTable ${this.id} disposed`);
747
777
  } catch (err: unknown) {
748
- throw new Error(
778
+ throw new PFrameError(
749
779
  `PTable ${this.id} dispose request ${requestId} failed, ` +
750
780
  `error:\n` +
751
- `${(err as Error).toString()}`
781
+ `${ensureError(err).message}`
752
782
  );
753
783
  }
754
784
  }
@@ -1,21 +1,22 @@
1
- "use strict";var I=Object.defineProperty;var j=(n,t,e)=>t in n?I(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var S=(n,t,e)=>j(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("humanize-duration"),u=require("ulid"),E=require("node:module"),w=require("node:path"),M=require("node:url"),U=require("@mapbox/node-pre-gyp"),R=require("node:crypto"),p=require("node:fs"),y=require("node:stream");var D=typeof document<"u"?document.currentScript:null;const F=typeof document>"u"?require("url").pathToFileURL(__filename).href:D&&D.tagName.toUpperCase()==="SCRIPT"&&D.src||new URL("index.js",document.baseURI).href,J=w.dirname(M.fileURLToPath(F)),N=E.createRequire(F),{find:O}=U,d=N(O(w.resolve(J,"../package.json")));async function C(n){try{return await p.promises.access(n),!0}catch{return!1}}async function k(n){await C(n)||await p.promises.mkdir(n,{recursive:!0})}async function v(n,t){const e=`${n}.tmp`;await C(e)&&await p.promises.rm(e,{recursive:!0});const r=typeof t=="string"?Buffer.from(t,"utf8"):t,i=y.Readable.from(r),a=p.createWriteStream(e,{flags:"wx"});await y.Readable.toWeb(i).pipeTo(y.Writable.toWeb(a)),await p.promises.rename(e,n)}function f(n){return R.createHash("sha256").update(n).digest("hex")}function b(n){return n.type==="column"?{...n,id:f(n.id)}:n}function T(n){return{...n,column:b(n.column)}}function _(n){return{...n,columnId:f(n.columnId),filters:n.filters.map(T)}}function A(n){return{...n,column:b(n.column)}}function g(n){const t=n.type;switch(t){case"column":return{...n,columnId:f(n.columnId)};case"slicedColumn":return{...n,columnId:f(n.columnId),newId:f(n.newId)};case"inlineColumn":return{...n,newId:f(n.newId)};case"inner":return{...n,entries:n.entries.map(g)};case"full":return{...n,entries:n.entries.map(g)};case"outer":return{...n,primary:g(n.primary),secondary:n.secondary.map(g)};default:throw new Error(`Unsupported join entry type: ${t}`)}}function B(n){return{...n,src:g(n.src),filters:n.filters.map(T)}}async function l(n,t,e){if(process.env.MI_DUMP_PFRAMES_RS)try{const r=n.map(o=>encodeURIComponent(o)),i=w.join(process.env.MI_DUMP_PFRAMES_RS,...r.slice(0,-1));await k(i);const a=w.join(process.env.MI_DUMP_PFRAMES_RS,...r),s=ArrayBuffer.isView(t)?t:JSON.stringify(t,null,2);await v(a,s)}catch(r){e==null||e("warn",`error while dumping PFrames data: ${r}`)}}let x=class{constructor(t,e){S(this,"id",u.ulid());S(this,"frame");var r;this.logger=e,l([`${this.id}`,`${this.id}.json`],{timeStamp:Date.now(),requestType:"create"},this.logger);try{this.frame=d.pFrameCreate(t,e),(r=this.logger)==null||r.call(this,"info",`PFrame ${this.id} created`)}catch(i){throw new Error(`PFrame ${this.id} creation failed, logger: ${e==null?void 0:e.toString()}, error:
2
- ${i.toString()}`)}}static async pprofDump(){return d.pprofDump()}addColumnSpec(t,e){const r=u.ulid();l([`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"addColumnSpec",requestData:{columnId:f(t),columnSpec:e}},this.logger),l([`${this.id}`,"data",`${f(t)}.spec`],{...e},this.logger);try{return d.pFrameAddColumnSpec(this.frame,t,e)}catch(i){throw new Error(`PFrame ${this.id} addColumnSpec request ${r} failed, columnId: ${JSON.stringify(t)}, columnSpec: ${JSON.stringify(e)}, error:
3
- ${i.toString()}`)}}setDataSource(t){const e=u.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"setDataSource"},this.logger);const r={preloadBlob:async i=>{var o,h;const a=u.ulid();l([`${this.id}`,`${a}.json`],{timeStamp:Date.now(),requestType:"preloadBlob",requestData:{blobIds:i}},this.logger),(o=this.logger)==null||o.call(this,"info",`PFrame ${this.id} preloadBlob started, blobIds: ${JSON.stringify(i)}`);const s=performance.now();try{return await t.preloadBlob(i)}finally{const c=performance.now();(h=this.logger)==null||h.call(this,"info",`PFrame ${this.id} preloadBlob finished, took ${m(Math.round(c-s))} (${i.length} blobs)`)}},resolveBlobContent:async i=>{var o;const a=u.ulid();l([`${this.id}`,`${a}.json`],{timeStamp:Date.now(),requestType:"resolveBlobContent",requestData:{blobId:i}},this.logger);const s=await t.resolveBlobContent(i);return(o=this.logger)==null||o.call(this,"info",`PFrame ${this.id} resolved blob ${i}`),l([`${this.id}`,"data",`${i}`],s,this.logger),s}};try{return d.pFrameSetDataSource(this.frame,r)}catch(i){throw new Error(`PFrame ${this.id} setDataSource request ${e} failed, dataSource: ${t.toString()}, error:
4
- ${i.toString()}`)}}setColumnData(t,e){const r=u.ulid();l([`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"setColumnData",requestData:{columnId:f(t),dataInfo:e}},this.logger),l([`${this.id}`,"data",`${f(t)}.datainfo`],{...e},this.logger);try{return d.pFrameSetColumnData(this.frame,t,e)}catch(i){throw new Error(`PFrame ${this.id} setColumnData request ${r} failed, columnId: ${JSON.stringify(t)}, dataInfo: ${JSON.stringify(e)}, error:
5
- ${i.toString()}`)}}dispose(){var e;const t=u.ulid();l([`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"dispose"},this.logger);try{d.pFrameDispose(this.frame),(e=this.logger)==null||e.call(this,"info",`PFrame ${this.id} disposed`)}catch(r){throw new Error(`PFrame ${this.id} dispose request ${t} failed, error:
6
- ${r.toString()}`)}}[Symbol.dispose](){this.dispose()}async findColumns(t){var i;const e=u.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"findColumns",requestData:t},this.logger);const r=performance.now();try{return await d.pFrameFindColumns(this.frame,t)}catch(a){throw new Error(`PFrame ${this.id} findColumns request ${e} failed, request: ${JSON.stringify(t)}, error:
7
- ${a.toString()}`)}finally{const a=performance.now();(i=this.logger)==null||i.call(this,"info",`PFrame ${this.id} findColumns request ${e} took ${m(Math.round(a-r))}`)}}async deleteColumn(t){var i;const e=u.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"deleteColumn",requestData:t},this.logger);const r=performance.now();try{return await d.pFrameDeleteColumn(this.frame,t)}catch(a){throw new Error(`PFrame ${this.id} deleteColumn request ${e} failed, request: ${JSON.stringify(t)}, error:
8
- ${a.toString()}`)}finally{const a=performance.now();(i=this.logger)==null||i.call(this,"info",`PFrame ${this.id} deleteColumn request ${e} took ${m(Math.round(a-r))}`)}}async getColumnSpec(t){var i;const e=u.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getColumnSpec",requestData:{columnId:f(t)}},this.logger);const r=performance.now();try{return await d.pFrameGetColumnSpec(this.frame,t)}catch(a){throw new Error(`PFrame ${this.id} getColumnSpec request ${e} failed, columnId: ${JSON.stringify(t)}, error:
9
- ${a.toString()}`)}finally{const a=performance.now();(i=this.logger)==null||i.call(this,"info",`PFrame ${this.id} getColumnSpec request ${e} took ${m(Math.round(a-r))}`)}}async listColumns(){var r;const t=u.ulid();l([`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"listColumns"},this.logger);const e=performance.now();try{return await d.pFrameListColumns(this.frame)}catch(i){throw new Error(`PFrame ${this.id} listColumns request ${t} failed, error:
10
- ${i.toString()}`)}finally{const i=performance.now();(r=this.logger)==null||r.call(this,"info",`PFrame ${this.id} listColumns request ${t} took ${m(Math.round(i-e))}`)}}createTable(t){var a;const e=u.ulid(),r={timeStamp:Date.now(),requestType:"createTable",requestData:B(t)};l([`${this.id}`,`${e}.json`],r,this.logger),l([`${this.id}`,`${e}`,`${e}.json`],r,this.logger);const i=performance.now();try{const s=d.pFrameCreateTable(this.frame,e,t);return new q(this,e,s)}catch(s){throw new Error(`PFrame ${this.id} createTable request ${e} failed, request: ${JSON.stringify(t)}, error:
11
- ${s.toString()}`)}finally{const s=performance.now();(a=this.logger)==null||a.call(this,"info",`PFrame ${this.id} createTable request ${e} took ${m(Math.round(s-i))}`)}}async getUniqueValues(t,e){var a,s,o;const r=u.ulid();l([`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"getUniqueValues",requestData:_(t)},this.logger),(a=this.logger)==null||a.call(this,"info",`PFrame ${this.id} getUniqueValues request ${r} started`);const i=performance.now();try{return(s=e==null?void 0:e.signal)==null||s.throwIfAborted(),await d.pFrameGetUniqueValues(this.frame,r,t,e==null?void 0:e.signal)}catch(h){throw new Error(`PFrame ${this.id} getUniqueValues request ${r} failed, request: ${JSON.stringify(t)}, error:
12
- ${h.toString()}`)}finally{const h=performance.now();(o=this.logger)==null||o.call(this,"info",`PFrame ${this.id} getUniqueValues request ${r} finished, took ${m(Math.round(h-i))}`)}}};class q{constructor(t,e,r){var i,a;this.frame=t,this.id=e,this.table=r,(a=(i=this.frame).logger)==null||a.call(i,"info",`PTable ${this.id} created`)}getSpec(){const t=u.ulid();l([`${this.frame.id}`,`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"getSpec"},this.frame.logger);try{return d.pTableGetSpec(this.table)}catch(e){throw new Error(`PTable ${this.id} getSpec request ${t} failed, error:
13
- ${e.toString()}`)}}getColumnIndices(t){const e=u.ulid();l([`${this.frame.id}`,`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getColumnIndices",requestData:{columnIds:t.map(b)}},this.frame.logger);try{return d.pTableGetColumnIndices(this.table,t)}catch(r){throw new Error(`PTable ${this.id} getColumnIndices request ${e} failed, columnIds: ${JSON.stringify(t)}, error:
14
- ${r.toString()}`)}}async getFootprint(t){var i,a,s,o,h;const e=u.ulid();l([`${this.frame.id}`,`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getFootprint"},this.frame.logger),(a=(i=this.frame).logger)==null||a.call(i,"info",`PTable ${this.id} getFootprint request ${e} started`);const r=performance.now();try{return(s=t==null?void 0:t.signal)==null||s.throwIfAborted(),await d.pTableGetFootprint(this.table,(t==null?void 0:t.withPredecessors)??!1,t==null?void 0:t.signal)}catch(c){throw new Error(`PTable ${this.id} getFootprint request ${e} failed, error:
15
- ${c.toString()}`)}finally{const c=performance.now();(h=(o=this.frame).logger)==null||h.call(o,"info",`PTable ${this.id} getFootprint request ${e} finished, took ${m(Math.round(c-r))}`)}}async getShape(t){var i,a,s,o,h;const e=u.ulid();l([`${this.frame.id}`,`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getShape"},this.frame.logger),(a=(i=this.frame).logger)==null||a.call(i,"info",`PTable ${this.id} getShape request ${e} started`);const r=performance.now();try{return(s=t==null?void 0:t.signal)==null||s.throwIfAborted(),await d.pTableGetShape(this.table,t==null?void 0:t.signal)}catch(c){throw new Error(`PTable ${this.id} getShape request ${e} failed, error:
16
- ${c.toString()}`)}finally{const c=performance.now();(h=(o=this.frame).logger)==null||h.call(o,"info",`PTable ${this.id} getShape request ${e} finished, took ${m(Math.round(c-r))}`)}}async getData(t,e){var s,o,h,c,P;const r=u.ulid();l([`${this.frame.id}`,`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"getData",requestData:{columnIndices:t,range:(e==null?void 0:e.range)??null}},this.frame.logger),(o=(s=this.frame).logger)==null||o.call(s,"info",`PTable ${this.id} getData request ${r} started`);let i=0;const a=performance.now();try{(h=e==null?void 0:e.signal)==null||h.throwIfAborted();const $=await d.pTableGetData(this.table,r,t,e==null?void 0:e.range,e==null?void 0:e.signal);return i=$[0].data.length,$}catch($){throw new Error(`PTable ${this.id} getData request ${r} failed, columnIndices: ${JSON.stringify(t)}, range: ${e!=null&&e.range?JSON.stringify(e.range):void 0}, error:
17
- ${$.toString()}`)}finally{const $=performance.now();(P=(c=this.frame).logger)==null||P.call(c,"info",`PTable ${this.id} getData request ${r} finished, took ${m(Math.round($-a))} (${i} rows)`)}}filter(t){var a,s;const e=u.ulid(),r={timeStamp:Date.now(),table:this.id,requestType:"filter",requestData:{filters:t.map(T)}};l([`${this.frame.id}`,`${e}.json`],r,this.frame.logger),l([`${this.frame.id}`,`${e}`,`${e}.json`],r,this.frame.logger);const i=performance.now();try{const o=d.pTableFilter(this.table,e,t);return new q(this.frame,e,o)}catch(o){throw new Error(`PTable ${this.id} filter request ${e} failed, request: ${JSON.stringify(t)}, error:
18
- ${o.toString()}`)}finally{const o=performance.now();(s=(a=this.frame).logger)==null||s.call(a,"info",`PTable ${this.id} filter request ${e} took ${m(Math.round(o-i))}`)}}sort(t){var a,s;const e=u.ulid(),r={timeStamp:Date.now(),table:this.id,requestType:"sort",requestData:t.map(A)};l([`${this.frame.id}`,`${e}.json`],r,this.frame.logger),l([`${this.frame.id}`,`${e}`,`${e}.json`],r,this.frame.logger);const i=performance.now();try{const o=d.pTableSort(this.table,e,t);return new q(this.frame,e,o)}catch(o){throw new Error(`PTable ${this.id} sort request ${e} failed, request: ${JSON.stringify(t)}, error:
19
- ${o.toString()}`)}finally{const o=performance.now();(s=(a=this.frame).logger)==null||s.call(a,"info",`PTable ${this.id} sort request ${e} took ${m(Math.round(o-i))}`)}}dispose(){var e,r;const t=u.ulid();l([`${this.frame.id}`,`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"dispose"},this.frame.logger);try{d.pTableDispose(this.table),(r=(e=this.frame).logger)==null||r.call(e,"info",`PTable ${this.id} disposed`)}catch(i){throw new Error(`PTable ${this.id} dispose request ${t} failed, error:
20
- ${i.toString()}`)}}[Symbol.dispose](){this.dispose()}}const V=x;exports.PFrame=V;
1
+ "use strict";var I=Object.defineProperty;var j=(s,r,e)=>r in s?I(s,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[r]=e;var P=(s,r,e)=>j(s,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("humanize-duration"),m=require("ulid"),a=require("@milaboratories/pl-model-common"),M=require("node:module"),q=require("node:path"),U=require("node:url"),A=require("@mapbox/node-pre-gyp"),R=require("node:crypto"),p=require("node:fs"),S=require("node:stream");var F=typeof document<"u"?document.currentScript:null;const E=typeof document>"u"?require("url").pathToFileURL(__filename).href:F&&F.tagName.toUpperCase()==="SCRIPT"&&F.src||new URL("index.js",document.baseURI).href,J=q.dirname(U.fileURLToPath(E)),N=M.createRequire(E),{find:O}=A,d=N(O(q.resolve(J,"../package.json")));async function C(s){try{return await p.promises.access(s),!0}catch{return!1}}async function k(s){await C(s)||await p.promises.mkdir(s,{recursive:!0})}async function v(s,r){const e=`${s}.tmp`;await C(e)&&await p.promises.rm(e,{recursive:!0});const t=typeof r=="string"?Buffer.from(r,"utf8"):r,i=S.Readable.from(t),n=p.createWriteStream(e,{flags:"wx"});await S.Readable.toWeb(i).pipeTo(S.Writable.toWeb(n)),await p.promises.rename(e,s)}function $(s){return R.createHash("sha256").update(s).digest("hex")}function b(s){return s.type==="column"?{...s,id:$(s.id)}:s}function D(s){return{...s,column:b(s.column)}}function _(s){return{...s,columnId:$(s.columnId),filters:s.filters.map(D)}}function B(s){return{...s,column:b(s.column)}}function w(s){const r=s.type;switch(r){case"column":return{...s,columnId:$(s.columnId)};case"slicedColumn":return{...s,columnId:$(s.columnId),newId:$(s.newId)};case"inlineColumn":return{...s,newId:$(s.newId)};case"inner":return{...s,entries:s.entries.map(w)};case"full":return{...s,entries:s.entries.map(w)};case"outer":return{...s,primary:w(s.primary),secondary:s.secondary.map(w)};default:throw new Error(`Unsupported join entry type: ${r}`)}}function V(s){return{...s,src:w(s.src),filters:s.filters.map(D)}}async function l(s,r,e){if(process.env.MI_DUMP_PFRAMES_RS)try{const t=s.map(o=>encodeURIComponent(o)),i=q.join(process.env.MI_DUMP_PFRAMES_RS,...t.slice(0,-1));await k(i);const n=q.join(process.env.MI_DUMP_PFRAMES_RS,...t),u=ArrayBuffer.isView(r)?r:JSON.stringify(r,null,2);await v(n,u)}catch(t){e==null||e("warn",`error while dumping PFrames data: ${t}`)}}let x=class{constructor(r,e){P(this,"id",m.ulid());P(this,"frame");var t;this.logger=e,l([`${this.id}`,`${this.id}.json`],{timeStamp:Date.now(),requestType:"create"},this.logger);try{this.frame=d.pFrameCreate(r,e),(t=this.logger)==null||t.call(this,"info",`PFrame ${this.id} created`)}catch(i){throw new a.PFrameError(`PFrame ${this.id} creation failed, logger: ${e==null?void 0:e.toString()}, error:
2
+ ${a.ensureError(i).message}`)}}static async pprofDump(){try{return await d.pprofDump()}catch(r){throw new a.PFrameError(`PFrame pprofDump failed, error:
3
+ ${a.ensureError(r).message}`)}}addColumnSpec(r,e){const t=m.ulid();l([`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"addColumnSpec",requestData:{columnId:$(r),columnSpec:e}},this.logger),l([`${this.id}`,"data",`${$(r)}.spec`],{...e},this.logger);try{return d.pFrameAddColumnSpec(this.frame,r,e)}catch(i){throw new a.PFrameError(`PFrame ${this.id} addColumnSpec request ${t} failed, columnId: ${JSON.stringify(r)}, columnSpec: ${JSON.stringify(e)}, error:
4
+ ${a.ensureError(i).message}`)}}setDataSource(r){const e=m.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"setDataSource"},this.logger);const t={preloadBlob:async i=>{var o,h;const n=m.ulid();l([`${this.id}`,`${n}.json`],{timeStamp:Date.now(),requestType:"preloadBlob",requestData:{blobIds:i}},this.logger),(o=this.logger)==null||o.call(this,"info",`PFrame ${this.id} preloadBlob started, blobIds: ${JSON.stringify(i)}`);const u=performance.now();try{return await r.preloadBlob(i)}finally{const c=performance.now();(h=this.logger)==null||h.call(this,"info",`PFrame ${this.id} preloadBlob finished, took ${f(Math.round(c-u))} (${i.length} blobs)`)}},resolveBlobContent:async i=>{var o;const n=m.ulid();l([`${this.id}`,`${n}.json`],{timeStamp:Date.now(),requestType:"resolveBlobContent",requestData:{blobId:i}},this.logger);const u=await r.resolveBlobContent(i);return(o=this.logger)==null||o.call(this,"info",`PFrame ${this.id} resolved blob ${i}`),l([`${this.id}`,"data",`${i}`],u,this.logger),u}};try{return d.pFrameSetDataSource(this.frame,t)}catch(i){throw new a.PFrameError(`PFrame ${this.id} setDataSource request ${e} failed, dataSource: ${r.toString()}, error:
5
+ ${a.ensureError(i).message}`)}}setColumnData(r,e){const t=m.ulid();l([`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"setColumnData",requestData:{columnId:$(r),dataInfo:e}},this.logger),l([`${this.id}`,"data",`${$(r)}.datainfo`],{...e},this.logger);try{return d.pFrameSetColumnData(this.frame,r,e)}catch(i){throw new a.PFrameError(`PFrame ${this.id} setColumnData request ${t} failed, columnId: ${JSON.stringify(r)}, dataInfo: ${JSON.stringify(e)}, error:
6
+ ${a.ensureError(i).message}`)}}dispose(){var e;const r=m.ulid();l([`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"dispose"},this.logger);try{d.pFrameDispose(this.frame),(e=this.logger)==null||e.call(this,"info",`PFrame ${this.id} disposed`)}catch(t){throw new a.PFrameError(`PFrame ${this.id} dispose request ${r} failed, error:
7
+ ${a.ensureError(t).message}`)}}[Symbol.dispose](){this.dispose()}async findColumns(r){var i;const e=m.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"findColumns",requestData:r},this.logger);const t=performance.now();try{return await d.pFrameFindColumns(this.frame,r)}catch(n){throw new a.PFrameError(`PFrame ${this.id} findColumns request ${e} failed, request: ${JSON.stringify(r)}, error:
8
+ ${a.ensureError(n).message}`)}finally{const n=performance.now();(i=this.logger)==null||i.call(this,"info",`PFrame ${this.id} findColumns request ${e} took ${f(Math.round(n-t))}`)}}async deleteColumn(r){var i;const e=m.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"deleteColumn",requestData:r},this.logger);const t=performance.now();try{return await d.pFrameDeleteColumn(this.frame,r)}catch(n){throw new a.PFrameError(`PFrame ${this.id} deleteColumn request ${e} failed, request: ${JSON.stringify(r)}, error:
9
+ ${a.ensureError(n).message}`)}finally{const n=performance.now();(i=this.logger)==null||i.call(this,"info",`PFrame ${this.id} deleteColumn request ${e} took ${f(Math.round(n-t))}`)}}async getColumnSpec(r){var i;const e=m.ulid();l([`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getColumnSpec",requestData:{columnId:$(r)}},this.logger);const t=performance.now();try{return await d.pFrameGetColumnSpec(this.frame,r)}catch(n){throw new a.PFrameError(`PFrame ${this.id} getColumnSpec request ${e} failed, columnId: ${JSON.stringify(r)}, error:
10
+ ${a.ensureError(n).message}`)}finally{const n=performance.now();(i=this.logger)==null||i.call(this,"info",`PFrame ${this.id} getColumnSpec request ${e} took ${f(Math.round(n-t))}`)}}async listColumns(){var t;const r=m.ulid();l([`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"listColumns"},this.logger);const e=performance.now();try{return await d.pFrameListColumns(this.frame)}catch(i){throw new a.PFrameError(`PFrame ${this.id} listColumns request ${r} failed, error:
11
+ ${a.ensureError(i).message}`)}finally{const i=performance.now();(t=this.logger)==null||t.call(this,"info",`PFrame ${this.id} listColumns request ${r} took ${f(Math.round(i-e))}`)}}createTable(r){var n;const e=m.ulid(),t={timeStamp:Date.now(),requestType:"createTable",requestData:V(r)};l([`${this.id}`,`${e}.json`],t,this.logger),l([`${this.id}`,`${e}`,`${e}.json`],t,this.logger);const i=performance.now();try{const u=d.pFrameCreateTable(this.frame,e,r);return new y(this,e,u)}catch(u){throw new a.PFrameError(`PFrame ${this.id} createTable request ${e} failed, request: ${JSON.stringify(r)}, error:
12
+ ${a.ensureError(u).message}`)}finally{const u=performance.now();(n=this.logger)==null||n.call(this,"info",`PFrame ${this.id} createTable request ${e} took ${f(Math.round(u-i))}`)}}async getUniqueValues(r,e){var n,u,o;const t=m.ulid();l([`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"getUniqueValues",requestData:_(r)},this.logger),(n=this.logger)==null||n.call(this,"info",`PFrame ${this.id} getUniqueValues request ${t} started`);const i=performance.now();try{return(u=e==null?void 0:e.signal)==null||u.throwIfAborted(),await d.pFrameGetUniqueValues(this.frame,t,r,e==null?void 0:e.signal)}catch(h){throw a.isAbortError(h)?new a.AbortError(`PFrame ${this.id} getUniqueValues request ${t} cancelled`):new a.PFrameError(`PFrame ${this.id} getUniqueValues request ${t} failed, request: ${JSON.stringify(r)}, error:
13
+ ${a.ensureError(h).message}`)}finally{const h=performance.now();(o=this.logger)==null||o.call(this,"info",`PFrame ${this.id} getUniqueValues request ${t} finished, took ${f(Math.round(h-i))}`)}}};class y{constructor(r,e,t){var i,n;this.frame=r,this.id=e,this.table=t,(n=(i=this.frame).logger)==null||n.call(i,"info",`PTable ${this.id} created`)}getSpec(){const r=m.ulid();l([`${this.frame.id}`,`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"getSpec"},this.frame.logger);try{return d.pTableGetSpec(this.table)}catch(e){throw new a.PFrameError(`PTable ${this.id} getSpec request ${r} failed, error:
14
+ ${a.ensureError(e).message}`)}}getColumnIndices(r){const e=m.ulid();l([`${this.frame.id}`,`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getColumnIndices",requestData:{columnIds:r.map(b)}},this.frame.logger);try{return d.pTableGetColumnIndices(this.table,r)}catch(t){throw new a.PFrameError(`PTable ${this.id} getColumnIndices request ${e} failed, columnIds: ${JSON.stringify(r)}, error:
15
+ ${a.ensureError(t).message}`)}}async getFootprint(r){var i,n,u,o,h;const e=m.ulid();l([`${this.frame.id}`,`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getFootprint"},this.frame.logger),(n=(i=this.frame).logger)==null||n.call(i,"info",`PTable ${this.id} getFootprint request ${e} started`);const t=performance.now();try{return(u=r==null?void 0:r.signal)==null||u.throwIfAborted(),await d.pTableGetFootprint(this.table,(r==null?void 0:r.withPredecessors)??!1,r==null?void 0:r.signal)}catch(c){throw a.isAbortError(c)?new a.AbortError(`PTable ${this.id} getFootprint request ${e} cancelled`):new a.PFrameError(`PTable ${this.id} getFootprint request ${e} failed, error:
16
+ ${a.ensureError(c).message}`)}finally{const c=performance.now();(h=(o=this.frame).logger)==null||h.call(o,"info",`PTable ${this.id} getFootprint request ${e} finished, took ${f(Math.round(c-t))}`)}}async getShape(r){var i,n,u,o,h;const e=m.ulid();l([`${this.frame.id}`,`${this.id}`,`${e}.json`],{timeStamp:Date.now(),requestType:"getShape"},this.frame.logger),(n=(i=this.frame).logger)==null||n.call(i,"info",`PTable ${this.id} getShape request ${e} started`);const t=performance.now();try{return(u=r==null?void 0:r.signal)==null||u.throwIfAborted(),await d.pTableGetShape(this.table,r==null?void 0:r.signal)}catch(c){throw a.isAbortError(c)?new a.AbortError(`PTable ${this.id} getShape request ${e} cancelled`):new a.PFrameError(`PTable ${this.id} getShape request ${e} failed, error:
17
+ ${a.ensureError(c).message}`)}finally{const c=performance.now();(h=(o=this.frame).logger)==null||h.call(o,"info",`PTable ${this.id} getShape request ${e} finished, took ${f(Math.round(c-t))}`)}}async getData(r,e){var u,o,h,c,T;const t=m.ulid();l([`${this.frame.id}`,`${this.id}`,`${t}.json`],{timeStamp:Date.now(),requestType:"getData",requestData:{columnIndices:r,range:(e==null?void 0:e.range)??null}},this.frame.logger),(o=(u=this.frame).logger)==null||o.call(u,"info",`PTable ${this.id} getData request ${t} started`);let i=0;const n=performance.now();try{(h=e==null?void 0:e.signal)==null||h.throwIfAborted();const g=await d.pTableGetData(this.table,t,r,e==null?void 0:e.range,e==null?void 0:e.signal);return i=g[0].data.length,g}catch(g){throw a.isAbortError(g)?new a.AbortError(`PTable ${this.id} getData request ${t} cancelled`):new a.PFrameError(`PTable ${this.id} getData request ${t} failed, columnIndices: ${JSON.stringify(r)}, range: ${e!=null&&e.range?JSON.stringify(e.range):void 0}, error:
18
+ ${a.ensureError(g).message}`)}finally{const g=performance.now();(T=(c=this.frame).logger)==null||T.call(c,"info",`PTable ${this.id} getData request ${t} finished, took ${f(Math.round(g-n))} (${i} rows)`)}}filter(r){var n,u;const e=m.ulid(),t={timeStamp:Date.now(),table:this.id,requestType:"filter",requestData:{filters:r.map(D)}};l([`${this.frame.id}`,`${e}.json`],t,this.frame.logger),l([`${this.frame.id}`,`${e}`,`${e}.json`],t,this.frame.logger);const i=performance.now();try{const o=d.pTableFilter(this.table,e,r);return new y(this.frame,e,o)}catch(o){throw new a.PFrameError(`PTable ${this.id} filter request ${e} failed, request: ${JSON.stringify(r)}, error:
19
+ ${a.ensureError(o).message}`)}finally{const o=performance.now();(u=(n=this.frame).logger)==null||u.call(n,"info",`PTable ${this.id} filter request ${e} took ${f(Math.round(o-i))}`)}}sort(r){var n,u;const e=m.ulid(),t={timeStamp:Date.now(),table:this.id,requestType:"sort",requestData:r.map(B)};l([`${this.frame.id}`,`${e}.json`],t,this.frame.logger),l([`${this.frame.id}`,`${e}`,`${e}.json`],t,this.frame.logger);const i=performance.now();try{const o=d.pTableSort(this.table,e,r);return new y(this.frame,e,o)}catch(o){throw new a.PFrameError(`PTable ${this.id} sort request ${e} failed, request: ${JSON.stringify(r)}, error:
20
+ ${a.ensureError(o).message}`)}finally{const o=performance.now();(u=(n=this.frame).logger)==null||u.call(n,"info",`PTable ${this.id} sort request ${e} took ${f(Math.round(o-i))}`)}}dispose(){var e,t;const r=m.ulid();l([`${this.frame.id}`,`${this.id}`,`${r}.json`],{timeStamp:Date.now(),requestType:"dispose"},this.frame.logger);try{d.pTableDispose(this.table),(t=(e=this.frame).logger)==null||t.call(e,"info",`PTable ${this.id} disposed`)}catch(i){throw new a.PFrameError(`PTable ${this.id} dispose request ${r} failed, error:
21
+ ${a.ensureError(i).message}`)}}[Symbol.dispose](){this.dispose()}}const G=x;exports.PFrame=G;
21
22
  //# sourceMappingURL=index.js.map