Skip to content

Commit 987bea7

Browse files
committed
Add tool definitions operations and schemas
1 parent 2de72b1 commit 987bea7

Some content is hidden

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

64 files changed

+6913
-65
lines changed

packages/lexical/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
"access": "public"
3030
},
3131
"scripts": {
32-
"build": "gulp resources-to-lib && tsc && webpack && npm run build:lib",
33-
"build:lib": "tsc",
34-
"build:prod": "gulp resources-to-lib && tsc && jlpm clean && jlpm build:lib",
32+
"build": "npm run validate:tools && gulp resources-to-lib && tsc && webpack && npm run build:lib",
33+
"build:lib": "npm run validate:tools && tsc",
34+
"build:prod": "npm run validate:tools && gulp resources-to-lib && tsc && jlpm clean && jlpm build:lib",
3535
"build:tsc:watch": "run-p 'build:tsc:watch:*'",
3636
"build:tsc:watch:res": "gulp resources-to-lib-watch",
3737
"build:tsc:watch:tsc": "tsc --watch",
@@ -57,6 +57,7 @@
5757
"stylelint:check": "stylelint --cache \"style/**/*.css\"",
5858
"test": "jest --coverage",
5959
"typedoc": "typedoc ./src",
60+
"validate:tools": "node scripts/validate-tools-sync.js",
6061
"watch": "run-p watch:src",
6162
"watch:src": "tsc -w"
6263
},
@@ -78,6 +79,7 @@
7879
"@lexical/table": "^0.35.0",
7980
"@lexical/utils": "^0.35.0",
8081
"@lexical/yjs": "^0.35.0",
82+
"@toon-format/toon": "^1.3.0",
8183
"autoprefixer": "^10.4.21",
8284
"katex": "^0.16.21",
8385
"lexical": "^0.35.0",
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Copyright (c) 2021-2025 Datalayer, Inc.
4+
*
5+
* MIT License
6+
*/
7+
8+
/**
9+
* Validation script to ensure tool definitions and operations stay in sync.
10+
*
11+
* Checks:
12+
* 1. Every definition has a corresponding operation
13+
* 2. Every operation has a corresponding definition
14+
* 3. Tool names match between definition and operation
15+
* 4. No orphaned files
16+
*
17+
* Usage: npm run validate:tools
18+
*/
19+
20+
const fs = require('fs');
21+
const path = require('path');
22+
23+
const TOOLS_DIR = path.join(__dirname, '../src/tools');
24+
const DEFINITIONS_DIR = path.join(TOOLS_DIR, 'definitions');
25+
const OPERATIONS_DIR = path.join(TOOLS_DIR, 'operations');
26+
27+
function getToolFiles(dir) {
28+
const files = fs.readdirSync(dir);
29+
return files
30+
.filter(f => f.endsWith('.ts') && f !== 'index.ts')
31+
.map(f => ({
32+
name: f.replace('.ts', ''),
33+
path: path.join(dir, f),
34+
}));
35+
}
36+
37+
function extractToolName(filePath) {
38+
const content = fs.readFileSync(filePath, 'utf-8');
39+
40+
// For definitions: export const xxxTool
41+
const defMatch = content.match(/export const (\w+)Tool:/);
42+
if (defMatch) {
43+
return defMatch[1]; // e.g., "insertBlock" from "insertBlockTool"
44+
}
45+
46+
// For operations: export const xxxOperation
47+
const opMatch = content.match(/export const (\w+)Operation:/);
48+
if (opMatch) {
49+
return opMatch[1]; // e.g., "insertBlock" from "insertBlockOperation"
50+
}
51+
52+
return null;
53+
}
54+
55+
function main() {
56+
console.log('🔍 Validating lexical tool definitions and operations sync...\n');
57+
58+
const definitions = getToolFiles(DEFINITIONS_DIR);
59+
const operations = getToolFiles(OPERATIONS_DIR);
60+
61+
console.log(`Found ${definitions.length} definitions:`);
62+
definitions.forEach(d => console.log(` - ${d.name}`));
63+
console.log();
64+
65+
console.log(`Found ${operations.length} operations:`);
66+
operations.forEach(o => console.log(` - ${o.name}`));
67+
console.log();
68+
69+
let hasErrors = false;
70+
71+
// Check 1: File name alignment
72+
const defNames = new Set(definitions.map(d => d.name));
73+
const opNames = new Set(operations.map(o => o.name));
74+
75+
// Find definitions without operations
76+
const missingOps = definitions.filter(d => !opNames.has(d.name));
77+
if (missingOps.length > 0) {
78+
console.error('❌ Definitions without matching operations:');
79+
missingOps.forEach(d => console.error(` ${d.name}`));
80+
hasErrors = true;
81+
}
82+
83+
// Find operations without definitions
84+
const missingDefs = operations.filter(o => !defNames.has(o.name));
85+
if (missingDefs.length > 0) {
86+
console.error('❌ Operations without matching definitions:');
87+
missingDefs.forEach(o => console.error(` ${o.name}`));
88+
hasErrors = true;
89+
}
90+
91+
// Check 2: Tool name extraction from file content
92+
console.log('\n📝 Checking exported names...');
93+
for (const def of definitions) {
94+
const toolName = extractToolName(def.path);
95+
if (!toolName) {
96+
console.error(`❌ Could not extract tool name from ${def.name}`);
97+
hasErrors = true;
98+
} else if (toolName !== def.name) {
99+
console.error(
100+
`❌ File name mismatch: ${def.name}.ts exports ${toolName}Tool`
101+
);
102+
hasErrors = true;
103+
}
104+
}
105+
106+
for (const op of operations) {
107+
const toolName = extractToolName(op.path);
108+
if (!toolName) {
109+
console.error(`❌ Could not extract tool name from ${op.name}`);
110+
hasErrors = true;
111+
} else if (toolName !== op.name) {
112+
console.error(
113+
`❌ File name mismatch: ${op.name}.ts exports ${toolName}Operation`
114+
);
115+
hasErrors = true;
116+
}
117+
}
118+
119+
// Summary
120+
console.log('\n' + '='.repeat(60));
121+
if (hasErrors) {
122+
console.error('❌ Validation FAILED - lexical tools are out of sync!');
123+
process.exit(1);
124+
} else {
125+
console.log('✅ Validation PASSED - all lexical tools are in sync!');
126+
console.log(`\n ${definitions.length} definition(s)`);
127+
console.log(` ${operations.length} operation(s)`);
128+
console.log(' Perfect 1:1 alignment! 🎉');
129+
}
130+
}
131+
132+
main();

packages/lexical/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export * from './hooks';
1212
export * from './nodes';
1313
export * from './plugins';
1414
export * from './themes';
15+
export * from './tools';
1516
export * from './utils';

0 commit comments

Comments
 (0)