@jsnote-zeina/local-api 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/cells.js +27 -2
- package/package.json +4 -3
package/dist/routes/cells.js
CHANGED
|
@@ -18,7 +18,7 @@ const promises_1 = __importDefault(require("fs/promises"));
|
|
|
18
18
|
const path_1 = __importDefault(require("path"));
|
|
19
19
|
const defaultCells = [
|
|
20
20
|
{
|
|
21
|
-
content: 'JSNote-Zeina\n----------\nThis is an interactive coding environment. You can write Javascript, see it executed, and write
|
|
21
|
+
content: 'JSNote-Zeina\n----------\nThis is an interactive coding environment. You can write Javascript, see it executed, and write comprehensive documentation using markdown.\n\n- Click any text cell (including this one) to edit it\n- The code in each code editor is all joined into one file. If you define a variable in cell #1, you can refer to it in any following code cell!\n- You can show any React component, string, number, or anything else by calling the `show `function. This is a function built into this environment. Call show multiple times to show multiple values\n- Re-order or delete cells using the buttons on the top right \n- Add new cells by hovering on the divider between each cell\n\nAll of your changes get saved to the file you opened Jbook with. So if you ran `npx jsnote-zeina serve test.js` , all of the text and code you write will be saved to the `test.js` file.',
|
|
22
22
|
type: 'text',
|
|
23
23
|
id: 'ohbrr',
|
|
24
24
|
},
|
|
@@ -40,10 +40,35 @@ const createCellsRouter = (filename, dir) => {
|
|
|
40
40
|
const isLocalApiError = (err) => {
|
|
41
41
|
return typeof err === 'object' && err !== null && typeof err.code === 'string';
|
|
42
42
|
};
|
|
43
|
+
const isCell = (value) => {
|
|
44
|
+
if (typeof value !== 'object' || value === null)
|
|
45
|
+
return false;
|
|
46
|
+
const c = value;
|
|
47
|
+
return (typeof c.id === 'string' &&
|
|
48
|
+
typeof c.content === 'string' &&
|
|
49
|
+
(c.type === 'text' || c.type === 'code'));
|
|
50
|
+
};
|
|
51
|
+
const isCellArray = (value) => {
|
|
52
|
+
return Array.isArray(value) && value.every(isCell);
|
|
53
|
+
};
|
|
43
54
|
router.get('/cells', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
55
|
try {
|
|
45
56
|
const result = yield promises_1.default.readFile(fullPath, { encoding: 'utf-8' });
|
|
46
|
-
|
|
57
|
+
let parsed;
|
|
58
|
+
try {
|
|
59
|
+
parsed = JSON.parse(result);
|
|
60
|
+
}
|
|
61
|
+
catch (parseErr) {
|
|
62
|
+
console.error(`Notebook file ${fullPath} contains invalid JSON; serving defaults:`, parseErr);
|
|
63
|
+
res.send(defaultCells);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!isCellArray(parsed)) {
|
|
67
|
+
console.error(`Notebook file ${fullPath} does not match expected cell schema; serving defaults.`);
|
|
68
|
+
res.send(defaultCells);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
res.send(parsed);
|
|
47
72
|
}
|
|
48
73
|
catch (err) {
|
|
49
74
|
if (isLocalApiError(err) && err.code === 'ENOENT') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsnote-zeina/local-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "tsc --watch --preserveWatchOutput",
|
|
15
|
-
"
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
16
17
|
},
|
|
17
18
|
"keywords": [],
|
|
18
19
|
"author": "",
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"typescript": "^5.4.5"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"@jsnote-zeina/local-client": "^1.0.
|
|
27
|
+
"@jsnote-zeina/local-client": "^1.0.4",
|
|
27
28
|
"cors": "^2.8.5",
|
|
28
29
|
"express": "^4.19.2",
|
|
29
30
|
"http-proxy-middleware": "^3.0.0"
|