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

Function client

packages/core/fumadb/src/index.ts:100–153  ·  view source on GitHub ↗
(adapter)

Source from the content-addressed store, hash-verified

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() {
143 if (!adapter.createMigrationEngine)
144 throw new Error("The adapter doesn't support migration engine.");
145
146 return adapter.createMigrationEngine.call(adapterContext);
147 },
148
149 get abstract() {
150 return this.orm(schemas.at(-1)!.version) as any;
151 },
152 };
153 },
154 };
155}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected