@r_masseater/masseater-utils 0.4.0 → 0.5.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/README.md CHANGED
@@ -22,12 +22,12 @@ vp add @r_masseater/masseater-utils
22
22
 
23
23
  ## Install what a subpath needs
24
24
 
25
- Install the peer dependencies of the subpath you import, and nothing else. A subpath that needs no extra package, such as `plugin-kit` (which bundles what it needs of Effect), installs this package alone.
25
+ Install the peer dependencies of the subpath you import, and nothing else. A subpath that needs no extra package installs this package alone.
26
26
 
27
27
  | Subpath | Install besides this package |
28
28
  | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
29
29
  | `skerm` | `react` |
30
- | `plugin-kit` | Nothing. |
30
+ | `plugin-kit` | `effect` and `@effect/platform-node` |
31
31
  | `model-server` | Nothing. The server installs its inference runtime into the user's cache folder with `npm` on the first call. |
32
32
  | `node-main` | `effect` and `@effect/platform-node` |
33
33
  | `github-workflow` | `effect` |
@@ -0,0 +1,36 @@
1
+ import { Effect, Layer, Runtime, Schema, Stdio } from "effect";
2
+ import { NodeServices } from "@effect/platform-node/NodeServices";
3
+ import { HttpClient } from "effect/http";
4
+ /** @internal */
5
+ type Platform = NodeServices | HttpClient.HttpClient;
6
+ /** @internal */
7
+ type Run<Provided> = <Success, Failure>(program: Effect.Effect<Success, Failure, Platform | Provided>) => void;
8
+ declare const runWithTracingAnd: <Provided, LayerFailure>({ serviceName, services }: Readonly<{
9
+ serviceName: string;
10
+ services: Layer.Layer<Provided, LayerFailure, Platform>;
11
+ }>) => Run<Provided>;
12
+ declare const runWithTracing: (serviceName: string) => Run<never>;
13
+ /** @internal */
14
+ declare const runMainWith: typeof runWithTracingAnd;
15
+ /** @internal */
16
+ declare const runMain: typeof runWithTracing;
17
+ declare const HookBlocked_base: Schema.Class<HookBlocked, Schema.TaggedStruct<"HookBlocked", {
18
+ readonly reason: Schema.String;
19
+ }>, import("effect/Cause").YieldableError & {
20
+ readonly brand: unique symbol;
21
+ }>;
22
+ /** @internal */
23
+ declare class HookBlocked extends HookBlocked_base {
24
+ readonly [Runtime.errorExitCode] = 2;
25
+ readonly [Runtime.errorReported] = false;
26
+ }
27
+ /** @internal */
28
+ declare const blockHook: (reason: string) => Effect.Effect<never, HookBlocked>;
29
+ /** @internal */
30
+ declare const readHookInput: <Codec extends Schema.Top>(schema: Codec) => Effect.Effect<Codec["Type"], Schema.SchemaError, Stdio.Stdio | Codec["DecodingServices"]>;
31
+ /** @internal */
32
+ declare const writeHookOutput: <Codec extends Schema.Top>(schema: Codec) => (value: Codec["Type"]) => Effect.Effect<void, never, Stdio.Stdio | Codec["EncodingServices"]>;
33
+ /** @internal */
34
+ declare const runHook: (serviceName: string) => <Success, Failure>(program: Effect.Effect<Success, Failure, Platform>) => void;
35
+ export { writeHookOutput as a, readHookInput as i, HookBlocked as n, runMain as o, blockHook as r, runMainWith as s, runHook as t };
36
+ //# sourceMappingURL=index-Dq8LlOKp.d.mts.map
@@ -1,19 +1,5 @@
1
- import { Effect, Layer, Option, Runtime, Schema } from "effect";
2
- import { NodeServices } from "@effect/platform-node/NodeServices";
3
- import { HttpClient } from "effect/http";
1
+ import { o as runMain, s as runMainWith } from "./index-Dq8LlOKp.mjs";
2
+ import { Effect, Option } from "effect";
4
3
  export declare const whileParentAlive: (parentPid: Option.Option<string>) => <Value, Failure, Requirements>(program: Effect.Effect<Value, Failure, Requirements>) => Effect.Effect<void, Failure, Requirements>;
5
- /** @internal */
6
- type Platform = NodeServices | HttpClient.HttpClient;
7
- /** @internal */
8
- type Run<Provided> = <Success, Failure>(program: Effect.Effect<Success, Failure, Platform | Provided>) => void;
9
- declare const runWithTracingAnd: <Provided, LayerFailure>({ serviceName, services }: Readonly<{
10
- serviceName: string;
11
- services: Layer.Layer<Provided, LayerFailure, Platform>;
12
- }>) => Run<Provided>;
13
- declare const runWithTracing: (serviceName: string) => Run<never>;
14
- /** @internal */
15
- export declare const runMainWith: typeof runWithTracingAnd;
16
- /** @internal */
17
- export declare const runMain: typeof runWithTracing;
18
- export {};
4
+ export { runMain, runMainWith };
19
5
  //# sourceMappingURL=node-main.d.mts.map
@@ -1,9 +1,5 @@
1
- import { t as flushUsage } from "./usage-meter-CmCceKx1.mjs";
2
- import { Array, Cause, Console, Duration, Effect, Layer, Option, Predicate, Record, Runtime, Schedule, String, pipe } from "effect";
3
- import { runMain as runMain$1 } from "@effect/platform-node/NodeRuntime";
4
- import { layer } from "@effect/platform-node/NodeServices";
5
- import { FetchHttpClient } from "effect/http";
6
- import { Otlp, OtlpSerialization } from "effect/observability";
1
+ import { n as runMainWith, t as runMain } from "./run-main-BD4uT8sr.mjs";
2
+ import { Duration, Effect, Option, Schedule, pipe } from "effect";
7
3
  // src/features/watch-parent/model/parent-process.ts
8
4
  const PARENT_CHECK_INTERVAL = Duration.fromInputUnsafe("2 seconds");
9
5
  const SIGNAL_PROBE = 0;
@@ -19,42 +15,6 @@ const untilExits = (pid) => Effect.sync(() => isAlive(pid)).pipe(Effect.repeat({
19
15
  while: (alive) => alive
20
16
  }), Effect.asVoid);
21
17
  const whileParentAlive = (parentPid) => (program) => Effect.raceFirst(Effect.asVoid(program), pipe(parentPid, Option.map((pid) => untilExits(globalThis.Number(pid))), Option.getOrElse(() => Effect.never)));
22
- // src/features/run-main/model/report.ts
23
- const TAG = "_tag";
24
- const fieldsOf = (failure) => pipe(Option.liftPredicate(failure, Predicate.isObject), Option.map((object) => Record.toEntries({ ...object })), Option.getOrElse(() => []), Array.flatMap(([key, value]) => pipe(Option.liftPredicate(value, Predicate.isString), Option.filter(() => key !== TAG), Option.map((text) => `${key}: ${text}`), Option.toArray)), Array.join(", "));
25
- const describedOf = (reason, name) => pipe(Option.liftPredicate(reason, Cause.isFailReason), Option.map((failed) => fieldsOf(failed.error)), Option.filter(String.isNonEmpty), Option.match({
26
- onNone: () => name,
27
- onSome: (fields) => `${name} (${fields})`
28
- }));
29
- const linesOf = (serviceName) => (reason) => pipe(Cause.prettyErrors(Cause.fromReasons([reason])), Array.map((error) => {
30
- if (String.isEmpty(error.message)) return `${serviceName}: ${describedOf(reason, error.name)}`;
31
- if (Cause.isDieReason(reason)) return `${serviceName}: ${error.name}: ${error.message}`;
32
- return `${serviceName}: ${error.message}`;
33
- }));
34
- /** @internal */
35
- const reportOf = (serviceName) => (cause) => {
36
- if (Cause.hasInterruptsOnly(cause) || !cause.pipe(Cause.squash, Runtime.getErrorReported)) return [];
37
- return pipe(cause.reasons, Array.filter((reason) => !Cause.isInterruptReason(reason)), Array.flatMap(linesOf(serviceName)));
38
- };
39
- // src/features/run-main/model/run-main.ts
40
- const platform = Layer.mergeAll(layer, FetchHttpClient.layer);
41
- const runWithTracingAnd = ({ serviceName, services }) => (program) => {
42
- const tracing = Otlp.layerFromConfig({ resource: { serviceName } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
43
- const provided = Layer.provideMerge(services, platform);
44
- const report = reportOf(serviceName);
45
- runMain$1(Layer.mergeAll(tracing, provided).pipe(Layer.build, Effect.flatMap((context) => Effect.provideContext(program, context)), Effect.scoped, Effect.ensuring(flushUsage), Effect.tapCause((cause) => Effect.forEach(report(cause), (line) => Console.error(line), {
46
- concurrency: 1,
47
- discard: true
48
- }))), { disableErrorReporting: true });
49
- };
50
- const runWithTracing = (serviceName) => runWithTracingAnd({
51
- serviceName,
52
- services: Layer.empty
53
- });
54
- /** @internal */
55
- const runMainWith = runWithTracingAnd;
56
- /** @internal */
57
- const runMain = runWithTracing;
58
18
  export { runMain, runMainWith, whileParentAlive };
59
19
 
60
20
  //# sourceMappingURL=node-main.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-main.mjs","names":["Rec","Arr","Str","nodeServices"],"sources":["../src/features/watch-parent/model/parent-process.ts","../src/features/run-main/model/report.ts","../src/features/run-main/model/run-main.ts"],"sourcesContent":["import { Duration, Effect, Option, Schedule, pipe } from \"effect\";\n\nconst PARENT_CHECK_INTERVAL = Duration.fromInputUnsafe(\"2 seconds\");\nconst SIGNAL_PROBE = 0;\n\nconst isAlive = (pid: number): boolean => {\n try {\n return globalThis.process.kill(pid, SIGNAL_PROBE);\n } catch {\n return false;\n }\n};\n\nconst untilExits = (pid: number): Effect.Effect<void> =>\n Effect.sync(() => isAlive(pid)).pipe(\n Effect.repeat({ schedule: Schedule.spaced(PARENT_CHECK_INTERVAL), while: (alive) => alive }),\n Effect.asVoid,\n );\n\nexport const whileParentAlive =\n (parentPid: Option.Option<string>) =>\n <Value, Failure, Requirements>(\n program: Effect.Effect<Value, Failure, Requirements>,\n ): Effect.Effect<void, Failure, Requirements> =>\n Effect.raceFirst(\n Effect.asVoid(program),\n pipe(\n parentPid,\n Option.map((pid) => untilExits(globalThis.Number(pid))),\n Option.getOrElse(() => Effect.never),\n ),\n );\n","import {\n Array as Arr,\n Cause,\n Option,\n Predicate,\n Record as Rec,\n Runtime,\n String as Str,\n pipe,\n} from \"effect\";\n\nconst TAG = \"_tag\";\n\nconst fieldsOf = (failure: unknown): string =>\n pipe(\n Option.liftPredicate(failure, Predicate.isObject),\n Option.map((object): readonly (readonly [string, unknown])[] => Rec.toEntries({ ...object })),\n Option.getOrElse((): readonly (readonly [string, unknown])[] => []),\n Arr.flatMap(([key, value]) =>\n pipe(\n Option.liftPredicate(value, Predicate.isString),\n Option.filter(() => key !== TAG),\n Option.map((text) => `${key}: ${text}`),\n Option.toArray,\n ),\n ),\n Arr.join(\", \"),\n );\n\nconst describedOf = <Failure>(reason: Cause.Reason<Failure>, name: string): string =>\n pipe(\n Option.liftPredicate(reason, Cause.isFailReason),\n Option.map((failed) => fieldsOf(failed.error)),\n Option.filter(Str.isNonEmpty),\n Option.match({ onNone: () => name, onSome: (fields) => `${name} (${fields})` }),\n );\n\nconst linesOf =\n (serviceName: string) =>\n <Failure>(reason: Cause.Reason<Failure>): readonly string[] =>\n pipe(\n Cause.prettyErrors(Cause.fromReasons([reason])),\n Arr.map((error) => {\n if (Str.isEmpty(error.message)) {\n return `${serviceName}: ${describedOf(reason, error.name)}`;\n }\n if (Cause.isDieReason(reason)) {\n return `${serviceName}: ${error.name}: ${error.message}`;\n }\n return `${serviceName}: ${error.message}`;\n }),\n );\n\n/** @internal */\nexport const reportOf =\n (serviceName: string) =>\n <Failure>(cause: Cause.Cause<Failure>): readonly string[] => {\n if (Cause.hasInterruptsOnly(cause) || !cause.pipe(Cause.squash, Runtime.getErrorReported)) {\n return [];\n }\n return pipe(\n cause.reasons,\n Arr.filter((reason) => !Cause.isInterruptReason(reason)),\n Arr.flatMap(linesOf(serviceName)),\n );\n };\n","import { runMain as nodeRuntimeRunMain } from \"@effect/platform-node/NodeRuntime\";\nimport { layer as nodeServices } from \"@effect/platform-node/NodeServices\";\nimport type { NodeServices } from \"@effect/platform-node/NodeServices\";\nimport { Console, Effect, Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport type { HttpClient } from \"effect/http\";\nimport { Otlp, OtlpSerialization } from \"effect/observability\";\n\nimport { flushUsage } from \"#/shared/lib/usage-meter.ts\";\n\nimport { reportOf } from \"./report.ts\";\n\n/** @internal */\nexport type Platform = NodeServices | HttpClient.HttpClient;\n\n/** @internal */\nexport type Run<Provided> = <Success, Failure>(\n program: Effect.Effect<Success, Failure, Platform | Provided>,\n) => void;\n\nconst platform = Layer.mergeAll(nodeServices, FetchHttpClient.layer);\n\nconst runWithTracingAnd =\n <Provided, LayerFailure>({\n serviceName,\n services,\n }: Readonly<{\n serviceName: string;\n services: Layer.Layer<Provided, LayerFailure, Platform>;\n }>): Run<Provided> =>\n (program) => {\n const tracing = Otlp.layerFromConfig({ resource: { serviceName } }).pipe(\n Layer.provide(OtlpSerialization.layerJson),\n Layer.provide(FetchHttpClient.layer),\n );\n const provided = Layer.provideMerge(services, platform);\n const report = reportOf(serviceName);\n nodeRuntimeRunMain(\n Layer.mergeAll(tracing, provided).pipe(\n Layer.build,\n Effect.flatMap((context) => Effect.provideContext(program, context)),\n Effect.scoped,\n Effect.ensuring(flushUsage),\n Effect.tapCause((cause) =>\n Effect.forEach(report(cause), (line) => Console.error(line), {\n concurrency: 1,\n discard: true,\n }),\n ),\n ),\n { disableErrorReporting: true },\n );\n };\n\nconst runWithTracing = (serviceName: string): Run<never> =>\n runWithTracingAnd({ serviceName, services: Layer.empty });\n\n/** @internal */\nexport const runMainWith = runWithTracingAnd;\n\n/** @internal */\nexport const runMain = runWithTracing;\n"],"mappings":";;;;;;;AAEA,MAAM,wBAAwB,SAAS,gBAAgB,WAAW;AAClE,MAAM,eAAe;AAErB,MAAM,WAAW,QAAyB;CACxC,IAAI;EACF,OAAO,WAAW,QAAQ,KAAK,KAAK,YAAY;CAClD,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,cAAc,QAClB,OAAO,WAAW,QAAQ,GAAG,CAAC,CAAC,CAAC,KAC9B,OAAO,OAAO;CAAE,UAAU,SAAS,OAAO,qBAAqB;CAAG,QAAQ,UAAU;AAAM,CAAC,GAC3F,OAAO,MACT;AAEF,MAAa,oBACV,eAEC,YAEA,OAAO,UACL,OAAO,OAAO,OAAO,GACrB,KACE,WACA,OAAO,KAAK,QAAQ,WAAW,WAAW,OAAO,GAAG,CAAC,CAAC,GACtD,OAAO,gBAAgB,OAAO,KAAK,CACrC,CACF;;ACpBJ,MAAM,MAAM;AAEZ,MAAM,YAAY,YAChB,KACE,OAAO,cAAc,SAAS,UAAU,QAAQ,GAChD,OAAO,KAAK,WAAoDA,OAAI,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC,GAC5F,OAAO,gBAAyD,CAAC,CAAC,GAClEC,MAAI,SAAS,CAAC,KAAK,WACjB,KACE,OAAO,cAAc,OAAO,UAAU,QAAQ,GAC9C,OAAO,aAAa,QAAQ,GAAG,GAC/B,OAAO,KAAK,SAAS,GAAG,IAAI,IAAI,MAAM,GACtC,OAAO,OACT,CACF,GACAA,MAAI,KAAK,IAAI,CACf;AAEF,MAAM,eAAwB,QAA+B,SAC3D,KACE,OAAO,cAAc,QAAQ,MA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E,OAAO,QACP,OAAO,SAAS,UAAU,GAC1B,OAAO,UAAU,UACf,OAAO,QAAQ,OAAO,KAAK,IAAI,SAAS,QAAQ,MAAM,IAAI,GAAG;EAC3D,aAAa;EACb,SAAS;CACX,CAAC,CACH,CACF,GACA,EAAE,uBAAuB,KAAK,CAChC;AACF;AAEF,MAAM,kBAAkB,gBACtB,kBAAkB;CAAE;CAAa,UAAU,MAAM;AAAM,CAAC;;AAG1D,MAAa,cAAc;;AAG3B,MAAa,UAAU"}
1
+ {"version":3,"file":"node-main.mjs","names":[],"sources":["../src/features/watch-parent/model/parent-process.ts"],"sourcesContent":["import { Duration, Effect, Option, Schedule, pipe } from \"effect\";\n\nconst PARENT_CHECK_INTERVAL = Duration.fromInputUnsafe(\"2 seconds\");\nconst SIGNAL_PROBE = 0;\n\nconst isAlive = (pid: number): boolean => {\n try {\n return globalThis.process.kill(pid, SIGNAL_PROBE);\n } catch {\n return false;\n }\n};\n\nconst untilExits = (pid: number): Effect.Effect<void> =>\n Effect.sync(() => isAlive(pid)).pipe(\n Effect.repeat({ schedule: Schedule.spaced(PARENT_CHECK_INTERVAL), while: (alive) => alive }),\n Effect.asVoid,\n );\n\nexport const whileParentAlive =\n (parentPid: Option.Option<string>) =>\n <Value, Failure, Requirements>(\n program: Effect.Effect<Value, Failure, Requirements>,\n ): Effect.Effect<void, Failure, Requirements> =>\n Effect.raceFirst(\n Effect.asVoid(program),\n pipe(\n parentPid,\n Option.map((pid) => untilExits(globalThis.Number(pid))),\n Option.getOrElse(() => Effect.never),\n ),\n );\n"],"mappings":";;;AAEA,MAAM,wBAAwB,SAAS,gBAAgB,WAAW;AAClE,MAAM,eAAe;AAErB,MAAM,WAAW,QAAyB;CACxC,IAAI;EACF,OAAO,WAAW,QAAQ,KAAK,KAAK,YAAY;CAClD,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,cAAc,QAClB,OAAO,WAAW,QAAQ,GAAG,CAAC,CAAC,CAAC,KAC9B,OAAO,OAAO;CAAE,UAAU,SAAS,OAAO,qBAAqB;CAAG,QAAQ,UAAU;AAAM,CAAC,GAC3F,OAAO,MACT;AAEF,MAAa,oBACV,eAEC,YAEA,OAAO,UACL,OAAO,OAAO,OAAO,GACrB,KACE,WACA,OAAO,KAAK,QAAQ,WAAW,WAAW,OAAO,GAAG,CAAC,CAAC,GACtD,OAAO,gBAAgB,OAAO,KAAK,CACrC,CACF"}