@effect-atom/atom 0.4.5 → 0.4.6
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/dist/cjs/AtomHttpApi.js +14 -8
- package/dist/cjs/AtomHttpApi.js.map +1 -1
- package/dist/dts/AtomHttpApi.d.ts +8 -5
- package/dist/dts/AtomHttpApi.d.ts.map +1 -1
- package/dist/esm/AtomHttpApi.js +14 -8
- package/dist/esm/AtomHttpApi.js.map +1 -1
- package/package.json +1 -1
- package/src/AtomHttpApi.ts +30 -12
package/dist/cjs/AtomHttpApi.js
CHANGED
|
@@ -50,15 +50,20 @@ const Tag = () => (id, options) => {
|
|
|
50
50
|
self.runtime = Atom.runtime(self.layer);
|
|
51
51
|
const mutationFamily = Atom.family(({
|
|
52
52
|
endpoint,
|
|
53
|
-
group
|
|
53
|
+
group,
|
|
54
|
+
withResponse
|
|
54
55
|
}) => self.runtime.fn()(Effect.fnUntraced(function* (opts) {
|
|
55
56
|
const client = yield* self;
|
|
56
|
-
const effect = client[group][endpoint](
|
|
57
|
+
const effect = client[group][endpoint]({
|
|
58
|
+
...opts,
|
|
59
|
+
withResponse
|
|
60
|
+
});
|
|
57
61
|
return yield* opts.reactivityKeys ? Reactivity.mutation(effect, opts.reactivityKeys) : effect;
|
|
58
62
|
})));
|
|
59
|
-
self.mutation = (group, endpoint) => mutationFamily(new MutationKey({
|
|
63
|
+
self.mutation = (group, endpoint, options) => mutationFamily(new MutationKey({
|
|
60
64
|
group,
|
|
61
|
-
endpoint
|
|
65
|
+
endpoint,
|
|
66
|
+
withResponse: options?.withResponse ?? false
|
|
62
67
|
}));
|
|
63
68
|
const queryFamily = Atom.family(opts => {
|
|
64
69
|
let atom = self.runtime.atom(Effect.flatMap(self, client_ => {
|
|
@@ -77,6 +82,7 @@ const Tag = () => (id, options) => {
|
|
|
77
82
|
urlParams: request.urlParams && Data.struct(request.urlParams),
|
|
78
83
|
payload: request.payload && Data.struct(request.payload),
|
|
79
84
|
headers: request.headers && Data.struct(request.headers),
|
|
85
|
+
withResponse: request.withResponse ?? false,
|
|
80
86
|
reactivityKeys: request.reactivityKeys ? (0, _data.wrapReactivityKeys)(request.reactivityKeys) : undefined,
|
|
81
87
|
timeToLive: request.timeToLive ? Duration.decode(request.timeToLive) : undefined
|
|
82
88
|
}));
|
|
@@ -85,18 +91,18 @@ const Tag = () => (id, options) => {
|
|
|
85
91
|
exports.Tag = Tag;
|
|
86
92
|
class MutationKey extends Data.Class {
|
|
87
93
|
[Equal.symbol](that) {
|
|
88
|
-
return this.group === that.group && this.endpoint === that.endpoint;
|
|
94
|
+
return this.group === that.group && this.endpoint === that.endpoint && this.withResponse === that.withResponse;
|
|
89
95
|
}
|
|
90
96
|
[Hash.symbol]() {
|
|
91
|
-
return (0, _Function.pipe)(Hash.string(`${this.group}/${this.endpoint}`), Hash.cached(this));
|
|
97
|
+
return (0, _Function.pipe)(Hash.string(`${this.group}/${this.endpoint}/${this.withResponse}`), Hash.cached(this));
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
class QueryKey extends Data.Class {
|
|
95
101
|
[Equal.symbol](that) {
|
|
96
|
-
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);
|
|
102
|
+
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.withResponse, that.withResponse) && Equal.equals(this.reactivityKeys, that.reactivityKeys) && Equal.equals(this.timeToLive, that.timeToLive);
|
|
97
103
|
}
|
|
98
104
|
[Hash.symbol]() {
|
|
99
|
-
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));
|
|
105
|
+
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.withResponse)), Hash.combine(Hash.hash(this.reactivityKeys)), Hash.combine(Hash.hash(this.timeToLive)), Hash.cached(this));
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
//# sourceMappingURL=AtomHttpApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomHttpApi.js","names":["Reactivity","_interopRequireWildcard","require","HttpApiClient","Context","Data","Duration","Effect","Equal","_Function","Hash","Layer","Atom","_data","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","wrapReactivityKeys","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;
|
|
1
|
+
{"version":3,"file":"AtomHttpApi.js","names":["Reactivity","_interopRequireWildcard","require","HttpApiClient","Context","Data","Duration","Effect","Equal","_Function","Hash","Layer","Atom","_data","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","withResponse","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","wrapReactivityKeys","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;AAOA,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;AACA,IAAAW,KAAA,gBAAAX,OAAA;AAAuD,SAAAD,wBAAAa,CAAA,EAAAC,CAAA;EAAA,yBAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAf,uBAAA,YAAAA,CAAAa,CAAA,EAAAC,CAAA;IAAA,KAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA;IAAA,IAAAM,CAAA;MAAAC,CAAA;MAAAC,CAAA;QAAAC,SAAA;QAA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AxE,SAAA,CAAAgC,IAAI,EACT/B,IAAI,CAACyE,MAAM,CAAC,GAAG,IAAI,CAACnC,KAAK,IAAI,IAAI,CAACD,QAAQ,EAAE,CAAC,EAC7CrC,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAAChB,IAAI,CAAC,CAAC,EAClC7D,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAACd,SAAS,CAAC,CAAC,EACvC/D,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAACb,OAAO,CAAC,CAAC,EACrChE,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAACZ,OAAO,CAAC,CAAC,EACrCjE,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAACtC,YAAY,CAAC,CAAC,EAC1CvC,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAAChC,cAAc,CAAC,CAAC,EAC5C7C,IAAI,CAAC4E,OAAO,CAAC5E,IAAI,CAAC6E,IAAI,CAAC,IAAI,CAACzB,UAAU,CAAC,CAAC,EACxCpD,IAAI,CAAC0E,MAAM,CAAC,IAAI,CAAC,CAClB;EACH","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@ import type * as HttpApiGroup from "@effect/platform/HttpApiGroup";
|
|
|
5
5
|
import type * as HttpApiMiddleware from "@effect/platform/HttpApiMiddleware";
|
|
6
6
|
import type * as HttpClient from "@effect/platform/HttpClient";
|
|
7
7
|
import type * as HttpClientError from "@effect/platform/HttpClientError";
|
|
8
|
+
import type { HttpClientResponse } from "@effect/platform/HttpClientResponse";
|
|
8
9
|
import * as Context from "effect/Context";
|
|
9
10
|
import * as Duration from "effect/Duration";
|
|
10
11
|
import * as Effect from "effect/Effect";
|
|
@@ -22,19 +23,21 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
22
23
|
new (_: never): Context.TagClassShape<Id, Simplify<HttpApiClient.Client<Groups, ApiE, never>>>;
|
|
23
24
|
readonly layer: Layer.Layer<Self, E>;
|
|
24
25
|
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
|
|
26
|
+
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>, const WithResponse extends boolean = false>(group: GroupName, endpoint: Name, options?: {
|
|
27
|
+
readonly withResponse?: WithResponse | undefined;
|
|
28
|
+
}) => [Endpoint] extends [
|
|
26
29
|
HttpApiEndpoint.HttpApiEndpoint<infer _Name, infer _Method, infer _Path, infer _UrlParams, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _R, infer _RE>
|
|
27
30
|
] ? Atom.AtomResultFn<Simplify<HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, false> & {
|
|
28
31
|
readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, 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
|
|
32
|
+
}>, WithResponse extends true ? [_Success, HttpClientResponse] : _Success, _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError> : never;
|
|
33
|
+
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>, const WithResponse extends boolean = false>(group: GroupName, endpoint: Name, request: [Endpoint] extends [
|
|
31
34
|
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,
|
|
35
|
+
] ? Simplify<HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, WithResponse> & {
|
|
33
36
|
readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined;
|
|
34
37
|
readonly timeToLive?: Duration.DurationInput | undefined;
|
|
35
38
|
}> : never) => [Endpoint] extends [
|
|
36
39
|
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;
|
|
40
|
+
] ? Atom.Atom<Result.Result<WithResponse extends true ? [_Success, HttpClientResponse] : _Success, _Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError>> : never;
|
|
38
41
|
}
|
|
39
42
|
declare global {
|
|
40
43
|
interface ErrorConstructor {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomHttpApi.d.ts","sourceRoot":"","sources":["../../src/AtomHttpApi.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,OAAO,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,aAAa,MAAM,gCAAgC,CAAA;AAC/D,OAAO,KAAK,KAAK,eAAe,MAAM,kCAAkC,CAAA;AACxE,OAAO,KAAK,KAAK,YAAY,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,KAAK,iBAAiB,MAAM,oCAAoC,CAAA;AAC5E,OAAO,KAAK,KAAK,UAAU,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,KAAK,eAAe,MAAM,kCAAkC,CAAA;AACxE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,e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AAS,MAAM,EAAE,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,YAAY,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EACtG,IAAI,EAAE,EACN,SAAS;IACP,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACrD,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,KAAK,CAC5B,iBAAiB,CAAC,iBAAiB,CAAC,OAAO,CAC3C,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CACtE,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,CA6F7C,CAAA"}
|
package/dist/esm/AtomHttpApi.js
CHANGED
|
@@ -23,15 +23,20 @@ export const Tag = () => (id, options) => {
|
|
|
23
23
|
self.runtime = Atom.runtime(self.layer);
|
|
24
24
|
const mutationFamily = Atom.family(({
|
|
25
25
|
endpoint,
|
|
26
|
-
group
|
|
26
|
+
group,
|
|
27
|
+
withResponse
|
|
27
28
|
}) => self.runtime.fn()(Effect.fnUntraced(function* (opts) {
|
|
28
29
|
const client = yield* self;
|
|
29
|
-
const effect = client[group][endpoint](
|
|
30
|
+
const effect = client[group][endpoint]({
|
|
31
|
+
...opts,
|
|
32
|
+
withResponse
|
|
33
|
+
});
|
|
30
34
|
return yield* opts.reactivityKeys ? Reactivity.mutation(effect, opts.reactivityKeys) : effect;
|
|
31
35
|
})));
|
|
32
|
-
self.mutation = (group, endpoint) => mutationFamily(new MutationKey({
|
|
36
|
+
self.mutation = (group, endpoint, options) => mutationFamily(new MutationKey({
|
|
33
37
|
group,
|
|
34
|
-
endpoint
|
|
38
|
+
endpoint,
|
|
39
|
+
withResponse: options?.withResponse ?? false
|
|
35
40
|
}));
|
|
36
41
|
const queryFamily = Atom.family(opts => {
|
|
37
42
|
let atom = self.runtime.atom(Effect.flatMap(self, client_ => {
|
|
@@ -50,6 +55,7 @@ export const Tag = () => (id, options) => {
|
|
|
50
55
|
urlParams: request.urlParams && Data.struct(request.urlParams),
|
|
51
56
|
payload: request.payload && Data.struct(request.payload),
|
|
52
57
|
headers: request.headers && Data.struct(request.headers),
|
|
58
|
+
withResponse: request.withResponse ?? false,
|
|
53
59
|
reactivityKeys: request.reactivityKeys ? wrapReactivityKeys(request.reactivityKeys) : undefined,
|
|
54
60
|
timeToLive: request.timeToLive ? Duration.decode(request.timeToLive) : undefined
|
|
55
61
|
}));
|
|
@@ -57,18 +63,18 @@ export const Tag = () => (id, options) => {
|
|
|
57
63
|
};
|
|
58
64
|
class MutationKey extends Data.Class {
|
|
59
65
|
[Equal.symbol](that) {
|
|
60
|
-
return this.group === that.group && this.endpoint === that.endpoint;
|
|
66
|
+
return this.group === that.group && this.endpoint === that.endpoint && this.withResponse === that.withResponse;
|
|
61
67
|
}
|
|
62
68
|
[Hash.symbol]() {
|
|
63
|
-
return pipe(Hash.string(`${this.group}/${this.endpoint}`), Hash.cached(this));
|
|
69
|
+
return pipe(Hash.string(`${this.group}/${this.endpoint}/${this.withResponse}`), Hash.cached(this));
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
class QueryKey extends Data.Class {
|
|
67
73
|
[Equal.symbol](that) {
|
|
68
|
-
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);
|
|
74
|
+
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.withResponse, that.withResponse) && Equal.equals(this.reactivityKeys, that.reactivityKeys) && Equal.equals(this.timeToLive, that.timeToLive);
|
|
69
75
|
}
|
|
70
76
|
[Hash.symbol]() {
|
|
71
|
-
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));
|
|
77
|
+
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.withResponse)), Hash.combine(Hash.hash(this.reactivityKeys)), Hash.combine(Hash.hash(this.timeToLive)), Hash.cached(this));
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
//# sourceMappingURL=AtomHttpApi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AtomHttpApi.js","names":["Reactivity","HttpApiClient","Context","Data","Duration","Effect","Equal","pipe","Hash","Layer","Atom","wrapReactivityKeys","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","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;
|
|
1
|
+
{"version":3,"file":"AtomHttpApi.js","names":["Reactivity","HttpApiClient","Context","Data","Duration","Effect","Equal","pipe","Hash","Layer","Atom","wrapReactivityKeys","Tag","id","options","self","layer","scoped","make","api","provide","httpClient","runtime","mutationFamily","family","endpoint","group","withResponse","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","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;AAO/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;AACjC,SAASC,kBAAkB,QAAQ,oBAAoB;AAqHvD;;;;AAIA,OAAO,MAAMC,GAAG,GACd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@ import type * as HttpApiGroup from "@effect/platform/HttpApiGroup"
|
|
|
9
9
|
import type * as HttpApiMiddleware from "@effect/platform/HttpApiMiddleware"
|
|
10
10
|
import type * as HttpClient from "@effect/platform/HttpClient"
|
|
11
11
|
import type * as HttpClientError from "@effect/platform/HttpClientError"
|
|
12
|
+
import type { HttpClientResponse } from "@effect/platform/HttpClientResponse"
|
|
12
13
|
import * as Context from "effect/Context"
|
|
13
14
|
import * as Data from "effect/Data"
|
|
14
15
|
import * as Duration from "effect/Duration"
|
|
@@ -43,10 +44,14 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
43
44
|
Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<
|
|
44
45
|
HttpApiGroup.HttpApiGroup.Endpoints<Group>,
|
|
45
46
|
Name
|
|
46
|
-
|
|
47
|
+
>,
|
|
48
|
+
const WithResponse extends boolean = false
|
|
47
49
|
>(
|
|
48
50
|
group: GroupName,
|
|
49
|
-
endpoint: Name
|
|
51
|
+
endpoint: Name,
|
|
52
|
+
options?: {
|
|
53
|
+
readonly withResponse?: WithResponse | undefined
|
|
54
|
+
}
|
|
50
55
|
) => [Endpoint] extends [
|
|
51
56
|
HttpApiEndpoint.HttpApiEndpoint<
|
|
52
57
|
infer _Name,
|
|
@@ -66,7 +71,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
66
71
|
readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
67
72
|
}
|
|
68
73
|
>,
|
|
69
|
-
_Success,
|
|
74
|
+
WithResponse extends true ? [_Success, HttpClientResponse] : _Success,
|
|
70
75
|
_Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError
|
|
71
76
|
>
|
|
72
77
|
: never
|
|
@@ -78,7 +83,8 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
78
83
|
Endpoint extends HttpApiEndpoint.HttpApiEndpoint.Any = HttpApiEndpoint.HttpApiEndpoint.WithName<
|
|
79
84
|
HttpApiGroup.HttpApiGroup.Endpoints<Group>,
|
|
80
85
|
Name
|
|
81
|
-
|
|
86
|
+
>,
|
|
87
|
+
const WithResponse extends boolean = false
|
|
82
88
|
>(
|
|
83
89
|
group: GroupName,
|
|
84
90
|
endpoint: Name,
|
|
@@ -96,7 +102,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
96
102
|
infer _RE
|
|
97
103
|
>
|
|
98
104
|
] ? Simplify<
|
|
99
|
-
HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers,
|
|
105
|
+
HttpApiEndpoint.HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, WithResponse> & {
|
|
100
106
|
readonly reactivityKeys?:
|
|
101
107
|
| ReadonlyArray<unknown>
|
|
102
108
|
| ReadonlyRecord<string, ReadonlyArray<unknown>>
|
|
@@ -120,7 +126,7 @@ export interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpA
|
|
|
120
126
|
>
|
|
121
127
|
] ? Atom.Atom<
|
|
122
128
|
Result.Result<
|
|
123
|
-
_Success,
|
|
129
|
+
WithResponse extends true ? [_Success, HttpClientResponse] : _Success,
|
|
124
130
|
_Error | HttpApiGroup.HttpApiGroup.Error<Group> | E | HttpClientError.HttpClientError | ParseResult.ParseError
|
|
125
131
|
>
|
|
126
132
|
>
|
|
@@ -168,7 +174,7 @@ export const Tag =
|
|
|
168
174
|
).pipe(Layer.provide(options.httpClient)) as Layer.Layer<Self, E>
|
|
169
175
|
self.runtime = Atom.runtime(self.layer)
|
|
170
176
|
|
|
171
|
-
const mutationFamily = Atom.family(({ endpoint, group }: MutationKey) =>
|
|
177
|
+
const mutationFamily = Atom.family(({ endpoint, group, withResponse }: MutationKey) =>
|
|
172
178
|
self.runtime.fn<{
|
|
173
179
|
path: any
|
|
174
180
|
urlParams: any
|
|
@@ -178,7 +184,10 @@ export const Tag =
|
|
|
178
184
|
}>()(
|
|
179
185
|
Effect.fnUntraced(function*(opts) {
|
|
180
186
|
const client = (yield* self) as any
|
|
181
|
-
const effect = client[group][endpoint](
|
|
187
|
+
const effect = client[group][endpoint]({
|
|
188
|
+
...opts,
|
|
189
|
+
withResponse
|
|
190
|
+
}) as Effect.Effect<any>
|
|
182
191
|
return yield* opts.reactivityKeys
|
|
183
192
|
? Reactivity.mutation(effect, opts.reactivityKeys)
|
|
184
193
|
: effect
|
|
@@ -186,11 +195,14 @@ export const Tag =
|
|
|
186
195
|
)
|
|
187
196
|
) as any
|
|
188
197
|
|
|
189
|
-
self.mutation = ((group: string, endpoint: string
|
|
198
|
+
self.mutation = ((group: string, endpoint: string, options?: {
|
|
199
|
+
readonly withResponse?: boolean | undefined
|
|
200
|
+
}) =>
|
|
190
201
|
mutationFamily(
|
|
191
202
|
new MutationKey({
|
|
192
203
|
group,
|
|
193
|
-
endpoint
|
|
204
|
+
endpoint,
|
|
205
|
+
withResponse: options?.withResponse ?? false
|
|
194
206
|
})
|
|
195
207
|
)) as any
|
|
196
208
|
|
|
@@ -219,6 +231,7 @@ export const Tag =
|
|
|
219
231
|
readonly urlParams?: any
|
|
220
232
|
readonly payload?: any
|
|
221
233
|
readonly headers?: any
|
|
234
|
+
readonly withResponse?: boolean
|
|
222
235
|
readonly reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
223
236
|
readonly timeToLive?: Duration.DurationInput | undefined
|
|
224
237
|
}
|
|
@@ -231,6 +244,7 @@ export const Tag =
|
|
|
231
244
|
urlParams: request.urlParams && Data.struct(request.urlParams),
|
|
232
245
|
payload: request.payload && Data.struct(request.payload),
|
|
233
246
|
headers: request.headers && Data.struct(request.headers),
|
|
247
|
+
withResponse: request.withResponse ?? false,
|
|
234
248
|
reactivityKeys: request.reactivityKeys
|
|
235
249
|
? wrapReactivityKeys(request.reactivityKeys)
|
|
236
250
|
: undefined,
|
|
@@ -246,13 +260,14 @@ export const Tag =
|
|
|
246
260
|
class MutationKey extends Data.Class<{
|
|
247
261
|
group: string
|
|
248
262
|
endpoint: string
|
|
263
|
+
withResponse: boolean
|
|
249
264
|
}> {
|
|
250
265
|
[Equal.symbol](that: QueryKey) {
|
|
251
|
-
return this.group === that.group && this.endpoint === that.endpoint
|
|
266
|
+
return this.group === that.group && this.endpoint === that.endpoint && this.withResponse === that.withResponse
|
|
252
267
|
}
|
|
253
268
|
[Hash.symbol]() {
|
|
254
269
|
return pipe(
|
|
255
|
-
Hash.string(`${this.group}/${this.endpoint}`),
|
|
270
|
+
Hash.string(`${this.group}/${this.endpoint}/${this.withResponse}`),
|
|
256
271
|
Hash.cached(this)
|
|
257
272
|
)
|
|
258
273
|
}
|
|
@@ -265,6 +280,7 @@ class QueryKey extends Data.Class<{
|
|
|
265
280
|
urlParams: any
|
|
266
281
|
headers: any
|
|
267
282
|
payload: any
|
|
283
|
+
withResponse: boolean
|
|
268
284
|
reactivityKeys?: ReadonlyArray<unknown> | ReadonlyRecord<string, ReadonlyArray<unknown>> | undefined
|
|
269
285
|
timeToLive?: Duration.Duration | undefined
|
|
270
286
|
}> {
|
|
@@ -276,6 +292,7 @@ class QueryKey extends Data.Class<{
|
|
|
276
292
|
Equal.equals(this.urlParams, that.urlParams) &&
|
|
277
293
|
Equal.equals(this.payload, that.payload) &&
|
|
278
294
|
Equal.equals(this.headers, that.headers) &&
|
|
295
|
+
Equal.equals(this.withResponse, that.withResponse) &&
|
|
279
296
|
Equal.equals(this.reactivityKeys, that.reactivityKeys) &&
|
|
280
297
|
Equal.equals(this.timeToLive, that.timeToLive)
|
|
281
298
|
)
|
|
@@ -287,6 +304,7 @@ class QueryKey extends Data.Class<{
|
|
|
287
304
|
Hash.combine(Hash.hash(this.urlParams)),
|
|
288
305
|
Hash.combine(Hash.hash(this.payload)),
|
|
289
306
|
Hash.combine(Hash.hash(this.headers)),
|
|
307
|
+
Hash.combine(Hash.hash(this.withResponse)),
|
|
290
308
|
Hash.combine(Hash.hash(this.reactivityKeys)),
|
|
291
309
|
Hash.combine(Hash.hash(this.timeToLive)),
|
|
292
310
|
Hash.cached(this)
|