@perspective-dev/client 5.6.0 → 5.6.1

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.
@@ -1,2 +1,2 @@
1
- var _=["sum","count","any_value","arbitrary","array_agg","avg","bit_and","bit_or","bit_xor","bitstring_agg","bool_and","bool_or","countif","favg","fsum","geomean","kahan_sum","last","max","min","product","string_agg","sumkahan"],f=["count","any_value","arbitrary","first","countif","last","string_agg"],a=["rows","range","cumulative"],b=[{name:"sum",frames:a,result_type:"float"},{name:"avg",frames:a,result_type:"float"},{name:"count",frames:a,result_type:"float"},{name:"min",frames:a},{name:"max",frames:a},{name:"product",frames:a,result_type:"float"},{name:"median",frames:a,result_type:"float"},{name:"stddev_samp",frames:a,result_type:"float"},{name:"stddev_pop",frames:a,result_type:"float"},{name:"var_samp",frames:a,result_type:"float"},{name:"var_pop",frames:a,result_type:"float"},{name:"first_value",frames:a},{name:"last_value",frames:a},{name:"nth_value",frames:a,offset:!0},{name:"lag",offset:!0},{name:"lead",offset:!0},{name:"row_number",result_type:"float"},{name:"rank",result_type:"float"},{name:"dense_rank",result_type:"float"},{name:"percent_rank",result_type:"float"},{name:"cume_dist",result_type:"float"},{name:"ntile",offset:!0,result_type:"float"},{name:"diff",offset:!0,result_type:"float"},{name:"rate",frames:["range"],result_type:"float"}],d=[{name:"count",frames:a,result_type:"float"},{name:"min",frames:a},{name:"max",frames:a},{name:"first_value",frames:a},{name:"last_value",frames:a},{name:"nth_value",frames:a,offset:!0},{name:"lag",offset:!0},{name:"lead",offset:!0},{name:"row_number",result_type:"float"},{name:"rank",result_type:"float"},{name:"dense_rank",result_type:"float"},{name:"percent_rank",result_type:"float"},{name:"cume_dist",result_type:"float"},{name:"ntile",offset:!0,result_type:"float"}],m=["==","!=","IS DISTINCT FROM","IS NOT DISTINCT FROM",">=","<=",">","<","is null","is not null"],h=[...m,"begins with","not begins with","contains","not contains","ends with","not ends with","matches","not matches","in","not in","LIKE","NOT LIKE","ILIKE","NOT ILIKE"];function y(r){return r=r.toLowerCase(),r.startsWith("bool")?"boolean":["tinyint","smallint","integer","utinyint","usmallint"].includes(r)||["int8","int16","int32","uint8","uint16"].includes(r)?"integer":["bigint","hugeint","uhugeint","uinteger","ubigint"].includes(r)||["float","real","double","varint"].includes(r)||["int64","uint32","uint64","float32","float64"].includes(r)||r.startsWith("decimal")||r.startsWith("numeric")?"float":r.startsWith("date")?"date":r.startsWith("time")?"datetime":(r.startsWith("varchar")||r==="utf8"||r.startsWith("enum")||["json","uuid","blob","bit","interval"].includes(r)||r.startsWith("struct")||r.startsWith("map")||r.startsWith("union")||r.endsWith("[]")||console.warn(`Unknown type '${r}'`),"string")}async function c(r,e,s={}){e=e.replace(/\s+/g," ").trim();try{let t=await r.query(e);return s.columns?{rows:t.toArray(),columns:t.schema.fields.map(n=>n.name),dtypes:t.schema.fields.map(n=>n.type.toString())}:t.toArray()}catch(t){throw console.error("Query error:",t),console.error("Query:",e),t}}var w=class{db;sqlBuilder;constructor(e,s){if(!s&&customElements){let t=customElements.get("perspective-viewer");if(t)s=t.__wasm_module__;else throw new Error("Missing perspective-client.wasm")}this.db=e,this.sqlBuilder=new s.GenericSQLVirtualServerModel({column_separator:"|",like_escape_clause:"\\",regex_fn:"regexp_matches"})}getFeatures(){return{group_by:!0,split_by:!0,sort:!0,expressions:!0,view_derivations:!0,window_aggregates:{integer:b,float:b,string:d,date:d,datetime:d,boolean:d},group_rollup_mode:["rollup","flat","total"],split_rollup_mode:["flat","rollup"],filter_ops:{integer:m,float:m,string:h,boolean:m,date:m,datetime:m},aggregates:{integer:_,float:_,string:f,boolean:f,date:f,datetime:f}}}async getHostedTables(){let e=this.sqlBuilder.getHostedTables();return(await c(this.db,e)).map(t=>{let n=t.toJSON();return`${n.database||"memory"}.${n.name}`})}async tableSchema(e,s){let t=this.sqlBuilder.tableSchema(e),n=await c(this.db,t),i={};for(let l of n){let o=l.toJSON(),u=o.column_name;u.startsWith("__")||(i[u]=y(o.column_type))}return i}async viewColumnSize(e,s){let t=this.sqlBuilder.viewColumnSize(e),n=await c(this.db,t),i=Number(Object.values(n[0].toJSON())[0]),l=s.group_by?.length||0,o=s.group_rollup_mode==="flat";return i-(l===0?0:o?l:l+1)}async tableSize(e){let s=this.sqlBuilder.tableSize(e),t=await c(this.db,s);return Number(t[0].toJSON()["count_star()"])}async tableMakeView(e,s,t){let n=Object.keys(t.windows??{}).length?await this.tableSchema(e):void 0,i=this.sqlBuilder.tableMakeView(e,s,t,n);await c(this.db,i)}async tableDescribe(e,s){let t={},n=this.sqlBuilder.expressionsDescribe(e,s);if(n!==void 0)try{t=await this.describeQuery(n)}catch(u){return await this.attributeExpressionErrors(e,s,u)}let i=Object.keys(s.windows??{}).length?await this.tableSchema(e):void 0,l=this.sqlBuilder.tableDescribe(e,s,i),o={};if(l!==void 0)try{o=await this.describeQuery(l)}catch(u){return{config_error:g(u)}}return{expression_schema:t,view_schema:o}}async describeQuery(e){let s=await c(this.db,e),t={};for(let n of s){let i=n.toJSON();i.column_name.startsWith("__")||(t[i.column_name]=y(i.column_type))}return t}async attributeExpressionErrors(e,s,t){let n={},i={};for(let[l,o]of Object.entries(s.expressions)){let u=this.sqlBuilder.expressionDescribe(e,o);try{let p=await c(this.db,u);n[l]=y(p[0].toJSON().column_type)}catch(p){i[l]={error_message:g(p),line:0,column:0}}}return Object.keys(i).length===0?{config_error:g(t)}:{expression_schema:n,expression_errors:i}}async viewMakeTable(e,s,t,n){let i=this.sqlBuilder.viewMakeTable(e,s,t,await this.tableSchema(e),n);await c(this.db,i)}async viewDelete(e){let s=this.sqlBuilder.viewDelete(e);await c(this.db,s)}async viewGetMinMax(e,s,t){let n=this.sqlBuilder.viewGetMinMax(e,s,t),l=(await c(this.db,n))[0].toJSON(),[o,u]=Object.values(l);return typeof o=="bigint"&&(o=Number(o)),typeof u=="bigint"&&(u=Number(u)),{min:o??null,max:u??null}}async viewGetData(e,s,t,n,i){let l=this.sqlBuilder.viewGetData(e,s,n,t),o=await this.db.useUnsafe((u,p)=>u.runQuery(p,l));i.fromArrowIpc(o)}};function g(r){return r instanceof Error?r.message:String(r)}export{w as DuckDBHandler};
1
+ var _=["sum","count","any_value","arbitrary","array_agg","avg","bit_and","bit_or","bit_xor","bitstring_agg","bool_and","bool_or","countif","favg","fsum","geomean","kahan_sum","last","max","min","product","string_agg","sumkahan"],f=["count","any_value","arbitrary","first","countif","last","string_agg"],a=["rows","range","cumulative"],b=[{name:"sum",frames:a,result_type:"float"},{name:"avg",frames:a,result_type:"float"},{name:"count",frames:a,result_type:"float"},{name:"min",frames:a},{name:"max",frames:a},{name:"product",frames:a,result_type:"float"},{name:"median",frames:a,result_type:"float"},{name:"stddev_samp",frames:a,result_type:"float"},{name:"stddev_pop",frames:a,result_type:"float"},{name:"var_samp",frames:a,result_type:"float"},{name:"var_pop",frames:a,result_type:"float"},{name:"first_value",frames:a},{name:"last_value",frames:a},{name:"nth_value",frames:a,offset:!0},{name:"lag",offset:!0},{name:"lead",offset:!0},{name:"row_number",result_type:"float"},{name:"rank",result_type:"float"},{name:"dense_rank",result_type:"float"},{name:"percent_rank",result_type:"float"},{name:"cume_dist",result_type:"float"},{name:"ntile",offset:!0,result_type:"float"},{name:"diff",offset:!0,result_type:"float"},{name:"rate",frames:["range"],result_type:"float"}],d=[{name:"count",frames:a,result_type:"float"},{name:"min",frames:a},{name:"max",frames:a},{name:"first_value",frames:a},{name:"last_value",frames:a},{name:"nth_value",frames:a,offset:!0},{name:"lag",offset:!0},{name:"lead",offset:!0},{name:"row_number",result_type:"float"},{name:"rank",result_type:"float"},{name:"dense_rank",result_type:"float"},{name:"percent_rank",result_type:"float"},{name:"cume_dist",result_type:"float"},{name:"ntile",offset:!0,result_type:"float"}],m=["==","!=","IS DISTINCT FROM","IS NOT DISTINCT FROM",">=","<=",">","<","is null","is not null"],h=[...m,"begins with","not begins with","contains","not contains","ends with","not ends with","matches","not matches","in","not in","LIKE","NOT LIKE","ILIKE","NOT ILIKE"];function y(r){return r=r.toLowerCase(),r.startsWith("bool")?"boolean":["tinyint","smallint","integer","utinyint","usmallint"].includes(r)||["int8","int16","int32","uint8","uint16"].includes(r)?"integer":["bigint","hugeint","uhugeint","uinteger","ubigint"].includes(r)||["float","real","double","varint","bignum"].includes(r)||["int64","uint32","uint64","float32","float64"].includes(r)||r.startsWith("decimal")||r.startsWith("numeric")?"float":r.startsWith("date")?"date":r.startsWith("time")?"datetime":(r.startsWith("varchar")||r==="utf8"||r.startsWith("enum")||["json","uuid","blob","bit","interval"].includes(r)||r.startsWith("struct")||r.startsWith("map")||r.startsWith("union")||r.endsWith("[]")||console.warn(`Unknown type '${r}'`),"string")}async function c(r,e,s={}){e=e.replace(/\s+/g," ").trim();try{let t=await r.query(e);return s.columns?{rows:t.toArray(),columns:t.schema.fields.map(n=>n.name),dtypes:t.schema.fields.map(n=>n.type.toString())}:t.toArray()}catch(t){throw console.error("Query error:",t),console.error("Query:",e),t}}var w=class{db;sqlBuilder;constructor(e,s){if(!s&&customElements){let t=customElements.get("perspective-viewer");if(t)s=t.__wasm_module__;else throw new Error("Missing perspective-client.wasm")}this.db=e,this.sqlBuilder=new s.GenericSQLVirtualServerModel({column_separator:"|",like_escape_clause:"\\",regex_fn:"regexp_matches"})}getFeatures(){return{group_by:!0,split_by:!0,sort:!0,expressions:!0,view_derivations:!0,window_aggregates:{integer:b,float:b,string:d,date:d,datetime:d,boolean:d},group_rollup_mode:["rollup","flat","total"],split_rollup_mode:["flat","rollup"],filter_ops:{integer:m,float:m,string:h,boolean:m,date:m,datetime:m},aggregates:{integer:_,float:_,string:f,boolean:f,date:f,datetime:f}}}async getHostedTables(){let e=this.sqlBuilder.getHostedTables();return(await c(this.db,e)).map(t=>{let n=t.toJSON();return`${n.database||"memory"}.${n.name}`})}async tableSchema(e,s){let t=this.sqlBuilder.tableSchema(e),n=await c(this.db,t),i={};for(let l of n){let o=l.toJSON(),u=o.column_name;u.startsWith("__")||(i[u]=y(o.column_type))}return i}async viewColumnSize(e,s){let t=this.sqlBuilder.viewColumnSize(e),n=await c(this.db,t),i=Number(Object.values(n[0].toJSON())[0]),l=s.group_by?.length||0,o=s.group_rollup_mode==="flat";return i-(l===0?0:o?l:l+1)}async tableSize(e){let s=this.sqlBuilder.tableSize(e),t=await c(this.db,s);return Number(t[0].toJSON()["count_star()"])}async tableMakeView(e,s,t){let n=Object.keys(t.windows??{}).length?await this.tableSchema(e):void 0,i=this.sqlBuilder.tableMakeView(e,s,t,n);await c(this.db,i)}async tableDescribe(e,s){let t={},n=this.sqlBuilder.expressionsDescribe(e,s);if(n!==void 0)try{t=await this.describeQuery(n)}catch(u){return await this.attributeExpressionErrors(e,s,u)}let i=Object.keys(s.windows??{}).length?await this.tableSchema(e):void 0,l=this.sqlBuilder.tableDescribe(e,s,i),o={};if(l!==void 0)try{o=await this.describeQuery(l)}catch(u){return{config_error:g(u)}}return{expression_schema:t,view_schema:o}}async describeQuery(e){let s=await c(this.db,e),t={};for(let n of s){let i=n.toJSON();i.column_name.startsWith("__")||(t[i.column_name]=y(i.column_type))}return t}async attributeExpressionErrors(e,s,t){let n={},i={};for(let[l,o]of Object.entries(s.expressions)){let u=this.sqlBuilder.expressionDescribe(e,o);try{let p=await c(this.db,u);n[l]=y(p[0].toJSON().column_type)}catch(p){i[l]={error_message:g(p),line:0,column:0}}}return Object.keys(i).length===0?{config_error:g(t)}:{expression_schema:n,expression_errors:i}}async viewMakeTable(e,s,t,n){let i=this.sqlBuilder.viewMakeTable(e,s,t,await this.tableSchema(e),n);await c(this.db,i)}async viewDelete(e){let s=this.sqlBuilder.viewDelete(e);await c(this.db,s)}async viewGetMinMax(e,s,t){let n=this.sqlBuilder.viewGetMinMax(e,s,t),l=(await c(this.db,n))[0].toJSON(),[o,u]=Object.values(l);return typeof o=="bigint"&&(o=Number(o)),typeof u=="bigint"&&(u=Number(u)),{min:o??null,max:u??null}}async viewGetData(e,s,t,n,i){let l=this.sqlBuilder.viewGetData(e,s,n,t),o=await this.db.useUnsafe((u,p)=>u.runQuery(p,l));i.fromArrowIpc(o)}};function g(r){return r instanceof Error?r.message:String(r)}export{w as DuckDBHandler};
2
2
  //# sourceMappingURL=duckdb.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ts/virtual_servers/duckdb.ts"],
4
- "sourcesContent": ["// \u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n// \u2503 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588\u2584 \u2580\u2588\u2588\u2588 \u2588 \u2503\n// \u2503 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2584\u2584\u2584\u2584\u2584 \u2584\u2584\u2584\u2584\u2584\u2588 \u2580\u2580\u2580\u2580\u2580\u2588\u2580\u2580\u2580\u2580\u2580 \u2588 \u2580\u2580\u2580\u2580\u2580\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2584 \u2580\u2588 \u2588 \u2580\u2580\u2580\u2580\u2580 \u2503\n// \u2503 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2588\u2588\u2580\u2580 \u2584\u2584\u2584\u2584\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584 \u2503\n// \u2503 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2580\u2588\u2584 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2503\n// \u2523\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n// \u2503 Copyright (c) 2017, the Perspective Authors. \u2503\n// \u2503 \u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C \u2503\n// \u2503 This file is part of the Perspective library, distributed under the terms \u2503\n// \u2503 of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). \u2503\n// \u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n\n/**\n * An implementation of a Perspective Virtual Server for DuckDB.\n *\n * This import is optional, and so must be imported manually from either\n * `@perspective-dev/client/dist/esm/virtual_servers/duckdb.js` or\n * `@perspective-dev/client/src/ts/virtual_servers/duckdb.ts`, it is not\n * exported from the package root `@perspective-dev/client`\n *\n * @module\n */\n\nimport type * as perspective from \"@perspective-dev/client\";\nimport type { ColumnType } from \"@perspective-dev/client/dist/esm/ts-rs/ColumnType.d.ts\";\nimport type { ViewConfig } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts\";\nimport type {\n ExpressionError,\n TableDescription,\n} from \"@perspective-dev/client\";\nimport type { ViewConfigUpdate } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts\";\nimport type { ViewWindow } from \"@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts\";\nimport type { WindowAggSpec } from \"@perspective-dev/client/dist/esm/ts-rs/WindowAggSpec.d.ts\";\nimport type { Scalar } from \"@perspective-dev/client/dist/esm/ts-rs/Scalar.d.ts\";\nimport type * as duckdb from \"@duckdb/duckdb-wasm\";\n\nconst NUMBER_AGGS = [\n \"sum\",\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"array_agg\",\n \"avg\",\n \"bit_and\",\n \"bit_or\",\n \"bit_xor\",\n \"bitstring_agg\",\n \"bool_and\",\n \"bool_or\",\n \"countif\",\n \"favg\",\n \"fsum\",\n \"geomean\",\n \"kahan_sum\",\n \"last\",\n \"max\",\n \"min\",\n \"product\",\n \"string_agg\",\n \"sumkahan\",\n];\n\nconst STRING_AGGS = [\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"first\",\n \"countif\",\n \"last\",\n \"string_agg\",\n];\n\nconst FRAMES = [\"rows\", \"range\", \"cumulative\"];\n\nconst WINDOW_AGGREGATES: WindowAggSpec[] = [\n { name: \"sum\", frames: FRAMES, result_type: \"float\" },\n { name: \"avg\", frames: FRAMES, result_type: \"float\" },\n { name: \"count\", frames: FRAMES, result_type: \"float\" },\n { name: \"min\", frames: FRAMES },\n { name: \"max\", frames: FRAMES },\n { name: \"product\", frames: FRAMES, result_type: \"float\" },\n { name: \"median\", frames: FRAMES, result_type: \"float\" },\n // DuckDB spells sample and population variants separately, so both are\n // offered rather than one being picked on the user's behalf.\n { name: \"stddev_samp\", frames: FRAMES, result_type: \"float\" },\n { name: \"stddev_pop\", frames: FRAMES, result_type: \"float\" },\n { name: \"var_samp\", frames: FRAMES, result_type: \"float\" },\n { name: \"var_pop\", frames: FRAMES, result_type: \"float\" },\n // Navigation.\n { name: \"first_value\", frames: FRAMES },\n { name: \"last_value\", frames: FRAMES },\n { name: \"nth_value\", frames: FRAMES, offset: true },\n { name: \"lag\", offset: true },\n { name: \"lead\", offset: true },\n // Ranking. These take no source column - the window's `order_by` is their\n // input - but Perspective requires one, so the choice of source is\n // immaterial for them.\n { name: \"row_number\", result_type: \"float\" },\n { name: \"rank\", result_type: \"float\" },\n { name: \"dense_rank\", result_type: \"float\" },\n { name: \"percent_rank\", result_type: \"float\" },\n { name: \"cume_dist\", result_type: \"float\" },\n // `ntile`'s argument is a bucket count rather than a row offset.\n { name: \"ntile\", offset: true, result_type: \"float\" },\n // Perspective's own, with no DuckDB equivalent - the SQL translation\n // synthesizes them from `lag` and `first_value`.\n { name: \"diff\", offset: true, result_type: \"float\" },\n { name: \"rate\", frames: [\"range\"], result_type: \"float\" },\n];\n\n// Arithmetic is undefined for the non-numeric types; ordering and navigation\n// are not.\nconst WINDOW_AGGREGATES_ANY: WindowAggSpec[] = [\n { name: \"count\", frames: FRAMES, result_type: \"float\" },\n { name: \"min\", frames: FRAMES },\n { name: \"max\", frames: FRAMES },\n { name: \"first_value\", frames: FRAMES },\n { name: \"last_value\", frames: FRAMES },\n { name: \"nth_value\", frames: FRAMES, offset: true },\n { name: \"lag\", offset: true },\n { name: \"lead\", offset: true },\n { name: \"row_number\", result_type: \"float\" },\n { name: \"rank\", result_type: \"float\" },\n { name: \"dense_rank\", result_type: \"float\" },\n { name: \"percent_rank\", result_type: \"float\" },\n { name: \"cume_dist\", result_type: \"float\" },\n { name: \"ntile\", offset: true, result_type: \"float\" },\n];\n\nconst FILTER_OPS = [\n \"==\",\n \"!=\",\n \"IS DISTINCT FROM\",\n \"IS NOT DISTINCT FROM\",\n \">=\",\n \"<=\",\n \">\",\n \"<\",\n \"is null\",\n \"is not null\",\n];\n\n// Perspective's canonical string ops (translated to `ILIKE` / `regexp_matches`\n// by the SQL builder), plus DuckDB's raw infix pattern ops spliced verbatim.\nconst STRING_FILTER_OPS = [\n ...FILTER_OPS,\n \"begins with\",\n \"not begins with\",\n \"contains\",\n \"not contains\",\n \"ends with\",\n \"not ends with\",\n \"matches\",\n \"not matches\",\n \"in\",\n \"not in\",\n \"LIKE\",\n \"NOT LIKE\",\n \"ILIKE\",\n \"NOT ILIKE\",\n];\n\n/**\n * Convert a DuckDB `dtype` to a Perspective `ColumnType`.\n */\nfunction duckdbTypeToPsp(name: string): ColumnType {\n name = name.toLowerCase();\n\n if (name.startsWith(\"bool\")) {\n return \"boolean\";\n }\n\n // 32-bit and narrower - `coerce_column` widens these to `Int32`.\n if (\n [\"tinyint\", \"smallint\", \"integer\", \"utinyint\", \"usmallint\"].includes(\n name,\n ) ||\n [\"int8\", \"int16\", \"int32\", \"uint8\", \"uint16\"].includes(name)\n ) {\n return \"integer\";\n }\n\n // Wider than `Int32`, or fractional - all coerce to `Float64`.\n if (\n [\"bigint\", \"hugeint\", \"uhugeint\", \"uinteger\", \"ubigint\"].includes(\n name,\n ) ||\n [\"float\", \"real\", \"double\", \"varint\"].includes(name) ||\n [\"int64\", \"uint32\", \"uint64\", \"float32\", \"float64\"].includes(name) ||\n name.startsWith(\"decimal\") ||\n name.startsWith(\"numeric\")\n ) {\n return \"float\";\n }\n\n if (name.startsWith(\"date\")) {\n return \"date\";\n }\n\n // `timestamp`, `timestamptz`, `timestamp_ns`, and `time`/`timetz`,\n // which coerce to `Timestamp(Millisecond)` rather than to a number.\n if (name.startsWith(\"time\")) {\n return \"datetime\";\n }\n\n // Everything else renders as text: `varchar`, `enum(...)` (which\n // arrives dictionary-encoded), `json`, `uuid`, `blob`, `interval`,\n // and the nested types.\n if (\n !(\n name.startsWith(\"varchar\") ||\n name === \"utf8\" ||\n name.startsWith(\"enum\") ||\n [\"json\", \"uuid\", \"blob\", \"bit\", \"interval\"].includes(name) ||\n name.startsWith(\"struct\") ||\n name.startsWith(\"map\") ||\n name.startsWith(\"union\") ||\n name.endsWith(\"[]\")\n )\n ) {\n // Unknown, not fatal - the column still renders, as text.\n console.warn(`Unknown type '${name}'`);\n }\n\n return \"string\";\n}\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns: true },\n): Promise<{\n rows: any[];\n columns: string[];\n dtypes: string[];\n}>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options?: { columns: false },\n): Promise<any[]>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns?: boolean } = {},\n) {\n query = query.replace(/\\s+/g, \" \").trim();\n try {\n const result = await db.query(query);\n if (options.columns) {\n return {\n rows: result.toArray(),\n columns: result.schema.fields.map((f) => f.name),\n dtypes: result.schema.fields.map((f) => f.type.toString()),\n };\n }\n\n return result.toArray();\n } catch (error) {\n console.error(\"Query error:\", error);\n console.error(\"Query:\", query);\n throw error;\n }\n}\n\n/**\n * An implementation of Perspective's Virtual Server for `@duckdb/duckdb-wasm`.\n */\nexport class DuckDBHandler implements perspective.VirtualServerHandler {\n private db: duckdb.AsyncDuckDBConnection;\n private sqlBuilder: perspective.GenericSQLVirtualServerModel;\n constructor(db: duckdb.AsyncDuckDBConnection, mod?: typeof perspective) {\n if (!mod) {\n if (customElements) {\n const viewer_class: any =\n customElements.get(\"perspective-viewer\");\n if (viewer_class) {\n mod = viewer_class.__wasm_module__;\n } else {\n throw new Error(\"Missing perspective-client.wasm\");\n }\n } else {\n }\n }\n\n this.db = db;\n this.sqlBuilder = new mod!.GenericSQLVirtualServerModel({\n column_separator: \"|\",\n like_escape_clause: \"\\\\\",\n regex_fn: \"regexp_matches\",\n });\n }\n\n getFeatures(): perspective.Features {\n return {\n group_by: true,\n split_by: true,\n sort: true,\n expressions: true,\n view_derivations: true,\n window_aggregates: {\n // `ema` is recursive and has no SQL window translation.\n integer: WINDOW_AGGREGATES,\n float: WINDOW_AGGREGATES,\n string: WINDOW_AGGREGATES_ANY,\n date: WINDOW_AGGREGATES_ANY,\n datetime: WINDOW_AGGREGATES_ANY,\n boolean: WINDOW_AGGREGATES_ANY,\n },\n group_rollup_mode: [\"rollup\", \"flat\", \"total\"],\n split_rollup_mode: [\"flat\", \"rollup\"],\n filter_ops: {\n integer: FILTER_OPS,\n float: FILTER_OPS,\n string: STRING_FILTER_OPS,\n boolean: FILTER_OPS,\n date: FILTER_OPS,\n datetime: FILTER_OPS,\n },\n aggregates: {\n integer: NUMBER_AGGS,\n float: NUMBER_AGGS,\n string: STRING_AGGS,\n boolean: STRING_AGGS,\n date: STRING_AGGS,\n datetime: STRING_AGGS,\n },\n };\n }\n\n async getHostedTables() {\n const query = this.sqlBuilder.getHostedTables();\n const results = await runQuery(this.db, query);\n return results.map((row) => {\n const json = row.toJSON();\n return `${json.database || \"memory\"}.${json.name}`;\n });\n }\n\n async tableSchema(tableId: string, config?: ViewConfig) {\n const query = this.sqlBuilder.tableSchema(tableId);\n const results = await runQuery(this.db, query);\n const schema = {} as Record<string, ColumnType>;\n for (const result of results) {\n const res = result.toJSON();\n const colName = res.column_name;\n if (!colName.startsWith(\"__\")) {\n schema[colName] = duckdbTypeToPsp(\n res.column_type,\n ) as ColumnType;\n }\n }\n\n return schema;\n }\n\n async viewColumnSize(viewId: string, config: ViewConfig) {\n const query = this.sqlBuilder.viewColumnSize(viewId);\n const results = await runQuery(this.db, query);\n const count = Number(Object.values(results[0].toJSON())[0]);\n const gs = config.group_by?.length || 0;\n const is_flat = config.group_rollup_mode === \"flat\";\n return count - (gs === 0 ? 0 : is_flat ? gs : gs + 1);\n }\n\n async tableSize(tableId: string) {\n const query = this.sqlBuilder.tableSize(tableId);\n const results = await runQuery(this.db, query);\n return Number(results[0].toJSON()[\"count_star()\"]);\n }\n\n async tableMakeView(\n tableId: string,\n viewId: string,\n config: ViewConfigUpdate,\n ) {\n // Window order keys need column types for `range` frame emission.\n const schema = Object.keys(config.windows ?? {}).length\n ? await this.tableSchema(tableId)\n : undefined;\n\n const query = this.sqlBuilder.tableMakeView(\n tableId,\n viewId,\n config,\n schema,\n );\n\n await runQuery(this.db, query);\n }\n\n async tableDescribe(\n tableId: string,\n config: ViewConfig,\n ): Promise<TableDescription> {\n let expression_schema = {} as Record<string, ColumnType>;\n const expressions_query = this.sqlBuilder.expressionsDescribe(\n tableId,\n config,\n );\n\n if (expressions_query !== undefined) {\n try {\n expression_schema = await this.describeQuery(expressions_query);\n } catch (error) {\n return await this.attributeExpressionErrors(\n tableId,\n config,\n error,\n );\n }\n }\n\n const schema = Object.keys(config.windows ?? {}).length\n ? await this.tableSchema(tableId)\n : undefined;\n\n const view_query = this.sqlBuilder.tableDescribe(\n tableId,\n config,\n schema,\n );\n\n let view_schema = {} as Record<string, ColumnType>;\n if (view_query !== undefined) {\n try {\n view_schema = await this.describeQuery(view_query);\n } catch (error) {\n return { config_error: errorMessage(error) };\n }\n }\n\n return { expression_schema, view_schema };\n }\n\n /** The planned result columns of one `DESCRIBE` query. */\n private async describeQuery(query: string) {\n const results = await runQuery(this.db, query);\n const schema = {} as Record<string, ColumnType>;\n for (const result of results) {\n const res = result.toJSON();\n if (!res.column_name.startsWith(\"__\")) {\n schema[res.column_name] = duckdbTypeToPsp(\n res.column_type,\n ) as ColumnType;\n }\n }\n\n return schema;\n }\n\n /** Plans each expression on its own to name the ones at fault. */\n private async attributeExpressionErrors(\n tableId: string,\n config: ViewConfig,\n error: unknown,\n ): Promise<TableDescription> {\n const expression_schema = {} as Record<string, ColumnType>;\n const expression_errors = {} as Record<string, ExpressionError>;\n for (const [name, expression] of Object.entries(config.expressions)) {\n const query = this.sqlBuilder.expressionDescribe(\n tableId,\n expression!,\n );\n\n try {\n const results = await runQuery(this.db, query);\n expression_schema[name] = duckdbTypeToPsp(\n results[0].toJSON()[\"column_type\"],\n ) as ColumnType;\n } catch (error) {\n expression_errors[name] = {\n error_message: errorMessage(error),\n line: 0,\n column: 0,\n };\n }\n }\n\n if (Object.keys(expression_errors).length === 0) {\n return { config_error: errorMessage(error) };\n }\n\n return { expression_schema, expression_errors };\n }\n\n async viewMakeTable(\n viewId: string,\n tableId: string,\n config: ViewConfig,\n schema?: Record<string, ColumnType>,\n ) {\n const query = this.sqlBuilder.viewMakeTable(\n viewId,\n tableId,\n config,\n await this.tableSchema(viewId),\n schema,\n );\n\n await runQuery(this.db, query);\n }\n\n async viewDelete(viewId: string) {\n const query = this.sqlBuilder.viewDelete(viewId);\n await runQuery(this.db, query);\n }\n\n async viewGetMinMax(\n viewId: string,\n columnName: string,\n config: ViewConfig,\n ) {\n const query = this.sqlBuilder.viewGetMinMax(viewId, columnName, config);\n const results = await runQuery(this.db, query);\n const row = results[0].toJSON();\n let [min, max] = Object.values(row);\n if (typeof min === \"bigint\") min = Number(min);\n if (typeof max === \"bigint\") max = Number(max);\n return { min: (min ?? null) as Scalar, max: (max ?? null) as Scalar };\n }\n\n async viewGetData(\n viewId: string,\n config: ViewConfig,\n schema: Record<string, ColumnType>,\n viewport: ViewWindow,\n dataSlice: perspective.VirtualDataSlice,\n ) {\n const query = this.sqlBuilder.viewGetData(\n viewId,\n config,\n viewport,\n schema,\n );\n\n const ipc = await this.db.useUnsafe((bindings, conn) =>\n bindings.runQuery(conn, query),\n );\n\n dataSlice.fromArrowIpc(ipc);\n }\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],
5
- "mappings": "AAoCA,IAAMA,EAAc,CAChB,MACA,QACA,YACA,YACA,YACA,MACA,UACA,SACA,UACA,gBACA,WACA,UACA,UACA,OACA,OACA,UACA,YACA,OACA,MACA,MACA,UACA,aACA,UACJ,EAEMC,EAAc,CAChB,QACA,YACA,YACA,QACA,UACA,OACA,YACJ,EAEMC,EAAS,CAAC,OAAQ,QAAS,YAAY,EAEvCC,EAAqC,CACvC,CAAE,KAAM,MAAO,OAAQD,EAAQ,YAAa,OAAQ,EACpD,CAAE,KAAM,MAAO,OAAQA,EAAQ,YAAa,OAAQ,EACpD,CAAE,KAAM,QAAS,OAAQA,EAAQ,YAAa,OAAQ,EACtD,CAAE,KAAM,MAAO,OAAQA,CAAO,EAC9B,CAAE,KAAM,MAAO,OAAQA,CAAO,EAC9B,CAAE,KAAM,UAAW,OAAQA,EAAQ,YAAa,OAAQ,EACxD,CAAE,KAAM,SAAU,OAAQA,EAAQ,YAAa,OAAQ,EAGvD,CAAE,KAAM,cAAe,OAAQA,EAAQ,YAAa,OAAQ,EAC5D,CAAE,KAAM,aAAc,OAAQA,EAAQ,YAAa,OAAQ,EAC3D,CAAE,KAAM,WAAY,OAAQA,EAAQ,YAAa,OAAQ,EACzD,CAAE,KAAM,UAAW,OAAQA,EAAQ,YAAa,OAAQ,EAExD,CAAE,KAAM,cAAe,OAAQA,CAAO,EACtC,CAAE,KAAM,aAAc,OAAQA,CAAO,EACrC,CAAE,KAAM,YAAa,OAAQA,EAAQ,OAAQ,EAAK,EAClD,CAAE,KAAM,MAA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AAM,EAC7BH,CACJ,EAEA,MAAMf,EAAS,KAAK,GAAIE,CAAK,CACjC,CAEA,MAAM,WAAWgB,EAAgB,CAC7B,IAAMhB,EAAQ,KAAK,WAAW,WAAWgB,CAAM,EAC/C,MAAMlB,EAAS,KAAK,GAAIE,CAAK,CACjC,CAEA,MAAM,cACFgB,EACAW,EACAhB,EACF,CACE,IAAMX,EAAQ,KAAK,WAAW,cAAcgB,EAAQW,EAAYhB,CAAM,EAEhEH,GADU,MAAMV,EAAS,KAAK,GAAIE,CAAK,GACzB,CAAC,EAAE,OAAO,EAC1B,CAAC4B,EAAKC,CAAG,EAAI,OAAO,OAAOrB,CAAG,EAClC,OAAI,OAAOoB,GAAQ,WAAUA,EAAM,OAAOA,CAAG,GACzC,OAAOC,GAAQ,WAAUA,EAAM,OAAOA,CAAG,GACtC,CAAE,IAAMD,GAAO,KAAiB,IAAMC,GAAO,IAAgB,CACxE,CAEA,MAAM,YACFb,EACAL,EACAE,EACAiB,EACAC,EACF,CACE,IAAM/B,EAAQ,KAAK,WAAW,YAC1BgB,EACAL,EACAmB,EACAjB,CACJ,EAEMmB,EAAM,MAAM,KAAK,GAAG,UAAU,CAACC,EAAUC,IAC3CD,EAAS,SAASC,EAAMlC,CAAK,CACjC,EAEA+B,EAAU,aAAaC,CAAG,CAC9B,CACJ,EAEA,SAASR,EAAapB,EAAwB,CAC1C,OAAOA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAChE",
4
+ "sourcesContent": ["// \u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n// \u2503 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588 \u2588\u2584 \u2580\u2588\u2588\u2588 \u2588 \u2503\n// \u2503 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2584\u2584\u2584\u2584\u2584 \u2584\u2584\u2584\u2584\u2584\u2588 \u2580\u2580\u2580\u2580\u2580\u2588\u2580\u2580\u2580\u2580\u2580 \u2588 \u2580\u2580\u2580\u2580\u2580\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2584 \u2580\u2588 \u2588 \u2580\u2580\u2580\u2580\u2580 \u2503\n// \u2503 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2580\u2580\u2580\u2580 \u2588\u2580\u2588\u2588\u2580\u2580 \u2584\u2584\u2584\u2584\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2584\u2584\u2584\u2584\u2584\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2584\u2584\u2584\u2584\u2584 \u2503\n// \u2503 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2580\u2588\u2584 \u2588 \u2588\u2588\u2588\u2588\u2588\u2588 \u2588 \u2588\u2588\u2588\u258C\u2590\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2584 \u2588 \u2503\n// \u2523\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u252B\n// \u2503 Copyright (c) 2017, the Perspective Authors. \u2503\n// \u2503 \u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C\u254C \u2503\n// \u2503 This file is part of the Perspective library, distributed under the terms \u2503\n// \u2503 of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). \u2503\n// \u2517\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u251B\n\n/**\n * An implementation of a Perspective Virtual Server for DuckDB.\n *\n * This import is optional, and so must be imported manually from either\n * `@perspective-dev/client/dist/esm/virtual_servers/duckdb.js` or\n * `@perspective-dev/client/src/ts/virtual_servers/duckdb.ts`, it is not\n * exported from the package root `@perspective-dev/client`\n *\n * @module\n */\n\nimport type * as perspective from \"@perspective-dev/client\";\nimport type { ColumnType } from \"@perspective-dev/client/dist/esm/ts-rs/ColumnType.d.ts\";\nimport type { ViewConfig } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts\";\nimport type {\n ExpressionError,\n TableDescription,\n} from \"@perspective-dev/client\";\nimport type { ViewConfigUpdate } from \"@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts\";\nimport type { ViewWindow } from \"@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts\";\nimport type { WindowAggSpec } from \"@perspective-dev/client/dist/esm/ts-rs/WindowAggSpec.d.ts\";\nimport type { Scalar } from \"@perspective-dev/client/dist/esm/ts-rs/Scalar.d.ts\";\nimport type * as duckdb from \"@duckdb/duckdb-wasm\";\n\nconst NUMBER_AGGS = [\n \"sum\",\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"array_agg\",\n \"avg\",\n \"bit_and\",\n \"bit_or\",\n \"bit_xor\",\n \"bitstring_agg\",\n \"bool_and\",\n \"bool_or\",\n \"countif\",\n \"favg\",\n \"fsum\",\n \"geomean\",\n \"kahan_sum\",\n \"last\",\n \"max\",\n \"min\",\n \"product\",\n \"string_agg\",\n \"sumkahan\",\n];\n\nconst STRING_AGGS = [\n \"count\",\n \"any_value\",\n \"arbitrary\",\n \"first\",\n \"countif\",\n \"last\",\n \"string_agg\",\n];\n\nconst FRAMES = [\"rows\", \"range\", \"cumulative\"];\n\nconst WINDOW_AGGREGATES: WindowAggSpec[] = [\n { name: \"sum\", frames: FRAMES, result_type: \"float\" },\n { name: \"avg\", frames: FRAMES, result_type: \"float\" },\n { name: \"count\", frames: FRAMES, result_type: \"float\" },\n { name: \"min\", frames: FRAMES },\n { name: \"max\", frames: FRAMES },\n { name: \"product\", frames: FRAMES, result_type: \"float\" },\n { name: \"median\", frames: FRAMES, result_type: \"float\" },\n // DuckDB spells sample and population variants separately, so both are\n // offered rather than one being picked on the user's behalf.\n { name: \"stddev_samp\", frames: FRAMES, result_type: \"float\" },\n { name: \"stddev_pop\", frames: FRAMES, result_type: \"float\" },\n { name: \"var_samp\", frames: FRAMES, result_type: \"float\" },\n { name: \"var_pop\", frames: FRAMES, result_type: \"float\" },\n // Navigation.\n { name: \"first_value\", frames: FRAMES },\n { name: \"last_value\", frames: FRAMES },\n { name: \"nth_value\", frames: FRAMES, offset: true },\n { name: \"lag\", offset: true },\n { name: \"lead\", offset: true },\n // Ranking. These take no source column - the window's `order_by` is their\n // input - but Perspective requires one, so the choice of source is\n // immaterial for them.\n { name: \"row_number\", result_type: \"float\" },\n { name: \"rank\", result_type: \"float\" },\n { name: \"dense_rank\", result_type: \"float\" },\n { name: \"percent_rank\", result_type: \"float\" },\n { name: \"cume_dist\", result_type: \"float\" },\n // `ntile`'s argument is a bucket count rather than a row offset.\n { name: \"ntile\", offset: true, result_type: \"float\" },\n // Perspective's own, with no DuckDB equivalent - the SQL translation\n // synthesizes them from `lag` and `first_value`.\n { name: \"diff\", offset: true, result_type: \"float\" },\n { name: \"rate\", frames: [\"range\"], result_type: \"float\" },\n];\n\n// Arithmetic is undefined for the non-numeric types; ordering and navigation\n// are not.\nconst WINDOW_AGGREGATES_ANY: WindowAggSpec[] = [\n { name: \"count\", frames: FRAMES, result_type: \"float\" },\n { name: \"min\", frames: FRAMES },\n { name: \"max\", frames: FRAMES },\n { name: \"first_value\", frames: FRAMES },\n { name: \"last_value\", frames: FRAMES },\n { name: \"nth_value\", frames: FRAMES, offset: true },\n { name: \"lag\", offset: true },\n { name: \"lead\", offset: true },\n { name: \"row_number\", result_type: \"float\" },\n { name: \"rank\", result_type: \"float\" },\n { name: \"dense_rank\", result_type: \"float\" },\n { name: \"percent_rank\", result_type: \"float\" },\n { name: \"cume_dist\", result_type: \"float\" },\n { name: \"ntile\", offset: true, result_type: \"float\" },\n];\n\nconst FILTER_OPS = [\n \"==\",\n \"!=\",\n \"IS DISTINCT FROM\",\n \"IS NOT DISTINCT FROM\",\n \">=\",\n \"<=\",\n \">\",\n \"<\",\n \"is null\",\n \"is not null\",\n];\n\n// Perspective's canonical string ops (translated to `ILIKE` / `regexp_matches`\n// by the SQL builder), plus DuckDB's raw infix pattern ops spliced verbatim.\nconst STRING_FILTER_OPS = [\n ...FILTER_OPS,\n \"begins with\",\n \"not begins with\",\n \"contains\",\n \"not contains\",\n \"ends with\",\n \"not ends with\",\n \"matches\",\n \"not matches\",\n \"in\",\n \"not in\",\n \"LIKE\",\n \"NOT LIKE\",\n \"ILIKE\",\n \"NOT ILIKE\",\n];\n\n/**\n * Convert a DuckDB `dtype` to a Perspective `ColumnType`.\n */\nfunction duckdbTypeToPsp(name: string): ColumnType {\n name = name.toLowerCase();\n\n if (name.startsWith(\"bool\")) {\n return \"boolean\";\n }\n\n // 32-bit and narrower - `coerce_column` widens these to `Int32`.\n if (\n [\"tinyint\", \"smallint\", \"integer\", \"utinyint\", \"usmallint\"].includes(\n name,\n ) ||\n [\"int8\", \"int16\", \"int32\", \"uint8\", \"uint16\"].includes(name)\n ) {\n return \"integer\";\n }\n\n // Wider than `Int32`, or fractional - all coerce to `Float64`.\n if (\n [\"bigint\", \"hugeint\", \"uhugeint\", \"uinteger\", \"ubigint\"].includes(\n name,\n ) ||\n [\"float\", \"real\", \"double\", \"varint\", \"bignum\"].includes(name) ||\n [\"int64\", \"uint32\", \"uint64\", \"float32\", \"float64\"].includes(name) ||\n name.startsWith(\"decimal\") ||\n name.startsWith(\"numeric\")\n ) {\n return \"float\";\n }\n\n if (name.startsWith(\"date\")) {\n return \"date\";\n }\n\n // `timestamp`, `timestamptz`, `timestamp_ns`, and `time`/`timetz`,\n // which coerce to `Timestamp(Millisecond)` rather than to a number.\n if (name.startsWith(\"time\")) {\n return \"datetime\";\n }\n\n // Everything else renders as text: `varchar`, `enum(...)` (which\n // arrives dictionary-encoded), `json`, `uuid`, `blob`, `interval`,\n // and the nested types.\n if (\n !(\n name.startsWith(\"varchar\") ||\n name === \"utf8\" ||\n name.startsWith(\"enum\") ||\n [\"json\", \"uuid\", \"blob\", \"bit\", \"interval\"].includes(name) ||\n name.startsWith(\"struct\") ||\n name.startsWith(\"map\") ||\n name.startsWith(\"union\") ||\n name.endsWith(\"[]\")\n )\n ) {\n // Unknown, not fatal - the column still renders, as text.\n console.warn(`Unknown type '${name}'`);\n }\n\n return \"string\";\n}\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns: true },\n): Promise<{\n rows: any[];\n columns: string[];\n dtypes: string[];\n}>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options?: { columns: false },\n): Promise<any[]>;\n\nasync function runQuery(\n db: duckdb.AsyncDuckDBConnection,\n query: string,\n options: { columns?: boolean } = {},\n) {\n query = query.replace(/\\s+/g, \" \").trim();\n try {\n const result = await db.query(query);\n if (options.columns) {\n return {\n rows: result.toArray(),\n columns: result.schema.fields.map((f) => f.name),\n dtypes: result.schema.fields.map((f) => f.type.toString()),\n };\n }\n\n return result.toArray();\n } catch (error) {\n console.error(\"Query error:\", error);\n console.error(\"Query:\", query);\n throw error;\n }\n}\n\n/**\n * An implementation of Perspective's Virtual Server for `@duckdb/duckdb-wasm`.\n */\nexport class DuckDBHandler implements perspective.VirtualServerHandler {\n private db: duckdb.AsyncDuckDBConnection;\n private sqlBuilder: perspective.GenericSQLVirtualServerModel;\n constructor(db: duckdb.AsyncDuckDBConnection, mod?: typeof perspective) {\n if (!mod) {\n if (customElements) {\n const viewer_class: any =\n customElements.get(\"perspective-viewer\");\n if (viewer_class) {\n mod = viewer_class.__wasm_module__;\n } else {\n throw new Error(\"Missing perspective-client.wasm\");\n }\n } else {\n }\n }\n\n this.db = db;\n this.sqlBuilder = new mod!.GenericSQLVirtualServerModel({\n column_separator: \"|\",\n like_escape_clause: \"\\\\\",\n regex_fn: \"regexp_matches\",\n });\n }\n\n getFeatures(): perspective.Features {\n return {\n group_by: true,\n split_by: true,\n sort: true,\n expressions: true,\n view_derivations: true,\n window_aggregates: {\n // `ema` is recursive and has no SQL window translation.\n integer: WINDOW_AGGREGATES,\n float: WINDOW_AGGREGATES,\n string: WINDOW_AGGREGATES_ANY,\n date: WINDOW_AGGREGATES_ANY,\n datetime: WINDOW_AGGREGATES_ANY,\n boolean: WINDOW_AGGREGATES_ANY,\n },\n group_rollup_mode: [\"rollup\", \"flat\", \"total\"],\n split_rollup_mode: [\"flat\", \"rollup\"],\n filter_ops: {\n integer: FILTER_OPS,\n float: FILTER_OPS,\n string: STRING_FILTER_OPS,\n boolean: FILTER_OPS,\n date: FILTER_OPS,\n datetime: FILTER_OPS,\n },\n aggregates: {\n integer: NUMBER_AGGS,\n float: NUMBER_AGGS,\n string: STRING_AGGS,\n boolean: STRING_AGGS,\n date: STRING_AGGS,\n datetime: STRING_AGGS,\n },\n };\n }\n\n async getHostedTables() {\n const query = this.sqlBuilder.getHostedTables();\n const results = await runQuery(this.db, query);\n return results.map((row) => {\n const json = row.toJSON();\n return `${json.database || \"memory\"}.${json.name}`;\n });\n }\n\n async tableSchema(tableId: string, config?: ViewConfig) {\n const query = this.sqlBuilder.tableSchema(tableId);\n const results = await runQuery(this.db, query);\n const schema = {} as Record<string, ColumnType>;\n for (const result of results) {\n const res = result.toJSON();\n const colName = res.column_name;\n if (!colName.startsWith(\"__\")) {\n schema[colName] = duckdbTypeToPsp(\n res.column_type,\n ) as ColumnType;\n }\n }\n\n return schema;\n }\n\n async viewColumnSize(viewId: string, config: ViewConfig) {\n const query = this.sqlBuilder.viewColumnSize(viewId);\n const results = await runQuery(this.db, query);\n const count = Number(Object.values(results[0].toJSON())[0]);\n const gs = config.group_by?.length || 0;\n const is_flat = config.group_rollup_mode === \"flat\";\n return count - (gs === 0 ? 0 : is_flat ? gs : gs + 1);\n }\n\n async tableSize(tableId: string) {\n const query = this.sqlBuilder.tableSize(tableId);\n const results = await runQuery(this.db, query);\n return Number(results[0].toJSON()[\"count_star()\"]);\n }\n\n async tableMakeView(\n tableId: string,\n viewId: string,\n config: ViewConfigUpdate,\n ) {\n // Window order keys need column types for `range` frame emission.\n const schema = Object.keys(config.windows ?? {}).length\n ? await this.tableSchema(tableId)\n : undefined;\n\n const query = this.sqlBuilder.tableMakeView(\n tableId,\n viewId,\n config,\n schema,\n );\n\n await runQuery(this.db, query);\n }\n\n async tableDescribe(\n tableId: string,\n config: ViewConfig,\n ): Promise<TableDescription> {\n let expression_schema = {} as Record<string, ColumnType>;\n const expressions_query = this.sqlBuilder.expressionsDescribe(\n tableId,\n config,\n );\n\n if (expressions_query !== undefined) {\n try {\n expression_schema = await this.describeQuery(expressions_query);\n } catch (error) {\n return await this.attributeExpressionErrors(\n tableId,\n config,\n error,\n );\n }\n }\n\n const schema = Object.keys(config.windows ?? {}).length\n ? await this.tableSchema(tableId)\n : undefined;\n\n const view_query = this.sqlBuilder.tableDescribe(\n tableId,\n config,\n schema,\n );\n\n let view_schema = {} as Record<string, ColumnType>;\n if (view_query !== undefined) {\n try {\n view_schema = await this.describeQuery(view_query);\n } catch (error) {\n return { config_error: errorMessage(error) };\n }\n }\n\n return { expression_schema, view_schema };\n }\n\n /** The planned result columns of one `DESCRIBE` query. */\n private async describeQuery(query: string) {\n const results = await runQuery(this.db, query);\n const schema = {} as Record<string, ColumnType>;\n for (const result of results) {\n const res = result.toJSON();\n if (!res.column_name.startsWith(\"__\")) {\n schema[res.column_name] = duckdbTypeToPsp(\n res.column_type,\n ) as ColumnType;\n }\n }\n\n return schema;\n }\n\n /** Plans each expression on its own to name the ones at fault. */\n private async attributeExpressionErrors(\n tableId: string,\n config: ViewConfig,\n error: unknown,\n ): Promise<TableDescription> {\n const expression_schema = {} as Record<string, ColumnType>;\n const expression_errors = {} as Record<string, ExpressionError>;\n for (const [name, expression] of Object.entries(config.expressions)) {\n const query = this.sqlBuilder.expressionDescribe(\n tableId,\n expression!,\n );\n\n try {\n const results = await runQuery(this.db, query);\n expression_schema[name] = duckdbTypeToPsp(\n results[0].toJSON()[\"column_type\"],\n ) as ColumnType;\n } catch (error) {\n expression_errors[name] = {\n error_message: errorMessage(error),\n line: 0,\n column: 0,\n };\n }\n }\n\n if (Object.keys(expression_errors).length === 0) {\n return { config_error: errorMessage(error) };\n }\n\n return { expression_schema, expression_errors };\n }\n\n async viewMakeTable(\n viewId: string,\n tableId: string,\n config: ViewConfig,\n schema?: Record<string, ColumnType>,\n ) {\n const query = this.sqlBuilder.viewMakeTable(\n viewId,\n tableId,\n config,\n await this.tableSchema(viewId),\n schema,\n );\n\n await runQuery(this.db, query);\n }\n\n async viewDelete(viewId: string) {\n const query = this.sqlBuilder.viewDelete(viewId);\n await runQuery(this.db, query);\n }\n\n async viewGetMinMax(\n viewId: string,\n columnName: string,\n config: ViewConfig,\n ) {\n const query = this.sqlBuilder.viewGetMinMax(viewId, columnName, config);\n const results = await runQuery(this.db, query);\n const row = results[0].toJSON();\n let [min, max] = Object.values(row);\n if (typeof min === \"bigint\") min = Number(min);\n if (typeof max === \"bigint\") max = Number(max);\n return { min: (min ?? null) as Scalar, max: (max ?? null) as Scalar };\n }\n\n async viewGetData(\n viewId: string,\n config: ViewConfig,\n schema: Record<string, ColumnType>,\n viewport: ViewWindow,\n dataSlice: perspective.VirtualDataSlice,\n ) {\n const query = this.sqlBuilder.viewGetData(\n viewId,\n config,\n viewport,\n schema,\n );\n\n const ipc = await this.db.useUnsafe((bindings, conn) =>\n bindings.runQuery(conn, query),\n );\n\n dataSlice.fromArrowIpc(ipc);\n }\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],
5
+ "mappings": "AAoCA,IAAMA,EAAc,CAChB,MACA,QACA,YACA,YACA,YACA,MACA,UACA,SACA,UACA,gBACA,WACA,UACA,UACA,OACA,OACA,UACA,YACA,OACA,MACA,MACA,UACA,aACA,UACJ,EAEMC,EAAc,CAChB,QACA,YACA,YACA,QACA,UACA,OACA,YACJ,EAEMC,EAAS,CAAC,OAAQ,QAA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CAAG,GACtC,CAAE,IAAMD,GAAO,KAAiB,IAAMC,GAAO,IAAgB,CACxE,CAEA,MAAM,YACFb,EACAL,EACAE,EACAiB,EACAC,EACF,CACE,IAAM/B,EAAQ,KAAK,WAAW,YAC1BgB,EACAL,EACAmB,EACAjB,CACJ,EAEMmB,EAAM,MAAM,KAAK,GAAG,UAAU,CAACC,EAAUC,IAC3CD,EAAS,SAASC,EAAMlC,CAAK,CACjC,EAEA+B,EAAU,aAAaC,CAAG,CAC9B,CACJ,EAEA,SAASR,EAAapB,EAAwB,CAC1C,OAAOA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAChE",
6
6
  "names": ["NUMBER_AGGS", "STRING_AGGS", "FRAMES", "WINDOW_AGGREGATES", "WINDOW_AGGREGATES_ANY", "FILTER_OPS", "STRING_FILTER_OPS", "duckdbTypeToPsp", "name", "runQuery", "db", "query", "options", "result", "f", "error", "DuckDBHandler", "mod", "viewer_class", "row", "json", "tableId", "config", "results", "schema", "res", "colName", "viewId", "count", "gs", "is_flat", "expression_schema", "expressions_query", "view_query", "view_schema", "errorMessage", "expression_errors", "expression", "columnName", "min", "max", "viewport", "dataSlice", "ipc", "bindings", "conn"]
7
7
  }
@@ -1 +1,2 @@
1
+ export declare function extract(input: any): Promise<Uint8Array<ArrayBuffer>>;
1
2
  export declare function load_wasm_stage_0(wasm: ArrayBuffer | Response | WebAssembly.Module | (() => Promise<ArrayBuffer>)): Promise<Uint8Array>;
@@ -1087,7 +1087,7 @@ export interface InitOutput {
1087
1087
  readonly virtualserver_new: (a: number, b: number) => void;
1088
1088
  readonly __wasm_bindgen_func_elem_1688: (a: number, b: number) => void;
1089
1089
  readonly __wasm_bindgen_func_elem_4639: (a: number, b: number) => void;
1090
- readonly __wasm_bindgen_func_elem_13017: (a: number, b: number, c: number, d: number) => void;
1090
+ readonly __wasm_bindgen_func_elem_13018: (a: number, b: number, c: number, d: number) => void;
1091
1091
  readonly __wasm_bindgen_func_elem_4641: (a: number, b: number, c: number) => void;
1092
1092
  readonly __wasm_bindgen_func_elem_2057: (a: number, b: number) => number;
1093
1093
  readonly __wasm_bindgen_func_elem_2058: (a: number, b: number) => void;
@@ -2186,7 +2186,7 @@ function __wbg_get_imports() {
2186
2186
  const a = state0.a;
2187
2187
  state0.a = 0;
2188
2188
  try {
2189
- return __wasm_bindgen_func_elem_13017(a, state0.b, arg0, arg1);
2189
+ return __wasm_bindgen_func_elem_13018(a, state0.b, arg0, arg1);
2190
2190
  } finally {
2191
2191
  state0.a = a;
2192
2192
  }
@@ -2261,7 +2261,7 @@ function __wbg_get_imports() {
2261
2261
  const ret = Promise.resolve(getObject(arg0));
2262
2262
  return addHeapObject(ret);
2263
2263
  },
2264
- __wbg_run_56500aec144102b2: function() { return handleError(function (arg0, arg1) {
2264
+ __wbg_run_312def04b15a0d44: function() { return handleError(function (arg0, arg1) {
2265
2265
  const ret = getObject(arg0).run(getObject(arg1));
2266
2266
  return addHeapObject(ret);
2267
2267
  }, arguments); },
@@ -2453,8 +2453,8 @@ function __wasm_bindgen_func_elem_4641(arg0, arg1, arg2) {
2453
2453
  wasm.__wasm_bindgen_func_elem_4641(arg0, arg1, addHeapObject(arg2));
2454
2454
  }
2455
2455
 
2456
- function __wasm_bindgen_func_elem_13017(arg0, arg1, arg2, arg3) {
2457
- wasm.__wasm_bindgen_func_elem_13017(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2456
+ function __wasm_bindgen_func_elem_13018(arg0, arg1, arg2, arg3) {
2457
+ wasm.__wasm_bindgen_func_elem_13018(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
2458
2458
  }
2459
2459
 
2460
2460
  const ClientFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -101,7 +101,7 @@ export const virtualserver_handleRequest: (a: number, b: number, c: number) => n
101
101
  export const virtualserver_new: (a: number, b: number) => void;
102
102
  export const __wasm_bindgen_func_elem_1688: (a: number, b: number) => void;
103
103
  export const __wasm_bindgen_func_elem_4639: (a: number, b: number) => void;
104
- export const __wasm_bindgen_func_elem_13017: (a: number, b: number, c: number, d: number) => void;
104
+ export const __wasm_bindgen_func_elem_13018: (a: number, b: number, c: number, d: number) => void;
105
105
  export const __wasm_bindgen_func_elem_4641: (a: number, b: number, c: number) => void;
106
106
  export const __wasm_bindgen_func_elem_2057: (a: number, b: number) => number;
107
107
  export const __wasm_bindgen_func_elem_2058: (a: number, b: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perspective-dev/client",
3
- "version": "5.6.0",
3
+ "version": "5.6.1",
4
4
  "description": "Streaming query engine for data grids, pivot tables and charts over large, real-time datasets — WebAssembly in the browser, native in Node.js, or remote over WebSocket.",
5
5
  "keywords": [
6
6
  "perspective",
@@ -68,15 +68,14 @@
68
68
  "access": "public"
69
69
  },
70
70
  "dependencies": {
71
- "@perspective-dev/server": "^5.6.0",
72
- "pro_self_extracting_wasm": "0.0.9",
71
+ "@perspective-dev/server": "^5.6.1",
73
72
  "stoppable": "=1.1.0",
74
73
  "ws": "^8.17.0"
75
74
  },
76
75
  "devDependencies": {
77
- "@perspective-dev/esbuild-plugin": "^5.6.0",
78
- "@perspective-dev/metadata": "^5.6.0",
79
- "@perspective-dev/test": "^5.6.0",
76
+ "@perspective-dev/esbuild-plugin": "^5.6.1",
77
+ "@perspective-dev/metadata": "^5.6.1",
78
+ "@perspective-dev/test": "^5.6.1",
80
79
  "@clickhouse/client-web": "^1.12.0",
81
80
  "@duckdb/duckdb-wasm": "1.33.1-dev18.0",
82
81
  "@playwright/experimental-ct-react": "=1.62.0",
@@ -88,6 +87,7 @@
88
87
  "superstore-arrow": "3.2.0",
89
88
  "lodash": "^4.17.20",
90
89
  "moment": "^2.30.1",
90
+ "pro_self_extracting_wasm": "0.0.10",
91
91
  "typedoc": "^0.28.7",
92
92
  "typescript": ">=5 <6",
93
93
  "web-worker": "1.4.1",
@@ -185,7 +185,7 @@ function duckdbTypeToPsp(name: string): ColumnType {
185
185
  ["bigint", "hugeint", "uhugeint", "uinteger", "ubigint"].includes(
186
186
  name,
187
187
  ) ||
188
- ["float", "real", "double", "varint"].includes(name) ||
188
+ ["float", "real", "double", "varint", "bignum"].includes(name) ||
189
189
  ["int64", "uint32", "uint64", "float32", "float64"].includes(name) ||
190
190
  name.startsWith("decimal") ||
191
191
  name.startsWith("numeric")
@@ -10,8 +10,44 @@
10
10
  // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11
11
  // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
12
 
13
- // @ts-ignore
14
- import { extract } from "pro_self_extracting_wasm";
13
+ type ModType = {
14
+ resize: (x: number) => number;
15
+ memory: WebAssembly.Memory;
16
+ compile: (x: number, y: number) => number;
17
+ };
18
+
19
+ export async function extract(input: any) {
20
+ let bin: WebAssembly.WebAssemblyInstantiatedSource;
21
+ if (input instanceof Response) {
22
+ bin = await WebAssembly.instantiateStreaming(input);
23
+ } else if (typeof input === "string") {
24
+ bin = await WebAssembly.instantiateStreaming(fetch(input));
25
+ } else if (input instanceof ArrayBuffer) {
26
+ bin = await WebAssembly.instantiate(input);
27
+ } else {
28
+ bin = input;
29
+ }
30
+
31
+ const inst = bin.instance.exports as ModType;
32
+ const [payload] = WebAssembly.Module.customSections(
33
+ bin.module,
34
+ "psp-runtime",
35
+ );
36
+
37
+ const [raw_length_view] = WebAssembly.Module.customSections(
38
+ bin.module,
39
+ "psp-len",
40
+ );
41
+
42
+ const raw_length = new DataView(raw_length_view).getUint32(0, true);
43
+ const ptr = inst.resize(payload.byteLength);
44
+ new Uint8Array(inst.memory.buffer).set(new Uint8Array(payload), ptr);
45
+ const offset = inst.compile(payload.byteLength, raw_length);
46
+ return new Uint8Array(inst.memory.buffer).slice(
47
+ offset,
48
+ raw_length + offset,
49
+ );
50
+ }
15
51
 
16
52
  if (typeof WebAssembly === "undefined") {
17
53
  throw new Error("WebAssembly not supported.");
@@ -23,27 +59,6 @@ interface Module extends WebAssembly.Exports {
23
59
  memory: WebAssembly.Memory;
24
60
  }
25
61
 
26
- // Perform a silly dance to deal with the different ways webpack and esbuild
27
- // load binary, as this may either be an `ArrayBuffer` or `URL` depending
28
- // on whether `inline` option was specified to `perspective-esbuild-plugin`.
29
- async function compile(
30
- buffer: ArrayBuffer | Response | WebAssembly.Module | WebAssembly.Exports,
31
- ): Promise<Module> {
32
- if (buffer instanceof Response) {
33
- return (await WebAssembly.instantiateStreaming(buffer)).instance
34
- .exports as Module;
35
- } else if (buffer instanceof WebAssembly.Module) {
36
- return (await WebAssembly.instantiate(buffer)).exports as Module;
37
- } else if (buffer instanceof WebAssembly.Instance) {
38
- return buffer.exports as Module;
39
- } else if (buffer instanceof ArrayBuffer) {
40
- return (await WebAssembly.instantiate(buffer as BufferSource)).instance
41
- .exports as Module;
42
- } else {
43
- return buffer as Module;
44
- }
45
- }
46
-
47
62
  export async function load_wasm_stage_0(
48
63
  wasm:
49
64
  | ArrayBuffer
@@ -55,6 +70,10 @@ export async function load_wasm_stage_0(
55
70
  wasm = await wasm();
56
71
  }
57
72
 
73
+ if (wasm instanceof Promise) {
74
+ wasm = await wasm;
75
+ }
76
+
58
77
  try {
59
78
  return await extract(wasm as ArrayBuffer);
60
79
  } catch (e) {