@statezero/core 0.1.74 → 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 +34 -21
- package/package.json +1 -1
|
@@ -243,8 +243,10 @@ const dtsActionTemplate = Handlebars.compile(TS_ACTION_DECLARATION_TEMPLATE);
|
|
|
243
243
|
// ================================================================================================
|
|
244
244
|
function generateZodSchemaForProperty(prop) {
|
|
245
245
|
let zodString;
|
|
246
|
-
if (prop.choices && prop.choices.length > 0) {
|
|
247
|
-
|
|
246
|
+
if (prop.choices && Object.keys(prop.choices).length > 0) {
|
|
247
|
+
// Extract just the keys (values) from the choices dict
|
|
248
|
+
const choiceValues = Object.keys(prop.choices);
|
|
249
|
+
zodString = `z.enum(${JSON.stringify(choiceValues)})`;
|
|
248
250
|
}
|
|
249
251
|
else {
|
|
250
252
|
switch (prop.type) {
|
|
@@ -327,8 +329,8 @@ function generateZodSchemaForProperty(prop) {
|
|
|
327
329
|
return zodString;
|
|
328
330
|
}
|
|
329
331
|
function generateTsTypeForProperty(prop) {
|
|
330
|
-
if (prop.choices && prop.choices.length > 0) {
|
|
331
|
-
return prop.choices
|
|
332
|
+
if (prop.choices && Object.keys(prop.choices).length > 0) {
|
|
333
|
+
return Object.keys(prop.choices)
|
|
332
334
|
.map((c) => `'${String(c).replace(/'/g, "\\'")}'`)
|
|
333
335
|
.join(" | ");
|
|
334
336
|
}
|
|
@@ -467,6 +469,7 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
467
469
|
const registryByBackend = {};
|
|
468
470
|
const schemasByBackend = {};
|
|
469
471
|
const allImports = new Set();
|
|
472
|
+
const allSchemaImports = new Set();
|
|
470
473
|
for (const file of generatedFiles) {
|
|
471
474
|
const backendKey = file.backend;
|
|
472
475
|
if (!backendKey)
|
|
@@ -480,12 +483,16 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
480
483
|
const importPath = path
|
|
481
484
|
.relative(process.cwd(), path.join(actionsDir, `${file.relativePath}.js`))
|
|
482
485
|
.replace(/\\/g, "/");
|
|
486
|
+
// Generate action import
|
|
483
487
|
const importStatement = `import { ${functionName} } from './${importPath}';`;
|
|
484
488
|
allImports.add(importStatement);
|
|
485
489
|
registryByBackend[backendKey].actions[file.action] = functionName;
|
|
486
|
-
//
|
|
490
|
+
// Generate schema import
|
|
491
|
+
const schemaImportName = `${functionName}Schema`;
|
|
487
492
|
const schemaPath = `./${importPath.replace(/\.js$/, '')}.schema.json`;
|
|
488
|
-
|
|
493
|
+
const schemaImportStatement = `import ${schemaImportName} from '${schemaPath}' assert { type: 'json' };`;
|
|
494
|
+
allSchemaImports.add(schemaImportStatement);
|
|
495
|
+
schemasByBackend[backendKey][file.action] = schemaImportName;
|
|
489
496
|
}
|
|
490
497
|
let registryContent = `/**
|
|
491
498
|
* This file was auto-generated. Do not make direct changes to the file.
|
|
@@ -493,9 +500,11 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
493
500
|
*/
|
|
494
501
|
|
|
495
502
|
`;
|
|
503
|
+
// Add action imports
|
|
496
504
|
registryContent += Array.from(allImports).sort().join("\n") + "\n\n";
|
|
497
|
-
// Add schema
|
|
498
|
-
registryContent +=
|
|
505
|
+
// Add schema imports
|
|
506
|
+
registryContent += Array.from(allSchemaImports).sort().join("\n") + "\n\n";
|
|
507
|
+
// Add ACTION_REGISTRY
|
|
499
508
|
registryContent += `export const ACTION_REGISTRY = {\n`;
|
|
500
509
|
Object.entries(registryByBackend).forEach(([backendKey, data], index, arr) => {
|
|
501
510
|
registryContent += ` '${backendKey}': {\n`;
|
|
@@ -506,6 +515,17 @@ async function generateActionRegistry(generatedFiles, backendConfigs) {
|
|
|
506
515
|
registryContent += ` }${index < arr.length - 1 ? "," : ""}\n`;
|
|
507
516
|
});
|
|
508
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`;
|
|
509
529
|
registryContent += `/**
|
|
510
530
|
* Get an action function by name and config key
|
|
511
531
|
* @param {string} actionName - The name of the action
|
|
@@ -522,25 +542,18 @@ export function getAction(actionName, configKey) {
|
|
|
522
542
|
}
|
|
523
543
|
|
|
524
544
|
/**
|
|
525
|
-
* Get the full schema for an action
|
|
545
|
+
* Get the full schema for an action
|
|
526
546
|
* @param {string} actionName - The name of the action
|
|
527
547
|
* @param {string} configKey - The backend config key
|
|
528
|
-
* @returns {
|
|
548
|
+
* @returns {Object|null} The action schema or null if not found
|
|
529
549
|
*/
|
|
530
|
-
export
|
|
531
|
-
const
|
|
532
|
-
if (!
|
|
550
|
+
export function getSchema(actionName, configKey) {
|
|
551
|
+
const schema = SCHEMA_REGISTRY[configKey]?.[actionName];
|
|
552
|
+
if (!schema) {
|
|
533
553
|
console.warn(\`Schema for action '\${actionName}' not found for config key '\${configKey}'.\`);
|
|
534
554
|
return null;
|
|
535
555
|
}
|
|
536
|
-
|
|
537
|
-
try {
|
|
538
|
-
const schema = await import(schemaPath, { assert: { type: 'json' } });
|
|
539
|
-
return schema.default || schema;
|
|
540
|
-
} catch (error) {
|
|
541
|
-
console.error(\`Error loading schema for action '\${actionName}':\`, error);
|
|
542
|
-
return null;
|
|
543
|
-
}
|
|
556
|
+
return schema;
|
|
544
557
|
}
|
|
545
558
|
`;
|
|
546
559
|
const registryFilePath = path.join(process.cwd(), "action-registry.js");
|
package/package.json
CHANGED