@overkill-dev/resources 0.0.1 → 0.0.3

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +35 -6
  3. package/packages/resources/resources.entry-point.d.ts +22 -0
  4. package/packages/resources/resources.entry-point.d.ts.map +1 -0
  5. package/packages/resources/resources.entry-point.js +27 -0
  6. package/packages/resources/resources.entry-point.js.map +1 -0
  7. package/readme.md +139 -5
  8. package/resources/local-service-resource.d.ts +55 -0
  9. package/resources/local-service-resource.d.ts.map +1 -0
  10. package/resources/local-service-resource.js +66 -0
  11. package/resources/local-service-resource.js.map +1 -0
  12. package/resources/resource-definition-shape.d.ts +53 -0
  13. package/resources/resource-definition-shape.d.ts.map +1 -0
  14. package/resources/resource-graph.d.ts +23 -0
  15. package/resources/resource-graph.d.ts.map +1 -0
  16. package/resources/resource-graph.js +151 -0
  17. package/resources/resource-graph.js.map +1 -0
  18. package/resources/resource-lifecycle-error.d.ts +19 -0
  19. package/resources/resource-lifecycle-error.d.ts.map +1 -0
  20. package/resources/resource-lifecycle-error.js +32 -0
  21. package/resources/resource-lifecycle-error.js.map +1 -0
  22. package/resources/resource-session.d.ts +28 -0
  23. package/resources/resource-session.d.ts.map +1 -0
  24. package/resources/resource-session.js +182 -0
  25. package/resources/resource-session.js.map +1 -0
  26. package/resources/resources.d.ts +149 -0
  27. package/resources/resources.d.ts.map +1 -0
  28. package/resources/resources.js +99 -0
  29. package/resources/resources.js.map +1 -0
  30. package/resources/runtime-definition.d.ts +23 -0
  31. package/resources/runtime-definition.d.ts.map +1 -0
  32. package/resources/runtime-definition.js +19 -0
  33. package/resources/runtime-definition.js.map +1 -0
  34. package/resources/runtime-lifecycle.d.ts +14 -0
  35. package/resources/runtime-lifecycle.d.ts.map +1 -0
  36. package/resources/runtime-lifecycle.js +83 -0
  37. package/resources/runtime-lifecycle.js.map +1 -0
  38. package/resources/runtime-matrix-definition.d.ts +53 -0
  39. package/resources/runtime-matrix-definition.d.ts.map +1 -0
  40. package/resources/runtime-matrix-definition.js +159 -0
  41. package/resources/runtime-matrix-definition.js.map +1 -0
  42. package/resources/simulated-http-server-resource.d.ts +14 -0
  43. package/resources/simulated-http-server-resource.d.ts.map +1 -0
  44. package/resources/simulated-http-server-resource.js +26 -0
  45. package/resources/simulated-http-server-resource.js.map +1 -0
  46. package/sbom.cdx.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Overkill contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,7 +1,36 @@
1
1
  {
2
- "name": "@overkill-dev/resources",
3
- "version": "0.0.1",
4
- "description": "Placeholder claiming the npm package name \"@overkill-dev/resources\" so a trusted publisher can be configured. See https://github.com/npm/cli/issues/8544.",
5
- "license": "MIT",
6
- "deprecated": "Placeholder published as a workaround so a Trusted Publisher could be configured. See https://github.com/npm/cli/issues/8544."
7
- }
2
+ "author": "Christian Rackerseder <git@echooff.de>",
3
+ "bugs": {
4
+ "url": "https://github.com/enormora/overkill/issues"
5
+ },
6
+ "description": "Typed Overkill resource and runtime descriptors.",
7
+ "engines": {
8
+ "node": "^26.9.0"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./packages/resources/resources.entry-point.js",
13
+ "types": "./packages/resources/resources.entry-point.d.ts"
14
+ }
15
+ },
16
+ "homepage": "https://github.com/enormora/overkill#readme",
17
+ "keywords": [
18
+ "tdd",
19
+ "test",
20
+ "tests"
21
+ ],
22
+ "license": "MIT",
23
+ "name": "@overkill-dev/resources",
24
+ "peerDependencies": {
25
+ "@overkill-dev/simulation": "0.0.2"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/enormora/overkill.git"
30
+ },
31
+ "sideEffects": [
32
+ "./packages/resources/resources.entry-point.js"
33
+ ],
34
+ "type": "module",
35
+ "version": "0.0.3"
36
+ }
@@ -0,0 +1,22 @@
1
+ import { type ResourcesModule } from '../../resources/resources.ts';
2
+ export { defineLocalServiceResource } from '../../resources/local-service-resource.ts';
3
+ export declare const composeRuntimeContext: ResourcesModule['composeRuntimeContext'];
4
+ export declare const composeRuntimes: ResourcesModule['composeRuntimes'];
5
+ export declare const createTemporaryDirectoryResource: ResourcesModule['createTemporaryDirectoryResource'];
6
+ export declare const defineResource: ResourcesModule['defineResource'];
7
+ export declare const defineRuntime: ResourcesModule['defineRuntime'];
8
+ export declare const defineRuntimeMatrix: ResourcesModule['defineRuntimeMatrix'];
9
+ export { createSimulatedHttpServerResource } from '../../resources/simulated-http-server-resource.ts';
10
+ export { isDefinedResource, isDefinedRuntime, isDefinedRuntimeGraph, isDefinedRuntimeMatrix, runtimeGraphLeaves } from '../../resources/resources.ts';
11
+ export { assertPerCaseResourceGraph, assertResourceDependencyScopes } from '../../resources/resource-graph.ts';
12
+ export { startResources } from '../../resources/resource-session.ts';
13
+ export { ResourceLifecycleError } from '../../resources/resource-lifecycle-error.ts';
14
+ export { startRuntime } from '../../resources/runtime-lifecycle.ts';
15
+ 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 { SimulatedHttpServerResource, SimulatedHttpServerResourceOptions } from '../../resources/simulated-http-server-resource.ts';
18
+ export type { RuntimeDefinition as Runtime, RuntimeResourceMap as ResourceMap } from '../../resources/resources.ts';
19
+ export type { ResourceLifecycleFailure, ResourceLifecyclePhase } from '../../resources/resource-lifecycle-error.ts';
20
+ export type { ResourceSession, ResourceSessionDisposalContext, StartResourcesRequest } from '../../resources/resource-session.ts';
21
+ export type { RuntimeSession, RuntimeSessionDisposalContext, StartRuntimeRequest } from '../../resources/runtime-lifecycle.ts';
22
+ //# sourceMappingURL=resources.entry-point.d.ts.map
@@ -0,0 +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,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAYvF,eAAO,MAAM,qBAAqB,EAAE,eAAe,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,mCAAmC,EACtC,MAAM,2CAA2C,CAAC;AACnD,YAAY,EACR,2BAA2B,EAC3B,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"}
@@ -0,0 +1,27 @@
1
+ import { mkdtemp, rm } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { createResourcesModule } from "../../resources/resources.js";
5
+ export { defineLocalServiceResource } from "../../resources/local-service-resource.js";
6
+ const resourcesModule = createResourcesModule({
7
+ temporaryDirectoryPathPrefix: join(tmpdir(), 'overkill-temporary-directory-'),
8
+ async createTemporaryDirectory(pathPrefix) {
9
+ return await mkdtemp(pathPrefix);
10
+ },
11
+ async removeDirectory(path) {
12
+ await rm(path, { force: true, recursive: true });
13
+ }
14
+ });
15
+ export const composeRuntimeContext = resourcesModule.composeRuntimeContext;
16
+ export const composeRuntimes = resourcesModule.composeRuntimes;
17
+ export const createTemporaryDirectoryResource = resourcesModule.createTemporaryDirectoryResource;
18
+ export const defineResource = resourcesModule.defineResource;
19
+ export const defineRuntime = resourcesModule.defineRuntime;
20
+ export const defineRuntimeMatrix = resourcesModule.defineRuntimeMatrix;
21
+ export { createSimulatedHttpServerResource } from "../../resources/simulated-http-server-resource.js";
22
+ export { isDefinedResource, isDefinedRuntime, isDefinedRuntimeGraph, isDefinedRuntimeMatrix, runtimeGraphLeaves } from "../../resources/resources.js";
23
+ export { assertPerCaseResourceGraph, assertResourceDependencyScopes } from "../../resources/resource-graph.js";
24
+ export { startResources } from "../../resources/resource-session.js";
25
+ export { ResourceLifecycleError } from "../../resources/resource-lifecycle-error.js";
26
+ export { startRuntime } from "../../resources/runtime-lifecycle.js";
27
+ //# sourceMappingURL=resources.entry-point.js.map
@@ -0,0 +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,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAEvF,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
@@ -1,7 +1,141 @@
1
- # @overkill-dev/resources
1
+ # `@overkill-dev/resources`
2
2
 
3
- This version is a placeholder published only to claim the npm name `@overkill-dev/resources` so a Trusted Publisher
4
- can subsequently be configured for it. It contains no real package content and is published already
5
- deprecated.
3
+ Typed resource and runtime lifecycle composition for Overkill.
6
4
 
7
- Workaround context: https://github.com/npm/cli/issues/8544
5
+ This package defines resources as values and can start an explicit runtime
6
+ session from them. A resource declares its stable name, lifecycle scope,
7
+ execution requirements, dependencies, acquisition callback, and disposal
8
+ callback.
9
+
10
+ ```ts
11
+ import {
12
+ composeRuntimeContext,
13
+ composeRuntimes,
14
+ createTemporaryDirectoryResource,
15
+ defineResource,
16
+ defineRuntime,
17
+ startResources,
18
+ startRuntime,
19
+ type ResourceContext,
20
+ type RuntimeContext
21
+ } from '@overkill-dev/resources';
22
+
23
+ const database = defineResource({
24
+ name: 'database',
25
+ scope: 'per-case',
26
+ requirements: [ { kind: 'exclusive-resource', name: 'database' } ],
27
+ dependencies: {},
28
+ async acquire(context) {
29
+ context.signal.throwIfAborted();
30
+
31
+ return await openDatabase();
32
+ },
33
+ async dispose(database, _context) {
34
+ await database.close();
35
+ }
36
+ });
37
+
38
+ const server = defineResource({
39
+ name: 'server',
40
+ scope: 'per-case',
41
+ requirements: [],
42
+ dependencies: { database },
43
+ async acquire(context) {
44
+ return await startServer(context.dependencies.database);
45
+ },
46
+ async dispose(server, context) {
47
+ await server.stop(context.dependencies.database);
48
+ }
49
+ });
50
+
51
+ const scratch = createTemporaryDirectoryResource('scratch');
52
+ const sharedDatabase = defineResource({
53
+ name: 'shared-database',
54
+ scope: 'per-run',
55
+ requirements: [ { kind: 'single-worker' } ],
56
+ async acquire(context) {
57
+ context.signal.throwIfAborted();
58
+
59
+ return await openDatabase();
60
+ },
61
+ deserializeHandle(payload) {
62
+ return { url: payload.url };
63
+ },
64
+ async dispose(database) {
65
+ await database.close();
66
+ },
67
+ serializeHandle(database) {
68
+ return { url: database.url };
69
+ }
70
+ });
71
+ const runtime = defineRuntime({
72
+ name: 'api',
73
+ dimensions: {},
74
+ resources: { database, server, scratch },
75
+ requirements: [ { kind: 'startup-budget-milliseconds', minimumMilliseconds: 1000 } ]
76
+ });
77
+
78
+ type ApiContext = RuntimeContext<typeof runtime>;
79
+ type ScratchContext = ResourceContext<{ readonly scratch: typeof scratch; }>;
80
+
81
+ await using session = await startRuntime({ runtime, signal });
82
+
83
+ const scopeWithRuntime = composeRuntimeContext(testScope, runtime, session.context);
84
+ scopeWithRuntime.runtimes.api.database;
85
+
86
+ await using resources = await startResources({ resources: { scratch }, signal });
87
+ resources.context.scratch.path;
88
+ ```
89
+
90
+ `RuntimeContext` uses the keys from the runtime's `resources` object. Resource
91
+ `name` remains the stable identity used by reporters, artifacts, and future
92
+ scheduling work.
93
+
94
+ `composeRuntimeContext(...)` exposes acquired handles under
95
+ `scope.runtimes.<runtimeName>`, such as `scope.runtimes.api`.
96
+ `composeRuntimes(...)` combines leaf runtimes and runtime matrices into one
97
+ graph while exposing each child under its own public runtime name.
98
+
99
+ Dependency context uses the keys from the resource's `dependencies` object.
100
+ Omitting `dependencies` is accepted for compatibility and produces
101
+ `dependencies: {}` on the returned descriptor.
102
+
103
+ `createTemporaryDirectoryResource(name)` returns a per-case resource descriptor
104
+ whose handle is `{ readonly path: string }`. Each acquisition creates a unique
105
+ directory with an Overkill prefix. Disposal removes that directory recursively.
106
+
107
+ `defineLocalServiceResource(...)` wraps `defineResource(...)` for owned local
108
+ services. Callers declare scope, requirements, startup, and disposal. Startup
109
+ receives an address request with default `host: '127.0.0.1'` and `port: 0`.
110
+ Credentials, connection strings, and protocol-specific data stay in the typed
111
+ service handle. Projected scopes use the same serialize and deserialize rules
112
+ as ordinary resources.
113
+
114
+ `createSimulatedHttpServerResource({ simulation })` starts a simulated HTTP
115
+ server from `@overkill-dev/simulation` as a per-case resource. The acquired
116
+ handle exposes `baseUrl` for the `default` scenario and `scenarioUrl(...)` for
117
+ URL-selected scenarios.
118
+
119
+ `startRuntime(...)` acquires dependencies before dependents, shares one handle
120
+ per descriptor inside the session, and disposes acquired resources once in
121
+ reverse dependency order. Independent ready resources may acquire concurrently.
122
+
123
+ `startResources(...)` starts a direct resource session without wrapping the
124
+ handles in a runtime name. It uses the keys from the provided resource map and
125
+ the same acquisition, sharing, and disposal behavior as `startRuntime(...)`.
126
+
127
+ The package-level session API starts one explicit session and therefore shares
128
+ one handle per descriptor inside that session. Runner-managed wrappers in
129
+ `@overkill-dev/test/resources` interpret `scope` as `per-run`, `per-file`,
130
+ `per-suite`, `per-case`, or `shared-per-worker` lifetime boundaries.
131
+
132
+ `per-run` resources must define `serializeHandle(...)` and
133
+ `deserializeHandle(...)` so runner-owned resources can be projected into
134
+ consumer execution contexts. `per-file` and `per-suite` resources may also
135
+ define projection hooks when their owner handle is not the same value that
136
+ test code should consume. `per-case` and `shared-per-worker` resources are
137
+ local to their execution owner and do not use projection hooks.
138
+
139
+ Execution requirements describe placement pressure for the runner:
140
+ `serial`, `single-worker`, `exclusive-resource`, `capacity-weight`,
141
+ `affinity-key`, `fault-domain`, and `startup-budget-milliseconds`.
@@ -0,0 +1,55 @@
1
+ import { type Awaitable, type EmptyResourceDependencies, type ExecutionRequirement, type ResourceContext, type ResourceDefinition, type ResourceDependencies, type ResourceDisposalContext, type ResourceProjectionContext, type ResourceProjectionPayload, type ResourceScope } from './resources.ts';
2
+ import type { ValueOf } from './resource-definition-shape.ts';
3
+ export type LocalServiceAddress = {
4
+ readonly host: string;
5
+ readonly port: number;
6
+ };
7
+ export type LocalServiceCreationContext<Dependencies extends ResourceDependencies = EmptyResourceDependencies> = {
8
+ readonly address: LocalServiceAddress;
9
+ readonly dependencies: ResourceContext<Dependencies>;
10
+ readonly signal: AbortSignal;
11
+ };
12
+ type ProjectedLocalServiceScope = 'per-file' | 'per-run' | 'per-suite';
13
+ type ProjectedBase<Name extends string, OwnerHandle, Projection extends ResourceProjectionPayload, ConsumerHandle, Scope extends ProjectedLocalServiceScope, Dependencies extends ResourceDependencies> = ProjectedLocalServiceResourceDefinitionInput<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>;
14
+ type ProjectedServiceWithDependencies<Name extends string, OwnerHandle, Projection extends ResourceProjectionPayload, ConsumerHandle, Scope extends ProjectedLocalServiceScope, Dependencies extends ResourceDependencies> = {
15
+ 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
+ readonly name: Name;
20
+ readonly port?: number;
21
+ readonly requirements: readonly ExecutionRequirement[];
22
+ readonly scope: Scope;
23
+ readonly serializeHandle: ProjectedBase<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>['serializeHandle'];
24
+ readonly start: ProjectedBase<Name, OwnerHandle, Projection, ConsumerHandle, Scope, Dependencies>['start'];
25
+ };
26
+ type LocalServiceResourceDefinitionBaseInput<Name extends string, Handle, Scope extends ResourceScope, Dependencies extends ResourceDependencies = EmptyResourceDependencies> = {
27
+ readonly dependencies?: Dependencies;
28
+ readonly dispose: (handle: Handle, context: ResourceDisposalContext<Dependencies>) => Awaitable<void>;
29
+ readonly host?: string;
30
+ readonly name: Name;
31
+ readonly port?: number;
32
+ readonly requirements: readonly ExecutionRequirement[];
33
+ readonly scope: Scope;
34
+ readonly start: (context: LocalServiceCreationContext<Dependencies>) => Awaitable<Handle>;
35
+ };
36
+ type LocalOnlyLocalServiceResourceDefinitionInput<Name extends string, Handle, Scope extends ResourceScope, Dependencies extends ResourceDependencies = EmptyResourceDependencies> = LocalServiceResourceDefinitionBaseInput<Name, Handle, Scope, Dependencies> & {
37
+ readonly deserializeHandle?: never;
38
+ readonly serializeHandle?: never;
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>;
47
+ }>;
48
+ export declare function defineLocalServiceResource<const Name extends string, Handle, Scope extends Exclude<ResourceScope, 'per-run'>>(definition: LocalOnlyLocalServiceResourceDefinitionInput<Name, Handle, Scope>): ResourceDefinition<Name, Handle, EmptyResourceDependencies>;
49
+ export declare function defineLocalServiceResource<const Name extends string, OwnerHandle, Projection extends ResourceProjectionPayload, ConsumerHandle, Scope extends ProjectedLocalServiceScope>(definition: ProjectedLocalServiceResourceDefinitionInput<Name, OwnerHandle, Projection, ConsumerHandle, Scope>): ResourceDefinition<Name, OwnerHandle, EmptyResourceDependencies, ConsumerHandle>;
50
+ export declare function defineLocalServiceResource<const Name extends string, Handle, Scope extends Exclude<ResourceScope, 'per-run'>, const Dependencies extends ResourceDependencies>(definition: LocalOnlyLocalServiceResourceDefinitionInput<Name, Handle, Scope, Dependencies> & {
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>;
54
+ export {};
55
+ //# sourceMappingURL=local-service-resource.d.ts.map
@@ -0,0 +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,oBAAoB,EAEzB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,2BAA2B,CAAC,YAAY,SAAS,oBAAoB,GAAG,yBAAyB,IAAI;IAC7G,QA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AAI,SAAS,MAAM,EACzB,WAAW,EACX,UAAU,SAAS,yBAAyB,EAC5C,cAAc,EACd,KAAK,SAAS,0BAA0B,EAExC,UAAU,EAAE,4CAA4C,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,CAAC,GAC/G,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,yBAAyB,EAAE,cAAc,CAAC,CAAC;AACpF,wBAAgB,0BAA0B,CACtC,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,MAAM,EACN,KAAK,SAAS,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,EAC/C,KAAK,CAAC,YAAY,SAAS,oBAAoB,EAE/C,UAAU,EAAE,4CAA4C,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,GAAG;IAC1F,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACvC,GACF,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AAClD,wBAAgB,0BAA0B,CACtC,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,WAAW,EACX,UAAU,SAAS,yBAAyB,EAC5C,cAAc,EACd,KAAK,SAAS,0BAA0B,EACxC,KAAK,CAAC,YAAY,SAAS,oBAAoB,EAE/C,UAAU,EAAE,gCAAgC,CACxC,IAAI,EACJ,WAAW,EACX,UAAU,EACV,cAAc,EACd,KAAK,EACL,YAAY,CACf,GACF,kBAAkB,CAAC,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { defineResource } from "./resources.js";
2
+ function localServiceAddress(host, port) {
3
+ return Object.freeze({
4
+ host: host ?? '127.0.0.1',
5
+ port: port ?? 0
6
+ });
7
+ }
8
+ function localServiceAcquire(definition, address) {
9
+ return async function startLocalService(context) {
10
+ return definition.start(Object.freeze({
11
+ ...context,
12
+ address
13
+ }));
14
+ };
15
+ }
16
+ function hasDependencies(definition) {
17
+ return definition.dependencies !== undefined;
18
+ }
19
+ function isProjectedLocalService(definition) {
20
+ return Object.hasOwn(definition, 'serializeHandle') && Object.hasOwn(definition, 'deserializeHandle');
21
+ }
22
+ export function defineLocalServiceResource(definition) {
23
+ const address = localServiceAddress(definition.host, definition.port);
24
+ const acquire = localServiceAcquire(definition, address);
25
+ 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
+ return defineResource({
39
+ name: definition.name,
40
+ scope: definition.scope,
41
+ requirements: definition.requirements,
42
+ acquire,
43
+ dispose: definition.dispose,
44
+ serializeHandle: definition.serializeHandle,
45
+ deserializeHandle: definition.deserializeHandle
46
+ });
47
+ }
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
+ return defineResource({
59
+ name: definition.name,
60
+ scope: definition.scope,
61
+ requirements: definition.requirements,
62
+ acquire,
63
+ dispose: definition.dispose
64
+ });
65
+ }
66
+ //# 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,EAYjB,MAAM,gBAAgB,CAAC;AAyIxB,SAAS,mBAAmB,CAAC,IAAwB,EAAE,IAAwB;IAC3E,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,IAAI,IAAI,WAAW;QACzB,IAAI,EAAE,IAAI,IAAI,CAAC;KAClB,CAAC,CAAC;AACP,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,KAAK;YACvB,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,OAAO;YACP,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,eAAe,EAAE,UAAU,CAAC,eAAe;YAC3C,iBAAiB,EAAE,UAAU,CAAC,iBAAiB;SAClD,CAAC,CAAC;IACP,CAAC;IAED,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC;YAClB,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,KAAK,EAAE,UAAU,CAAC,KAAK;YACvB,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,OAAO;YACP,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,YAAY,EAAE,UAAU,CAAC,YAAY;SACxC,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,OAAO;QACP,OAAO,EAAE,UAAU,CAAC,OAAO;KAC9B,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,53 @@
1
+ export type Awaitable<Value> = Promise<Value> | Value;
2
+ export type ValueOf<Values> = Values[keyof Values];
3
+ type ExclusiveResource = {
4
+ readonly kind: 'exclusive-resource';
5
+ readonly name: string;
6
+ };
7
+ type SerialExecution = {
8
+ readonly kind: 'serial';
9
+ };
10
+ type SingleWorkerExecution = {
11
+ readonly kind: 'single-worker';
12
+ };
13
+ type StartupBudget = {
14
+ readonly kind: 'startup-budget-milliseconds';
15
+ readonly minimumMilliseconds: number;
16
+ };
17
+ type CapacityWeight = {
18
+ readonly kind: 'capacity-weight';
19
+ readonly weight: number;
20
+ };
21
+ type AffinityKey = {
22
+ readonly key: string;
23
+ readonly kind: 'affinity-key';
24
+ };
25
+ type FaultDomain = {
26
+ readonly key: string;
27
+ readonly kind: 'fault-domain';
28
+ };
29
+ type PlacementRequirement = AffinityKey | CapacityWeight | ExclusiveResource | FaultDomain;
30
+ type SchedulingRequirement = SerialExecution | SingleWorkerExecution | StartupBudget;
31
+ export type ExecutionRequirement = PlacementRequirement | SchedulingRequirement;
32
+ export type ResourceScope = 'per-case' | 'per-file' | 'per-run' | 'per-suite' | 'shared-per-worker';
33
+ export type AnyResourceDefinition = {
34
+ readonly acquire: (context: never) => Awaitable<unknown>;
35
+ readonly dependencies: ResourceDependencies;
36
+ readonly deserializeHandle?: (payload: never, context: never) => unknown;
37
+ readonly dispose: ((handle: never, context: never) => Awaitable<void>) | null;
38
+ readonly name: string;
39
+ readonly requirements: readonly ExecutionRequirement[];
40
+ readonly scope: ResourceScope;
41
+ readonly serializeHandle?: (handle: never, context: never) => ResourceProjectionPayload;
42
+ };
43
+ export type RuntimeResourceMap = Readonly<Record<string, AnyResourceDefinition>>;
44
+ export type EmptyResourceDependencies = Readonly<Record<PropertyKey, never>>;
45
+ export type ResourceDependencies = Readonly<Record<string, AnyResourceDefinition>>;
46
+ type ResourceProjectionObject = {
47
+ readonly [key: string]: ResourceProjectionPayload;
48
+ };
49
+ type ResourceProjectionScalar = boolean | number | string | null;
50
+ type ResourceProjectionCollection = ResourceProjectionObject | readonly ResourceProjectionPayload[];
51
+ export type ResourceProjectionPayload = ResourceProjectionCollection | ResourceProjectionScalar;
52
+ export {};
53
+ //# sourceMappingURL=resource-definition-shape.d.ts.map
@@ -0,0 +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,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,IA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AAO,EAAE,KAAK,KAAK,OAAO,CAAC;IACzE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,YAAY,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACvD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,KAAK,yBAAyB,CAAC;CAC3F,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;AACjF,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7E,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAEnF,KAAK,wBAAwB,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,yBAAyB,CAAC;CAAE,CAAC;AACvF,KAAK,wBAAwB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AACjE,KAAK,4BAA4B,GAAG,wBAAwB,GAAG,SAAS,yBAAyB,EAAE,CAAC;AACpG,MAAM,MAAM,yBAAyB,GAAG,4BAA4B,GAAG,wBAAwB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type AnyResourceDefinition, type Awaitable, type ResourceCreationContext, type ResourceDependencies, type ResourceDisposalContext } from './resources.ts';
2
+ export type ResourceEntry = readonly [string, AnyResourceDefinition];
3
+ export type ResourceNode = {
4
+ readonly dependencies: readonly ResourceNode[];
5
+ readonly descriptor: AnyResourceDefinition;
6
+ };
7
+ export type ResourceGraph = {
8
+ readonly order: readonly ResourceNode[];
9
+ readonly topLevelEntries: readonly ResourceEntry[];
10
+ };
11
+ type DependencyDisposalContext = ResourceDisposalContext<ResourceDependencies>;
12
+ export type ResourceDisposeCallback = (handle: unknown, context: DependencyDisposalContext) => Awaitable<void>;
13
+ export type CallableResourceDefinition = AnyResourceDefinition & {
14
+ readonly acquire: (context: ResourceCreationContext<ResourceDependencies>) => Awaitable<unknown>;
15
+ readonly dispose: ResourceDisposeCallback | null;
16
+ };
17
+ export declare function resourceEntries(resources: ResourceDependencies): readonly ResourceEntry[];
18
+ export declare function callableResourceDefinition(resource: AnyResourceDefinition): CallableResourceDefinition;
19
+ export declare function createResourceGraph(resources: ResourceDependencies): ResourceGraph;
20
+ export declare function assertPerCaseResourceGraph(resources: ResourceDependencies): void;
21
+ export declare function assertResourceDependencyScopes(resources: ResourceDependencies): void;
22
+ export {};
23
+ //# sourceMappingURL=resource-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-graph.d.ts","sourceRoot":"","sources":["../../../../source/resources/resource-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EAEd,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAE/B,MAAM,gBAAgB,CAAC;AAaxB,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AACrE,MAAM,MAAM,YAAY,GAAG;IACvB,QAAQ,CAAC,YAAY,EAAE,SAAS,YAAY,EAAE,CAAC;IAC/C,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;CAC9C,CAAC;AACF,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,QAAQ,CAAC,eAAe,EAAE,SAAS,aAAa,EAAE,CAAC;CACtD,CAAC;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