@altimateai/extension-components 0.0.1-beta.2 → 0.0.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +52 -19
- package/dist/index.js +36 -36
- package/dist/mockServiceWorker.js +102 -107
- package/package.json +33 -33
- package/readme.md +11 -0
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ interface PreconfiguredNotebookItem {
|
|
|
45
45
|
interface NotebookCellEvent {
|
|
46
46
|
cellId: string;
|
|
47
47
|
notebook: string;
|
|
48
|
-
result?:
|
|
48
|
+
result?: Record<string, unknown>;
|
|
49
49
|
event: "add" | "update" | "delete";
|
|
50
50
|
fragment?: string;
|
|
51
51
|
languageId: string;
|
|
@@ -93,16 +93,22 @@ interface ConnectionSettings {
|
|
|
93
93
|
}
|
|
94
94
|
interface RawKernelType {
|
|
95
95
|
realKernel: KernelConnection;
|
|
96
|
-
socket:
|
|
96
|
+
socket: WebSocket;
|
|
97
97
|
kernelProcess: {
|
|
98
98
|
connection: ConnectionSettings;
|
|
99
99
|
pid: number;
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
interface WidgetPayload {
|
|
104
|
+
[key: string]: unknown;
|
|
105
|
+
}
|
|
103
106
|
interface IPyWidgetMessage {
|
|
104
107
|
type: string;
|
|
105
|
-
payload:
|
|
108
|
+
payload: WidgetPayload;
|
|
109
|
+
}
|
|
110
|
+
interface NotebookContext {
|
|
111
|
+
[key: string]: unknown;
|
|
106
112
|
}
|
|
107
113
|
declare class NotebookKernelClient implements Disposable {
|
|
108
114
|
private executionInfrastructure;
|
|
@@ -125,7 +131,7 @@ declare class NotebookKernelClient implements Disposable {
|
|
|
125
131
|
private outputsAreSpecificToAWidget;
|
|
126
132
|
private versions?;
|
|
127
133
|
constructor(notebookPath: string, executionInfrastructure: DBTCommandExecutionInfrastructure, notebookDependencies: NotebookDependencies, dbtTerminal: DBTTerminal);
|
|
128
|
-
isInitialized(): Promise<
|
|
134
|
+
isInitialized(): Promise<boolean>;
|
|
129
135
|
dispose(): Promise<void>;
|
|
130
136
|
get jupyterPackagesVersions(): Record<string, string> | undefined;
|
|
131
137
|
private getDependenciesVersion;
|
|
@@ -134,8 +140,8 @@ declare class NotebookKernelClient implements Disposable {
|
|
|
134
140
|
onKernelSocketResponse(payload: {
|
|
135
141
|
id: string;
|
|
136
142
|
}): void;
|
|
137
|
-
storeContext(context:
|
|
138
|
-
storeDataInKernel(cellId: string, data:
|
|
143
|
+
storeContext(context: NotebookContext): Promise<void>;
|
|
144
|
+
storeDataInKernel(cellId: string, data: unknown): Promise<boolean>;
|
|
139
145
|
registerCommTarget(payload: string): Promise<void>;
|
|
140
146
|
getPythonCodeByType(type: string, cellId: string): Promise<string>;
|
|
141
147
|
executePython(code: string, cell: NotebookCell, onOutput: (output: NotebookCellOutput) => void): Promise<NotebookCellOutput[] | undefined>;
|
|
@@ -163,6 +169,25 @@ declare class ClientMapper {
|
|
|
163
169
|
getNotebookClient(notebookUri: Uri): Promise<NotebookKernelClient>;
|
|
164
170
|
}
|
|
165
171
|
|
|
172
|
+
interface ModelTestArgs {
|
|
173
|
+
model: string;
|
|
174
|
+
tests?: string[];
|
|
175
|
+
}
|
|
176
|
+
interface DbtSourceYamlArgs {
|
|
177
|
+
source: string;
|
|
178
|
+
schema?: string;
|
|
179
|
+
database?: string;
|
|
180
|
+
}
|
|
181
|
+
interface DbtModelArgs {
|
|
182
|
+
model: string;
|
|
183
|
+
schema?: string;
|
|
184
|
+
database?: string;
|
|
185
|
+
description?: string;
|
|
186
|
+
}
|
|
187
|
+
interface ExposureArgs {
|
|
188
|
+
connection: string;
|
|
189
|
+
project?: string;
|
|
190
|
+
}
|
|
166
191
|
declare class DatapilotNotebookController implements Disposable {
|
|
167
192
|
private clientMapper;
|
|
168
193
|
private queryManifestService;
|
|
@@ -180,13 +205,13 @@ declare class DatapilotNotebookController implements Disposable {
|
|
|
180
205
|
private readonly controller;
|
|
181
206
|
constructor(clientMapper: ClientMapper, queryManifestService: QueryManifestService, telemetry: TelemetryService, dbtTerminal: DBTTerminal, notebookDependencies: NotebookDependencies, altimate: AltimateRequest);
|
|
182
207
|
private getNotebookByTemplate;
|
|
183
|
-
modelTestSuggestions(args:
|
|
184
|
-
generateDbtSourceYaml(args:
|
|
185
|
-
generateDbtDbtModelSql(args:
|
|
186
|
-
generateDbtDbtModelYaml(args:
|
|
187
|
-
generateDbtDbtModelCTE(args:
|
|
188
|
-
extractExposuresFromMetabase(args:
|
|
189
|
-
extractExposuresFromTableau(args:
|
|
208
|
+
modelTestSuggestions(args: ModelTestArgs): Promise<void>;
|
|
209
|
+
generateDbtSourceYaml(args: DbtSourceYamlArgs): Promise<void>;
|
|
210
|
+
generateDbtDbtModelSql(args: DbtModelArgs): Promise<void>;
|
|
211
|
+
generateDbtDbtModelYaml(args: DbtModelArgs): Promise<void>;
|
|
212
|
+
generateDbtDbtModelCTE(args: DbtModelArgs): Promise<void>;
|
|
213
|
+
extractExposuresFromMetabase(args: ExposureArgs): Promise<void>;
|
|
214
|
+
extractExposuresFromTableau(args: ExposureArgs): Promise<void>;
|
|
190
215
|
private getFileName;
|
|
191
216
|
createNotebook(args: OpenNotebookRequest | undefined): Promise<void>;
|
|
192
217
|
private sendMessageToPreloadScript;
|
|
@@ -269,27 +294,35 @@ interface DBColumn {
|
|
|
269
294
|
column: string;
|
|
270
295
|
dtype: string;
|
|
271
296
|
}
|
|
272
|
-
interface ColumnConfig {
|
|
297
|
+
interface ColumnConfig$1 {
|
|
273
298
|
name: string;
|
|
274
299
|
tests: string[];
|
|
275
|
-
|
|
300
|
+
description?: string;
|
|
301
|
+
[key: string]: string | string[] | undefined;
|
|
276
302
|
}
|
|
277
303
|
interface Model {
|
|
278
304
|
name: string;
|
|
279
|
-
columns: ColumnConfig[];
|
|
280
|
-
tests?:
|
|
305
|
+
columns: ColumnConfig$1[];
|
|
306
|
+
tests?: Array<{
|
|
307
|
+
[key: string]: unknown;
|
|
308
|
+
}>;
|
|
281
309
|
}
|
|
282
310
|
interface DbtConfig {
|
|
283
311
|
[key: string]: Model[];
|
|
284
312
|
}
|
|
285
313
|
type QueryFn = (query: string) => Promise<ExecuteSQLResult | undefined>;
|
|
286
314
|
|
|
315
|
+
interface ColumnConfig {
|
|
316
|
+
tests?: string[];
|
|
317
|
+
description?: string;
|
|
318
|
+
[key: string]: unknown;
|
|
319
|
+
}
|
|
287
320
|
interface Props {
|
|
288
321
|
tableRelation: string;
|
|
289
322
|
sample?: boolean;
|
|
290
323
|
limit?: number;
|
|
291
324
|
resourceType?: string;
|
|
292
|
-
columnConfig?: Record<string,
|
|
325
|
+
columnConfig?: Record<string, ColumnConfig>;
|
|
293
326
|
excludeTypes?: string[];
|
|
294
327
|
excludeCols?: string[];
|
|
295
328
|
tests?: ("uniqueness" | "accepted_values" | "range" | "string_length" | "recency")[];
|
|
@@ -298,7 +331,7 @@ interface Props {
|
|
|
298
331
|
rangeStddevs?: number;
|
|
299
332
|
stringLengthStddevs?: number;
|
|
300
333
|
recencyStddevs?: number;
|
|
301
|
-
dbtConfig?:
|
|
334
|
+
dbtConfig?: DbtConfig;
|
|
302
335
|
returnObject?: boolean;
|
|
303
336
|
columnsInRelation: DBColumn[];
|
|
304
337
|
adapter: string;
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vscode"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vscode"),h=require("@extension"),se=require("python-bridge"),le=require("fs"),X=require("@jupyterlab/services");class ce{_disposables=[];dispose(){this._disposables.forEach(e=>e.dispose())}provideCellStatusBarItems(e){if(e.document.languageId!=="jinja-sql")return;const t=new l.NotebookCellStatusBarItem("$(globe) Profile your query",l.NotebookCellStatusBarAlignment.Left);return t.command="dbtPowerUser.datapilotProfileYourQuery",t.tooltip="Profile your query",[]}}const de=["python","sql","jinja-sql"],ue="jinja-sql",re=".notebook",ie="datapilot",O="datapilot-notebook";var pe=Object.defineProperty,he=Object.getOwnPropertyDescriptor,me=(n,e,t,o)=>{for(var s=o>1?void 0:o?he(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&pe(e,t,s),s};exports.NotebookService=class{constructor(e){this.notebookKernel=e,this.disposables.push(this.notebookKernel.onNotebookCellChangeEvent(t=>{this.onNotebookCellChanged(t)}))}disposables=[];cellByNotebookAutocompleteMap=new Map;dispose(){for(;this.disposables.length;){const e=this.disposables.pop();e&&e.dispose()}}getCellByNotebookAutocompleteMap(){return this.cellByNotebookAutocompleteMap}onNotebookCellChanged(e){if(!e.fragment)return;const t={cellId:e.cellId,fragment:e.fragment,languageId:e.languageId},o=this.cellByNotebookAutocompleteMap.get(e.notebook)||[];switch(e.event){case"add":case"update":this.cellByNotebookAutocompleteMap.set(e.notebook,[...o.filter(s=>s.cellId!==e.cellId),t]);break;case"delete":this.cellByNotebookAutocompleteMap.set(e.notebook,o.filter(s=>s.cellId!==e.cellId));break}}};exports.NotebookService=me([h.provideSingleton(exports.NotebookService)],exports.NotebookService);var W=(n=>(n.error="application/vnd.code.notebook.error",n.stderr="application/vnd.code.notebook.stderr",n.stdout="application/vnd.code.notebook.stdout",n))(W||{});const ge=["text/plain","text/markdown","application/vnd.code.notebook.stderr","application/vnd.code.notebook.stdout"],Z=["application/vnd.*","application/vdom.*","application/geo+json","application/x-nteract-model-debug+json","text/html","application/javascript","image/gif","text/latex","text/markdown","image/png","image/svg+xml","image/jpeg","application/json","text/plain"],M=new Map;M.set("display_data",z);M.set("error",Ce);M.set("execute_result",z);M.set("stream",Ne);M.set("update_display_data",z);function G(n){const e=M.get(n.output_type);let t;return e?t=e(n):(console.warn(`Unable to translate cell from ${n.output_type} to NotebookCellData for VS Code.`),t=z(n)),t}function Q(n){const e={outputType:n.output_type};switch(n.transient&&(e.transient=n.transient),n.output_type){case"display_data":case"execute_result":case"update_display_data":{e.executionCount=n.execution_count,e.metadata=n.metadata?JSON.parse(JSON.stringify(n.metadata)):{};break}}return e}function z(n){const e=Q(n);("image/svg+xml"in n.data||"image/png"in n.data)&&(e.__displayOpenPlotIcon=!0);const t=[];if(n.data)for(const o in n.data)t.push(be(o,n.data[o]));return new l.NotebookCellOutput(fe(t),e)}function fe(n){return n.sort((e,t)=>{const o=(i,a)=>(i.endsWith(".*")&&(i=i.substr(0,i.indexOf(".*"))),a.startsWith(i));let s=Z.findIndex(i=>o(i,e.mime)),r=Z.findIndex(i=>o(i,t.mime));return ee(e)&&(s=-1),ee(t)&&(r=-1),s=s===-1?100:s,r=r===-1?100:r,s-r})}function ee(n){if(n.mime.startsWith("application/vnd."))try{return new TextDecoder().decode(n.data).length===0}catch{console.error(`Failed to decode ${n.mime}`,n.data)}return!1}function be(n,e){if(!e)return l.NotebookCellOutputItem.text("",n);try{if((n.startsWith("text/")||ge.includes(n))&&(Array.isArray(e)||typeof e=="string")){const t=Array.isArray(e)?B(e):e;return l.NotebookCellOutputItem.text(t,n)}else return n.startsWith("image/")&&typeof e=="string"&&n!=="image/svg+xml"?new l.NotebookCellOutputItem(ye(e),n):typeof e=="object"&&e!==null&&!Array.isArray(e)?l.NotebookCellOutputItem.text(JSON.stringify(e),n):(e=Array.isArray(e)?B(e):e,l.NotebookCellOutputItem.text(e,n))}catch(t){return console.error(`Failed to convert ${n} output to a buffer ${typeof e}, ${e}`,t),l.NotebookCellOutputItem.text("")}}function ye(n){return typeof Buffer<"u"&&typeof Buffer.from=="function"?Buffer.from(n,"base64"):Uint8Array.from(atob(n),e=>e.charCodeAt(0))}function B(n){if(Array.isArray(n)){let e="";for(let t=0;t<n.length;t+=1){const o=n[t];t<n.length-1&&!o.endsWith(`
|
|
2
2
|
`)?e=e.concat(`${o}
|
|
3
|
-
`):e=e.concat(o)}return e}return n.toString()}function
|
|
4
|
-
`);n.search(/\r[^$]/g)>-1;){const e=n.match(/^(.*)\r+/m)[1];let t=n.match(/\r+(.*)$/m)[1];t=t+e.slice(t.length,e.length),n=n.replace(/\r+.*$/m,"\r").replace(/^.*\r/m,t)}return n}function
|
|
5
|
-
`)})],{...Q(n),originalError:n})}var K;(n=>{n.GeneratedThemeName="ipython-theme",n.MatplotLibDefaultParams="_VSCode_defaultMatplotlib_Params",n.MatplotLibFigureFormats="_VSCode_matplotLib_FigureFormats",n.DefaultCodeCellMarker="# %%",n.DefaultCommTarget="jupyter.widget",n.ALL_VARIABLES="ALL_VARIABLES",n.KERNEL_VARIABLES="KERNEL_VARIABLES",n.DEBUGGER_VARIABLES="DEBUGGER_VARIABLES",n.PYTHON_VARIABLES_REQUESTER="PYTHON_VARIABLES_REQUESTER",n.MULTIPLEXING_DEBUGSERVICE="MULTIPLEXING_DEBUGSERVICE",n.RUN_BY_LINE_DEBUGSERVICE="RUN_BY_LINE_DEBUGSERVICE",n.REMOTE_URI="https://remote/",n.REMOTE_URI_ID_PARAM="id",n.REMOTE_URI_HANDLE_PARAM="uriHandle",n.REMOTE_URI_EXTENSION_ID_PARAM="extensionId"})(K||(K={}));const U="application/vnd.jupyter.widget-view+json";class ve{constructor(e=null){this.scope=e,this._promise=new Promise((t,o)=>{this._resolve=t,this._reject=o})}_resolve;_reject;_resolved=!1;_rejected=!1;_promise;_value;get value(){return this._value}resolve(e){this._value=e,this._resolve.apply(this.scope?this.scope:this,arguments),this._resolved=!0}reject(e){this._reject.apply(this.scope?this.scope:this,arguments),this._rejected=!0}get promise(){return this._promise}get resolved(){return this._resolved}get rejected(){return this._rejected}get completed(){return this._rejected||this._resolved}}function Me(n=null){return new ve(n)}var P={};Object.defineProperty(P,"__esModule",{value:!0});P.serialize=J=P.deserialize=void 0;function De(n){let e;return typeof n=="string"?e=JSON.parse(n):e=Ae(n),e}var J=P.deserialize=De;function Oe(n){var e;let t;return!((e=n.buffers)===null||e===void 0)&&e.length?t=xe(n):t=JSON.stringify(n),t}P.serialize=Oe;function Ae(n){const e=new DataView(n),t=e.getUint32(0),o=[];if(t<2)throw new Error("Invalid incoming Kernel Message");for(let i=1;i<=t;i++)o.push(e.getUint32(i*4));const s=new Uint8Array(n.slice(o[0],o[1])),r=JSON.parse(new TextDecoder("utf8").decode(s));r.buffers=[];for(let i=1;i<t;i++){const a=o[i],c=o[i+1]||n.byteLength;r.buffers.push(new DataView(n.slice(a,c)))}return r}function xe(n){const e=[],t=[],o=new TextEncoder;let s=[];n.buffers!==void 0&&(s=n.buffers,delete n.buffers);const r=o.encode(JSON.stringify(n));t.push(r.buffer);for(let u=0;u<s.length;u++){const g=s[u];t.push(ArrayBuffer.isView(g)?g.buffer:g)}const i=t.length;e.push(4*(i+1));for(let u=0;u+1<t.length;u++)e.push(e[e.length-1]+t[u].byteLength);const a=new Uint8Array(e[e.length-1]+t[t.length-1].byteLength),c=new DataView(a.buffer);c.setUint32(0,i);for(let u=0;u<e.length;u++)c.setUint32(4*(u+1),e[u]);for(let u=0;u<t.length;u++)a.set(new Uint8Array(t[u]),e[u]);return a.buffer}function Pe(n){if(!n||!Array.isArray(n)||n.length===0)return;const e=[];for(let t=0;t<n.length;t+=1){const o=n[t];if("buffer"in o&&"byteOffset"in o){const s=[...new Uint8Array(o.buffer)];e.push({...o,byteLength:o.byteLength,byteOffset:o.byteOffset,buffer:s})}else e.push([...new Uint8Array(o)])}return e}const Re=n=>"getCells"in n?n.getCells():n.cells,$e=n=>n instanceof l.NotebookCellData?n.value:n.document.getText(),Le=n=>n instanceof l.NotebookCellData?n.languageId:n.document.languageId,te=(n,e,t)=>{var s;const o=[];for(const r of Re(n))o.push({cell_type:r.kind,source:$e(r).split(/\r?\n/g),languageId:Le(r),metadata:r.metadata,outputs:t?r.outputs:void 0});return{cells:o,metadata:{...n.metadata,name:e,createdAt:((s=n.metadata)==null?void 0:s.createdAt)||new Date().toISOString(),updatedAt:new Date().toISOString()}}},x=()=>Math.random().toString(36).substr(2,9);function qe(){const n=new Date,e=n.toLocaleDateString("en-GB").replace(/\//g,"-"),t=n.toLocaleTimeString("en-GB",{hour12:!1}).replace(/:/g,"-");return`${e}-${t}`}const je=require("path");function M(){}je.join(__dirname,".");function We(){console.log("Trying to load zmq");const n=require("zeromq");return n.context.blocky=!1,console.info("ZMQ loaded."),n}function Fe(n,e){const t=n.transport==="tcp"?":":"-",o=n[`${e}_port`];if(!o)throw new Error(`Port not found for channel "${e}"`);return`${n.transport}://${n.ip}${t}${o}`}const Ue=["username","version","session","msg_id","msg_type"],oe={stream:{name:"string",text:"string"},display_data:{data:"object",metadata:"object"},execute_input:{code:"string",execution_count:"number"},execute_result:{execution_count:"number",data:"object",metadata:"object"},error:{ename:"string",evalue:"string",traceback:"object"},status:{execution_state:["string",["starting","idle","busy","restarting","dead"]]},clear_output:{wait:"boolean"},comm_open:{comm_id:"string",target_name:"string",data:"object"},comm_msg:{comm_id:"string",data:"object"},comm_close:{comm_id:"string"},shutdown_reply:{restart:"boolean"}};function Be(n){if(n.channel!=="iopub")return;const e=n.header.msg_type;if(e in oe){const t=oe[e];if(t===void 0)return;const o=Object.keys(t),s=n.content;for(let r=0;r<o.length;r++){let i=t[o[r]];Array.isArray(i)||(i=[i]);const a=o[r];if(!(a in s)||typeof s[a]!==i[0])switch(i[0]){case"string":s[a]="";break;case"boolean":s[a]=!1;break;case"object":s[a]={};break;case"number":s[a]=0;break}}}}function Ke(n,e){const t=n.header;Ue.forEach(o=>{typeof t[o]!="string"&&(t[o]="")}),typeof n.channel!="string"&&(n.channel=e),n.content||(n.content={}),n.metadata||(n.metadata={}),n.channel==="iopub"&&Be(n)}class Ve{constructor(e,t){this.connection=e,this.serialize=t,this.channels=this.generateChannels(e)}onopen=M;onerror=M;onclose=M;onmessage=M;receiveHooks=[];sendHooks=[];msgChain=Promise.resolve();sendChain=Promise.resolve();channels;closed=!1;dispose(){this.closed||this.close()}close(){this.closed=!0;const e=t=>{try{t.close()}catch(o){console.error("Error during socket shutdown",o)}};e(this.channels.control),e(this.channels.iopub),e(this.channels.shell),e(this.channels.stdin)}emit(e,...t){switch(e){case"message":this.onmessage({data:t[0],type:"message",target:this});break;case"close":this.onclose({wasClean:!0,code:0,reason:"",target:this});break;case"error":this.onerror({error:"",message:"to do",type:"error",target:this});break;case"open":this.onopen({target:this});break}return!0}send(e,t){this.sendMessage(e,!1)}addReceiveHook(e){this.receiveHooks.push(e)}removeReceiveHook(e){this.receiveHooks=this.receiveHooks.filter(t=>t!==e)}addSendHook(e){this.sendHooks.push(e)}removeSendHook(e){this.sendHooks=this.sendHooks.filter(t=>t!==e)}generateChannel(e,t,o){const s=o();return s.connect(Fe(e,t)),this.processSocketMessages(t,s).catch(r=>console.error(`Failed to read messages from channel ${t}`,r)),s}async processSocketMessages(e,t){for await(const o of t){if(this.closed)break;this.onIncomingMessage(e,o)}}generateChannels(e){const t=We(),o=x(),s={iopub:this.generateChannel(e,"iopub",()=>new t.Subscriber({maxMessageSize:-1,receiveHighWaterMark:0})),shell:this.generateChannel(e,"shell",()=>new t.Dealer({routingId:o,sendHighWaterMark:0,receiveHighWaterMark:0,maxMessageSize:-1})),control:this.generateChannel(e,"control",()=>new t.Dealer({routingId:o,sendHighWaterMark:0,receiveHighWaterMark:0,maxMessageSize:-1})),stdin:this.generateChannel(e,"stdin",()=>new t.Dealer({routingId:o,sendHighWaterMark:0,receiveHighWaterMark:0,maxMessageSize:-1}))};return s.iopub.subscribe(),s}onIncomingMessage(e,t){const o=this.closed?{}:X.decode(t,this.connection.key,this.connection.signature_scheme);o.channel=e,this.receiveHooks.length?this.msgChain=this.msgChain.then(()=>{const s=this.serialize(o);return Promise.all(this.receiveHooks.map(r=>r(s)))}).then(()=>this.fireOnMessage(o,e)):this.msgChain=this.msgChain.then(()=>this.fireOnMessage(o,e))}fireOnMessage(e,t){if(!this.closed)try{Ke(e,t),this.onmessage({data:e,type:"message",target:this})}catch(o){console.error(`Failed to handle message in Jupyter Kernel package ${JSON.stringify(e)}`,o)}}sendMessage(e,t){const o=X.encode(e,this.connection.key,this.connection.signature_scheme);if(!t&&this.sendHooks.length){const s=this.serialize(e);this.sendChain=this.sendChain.then(()=>Promise.all(this.sendHooks.map(r=>r(s,M)))).then(async()=>{try{await this.postToSocket(e.channel,o)}catch(r){console.error(`Failed to write data to the kernel channel ${e.channel}`,o,r)}})}else this.sendChain=this.sendChain.then(()=>{this.postToSocket(e.channel,o)});this.sendChain.catch(M)}postToSocket(e,t){const o=this.channels[e];o?o.send(t).catch(s=>{console.error("Error communicating with the kernel",s)}):console.error(`Attempting to send message on invalid channel: ${e}`)}}let Y;class He{outputWidgetIds=new Set;waitingMessageIds=new Map;kernel;get postMessage(){return this._postMessageEmitter.event}_postMessageEmitter=new l.EventEmitter;constructor(e,t,o,s){this.kernel=this.initializeKernel(e,t,o,s)}get rawKernel(){return this.kernel}initializeKernel(e,t,o,s){const r=require("@jupyterlab/services"),i=require("@jupyterlab/services/lib/kernel/serialize");let a;class c extends Ve{constructor(){super(e.connection,i.serialize),a=this}}const u=r.ServerConnection.makeSettings({WebSocket:c,wsUrl:"RAW"});Y||(Y=require("@jupyterlab/services/lib/kernel/nonSerializingKernel"));const g=new Y.KernelConnection({serverSettings:u,clientId:t,handleComms:!1,username:o,model:s});return a&&(a.emit("open"),a.addReceiveHook(this.onKernelSocketMessage.bind(this)),a.addSendHook(this.mirrorSend.bind(this))),{realKernel:g,socket:a,kernelProcess:e}}async mirrorSend(e,t){if(typeof e=="string"&&e.includes("shell")&&e.includes("execute_request")){const o=J(e);if(o.channel==="shell"&&o.header.msg_type==="execute_request"){if(!G(o))return;this.mirrorExecuteRequest(o)}}}raisePostMessage(e,t){this._postMessageEmitter.fire({payload:t,type:e})}mirrorExecuteRequest(e){this.raisePostMessage("IPyWidgets_mirror_execute",{id:e.header.msg_id,msg:e})}async onKernelSocketMessage(e){var r,i,a,c,u,g,h,d,p;const t=x(),o=Me();if(this.waitingMessageIds.set(t,{startTime:Date.now(),resultPromise:o}),typeof e=="string"?G(e)&&this.raisePostMessage("IPyWidgets_msg",{id:t,data:e}):this.raisePostMessage("IPyWidgets_binary_msg",{id:t,data:Pe([e])}),typeof e!="string"||e.includes(U)||e.includes(K.DefaultCommTarget)||e.includes("comm_open")||e.includes("comm_close")||e.includes("comm_msg")){const b=J(e);if(!G(b))return;const _=((r=b.header)==null?void 0:r.msg_type)==="comm_open"&&((c=(a=(i=b.content)==null?void 0:i.data)==null?void 0:a.state)==null?void 0:c._model_module)==="@jupyter-widgets/output"&&((h=(g=(u=b.content)==null?void 0:u.data)==null?void 0:g.state)==null?void 0:h._model_name)==="OutputModel",C=((d=b.header)==null?void 0:d.msg_type)==="comm_close"&&this.outputWidgetIds.has((p=b.content)==null?void 0:p.comm_id);_?this.outputWidgetIds.add(b.content.comm_id):C&&this.outputWidgetIds.delete(b.content.comm_id)}}onKernelSocketResponse(e){const t=this.waitingMessageIds.get(e.id);t&&(this.waitingMessageIds.delete(e.id),t.resultPromise.resolve())}}const ze=require("path");class V{constructor(e,t,o,s){this.executionInfrastructure=t,this.notebookDependencies=o,this.dbtTerminal=s,this.dbtTerminal.debug("NotebookKernelClient","creating python bridge for notebook:",e),this.python=this.executionInfrastructure.createPythonBridge(ze.dirname(e)),this.initializeNotebookKernel(e)}get postMessage(){return this._postMessageEmitter.event}_postMessageEmitter=new l.EventEmitter;disposables=[];lastUsedStreamOutput;static modelIdsOwnedByCells=new WeakMap;python;kernel;isInitializing=!0;ownedCommIds=new Set;commIdsMappedToWidgetOutputModels=new Set;ownedRequestMsgIds=new Set;commIdsMappedToParentWidgetModel=new Map;streamsReAttachedToExecutingCell=!1;registerdCommTargets=new Set;outputsAreSpecificToAWidget=[];versions;async isInitialized(){return new Promise(e=>{const t=setInterval(()=>{var o,s;this.dbtTerminal.debug("Notebookclient","isInitialized",!!((o=this.kernel)!=null&&o.rawKernel)),(s=this.kernel)!=null&&s.rawKernel&&(e(!0),clearInterval(t))},500)})}async dispose(){this.disposables.forEach(e=>e.dispose());try{await this.python.ex`
|
|
3
|
+
`):e=e.concat(o)}return e}return n.toString()}function we(n){let e=n;do n=e,e=n.replace(/[^\n]\x08/gm,"");while(e.length<n.length);return n}function ke(n){for(n=n.replace(/\r+\n/gm,`
|
|
4
|
+
`);n.search(/\r[^$]/g)>-1;){const e=n.match(/^(.*)\r+/m)[1];let t=n.match(/\r+(.*)$/m)[1];t=t+e.slice(t.length,e.length),n=n.replace(/\r+.*$/m,"\r").replace(/^.*\r/m,t)}return n}function _e(n){return ke(we(n))}function j(n){if(n.parent_header&&"msg_id"in n.parent_header)return n.parent_header.msg_id}function Te(n){if(Object.prototype.hasOwnProperty.call(n,"text/html")){const e=n["text/html"];typeof e=="string"&&e.includes('<iframe id="tensorboard-frame-')&&(n["text/html"]=e.replace(/new URL\((.*), window.location\)/,'new URL("http://localhost")'))}return n}const Ee="e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPyWidgets:";function H(n){let e=typeof n=="string"?n:"";return typeof n!="string"&&"content"in n&&"code"in n.content&&typeof n.content.code=="string"&&(e=n.content.code),!e.includes(Ee)}function Ne(n){const e=B(n.text),t=n.name==="stderr"?l.NotebookCellOutputItem.stderr:l.NotebookCellOutputItem.stdout;return new l.NotebookCellOutput([t(e)],Q(n))}function Ce(n){return n=n||{output_type:"error",ename:"",evalue:"",traceback:[]},new l.NotebookCellOutput([l.NotebookCellOutputItem.error({name:(n==null?void 0:n.ename)||"",message:(n==null?void 0:n.evalue)||"",stack:((n==null?void 0:n.traceback)||[]).join(`
|
|
5
|
+
`)})],{...Q(n),originalError:n})}var J;(n=>{n.GeneratedThemeName="ipython-theme",n.MatplotLibDefaultParams="_VSCode_defaultMatplotlib_Params",n.MatplotLibFigureFormats="_VSCode_matplotLib_FigureFormats",n.DefaultCodeCellMarker="# %%",n.DefaultCommTarget="jupyter.widget",n.ALL_VARIABLES="ALL_VARIABLES",n.KERNEL_VARIABLES="KERNEL_VARIABLES",n.DEBUGGER_VARIABLES="DEBUGGER_VARIABLES",n.PYTHON_VARIABLES_REQUESTER="PYTHON_VARIABLES_REQUESTER",n.MULTIPLEXING_DEBUGSERVICE="MULTIPLEXING_DEBUGSERVICE",n.RUN_BY_LINE_DEBUGSERVICE="RUN_BY_LINE_DEBUGSERVICE",n.REMOTE_URI="https://remote/",n.REMOTE_URI_ID_PARAM="id",n.REMOTE_URI_HANDLE_PARAM="uriHandle",n.REMOTE_URI_EXTENSION_ID_PARAM="extensionId"})(J||(J={}));const U="application/vnd.jupyter.widget-view+json";class Se{constructor(e=null){this.scope=e,this._promise=new Promise((t,o)=>{this._resolve=t,this._reject=o})}_resolve;_reject;_resolved=!1;_rejected=!1;_promise;_value;get value(){return this._value}resolve(e){this._value=e,this._resolve.apply(this.scope?this.scope:this,arguments),this._resolved=!0}reject(e){this._reject.apply(this.scope?this.scope:this,arguments),this._rejected=!0}get promise(){return this._promise}get resolved(){return this._resolved}get rejected(){return this._rejected}get completed(){return this._rejected||this._resolved}}function Ie(n=null){return new Se(n)}var A={};Object.defineProperty(A,"__esModule",{value:!0});A.serialize=K=A.deserialize=void 0;function ve(n){let e;return typeof n=="string"?e=JSON.parse(n):e=De(n),e}var K=A.deserialize=ve;function Me(n){var e;let t;return!((e=n.buffers)===null||e===void 0)&&e.length?t=Oe(n):t=JSON.stringify(n),t}A.serialize=Me;function De(n){const e=new DataView(n),t=e.getUint32(0),o=[];if(t<2)throw new Error("Invalid incoming Kernel Message");for(let i=1;i<=t;i++)o.push(e.getUint32(i*4));const s=new Uint8Array(n.slice(o[0],o[1])),r=JSON.parse(new TextDecoder("utf8").decode(s));r.buffers=[];for(let i=1;i<t;i++){const a=o[i],c=o[i+1]||n.byteLength;r.buffers.push(new DataView(n.slice(a,c)))}return r}function Oe(n){const e=[],t=[],o=new TextEncoder;let s=[];n.buffers!==void 0&&(s=n.buffers,delete n.buffers);const r=o.encode(JSON.stringify(n));t.push(r.buffer);for(let d=0;d<s.length;d++){const p=s[d];t.push(ArrayBuffer.isView(p)?p.buffer:p)}const i=t.length;e.push(4*(i+1));for(let d=0;d+1<t.length;d++)e.push(e[e.length-1]+t[d].byteLength);const a=new Uint8Array(e[e.length-1]+t[t.length-1].byteLength),c=new DataView(a.buffer);c.setUint32(0,i);for(let d=0;d<e.length;d++)c.setUint32(4*(d+1),e[d]);for(let d=0;d<t.length;d++)a.set(new Uint8Array(t[d]),e[d]);return a.buffer}function xe(n){if(!n||!Array.isArray(n)||n.length===0)return;const e=[];for(let t=0;t<n.length;t+=1){const o=n[t];if("buffer"in o&&"byteOffset"in o){const s=o,r=[...new Uint8Array(s.buffer)];e.push({byteLength:s.byteLength,byteOffset:s.byteOffset,buffer:r})}else e.push([...new Uint8Array(o)])}return e}const Ae=n=>"getCells"in n?n.getCells():n.cells,Pe=n=>n instanceof l.NotebookCellData?n.value:n.document.getText(),Re=n=>n instanceof l.NotebookCellData?n.languageId:n.document.languageId,te=(n,e,t)=>{var s;const o=[];for(const r of Ae(n))o.push({cell_type:r.kind,source:Pe(r).split(/\r?\n/g),languageId:Re(r),metadata:r.metadata,outputs:t?r.outputs:void 0});return{cells:o,metadata:{...n.metadata,name:e,createdAt:((s=n.metadata)==null?void 0:s.createdAt)||new Date().toISOString(),updatedAt:new Date().toISOString()}}},x=()=>Math.random().toString(36).substr(2,9);function Le(){const n=new Date,e=n.toLocaleDateString("en-GB").replace(/\//g,"-"),t=n.toLocaleTimeString("en-GB",{hour12:!1}).replace(/:/g,"-");return`${e}-${t}`}const $e=require("path");function F(){}$e.join(__dirname,".");function qe(){console.log("Trying to load zmq");const n=require("zeromq");return n.context.blocky=!1,console.info("ZMQ loaded."),n}function je(n,e){const t=n.transport==="tcp"?":":"-",o=n[`${e}_port`];if(!o)throw new Error(`Port not found for channel "${e}"`);return`${n.transport}://${n.ip}${t}${o}`}const Fe=["username","version","session","msg_id","msg_type"],oe={stream:{name:"string",text:"string"},display_data:{data:"object",metadata:"object"},execute_input:{code:"string",execution_count:"number"},execute_result:{execution_count:"number",data:"object",metadata:"object"},error:{ename:"string",evalue:"string",traceback:"object"},status:{execution_state:["string",["starting","idle","busy","restarting","dead"]]},clear_output:{wait:"boolean"},comm_open:{comm_id:"string",target_name:"string",data:"object"},comm_msg:{comm_id:"string",data:"object"},comm_close:{comm_id:"string"},shutdown_reply:{restart:"boolean"}};function We(n){if(n.channel!=="iopub")return;const e=n.header.msg_type;if(e in oe){const t=oe[e];if(t===void 0)return;const o=Object.keys(t),s=n.content;for(let r=0;r<o.length;r++){const i=t[o[r]],a=Array.isArray(i)?i:[i,[]],c=o[r];if(!(c in s)||typeof s[c]!==a[0])switch(a[0]){case"string":s[c]="";break;case"boolean":s[c]=!1;break;case"object":s[c]={};break;case"number":s[c]=0;break}}}}function Ue(n,e){const t=n.header;Fe.forEach(o=>{typeof t[o]!="string"&&(t[o]="")}),typeof n.channel!="string"&&(n.channel=e),n.content||(n.content={}),n.metadata||(n.metadata={}),n.channel==="iopub"&&We(n)}console.log(Ue);class Be{constructor(e,t){this.connection=e,this.serialize=t,this.channels=this.generateChannels(this.connection)}onopen=F;onerror=F;onclose=F;onmessage=F;receiveHooks=[];sendHooks=[];msgChain=Promise.resolve();sendChain=Promise.resolve();channels;closed=!1;dispose(){this.closed||this.close()}close(){this.closed=!0;const e=t=>{try{t.close()}catch(o){console.error("Error during socket shutdown",o)}};e(this.channels.control),e(this.channels.iopub),e(this.channels.shell),e(this.channels.stdin)}emit(e,...t){switch(e){case"message":this.onmessage({data:t[0],type:"message",target:this});break;case"close":this.onclose({wasClean:!0,code:0,reason:"",target:this});break;case"error":this.onerror({error:new Error,message:"to do",type:"error",target:this});break;case"open":this.onopen({target:this});break}return!0}send(e,t){this.sendMessage(e,!1)}addReceiveHook(e){this.receiveHooks.push(e)}removeReceiveHook(e){this.receiveHooks=this.receiveHooks.filter(t=>t!==e)}addSendHook(e){this.sendHooks.push(e)}removeSendHook(e){this.sendHooks=this.sendHooks.filter(t=>t!==e)}generateChannel(e,t,o){const s=o();return s.connect(je(e,t)),this.processSocketMessages(t,s).catch(r=>console.error(`Failed to read messages from channel ${t}`,r)),s}async processSocketMessages(e,t){for await(const o of t){if(this.closed)break;this.onIncomingMessage(e,o)}}generateChannels(e){const t=qe(),o=x();return{iopub:this.generateChannel(e,"iopub",()=>new t.Subscriber({maxMessageSize:-1,receiveHighWaterMark:0})),shell:this.generateChannel(e,"shell",()=>new t.Dealer({routingId:o,maxMessageSize:-1})),control:this.generateChannel(e,"control",()=>new t.Dealer({routingId:o,maxMessageSize:-1})),stdin:this.generateChannel(e,"stdin",()=>new t.Dealer({routingId:o,maxMessageSize:-1}))}}onIncomingMessage(e,t){this.msgChain=this.msgChain.then(()=>this.handleIncomingMessage(e,t)).catch(o=>{console.error("Failed to handle incoming message",o)})}async handleIncomingMessage(e,t){for(const o of this.receiveHooks)await o(t);this.emit("message",t)}sendMessage(e,t){this.sendChain=this.sendChain.then(()=>this.handleOutgoingMessage(e,t)).catch(o=>{console.error("Failed to handle outgoing message",o)})}async handleOutgoingMessage(e,t){if(!t)for(const r of this.sendHooks)await r(e);let o,s;try{if(typeof e=="string")o=K(e),s=o.channel;else throw new Error("Not supported")}catch{s="shell",o=e}this.postToSocket(s,o)}postToSocket(e,t){const o=this.channels[e];o&&o.send(this.serialize(t))}}let Y;class Ke{outputWidgetIds=new Set;waitingMessageIds=new Map;kernel;get postMessage(){return this._postMessageEmitter.event}_postMessageEmitter=new l.EventEmitter;constructor(e,t,o,s){this.kernel=this.initializeKernel(e,t,o,s)}get rawKernel(){return this.kernel}initializeKernel(e,t,o,s){const r=require("@jupyterlab/services"),i=require("@jupyterlab/services/lib/kernel/serialize");let a;const c=class extends Be{static CONNECTING=0;static OPEN=1;static CLOSING=2;static CLOSED=3;constructor(){super(e.connection,i.serialize),a=this}},d=r.ServerConnection.makeSettings({WebSocket:c,wsUrl:"RAW"});Y||(Y=require("@jupyterlab/services/lib/kernel/nonSerializingKernel"));const p=new Y.KernelConnection({serverSettings:d,clientId:t,handleComms:!1,username:o,model:s});return a&&(a.emit("open"),a.addReceiveHook(this.onKernelSocketMessage.bind(this)),a.addSendHook(this.mirrorSend.bind(this))),{realKernel:p,socket:a,kernelProcess:e}}async mirrorSend(e,t){if(typeof e=="string"&&e.includes("shell")&&e.includes("execute_request")){const o=K(e);if(o.channel==="shell"&&o.header.msg_type==="execute_request"&&"content"in o&&typeof o.content=="object"&&o.content!==null&&"code"in o.content){const s=o;if(!H(s))return;this.mirrorExecuteRequest(s)}}}raisePostMessage(e,t){this._postMessageEmitter.fire({payload:t,type:e})}mirrorExecuteRequest(e){this.raisePostMessage("IPyWidgets_mirror_execute",{id:e.header.msg_id,msg:e})}async onKernelSocketMessage(e){var r;const t=x(),o=Ie();if(this.waitingMessageIds.set(t,{startTime:Date.now(),resultPromise:o}),typeof e=="string"?H(e)&&this.raisePostMessage("IPyWidgets_msg",{id:t,data:e}):(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&this.raisePostMessage("IPyWidgets_binary_msg",{id:t,data:xe([e])}),(typeof e!="string"||e.includes(U)||e.includes(J.DefaultCommTarget)||e.includes("comm_open")||e.includes("comm_close")||e.includes("comm_msg"))&&typeof e=="string"){const i=K(e);if(!H(i))return;if(X.KernelMessage.isCommOpenMsg(i)){const a=i.content,c=(r=a.data)==null?void 0:r.state;c&&typeof c=="object"&&"_model_module"in c&&"_model_name"in c&&c._model_module==="@jupyter-widgets/output"&&c._model_name==="OutputModel"&&this.outputWidgetIds.add(a.comm_id)}else if(X.KernelMessage.isCommCloseMsg(i)){const a=i.content;this.outputWidgetIds.has(a.comm_id)&&this.outputWidgetIds.delete(a.comm_id)}}}onKernelSocketResponse(e){const t=this.waitingMessageIds.get(e.id);t&&(this.waitingMessageIds.delete(e.id),t.resultPromise.resolve())}}const Ve=require("path");class V{constructor(e,t,o,s){this.executionInfrastructure=t,this.notebookDependencies=o,this.dbtTerminal=s,this.dbtTerminal.debug("NotebookKernelClient","creating python bridge for notebook:",e),this.python=this.executionInfrastructure.createPythonBridge(Ve.dirname(e)),this.initializeNotebookKernel(e),console.log("NotebookKernelClient",this.commIdsMappedToParentWidgetModel,this.ownedRequestMsgIds,this.ownedCommIds)}get postMessage(){return this._postMessageEmitter.event}_postMessageEmitter=new l.EventEmitter;disposables=[];lastUsedStreamOutput;static modelIdsOwnedByCells=new WeakMap;python;kernel;isInitializing=!0;ownedCommIds=new Set;commIdsMappedToWidgetOutputModels=new Set;ownedRequestMsgIds=new Set;commIdsMappedToParentWidgetModel=new Map;streamsReAttachedToExecutingCell=!1;registerdCommTargets=new Set;outputsAreSpecificToAWidget=[];versions;async isInitialized(){return new Promise(e=>{const t=setInterval(()=>{var o,s;this.dbtTerminal.debug("Notebookclient","isInitialized",!!((o=this.kernel)!=null&&o.rawKernel)),(s=this.kernel)!=null&&s.rawKernel&&(e(!0),clearInterval(t))},500)})}async dispose(){this.disposables.forEach(e=>e.dispose());try{await this.python.ex`
|
|
6
6
|
notebook_kernel.close_notebook()
|
|
7
|
-
`}catch(e){this.dbtTerminal.error(
|
|
7
|
+
`}catch(e){this.dbtTerminal.error(h.TelemetryEvents["Notebook/KernelCloseError"],e.exception.message,e)}}get jupyterPackagesVersions(){return this.versions}async getDependenciesVersion(){this.versions=await this.notebookDependencies.getDependenciesVersion()}async getKernel(){return new Promise(e=>{const t=setInterval(()=>{var o;this.isInitializing||(e((o=this.kernel)==null?void 0:o.rawKernel),clearInterval(t))},500)})}async initializeNotebookKernel(e){try{if(!await this.notebookDependencies.validateAndInstallNotebookDependencies())return;await this.python.ex`
|
|
8
8
|
from altimate_notebook_kernel import AltimateNotebookKernel
|
|
9
9
|
notebook_kernel = AltimateNotebookKernel(${e})
|
|
10
|
-
`;const t=await this.python.lock(a=>a`notebook_kernel.get_connection_file()`),o=JSON.parse(le.readFileSync(t,{encoding:"utf-8"})),s=await this.python.lock(a=>a`notebook_kernel.get_session_id()`),r={connection:o,pid:s},i=new He(r,x(),x(),{name:o.kernel_name,id:x()});this.kernel=i,this.disposables.push(i.postMessage(a=>this._postMessageEmitter.fire(a))),this.dbtTerminal.log(`Notebook Kernel started with PID: ${s} connection: ${JSON.stringify(o)}`),this.getDependenciesVersion()}catch(t){let o=t.message;t instanceof se.PythonException&&(o=t.exception.message),this.dbtTerminal.error(m.TelemetryEvents["Notebook/KernelInitializationError"],o,t),l.window.showErrorMessage(o)}this.isInitializing=!1}onKernelSocketResponse(e){var t;(t=this.kernel)==null||t.onKernelSocketResponse(e)}async storeContext(e){this.dbtTerminal.log(`storeContext: ${e}`),await this.python.lock(t=>t`notebook_kernel.store_context(${e})`)}async storeDataInKernel(e,t){return new Promise(async(o,s)=>{try{this.dbtTerminal.log(`storeDataInKernel: ${e}`),await this.python.lock(r=>r`notebook_kernel.store_sql_result(${e}, ${JSON.stringify(t)})`),o(!0)}catch(r){this.dbtTerminal.error(m.TelemetryEvents["Notebook/StoreDataInKernelError"],r.exception.message,r),s(r)}})}async registerCommTarget(e){if(this.registerdCommTargets.has(e)){this.dbtTerminal.log(`registerCommTarget already registered: ${e}`);return}this.registerdCommTargets.add(e),this.dbtTerminal.log(`registerCommTarget registering: ${e}`);const t=await this.getKernel();if(!t)throw this.registerdCommTargets.delete(e),new Error("Kernel not found for registering comm target");return t.realKernel.registerCommTarget(e,(o,s)=>{this.dbtTerminal.log(`registerCommTarget registered: ${e}`,o,s)})}async getPythonCodeByType(e,t){return this.dbtTerminal.debug("getPythonCodeByType",e,t),await this.python.lock(o=>o`notebook_kernel.get_python_code_by_type(${e}, ${t})`)}async executePython(e,t,o){return new Promise(async(s,r)=>{var g,h;if(!((h=(g=this.kernel)==null?void 0:g.rawKernel)!=null&&h.realKernel)){r(new Error("Kernel not found"));return}const i=t.metadata.cellId;this.dbtTerminal.log(`Executing python code in cell: ${i}`,e);const a=require("@jupyterlab/services");this.dbtTerminal.log("kernel status",this.kernel.rawKernel.realKernel.status);const c=await this.kernel.rawKernel.realKernel.requestExecute({code:e,silent:!1,stop_on_error:!1,allow_stdin:!0,store_history:!0},!1,{cellId:t.document.uri.toString()});if(!c){r(new Error("Unknown request error"));return}c.onReply=d=>{if(t.document.isClosed){c.dispose();return}const p=d.content;p.payload&&p.payload.forEach(b=>{if(b.data&&b.data.hasOwnProperty("text/plain")){const _=this.addToCellData({output_type:"stream",text:b.data["text/plain"].toString(),name:"stdout",metadata:{},execution_count:p.execution_count},d,t);_&&o(_)}})};const u=[];return c.done.finally(()=>{c.dispose(),s(u.filter(d=>!!d))}),c.onStdin=d=>{this.dbtTerminal.log("onStdin",d)},c.onIOPub=d=>{if(a.KernelMessage.isCommOpenMsg(d))this.handleCommOpen(d);else if(a.KernelMessage.isExecuteResultMsg(d))u.push(this.handleExecuteResult(d,t));else if(a.KernelMessage.isExecuteInputMsg(d))this.handleExecuteInput(d);else if(a.KernelMessage.isStatusMsg(d)){const p=d;this.handleStatusMessage(p)}else if(a.KernelMessage.isStreamMsg(d)){const p=this.handleStreamMessage(d,t);p==null||p.forEach(b=>{u.push(b)})}else a.KernelMessage.isDisplayDataMsg(d)?u.push(this.handleDisplayData(d,t)):a.KernelMessage.isUpdateDisplayDataMsg(d)?this.handleUpdateDisplayDataMessage(d):a.KernelMessage.isClearOutputMsg(d)?this.handleClearOutput(d):a.KernelMessage.isErrorMsg(d)?u.push(this.handleError(d,t)):a.KernelMessage.isCommOpenMsg(d)||(a.KernelMessage.isCommMsgMsg(d)?this.handleCommMsg(d):a.KernelMessage.isCommCloseMsg(d)||this.dbtTerminal.warn("NotebookUnknownIOPubMessage",`Unknown message ${d.header.msg_type} : hasData=${"data"in d.content}`))},c})}handleUpdateDisplayDataMessage(e){if(this.dbtTerminal.log("handleUpdateDisplayDataMessage",e),!e.content.transient.display_id){this.dbtTerminal.warn("NotebookUpdateDisplayDataMessageReceivedButNoDisplayId","Update display data message received, but no display id",!1,e.content);return}}handleCommOpen(e){var o;this.ownedCommIds.add(e.content.comm_id);const t=((o=e.content.data)==null?void 0:o.state)||void 0;e.content.target_name===K.DefaultCommTarget&&t&&t._model_module==="@jupyter-widgets/output"&&this.commIdsMappedToWidgetOutputModels.add(e.content.comm_id)}handleCommMsg(e){const t=e.content.data;if(!(!t||t.method!=="update"||typeof t.state!="object")){if("msg_id"in t.state&&typeof t.state.msg_id=="string"){const o="msg_id"in e.parent_header?e.parent_header:void 0;(this.ownedRequestMsgIds.has(e.content.comm_id)||o&&this.ownedRequestMsgIds.has(o.msg_id))&&(t.state.msg_id?this.outputsAreSpecificToAWidget.push({handlingCommId:e.content.comm_id,msgIdsToSwallow:t.state.msg_id}):this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].handlingCommId===e.content.comm_id&&this.outputsAreSpecificToAWidget.pop())}else if("children"in t.state&&Array.isArray(t.state.children)&&this.ownedCommIds.has(e.content.comm_id)){const o="IPY_MODEL_";t.state.children.forEach(s=>{if(typeof s!="string")return this.dbtTerminal.warn("Came across a comm update message a child that isn't a string",s);if(!s.startsWith(o))return this.dbtTerminal.warn(`Came across a comm update message a child that start start with ${o}`,s);const r=s.substring(o.length);this.ownedCommIds.add(r),this.commIdsMappedToParentWidgetModel.set(r,e.content.comm_id)})}}}handleExecuteResult(e,t){return this.addToCellData({output_type:"execute_result",data:e.content.data,metadata:e.content.metadata,transient:e.content.transient,execution_count:e.content.execution_count},e,t)}addToCellData(e,t,o){if(e.data&&typeof e.data=="object"&&U in e.data){const i=e.data[U];if(i&&"model_id"in i){const a=V.modelIdsOwnedByCells.get(o)||new Set;a.add(i.model_id),V.modelIdsOwnedByCells.set(o,a)}}const s=z(e);if(o.document.isClosed)return;this.dbtTerminal.log(o.document.uri.fsPath,`Update output with mimes ${s.items.map(i=>i.mime).toString()}`);const r=W(t);return this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===r&&s.items.every(i=>this.canMimeTypeBeRenderedByWidgetManager(i))||this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===r&&this.dbtTerminal.warn("NotebookAddToCellData","unknown operation"),s}canMimeTypeBeRenderedByWidgetManager(e){const t=e.mime;if(t===F.stderr||t===F.stdout||t===F.error)return!0;if(t===U){const o=JSON.parse(new TextDecoder().decode(e.data));return!(typeof o.model_id=="string"&&this.commIdsMappedToWidgetOutputModels.has(o.model_id))}return!t.startsWith("application/vnd")}handleExecuteInput(e){}handleStatusMessage(e){}handleStreamMessage(e,t){var s;if(W(e)&&this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===W(e))return;const o=e.content.name==="stdout"?l.NotebookCellOutputItem.stdout("").mime:l.NotebookCellOutputItem.stderr("").mime;if(!this.streamsReAttachedToExecutingCell&&!this.lastUsedStreamOutput&&t.outputs.length&&t.outputs[t.outputs.length-1].items.length>=1&&t.outputs[t.outputs.length-1].items.every(r=>r.mime===o)&&(this.lastUsedStreamOutput={output:t.outputs[0],stream:e.content.name}),this.streamsReAttachedToExecutingCell=!0,((s=this.lastUsedStreamOutput)==null?void 0:s.stream)===e.content.name)return[z({output_type:"stream",name:e.content.name,text:e.content.text}),this.lastUsedStreamOutput.output];{const r=Ee(B(e.content.text));return[z({output_type:"stream",name:e.content.name,text:r})]}}handleDisplayData(e,t){const o={output_type:"display_data",data:Ne(e.content.data),metadata:e.content.metadata,transient:e.content.transient};return this.addToCellData(o,e,t)}handleClearOutput(e){if(this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===W(e)){e.content.wait&&this.outputsAreSpecificToAWidget.length&&(this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].clearOutputOnNextUpdateToOutput=!0);return}}handleError(e,t){const o=e.content.traceback;this.dbtTerminal.log(`Traceback for error ${o}`);const s={output_type:"error",ename:e.content.ename,evalue:e.content.evalue,traceback:o};return this.addToCellData(s,e,t)}}var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Je=(n,e,t,o)=>{for(var s=o>1?void 0:o?Ye(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&Ge(e,t,s),s};exports.NotebookDependencies=class{constructor(e,t,o,s){this.dbtTerminal=e,this.telemetry=t,this.commandProcessExecutionFactory=o,this.pythonEnvironment=s}async checkPythonDependencies(e){const t=[];for(const o of e){const s=["-m","pip","show",o],{stderr:r}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:s,cwd:m.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();r&&t.push(o)}return t}checkDbtDependencies(e,t){return e.map(o=>{try{return t.findPackageVersion(o),null}catch{return o}}).filter(Boolean)}async installMissingPythonPackages(e,t){const o=await this.checkPythonDependencies(e);if(!o.length)return;if(this.dbtTerminal.debug("Notebook","asking user to install missing python dependencies for notebook",o),await l.window.showInformationMessage(`You need the following python packages to use this notebook: ${o.join(", ")}`,"Install","Cancel")!=="Install")throw this.telemetry.sendTelemetryEvent(m.TelemetryEvents["Notebook/DependenciesInstallCancelled"]),new Error("User cancelled python package installation");return this.dbtTerminal.debug("Notebook","installing required dependencies",o),await l.window.withProgress({title:"Installing python packages...",location:l.ProgressLocation.Notification,cancellable:!1},async()=>{try{const r=["-m","pip","install",...o],{stdout:i,stderr:a}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:r,cwd:m.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();if(!i.includes("Successfully installed")&&!i.includes("Requirement already satisfied")&&a)throw new Error(a);return this.dbtTerminal.log("Notebook dependencies have been installed successfully."),this.telemetry.sendTelemetryEvent(m.TelemetryEvents["Notebook/DependenciesInstalled"]),await t.initialize(),!0}catch(r){this.telemetry.sendTelemetryError(m.TelemetryEvents["Notebook/DependenciesInstallError"],r),l.window.showErrorMessage(m.extendErrorWithSupportLinks(r.message))}})}async installMissingDbtPackages(e,t){const o=this.checkDbtDependencies(e.map(i=>`${i.name}`),t);if(!o.length)return;const s=e.filter(i=>i.name?o.includes(i.name):!1);if(this.dbtTerminal.debug("Notebook","asking user to install missing dbt dependencies for notebook",s),await l.window.showInformationMessage(`You need following dbt packages to use this notebook: ${s.map(i=>`${i.package}`).join(", ")}`,"Install","Cancel")!=="Install")throw this.telemetry.sendTelemetryEvent(m.TelemetryEvents["Notebook/DependenciesInstallCancelled"]),new Error("User cancelled dbt package installation");return await l.window.withProgress({title:"Installing dbt packages...",location:l.ProgressLocation.Notification,cancellable:!1},async()=>{try{const i=s.map(c=>`${c.package}@${c.version}`);this.dbtTerminal.debug("Notebook","installing dbt packages",i),await t.installDbtPackages(i),await t.initialize();const a=this.checkDbtDependencies(e.map(c=>`${c.name}`),t);if(a.length)throw new Error(`Failed to install dbt packages ${a.join(", ")}`);return this.dbtTerminal.log("Notebook dependencies have been installed successfully."),this.telemetry.sendTelemetryEvent(m.TelemetryEvents["Notebook/DependenciesInstalled"]),!0}catch(i){this.telemetry.sendTelemetryError(m.TelemetryEvents["Notebook/DependenciesInstallError"],i),l.window.showErrorMessage(m.extendErrorWithSupportLinks(i.message))}})}async verifyAndInstallDependenciesIfNeeded(e,t){this.dbtTerminal.debug("NotebookDependencies","verifying required dependencies",e),await Promise.all([this.validateAndInstallNotebookDependencies(),this.installMissingPythonPackages(e.filter(o=>o.type==="python").map(o=>o.package),t),this.installMissingDbtPackages(e.filter(o=>o.type==="dbt"),t)])}async getDependenciesVersion(){const e=["-m","jupyter","--version"],{stdout:t,stderr:o}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:e,cwd:m.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();if(!t.includes("Successfully installed")&&!t.includes("Requirement already satisfied")&&o)throw new Error(o);const s=t.split(`
|
|
11
|
-
`),r={};return s.forEach(i=>{const[a,c]=i.split(":").map(u=>u.trim());a&&c&&(r[a]=c)}),r}async validateAndInstallNotebookDependencies(){try{if(await this.notebookDependenciesAreInstalled())return this.dbtTerminal.log("Notebook dependencies are already installed."),!0;if(await l.window.showInformationMessage("You need [ipykernel](https://pypi.org/project/ipykernel/) and [jupyter_client](https://github.com/jupyter/jupyter_client) to use the notebook","Install","Cancel")!=="Install")return this.telemetry.sendTelemetryEvent(m.TelemetryEvents["Notebook/DependenciesInstallCancelled"]),!1;await l.window.withProgress({title:"Installing required dependencies...",location:l.ProgressLocation.Notification,cancellable:!1},async()=>{try{const o=["-m","pip","install","ipykernel","jupyter_client","jupyter_contrib_nbextensions","ipywidgets"],{stdout:s,stderr:r}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:o,cwd:m.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();if(!s.includes("Successfully installed")&&!s.includes("Requirement already satisfied")&&r)throw new Error(r);return this.dbtTerminal.log("Notebook dependencies have been installed successfully."),this.telemetry.sendTelemetryEvent(m.TelemetryEvents["Notebook/DependenciesInstalled"]),!0}catch(o){return this.telemetry.sendTelemetryError(m.TelemetryEvents["Notebook/DependenciesInstallError"],o),l.window.showErrorMessage(m.extendErrorWithSupportLinks(o.message)),!1}})&&await l.window.showInformationMessage("Notebook dependencies installed. Please reload the window to use the notebook.","Reload Window")==="Reload Window"&&l.commands.executeCommand("workbench.action.reloadWindow")}catch(e){throw this.dbtTerminal.error(m.TelemetryEvents["Notebook/DependenciesInstallError"],e.message,e),e}}async notebookDependenciesAreInstalled(){try{const e=this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:["-c","import jupyter_client"],cwd:m.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}),{stderr:t}=await e.complete();if(t)throw new Error(t);return!0}catch{return!1}}};exports.NotebookDependencies=Je([m.provideSingleton(exports.NotebookDependencies)],exports.NotebookDependencies);var Qe=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(n,e,t,o)=>{for(var s=o>1?void 0:o?Xe(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&Qe(e,t,s),s};const et=require("path");exports.DatapilotNotebookController=class{constructor(e,t,o,s,r,i){this.clientMapper=e,this.queryManifestService=t,this.telemetry=o,this.dbtTerminal=s,this.notebookDependencies=r,this.altimate=i,this.controller=l.notebooks.createNotebookController(this.id,A,this.label),this.controller.supportedLanguages=he,this.controller.supportsExecutionOrder=!0,this.controller.executeHandler=this._executeAll.bind(this),this.disposables.push(l.workspace.onDidChangeNotebookDocument(a=>{a.contentChanges.forEach(async c=>{c.addedCells&&await this.updateCellId(a.notebook.getCells(),a.notebook),c.removedCells&&c.removedCells.forEach(u=>{this._onNotebookCellEvent.fire({cellId:u.metadata.cellId,notebook:a.notebook.uri.fsPath,result:null,event:"delete",fragment:u.document.uri.fragment,languageId:u.document.languageId})})})})),this.disposables.push(this.controller),this.controller.onDidChangeSelectedNotebooks(this.onDidChangeSelectedNotebooks,this,this.disposables),this.disposables.push(l.workspace.onDidOpenNotebookDocument(async a=>{await this.onNotebookOpen(a)})),this.disposables.push(l.workspace.onDidCloseNotebookDocument(async a=>{await this.onNotebookClose(a)}))}id="DatapilotNotebookController";label="Datapilot";_onNotebookCellEvent=new l.EventEmitter;onNotebookCellChangeEvent=this._onNotebookCellEvent.event;disposables=[this._onNotebookCellEvent];associatedNotebooks=new Set;executionOrder=0;controller;async getNotebookByTemplate(e){var o;return this.dbtTerminal.debug("Notebook","getting notebook by template",e),e?(o=(await this.altimate.getPreConfiguredNotebooks()).find(s=>s.name===e))==null?void 0:o.data:(this.dbtTerminal.debug("Notebook","sending blank notebook"),{cells:[{cell_type:l.NotebookCellKind.Markup,source:["### Welcome to your new dbt Power User Notebook!","> Note: Remember, you can delete any or all of these example cells to start fresh with your own work. Enjoy exploring and analyzing your data!","#### Documentation and Feedback","For more detailed information on how to use this notebook and the dbt Power User extension, please refer to our documentation:","[dbt Power User Documentation](https://docs.myaltimate.com/govern/notebooks/)"," ","We value your feedback! If you have any suggestions, encounter issues, or want to share your experience, please let us know:","[Share Feedback](https://docs.google.com/forms/d/e/1FAIpQLScwN3wRTAniQzvcO6Hn3jC0WtBoFE2NP4X_6qGQ09IZKZ3Ojw/viewform?usp=sf_link)"," ","Happy analyzing with your new dbt Power User Notebook!"," ","This notebook allows you to combine Jinja SQL queries, Python code, and Markdown text. Let's explore each of these features.","##### 1. Jinja SQL Queries","You can write and execute Jinja SQL queries directly in this notebook. Here's an example:"],languageId:"markdown",metadata:{}},{cell_type:l.NotebookCellKind.Code,source:["select * from {{ ref('your_model_name') }}","{# Replace 'your_model_name' with the name of your dbt model. #}"],languageId:pe,metadata:{cellId:"jinja_sql_0"}},{cell_type:l.NotebookCellKind.Markup,source:["##### 2. Python Code","You can also write and execute Python code on top of the results of previous `jinja-sql` cell in this notebook. Here's a simple example:"],languageId:"markdown",metadata:{}},{cell_type:l.NotebookCellKind.Code,source:["import pandas as pd","from IPython.display import display, HTML","from ydata_profiling import ProfileReport","from io import StringIO","","# Extract the data field","# NOTE: we use the cell id from previous cell to extract the data","data = cell_jinja_sql_0['data']","","# Create a DataFrame","df = pd.DataFrame(data)","","# Display the DataFrame","# display(HTML(df.to_html()))","",'profile = ProfileReport(df, title="Profiling Report")',"profile.to_notebook_iframe()"],languageId:"python",metadata:{}},{cell_type:l.NotebookCellKind.Markup,source:["This Python code creates a profile report of your query results. You can customize the code to suit your needs.","##### 3. Markdown Text","As you can see, you can use Markdown to structure your notebook with headings, lists, and more. You can also use it to add explanations and documentation to your queries and code.","##### Tips for Using This Notebook","- Use Jinja cells for your dbt model queries and data exploration","- Use Python cells for data analysis, visualization, and custom transformations. The jinja data can be referenced using the cell id","- Use Markdown cells to explain your process, document your findings, and create a narrative for your analysis"],languageId:"markdown",metadata:{}}]})}async modelTestSuggestions(e){this.dbtTerminal.log("modelTestSuggestions",e)}async generateDbtSourceYaml(e){this.dbtTerminal.log("generateDbtSourceYaml",e)}async generateDbtDbtModelSql(e){this.dbtTerminal.log("generateDbtDbtModelSql",e)}async generateDbtDbtModelYaml(e){this.dbtTerminal.log("generateDbtDbtModelYaml",e)}async generateDbtDbtModelCTE(e){this.dbtTerminal.log("generateDbtDbtModelCTE",e)}async extractExposuresFromMetabase(e){this.dbtTerminal.log("extractExposuresFromMetabase",e)}async extractExposuresFromTableau(e){this.dbtTerminal.log("extractExposuresFromTableau",e)}async getFileName(e,t){if(e)return e;const o=qe();if((await this.altimate.addNotebook({name:o,description:"",data:t?{...t,metadata:{...t.metadata||{},isDraft:!0}}:{},tags_list:[]})).ok&&(await this.altimate.getNotebooks(o)).length>0)return o}async createNotebook(e){var i;const{notebookId:t,template:o,context:s={},notebookSchema:r}=e||{};if(this.dbtTerminal.info(m.TelemetryEvents["Notebook/Launch"],"creating notebook",!0,e),!s.model&&((i=l.window.activeTextEditor)!=null&&i.document.uri.fsPath.endsWith(".sql"))){const a=et.basename(l.window.activeTextEditor.document.uri.fsPath,".sql"),c=l.window.activeTextEditor.document.getText();s.model=a,s.query=c}l.window.withProgress({location:l.ProgressLocation.Notification,title:"Launching notebook...",cancellable:!1},async()=>{var a;try{const c=r||(t?null:await this.getNotebookByTemplate(o)),u=await this.queryManifestService.getOrPickProjectFromWorkspace();if(!u){l.window.showErrorMessage("No dbt project selected.");return}if((a=c==null?void 0:c.metadata)!=null&&a.dependencies&&await this.notebookDependencies.verifyAndInstallDependenciesIfNeeded(c.metadata.dependencies,u),s&&c)for(const p in s)s.hasOwnProperty(p)&&typeof s[p]=="string"&&(c.cells[0].source=c.cells[0].source.map(b=>b.replace(`%_${p}_%`,s[p])));const g=await this.getFileName(t,c),h=l.Uri.parse(`${u.projectRoot}/${g}${re}`).with({scheme:ie});this.dbtTerminal.debug("Notebook","opening notebook",h);const d=await l.workspace.openNotebookDocument(h);await l.window.showNotebookDocument(d)}catch(c){const u=c instanceof se.PythonException?c.exception.message:c.message;this.dbtTerminal.error(`${m.TelemetryEvents["Notebook/LaunchError"]}`,u,c),l.window.showErrorMessage(m.extendErrorWithSupportLinks(u))}})}sendMessageToPreloadScript(e){}getRandomString=()=>(Math.random()+1).toString(36).substring(7);genUniqueId(e){return`${e.document.languageId.replace(/-/g,"_")}_${this.getRandomString()}`}async updateCellId(e,t){if(!!!l.window.visibleNotebookEditors.find(r=>r.notebook.uri.fsPath===t.uri.fsPath))return;const s=[];if(e.forEach(r=>{let i=r.metadata.cellId;if(!i){i=this.genUniqueId(r);const a={...r.metadata,cellId:i},c=l.NotebookEdit.updateCellMetadata(r.index,a);s.push(c)}this._onNotebookCellEvent.fire({cellId:i,notebook:t.uri.fsPath,event:"update",fragment:r.document.uri.fragment,languageId:r.document.languageId})}),s.length>0){const r=new l.WorkspaceEdit;r.set(t.uri,s),await l.workspace.applyEdit(r)}}async onNotebookClose(e){if(e.notebookType!==A)return;const t=await this.clientMapper.getNotebookClient(e.uri);t&&t.dispose(),this.dbtTerminal.debug("Notebookcontroller",`notebook closed: ${e.uri.fsPath}`,e.isUntitled),e.isUntitled&&await l.workspace.fs.delete(e.uri)}async onDidChangeSelectedNotebooks({notebook:e,selected:t}){this.dbtTerminal.debug("Notebookcontroller",`notebook controller selected: ${e.uri.fsPath}`,t);const o=e.uri.toString();t?this.associatedNotebooks.add(o):this.associatedNotebooks.delete(o)}async onNotebookOpen(e){var r;if(e.notebookType!==A)return;this.controller.updateNotebookAffinity(e,l.NotebookControllerAffinity.Default),this.dbtTerminal.debug("Notebookcontroller",`notebook open and controller associated: ${e.uri.fsPath}`);const t=await this.clientMapper.initializeNotebookClient(e.uri),o=await t.getKernel();if(!(o!=null&&o.realKernel))throw new Error("Unable to initialize kernel");this.disposables.push(t.postMessage(i=>{this.sendMessageToPreloadScript(i)},this));const s=e.getCells();await this.updateCellId(s,e);try{await this.waitForControllerAssociation(e)}catch{this.dbtTerminal.warn("Notebookcontroller",`Controller association timeout for ${e.uri.fsPath}. Proceeding anyway.`),this.associatedNotebooks.add(e.uri.toString())}(r=e.metadata)!=null&&r.autoRun&&await this._executeAll(e.getCells(),e,this.controller)}async waitForControllerAssociation(e,t=2e3){const o=Date.now();for(;!this.isControllerAssociatedWithNotebook(e);){if(Date.now()-o>t)throw new Error("Timeout waiting for controller association");await new Promise(s=>setTimeout(s,500))}}isControllerAssociatedWithNotebook(e){return this.associatedNotebooks.has(e.uri.toString())}dispose(){this.disposables.forEach(e=>e.dispose())}async _executeAll(e,t,o){var i,a;const s=await this.queryManifestService.getOrPickProjectFromWorkspace();if(!s){l.window.showErrorMessage("No dbt project selected.");return}(i=t.metadata)!=null&&i.dependencies&&await this.notebookDependencies.verifyAndInstallDependenciesIfNeeded(t.metadata.dependencies,s);const r=await this.clientMapper.getNotebookClient(t.uri);await this.updateContextVariablesInKernel(s,r,e[0]);for(const c of e)await this._doExecution(c,t,(a=t.metadata)==null?void 0:a.isUserNotebook,o,s,r)}filterIPyWidgets(e,t=!1){return e.map(o=>{const r=o.items.find(i=>i.mime==="application/vnd.jupyter.widget-view+json")?t?[l.NotebookCellOutputItem.text("IPyWidgets not supported")]:[]:o.items;return new l.NotebookCellOutput(r)})}updateContextVariablesInKernel(e,t,o){return t.executePython(`
|
|
10
|
+
`;const t=await this.python.lock(a=>a`notebook_kernel.get_connection_file()`),o=JSON.parse(le.readFileSync(t,{encoding:"utf-8"})),s=await this.python.lock(a=>a`notebook_kernel.get_session_id()`),r={connection:o,pid:s},i=new Ke(r,x(),x(),{name:o.kernel_name,id:x(),language:"python",argv:[],display_name:o.kernel_name,resources:{}});this.kernel=i,this.disposables.push(i.postMessage(a=>this._postMessageEmitter.fire(a))),this.dbtTerminal.log(`Notebook Kernel started with PID: ${s} connection: ${JSON.stringify(o)}`),this.getDependenciesVersion()}catch(t){let o=t.message;t instanceof se.PythonException&&(o=t.exception.message),this.dbtTerminal.error(h.TelemetryEvents["Notebook/KernelInitializationError"],o,t),l.window.showErrorMessage(o)}this.isInitializing=!1}onKernelSocketResponse(e){var t;(t=this.kernel)==null||t.onKernelSocketResponse(e)}async storeContext(e){this.dbtTerminal.log(`storeContext: ${e}`),await this.python.lock(t=>t`notebook_kernel.store_context(${e})`)}async storeDataInKernel(e,t){try{return this.dbtTerminal.log(`storeDataInKernel: ${e}`),await this.python.lock(o=>o`notebook_kernel.store_sql_result(${e}, ${JSON.stringify(t)})`),!0}catch(o){throw this.dbtTerminal.error(h.TelemetryEvents["Notebook/StoreDataInKernelError"],o.exception.message,o),o}}async registerCommTarget(e){if(this.registerdCommTargets.has(e)){this.dbtTerminal.log(`registerCommTarget already registered: ${e}`);return}this.registerdCommTargets.add(e),this.dbtTerminal.log(`registerCommTarget registering: ${e}`);const t=await this.getKernel();if(!t)throw this.registerdCommTargets.delete(e),new Error("Kernel not found for registering comm target");return t.realKernel.registerCommTarget(e,(o,s)=>{this.dbtTerminal.log(`registerCommTarget registered: ${e}`,o,s)})}async getPythonCodeByType(e,t){return this.dbtTerminal.debug("getPythonCodeByType",e,t),await this.python.lock(o=>o`notebook_kernel.get_python_code_by_type(${e}, ${t})`)}async executePython(e,t,o){return new Promise((s,r)=>{var a,c;if(!((c=(a=this.kernel)==null?void 0:a.rawKernel)!=null&&c.realKernel)){r(new Error("Kernel not found"));return}(async()=>{try{const d=t.metadata.cellId;this.dbtTerminal.log(`Executing python code in cell: ${d}`,e);const p=require("@jupyterlab/services");this.dbtTerminal.log("kernel status",this.kernel.rawKernel.realKernel.status);const m=await this.kernel.rawKernel.realKernel.requestExecute({code:e,silent:!1,stop_on_error:!1,allow_stdin:!0,store_history:!0},!1,{cellId:t.document.uri.toString()});if(!m){r(new Error("Unknown request error"));return}m.onReply=u=>{if(t.document.isClosed){m.dispose();return}const y=u.content;y.payload&&y.payload.forEach(k=>{if(k.data&&Object.prototype.hasOwnProperty.call(k.data,"text/plain")){const N=this.addToCellData({output_type:"stream",text:k.data["text/plain"].toString(),name:"stdout",metadata:{},execution_count:y.execution_count},u,t);N&&o(N)}})};const g=[];m.done.finally(()=>{m.dispose(),s(g.filter(u=>!!u))}),m.onStdin=u=>{this.dbtTerminal.log("onStdin",u)},m.onIOPub=u=>{if(p.KernelMessage.isCommOpenMsg(u))this.handleCommOpen(u);else if(p.KernelMessage.isExecuteResultMsg(u))g.push(this.handleExecuteResult(u,t));else if(p.KernelMessage.isExecuteInputMsg(u))this.handleExecuteInput(u);else if(p.KernelMessage.isStatusMsg(u)){const y=u;this.handleStatusMessage(y)}else if(p.KernelMessage.isStreamMsg(u)){const y=this.handleStreamMessage(u,t);y==null||y.forEach(k=>{g.push(k)})}else p.KernelMessage.isDisplayDataMsg(u)?g.push(this.handleDisplayData(u,t)):p.KernelMessage.isUpdateDisplayDataMsg(u)?this.handleUpdateDisplayDataMessage(u):p.KernelMessage.isClearOutputMsg(u)?this.handleClearOutput(u):p.KernelMessage.isErrorMsg(u)?g.push(this.handleError(u,t)):p.KernelMessage.isCommMsgMsg(u)?this.handleCommMsg(u):p.KernelMessage.isCommCloseMsg(u)||this.dbtTerminal.warn("NotebookUnknownIOPubMessage",`Unknown message ${u.header.msg_type} : hasData=${"data"in u.content}`)}}catch(d){r(d)}})().catch(r)})}handleUpdateDisplayDataMessage(e){if(this.dbtTerminal.log("handleUpdateDisplayDataMessage",e),!e.content.transient.display_id){this.dbtTerminal.warn("NotebookUpdateDisplayDataMessageReceivedButNoDisplayId","Update display data message received, but no display id",!1,e.content);return}}handleCommOpen(e){var r;const t=e.content,o=(r=t.data)==null?void 0:r.state;o&&o._model_module==="@jupyter-widgets/output"&&o._model_name==="OutputModel"&&this.commIdsMappedToWidgetOutputModels.add(t.comm_id)}handleCommMsg(e){const t=e.content,o=t.data,s=o.method,r=o.state;if(s==="update"&&(r!=null&&r.msg_id)){const i=r.msg_id,a=t.comm_id,c=this.outputsAreSpecificToAWidget.find(d=>d.handlingCommId===a);c?(c.msgIdsToSwallow=i,c.clearOutputOnNextUpdateToOutput=!0):this.outputsAreSpecificToAWidget.push({handlingCommId:a,msgIdsToSwallow:i,clearOutputOnNextUpdateToOutput:!0})}}handleExecuteResult(e,t){return this.addToCellData({output_type:"execute_result",data:e.content.data,metadata:e.content.metadata,transient:e.content.transient,execution_count:e.content.execution_count},e,t)}addToCellData(e,t,o){if(e.data&&typeof e.data=="object"&&U in e.data){const i=e.data[U];if(i&&"model_id"in i){const a=V.modelIdsOwnedByCells.get(o)||new Set;a.add(i.model_id),V.modelIdsOwnedByCells.set(o,a)}}const s=G(e);if(o.document.isClosed)return;this.dbtTerminal.log(o.document.uri.fsPath,`Update output with mimes ${s.items.map(i=>i.mime).toString()}`);const r=j(t);return this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===r&&s.items.every(i=>this.canMimeTypeBeRenderedByWidgetManager(i))||this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===r&&this.dbtTerminal.warn("NotebookAddToCellData","unknown operation"),s}canMimeTypeBeRenderedByWidgetManager(e){const t=e.mime;if(t===W.stderr||t===W.stdout||t===W.error)return!0;if(t===U){const o=JSON.parse(new TextDecoder().decode(e.data));return!(typeof o.model_id=="string"&&this.commIdsMappedToWidgetOutputModels.has(o.model_id))}return!t.startsWith("application/vnd")}handleExecuteInput(e){}handleStatusMessage(e){}handleStreamMessage(e,t){var s;if(j(e)&&this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===j(e))return;const o=e.content.name==="stdout"?l.NotebookCellOutputItem.stdout("").mime:l.NotebookCellOutputItem.stderr("").mime;if(!this.streamsReAttachedToExecutingCell&&!this.lastUsedStreamOutput&&t.outputs.length&&t.outputs[t.outputs.length-1].items.length>=1&&t.outputs[t.outputs.length-1].items.every(r=>r.mime===o)&&(this.lastUsedStreamOutput={output:t.outputs[0],stream:e.content.name}),this.streamsReAttachedToExecutingCell=!0,((s=this.lastUsedStreamOutput)==null?void 0:s.stream)===e.content.name)return[G({output_type:"stream",name:e.content.name,text:e.content.text}),this.lastUsedStreamOutput.output];{const r=_e(B(e.content.text));return[G({output_type:"stream",name:e.content.name,text:r})]}}handleDisplayData(e,t){const o={output_type:"display_data",data:Te(e.content.data),metadata:e.content.metadata,transient:e.content.transient};return this.addToCellData(o,e,t)}handleClearOutput(e){if(this.outputsAreSpecificToAWidget.length&&this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].msgIdsToSwallow===j(e)){e.content.wait&&this.outputsAreSpecificToAWidget.length&&(this.outputsAreSpecificToAWidget[this.outputsAreSpecificToAWidget.length-1].clearOutputOnNextUpdateToOutput=!0);return}}handleError(e,t){const o=e.content.traceback;this.dbtTerminal.log(`Traceback for error ${o}`);const s={output_type:"error",ename:e.content.ename,evalue:e.content.evalue,traceback:o};return this.addToCellData(s,e,t)}}var ze=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,He=(n,e,t,o)=>{for(var s=o>1?void 0:o?Ge(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&ze(e,t,s),s};exports.NotebookDependencies=class{constructor(e,t,o,s){this.dbtTerminal=e,this.telemetry=t,this.commandProcessExecutionFactory=o,this.pythonEnvironment=s}async checkPythonDependencies(e){const t=[];for(const o of e){const s=["-m","pip","show",o],{stderr:r}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:s,cwd:h.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();r&&t.push(o)}return t}checkDbtDependencies(e,t){return e.map(o=>{try{return t.findPackageVersion(o),null}catch{return o}}).filter(Boolean)}async installMissingPythonPackages(e,t){const o=await this.checkPythonDependencies(e);if(!o.length)return;if(this.dbtTerminal.debug("Notebook","asking user to install missing python dependencies for notebook",o),await l.window.showInformationMessage(`You need the following python packages to use this notebook: ${o.join(", ")}`,"Install","Cancel")!=="Install")throw this.telemetry.sendTelemetryEvent(h.TelemetryEvents["Notebook/DependenciesInstallCancelled"]),new Error("User cancelled python package installation");return this.dbtTerminal.debug("Notebook","installing required dependencies",o),await l.window.withProgress({title:"Installing python packages...",location:l.ProgressLocation.Notification,cancellable:!1},async()=>{try{const r=["-m","pip","install",...o],{stdout:i,stderr:a}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:r,cwd:h.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();if(!i.includes("Successfully installed")&&!i.includes("Requirement already satisfied")&&a)throw new Error(a);return this.dbtTerminal.log("Notebook dependencies have been installed successfully."),this.telemetry.sendTelemetryEvent(h.TelemetryEvents["Notebook/DependenciesInstalled"]),await t.initialize(),!0}catch(r){this.telemetry.sendTelemetryError(h.TelemetryEvents["Notebook/DependenciesInstallError"],r),l.window.showErrorMessage(h.extendErrorWithSupportLinks(r.message))}})}async installMissingDbtPackages(e,t){const o=this.checkDbtDependencies(e.map(i=>`${i.name}`),t);if(!o.length)return;const s=e.filter(i=>i.name?o.includes(i.name):!1);if(this.dbtTerminal.debug("Notebook","asking user to install missing dbt dependencies for notebook",s),await l.window.showInformationMessage(`You need following dbt packages to use this notebook: ${s.map(i=>`${i.package}`).join(", ")}`,"Install","Cancel")!=="Install")throw this.telemetry.sendTelemetryEvent(h.TelemetryEvents["Notebook/DependenciesInstallCancelled"]),new Error("User cancelled dbt package installation");return await l.window.withProgress({title:"Installing dbt packages...",location:l.ProgressLocation.Notification,cancellable:!1},async()=>{try{const i=s.map(c=>`${c.package}@${c.version}`);this.dbtTerminal.debug("Notebook","installing dbt packages",i),await t.installDbtPackages(i),await t.initialize();const a=this.checkDbtDependencies(e.map(c=>`${c.name}`),t);if(a.length)throw new Error(`Failed to install dbt packages ${a.join(", ")}`);return this.dbtTerminal.log("Notebook dependencies have been installed successfully."),this.telemetry.sendTelemetryEvent(h.TelemetryEvents["Notebook/DependenciesInstalled"]),!0}catch(i){this.telemetry.sendTelemetryError(h.TelemetryEvents["Notebook/DependenciesInstallError"],i),l.window.showErrorMessage(h.extendErrorWithSupportLinks(i.message))}})}async verifyAndInstallDependenciesIfNeeded(e,t){this.dbtTerminal.debug("NotebookDependencies","verifying required dependencies",e),await Promise.all([this.validateAndInstallNotebookDependencies(),this.installMissingPythonPackages(e.filter(o=>o.type==="python").map(o=>o.package),t),this.installMissingDbtPackages(e.filter(o=>o.type==="dbt"),t)])}async getDependenciesVersion(){const e=["-m","jupyter","--version"],{stdout:t,stderr:o}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:e,cwd:h.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();if(!t.includes("Successfully installed")&&!t.includes("Requirement already satisfied")&&o)throw new Error(o);const s=t.split(`
|
|
11
|
+
`),r={};return s.forEach(i=>{const[a,c]=i.split(":").map(d=>d.trim());a&&c&&(r[a]=c)}),r}async validateAndInstallNotebookDependencies(){try{if(await this.notebookDependenciesAreInstalled())return this.dbtTerminal.log("Notebook dependencies are already installed."),!0;if(await l.window.showInformationMessage("You need [ipykernel](https://pypi.org/project/ipykernel/) and [jupyter_client](https://github.com/jupyter/jupyter_client) to use the notebook","Install","Cancel")!=="Install")return this.telemetry.sendTelemetryEvent(h.TelemetryEvents["Notebook/DependenciesInstallCancelled"]),!1;await l.window.withProgress({title:"Installing required dependencies...",location:l.ProgressLocation.Notification,cancellable:!1},async()=>{try{const o=["-m","pip","install","ipykernel","jupyter_client","jupyter_contrib_nbextensions","ipywidgets"],{stdout:s,stderr:r}=await this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:o,cwd:h.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}).completeWithTerminalOutput();if(!s.includes("Successfully installed")&&!s.includes("Requirement already satisfied")&&r)throw new Error(r);return this.dbtTerminal.log("Notebook dependencies have been installed successfully."),this.telemetry.sendTelemetryEvent(h.TelemetryEvents["Notebook/DependenciesInstalled"]),!0}catch(o){return this.telemetry.sendTelemetryError(h.TelemetryEvents["Notebook/DependenciesInstallError"],o),l.window.showErrorMessage(h.extendErrorWithSupportLinks(o.message)),!1}})&&await l.window.showInformationMessage("Notebook dependencies installed. Please reload the window to use the notebook.","Reload Window")==="Reload Window"&&l.commands.executeCommand("workbench.action.reloadWindow")}catch(e){throw this.dbtTerminal.error(h.TelemetryEvents["Notebook/DependenciesInstallError"],e.message,e),e}}async notebookDependenciesAreInstalled(){try{const e=this.commandProcessExecutionFactory.createCommandProcessExecution({command:this.pythonEnvironment.pythonPath,args:["-c","import jupyter_client"],cwd:h.getFirstWorkspacePath(),envVars:this.pythonEnvironment.environmentVariables}),{stderr:t}=await e.complete();if(t)throw new Error(t);return!0}catch{return!1}}};exports.NotebookDependencies=He([h.provideSingleton(exports.NotebookDependencies)],exports.NotebookDependencies);var Ye=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(n,e,t,o)=>{for(var s=o>1?void 0:o?Je(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&Ye(e,t,s),s};const Xe=require("path");exports.DatapilotNotebookController=class{constructor(e,t,o,s,r,i){this.clientMapper=e,this.queryManifestService=t,this.telemetry=o,this.dbtTerminal=s,this.notebookDependencies=r,this.altimate=i,this.controller=l.notebooks.createNotebookController(this.id,O,this.label),this.controller.supportedLanguages=de,this.controller.supportsExecutionOrder=!0,this.controller.executeHandler=this._executeAll.bind(this),this.disposables.push(l.workspace.onDidChangeNotebookDocument(a=>{a.contentChanges.forEach(async c=>{c.addedCells&&await this.updateCellId(a.notebook.getCells(),a.notebook),c.removedCells&&c.removedCells.forEach(d=>{this._onNotebookCellEvent.fire({cellId:d.metadata.cellId,notebook:a.notebook.uri.fsPath,result:void 0,event:"delete",fragment:d.document.uri.fragment,languageId:d.document.languageId})})})})),this.disposables.push(this.controller),this.controller.onDidChangeSelectedNotebooks(this.onDidChangeSelectedNotebooks,this,this.disposables),this.disposables.push(l.workspace.onDidOpenNotebookDocument(async a=>{await this.onNotebookOpen(a)})),this.disposables.push(l.workspace.onDidCloseNotebookDocument(async a=>{await this.onNotebookClose(a)}))}id="DatapilotNotebookController";label="Datapilot";_onNotebookCellEvent=new l.EventEmitter;onNotebookCellChangeEvent=this._onNotebookCellEvent.event;disposables=[this._onNotebookCellEvent];associatedNotebooks=new Set;executionOrder=0;controller;async getNotebookByTemplate(e){var o;return this.dbtTerminal.debug("Notebook","getting notebook by template",e),e?(o=(await this.altimate.getPreConfiguredNotebooks()).find(s=>s.name===e))==null?void 0:o.data:(this.dbtTerminal.debug("Notebook","sending blank notebook"),{cells:[{cell_type:l.NotebookCellKind.Markup,source:["### Welcome to your new dbt Power User Notebook!","> Note: Remember, you can delete any or all of these example cells to start fresh with your own work. Enjoy exploring and analyzing your data!","#### Documentation and Feedback","For more detailed information on how to use this notebook and the dbt Power User extension, please refer to our documentation:","[dbt Power User Documentation](https://docs.myaltimate.com/govern/notebooks/)"," ","We value your feedback! If you have any suggestions, encounter issues, or want to share your experience, please let us know:","[Share Feedback](https://docs.google.com/forms/d/e/1FAIpQLScwN3wRTAniQzvcO6Hn3jC0WtBoFE2NP4X_6qGQ09IZKZ3Ojw/viewform?usp=sf_link)"," ","Happy analyzing with your new dbt Power User Notebook!"," ","This notebook allows you to combine Jinja SQL queries, Python code, and Markdown text. Let's explore each of these features.","##### 1. Jinja SQL Queries","You can write and execute Jinja SQL queries directly in this notebook. Here's an example:"],languageId:"markdown",metadata:{}},{cell_type:l.NotebookCellKind.Code,source:["select * from {{ ref('your_model_name') }}","{# Replace 'your_model_name' with the name of your dbt model. #}"],languageId:ue,metadata:{cellId:"jinja_sql_0"}},{cell_type:l.NotebookCellKind.Markup,source:["##### 2. Python Code","You can also write and execute Python code on top of the results of previous `jinja-sql` cell in this notebook. Here's a simple example:"],languageId:"markdown",metadata:{}},{cell_type:l.NotebookCellKind.Code,source:["import pandas as pd","from IPython.display import display, HTML","from ydata_profiling import ProfileReport","from io import StringIO","","# Extract the data field","# NOTE: we use the cell id from previous cell to extract the data","data = cell_jinja_sql_0['data']","","# Create a DataFrame","df = pd.DataFrame(data)","","# Display the DataFrame","# display(HTML(df.to_html()))","",'profile = ProfileReport(df, title="Profiling Report")',"profile.to_notebook_iframe()"],languageId:"python",metadata:{}},{cell_type:l.NotebookCellKind.Markup,source:["This Python code creates a profile report of your query results. You can customize the code to suit your needs.","##### 3. Markdown Text","As you can see, you can use Markdown to structure your notebook with headings, lists, and more. You can also use it to add explanations and documentation to your queries and code.","##### Tips for Using This Notebook","- Use Jinja cells for your dbt model queries and data exploration","- Use Python cells for data analysis, visualization, and custom transformations. The jinja data can be referenced using the cell id","- Use Markdown cells to explain your process, document your findings, and create a narrative for your analysis"],languageId:"markdown",metadata:{}}]})}async modelTestSuggestions(e){this.dbtTerminal.log("modelTestSuggestions",e)}async generateDbtSourceYaml(e){this.dbtTerminal.log("generateDbtSourceYaml",e)}async generateDbtDbtModelSql(e){this.dbtTerminal.log("generateDbtDbtModelSql",e)}async generateDbtDbtModelYaml(e){this.dbtTerminal.log("generateDbtDbtModelYaml",e)}async generateDbtDbtModelCTE(e){this.dbtTerminal.log("generateDbtDbtModelCTE",e)}async extractExposuresFromMetabase(e){this.dbtTerminal.log("extractExposuresFromMetabase",e)}async extractExposuresFromTableau(e){this.dbtTerminal.log("extractExposuresFromTableau",e)}async getFileName(e,t){if(e)return e;const o=Le();if((await this.altimate.addNotebook({name:o,description:"",data:t?{...t,metadata:{...t.metadata||{},isDraft:!0}}:{},tags_list:[]})).ok&&(await this.altimate.getNotebooks(o)).length>0)return o}async createNotebook(e){var i;const{notebookId:t,template:o,context:s={},notebookSchema:r}=e||{};if(this.dbtTerminal.info(h.TelemetryEvents["Notebook/Launch"],"creating notebook",!0,e),!s.model&&((i=l.window.activeTextEditor)!=null&&i.document.uri.fsPath.endsWith(".sql"))){const a=Xe.basename(l.window.activeTextEditor.document.uri.fsPath,".sql"),c=l.window.activeTextEditor.document.getText();s.model=a,s.query=c}l.window.withProgress({location:l.ProgressLocation.Notification,title:"Launching notebook...",cancellable:!1},async()=>{var a;try{const c=r||(t?null:await this.getNotebookByTemplate(o)),d=await this.queryManifestService.getOrPickProjectFromWorkspace();if(!d){l.window.showErrorMessage("No dbt project selected.");return}if((a=c==null?void 0:c.metadata)!=null&&a.dependencies&&await this.notebookDependencies.verifyAndInstallDependenciesIfNeeded(c.metadata.dependencies,d),s&&c)for(const u in s)Object.prototype.hasOwnProperty.call(s,u)&&typeof s[u]=="string"&&(c.cells[0].source=c.cells[0].source.map(y=>y.replace(`%_${u}_%`,s[u])));const p=await this.getFileName(t,c),m=l.Uri.parse(`${d.projectRoot}/${p}${re}`).with({scheme:ie});this.dbtTerminal.debug("Notebook","opening notebook",m);const g=await l.workspace.openNotebookDocument(m);await l.window.showNotebookDocument(g)}catch(c){const d=c instanceof se.PythonException?c.exception.message:c.message;this.dbtTerminal.error(`${h.TelemetryEvents["Notebook/LaunchError"]}`,d,c),l.window.showErrorMessage(h.extendErrorWithSupportLinks(d))}})}sendMessageToPreloadScript(e){}getRandomString=()=>(Math.random()+1).toString(36).substring(7);genUniqueId(e){return`${e.document.languageId.replace(/-/g,"_")}_${this.getRandomString()}`}async updateCellId(e,t){if(!!!l.window.visibleNotebookEditors.find(r=>r.notebook.uri.fsPath===t.uri.fsPath))return;const s=[];if(e.forEach(r=>{let i=r.metadata.cellId;if(!i){i=this.genUniqueId(r);const a={...r.metadata,cellId:i},c=l.NotebookEdit.updateCellMetadata(r.index,a);s.push(c)}this._onNotebookCellEvent.fire({cellId:i,notebook:t.uri.fsPath,event:"update",fragment:r.document.uri.fragment,languageId:r.document.languageId})}),s.length>0){const r=new l.WorkspaceEdit;r.set(t.uri,s),await l.workspace.applyEdit(r)}}async onNotebookClose(e){if(e.notebookType!==O)return;const t=await this.clientMapper.getNotebookClient(e.uri);t&&t.dispose(),this.dbtTerminal.debug("Notebookcontroller",`notebook closed: ${e.uri.fsPath}`,e.isUntitled),e.isUntitled&&await l.workspace.fs.delete(e.uri)}async onDidChangeSelectedNotebooks({notebook:e,selected:t}){this.dbtTerminal.debug("Notebookcontroller",`notebook controller selected: ${e.uri.fsPath}`,t);const o=e.uri.toString();t?this.associatedNotebooks.add(o):this.associatedNotebooks.delete(o)}async onNotebookOpen(e){var r;if(e.notebookType!==O)return;this.controller.updateNotebookAffinity(e,l.NotebookControllerAffinity.Default),this.dbtTerminal.debug("Notebookcontroller",`notebook open and controller associated: ${e.uri.fsPath}`);const t=await this.clientMapper.initializeNotebookClient(e.uri),o=await t.getKernel();if(!(o!=null&&o.realKernel))throw new Error("Unable to initialize kernel");this.disposables.push(t.postMessage(i=>{this.sendMessageToPreloadScript(i)},this));const s=e.getCells();await this.updateCellId(s,e);try{await this.waitForControllerAssociation(e)}catch{this.dbtTerminal.warn("Notebookcontroller",`Controller association timeout for ${e.uri.fsPath}. Proceeding anyway.`),this.associatedNotebooks.add(e.uri.toString())}(r=e.metadata)!=null&&r.autoRun&&await this._executeAll(e.getCells(),e,this.controller)}async waitForControllerAssociation(e,t=2e3){const o=Date.now();for(;!this.isControllerAssociatedWithNotebook(e);){if(Date.now()-o>t)throw new Error("Timeout waiting for controller association");await new Promise(s=>setTimeout(s,500))}}isControllerAssociatedWithNotebook(e){return this.associatedNotebooks.has(e.uri.toString())}dispose(){this.disposables.forEach(e=>e.dispose())}async _executeAll(e,t,o){var i,a;const s=await this.queryManifestService.getOrPickProjectFromWorkspace();if(!s){l.window.showErrorMessage("No dbt project selected.");return}(i=t.metadata)!=null&&i.dependencies&&await this.notebookDependencies.verifyAndInstallDependenciesIfNeeded(t.metadata.dependencies,s);const r=await this.clientMapper.getNotebookClient(t.uri);await this.updateContextVariablesInKernel(s,r,e[0]);for(const c of e)await this._doExecution(c,t,(a=t.metadata)==null?void 0:a.isUserNotebook,o,s,r)}filterIPyWidgets(e,t=!1){return e.map(o=>{const r=o.items.find(i=>i.mime==="application/vnd.jupyter.widget-view+json")?t?[l.NotebookCellOutputItem.text("IPyWidgets not supported")]:[]:o.items;return new l.NotebookCellOutput(r)})}updateContextVariablesInKernel(e,t,o){return t.executePython(`
|
|
12
12
|
manifest_path="${e.getManifestPath()}"
|
|
13
13
|
project_name="${e.getProjectName()}"
|
|
14
|
-
`,o,()=>{})}async _doExecution(e,t,o,s,r,i){this.dbtTerminal.debug("Notebook","executing cell",e.index,t.uri.fsPath);let a;try{const c=[];switch(a=s.createNotebookCellExecution(e),a.executionOrder=++this.executionOrder,a.start(Date.now()),a.token.onCancellationRequested(
|
|
14
|
+
`,o,()=>{})}async _doExecution(e,t,o,s,r,i){this.dbtTerminal.debug("Notebook","executing cell",e.index,t.uri.fsPath);let a;try{const c=[];switch(a=s.createNotebookCellExecution(e),a.executionOrder=++this.executionOrder,a.start(Date.now()),a.token.onCancellationRequested(d=>{a==null||a.end(!0,Date.now())}),a.clearOutput(),e.document.languageId){case"markdown":break;case"python":{this.telemetry.startTelemetryEvent(h.TelemetryEvents["Notebook/Execute"],{language:e.document.languageId});const d=await(i==null?void 0:i.executePython(e.document.getText(),e,p=>{a==null||a.appendOutput(this.filterIPyWidgets([p],o))}));d&&a.appendOutput(this.filterIPyWidgets(d,o))}break;case"jinja-sql":case"sql":{this.dbtTerminal.debug("Notebook","executing sql",e.document.getText()),this.telemetry.startTelemetryEvent(h.TelemetryEvents["Notebook/Execute"],{language:e.document.languageId});const{metadata:d}=e;if((d==null?void 0:d.execution_type)==="compile"){const p=await r.unsafeCompileQuery(e.document.getText());a.appendOutput(new l.NotebookCellOutput([l.NotebookCellOutputItem.text(p,d==null?void 0:d.output_mime_type)]))}else{const p=await r.executeSQL(e.document.getText(),"",!0);this._onNotebookCellEvent.fire({cellId:e.metadata.cellId,notebook:t.uri.fsPath,result:p,event:"add",languageId:e.document.languageId}),o||(c.push(l.NotebookCellOutputItem.json(p,"application/perspective-json")),a.appendOutput(new l.NotebookCellOutput(c))),await i.storeDataInKernel(e.metadata.cellId,p)}}break;default:l.window.showErrorMessage(`Language: ${e.document.languageId} not supported`);break}this.telemetry.endTelemetryEvent(h.TelemetryEvents["Notebook/Execute"],{language:e.document.languageId}),a.end(!0,Date.now())}catch(c){this.dbtTerminal.error("Notebook",`Error executing cell: ${c.message}`,c,!1),a==null||a.replaceOutput([new l.NotebookCellOutput([l.NotebookCellOutputItem.error(c)])]),this.telemetry.endTelemetryEvent(h.TelemetryEvents["Notebook/Execute"],c,{language:e.document.languageId}),a==null||a.end(!1,Date.now())}}};exports.DatapilotNotebookController=Qe([h.provideSingleton(exports.DatapilotNotebookController)],exports.DatapilotNotebookController);const Ze={notebooks:[{name:"Profile your query",description:"Notebook to profile your query",created_at:new Date().toISOString(),updated_at:new Date().toISOString(),id:"1",data:{cells:[{cell_type:l.NotebookCellKind.Code,source:["{{context.query}}"],languageId:"jinja-sql",metadata:{cellId:"jinja_sql_cu6pt"}},{cell_type:l.NotebookCellKind.Code,source:["import pandas as pd","from IPython.display import display, HTML","from ydata_profiling import ProfileReport","from io import StringIO","","# Extract the data field","data = cell_jinja_sql_cu6pt['data']","","# Create a DataFrame","df = pd.DataFrame(data)","","# Display the DataFrame","# display(HTML(df.to_html()))","",'profile = ProfileReport(df, title="Profiling Report")',"profile.to_notebook_iframe()"],languageId:"python",metadata:{}}],metadata:{dependencies:["pandas","ydata_profiling"],autoRun:!0}},tags:["profile"]}]};var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,ot=(n,e,t,o)=>{for(var s=o>1?void 0:o?tt(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&et(e,t,s),s};const ne=require("path");exports.NotebookFileSystemProvider=class{constructor(e,t){this.dbtTerminal=e,this.altimate=t}_emitter=new l.EventEmitter;onDidChangeFile=this._emitter.event;notebookDataMap=new Map;watch(e,t){return new l.Disposable(()=>{})}stat(e){return{type:l.FileType.File,ctime:Date.now(),mtime:Date.now(),size:0}}readDirectory(e){return[]}createDirectory(e){}async getNotebookData(e){if(this.notebookDataMap.has(e))return this.notebookDataMap.get(e);const t=await this.altimate.getNotebooks(e)||[];return t.length?t[0]:null}async readFile(e){const t=this.getFileNameFromUri(e),o=await this.getNotebookData(t),s=(o==null?void 0:o.data)||{};return"cells"in s&&"metadata"in s&&(s.metadata?s.metadata={...s.metadata,id:o==null?void 0:o.id}:s.metadata={id:o==null?void 0:o.id}),o&&this.notebookDataMap.set(t,o),new TextEncoder().encode(JSON.stringify(s))}async writeFile(e,t,o){await this.customSave(e,t)}delete(e,t){const o=e.with({path:ne.posix.dirname(e.path)});this._emitter.fire([{type:l.FileChangeType.Changed,uri:o},{uri:e,type:l.FileChangeType.Deleted}])}rename(e,t,o){this._emitter.fire([{type:l.FileChangeType.Deleted,uri:e},{type:l.FileChangeType.Created,uri:t}])}getFileNameFromUri(e){return ne.basename(e.fsPath,re)}async customSave(e,t){var o;try{console.log("custom save",e,new TextDecoder().decode(t));const s=(o=l.window.activeNotebookEditor)==null?void 0:o.notebook;if(!s)return this.dbtTerminal.warn(h.TelemetryEvents["Notebook/SaveError"],"No active notebook found"),!1;this.dbtTerminal.log("saving notebook",s);const{name:r}=s.metadata;return await this.saveNotebook(s,r),this._emitter.fire([{type:l.FileChangeType.Changed,uri:e}]),!0}catch(s){this.dbtTerminal.error(h.TelemetryEvents["Notebook/SaveError"],s.message,s),l.window.showErrorMessage(h.extendErrorWithSupportLinks(`Failed to save notebook. Error: ${s.message}`))}return!1}async saveNotebook(e,t){try{const o=te(e,t);this.dbtTerminal.log("saving notebook",t,o),await this.altimate.updateNotebook(e.metadata.id,{name:t,description:"",data:o,tags_list:[]}),this.dbtTerminal.log("notebook saved",t,o);const s=this.getFileNameFromUri(e.uri),r=this.notebookDataMap.get(s);return r&&(r.data=te(e,t,!0),this.notebookDataMap.set(s,r)),o}catch(o){this.dbtTerminal.error(h.TelemetryEvents["Notebook/SaveError"],o.message,o),l.window.showErrorMessage(h.extendErrorWithSupportLinks(`Failed to save notebook. Error: ${o.message}`))}}};exports.NotebookFileSystemProvider=ot([h.provideSingleton(exports.NotebookFileSystemProvider)],exports.NotebookFileSystemProvider);var nt=Object.defineProperty,st=Object.getOwnPropertyDescriptor,rt=(n,e,t,o)=>{for(var s=o>1?void 0:o?st(e,t):e,r=n.length-1,i;r>=0;r--)(i=n[r])&&(s=(o?i(e,t,s):i(s))||s);return o&&s&&nt(e,t,s),s};exports.NotebookProviders=class{constructor(e,t,o,s){this.notebookProvider=e,this.notebookController=t,this.notebookFileSystemProvider=o,this.dbtTerminal=s,this.disposables.push(l.workspace.onDidChangeConfiguration(r=>{r.affectsConfiguration("dbt.enableNotebooks")&&this.bindNotebookActions()})),this.bindNotebookActions()}disposables=[];bindNotebookActions(){l.workspace.getConfiguration("dbt").get("enableNotebooks",!1)&&(this.dbtTerminal.log("Notebooks enabled, binding actions"),this.disposables.push(l.notebooks.registerNotebookCellStatusBarItemProvider(O,new ce),l.workspace.registerNotebookSerializer(O,this.notebookProvider,{}),this.notebookController),this.disposables.push(l.workspace.registerFileSystemProvider(ie,this.notebookFileSystemProvider,{isCaseSensitive:!0,isReadonly:!1})))}dispose(){for(;this.disposables.length;){const e=this.disposables.pop();e&&e.dispose()}}};exports.NotebookProviders=rt([h.provideSingleton(exports.NotebookProviders)],exports.NotebookProviders);const R=n=>n==="bigquery"?"RAND":"RANDOM",P=async(n,e)=>{const t=await e(n);return(t==null?void 0:t.table.rows)||[]},L=(n,e,t)=>n.filter(o=>!e.includes(o.column)&&!t.includes(o.dtype)),it=n=>["timestamp","date"].includes(n.dtype.toLowerCase()),at=n=>["char","character","varchar","string","text","nchar","nvarchar","variant","character varying","citext","name","json","jsonb","bstring","bpchar","tinytext","mediumtext","longtext","enum"].includes(n.dtype.toLowerCase()),lt=n=>{const e=["int","integer","bigint","smallint","tinyint","decimal","numeric","float","real","double","number"],t=n.dtype.toLowerCase();return e.some(o=>t.includes(o))},D=n=>Number(n),$=(n={},e)=>{if(!n)return e||{};if(!e)return n;const t={},o=[...new Set([...Object.keys(n),...Object.keys(e)])].filter(s=>["models","sources","seeds"].includes(s));for(const s of o){if(!n[s]){t[s]=e[s];continue}if(!e[s]){t[s]=n[s];continue}const r=n[s]||[],i=e[s]||[],a=new Map(r.map(m=>[m.name,m])),c=new Map(i.map(m=>[m.name,m])),p=[...new Set([...r.map(m=>m.name),...i.map(m=>m.name)])].map(m=>{var b,C,T,_;const g=a.get(m),u=c.get(m),y=[...(g==null?void 0:g.tests)||[],...(u==null?void 0:u.tests)||[]],k=new Map(((b=g==null?void 0:g.columns)==null?void 0:b.map(f=>[f.name,f]))||[]),N=new Map(((C=u==null?void 0:u.columns)==null?void 0:C.map(f=>[f.name,f]))||[]),w=[...new Set([...((T=g==null?void 0:g.columns)==null?void 0:T.map(f=>f.name))||[],...((_=u==null?void 0:u.columns)==null?void 0:_.map(f=>f.name))||[]])].map(f=>{const I=k.get(f),v=N.get(f);return I?v?{...I,...v,name:f,tests:[...I.tests||[],...v.tests||[]]}:I:v}),E={name:m,columns:w};return y.length>0&&(E.tests=y),E});t[s]=p}return t};class q{quote;adapter;queryFn;constructor(e,t){this.quote=(o,s)=>s?`adapter.quote('${o}')`:`{{adapter.quote('${o}')}}`,this.adapter=e,this.queryFn=t}}class ct extends q{async generateRangeTests({tableRelation:e,excludeTypes:t,excludeCols:o,stddevs:s,limit:r,sample:i,columnConfig:a,resourceType:c,dbtConfig:d,columnsInRelation:p}){const g=L(p,o,t).filter(b=>lt(b));if(g.length===0)return d;let u="";r!==null&&(i?u=`ORDER BY ${R(this.adapter)}() LIMIT ${r}`:u=`LIMIT ${r}`);const y=g.map((b,C)=>`SELECT '${b.column}' AS COLNAME, MIN(${this.quote(b.column)}) as COL_MIN, MAX(${this.quote(b.column)}) as COL_MAX, STDDEV(${this.quote(b.column)}) as COL_STDDEV, ${C+1} AS ORDERING FROM base`),k=`
|
|
15
15
|
WITH base AS (
|
|
16
16
|
SELECT * FROM {{ref('${e}')}}
|
|
17
|
-
${
|
|
17
|
+
${u}
|
|
18
18
|
)
|
|
19
19
|
SELECT * FROM (
|
|
20
|
-
${
|
|
20
|
+
${y.join(`
|
|
21
21
|
UNION ALL
|
|
22
22
|
`)}
|
|
23
23
|
) t1
|
|
24
24
|
ORDER BY ORDERING ASC
|
|
25
|
-
`,S=(await
|
|
25
|
+
`,S=(await P(k,this.queryFn)).map(b=>{const C=D(b[1]),T=D(b[2]),_=D(b[3]);return{...{name:b[0],tests:[{"dbt_utils.accepted_range":{min_value:D(C-s*_/2),max_value:D(T+s*_/2)}}]},...a}}),w={name:e,columns:S},E={[c]:[w]};return $(d,E)}}class dt extends q{getColumnCombinations(e,t){const o=[];for(let s=0;s<t;s++)o.push(...this.combinations(e,s+1));return o}combinations(e,t){if(t===0)return[[]];if(e.length===0)return[];const[o,...s]=e,r=this.combinations(s,t),i=this.combinations(s,t-1).map(a=>[o,...a]);return[...r,...i]}buildLimitStatement(e,t,o){return t===null?"":o?`ORDER BY ${R(e)}() LIMIT ${t}`:`LIMIT ${t}`}buildCountDistinctQuery(e,t,o){const s=e.map((r,i)=>{const a=r.map(c=>this.quote(c));return`
|
|
26
26
|
SELECT ${i+1} AS ORDERING, count(1) AS CARDINALITY
|
|
27
27
|
from (
|
|
28
28
|
SELECT 1 FROM base
|
|
@@ -37,59 +37,59 @@ UNION ALL
|
|
|
37
37
|
UNION ALL
|
|
38
38
|
`)}
|
|
39
39
|
ORDER BY ordering ASC
|
|
40
|
-
`}async generateUniquenessTests({tableRelation:e,excludeTypes:t,excludeCols:o,compositeKeyLength:s,limit:r,sample:i,columnConfig:a,resourceType:c,dbtConfig:
|
|
40
|
+
`}async generateUniquenessTests({tableRelation:e,excludeTypes:t,excludeCols:o,compositeKeyLength:s,limit:r,sample:i,columnConfig:a,resourceType:c,dbtConfig:d,columnsInRelation:p}){const g=L(p,o,t).map(T=>T.column);if(g.length===0)return d;const u=this.getColumnCombinations(g,s),y=this.buildLimitStatement(this.adapter,r,i),k=this.buildCountDistinctQuery(u,e,y),S=(await P(`
|
|
41
41
|
WITH base AS (
|
|
42
42
|
SELECT * FROM {{ref('${e}')}}
|
|
43
|
-
${
|
|
43
|
+
${y}
|
|
44
44
|
)
|
|
45
45
|
SELECT count(1) AS TABLE_COUNT FROM base
|
|
46
|
-
`,this.queryFn))[0][0],w=await
|
|
46
|
+
`,this.queryFn))[0][0],w=await P(k,this.queryFn),E=u.filter((T,_)=>w[_][1]===S),b={name:e,columns:[],tests:[]};E.forEach(T=>{T.length===1?b.columns.push({name:T[0],tests:["unique","not_null"],...a}):b.tests.push({"dbt_utils.unique_combination_of_columns":{combination_of_columns:T}})});const C={[c]:[b]};return $(d,C)}}class ut extends q{async getAcceptedValuesTestSuggestions({tableRelation:e,excludeTypes:t,excludeCols:o,limit:s,sample:r,columnConfig:i,resourceType:a,dbtConfig:c,columnsInRelation:d,maxCardinality:p=5}){const m=(_,f)=>{switch(_){case"bigquery":return`array_agg(CAST(${this.quote(f)} AS STRING))`;case"redshift":return`split_to_array(listagg(${this.quote(f)}::VARCHAR, '|'), '|') `;case"databricks":return`to_json(array_agg(CAST(${this.quote(f)} AS STRING)))`;default:return`array_agg(${this.quote(f)}::VARCHAR)`}},g=L(d,o,t);if(g.length===0)return c;const u=g.map((_,f)=>`
|
|
47
47
|
select ${f+1} AS ORDERING,
|
|
48
|
-
'${
|
|
48
|
+
'${_.column}' AS COLNAME,
|
|
49
49
|
count(1) as CARDINALITY,
|
|
50
|
-
${
|
|
50
|
+
${m(this.adapter,_.column)} AS UNIQUE_VALUES
|
|
51
51
|
from (
|
|
52
|
-
select ${this.quote(
|
|
52
|
+
select ${this.quote(_.column)}
|
|
53
53
|
from base
|
|
54
|
-
group by ${this.quote(
|
|
54
|
+
group by ${this.quote(_.column)}
|
|
55
55
|
) t1
|
|
56
|
-
`),
|
|
56
|
+
`),y=s?r?`ORDER BY ${R(this.adapter)}() LIMIT ${s}`:`LIMIT ${s}`:"",k=`
|
|
57
57
|
WITH base AS (
|
|
58
58
|
SELECT * FROM {{ref('${e}')}}
|
|
59
|
-
${
|
|
59
|
+
${y}
|
|
60
60
|
)
|
|
61
61
|
SELECT * FROM (
|
|
62
|
-
${
|
|
62
|
+
${u.join(`
|
|
63
63
|
UNION ALL
|
|
64
64
|
`)}
|
|
65
65
|
) t2
|
|
66
|
-
WHERE CARDINALITY <= ${
|
|
66
|
+
WHERE CARDINALITY <= ${p}
|
|
67
67
|
ORDER BY ORDERING ASC
|
|
68
|
-
`,
|
|
69
|
-
SELECT '${
|
|
70
|
-
MIN(LENGTH(CAST(${this.quote(
|
|
71
|
-
MAX(LENGTH(CAST(${this.quote(
|
|
72
|
-
STDDEV(LENGTH(CAST(${this.quote(
|
|
73
|
-
${
|
|
68
|
+
`,N=await this.queryFn(k);if(!N)return c;const{table:{column_names:S,rows:w}}=N,E=S.indexOf("COLNAME"),b=S.indexOf("UNIQUE_VALUES"),C=w.map(_=>{const f=_[b];if(!f)return null;const I=typeof f=="string"?JSON.parse(f):f;return{name:_[E],tests:[{accepted_values:{values:I.sort()}}],...i}}).filter(Boolean),T={[a]:[{name:e,columns:C}]};return $(c,T)}}class pt extends q{async generateStringLengthTests({tableRelation:e,excludeTypes:t,excludeCols:o,stddevs:s,limit:r,sample:i,columnConfig:a,resourceType:c,dbtConfig:d,columnsInRelation:p}){const g=L(p,o,t).filter(b=>at(b));if(g.length===0)return d;const u=r?i?`ORDER BY ${R(this.adapter)}() LIMIT ${r}`:`LIMIT ${r}`:"",y=g.map((b,C)=>`
|
|
69
|
+
SELECT '${b.column}' AS COLNAME,
|
|
70
|
+
MIN(LENGTH(CAST(${this.quote(b.column)} as varchar))) as COL_MIN,
|
|
71
|
+
MAX(LENGTH(CAST(${this.quote(b.column)} as varchar))) as COL_MAX,
|
|
72
|
+
STDDEV(LENGTH(CAST(${this.quote(b.column)} as varchar))) as COL_STDDEV,
|
|
73
|
+
${C+1} AS ORDERING
|
|
74
74
|
FROM base
|
|
75
|
-
WHERE ${this.quote(
|
|
76
|
-
`),
|
|
75
|
+
WHERE ${this.quote(b.column)} IS NOT NULL
|
|
76
|
+
`),k=`
|
|
77
77
|
WITH base AS (
|
|
78
78
|
SELECT * FROM {{ref('${e}')}}
|
|
79
|
-
${
|
|
79
|
+
${u}
|
|
80
80
|
)
|
|
81
81
|
SELECT * FROM (
|
|
82
|
-
${
|
|
82
|
+
${y.join(`
|
|
83
83
|
UNION ALL
|
|
84
84
|
`)}
|
|
85
85
|
) t1
|
|
86
86
|
ORDER BY ORDERING ASC
|
|
87
|
-
`,S=(await
|
|
87
|
+
`,S=(await P(k,this.queryFn)).map(b=>{const[C,T,_,f]=b;let I;if(T===_)I={"dbt_expectations.expect_column_value_lengths_to_equal":{value:T,row_condition:`${this.quote(C)} is not null`}};else{let v=T-s*f;const ae=_+s*f;v<0&&(v=0),I={"dbt_expectations.expect_column_value_lengths_to_be_between":{min_value:Math.floor(v),max_value:Math.ceil(ae),row_condition:`${this.quote(C)} is not null`}}}return{name:C,tests:[I],...a}}),w={name:e,columns:S},E={[c]:[w]};return $(d,E)}}class ht extends q{async generateRecencyTests({tableRelation:e,excludeTypes:t,excludeCols:o,stddevs:s,limit:r,sample:i,resourceType:a,dbtConfig:c,columnsInRelation:d}){const m=L(d,o,t).filter(it);if(m.length===0)return c;const g=r?i?`ORDER BY ${R(this.adapter)}() LIMIT ${r}`:`LIMIT ${r}`:"",u=`
|
|
88
88
|
WITH base AS (
|
|
89
89
|
SELECT * FROM {{ref('${e}')}}
|
|
90
|
-
${
|
|
90
|
+
${g}
|
|
91
91
|
)
|
|
92
|
-
${
|
|
92
|
+
${m.map((w,E)=>`
|
|
93
93
|
SELECT
|
|
94
94
|
MAX(minutes_diff) AS max_minutes_diff,
|
|
95
95
|
AVG(minutes_diff) AS avg_minutes_diff,
|
|
@@ -105,4 +105,4 @@ UNION ALL
|
|
|
105
105
|
UNION ALL
|
|
106
106
|
`)}
|
|
107
107
|
ORDER BY ordering ASC
|
|
108
|
-
`,
|
|
108
|
+
`,y=await P(u,this.queryFn),k=m.map((w,E)=>{const[,b,C]=y[E],T=b+C*s;let _,f;return T>=60*24?(_="day",f=Math.floor(T/(60*24))):T>=60?(_="hour",f=Math.floor(T/60)):(_="minute",f=Math.floor(T)),{"dbt_utils.recency":{field:w.column,datepart:_,interval:f}}}),N={name:e,...k.length>0&&{tests:k}},S={[a]:[N]};return $(c,S)}}const mt=async({tableRelation:n,sample:e=!1,limit:t=1e4,resourceType:o="models",columnConfig:s={},excludeTypes:r=[],excludeCols:i=[],tests:a=["uniqueness","accepted_values","range","string_length","recency"],uniquenessCompositeKeyLength:c=1,acceptedValuesMaxCardinality:d=5,rangeStddevs:p=0,stringLengthStddevs:m=0,recencyStddevs:g=1,dbtConfig:u,returnObject:y=!1,columnsInRelation:k,adapter:N,queryFn:S})=>{console.log("testgen getTestSuggestions args",{tableRelation:n,sample:e,limit:t,resourceType:o,columnConfig:s,excludeTypes:r,excludeCols:i,tests:a,uniquenessCompositeKeyLength:c,acceptedValuesMaxCardinality:d,rangeStddevs:p,stringLengthStddevs:m,recencyStddevs:g,dbtConfig:u,returnObject:y,columnsInRelation:k});let w=u;return a.includes("uniqueness")&&(w=await new dt(N,S).generateUniquenessTests({tableRelation:n,excludeTypes:r,excludeCols:i,limit:t,sample:e,columnConfig:s,resourceType:o,dbtConfig:w,columnsInRelation:k,compositeKeyLength:c})),a.includes("accepted_values")&&(w=await new ut(N,S).getAcceptedValuesTestSuggestions({tableRelation:n,excludeTypes:r,excludeCols:i,limit:t,sample:e,columnConfig:s,resourceType:o,dbtConfig:w,columnsInRelation:k,maxCardinality:d})),a.includes("range")&&(w=await new ct(N,S).generateRangeTests({tableRelation:n,excludeTypes:r,excludeCols:i,limit:t,sample:e,columnConfig:s,resourceType:o,dbtConfig:w,columnsInRelation:k,stddevs:p})),a.includes("string_length")&&(w=await new pt(N,S).generateStringLengthTests({tableRelation:n,excludeTypes:r,excludeCols:i,limit:t,sample:e,columnConfig:s,resourceType:o,dbtConfig:w,columnsInRelation:k,stddevs:m})),a.includes("recency")&&(w=await new ht(N,S).generateRecencyTests({tableRelation:n,excludeTypes:r,excludeCols:i,limit:t,sample:e,resourceType:o,dbtConfig:w,columnsInRelation:k,stddevs:g})),w};exports.CustomNotebooks=Ze;exports.NotebookKernelClient=V;exports.getTestSuggestions=mt;
|
|
@@ -8,133 +8,133 @@
|
|
|
8
8
|
* - Please do NOT serve this file on production.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const PACKAGE_VERSION =
|
|
12
|
-
const INTEGRITY_CHECKSUM =
|
|
13
|
-
const IS_MOCKED_RESPONSE = Symbol(
|
|
14
|
-
const activeClientIds = new Set()
|
|
11
|
+
const PACKAGE_VERSION = "2.7.0";
|
|
12
|
+
const INTEGRITY_CHECKSUM = "00729d72e3b82faf54ca8b9621dbb96f";
|
|
13
|
+
const IS_MOCKED_RESPONSE = Symbol("isMockedResponse");
|
|
14
|
+
const activeClientIds = new Set();
|
|
15
15
|
|
|
16
|
-
self.addEventListener(
|
|
17
|
-
self.skipWaiting()
|
|
18
|
-
})
|
|
16
|
+
self.addEventListener("install", function () {
|
|
17
|
+
self.skipWaiting();
|
|
18
|
+
});
|
|
19
19
|
|
|
20
|
-
self.addEventListener(
|
|
21
|
-
event.waitUntil(self.clients.claim())
|
|
22
|
-
})
|
|
20
|
+
self.addEventListener("activate", function (event) {
|
|
21
|
+
event.waitUntil(self.clients.claim());
|
|
22
|
+
});
|
|
23
23
|
|
|
24
|
-
self.addEventListener(
|
|
25
|
-
const clientId = event.source.id
|
|
24
|
+
self.addEventListener("message", async function (event) {
|
|
25
|
+
const clientId = event.source.id;
|
|
26
26
|
|
|
27
27
|
if (!clientId || !self.clients) {
|
|
28
|
-
return
|
|
28
|
+
return;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const client = await self.clients.get(clientId)
|
|
31
|
+
const client = await self.clients.get(clientId);
|
|
32
32
|
|
|
33
33
|
if (!client) {
|
|
34
|
-
return
|
|
34
|
+
return;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const allClients = await self.clients.matchAll({
|
|
38
|
-
type:
|
|
39
|
-
})
|
|
38
|
+
type: "window",
|
|
39
|
+
});
|
|
40
40
|
|
|
41
41
|
switch (event.data) {
|
|
42
|
-
case
|
|
42
|
+
case "KEEPALIVE_REQUEST": {
|
|
43
43
|
sendToClient(client, {
|
|
44
|
-
type:
|
|
45
|
-
})
|
|
46
|
-
break
|
|
44
|
+
type: "KEEPALIVE_RESPONSE",
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
case
|
|
49
|
+
case "INTEGRITY_CHECK_REQUEST": {
|
|
50
50
|
sendToClient(client, {
|
|
51
|
-
type:
|
|
51
|
+
type: "INTEGRITY_CHECK_RESPONSE",
|
|
52
52
|
payload: {
|
|
53
53
|
packageVersion: PACKAGE_VERSION,
|
|
54
54
|
checksum: INTEGRITY_CHECKSUM,
|
|
55
55
|
},
|
|
56
|
-
})
|
|
57
|
-
break
|
|
56
|
+
});
|
|
57
|
+
break;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
case
|
|
61
|
-
activeClientIds.add(clientId)
|
|
60
|
+
case "MOCK_ACTIVATE": {
|
|
61
|
+
activeClientIds.add(clientId);
|
|
62
62
|
|
|
63
63
|
sendToClient(client, {
|
|
64
|
-
type:
|
|
64
|
+
type: "MOCKING_ENABLED",
|
|
65
65
|
payload: {
|
|
66
66
|
client: {
|
|
67
67
|
id: client.id,
|
|
68
68
|
frameType: client.frameType,
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
|
-
})
|
|
72
|
-
break
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
case
|
|
76
|
-
activeClientIds.delete(clientId)
|
|
77
|
-
break
|
|
75
|
+
case "MOCK_DEACTIVATE": {
|
|
76
|
+
activeClientIds.delete(clientId);
|
|
77
|
+
break;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
case
|
|
81
|
-
activeClientIds.delete(clientId)
|
|
80
|
+
case "CLIENT_CLOSED": {
|
|
81
|
+
activeClientIds.delete(clientId);
|
|
82
82
|
|
|
83
|
-
const remainingClients = allClients.filter(
|
|
84
|
-
return client.id !== clientId
|
|
85
|
-
})
|
|
83
|
+
const remainingClients = allClients.filter(client => {
|
|
84
|
+
return client.id !== clientId;
|
|
85
|
+
});
|
|
86
86
|
|
|
87
87
|
// Unregister itself when there are no more clients
|
|
88
88
|
if (remainingClients.length === 0) {
|
|
89
|
-
self.registration.unregister()
|
|
89
|
+
self.registration.unregister();
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
break
|
|
92
|
+
break;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
})
|
|
95
|
+
});
|
|
96
96
|
|
|
97
|
-
self.addEventListener(
|
|
98
|
-
const { request } = event
|
|
97
|
+
self.addEventListener("fetch", function (event) {
|
|
98
|
+
const { request } = event;
|
|
99
99
|
|
|
100
100
|
// Bypass navigation requests.
|
|
101
|
-
if (request.mode ===
|
|
102
|
-
return
|
|
101
|
+
if (request.mode === "navigate") {
|
|
102
|
+
return;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// Opening the DevTools triggers the "only-if-cached" request
|
|
106
106
|
// that cannot be handled by the worker. Bypass such requests.
|
|
107
|
-
if (request.cache ===
|
|
108
|
-
return
|
|
107
|
+
if (request.cache === "only-if-cached" && request.mode !== "same-origin") {
|
|
108
|
+
return;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
// Bypass all requests when there are no active clients.
|
|
112
112
|
// Prevents the self-unregistered worked from handling requests
|
|
113
113
|
// after it's been deleted (still remains active until the next reload).
|
|
114
114
|
if (activeClientIds.size === 0) {
|
|
115
|
-
return
|
|
115
|
+
return;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// Generate unique request ID.
|
|
119
|
-
const requestId = crypto.randomUUID()
|
|
120
|
-
event.respondWith(handleRequest(event, requestId))
|
|
121
|
-
})
|
|
119
|
+
const requestId = crypto.randomUUID();
|
|
120
|
+
event.respondWith(handleRequest(event, requestId));
|
|
121
|
+
});
|
|
122
122
|
|
|
123
123
|
async function handleRequest(event, requestId) {
|
|
124
|
-
const client = await resolveMainClient(event)
|
|
125
|
-
const response = await getResponse(event, client, requestId)
|
|
124
|
+
const client = await resolveMainClient(event);
|
|
125
|
+
const response = await getResponse(event, client, requestId);
|
|
126
126
|
|
|
127
127
|
// Send back the response clone for the "response:*" life-cycle events.
|
|
128
128
|
// Ensure MSW is active and ready to handle the message, otherwise
|
|
129
129
|
// this message will pend indefinitely.
|
|
130
130
|
if (client && activeClientIds.has(client.id)) {
|
|
131
|
-
|
|
132
|
-
const responseClone = response.clone()
|
|
131
|
+
(async function () {
|
|
132
|
+
const responseClone = response.clone();
|
|
133
133
|
|
|
134
134
|
sendToClient(
|
|
135
135
|
client,
|
|
136
136
|
{
|
|
137
|
-
type:
|
|
137
|
+
type: "RESPONSE",
|
|
138
138
|
payload: {
|
|
139
139
|
requestId,
|
|
140
140
|
isMockedResponse: IS_MOCKED_RESPONSE in response,
|
|
@@ -145,12 +145,12 @@ async function handleRequest(event, requestId) {
|
|
|
145
145
|
headers: Object.fromEntries(responseClone.headers.entries()),
|
|
146
146
|
},
|
|
147
147
|
},
|
|
148
|
-
[responseClone.body]
|
|
149
|
-
)
|
|
150
|
-
})()
|
|
148
|
+
[responseClone.body]
|
|
149
|
+
);
|
|
150
|
+
})();
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
return response
|
|
153
|
+
return response;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// Resolve the main client for the given event.
|
|
@@ -158,67 +158,65 @@ async function handleRequest(event, requestId) {
|
|
|
158
158
|
// that registered the worker. It's with the latter the worker should
|
|
159
159
|
// communicate with during the response resolving phase.
|
|
160
160
|
async function resolveMainClient(event) {
|
|
161
|
-
const client = await self.clients.get(event.clientId)
|
|
161
|
+
const client = await self.clients.get(event.clientId);
|
|
162
162
|
|
|
163
163
|
if (activeClientIds.has(event.clientId)) {
|
|
164
|
-
return client
|
|
164
|
+
return client;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
if (client?.frameType ===
|
|
168
|
-
return client
|
|
167
|
+
if (client?.frameType === "top-level") {
|
|
168
|
+
return client;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
const allClients = await self.clients.matchAll({
|
|
172
|
-
type:
|
|
173
|
-
})
|
|
172
|
+
type: "window",
|
|
173
|
+
});
|
|
174
174
|
|
|
175
175
|
return allClients
|
|
176
|
-
.filter(
|
|
176
|
+
.filter(client => {
|
|
177
177
|
// Get only those clients that are currently visible.
|
|
178
|
-
return client.visibilityState ===
|
|
178
|
+
return client.visibilityState === "visible";
|
|
179
179
|
})
|
|
180
|
-
.find(
|
|
180
|
+
.find(client => {
|
|
181
181
|
// Find the client ID that's recorded in the
|
|
182
182
|
// set of clients that have registered the worker.
|
|
183
|
-
return activeClientIds.has(client.id)
|
|
184
|
-
})
|
|
183
|
+
return activeClientIds.has(client.id);
|
|
184
|
+
});
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
async function getResponse(event, client, requestId) {
|
|
188
|
-
const { request } = event
|
|
188
|
+
const { request } = event;
|
|
189
189
|
|
|
190
190
|
// Clone the request because it might've been already used
|
|
191
191
|
// (i.e. its body has been read and sent to the client).
|
|
192
|
-
const requestClone = request.clone()
|
|
192
|
+
const requestClone = request.clone();
|
|
193
193
|
|
|
194
194
|
function passthrough() {
|
|
195
195
|
// Cast the request headers to a new Headers instance
|
|
196
196
|
// so the headers can be manipulated with.
|
|
197
|
-
const headers = new Headers(requestClone.headers)
|
|
197
|
+
const headers = new Headers(requestClone.headers);
|
|
198
198
|
|
|
199
199
|
// Remove the "accept" header value that marked this request as passthrough.
|
|
200
200
|
// This prevents request alteration and also keeps it compliant with the
|
|
201
201
|
// user-defined CORS policies.
|
|
202
|
-
const acceptHeader = headers.get(
|
|
202
|
+
const acceptHeader = headers.get("accept");
|
|
203
203
|
if (acceptHeader) {
|
|
204
|
-
const values = acceptHeader.split(
|
|
205
|
-
const filteredValues = values.filter(
|
|
206
|
-
(value) => value !== 'msw/passthrough',
|
|
207
|
-
)
|
|
204
|
+
const values = acceptHeader.split(",").map(value => value.trim());
|
|
205
|
+
const filteredValues = values.filter(value => value !== "msw/passthrough");
|
|
208
206
|
|
|
209
207
|
if (filteredValues.length > 0) {
|
|
210
|
-
headers.set(
|
|
208
|
+
headers.set("accept", filteredValues.join(", "));
|
|
211
209
|
} else {
|
|
212
|
-
headers.delete(
|
|
210
|
+
headers.delete("accept");
|
|
213
211
|
}
|
|
214
212
|
}
|
|
215
213
|
|
|
216
|
-
return fetch(requestClone, { headers })
|
|
214
|
+
return fetch(requestClone, { headers });
|
|
217
215
|
}
|
|
218
216
|
|
|
219
217
|
// Bypass mocking when the client is not active.
|
|
220
218
|
if (!client) {
|
|
221
|
-
return passthrough()
|
|
219
|
+
return passthrough();
|
|
222
220
|
}
|
|
223
221
|
|
|
224
222
|
// Bypass initial page load requests (i.e. static assets).
|
|
@@ -226,15 +224,15 @@ async function getResponse(event, client, requestId) {
|
|
|
226
224
|
// means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
|
|
227
225
|
// and is not ready to handle requests.
|
|
228
226
|
if (!activeClientIds.has(client.id)) {
|
|
229
|
-
return passthrough()
|
|
227
|
+
return passthrough();
|
|
230
228
|
}
|
|
231
229
|
|
|
232
230
|
// Notify the client that a request has been intercepted.
|
|
233
|
-
const requestBuffer = await request.arrayBuffer()
|
|
231
|
+
const requestBuffer = await request.arrayBuffer();
|
|
234
232
|
const clientMessage = await sendToClient(
|
|
235
233
|
client,
|
|
236
234
|
{
|
|
237
|
-
type:
|
|
235
|
+
type: "REQUEST",
|
|
238
236
|
payload: {
|
|
239
237
|
id: requestId,
|
|
240
238
|
url: request.url,
|
|
@@ -252,39 +250,36 @@ async function getResponse(event, client, requestId) {
|
|
|
252
250
|
keepalive: request.keepalive,
|
|
253
251
|
},
|
|
254
252
|
},
|
|
255
|
-
[requestBuffer]
|
|
256
|
-
)
|
|
253
|
+
[requestBuffer]
|
|
254
|
+
);
|
|
257
255
|
|
|
258
256
|
switch (clientMessage.type) {
|
|
259
|
-
case
|
|
260
|
-
return respondWithMock(clientMessage.data)
|
|
257
|
+
case "MOCK_RESPONSE": {
|
|
258
|
+
return respondWithMock(clientMessage.data);
|
|
261
259
|
}
|
|
262
260
|
|
|
263
|
-
case
|
|
264
|
-
return passthrough()
|
|
261
|
+
case "PASSTHROUGH": {
|
|
262
|
+
return passthrough();
|
|
265
263
|
}
|
|
266
264
|
}
|
|
267
265
|
|
|
268
|
-
return passthrough()
|
|
266
|
+
return passthrough();
|
|
269
267
|
}
|
|
270
268
|
|
|
271
269
|
function sendToClient(client, message, transferrables = []) {
|
|
272
270
|
return new Promise((resolve, reject) => {
|
|
273
|
-
const channel = new MessageChannel()
|
|
271
|
+
const channel = new MessageChannel();
|
|
274
272
|
|
|
275
|
-
channel.port1.onmessage =
|
|
273
|
+
channel.port1.onmessage = event => {
|
|
276
274
|
if (event.data && event.data.error) {
|
|
277
|
-
return reject(event.data.error)
|
|
275
|
+
return reject(event.data.error);
|
|
278
276
|
}
|
|
279
277
|
|
|
280
|
-
resolve(event.data)
|
|
281
|
-
}
|
|
278
|
+
resolve(event.data);
|
|
279
|
+
};
|
|
282
280
|
|
|
283
|
-
client.postMessage(
|
|
284
|
-
|
|
285
|
-
[channel.port2].concat(transferrables.filter(Boolean)),
|
|
286
|
-
)
|
|
287
|
-
})
|
|
281
|
+
client.postMessage(message, [channel.port2].concat(transferrables.filter(Boolean)));
|
|
282
|
+
});
|
|
288
283
|
}
|
|
289
284
|
|
|
290
285
|
async function respondWithMock(response) {
|
|
@@ -293,15 +288,15 @@ async function respondWithMock(response) {
|
|
|
293
288
|
// instance will have status code set to 0. Since it's not possible to create
|
|
294
289
|
// a Response instance with status code 0, handle that use-case separately.
|
|
295
290
|
if (response.status === 0) {
|
|
296
|
-
return Response.error()
|
|
291
|
+
return Response.error();
|
|
297
292
|
}
|
|
298
293
|
|
|
299
|
-
const mockedResponse = new Response(response.body, response)
|
|
294
|
+
const mockedResponse = new Response(response.body, response);
|
|
300
295
|
|
|
301
296
|
Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
|
|
302
297
|
value: true,
|
|
303
298
|
enumerable: true,
|
|
304
|
-
})
|
|
299
|
+
});
|
|
305
300
|
|
|
306
|
-
return mockedResponse
|
|
301
|
+
return mockedResponse;
|
|
307
302
|
}
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@altimateai/extension-components",
|
|
3
|
+
"version": "0.0.1-beta.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/AltimateAI/altimate-components.git"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/",
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"dist/postInstall.cjs"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"postinstall": "node ./dist/postInstall.cjs"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@jupyterlab/services": "^6.6.7"
|
|
32
|
+
}
|
|
33
|
+
}
|