@loutrejs/loutre 0.5.0 → 0.6.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.
- package/README.md +63 -32
- package/dist/adapters/aws-lambda.d.ts +5 -3
- package/dist/adapters/aws-lambda.js +53 -23
- package/dist/adapters/bun.d.ts +7 -4
- package/dist/adapters/bun.js +52 -42
- package/dist/adapters/cloudflare-workers.d.ts +5 -3
- package/dist/adapters/cloudflare-workers.js +23 -28
- package/dist/adapters/deno.d.ts +7 -4
- package/dist/adapters/deno.js +94 -57
- package/dist/adapters/electron.d.ts +13 -5
- package/dist/adapters/electron.js +76 -28
- package/dist/application/definition.d.ts +31 -0
- package/dist/application/definition.js +16 -0
- package/dist/application/index.d.ts +4 -63
- package/dist/application/index.js +2 -11
- package/dist/application/kernel-internal.d.ts +2 -0
- package/dist/application/kernel-internal.js +10 -0
- package/dist/application/kernel.d.ts +21 -0
- package/dist/application/kernel.js +65 -0
- package/dist/core/diagnostic.d.ts +9 -0
- package/dist/core/diagnostic.js +9 -0
- package/dist/core/extension.d.ts +107 -0
- package/dist/core/extension.js +73 -0
- package/dist/core/generic-layer.d.ts +26 -0
- package/dist/core/generic-layer.js +116 -0
- package/dist/core/index.d.ts +31 -15
- package/dist/core/index.js +15 -15
- package/dist/core/injection.d.ts +4 -13
- package/dist/core/injection.js +63 -0
- package/dist/core/model/context.d.ts +18 -0
- package/dist/core/model/context.js +34 -0
- package/dist/core/model/lifecycle.d.ts +5 -0
- package/dist/core/model/lifecycle.js +44 -0
- package/dist/core/model/modules.d.ts +2 -0
- package/dist/core/model/modules.js +101 -0
- package/dist/core/model/providers.d.ts +4 -0
- package/dist/core/model/providers.js +74 -0
- package/dist/core/model/snapshot.d.ts +6 -0
- package/dist/core/model/snapshot.js +31 -0
- package/dist/core/model/types.d.ts +78 -0
- package/dist/core/model/validation.d.ts +4 -0
- package/dist/core/model/validation.js +40 -0
- package/dist/core/model/visibility.d.ts +4 -0
- package/dist/core/model/visibility.js +20 -0
- package/dist/core/model.d.ts +10 -0
- package/dist/core/model.js +346 -0
- package/dist/core/module.d.ts +8 -13
- package/dist/core/source-location.d.ts +8 -0
- package/dist/core/source-location.js +31 -0
- package/dist/core/token-internal.d.ts +3 -0
- package/dist/core/token-internal.js +4 -0
- package/dist/core/type.d.ts +7 -0
- package/dist/core/type.js +4 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/graph/index.d.ts +2 -3
- package/dist/graph/index.js +1 -3
- package/dist/graph/model.d.ts +34 -0
- package/dist/graph/model.js +127 -0
- package/dist/http/auth.d.ts +46 -0
- package/dist/http/auth.js +96 -0
- package/dist/http/client.d.ts +28 -31
- package/dist/http/client.js +58 -44
- package/dist/http/cors-internal.d.ts +29 -0
- package/dist/http/cors-internal.js +160 -0
- package/dist/http/cors.d.ts +5 -8
- package/dist/http/cors.js +7 -165
- package/dist/http/extension.d.ts +348 -0
- package/dist/http/extension.js +947 -0
- package/dist/http/index.d.ts +9 -7
- package/dist/http/index.js +5 -7
- package/dist/{application → http}/openapi.d.ts +12 -3
- package/dist/{application → http}/openapi.js +164 -102
- package/dist/http/path.d.ts +1 -42
- package/dist/http/path.js +1 -2
- package/dist/http/runtime/request.d.ts +17 -0
- package/dist/http/runtime/request.js +109 -0
- package/dist/http/runtime/response.d.ts +18 -0
- package/dist/http/runtime/response.js +108 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/message-port/extension.d.ts +66 -0
- package/dist/message-port/extension.js +395 -0
- package/dist/message-port/index.d.ts +4 -73
- package/dist/message-port/index.js +2 -189
- package/dist/message-port/transport.d.ts +11 -0
- package/dist/message-port/transport.js +45 -0
- package/dist/runtime/async-iterator-lifecycle.d.ts +12 -0
- package/dist/runtime/async-iterator-lifecycle.js +95 -0
- package/dist/runtime/capability.d.ts +11 -11
- package/dist/runtime/capability.js +3 -3
- package/dist/runtime/di.d.ts +2 -22
- package/dist/runtime/di.js +8 -285
- package/dist/runtime/execution-tracker.d.ts +8 -0
- package/dist/runtime/execution-tracker.js +54 -0
- package/dist/runtime/index.d.ts +15 -9
- package/dist/runtime/index.js +9 -9
- package/dist/runtime/ingress-gate.d.ts +7 -0
- package/dist/runtime/ingress-gate.js +33 -0
- package/dist/runtime/kernel.d.ts +23 -0
- package/dist/runtime/kernel.js +354 -0
- package/dist/runtime/logger.d.ts +2 -0
- package/dist/runtime/logger.js +2 -0
- package/dist/runtime/node-capabilities.d.ts +1 -1
- package/dist/runtime/node-capabilities.js +1 -1
- package/dist/runtime/server-port.d.ts +2 -0
- package/dist/runtime/server-port.js +11 -0
- package/dist/tasks/extension.d.ts +144 -0
- package/dist/tasks/extension.js +499 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.js +1 -0
- package/dist/tasks/runtime/cron.d.ts +6 -0
- package/dist/tasks/runtime/cron.js +89 -0
- package/dist/websocket/errors.d.ts +9 -0
- package/dist/websocket/errors.js +18 -0
- package/dist/websocket/extension.d.ts +154 -0
- package/dist/websocket/extension.js +524 -0
- package/dist/websocket/index.d.ts +3 -0
- package/dist/websocket/index.js +2 -0
- package/package.json +12 -16
- package/dist/application/binding.d.ts +0 -33
- package/dist/application/binding.js +0 -295
- package/dist/application/host.d.ts +0 -8
- package/dist/application/host.js +0 -14
- package/dist/application/queue.d.ts +0 -3
- package/dist/application/queue.js +0 -4
- package/dist/application/scheduler.d.ts +0 -2
- package/dist/application/scheduler.js +0 -45
- package/dist/core/context-key.d.ts +0 -16
- package/dist/core/context-key.js +0 -17
- package/dist/core/contract-internal.d.ts +0 -22
- package/dist/core/contract-internal.js +0 -61
- package/dist/core/contract.d.ts +0 -96
- package/dist/core/contract.js +0 -88
- package/dist/core/execution.d.ts +0 -78
- package/dist/core/execution.js +0 -61
- package/dist/core/implementation.d.ts +0 -44
- package/dist/core/implementation.js +0 -35
- package/dist/core/layer.d.ts +0 -137
- package/dist/core/layer.js +0 -81
- package/dist/graph/compiler.d.ts +0 -4
- package/dist/graph/compiler.js +0 -228
- package/dist/graph/graph.d.ts +0 -18
- package/dist/graph/graph.js +0 -1118
- package/dist/graph/ir.d.ts +0 -175
- package/dist/http/application.d.ts +0 -18
- package/dist/http/application.js +0 -515
- package/dist/http/basic-auth.d.ts +0 -37
- package/dist/http/basic-auth.js +0 -67
- package/dist/http/definitions.d.ts +0 -363
- package/dist/http/definitions.js +0 -310
- package/dist/http/hosted-protocol.d.ts +0 -4
- package/dist/http/hosted-protocol.js +0 -4
- package/dist/http/internal.d.ts +0 -8
- package/dist/http/internal.js +0 -1
- package/dist/http/params.d.ts +0 -2
- package/dist/http/params.js +0 -19
- package/dist/http/request-body.d.ts +0 -4
- package/dist/http/request-body.js +0 -6
- package/dist/http/validate.d.ts +0 -20
- package/dist/http/validate.js +0 -6
- package/dist/message-port/environment.d.ts +0 -2
- package/dist/message-port/environment.js +0 -4
- package/dist/runtime/application.d.ts +0 -38
- package/dist/runtime/application.js +0 -339
- package/dist/runtime/pipeline.d.ts +0 -11
- package/dist/runtime/pipeline.js +0 -161
- /package/dist/{graph/ir.js → core/model/types.js} +0 -0
|
@@ -1,189 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const handler = Object.freeze({
|
|
4
|
-
kind: 'terminal',
|
|
5
|
-
name: 'messagePort.handler',
|
|
6
|
-
role: 'terminal',
|
|
7
|
-
protocol: 'messagePort',
|
|
8
|
-
});
|
|
9
|
-
function defineMessagePort(definition) {
|
|
10
|
-
return {
|
|
11
|
-
kind: 'protocol',
|
|
12
|
-
protocol: 'messagePort',
|
|
13
|
-
interaction: definition.interaction ?? 'unary',
|
|
14
|
-
dispatchKey: null,
|
|
15
|
-
definition,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function defineMessagePortGroup(definitions) {
|
|
19
|
-
return protocolGroup('messagePort', Object.fromEntries(Object.entries(definitions).map(([name, definition]) => [
|
|
20
|
-
name,
|
|
21
|
-
defineMessagePort(definition),
|
|
22
|
-
])));
|
|
23
|
-
}
|
|
24
|
-
export const messagePort = Object.assign(defineMessagePortGroup, {
|
|
25
|
-
protocol: 'messagePort',
|
|
26
|
-
route: defineMessagePort,
|
|
27
|
-
handler,
|
|
28
|
-
});
|
|
29
|
-
export function createMessagePortExecution(options) {
|
|
30
|
-
const graph = options.graph;
|
|
31
|
-
const applicationLogger = options.logger ?? new Logger();
|
|
32
|
-
const runtime = options.runtime;
|
|
33
|
-
const logger = applicationLogger.child({ protocol: 'messagePort' });
|
|
34
|
-
const routes = collectRoutes(runtime.graph.modules);
|
|
35
|
-
let initialization;
|
|
36
|
-
const initialize = () => (initialization ??= runtime.initialize());
|
|
37
|
-
return {
|
|
38
|
-
graph,
|
|
39
|
-
initialize,
|
|
40
|
-
shutdown: (signal) => runtime.shutdown(signal),
|
|
41
|
-
async invoke(procedure, input) {
|
|
42
|
-
const startedAt = Date.now();
|
|
43
|
-
let invocationLogger = logger.child({
|
|
44
|
-
procedure,
|
|
45
|
-
executionId: crypto.randomUUID(),
|
|
46
|
-
});
|
|
47
|
-
try {
|
|
48
|
-
return await runtime.execute(async () => {
|
|
49
|
-
const route = routes.find((candidate) => candidate.procedure === procedure);
|
|
50
|
-
if (!route)
|
|
51
|
-
throw new Error(`MessagePort procedure not found: ${procedure}`);
|
|
52
|
-
invocationLogger = invocationLogger.child({
|
|
53
|
-
source: `${route.implementation.name}.${route.procedure}`,
|
|
54
|
-
});
|
|
55
|
-
const message = Object.fromEntries(Object.keys(route.protocol.definition.responses).map((variant) => [
|
|
56
|
-
variant,
|
|
57
|
-
(value) => ({
|
|
58
|
-
kind: 'message-port-result',
|
|
59
|
-
variant,
|
|
60
|
-
value,
|
|
61
|
-
}),
|
|
62
|
-
]));
|
|
63
|
-
const context = {
|
|
64
|
-
input,
|
|
65
|
-
message,
|
|
66
|
-
logger: invocationLogger,
|
|
67
|
-
};
|
|
68
|
-
const result = await executePipeline(route.protocol.definition.pipeline, {
|
|
69
|
-
context,
|
|
70
|
-
layer: (descriptor) => runtime.container.layerRuntime(descriptor),
|
|
71
|
-
validate: () => undefined,
|
|
72
|
-
terminal: async (_layer, terminalContext) => {
|
|
73
|
-
const target = runtime.container.implementationRuntime(route.implementation);
|
|
74
|
-
const method = target[route.procedure];
|
|
75
|
-
if (typeof method !== 'function')
|
|
76
|
-
throw new Error('Handler method is missing');
|
|
77
|
-
return Reflect.apply(method, target, [
|
|
78
|
-
terminalContext,
|
|
79
|
-
]);
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
const finalized = await finalize(route.protocol.definition, result);
|
|
83
|
-
invocationLogger.info('MessagePort invocation completed', {
|
|
84
|
-
event: 'message_port.invocation.completed',
|
|
85
|
-
durationMs: Math.max(0, Date.now() - startedAt),
|
|
86
|
-
});
|
|
87
|
-
return finalized;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
const normalized = normalizeUnknownError(error, invocationLogger.context);
|
|
92
|
-
invocationLogger.error('Unhandled application error', {
|
|
93
|
-
event: 'application.error',
|
|
94
|
-
durationMs: Math.max(0, Date.now() - startedAt),
|
|
95
|
-
error: {
|
|
96
|
-
code: normalized.code,
|
|
97
|
-
id: normalized.errorId,
|
|
98
|
-
name: error instanceof Error ? error.name : typeof error,
|
|
99
|
-
message: normalized.message,
|
|
100
|
-
...(normalized.stack === undefined
|
|
101
|
-
? {}
|
|
102
|
-
: { stack: normalized.stack }),
|
|
103
|
-
...(normalized.cause === undefined
|
|
104
|
-
? {}
|
|
105
|
-
: { cause: normalized.cause }),
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
async function finalize(definition, result) {
|
|
114
|
-
const response = definition.responses[result.variant];
|
|
115
|
-
if (!response)
|
|
116
|
-
throw new Error(`Undeclared variant: ${result.variant}`);
|
|
117
|
-
if (response.stream === 'server') {
|
|
118
|
-
if (!isAsyncIterable(result.value)) {
|
|
119
|
-
throw new Error('Server-stream result requires an AsyncIterable');
|
|
120
|
-
}
|
|
121
|
-
const source = result.value;
|
|
122
|
-
return {
|
|
123
|
-
...result,
|
|
124
|
-
value: (async function* () {
|
|
125
|
-
for await (const value of source) {
|
|
126
|
-
yield await validateSchema(response.body, value);
|
|
127
|
-
}
|
|
128
|
-
})(),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return { ...result, value: await validateSchema(response.body, result.value) };
|
|
132
|
-
}
|
|
133
|
-
function collectRoutes(modules) {
|
|
134
|
-
return modules.flatMap((module) => (module.definition.implementations ?? []).flatMap((implementation) => {
|
|
135
|
-
if (implementation.protocol !== 'messagePort')
|
|
136
|
-
return [];
|
|
137
|
-
return implementation.procedures.map((procedure) => ({
|
|
138
|
-
procedure,
|
|
139
|
-
protocol: implementation.contract.procedures[procedure].protocols
|
|
140
|
-
.messagePort,
|
|
141
|
-
implementation,
|
|
142
|
-
}));
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
export function attachMessagePort(application, port) {
|
|
146
|
-
port.addEventListener('message', async (event) => {
|
|
147
|
-
const request = event.data;
|
|
148
|
-
try {
|
|
149
|
-
const result = await application.invoke(request.procedure, request.input);
|
|
150
|
-
if (isAsyncIterable(result.value)) {
|
|
151
|
-
for await (const value of result.value) {
|
|
152
|
-
port.postMessage({
|
|
153
|
-
id: request.id,
|
|
154
|
-
variant: result.variant,
|
|
155
|
-
value,
|
|
156
|
-
done: false,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
port.postMessage({
|
|
160
|
-
id: request.id,
|
|
161
|
-
variant: result.variant,
|
|
162
|
-
done: true,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
port.postMessage({
|
|
167
|
-
id: request.id,
|
|
168
|
-
variant: result.variant,
|
|
169
|
-
value: result.value,
|
|
170
|
-
done: true,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
port.postMessage({
|
|
176
|
-
id: request.id,
|
|
177
|
-
error: error instanceof Error ? error.message : String(error),
|
|
178
|
-
done: true,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
port.start?.();
|
|
183
|
-
}
|
|
184
|
-
function isAsyncIterable(value) {
|
|
185
|
-
return (typeof value === 'object' &&
|
|
186
|
-
value !== null &&
|
|
187
|
-
Symbol.asyncIterator in value &&
|
|
188
|
-
typeof value[Symbol.asyncIterator] === 'function');
|
|
189
|
-
}
|
|
1
|
+
export { defineMessagePortContract, defineMessagePortImplementation, messagePort, messagePortExtension, } from './extension.js';
|
|
2
|
+
export { attachMessagePort } from './transport.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface MessagePortHost {
|
|
2
|
+
invoke(method: string, input?: unknown): Promise<{
|
|
3
|
+
readonly response: string;
|
|
4
|
+
readonly value: unknown;
|
|
5
|
+
}>;
|
|
6
|
+
}
|
|
7
|
+
export type MessagePortLike = {
|
|
8
|
+
postMessage(value: unknown): void;
|
|
9
|
+
start?(): void;
|
|
10
|
+
} & Pick<EventTarget, 'addEventListener'>;
|
|
11
|
+
export declare function attachMessagePort(host: MessagePortHost, port: MessagePortLike): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function attachMessagePort(host, port) {
|
|
2
|
+
port.addEventListener('message', async (event) => {
|
|
3
|
+
const request = event.data;
|
|
4
|
+
try {
|
|
5
|
+
const result = await host.invoke(request.procedure, request.input);
|
|
6
|
+
if (isAsyncIterable(result.value)) {
|
|
7
|
+
for await (const value of result.value) {
|
|
8
|
+
port.postMessage({
|
|
9
|
+
id: request.id,
|
|
10
|
+
response: result.response,
|
|
11
|
+
value,
|
|
12
|
+
done: false,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
port.postMessage({
|
|
16
|
+
id: request.id,
|
|
17
|
+
response: result.response,
|
|
18
|
+
done: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
port.postMessage({
|
|
23
|
+
id: request.id,
|
|
24
|
+
response: result.response,
|
|
25
|
+
value: result.value,
|
|
26
|
+
done: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
port.postMessage({
|
|
32
|
+
id: request.id,
|
|
33
|
+
error: error instanceof Error ? error.message : String(error),
|
|
34
|
+
done: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
port.start?.();
|
|
39
|
+
}
|
|
40
|
+
function isAsyncIterable(value) {
|
|
41
|
+
return (typeof value === 'object' &&
|
|
42
|
+
value !== null &&
|
|
43
|
+
Symbol.asyncIterator in value &&
|
|
44
|
+
typeof value[Symbol.asyncIterator] === 'function');
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class AsyncIteratorCleanupDeadlineError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class AsyncIteratorLifecycle<T> {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(iterator: AsyncIterator<T>);
|
|
7
|
+
get done(): boolean;
|
|
8
|
+
next(): Promise<IteratorResult<T>>;
|
|
9
|
+
return(reason?: unknown): Promise<IteratorResult<T>>;
|
|
10
|
+
throw(error?: unknown): Promise<IteratorResult<T>>;
|
|
11
|
+
drain(reason: unknown, deadline: () => number | undefined, timeoutMessage: string): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const cleanupYieldInterval = 32;
|
|
2
|
+
export class AsyncIteratorCleanupDeadlineError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'AsyncIteratorCleanupDeadlineError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class AsyncIteratorLifecycle {
|
|
9
|
+
#iterator;
|
|
10
|
+
#idleWaiters = new Set();
|
|
11
|
+
#inFlight = 0;
|
|
12
|
+
#returnPending = false;
|
|
13
|
+
#returnContinuationPending = false;
|
|
14
|
+
#done = false;
|
|
15
|
+
constructor(iterator) {
|
|
16
|
+
this.#iterator = iterator;
|
|
17
|
+
}
|
|
18
|
+
get done() {
|
|
19
|
+
return this.#done;
|
|
20
|
+
}
|
|
21
|
+
async next() {
|
|
22
|
+
return this.#run(() => this.#iterator.next());
|
|
23
|
+
}
|
|
24
|
+
async return(reason) {
|
|
25
|
+
if (!this.#iterator.return) {
|
|
26
|
+
const result = { done: true, value: reason };
|
|
27
|
+
this.#record(result);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
this.#returnPending = true;
|
|
31
|
+
try {
|
|
32
|
+
const result = await this.#run(() => this.#iterator.return(reason));
|
|
33
|
+
this.#returnContinuationPending = !result.done;
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
this.#returnPending = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async throw(error) {
|
|
41
|
+
if (!this.#iterator.throw)
|
|
42
|
+
throw error;
|
|
43
|
+
return this.#run(() => this.#iterator.throw(error));
|
|
44
|
+
}
|
|
45
|
+
async drain(reason, deadline, timeoutMessage) {
|
|
46
|
+
if (this.#returnPending)
|
|
47
|
+
await this.#waitForIdle();
|
|
48
|
+
if (this.#done)
|
|
49
|
+
return;
|
|
50
|
+
if (!this.#returnContinuationPending) {
|
|
51
|
+
const result = await this.return(reason);
|
|
52
|
+
if (result.done)
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await this.#waitForIdle();
|
|
56
|
+
let continuationSteps = 0;
|
|
57
|
+
while (!this.#done) {
|
|
58
|
+
const currentDeadline = deadline();
|
|
59
|
+
if (currentDeadline !== undefined && Date.now() >= currentDeadline) {
|
|
60
|
+
throw new AsyncIteratorCleanupDeadlineError(timeoutMessage);
|
|
61
|
+
}
|
|
62
|
+
await this.next();
|
|
63
|
+
continuationSteps += 1;
|
|
64
|
+
if (continuationSteps % cleanupYieldInterval === 0) {
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async #run(operation) {
|
|
70
|
+
this.#inFlight += 1;
|
|
71
|
+
try {
|
|
72
|
+
return this.#record(await operation());
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
this.#inFlight -= 1;
|
|
76
|
+
if (this.#inFlight === 0) {
|
|
77
|
+
for (const resolve of this.#idleWaiters)
|
|
78
|
+
resolve();
|
|
79
|
+
this.#idleWaiters.clear();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
#record(result) {
|
|
84
|
+
if (result.done) {
|
|
85
|
+
this.#done = true;
|
|
86
|
+
this.#returnContinuationPending = false;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
#waitForIdle() {
|
|
91
|
+
return this.#inFlight === 0
|
|
92
|
+
? Promise.resolve()
|
|
93
|
+
: new Promise((resolve) => this.#idleWaiters.add(resolve));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export interface
|
|
1
|
+
export type RuntimeCapabilityId = string;
|
|
2
|
+
export interface RuntimeSupportProfile {
|
|
3
3
|
readonly runtime: string;
|
|
4
|
-
readonly capabilities: ReadonlySet<
|
|
4
|
+
readonly capabilities: ReadonlySet<RuntimeCapabilityId>;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface RuntimeSupportCheck {
|
|
7
7
|
readonly ok: boolean;
|
|
8
|
-
readonly required: readonly
|
|
9
|
-
readonly supported: readonly
|
|
10
|
-
readonly missing: readonly
|
|
8
|
+
readonly required: readonly RuntimeCapabilityId[];
|
|
9
|
+
readonly supported: readonly RuntimeCapabilityId[];
|
|
10
|
+
readonly missing: readonly RuntimeCapabilityId[];
|
|
11
11
|
}
|
|
12
|
-
export declare function
|
|
13
|
-
export declare class
|
|
14
|
-
readonly check:
|
|
15
|
-
constructor(check:
|
|
12
|
+
export declare function checkRuntimeSupport(required: Iterable<RuntimeCapabilityId>, runtime: RuntimeSupportProfile): RuntimeSupportCheck;
|
|
13
|
+
export declare class MissingRuntimeSupportError extends Error {
|
|
14
|
+
readonly check: RuntimeSupportCheck;
|
|
15
|
+
constructor(check: RuntimeSupportCheck);
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function checkRuntimeSupport(required, runtime) {
|
|
2
2
|
const requirements = [...new Set(required)];
|
|
3
3
|
const missing = requirements.filter((capability) => !runtime.capabilities.has(capability));
|
|
4
4
|
return {
|
|
@@ -8,11 +8,11 @@ export function checkCapabilities(required, runtime) {
|
|
|
8
8
|
missing,
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export class
|
|
11
|
+
export class MissingRuntimeSupportError extends Error {
|
|
12
12
|
check;
|
|
13
13
|
constructor(check) {
|
|
14
14
|
super(`Runtime is missing required capabilities: ${check.missing.join(', ')}`);
|
|
15
15
|
this.check = check;
|
|
16
|
-
this.name = '
|
|
16
|
+
this.name = 'MissingRuntimeSupportError';
|
|
17
17
|
}
|
|
18
18
|
}
|
package/dist/runtime/di.d.ts
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
import { type ArgsClass, type
|
|
1
|
+
import { type ArgsClass, type EnvClass, type ProviderDescriptor, type TokenLike } from '../core/index.js';
|
|
2
2
|
import { Logger } from './logger.js';
|
|
3
3
|
export declare class DependencyResolutionError extends Error {
|
|
4
4
|
constructor(message: string);
|
|
5
5
|
}
|
|
6
|
-
export interface RuntimeModuleGraph {
|
|
7
|
-
readonly modules: readonly ModuleInstance[];
|
|
8
|
-
readonly providers: readonly ProviderDescriptor[];
|
|
9
|
-
}
|
|
10
|
-
export interface DependencyRecorder {
|
|
11
|
-
record(consumer: DependencyConsumer, dependency: TokenLike): void;
|
|
12
|
-
}
|
|
13
6
|
export interface ContainerOptions {
|
|
14
7
|
readonly logger?: Logger;
|
|
15
|
-
readonly recorder?: DependencyRecorder;
|
|
16
8
|
readonly environment?: ReadonlyMap<EnvClass, object>;
|
|
17
9
|
readonly arguments?: ReadonlyMap<ArgsClass, object>;
|
|
18
|
-
readonly probe?: boolean;
|
|
19
10
|
}
|
|
20
|
-
export declare function collectRuntimeModuleGraph(roots: readonly (ModuleInstance | ModuleTemplate<void>)[]): RuntimeModuleGraph;
|
|
21
11
|
export declare class Container {
|
|
22
12
|
#private;
|
|
23
13
|
constructor(providers: readonly ProviderDescriptor[], options?: Logger | ContainerOptions);
|
|
24
14
|
bindEnvironment(environment: EnvClass, value: object): void;
|
|
25
15
|
bindArguments(argumentsContract: ArgsClass, value: object): void;
|
|
26
|
-
resolve<T>(token: TokenLike<T
|
|
16
|
+
resolve<T>(token: TokenLike<T>, source?: string): T;
|
|
27
17
|
get<T>(token: TokenLike<T>): T;
|
|
28
|
-
probeClass<T>(target: Class<T>): T;
|
|
29
|
-
prepareImplementation(implementation: ImplementationDescriptor): void;
|
|
30
|
-
implementationRuntime(implementation: ImplementationDescriptor): object;
|
|
31
|
-
prepareTask(task: TaskDescriptor): void;
|
|
32
|
-
taskRuntime<TInput, TOutput>(task: TaskDescriptor<TInput, TOutput>): TaskRuntime<TInput, TOutput>;
|
|
33
|
-
probeTask(task: TaskDescriptor, consumer: TaskConsumer): void;
|
|
34
|
-
probeImplementation(implementation: ImplementationDescriptor, consumer: ImplementationConsumer): object;
|
|
35
|
-
preparePipeline(pipeline: readonly PipelineItem[]): void;
|
|
36
|
-
layerRuntime(layer: LayerDescriptor): LayerRuntime<object, readonly [], unknown>;
|
|
37
|
-
probeLayer(layer: LayerDescriptor, consumer: LayerConsumer): void;
|
|
38
18
|
}
|