bazis 0.98.23 → 0.98.24
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.
|
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
|
|
|
232
232
|
if (method === "account/updated") this.modelCache = undefined;
|
|
233
233
|
}, () => { this.clearLogin(); this.modelCache = undefined; });
|
|
234
234
|
const initialized = await client.request("initialize", {
|
|
235
|
-
clientInfo: { name: "bazis", title: "Bazis", version: "0.98.
|
|
235
|
+
clientInfo: { name: "bazis", title: "Bazis", version: "0.98.24" }, capabilities: { experimentalApi: true },
|
|
236
236
|
}, 15_000, signal);
|
|
237
237
|
if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
|
|
238
238
|
client.notify("initialized");
|
package/library/orm/DbContext.ts
CHANGED
|
@@ -59,7 +59,7 @@ export abstract class DbContext {
|
|
|
59
59
|
setByName(name: string): DbSet<Record<string, unknown>> {
|
|
60
60
|
const model = this.#options.model.tryByName(name);
|
|
61
61
|
if (!model) {
|
|
62
|
-
throw new EntityNotMappedError(name);
|
|
62
|
+
throw new EntityNotMappedError(name, "dynamic");
|
|
63
63
|
}
|
|
64
64
|
return new DbSet<Record<string, unknown>>(model, this.#runtime);
|
|
65
65
|
}
|
|
@@ -184,13 +184,12 @@ function buildDynamicModelWithCtor(
|
|
|
184
184
|
const keys = properties.filter((property) => property.isKey);
|
|
185
185
|
if (def.primaryKey && keys.length > 0) throw new ModelBuildError(`Dynamic table "${def.name}" cannot combine primaryKey with legacy isKey.`);
|
|
186
186
|
if (keys.length === 0 && !def.primaryKey) {
|
|
187
|
-
throw new ModelBuildError(`Dynamic table "${def.name}" has no primary key. Mark one field with isKey.`);
|
|
187
|
+
throw new ModelBuildError(`Dynamic table "${def.name}" has no primary key. Mark one field with isKey, or set primaryKey: { properties: [...] }.`);
|
|
188
188
|
}
|
|
189
189
|
if (keys.length > 1) {
|
|
190
|
+
const names = keys.map((key) => key.propertyName);
|
|
190
191
|
throw new ModelBuildError(
|
|
191
|
-
`Dynamic table "${def.name}" declares
|
|
192
|
-
.map((key) => key.propertyName)
|
|
193
|
-
.join('", "')}"). Composite keys are not supported.`,
|
|
192
|
+
`Dynamic table "${def.name}" declares several isKey fields ("${names.join('", "')}"). Mark one field with isKey, or for a composite key use primaryKey: { properties: ["${names.join('", "')}"] }.`,
|
|
194
193
|
);
|
|
195
194
|
}
|
|
196
195
|
const key = keys[0];
|
|
@@ -70,6 +70,9 @@ export class OrmModel {
|
|
|
70
70
|
|
|
71
71
|
/** Model for an instance, by its constructor. */
|
|
72
72
|
requireForInstance(entity: object): EntityModel {
|
|
73
|
+
// Rows of dynamic tables are plain objects; their model is known only to setByName().
|
|
74
|
+
const prototype = Object.getPrototypeOf(entity);
|
|
75
|
+
if (prototype === Object.prototype || prototype === null) throw new EntityNotMappedError("Object", "plain");
|
|
73
76
|
return this.requireByCtor(entity.constructor as EntityClass);
|
|
74
77
|
}
|
|
75
78
|
|
package/library/orm/errors.ts
CHANGED
|
@@ -96,9 +96,14 @@ export class EntityNotFoundError extends OrmError {
|
|
|
96
96
|
|
|
97
97
|
/** The class is not registered as an entity in this context. */
|
|
98
98
|
export class EntityNotMappedError extends OrmError {
|
|
99
|
-
|
|
99
|
+
/** `dynamic`: looked up by name through `setByName`; `plain`: a plain object, not an entity instance. */
|
|
100
|
+
constructor(name: string, kind: "class" | "dynamic" | "plain" = "class") {
|
|
100
101
|
super(
|
|
101
|
-
|
|
102
|
+
kind === "dynamic"
|
|
103
|
+
? `No entity or dynamic model named "${name}" is registered in this DbContext. Register a dynamic table first: options.model.registerModel(buildDynamicModel({ name: "${name}", fields: [...] })).`
|
|
104
|
+
: kind === "plain"
|
|
105
|
+
? `A plain object is not an entity class. For a dynamic table add the row through its set: db.setByName("Table").add(row).`
|
|
106
|
+
: `Type "${name}" is not mapped in this DbContext. Add it to ormModule({ entities: [...] }) and annotate it with @Entity().`,
|
|
102
107
|
);
|
|
103
108
|
}
|
|
104
109
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bazis",
|
|
3
|
-
"version": "0.98.
|
|
3
|
+
"version": "0.98.24",
|
|
4
4
|
"description": "Modular backend framework for Bun in TypeScript: DI wired by codegen, HTTP, a PostgreSQL ORM, JWT, WebSocket, agents and a CLI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Alexander Alenin",
|