bazis 0.105.3 → 0.106.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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AsyncResolutionRequiredError,
|
|
3
3
|
ClassDependenciesMismatchError,
|
|
4
|
+
DiError,
|
|
4
5
|
InvalidProviderError,
|
|
5
6
|
NamedDependencyNotFoundError,
|
|
6
7
|
ProviderNotFoundError,
|
|
@@ -44,7 +45,27 @@ import {
|
|
|
44
45
|
import type { Token } from "./token";
|
|
45
46
|
import { tokenToDebugName } from "./token";
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* `ServiceProvider` as a service in a scope sees that scope, as .NET's
|
|
50
|
+
* IServiceProvider does: `resolve` returns the scope's services and
|
|
51
|
+
* `createScope()` opens a new one. The scope is disposed by whoever created it.
|
|
52
|
+
*/
|
|
53
|
+
class ScopeServiceProvider extends ServiceScope {
|
|
54
|
+
public constructor(provider: ConstructorParameters<typeof ServiceScope>[0], state: ResolutionScopeState, private readonly root: ServiceProvider) {
|
|
55
|
+
super(provider, state);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public createScope(): ServiceScope {
|
|
59
|
+
return this.root.createScope();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public override dispose(): Promise<void> {
|
|
63
|
+
return Promise.reject(new DiError("This ServiceProvider is the scope that resolved the service; whoever created the scope disposes it. To own a scope, call createScope() and dispose that one."));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
47
67
|
export class ServiceProvider implements ServiceResolver {
|
|
68
|
+
private readonly scopeProviders = new WeakMap<ResolutionScopeState, ScopeServiceProvider>();
|
|
48
69
|
private readonly registry: ServiceRegistry;
|
|
49
70
|
private readonly activations = new ResolutionTracker();
|
|
50
71
|
private readonly lifetime: ScopeLifecycle;
|
|
@@ -185,6 +206,17 @@ export class ServiceProvider implements ServiceResolver {
|
|
|
185
206
|
return this.lifetime.disposeScope(scopeState);
|
|
186
207
|
}
|
|
187
208
|
|
|
209
|
+
/** `ServiceProvider` asked for inside a scope: the scope itself, not the root. */
|
|
210
|
+
private providerForScope<T>(token: Token<T>, key: ServiceKey | undefined, scopeState: ResolutionScopeState): T | undefined {
|
|
211
|
+
if (token !== (ServiceProvider as unknown) || key !== undefined || scopeState.isRoot) return undefined;
|
|
212
|
+
let view = this.scopeProviders.get(scopeState);
|
|
213
|
+
if (view === undefined) {
|
|
214
|
+
view = new ScopeServiceProvider(this, scopeState, this);
|
|
215
|
+
this.scopeProviders.set(scopeState, view);
|
|
216
|
+
}
|
|
217
|
+
return view as unknown as T;
|
|
218
|
+
}
|
|
219
|
+
|
|
188
220
|
private resolveSingle<T>(
|
|
189
221
|
token: Token<T>,
|
|
190
222
|
key: ServiceKey | undefined,
|
|
@@ -192,6 +224,8 @@ export class ServiceProvider implements ServiceResolver {
|
|
|
192
224
|
stack: ResolutionActivation[],
|
|
193
225
|
ownerLifetime: ProviderLifetime | undefined,
|
|
194
226
|
): T {
|
|
227
|
+
const scopeProvider = this.providerForScope(token, key, scopeState);
|
|
228
|
+
if (scopeProvider !== undefined) return scopeProvider;
|
|
195
229
|
const registration = this.registry.find(token, key);
|
|
196
230
|
if (!registration) {
|
|
197
231
|
throw new ProviderNotFoundError(token, this.describeResolutionPath(stack, token));
|
|
@@ -278,6 +312,8 @@ export class ServiceProvider implements ServiceResolver {
|
|
|
278
312
|
stack: ResolutionActivation[],
|
|
279
313
|
ownerLifetime?: ProviderLifetime,
|
|
280
314
|
): Promise<T> {
|
|
315
|
+
const scopeProvider = this.providerForScope(token, key, scopeState);
|
|
316
|
+
if (scopeProvider !== undefined) return scopeProvider;
|
|
281
317
|
const registration = this.registry.find(token, key);
|
|
282
318
|
if (!registration) {
|
|
283
319
|
throw new ProviderNotFoundError(token, this.describeResolutionPath(stack, token));
|
|
@@ -733,6 +769,8 @@ export class ServiceProvider implements ServiceResolver {
|
|
|
733
769
|
ownerLifetime: ProviderLifetime | undefined,
|
|
734
770
|
): T | undefined {
|
|
735
771
|
this.lifetime.assertLive(scopeState);
|
|
772
|
+
const scopeProvider = this.providerForScope(token, key, scopeState);
|
|
773
|
+
if (scopeProvider !== undefined) return scopeProvider;
|
|
736
774
|
const registration = this.registry.find(token, key);
|
|
737
775
|
if (!registration) {
|
|
738
776
|
return undefined;
|
|
@@ -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.
|
|
235
|
+
clientInfo: { name: "bazis", title: "Bazis", version: "0.106.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");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bazis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.106.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",
|