@statezero/core 0.1.75 → 0.1.76
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/cli/commands/syncActions.js +28 -17
- package/package.json +1 -1
|
@@ -469,6 +469,7 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
469
469
|
const registryByBackend = {};
|
|
470
470
|
const schemasByBackend = {};
|
|
471
471
|
const allImports = new Set();
|
|
472
|
+
const allSchemaImports = new Set();
|
|
472
473
|
for (const file of generatedFiles) {
|
|
473
474
|
const backendKey = file.backend;
|
|
474
475
|
if (!backendKey)
|
|
@@ -482,12 +483,16 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
482
483
|
const importPath = path
|
|
483
484
|
.relative(process.cwd(), path.join(actionsDir, `${file.relativePath}.js`))
|
|
484
485
|
.replace(/\\/g, "/");
|
|
486
|
+
// Generate action import
|
|
485
487
|
const importStatement = `import { ${functionName} } from './${importPath}';`;
|
|
486
488
|
allImports.add(importStatement);
|
|
487
489
|
registryByBackend[backendKey].actions[file.action] = functionName;
|
|
488
|
-
//
|
|
490
|
+
// Generate schema import
|
|
491
|
+
const schemaImportName = `${functionName}Schema`;
|
|
489
492
|
const schemaPath = `./${importPath.replace(/\.js$/, '')}.schema.json`;
|
|
490
|
-
|
|
493
|
+
const schemaImportStatement = `import ${schemaImportName} from '${schemaPath}' assert { type: 'json' };`;
|
|
494
|
+
allSchemaImports.add(schemaImportStatement);
|
|
495
|
+
schemasByBackend[backendKey][file.action] = schemaImportName;
|
|
491
496
|
}
|
|
492
497
|
let registryContent = `/**
|
|
493
498
|
* This file was auto-generated. Do not make direct changes to the file.
|
|
@@ -495,9 +500,11 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
495
500
|
*/
|
|
496
501
|
|
|
497
502
|
`;
|
|
503
|
+
// Add action imports
|
|
498
504
|
registryContent += Array.from(allImports).sort().join("\n") + "\n\n";
|
|
499
|
-
// Add schema
|
|
500
|
-
registryContent +=
|
|
505
|
+
// Add schema imports
|
|
506
|
+
registryContent += Array.from(allSchemaImports).sort().join("\n") + "\n\n";
|
|
507
|
+
// Add ACTION_REGISTRY
|
|
501
508
|
registryContent += `export const ACTION_REGISTRY = {\n`;
|
|
502
509
|
Object.entries(registryByBackend).forEach(([backendKey, data], index, arr) => {
|
|
503
510
|
registryContent += ` '${backendKey}': {\n`;
|
|
@@ -508,6 +515,17 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
508
515
|
registryContent += ` }${index < arr.length - 1 ? "," : ""}\n`;
|
|
509
516
|
});
|
|
510
517
|
registryContent += `};\n\n`;
|
|
518
|
+
// Add SCHEMA_REGISTRY
|
|
519
|
+
registryContent += `export const SCHEMA_REGISTRY = {\n`;
|
|
520
|
+
Object.entries(schemasByBackend).forEach(([backendKey, schemas], index, arr) => {
|
|
521
|
+
registryContent += ` '${backendKey}': {\n`;
|
|
522
|
+
const schemaEntries = Object.entries(schemas);
|
|
523
|
+
schemaEntries.forEach(([actionName, schemaName], idx, schemasArr) => {
|
|
524
|
+
registryContent += ` '${actionName}': ${schemaName}${idx < schemasArr.length - 1 ? "," : ""}\n`;
|
|
525
|
+
});
|
|
526
|
+
registryContent += ` }${index < arr.length - 1 ? "," : ""}\n`;
|
|
527
|
+
});
|
|
528
|
+
registryContent += `};\n\n`;
|
|
511
529
|
registryContent += `/**
|
|
512
530
|
* Get an action function by name and config key
|
|
513
531
|
* @param {string} actionName - The name of the action
|
|
@@ -524,25 +542,18 @@ export function getAction(actionName, configKey) {
|
|
|
524
542
|
}
|
|
525
543
|
|
|
526
544
|
/**
|
|
527
|
-
* Get the full schema for an action
|
|
545
|
+
* Get the full schema for an action
|
|
528
546
|
* @param {string} actionName - The name of the action
|
|
529
547
|
* @param {string} configKey - The backend config key
|
|
530
|
-
* @returns {
|
|
548
|
+
* @returns {Object|null} The action schema or null if not found
|
|
531
549
|
*/
|
|
532
|
-
export
|
|
533
|
-
const
|
|
534
|
-
if (!
|
|
550
|
+
export function getSchema(actionName, configKey) {
|
|
551
|
+
const schema = SCHEMA_REGISTRY[configKey]?.[actionName];
|
|
552
|
+
if (!schema) {
|
|
535
553
|
console.warn(\`Schema for action '\${actionName}' not found for config key '\${configKey}'.\`);
|
|
536
554
|
return null;
|
|
537
555
|
}
|
|
538
|
-
|
|
539
|
-
try {
|
|
540
|
-
const schema = await import(schemaPath, { assert: { type: 'json' } });
|
|
541
|
-
return schema.default || schema;
|
|
542
|
-
} catch (error) {
|
|
543
|
-
console.error(\`Error loading schema for action '\${actionName}':\`, error);
|
|
544
|
-
return null;
|
|
545
|
-
}
|
|
556
|
+
return schema;
|
|
546
557
|
}
|
|
547
558
|
`;
|
|
548
559
|
const registryFilePath = path.join(process.cwd(), "action-registry.js");
|
package/package.json
CHANGED