@effect-atom/atom 0.1.9 → 0.1.11

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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AAC2E,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: GroupName, 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
+ //# sourceMappingUR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tE,GACC,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;AAgHjC;;;;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;EAEv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O,CAAC,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.11",
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,294 @@
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(_: never): Context.TagClassShape<Id, Simplify<HttpApiClient.Client<Groups, ApiE, never>>>
34
+
35
+ readonly layer: Layer.Layer<Self, E>
36
+ readonly runtime: Atom.AtomRuntime<Self, E>
37
+
38
+ readonly mutation: <
39
+ GroupName extends HttpApiGroup.HttpApiGroup.Name<Groups>,
40
+ Name extends HttpApiEndpoint.HttpApiEndpoint.Name<HttpApiGroup.HttpApiGroup.Endpoints<Group>>,
41
+ Group extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.WithName<Groups, GroupName>,
42
+ Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<
43
+ HttpApiGroup.HttpApiGroup.Endpoints<Group>,
44
+ Name
45
+ >
46
+ >(
47
+ group: GroupName,
48
+ endpoint: Name
49
+ ) => [Endpoint] extends [
50
+ HttpApiEndpoint.HttpApiEndpoint<
51
+ infer _Name,
52
+ infer _Method,
53
+ infer _Path,
54
+ infer _UrlParams,
55
+ infer _Payload,
56
+ infer _Headers,
57
+ infer _Success,
58
+ infer _Error,
59
+ infer _R,
60
+ infer _RE
61
+ >
62
+ ] ? Atom.AtomResultFn<
63
+ Simplify<
64
+ HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
65
+ readonly reactivityKeys?: ReadonlyArray<unknown> | undefined
66
+ }
67
+ >,
68
+ _Success,
69
+ _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError
70
+ >
71
+ : never
72
+
73
+ readonly query: <
74
+ GroupName extends HttpApiGroup.HttpApiGroup.Name<Groups>,
75
+ Name extends HttpApiEndpoint.HttpApiEndpoint.Name<HttpApiGroup.HttpApiGroup.Endpoints<Group>>,
76
+ Group extends HttpApiGroup.HttpApiGroup.Any = HttpApiGroup.HttpApiGroup.WithName<Groups, GroupName>,
77
+ Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<
78
+ HttpApiGroup.HttpApiGroup.Endpoints<Group>,
79
+ Name
80
+ >
81
+ >(
82
+ group: GroupName,
83
+ endpoint: Name,
84
+ request: [Endpoint] extends [
85
+ HttpApiEndpoint.HttpApiEndpoint<
86
+ infer _Name,
87
+ infer _Method,
88
+ infer _Path,
89
+ infer _UrlParams,
90
+ infer _Payload,
91
+ infer _Headers,
92
+ infer _Success,
93
+ infer _Error,
94
+ infer _R,
95
+ infer _RE
96
+ >
97
+ ] ? Simplify<
98
+ HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
99
+ readonly reactivityKeys?:
100
+ | ReadonlyArray<unknown>
101
+ | ReadonlyRecord<string, ReadonlyArray<unknown>>
102
+ | undefined
103
+ readonly timeToLive?: Duration.DurationInput | undefined
104
+ }
105
+ >
106
+ : never
107
+ ) => [Endpoint] extends [
108
+ HttpApiEndpoint.HttpApiEndpoint<
109
+ infer _Name,
110
+ infer _Method,
111
+ infer _Path,
112
+ infer _UrlParams,
113
+ infer _Payload,
114
+ infer _Headers,
115
+ infer _Success,
116
+ infer _Error,
117
+ infer _R,
118
+ infer _RE
119
+ >
120
+ ] ? Atom.Atom<
121
+ Result.Result<
122
+ _Success,
123
+ _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError
124
+ >
125
+ >
126
+ : never
127
+ }
128
+
129
+ declare global {
130
+ interface ErrorConstructor {
131
+ stackTraceLimit: number
132
+ }
133
+ }
134
+
135
+ /**
136
+ * @since 1.0.0
137
+ * @category Constructors
138
+ */
139
+ export const Tag =
140
+ <Self>() =>
141
+ <const Id extends string, ApiId extends string, Groups extends HttpApiGroup.HttpApiGroup.Any, ApiE, E, R>(
142
+ id: Id,
143
+ options: {
144
+ readonly api: HttpApi.HttpApi<ApiId, Groups, ApiE, R>
145
+ readonly httpClient: Layer.Layer<
146
+ | HttpApiMiddleware.HttpApiMiddleware.Without<
147
+ NoInfer<R> | HttpApiGroup.HttpApiGroup.ClientContext<NoInfer<Groups>>
148
+ >
149
+ | HttpClient.HttpClient,
150
+ E
151
+ >
152
+ readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
153
+ readonly transformResponse?:
154
+ | ((effect: Effect.Effect<unknown, unknown>) => Effect.Effect<unknown, unknown>)
155
+ | undefined
156
+ readonly baseUrl?: URL | string | undefined
157
+ }
158
+ ): AtomHttpApiClient<Self, Id, Groups, ApiE, E> => {
159
+ const self: Mutable<AtomHttpApiClient<Self, Id, Groups, ApiE, E>> = Context.Tag(id)<
160
+ Self,
161
+ HttpApiClient.Client<Groups, E, R>
162
+ >() as any
163
+
164
+ self.layer = Layer.scoped(
165
+ self,
166
+ HttpApiClient.make(options.api, options)
167
+ ).pipe(Layer.provide(options.httpClient)) as Layer.Layer<Self, E>
168
+ self.runtime = Atom.runtime(self.layer)
169
+
170
+ const mutationFamily = Atom.family(({ endpoint, group }: MutationKey) =>
171
+ self.runtime.fn<{
172
+ path: any
173
+ urlParams: any
174
+ headers: any
175
+ payload: any
176
+ reactivityKeys?: ReadonlyArray<unknown> | undefined
177
+ }>()(
178
+ Effect.fnUntraced(function*(opts) {
179
+ const client = (yield* self) as any
180
+ const effect = client[group][endpoint](opts) as Effect.Effect<any>
181
+ return yield* opts.reactivityKeys
182
+ ? Reactivity.mutation(effect, opts.reactivityKeys)
183
+ : effect
184
+ })
185
+ )
186
+ ) as any
187
+
188
+ self.mutation = ((group: string, endpoint: string) =>
189
+ mutationFamily(
190
+ new MutationKey({
191
+ group,
192
+ endpoint
193
+ })
194
+ )) as any
195
+
196
+ const queryFamily = Atom.family((opts: QueryKey) => {
197
+ let atom = self.runtime.atom(
198
+ Effect.flatMap(self, (client_) => {
199
+ const client = client_ as any
200
+ return client[opts.group][opts.endpoint](opts) as Effect.Effect<any>
201
+ })
202
+ )
203
+ if (opts.timeToLive) {
204
+ atom = Duration.isFinite(opts.timeToLive)
205
+ ? Atom.setIdleTTL(atom, opts.timeToLive)
206
+ : Atom.keepAlive(atom)
207
+ }
208
+ return opts.reactivityKeys
209
+ ? self.runtime.factory.withReactivity(opts.reactivityKeys)(atom)
210
+ : atom
211
+ })
212
+
213
+ self.query = ((
214
+ group: string,
215
+ endpoint: string,
216
+ request: {
217
+ readonly path?: any
218
+ readonly urlParams?: any
219
+ readonly payload?: any
220
+ readonly headers?: any
221
+ readonly reactivityKeys?: ReadonlyArray<unknown> | undefined
222
+ readonly timeToLive?: Duration.DurationInput | undefined
223
+ }
224
+ ) =>
225
+ queryFamily(
226
+ new QueryKey({
227
+ group,
228
+ endpoint,
229
+ path: request.path && Data.struct(request.path),
230
+ urlParams: request.urlParams && Data.struct(request.urlParams),
231
+ payload: request.payload && Data.struct(request.payload),
232
+ headers: request.headers && Data.struct(request.headers),
233
+ reactivityKeys: request.reactivityKeys
234
+ ? Data.array(request.reactivityKeys)
235
+ : undefined,
236
+ timeToLive: request.timeToLive
237
+ ? Duration.decode(request.timeToLive)
238
+ : undefined
239
+ })
240
+ )) as any
241
+
242
+ return self as AtomHttpApiClient<Self, Id, Groups, ApiE, E>
243
+ }
244
+
245
+ class MutationKey extends Data.Class<{
246
+ group: string
247
+ endpoint: string
248
+ }> {
249
+ [Equal.symbol](that: QueryKey) {
250
+ return this.group === that.group && this.endpoint === that.endpoint
251
+ }
252
+ [Hash.symbol]() {
253
+ return pipe(
254
+ Hash.string(`${this.group}/${this.endpoint}`),
255
+ Hash.cached(this)
256
+ )
257
+ }
258
+ }
259
+
260
+ class QueryKey extends Data.Class<{
261
+ group: string
262
+ endpoint: string
263
+ path: any
264
+ urlParams: any
265
+ headers: any
266
+ payload: any
267
+ reactivityKeys?: ReadonlyArray<unknown> | undefined
268
+ timeToLive?: Duration.Duration | undefined
269
+ }> {
270
+ [Equal.symbol](that: QueryKey) {
271
+ return (
272
+ this.group === that.group &&
273
+ this.endpoint === that.endpoint &&
274
+ Equal.equals(this.path, that.path) &&
275
+ Equal.equals(this.urlParams, that.urlParams) &&
276
+ Equal.equals(this.payload, that.payload) &&
277
+ Equal.equals(this.headers, that.headers) &&
278
+ Equal.equals(this.reactivityKeys, that.reactivityKeys) &&
279
+ Equal.equals(this.timeToLive, that.timeToLive)
280
+ )
281
+ }
282
+ [Hash.symbol]() {
283
+ return pipe(
284
+ Hash.string(`${this.group}/${this.endpoint}`),
285
+ Hash.combine(Hash.hash(this.path)),
286
+ Hash.combine(Hash.hash(this.urlParams)),
287
+ Hash.combine(Hash.hash(this.payload)),
288
+ Hash.combine(Hash.hash(this.headers)),
289
+ Hash.combine(Hash.hash(this.reactivityKeys)),
290
+ Hash.combine(Hash.hash(this.timeToLive)),
291
+ Hash.cached(this)
292
+ )
293
+ }
294
+ }
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
  */