@overkill-dev/resources 0.0.3 → 0.0.5
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/package.json +4 -3
- package/packages/resources/resources.entry-point.d.ts +6 -2
- package/packages/resources/resources.entry-point.d.ts.map +1 -1
- package/packages/resources/resources.entry-point.js +2 -0
- package/packages/resources/resources.entry-point.js.map +1 -1
- package/readme.md +45 -13
- package/resources/local-http-service-resource.d.ts +49 -0
- package/resources/local-http-service-resource.d.ts.map +1 -0
- package/resources/local-http-service-resource.js +92 -0
- package/resources/local-http-service-resource.js.map +1 -0
- package/resources/local-process-service-resource.d.ts +60 -0
- package/resources/local-process-service-resource.d.ts.map +1 -0
- package/resources/local-process-service-resource.js +146 -0
- package/resources/local-process-service-resource.js.map +1 -0
- package/resources/local-service-resource.d.ts +44 -33
- package/resources/local-service-resource.d.ts.map +1 -1
- package/resources/local-service-resource.js +92 -36
- package/resources/local-service-resource.js.map +1 -1
- package/resources/resource-definition-shape.d.ts +5 -1
- package/resources/resource-definition-shape.d.ts.map +1 -1
- package/resources/simulated-http-server-resource.d.ts +11 -4
- package/resources/simulated-http-server-resource.d.ts.map +1 -1
- package/resources/simulated-http-server-resource.js +28 -16
- package/resources/simulated-http-server-resource.js.map +1 -1
- package/sbom.cdx.json +9 -9
package/package.json
CHANGED
|
@@ -22,15 +22,16 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"name": "@overkill-dev/resources",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@overkill-dev/simulation": "0.0.
|
|
25
|
+
"@overkill-dev/simulation": "0.0.3"
|
|
26
26
|
},
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
29
|
"url": "git+https://github.com/enormora/overkill.git"
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": [
|
|
32
|
-
"./packages/resources/resources.entry-point.js"
|
|
32
|
+
"./packages/resources/resources.entry-point.js",
|
|
33
|
+
"./resources/local-service-resource.js"
|
|
33
34
|
],
|
|
34
35
|
"type": "module",
|
|
35
|
-
"version": "0.0.
|
|
36
|
+
"version": "0.0.5"
|
|
36
37
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ResourcesModule } from '../../resources/resources.ts';
|
|
2
2
|
export { defineLocalServiceResource } from '../../resources/local-service-resource.ts';
|
|
3
|
+
export { createLocalHttpServiceResource } from '../../resources/local-http-service-resource.ts';
|
|
4
|
+
export { createLocalProcessServiceResource } from '../../resources/local-process-service-resource.ts';
|
|
3
5
|
export declare const composeRuntimeContext: ResourcesModule['composeRuntimeContext'];
|
|
4
6
|
export declare const composeRuntimes: ResourcesModule['composeRuntimes'];
|
|
5
7
|
export declare const createTemporaryDirectoryResource: ResourcesModule['createTemporaryDirectoryResource'];
|
|
@@ -13,8 +15,10 @@ export { startResources } from '../../resources/resource-session.ts';
|
|
|
13
15
|
export { ResourceLifecycleError } from '../../resources/resource-lifecycle-error.ts';
|
|
14
16
|
export { startRuntime } from '../../resources/runtime-lifecycle.ts';
|
|
15
17
|
export type { AnyResourceDefinition, ComposedRuntimeGraph, ExecutionRequirement, ResourceContext, ResourceCreationContext, ResourceDependencies, ResourceDefinition, ResourceDefinitionInput, ResourceDisposalContext, ResourceHandle, ResourceProjectionContext, ResourceProjectionPayload, ResourceScope, RuntimeContext, RuntimeContextComposition, RuntimeDefinition, RuntimeDefinitionInput, RuntimeDimensions, RuntimeGraph, RuntimeGraphLeaf, RuntimeGraphContext, RuntimeId, RuntimeMatrixDefinition, RuntimeMatrixDefinitionInput, RuntimeMatrixVariant, RuntimeMatrixVariantMap, RuntimeResourceMap, RuntimeScopeContext, SharedRuntimeMatrixDefinitionInput, TemporaryDirectoryHandle } from '../../resources/resources.ts';
|
|
16
|
-
export type { LocalServiceAddress, LocalServiceCreationContext, LocalServiceResourceDefinitionInput } from '../../resources/local-service-resource.ts';
|
|
17
|
-
export type {
|
|
18
|
+
export type { LocalServiceAddress, LocalServiceAddressRequest, LocalServiceCreationContext, LocalServiceDisposalContext, LocalServiceHostAddressRequest, LocalServiceLoopbackAddressRequest, LocalServiceResourceDefinitionInput, LocalOnlyLocalServiceResourceDefinitionInput, ProjectedLocalServiceResourceDefinitionInput } from '../../resources/local-service-resource.ts';
|
|
19
|
+
export type { LocalHttpServiceHandle, LocalHttpServiceResourceInput } from '../../resources/local-http-service-resource.ts';
|
|
20
|
+
export type { LocalProcessCommand, LocalProcessOutput, LocalProcessOutputBuffer, LocalProcessOwner, LocalProcessServiceResourceInput, LocalProcessShutdown, LocalProcessSignal } from '../../resources/local-process-service-resource.ts';
|
|
21
|
+
export type { SimulatedHttpServerResource, SimulatedHttpServerResourceHandle, SimulatedHttpServerResourceOptions } from '../../resources/simulated-http-server-resource.ts';
|
|
18
22
|
export type { RuntimeDefinition as Runtime, RuntimeResourceMap as ResourceMap } from '../../resources/resources.ts';
|
|
19
23
|
export type { ResourceLifecycleFailure, ResourceLifecyclePhase } from '../../resources/resource-lifecycle-error.ts';
|
|
20
24
|
export type { ResourceSession, ResourceSessionDisposalContext, StartResourcesRequest } from '../../resources/resource-session.ts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.entry-point.d.ts","sourceRoot":"","sources":["../../../../../source/packages/resources/resources.entry-point.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE3F,OAAO,
|
|
1
|
+
{"version":3,"file":"resources.entry-point.d.ts","sourceRoot":"","sources":["../../../../../source/packages/resources/resources.entry-point.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE3F,OAAO,EACH,0BAA0B,EAC7B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACH,8BAA8B,EACjC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACH,iCAAiC,EACpC,MAAM,mDAAmD,CAAC;AAY3D,eAAO,MAAM,qBAAqB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BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,8BAA8B,EAC9B,kCAAkC,EAClC,mCAAmC,EACnC,4CAA4C,EAC5C,4CAA4C,EAC/C,MAAM,2CAA2C,CAAC;AACnD,YAAY,EACR,sBAAsB,EACtB,6BAA6B,EAChC,MAAM,gDAAgD,CAAC;AACxD,YAAY,EACR,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,gCAAgC,EAChC,oBAAoB,EACpB,kBAAkB,EACrB,MAAM,mDAAmD,CAAC;AAC3D,YAAY,EACR,2BAA2B,EAC3B,iCAAiC,EACjC,kCAAkC,EACrC,MAAM,mDAAmD,CAAC;AAC3D,YAAY,EACR,iBAAiB,IAAI,OAAO,EAC5B,kBAAkB,IAAI,WAAW,EACpC,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACR,wBAAwB,EACxB,sBAAsB,EACzB,MAAM,6CAA6C,CAAC;AACrD,YAAY,EACR,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACxB,MAAM,qCAAqC,CAAC;AAC7C,YAAY,EACR,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,EACtB,MAAM,sCAAsC,CAAC"}
|
|
@@ -3,6 +3,8 @@ import { tmpdir } from 'node:os';
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { createResourcesModule } from "../../resources/resources.js";
|
|
5
5
|
export { defineLocalServiceResource } from "../../resources/local-service-resource.js";
|
|
6
|
+
export { createLocalHttpServiceResource } from "../../resources/local-http-service-resource.js";
|
|
7
|
+
export { createLocalProcessServiceResource } from "../../resources/local-process-service-resource.js";
|
|
6
8
|
const resourcesModule = createResourcesModule({
|
|
7
9
|
temporaryDirectoryPathPrefix: join(tmpdir(), 'overkill-temporary-directory-'),
|
|
8
10
|
async createTemporaryDirectory(pathPrefix) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.entry-point.js","sourceRoot":"","sources":["../../../../../source/packages/resources/resources.entry-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAwB,MAAM,8BAA8B,CAAC;AAE3F,OAAO,
|
|
1
|
+
{"version":3,"file":"resources.entry-point.js","sourceRoot":"","sources":["../../../../../source/packages/resources/resources.entry-point.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAwB,MAAM,8BAA8B,CAAC;AAE3F,OAAO,EACH,0BAA0B,EAC7B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACH,8BAA8B,EACjC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACH,iCAAiC,EACpC,MAAM,mDAAmD,CAAC;AAE3D,MAAM,eAAe,GAAG,qBAAqB,CAAC;IAC1C,4BAA4B,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,+BAA+B,CAAC;IAC7E,KAAK,CAAC,wBAAwB,CAAC,UAAU;QACrC,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,CAAC,eAAe,CAAC,IAAI;QACtB,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;CACJ,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAA6C,eAAe,CAAC,qBAAqB,CAAC;AACrH,MAAM,CAAC,MAAM,eAAe,GAAuC,eAAe,CAAC,eAAe,CAAC;AACnG,MAAM,CAAC,MAAM,gCAAgC,GACzC,eAAe,CAAC,gCAAgC,CAAC;AACrD,MAAM,CAAC,MAAM,cAAc,GAAsC,eAAe,CAAC,cAAc,CAAC;AAChG,MAAM,CAAC,MAAM,aAAa,GAAqC,eAAe,CAAC,aAAa,CAAC;AAC7F,MAAM,CAAC,MAAM,mBAAmB,GAA2C,eAAe,CAAC,mBAAmB,CAAC;AAE/G,OAAO,EACH,iCAAiC,EACpC,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EACH,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACH,0BAA0B,EAC1B,8BAA8B,EACjC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACH,cAAc,EACjB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,sBAAsB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACH,YAAY,EACf,MAAM,sCAAsC,CAAC"}
|
package/readme.md
CHANGED
|
@@ -11,6 +11,7 @@ callback.
|
|
|
11
11
|
import {
|
|
12
12
|
composeRuntimeContext,
|
|
13
13
|
composeRuntimes,
|
|
14
|
+
createLocalHttpServiceResource,
|
|
14
15
|
createTemporaryDirectoryResource,
|
|
15
16
|
defineResource,
|
|
16
17
|
defineRuntime,
|
|
@@ -48,6 +49,23 @@ const server = defineResource({
|
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
|
|
52
|
+
const app = createLocalHttpServiceResource({
|
|
53
|
+
name: 'app',
|
|
54
|
+
scope: 'per-case',
|
|
55
|
+
requirements: [],
|
|
56
|
+
dependencies: { database },
|
|
57
|
+
address: { kind: 'loopback', port: 0 },
|
|
58
|
+
createServer(context) {
|
|
59
|
+
return createAppServer({ database: context.dependencies.database });
|
|
60
|
+
},
|
|
61
|
+
handle(service) {
|
|
62
|
+
return { baseUrl: service.baseUrl };
|
|
63
|
+
},
|
|
64
|
+
dispose() {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
51
69
|
const scratch = createTemporaryDirectoryResource('scratch');
|
|
52
70
|
const sharedDatabase = defineResource({
|
|
53
71
|
name: 'shared-database',
|
|
@@ -71,7 +89,7 @@ const sharedDatabase = defineResource({
|
|
|
71
89
|
const runtime = defineRuntime({
|
|
72
90
|
name: 'api',
|
|
73
91
|
dimensions: {},
|
|
74
|
-
resources: { database, server, scratch },
|
|
92
|
+
resources: { app, database, server, scratch },
|
|
75
93
|
requirements: [ { kind: 'startup-budget-milliseconds', minimumMilliseconds: 1000 } ]
|
|
76
94
|
});
|
|
77
95
|
|
|
@@ -104,17 +122,27 @@ Omitting `dependencies` is accepted for compatibility and produces
|
|
|
104
122
|
whose handle is `{ readonly path: string }`. Each acquisition creates a unique
|
|
105
123
|
directory with an Overkill prefix. Disposal removes that directory recursively.
|
|
106
124
|
|
|
107
|
-
`defineLocalServiceResource(...)`
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
`defineLocalServiceResource(...)` models owned local services with explicit
|
|
126
|
+
`start`, `ready`, and `dispose` phases. Callers declare scope, requirements,
|
|
127
|
+
dependencies, and an explicit address request such as
|
|
128
|
+
`{ kind: 'loopback', port: 0 }`. `start` owns the service internals, `ready`
|
|
129
|
+
returns the object handle exposed to tests, and `dispose` receives only the
|
|
130
|
+
owner state. If readiness fails, the owner is disposed before acquisition
|
|
131
|
+
fails. Projected scopes use the same serialize and deserialize rules as
|
|
132
|
+
ordinary resources.
|
|
133
|
+
|
|
134
|
+
`createLocalHttpServiceResource(...)` owns HTTP `listen` and `close`, exposes
|
|
135
|
+
the actual loopback endpoint and `baseUrl`, and lets callers map that into a
|
|
136
|
+
typed object handle. `createLocalProcessServiceResource(...)` starts a child
|
|
137
|
+
process, drains bounded stdout/stderr lifecycle buffers, waits for explicit
|
|
138
|
+
readiness, and terminates then force-kills during disposal according to the
|
|
139
|
+
declared shutdown contract. Output buffers are lifecycle diagnostics, not
|
|
140
|
+
artifacts.
|
|
141
|
+
|
|
142
|
+
`createSimulatedHttpServerResource({ simulation, address })` starts a simulated
|
|
143
|
+
HTTP server from `@overkill-dev/simulation` as a per-case resource. The
|
|
144
|
+
acquired handle exposes `baseUrl` for the `default` scenario and
|
|
145
|
+
`scenarioUrl(...)` for URL-selected scenarios.
|
|
118
146
|
|
|
119
147
|
`startRuntime(...)` acquires dependencies before dependents, shares one handle
|
|
120
148
|
per descriptor inside the session, and disposes acquired resources once in
|
|
@@ -138,4 +166,8 @@ local to their execution owner and do not use projection hooks.
|
|
|
138
166
|
|
|
139
167
|
Execution requirements describe placement pressure for the runner:
|
|
140
168
|
`serial`, `single-worker`, `exclusive-resource`, `capacity-weight`,
|
|
141
|
-
`affinity-key`, `fault-domain`,
|
|
169
|
+
`affinity-key`, `fault-domain`, `duplicate-execution`, and
|
|
170
|
+
`startup-budget-milliseconds`. `duplicate-execution` declares that a resource
|
|
171
|
+
or runtime makes work safe to duplicate as `idempotent` or
|
|
172
|
+
`disposable-isolated`; the runner still decides whether the active execution
|
|
173
|
+
envelope is strong enough to hedge.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Awaitable, ExecutionRequirement, ResourceDefinition, ResourceDependencies, ResourceProjectionPayload, ResourceScope } from './resources.ts';
|
|
2
|
+
import { type LocalServiceAddressRequest, type LocalServiceConsumerHandle, type LocalServiceCreationContext, type LocalServiceDisposalContext, type LocalServiceHandleProjection, type LocalServiceAddress, type ProjectedLocalServiceScope } from './local-service-resource.ts';
|
|
3
|
+
export type LocalHttpServiceHandle = {
|
|
4
|
+
readonly baseUrl: string;
|
|
5
|
+
readonly endpoint: LocalServiceAddress;
|
|
6
|
+
};
|
|
7
|
+
type LocalHttpServerAddress = {
|
|
8
|
+
readonly port: number;
|
|
9
|
+
};
|
|
10
|
+
export type LocalHttpServer = {
|
|
11
|
+
readonly address: () => LocalHttpServerAddress | string | null;
|
|
12
|
+
readonly close: (callback: (error?: Error) => void) => unknown;
|
|
13
|
+
readonly listen: (port: number, host: string) => unknown;
|
|
14
|
+
readonly listening: boolean;
|
|
15
|
+
readonly off: {
|
|
16
|
+
(event: 'error', listener: (error: Error) => void): unknown;
|
|
17
|
+
(event: 'listening', listener: () => void): unknown;
|
|
18
|
+
};
|
|
19
|
+
readonly once: {
|
|
20
|
+
(event: 'error', listener: (error: Error) => void): unknown;
|
|
21
|
+
(event: 'listening', listener: () => void): unknown;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type LocalHttpServiceResourceInput<Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends ResourceScope, Dependencies extends ResourceDependencies> = {
|
|
25
|
+
readonly address: LocalServiceAddressRequest;
|
|
26
|
+
readonly createServer: (context: LocalServiceCreationContext<Dependencies>) => LocalHttpServer;
|
|
27
|
+
readonly dependencies: Dependencies;
|
|
28
|
+
readonly dispose: (server: LocalHttpServer, context: LocalServiceDisposalContext<Dependencies>) => Awaitable<void>;
|
|
29
|
+
readonly handle: (service: LocalHttpServiceHandle, server: LocalHttpServer, context: LocalServiceCreationContext<Dependencies>) => ConsumerHandle;
|
|
30
|
+
readonly name: Name;
|
|
31
|
+
readonly requirements: readonly ExecutionRequirement[];
|
|
32
|
+
readonly scope: Scope;
|
|
33
|
+
};
|
|
34
|
+
type ProjectedHttpServiceInput<Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, Dependencies extends ResourceDependencies> = {
|
|
35
|
+
readonly address: LocalServiceAddressRequest;
|
|
36
|
+
readonly createServer: LocalHttpServiceResourceInput<Name, ConsumerHandle, ProjectedLocalServiceScope, Dependencies>['createServer'];
|
|
37
|
+
readonly dependencies: Dependencies;
|
|
38
|
+
readonly deserializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['deserializeHandle'];
|
|
39
|
+
readonly dispose: LocalHttpServiceResourceInput<Name, ConsumerHandle, ProjectedLocalServiceScope, Dependencies>['dispose'];
|
|
40
|
+
readonly handle: LocalHttpServiceResourceInput<Name, ConsumerHandle, ProjectedLocalServiceScope, Dependencies>['handle'];
|
|
41
|
+
readonly name: Name;
|
|
42
|
+
readonly requirements: readonly ExecutionRequirement[];
|
|
43
|
+
readonly scope: ProjectedLocalServiceScope;
|
|
44
|
+
readonly serializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['serializeHandle'];
|
|
45
|
+
};
|
|
46
|
+
export declare function createLocalHttpServiceResource<const Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends Exclude<ResourceScope, 'per-run'>, const Dependencies extends ResourceDependencies>(input: LocalHttpServiceResourceInput<Name, ConsumerHandle, Scope, Dependencies>): ResourceDefinition<Name, ConsumerHandle, Dependencies>;
|
|
47
|
+
export declare function createLocalHttpServiceResource<const Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, const Dependencies extends ResourceDependencies>(input: ProjectedHttpServiceInput<Name, ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>): ResourceDefinition<Name, ConsumerHandle, Dependencies, ProjectedConsumerHandle>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=local-http-service-resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-http-service-resource.d.ts","sourceRoot":"","sources":["../../../../source/resources/local-http-service-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,SAAS,EACT,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,aAAa,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGH,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK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AA0B,EAC1B,YAAY,CACf,CAAC,SAAS,CAAC,CAAC;IACb,QAAQ,CAAC,MAAM,EAAE,6BAA6B,CAC1C,IAAI,EACJ,cAAc,EACd,0BAA0B,EAC1B,YAAY,CACf,CAAC,QAAQ,CAAC,CAAC;IACZ,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,YAAY,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,0BAA0B,CAAC;IAC3C,QAAQ,CAAC,eAAe,EAAE,4BAA4B,CAClD,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,YAAY,CACf,CAAC,iBAAiB,CAAC,CAAC;CACxB,CAAC;AAmLF,wBAAgB,8BAA8B,CAC1C,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,cAAc,SAAS,0BAA0B,EACjD,KAAK,SAAS,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,EAC/C,KAAK,CAAC,YAAY,SAAS,oBAAoB,EAE/C,KAAK,EAAE,6BAA6B,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,CAAC,GAChF,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;AAC1D,wBAAgB,8BAA8B,CAC1C,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,cAAc,SAAS,0BAA0B,EACjD,UAAU,SAAS,yBAAyB,EAC5C,uBAAuB,EACvB,KAAK,CAAC,YAAY,SAAS,oBAAoB,EAE/C,KAAK,EAAE,yBAAyB,CAC5B,IAAI,EACJ,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,YAAY,CACf,GACF,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { defineLocalServiceResource, isProjectedLocalServiceScope } from "./local-service-resource.js";
|
|
2
|
+
function serverEndpoint(server, host) {
|
|
3
|
+
const address = server.address();
|
|
4
|
+
if (typeof address !== 'object' || address === null) {
|
|
5
|
+
throw new TypeError('Local HTTP service did not expose a TCP address.');
|
|
6
|
+
}
|
|
7
|
+
return Object.freeze({
|
|
8
|
+
host,
|
|
9
|
+
port: address.port
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async function listen(server, address) {
|
|
13
|
+
await new Promise(function startListening(resolve, reject) {
|
|
14
|
+
const listener = {
|
|
15
|
+
reject(error) {
|
|
16
|
+
server.off('listening', listener.resolve);
|
|
17
|
+
reject(error);
|
|
18
|
+
},
|
|
19
|
+
resolve() {
|
|
20
|
+
server.off('error', listener.reject);
|
|
21
|
+
resolve();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
server.once('error', listener.reject);
|
|
25
|
+
server.once('listening', listener.resolve);
|
|
26
|
+
server.listen(address.port, address.host);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function closeServer(server) {
|
|
30
|
+
if (!server.listening) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await new Promise(function close(resolve, reject) {
|
|
34
|
+
server.close(function finish(error) {
|
|
35
|
+
if (error === undefined) {
|
|
36
|
+
resolve();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
reject(error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function localHttpServiceHandle(endpoint) {
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
endpoint,
|
|
47
|
+
baseUrl: `http://${endpoint.host}:${endpoint.port}`
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function localHttpDefinition(input) {
|
|
51
|
+
return {
|
|
52
|
+
name: input.name,
|
|
53
|
+
scope: input.scope,
|
|
54
|
+
requirements: input.requirements,
|
|
55
|
+
dependencies: input.dependencies,
|
|
56
|
+
address: input.address,
|
|
57
|
+
start(context) {
|
|
58
|
+
return input.createServer(context);
|
|
59
|
+
},
|
|
60
|
+
async ready(server, context) {
|
|
61
|
+
await listen(server, context.address);
|
|
62
|
+
return input.handle(localHttpServiceHandle(serverEndpoint(server, context.address.host)), server, context);
|
|
63
|
+
},
|
|
64
|
+
async dispose(server, context) {
|
|
65
|
+
await closeServer(server);
|
|
66
|
+
await input.dispose(server, context);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function projectedHttpDefinition(input) {
|
|
71
|
+
return {
|
|
72
|
+
...localHttpDefinition(input),
|
|
73
|
+
serializeHandle: input.serializeHandle,
|
|
74
|
+
deserializeHandle: input.deserializeHandle
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function assertProjectedHttpService(input) {
|
|
78
|
+
if (input.serializeHandle === undefined || input.deserializeHandle === undefined) {
|
|
79
|
+
throw new TypeError('Projected local HTTP services require handle projection callbacks.');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function createLocalHttpServiceResource(input) {
|
|
83
|
+
if (isProjectedLocalServiceScope(input.scope)) {
|
|
84
|
+
assertProjectedHttpService(input);
|
|
85
|
+
return defineLocalServiceResource(projectedHttpDefinition(input));
|
|
86
|
+
}
|
|
87
|
+
return defineLocalServiceResource({
|
|
88
|
+
...localHttpDefinition(input),
|
|
89
|
+
scope: input.scope
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=local-http-service-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-http-service-resource.js","sourceRoot":"","sources":["../../../../source/resources/local-http-service-resource.ts"],"names":[],"mappings":"AAQA,OAAO,EACH,0BAA0B,EAC1B,4BAA4B,EAS/B,MAAM,6BAA6B,CAAC;AAuJrC,SAAS,cAAc,CAAC,MAAwC,EAAE,IAAY;IAC1E,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE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,0BAA0B,CAM/B,KAMC;IAQD,IAAI,KAAK,CAAC,eAAe,KAAK,SAAS,IAAI,KAAK,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QAC/E,MAAM,IAAI,SAAS,CAAC,oEAAoE,CAAC,CAAC;IAC9F,CAAC;AACL,CAAC;AAyBD,MAAM,UAAU,8BAA8B,CAO1C,KAMC;IAED,IAAI,4BAA4B,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAElC,OAAO,0BAA0B,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,0BAA0B,CAAC;QAC9B,GAAG,mBAAmB,CAAC,KAAK,CAAC;QAC7B,KAAK,EAAE,KAAK,CAAC,KAAK;KACrB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Awaitable, ExecutionRequirement, ResourceDefinition, ResourceDependencies, ResourceProjectionPayload, ResourceScope } from './resources.ts';
|
|
2
|
+
import { type LocalServiceAddressRequest, type LocalServiceConsumerHandle, type LocalServiceCreationContext, type LocalServiceHandleProjection, type ProjectedLocalServiceScope } from './local-service-resource.ts';
|
|
3
|
+
export type LocalProcessOutputBuffer = {
|
|
4
|
+
readonly bytes: () => Uint8Array;
|
|
5
|
+
readonly text: () => string;
|
|
6
|
+
};
|
|
7
|
+
export type LocalProcessOutput = {
|
|
8
|
+
readonly stderr: LocalProcessOutputBuffer;
|
|
9
|
+
readonly stdout: LocalProcessOutputBuffer;
|
|
10
|
+
};
|
|
11
|
+
export type LocalProcessCommand = {
|
|
12
|
+
readonly arguments: readonly string[];
|
|
13
|
+
readonly command: string;
|
|
14
|
+
readonly environment: Readonly<Record<string, string>>;
|
|
15
|
+
readonly workingDirectory: string | null;
|
|
16
|
+
};
|
|
17
|
+
export type LocalProcessSignal = 'SIGHUP' | 'SIGINT' | 'SIGKILL' | 'SIGTERM' | 'SIGUSR1' | 'SIGUSR2';
|
|
18
|
+
export type LocalProcessShutdown = {
|
|
19
|
+
readonly forceSignal: LocalProcessSignal;
|
|
20
|
+
readonly graceMilliseconds: number;
|
|
21
|
+
readonly gracefulSignal: LocalProcessSignal;
|
|
22
|
+
};
|
|
23
|
+
type LocalProcessChild = {
|
|
24
|
+
readonly exitCode: number | null;
|
|
25
|
+
readonly kill: (signal: LocalProcessSignal) => boolean;
|
|
26
|
+
readonly once: (event: 'error' | 'exit', listener: ((code: number | null, signal: string | null) => void) | ((error: Error) => void)) => unknown;
|
|
27
|
+
readonly signalCode: string | null;
|
|
28
|
+
};
|
|
29
|
+
export type LocalProcessOwner = {
|
|
30
|
+
readonly child: LocalProcessChild;
|
|
31
|
+
readonly output: LocalProcessOutput;
|
|
32
|
+
};
|
|
33
|
+
export type LocalProcessServiceResourceInput<Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends ResourceScope, Dependencies extends ResourceDependencies> = {
|
|
34
|
+
readonly address: LocalServiceAddressRequest;
|
|
35
|
+
readonly command: (context: LocalServiceCreationContext<Dependencies>) => Awaitable<LocalProcessCommand>;
|
|
36
|
+
readonly dependencies: Dependencies;
|
|
37
|
+
readonly name: Name;
|
|
38
|
+
readonly outputBufferBytes: number;
|
|
39
|
+
readonly ready: (owner: LocalProcessOwner, context: LocalServiceCreationContext<Dependencies>) => Awaitable<ConsumerHandle>;
|
|
40
|
+
readonly requirements: readonly ExecutionRequirement[];
|
|
41
|
+
readonly scope: Scope;
|
|
42
|
+
readonly shutdown: LocalProcessShutdown;
|
|
43
|
+
};
|
|
44
|
+
type ProjectedProcessServiceInput<Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, Dependencies extends ResourceDependencies> = {
|
|
45
|
+
readonly address: LocalServiceAddressRequest;
|
|
46
|
+
readonly command: LocalProcessServiceResourceInput<Name, ConsumerHandle, ProjectedLocalServiceScope, Dependencies>['command'];
|
|
47
|
+
readonly dependencies: Dependencies;
|
|
48
|
+
readonly deserializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['deserializeHandle'];
|
|
49
|
+
readonly name: Name;
|
|
50
|
+
readonly outputBufferBytes: number;
|
|
51
|
+
readonly ready: LocalProcessServiceResourceInput<Name, ConsumerHandle, ProjectedLocalServiceScope, Dependencies>['ready'];
|
|
52
|
+
readonly requirements: readonly ExecutionRequirement[];
|
|
53
|
+
readonly scope: ProjectedLocalServiceScope;
|
|
54
|
+
readonly serializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['serializeHandle'];
|
|
55
|
+
readonly shutdown: LocalProcessShutdown;
|
|
56
|
+
};
|
|
57
|
+
export declare function createLocalProcessServiceResource<const Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends Exclude<ResourceScope, 'per-run'>, const Dependencies extends ResourceDependencies>(input: LocalProcessServiceResourceInput<Name, ConsumerHandle, Scope, Dependencies>): ResourceDefinition<Name, ConsumerHandle, Dependencies>;
|
|
58
|
+
export declare function createLocalProcessServiceResource<const Name extends string, ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, const Dependencies extends ResourceDependencies>(input: ProjectedProcessServiceInput<Name, ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>): ResourceDefinition<Name, ConsumerHandle, Dependencies, ProjectedConsumerHandle>;
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=local-process-service-resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-process-service-resource.d.ts","sourceRoot":"","sources":["../../../../source/resources/local-process-service-resource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,SAAS,EACT,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EACzB,aAAa,EAChB,MAAM,gBAAgB,CAAC;AACxB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IAAI,SAAS,MAAM,EACzB,cAAc,SAAS,0BAA0B,EACjD,UAAU,SAAS,yBAAyB,EAC5C,uBAAuB,EACvB,KAAK,CAAC,YAAY,SAAS,oBAAoB,EAE/C,KAAK,EAAE,4BAA4B,CAC/B,IAAI,EACJ,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,YAAY,CACf,GACF,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { setTimeout as wait } from 'node:timers/promises';
|
|
3
|
+
import { defineLocalServiceResource, isProjectedLocalServiceScope } from "./local-service-resource.js";
|
|
4
|
+
function createBoundedOutputBuffer(maxBytes) {
|
|
5
|
+
let value = Buffer.alloc(0);
|
|
6
|
+
return {
|
|
7
|
+
append(chunk) {
|
|
8
|
+
value = Buffer.concat([value, chunk]);
|
|
9
|
+
if (value.byteLength > maxBytes) {
|
|
10
|
+
value = value.subarray(value.byteLength - maxBytes);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
buffer: Object.freeze({
|
|
14
|
+
bytes() {
|
|
15
|
+
return new Uint8Array(value);
|
|
16
|
+
},
|
|
17
|
+
text() {
|
|
18
|
+
return value.toString('utf8');
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function localProcessOutput(maxBytes) {
|
|
24
|
+
const stdout = createBoundedOutputBuffer(maxBytes);
|
|
25
|
+
const stderr = createBoundedOutputBuffer(maxBytes);
|
|
26
|
+
return {
|
|
27
|
+
appendStderr: stderr.append,
|
|
28
|
+
appendStdout: stdout.append,
|
|
29
|
+
output: Object.freeze({
|
|
30
|
+
stderr: stderr.buffer,
|
|
31
|
+
stdout: stdout.buffer
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function attachOutputDrains(child, output) {
|
|
36
|
+
if (child.stdout === null || child.stderr === null) {
|
|
37
|
+
throw new TypeError('Local process service requires piped stdout and stderr.');
|
|
38
|
+
}
|
|
39
|
+
child.stdout.on('data', output.appendStdout);
|
|
40
|
+
child.stderr.on('data', output.appendStderr);
|
|
41
|
+
}
|
|
42
|
+
function spawnLocalProcess(command, output) {
|
|
43
|
+
const child = spawn(command.command, command.arguments, {
|
|
44
|
+
cwd: command.workingDirectory ?? process.cwd(),
|
|
45
|
+
env: command.environment,
|
|
46
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
47
|
+
});
|
|
48
|
+
attachOutputDrains(child, output);
|
|
49
|
+
return child;
|
|
50
|
+
}
|
|
51
|
+
async function processExitFailure(owner) {
|
|
52
|
+
return await new Promise(function rejectOnProcessExit(_resolve, reject) {
|
|
53
|
+
owner.child.once('error', reject);
|
|
54
|
+
owner.child.once('exit', function rejectEarlyExit(code, signal) {
|
|
55
|
+
reject(new Error([
|
|
56
|
+
`Local process service exited before readiness: code ${String(code)}, signal ${String(signal)}.`,
|
|
57
|
+
owner.output.stderr.text()
|
|
58
|
+
]
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.join('\n')));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async function readyLocalProcess(owner, context, input) {
|
|
65
|
+
return await Promise.race([
|
|
66
|
+
input.ready(owner, context),
|
|
67
|
+
processExitFailure(owner)
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
async function waitForProcessExit(child) {
|
|
71
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await new Promise(function resolveOnExit(resolve) {
|
|
75
|
+
child.once('exit', function resolveExit() {
|
|
76
|
+
resolve();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function disposeLocalProcess(owner, shutdown) {
|
|
81
|
+
if (owner.child.exitCode !== null || owner.child.signalCode !== null) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
owner.child.kill(shutdown.gracefulSignal);
|
|
85
|
+
const exited = waitForProcessExit(owner.child);
|
|
86
|
+
const result = await Promise.race([exited, wait(shutdown.graceMilliseconds, 'delay')]);
|
|
87
|
+
if (result === 'delay') {
|
|
88
|
+
owner.child.kill(shutdown.forceSignal);
|
|
89
|
+
await waitForProcessExit(owner.child);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function assertProcessInput(input) {
|
|
93
|
+
if (!Number.isSafeInteger(input.outputBufferBytes) || input.outputBufferBytes < 0) {
|
|
94
|
+
throw new TypeError('Local process service outputBufferBytes must be a non-negative integer.');
|
|
95
|
+
}
|
|
96
|
+
if (!Number.isSafeInteger(input.shutdown.graceMilliseconds) || input.shutdown.graceMilliseconds < 0) {
|
|
97
|
+
throw new TypeError('Local process service shutdown.graceMilliseconds must be a non-negative integer.');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function localProcessDefinition(input) {
|
|
101
|
+
return {
|
|
102
|
+
name: input.name,
|
|
103
|
+
scope: input.scope,
|
|
104
|
+
requirements: input.requirements,
|
|
105
|
+
dependencies: input.dependencies,
|
|
106
|
+
address: input.address,
|
|
107
|
+
async start(context) {
|
|
108
|
+
const command = await input.command(context);
|
|
109
|
+
const output = localProcessOutput(input.outputBufferBytes);
|
|
110
|
+
return Object.freeze({
|
|
111
|
+
child: spawnLocalProcess(command, output),
|
|
112
|
+
output: output.output
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
async ready(owner, context) {
|
|
116
|
+
return await readyLocalProcess(owner, context, input);
|
|
117
|
+
},
|
|
118
|
+
async dispose(owner) {
|
|
119
|
+
await disposeLocalProcess(owner, input.shutdown);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function projectedProcessDefinition(input) {
|
|
124
|
+
return {
|
|
125
|
+
...localProcessDefinition(input),
|
|
126
|
+
serializeHandle: input.serializeHandle,
|
|
127
|
+
deserializeHandle: input.deserializeHandle
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function assertProjectedProcessService(input) {
|
|
131
|
+
if (input.serializeHandle === undefined || input.deserializeHandle === undefined) {
|
|
132
|
+
throw new TypeError('Projected local process services require handle projection callbacks.');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function createLocalProcessServiceResource(input) {
|
|
136
|
+
assertProcessInput(input);
|
|
137
|
+
if (isProjectedLocalServiceScope(input.scope)) {
|
|
138
|
+
assertProjectedProcessService(input);
|
|
139
|
+
return defineLocalServiceResource(projectedProcessDefinition(input));
|
|
140
|
+
}
|
|
141
|
+
return defineLocalServiceResource({
|
|
142
|
+
...localProcessDefinition(input),
|
|
143
|
+
scope: input.scope
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=local-process-service-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-process-service-resource.js","sourceRoot":"","sources":["../../../../source/resources/local-process-service-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EACH,0BAA0B,EAC1B,4BAA4B,EAQ/B,MAAM,6BAA6B,CAAC;AA0KrC,SAAS,yBAAyB,CAAC,QAAgB;IAC/C,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE5B,OAAO;QACH,MAAM,CAAC,KAAK;YACR,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAE,KAAK,EAAE,KAAK,CAAE,CAAC,CAAC;YAExC,IAAI,KAAK,CAAC,UAAU,GAAG,QAAQ,EAAE,CAAC;gBAC9B,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC;YACxD,CAAC;QACL,C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BAAkB,CAAC,KAAK,CAAC,CAAC;IAE1B,IAAI,4BAA4B,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5C,6BAA6B,CAAC,KAAK,CAAC,CAAC;QAErC,OAAO,0BAA0B,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,0BAA0B,CAAC;QAC9B,GAAG,sBAAsB,CAAC,KAAK,CAAC;QAChC,KAAK,EAAE,KAAK,CAAC,KAAK;KACrB,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import { type Awaitable, type EmptyResourceDependencies, type ExecutionRequirement, type ResourceContext, type ResourceDefinition, type ResourceDependencies, type
|
|
1
|
+
import { type Awaitable, type EmptyResourceDependencies, type ExecutionRequirement, type ResourceContext, type ResourceDefinition, type ResourceDependencies, type ResourceProjectionContext, type ResourceProjectionPayload, type ResourceScope } from './resources.ts';
|
|
2
2
|
import type { ValueOf } from './resource-definition-shape.ts';
|
|
3
|
+
export type LocalServiceLoopbackAddressRequest = {
|
|
4
|
+
readonly kind: 'loopback';
|
|
5
|
+
readonly port: number;
|
|
6
|
+
};
|
|
7
|
+
export type LocalServiceHostAddressRequest = {
|
|
8
|
+
readonly host: string;
|
|
9
|
+
readonly kind: 'host';
|
|
10
|
+
readonly port: number;
|
|
11
|
+
};
|
|
12
|
+
export type LocalServiceAddressRequest = LocalServiceHostAddressRequest | LocalServiceLoopbackAddressRequest;
|
|
3
13
|
export type LocalServiceAddress = {
|
|
4
14
|
readonly host: string;
|
|
5
15
|
readonly port: number;
|
|
@@ -9,47 +19,48 @@ export type LocalServiceCreationContext<Dependencies extends ResourceDependencie
|
|
|
9
19
|
readonly dependencies: ResourceContext<Dependencies>;
|
|
10
20
|
readonly signal: AbortSignal;
|
|
11
21
|
};
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
export type LocalServiceDisposalContext<Dependencies extends ResourceDependencies = EmptyResourceDependencies> = {
|
|
23
|
+
readonly address: LocalServiceAddress;
|
|
24
|
+
readonly dependencies: ResourceContext<Dependencies>;
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
};
|
|
27
|
+
export type LocalServiceConsumerHandle = Readonly<Partial<Record<PropertyKey, unknown>>>;
|
|
28
|
+
export type ProjectedLocalServiceScope = 'per-file' | 'per-run' | 'per-suite';
|
|
29
|
+
export type LocalServiceHandleProjection<ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, Dependencies extends ResourceDependencies> = {
|
|
30
|
+
readonly deserializeHandle: (payload: Projection, context: ResourceProjectionContext<Dependencies>) => ProjectedConsumerHandle;
|
|
31
|
+
readonly serializeHandle: (handle: ConsumerHandle, context: ResourceProjectionContext<Dependencies>) => Projection;
|
|
32
|
+
};
|
|
33
|
+
type LocalServiceDefinitionDisposal<OwnerHandle, Dependencies extends ResourceDependencies> = {
|
|
34
|
+
readonly dispose: (owner: OwnerHandle, context: LocalServiceDisposalContext<Dependencies>) => Awaitable<void>;
|
|
35
|
+
};
|
|
36
|
+
type LocalServiceResourceDefinitionBaseInput<Name extends string, OwnerHandle, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends ResourceScope, Dependencies extends ResourceDependencies> = LocalServiceDefinitionDisposal<OwnerHandle, Dependencies> & {
|
|
37
|
+
readonly address: LocalServiceAddressRequest;
|
|
15
38
|
readonly dependencies: Dependencies;
|
|
16
|
-
readonly deserializeHandle: ProjectedBase<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>['deserializeHandle'];
|
|
17
|
-
readonly dispose: ProjectedBase<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>['dispose'];
|
|
18
|
-
readonly host?: string;
|
|
19
39
|
readonly name: Name;
|
|
20
|
-
readonly
|
|
40
|
+
readonly ready: (owner: OwnerHandle, context: LocalServiceCreationContext<Dependencies>) => Awaitable<ConsumerHandle>;
|
|
21
41
|
readonly requirements: readonly ExecutionRequirement[];
|
|
22
42
|
readonly scope: Scope;
|
|
23
|
-
readonly
|
|
24
|
-
readonly start: ProjectedBase<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>['start'];
|
|
43
|
+
readonly start: (context: LocalServiceCreationContext<Dependencies>) => Awaitable<OwnerHandle>;
|
|
25
44
|
};
|
|
26
|
-
type
|
|
27
|
-
|
|
28
|
-
readonly
|
|
29
|
-
readonly
|
|
45
|
+
export type LocalOnlyLocalServiceResourceDefinitionInput<Name extends string, OwnerHandle, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends Exclude<ResourceScope, 'per-run'>, Dependencies extends ResourceDependencies = EmptyResourceDependencies> = LocalServiceResourceDefinitionBaseInput<Name, OwnerHandle, ConsumerHandle, Scope, Dependencies>;
|
|
46
|
+
export type ProjectedLocalServiceResourceDefinitionInput<Name extends string, OwnerHandle, ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, Scope extends ProjectedLocalServiceScope, Dependencies extends ResourceDependencies = EmptyResourceDependencies> = {
|
|
47
|
+
readonly address: LocalServiceAddressRequest;
|
|
48
|
+
readonly dependencies: Dependencies;
|
|
49
|
+
readonly deserializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['deserializeHandle'];
|
|
50
|
+
readonly dispose: LocalServiceDefinitionDisposal<OwnerHandle, Dependencies>['dispose'];
|
|
30
51
|
readonly name: Name;
|
|
31
|
-
readonly
|
|
52
|
+
readonly ready: (owner: OwnerHandle, context: LocalServiceCreationContext<Dependencies>) => Awaitable<ConsumerHandle>;
|
|
32
53
|
readonly requirements: readonly ExecutionRequirement[];
|
|
33
54
|
readonly scope: Scope;
|
|
34
|
-
readonly
|
|
55
|
+
readonly serializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['serializeHandle'];
|
|
56
|
+
readonly start: (context: LocalServiceCreationContext<Dependencies>) => Awaitable<OwnerHandle>;
|
|
35
57
|
};
|
|
36
|
-
type
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
39
|
-
};
|
|
40
|
-
type ProjectedLocalServiceResourceDefinitionInput<Name extends string, OwnerHandle, Projection extends ResourceProjectionPayload, ConsumerHandle, Scope extends ProjectedLocalServiceScope, Dependencies extends ResourceDependencies = EmptyResourceDependencies> = LocalServiceResourceDefinitionBaseInput<Name, OwnerHandle, Scope, Dependencies> & {
|
|
41
|
-
readonly deserializeHandle: (payload: Projection, context: ResourceProjectionContext<Dependencies>) => ConsumerHandle;
|
|
42
|
-
readonly serializeHandle: (handle: OwnerHandle, context: ResourceProjectionContext<Dependencies>) => Projection;
|
|
43
|
-
};
|
|
44
|
-
export type LocalServiceResourceDefinitionInput<Name extends string, Handle, Dependencies extends ResourceDependencies = EmptyResourceDependencies, Projection extends ResourceProjectionPayload = ResourceProjectionPayload, ConsumerHandle = Handle> = ValueOf<{
|
|
45
|
-
readonly local: LocalOnlyLocalServiceResourceDefinitionInput<Name, Handle, Exclude<ResourceScope, 'per-run'>, Dependencies>;
|
|
46
|
-
readonly projected: ProjectedLocalServiceResourceDefinitionInput<Name, Handle, Projection, ConsumerHandle, ProjectedLocalServiceScope, Dependencies>;
|
|
58
|
+
export type LocalServiceResourceDefinitionInput<Name extends string, OwnerHandle, ConsumerHandle extends LocalServiceConsumerHandle, Dependencies extends ResourceDependencies = EmptyResourceDependencies, Projection extends ResourceProjectionPayload = ResourceProjectionPayload, ProjectedConsumerHandle = ConsumerHandle> = ValueOf<{
|
|
59
|
+
readonly local: LocalOnlyLocalServiceResourceDefinitionInput<Name, OwnerHandle, ConsumerHandle, Exclude<ResourceScope, 'per-run'>, Dependencies>;
|
|
60
|
+
readonly projected: ProjectedLocalServiceResourceDefinitionInput<Name, OwnerHandle, ConsumerHandle, Projection, ProjectedConsumerHandle, ProjectedLocalServiceScope, Dependencies>;
|
|
47
61
|
}>;
|
|
48
|
-
export declare function
|
|
49
|
-
export declare function defineLocalServiceResource<const Name extends string, OwnerHandle,
|
|
50
|
-
export declare function defineLocalServiceResource<const Name extends string,
|
|
51
|
-
readonly dependencies: Dependencies;
|
|
52
|
-
}): ResourceDefinition<Name, Handle, Dependencies>;
|
|
53
|
-
export declare function defineLocalServiceResource<const Name extends string, OwnerHandle, Projection extends ResourceProjectionPayload, ConsumerHandle, Scope extends ProjectedLocalServiceScope, const Dependencies extends ResourceDependencies>(definition: ProjectedServiceWithDependencies<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>): ResourceDefinition<Name, OwnerHandle, Dependencies, ConsumerHandle>;
|
|
62
|
+
export declare function isProjectedLocalServiceScope(scope: ResourceScope): scope is ProjectedLocalServiceScope;
|
|
63
|
+
export declare function defineLocalServiceResource<const Name extends string, OwnerHandle, ConsumerHandle extends LocalServiceConsumerHandle, Scope extends Exclude<ResourceScope, 'per-run'>, const Dependencies extends ResourceDependencies>(definition: LocalOnlyLocalServiceResourceDefinitionInput<Name, OwnerHandle, ConsumerHandle, Scope, Dependencies>): ResourceDefinition<Name, ConsumerHandle, Dependencies>;
|
|
64
|
+
export declare function defineLocalServiceResource<const Name extends string, OwnerHandle, ConsumerHandle extends LocalServiceConsumerHandle, Projection extends ResourceProjectionPayload, ProjectedConsumerHandle, Scope extends ProjectedLocalServiceScope, const Dependencies extends ResourceDependencies>(definition: ProjectedLocalServiceResourceDefinitionInput<Name, OwnerHandle, ConsumerHandle, Projection, ProjectedConsumerHandle, Scope, Dependencies>): ResourceDefinition<Name, ConsumerHandle, Dependencies, ProjectedConsumerHandle>;
|
|
54
65
|
export {};
|
|
55
66
|
//# sourceMappingURL=local-service-resource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-service-resource.d.ts","sourceRoot":"","sources":["../../../../source/resources/local-service-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,SAAS,EACd,KAAK,yBAAyB,EAC9B,KAAK,oBAA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AAI,EACJ,WAAW,EACX,cAAc,EACd,KAAK,EACL,YAAY,CACf,GACF,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;AAC1D,wBAAgB,0BAA0B,CACtC,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,WAAW,EACX,cAAc,SAAS,0BAA0B,EACjD,UAAU,SAAS,yBAAyB,EAC5C,uBAAuB,EACvB,KAAK,SAAS,0BAA0B,EACxC,KAAK,CAAC,YAAY,SAAS,oBAAoB,EAE/C,UAAU,EAAE,4CAA4C,CACpD,IAAI,EACJ,WAAW,EACX,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,KAAK,EACL,YAAY,CACf,GACF,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,uBAAuB,CAAC,CAAC"}
|
|
@@ -1,66 +1,122 @@
|
|
|
1
1
|
import { defineResource } from "./resources.js";
|
|
2
|
-
|
|
2
|
+
const localServiceAcquireFailures = new WeakMap();
|
|
3
|
+
function localServiceAcquireFailureError(failure) {
|
|
4
|
+
const error = new Error('Local service acquisition failed.', { cause: failure.cause });
|
|
5
|
+
localServiceAcquireFailures.set(error, failure);
|
|
6
|
+
return error;
|
|
7
|
+
}
|
|
8
|
+
function localServiceAddress(request) {
|
|
9
|
+
return Object.freeze({
|
|
10
|
+
host: request.kind === 'loopback' ? '127.0.0.1' : request.host,
|
|
11
|
+
port: request.port
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export function isProjectedLocalServiceScope(scope) {
|
|
15
|
+
return ['per-file', 'per-run', 'per-suite'].includes(scope);
|
|
16
|
+
}
|
|
17
|
+
function internalCleanupSignal() {
|
|
18
|
+
const controller = new AbortController();
|
|
19
|
+
return controller.signal;
|
|
20
|
+
}
|
|
21
|
+
function resourceAcquireFailure(cause, cleanupError) {
|
|
22
|
+
return { cause, cleanupError };
|
|
23
|
+
}
|
|
24
|
+
function lifecycleError(failure) {
|
|
25
|
+
return failure.cleanupError === null
|
|
26
|
+
? failure.cause
|
|
27
|
+
: new AggregateError([failure.cause, failure.cleanupError], 'Local service acquisition cleanup failed.');
|
|
28
|
+
}
|
|
29
|
+
async function cleanupStartedService(owner, definition, context) {
|
|
30
|
+
try {
|
|
31
|
+
await definition.dispose(owner, {
|
|
32
|
+
address: context.address,
|
|
33
|
+
dependencies: context.dependencies,
|
|
34
|
+
signal: internalCleanupSignal()
|
|
35
|
+
});
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function serviceContext(context, address) {
|
|
3
43
|
return Object.freeze({
|
|
4
|
-
|
|
5
|
-
|
|
44
|
+
...context,
|
|
45
|
+
address
|
|
6
46
|
});
|
|
7
47
|
}
|
|
8
|
-
function
|
|
48
|
+
async function acquireReadyHandle(definition, context) {
|
|
49
|
+
context.signal.throwIfAborted();
|
|
50
|
+
const owner = await definition.start(context);
|
|
51
|
+
try {
|
|
52
|
+
context.signal.throwIfAborted();
|
|
53
|
+
const consumer = await definition.ready(owner, context);
|
|
54
|
+
context.signal.throwIfAborted();
|
|
55
|
+
return [owner, consumer];
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw localServiceAcquireFailureError(resourceAcquireFailure(error, await cleanupStartedService(owner, definition, context)));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function localServiceAcquire(definition, address, owners) {
|
|
9
62
|
return async function startLocalService(context) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
63
|
+
try {
|
|
64
|
+
const [owner, consumer] = await acquireReadyHandle(definition, serviceContext(context, address));
|
|
65
|
+
owners.set(consumer, owner);
|
|
66
|
+
return consumer;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof Error) {
|
|
70
|
+
const failure = localServiceAcquireFailures.get(error);
|
|
71
|
+
if (failure !== undefined) {
|
|
72
|
+
throw lifecycleError(failure);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
14
77
|
};
|
|
15
78
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
79
|
+
function localServiceDispose(definition, address, owners) {
|
|
80
|
+
return async function disposeLocalService(handle, context) {
|
|
81
|
+
const owner = owners.get(handle);
|
|
82
|
+
if (owner === undefined) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
owners.delete(handle);
|
|
86
|
+
await definition.dispose(owner, {
|
|
87
|
+
address,
|
|
88
|
+
dependencies: context.dependencies,
|
|
89
|
+
signal: context.signal
|
|
90
|
+
});
|
|
91
|
+
};
|
|
18
92
|
}
|
|
19
93
|
function isProjectedLocalService(definition) {
|
|
20
94
|
return Object.hasOwn(definition, 'serializeHandle') && Object.hasOwn(definition, 'deserializeHandle');
|
|
21
95
|
}
|
|
22
96
|
export function defineLocalServiceResource(definition) {
|
|
23
|
-
const address = localServiceAddress(definition.
|
|
24
|
-
const
|
|
97
|
+
const address = localServiceAddress(definition.address);
|
|
98
|
+
const owners = new WeakMap();
|
|
99
|
+
const acquire = localServiceAcquire(definition, address, owners);
|
|
100
|
+
const dispose = localServiceDispose(definition, address, owners);
|
|
25
101
|
if (isProjectedLocalService(definition)) {
|
|
26
|
-
if (hasDependencies(definition)) {
|
|
27
|
-
return defineResource({
|
|
28
|
-
name: definition.name,
|
|
29
|
-
scope: definition.scope,
|
|
30
|
-
requirements: definition.requirements,
|
|
31
|
-
acquire,
|
|
32
|
-
dispose: definition.dispose,
|
|
33
|
-
dependencies: definition.dependencies,
|
|
34
|
-
serializeHandle: definition.serializeHandle,
|
|
35
|
-
deserializeHandle: definition.deserializeHandle
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
102
|
return defineResource({
|
|
39
103
|
name: definition.name,
|
|
40
104
|
scope: definition.scope,
|
|
41
105
|
requirements: definition.requirements,
|
|
106
|
+
dependencies: definition.dependencies,
|
|
42
107
|
acquire,
|
|
43
|
-
dispose
|
|
108
|
+
dispose,
|
|
44
109
|
serializeHandle: definition.serializeHandle,
|
|
45
110
|
deserializeHandle: definition.deserializeHandle
|
|
46
111
|
});
|
|
47
112
|
}
|
|
48
|
-
if (hasDependencies(definition)) {
|
|
49
|
-
return defineResource({
|
|
50
|
-
name: definition.name,
|
|
51
|
-
scope: definition.scope,
|
|
52
|
-
requirements: definition.requirements,
|
|
53
|
-
acquire,
|
|
54
|
-
dispose: definition.dispose,
|
|
55
|
-
dependencies: definition.dependencies
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
113
|
return defineResource({
|
|
59
114
|
name: definition.name,
|
|
60
115
|
scope: definition.scope,
|
|
61
116
|
requirements: definition.requirements,
|
|
117
|
+
dependencies: definition.dependencies,
|
|
62
118
|
acquire,
|
|
63
|
-
dispose
|
|
119
|
+
dispose
|
|
64
120
|
});
|
|
65
121
|
}
|
|
66
122
|
//# sourceMappingURL=local-service-resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-service-resource.js","sourceRoot":"","sources":["../../../../source/resources/local-service-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,
|
|
1
|
+
{"version":3,"file":"local-service-resource.js","sourceRoot":"","sources":["../../../../source/resources/local-service-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EAWjB,MAAM,gBAAgB,CAAC;AAsExB,MAAM,2BAA2B,GAAG,IAAI,OAAO,EAAiC,CAAC;AAEjF,SAAS,+BAA+B,CAAC,OAA+B;IACpE,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,mCAAmC,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAEvF,2BAA2B,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAEhD,OAAO,KAAK,CAAC;AACjB,CAAC;AA8FD,SAAS,mBAAmB,CAAC,OAAmC;IAC5D,OA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AC,KAAK;YACvB,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,OAAO;YACP,OAAO;YACP,eAAe,EAAE,UAAU,CAAC,eAAe;YAC3C,iBAAiB,EAAE,UAAU,CAAC,iBAAiB;SAClD,CAAC,CAAC;IACP,CAAC;IAED,OAAO,cAAc,CAAC;QAClB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,YAAY,EAAE,UAAU,CAAC,YAAY;QACrC,YAAY,EAAE,UAAU,CAAC,YAAY;QACrC,OAAO;QACP,OAAO;KACV,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -26,7 +26,11 @@ type FaultDomain = {
|
|
|
26
26
|
readonly key: string;
|
|
27
27
|
readonly kind: 'fault-domain';
|
|
28
28
|
};
|
|
29
|
-
type
|
|
29
|
+
type DuplicateExecution = {
|
|
30
|
+
readonly kind: 'duplicate-execution';
|
|
31
|
+
readonly safety: 'disposable-isolated' | 'idempotent';
|
|
32
|
+
};
|
|
33
|
+
type PlacementRequirement = AffinityKey | CapacityWeight | DuplicateExecution | ExclusiveResource | FaultDomain;
|
|
30
34
|
type SchedulingRequirement = SerialExecution | SingleWorkerExecution | StartupBudget;
|
|
31
35
|
export type ExecutionRequirement = PlacementRequirement | SchedulingRequirement;
|
|
32
36
|
export type ResourceScope = 'per-case' | 'per-file' | 'per-run' | 'per-suite' | 'shared-per-worker';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-definition-shape.d.ts","sourceRoot":"","sources":["../../../../source/resources/resource-definition-shape.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;AACtD,MAAM,MAAM,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC;AAEnD,KAAK,iBAAiB,GAAG;IAAE,Q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imulatedHttpServerDefinition, SimulationScenarioCatalog } from '@overkill-dev/simulation';
|
|
3
2
|
import type { EmptyResourceDependencies, ResourceDefinition } from './resources.ts';
|
|
3
|
+
import { type LocalHttpServiceHandle } from './local-http-service-resource.ts';
|
|
4
|
+
import type { LocalServiceAddressRequest } from './local-service-resource.ts';
|
|
4
5
|
export type SimulatedHttpServerResourceOptions<Name extends string, Scenarios extends SimulationScenarioCatalog> = {
|
|
5
|
-
readonly
|
|
6
|
-
readonly port?: number;
|
|
6
|
+
readonly address: LocalServiceAddressRequest;
|
|
7
7
|
readonly simulation: SimulatedHttpServerDefinition<Name, Scenarios>;
|
|
8
8
|
};
|
|
9
|
+
export type SimulatedHttpServerResourceHandle<Simulation extends {
|
|
10
|
+
readonly scenarios: SimulationScenarioCatalog;
|
|
11
|
+
}> = {
|
|
12
|
+
readonly baseUrl: string;
|
|
13
|
+
readonly endpoint: LocalHttpServiceHandle['endpoint'];
|
|
14
|
+
readonly scenarioUrl: (scenario: string & keyof Simulation['scenarios'], path: string) => string;
|
|
15
|
+
};
|
|
9
16
|
export type SimulatedHttpServerResource<Simulation extends {
|
|
10
17
|
readonly name: string;
|
|
11
18
|
readonly scenarios: SimulationScenarioCatalog;
|
|
12
|
-
}> = ResourceDefinition<Simulation['name'],
|
|
19
|
+
}> = ResourceDefinition<Simulation['name'], SimulatedHttpServerResourceHandle<Simulation>, EmptyResourceDependencies>;
|
|
13
20
|
export declare function createSimulatedHttpServerResource<const Name extends string, const Scenarios extends SimulationScenarioCatalog>(options: SimulatedHttpServerResourceOptions<Name, Scenarios>): SimulatedHttpServerResource<SimulatedHttpServerDefinition<Name, Scenarios>>;
|
|
14
21
|
//# sourceMappingURL=simulated-http-server-resource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulated-http-server-resource.d.ts","sourceRoot":"","sources":["../../../../source/resources/simulated-http-server-resource.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"simulated-http-server-res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S,SAAS,yBAAyB,EAEjD,OAAO,EAAE,kCAAkC,CAAC,IAAI,EAAE,SAAS,CAAC,GAC7D,2BAA2B,CAAC,6BAA6B,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAyB7E"}
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { assertNoSimulatedHttpHandlerErrors, createSimulatedHttpListeningServer } from "@overkill-dev/simulation/http";
|
|
2
|
+
import { createLocalHttpServiceResource } from "./local-http-service-resource.js";
|
|
3
|
+
const scenarioQueryParameterName = '__overkill_scenario';
|
|
4
|
+
function scenarioUrl(baseUrl, scenario, path) {
|
|
5
|
+
const url = new URL(path, baseUrl);
|
|
6
|
+
url.searchParams.set(scenarioQueryParameterName, scenario);
|
|
7
|
+
return url.href;
|
|
8
|
+
}
|
|
9
|
+
function simulatedHttpServerResourceHandle(service) {
|
|
10
|
+
return Object.freeze({
|
|
11
|
+
baseUrl: service.baseUrl,
|
|
12
|
+
endpoint: service.endpoint,
|
|
13
|
+
scenarioUrl(scenario, path) {
|
|
14
|
+
return scenarioUrl(service.baseUrl, scenario, path);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
3
18
|
export function createSimulatedHttpServerResource(options) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
...options.port === undefined ? {} : { port: options.port }
|
|
7
|
-
};
|
|
8
|
-
return defineLocalServiceResource({
|
|
19
|
+
const handlerErrors = new WeakMap();
|
|
20
|
+
return createLocalHttpServiceResource({
|
|
9
21
|
name: options.simulation.name,
|
|
10
22
|
scope: 'per-case',
|
|
11
23
|
requirements: [],
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
dependencies: {},
|
|
25
|
+
address: options.address,
|
|
26
|
+
createServer(context) {
|
|
14
27
|
context.signal.throwIfAborted();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
port: context.address.port
|
|
19
|
-
});
|
|
28
|
+
const listeningServer = createSimulatedHttpListeningServer(options.simulation, context.address.host);
|
|
29
|
+
handlerErrors.set(listeningServer.server, listeningServer.errors);
|
|
30
|
+
return listeningServer.server;
|
|
20
31
|
},
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
handle: (simulatedHttpServerResourceHandle),
|
|
33
|
+
dispose(server) {
|
|
34
|
+
assertNoSimulatedHttpHandlerErrors(handlerErrors.get(server) ?? []);
|
|
23
35
|
}
|
|
24
36
|
});
|
|
25
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulated-http-server-resource.js","sourceRoot":"","sources":["../../../../source/resources/simulated-http-server-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,
|
|
1
|
+
{"version":3,"file":"simulated-http-server-resource.js","sourceRoot":"","sources":["../../../../source/resources/simulated-http-server-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,kCAAkC,EAClC,kCAAkC,EACrC,MAAM,+BAAwC,CAAC;AAShD,OAAO,EACH,8BAA8B,EAGjC,MAAM,kCAAkC,CAAC;AAkC1C,MAAM,0BAA0B,GAAG,qBAAqB,CAAC;AAEzD,SAAS,WAAW,CAAC,OAAe,EAAE,QAAgB,EAAE,IAAY;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEnC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,0BAA0B,EAAE,QAAQ,CAAC,CAAC;IAE3D,OAAO,GAAG,CAAC,IAAI,CAAC;AACpB,CAAC;AAED,SAAS,iCAAiC,CAKtC,OAA+B;IAE/B,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,CAAC,QAAgD,EAAE,IAAY;YACtE,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxD,CAAC;KACJ,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,iCAAiC,CAI7C,OAA4D;IAE5D,MAAM,aAAa,GAAG,IAAI,OAAO,EAAuC,CAAC;IAEzE,OAAO,8BAA8B,CAAC;QAClC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;QAC7B,KAAK,EAAE,UAAU;QACjB,YAAY,EAAE,EAAE;QAChB,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,YAAY,CAAC,OAAO;YAChB,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAChC,MAAM,eAAe,GAAG,kCAAkC,CACtD,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,OAAO,CAAC,IAAI,CACvB,CAAC;YAEF,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;YAElE,OAAO,eAAe,CAAC,MAAM,CAAC;QAClC,CAAC;QACD,MAAM,EAAE,CAAA,iCAAiF,CAAA;QACzF,OAAO,CAAC,MAAM;YACV,kCAAkC,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;KACJ,CAAC,CAAC;AACP,CAAC"}
|
package/sbom.cdx.json
CHANGED
|
@@ -16,35 +16,35 @@
|
|
|
16
16
|
"component": {
|
|
17
17
|
"type": "library",
|
|
18
18
|
"name": "@overkill-dev/resources",
|
|
19
|
-
"version": "0.0.
|
|
20
|
-
"bom-ref": "pkg:npm/@overkill-dev/resources@0.0.
|
|
21
|
-
"purl": "pkg:npm/@overkill-dev/resources@0.0.
|
|
19
|
+
"version": "0.0.5",
|
|
20
|
+
"bom-ref": "pkg:npm/@overkill-dev/resources@0.0.5",
|
|
21
|
+
"purl": "pkg:npm/@overkill-dev/resources@0.0.5"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"components": [
|
|
25
25
|
{
|
|
26
26
|
"type": "library",
|
|
27
27
|
"name": "@overkill-dev/simulation",
|
|
28
|
-
"version": "0.0.
|
|
29
|
-
"bom-ref": "pkg:npm/@overkill-dev/simulation@0.0.
|
|
28
|
+
"version": "0.0.3",
|
|
29
|
+
"bom-ref": "pkg:npm/@overkill-dev/simulation@0.0.3",
|
|
30
30
|
"scope": "optional",
|
|
31
31
|
"licenses": [
|
|
32
32
|
{
|
|
33
33
|
"expression": "MIT"
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
|
-
"purl": "pkg:npm/@overkill-dev/simulation@0.0.
|
|
36
|
+
"purl": "pkg:npm/@overkill-dev/simulation@0.0.3"
|
|
37
37
|
}
|
|
38
38
|
],
|
|
39
39
|
"dependencies": [
|
|
40
40
|
{
|
|
41
|
-
"ref": "pkg:npm/@overkill-dev/resources@0.0.
|
|
41
|
+
"ref": "pkg:npm/@overkill-dev/resources@0.0.5",
|
|
42
42
|
"dependsOn": [
|
|
43
|
-
"pkg:npm/@overkill-dev/simulation@0.0.
|
|
43
|
+
"pkg:npm/@overkill-dev/simulation@0.0.3"
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
|
-
"ref": "pkg:npm/@overkill-dev/simulation@0.0.
|
|
47
|
+
"ref": "pkg:npm/@overkill-dev/simulation@0.0.3"
|
|
48
48
|
}
|
|
49
49
|
]
|
|
50
50
|
}
|