@loutrejs/loutre 0.5.0 → 0.7.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 +22 -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 +118 -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 +32 -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/instrumentation.d.ts +36 -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/types.js +1 -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/devtools/capsule.d.ts +51 -0
- package/dist/devtools/capsule.js +245 -0
- package/dist/devtools/index.d.ts +11 -0
- package/dist/devtools/index.js +6 -0
- package/dist/devtools/inspector.d.ts +57 -0
- package/dist/devtools/inspector.js +1 -0
- package/dist/devtools/module.d.ts +18 -0
- package/dist/devtools/module.js +26 -0
- package/dist/devtools/observer.d.ts +77 -0
- package/dist/devtools/observer.js +10 -0
- package/dist/devtools/protocol.d.ts +1 -0
- package/dist/devtools/protocol.js +1 -0
- package/dist/devtools/provider-instrumentation.d.ts +14 -0
- package/dist/devtools/provider-instrumentation.js +117 -0
- package/dist/devtools/runtime.d.ts +20 -0
- package/dist/devtools/runtime.js +519 -0
- package/dist/devtools/values.d.ts +35 -0
- package/dist/devtools/values.js +175 -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 +1061 -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 +411 -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 +5 -21
- package/dist/runtime/di.js +22 -289
- 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 +25 -0
- package/dist/runtime/kernel.js +447 -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 +525 -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 +533 -0
- package/dist/websocket/index.d.ts +3 -0
- package/dist/websocket/index.js +2 -0
- package/package.json +16 -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/instrumentation.js} +0 -0
package/dist/graph/compiler.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { asModuleInstance, normalizeProvider, tokenName, } from '../core/index.js';
|
|
2
|
-
import { compileApplication as compileBaseApplication, } from './graph.js';
|
|
3
|
-
export function compileApplication(input) {
|
|
4
|
-
const base = compileBaseApplication(input);
|
|
5
|
-
const modules = collectModules(input.modules);
|
|
6
|
-
const moduleIds = new Map(modules.map((module, index) => [module, `module:${index + 1}`]));
|
|
7
|
-
const implementationModules = collectImplementationModules(modules, moduleIds);
|
|
8
|
-
const implementationNames = new Map(base.graph.implementations.map((implementation) => [
|
|
9
|
-
implementation.id,
|
|
10
|
-
implementation.name,
|
|
11
|
-
]));
|
|
12
|
-
const graphModules = new Map(base.graph.modules.map((module) => [module.id, module]));
|
|
13
|
-
const executionModules = new Map();
|
|
14
|
-
for (const execution of base.graph.executions) {
|
|
15
|
-
if (execution.kind !== 'protocol')
|
|
16
|
-
continue;
|
|
17
|
-
const implementationName = implementationNames.get(execution.implementation);
|
|
18
|
-
const module = implementationName
|
|
19
|
-
? implementationModules.get(implementationName)
|
|
20
|
-
: undefined;
|
|
21
|
-
if (!module)
|
|
22
|
-
continue;
|
|
23
|
-
executionModules.set(`${execution.contract}:${execution.procedure}:${execution.protocol}`, module);
|
|
24
|
-
}
|
|
25
|
-
const providerModules = collectProviderModules(modules, moduleIds);
|
|
26
|
-
const nodes = base.graph.nodes.map((node) => {
|
|
27
|
-
const module = node.module ??
|
|
28
|
-
providerModules.get(node.label) ??
|
|
29
|
-
moduleForImplementation(node, implementationModules) ??
|
|
30
|
-
moduleForLifecycle(node) ??
|
|
31
|
-
moduleForLayer(node, executionModules);
|
|
32
|
-
if (!module)
|
|
33
|
-
return node;
|
|
34
|
-
const owner = graphModules.get(module);
|
|
35
|
-
if (!owner)
|
|
36
|
-
return node;
|
|
37
|
-
return {
|
|
38
|
-
...node,
|
|
39
|
-
module,
|
|
40
|
-
visibility: owner.exports.includes(node.label) ? 'exported' : 'private',
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
const diagnostics = [
|
|
44
|
-
...base.diagnostics,
|
|
45
|
-
...validateModuleExports(base.graph.modules),
|
|
46
|
-
...validateModuleVisibility(base.graph, nodes),
|
|
47
|
-
];
|
|
48
|
-
const graph = {
|
|
49
|
-
...base.graph,
|
|
50
|
-
nodes,
|
|
51
|
-
diagnostics,
|
|
52
|
-
};
|
|
53
|
-
return { graph, diagnostics };
|
|
54
|
-
}
|
|
55
|
-
export const buildApplicationGraph = compileApplication;
|
|
56
|
-
function collectModules(roots) {
|
|
57
|
-
const modules = [];
|
|
58
|
-
const seen = new Set();
|
|
59
|
-
const visit = (candidate) => {
|
|
60
|
-
const module = asModuleInstance(candidate);
|
|
61
|
-
if (seen.has(module))
|
|
62
|
-
return;
|
|
63
|
-
seen.add(module);
|
|
64
|
-
for (const imported of module.definition.imports ?? [])
|
|
65
|
-
visit(imported);
|
|
66
|
-
modules.push(module);
|
|
67
|
-
};
|
|
68
|
-
for (const root of roots)
|
|
69
|
-
visit(root);
|
|
70
|
-
return modules;
|
|
71
|
-
}
|
|
72
|
-
function collectProviderModules(modules, moduleIds) {
|
|
73
|
-
const result = new Map();
|
|
74
|
-
const ambiguous = new Set();
|
|
75
|
-
for (const module of modules) {
|
|
76
|
-
const moduleId = moduleIds.get(module);
|
|
77
|
-
if (!moduleId)
|
|
78
|
-
continue;
|
|
79
|
-
for (const declaration of module.definition.providers ?? []) {
|
|
80
|
-
const provider = normalizeProvider(declaration);
|
|
81
|
-
const labels = [
|
|
82
|
-
tokenName(provider.provide),
|
|
83
|
-
...(provider.kind === 'class' ? [provider.useClass.name] : []),
|
|
84
|
-
...(provider.kind === 'conditional'
|
|
85
|
-
? Reflect.ownKeys(provider.mapping).flatMap((key) => {
|
|
86
|
-
const candidate = provider.mapping[key];
|
|
87
|
-
return candidate ? [candidate.name] : [];
|
|
88
|
-
})
|
|
89
|
-
: []),
|
|
90
|
-
];
|
|
91
|
-
for (const label of labels) {
|
|
92
|
-
const current = result.get(label);
|
|
93
|
-
if (current && current !== moduleId)
|
|
94
|
-
ambiguous.add(label);
|
|
95
|
-
else
|
|
96
|
-
result.set(label, moduleId);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
for (const label of ambiguous)
|
|
101
|
-
result.delete(label);
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
function collectImplementationModules(modules, moduleIds) {
|
|
105
|
-
const result = new Map();
|
|
106
|
-
const ambiguous = new Set();
|
|
107
|
-
for (const module of modules) {
|
|
108
|
-
const moduleId = moduleIds.get(module);
|
|
109
|
-
if (!moduleId)
|
|
110
|
-
continue;
|
|
111
|
-
for (const implementation of module.definition.implementations ?? []) {
|
|
112
|
-
const current = result.get(implementation.name);
|
|
113
|
-
if (current && current !== moduleId)
|
|
114
|
-
ambiguous.add(implementation.name);
|
|
115
|
-
else
|
|
116
|
-
result.set(implementation.name, moduleId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const name of ambiguous)
|
|
120
|
-
result.delete(name);
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
function moduleForImplementation(node, modules) {
|
|
124
|
-
return node.kind === 'implementation' ? modules.get(node.label) : undefined;
|
|
125
|
-
}
|
|
126
|
-
function moduleForLifecycle(node) {
|
|
127
|
-
if (node.kind !== 'framework' || !node.id.startsWith('lifecycle:module:')) {
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
const match = /^lifecycle:(module:\d+):/.exec(node.id);
|
|
131
|
-
return match?.[1];
|
|
132
|
-
}
|
|
133
|
-
function moduleForLayer(node, executionModules) {
|
|
134
|
-
if (node.kind !== 'layer')
|
|
135
|
-
return undefined;
|
|
136
|
-
const match = /^layer:(contract:\d+)\/([^/]+)\/([^/]+)\//.exec(node.id);
|
|
137
|
-
if (!match)
|
|
138
|
-
return undefined;
|
|
139
|
-
const [, contract, procedure, protocol] = match;
|
|
140
|
-
return executionModules.get(`${contract}:${procedure}:${protocol}`);
|
|
141
|
-
}
|
|
142
|
-
function validateModuleExports(modules) {
|
|
143
|
-
const byId = new Map(modules.map((module) => [module.id, module]));
|
|
144
|
-
return modules.flatMap((module) => module.exports.flatMap((token) => declaresToken(module, token) ||
|
|
145
|
-
canResolveExport(module, token, byId, new Set())
|
|
146
|
-
? []
|
|
147
|
-
: [
|
|
148
|
-
{
|
|
149
|
-
code: 'LUTRE_MODULE_EXPORT_UNRESOLVED',
|
|
150
|
-
message: `${describeModule(module)} exports ${token}, but the token is neither declared nor re-exported from an imported Module.`,
|
|
151
|
-
path: `${module.id}.exports.${token}`,
|
|
152
|
-
},
|
|
153
|
-
]));
|
|
154
|
-
}
|
|
155
|
-
function declaresToken(module, token) {
|
|
156
|
-
return module.providers.includes(token) || module.environment.includes(token);
|
|
157
|
-
}
|
|
158
|
-
function canResolveExport(source, token, modules, visited) {
|
|
159
|
-
if (visited.has(source.id))
|
|
160
|
-
return false;
|
|
161
|
-
visited.add(source.id);
|
|
162
|
-
for (const importedId of source.imports) {
|
|
163
|
-
const imported = modules.get(importedId);
|
|
164
|
-
if (!imported || !imported.exports.includes(token))
|
|
165
|
-
continue;
|
|
166
|
-
if (declaresToken(imported, token))
|
|
167
|
-
return true;
|
|
168
|
-
if (canResolveExport(imported, token, modules, new Set(visited)))
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
function validateModuleVisibility(graph, nodes) {
|
|
174
|
-
const modules = new Map(graph.modules.map((module) => [module.id, module]));
|
|
175
|
-
const nodesById = new Map(nodes.map((node) => [node.id, node]));
|
|
176
|
-
const seen = new Set();
|
|
177
|
-
const diagnostics = [];
|
|
178
|
-
for (const edge of graph.edges) {
|
|
179
|
-
const consumer = nodesById.get(edge.from);
|
|
180
|
-
const dependency = nodesById.get(edge.to);
|
|
181
|
-
if (!consumer?.module ||
|
|
182
|
-
!dependency?.module ||
|
|
183
|
-
consumer.module === dependency.module ||
|
|
184
|
-
!modules.has(consumer.module) ||
|
|
185
|
-
!modules.has(dependency.module)) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
const key = `${consumer.id}->${dependency.id}`;
|
|
189
|
-
if (seen.has(key))
|
|
190
|
-
continue;
|
|
191
|
-
seen.add(key);
|
|
192
|
-
if (isTokenVisibleFrom(consumer.module, dependency.module, dependency.label, modules)) {
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
diagnostics.push({
|
|
196
|
-
code: 'LUTRE_MODULE_VISIBILITY',
|
|
197
|
-
message: `${consumer.label} in ${describeModuleId(consumer.module, modules)} depends on private ${dependency.label} from ${describeModuleId(dependency.module, modules)}. Export the dependency and import its Module explicitly.`,
|
|
198
|
-
path: consumer.id,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return diagnostics;
|
|
202
|
-
}
|
|
203
|
-
function isTokenVisibleFrom(sourceId, targetId, token, modules, visited = new Set()) {
|
|
204
|
-
if (visited.has(sourceId))
|
|
205
|
-
return false;
|
|
206
|
-
visited.add(sourceId);
|
|
207
|
-
const source = modules.get(sourceId);
|
|
208
|
-
if (!source)
|
|
209
|
-
return false;
|
|
210
|
-
for (const importedId of source.imports) {
|
|
211
|
-
const imported = modules.get(importedId);
|
|
212
|
-
if (!imported || !imported.exports.includes(token))
|
|
213
|
-
continue;
|
|
214
|
-
if (importedId === targetId)
|
|
215
|
-
return true;
|
|
216
|
-
if (isTokenVisibleFrom(importedId, targetId, token, modules, new Set(visited))) {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
function describeModule(module) {
|
|
223
|
-
return module.name ?? module.description ?? module.id;
|
|
224
|
-
}
|
|
225
|
-
function describeModuleId(id, modules) {
|
|
226
|
-
const module = modules.get(id);
|
|
227
|
-
return module ? describeModule(module) : id;
|
|
228
|
-
}
|
package/dist/graph/graph.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type ArgsClass, type ContractBinding, type ModuleInstance, type ModuleTemplate, type TaskDescriptor, type TriggerDescriptor } from '../core/index.js';
|
|
2
|
-
import type { ApplicationGraphIR, CompilationResult, Diagnostic } from './ir.js';
|
|
3
|
-
export declare class StaticValidationError extends Error {
|
|
4
|
-
readonly diagnostics: readonly Diagnostic[];
|
|
5
|
-
readonly graph?: ApplicationGraphIR | undefined;
|
|
6
|
-
constructor(diagnostics: readonly Diagnostic[], graph?: ApplicationGraphIR | undefined);
|
|
7
|
-
}
|
|
8
|
-
export interface ApplicationCompilationInput {
|
|
9
|
-
readonly contract?: ContractBinding;
|
|
10
|
-
readonly modules: readonly (ModuleInstance | ModuleTemplate<void>)[];
|
|
11
|
-
readonly arguments?: ArgsClass | undefined;
|
|
12
|
-
readonly tasks?: readonly TaskDescriptor<any, any>[];
|
|
13
|
-
readonly triggers?: readonly TriggerDescriptor[];
|
|
14
|
-
}
|
|
15
|
-
export declare function compileApplication(input: ApplicationCompilationInput): CompilationResult;
|
|
16
|
-
export declare const buildApplicationGraph: typeof compileApplication;
|
|
17
|
-
export declare function validateGraph(graph: ApplicationGraphIR): readonly Diagnostic[];
|
|
18
|
-
export declare function assertValidCompilation(result: CompilationResult): ApplicationGraphIR;
|