@overkill-dev/resources 0.0.2 → 0.0.4

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 CHANGED
@@ -21,13 +21,17 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "name": "@overkill-dev/resources",
24
+ "peerDependencies": {
25
+ "@overkill-dev/simulation": "0.0.3"
26
+ },
24
27
  "repository": {
25
28
  "type": "git",
26
29
  "url": "git+https://github.com/enormora/overkill.git"
27
30
  },
28
31
  "sideEffects": [
29
- "./packages/resources/resources.entry-point.js"
32
+ "./packages/resources/resources.entry-point.js",
33
+ "./resources/local-service-resource.js"
30
34
  ],
31
35
  "type": "module",
32
- "version": "0.0.2"
36
+ "version": "0.0.4"
33
37
  }
@@ -1,16 +1,24 @@
1
1
  import { type ResourcesModule } from '../../resources/resources.ts';
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';
2
5
  export declare const composeRuntimeContext: ResourcesModule['composeRuntimeContext'];
3
6
  export declare const composeRuntimes: ResourcesModule['composeRuntimes'];
4
7
  export declare const createTemporaryDirectoryResource: ResourcesModule['createTemporaryDirectoryResource'];
5
8
  export declare const defineResource: ResourcesModule['defineResource'];
6
9
  export declare const defineRuntime: ResourcesModule['defineRuntime'];
7
10
  export declare const defineRuntimeMatrix: ResourcesModule['defineRuntimeMatrix'];
11
+ export { createSimulatedHttpServerResource } from '../../resources/simulated-http-server-resource.ts';
8
12
  export { isDefinedResource, isDefinedRuntime, isDefinedRuntimeGraph, isDefinedRuntimeMatrix, runtimeGraphLeaves } from '../../resources/resources.ts';
9
13
  export { assertPerCaseResourceGraph, assertResourceDependencyScopes } from '../../resources/resource-graph.ts';
10
14
  export { startResources } from '../../resources/resource-session.ts';
11
15
  export { ResourceLifecycleError } from '../../resources/resource-lifecycle-error.ts';
12
16
  export { startRuntime } from '../../resources/runtime-lifecycle.ts';
13
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';
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';
14
22
  export type { RuntimeDefinition as Runtime, RuntimeResourceMap as ResourceMap } from '../../resources/resources.ts';
15
23
  export type { ResourceLifecycleFailure, ResourceLifecyclePhase } from '../../resources/resource-lifecycle-error.ts';
16
24
  export type { ResourceSession, ResourceSessionDisposalContext, StartResourcesRequest } from '../../resources/resource-session.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"resources.entry-point.d.ts","sourceRoot":"","sources":["../../../../../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wBAAwB,EAC3B,MAAM,8BAA8B,CAAC;AACtC,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"}
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,EAAE,eAAe,CAAC,uBAAuB,CAAyC,CAAC;AACrH,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,iBAAiB,CAAmC,CAAC;AACnG,eAAO,MAAM,gCAAgC,EAAE,eAAe,CAAC,kCAAkC,CAC7C,CAAC;AACrD,eAAO,MAAM,cAAc,EAAE,eAAe,CAAC,gBAAgB,CAAkC,CAAC;AAChG,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,eAAe,CAAiC,CAAC;AAC7F,eAAO,MAAM,mBAAmB,EAAE,eAAe,CAAC,qBAAqB,CAAuC,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,0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B,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"}
@@ -2,6 +2,9 @@ import { mkdtemp, rm } from 'node:fs/promises';
2
2
  import { tmpdir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { createResourcesModule } from "../../resources/resources.js";
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";
5
8
  const resourcesModule = createResourcesModule({
6
9
  temporaryDirectoryPathPrefix: join(tmpdir(), 'overkill-temporary-directory-'),
7
10
  async createTemporaryDirectory(pathPrefix) {
@@ -17,6 +20,7 @@ export const createTemporaryDirectoryResource = resourcesModule.createTemporaryD
17
20
  export const defineResource = resourcesModule.defineResource;
18
21
  export const defineRuntime = resourcesModule.defineRuntime;
19
22
  export const defineRuntimeMatrix = resourcesModule.defineRuntimeMatrix;
23
+ export { createSimulatedHttpServerResource } from "../../resources/simulated-http-server-resource.js";
20
24
  export { isDefinedResource, isDefinedRuntime, isDefinedRuntimeGraph, isDefinedRuntimeMatrix, runtimeGraphLeaves } from "../../resources/resources.js";
21
25
  export { assertPerCaseResourceGraph, assertResourceDependencyScopes } from "../../resources/resource-graph.js";
22
26
  export { startResources } from "../../resources/resource-session.js";
@@ -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,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,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"}
1
+ {"version":3,"file":"resources.entry-point.js","sourceRoot":"","sources":["../../../../../source/packages/resources/resources.entry-point.ts"],"names":[],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B,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,6 +122,28 @@ 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
 
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.
146
+
107
147
  `startRuntime(...)` acquires dependencies before dependents, shares one handle
108
148
  per descriptor inside the session, and disposes acquired resources once in
109
149
  reverse dependency order. Independent ready resources may acquire concurrently.
@@ -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,2BAA2B,EAChC,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EAExB,KAAK,0BAA0B,EAClC,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,sBAAsB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,sBAAsB,GAAG,MAAM,GAAG,IAAI,CAAC;IAC/D,QAA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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,MAA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,KAAK,CAAC,eAAe;QACtC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;KAC7C,CAAC;AACN,CAAC;AAED,SAAS,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,OAAO,EAGH,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAEhC,KAAK,4BAA4B,EAEjC,KAAK,0BAA0B,EAClC,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,wBAAwB,GAAG;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,UAAU,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CA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'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,CAAC;QACD,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YAClB,KAAK;gBACD,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC;YACD,IAAI;gBACA,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC;SACJ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IACzE,CAAC;IAED,OAAO,0BAA0B,CAAC;QAC9B,GAAG,sBAAsB,CAAC,KAAK,CAAC;QAChC,KAAK,EAAE,KAAK,CAAC,KAAK;KACrB,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { type Awaitable, type EmptyResourceDependencies, type ExecutionRequirement, type ResourceContext, type ResourceDefinition, type ResourceDependencies, type ResourceProjectionContext, type ResourceProjectionPayload, type ResourceScope } from './resources.ts';
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;
13
+ export type LocalServiceAddress = {
14
+ readonly host: string;
15
+ readonly port: number;
16
+ };
17
+ export type LocalServiceCreationContext<Dependencies extends ResourceDependencies = EmptyResourceDependencies> = {
18
+ readonly address: LocalServiceAddress;
19
+ readonly dependencies: ResourceContext<Dependencies>;
20
+ readonly signal: AbortSignal;
21
+ };
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;
38
+ readonly dependencies: Dependencies;
39
+ readonly name: Name;
40
+ readonly ready: (owner: OwnerHandle, context: LocalServiceCreationContext<Dependencies>) => Awaitable<ConsumerHandle>;
41
+ readonly requirements: readonly ExecutionRequirement[];
42
+ readonly scope: Scope;
43
+ readonly start: (context: LocalServiceCreationContext<Dependencies>) => Awaitable<OwnerHandle>;
44
+ };
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'];
51
+ readonly name: Name;
52
+ readonly ready: (owner: OwnerHandle, context: LocalServiceCreationContext<Dependencies>) => Awaitable<ConsumerHandle>;
53
+ readonly requirements: readonly ExecutionRequirement[];
54
+ readonly scope: Scope;
55
+ readonly serializeHandle: LocalServiceHandleProjection<ConsumerHandle, Projection, ProjectedConsumerHandle, Dependencies>['serializeHandle'];
56
+ readonly start: (context: LocalServiceCreationContext<Dependencies>) => Awaitable<OwnerHandle>;
57
+ };
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>;
61
+ }>;
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>;
65
+ export {};
66
+ //# sourceMappingURL=local-service-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3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AAc,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"}
@@ -0,0 +1,122 @@
1
+ import { defineResource } from "./resources.js";
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) {
43
+ return Object.freeze({
44
+ ...context,
45
+ address
46
+ });
47
+ }
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) {
62
+ return async function startLocalService(context) {
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
+ }
77
+ };
78
+ }
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
+ };
92
+ }
93
+ function isProjectedLocalService(definition) {
94
+ return Object.hasOwn(definition, 'serializeHandle') && Object.hasOwn(definition, 'deserializeHandle');
95
+ }
96
+ export function defineLocalServiceResource(definition) {
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);
101
+ if (isProjectedLocalService(definition)) {
102
+ return defineResource({
103
+ name: definition.name,
104
+ scope: definition.scope,
105
+ requirements: definition.requirements,
106
+ dependencies: definition.dependencies,
107
+ acquire,
108
+ dispose,
109
+ serializeHandle: definition.serializeHandle,
110
+ deserializeHandle: definition.deserializeHandle
111
+ });
112
+ }
113
+ return defineResource({
114
+ name: definition.name,
115
+ scope: definition.scope,
116
+ requirements: definition.requirements,
117
+ dependencies: definition.dependencies,
118
+ acquire,
119
+ dispose
120
+ });
121
+ }
122
+ //# sourceMappingURL=local-service-resource.js.map
@@ -0,0 +1 @@
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,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI;QAC9D,IAAI,EAAE,OAAO,CAAC,IAAI;KACrB,CAAC,CAAC;AACP,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAAoB;IAC7D,OAAO,CAAE,UAAU,EAAE,SAAS,EAAE,WAAW,CAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,qBAAqB;IAC1B,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAEzC,OAAO,UAAU,CAAC,MAAM,CAAC;AAC7B,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAc,EAAE,YAAqB;IACjE,OAAO,EA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ResourceDependencies, ResourceDefinition } from './resources.ts';
3
+ import { type LocalHttpServiceHandle } from './local-http-service-resource.ts';
4
+ import type { LocalServiceAddressRequest } from './local-service-resource.ts';
5
+ export type SimulatedHttpServerResourceOptions<Name extends string, Scenarios extends SimulationScenarioCatalog> = {
6
+ readonly address: LocalServiceAddressRequest;
7
+ readonly simulation: SimulatedHttpServerDefinition<Name, Scenarios>;
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
+ };
16
+ export type SimulatedHttpServerResource<Simulation extends {
17
+ readonly name: string;
18
+ readonly scenarios: SimulationScenarioCatalog;
19
+ }> = ResourceDefinition<Simulation['name'], SimulatedHttpServerResourceHandle<Simulation>, EmptyResourceDependencies>;
20
+ export declare function createSimulatedHttpServerResource<const Name extends string, const Scenarios extends SimulationScenarioCatalog>(options: SimulatedHttpServerResourceOptions<Name, Scenarios>): SimulatedHttpServerResource<SimulatedHttpServerDefinition<Name, Scenarios>>;
21
+ //# sourceMappingURL=simulated-http-server-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulated-http-server-resource.d.ts","sourceRoot":"","sources":["../../../../source/resources/simulated-http-server-resource.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACR,6BAA6B,EAC7B,yBAAyB,EAC5B,MAAM,0BAA6B,CAAC;AACrC,OAAO,KAAK,EACR,yBAAyB,EACzB,kBAAkB,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGH,KAAK,sBAAsB,EAC9B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EACR,0BAA0B,EAC7B,MAAM,6BAA6B,CAAC;AAErC,MAAM,MAAM,kCAAkC,CAC1C,IAAI,SAAS,MAAM,EACnB,SAAS,SAAS,yBAAyB,IAC3C;IACA,QAAQ,CAAC,OAAO,EAAE,0BAA0B,CAAC;IAC7C,QAAQ,CAAC,UAAU,EAAE,6BAA6B,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;CACvE,CAAC;AAEF,MAAM,MAAM,iCAAiC,CACzC,UAAU,SAAS;IACf,QAAQ,CAAC,SAAS,EAAE,yBAAyB,CAAC;CACjD,IACD;IACA,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC,UAAU,CAAC,CAAC;IACtD,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACpG,CAAC;AAEF,MAAM,MAAM,2BAA2B,CACnC,UAAU,SAAS;IACf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,yBAAyB,CAAC;CACjD,IACD,kBAAkB,CAClB,UAAU,CAAC,MAAM,CAAC,EAClB,iCAAiC,CAAC,UAAU,CAAC,EAC7C,yBAAyB,CAC5B,CAAC;AA4BF,wBAAgB,iCAAiC,CAC7C,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,KAAK,CAAC,SAAS,SAAS,yBAAyB,EAEjD,OAAO,EAAE,kCAAkC,CAAC,IAAI,EAAE,SAAS,CAAC,GAC7D,2BAA2B,CAAC,6BAA6B,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAyB7E"}
@@ -0,0 +1,38 @@
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
+ }
18
+ export function createSimulatedHttpServerResource(options) {
19
+ const handlerErrors = new WeakMap();
20
+ return createLocalHttpServiceResource({
21
+ name: options.simulation.name,
22
+ scope: 'per-case',
23
+ requirements: [],
24
+ dependencies: {},
25
+ address: options.address,
26
+ createServer(context) {
27
+ context.signal.throwIfAborted();
28
+ const listeningServer = createSimulatedHttpListeningServer(options.simulation, context.address.host);
29
+ handlerErrors.set(listeningServer.server, listeningServer.errors);
30
+ return listeningServer.server;
31
+ },
32
+ handle: (simulatedHttpServerResourceHandle),
33
+ dispose(server) {
34
+ assertNoSimulatedHttpHandlerErrors(handlerErrors.get(server) ?? []);
35
+ }
36
+ });
37
+ }
38
+ //# sourceMappingURL=simulated-http-server-resource.js.map
@@ -0,0 +1 @@
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,15 +16,35 @@
16
16
  "component": {
17
17
  "type": "library",
18
18
  "name": "@overkill-dev/resources",
19
- "version": "0.0.2",
20
- "bom-ref": "pkg:npm/@overkill-dev/resources@0.0.2",
21
- "purl": "pkg:npm/@overkill-dev/resources@0.0.2"
19
+ "version": "0.0.4",
20
+ "bom-ref": "pkg:npm/@overkill-dev/resources@0.0.4",
21
+ "purl": "pkg:npm/@overkill-dev/resources@0.0.4"
22
22
  }
23
23
  },
24
- "components": [],
24
+ "components": [
25
+ {
26
+ "type": "library",
27
+ "name": "@overkill-dev/simulation",
28
+ "version": "0.0.3",
29
+ "bom-ref": "pkg:npm/@overkill-dev/simulation@0.0.3",
30
+ "scope": "optional",
31
+ "licenses": [
32
+ {
33
+ "expression": "MIT"
34
+ }
35
+ ],
36
+ "purl": "pkg:npm/@overkill-dev/simulation@0.0.3"
37
+ }
38
+ ],
25
39
  "dependencies": [
26
40
  {
27
- "ref": "pkg:npm/@overkill-dev/resources@0.0.2"
41
+ "ref": "pkg:npm/@overkill-dev/resources@0.0.4",
42
+ "dependsOn": [
43
+ "pkg:npm/@overkill-dev/simulation@0.0.3"
44
+ ]
45
+ },
46
+ {
47
+ "ref": "pkg:npm/@overkill-dev/simulation@0.0.3"
28
48
  }
29
49
  ]
30
50
  }