Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit a64295d

Browse files
committed
chore: port notebooks to markdown
BREAKING CHANGE: removes support for JSON notebooks
1 parent 77ea3a5 commit a64295d

File tree

66 files changed

+1068
-152443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1068
-152443
lines changed

packages/core/src/api/Util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ export { isHTML, isPromise } from '../util/types'
2424
// pretty printing
2525
export { prettyPrintTime } from '../webapp/util/time'
2626
export { default as prettyPrintBytes } from '../webapp/util/bytes'
27+
28+
// gzip+base64
29+
export { base64PlusGzip, decodeBase64PlusGzip } from '../util/gzip'

packages/core/src/core/events.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@ export type StatusStripeChangeEvent = {
3737
}
3838

3939
export type SnapshotRequestEvent = {
40-
cb: (snapshot: Buffer) => void
41-
filter?: (evt: CommandStartEvent) => boolean
42-
opts?: {
43-
name?: string
44-
description?: string
45-
preferReExecute?: boolean
46-
shallow?: boolean
47-
}
40+
/** Capture just one block? */
41+
execUUID?: string
42+
43+
cb?: (snapshot: Buffer) => void
4844
}
4945

5046
export type TabLayoutChangeEvent = { isSidecarNowHidden: boolean; isWidthConstrained?: boolean }
@@ -77,12 +73,6 @@ export interface NewTabRequestEvent {
7773
/** Execute the command line with qexec or pexec? Default: pexec. */
7874
exec?: 'pexec' | 'qexec'
7975

80-
/** Optionally open a snapshot file in the new tab */
81-
snapshot?: Buffer
82-
83-
/** Replace the contents of the current tab with that of the given snapshot? */
84-
replaceCurrentTab?: boolean
85-
8676
/** Optionally execute a command when the tab is closed */
8777
onClose?: string
8878
}[]

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export { splitIntoPipeStages } from './repl/pipe-stages'
124124
export { ReplEval, DirectReplEval } from './repl/types'
125125
export { default as encodeComponent } from './repl/encode'
126126
export { exec as internalBeCarefulExec, pexec as internalBeCarefulPExec, setEvaluatorImpl, doEval } from './repl/exec'
127-
export { CommandStartEvent, CommandCompleteEvent, Notebook, isNotebook, SnapshottedEvent } from './repl/events'
127+
export { CommandStartEvent, CommandCompleteEvent, SnapshottedEvent } from './repl/events'
128128

129129
// Tabs
130130
export {

packages/core/src/main/open.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { replay } from './notebooks'
1818

19-
export const filters = [{ name: 'Kui snapshot', extensions: ['kui', 'json'] }]
19+
export const filters = [{ name: 'Kui snapshot', extensions: ['md'] }]
2020

2121
/**
2222
* Open a file and replay its session.

packages/core/src/main/save.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { filters } from './open'
1817
import tellRendererToExecute from './tell'
19-
import encodeComponent from '../repl/encode'
20-
21-
let previousChoice: string
2218

2319
/**
2420
* Save the current tab as a Notebook
2521
*
2622
*/
2723
export default async function saveAsNotebook() {
28-
const { dialog } = await import('electron')
29-
30-
const resp = await dialog.showSaveDialog({
31-
title: 'Save as Notebook',
32-
filters,
33-
defaultPath: previousChoice
34-
})
35-
36-
if (!resp.canceled) {
37-
const thisChoice = resp.filePath
38-
previousChoice = thisChoice
39-
tellRendererToExecute(`snapshot ${encodeComponent(thisChoice)}`, 'pexec')
40-
}
24+
tellRendererToExecute(`snapshot`, 'pexec')
4125
}

packages/core/src/models/CommentaryResponse.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export type CommentaryResponse = {
2424
/** Content rendered inside the CardTitle */
2525
title?: string
2626

27+
/** Source filepath */
28+
filepath?: string
29+
2730
/** Body of the Card. It will be passed through as the source <Markdown source="..." /> */
2831
children: string
2932

packages/core/src/models/entity.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ export function isRawResponse<Content extends RawContent>(entity: Entity<Content
194194
return raw.mode === 'raw' && raw.content !== undefined
195195
}
196196

197-
type RandomErrorResponse1 = { code: string }
197+
type RandomErrorResponse1 = { code: string | number; message?: string }
198198
export function isRandomErrorResponse1(response: Entity): response is RandomErrorResponse1 {
199-
return typeof (response as RandomErrorResponse1).code === 'string'
199+
const code = (response as RandomErrorResponse1).code
200+
return typeof code === 'string' || typeof code === 'number'
200201
}
201202

202203
type RandomErrorResponse2 = { errno: string | number }

packages/core/src/repl/events.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,3 @@ export type CommandCompleteHandler<R extends KResponse = KResponse, T extends Re
6868
export type SnapshottedEvent<E extends CommandStartEvent | CommandCompleteEvent> = Omit<E, 'tab'> & {
6969
tab: E['tab']['uuid']
7070
}
71-
72-
export interface Notebook {
73-
apiVersion: 'kui-shell/v1'
74-
kind: 'Notebook'
75-
metadata?: {
76-
name?: string
77-
description?: string
78-
preferReExecute?: boolean
79-
}
80-
}
81-
82-
/** @return wether or not the given `raw` json is an instance of Notebook */
83-
export function isNotebook(raw: Record<string, any>): raw is Notebook {
84-
const model = raw as Notebook
85-
return model.apiVersion === 'kui-shell/v1' && model.kind === 'Notebook'
86-
}

packages/core/src/util/gzip.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2021 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { gunzipSync, gzipSync } from 'zlib'
18+
19+
/**
20+
* @return a base64-encoded and gzip-compressed version of the given
21+
* `plaintext`
22+
*
23+
*/
24+
export function base64PlusGzip(plaintext: string, compress = true): string {
25+
if (!compress) {
26+
return Buffer.from(plaintext).toString('base64')
27+
}
28+
29+
return Buffer.from(gzipSync(plaintext)).toString('base64')
30+
}
31+
32+
/** @return the reverse of `base64PlusGzip` */
33+
export function decodeBase64PlusGzip(data: string, compressed = true): Buffer {
34+
if (!compressed) {
35+
return Buffer.from(data, 'base64')
36+
} else {
37+
return gunzipSync(Buffer.from(data, 'base64'))
38+
}
39+
}

plugins/plugin-bash-like/fs/src/vfs/TrieVFS.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ export abstract class TrieVFS<D extends any, L extends Leaf<D> = Leaf<D>> implem
186186
public cp(_, srcFilepaths: string[], dstFilepath: string): Promise<string> {
187187
return Promise.all(
188188
srcFilepaths.map(srcFilepath => {
189-
const match1 = srcFilepath.match(/^plugin:\/\/plugin-(.*)\/notebooks\/(.*)\.json$/)
190-
const match2 = srcFilepath.match(/^plugin:\/\/client\/notebooks\/(.*)\.json$/)
189+
const match1 = srcFilepath.match(/^plugin:\/\/plugin-(.*)\/notebooks\/(.*)\.md$/)
190+
const match2 = srcFilepath.match(/^plugin:\/\/client\/notebooks\/(.*)\.md$/)
191191
const match3 = srcFilepath.match(/^plugin:\/\/client\/(.*)\.md$/)
192192
const match = match1 || match2 || match3
193193
if (match) {
194-
const extension = match1 || match2 ? '.json' : '.md'
194+
const extension = '.md'
195195

196196
const dir = dirname(dstFilepath)
197197
if (!this.trieGet(dir)) {
@@ -202,7 +202,7 @@ export abstract class TrieVFS<D extends any, L extends Leaf<D> = Leaf<D>> implem
202202
this.trie.map(mountPath, { mountPath, data: { srcFilepath } })
203203
}
204204
} else {
205-
throw new Error(`Unable to copy given source into the notebooks VFS: ${srcFilepath}`)
205+
throw new Error(`Unable to copy given source into the VFS: ${srcFilepath}`)
206206
}
207207
})
208208
).then(() => 'ok')

0 commit comments

Comments
 (0)