devsess 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +3 -3
- package/dist/async/index.d.ts +1 -1
- package/dist/async/index.d.ts.map +1 -1
- package/dist/async/index.js +9 -7
- package/dist/async/index.js.map +1 -1
- package/dist/async/platform.d.ts +2 -2
- package/dist/async/platform.d.ts.map +1 -1
- package/dist/async/run-dev-cli.d.ts +1 -1
- package/dist/async/run-dev-cli.d.ts.map +1 -1
- package/dist/chunk-CBRTTFXG.js +29 -0
- package/dist/chunk-CBRTTFXG.js.map +1 -0
- package/dist/chunk-GX4J6JR3.js +214 -0
- package/dist/chunk-GX4J6JR3.js.map +1 -0
- package/dist/chunk-SX5HBQHG.js +226 -0
- package/dist/chunk-SX5HBQHG.js.map +1 -0
- package/dist/dev/subprocess.d.ts +1 -1
- package/dist/dev/subprocess.d.ts.map +1 -1
- package/dist/index.js +10 -26
- package/dist/index.js.map +1 -1
- package/dist/pglite/index.d.ts +2 -2
- package/dist/pglite/index.d.ts.map +1 -1
- package/dist/pglite/index.js +20 -30
- package/dist/pglite/index.js.map +1 -1
- package/dist/services/container.d.ts +17 -0
- package/dist/services/container.d.ts.map +1 -0
- package/dist/services/core.d.ts +18 -0
- package/dist/services/core.d.ts.map +1 -0
- package/dist/services/docker-args.d.ts +31 -0
- package/dist/services/docker-args.d.ts.map +1 -0
- package/dist/services/index.d.ts +45 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +312 -0
- package/dist/services/index.js.map +1 -0
- package/package.json +92 -88
- package/dist/chunk-ULIVG5ID.js +0 -429
- package/dist/chunk-ULIVG5ID.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026-present Farrel Fachrizal Darian
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -29,12 +29,12 @@ bun add @electric-sql/pglite drizzle-orm
|
|
|
29
29
|
import { CurrentSession, DevSessions, getStickyPort, runManagedSubprocess } from 'devsess';
|
|
30
30
|
import { NodeRuntime, NodeServices } from '@effect/platform-node';
|
|
31
31
|
import { Effect } from 'effect';
|
|
32
|
-
import { Command, Flag } from 'effect/
|
|
32
|
+
import { Command, Flag } from 'effect/cli';
|
|
33
33
|
|
|
34
34
|
const web = Command.make(
|
|
35
35
|
'web',
|
|
36
36
|
{
|
|
37
|
-
lite: Flag.
|
|
37
|
+
lite: Flag.Boolean('lite').pipe(
|
|
38
38
|
Flag.withDescription('Use a per-session PGlite database'),
|
|
39
39
|
),
|
|
40
40
|
},
|
|
@@ -99,7 +99,7 @@ From `devsess` (the Effect API):
|
|
|
99
99
|
- `getStickyPort(session)`, `runManagedSubprocess(cmd, args, opts?)`, `publishRunning(data)`, `awaitRunning(pkg)` — free functions; only `getStickyPort` takes a `DevSession`
|
|
100
100
|
- `SessionState.slot(schema)` — typed per-session JSON state
|
|
101
101
|
|
|
102
|
-
Build your CLI with a stock `Command.make(...)` from `effect/
|
|
102
|
+
Build your CLI with a stock `Command.make(...)` from `effect/cli` — devsess no longer wraps it.
|
|
103
103
|
|
|
104
104
|
From `devsess/pglite`:
|
|
105
105
|
|
package/dist/async/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Schema } from 'effect';
|
|
2
|
-
export * as cli from 'effect/
|
|
2
|
+
export * as cli from 'effect/cli';
|
|
3
3
|
export { SessionStateError } from '../dev/session-state';
|
|
4
4
|
export { defineDevCli } from './define-cli';
|
|
5
5
|
export { createDevSessions, type DevSessionManager } from './dev-sessions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/async/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/async/index.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
DevSessions,
|
|
3
|
-
SessionState,
|
|
4
|
-
SessionStateError,
|
|
5
2
|
awaitRunningSignal,
|
|
6
|
-
getStickyPort,
|
|
7
3
|
publishRunningSignal,
|
|
8
4
|
resolveSiblingDir,
|
|
9
5
|
runManagedSubprocess,
|
|
10
6
|
runningSignalPath
|
|
11
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-SX5HBQHG.js";
|
|
8
|
+
import {
|
|
9
|
+
DevSessions,
|
|
10
|
+
SessionState,
|
|
11
|
+
SessionStateError,
|
|
12
|
+
getStickyPort
|
|
13
|
+
} from "../chunk-GX4J6JR3.js";
|
|
12
14
|
|
|
13
15
|
// src/async/index.ts
|
|
14
16
|
import { Schema } from "effect";
|
|
15
|
-
import * as cli2 from "effect/
|
|
17
|
+
import * as cli2 from "effect/cli";
|
|
16
18
|
|
|
17
19
|
// src/async/define-cli.ts
|
|
18
20
|
import { Effect as Effect3 } from "effect";
|
|
19
21
|
|
|
20
22
|
// src/async/run-dev-cli.ts
|
|
21
23
|
import { Effect, Layer } from "effect";
|
|
22
|
-
import * as cli from "effect/
|
|
24
|
+
import * as cli from "effect/cli";
|
|
23
25
|
var runDevCli = (config) => {
|
|
24
26
|
const command = cli.Command.make(
|
|
25
27
|
config.name,
|
package/dist/async/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/async/index.ts","../../src/async/define-cli.ts","../../src/async/run-dev-cli.ts","../../src/async/session.ts","../../src/async/dev-sessions.ts","../../src/async/run.ts","../../src/async/session-state.ts"],"sourcesContent":["// Re-exported so consumers can declare CLI flags/arguments without a direct\n// dependency on `effect/unstable/cli`, e.g. `cli.Flag.string('local')`.\n\nexport { Schema } from 'effect';\nexport * as cli from 'effect/unstable/cli';\n\nexport { SessionStateError } from '../dev/session-state';\nexport { defineDevCli } from './define-cli';\nexport { createDevSessions, type DevSessionManager } from './dev-sessions';\nexport type { DevPlatform, DevServices } from './platform';\nexport type { DevSession } from './session';\nexport { SessionState } from './session-state';\n","import { Effect, type Scope } from 'effect';\nimport type { FileSystem } from 'effect/FileSystem';\nimport type { Path } from 'effect/Path';\nimport type { ChildProcessSpawner } from 'effect/unstable/process/ChildProcessSpawner';\nimport {\n\tawaitRunningSignal,\n\tpublishRunningSignal,\n\tresolveSiblingDir,\n\trunningSignalPath,\n} from '../dev/running-signal';\nimport { getStickyPort } from '../dev/sticky-port';\nimport { runManagedSubprocess } from '../dev/subprocess';\nimport { DevSessions } from '../dev-sessions';\nimport type { DevPlatform } from './platform';\nimport { type CommandConfig, runDevCli } from './run-dev-cli';\nimport { type DevSession, toAsyncSession } from './session';\n\n/** Promise-returning mirror of the Effect core's free functions (`getStickyPort`, `runManagedSubprocess`, `publishRunning`, `awaitRunning`), bundled into a single per-run context. */\ntype AsyncRunContext = {\n\tsession: () => Promise<DevSession>;\n\tgetStickyPort: (options?: { name?: string }) => Promise<number>;\n\trunManagedSubprocess: (\n\t\t...args: Parameters<typeof runManagedSubprocess>\n\t) => Promise<Effect.Success<ReturnType<typeof runManagedSubprocess>>>;\n\tpublishRunning: (data: unknown) => Promise<void>;\n\tawaitRunning: <T>(pkg: string) => Promise<T>;\n};\n\nexport const defineDevCli = (config: {\n\tname: string;\n\tdir: string;\n\toptions?: CommandConfig;\n\tplatform: DevPlatform;\n\trun: (\n\t\tctx: AsyncRunContext,\n\t\topts: Record<string, unknown>,\n\t) => Promise<void> | void;\n}): ((argv: string[]) => void) =>\n\trunDevCli({\n\t\tname: config.name,\n\t\tdir: config.dir,\n\t\toptions: config.options,\n\t\tplatform: config.platform,\n\t\tmakeHandler: (opts) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst sessions = yield* DevSessions;\n\t\t\t\tconst session = yield* Effect.cached(sessions.getLatestOrCreate);\n\n\t\t\t\t// Capture the process-lifetime context (the Scope opened by `runDevCli`'s\n\t\t\t\t// outer `Effect.scoped`, plus DevSessions | FileSystem | Path | ChildProcessSpawner).\n\t\t\t\t// Running each ctx helper with this captured context — instead of a fresh,\n\t\t\t\t// transient `Effect.runPromise` per call — attaches its scoped resources\n\t\t\t\t// (managed subprocess, running-signal file) to that process-lifetime scope,\n\t\t\t\t// so they only release when the CLI process ends, not right after the Promise settles.\n\t\t\t\tconst services = yield* Effect.context<\n\t\t\t\t\tDevSessions | FileSystem | Path | ChildProcessSpawner | Scope.Scope\n\t\t\t\t>();\n\n\t\t\t\tconst ctx: AsyncRunContext = {\n\t\t\t\t\tsession: () =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(session).then(toAsyncSession),\n\t\t\t\t\tgetStickyPort: (options) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(\n\t\t\t\t\t\t\tEffect.flatMap(session, (resolved) =>\n\t\t\t\t\t\t\t\tgetStickyPort(resolved, options),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\trunManagedSubprocess: (...args) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(runManagedSubprocess(...args)),\n\t\t\t\t\tpublishRunning: (data) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(\n\t\t\t\t\t\t\tpublishRunningSignal(runningSignalPath(config.dir), data),\n\t\t\t\t\t\t),\n\t\t\t\t\tawaitRunning: <T>(pkg: string) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(\n\t\t\t\t\t\t\tawaitRunningSignal<T>(\n\t\t\t\t\t\t\t\trunningSignalPath(resolveSiblingDir(pkg, config.dir)),\n\t\t\t\t\t\t\t\t{ parse: (raw) => JSON.parse(raw) as T },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t};\n\n\t\t\t\tyield* Effect.promise(() => Promise.resolve(config.run(ctx, opts)));\n\t\t\t}),\n\t});\n","import { Effect, Layer, type Scope } from 'effect';\nimport * as cli from 'effect/unstable/cli';\nimport { DevSessions } from '../dev-sessions';\nimport type { DevPlatform, DevServices } from './platform';\n\nexport type CommandConfig = typeof cli.Command.make extends (\n\tname: string,\n\tconfig: infer C,\n\t...rest: Array<unknown>\n) => unknown\n\t? C\n\t: never;\n\ntype CliHandler = (\n\topts: Record<string, unknown>,\n) => Effect.Effect<void, unknown, DevSessions | DevServices | Scope.Scope>;\n\n/**\n * CLI scaffolding for the plain-async `defineDevCli` facade (`src/async/define-cli.ts`):\n * builds the `cli.Command`, wires the per-project `DevSessions` + caller-supplied\n * platform services layer, and runs it via `platform.runMain`.\n */\nexport const runDevCli = (config: {\n\tname: string;\n\tdir: string;\n\toptions?: CommandConfig;\n\tplatform: DevPlatform;\n\tmakeHandler: CliHandler;\n}): ((argv: string[]) => void) => {\n\tconst command = cli.Command.make(config.name, config.options ?? {}, (opts) =>\n\t\tconfig.makeHandler(opts as Record<string, unknown>),\n\t);\n\n\treturn (argv) => {\n\t\tconst layer = DevSessions.layerAt(config.dir).pipe(\n\t\t\tLayer.provideMerge(config.platform.services),\n\t\t);\n\n\t\tconst program = cli.Command.runWith(command, {\n\t\t\tversion: '0.0.0',\n\t\t})(argv);\n\n\t\tconfig.platform.runMain(Effect.scoped(Effect.provide(program, layer)));\n\t};\n};\n","import { Effect } from 'effect';\nimport type { DevSession as EffectDevSession } from '../dev-sessions';\n\n/** Non-enumerable, module-private key used to stash the Effect session on its async wrapper. */\nconst EFFECT_SESSION = Symbol('devsess/async/DevSession#effectSession');\n\nexport type DevSession = {\n\treadonly name: string;\n\treadonly lastModifiedAt: Date | null;\n\tpath(relativePath: string): string;\n\ttoString(): string;\n};\n\n/**\n * Wraps an Effect `DevSession` as a plain-async `DevSession`. The original Effect\n * session is stashed under `EFFECT_SESSION` so other async ops (e.g. `SessionState`)\n * can reuse the Effect core via `unwrapSession`.\n */\nexport const toAsyncSession = (session: EffectDevSession): DevSession => {\n\tconst asyncSession: DevSession = {\n\t\tname: session.name,\n\t\tlastModifiedAt: session.lastModifiedAt,\n\t\t// Safe to run synchronously: the core `path` is `Effect.succeed(pathJoin(rel))`, pure.\n\t\tpath: (relativePath) => Effect.runSync(session.path(relativePath)),\n\t\ttoString: () => session.toString(),\n\t};\n\n\tObject.defineProperty(asyncSession, EFFECT_SESSION, {\n\t\tvalue: session,\n\t\tenumerable: false,\n\t});\n\n\treturn asyncSession;\n};\n\n/** Recovers the Effect `DevSession` stashed by `toAsyncSession`. */\nexport const unwrapSession = (session: DevSession): EffectDevSession => {\n\tconst effectSession = (\n\t\tsession as unknown as Record<\n\t\t\ttypeof EFFECT_SESSION,\n\t\t\tEffectDevSession | undefined\n\t\t>\n\t)[EFFECT_SESSION];\n\tif (effectSession === undefined) {\n\t\tthrow new Error(\n\t\t\t'devsess/async: expected a DevSession created by this package, but the internal Effect session handle is missing',\n\t\t);\n\t}\n\treturn effectSession;\n};\n","import { Effect, Layer } from 'effect';\nimport { DevSessions } from '../dev-sessions';\nimport type { DevServices } from './platform';\nimport { type DevSession, toAsyncSession } from './session';\n\nexport type DevSessionManager = {\n\treadonly dir: string;\n\tgetSessions(): Promise<Array<DevSession>>;\n\tcreateSession(): Promise<DevSession>;\n\tgetLatestOrCreate(): Promise<DevSession>;\n};\n\n/**\n * Creates a manager for slug-named dev session directories under\n * `<rootDir>/.data/sessions`, using the caller-supplied platform `services` layer\n * (e.g. `NodeServices.layer`). Same `rootDir` convention as `DevSessions.layerAt` — the\n * CLI facade and this one agree on where sessions live given the same root.\n *\n * `DevSessions.layerAt` only wires lazy service methods when built (no directory IO\n * happens at build time — see `src/dev-sessions.ts`), so it's cheap to re-provide the\n * same `layer` value on every call rather than resolving a shared runtime once.\n */\nexport const createDevSessions = (\n\trootDir: string,\n\tservices: Layer.Layer<DevServices>,\n): DevSessionManager => {\n\tconst layer = DevSessions.layerAt(rootDir).pipe(Layer.provide(services));\n\n\tconst run = <A, E>(effect: Effect.Effect<A, E, DevSessions>): Promise<A> =>\n\t\tEffect.runPromise(Effect.provide(effect, layer));\n\n\treturn {\n\t\t// Matches the service's own `dir`, which is `rootDir` verbatim — safe to read synchronously.\n\t\tdir: rootDir,\n\t\tgetSessions: () =>\n\t\t\trun(DevSessions.use((sessions) => sessions.getSessions)).then(\n\t\t\t\t(sessions) => sessions.map(toAsyncSession),\n\t\t\t),\n\t\tcreateSession: () =>\n\t\t\trun(DevSessions.use((sessions) => sessions.createSession)).then(\n\t\t\t\ttoAsyncSession,\n\t\t\t),\n\t\tgetLatestOrCreate: () =>\n\t\t\trun(DevSessions.use((sessions) => sessions.getLatestOrCreate)).then(\n\t\t\t\ttoAsyncSession,\n\t\t\t),\n\t};\n};\n","import { Effect, type Layer, type Scope } from 'effect';\nimport type { DevServices } from './platform';\n\n/** Runs an Effect that only needs the caller-supplied platform services (+ an optional Scope) as a Promise. */\nexport const run = <A, E>(\n\teffect: Effect.Effect<A, E, DevServices | Scope.Scope>,\n\tservices: Layer.Layer<DevServices>,\n): Promise<A> =>\n\tEffect.runPromise(Effect.scoped(Effect.provide(effect, services)));\n","import type { Layer } from 'effect';\nimport type * as S from 'effect/Schema';\nimport { SessionState as EffectSessionState } from '../dev/session-state';\nimport type { DevServices } from './platform';\nimport { run } from './run';\nimport { type DevSession, unwrapSession } from './session';\n\nexport namespace SessionState {\n\t// Decoding must run without extra context beyond the platform `services` layer, so\n\t// schemas cannot require decoding services of their own.\n\ttype Shape = S.Codec<unknown, unknown, never>;\n\n\texport function slot<T extends Shape>(\n\t\tschema: T,\n\t\tservices: Layer.Layer<DevServices>,\n\t) {\n\t\tconst effectSlot = EffectSessionState.slot(schema);\n\t\treturn {\n\t\t\tread: (session: DevSession): Promise<T['Type'] | null> =>\n\t\t\t\trun(effectSlot.read(unwrapSession(session)), services),\n\t\t\twrite: (session: DevSession, data: T['Type']): Promise<void> =>\n\t\t\t\trun(effectSlot.write(unwrapSession(session), data), services),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAGA,SAAS,cAAc;AACvB,YAAYA,UAAS;;;ACJrB,SAAS,UAAAC,eAA0B;;;ACAnC,SAAS,QAAQ,aAAyB;AAC1C,YAAY,SAAS;AAqBd,IAAM,YAAY,CAAC,WAMQ;AACjC,QAAM,UAAc,YAAQ;AAAA,IAAK,OAAO;AAAA,IAAM,OAAO,WAAW,CAAC;AAAA,IAAG,CAAC,SACpE,OAAO,YAAY,IAA+B;AAAA,EACnD;AAEA,SAAO,CAAC,SAAS;AAChB,UAAM,QAAQ,YAAY,QAAQ,OAAO,GAAG,EAAE;AAAA,MAC7C,MAAM,aAAa,OAAO,SAAS,QAAQ;AAAA,IAC5C;AAEA,UAAM,UAAc,YAAQ,QAAQ,SAAS;AAAA,MAC5C,SAAS;AAAA,IACV,CAAC,EAAE,IAAI;AAEP,WAAO,SAAS,QAAQ,OAAO,OAAO,OAAO,QAAQ,SAAS,KAAK,CAAC,CAAC;AAAA,EACtE;AACD;;;AC5CA,SAAS,UAAAC,eAAc;AAIv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AACjD,WAAO;AAAA,MACN,MAAM,CAAC,YACN,IAAI,WAAW,KAAK,cAAc,OAAO,CAAC,GAAG,QAAQ;AAAA,MACtD,OAAO,CAAC,SAAqB,SAC5B,IAAI,WAAW,MAAM,cAAc,OAAO,GAAG,IAAI,GAAG,QAAQ;AAAA,IAC9D;AAAA,EACD;AAXO,EAAAA,cAAS;AAAA,GALAA,kCAAA;","names":["cli","Effect","Effect","Effect","Effect","Layer","Layer","run","Effect","Effect","SessionState"]}
|
|
1
|
+
{"version":3,"sources":["../../src/async/index.ts","../../src/async/define-cli.ts","../../src/async/run-dev-cli.ts","../../src/async/session.ts","../../src/async/dev-sessions.ts","../../src/async/run.ts","../../src/async/session-state.ts"],"sourcesContent":["// Re-exported so consumers can declare CLI flags/arguments without a direct\n// dependency on `effect/cli`, e.g. `cli.Flag.String('local')`.\n\nexport { Schema } from 'effect';\nexport * as cli from 'effect/cli';\n\nexport { SessionStateError } from '../dev/session-state';\nexport { defineDevCli } from './define-cli';\nexport { createDevSessions, type DevSessionManager } from './dev-sessions';\nexport type { DevPlatform, DevServices } from './platform';\nexport type { DevSession } from './session';\nexport { SessionState } from './session-state';\n","import { Effect, type Scope } from 'effect';\nimport type { FileSystem } from 'effect/FileSystem';\nimport type { Path } from 'effect/Path';\nimport type { ChildProcessSpawner } from 'effect/process/ChildProcessSpawner';\nimport {\n\tawaitRunningSignal,\n\tpublishRunningSignal,\n\tresolveSiblingDir,\n\trunningSignalPath,\n} from '../dev/running-signal';\nimport { getStickyPort } from '../dev/sticky-port';\nimport { runManagedSubprocess } from '../dev/subprocess';\nimport { DevSessions } from '../dev-sessions';\nimport type { DevPlatform } from './platform';\nimport { type CommandConfig, runDevCli } from './run-dev-cli';\nimport { type DevSession, toAsyncSession } from './session';\n\n/** Promise-returning mirror of the Effect core's free functions (`getStickyPort`, `runManagedSubprocess`, `publishRunning`, `awaitRunning`), bundled into a single per-run context. */\ntype AsyncRunContext = {\n\tsession: () => Promise<DevSession>;\n\tgetStickyPort: (options?: { name?: string }) => Promise<number>;\n\trunManagedSubprocess: (\n\t\t...args: Parameters<typeof runManagedSubprocess>\n\t) => Promise<Effect.Success<ReturnType<typeof runManagedSubprocess>>>;\n\tpublishRunning: (data: unknown) => Promise<void>;\n\tawaitRunning: <T>(pkg: string) => Promise<T>;\n};\n\nexport const defineDevCli = (config: {\n\tname: string;\n\tdir: string;\n\toptions?: CommandConfig;\n\tplatform: DevPlatform;\n\trun: (\n\t\tctx: AsyncRunContext,\n\t\topts: Record<string, unknown>,\n\t) => Promise<void> | void;\n}): ((argv: string[]) => void) =>\n\trunDevCli({\n\t\tname: config.name,\n\t\tdir: config.dir,\n\t\toptions: config.options,\n\t\tplatform: config.platform,\n\t\tmakeHandler: (opts) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst sessions = yield* DevSessions;\n\t\t\t\tconst session = yield* Effect.cached(sessions.getLatestOrCreate);\n\n\t\t\t\t// Capture the process-lifetime context (the Scope opened by `runDevCli`'s\n\t\t\t\t// outer `Effect.scoped`, plus DevSessions | FileSystem | Path | ChildProcessSpawner).\n\t\t\t\t// Running each ctx helper with this captured context — instead of a fresh,\n\t\t\t\t// transient `Effect.runPromise` per call — attaches its scoped resources\n\t\t\t\t// (managed subprocess, running-signal file) to that process-lifetime scope,\n\t\t\t\t// so they only release when the CLI process ends, not right after the Promise settles.\n\t\t\t\tconst services = yield* Effect.context<\n\t\t\t\t\tDevSessions | FileSystem | Path | ChildProcessSpawner | Scope.Scope\n\t\t\t\t>();\n\n\t\t\t\tconst ctx: AsyncRunContext = {\n\t\t\t\t\tsession: () =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(session).then(toAsyncSession),\n\t\t\t\t\tgetStickyPort: (options) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(\n\t\t\t\t\t\t\tEffect.flatMap(session, (resolved) =>\n\t\t\t\t\t\t\t\tgetStickyPort(resolved, options),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\trunManagedSubprocess: (...args) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(runManagedSubprocess(...args)),\n\t\t\t\t\tpublishRunning: (data) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(\n\t\t\t\t\t\t\tpublishRunningSignal(runningSignalPath(config.dir), data),\n\t\t\t\t\t\t),\n\t\t\t\t\tawaitRunning: <T>(pkg: string) =>\n\t\t\t\t\t\tEffect.runPromiseWith(services)(\n\t\t\t\t\t\t\tawaitRunningSignal<T>(\n\t\t\t\t\t\t\t\trunningSignalPath(resolveSiblingDir(pkg, config.dir)),\n\t\t\t\t\t\t\t\t{ parse: (raw) => JSON.parse(raw) as T },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t};\n\n\t\t\t\tyield* Effect.promise(() => Promise.resolve(config.run(ctx, opts)));\n\t\t\t}),\n\t});\n","import { Effect, Layer, type Scope } from 'effect';\nimport * as cli from 'effect/cli';\nimport { DevSessions } from '../dev-sessions';\nimport type { DevPlatform, DevServices } from './platform';\n\nexport type CommandConfig = typeof cli.Command.make extends (\n\tname: string,\n\tconfig: infer C,\n\t...rest: Array<unknown>\n) => unknown\n\t? C\n\t: never;\n\ntype CliHandler = (\n\topts: Record<string, unknown>,\n) => Effect.Effect<void, unknown, DevSessions | DevServices | Scope.Scope>;\n\n/**\n * CLI scaffolding for the plain-async `defineDevCli` facade (`src/async/define-cli.ts`):\n * builds the `cli.Command`, wires the per-project `DevSessions` + caller-supplied\n * platform services layer, and runs it via `platform.runMain`.\n */\nexport const runDevCli = (config: {\n\tname: string;\n\tdir: string;\n\toptions?: CommandConfig;\n\tplatform: DevPlatform;\n\tmakeHandler: CliHandler;\n}): ((argv: string[]) => void) => {\n\tconst command = cli.Command.make(config.name, config.options ?? {}, (opts) =>\n\t\tconfig.makeHandler(opts as Record<string, unknown>),\n\t);\n\n\treturn (argv) => {\n\t\tconst layer = DevSessions.layerAt(config.dir).pipe(\n\t\t\tLayer.provideMerge(config.platform.services),\n\t\t);\n\n\t\tconst program = cli.Command.runWith(command, {\n\t\t\tversion: '0.0.0',\n\t\t})(argv);\n\n\t\tconfig.platform.runMain(Effect.scoped(Effect.provide(program, layer)));\n\t};\n};\n","import { Effect } from 'effect';\nimport type { DevSession as EffectDevSession } from '../dev-sessions';\n\n/** Non-enumerable, module-private key used to stash the Effect session on its async wrapper. */\nconst EFFECT_SESSION = Symbol('devsess/async/DevSession#effectSession');\n\nexport type DevSession = {\n\treadonly name: string;\n\treadonly lastModifiedAt: Date | null;\n\tpath(relativePath: string): string;\n\ttoString(): string;\n};\n\n/**\n * Wraps an Effect `DevSession` as a plain-async `DevSession`. The original Effect\n * session is stashed under `EFFECT_SESSION` so other async ops (e.g. `SessionState`)\n * can reuse the Effect core via `unwrapSession`.\n */\nexport const toAsyncSession = (session: EffectDevSession): DevSession => {\n\tconst asyncSession: DevSession = {\n\t\tname: session.name,\n\t\tlastModifiedAt: session.lastModifiedAt,\n\t\t// Safe to run synchronously: the core `path` is `Effect.succeed(pathJoin(rel))`, pure.\n\t\tpath: (relativePath) => Effect.runSync(session.path(relativePath)),\n\t\ttoString: () => session.toString(),\n\t};\n\n\tObject.defineProperty(asyncSession, EFFECT_SESSION, {\n\t\tvalue: session,\n\t\tenumerable: false,\n\t});\n\n\treturn asyncSession;\n};\n\n/** Recovers the Effect `DevSession` stashed by `toAsyncSession`. */\nexport const unwrapSession = (session: DevSession): EffectDevSession => {\n\tconst effectSession = (\n\t\tsession as unknown as Record<\n\t\t\ttypeof EFFECT_SESSION,\n\t\t\tEffectDevSession | undefined\n\t\t>\n\t)[EFFECT_SESSION];\n\tif (effectSession === undefined) {\n\t\tthrow new Error(\n\t\t\t'devsess/async: expected a DevSession created by this package, but the internal Effect session handle is missing',\n\t\t);\n\t}\n\treturn effectSession;\n};\n","import { Effect, Layer } from 'effect';\nimport { DevSessions } from '../dev-sessions';\nimport type { DevServices } from './platform';\nimport { type DevSession, toAsyncSession } from './session';\n\nexport type DevSessionManager = {\n\treadonly dir: string;\n\tgetSessions(): Promise<Array<DevSession>>;\n\tcreateSession(): Promise<DevSession>;\n\tgetLatestOrCreate(): Promise<DevSession>;\n};\n\n/**\n * Creates a manager for slug-named dev session directories under\n * `<rootDir>/.data/sessions`, using the caller-supplied platform `services` layer\n * (e.g. `NodeServices.layer`). Same `rootDir` convention as `DevSessions.layerAt` — the\n * CLI facade and this one agree on where sessions live given the same root.\n *\n * `DevSessions.layerAt` only wires lazy service methods when built (no directory IO\n * happens at build time — see `src/dev-sessions.ts`), so it's cheap to re-provide the\n * same `layer` value on every call rather than resolving a shared runtime once.\n */\nexport const createDevSessions = (\n\trootDir: string,\n\tservices: Layer.Layer<DevServices>,\n): DevSessionManager => {\n\tconst layer = DevSessions.layerAt(rootDir).pipe(Layer.provide(services));\n\n\tconst run = <A, E>(effect: Effect.Effect<A, E, DevSessions>): Promise<A> =>\n\t\tEffect.runPromise(Effect.provide(effect, layer));\n\n\treturn {\n\t\t// Matches the service's own `dir`, which is `rootDir` verbatim — safe to read synchronously.\n\t\tdir: rootDir,\n\t\tgetSessions: () =>\n\t\t\trun(DevSessions.use((sessions) => sessions.getSessions)).then(\n\t\t\t\t(sessions) => sessions.map(toAsyncSession),\n\t\t\t),\n\t\tcreateSession: () =>\n\t\t\trun(DevSessions.use((sessions) => sessions.createSession)).then(\n\t\t\t\ttoAsyncSession,\n\t\t\t),\n\t\tgetLatestOrCreate: () =>\n\t\t\trun(DevSessions.use((sessions) => sessions.getLatestOrCreate)).then(\n\t\t\t\ttoAsyncSession,\n\t\t\t),\n\t};\n};\n","import { Effect, type Layer, type Scope } from 'effect';\nimport type { DevServices } from './platform';\n\n/** Runs an Effect that only needs the caller-supplied platform services (+ an optional Scope) as a Promise. */\nexport const run = <A, E>(\n\teffect: Effect.Effect<A, E, DevServices | Scope.Scope>,\n\tservices: Layer.Layer<DevServices>,\n): Promise<A> =>\n\tEffect.runPromise(Effect.scoped(Effect.provide(effect, services)));\n","import type { Layer } from 'effect';\nimport type * as S from 'effect/Schema';\nimport { SessionState as EffectSessionState } from '../dev/session-state';\nimport type { DevServices } from './platform';\nimport { run } from './run';\nimport { type DevSession, unwrapSession } from './session';\n\nexport namespace SessionState {\n\t// Decoding must run without extra context beyond the platform `services` layer, so\n\t// schemas cannot require decoding services of their own.\n\ttype Shape = S.Codec<unknown, unknown, never>;\n\n\texport function slot<T extends Shape>(\n\t\tschema: T,\n\t\tservices: Layer.Layer<DevServices>,\n\t) {\n\t\tconst effectSlot = EffectSessionState.slot(schema);\n\t\treturn {\n\t\t\tread: (session: DevSession): Promise<T['Type'] | null> =>\n\t\t\t\trun(effectSlot.read(unwrapSession(session)), services),\n\t\t\twrite: (session: DevSession, data: T['Type']): Promise<void> =>\n\t\t\t\trun(effectSlot.write(unwrapSession(session), data), services),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAGA,SAAS,cAAc;AACvB,YAAYA,UAAS;;;ACJrB,SAAS,UAAAC,eAA0B;;;ACAnC,SAAS,QAAQ,aAAyB;AAC1C,YAAY,SAAS;AAqBd,IAAM,YAAY,CAAC,WAMQ;AACjC,QAAM,UAAc,YAAQ;AAAA,IAAK,OAAO;AAAA,IAAM,OAAO,WAAW,CAAC;AAAA,IAAG,CAAC,SACpE,OAAO,YAAY,IAA+B;AAAA,EACnD;AAEA,SAAO,CAAC,SAAS;AAChB,UAAM,QAAQ,YAAY,QAAQ,OAAO,GAAG,EAAE;AAAA,MAC7C,MAAM,aAAa,OAAO,SAAS,QAAQ;AAAA,IAC5C;AAEA,UAAM,UAAc,YAAQ,QAAQ,SAAS;AAAA,MAC5C,SAAS;AAAA,IACV,CAAC,EAAE,IAAI;AAEP,WAAO,SAAS,QAAQ,OAAO,OAAO,OAAO,QAAQ,SAAS,KAAK,CAAC,CAAC;AAAA,EACtE;AACD;;;AC5CA,SAAS,UAAAC,eAAc;AAIvB,IAAM,iBAAiB,uBAAO,wCAAwC;AAc/D,IAAM,iBAAiB,CAAC,YA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,OAAO,CAAC,GAAG,QAAQ;AAAA,MACtD,OAAO,CAAC,SAAqB,SAC5B,IAAI,WAAW,MAAM,cAAc,OAAO,GAAG,IAAI,GAAG,QAAQ;AAAA,IAC9D;AAAA,EACD;AAXO,EAAAA,cAAS;AAAA,GALAA,kCAAA;","names":["cli","Effect","Effect","Effect","Effect","Layer","Layer","run","Effect","Effect","SessionState"]}
|
package/dist/async/platform.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Effect, Layer } from 'effect';
|
|
2
2
|
import type { FileSystem } from 'effect/FileSystem';
|
|
3
3
|
import type { Path } from 'effect/Path';
|
|
4
|
+
import type { ChildProcessSpawner } from 'effect/process/ChildProcessSpawner';
|
|
4
5
|
import type * as Runtime from 'effect/Runtime';
|
|
5
6
|
import type { Stdio } from 'effect/Stdio';
|
|
6
7
|
import type { Terminal } from 'effect/Terminal';
|
|
7
|
-
import type { ChildProcessSpawner } from 'effect/unstable/process/ChildProcessSpawner';
|
|
8
8
|
/**
|
|
9
9
|
* Core `effect` service tags this library needs from the caller-supplied platform.
|
|
10
|
-
* `effect/
|
|
10
|
+
* `effect/cli`'s `Command.runWith` pulls in `Stdio`/`Terminal` alongside the
|
|
11
11
|
* `FileSystem`/`Path`/`ChildProcessSpawner` the library's own code depends on directly.
|
|
12
12
|
*
|
|
13
13
|
* Both `@effect/platform-node`'s `NodeServices.NodeServices` and `@effect/platform-bun`'s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/async/platform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"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AC;CAC1B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, type Scope } from 'effect';
|
|
2
|
-
import * as cli from 'effect/
|
|
2
|
+
import * as cli from 'effect/cli';
|
|
3
3
|
import { DevSessions } from '../dev-sessions';
|
|
4
4
|
import type { DevPlatform, DevServices } from './platform';
|
|
5
5
|
export type CommandConfig = typeof cli.Command.make extends (name: string, config: infer C, ...rest: Array<unknown>) => unknown ? C : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-dev-cli.d.ts","sourceRoot":"","sources":["../../src/async/run-dev-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"run-dev-cli.d.ts","sourceRoot":"","sources":["../../src/async/run-dev-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAS,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,GAAG,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,SAAS,CAC3D,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,EACf,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KACnB,OAAO,GACT,CAAC,GACD,KAAK,CAAC;AAET,KAAK,UAAU,GAAG,CACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;AAE3E;;;;GAIG;AACH,eAAO,MAAM,SAAS,WAAY;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,WAAW,CAAC;IACtB,WAAW,EAAE,UAAU,CAAC;CACxB,KAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAgB5B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DevSessions
|
|
3
|
+
} from "./chunk-GX4J6JR3.js";
|
|
4
|
+
|
|
5
|
+
// src/current-session.ts
|
|
6
|
+
import { Context, Effect, Layer } from "effect";
|
|
7
|
+
var CurrentSession = class _CurrentSession extends Context.Service()("devsess/CurrentSession") {
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the session via `DevSessions#getLatestOrCreate`. Provide this around a
|
|
10
|
+
* command's own handler effect, not the whole CLI program: a `Layer`'s build effect
|
|
11
|
+
* runs the moment it's provided, regardless of what the effect it wraps ends up
|
|
12
|
+
* doing — wrapping `Command.run` itself would create a session for `--help`,
|
|
13
|
+
* `--version`, or a bad flag too, none of which ever reach a handler.
|
|
14
|
+
*/
|
|
15
|
+
static layer = Layer.effect(
|
|
16
|
+
_CurrentSession,
|
|
17
|
+
Effect.gen(function* () {
|
|
18
|
+
const sessions = yield* DevSessions;
|
|
19
|
+
return yield* sessions.getLatestOrCreate;
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
/** Pins an explicit session instead of resolving one via `DevSessions` — for tests. */
|
|
23
|
+
static layerOf = (session) => Layer.succeed(_CurrentSession, session);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
CurrentSession
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-CBRTTFXG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/current-session.ts"],"sourcesContent":["import { Context, Effect, Layer } from 'effect';\nimport type { PlatformError } from 'effect/PlatformError';\nimport { type DevSession, DevSessions } from './dev-sessions';\n\n/**\n * The dev session resolved for a single command run. `yield* CurrentSession` always\n * gives a plain `DevSession` — never a wrapper effect to unwrap — so provide whichever\n * layer resolves it (`layer` or the test-only `layerOf(session)`) close to where it's\n * actually used.\n */\nexport class CurrentSession extends Context.Service<\n\tCurrentSession,\n\tDevSession\n>()('devsess/CurrentSession') {\n\t/**\n\t * Resolves the session via `DevSessions#getLatestOrCreate`. Provide this around a\n\t * command's own handler effect, not the whole CLI program: a `Layer`'s build effect\n\t * runs the moment it's provided, regardless of what the effect it wraps ends up\n\t * doing — wrapping `Command.run` itself would create a session for `--help`,\n\t * `--version`, or a bad flag too, none of which ever reach a handler.\n\t */\n\tstatic readonly layer: Layer.Layer<\n\t\tCurrentSession,\n\t\tPlatformError,\n\t\tDevSessions\n\t> = Layer.effect(\n\t\tCurrentSession,\n\t\tEffect.gen(function* () {\n\t\t\tconst sessions = yield* DevSessions;\n\t\t\treturn yield* sessions.getLatestOrCreate;\n\t\t}),\n\t);\n\n\t/** Pins an explicit session instead of resolving one via `DevSessions` — for tests. */\n\tstatic readonly layerOf = (session: DevSession) =>\n\t\tLayer.succeed(CurrentSession, session);\n}\n"],"mappings":";;;;;AAAA,SAAS,SAAS,QAAQ,aAAa;AAUhC,IAAM,iBAAN,MAAM,wBAAuB,QAAQ,QAG1C,EAAE,wBAAwB,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7B,OAAgB,QAIZ,MAAM;AAAA,IACT;AAAA,IACA,OAAO,IAAI,aAAa;AACvB,YAAM,WAAW,OAAO;AACxB,aAAO,OAAO,SAAS;AAAA,IACxB,CAAC;AAAA,EACF;AAAA;AAAA,EAGA,OAAgB,UAAU,CAAC,YAC1B,MAAM,QAAQ,iBAAgB,OAAO;AACvC;","names":[]}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// src/dev-sessions.ts
|
|
2
|
+
import { Array as A, Context, Data, Effect, Layer, Option } from "effect";
|
|
3
|
+
import { FileSystem } from "effect/FileSystem";
|
|
4
|
+
import { Path } from "effect/Path";
|
|
5
|
+
import { generateSlug } from "random-word-slugs";
|
|
6
|
+
var DevSession;
|
|
7
|
+
((DevSession2) => {
|
|
8
|
+
function make(input) {
|
|
9
|
+
return {
|
|
10
|
+
name: input.name,
|
|
11
|
+
lastModifiedAt: input.lastModifiedAt,
|
|
12
|
+
path: (relativePath) => Effect.succeed(input.pathJoin(relativePath)),
|
|
13
|
+
toString: () => input.name
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
DevSession2.make = make;
|
|
17
|
+
})(DevSession || (DevSession = {}));
|
|
18
|
+
var DevSessions = class _DevSessions extends Context.Service()("devsess/DevSessions") {
|
|
19
|
+
/**
|
|
20
|
+
* `DevSessions` explicitly rooted at `rootDir`: `dir`/`path` resolve against `rootDir`
|
|
21
|
+
* itself (e.g. `sessions.path('drizzle')` reaches a project's real `drizzle/` folder),
|
|
22
|
+
* while session directories are namespaced under `<rootDir>/.data/sessions`.
|
|
23
|
+
*
|
|
24
|
+
* Deliberately does *not* also provide `CurrentSession` — a `Layer`'s build effect
|
|
25
|
+
* runs as soon as it's provided, before anything downstream (e.g. `cli.Command.run`'s
|
|
26
|
+
* argv parsing) gets a say. Bundling session resolution in here would create a
|
|
27
|
+
* session for `--help`/`--version`/a bad flag too, since those never reach a command
|
|
28
|
+
* handler at all. Provide `CurrentSession.layer` around the handler itself instead.
|
|
29
|
+
*/
|
|
30
|
+
static layerAt = (rootDir) => buildDevSessionsLayer(rootDir);
|
|
31
|
+
/**
|
|
32
|
+
* `DevSessions.layerAt` rooted at the auto-detected project root — the nearest
|
|
33
|
+
* ancestor of `process.cwd()` containing a `package.json`.
|
|
34
|
+
*/
|
|
35
|
+
static layer = Layer.unwrap(
|
|
36
|
+
Effect.suspend(
|
|
37
|
+
() => Effect.map(findProjectRoot, (rootDir) => _DevSessions.layerAt(rootDir))
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
var ProjectRootNotFoundError = class extends Data.TaggedError(
|
|
42
|
+
"ProjectRootNotFoundError"
|
|
43
|
+
) {
|
|
44
|
+
};
|
|
45
|
+
var findProjectRoot = Effect.gen(function* () {
|
|
46
|
+
const fs = yield* FileSystem;
|
|
47
|
+
const path = yield* Path;
|
|
48
|
+
const startDir = process.cwd();
|
|
49
|
+
const walkUp = (dir) => Effect.gen(function* () {
|
|
50
|
+
if (yield* fs.exists(path.join(dir, "package.json"))) {
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
const parent = path.dirname(dir);
|
|
54
|
+
if (parent === dir) {
|
|
55
|
+
return yield* Effect.fail(
|
|
56
|
+
new ProjectRootNotFoundError({ searchedFrom: startDir })
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return yield* walkUp(parent);
|
|
60
|
+
});
|
|
61
|
+
return yield* walkUp(startDir);
|
|
62
|
+
});
|
|
63
|
+
var buildDevSessionsCore = (sessionsDir) => Effect.gen(function* () {
|
|
64
|
+
const fs = yield* FileSystem;
|
|
65
|
+
const path = yield* Path;
|
|
66
|
+
yield* Effect.logDebug(`DevSessions dir: ${sessionsDir}`);
|
|
67
|
+
const getSessions = Effect.gen(function* () {
|
|
68
|
+
const entries = yield* fs.readDirectory(sessionsDir).pipe(Effect.catch(() => Effect.succeed([])));
|
|
69
|
+
const possibleSessions = yield* Effect.all(
|
|
70
|
+
entries.map(
|
|
71
|
+
(entry) => Effect.gen(function* () {
|
|
72
|
+
const stat = yield* fs.stat(path.join(sessionsDir, entry));
|
|
73
|
+
if (stat.type !== "Directory") return Option.none();
|
|
74
|
+
return Option.some(
|
|
75
|
+
DevSession.make({
|
|
76
|
+
name: entry,
|
|
77
|
+
lastModifiedAt: Option.getOrNull(stat.mtime),
|
|
78
|
+
rootDir: sessionsDir,
|
|
79
|
+
pathJoin: (relativePath) => path.join(sessionsDir, entry, relativePath)
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
})
|
|
83
|
+
),
|
|
84
|
+
{ concurrency: "unbounded" }
|
|
85
|
+
);
|
|
86
|
+
return A.getSomes(possibleSessions);
|
|
87
|
+
});
|
|
88
|
+
const createSession = Effect.gen(function* () {
|
|
89
|
+
const slug = generateSlug(1, { partsOfSpeech: ["noun"] });
|
|
90
|
+
yield* fs.makeDirectory(path.join(sessionsDir, slug), {
|
|
91
|
+
recursive: true
|
|
92
|
+
});
|
|
93
|
+
return DevSession.make({
|
|
94
|
+
name: slug,
|
|
95
|
+
lastModifiedAt: null,
|
|
96
|
+
rootDir: sessionsDir,
|
|
97
|
+
pathJoin: (relativePath) => path.join(sessionsDir, slug, relativePath)
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
const getLatestOrCreate = Effect.gen(function* () {
|
|
101
|
+
yield* fs.makeDirectory(sessionsDir, { recursive: true });
|
|
102
|
+
const sessions = yield* getSessions;
|
|
103
|
+
if (sessions.length > 0) {
|
|
104
|
+
sessions.sort(
|
|
105
|
+
(a, b) => (b.lastModifiedAt?.getTime() ?? 0) - (a.lastModifiedAt?.getTime() ?? 0)
|
|
106
|
+
);
|
|
107
|
+
const latest = sessions[0];
|
|
108
|
+
return latest;
|
|
109
|
+
}
|
|
110
|
+
return yield* createSession;
|
|
111
|
+
});
|
|
112
|
+
return { getSessions, createSession, getLatestOrCreate };
|
|
113
|
+
});
|
|
114
|
+
var buildDevSessionsLayer = (rootDir) => Layer.effect(
|
|
115
|
+
DevSessions,
|
|
116
|
+
Effect.gen(function* () {
|
|
117
|
+
const path = yield* Path;
|
|
118
|
+
const sessionsDir = path.join(rootDir, ".data", "sessions");
|
|
119
|
+
const core = yield* buildDevSessionsCore(sessionsDir);
|
|
120
|
+
return {
|
|
121
|
+
dir: rootDir,
|
|
122
|
+
path: (relativePath) => path.join(rootDir, relativePath),
|
|
123
|
+
...core
|
|
124
|
+
};
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// src/dev/session-state.ts
|
|
129
|
+
import { Data as Data2, Effect as Effect2 } from "effect";
|
|
130
|
+
import { FileSystem as FileSystem2 } from "effect/FileSystem";
|
|
131
|
+
import { Path as Path2 } from "effect/Path";
|
|
132
|
+
import * as S from "effect/Schema";
|
|
133
|
+
var SessionStateError = class extends Data2.TaggedError("SessionStateError") {
|
|
134
|
+
};
|
|
135
|
+
function getPath(session) {
|
|
136
|
+
return session.path("sess.json");
|
|
137
|
+
}
|
|
138
|
+
function read(filePath) {
|
|
139
|
+
return Effect2.gen(function* () {
|
|
140
|
+
const fs = yield* FileSystem2;
|
|
141
|
+
if (!(yield* fs.exists(filePath))) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return yield* fs.readFileString(filePath);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
var SessionState;
|
|
148
|
+
((SessionState2) => {
|
|
149
|
+
function slot(schema) {
|
|
150
|
+
return {
|
|
151
|
+
read: (session) => Effect2.gen(function* () {
|
|
152
|
+
const filePath = yield* getPath(session);
|
|
153
|
+
const content = yield* read(filePath);
|
|
154
|
+
if (content == null) return null;
|
|
155
|
+
return yield* S.decodeEffect(S.fromJsonString(schema))(content).pipe(
|
|
156
|
+
Effect2.catchTag("SchemaError", () => Effect2.succeed(null))
|
|
157
|
+
);
|
|
158
|
+
}),
|
|
159
|
+
write: (session, data) => Effect2.gen(function* () {
|
|
160
|
+
const fs = yield* FileSystem2;
|
|
161
|
+
const path = yield* Path2;
|
|
162
|
+
const filePath = yield* getPath(session);
|
|
163
|
+
yield* fs.makeDirectory(path.dirname(filePath), { recursive: true });
|
|
164
|
+
const existing = yield* read(filePath);
|
|
165
|
+
const parsed = yield* Effect2.try({
|
|
166
|
+
try: () => JSON.parse(existing ?? "{}"),
|
|
167
|
+
catch: (cause) => new SessionStateError({
|
|
168
|
+
message: `Failed to parse ${filePath} as JSON`,
|
|
169
|
+
cause
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
const merged = { ...parsed, ...data };
|
|
173
|
+
yield* fs.writeFileString(filePath, JSON.stringify(merged));
|
|
174
|
+
})
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
SessionState2.slot = slot;
|
|
178
|
+
})(SessionState || (SessionState = {}));
|
|
179
|
+
|
|
180
|
+
// src/dev/sticky-port.ts
|
|
181
|
+
import { Effect as Effect3 } from "effect";
|
|
182
|
+
import * as S2 from "effect/Schema";
|
|
183
|
+
import getPort from "get-port";
|
|
184
|
+
var DEFAULT_NAME = "default";
|
|
185
|
+
var StickyPorts = SessionState.slot(
|
|
186
|
+
S2.Struct({
|
|
187
|
+
ports: S2.optional(S2.Record(S2.String, S2.Number)),
|
|
188
|
+
port: S2.optional(S2.Number)
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
var getStickyPort = (session, options) => Effect3.gen(function* () {
|
|
192
|
+
const name = options?.name ?? DEFAULT_NAME;
|
|
193
|
+
const file = yield* StickyPorts.read(session);
|
|
194
|
+
const ports = file?.ports ?? (file?.port !== void 0 ? { [DEFAULT_NAME]: file.port } : {});
|
|
195
|
+
const preferred = ports[name];
|
|
196
|
+
const exclude = Object.entries(ports).filter((entry) => entry[0] !== name).map((entry) => entry[1]);
|
|
197
|
+
const port = yield* Effect3.promise(
|
|
198
|
+
async () => getPort({
|
|
199
|
+
port: preferred !== void 0 ? [preferred] : void 0,
|
|
200
|
+
...exclude.length > 0 ? { exclude } : {}
|
|
201
|
+
})
|
|
202
|
+
);
|
|
203
|
+
yield* StickyPorts.write(session, { ports: { ...ports, [name]: port } });
|
|
204
|
+
return port;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
DevSessions,
|
|
209
|
+
ProjectRootNotFoundError,
|
|
210
|
+
SessionStateError,
|
|
211
|
+
SessionState,
|
|
212
|
+
getStickyPort
|
|
213
|
+
};
|
|
214
|
+
//# sourceMappingURL=chunk-GX4J6JR3.js.map
|