bazis 0.136.0 → 0.137.0

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.
Files changed (75) hide show
  1. package/cli/main.ts +8 -0
  2. package/cli/parseCli.ts +9 -0
  3. package/cli/templates/module.ts +16 -19
  4. package/cli/templates/passport.ts +1 -1
  5. package/cli/upgrade/markColumns.ts +151 -0
  6. package/cli/upgrade/runUpgrade.ts +57 -0
  7. package/core/access/Access.module.ts +1 -1
  8. package/core/access/catalog/moduleFields.ts +16 -2
  9. package/core/access/catalog/permissions.ts +10 -0
  10. package/core/access/check/Access.ts +5 -5
  11. package/core/access/check/can.ts +2 -1
  12. package/core/access/index.ts +11 -1
  13. package/core/access/roles/roles.ts +4 -2
  14. package/core/agent/ToolRunner.ts +5 -0
  15. package/core/agent/session/entities.ts +45 -45
  16. package/core/http/Decorators/metadata.ts +3 -0
  17. package/core/http/Decorators/routes.ts +12 -0
  18. package/core/http/Errors/HttpError.ts +15 -1
  19. package/core/http/HttpServer.ts +19 -2
  20. package/core/http/Middleware/errorHandler.ts +16 -1
  21. package/core/http/OpenApi/openApiDocument.ts +43 -4
  22. package/core/http/Results/normalize.ts +38 -1
  23. package/core/http/Results/results.ts +5 -2
  24. package/core/http/Routing/RouterBuilder.ts +27 -2
  25. package/core/http/index.ts +3 -0
  26. package/core/http/middlewareTokens.ts +12 -0
  27. package/core/infra/connectors/codex/CodexAppServerClient.ts +1 -1
  28. package/core/infra/connectors/postgres.ts +4 -2
  29. package/core/infra/index.ts +1 -1
  30. package/core/kernel/config/defineConfig.ts +55 -19
  31. package/core/kernel/index.ts +3 -0
  32. package/core/orm/buildOrmProviders.ts +2 -1
  33. package/core/orm/contextEntities.ts +36 -0
  34. package/core/orm/databaseConnector.ts +9 -3
  35. package/core/orm/databaseHttpError.ts +21 -0
  36. package/core/orm/index.ts +12 -1
  37. package/core/orm/ormModule.ts +17 -7
  38. package/core/orm/ownedStoreContributions.ts +2 -1
  39. package/core/scripts/di-generate.ts +61 -4
  40. package/core/tools/StandardTools.module.ts +1 -1
  41. package/core/tools/contracts/Tools.config.ts +13 -7
  42. package/core/tools/generated/deps.ts +3 -3
  43. package/core/tools/http/HttpRequest.tool.ts +1 -2
  44. package/core/tools/http/publicAddress.ts +2 -2
  45. package/core/tools/orm/OrmEntity.references.ts +7 -8
  46. package/core/workflow/contracts/Workflow.config.ts +5 -5
  47. package/core/workflow/definitions_module/WorkflowDefinitions.module.ts +2 -2
  48. package/core/workflow/definitions_module/http/Processes.controller.ts +2 -2
  49. package/core/workflow/definitions_module/internal/PublishedVersions.ts +39 -0
  50. package/core/workflow/definitions_module/model/WfProcess.model.ts +24 -11
  51. package/core/workflow/definitions_module/model/WfVersion.model.ts +7 -1
  52. package/core/workflow/definitions_module/services/IWorkflowDefinitions.service.ts +4 -1
  53. package/core/workflow/definitions_module/services/WorkflowDefinitions.service.ts +17 -7
  54. package/core/workflow/generated/deps.ts +2 -1
  55. package/core/workflow/index.ts +9 -0
  56. package/core/workflow/internal/WorkflowLanguages.ts +1 -1
  57. package/core/workflow/internal/http.ts +2 -2
  58. package/core/workflow/runtime_module/background/WorkflowWorker.ts +6 -2
  59. package/core/workflow/runtime_module/http/Instances.controller.ts +1 -1
  60. package/core/workflow/runtime_module/internal/WorkflowJobs.ts +43 -1
  61. package/core/workflow/runtime_module/model/WfHistory.model.ts +13 -6
  62. package/core/workflow/runtime_module/model/WfInstance.model.ts +30 -10
  63. package/core/workflow/runtime_module/model/WfJob.model.ts +22 -10
  64. package/core/workflow/runtime_module/model/WfSubscription.model.ts +8 -3
  65. package/core/workflow/runtime_module/model/WfToken.model.ts +16 -7
  66. package/core/workflow/tasks_module/model/WfTask.model.ts +25 -9
  67. package/library/openapi/codegen.ts +2 -2
  68. package/library/orm/DbContext.ts +37 -1
  69. package/library/orm/Metadata/ModelBuilder.ts +23 -7
  70. package/library/orm/Metadata/decorators.ts +23 -10
  71. package/library/orm/Metadata/types.ts +2 -0
  72. package/library/orm/Transactions/TransactionScopeCoordinator.ts +3 -3
  73. package/library/orm/errors.ts +39 -1
  74. package/library/orm/index.ts +1 -0
  75. package/package.json +1 -1
@@ -103,7 +103,7 @@ export class EntityNotMappedError extends OrmError {
103
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
104
  : kind === "plain"
105
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().`,
106
+ : `Type "${name}" is not mapped in this DbContext. Declare a set for it in the context (this.set(${name})) or add it to entities of ormBazis, and annotate it with @Entity().`,
107
107
  );
108
108
  }
109
109
  }
@@ -168,6 +168,13 @@ export class OrmUndeclaredConflictTargetError extends OrmError {
168
168
  export class UniqueViolationError extends DbUpdateError {
169
169
  readonly constraint: string | undefined;
170
170
  readonly table: string | undefined;
171
+ /**
172
+ * The properties of the index or key that rejected the value, when a context
173
+ * with the entity of the table made the call; otherwise empty.
174
+ */
175
+ properties: readonly string[] = [];
176
+ /** `conflict` of the index: what to tell the client. */
177
+ conflict: string | undefined;
171
178
 
172
179
  constructor(cause: object) {
173
180
  const field = (name: string): string | undefined => {
@@ -284,3 +291,34 @@ export class OrmValidationError extends DbUpdateError {
284
291
  super(`Validation failed for "${entityName}": ${errors.map((error) => error.message).join("; ")}`);
285
292
  }
286
293
  }
294
+
295
+ /** What a context knows of a table, to name the properties of a violated constraint. */
296
+ export interface ViolationModels {
297
+ readonly entities: readonly {
298
+ readonly tableName: string;
299
+ readonly keyName?: string;
300
+ readonly key: readonly { readonly propertyName: string }[];
301
+ readonly properties: readonly { readonly propertyName: string; readonly columnName: string }[];
302
+ readonly indexes: readonly { readonly name: string; readonly columns: readonly string[]; readonly unique: boolean; readonly conflict?: string }[];
303
+ }[];
304
+ }
305
+
306
+ /** Names the properties behind a unique violation by the model of the context. Returns the same error. */
307
+ export function describeViolation(error: unknown, models: ViolationModels): unknown {
308
+ if (!(error instanceof UniqueViolationError) || error.constraint === undefined || error.properties.length > 0) return error;
309
+ for (const entity of models.entities) {
310
+ if (error.table !== undefined && entity.tableName !== error.table) continue;
311
+ const index = entity.indexes.find((item) => item.unique && item.name === error.constraint);
312
+ if (index !== undefined) {
313
+ error.properties = index.columns.map((column) => entity.properties.find((property) => property.columnName === column)?.propertyName ?? column);
314
+ error.conflict = index.conflict;
315
+ return error;
316
+ }
317
+ // `pk_<table>` is the name this ORM gives; `<table>_pkey` is PostgreSQL's own, from an older schema.
318
+ if (error.constraint === (entity.keyName ?? `pk_${entity.tableName}`) || error.constraint === `${entity.tableName}_pkey`) {
319
+ error.properties = entity.key.map((property) => property.propertyName);
320
+ return error;
321
+ }
322
+ }
323
+ return error;
324
+ }
@@ -12,6 +12,7 @@ export {
12
12
  OneToMany,
13
13
  QueryFilter,
14
14
  Required,
15
+ Nullable,
15
16
  Schema,
16
17
  SoftDelete,
17
18
  UpdatedAt,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bazis",
3
- "version": "0.136.0",
3
+ "version": "0.137.0",
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",