bazis 0.109.0 → 0.110.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.
@@ -199,6 +199,15 @@ export function validateModuleEncapsulation(
199
199
  : `which module "${owner.name}" provides but does not export. Add it to the exports of "${owner.name}".`;
200
200
  };
201
201
 
202
+ // Whether `record` imports `target`, directly or through other modules. Such a
203
+ // module cannot be the fix: importing it into `target` would be a cycle, and a
204
+ // root without exports (AppModule, the kernel root) passes on everything.
205
+ const importsModule = (record: ModuleGraphRecord, target: ModuleGraphRecord, path = new Set<ModuleGraphRecord>()): boolean => {
206
+ if (path.has(record)) return false;
207
+ path.add(record);
208
+ return record.imports.some((imported) => imported === target || importsModule(imported as ModuleGraphRecord, target, path));
209
+ };
210
+
202
211
  // A closed token (`IRepository<Product>`) travels with its family export, so
203
212
  // the fix is named in family terms and skips unnamed inner modules such as
204
213
  // the one `ormBazis` creates.
@@ -208,7 +217,7 @@ export function validateModuleEncapsulation(
208
217
  const exportFix = `${family} (or only ${closed})`;
209
218
  const sees = (record: ModuleGraphRecord) => visibleFamilies(record).has(familyId) || visibleTokens(record).has(token);
210
219
  const passes = (record: ModuleGraphRecord) => exportedFamilies(record).has(familyId) || exportedTokens(record).has(token);
211
- const named = (record: ModuleGraphRecord) => !/^module#\d+$/.test(record.name);
220
+ const named = (record: ModuleGraphRecord) => !/^module#\d+$/.test(record.name) && !importsModule(record, consumer);
212
221
  const blocking = consumer.imports.find((imported) => named(imported) && sees(imported) && !passes(imported));
213
222
  if (blocking !== undefined) {
214
223
  return `which its import "${blocking.name}" receives from its own imports but does not export. Add ${exportFix} to the exports of "${blocking.name}".`;
@@ -1,4 +1,5 @@
1
1
  import type { ServiceScope } from "../../di";
2
+ import { HttpSetupError } from "../Errors/HttpError";
2
3
 
3
4
  // Same one-line polyfill as the rest of the HTTP module: Bun executes TC39
4
5
  // decorators natively, but Symbol.metadata may be missing in the runtime.
@@ -46,6 +47,8 @@ interface AuthActionMeta {
46
47
  allowAnonymous?: boolean;
47
48
  /** Declaration made on this exact class/method metadata object. */
48
49
  declaration?: "authorize" | "anonymous";
50
+ /** Both `@Authorize` and `@AllowAnonymous` were declared here. */
51
+ conflict?: true;
49
52
  }
50
53
 
51
54
  interface AuthControllerMeta {
@@ -53,6 +56,8 @@ interface AuthControllerMeta {
53
56
  allowAnonymous?: boolean;
54
57
  /** Declaration made on this exact class metadata object. */
55
58
  declaration?: "authorize" | "anonymous";
59
+ /** Both `@Authorize` and `@AllowAnonymous` were declared on the class. */
60
+ conflict?: true;
56
61
  actions: Map<string | symbol, AuthActionMeta>;
57
62
  }
58
63
 
@@ -105,8 +110,15 @@ function ownActionMeta(metadata: object, methodName: string | symbol): AuthActio
105
110
  return action;
106
111
  }
107
112
 
113
+ // The other declaration on the same class or method: each would silently undo
114
+ // the other and the decorator order would decide. Reported when routes are built.
115
+ function markConflict(target: { declaration?: "authorize" | "anonymous"; conflict?: true }, declaration: "authorize" | "anonymous"): void {
116
+ if (target.declaration !== undefined && target.declaration !== declaration) target.conflict = true;
117
+ }
118
+
108
119
  export function setControllerAuthorize(metadata: object, options: AuthorizeOptions): void {
109
120
  const meta = ownMeta(metadata);
121
+ markConflict(meta, "authorize");
110
122
  meta.authorize = meta.declaration === "authorize" && meta.authorize
111
123
  ? { checks: [...options.checks, ...meta.authorize.checks] }
112
124
  : options;
@@ -116,6 +128,7 @@ export function setControllerAuthorize(metadata: object, options: AuthorizeOptio
116
128
 
117
129
  export function setControllerAllowAnonymous(metadata: object): void {
118
130
  const meta = ownMeta(metadata);
131
+ markConflict(meta, "anonymous");
119
132
  meta.allowAnonymous = true;
120
133
  meta.declaration = "anonymous";
121
134
  delete meta.authorize;
@@ -123,6 +136,7 @@ export function setControllerAllowAnonymous(metadata: object): void {
123
136
 
124
137
  export function setActionAuthorize(metadata: object, methodName: string | symbol, options: AuthorizeOptions): void {
125
138
  const action = ownActionMeta(metadata, methodName);
139
+ markConflict(action, "authorize");
126
140
  action.authorize = action.declaration === "authorize" && action.authorize
127
141
  ? { checks: [...options.checks, ...action.authorize.checks] }
128
142
  : options;
@@ -132,6 +146,7 @@ export function setActionAuthorize(metadata: object, methodName: string | symbol
132
146
 
133
147
  export function setActionAllowAnonymous(metadata: object, methodName: string | symbol): void {
134
148
  const action = ownActionMeta(metadata, methodName);
149
+ markConflict(action, "anonymous");
135
150
  action.allowAnonymous = true;
136
151
  action.declaration = "anonymous";
137
152
  delete action.authorize;
@@ -153,6 +168,7 @@ export interface ResolvedAuthorizeMeta {
153
168
  *
154
169
  * Inheritance is different: a subclass's own class-level declaration replaces
155
170
  * the base class's, and an overriding method's declaration replaces the base method's.
171
+ * Both decorators on the same class or method throw `HttpSetupError`.
156
172
  */
157
173
  export function resolveAuthorizeMeta(ctor: object, methodName: string | symbol): ResolvedAuthorizeMeta {
158
174
  const metadata = (ctor as { [key: symbol]: unknown })[Symbol.metadata as unknown as symbol] as
@@ -163,7 +179,20 @@ export function resolveAuthorizeMeta(ctor: object, methodName: string | symbol):
163
179
  return { allowAnonymous: false };
164
180
  }
165
181
 
182
+ const owner = (ctor as { readonly name?: string }).name || "Controller";
183
+ if (meta.conflict) {
184
+ throw new HttpSetupError(
185
+ `${owner} has both @AllowAnonymous() and @Authorize(...) on the class: the result would depend on the decorator order. `
186
+ + "Keep one; to open single methods of a protected class, put @AllowAnonymous() on them.",
187
+ );
188
+ }
166
189
  const action = meta.actions.get(methodName);
190
+ if (action?.conflict) {
191
+ throw new HttpSetupError(
192
+ `${owner}.${String(methodName)} has both @AllowAnonymous() and @Authorize(...): the result would depend on the decorator order. `
193
+ + "Keep @Authorize(...) to protect the route, or @AllowAnonymous() to open it.",
194
+ );
195
+ }
167
196
  if (action?.allowAnonymous) {
168
197
  return { allowAnonymous: true };
169
198
  }
@@ -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.109.0" }, capabilities: { experimentalApi: true },
235
+ clientInfo: { name: "bazis", title: "Bazis", version: "0.110.0" }, 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");
@@ -84,10 +84,25 @@ function redactValue(
84
84
  if (depth >= options.maxDepth) {
85
85
  return options.replacement;
86
86
  }
87
+ // `seen` holds the objects on the current path only: an object reached
88
+ // again through another branch is a shared reference, not a cycle.
87
89
  if (seen.has(value)) {
88
90
  return CIRCULAR;
89
91
  }
90
92
  seen.add(value);
93
+ try {
94
+ return redactObject(value, options, seen, depth);
95
+ } finally {
96
+ seen.delete(value);
97
+ }
98
+ }
99
+
100
+ function redactObject(
101
+ value: object,
102
+ options: NormalizedRedactionOptions,
103
+ seen: WeakSet<object>,
104
+ depth: number,
105
+ ): unknown {
91
106
  if (value instanceof Error) {
92
107
  return redactError(value, options, seen, depth);
93
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bazis",
3
- "version": "0.109.0",
3
+ "version": "0.110.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",