@altimateai/extension-components 0.0.1-beta.10

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.
@@ -0,0 +1,342 @@
1
+ import * as vscode from 'vscode';
2
+ import { NotebookSerializer, Disposable, CancellationToken, NotebookData, NotebookCellKind, NotebookCellOutput, Event, NotebookCell, Uri, FileSystemProvider, FileChangeEvent, FileStat, FileType } from 'vscode';
3
+ import { DBTTerminal, TelemetryService, CommandProcessExecutionFactory, PythonEnvironment, DBTProject, DBTCommandExecutionInfrastructure, QueryManifestService, AltimateRequest, ExecuteSQLResult } from '@extension';
4
+ import { KernelConnection } from '@jupyterlab/services';
5
+
6
+ declare class DatapilotNotebookSerializer implements NotebookSerializer, Disposable {
7
+ dispose(): void;
8
+ deserializeNotebook(content: Uint8Array, _token: CancellationToken): Promise<NotebookData>;
9
+ serializeNotebook(data: NotebookData, _token: CancellationToken): Promise<Uint8Array>;
10
+ }
11
+
12
+ interface NotebookItem {
13
+ id: number;
14
+ name: string;
15
+ data: NotebookSchema;
16
+ description: string;
17
+ created_on: string;
18
+ updated_on: string;
19
+ tags: {
20
+ id: number;
21
+ tag: string;
22
+ }[];
23
+ privacy: boolean;
24
+ }
25
+ interface NotebookSchema {
26
+ cells: NotebookCellSchema[];
27
+ metadata?: Record<string, unknown>;
28
+ }
29
+ interface NotebookCellSchema {
30
+ source: string[];
31
+ cell_type: NotebookCellKind;
32
+ languageId: string;
33
+ metadata?: Record<string, unknown>;
34
+ outputs?: NotebookCellOutput[];
35
+ }
36
+ interface PreconfiguredNotebookItem {
37
+ name: string;
38
+ description: string;
39
+ created_at: string;
40
+ updated_at: string;
41
+ id: string;
42
+ tags: string[];
43
+ data: NotebookSchema;
44
+ }
45
+ interface NotebookCellEvent {
46
+ cellId: string;
47
+ notebook: string;
48
+ result?: Record<string, unknown>;
49
+ event: "add" | "update" | "delete";
50
+ fragment?: string;
51
+ languageId: string;
52
+ }
53
+ interface OpenNotebookRequest {
54
+ notebookId?: string;
55
+ template?: string;
56
+ context?: Record<string, unknown>;
57
+ notebookSchema?: NotebookSchema;
58
+ }
59
+ interface NotebookDependency {
60
+ type: "dbt" | "python";
61
+ package: string;
62
+ name?: string;
63
+ version?: string;
64
+ }
65
+
66
+ declare class NotebookDependencies {
67
+ private readonly dbtTerminal;
68
+ private readonly telemetry;
69
+ private commandProcessExecutionFactory;
70
+ private pythonEnvironment;
71
+ constructor(dbtTerminal: DBTTerminal, telemetry: TelemetryService, commandProcessExecutionFactory: CommandProcessExecutionFactory, pythonEnvironment: PythonEnvironment);
72
+ private checkPythonDependencies;
73
+ private checkDbtDependencies;
74
+ private installMissingPythonPackages;
75
+ private installMissingDbtPackages;
76
+ verifyAndInstallDependenciesIfNeeded(dependencies: NotebookDependency[], project: DBTProject): Promise<void>;
77
+ getDependenciesVersion(): Promise<Record<string, string>>;
78
+ validateAndInstallNotebookDependencies(): Promise<boolean | undefined>;
79
+ private notebookDependenciesAreInstalled;
80
+ }
81
+
82
+ interface ConnectionSettings {
83
+ control_port: number;
84
+ hb_port: number;
85
+ iopub_port: number;
86
+ ip: string;
87
+ key: string;
88
+ kernel_name: string;
89
+ shell_port: number;
90
+ signature_scheme: string;
91
+ stdin_port: number;
92
+ transport: string;
93
+ }
94
+ interface RawKernelType {
95
+ realKernel: KernelConnection;
96
+ socket: WebSocket;
97
+ kernelProcess: {
98
+ connection: ConnectionSettings;
99
+ pid: number;
100
+ };
101
+ }
102
+
103
+ interface WidgetPayload {
104
+ [key: string]: unknown;
105
+ }
106
+ interface IPyWidgetMessage {
107
+ type: string;
108
+ payload: WidgetPayload;
109
+ }
110
+ interface NotebookContext {
111
+ [key: string]: unknown;
112
+ }
113
+ declare class NotebookKernelClient implements Disposable {
114
+ private executionInfrastructure;
115
+ private notebookDependencies;
116
+ private dbtTerminal;
117
+ get postMessage(): Event<IPyWidgetMessage>;
118
+ private _postMessageEmitter;
119
+ private disposables;
120
+ private lastUsedStreamOutput?;
121
+ private static modelIdsOwnedByCells;
122
+ private python;
123
+ private kernel;
124
+ private isInitializing;
125
+ private readonly ownedCommIds;
126
+ private readonly commIdsMappedToWidgetOutputModels;
127
+ private readonly ownedRequestMsgIds;
128
+ private commIdsMappedToParentWidgetModel;
129
+ private streamsReAttachedToExecutingCell;
130
+ private registerdCommTargets;
131
+ private outputsAreSpecificToAWidget;
132
+ private versions?;
133
+ constructor(notebookPath: string, executionInfrastructure: DBTCommandExecutionInfrastructure, notebookDependencies: NotebookDependencies, dbtTerminal: DBTTerminal);
134
+ isInitialized(): Promise<boolean>;
135
+ dispose(): Promise<void>;
136
+ get jupyterPackagesVersions(): Record<string, string> | undefined;
137
+ private getDependenciesVersion;
138
+ getKernel(): Promise<RawKernelType | undefined>;
139
+ private initializeNotebookKernel;
140
+ onKernelSocketResponse(payload: {
141
+ id: string;
142
+ }): void;
143
+ storeContext(context: NotebookContext): Promise<void>;
144
+ storeDataInKernel(cellId: string, data: unknown): Promise<boolean>;
145
+ registerCommTarget(payload: string): Promise<void>;
146
+ getPythonCodeByType(type: string, cellId: string): Promise<string>;
147
+ executePython(code: string, cell: NotebookCell, onOutput: (output: NotebookCellOutput) => void): Promise<NotebookCellOutput[] | undefined>;
148
+ private handleUpdateDisplayDataMessage;
149
+ private handleCommOpen;
150
+ private handleCommMsg;
151
+ private handleExecuteResult;
152
+ private addToCellData;
153
+ private canMimeTypeBeRenderedByWidgetManager;
154
+ private handleExecuteInput;
155
+ private handleStatusMessage;
156
+ private handleStreamMessage;
157
+ private handleDisplayData;
158
+ private handleClearOutput;
159
+ private handleError;
160
+ }
161
+
162
+ declare class ClientMapper {
163
+ private executionInfrastructure;
164
+ private notebookDependencies;
165
+ private dbtTerminal;
166
+ private clientMap;
167
+ constructor(executionInfrastructure: DBTCommandExecutionInfrastructure, notebookDependencies: NotebookDependencies, dbtTerminal: DBTTerminal);
168
+ initializeNotebookClient(notebookUri: Uri): Promise<NotebookKernelClient>;
169
+ getNotebookClient(notebookUri: Uri): Promise<NotebookKernelClient>;
170
+ }
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
+ }
191
+ declare class DatapilotNotebookController implements Disposable {
192
+ private clientMapper;
193
+ private queryManifestService;
194
+ private telemetry;
195
+ private dbtTerminal;
196
+ private notebookDependencies;
197
+ private altimate;
198
+ private readonly id;
199
+ private readonly label;
200
+ private _onNotebookCellEvent;
201
+ readonly onNotebookCellChangeEvent: vscode.Event<NotebookCellEvent>;
202
+ private readonly disposables;
203
+ private associatedNotebooks;
204
+ private executionOrder;
205
+ private readonly controller;
206
+ constructor(clientMapper: ClientMapper, queryManifestService: QueryManifestService, telemetry: TelemetryService, dbtTerminal: DBTTerminal, notebookDependencies: NotebookDependencies, altimate: AltimateRequest);
207
+ private getNotebookByTemplate;
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>;
215
+ private getFileName;
216
+ createNotebook(args: OpenNotebookRequest | undefined): Promise<void>;
217
+ private sendMessageToPreloadScript;
218
+ private getRandomString;
219
+ private genUniqueId;
220
+ private updateCellId;
221
+ private onNotebookClose;
222
+ private onDidChangeSelectedNotebooks;
223
+ private onNotebookOpen;
224
+ private waitForControllerAssociation;
225
+ private isControllerAssociatedWithNotebook;
226
+ dispose(): void;
227
+ private _executeAll;
228
+ private filterIPyWidgets;
229
+ private updateContextVariablesInKernel;
230
+ private _doExecution;
231
+ }
232
+
233
+ declare class NotebookFileSystemProvider implements FileSystemProvider {
234
+ private dbtTerminal;
235
+ private altimate;
236
+ private _emitter;
237
+ readonly onDidChangeFile: Event<FileChangeEvent[]>;
238
+ private notebookDataMap;
239
+ constructor(dbtTerminal: DBTTerminal, altimate: AltimateRequest);
240
+ watch(_uri: Uri, _options: {
241
+ recursive: boolean;
242
+ excludes: string[];
243
+ }): Disposable;
244
+ stat(_uri: Uri): FileStat;
245
+ readDirectory(_uri: Uri): [string, FileType][];
246
+ createDirectory(_uri: Uri): void;
247
+ private getNotebookData;
248
+ readFile(uri: Uri): Promise<Uint8Array>;
249
+ writeFile(uri: Uri, content: Uint8Array, _options: {
250
+ create: boolean;
251
+ overwrite: boolean;
252
+ }): Promise<void>;
253
+ delete(uri: Uri, _options: {
254
+ recursive: boolean;
255
+ }): void;
256
+ rename(oldUri: Uri, newUri: Uri, _options: {
257
+ overwrite: boolean;
258
+ }): void;
259
+ private getFileNameFromUri;
260
+ private customSave;
261
+ private saveNotebook;
262
+ }
263
+
264
+ declare class NotebookService implements Disposable {
265
+ private notebookKernel;
266
+ private disposables;
267
+ private cellByNotebookAutocompleteMap;
268
+ constructor(notebookKernel: DatapilotNotebookController);
269
+ dispose(): void;
270
+ getCellByNotebookAutocompleteMap(): Map<string, {
271
+ cellId: string;
272
+ fragment: string;
273
+ languageId: string;
274
+ }[]>;
275
+ private onNotebookCellChanged;
276
+ }
277
+
278
+ declare const CustomNotebooks: {
279
+ notebooks: PreconfiguredNotebookItem[];
280
+ };
281
+
282
+ declare class NotebookProviders implements Disposable {
283
+ private notebookProvider;
284
+ private notebookController;
285
+ private notebookFileSystemProvider;
286
+ private dbtTerminal;
287
+ private disposables;
288
+ constructor(notebookProvider: DatapilotNotebookSerializer, notebookController: DatapilotNotebookController, notebookFileSystemProvider: NotebookFileSystemProvider, dbtTerminal: DBTTerminal);
289
+ private bindNotebookActions;
290
+ dispose(): void;
291
+ }
292
+
293
+ interface DBColumn {
294
+ column: string;
295
+ dtype: string;
296
+ }
297
+ interface ColumnConfig$1 {
298
+ name: string;
299
+ tests: string[];
300
+ description?: string;
301
+ [key: string]: string | string[] | undefined;
302
+ }
303
+ interface Model {
304
+ name: string;
305
+ columns: ColumnConfig$1[];
306
+ tests?: Array<{
307
+ [key: string]: unknown;
308
+ }>;
309
+ }
310
+ interface DbtConfig {
311
+ [key: string]: Model[];
312
+ }
313
+ type QueryFn = (query: string) => Promise<ExecuteSQLResult | undefined>;
314
+
315
+ interface ColumnConfig {
316
+ tests?: string[];
317
+ description?: string;
318
+ [key: string]: unknown;
319
+ }
320
+ interface Props {
321
+ tableRelation: string;
322
+ sample?: boolean;
323
+ limit?: number;
324
+ resourceType?: string;
325
+ columnConfig?: Record<string, ColumnConfig>;
326
+ excludeTypes?: string[];
327
+ excludeCols?: string[];
328
+ tests?: ("uniqueness" | "accepted_values" | "range" | "string_length" | "recency")[];
329
+ uniquenessCompositeKeyLength?: number;
330
+ acceptedValuesMaxCardinality?: number;
331
+ rangeStddevs?: number;
332
+ stringLengthStddevs?: number;
333
+ recencyStddevs?: number;
334
+ dbtConfig?: DbtConfig;
335
+ returnObject?: boolean;
336
+ columnsInRelation: DBColumn[];
337
+ adapter: string;
338
+ queryFn: QueryFn;
339
+ }
340
+ declare const getTestSuggestions: ({ tableRelation, sample, limit, resourceType, columnConfig, excludeTypes, excludeCols, tests, uniquenessCompositeKeyLength, acceptedValuesMaxCardinality, rangeStddevs, stringLengthStddevs, recencyStddevs, dbtConfig, returnObject, columnsInRelation, adapter, queryFn, }: Props) => Promise<DbtConfig | undefined>;
341
+
342
+ export { CustomNotebooks, DatapilotNotebookController, type DbtConfig, type IPyWidgetMessage, type Model, type NotebookCellEvent, type NotebookCellSchema, NotebookDependencies, type NotebookDependency, NotebookFileSystemProvider, type NotebookItem, NotebookKernelClient, NotebookProviders, type NotebookSchema, NotebookService, type OpenNotebookRequest, type PreconfiguredNotebookItem, getTestSuggestions };
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
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
+ `)?e=e.concat(`${o}
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
+ notebook_kernel.close_notebook()
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
+ from altimate_notebook_kernel import AltimateNotebookKernel
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 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
+ manifest_path="${e.getManifestPath()}"
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(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
+ WITH base AS (
16
+ SELECT * FROM {{ref('${e}')}}
17
+ ${u}
18
+ )
19
+ SELECT * FROM (
20
+ ${y.join(`
21
+ UNION ALL
22
+ `)}
23
+ ) t1
24
+ ORDER BY ORDERING ASC
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
+ SELECT ${i+1} AS ORDERING, count(1) AS CARDINALITY
27
+ from (
28
+ SELECT 1 FROM base
29
+ GROUP BY ${a.join(", ")}
30
+ ) t
31
+ `});return`
32
+ WITH base AS (
33
+ SELECT * FROM {{ref('${t}')}}
34
+ ${o}
35
+ )
36
+ ${s.join(`
37
+ UNION ALL
38
+ `)}
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: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
+ WITH base AS (
42
+ SELECT * FROM {{ref('${e}')}}
43
+ ${y}
44
+ )
45
+ SELECT count(1) AS TABLE_COUNT FROM base
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
+ select ${f+1} AS ORDERING,
48
+ '${_.column}' AS COLNAME,
49
+ count(1) as CARDINALITY,
50
+ ${m(this.adapter,_.column)} AS UNIQUE_VALUES
51
+ from (
52
+ select ${this.quote(_.column)}
53
+ from base
54
+ group by ${this.quote(_.column)}
55
+ ) t1
56
+ `),y=s?r?`ORDER BY ${R(this.adapter)}() LIMIT ${s}`:`LIMIT ${s}`:"",k=`
57
+ WITH base AS (
58
+ SELECT * FROM {{ref('${e}')}}
59
+ ${y}
60
+ )
61
+ SELECT * FROM (
62
+ ${u.join(`
63
+ UNION ALL
64
+ `)}
65
+ ) t2
66
+ WHERE CARDINALITY <= ${p}
67
+ ORDER BY ORDERING ASC
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
+ FROM base
75
+ WHERE ${this.quote(b.column)} IS NOT NULL
76
+ `),k=`
77
+ WITH base AS (
78
+ SELECT * FROM {{ref('${e}')}}
79
+ ${u}
80
+ )
81
+ SELECT * FROM (
82
+ ${y.join(`
83
+ UNION ALL
84
+ `)}
85
+ ) t1
86
+ ORDER BY ORDERING ASC
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
+ WITH base AS (
89
+ SELECT * FROM {{ref('${e}')}}
90
+ ${g}
91
+ )
92
+ ${m.map((w,E)=>`
93
+ SELECT
94
+ MAX(minutes_diff) AS max_minutes_diff,
95
+ AVG(minutes_diff) AS avg_minutes_diff,
96
+ STDDEV(minutes_diff) AS stddev_minutes_diff,
97
+ ${E+1} AS ordering
98
+ FROM (
99
+ SELECT
100
+ {{ dbt.datediff("LAG("~${this.quote(w.column,!0)}~", 1) OVER(ORDER BY "~${this.quote(w.column,!0)}~")", ${this.quote(w.column,!0)}, "minute") }} AS minutes_diff
101
+ FROM base
102
+ ) t2
103
+ WHERE minutes_diff <> 0
104
+ `).join(`
105
+ UNION ALL
106
+ `)}
107
+ ORDER BY ordering ASC
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;
@@ -0,0 +1,307 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+
4
+ /**
5
+ * Mock Service Worker.
6
+ * @see https://github.com/mswjs/msw
7
+ * - Please do NOT modify this file.
8
+ * - Please do NOT serve this file on production.
9
+ */
10
+
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
+
16
+ self.addEventListener('install', function () {
17
+ self.skipWaiting()
18
+ })
19
+
20
+ self.addEventListener('activate', function (event) {
21
+ event.waitUntil(self.clients.claim())
22
+ })
23
+
24
+ self.addEventListener('message', async function (event) {
25
+ const clientId = event.source.id
26
+
27
+ if (!clientId || !self.clients) {
28
+ return
29
+ }
30
+
31
+ const client = await self.clients.get(clientId)
32
+
33
+ if (!client) {
34
+ return
35
+ }
36
+
37
+ const allClients = await self.clients.matchAll({
38
+ type: 'window',
39
+ })
40
+
41
+ switch (event.data) {
42
+ case 'KEEPALIVE_REQUEST': {
43
+ sendToClient(client, {
44
+ type: 'KEEPALIVE_RESPONSE',
45
+ })
46
+ break
47
+ }
48
+
49
+ case 'INTEGRITY_CHECK_REQUEST': {
50
+ sendToClient(client, {
51
+ type: 'INTEGRITY_CHECK_RESPONSE',
52
+ payload: {
53
+ packageVersion: PACKAGE_VERSION,
54
+ checksum: INTEGRITY_CHECKSUM,
55
+ },
56
+ })
57
+ break
58
+ }
59
+
60
+ case 'MOCK_ACTIVATE': {
61
+ activeClientIds.add(clientId)
62
+
63
+ sendToClient(client, {
64
+ type: 'MOCKING_ENABLED',
65
+ payload: {
66
+ client: {
67
+ id: client.id,
68
+ frameType: client.frameType,
69
+ },
70
+ },
71
+ })
72
+ break
73
+ }
74
+
75
+ case 'MOCK_DEACTIVATE': {
76
+ activeClientIds.delete(clientId)
77
+ break
78
+ }
79
+
80
+ case 'CLIENT_CLOSED': {
81
+ activeClientIds.delete(clientId)
82
+
83
+ const remainingClients = allClients.filter((client) => {
84
+ return client.id !== clientId
85
+ })
86
+
87
+ // Unregister itself when there are no more clients
88
+ if (remainingClients.length === 0) {
89
+ self.registration.unregister()
90
+ }
91
+
92
+ break
93
+ }
94
+ }
95
+ })
96
+
97
+ self.addEventListener('fetch', function (event) {
98
+ const { request } = event
99
+
100
+ // Bypass navigation requests.
101
+ if (request.mode === 'navigate') {
102
+ return
103
+ }
104
+
105
+ // Opening the DevTools triggers the "only-if-cached" request
106
+ // that cannot be handled by the worker. Bypass such requests.
107
+ if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') {
108
+ return
109
+ }
110
+
111
+ // Bypass all requests when there are no active clients.
112
+ // Prevents the self-unregistered worked from handling requests
113
+ // after it's been deleted (still remains active until the next reload).
114
+ if (activeClientIds.size === 0) {
115
+ return
116
+ }
117
+
118
+ // Generate unique request ID.
119
+ const requestId = crypto.randomUUID()
120
+ event.respondWith(handleRequest(event, requestId))
121
+ })
122
+
123
+ async function handleRequest(event, requestId) {
124
+ const client = await resolveMainClient(event)
125
+ const response = await getResponse(event, client, requestId)
126
+
127
+ // Send back the response clone for the "response:*" life-cycle events.
128
+ // Ensure MSW is active and ready to handle the message, otherwise
129
+ // this message will pend indefinitely.
130
+ if (client && activeClientIds.has(client.id)) {
131
+ ;(async function () {
132
+ const responseClone = response.clone()
133
+
134
+ sendToClient(
135
+ client,
136
+ {
137
+ type: 'RESPONSE',
138
+ payload: {
139
+ requestId,
140
+ isMockedResponse: IS_MOCKED_RESPONSE in response,
141
+ type: responseClone.type,
142
+ status: responseClone.status,
143
+ statusText: responseClone.statusText,
144
+ body: responseClone.body,
145
+ headers: Object.fromEntries(responseClone.headers.entries()),
146
+ },
147
+ },
148
+ [responseClone.body],
149
+ )
150
+ })()
151
+ }
152
+
153
+ return response
154
+ }
155
+
156
+ // Resolve the main client for the given event.
157
+ // Client that issues a request doesn't necessarily equal the client
158
+ // that registered the worker. It's with the latter the worker should
159
+ // communicate with during the response resolving phase.
160
+ async function resolveMainClient(event) {
161
+ const client = await self.clients.get(event.clientId)
162
+
163
+ if (activeClientIds.has(event.clientId)) {
164
+ return client
165
+ }
166
+
167
+ if (client?.frameType === 'top-level') {
168
+ return client
169
+ }
170
+
171
+ const allClients = await self.clients.matchAll({
172
+ type: 'window',
173
+ })
174
+
175
+ return allClients
176
+ .filter((client) => {
177
+ // Get only those clients that are currently visible.
178
+ return client.visibilityState === 'visible'
179
+ })
180
+ .find((client) => {
181
+ // Find the client ID that's recorded in the
182
+ // set of clients that have registered the worker.
183
+ return activeClientIds.has(client.id)
184
+ })
185
+ }
186
+
187
+ async function getResponse(event, client, requestId) {
188
+ const { request } = event
189
+
190
+ // Clone the request because it might've been already used
191
+ // (i.e. its body has been read and sent to the client).
192
+ const requestClone = request.clone()
193
+
194
+ function passthrough() {
195
+ // Cast the request headers to a new Headers instance
196
+ // so the headers can be manipulated with.
197
+ const headers = new Headers(requestClone.headers)
198
+
199
+ // Remove the "accept" header value that marked this request as passthrough.
200
+ // This prevents request alteration and also keeps it compliant with the
201
+ // user-defined CORS policies.
202
+ const acceptHeader = headers.get('accept')
203
+ if (acceptHeader) {
204
+ const values = acceptHeader.split(',').map((value) => value.trim())
205
+ const filteredValues = values.filter(
206
+ (value) => value !== 'msw/passthrough',
207
+ )
208
+
209
+ if (filteredValues.length > 0) {
210
+ headers.set('accept', filteredValues.join(', '))
211
+ } else {
212
+ headers.delete('accept')
213
+ }
214
+ }
215
+
216
+ return fetch(requestClone, { headers })
217
+ }
218
+
219
+ // Bypass mocking when the client is not active.
220
+ if (!client) {
221
+ return passthrough()
222
+ }
223
+
224
+ // Bypass initial page load requests (i.e. static assets).
225
+ // The absence of the immediate/parent client in the map of the active clients
226
+ // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
227
+ // and is not ready to handle requests.
228
+ if (!activeClientIds.has(client.id)) {
229
+ return passthrough()
230
+ }
231
+
232
+ // Notify the client that a request has been intercepted.
233
+ const requestBuffer = await request.arrayBuffer()
234
+ const clientMessage = await sendToClient(
235
+ client,
236
+ {
237
+ type: 'REQUEST',
238
+ payload: {
239
+ id: requestId,
240
+ url: request.url,
241
+ mode: request.mode,
242
+ method: request.method,
243
+ headers: Object.fromEntries(request.headers.entries()),
244
+ cache: request.cache,
245
+ credentials: request.credentials,
246
+ destination: request.destination,
247
+ integrity: request.integrity,
248
+ redirect: request.redirect,
249
+ referrer: request.referrer,
250
+ referrerPolicy: request.referrerPolicy,
251
+ body: requestBuffer,
252
+ keepalive: request.keepalive,
253
+ },
254
+ },
255
+ [requestBuffer],
256
+ )
257
+
258
+ switch (clientMessage.type) {
259
+ case 'MOCK_RESPONSE': {
260
+ return respondWithMock(clientMessage.data)
261
+ }
262
+
263
+ case 'PASSTHROUGH': {
264
+ return passthrough()
265
+ }
266
+ }
267
+
268
+ return passthrough()
269
+ }
270
+
271
+ function sendToClient(client, message, transferrables = []) {
272
+ return new Promise((resolve, reject) => {
273
+ const channel = new MessageChannel()
274
+
275
+ channel.port1.onmessage = (event) => {
276
+ if (event.data && event.data.error) {
277
+ return reject(event.data.error)
278
+ }
279
+
280
+ resolve(event.data)
281
+ }
282
+
283
+ client.postMessage(
284
+ message,
285
+ [channel.port2].concat(transferrables.filter(Boolean)),
286
+ )
287
+ })
288
+ }
289
+
290
+ async function respondWithMock(response) {
291
+ // Setting response status code to 0 is a no-op.
292
+ // However, when responding with a "Response.error()", the produced Response
293
+ // instance will have status code set to 0. Since it's not possible to create
294
+ // a Response instance with status code 0, handle that use-case separately.
295
+ if (response.status === 0) {
296
+ return Response.error()
297
+ }
298
+
299
+ const mockedResponse = new Response(response.body, response)
300
+
301
+ Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
302
+ value: true,
303
+ enumerable: true,
304
+ })
305
+
306
+ return mockedResponse
307
+ }
@@ -0,0 +1,53 @@
1
+ // Copied from https://github.com/microsoft/vscode-jupyter/blob/main/build/ci/postInstall.js
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+
5
+ /**
6
+ * In order to get raw kernels working, we reuse the default kernel that jupyterlab ships.
7
+ * However it expects to be talking to a websocket which is serializing the messages to strings.
8
+ * Our raw kernel is not a web socket and needs to do its own serialization. To do so, we make a copy
9
+ * of the default kernel with the serialization stripped out. This is simpler than making a copy of the module
10
+ * at runtime.
11
+ */
12
+ function createJupyterKernelWithoutSerialization() {
13
+ var relativePath = path.join(
14
+ "node_modules",
15
+ "@jupyterlab",
16
+ "services",
17
+ "lib",
18
+ "kernel",
19
+ "default.js"
20
+ );
21
+ var filePath = path.join("", relativePath);
22
+ if (!fs.existsSync(filePath)) {
23
+ // If installing in extension, we need to go up one more level
24
+ filePath = path.join(__dirname, "../../../../", relativePath);
25
+ if (!fs.existsSync(filePath)) {
26
+ throw new Error(
27
+ "Jupyter lab default kernel not found '" +
28
+ filePath +
29
+ "' (Jupyter Extension post install script)"
30
+ );
31
+ }
32
+ }
33
+ var fileContents = fs.readFileSync(filePath, { encoding: "utf8" });
34
+ var replacedContents = fileContents
35
+ .replace(
36
+ /^const serialize =.*$/gm,
37
+ "const serialize = { serialize: (a) => a, deserialize: (a) => a };"
38
+ )
39
+ .replace(
40
+ "const owned = team.session === this.clientId;",
41
+ "const owned = parentHeader.session === this.clientId;"
42
+ );
43
+ if (replacedContents === fileContents) {
44
+ throw new Error(
45
+ "Jupyter lab default kernel cannot be made non serializing"
46
+ );
47
+ }
48
+ var destPath = path.join(path.dirname(filePath), "nonSerializingKernel.js");
49
+ fs.writeFileSync(destPath, replacedContents);
50
+ console.log(destPath + " file generated (by Jupyter VSC)");
51
+ }
52
+
53
+ createJupyterKernelWithoutSerialization();
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@altimateai/extension-components",
3
+ "version": "0.0.1-beta.10",
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
+ }
package/readme.md ADDED
@@ -0,0 +1,11 @@
1
+ ## Installation
2
+
3
+ To install the package, you can use either npm or yarn:
4
+
5
+ ```bash
6
+ # Using npm
7
+ npm install @altimateai/extension-components
8
+
9
+ # Using yarn
10
+ yarn add @altimateai/extension-components
11
+ ```