@effect/platform 0.46.3 → 0.47.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/PlatformLogger/package.json +6 -0
- package/Socket/package.json +6 -0
- package/dist/cjs/Http/ServerRequest.js +11 -1
- package/dist/cjs/Http/ServerRequest.js.map +1 -1
- package/dist/cjs/PlatformLogger.js +57 -0
- package/dist/cjs/PlatformLogger.js.map +1 -0
- package/dist/cjs/Socket.js +212 -0
- package/dist/cjs/Socket.js.map +1 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/internal/http/serverRequest.js +15 -1
- package/dist/cjs/internal/http/serverRequest.js.map +1 -1
- package/dist/cjs/internal/platformLogger.js +46 -0
- package/dist/cjs/internal/platformLogger.js.map +1 -0
- package/dist/cjs/internal/worker.js.map +1 -1
- package/dist/dts/Http/ServerRequest.d.ts +14 -0
- package/dist/dts/Http/ServerRequest.d.ts.map +1 -1
- package/dist/dts/PlatformLogger.d.ts +41 -0
- package/dist/dts/PlatformLogger.d.ts.map +1 -0
- package/dist/dts/Socket.d.ts +111 -0
- package/dist/dts/Socket.d.ts.map +1 -0
- package/dist/dts/index.d.ts +8 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/platformLogger.d.ts +2 -0
- package/dist/dts/internal/platformLogger.d.ts.map +1 -0
- package/dist/esm/Http/ServerRequest.js +10 -0
- package/dist/esm/Http/ServerRequest.js.map +1 -1
- package/dist/esm/PlatformLogger.js +26 -0
- package/dist/esm/PlatformLogger.js.map +1 -0
- package/dist/esm/Socket.js +166 -0
- package/dist/esm/Socket.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/http/serverRequest.js +13 -0
- package/dist/esm/internal/http/serverRequest.js.map +1 -1
- package/dist/esm/internal/platformLogger.js +15 -0
- package/dist/esm/internal/platformLogger.js.map +1 -0
- package/dist/esm/internal/worker.js.map +1 -1
- package/package.json +20 -3
- package/src/Http/ServerRequest.ts +25 -0
- package/src/PlatformLogger.ts +59 -0
- package/src/Socket.ts +291 -0
- package/src/index.ts +10 -0
- package/src/internal/http/serverRequest.ts +16 -0
- package/src/internal/platformLogger.ts +42 -0
- package/src/internal/worker.ts +5 -1
package/src/index.ts
CHANGED
|
@@ -43,11 +43,21 @@ export * as KeyValueStore from "./KeyValueStore.js"
|
|
|
43
43
|
*/
|
|
44
44
|
export * as Path from "./Path.js"
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
export * as PlatformLogger from "./PlatformLogger.js"
|
|
50
|
+
|
|
46
51
|
/**
|
|
47
52
|
* @since 1.0.0
|
|
48
53
|
*/
|
|
49
54
|
export * as Runtime from "./Runtime.js"
|
|
50
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @since 1.0.0
|
|
58
|
+
*/
|
|
59
|
+
export * as Socket from "./Socket.js"
|
|
60
|
+
|
|
51
61
|
/**
|
|
52
62
|
* @since 1.0.0
|
|
53
63
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type * as ParseResult from "@effect/schema/ParseResult"
|
|
2
2
|
import type * as Schema from "@effect/schema/Schema"
|
|
3
|
+
import * as Channel from "effect/Channel"
|
|
3
4
|
import * as Context from "effect/Context"
|
|
4
5
|
import * as Effect from "effect/Effect"
|
|
5
6
|
import * as Option from "effect/Option"
|
|
@@ -14,6 +15,7 @@ import * as Error from "../../Http/ServerError.js"
|
|
|
14
15
|
import type * as ServerRequest from "../../Http/ServerRequest.js"
|
|
15
16
|
import * as UrlParams from "../../Http/UrlParams.js"
|
|
16
17
|
import type * as Path from "../../Path.js"
|
|
18
|
+
import * as Socket from "../../Socket.js"
|
|
17
19
|
|
|
18
20
|
/** @internal */
|
|
19
21
|
export const TypeId: ServerRequest.TypeId = Symbol.for("@effect/platform/Http/ServerRequest") as ServerRequest.TypeId
|
|
@@ -21,6 +23,12 @@ export const TypeId: ServerRequest.TypeId = Symbol.for("@effect/platform/Http/Se
|
|
|
21
23
|
/** @internal */
|
|
22
24
|
export const serverRequestTag = Context.GenericTag<ServerRequest.ServerRequest>("@effect/platform/Http/ServerRequest")
|
|
23
25
|
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const upgrade = Effect.flatMap(serverRequestTag, (request) => request.upgrade)
|
|
28
|
+
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const upgradeChannel = <IE = never>() => Channel.unwrap(Effect.map(upgrade, Socket.toChannelWith<IE>()))
|
|
31
|
+
|
|
24
32
|
/** @internal */
|
|
25
33
|
export const multipartPersisted = Effect.flatMap(serverRequestTag, (request) => request.multipart)
|
|
26
34
|
|
|
@@ -252,4 +260,12 @@ class ServerRequestImpl implements ServerRequest.ServerRequest {
|
|
|
252
260
|
))
|
|
253
261
|
return this.arrayBufferEffect
|
|
254
262
|
}
|
|
263
|
+
|
|
264
|
+
get upgrade(): Effect.Effect<Socket.Socket, Error.RequestError> {
|
|
265
|
+
return Effect.fail(Error.RequestError({
|
|
266
|
+
request: this,
|
|
267
|
+
reason: "Decode",
|
|
268
|
+
error: "Not an upgradeable ServerRequest"
|
|
269
|
+
}))
|
|
270
|
+
}
|
|
255
271
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { DurationInput } from "effect/Duration"
|
|
5
|
+
import * as Effect from "effect/Effect"
|
|
6
|
+
import { dual } from "effect/Function"
|
|
7
|
+
import * as Logger from "effect/Logger"
|
|
8
|
+
import type * as Scope from "effect/Scope"
|
|
9
|
+
import type { PlatformError } from "../Error.js"
|
|
10
|
+
import * as FileSystem from "../FileSystem.js"
|
|
11
|
+
|
|
12
|
+
/** @internal */
|
|
13
|
+
export const toFile = dual<
|
|
14
|
+
(
|
|
15
|
+
path: string,
|
|
16
|
+
options?: FileSystem.OpenFileOptions & {
|
|
17
|
+
readonly batchWindow?: DurationInput
|
|
18
|
+
}
|
|
19
|
+
) => <Message>(
|
|
20
|
+
self: Logger.Logger<Message, string>
|
|
21
|
+
) => Effect.Effect<Logger.Logger<Message, void>, PlatformError, Scope.Scope | FileSystem.FileSystem>,
|
|
22
|
+
<Message>(
|
|
23
|
+
self: Logger.Logger<Message, string>,
|
|
24
|
+
path: string,
|
|
25
|
+
options?: FileSystem.OpenFileOptions & {
|
|
26
|
+
readonly batchWindow?: DurationInput
|
|
27
|
+
}
|
|
28
|
+
) => Effect.Effect<Logger.Logger<Message, void>, PlatformError, Scope.Scope | FileSystem.FileSystem>
|
|
29
|
+
>(
|
|
30
|
+
(args) => Logger.isLogger(args[0]),
|
|
31
|
+
(self, path, options) =>
|
|
32
|
+
Effect.gen(function*(_) {
|
|
33
|
+
const fs = yield* _(FileSystem.FileSystem)
|
|
34
|
+
const logFile = yield* _(fs.open(path, { flag: "a+", ...options }))
|
|
35
|
+
const encoder = new TextEncoder()
|
|
36
|
+
return yield* _(Logger.batched(
|
|
37
|
+
self,
|
|
38
|
+
options?.batchWindow ?? 1000,
|
|
39
|
+
(output) => Effect.ignore(logFile.write(encoder.encode(output.join("\n") + "\n")))
|
|
40
|
+
))
|
|
41
|
+
})
|
|
42
|
+
)
|
package/src/internal/worker.ts
CHANGED
|
@@ -405,7 +405,11 @@ export const makePoolSerialized = <I extends Schema.TaggedRequest.Any>(
|
|
|
405
405
|
makeSerialized<I>(options),
|
|
406
406
|
Effect.tap((worker) => Effect.sync(() => workers.add(worker))),
|
|
407
407
|
Effect.tap((worker) => Effect.addFinalizer(() => Effect.sync(() => workers.delete(worker)))),
|
|
408
|
-
options.onCreate
|
|
408
|
+
options.onCreate
|
|
409
|
+
? Effect.tap(
|
|
410
|
+
options.onCreate as (worker: Worker.SerializedWorker<I>) => Effect.Effect<void, WorkerError>
|
|
411
|
+
)
|
|
412
|
+
: identity,
|
|
409
413
|
Effect.provideService(WorkerManager, manager)
|
|
410
414
|
)
|
|
411
415
|
const backing = yield* _(
|