@lark-base-open/base-database-toolchain 1.0.0 → 1.1.0

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,137 @@
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
+ import { extname, join, relative } from 'node:path';
3
+ import { parse } from '@babel/parser';
4
+ const channelPackage = '@lark-base-open/base-site-channel';
5
+ const extensions = new Set(['.ts', '.tsx', '.js', '.jsx']);
6
+ function isNode(value) {
7
+ return (value !== null &&
8
+ typeof value === 'object' &&
9
+ 'type' in value &&
10
+ typeof value.type === 'string');
11
+ }
12
+ // Visit only AST nodes, excluding locations, comments and other parser metadata.
13
+ function walk(value, visit) {
14
+ if (!isNode(value))
15
+ return;
16
+ visit(value);
17
+ for (const [key, child] of Object.entries(value)) {
18
+ if (key === 'comments' || key.endsWith('Comments') || key === 'tokens')
19
+ continue;
20
+ if (Array.isArray(child))
21
+ child.forEach((node) => walk(node, visit));
22
+ else if (isNode(child))
23
+ walk(child, visit);
24
+ }
25
+ }
26
+ function identifier(value, name) {
27
+ return isNode(value) && value.type === 'Identifier' && value.name === name;
28
+ }
29
+ function stringLiteral(value, text) {
30
+ return (isNode(value) && value.type === 'StringLiteral' && value.value === text);
31
+ }
32
+ /** Best-effort syntax warning; does not resolve symbols or execute user code. */
33
+ export function checkLinkGuard(workspace) {
34
+ const root = join(workspace, 'page/src');
35
+ if (!existsSync(root))
36
+ return [];
37
+ const files = [];
38
+ const collect = (directory) => {
39
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
40
+ const path = join(directory, entry.name);
41
+ if (entry.isDirectory() && entry.name !== 'node_modules')
42
+ collect(path);
43
+ else if (entry.isFile() && extensions.has(extname(path)))
44
+ files.push(path);
45
+ }
46
+ };
47
+ collect(root);
48
+ const locations = [];
49
+ let installed = false;
50
+ for (const path of files.sort()) {
51
+ let source;
52
+ try {
53
+ source = parse(readFileSync(path, 'utf8'), {
54
+ sourceType: 'unambiguous',
55
+ plugins: ['typescript', 'jsx'],
56
+ errorRecovery: true,
57
+ });
58
+ // Recovered syntax is also unreliable: discard this file's entire result.
59
+ if (source.errors?.length)
60
+ continue;
61
+ }
62
+ catch {
63
+ continue;
64
+ }
65
+ const guards = new Set();
66
+ const namespaces = new Set();
67
+ for (const statement of source.program.body) {
68
+ if (statement.type !== 'ImportDeclaration' ||
69
+ statement.source.value !== channelPackage ||
70
+ statement.importKind === 'type')
71
+ continue;
72
+ for (const specifier of statement.specifiers) {
73
+ if (specifier.type === 'ImportNamespaceSpecifier')
74
+ namespaces.add(specifier.local.name);
75
+ else if (specifier.type === 'ImportSpecifier' &&
76
+ specifier.importKind !== 'type' &&
77
+ (specifier.imported.type === 'Identifier'
78
+ ? specifier.imported.name
79
+ : specifier.imported.value) === 'installLinkGuard')
80
+ guards.add(specifier.local.name);
81
+ }
82
+ }
83
+ walk(source.program, (node) => {
84
+ if (node.type === 'CallExpression' ||
85
+ node.type === 'OptionalCallExpression') {
86
+ const callee = node.callee;
87
+ if (isNode(callee)) {
88
+ if (callee.type === 'Identifier' &&
89
+ typeof callee.name === 'string' &&
90
+ guards.has(callee.name))
91
+ installed = true;
92
+ if ((callee.type === 'MemberExpression' ||
93
+ callee.type === 'OptionalMemberExpression') &&
94
+ !callee.computed &&
95
+ identifier(callee.property, 'installLinkGuard') &&
96
+ isNode(callee.object) &&
97
+ callee.object.type === 'Identifier' &&
98
+ typeof callee.object.name === 'string' &&
99
+ namespaces.has(callee.object.name))
100
+ installed = true;
101
+ }
102
+ }
103
+ const windowOpen = (node.type === 'MemberExpression' ||
104
+ node.type === 'OptionalMemberExpression') &&
105
+ identifier(node.object, 'window') &&
106
+ (node.computed
107
+ ? stringLiteral(node.property, 'open')
108
+ : identifier(node.property, 'open'));
109
+ const blankTarget = node.type === 'JSXAttribute' &&
110
+ isNode(node.name) &&
111
+ node.name.type === 'JSXIdentifier' &&
112
+ node.name.name === 'target' &&
113
+ (stringLiteral(node.value, '_blank') ||
114
+ (isNode(node.value) &&
115
+ node.value.type === 'JSXExpressionContainer' &&
116
+ stringLiteral(node.value.expression, '_blank')));
117
+ if (windowOpen || blankTarget) {
118
+ // Every parsed source node has a location; metadata nodes are not visited.
119
+ const loc = node.loc;
120
+ locations.push({
121
+ file: relative(workspace, path),
122
+ line: loc.start.line,
123
+ column: loc.start.column + 1,
124
+ });
125
+ }
126
+ });
127
+ }
128
+ return installed || locations.length === 0
129
+ ? []
130
+ : [
131
+ {
132
+ code: 'PAGE_LINK_GUARD_MISSING',
133
+ message: 'Page uses window.open or target="_blank" without a statically detected installLinkGuard call. Follow the installed Channel SDK documentation for >=0.1.5 and initialize its guard in the entry; review any dependency upgrade before changing versions.',
134
+ locations,
135
+ },
136
+ ];
137
+ }
@@ -1,21 +1,23 @@
1
1
  {
2
2
  "name": "@lark-base-open/base-database-toolchain",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@lark-base-open/base-database-toolchain",
9
- "version": "1.0.0",
9
+ "version": "1.1.0",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "dependencies": {
12
12
  "@babel/parser": "7.28.5",
13
13
  "@babel/traverse": "7.28.5",
14
14
  "ajv": "8.17.1",
15
15
  "esbuild": "0.28.2",
16
- "jsonc-parser": "3.3.1"
16
+ "jsonc-parser": "3.3.1",
17
+ "parse5": "7.3.0"
17
18
  },
18
19
  "bin": {
20
+ "base-database-dev": "bin/base-database-dev.mjs",
19
21
  "base-database-toolchain": "bin/base-database-toolchain.mjs"
20
22
  },
21
23
  "devDependencies": {
@@ -1007,6 +1009,18 @@
1007
1009
  }
1008
1010
  }
1009
1011
  },
1012
+ "node_modules/entities": {
1013
+ "version": "6.0.1",
1014
+ "resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz",
1015
+ "integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==",
1016
+ "license": "BSD-2-Clause",
1017
+ "engines": {
1018
+ "node": ">=0.12"
1019
+ },
1020
+ "funding": {
1021
+ "url": "https://github.com/fb55/entities?sponsor=1"
1022
+ }
1023
+ },
1010
1024
  "node_modules/esbuild": {
1011
1025
  "version": "0.28.2",
1012
1026
  "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz",
@@ -1106,6 +1120,18 @@
1106
1120
  "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
1107
1121
  "license": "MIT"
1108
1122
  },
1123
+ "node_modules/parse5": {
1124
+ "version": "7.3.0",
1125
+ "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.3.0.tgz",
1126
+ "integrity": "sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==",
1127
+ "license": "MIT",
1128
+ "dependencies": {
1129
+ "entities": "^6.0.0"
1130
+ },
1131
+ "funding": {
1132
+ "url": "https://github.com/inikulin/parse5?sponsor=1"
1133
+ }
1134
+ },
1109
1135
  "node_modules/picocolors": {
1110
1136
  "version": "1.1.1",
1111
1137
  "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-base-open/base-database-toolchain",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared local development toolchain for Base Database application CLIs",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -8,7 +8,8 @@
8
8
  "node": ">=20.19.0"
9
9
  },
10
10
  "bin": {
11
- "base-database-toolchain": "bin/base-database-toolchain.mjs"
11
+ "base-database-toolchain": "bin/base-database-toolchain.mjs",
12
+ "base-database-dev": "bin/base-database-dev.mjs"
12
13
  },
13
14
  "exports": {
14
15
  ".": {
@@ -35,11 +36,23 @@
35
36
  "types": "./dist/sdk-codegen.d.ts",
36
37
  "import": "./dist/sdk-codegen.js"
37
38
  },
39
+ "./batch": {
40
+ "types": "./dist/function-batch.d.ts",
41
+ "import": "./dist/function-batch.js"
42
+ },
38
43
  "./schema": {
39
44
  "types": "./dist/app-builder/schema.d.ts",
40
45
  "import": "./dist/app-builder/schema.js"
41
46
  },
42
- "./builder": "./dist/app-builder/core.mjs"
47
+ "./builder": "./dist/app-builder/core.mjs",
48
+ "./page-inspection": {
49
+ "types": "./dist/page-inspection.d.ts",
50
+ "import": "./dist/page-inspection.js"
51
+ },
52
+ "./development": {
53
+ "types": "./dist/development.d.ts",
54
+ "import": "./dist/development.js"
55
+ }
43
56
  },
44
57
  "files": [
45
58
  "dist",
@@ -66,7 +79,8 @@
66
79
  "@babel/traverse": "7.28.5",
67
80
  "ajv": "8.17.1",
68
81
  "esbuild": "0.28.2",
69
- "jsonc-parser": "3.3.1"
82
+ "jsonc-parser": "3.3.1",
83
+ "parse5": "7.3.0"
70
84
  },
71
85
  "devDependencies": {
72
86
  "typescript": "7.0.2",