@fibery/ai-utils
Version:
Utilities for Fibery AI
45 lines • 1.84 kB
JavaScript
import { factory } from '@fibery/schema';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export const mockEnumFetcher = async (types) => {
return Object.fromEntries(types.map(x => [x.name, [
{ id: 'w1', name: 'Not started', rank: '1', color: 'gray' },
{ id: 'w2', name: 'Started', rank: '2', color: 'blue' },
{ id: 'w3', name: 'Finished', rank: '3', color: 'green', isFinal: true },
]]));
};
export const mockExecuteCommands = async (commands) => {
return commands.map(() => ({
success: true,
result: [
{ id: 'w1', name: 'Not started', rank: '1', color: 'gray', icon: '' },
{ id: 'w2', name: 'Started', rank: '2', color: 'blue', icon: '' },
{ id: 'w3', name: 'Finished', rank: '3', color: 'green', icon: '', isFinal: true },
]
}));
};
export const loadTestSchema = () => {
const schemaPath = path.join(__dirname, 'test-data', 'schema.json');
const schemaData = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
return factory.makeSchema(schemaData);
};
export const getDomainTypes = (schema) => {
return schema.typeObjects.filter((type) => type.isDomain);
};
export const getEnumTypes = (schema) => {
return schema.typeObjects.filter((type) => type.isEnum);
};
export const getSpaceNames = (schema) => {
const spaceNames = new Set();
schema.typeObjects.forEach((type) => {
if (type.isDomain || type.name === 'fibery/file' || type.name === 'comments/comment') {
spaceNames.add(type.nameParts.namespace);
}
});
return Array.from(spaceNames);
};
//# sourceMappingURL=mocks.js.map