bazis 0.136.0 → 0.138.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 (132) hide show
  1. package/README.md +7 -4
  2. package/cli/generateProject.ts +11 -18
  3. package/cli/main.ts +9 -1
  4. package/cli/parseCli.ts +9 -0
  5. package/cli/templates/module.ts +16 -19
  6. package/cli/templates/passport.ts +2 -2
  7. package/cli/upgrade/markColumns.ts +151 -0
  8. package/cli/upgrade/runUpgrade.ts +57 -0
  9. package/core/access/Access.module.ts +1 -1
  10. package/core/access/catalog/moduleFields.ts +41 -4
  11. package/core/access/catalog/permissions.ts +10 -0
  12. package/core/access/check/Access.ts +5 -5
  13. package/core/access/check/can.ts +2 -1
  14. package/core/access/index.ts +11 -1
  15. package/core/access/roles/roles.ts +4 -2
  16. package/core/access/testing/index.ts +26 -4
  17. package/core/agent/ToolRunner.ts +7 -1
  18. package/core/agent/defineTool.ts +109 -0
  19. package/core/agent/index.ts +8 -3
  20. package/core/agent/moduleContributions-v1.ts +3 -10
  21. package/core/agent/session/entities.ts +45 -45
  22. package/core/app/index.ts +1 -1
  23. package/core/app/messages.ts +3 -3
  24. package/core/app/runApp.ts +90 -26
  25. package/core/cache/ICache.ts +1 -1
  26. package/core/cache/README.md +4 -2
  27. package/core/cache/SPEC.md +16 -9
  28. package/core/cache/http/missingCacheModuleCheck.ts +5 -4
  29. package/core/cache/internal/buildCacheProviders.ts +4 -5
  30. package/core/cache/providers/cachedProviders.ts +1 -1
  31. package/core/di/index.ts +0 -4
  32. package/core/di/lowLevel.ts +12 -0
  33. package/core/di/module/index.ts +0 -3
  34. package/core/di/module/shortcuts.ts +31 -86
  35. package/core/generatedRuntime.ts +11 -0
  36. package/core/grpc/Grpc.module.ts +2 -1
  37. package/core/grpc/grpcClients.ts +2 -1
  38. package/core/http/Authorization/metadata.ts +1 -1
  39. package/core/http/Decorators/metadata.ts +3 -0
  40. package/core/http/Decorators/routes.ts +12 -0
  41. package/core/http/Errors/HttpError.ts +16 -2
  42. package/core/http/Http.config.ts +22 -0
  43. package/core/http/HttpContext/HttpContext.ts +1 -1
  44. package/core/http/HttpServer.ts +29 -9
  45. package/core/http/Middleware/errorHandler.ts +16 -1
  46. package/core/http/OpenApi/openApiDocument.ts +44 -5
  47. package/core/http/Results/normalize.ts +38 -1
  48. package/core/http/Results/results.ts +5 -2
  49. package/core/http/Routing/RouterBuilder.ts +27 -2
  50. package/core/http/httpModule.ts +10 -8
  51. package/core/http/index.ts +4 -0
  52. package/core/http/middlewareTokens.ts +12 -0
  53. package/core/http/options.ts +5 -1
  54. package/core/http-client/httpClients.ts +2 -1
  55. package/core/infra/Infra.ts +3 -3
  56. package/core/infra/connectors/codex/CodexAppServerClient.ts +1 -1
  57. package/core/infra/connectors/codex/contracts.ts +3 -3
  58. package/core/infra/connectors/llm.ts +2 -1
  59. package/core/infra/connectors/postgres.ts +4 -2
  60. package/core/infra/connectors/redis.ts +2 -1
  61. package/core/infra/index.ts +1 -1
  62. package/core/kernel/KernelBuilder.ts +2 -1
  63. package/core/kernel/config/ConfigRegistry.ts +2 -1
  64. package/core/kernel/config/addConfigOptions.ts +2 -1
  65. package/core/kernel/config/defineConfig.ts +56 -20
  66. package/core/kernel/events/EventBus.ts +1 -0
  67. package/core/kernel/events/eventSubscribers.ts +1 -1
  68. package/core/kernel/events/onEvent.ts +2 -1
  69. package/core/kernel/index.ts +3 -0
  70. package/core/orm/buildOrmProviders.ts +4 -2
  71. package/core/orm/contextEntities.ts +36 -0
  72. package/core/orm/databaseConnector.ts +9 -3
  73. package/core/orm/databaseHttpError.ts +21 -0
  74. package/core/orm/encryptedWith.ts +1 -1
  75. package/core/orm/index.ts +12 -1
  76. package/core/orm/ormModule.ts +19 -8
  77. package/core/orm/ownedStoreContributions.ts +2 -1
  78. package/core/orm/registerRepositories.ts +2 -1
  79. package/core/scripts/di-generate.ts +113 -12
  80. package/core/testing/index.ts +51 -11
  81. package/core/tools/StandardTools.module.ts +1 -1
  82. package/core/tools/contracts/Tools.config.ts +13 -7
  83. package/core/tools/generated/deps.ts +3 -3
  84. package/core/tools/http/HttpRequest.tool.ts +1 -2
  85. package/core/tools/http/publicAddress.ts +2 -2
  86. package/core/tools/index.ts +1 -1
  87. package/core/tools/orm/OrmEntity.references.ts +7 -8
  88. package/core/tools/orm/ormEntityTools.ts +54 -28
  89. package/core/websocket/DESIGN.md +5 -3
  90. package/core/websocket/middleware.ts +1 -1
  91. package/core/websocket/websocketModule.ts +3 -3
  92. package/core/workflow/contracts/Workflow.config.ts +5 -5
  93. package/core/workflow/definitions_module/WorkflowDefinitions.module.ts +3 -4
  94. package/core/workflow/definitions_module/code/defineProcess.ts +213 -11
  95. package/core/workflow/definitions_module/code/inspectProcesses.ts +12 -2
  96. package/core/workflow/definitions_module/http/Processes.controller.ts +2 -2
  97. package/core/workflow/definitions_module/internal/PublishedVersions.ts +39 -0
  98. package/core/workflow/definitions_module/model/WfProcess.model.ts +24 -11
  99. package/core/workflow/definitions_module/model/WfVersion.model.ts +7 -1
  100. package/core/workflow/definitions_module/services/IWorkflowDefinitions.service.ts +4 -1
  101. package/core/workflow/definitions_module/services/WorkflowDefinitions.service.ts +17 -7
  102. package/core/workflow/generated/deps.ts +2 -1
  103. package/core/workflow/index.ts +23 -1
  104. package/core/workflow/internal/WorkflowLanguages.ts +1 -1
  105. package/core/workflow/internal/http.ts +2 -2
  106. package/core/workflow/runtime_module/background/WorkflowWorker.ts +6 -2
  107. package/core/workflow/runtime_module/http/Instances.controller.ts +1 -1
  108. package/core/workflow/runtime_module/internal/WorkflowJobs.ts +43 -1
  109. package/core/workflow/runtime_module/model/WfHistory.model.ts +13 -6
  110. package/core/workflow/runtime_module/model/WfInstance.model.ts +30 -10
  111. package/core/workflow/runtime_module/model/WfJob.model.ts +22 -10
  112. package/core/workflow/runtime_module/model/WfSubscription.model.ts +8 -3
  113. package/core/workflow/runtime_module/model/WfToken.model.ts +16 -7
  114. package/core/workflow/runtime_module/services/IWorkflowRuntime.service.ts +10 -6
  115. package/core/workflow/runtime_module/services/WorkflowRuntime.service.ts +5 -2
  116. package/core/workflow/tasks_module/model/WfTask.model.ts +25 -9
  117. package/core/workflow/testing/index.ts +46 -4
  118. package/index.ts +4 -3
  119. package/library/openapi/codegen.ts +2 -2
  120. package/library/orm/DbContext.ts +37 -1
  121. package/library/orm/Metadata/ModelBuilder.ts +23 -7
  122. package/library/orm/Metadata/decorators.ts +23 -10
  123. package/library/orm/Metadata/types.ts +2 -0
  124. package/library/orm/Transactions/TransactionScopeCoordinator.ts +3 -3
  125. package/library/orm/errors.ts +39 -1
  126. package/library/orm/index.ts +1 -0
  127. package/library/terminal/messages.ts +6 -6
  128. package/library/validation/README.md +1 -1
  129. package/library/validation/SPEC.md +1 -1
  130. package/library/workflow/index.ts +1 -0
  131. package/library/workflow/nodeConfigs.ts +130 -0
  132. package/package.json +2 -1
@@ -0,0 +1,130 @@
1
+ import type { Expr } from "./expressions";
2
+ import type { FormSpec } from "./formFields";
3
+ import type { LocalizedText } from "./localized";
4
+ import type { NodeKind } from "./ProcessDocument";
5
+
6
+ /** Automatic retries of a failed Tool call. */
7
+ export interface RetryPolicy {
8
+ /** 1–10. */
9
+ readonly maxAttempts: number;
10
+ /** The pause before a retry: an ISO duration. */
11
+ readonly backoff?: string;
12
+ readonly growth?: "fixed" | "exponential";
13
+ /** For `exponential` growth: 1–100. */
14
+ readonly factor?: number;
15
+ }
16
+
17
+ /** A timer: a duration from now, or a path to a moment in instance data. */
18
+ export type TimerConfig = { readonly duration: string; readonly at?: never } | { readonly at: string; readonly duration?: never };
19
+
20
+ /** Tool or process input: parameter → a literal, a path string (`$input.orderId`) or an expression. */
21
+ export type InputMapping = Readonly<Record<string, Expr>>;
22
+
23
+ /**
24
+ * The `config` of a node by its kind: what `NODE_KINDS` checks at run time,
25
+ * as types. `validateProcess` stays the judge of a stored document; these
26
+ * types help to write one.
27
+ */
28
+ export interface NodeConfigs {
29
+ readonly manualStart: Readonly<Record<string, never>>;
30
+ readonly scheduleStart: {
31
+ /** Five fields: minute hour day month weekday. */
32
+ readonly cron: string;
33
+ /** An IANA time zone; UTC by default. */
34
+ readonly timezone?: string;
35
+ readonly from?: string;
36
+ readonly until?: string;
37
+ readonly overlap?: "skip" | "queue" | "parallel";
38
+ readonly catchUp?: boolean;
39
+ readonly partitions?: "none" | "all" | readonly string[];
40
+ };
41
+ readonly eventStart: {
42
+ readonly event: string;
43
+ readonly filter?: Expr;
44
+ readonly debounce?: { readonly key: Expr; readonly window: string };
45
+ readonly delay?: string;
46
+ readonly ignoreOwn?: boolean;
47
+ };
48
+ readonly userTask: {
49
+ readonly assignee: { readonly role: string; readonly user?: never } | { readonly user: string; readonly role?: never };
50
+ readonly form?: FormSpec;
51
+ readonly dueIn?: string;
52
+ readonly saveTo?: string;
53
+ };
54
+ readonly serviceTask: {
55
+ readonly tool: string;
56
+ readonly input?: InputMapping;
57
+ readonly saveTo?: string;
58
+ readonly timeout?: string;
59
+ readonly retry?: RetryPolicy;
60
+ readonly onError?: "fail" | "skip";
61
+ };
62
+ readonly assign: {
63
+ readonly assignments: readonly { readonly var: string; readonly value: Expr }[];
64
+ };
65
+ readonly loop: {
66
+ readonly over?: Expr;
67
+ readonly while?: Expr;
68
+ readonly times?: number;
69
+ readonly item?: string;
70
+ readonly index?: string;
71
+ readonly maxIterations: number;
72
+ readonly parallel?: { readonly limit: number };
73
+ readonly onItemError?: "stop" | "skip";
74
+ readonly collect?: { readonly from: Expr; readonly to: string };
75
+ };
76
+ readonly callProcess: {
77
+ readonly process: string;
78
+ readonly input?: InputMapping;
79
+ readonly saveTo?: string;
80
+ readonly onError?: "fail" | "skip";
81
+ };
82
+ readonly timerCatch: TimerConfig;
83
+ readonly eventWait: {
84
+ readonly event: string;
85
+ readonly correlation?: string;
86
+ readonly saveTo?: string;
87
+ readonly until?: Expr;
88
+ };
89
+ readonly exclusiveGateway: Readonly<Record<string, never>>;
90
+ readonly parallelGateway: Readonly<Record<string, never>>;
91
+ readonly boundaryError: { readonly errorCode?: string };
92
+ readonly boundaryTimer: TimerConfig & { readonly interrupting?: boolean };
93
+ readonly boundaryEvent: { readonly event: string; readonly correlation?: string; readonly interrupting?: boolean };
94
+ readonly end: Readonly<Record<string, never>>;
95
+ }
96
+
97
+ /** The kinds whose `config` has required fields. */
98
+ export type ConfiguredNodeKind = "scheduleStart" | "eventStart" | "userTask" | "serviceTask" | "assign" | "loop" | "callProcess" | "timerCatch" | "eventWait" | "boundaryTimer" | "boundaryEvent";
99
+ /** The kinds attached to a step. */
100
+ export type BoundaryNodeKind = "boundaryError" | "boundaryTimer" | "boundaryEvent";
101
+
102
+ /**
103
+ * A node of one kind with its own `config`. `Id` is what `attachedTo` and
104
+ * `parent` may name: the ids of the nodes of the document. `Configs` lets the
105
+ * owner of a document widen single configs (a Tool by reference in code).
106
+ */
107
+ export type ProcessNodeOf<K extends NodeKind, Id extends string = string, Configs extends Record<NodeKind, object> = NodeConfigs> = {
108
+ readonly kind: K;
109
+ readonly title: LocalizedText;
110
+ /** The `loop` whose body the node belongs to. */
111
+ readonly parent?: Id;
112
+ /** The application's data by namespace; the engine does not read it. */
113
+ readonly extensions?: Readonly<Record<string, unknown>>;
114
+ }
115
+ & (K extends ConfiguredNodeKind ? { readonly config: Configs[K] } : { readonly config?: Configs[K] })
116
+ & (K extends BoundaryNodeKind ? { /** The step the node is attached to. */ readonly attachedTo: Id } : { readonly attachedTo?: never });
117
+
118
+ /** A node of any kind, with the `config` its kind takes. */
119
+ export type TypedProcessNode<Id extends string = string, Configs extends Record<NodeKind, object> = NodeConfigs> = { [K in NodeKind]: ProcessNodeOf<K, Id, Configs> }[NodeKind];
120
+
121
+ /** A flow between two of the nodes named by `Id`. */
122
+ export interface TypedProcessFlow<Id extends string = string> {
123
+ readonly source: Id;
124
+ readonly target: Id;
125
+ readonly title?: LocalizedText;
126
+ /** Condition of a flow that leaves an exclusive gateway. */
127
+ readonly condition?: Expr;
128
+ /** The flow an exclusive gateway takes when no condition holds. */
129
+ readonly isDefault?: boolean;
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bazis",
3
- "version": "0.136.0",
3
+ "version": "0.138.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",
@@ -35,6 +35,7 @@
35
35
  "./core/background": "./core/background/index.ts",
36
36
  "./core/cache": "./core/cache/index.ts",
37
37
  "./core/di": "./core/di/index.ts",
38
+ "./core/di/lowLevel": "./core/di/lowLevel.ts",
38
39
  "./core/generatedRuntime": "./core/generatedRuntime.ts",
39
40
  "./core/grpc": "./core/grpc/index.ts",
40
41
  "./core/http": "./core/http/index.ts",