@effect-atom/atom 0.1.9 → 0.1.10

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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/AtomHttpApi.js",
3
+ "module": "../dist/esm/AtomHttpApi.js",
4
+ "types": "../dist/dts/AtomHttpApi.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Tag = void 0;
7
+ var Reactivity = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect/experimental/Reactivity"));
8
+ var HttpApiClient = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect/platform/HttpApiClient"));
9
+ var Context = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Context"));
10
+ var Data = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Data"));
11
+ var Duration = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Duration"));
12
+ var Effect = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Effect"));
13
+ var Equal = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Equal"));
14
+ var _Function = /*#__PURE__*/require("effect/Function");
15
+ var Hash = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Hash"));
16
+ var Layer = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Layer"));
17
+ var Atom = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./Atom.js"));
18
+ function _interopRequireWildcard(e, t) {
19
+ if ("function" == typeof WeakMap) var r = new WeakMap(),
20
+ n = new WeakMap();
21
+ return (_interopRequireWildcard = function (e, t) {
22
+ if (!t && e && e.__esModule) return e;
23
+ var o,
24
+ i,
25
+ f = {
26
+ __proto__: null,
27
+ default: e
28
+ };
29
+ if (null === e || "object" != typeof e && "function" != typeof e) return f;
30
+ if (o = t ? n : r) {
31
+ if (o.has(e)) return o.get(e);
32
+ o.set(e, f);
33
+ }
34
+ for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
35
+ return f;
36
+ })(e, t);
37
+ }
38
+ /**
39
+ * @since 1.0.0
40
+ */
41
+
42
+ /**
43
+ * @since 1.0.0
44
+ * @category Constructors
45
+ */
46
+ const Tag = () => (id, options) => {
47
+ const self = Context.Tag(id)();
48
+ self.layer = Layer.scoped(self, HttpApiClient.make(options.api, options)).pipe(Layer.provide(options.httpClient));
49
+ self.runtime = Atom.runtime(self.layer);
50
+ const mutationFamily = Atom.family(({
51
+ endpoint,
52
+ group
53
+ }) => self.runtime.fn()(Effect.fnUntraced(function* (opts) {
54
+ const client = yield* self;
55
+ const effect = client[group][endpoint](opts);
56
+ return yield* opts.reactivityKeys ? Reactivity.mutation(effect, opts.reactivityKeys) : effect;
57
+ })));
58
+ self.mutation = (group, endpoint) => mutationFamily(new MutationKey({
59
+ group,
60
+ endpoint
61
+ }));
62
+ const queryFamily = Atom.family(opts => {
63
+ let atom = self.runtime.atom(Effect.flatMap(self, client_ => {
64
+ const client = client_;
65
+ return client[opts.group][opts.endpoint](opts);
66
+ }));
67
+ if (opts.timeToLive) {
68
+ atom = Duration.isFinite(opts.timeToLive) ? Atom.setIdleTTL(atom, opts.timeToLive) : Atom.keepAlive(atom);
69
+ }
70
+ return opts.reactivityKeys ? self.runtime.factory.withReactivity(opts.reactivityKeys)(atom) : atom;
71
+ });
72
+ self.query = (group, endpoint, request) => queryFamily(new QueryKey({
73
+ group,
74
+ endpoint,
75
+ path: request.path && Data.struct(request.path),
76
+ urlParams: request.urlParams && Data.struct(request.urlParams),
77
+ payload: request.payload && Data.struct(request.payload),
78
+ headers: request.headers && Data.struct(request.headers),
79
+ reactivityKeys: request.reactivityKeys ? Data.array(request.reactivityKeys) : undefined,
80
+ timeToLive: request.timeToLive ? Duration.decode(request.timeToLive) : undefined
81
+ }));
82
+ return self;
83
+ };
84
+ exports.Tag = Tag;
85
+ class MutationKey extends Data.Class {
86
+ [Equal.symbol](that) {
87
+ return this.group === that.group && this.endpoint === that.endpoint;
88
+ }
89
+ [Hash.symbol]() {
90
+ return (0, _Function.pipe)(Hash.string(`${this.group}/${this.endpoint}`), Hash.cached(this));
91
+ }
92
+ }
93
+ class QueryKey extends Data.Class {
94
+ [Equal.symbol](that) {
95
+ return this.group === that.group && this.endpoint === that.endpoint && Equal.equals(this.path, that.path) && Equal.equals(this.urlParams, that.urlParams) && Equal.equals(this.payload, that.payload) && Equal.equals(this.headers, that.headers) && Equal.equals(this.reactivityKeys, that.reactivityKeys) && Equal.equals(this.timeToLive, that.timeToLive);
96
+ }
97
+ [Hash.symbol]() {
98
+ return (0, _Function.pipe)(Hash.string(`${this.group}/${this.endpoint}`), Hash.combine(Hash.hash(this.path)), Hash.combine(Hash.hash(this.urlParams)), Hash.combine(Hash.hash(this.payload)), Hash.combine(Hash.hash(this.headers)), Hash.combine(Hash.hash(this.reactivityKeys)), Hash.combine(Hash.hash(this.timeToLive)), Hash.cached(this));
99
+ }
100
+ }
101
+ //# sourceMappingURL=AtomHttpApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AtomHttpApi.js","names":["Reactivity","_interopRequireWildcard","require","HttpApiClient","Context","Data","Duration","Effect","Equal","_Function","Hash","Layer","Atom","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Tag","id","options","self","layer","scoped","make","api","pipe","provide","httpClient","runtime","mutationFamily","family","endpoint","group","fn","fnUntraced","opts","client","effect","reactivityKeys","mutation","MutationKey","queryFamily","atom","flatMap","client_","timeToLive","isFinite","setIdleTTL","keepAlive","factory","withReactivity","query","request","QueryKey","path","struct","urlParams","payload","headers","array","undefined","decode","exports","Class","symbol","that","string","cached","equals","combine","hash"],"sources":["../../src/AtomHttpApi.ts"],"sourcesContent":[null],"mappings":";;;;;;AAGA,IAAAA,UAAA,gBAAAC,uBAAA,cAAAC,OAAA;AAEA,IAAAC,aAAA,gBAAAF,uBAAA,cAAAC,OAAA;AAMA,IAAAE,OAAA,gBAAAH,uBAAA,cAAAC,OAAA;AACA,IAAAG,IAAA,gBAAAJ,uBAAA,cAAAC,OAAA;AACA,IAAAI,QAAA,gBAAAL,uBAAA,cAAAC,OAAA;AACA,IAAAK,MAAA,gBAAAN,uBAAA,cAAAC,OAAA;AACA,IAAAM,KAAA,gBAAAP,uBAAA,cAAAC,OAAA;AACA,IAAAO,SAAA,gBAAAP,OAAA;AACA,IAAAQ,IAAA,gBAAAT,uBAAA,cAAAC,OAAA;AACA,IAAAS,KAAA,gBAAAV,uBAAA,cAAAC,OAAA;AAIA,IAAAU,IAAA,gBAAAX,uBAAA,cAAAC,OAAA;AAAiC,SAAAD,wBAAAY,CAAA,EAAAC,CAAA;EAAA,yBAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAd,uBAAA,YAAAA,CAAAY,CAAA,EAAAC,CAAA;IAAA,KAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA;IAAA,IAAAM,CAAA;MAAAC,CAAA;MAAAC,CAAA;QAAAC,SAAA;QAAAC,OAAA,EAAAV;MAAA;IAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA;IAAA,IAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA;MAAA,IAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA;MAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA;IAAA;IAAA,WAAAP,CAAA,I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AC2E,IAAI,CAAC,IAAI,CAACzB,UAAU,CAAC,CAAC,EACxClD,IAAI,CAACwE,MAAM,CAAC,IAAI,CAAC,CAClB;EACH","ignoreList":[]}
package/dist/cjs/index.js CHANGED
@@ -3,9 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Result = exports.Registry = exports.Hydration = exports.AtomRpc = exports.AtomRef = exports.Atom = void 0;
6
+ exports.Result = exports.Registry = exports.Hydration = exports.AtomRpc = exports.AtomRef = exports.AtomHttpApi = exports.Atom = void 0;
7
7
  var _Atom = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./Atom.js"));
8
8
  exports.Atom = _Atom;
9
+ var _AtomHttpApi = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./AtomHttpApi.js"));
10
+ exports.AtomHttpApi = _AtomHttpApi;
9
11
  var _AtomRef = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./AtomRef.js"));
10
12
  exports.AtomRef = _AtomRef;
11
13
  var _AtomRpc = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./AtomRpc.js"));
@@ -0,0 +1,55 @@
1
+ import type * as HttpApi from "@effect/platform/HttpApi";
2
+ import * as HttpApiClient from "@effect/platform/HttpApiClient";
3
+ import type * as HttpApiEndpoint from "@effect/platform/HttpApiEndpoint";
4
+ import type * as HttpApiGroup from "@effect/platform/HttpApiGroup";
5
+ import type * as HttpApiMiddleware from "@effect/platform/HttpApiMiddleware";
6
+ import type * as HttpClient from "@effect/platform/HttpClient";
7
+ import type * as HttpClientError from "@effect/platform/HttpClientError";
8
+ import * as Context from "effect/Context";
9
+ import * as Duration from "effect/Duration";
10
+ import * as Effect from "effect/Effect";
11
+ import * as Layer from "effect/Layer";
12
+ import type * as ParseResult from "effect/ParseResult";
13
+ import type { ReadonlyRecord } from "effect/Record";
14
+ import type { NoInfer, Simplify } from "effect/Types";
15
+ import * as Atom from "./Atom.js";
16
+ import type * as Result from "./Result.js";
17
+ /**
18
+ * @since 1.0.0
19
+ * @category Models
20
+ */
21
+ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpApiGroup.HttpApiGroup.Any, ApiE, E> extends Context.Tag<Self, Simplify<HttpApiClient.Client<Groups, ApiE, never>>> {
22
+ new (_: never): Context.TagClassShape<Id, Simplify<HttpApiClient.Client<Groups, ApiE, never>>>;
23
+ readonly layer: Layer.Layer<Self, E>;
24
+ readonly runtime: Atom.AtomRuntime<Self, E>;
25
+ readonly mutation: <GroupName extends HttpApiGroup.HttpApiGroup.Name<Groups>, Name extends HttpApiEndpoint.HttpApiEndpoint.Name<HttpApiGroup.HttpApiGroup.Endpoints<Group>>, Group extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.WithName<Groups, GroupName>, Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<HttpApiGroup.HttpApiGroup.Endpoints<Group>, Name>>(group: GroupName, endpoint: Name) => [Endpoint] extends [
26
+ HttpApiEndpoint.HttpApiEndpoint<infer _Name, infer _Method, infer _Path, infer _UrlParams, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _R, infer _RE>
27
+ ] ? Atom.AtomResultFn<Simplify<HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
28
+ readonly reactivityKeys?: ReadonlyArray<unknown> | undefined;
29
+ }>, _Success, _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError> : never;
30
+ readonly query: <GroupName extends HttpApiGroup.HttpApiGroup.Name<Groups>, Name extends HttpApiEndpoint.HttpApiEndpoint.Name<HttpApiGroup.HttpApiGroup.Endpoints<Group>>, Group extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.WithName<Groups, GroupName>, Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<HttpApiGroup.HttpApiGroup.Endpoints<Group>, Name>>(group: Group, endpoint: Name, request: [Endpoint] extends [
31
+ HttpApiEndpoint.HttpApiEndpoint<infer _Name, infer _Method, infer _Path, infer _UrlParams, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _R, infer _RE>
32
+ ] ? Simplify<HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
33
+ readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined;
34
+ readonly timeToLive?: Duration.DurationInput | undefined;
35
+ }> : never) => [Endpoint] extends [
36
+ HttpApiEndpoint.HttpApiEndpoint<infer _Name, infer _Method, infer _Path, infer _UrlParams, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _R, infer _RE>
37
+ ] ? Atom.Atom<Result.Result<_Success, _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError>> : never;
38
+ }
39
+ declare global {
40
+ interface ErrorConstructor {
41
+ stackTraceLimit: number;
42
+ }
43
+ }
44
+ /**
45
+ * @since 1.0.0
46
+ * @category Constructors
47
+ */
48
+ export declare const Tag: <Self>() => <const Id extends string, ApiId extends string, Groups extends HttpApiGroup.HttpApiGroup.Any, ApiE, E, R>(id: Id, options: {
49
+ readonly api: HttpApi.HttpApi<ApiId, Groups, ApiE, R>;
50
+ readonly httpClient: Layer.Layer<HttpApiMiddleware.HttpApiMiddleware.Without<NoInfer<R> | HttpApiGroup.HttpApiGroup.ClientContext<NoInfer<Groups>>> | HttpClient.HttpClient, E>;
51
+ readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
52
+ readonly transformResponse?: ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>) | undefined;
53
+ readonly baseUrl?: URL | string | undefined;
54
+ }) => AtomHttpApiClient<Self, Id, Groups, ApiE, E>;
55
+ //# sourceMappingURL=A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C,UAAU,CAAC,UAAU,EACvB,CAAC,CACF,CAAA;IACD,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;IACjG,QAAQ,CAAC,iBAAiB,CAAC,EACvB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAC9E,SAAS,CAAA;IACb,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAAA;CAC5C,KACA,iBAAiB,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAqF7C,CAAA"}
@@ -2,6 +2,10 @@
2
2
  * @since 1.0.0
3
3
  */
4
4
  export * as Atom from "./Atom.js";
5
+ /**
6
+ * @since 1.0.0
7
+ */
8
+ export * as AtomHttpApi from "./AtomHttpApi.js";
5
9
  /**
6
10
  * @since 1.0.0
7
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;GAEG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;GAEG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;GAEG;AACH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C;;GAEG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;GAEG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Reactivity from "@effect/experimental/Reactivity";
5
+ import * as HttpApiClient from "@effect/platform/HttpApiClient";
6
+ import * as Context from "effect/Context";
7
+ import * as Data from "effect/Data";
8
+ import * as Duration from "effect/Duration";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Equal from "effect/Equal";
11
+ import { pipe } from "effect/Function";
12
+ import * as Hash from "effect/Hash";
13
+ import * as Layer from "effect/Layer";
14
+ import * as Atom from "./Atom.js";
15
+ /**
16
+ * @since 1.0.0
17
+ * @category Constructors
18
+ */
19
+ export const Tag = () => (id, options) => {
20
+ const self = Context.Tag(id)();
21
+ self.layer = Layer.scoped(self, HttpApiClient.make(options.api, options)).pipe(Layer.provide(options.httpClient));
22
+ self.runtime = Atom.runtime(self.layer);
23
+ const mutationFamily = Atom.family(({
24
+ endpoint,
25
+ group
26
+ }) => self.runtime.fn()(Effect.fnUntraced(function* (opts) {
27
+ const client = yield* self;
28
+ const effect = client[group][endpoint](opts);
29
+ return yield* opts.reactivityKeys ? Reactivity.mutation(effect, opts.reactivityKeys) : effect;
30
+ })));
31
+ self.mutation = (group, endpoint) => mutationFamily(new MutationKey({
32
+ group,
33
+ endpoint
34
+ }));
35
+ const queryFamily = Atom.family(opts => {
36
+ let atom = self.runtime.atom(Effect.flatMap(self, client_ => {
37
+ const client = client_;
38
+ return client[opts.group][opts.endpoint](opts);
39
+ }));
40
+ if (opts.timeToLive) {
41
+ atom = Duration.isFinite(opts.timeToLive) ? Atom.setIdleTTL(atom, opts.timeToLive) : Atom.keepAlive(atom);
42
+ }
43
+ return opts.reactivityKeys ? self.runtime.factory.withReactivity(opts.reactivityKeys)(atom) : atom;
44
+ });
45
+ self.query = (group, endpoint, request) => queryFamily(new QueryKey({
46
+ group,
47
+ endpoint,
48
+ path: request.path && Data.struct(request.path),
49
+ urlParams: request.urlParams && Data.struct(request.urlParams),
50
+ payload: request.payload && Data.struct(request.payload),
51
+ headers: request.headers && Data.struct(request.headers),
52
+ reactivityKeys: request.reactivityKeys ? Data.array(request.reactivityKeys) : undefined,
53
+ timeToLive: request.timeToLive ? Duration.decode(request.timeToLive) : undefined
54
+ }));
55
+ return self;
56
+ };
57
+ class MutationKey extends Data.Class {
58
+ [Equal.symbol](that) {
59
+ return this.group === that.group && this.endpoint === that.endpoint;
60
+ }
61
+ [Hash.symbol]() {
62
+ return pipe(Hash.string(`${this.group}/${this.endpoint}`), Hash.cached(this));
63
+ }
64
+ }
65
+ class QueryKey extends Data.Class {
66
+ [Equal.symbol](that) {
67
+ return this.group === that.group && this.endpoint === that.endpoint && Equal.equals(this.path, that.path) && Equal.equals(this.urlParams, that.urlParams) && Equal.equals(this.payload, that.payload) && Equal.equals(this.headers, that.headers) && Equal.equals(this.reactivityKeys, that.reactivityKeys) && Equal.equals(this.timeToLive, that.timeToLive);
68
+ }
69
+ [Hash.symbol]() {
70
+ return pipe(Hash.string(`${this.group}/${this.endpoint}`), Hash.combine(Hash.hash(this.path)), Hash.combine(Hash.hash(this.urlParams)), Hash.combine(Hash.hash(this.payload)), Hash.combine(Hash.hash(this.headers)), Hash.combine(Hash.hash(this.reactivityKeys)), Hash.combine(Hash.hash(this.timeToLive)), Hash.cached(this));
71
+ }
72
+ }
73
+ //# sourceMappingURL=AtomHttpApi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AtomHttpApi.js","names":["Reactivity","HttpApiClient","Context","Data","Duration","Effect","Equal","pipe","Hash","Layer","Atom","Tag","id","options","self","layer","scoped","make","api","provide","httpClient","runtime","mutationFamily","family","endpoint","group","fn","fnUntraced","opts","client","effect","reactivityKeys","mutation","MutationKey","queryFamily","atom","flatMap","client_","timeToLive","isFinite","setIdleTTL","keepAlive","factory","withReactivity","query","request","QueryKey","path","struct","urlParams","payload","headers","array","undefined","decode","Class","symbol","that","string","cached","equals","combine","hash"],"sources":["../../src/AtomHttpApi.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,UAAU,MAAM,iCAAiC;AAE7D,OAAO,KAAKC,aAAa,MAAM,gCAAgC;AAM/D,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAIrC,OAAO,KAAKC,IAAI,MAAM,WAAW;AAkHjC;;;;AAIA,OAAO,MAAMC,GAAG,GACdA,CAAA,KACA,CACEC,EAAM,EACNC,OAcC,KAC+C;EAChD,MAAMC,IAAI,GAA0DZ,OAAO,CAACS,GAAG,CAACC,EAAE,CAAC,EAGzE;EAEVE,IAAI,CAACC,KAAK,GAAGN,KAAK,CAACO,MAAM,CACvBF,IAAI,EACJb,aAAa,CAACgB,IAAI,CAACJ,OAAO,CAACK,GAAG,EAAEL,OAAO,CAAC,CACzC,CAACN,IAAI,CAACE,KAAK,CAACU,OAAO,CAACN,OAAO,CAACO,UAAU,CAAC,CAAyB;EACjEN,IAAI,CAACO,OAAO,GAAGX,IAAI,CAACW,OAAO,CAACP,IAAI,CAACC,KAAK,CAAC;EAEvC,MAA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C,CAAC,EACrC1C,IAAI,CAACqD,OAAO,CAACrD,IAAI,CAACsD,IAAI,CAAC,IAAI,CAACX,OAAO,CAAC,CAAC,EACrC3C,IAAI,CAACqD,OAAO,CAACrD,IAAI,CAACsD,IAAI,CAAC,IAAI,CAAC/B,cAAc,CAAC,CAAC,EAC5CvB,IAAI,CAACqD,OAAO,CAACrD,IAAI,CAACsD,IAAI,CAAC,IAAI,CAACxB,UAAU,CAAC,CAAC,EACxC9B,IAAI,CAACmD,MAAM,CAAC,IAAI,CAAC,CAClB;EACH","ignoreList":[]}
package/dist/esm/index.js CHANGED
@@ -2,6 +2,10 @@
2
2
  * @since 1.0.0
3
3
  */
4
4
  export * as Atom from "./Atom.js";
5
+ /**
6
+ * @since 1.0.0
7
+ */
8
+ export * as AtomHttpApi from "./AtomHttpApi.js";
5
9
  /**
6
10
  * @since 1.0.0
7
11
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Atom","AtomRef","AtomRpc","Hydration","Registry","Result"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,WAAW;AAEjC;;;AAGA,OAAO,KAAKC,OAAO,MAAM,cAAc;AAEvC;;;AAGA,OAAO,KAAKC,OAAO,MAAM,cAAc;AAEvC;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAKC,QAAQ,MAAM,eAAe;AAEzC;;;AAGA,OAAO,KAAKC,MAAM,MAAM,aAAa","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["Atom","AtomHttpApi","AtomRef","AtomRpc","Hydration","Registry","Result"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,IAAI,MAAM,WAAW;AAEjC;;;AAGA,OAAO,KAAKC,WAAW,MAAM,kBAAkB;AAE/C;;;AAGA,OAAO,KAAKC,OAAO,MAAM,cAAc;AAEvC;;;AAGA,OAAO,KAAKC,OAAO,MAAM,cAAc;AAEvC;;;AAGA,OAAO,KAAKC,SAAS,MAAM,gBAAgB;AAE3C;;;AAGA,OAAO,KAAKC,QAAQ,MAAM,eAAe;AAEzC;;;AAGA,OAAO,KAAKC,MAAM,MAAM,aAAa","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-atom/atom",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Reactive toolkit for Effect",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,6 +31,11 @@
31
31
  "import": "./dist/esm/Atom.js",
32
32
  "default": "./dist/cjs/Atom.js"
33
33
  },
34
+ "./AtomHttpApi": {
35
+ "types": "./dist/dts/AtomHttpApi.d.ts",
36
+ "import": "./dist/esm/AtomHttpApi.js",
37
+ "default": "./dist/cjs/AtomHttpApi.js"
38
+ },
34
39
  "./AtomRef": {
35
40
  "types": "./dist/dts/AtomRef.d.ts",
36
41
  "import": "./dist/esm/AtomRef.js",
@@ -62,6 +67,9 @@
62
67
  "Atom": [
63
68
  "./dist/dts/Atom.d.ts"
64
69
  ],
70
+ "AtomHttpApi": [
71
+ "./dist/dts/AtomHttpApi.d.ts"
72
+ ],
65
73
  "AtomRef": [
66
74
  "./dist/dts/AtomRef.d.ts"
67
75
  ],
@@ -0,0 +1,296 @@
1
+ /**
2
+ * @since 1.0.0
3
+ */
4
+ import * as Reactivity from "@effect/experimental/Reactivity"
5
+ import type * as HttpApi from "@effect/platform/HttpApi"
6
+ import * as HttpApiClient from "@effect/platform/HttpApiClient"
7
+ import type * as HttpApiEndpoint from "@effect/platform/HttpApiEndpoint"
8
+ import type * as HttpApiGroup from "@effect/platform/HttpApiGroup"
9
+ import type * as HttpApiMiddleware from "@effect/platform/HttpApiMiddleware"
10
+ import type * as HttpClient from "@effect/platform/HttpClient"
11
+ import type * as HttpClientError from "@effect/platform/HttpClientError"
12
+ import * as Context from "effect/Context"
13
+ import * as Data from "effect/Data"
14
+ import * as Duration from "effect/Duration"
15
+ import * as Effect from "effect/Effect"
16
+ import * as Equal from "effect/Equal"
17
+ import { pipe } from "effect/Function"
18
+ import * as Hash from "effect/Hash"
19
+ import * as Layer from "effect/Layer"
20
+ import type * as ParseResult from "effect/ParseResult"
21
+ import type { ReadonlyRecord } from "effect/Record"
22
+ import type { Mutable, NoInfer, Simplify } from "effect/Types"
23
+ import * as Atom from "./Atom.js"
24
+ import type * as Result from "./Result.js"
25
+
26
+ /**
27
+ * @since 1.0.0
28
+ * @category Models
29
+ */
30
+ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpApiGroup.HttpApiGroup.Any, ApiE, E>
31
+ extends Context.Tag<Self, Simplify<HttpApiClient.Client<Groups, ApiE, never>>>
32
+ {
33
+ new(
34
+ _: never
35
+ ): Context.TagClassShape<Id, Simplify<HttpApiClient.Client<Groups, ApiE, never>>>
36
+
37
+ readonly layer: Layer.Layer<Self, E>
38
+ readonly runtime: Atom.AtomRuntime<Self, E>
39
+
40
+ readonly mutation: <
41
+ GroupName extends HttpApiGroup.HttpApiGroup.Name<Groups>,
42
+ Name extends HttpApiEndpoint.HttpApiEndpoint.Name<HttpApiGroup.HttpApiGroup.Endpoints<Group>>,
43
+ Group extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.WithName<Groups, GroupName>,
44
+ Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<
45
+ HttpApiGroup.HttpApiGroup.Endpoints<Group>,
46
+ Name
47
+ >
48
+ >(
49
+ group: GroupName,
50
+ endpoint: Name
51
+ ) => [Endpoint] extends [
52
+ HttpApiEndpoint.HttpApiEndpoint<
53
+ infer _Name,
54
+ infer _Method,
55
+ infer _Path,
56
+ infer _UrlParams,
57
+ infer _Payload,
58
+ infer _Headers,
59
+ infer _Success,
60
+ infer _Error,
61
+ infer _R,
62
+ infer _RE
63
+ >
64
+ ] ? Atom.AtomResultFn<
65
+ Simplify<
66
+ HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
67
+ readonly reactivityKeys?: ReadonlyArray<unknown> | undefined
68
+ }
69
+ >,
70
+ _Success,
71
+ _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError
72
+ >
73
+ : never
74
+
75
+ readonly query: <
76
+ GroupName extends HttpApiGroup.HttpApiGroup.Name<Groups>,
77
+ Name extends HttpApiEndpoint.HttpApiEndpoint.Name<HttpApiGroup.HttpApiGroup.Endpoints<Group>>,
78
+ Group extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.WithName<Groups, GroupName>,
79
+ Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<
80
+ HttpApiGroup.HttpApiGroup.Endpoints<Group>,
81
+ Name
82
+ >
83
+ >(
84
+ group: Group,
85
+ endpoint: Name,
86
+ request: [Endpoint] extends [
87
+ HttpApiEndpoint.HttpApiEndpoint<
88
+ infer _Name,
89
+ infer _Method,
90
+ infer _Path,
91
+ infer _UrlParams,
92
+ infer _Payload,
93
+ infer _Headers,
94
+ infer _Success,
95
+ infer _Error,
96
+ infer _R,
97
+ infer _RE
98
+ >
99
+ ] ? Simplify<
100
+ HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
101
+ readonly reactivityKeys?:
102
+ | ReadonlyArray<unknown>
103
+ | ReadonlyRecord<string, ReadonlyArray<unknown>>
104
+ | undefined
105
+ readonly timeToLive?: Duration.DurationInput | undefined
106
+ }
107
+ >
108
+ : never
109
+ ) => [Endpoint] extends [
110
+ HttpApiEndpoint.HttpApiEndpoint<
111
+ infer _Name,
112
+ infer _Method,
113
+ infer _Path,
114
+ infer _UrlParams,
115
+ infer _Payload,
116
+ infer _Headers,
117
+ infer _Success,
118
+ infer _Error,
119
+ infer _R,
120
+ infer _RE
121
+ >
122
+ ] ? Atom.Atom<
123
+ Result.Result<
124
+ _Success,
125
+ _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError
126
+ >
127
+ >
128
+ : never
129
+ }
130
+
131
+ declare global {
132
+ interface ErrorConstructor {
133
+ stackTraceLimit: number
134
+ }
135
+ }
136
+
137
+ /**
138
+ * @since 1.0.0
139
+ * @category Constructors
140
+ */
141
+ export const Tag =
142
+ <Self>() =>
143
+ <const Id extends string, ApiId extends string, Groups extends HttpApiGroup.HttpApiGroup.Any, ApiE, E, R>(
144
+ id: Id,
145
+ options: {
146
+ readonly api: HttpApi.HttpApi<ApiId, Groups, ApiE, R>
147
+ readonly httpClient: Layer.Layer<
148
+ | HttpApiMiddleware.HttpApiMiddleware.Without<
149
+ NoInfer<R> | HttpApiGroup.HttpApiGroup.ClientContext<NoInfer<Groups>>
150
+ >
151
+ | HttpClient.HttpClient,
152
+ E
153
+ >
154
+ readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
155
+ readonly transformResponse?:
156
+ | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
157
+ | undefined
158
+ readonly baseUrl?: URL | string | undefined
159
+ }
160
+ ): AtomHttpApiClient<Self, Id, Groups, ApiE, E> => {
161
+ const self: Mutable<AtomHttpApiClient<Self, Id, Groups, ApiE, E>> = Context.Tag(id)<
162
+ Self,
163
+ HttpApiClient.Client<Groups, E, R>
164
+ >() as any
165
+
166
+ self.layer = Layer.scoped(
167
+ self,
168
+ HttpApiClient.make(options.api, options)
169
+ ).pipe(Layer.provide(options.httpClient)) as Layer.Layer<Self, E>
170
+ self.runtime = Atom.runtime(self.layer)
171
+
172
+ const mutationFamily = (Atom.family(({ endpoint, group }: MutationKey) =>
173
+ self.runtime.fn<{
174
+ path: any
175
+ urlParams: any
176
+ headers: any
177
+ payload: any
178
+ reactivityKeys?: ReadonlyArray<unknown> | undefined
179
+ }>()(
180
+ Effect.fnUntraced(function*(opts) {
181
+ const client = (yield* self) as any
182
+ const effect = client[group][endpoint](opts) as Effect.Effect<any>
183
+ return yield* opts.reactivityKeys
184
+ ? Reactivity.mutation(effect, opts.reactivityKeys)
185
+ : effect
186
+ })
187
+ )
188
+ )) as any
189
+
190
+ self.mutation = ((group: string, endpoint: string) =>
191
+ mutationFamily(
192
+ new MutationKey({
193
+ group,
194
+ endpoint
195
+ })
196
+ )) as any
197
+
198
+ const queryFamily = Atom.family(
199
+ (opts: QueryKey) => {
200
+ let atom = self.runtime.atom(Effect.flatMap(self, (client_) => {
201
+ const client = client_ as any
202
+ return client[opts.group][opts.endpoint](opts) as Effect.Effect<any>
203
+ }))
204
+ if (opts.timeToLive) {
205
+ atom = Duration.isFinite(opts.timeToLive)
206
+ ? Atom.setIdleTTL(atom, opts.timeToLive)
207
+ : Atom.keepAlive(atom)
208
+ }
209
+ return opts.reactivityKeys
210
+ ? self.runtime.factory.withReactivity(opts.reactivityKeys)(atom)
211
+ : atom
212
+ }
213
+ )
214
+
215
+ self.query = ((
216
+ group: string,
217
+ endpoint: string,
218
+ request: {
219
+ readonly path?: any
220
+ readonly urlParams?: any
221
+ readonly payload?: any
222
+ readonly headers?: any
223
+ readonly reactivityKeys?: ReadonlyArray<unknown> | undefined
224
+ readonly timeToLive?: Duration.DurationInput | undefined
225
+ }
226
+ ) =>
227
+ queryFamily(
228
+ new QueryKey({
229
+ group,
230
+ endpoint,
231
+ path: request.path && Data.struct(request.path),
232
+ urlParams: request.urlParams && Data.struct(request.urlParams),
233
+ payload: request.payload && Data.struct(request.payload),
234
+ headers: request.headers && Data.struct(request.headers),
235
+ reactivityKeys: request.reactivityKeys
236
+ ? Data.array(request.reactivityKeys)
237
+ : undefined,
238
+ timeToLive: request.timeToLive
239
+ ? Duration.decode(request.timeToLive)
240
+ : undefined
241
+ })
242
+ )) as any
243
+
244
+ return self as AtomHttpApiClient<Self, Id, Groups, ApiE, E>
245
+ }
246
+
247
+ class MutationKey extends Data.Class<{
248
+ group: string
249
+ endpoint: string
250
+ }> {
251
+ [Equal.symbol](that: QueryKey) {
252
+ return this.group === that.group && this.endpoint === that.endpoint
253
+ }
254
+ [Hash.symbol]() {
255
+ return pipe(
256
+ Hash.string(`${this.group}/${this.endpoint}`),
257
+ Hash.cached(this)
258
+ )
259
+ }
260
+ }
261
+
262
+ class QueryKey extends Data.Class<{
263
+ group: string
264
+ endpoint: string
265
+ path: any
266
+ urlParams: any
267
+ headers: any
268
+ payload: any
269
+ reactivityKeys?: ReadonlyArray<unknown> | undefined
270
+ timeToLive?: Duration.Duration | undefined
271
+ }> {
272
+ [Equal.symbol](that: QueryKey) {
273
+ return (
274
+ this.group === that.group &&
275
+ this.endpoint === that.endpoint &&
276
+ Equal.equals(this.path, that.path) &&
277
+ Equal.equals(this.urlParams, that.urlParams) &&
278
+ Equal.equals(this.payload, that.payload) &&
279
+ Equal.equals(this.headers, that.headers) &&
280
+ Equal.equals(this.reactivityKeys, that.reactivityKeys) &&
281
+ Equal.equals(this.timeToLive, that.timeToLive)
282
+ )
283
+ }
284
+ [Hash.symbol]() {
285
+ return pipe(
286
+ Hash.string(`${this.group}/${this.endpoint}`),
287
+ Hash.combine(Hash.hash(this.path)),
288
+ Hash.combine(Hash.hash(this.urlParams)),
289
+ Hash.combine(Hash.hash(this.payload)),
290
+ Hash.combine(Hash.hash(this.headers)),
291
+ Hash.combine(Hash.hash(this.reactivityKeys)),
292
+ Hash.combine(Hash.hash(this.timeToLive)),
293
+ Hash.cached(this)
294
+ )
295
+ }
296
+ }
package/src/index.ts CHANGED
@@ -3,6 +3,11 @@
3
3
  */
4
4
  export * as Atom from "./Atom.js"
5
5
 
6
+ /**
7
+ * @since 1.0.0
8
+ */
9
+ export * as AtomHttpApi from "./AtomHttpApi.js"
10
+
6
11
  /**
7
12
  * @since 1.0.0
8
13
  */