alchemy-effect 0.0.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/lib/app.d.ts +23 -0
- package/lib/app.d.ts.map +1 -0
- package/lib/app.js +26 -0
- package/lib/app.js.map +1 -0
- package/lib/apply.d.ts +22 -0
- package/lib/apply.d.ts.map +1 -0
- package/lib/apply.js +191 -0
- package/lib/apply.js.map +1 -0
- package/lib/approve.d.ts +15 -0
- package/lib/approve.d.ts.map +1 -0
- package/lib/approve.js +7 -0
- package/lib/approve.js.map +1 -0
- package/lib/binding.d.ts +58 -0
- package/lib/binding.d.ts.map +1 -0
- package/lib/binding.js +27 -0
- package/lib/binding.js.map +1 -0
- package/lib/capability.d.ts +11 -0
- package/lib/capability.d.ts.map +1 -0
- package/lib/capability.js +1 -0
- package/lib/capability.js.map +1 -0
- package/lib/destroy.d.ts +4 -0
- package/lib/destroy.d.ts.map +1 -0
- package/lib/destroy.js +1 -0
- package/lib/destroy.js.map +1 -0
- package/lib/dot-alchemy.d.ts +9 -0
- package/lib/dot-alchemy.d.ts.map +1 -0
- package/lib/dot-alchemy.js +14 -0
- package/lib/dot-alchemy.js.map +1 -0
- package/lib/env.d.ts +4 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +33 -0
- package/lib/env.js.map +1 -0
- package/lib/event.d.ts +16 -0
- package/lib/event.d.ts.map +1 -0
- package/lib/event.js +1 -0
- package/lib/event.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/lib/phase.d.ts +2 -0
- package/lib/phase.d.ts.map +1 -0
- package/lib/phase.js +1 -0
- package/lib/phase.js.map +1 -0
- package/lib/physical-name.d.ts +4 -0
- package/lib/physical-name.d.ts.map +1 -0
- package/lib/physical-name.js +7 -0
- package/lib/physical-name.js.map +1 -0
- package/lib/plan.d.ts +98 -0
- package/lib/plan.d.ts.map +1 -0
- package/lib/plan.js +228 -0
- package/lib/plan.js.map +1 -0
- package/lib/policy.d.ts +37 -0
- package/lib/policy.d.ts.map +1 -0
- package/lib/policy.js +16 -0
- package/lib/policy.js.map +1 -0
- package/lib/provider.d.ts +57 -0
- package/lib/provider.d.ts.map +1 -0
- package/lib/provider.js +2 -0
- package/lib/provider.js.map +1 -0
- package/lib/reporter.d.ts +8 -0
- package/lib/reporter.d.ts.map +1 -0
- package/lib/reporter.js +4 -0
- package/lib/reporter.js.map +1 -0
- package/lib/resource.d.ts +38 -0
- package/lib/resource.d.ts.map +1 -0
- package/lib/resource.js +25 -0
- package/lib/resource.js.map +1 -0
- package/lib/runtime.d.ts +39 -0
- package/lib/runtime.d.ts.map +1 -0
- package/lib/runtime.js +54 -0
- package/lib/runtime.js.map +1 -0
- package/lib/service.d.ts +33 -0
- package/lib/service.d.ts.map +1 -0
- package/lib/service.js +4 -0
- package/lib/service.js.map +1 -0
- package/lib/state.d.ts +38 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +66 -0
- package/lib/state.js.map +1 -0
- package/package.json +49 -0
- package/src/app.ts +43 -0
- package/src/apply.ts +318 -0
- package/src/approve.ts +13 -0
- package/src/binding.ts +144 -0
- package/src/capability.ts +19 -0
- package/src/destroy.ts +4 -0
- package/src/dot-alchemy.ts +17 -0
- package/src/env.ts +51 -0
- package/src/event.ts +27 -0
- package/src/index.ts +17 -0
- package/src/phase.ts +1 -0
- package/src/physical-name.ts +7 -0
- package/src/plan.ts +470 -0
- package/src/policy.ts +77 -0
- package/src/provider.ts +74 -0
- package/src/reporter.ts +8 -0
- package/src/resource.ts +68 -0
- package/src/runtime.ts +145 -0
- package/src/service.ts +55 -0
- package/src/state.ts +196 -0
package/lib/runtime.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Types } from "effect";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import type { Capability } from "./capability.ts";
|
|
4
|
+
import type { Policy } from "./policy.ts";
|
|
5
|
+
import type { Resource, ResourceTags } from "./resource.ts";
|
|
6
|
+
import type { Service } from "./service.ts";
|
|
7
|
+
export type RuntimeHandler<Inputs extends any[] = any[], Output = any, Err = any, Req = any> = (...inputs: Inputs) => Effect.Effect<Output, Err, Req>;
|
|
8
|
+
export declare namespace RuntimeHandler {
|
|
9
|
+
type Caps<H extends RuntimeHandler | unknown> = Extract<Effect.Effect.Context<ReturnType<Extract<H, RuntimeHandler>>>, Capability>;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace Runtime {
|
|
12
|
+
type Binding<F, Cap> = F extends {
|
|
13
|
+
readonly Binding: unknown;
|
|
14
|
+
} ? (F & {
|
|
15
|
+
readonly cap: Cap;
|
|
16
|
+
})["Binding"] : {
|
|
17
|
+
readonly F: F;
|
|
18
|
+
readonly cap: Types.Contravariant<Cap>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export type AnyRuntime = Runtime<string>;
|
|
22
|
+
export interface RuntimeProps<Run extends Runtime, Req> {
|
|
23
|
+
bindings: Policy<Run, Extract<Req, Capability>>;
|
|
24
|
+
}
|
|
25
|
+
export interface Runtime<Type extends string = string, Handler = unknown, Props = unknown> extends Resource<Type, string, Props, unknown> {
|
|
26
|
+
type: Type;
|
|
27
|
+
props: Props;
|
|
28
|
+
handler: Handler;
|
|
29
|
+
binding: unknown;
|
|
30
|
+
/** @internal phantom */
|
|
31
|
+
capability: unknown;
|
|
32
|
+
<const ID extends string, Inputs extends any[], Output, Err, Req, Handler extends RuntimeHandler<Inputs, Output, Err, Req>>(id: ID, { handle }: {
|
|
33
|
+
handle: Handler;
|
|
34
|
+
}): <const Props extends this["props"]>(props: Props) => Service<ID, this, Handler, Props>;
|
|
35
|
+
}
|
|
36
|
+
export declare const Runtime: <const Type extends string>(type: Type) => <Self extends Runtime>() => Self & {
|
|
37
|
+
provider: ResourceTags<Self>;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
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AAC;CAkE9B,CAAC"}
|
package/lib/runtime.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
export const Runtime = (type) => () => {
|
|
5
|
+
const Tag = Context.Tag(type)();
|
|
6
|
+
const provider = {
|
|
7
|
+
tag: Tag,
|
|
8
|
+
effect: (eff) => Layer.effect(Tag, eff),
|
|
9
|
+
succeed: (service) => Layer.succeed(Tag, service),
|
|
10
|
+
};
|
|
11
|
+
const self = Object.assign((...args) => {
|
|
12
|
+
if (args.length === 1) {
|
|
13
|
+
const [cap] = args;
|
|
14
|
+
const tag = `${type}(${cap})`;
|
|
15
|
+
return class extends Context.Tag(tag)() {
|
|
16
|
+
Capability = cap;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const [id, { handle }] = args;
|
|
21
|
+
return (props) => Object.assign(class {
|
|
22
|
+
constructor() {
|
|
23
|
+
throw new Error("Cannot instantiate a Service directly");
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
kind: "Service",
|
|
27
|
+
type,
|
|
28
|
+
id,
|
|
29
|
+
attr: undefined,
|
|
30
|
+
impl: handle,
|
|
31
|
+
handler: Effect.succeed(handle),
|
|
32
|
+
props,
|
|
33
|
+
runtime: self,
|
|
34
|
+
// TODO(sam): is this right?
|
|
35
|
+
parent: self,
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
provider,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
kind: "Runtime",
|
|
42
|
+
type: type,
|
|
43
|
+
id: undefined,
|
|
44
|
+
capability: undefined,
|
|
45
|
+
provider,
|
|
46
|
+
toString() {
|
|
47
|
+
return `${this.type}(${this.id}${this.capability?.length
|
|
48
|
+
? `, ${this.capability.map((c) => `${c}`).join(", ")}`
|
|
49
|
+
: ""})`;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return self;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAwEtC,MAAM,CAAC,MAAM,OAAO,GAClB,CAA4B,IAAU,EAAE,EAAE,CAC1C,GAEE,EAAE;IACF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;IAChC,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,GAAG;QACR,MAAM,EAAE,CAAC,GAAmD,EAAE,EAAE,CAC9D,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;QACxB,OAAO,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;KACzE,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CACxB,CACE,GAAG,IAKE,EACL,EAAE;QACF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACnB,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,GAAY,CAAC;YACvC,OAAO,KAAM,SAAQ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAgB;gBACnD,UAAU,GAAG,GAAG,CAAC;aAClB,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;YAC9B,OAAO,CAA8C,KAAY,EAAE,EAAE,CACnE,MAAM,CAAC,MAAM,CACX;gBACE;oBACE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBAC3D,CAAC;aACF,EACD;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI;gBACJ,EAAE;gBACF,IAAI,EAAE,SAAU;gBAChB,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAa,CAAC;gBACtC,KAAK;gBACL,OAAO,EAAE,IAAI;gBACb,4BAA4B;gBAC5B,MAAM,EAAE,IAAI;gBACZ,mBAAmB;gBACnB,QAAQ;aACkC,CAC7C,CAAC;QACN,CAAC;IACH,CAAC,EACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAI;QACV,EAAE,EAAE,SAAoB;QACxB,UAAU,EAAE,SAA0B;QACtC,QAAQ;QACR,QAAQ;YACN,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,GAC5B,IAAI,CAAC,UAAU,EAAE,MAAM;gBACrB,CAAC,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACtD,CAAC,CAAC,EACN,GAAG,CAAC;QACN,CAAC;KACF,CACiB,CAAC;IACrB,OAAO,IAAW,CAAC;AACrB,CAAC,CAAC"}
|
package/lib/service.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Effect } from "effect/Effect";
|
|
2
|
+
import type { Capability } from "./capability.ts";
|
|
3
|
+
import type { Resource } from "./resource.ts";
|
|
4
|
+
import type { Runtime, RuntimeHandler, RuntimeProps } from "./runtime.ts";
|
|
5
|
+
export interface IService<ID extends string = string, F extends Runtime = Runtime, Handler extends RuntimeHandler = RuntimeHandler, Props extends RuntimeProps<F, any> = RuntimeProps<F, any>, Attr = (F & {
|
|
6
|
+
props: Props;
|
|
7
|
+
})["attr"]> extends Resource<F["type"], ID, Props, Attr> {
|
|
8
|
+
kind: "Service";
|
|
9
|
+
type: F["type"];
|
|
10
|
+
id: ID;
|
|
11
|
+
runtime: F;
|
|
12
|
+
/**
|
|
13
|
+
* The raw handler function as passed in to the Runtime.
|
|
14
|
+
*
|
|
15
|
+
* @internal phantom type
|
|
16
|
+
*/
|
|
17
|
+
impl: Handler;
|
|
18
|
+
/**
|
|
19
|
+
* An Effect that produces a handler stripped of its Infrastructure-time-only Capabilities.
|
|
20
|
+
*/
|
|
21
|
+
handler: Effect<(...inputs: Parameters<Handler>) => Effect<Effect.Success<ReturnType<Handler>>, Effect.Error<ReturnType<Handler>>, never>, never, Exclude<Effect.Context<ReturnType<Handler>>, Capability>>;
|
|
22
|
+
props: Props;
|
|
23
|
+
/** @internal phantom type of this resource's output attributes */
|
|
24
|
+
attr: Attr;
|
|
25
|
+
/** @internal phantom type of this resource's parent */
|
|
26
|
+
parent: unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface Service<ID extends string = string, F extends Runtime = Runtime, Handler extends RuntimeHandler = RuntimeHandler, Props extends RuntimeProps<F, any> = RuntimeProps<F, any>, Attr = (F & {
|
|
29
|
+
props: Props;
|
|
30
|
+
})["attr"]> extends IService<ID, F, Handler, Props, Attr>, Resource<F["type"], ID, Props, Attr> {
|
|
31
|
+
}
|
|
32
|
+
export declare const isService: (resource: any) => resource is IService;
|
|
33
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,C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YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,EACzD,IAAI,GAAG,CAAC,CAAC,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC,MAAM,CAAC,CACrC,SAAQ,QAAQ,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAC3C,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC;CAAG;AAE3C,eAAO,MAAM,SAAS,GAAI,UAAU,GAAG,KAAG,QAAQ,IAAI,QAErD,CAAC"}
|
package/lib/service.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAoDA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAa,EAAwB,EAAE;IAC/D,OAAO,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC;AACjD,CAAC,CAAC"}
|
package/lib/state.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FileSystem } from "@effect/platform";
|
|
2
|
+
import type { PlatformError } from "@effect/platform/Error";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import { App } from "./app.ts";
|
|
7
|
+
import type { BindNode } from "./plan.ts";
|
|
8
|
+
export type ResourceStatus = "creating" | "created" | "updating" | "updated" | "deleting" | "deleted";
|
|
9
|
+
export type ResourceState = {
|
|
10
|
+
type: string;
|
|
11
|
+
id: string;
|
|
12
|
+
status: ResourceStatus;
|
|
13
|
+
props: any;
|
|
14
|
+
output: any;
|
|
15
|
+
bindings?: BindNode[];
|
|
16
|
+
};
|
|
17
|
+
declare const StateStoreError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
18
|
+
readonly _tag: "StateStoreError";
|
|
19
|
+
} & Readonly<A>;
|
|
20
|
+
export declare class StateStoreError extends StateStoreError_base<{
|
|
21
|
+
message: string;
|
|
22
|
+
}> {
|
|
23
|
+
}
|
|
24
|
+
export interface StateService {
|
|
25
|
+
listApps(): Effect.Effect<string[], StateStoreError, never>;
|
|
26
|
+
listStages(appName?: string): Effect.Effect<string[], StateStoreError, never>;
|
|
27
|
+
get(id: string): Effect.Effect<ResourceState | undefined, StateStoreError, never>;
|
|
28
|
+
set<V extends ResourceState>(id: string, value: V): Effect.Effect<V, StateStoreError, never>;
|
|
29
|
+
delete(id: string): Effect.Effect<void, StateStoreError, never>;
|
|
30
|
+
list(): Effect.Effect<string[], StateStoreError, never>;
|
|
31
|
+
}
|
|
32
|
+
declare const State_base: Context.TagClass<State, "AWS::Lambda::State", StateService>;
|
|
33
|
+
export declare class State extends State_base {
|
|
34
|
+
}
|
|
35
|
+
export declare const localFs: Layer.Layer<State, PlatformError, App | FileSystem.FileSystem>;
|
|
36
|
+
export declare const inMemory: () => Layer.Layer<State, never, never>;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,EAA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AO,gEA+EnB,CAAC;AAEF,eAAO,MAAM,QAAQ,wCAiBpB,CAAC"}
|
package/lib/state.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { FileSystem } from "@effect/platform";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Data from "effect/Data";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { App } from "./app.js";
|
|
8
|
+
import { isResource } from "./resource.js";
|
|
9
|
+
export class StateStoreError extends Data.TaggedError("StateStoreError") {
|
|
10
|
+
}
|
|
11
|
+
export class State extends Context.Tag("AWS::Lambda::State")() {
|
|
12
|
+
}
|
|
13
|
+
// TODO(sam): implement with SQLite3
|
|
14
|
+
export const localFs = Layer.effect(State, Effect.gen(function* () {
|
|
15
|
+
const app = yield* App;
|
|
16
|
+
const fs = yield* FileSystem.FileSystem;
|
|
17
|
+
const dotAlchemy = path.join(process.cwd(), ".alchemy");
|
|
18
|
+
const stateDir = path.join(dotAlchemy, "state");
|
|
19
|
+
const appDir = path.join(stateDir, app.name);
|
|
20
|
+
const stageDir = path.join(appDir, app.stage);
|
|
21
|
+
const fail = (err) => Effect.fail(new StateStoreError({
|
|
22
|
+
message: err.description ?? err.message,
|
|
23
|
+
}));
|
|
24
|
+
const recover = (effect) => effect.pipe(Effect.catchTag("SystemError", (e) => e.reason === "NotFound" ? Effect.succeed(undefined) : fail(e)), Effect.catchTag("BadArgument", (e) => fail(e)));
|
|
25
|
+
const resourceFile = (id) => path.join(stageDir, `${id}.json`);
|
|
26
|
+
yield* fs.makeDirectory(stageDir, { recursive: true });
|
|
27
|
+
return {
|
|
28
|
+
listApps: () => fs.readDirectory(stateDir).pipe(recover, Effect.map((files) => files ?? [])),
|
|
29
|
+
listStages: (appName = app.name) => fs.readDirectory(path.join(stateDir, appName)).pipe(recover, Effect.map((files) => files ?? [])),
|
|
30
|
+
get: (id) => fs.readFile(resourceFile(id)).pipe(Effect.map((file) => JSON.parse(file.toString())), recover),
|
|
31
|
+
set: (id, value) => fs
|
|
32
|
+
.writeFileString(resourceFile(id), JSON.stringify(value, (k, v) => {
|
|
33
|
+
if (isResource(v)) {
|
|
34
|
+
return {
|
|
35
|
+
id: v.id,
|
|
36
|
+
type: v.type,
|
|
37
|
+
props: v.props,
|
|
38
|
+
attr: v.attr,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return v;
|
|
42
|
+
}, 2))
|
|
43
|
+
.pipe(recover, Effect.map(() => value)),
|
|
44
|
+
delete: (id) => fs.remove(resourceFile(id)).pipe(recover),
|
|
45
|
+
list: () => fs.readDirectory(stageDir).pipe(recover, Effect.map((files) => files?.map((file) => file.replace(/\.json$/, "")) ?? [])),
|
|
46
|
+
};
|
|
47
|
+
}));
|
|
48
|
+
export const inMemory = () => {
|
|
49
|
+
const state = new Map();
|
|
50
|
+
return Layer.succeed(State, {
|
|
51
|
+
listApps: () => Effect.succeed([]),
|
|
52
|
+
// oxlint-disable-next-line require-yield
|
|
53
|
+
listStages: (_appName) => Effect.succeed([]),
|
|
54
|
+
get: (id) => Effect.succeed(state.get(id)),
|
|
55
|
+
set: (id, value) => {
|
|
56
|
+
state.set(id, value);
|
|
57
|
+
return Effect.succeed(value);
|
|
58
|
+
},
|
|
59
|
+
delete: (id) => {
|
|
60
|
+
state.delete(id);
|
|
61
|
+
return Effect.succeed(undefined);
|
|
62
|
+
},
|
|
63
|
+
list: () => Effect.succeed(Array.from(state.keys())),
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=state.js.map
|
package/lib/state.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,O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C1B,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,yCAAyC;QACzC,UAAU,EAAE,CAAC,QAAiB,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACrD,GAAG,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClD,GAAG,EAAE,CAAI,EAAU,EAAE,KAAQ,EAAE,EAAE;YAC/B,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACrB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,MAAM,EAAE,CAAC,EAAU,EAAE,EAAE;YACrB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACjB,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;KACrD,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "alchemy-effect",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"author": "Sam Goodwin <sam@alchemy.run>",
|
|
6
|
+
"homepage": "https://alchemy.run",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/alchemy-run/alchemy-effect.git",
|
|
10
|
+
"directory": "alchemy"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"files": [
|
|
15
|
+
"bin",
|
|
16
|
+
"lib",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"bun": "./src/index.ts",
|
|
22
|
+
"import": "./lib/index.js",
|
|
23
|
+
"types": "./src/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@effect/platform-node": "^0.98.3",
|
|
28
|
+
"@effect/platform": "^0.92.1",
|
|
29
|
+
"@types/bun": "latest",
|
|
30
|
+
"@types/node": "latest",
|
|
31
|
+
"effect": "^3.18.4"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@effect/platform": "*",
|
|
35
|
+
"@effect/platform-node": "*",
|
|
36
|
+
"effect": "*"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@effect/platform": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"@effect/platform-node": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/app.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
|
|
6
|
+
export class App extends Context.Tag("App")<
|
|
7
|
+
App,
|
|
8
|
+
{
|
|
9
|
+
name: string;
|
|
10
|
+
stage: string;
|
|
11
|
+
}
|
|
12
|
+
>() {}
|
|
13
|
+
|
|
14
|
+
export class FailedToParseArg extends Data.TaggedError("FailedToParseArg")<{
|
|
15
|
+
message: string;
|
|
16
|
+
arg: string;
|
|
17
|
+
}> {}
|
|
18
|
+
|
|
19
|
+
const parseArg = Effect.fn(function* (arg: string, defaultValue?: string) {
|
|
20
|
+
const i = process.argv.indexOf(arg);
|
|
21
|
+
return i !== -1 && i + 1 < process.argv.length
|
|
22
|
+
? process.argv[i + 1]
|
|
23
|
+
: (defaultValue ??
|
|
24
|
+
(yield* Effect.fail(
|
|
25
|
+
new FailedToParseArg({
|
|
26
|
+
message: `Argument ${arg} not found`,
|
|
27
|
+
arg: arg,
|
|
28
|
+
}),
|
|
29
|
+
)));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const fromArgs = Layer.effect(
|
|
33
|
+
App,
|
|
34
|
+
Effect.gen(function* () {
|
|
35
|
+
return App.of({
|
|
36
|
+
name: yield* parseArg("--app"),
|
|
37
|
+
stage: yield* parseArg("--stage"),
|
|
38
|
+
});
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const app = (input: { name: string; stage: string }) =>
|
|
43
|
+
Layer.succeed(App, App.of(input));
|