@systemfsoftware/effect-atom 0.5.3
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/LICENSE +231 -0
- package/README.md +30 -0
- package/dist/Atom-BgqgP-Qc.d.ts +1287 -0
- package/dist/Atom-BhgqoTsf.mjs +1348 -0
- package/dist/Atom-CxKJ3i4d.d.ts +1257 -0
- package/dist/Atom-DGWqaX9a.d.ts +1257 -0
- package/dist/Atom-DVWTGeoV.mjs +1449 -0
- package/dist/Atom-NsW01Gu1.mjs +1348 -0
- package/dist/Atom.d.ts +2 -0
- package/dist/Atom.mjs +2 -0
- package/dist/AtomHttpApi.d.ts +74 -0
- package/dist/AtomHttpApi.mjs +129 -0
- package/dist/AtomRef.d.ts +91 -0
- package/dist/AtomRef.mjs +248 -0
- package/dist/AtomRpc.d.ts +73 -0
- package/dist/AtomRpc.mjs +111 -0
- package/dist/Hydration.d.ts +75 -0
- package/dist/Hydration.mjs +113 -0
- package/dist/Registry-B1ULaW2_.mjs +769 -0
- package/dist/Registry-BE4aKSZk.mjs +823 -0
- package/dist/Registry-DhP1TSer.mjs +769 -0
- package/dist/Registry.d.ts +2 -0
- package/dist/Registry.mjs +2 -0
- package/dist/Result-B2vSp_sE.d.ts +480 -0
- package/dist/Result-BHH-qTvm.d.ts +491 -0
- package/dist/Result-CAjFdzam.d.ts +490 -0
- package/dist/Result-D8FNEzuX.mjs +633 -0
- package/dist/Result-DwtHFH70.mjs +663 -0
- package/dist/Result-rlUvoHzK.mjs +624 -0
- package/dist/Result.d.ts +2 -0
- package/dist/Result.mjs +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +8 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +94 -0
package/dist/Atom.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as toStreamResult, A as get, At as isAtom, B as modify, C as autoDispose, D as family, E as debounce, F as kvs, Ft as writable, G as refresh, H as optimistic, I as make, J as set, K as runtime, L as makeRead, M as initialValue, Mt as readable, N as isSerializable, Nt as setIdleTTL, O as fn, Ot as TypeId, P as keepAlive, Pt as transform, Q as toStream, R as map, S as WriteContext, T as context, U as optimisticFn, V as mount, W as pull, X as subscriptionRef, Y as setLazy, Z as swr, _ as SharedRuntimeFactory, at as withRefresh, b as WithoutSerializable, c as Interrupt, ct as getServerValue, d as RegistryRuntimeFactory, dt as makeRefreshOnSignal, et as update, f as Reset, ft as refreshOnWindowFocus, g as SerializableTypeId, h as SerializableJson, i as AtomRuntime, it as withReactivity, j as getResult, jt as isWritable, k as fnSync, kt as WritableTypeId, l as PullResult, lt as withServerValue, m as Serializable, mt as windowFocusSignal, n as AtomContext, nt as withFallback, o as Failure, ot as ServerValue, p as RuntimeFactory, pt as searchParam, q as serializable, r as AtomResultFn, rt as withLabel, s as FnContext, st as ServerValueTypeId, t as Atom, tt as withEquality, u as PullSuccess, ut as withServerValueInitial, v as Success, w as batch, x as Writable, y as Type, z as mapResult } from "./Atom-BgqgP-Qc.js";
|
|
2
|
+
export { Atom, AtomContext, AtomResultFn, AtomRuntime, Failure, FnContext, Interrupt, PullResult, PullSuccess, RegistryRuntimeFactory, Reset, RuntimeFactory, Serializable, SerializableJson, SerializableTypeId, type ServerValue, ServerValueTypeId, SharedRuntimeFactory, Success, Type, TypeId, WithoutSerializable, Writable, WritableTypeId, WriteContext, autoDispose, batch, context, debounce, family, fn, fnSync, get, getResult, getServerValue, initialValue, isAtom, isSerializable, isWritable, keepAlive, kvs, make, makeRead, makeRefreshOnSignal, map, mapResult, modify, mount, optimistic, optimisticFn, pull, readable, refresh, refreshOnWindowFocus, runtime, searchParam, serializable, set, setIdleTTL, setLazy, subscriptionRef, swr, toStream, toStreamResult, transform, update, windowFocusSignal, withEquality, withFallback, withLabel, withReactivity, withRefresh, withServerValue, withServerValueInitial, writable };
|
package/dist/Atom.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as isWritable, A as set, B as withReactivity, C as mount, D as refresh, E as pull, F as toStreamResult, G as withServerValueInitial, H as ServerValueTypeId, I as update, J as searchParam, K as makeRefreshOnSignal, L as withEquality, M as subscriptionRef, N as swr, O as runtime, P as toStream, Q as isAtom, R as withFallback, S as modify, T as optimisticFn, U as getServerValue, V as withRefresh, W as withServerValue, X as TypeId, Y as windowFocusSignal, Z as WritableTypeId, _ as kvs, a as autoDispose, b as map, c as debounce, d as fnSync, et as readable, f as get, g as keepAlive, h as isSerializable, i as SerializableTypeId, j as setLazy, k as serializable, l as family, m as initialValue, n as Interrupt, nt as transform, o as batch, p as getResult, q as refreshOnWindowFocus, r as Reset, rt as writable, s as context, tt as setIdleTTL, u as fn, v as make, w as optimistic, x as mapResult, y as makeRead, z as withLabel } from "./Atom-DVWTGeoV.mjs";
|
|
2
|
+
export { Interrupt, Reset, SerializableTypeId, ServerValueTypeId, TypeId, WritableTypeId, autoDispose, batch, context, debounce, family, fn, fnSync, get, getResult, getServerValue, initialValue, isAtom, isSerializable, isWritable, keepAlive, kvs, make, makeRead, makeRefreshOnSignal, map, mapResult, modify, mount, optimistic, optimisticFn, pull, readable, refresh, refreshOnWindowFocus, runtime, searchParam, serializable, set, setIdleTTL, setLazy, subscriptionRef, swr, toStream, toStreamResult, transform, update, windowFocusSignal, withEquality, withFallback, withLabel, withReactivity, withRefresh, withServerValue, withServerValueInitial, writable };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { i as AtomRuntime, n as AtomContext, p as RuntimeFactory, r as AtomResultFn, t as Atom } from "./Atom-BgqgP-Qc.js";
|
|
2
|
+
import { L as Result } from "./Result-BHH-qTvm.js";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Duration from "effect/Duration";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as HttpApiClient from "effect/unstable/httpapi/HttpApiClient";
|
|
9
|
+
import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint";
|
|
10
|
+
import { ReadonlyRecord } from "effect/Record";
|
|
11
|
+
import { Simplify } from "effect/Types";
|
|
12
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
13
|
+
import { HttpClientResponse } from "effect/unstable/http/HttpClientResponse";
|
|
14
|
+
import * as HttpApi from "effect/unstable/httpapi/HttpApi";
|
|
15
|
+
import * as HttpApiGroup from "effect/unstable/httpapi/HttpApiGroup";
|
|
16
|
+
import * as HttpApiMiddleware from "effect/unstable/httpapi/HttpApiMiddleware";
|
|
17
|
+
declare namespace AtomHttpApi_d_exports {
|
|
18
|
+
export { AtomHttpApiClient, Service };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A `Context.Service` for an HTTP API client integrated with atom reactivity.
|
|
22
|
+
*
|
|
23
|
+
* **Details**
|
|
24
|
+
*
|
|
25
|
+
* It exposes the generated HTTP API client, an atom runtime, mutation helpers that
|
|
26
|
+
* return `AtomResultFn`s, and query helpers that return atoms of endpoint results.
|
|
27
|
+
*
|
|
28
|
+
* @category services
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
interface AtomHttpApiClient<Self, Id extends string, Groups extends HttpApiGroup.Constraint> extends Context.Service<Self, HttpApiClient.Client<Groups, never, never>> {
|
|
32
|
+
new (_: never): Context.ServiceClass.Shape<Id, HttpApiClient.Client<Groups, never, never>>;
|
|
33
|
+
readonly runtime: AtomRuntime<Self>;
|
|
34
|
+
readonly mutation: <GroupIdentifier extends HttpApiGroup.Identifier<Groups>, EndpointIdentifier extends HttpApiEndpoint.Identifier<HttpApiGroup.Endpoints<Group>>, Group extends HttpApiGroup.WithIdentifier<Groups, GroupIdentifier> = HttpApiGroup.WithIdentifier<Groups, GroupIdentifier>, Endpoint extends HttpApiEndpoint.WithIdentifier<HttpApiGroup.Endpoints<Group>, EndpointIdentifier> = HttpApiEndpoint.WithIdentifier<HttpApiGroup.Endpoints<Group>, EndpointIdentifier>, const ResponseMode extends HttpApiEndpoint.ClientResponseMode = HttpApiEndpoint.ClientResponseMode>(group: GroupIdentifier, endpoint: EndpointIdentifier, options?: {
|
|
35
|
+
readonly responseMode?: ResponseMode | undefined;
|
|
36
|
+
}) => [Endpoint] extends [HttpApiEndpoint.HttpApiEndpoint<infer _Identifier, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _Middleware, infer _RE>] ? AtomResultFn<Simplify<HttpApiEndpoint.ClientRequest<_Params, _Query, _Payload, _Headers, 'decoded-only'> & {
|
|
37
|
+
readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
|
|
38
|
+
}>, ResponseByMode<Extract<_Success, Schema.Top>['Type'], ResponseMode>, ErrorByMode<_Error, _Middleware, ResponseMode>> : never;
|
|
39
|
+
readonly query: <GroupIdentifier extends HttpApiGroup.Identifier<Groups>, EndpointIdentifier extends HttpApiEndpoint.Identifier<HttpApiGroup.Endpoints<Group>>, Group extends HttpApiGroup.WithIdentifier<Groups, GroupIdentifier> = HttpApiGroup.WithIdentifier<Groups, GroupIdentifier>, Endpoint extends HttpApiEndpoint.WithIdentifier<HttpApiGroup.Endpoints<Group>, EndpointIdentifier> = HttpApiEndpoint.WithIdentifier<HttpApiGroup.Endpoints<Group>, EndpointIdentifier>, const ResponseMode extends HttpApiEndpoint.ClientResponseMode = 'decoded-only'>(group: GroupIdentifier, endpoint: EndpointIdentifier, request: [Endpoint] extends [HttpApiEndpoint.HttpApiEndpoint<infer _Identifier, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _R, infer _RE>] ? Simplify<HttpApiEndpoint.ClientRequest<_Params, _Query, _Payload, _Headers, ResponseMode> & {
|
|
40
|
+
readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
|
|
41
|
+
readonly timeToLive?: Duration.Input | undefined;
|
|
42
|
+
readonly serializationKey?: string | undefined;
|
|
43
|
+
}> : never) => [Endpoint] extends [HttpApiEndpoint.HttpApiEndpoint<infer _Identifier, infer _Method, infer _Path, infer _Params, infer _Query, infer _Payload, infer _Headers, infer _Success, infer _Error, infer _Middleware, infer _RE>] ? Atom<Result<ResponseByMode<Extract<_Success, Schema.Top>['Type'], ResponseMode>, ErrorByMode<_Error, _Middleware, ResponseMode>>> : never;
|
|
44
|
+
}
|
|
45
|
+
declare global {
|
|
46
|
+
interface ErrorConstructor {
|
|
47
|
+
stackTraceLimit: number;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a `Context.Service` class for an HTTP API client backed by an atom
|
|
52
|
+
* runtime.
|
|
53
|
+
*
|
|
54
|
+
* **Details**
|
|
55
|
+
*
|
|
56
|
+
* The options provide the API definition, HTTP client layer, optional client and
|
|
57
|
+
* response transforms, base URL, and runtime factory used by the query and
|
|
58
|
+
* mutation helpers.
|
|
59
|
+
*
|
|
60
|
+
* @category constructors
|
|
61
|
+
* @since 4.0.0
|
|
62
|
+
*/
|
|
63
|
+
declare const Service: <Self>() => <const Id extends string, ApiId extends string, Groups extends HttpApiGroup.Constraint>(id: Id, options: {
|
|
64
|
+
readonly api: HttpApi.HttpApi<ApiId, Groups>;
|
|
65
|
+
readonly httpClient: Layer.Layer<HttpApiGroup.ClientServices<Groups> | HttpApiGroup.MiddlewareClient<Groups> | HttpClient.HttpClient> | ((get: AtomContext) => Layer.Layer<HttpApiGroup.ClientServices<Groups> | HttpApiGroup.MiddlewareClient<Groups> | HttpClient.HttpClient>);
|
|
66
|
+
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
67
|
+
readonly transformResponse?: ((effect: Effect.Effect<unknown, unknown, unknown>) => Effect.Effect<unknown, unknown, unknown>) | undefined;
|
|
68
|
+
readonly baseUrl?: URL | string | undefined;
|
|
69
|
+
readonly runtime?: RuntimeFactory | undefined;
|
|
70
|
+
}) => AtomHttpApiClient<Self, Id, Groups>;
|
|
71
|
+
type ResponseByMode<Success, ResponseMode extends HttpApiEndpoint.ClientResponseMode> = [ResponseMode] extends ['decoded-and-response'] ? [Success, HttpClientResponse] : [ResponseMode] extends ['response-only'] ? HttpClientResponse : Success;
|
|
72
|
+
type ErrorByMode<Error extends Schema.Constraint, Middleware, ResponseMode extends HttpApiEndpoint.ClientResponseMode> = HttpApiMiddleware.Error<Middleware> | HttpApiMiddleware.ClientError<Middleware> | ([ResponseMode] extends ['response-only'] ? never : Error['Type']);
|
|
73
|
+
//#endregion
|
|
74
|
+
export { AtomHttpApiClient, Service, AtomHttpApi_d_exports as t };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { O as runtime, g as keepAlive, k as serializable, l as family, tt as setIdleTTL } from "./Atom-DVWTGeoV.mjs";
|
|
3
|
+
import { j as schemaCodec } from "./Result-rlUvoHzK.mjs";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Duration from "effect/Duration";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
import * as Reactivity from "effect/unstable/reactivity/Reactivity";
|
|
10
|
+
import * as HttpClientError from "effect/unstable/http/HttpClientError";
|
|
11
|
+
import * as HttpApiClient from "effect/unstable/httpapi/HttpApiClient";
|
|
12
|
+
import * as HttpApiEndpoint from "effect/unstable/httpapi/HttpApiEndpoint";
|
|
13
|
+
import * as HttpApiSchema from "effect/unstable/httpapi/HttpApiSchema";
|
|
14
|
+
//#region src/AtomHttpApi.ts
|
|
15
|
+
/**
|
|
16
|
+
* Connects typed `HttpApi` clients to atoms.
|
|
17
|
+
*
|
|
18
|
+
* The service created here exposes the generated HTTP API client plus
|
|
19
|
+
* atom-based query and mutation helpers. Query atoms call endpoints and track
|
|
20
|
+
* their asynchronous result, while mutations run endpoint calls that can
|
|
21
|
+
* invalidate reactivity keys after a successful request. Query atoms can also be
|
|
22
|
+
* cached, serialized for hydration, and kept alive with a time-to-live.
|
|
23
|
+
*
|
|
24
|
+
* @since 4.0.0
|
|
25
|
+
*/
|
|
26
|
+
var AtomHttpApi_exports = /* @__PURE__ */ __exportAll({ Service: () => Service });
|
|
27
|
+
const getSuccessSchemas = (endpoint) => {
|
|
28
|
+
const [first, ...rest] = Array.from(endpoint.success);
|
|
29
|
+
return first === void 0 ? [HttpApiSchema.NoContent] : [first, ...rest];
|
|
30
|
+
};
|
|
31
|
+
const getErrorSchemas = (endpoint) => Array.from(endpoint.error);
|
|
32
|
+
/**
|
|
33
|
+
* Creates a `Context.Service` class for an HTTP API client backed by an atom
|
|
34
|
+
* runtime.
|
|
35
|
+
*
|
|
36
|
+
* **Details**
|
|
37
|
+
*
|
|
38
|
+
* The options provide the API definition, HTTP client layer, optional client and
|
|
39
|
+
* response transforms, base URL, and runtime factory used by the query and
|
|
40
|
+
* mutation helpers.
|
|
41
|
+
*
|
|
42
|
+
* @category constructors
|
|
43
|
+
* @since 4.0.0
|
|
44
|
+
*/
|
|
45
|
+
const Service = () => (id, options) => {
|
|
46
|
+
const service = Context.Service()(id);
|
|
47
|
+
const layer = Layer.effect(service, HttpApiClient.make(options.api, options));
|
|
48
|
+
const httpClient = options.httpClient;
|
|
49
|
+
const runtime$1 = (options.runtime ?? runtime)(typeof httpClient === "function" ? (get) => Layer.provide(layer, httpClient(get)) : Layer.provide(layer, httpClient));
|
|
50
|
+
const catchErrors = Effect.catch((e) => Schema.isSchemaError(e) || HttpClientError.isHttpClientError(e) ? Effect.die(e) : Effect.fail(e));
|
|
51
|
+
const isEndpointCall = (u) => typeof u === "function";
|
|
52
|
+
const endpointFor = (group, endpoint) => {
|
|
53
|
+
for (const candidate of Object.values(options.api.groups)) {
|
|
54
|
+
if ((typeof candidate !== "object" || candidate === null) && typeof candidate !== "function" || "identifier" in candidate === false || candidate.identifier !== group) continue;
|
|
55
|
+
if (!("endpoints" in candidate) || typeof candidate.endpoints !== "object" || candidate.endpoints === null) break;
|
|
56
|
+
for (const definition of Object.values(candidate.endpoints)) if ((typeof definition === "object" && definition !== null || typeof definition === "function") && HttpApiEndpoint.isHttpApiEndpoint(definition) && definition.identifier === endpoint) return definition;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`Unknown endpoint: ${group}.${endpoint}`);
|
|
60
|
+
};
|
|
61
|
+
const callEndpoint = (client, group, endpoint, request) => {
|
|
62
|
+
const groupEntry = typeof client === "object" && client !== null || typeof client === "function" ? Reflect.get(client, group) : void 0;
|
|
63
|
+
if (typeof groupEntry !== "object" || groupEntry === null) throw new Error(`Unknown API group: ${group}`);
|
|
64
|
+
const call = Reflect.get(groupEntry, endpoint);
|
|
65
|
+
if (!isEndpointCall(call)) throw new Error(`Unknown endpoint: ${group}.${endpoint}`);
|
|
66
|
+
return call(request);
|
|
67
|
+
};
|
|
68
|
+
const resultSchema = schemaCodec;
|
|
69
|
+
const mutationFamily = family(({ endpoint, group, responseMode }) => {
|
|
70
|
+
const fnAtom = runtime$1.fn()(Effect.fnUntraced(function* (opts) {
|
|
71
|
+
const client = yield* service;
|
|
72
|
+
const effect = catchErrors(callEndpoint(client, group, endpoint, {
|
|
73
|
+
...opts,
|
|
74
|
+
responseMode
|
|
75
|
+
}));
|
|
76
|
+
return yield* opts.reactivityKeys ? Reactivity.mutation(effect, opts.reactivityKeys) : effect;
|
|
77
|
+
}));
|
|
78
|
+
if (responseMode === "decoded-only") {
|
|
79
|
+
const definition = endpointFor(group, endpoint);
|
|
80
|
+
return serializable(fnAtom, {
|
|
81
|
+
key: `AtomHttpApi:mutation:${group}:${endpoint}`,
|
|
82
|
+
schema: resultSchema(Schema.Union(getSuccessSchemas(definition)), Schema.Union(getErrorSchemas(definition)))
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return fnAtom;
|
|
86
|
+
});
|
|
87
|
+
function mutation(group, endpoint, options) {
|
|
88
|
+
return mutationFamily({
|
|
89
|
+
group,
|
|
90
|
+
endpoint,
|
|
91
|
+
responseMode: options?.responseMode ?? "decoded-only"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const queryFamily = family((opts) => {
|
|
95
|
+
let atom = runtime$1.atom(service.use((client) => catchErrors(callEndpoint(client, opts.group, opts.endpoint, opts))));
|
|
96
|
+
if (opts.reactivityKeys) atom = runtime$1.factory.withReactivity(opts.reactivityKeys)(atom);
|
|
97
|
+
if (opts.responseMode === "decoded-only" && opts.serializationKey) {
|
|
98
|
+
const endpoint = endpointFor(opts.group, opts.endpoint);
|
|
99
|
+
atom = serializable(atom, {
|
|
100
|
+
key: `AtomHttpApi:${opts.group}:${opts.endpoint}:${opts.serializationKey}`,
|
|
101
|
+
schema: resultSchema(Schema.Union(getSuccessSchemas(endpoint)), Schema.Union(getErrorSchemas(endpoint)))
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (opts.timeToLive) atom = Duration.isFinite(opts.timeToLive) ? setIdleTTL(atom, opts.timeToLive) : keepAlive(atom);
|
|
105
|
+
return atom;
|
|
106
|
+
});
|
|
107
|
+
function query(group, endpoint, request) {
|
|
108
|
+
const key = {
|
|
109
|
+
group,
|
|
110
|
+
endpoint,
|
|
111
|
+
params: request.params,
|
|
112
|
+
query: request.query,
|
|
113
|
+
payload: request.payload,
|
|
114
|
+
headers: request.headers,
|
|
115
|
+
responseMode: request.responseMode ?? "decoded-only",
|
|
116
|
+
reactivityKeys: request.reactivityKeys,
|
|
117
|
+
timeToLive: request.timeToLive ? Duration.fromInputUnsafe(request.timeToLive) : void 0,
|
|
118
|
+
serializationKey: request.serializationKey
|
|
119
|
+
};
|
|
120
|
+
return queryFamily(key);
|
|
121
|
+
}
|
|
122
|
+
return Object.assign(service, {
|
|
123
|
+
runtime: runtime$1,
|
|
124
|
+
mutation,
|
|
125
|
+
query
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
export { Service, AtomHttpApi_exports as t };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Equal } from "effect/Equal";
|
|
2
|
+
declare namespace AtomRef_d_exports {
|
|
3
|
+
export { AtomRef, Collection, ReadonlyRef, TypeId, collection, make };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The literal type used to identify `AtomRef` values.
|
|
7
|
+
*
|
|
8
|
+
* @category type IDs
|
|
9
|
+
* @since 4.0.0
|
|
10
|
+
*/
|
|
11
|
+
type TypeId = '~effect/reactivity/AtomRef';
|
|
12
|
+
/**
|
|
13
|
+
* The runtime type id used to identify `AtomRef` values.
|
|
14
|
+
*
|
|
15
|
+
* @category type IDs
|
|
16
|
+
* @since 4.0.0
|
|
17
|
+
*/
|
|
18
|
+
declare const TypeId: TypeId;
|
|
19
|
+
/**
|
|
20
|
+
* A read-only reactive reference.
|
|
21
|
+
*
|
|
22
|
+
* **Details**
|
|
23
|
+
*
|
|
24
|
+
* It exposes a stable key, the current value, subscriptions to value changes, and
|
|
25
|
+
* `map` for creating derived read-only references. Equality and hashing are based
|
|
26
|
+
* on the current value.
|
|
27
|
+
*
|
|
28
|
+
* @category models
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
interface ReadonlyRef<A> extends Equal {
|
|
32
|
+
readonly [TypeId]: TypeId;
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly value: A;
|
|
35
|
+
readonly subscribe: (f: (a: A) => void) => () => void;
|
|
36
|
+
readonly map: <B>(f: (a: A) => B) => ReadonlyRef<B>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A mutable reactive reference.
|
|
40
|
+
*
|
|
41
|
+
* **Details**
|
|
42
|
+
*
|
|
43
|
+
* It supports replacing the whole value, updating it from the current value, and
|
|
44
|
+
* creating mutable references to nested properties.
|
|
45
|
+
*
|
|
46
|
+
* @category models
|
|
47
|
+
* @since 4.0.0
|
|
48
|
+
*/
|
|
49
|
+
interface AtomRef<A> extends ReadonlyRef<A> {
|
|
50
|
+
readonly prop: <K extends keyof A>(prop: K) => AtomRef<A[K]>;
|
|
51
|
+
readonly set: (value: A) => AtomRef<A>;
|
|
52
|
+
readonly update: (f: (value: A) => A) => AtomRef<A>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A reactive collection of mutable item references.
|
|
56
|
+
*
|
|
57
|
+
* **Details**
|
|
58
|
+
*
|
|
59
|
+
* The collection can push, insert, and remove item refs, and `toArray` returns the
|
|
60
|
+
* current raw item values.
|
|
61
|
+
*
|
|
62
|
+
* @category models
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
interface Collection<A> extends ReadonlyRef<readonly AtomRef<A>[]> {
|
|
66
|
+
readonly push: (item: A) => Collection<A>;
|
|
67
|
+
readonly insertAt: (index: number, item: A) => Collection<A>;
|
|
68
|
+
readonly remove: (ref: AtomRef<A>) => Collection<A>;
|
|
69
|
+
readonly toArray: () => A[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates a mutable reactive reference initialized with the supplied value.
|
|
73
|
+
*
|
|
74
|
+
* @category constructors
|
|
75
|
+
* @since 4.0.0
|
|
76
|
+
*/
|
|
77
|
+
declare const make: <A>(value: A) => AtomRef<A>;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a reactive collection from an iterable of initial item values.
|
|
80
|
+
*
|
|
81
|
+
* **Details**
|
|
82
|
+
*
|
|
83
|
+
* Each item is wrapped in an `AtomRef`, and changes to item refs notify the
|
|
84
|
+
* collection subscribers.
|
|
85
|
+
*
|
|
86
|
+
* @category constructors
|
|
87
|
+
* @since 4.0.0
|
|
88
|
+
*/
|
|
89
|
+
declare const collection: <A>(items: Iterable<A>) => Collection<A>;
|
|
90
|
+
//#endregion
|
|
91
|
+
export { AtomRef, Collection, ReadonlyRef, TypeId, collection, make, AtomRef_d_exports as t };
|
package/dist/AtomRef.mjs
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import * as Equal$1 from "effect/Equal";
|
|
3
|
+
import * as Hash from "effect/Hash";
|
|
4
|
+
//#region src/AtomRef.ts
|
|
5
|
+
/**
|
|
6
|
+
* Mutable reactive references for local, in-memory state.
|
|
7
|
+
*
|
|
8
|
+
* `AtomRef` provides small observable state cells that can be read, updated,
|
|
9
|
+
* mapped, and subscribed to without going through an `AtomRegistry`. Mutable
|
|
10
|
+
* refs can also create refs for nested properties. The module also provides a
|
|
11
|
+
* collection helper that stores item refs and notifies subscribers when items are
|
|
12
|
+
* inserted, removed, or changed.
|
|
13
|
+
*
|
|
14
|
+
* @since 4.0.0
|
|
15
|
+
*/
|
|
16
|
+
var AtomRef_exports = /* @__PURE__ */ __exportAll({
|
|
17
|
+
TypeId: () => TypeId,
|
|
18
|
+
collection: () => collection,
|
|
19
|
+
make: () => make
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* The runtime type id used to identify `AtomRef` values.
|
|
23
|
+
*
|
|
24
|
+
* @category type IDs
|
|
25
|
+
* @since 4.0.0
|
|
26
|
+
*/
|
|
27
|
+
const TypeId = "~effect/reactivity/AtomRef";
|
|
28
|
+
/**
|
|
29
|
+
* Creates a mutable reactive reference initialized with the supplied value.
|
|
30
|
+
*
|
|
31
|
+
* @category constructors
|
|
32
|
+
* @since 4.0.0
|
|
33
|
+
*/
|
|
34
|
+
const make = (value) => new AtomRefImpl(value);
|
|
35
|
+
/**
|
|
36
|
+
* Creates a reactive collection from an iterable of initial item values.
|
|
37
|
+
*
|
|
38
|
+
* **Details**
|
|
39
|
+
*
|
|
40
|
+
* Each item is wrapped in an `AtomRef`, and changes to item refs notify the
|
|
41
|
+
* collection subscribers.
|
|
42
|
+
*
|
|
43
|
+
* @category constructors
|
|
44
|
+
* @since 4.0.0
|
|
45
|
+
*/
|
|
46
|
+
const collection = (items) => new CollectionImpl(items);
|
|
47
|
+
const isReadonlyRef = (u) => typeof u === "object" && u !== null && "~effect/reactivity/AtomRef" in u;
|
|
48
|
+
const isArrayWithProp = (value, _prop) => Array.isArray(value);
|
|
49
|
+
const keyState = {
|
|
50
|
+
count: 0,
|
|
51
|
+
generate() {
|
|
52
|
+
return `AtomRef-${this.count++}`;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var ReadonlyRefImpl = class {
|
|
56
|
+
[TypeId];
|
|
57
|
+
key = keyState.generate();
|
|
58
|
+
value;
|
|
59
|
+
constructor(value) {
|
|
60
|
+
this[TypeId] = TypeId;
|
|
61
|
+
this.value = value;
|
|
62
|
+
}
|
|
63
|
+
[Equal$1.symbol](that) {
|
|
64
|
+
return isReadonlyRef(that) && Equal$1.equals(this.value, that.value);
|
|
65
|
+
}
|
|
66
|
+
[Hash.symbol]() {
|
|
67
|
+
return Hash.hash(this.value);
|
|
68
|
+
}
|
|
69
|
+
listeners = null;
|
|
70
|
+
notify(a) {
|
|
71
|
+
let listener = this.listeners;
|
|
72
|
+
while (listener !== null) {
|
|
73
|
+
listener.f(a);
|
|
74
|
+
listener = listener.next;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
subscribe(f) {
|
|
78
|
+
const listener = {
|
|
79
|
+
f,
|
|
80
|
+
prev: null,
|
|
81
|
+
next: this.listeners
|
|
82
|
+
};
|
|
83
|
+
if (this.listeners) this.listeners.prev = listener;
|
|
84
|
+
this.listeners = listener;
|
|
85
|
+
return () => {
|
|
86
|
+
if (this.listeners === listener) this.listeners = listener.next;
|
|
87
|
+
if (listener.prev) listener.prev.next = listener.next;
|
|
88
|
+
if (listener.next) listener.next.prev = listener.prev;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
map(f) {
|
|
92
|
+
return new MapRefImpl(this, f);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var AtomRefImpl = class extends ReadonlyRefImpl {
|
|
96
|
+
prop(prop) {
|
|
97
|
+
return new PropRefImpl(this, prop);
|
|
98
|
+
}
|
|
99
|
+
set(value) {
|
|
100
|
+
if (Equal$1.equals(value, this.value)) return this;
|
|
101
|
+
this.value = value;
|
|
102
|
+
this.notify(value);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
update(f) {
|
|
106
|
+
return this.set(f(this.value));
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var MapRefImpl = class MapRefImpl {
|
|
110
|
+
[TypeId];
|
|
111
|
+
key = keyState.generate();
|
|
112
|
+
parent;
|
|
113
|
+
transform;
|
|
114
|
+
constructor(parent, transform) {
|
|
115
|
+
this[TypeId] = TypeId;
|
|
116
|
+
this.parent = parent;
|
|
117
|
+
this.transform = transform;
|
|
118
|
+
}
|
|
119
|
+
[Equal$1.symbol](that) {
|
|
120
|
+
return isReadonlyRef(that) && Equal$1.equals(this.value, that.value);
|
|
121
|
+
}
|
|
122
|
+
[Hash.symbol]() {
|
|
123
|
+
return Hash.hash(this.value);
|
|
124
|
+
}
|
|
125
|
+
get value() {
|
|
126
|
+
return this.transform(this.parent.value);
|
|
127
|
+
}
|
|
128
|
+
subscribe(f) {
|
|
129
|
+
let previous = this.transform(this.parent.value);
|
|
130
|
+
return this.parent.subscribe((a) => {
|
|
131
|
+
const next = this.transform(a);
|
|
132
|
+
if (Equal$1.equals(next, previous)) return;
|
|
133
|
+
previous = next;
|
|
134
|
+
f(next);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
map(f) {
|
|
138
|
+
return new MapRefImpl(this, f);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var PropRefImpl = class PropRefImpl {
|
|
142
|
+
[TypeId];
|
|
143
|
+
key = keyState.generate();
|
|
144
|
+
previous;
|
|
145
|
+
parent;
|
|
146
|
+
_prop;
|
|
147
|
+
constructor(parent, _prop) {
|
|
148
|
+
this[TypeId] = TypeId;
|
|
149
|
+
this.parent = parent;
|
|
150
|
+
this._prop = _prop;
|
|
151
|
+
this.previous = parent.value[_prop];
|
|
152
|
+
}
|
|
153
|
+
[Equal$1.symbol](that) {
|
|
154
|
+
return isReadonlyRef(that) && Equal$1.equals(this.value, that.value);
|
|
155
|
+
}
|
|
156
|
+
[Hash.symbol]() {
|
|
157
|
+
return Hash.hash(this.value);
|
|
158
|
+
}
|
|
159
|
+
get value() {
|
|
160
|
+
if (this.parent.value && this._prop in this.parent.value) this.previous = this.parent.value[this._prop];
|
|
161
|
+
return this.previous;
|
|
162
|
+
}
|
|
163
|
+
subscribe(f) {
|
|
164
|
+
let previous = this.value;
|
|
165
|
+
return this.parent.subscribe((a) => {
|
|
166
|
+
if (!a || !(this._prop in a)) return;
|
|
167
|
+
const next = a[this._prop];
|
|
168
|
+
if (Equal$1.equals(next, previous)) return;
|
|
169
|
+
previous = next;
|
|
170
|
+
f(next);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
map(f) {
|
|
174
|
+
return new MapRefImpl(this, f);
|
|
175
|
+
}
|
|
176
|
+
prop(prop) {
|
|
177
|
+
return new PropRefImpl(this, prop);
|
|
178
|
+
}
|
|
179
|
+
set(value) {
|
|
180
|
+
if (isArrayWithProp(this.parent.value, this._prop)) {
|
|
181
|
+
const newArray = Object.assign(new Array(), this.parent.value);
|
|
182
|
+
newArray[Number(this._prop)] = value;
|
|
183
|
+
this.parent.set(newArray);
|
|
184
|
+
} else this.parent.set({
|
|
185
|
+
...this.parent.value,
|
|
186
|
+
[this._prop]: value
|
|
187
|
+
});
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
update(f) {
|
|
191
|
+
if (isArrayWithProp(this.parent.value, this._prop)) {
|
|
192
|
+
const newArray = Object.assign(new Array(), this.parent.value);
|
|
193
|
+
newArray[Number(this._prop)] = f(this.parent.value[this._prop]);
|
|
194
|
+
this.parent.set(newArray);
|
|
195
|
+
} else this.parent.set({
|
|
196
|
+
...this.parent.value,
|
|
197
|
+
[this._prop]: f(this.parent.value[this._prop])
|
|
198
|
+
});
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var CollectionImpl = class extends ReadonlyRefImpl {
|
|
203
|
+
linked = /* @__PURE__ */ new Set();
|
|
204
|
+
constructor(items) {
|
|
205
|
+
super([]);
|
|
206
|
+
for (const item of items) this.value.push(this.makeRef(item));
|
|
207
|
+
}
|
|
208
|
+
makeRef(value) {
|
|
209
|
+
const ref = new AtomRefImpl(value);
|
|
210
|
+
let proxy;
|
|
211
|
+
const notify = (value) => {
|
|
212
|
+
ref.notify(value);
|
|
213
|
+
if (this.linked.has(proxy)) this.notify(this.value);
|
|
214
|
+
};
|
|
215
|
+
proxy = new Proxy(ref, { get(target, p, receiver) {
|
|
216
|
+
if (p === "notify") return notify;
|
|
217
|
+
return Reflect.get(target, p, receiver);
|
|
218
|
+
} });
|
|
219
|
+
this.linked.add(proxy);
|
|
220
|
+
return proxy;
|
|
221
|
+
}
|
|
222
|
+
push(item) {
|
|
223
|
+
const ref = this.makeRef(item);
|
|
224
|
+
this.value.push(ref);
|
|
225
|
+
this.notify(this.value);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
insertAt(index, item) {
|
|
229
|
+
const ref = this.makeRef(item);
|
|
230
|
+
this.value.splice(index, 0, ref);
|
|
231
|
+
this.notify(this.value);
|
|
232
|
+
return this;
|
|
233
|
+
}
|
|
234
|
+
remove(ref) {
|
|
235
|
+
const index = this.value.indexOf(ref);
|
|
236
|
+
if (index !== -1) {
|
|
237
|
+
this.value.splice(index, 1);
|
|
238
|
+
this.linked.delete(ref);
|
|
239
|
+
this.notify(this.value);
|
|
240
|
+
}
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
toArray() {
|
|
244
|
+
return this.value.map((ref) => ref.value);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
//#endregion
|
|
248
|
+
export { TypeId, collection, make, AtomRef_exports as t };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { i as AtomRuntime, l as PullResult, n as AtomContext, p as RuntimeFactory, r as AtomResultFn, t as Atom, x as Writable } from "./Atom-BgqgP-Qc.js";
|
|
2
|
+
import { L as Result } from "./Result-BHH-qTvm.js";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Duration from "effect/Duration";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Scope from "effect/Scope";
|
|
8
|
+
import * as Headers from "effect/unstable/http/Headers";
|
|
9
|
+
import * as RpcClient from "effect/unstable/rpc/RpcClient";
|
|
10
|
+
import { RpcClientError } from "effect/unstable/rpc/RpcClientError";
|
|
11
|
+
import * as RpcSchema from "effect/unstable/rpc/RpcSchema";
|
|
12
|
+
import { ReadonlyRecord } from "effect/Record";
|
|
13
|
+
import { NoInfer } from "effect/Types";
|
|
14
|
+
import * as Rpc from "effect/unstable/rpc/Rpc";
|
|
15
|
+
import * as RpcGroup from "effect/unstable/rpc/RpcGroup";
|
|
16
|
+
import { RequestId } from "effect/unstable/rpc/RpcMessage";
|
|
17
|
+
declare namespace AtomRpc_d_exports {
|
|
18
|
+
export { AtomRpcClient, Service };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A `Context.Service` for a flattened RPC client integrated with atom reactivity.
|
|
22
|
+
*
|
|
23
|
+
* **Details**
|
|
24
|
+
*
|
|
25
|
+
* It exposes the RPC client, an atom runtime, mutation helpers that return `AtomResultFn`s, and query helpers that
|
|
26
|
+
* return atoms or pull atoms for RPC results.
|
|
27
|
+
*
|
|
28
|
+
* @category services
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
interface AtomRpcClient<Self, Id extends string, Rpcs extends Rpc.Any> extends Context.Service<Self, RpcClient.RpcClient.Flat<Rpcs, RpcClientError>> {
|
|
32
|
+
new (_: never): Context.ServiceClass.Shape<Id, RpcClient.RpcClient.Flat<Rpcs, RpcClientError>>;
|
|
33
|
+
readonly runtime: AtomRuntime<Self>;
|
|
34
|
+
readonly mutation: <Tag extends Rpc.Tag<Rpcs>>(arg: Tag) => Rpc.ExtractTag<Rpcs, Tag> extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware, infer _Requires> ? [_Success] extends [RpcSchema.Stream<infer _A, infer _E>] ? never : AtomResultFn<{
|
|
35
|
+
readonly payload: Rpc.PayloadConstructor<Rpc.ExtractTag<Rpcs, Tag>>;
|
|
36
|
+
readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
|
|
37
|
+
readonly headers?: Headers.Input | undefined;
|
|
38
|
+
}, _Success['Type'], _Error['Type'] | RpcClientError | _Middleware['error']['Type']> : never;
|
|
39
|
+
readonly query: <Tag extends Rpc.Tag<Rpcs>>(tag: Tag, payload: Rpc.PayloadConstructor<Rpc.ExtractTag<Rpcs, Tag>>, options?: {
|
|
40
|
+
readonly headers?: Headers.Input | undefined;
|
|
41
|
+
readonly reactivityKeys?: readonly unknown[] | ReadonlyRecord<string, readonly unknown[]> | undefined;
|
|
42
|
+
readonly timeToLive?: Duration.Input | undefined;
|
|
43
|
+
readonly serializationKey?: string | undefined;
|
|
44
|
+
}) => Rpc.ExtractTag<Rpcs, Tag> extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? [_Success] extends [RpcSchema.Stream<infer _A, infer _E>] ? Writable<PullResult<_A['Type'], _E['Type'] | _Error['Type'] | RpcClientError | _Middleware['error']['Type']>, void> : Atom<Result<_Success['Type'], _Error['Type'] | RpcClientError | _Middleware['error']['Type']>> : never;
|
|
45
|
+
}
|
|
46
|
+
declare global {
|
|
47
|
+
interface ErrorConstructor {
|
|
48
|
+
stackTraceLimit: number;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a `Context.Service` class for an RPC client backed by an atom runtime.
|
|
53
|
+
*
|
|
54
|
+
* **Details**
|
|
55
|
+
*
|
|
56
|
+
* The options provide the RPC group, protocol layer, tracing options, request id generation, optional custom client
|
|
57
|
+
* effect, and runtime factory used by the query and mutation helpers.
|
|
58
|
+
*
|
|
59
|
+
* @category constructors
|
|
60
|
+
* @since 4.0.0
|
|
61
|
+
*/
|
|
62
|
+
declare const Service: <Self>() => <const Id extends string, Rpcs extends Rpc.Any, ER, RM = RpcClient.Protocol | Rpc.MiddlewareClient<NoInfer<Rpcs>> | Rpc.ServicesClient<NoInfer<Rpcs>>>(id: Id, options: {
|
|
63
|
+
readonly group: RpcGroup.RpcGroup<Rpcs>;
|
|
64
|
+
readonly protocol: Layer.Layer<Exclude<NoInfer<RM>, Scope.Scope>, ER> | ((get: AtomContext) => Layer.Layer<Exclude<NoInfer<RM>, Scope.Scope>, ER>);
|
|
65
|
+
readonly spanPrefix?: string | undefined;
|
|
66
|
+
readonly spanAttributes?: Record<string, unknown> | undefined;
|
|
67
|
+
readonly generateRequestId?: (() => RequestId) | undefined;
|
|
68
|
+
readonly disableTracing?: boolean | undefined;
|
|
69
|
+
readonly makeEffect?: Effect.Effect<RpcClient.RpcClient.Flat<Rpcs, RpcClientError>, never, RM | RpcClient.Protocol | Rpc.MiddlewareClient<Rpcs> | Scope.Scope> | undefined;
|
|
70
|
+
readonly runtime?: RuntimeFactory | undefined;
|
|
71
|
+
}) => AtomRpcClient<Self, Id, Rpcs>;
|
|
72
|
+
//#endregion
|
|
73
|
+
export { AtomRpcClient, Service, AtomRpc_d_exports as t };
|