@livestore/utils-dev 0.4.0-dev.2 → 0.4.0-dev.20

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 (73) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/node/DockerComposeService/DockerComposeService.d.ts +58 -0
  3. package/dist/node/DockerComposeService/DockerComposeService.d.ts.map +1 -0
  4. package/dist/node/DockerComposeService/DockerComposeService.js +144 -0
  5. package/dist/node/DockerComposeService/DockerComposeService.js.map +1 -0
  6. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts +2 -0
  7. package/dist/node/DockerComposeService/DockerComposeService.test.d.ts.map +1 -0
  8. package/dist/node/DockerComposeService/DockerComposeService.test.js +64 -0
  9. package/dist/node/DockerComposeService/DockerComposeService.test.js.map +1 -0
  10. package/dist/node/cmd-log.d.ts +21 -0
  11. package/dist/node/cmd-log.d.ts.map +1 -0
  12. package/dist/node/cmd-log.js +47 -0
  13. package/dist/node/cmd-log.js.map +1 -0
  14. package/dist/node/cmd.d.ts +35 -0
  15. package/dist/node/cmd.d.ts.map +1 -0
  16. package/dist/node/cmd.js +235 -0
  17. package/dist/node/cmd.js.map +1 -0
  18. package/dist/node/cmd.test.d.ts +2 -0
  19. package/dist/node/cmd.test.d.ts.map +1 -0
  20. package/dist/node/cmd.test.js +102 -0
  21. package/dist/node/cmd.test.js.map +1 -0
  22. package/dist/node/mod.d.ts +5 -26
  23. package/dist/node/mod.d.ts.map +1 -1
  24. package/dist/node/mod.js +52 -59
  25. package/dist/node/mod.js.map +1 -1
  26. package/dist/node/workspace.d.ts +22 -0
  27. package/dist/node/workspace.d.ts.map +1 -0
  28. package/dist/node/workspace.js +26 -0
  29. package/dist/node/workspace.js.map +1 -0
  30. package/dist/node-vitest/Vitest.d.ts +41 -7
  31. package/dist/node-vitest/Vitest.d.ts.map +1 -1
  32. package/dist/node-vitest/Vitest.js +82 -5
  33. package/dist/node-vitest/Vitest.js.map +1 -1
  34. package/dist/node-vitest/Vitest.test.d.ts +2 -0
  35. package/dist/node-vitest/Vitest.test.d.ts.map +1 -0
  36. package/dist/node-vitest/Vitest.test.js +70 -0
  37. package/dist/node-vitest/Vitest.test.js.map +1 -0
  38. package/dist/wrangler/WranglerDevServer.d.ts +69 -0
  39. package/dist/wrangler/WranglerDevServer.d.ts.map +1 -0
  40. package/dist/wrangler/WranglerDevServer.js +103 -0
  41. package/dist/wrangler/WranglerDevServer.js.map +1 -0
  42. package/dist/wrangler/WranglerDevServer.test.d.ts +2 -0
  43. package/dist/wrangler/WranglerDevServer.test.d.ts.map +1 -0
  44. package/dist/wrangler/WranglerDevServer.test.js +77 -0
  45. package/dist/wrangler/WranglerDevServer.test.js.map +1 -0
  46. package/dist/wrangler/fixtures/cf-worker.d.ts +8 -0
  47. package/dist/wrangler/fixtures/cf-worker.d.ts.map +1 -0
  48. package/dist/wrangler/fixtures/cf-worker.js +11 -0
  49. package/dist/wrangler/fixtures/cf-worker.js.map +1 -0
  50. package/dist/wrangler/mod.d.ts +2 -0
  51. package/dist/wrangler/mod.d.ts.map +1 -0
  52. package/dist/wrangler/mod.js +2 -0
  53. package/dist/wrangler/mod.js.map +1 -0
  54. package/package.json +11 -10
  55. package/src/node/DockerComposeService/DockerComposeService.test.ts +91 -0
  56. package/src/node/DockerComposeService/DockerComposeService.ts +328 -0
  57. package/src/node/DockerComposeService/test-fixtures/docker-compose.yml +4 -0
  58. package/src/node/cmd-log.ts +87 -0
  59. package/src/node/cmd.test.ts +130 -0
  60. package/src/node/cmd.ts +420 -0
  61. package/src/node/mod.ts +63 -116
  62. package/src/node/workspace.ts +45 -0
  63. package/src/node-vitest/Vitest.test.ts +112 -0
  64. package/src/node-vitest/Vitest.ts +193 -17
  65. package/src/wrangler/WranglerDevServer.test.ts +133 -0
  66. package/src/wrangler/WranglerDevServer.ts +220 -0
  67. package/src/wrangler/fixtures/cf-worker.ts +11 -0
  68. package/src/wrangler/fixtures/wrangler.toml +11 -0
  69. package/src/wrangler/mod.ts +6 -0
  70. package/dist/node-vitest/polyfill.d.ts +0 -2
  71. package/dist/node-vitest/polyfill.d.ts.map +0 -1
  72. package/dist/node-vitest/polyfill.js +0 -3
  73. package/dist/node-vitest/polyfill.js.map +0 -1
@@ -0,0 +1,77 @@
1
+ import { Effect, FetchHttpClient, Layer } from '@livestore/utils/effect';
2
+ import { getFreePort, PlatformNode } from '@livestore/utils/node';
3
+ import { Vitest } from '@livestore/utils-dev/node-vitest';
4
+ import { expect } from 'vitest';
5
+ import { WranglerDevServerError, WranglerDevServerService, } from "./WranglerDevServer.js";
6
+ const testTimeout = 60_000;
7
+ const WranglerDevServerTest = (args = {}) => WranglerDevServerService.Default({
8
+ cwd: `${import.meta.dirname}/fixtures`,
9
+ ...args,
10
+ }).pipe(Layer.provide(FetchHttpClient.layer));
11
+ Vitest.describe('WranglerDevServer', { timeout: testTimeout }, () => {
12
+ Vitest.describe('Basic Operations', () => {
13
+ const withBasicTest = (args = {}) => Vitest.makeWithTestCtx({
14
+ timeout: testTimeout,
15
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
16
+ });
17
+ Vitest.scopedLive('should start wrangler dev server and return port', (test) => Effect.gen(function* () {
18
+ const server = yield* WranglerDevServerService;
19
+ expect(server.port).toBeGreaterThan(0);
20
+ expect(server.url).toMatch(/http:\/\/127.0.0.1:\d+/);
21
+ }).pipe(withBasicTest()(test)));
22
+ Vitest.scopedLive('should use specified port when provided', (test) => Effect.andThen(getFreePort, (port) => Effect.gen(function* () {
23
+ const server = yield* WranglerDevServerService;
24
+ expect(server.port).toBe(port);
25
+ expect(server.url).toBe(`http://127.0.0.1:${port}`);
26
+ }).pipe(withBasicTest({ preferredPort: port })(test))));
27
+ });
28
+ Vitest.describe('Error Handling', () => {
29
+ const withErrorTest = (args = {}) => Vitest.makeWithTestCtx({
30
+ timeout: testTimeout,
31
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
32
+ });
33
+ Vitest.scopedLive('should handle missing wrangler.toml but should timeout', (test) => Effect.gen(function* () {
34
+ const error = yield* WranglerDevServerService.pipe(Effect.provide(WranglerDevServerTest({
35
+ cwd: '/tmp',
36
+ wranglerConfigPath: '/dev/null',
37
+ readiness: { connectTimeout: '500 millis' },
38
+ }).pipe(Layer.provide(PlatformNode.NodeContext.layer))), Effect.flip);
39
+ expect(error).toBeInstanceOf(WranglerDevServerError);
40
+ }).pipe(Vitest.withTestCtx(test)));
41
+ Vitest.scopedLive('should handle invalid working directory', (test) => Effect.gen(function* () {
42
+ const result = yield* WranglerDevServerService.pipe(Effect.provide(WranglerDevServerTest({
43
+ cwd: '/completely/nonexistent/directory',
44
+ }).pipe(Layer.provide(PlatformNode.NodeContext.layer))), Effect.either);
45
+ expect(result._tag).toBe('Left');
46
+ if (result._tag === 'Left') {
47
+ expect(result.left).toBeInstanceOf(WranglerDevServerError);
48
+ }
49
+ }).pipe(Vitest.withTestCtx(test)));
50
+ Vitest.scopedLive('should timeout if server fails to start', (test) => Effect.gen(function* () {
51
+ // Create a command that will never output "Ready on"
52
+ const result = yield* WranglerDevServerService.pipe(
53
+ // Override the timeout for this test to be shorter
54
+ Effect.timeout('5 seconds'), Effect.either);
55
+ // This might succeed or fail depending on actual wrangler behavior
56
+ // The main point is testing timeout functionality
57
+ expect(['Left', 'Right']).toContain(result._tag);
58
+ }).pipe(withErrorTest()(test)));
59
+ });
60
+ Vitest.describe('Service Pattern', () => {
61
+ const withServiceTest = (args = {}) => Vitest.makeWithTestCtx({
62
+ timeout: testTimeout,
63
+ makeLayer: () => WranglerDevServerTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
64
+ });
65
+ Vitest.scopedLive('should work with service pattern', (test) => Effect.gen(function* () {
66
+ const server = yield* WranglerDevServerService;
67
+ expect(server.port).toBeGreaterThan(0);
68
+ expect(server.url).toMatch(/http:\/\/127.0.0.1:\d+/);
69
+ }).pipe(withServiceTest()(test)));
70
+ Vitest.scopedLive('should work with custom port via service', (test) => Effect.andThen(getFreePort, (port) => Effect.gen(function* () {
71
+ const server = yield* WranglerDevServerService;
72
+ expect(server.port).toBe(port);
73
+ expect(server.url).toBe(`http://127.0.0.1:${port}`);
74
+ }).pipe(withServiceTest({ preferredPort: port })(test))));
75
+ });
76
+ });
77
+ //# sourceMappingURL=WranglerDevServer.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WranglerDevServer.test.js","sourceRoot":"","sources":["../../src/wrangler/WranglerDevServer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAEL,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,wBAAwB,CAAA;AAE/B,MAAM,WAAW,GAAG,MAAM,CAAA;AAE1B,MAAM,qBAAqB,GAAG,CAAC,OAA4C,EAAE,EAAE,EAAE,CAC/E,wBAAwB,CAAC,OAAO,CAAC;IAC/B,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW;IACtC,GAAG,IAAI;CACR,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAA;AAE/C,MAAM,CAAC,QAAQ,CAAC,mBAAmB,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE;IAClE,MAAM,CAAC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QACvC,MAAM,aAAa,GAAG,CAAC,OAA4C,EAAE,EAAE,EAAE,CACvE,MAAM,CAAC,eAAe,CAAC;YACrB,OAAO,EAAE,WAAW;YACp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AAE,CAC7D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,wBAAwB,CAAA;YAE9C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;YACtC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAA;QACtD,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,CAAC,CACjC,CAAA;QAED,MAAM,CAAC,UAAU,CAAC,0CAA0C,EAAE,CAAC,IAAI,EAAE,EAAE,CACrE,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CACnC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YAClB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,wBAAwB,CAAA;YAE9C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC9B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAA;QACrD,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CACxD,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ fetch(_request: Request): Promise<Response>;
3
+ };
4
+ export default _default;
5
+ export declare class TestDO {
6
+ fetch(_request: Request): Promise<Response>;
7
+ }
8
+ //# sourceMappingURL=cf-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cf-worker.d.ts","sourceRoot":"","sources":["../../../src/wrangler/fixtures/cf-worker.ts"],"names":[],"mappings":";oBACwB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;;AADnD,wBAIC;AAED,qBAAa,MAAM;IACX,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGlD"}
@@ -0,0 +1,11 @@
1
+ export default {
2
+ async fetch(_request) {
3
+ return new Response('Hello from Wrangler Dev Server test worker!');
4
+ },
5
+ };
6
+ export class TestDO {
7
+ async fetch(_request) {
8
+ return new Response('Hello from Test Durable Object!');
9
+ }
10
+ }
11
+ //# sourceMappingURL=cf-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cf-worker.js","sourceRoot":"","sources":["../../../src/wrangler/fixtures/cf-worker.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,KAAK,CAAC,KAAK,CAAC,QAAiB;QAC3B,OAAO,IAAI,QAAQ,CAAC,6CAA6C,CAAC,CAAA;IACpE,CAAC;CACF,CAAA;AAED,MAAM,OAAO,MAAM;IACjB,KAAK,CAAC,KAAK,CAAC,QAAiB;QAC3B,OAAO,IAAI,QAAQ,CAAC,iCAAiC,CAAC,CAAA;IACxD,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export { type StartWranglerDevServerArgs, type WranglerDevServer, WranglerDevServerError, WranglerDevServerService, } from './WranglerDevServer.ts';
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/wrangler/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,EACtB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { WranglerDevServerError, WranglerDevServerService, } from "./WranglerDevServer.js";
2
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/wrangler/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,wBAAwB,CAAA"}
package/package.json CHANGED
@@ -1,24 +1,28 @@
1
1
  {
2
2
  "name": "@livestore/utils-dev",
3
- "version": "0.4.0-dev.2",
3
+ "version": "0.4.0-dev.20",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
- "./src/node-vitest/polyfill.ts"
6
+ "./src/node-vitest/global.ts",
7
+ "./dist/node-vitest/global.js"
7
8
  ],
8
9
  "exports": {
9
10
  "./node": "./dist/node/mod.js",
10
- "./node-vitest": "./dist/node-vitest/mod.js"
11
+ "./node-vitest": "./dist/node-vitest/mod.js",
12
+ "./wrangler": "./dist/wrangler/mod.js"
11
13
  },
12
14
  "dependencies": {
13
- "@effect/opentelemetry": "0.56.1",
14
- "@effect/vitest": "0.25.0",
15
+ "@effect/opentelemetry": "0.58.0",
16
+ "@effect/vitest": "0.26.0",
17
+ "@iarna/toml": "2.2.5",
15
18
  "@opentelemetry/api": "1.9.0",
16
19
  "@opentelemetry/exporter-metrics-otlp-http": "0.203.0",
17
20
  "@opentelemetry/exporter-trace-otlp-http": "0.203.0",
18
21
  "@opentelemetry/sdk-metrics": "2.0.1",
19
22
  "@opentelemetry/sdk-trace-base": "2.0.1",
20
23
  "@opentelemetry/sdk-trace-node": "2.0.1",
21
- "@livestore/utils": "0.4.0-dev.2"
24
+ "wrangler": "4.42.2",
25
+ "@livestore/utils": "0.4.0-dev.20"
22
26
  },
23
27
  "devDependencies": {},
24
28
  "files": [
@@ -29,10 +33,7 @@
29
33
  "license": "Apache-2.0",
30
34
  "peerDependencies": {},
31
35
  "publishConfig": {
32
- "access": "public",
33
- "sideEffects": [
34
- "./dist/node-vitest/polyfill.js"
35
- ]
36
+ "access": "public"
36
37
  },
37
38
  "scripts": {
38
39
  "test": "echo 'No tests for utils-dev'"
@@ -0,0 +1,91 @@
1
+ import path from 'node:path'
2
+ import { Duration, Effect, Layer, Stream } from '@livestore/utils/effect'
3
+ import { PlatformNode } from '@livestore/utils/node'
4
+ import { Vitest } from '@livestore/utils-dev/node-vitest'
5
+ import { expect } from 'vitest'
6
+ import { type DockerComposeArgs, DockerComposeService } from './DockerComposeService.ts'
7
+
8
+ const testTimeout = 30_000
9
+ const testFixturePath = path.join(import.meta.dirname, 'test-fixtures')
10
+
11
+ const DockerComposeTest = (args: Partial<DockerComposeArgs> = {}) =>
12
+ DockerComposeService.Default({
13
+ cwd: testFixturePath,
14
+ ...args,
15
+ })
16
+
17
+ Vitest.describe('DockerComposeService', { timeout: testTimeout }, () => {
18
+ Vitest.describe('Basic Operations', () => {
19
+ const withBasicTest = (args: Partial<DockerComposeArgs> = {}) =>
20
+ Vitest.makeWithTestCtx({
21
+ timeout: testTimeout,
22
+ makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
23
+ })
24
+
25
+ Vitest.scopedLive('can pull docker images', (test) =>
26
+ Effect.gen(function* () {
27
+ const dockerCompose = yield* DockerComposeService
28
+
29
+ // Test that pull operation works (should succeed for hello-world image)
30
+ yield* dockerCompose.pull
31
+ }).pipe(withBasicTest()(test)),
32
+ )
33
+
34
+ Vitest.scopedLive('can start and stop docker compose services', (test) =>
35
+ Effect.gen(function* () {
36
+ const dockerCompose = yield* DockerComposeService
37
+
38
+ // Start the service
39
+ yield* dockerCompose.start({ detached: true })
40
+
41
+ // Stop the service
42
+ yield* dockerCompose.stop
43
+ }).pipe(withBasicTest({ serviceName: 'hello-world' })(test)),
44
+ )
45
+
46
+ Vitest.scopedLive('can get logs from docker compose services', (test) =>
47
+ Effect.gen(function* () {
48
+ const dockerCompose = yield* DockerComposeService
49
+
50
+ // Start the service first
51
+ yield* dockerCompose.start({ detached: true })
52
+
53
+ // Get logs (should contain at least the "Hello from Docker!" message)
54
+ const firstLogLine = yield* dockerCompose.logs().pipe(Stream.runHead)
55
+
56
+ expect(firstLogLine._tag).toBe('Some')
57
+
58
+ // Stop the service
59
+ yield* dockerCompose.stop
60
+ }).pipe(withBasicTest({ serviceName: 'hello-world' })(test)),
61
+ )
62
+ })
63
+
64
+ Vitest.describe('Health Check Operations', () => {
65
+ const withHealthCheckTest = (args: Partial<DockerComposeArgs> = {}) =>
66
+ Vitest.makeWithTestCtx({
67
+ timeout: testTimeout,
68
+ makeLayer: () => DockerComposeTest(args).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
69
+ })
70
+
71
+ Vitest.scopedLive('handles health check timeout gracefully', (test) =>
72
+ Effect.gen(function* () {
73
+ const dockerCompose = yield* DockerComposeService
74
+
75
+ // Test starting with a health check that will timeout (invalid URL)
76
+ const result = yield* dockerCompose
77
+ .start({
78
+ detached: true,
79
+ healthCheck: {
80
+ url: 'http://localhost:99999/nonexistent',
81
+ timeout: Duration.seconds(2),
82
+ },
83
+ })
84
+ .pipe(Effect.either)
85
+
86
+ // Should fail due to health check timeout
87
+ expect(result._tag).toBe('Left')
88
+ }).pipe(withHealthCheckTest({ serviceName: 'hello-world' })(test)),
89
+ )
90
+ })
91
+ })
@@ -0,0 +1,328 @@
1
+ import { omitUndefineds } from '@livestore/utils'
2
+ import {
3
+ Command,
4
+ type CommandExecutor,
5
+ Duration,
6
+ Effect,
7
+ Fiber,
8
+ type PlatformError,
9
+ Schedule,
10
+ Schema,
11
+ type Scope,
12
+ Stream,
13
+ } from '@livestore/utils/effect'
14
+
15
+ export class DockerComposeError extends Schema.TaggedError<DockerComposeError>()('DockerComposeError', {
16
+ cause: Schema.Defect,
17
+ note: Schema.String,
18
+ }) {}
19
+
20
+ export interface DockerComposeArgs {
21
+ readonly cwd: string
22
+ readonly serviceName?: string
23
+ }
24
+
25
+ export interface StartOptions {
26
+ readonly detached?: boolean
27
+ readonly env?: Record<string, string>
28
+ readonly healthCheck?: {
29
+ readonly url: string
30
+ readonly timeout?: Duration.Duration
31
+ readonly interval?: Duration.Duration
32
+ }
33
+ }
34
+
35
+ export interface LogsOptions {
36
+ readonly follow?: boolean
37
+ readonly tail?: number
38
+ readonly since?: string
39
+ }
40
+
41
+ export interface DockerComposeOperations {
42
+ readonly pull: Effect.Effect<void, DockerComposeError | PlatformError.PlatformError>
43
+ readonly start: (
44
+ options?: StartOptions,
45
+ ) => Effect.Effect<void, DockerComposeError | PlatformError.PlatformError, Scope.Scope>
46
+ readonly stop: Effect.Effect<void, DockerComposeError | PlatformError.PlatformError>
47
+ readonly down: (options?: {
48
+ readonly env?: Record<string, string>
49
+ readonly volumes?: boolean
50
+ readonly removeOrphans?: boolean
51
+ }) => Effect.Effect<void, DockerComposeError | PlatformError.PlatformError>
52
+ readonly logs: (
53
+ options?: LogsOptions,
54
+ ) => Stream.Stream<string, DockerComposeError | PlatformError.PlatformError, Scope.Scope>
55
+ }
56
+
57
+ export class DockerComposeService extends Effect.Service<DockerComposeService>()('DockerComposeService', {
58
+ scoped: (args: DockerComposeArgs) =>
59
+ Effect.gen(function* () {
60
+ const { cwd, serviceName } = args
61
+
62
+ const commandExecutorContext = yield* Effect.context<CommandExecutor.CommandExecutor>()
63
+
64
+ const pull = Effect.gen(function* () {
65
+ yield* Effect.log(`Pulling Docker Compose images in ${cwd}`)
66
+
67
+ // TODO (@IMax153) Refactor the effect command related code below as there is probably a much more elegant way to accomplish what we want here in a more effect idiomatic way.
68
+ const pullCommand = Command.make('docker', 'compose', 'pull').pipe(
69
+ Command.workingDirectory(cwd),
70
+ Command.stdout('pipe'),
71
+ Command.stderr('pipe'),
72
+ )
73
+
74
+ const process = yield* pullCommand.pipe(Command.start, Effect.provide(commandExecutorContext))
75
+
76
+ const stdoutFiber = yield* process.stdout.pipe(
77
+ Stream.decodeText('utf8'),
78
+ Stream.runFold('', (acc, chunk) => acc + chunk),
79
+ Effect.fork,
80
+ )
81
+
82
+ const stderrFiber = yield* process.stderr.pipe(
83
+ Stream.decodeText('utf8'),
84
+ Stream.runFold('', (acc, chunk) => acc + chunk),
85
+ Effect.fork,
86
+ )
87
+
88
+ const exitCode = yield* process.exitCode
89
+ const stdout = yield* Fiber.join(stdoutFiber)
90
+ const stderr = yield* Fiber.join(stderrFiber)
91
+
92
+ const exitCodeNumber = Number(exitCode)
93
+
94
+ if (exitCodeNumber !== 0) {
95
+ const stdoutLog = stdout.length > 0 ? stdout : '<empty stdout>'
96
+ const stderrLog = stderr.length > 0 ? stderr : '<empty stderr>'
97
+ const failureMessage = [
98
+ `Docker compose pull failed with exit code ${exitCodeNumber} in ${cwd}`,
99
+ `stdout:\n${stdoutLog}`,
100
+ `stderr:\n${stderrLog}`,
101
+ ].join('\n')
102
+
103
+ yield* Effect.logError(failureMessage)
104
+
105
+ return yield* new DockerComposeError({
106
+ cause: new Error(`Docker compose pull failed with exit code ${exitCodeNumber}`),
107
+ note: failureMessage,
108
+ })
109
+ }
110
+
111
+ yield* Effect.log(`Successfully pulled Docker Compose images`)
112
+ }).pipe(
113
+ Effect.retry({
114
+ schedule: Schedule.exponentialBackoff10Sec,
115
+ while: Schema.is(DockerComposeError),
116
+ }),
117
+ Effect.withSpan('pullDockerComposeImages'),
118
+ Effect.scoped,
119
+ )
120
+
121
+ const start = (options: StartOptions = {}) =>
122
+ Effect.gen(function* () {
123
+ const { detached = true, healthCheck } = options
124
+
125
+ // Build start command
126
+ const baseArgs = ['docker', 'compose', 'up']
127
+ if (detached) baseArgs.push('-d')
128
+ if (serviceName) baseArgs.push(serviceName)
129
+
130
+ const command = yield* Command.make(baseArgs[0]!, ...baseArgs.slice(1)).pipe(
131
+ Command.workingDirectory(cwd),
132
+ Command.env(options.env ?? {}),
133
+ Command.stderr('inherit'),
134
+ Command.stdout('inherit'),
135
+ Command.start,
136
+ Effect.catchAll((cause) =>
137
+ Effect.fail(
138
+ new DockerComposeError({
139
+ cause,
140
+ note: `Failed to start Docker Compose services in ${cwd}`,
141
+ }),
142
+ ),
143
+ ),
144
+ Effect.provide(commandExecutorContext),
145
+ )
146
+
147
+ // Wait for command completion
148
+ yield* command.exitCode.pipe(
149
+ Effect.flatMap((exitCode) =>
150
+ exitCode === 0
151
+ ? Effect.void
152
+ : Effect.fail(
153
+ new DockerComposeError({
154
+ cause: new Error(`Docker compose exited with code ${exitCode}`),
155
+ note: `Docker Compose failed to start with exit code ${exitCode}. Env: ${JSON.stringify(options.env)}`,
156
+ }),
157
+ ),
158
+ ),
159
+ Effect.provide(commandExecutorContext),
160
+ )
161
+
162
+ // Perform health check if requested
163
+ if (healthCheck) {
164
+ yield* performHealthCheck(healthCheck).pipe(Effect.provide(commandExecutorContext))
165
+ }
166
+
167
+ yield* Effect.log(`Docker Compose services started successfully in ${cwd}`)
168
+ }).pipe(Effect.withSpan('startDockerCompose'))
169
+
170
+ const stop = Effect.gen(function* () {
171
+ yield* Effect.log(`Stopping Docker Compose services in ${cwd}`)
172
+
173
+ const stopCommand = serviceName
174
+ ? Command.make('docker', 'compose', 'stop', serviceName)
175
+ : Command.make('docker', 'compose', 'stop')
176
+
177
+ yield* stopCommand.pipe(
178
+ Command.workingDirectory(cwd),
179
+ Command.exitCode,
180
+ Effect.flatMap((exitCode: number) =>
181
+ exitCode === 0
182
+ ? Effect.void
183
+ : Effect.fail(
184
+ new DockerComposeError({
185
+ cause: new Error(`Docker compose stop exited with code ${exitCode}`),
186
+ note: `Failed to stop Docker Compose services`,
187
+ }),
188
+ ),
189
+ ),
190
+ Effect.provide(commandExecutorContext),
191
+ )
192
+
193
+ yield* Effect.log(`Docker Compose services stopped successfully`)
194
+ }).pipe(Effect.withSpan('stopDockerCompose'))
195
+
196
+ const logs = (options: LogsOptions = {}) =>
197
+ Effect.gen(function* () {
198
+ const { follow = false, tail, since } = options
199
+
200
+ const baseArgs = ['docker', 'compose', 'logs']
201
+ if (follow) baseArgs.push('-f')
202
+ if (tail) baseArgs.push('--tail', tail.toString())
203
+ if (since) baseArgs.push('--since', since)
204
+ if (serviceName) baseArgs.push(serviceName)
205
+
206
+ const command = yield* Command.make(baseArgs[0]!, ...baseArgs.slice(1)).pipe(
207
+ Command.workingDirectory(cwd),
208
+ Command.start,
209
+ Effect.catchAll((cause) =>
210
+ Effect.fail(
211
+ new DockerComposeError({
212
+ cause,
213
+ note: `Failed to read Docker Compose logs in ${cwd}`,
214
+ }),
215
+ ),
216
+ ),
217
+ Effect.provide(commandExecutorContext),
218
+ )
219
+
220
+ return command.stdout.pipe(
221
+ Stream.decodeText('utf8'),
222
+ Stream.splitLines,
223
+ Stream.mapError(
224
+ (cause) =>
225
+ new DockerComposeError({
226
+ cause,
227
+ note: `Error reading Docker Compose logs in ${cwd}`,
228
+ }),
229
+ ),
230
+ )
231
+ }).pipe(Stream.unwrapScoped)
232
+
233
+ const down = (options?: {
234
+ readonly env?: Record<string, string>
235
+ readonly volumes?: boolean
236
+ readonly removeOrphans?: boolean
237
+ }) =>
238
+ Effect.gen(function* () {
239
+ yield* Effect.log(`Tearing down Docker Compose services in ${cwd}`)
240
+
241
+ const baseArgs = ['docker', 'compose', 'down']
242
+ if (options?.volumes) baseArgs.push('-v')
243
+ if (options?.removeOrphans) baseArgs.push('--remove-orphans')
244
+ if (serviceName) baseArgs.push(serviceName)
245
+
246
+ yield* Command.make(baseArgs[0]!, ...baseArgs.slice(1)).pipe(
247
+ Command.workingDirectory(cwd),
248
+ Command.env(options?.env ?? {}),
249
+ Command.exitCode,
250
+ Effect.flatMap((exitCode: number) =>
251
+ exitCode === 0
252
+ ? Effect.void
253
+ : Effect.fail(
254
+ new DockerComposeError({
255
+ cause: new Error(`Docker compose down exited with code ${exitCode}`),
256
+ note: `Failed to tear down Docker Compose services`,
257
+ }),
258
+ ),
259
+ ),
260
+ Effect.provide(commandExecutorContext),
261
+ )
262
+
263
+ yield* Effect.log(`Docker Compose services torn down successfully`)
264
+ }).pipe(Effect.withSpan('downDockerCompose'))
265
+
266
+ return { pull, start, stop, down, logs }
267
+ }),
268
+ }) {}
269
+
270
+ const performHealthCheck = ({
271
+ url,
272
+ timeout = Duration.minutes(2),
273
+ interval = Duration.seconds(2),
274
+ }: {
275
+ url: string
276
+ timeout?: Duration.Duration
277
+ interval?: Duration.Duration
278
+ }): Effect.Effect<void, DockerComposeError, CommandExecutor.CommandExecutor | Scope.Scope> =>
279
+ Effect.gen(function* () {
280
+ yield* Effect.log(`Performing health check on ${url}`)
281
+
282
+ const checkHealth = Command.make('curl', '-f', '-s', url).pipe(
283
+ Command.exitCode,
284
+ Effect.map((code: number) => code === 0),
285
+ Effect.catchAll(() => Effect.succeed(false)),
286
+ )
287
+
288
+ const healthCheck = checkHealth.pipe(
289
+ Effect.repeat({
290
+ while: (healthy: boolean) => !healthy,
291
+ schedule: Schedule.fixed(interval),
292
+ }),
293
+ Effect.timeout(timeout),
294
+ Effect.catchAll(() =>
295
+ Effect.fail(
296
+ new DockerComposeError({
297
+ cause: new Error('Health check timeout'),
298
+ note: `Health check failed for ${url} after ${Duration.toMillis(timeout)}ms`,
299
+ }),
300
+ ),
301
+ ),
302
+ )
303
+
304
+ yield* healthCheck
305
+ yield* Effect.log(`Health check passed for ${url}`)
306
+ })
307
+
308
+ // Convenience function for scoped Docker Compose operations with automatic cleanup
309
+ export const startDockerComposeServicesScoped = (
310
+ args: DockerComposeArgs & {
311
+ healthCheck?: StartOptions['healthCheck']
312
+ },
313
+ ): Effect.Effect<
314
+ void,
315
+ DockerComposeError | PlatformError.PlatformError,
316
+ DockerComposeService | CommandExecutor.CommandExecutor | Scope.Scope
317
+ > =>
318
+ Effect.gen(function* () {
319
+ const dockerCompose = yield* DockerComposeService
320
+
321
+ // Start the services
322
+ yield* dockerCompose.start({
323
+ ...omitUndefineds({ healthCheck: args.healthCheck ? args.healthCheck : undefined }),
324
+ })
325
+
326
+ // Add cleanup finalizer to the current scope
327
+ yield* Effect.addFinalizer(() => dockerCompose.stop.pipe(Effect.orDie))
328
+ })
@@ -0,0 +1,4 @@
1
+ services:
2
+ hello-world:
3
+ image: hello-world
4
+ profiles: [manual] # Don't auto-start this service