MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / fumadb

Function fumadb

packages/core/fumadb/src/index.ts:85–155  ·  view source on GitHub ↗
(
  config: LibraryConfig<Schemas>
)

Source from the content-addressed store, hash-verified

83 : never;
84
85export function fumadb<Schemas extends AnySchema[]>(
86 config: LibraryConfig<Schemas>
87): FumaDBFactory<Schemas> {
88 const schemas = config.schemas.sort((a, b) => compare(a.version, b.version));
89 return {
90 names: createNameVariantsBuilder(config.namespace, schemas, (schemas) => {
91 return fumadb({
92 ...config,
93 schemas,
94 });
95 }),
96 version(targetVersion) {
97 return targetVersion;
98 },
99
100 client(adapter) {
101 const orms = new Map<string, AbstractQuery<AnySchema>>();
102 const adapterContext: FumaDBAdapterContext = {
103 ...config,
104 };
105
106 return {
107 adapter,
108 schemas,
109 orm(version) {
110 let orm = orms.get(version);
111 if (orm) return orm;
112
113 const schema = schemas.find((schema) => schema.version === version);
114 if (!schema) throw new Error(`unknown schema version ${version}`);
115
116 orm = adapter.createORM.call(adapterContext, schema);
117 orms.set(version, orm);
118 return orm as any;
119 },
120 async version() {
121 const version = await adapter.getSchemaVersion.call(adapterContext);
122 if (!version)
123 throw new Error(`FumaDB ${config.namespace} is not initialized.`);
124
125 return version;
126 },
127 generateSchema(version, name = config.namespace) {
128 if (!adapter.generateSchema)
129 throw new Error("The adapter doesn't support schema API.");
130 let schema: AnySchema;
131
132 if (version === "latest") {
133 schema = schemas.at(-1)!;
134 } else {
135 schema = schemas.find((schema) => schema.version === version)!;
136 if (!schema) throw new Error(`Invalid version: ${version}`);
137 }
138
139 return adapter.generateSchema.call(adapterContext, schema, name);
140 },
141
142 createMigrator() {

Callers 9

createDefaultMemoryDbFunction · 0.90
createExecutorFumaDbFunction · 0.90
migrate.test.tsFile · 0.90
cli.tsFile · 0.90
query.test.tsFile · 0.90
relations.test.tsFile · 0.90
createPostgresFumaDbFunction · 0.90
schemaGenerateActionFunction · 0.85

Calls 1

Tested by 1

createPostgresFumaDbFunction · 0.72