@runku/react 0.4.8
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 +202 -0
- package/README.md +94 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +18 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +35 -0
- package/dist/server.js.map +1 -0
- package/dist/shared.d.ts +22 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +28 -0
- package/dist/shared.js.map +1 -0
- package/dist/store.d.ts +31 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +131 -0
- package/dist/store.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Aldemi Tech
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# `@runku/react`
|
|
2
|
+
|
|
3
|
+
React and Next.js bindings for `@runku/client`. The package provides typed Function references,
|
|
4
|
+
Realtime Query hooks, Mutation and Action hooks, file transfer helpers, and request-local server
|
|
5
|
+
utilities with hydration.
|
|
6
|
+
|
|
7
|
+
Install the exact frontend SDK pair together:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @runku/react@0.4.8 @runku/client@0.4.8
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Version 0.4.8 uses Public Protocol v1 and is compatible with the Runku 0.4.7 gateway. The published
|
|
14
|
+
0.4.7 CLI predates runtime Function-reference generation; use references emitted by the current
|
|
15
|
+
source CLI until a later coordinated distribution includes that codegen.
|
|
16
|
+
|
|
17
|
+
## Generated Function references
|
|
18
|
+
|
|
19
|
+
`runku build` writes two runtime/type pairs below `runku/_generated`:
|
|
20
|
+
|
|
21
|
+
- `api.js` and `api.d.ts`: browser-safe public Functions. Functions with `auth: "service"` are
|
|
22
|
+
excluded.
|
|
23
|
+
- `server.js` and `server.d.ts`: every externally callable public Function, including service-only
|
|
24
|
+
Functions. Keep imports from this module in server-only files.
|
|
25
|
+
|
|
26
|
+
Internal Functions are callable only by trusted nested Function calls and are never emitted into
|
|
27
|
+
either external tree. Function names separated by `.` or `/` become nested properties, so a
|
|
28
|
+
Function named `tasks.list` is addressed as `api.tasks.list`. Authentication is part of the
|
|
29
|
+
reference type; browser hooks reject an `auth: "service"` reference even if one is imported from
|
|
30
|
+
the wrong module.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
"use client";
|
|
34
|
+
|
|
35
|
+
import { useMutation, useQuery } from "@runku/react";
|
|
36
|
+
import { api } from "../runku/_generated/api.js";
|
|
37
|
+
|
|
38
|
+
export function Tasks() {
|
|
39
|
+
const tasks = useQuery(api.tasks.list, { board: "today" });
|
|
40
|
+
const createTask = useMutation(api.tasks.create);
|
|
41
|
+
// Arguments and results are inferred from the generated reference.
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Provider and identity isolation
|
|
47
|
+
|
|
48
|
+
Create one stable `RunkuClient`, then provide a non-secret `identityKey` that changes whenever the
|
|
49
|
+
effective user, guest, or service identity changes. Changing it closes the old Realtime connection
|
|
50
|
+
and drops the old cache.
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<RunkuProvider client={client} identityKey={session.user.id}>
|
|
54
|
+
{children}
|
|
55
|
+
</RunkuProvider>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`useQuery` shares one Realtime subscription per canonical Function/arguments/target key. Its
|
|
59
|
+
hydrated value is marked `isStale` until Realtime confirms the current state. `useMutation` keeps a
|
|
60
|
+
stable Operation ID within the underlying client's retry cycle. `useAction` is never automatically
|
|
61
|
+
retried. `useUploadFile` and `useDownloadFile` consume short-lived grants returned by storage
|
|
62
|
+
Actions; the grant itself is authority and must not be logged or persisted.
|
|
63
|
+
|
|
64
|
+
The provider supports the development effect replay performed by React Strict Mode. Cleanup closes
|
|
65
|
+
the current Realtime transport; if React subscribes the same mounted store again, the provider opens
|
|
66
|
+
a fresh transport while retaining only that identity's cached Query snapshots.
|
|
67
|
+
|
|
68
|
+
## Next.js server usage
|
|
69
|
+
|
|
70
|
+
Create the facade per request. It exposes every operation available to browser code plus
|
|
71
|
+
`preloadQuery` and `dehydrate`.
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import "server-only";
|
|
75
|
+
import { createRunkuReactServer } from "@runku/react/server";
|
|
76
|
+
import { serverApi } from "../runku/_generated/server.js";
|
|
77
|
+
|
|
78
|
+
const runku = createRunkuReactServer(serverClient, session.user.id);
|
|
79
|
+
const result = await runku.preloadQuery(serverApi.tasks.list, { board: "today" });
|
|
80
|
+
await runku.mutation(serverApi.tasks.create, { title: "Review" });
|
|
81
|
+
await runku.action(serverApi.tasks.export, null);
|
|
82
|
+
const state = runku.dehydrate();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Pass `state` through a `RunkuHydrationBoundary` surrounding `RunkuProvider`. Hydration uses Runku
|
|
86
|
+
Wire Value v1 rather than JavaScript class instances, so timestamps, IDs, bytes, and 64-bit integers
|
|
87
|
+
cross the React Server Component boundary losslessly.
|
|
88
|
+
|
|
89
|
+
The server facade also delegates `uploadFile`, `downloadFile`, and `realtime`. Use Realtime only in
|
|
90
|
+
a long-lived server process with an injected WebSocket factory, not as a request-scoped Server
|
|
91
|
+
Component subscription. It does not make Action effects
|
|
92
|
+
retry-safe: callers remain responsible for Action idempotency. The current SDK supports Runku
|
|
93
|
+
Application File grants. Native S3 multipart operations and a generic object-storage presigner are
|
|
94
|
+
not part of this package.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { BrowserFunctionAuth, CallOptions, FileDownloadGrant, FileDownloadOptions, FileMetadata, FileUploadGrant, FileUploadOptions, FunctionReference, MutationOptions, RunkuClient, RunkuResult, RunkuValue } from "@runku/client";
|
|
3
|
+
import { type RunkuDehydratedState } from "./shared.js";
|
|
4
|
+
import { type QueryState } from "./store.js";
|
|
5
|
+
export type { RunkuDehydratedState } from "./shared.js";
|
|
6
|
+
export type { QueryState, QueryStatus } from "./store.js";
|
|
7
|
+
export interface UseQueryResult<T extends RunkuValue> extends QueryState<T> {
|
|
8
|
+
readonly refetch: () => Promise<RunkuResult<T>>;
|
|
9
|
+
}
|
|
10
|
+
export interface OperationState<T extends RunkuValue> {
|
|
11
|
+
readonly status: "idle" | "pending" | "success" | "error";
|
|
12
|
+
readonly data: T | undefined;
|
|
13
|
+
readonly result: RunkuResult<T> | undefined;
|
|
14
|
+
readonly error: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface UseMutationResult<A extends RunkuValue, R extends RunkuValue> extends OperationState<R> {
|
|
17
|
+
readonly mutate: (argumentsValue: A, options?: MutationOptions) => Promise<RunkuResult<R>>;
|
|
18
|
+
readonly reset: () => void;
|
|
19
|
+
}
|
|
20
|
+
export interface UseActionResult<A extends RunkuValue, R extends RunkuValue> extends OperationState<R> {
|
|
21
|
+
readonly execute: (argumentsValue: A, options?: CallOptions) => Promise<RunkuResult<R>>;
|
|
22
|
+
readonly reset: () => void;
|
|
23
|
+
}
|
|
24
|
+
export interface RunkuHydrationBoundaryProps {
|
|
25
|
+
readonly state: RunkuDehydratedState;
|
|
26
|
+
readonly children: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export declare function RunkuHydrationBoundary({ state, children }: RunkuHydrationBoundaryProps): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
export interface RunkuProviderProps {
|
|
30
|
+
readonly client: RunkuClient;
|
|
31
|
+
/** Stable, non-secret identity/cache partition such as a user ID or `anonymous`. */
|
|
32
|
+
readonly identityKey: string;
|
|
33
|
+
readonly children: ReactNode;
|
|
34
|
+
}
|
|
35
|
+
export declare function RunkuProvider({ client, identityKey, children }: RunkuProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
export declare function useRunkuClient(): RunkuClient;
|
|
37
|
+
export declare function useQuery<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"query", A, R, BrowserFunctionAuth>, argumentsValue: A, options?: CallOptions): UseQueryResult<R>;
|
|
38
|
+
export declare function useMutation<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"mutation", A, R, BrowserFunctionAuth>): UseMutationResult<A, R>;
|
|
39
|
+
export declare function useAction<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"action", A, R, BrowserFunctionAuth>): UseActionResult<A, R>;
|
|
40
|
+
export declare function useUploadFile(): (grant: FileUploadGrant, body: BodyInit, options?: FileUploadOptions) => Promise<FileMetadata>;
|
|
41
|
+
export declare function useDownloadFile(): (grant: FileDownloadGrant, options?: FileDownloadOptions) => Promise<Response>;
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,WAAW,EACX,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,KAAK,UAAU,E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,QAAQ,EACd,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC,YAAY,CAAC,CAGzB;AAED,wBAAgB,eAAe,IAAI,CACjC,KAAK,EAAE,iBAAiB,EACxB,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,QAAQ,CAAC,CAGrB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState, useSyncExternalStore, } from "react";
|
|
4
|
+
import { queryKey, } from "./shared.js";
|
|
5
|
+
import { RunkuStore, } from "./store.js";
|
|
6
|
+
const StoreContext = createContext(null);
|
|
7
|
+
const HydrationContext = createContext(null);
|
|
8
|
+
export function RunkuHydrationBoundary({ state, children }) {
|
|
9
|
+
return _jsx(HydrationContext.Provider, { value: state, children: children });
|
|
10
|
+
}
|
|
11
|
+
export function RunkuProvider({ client, identityKey, children }) {
|
|
12
|
+
const hydration = useContext(HydrationContext);
|
|
13
|
+
const store = useMemo(() => new RunkuStore(client, identityKey, hydration), [client, identityKey, hydration]);
|
|
14
|
+
useEffect(() => () => store.close(), [store]);
|
|
15
|
+
return _jsx(StoreContext.Provider, { value: store, children: children });
|
|
16
|
+
}
|
|
17
|
+
export function useRunkuClient() {
|
|
18
|
+
return useStore().client;
|
|
19
|
+
}
|
|
20
|
+
export function useQuery(reference, argumentsValue, options = {}) {
|
|
21
|
+
const store = useStore();
|
|
22
|
+
const key = queryKey(reference, argumentsValue, options);
|
|
23
|
+
const stableArguments = useMemo(() => argumentsValue, [key]);
|
|
24
|
+
const stableOptions = useMemo(() => ({
|
|
25
|
+
...(options.target === undefined ? {} : { target: options.target }),
|
|
26
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
27
|
+
}), [options.target, options.signal]);
|
|
28
|
+
const subscribe = useCallback((listener) => store.listen(key, reference, stableArguments, stableOptions, listener), [store, key, reference, stableArguments, stableOptions]);
|
|
29
|
+
const getSnapshot = useCallback(() => store.entry(key).snapshot, [store, key]);
|
|
30
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
31
|
+
const refetch = useCallback(() => store.refetch(key, reference, stableArguments, stableOptions), [store, key, reference, stableArguments, stableOptions]);
|
|
32
|
+
return useMemo(() => ({ ...snapshot, refetch }), [snapshot, refetch]);
|
|
33
|
+
}
|
|
34
|
+
export function useMutation(reference) {
|
|
35
|
+
const client = useRunkuClient();
|
|
36
|
+
const [state, setState] = useState(idleState);
|
|
37
|
+
const mutate = useCallback(async (argumentsValue, options) => {
|
|
38
|
+
setState(pendingState);
|
|
39
|
+
try {
|
|
40
|
+
const result = await client.mutation(reference, argumentsValue, options);
|
|
41
|
+
setState({ status: "success", data: result.value, result, error: null });
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
setState({ status: "error", data: undefined, result: undefined, error });
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}, [client, reference]);
|
|
49
|
+
const reset = useCallback(() => setState(idleState), []);
|
|
50
|
+
return { ...state, mutate, reset };
|
|
51
|
+
}
|
|
52
|
+
export function useAction(reference) {
|
|
53
|
+
const client = useRunkuClient();
|
|
54
|
+
const [state, setState] = useState(idleState);
|
|
55
|
+
const execute = useCallback(async (argumentsValue, options) => {
|
|
56
|
+
setState(pendingState);
|
|
57
|
+
try {
|
|
58
|
+
const result = await client.action(reference, argumentsValue, options);
|
|
59
|
+
setState({ status: "success", data: result.value, result, error: null });
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
setState({ status: "error", data: undefined, result: undefined, error });
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}, [client, reference]);
|
|
67
|
+
const reset = useCallback(() => setState(idleState), []);
|
|
68
|
+
return { ...state, execute, reset };
|
|
69
|
+
}
|
|
70
|
+
export function useUploadFile() {
|
|
71
|
+
const client = useRunkuClient();
|
|
72
|
+
return useCallback((grant, body, options) => client.uploadFile(grant, body, options), [client]);
|
|
73
|
+
}
|
|
74
|
+
export function useDownloadFile() {
|
|
75
|
+
const client = useRunkuClient();
|
|
76
|
+
return useCallback((grant, options) => client.downloadFile(grant, options), [client]);
|
|
77
|
+
}
|
|
78
|
+
function useStore() {
|
|
79
|
+
const store = useContext(StoreContext);
|
|
80
|
+
if (store === null)
|
|
81
|
+
throw new Error("Runku hooks must be used inside RunkuProvider");
|
|
82
|
+
return store;
|
|
83
|
+
}
|
|
84
|
+
const idleState = Object.freeze({
|
|
85
|
+
status: "idle",
|
|
86
|
+
data: undefined,
|
|
87
|
+
result: undefined,
|
|
88
|
+
error: null,
|
|
89
|
+
});
|
|
90
|
+
const pendingState = Object.freeze({
|
|
91
|
+
status: "pending",
|
|
92
|
+
data: undefined,
|
|
93
|
+
result: undefined,
|
|
94
|
+
error: null,
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,oBAAoB,GAErB,MAAM,OAAO,CAAC;AAgBf,OAAO,EACL,QAAQ,GAET,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,UAAU,GAEX,MAAM,YAAY,CAAC;AA4BpB,MAAM,YAAY,GAAG,aAAa,CAAoB,IAAI,CAAC,CAAC;AAC5D,MAAM,gBAAgB,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAC;AAO1E,MAAM,UAAU,sBAAsB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAA+B;IACrF,OAAO,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GA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AS;IACjB,KAAK,EAAE,IAAI;CACZ,CAAC,CAAC;AAEH,MAAM,YAAY,GAA0B,MAAM,CAAC,MAAM,CAAC;IACxD,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,IAAI;CACZ,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CallOptions, FileDownloadGrant, FileDownloadOptions, FileMetadata, FileUploadGrant, FileUploadOptions, FunctionReference, MutationOptions, RunkuClient, RunkuRealtimeClient, RunkuResult, RunkuValue, RealtimeClientOptions } from "@runku/client";
|
|
2
|
+
import { type RunkuDehydratedState } from "./shared.js";
|
|
3
|
+
export type { DehydratedQuery, RunkuDehydratedState } from "./shared.js";
|
|
4
|
+
export interface RunkuReactServer {
|
|
5
|
+
readonly client: RunkuClient;
|
|
6
|
+
query<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"query", A, R>, argumentsValue: A, options?: CallOptions): Promise<RunkuResult<R>>;
|
|
7
|
+
preloadQuery<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"query", A, R>, argumentsValue: A, options?: CallOptions): Promise<RunkuResult<R>>;
|
|
8
|
+
mutation<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"mutation", A, R>, argumentsValue: A, options?: MutationOptions): Promise<RunkuResult<R>>;
|
|
9
|
+
action<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"action", A, R>, argumentsValue: A, options?: CallOptions): Promise<RunkuResult<R>>;
|
|
10
|
+
uploadFile(grant: FileUploadGrant, body: BodyInit, options?: FileUploadOptions): Promise<FileMetadata>;
|
|
11
|
+
downloadFile(grant: FileDownloadGrant, options?: FileDownloadOptions): Promise<Response>;
|
|
12
|
+
/** Opens Realtime for a long-lived server process; avoid request-scoped RSC subscriptions. */
|
|
13
|
+
realtime(options?: RealtimeClientOptions): RunkuRealtimeClient;
|
|
14
|
+
dehydrate(): RunkuDehydratedState;
|
|
15
|
+
}
|
|
16
|
+
/** Creates a request-local server facade. Never share it between identities or requests. */
|
|
17
|
+
export declare function createRunkuReactServer(client: RunkuClient, identityKey: string): RunkuReactServer;
|
|
18
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,qBAAqB,EACtB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEzE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,KAAK,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAC9C,SAAS,EAAE,iBAAiB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,EAC3C,cAAc,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACrD,SAAS,EAAE,iBAAiB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,EAC3C,cAAc,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,QAAQ,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EACjD,SAAS,EAAE,iBAAiB,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC,EAC9C,cAAc,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,UAAU,EAC/C,SAAS,EAAE,iBAAiB,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5C,cAAc,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACvG,YAAY,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzF,8FAA8F;IAC9F,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAC;IAC/D,SAAS,IAAI,oBAAoB,CAAC;CACnC;AAED,4FAA4F;AAC5F,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,GAAG,gBAAgB,CAkCjG"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { dehydrateResult, queryKey, } from "./shared.js";
|
|
2
|
+
/** Creates a request-local server facade. Never share it between identities or requests. */
|
|
3
|
+
export function createRunkuReactServer(client, identityKey) {
|
|
4
|
+
if (identityKey.length === 0)
|
|
5
|
+
throw new TypeError("identityKey must not be empty");
|
|
6
|
+
const queries = new Map();
|
|
7
|
+
const pending = new Map();
|
|
8
|
+
const preloadQuery = async (reference, argumentsValue, options = {}) => {
|
|
9
|
+
const key = queryKey(reference, argumentsValue, options);
|
|
10
|
+
let promise = pending.get(key);
|
|
11
|
+
if (promise === undefined) {
|
|
12
|
+
promise = client.query(reference, argumentsValue, options);
|
|
13
|
+
pending.set(key, promise);
|
|
14
|
+
}
|
|
15
|
+
const result = await promise;
|
|
16
|
+
queries.set(key, dehydrateResult(key, reference, argumentsValue, options, result));
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
client,
|
|
21
|
+
query: (reference, argumentsValue, options) => client.query(reference, argumentsValue, options),
|
|
22
|
+
preloadQuery,
|
|
23
|
+
mutation: (reference, argumentsValue, options) => client.mutation(reference, argumentsValue, options),
|
|
24
|
+
action: (reference, argumentsValue, options) => client.action(reference, argumentsValue, options),
|
|
25
|
+
uploadFile: (grant, body, options) => client.uploadFile(grant, body, options),
|
|
26
|
+
downloadFile: (grant, options) => client.downloadFile(grant, options),
|
|
27
|
+
realtime: (options) => client.realtime(options),
|
|
28
|
+
dehydrate: () => Object.freeze({
|
|
29
|
+
version: 1,
|
|
30
|
+
identityKey,
|
|
31
|
+
queries: Object.freeze([...queries.values()]),
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,eAAe,EACf,QAAQ,GAET,MAAM,aAAa,CAAC;AAiCrB,4FAA4F;AAC5F,MAAM,UAAU,sBAAsB,CAAC,MAAmB,EAAE,WAAmB;IAC7E,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;IACnF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmD,CAAC;IAC3E,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4C,CAAC;IACpE,MAAM,YAAY,GAAG,KAAK,EACxB,SAA2C,EAC3C,cAAiB,EACjB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YAAY,CAAC,KAAK,EAAE,OAAO,CAAC;QACrE,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC/C,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;YAC7B,OAAO,EAAE,CAAC;YACV,WAAW;YACX,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;SAC9C,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CallOptions, type CodeTarget, type FunctionReference, type RunkuResult, type RunkuValue } from "@runku/client";
|
|
2
|
+
export interface DehydratedQuery {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly target: CodeTarget | null;
|
|
5
|
+
readonly functionName: string;
|
|
6
|
+
readonly arguments: unknown;
|
|
7
|
+
readonly result: {
|
|
8
|
+
readonly requestId: string;
|
|
9
|
+
readonly releaseId: string;
|
|
10
|
+
readonly value: unknown;
|
|
11
|
+
readonly snapshotSequence: string | null;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface RunkuDehydratedState {
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
readonly identityKey: string;
|
|
17
|
+
readonly queries: readonly DehydratedQuery[];
|
|
18
|
+
}
|
|
19
|
+
export declare function queryKey<A extends RunkuValue, R extends RunkuValue>(reference: FunctionReference<"query", A, R>, argumentsValue: A, options?: CallOptions): string;
|
|
20
|
+
export declare function dehydrateResult<A extends RunkuValue, T extends RunkuValue>(key: string, reference: FunctionReference<"query", A, T>, argumentsValue: A, options: CallOptions, result: RunkuResult<T>): DehydratedQuery;
|
|
21
|
+
export declare function hydrateValue(entry: DehydratedQuery): RunkuValue;
|
|
22
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,eAAe,CAcjB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,UAAU,CAE/D"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { decodeValue, encodeValue, } from "@runku/client";
|
|
2
|
+
export function queryKey(reference, argumentsValue, options = {}) {
|
|
3
|
+
return JSON.stringify([
|
|
4
|
+
options.target ?? null,
|
|
5
|
+
reference.name,
|
|
6
|
+
encodeValue(argumentsValue),
|
|
7
|
+
]);
|
|
8
|
+
}
|
|
9
|
+
export function dehydrateResult(key, reference, argumentsValue, options, result) {
|
|
10
|
+
if (result.metadata.kind !== "query")
|
|
11
|
+
throw new TypeError("Only query results can be dehydrated");
|
|
12
|
+
return Object.freeze({
|
|
13
|
+
key,
|
|
14
|
+
target: options.target ?? null,
|
|
15
|
+
functionName: reference.name,
|
|
16
|
+
arguments: encodeValue(argumentsValue),
|
|
17
|
+
result: Object.freeze({
|
|
18
|
+
requestId: result.requestId,
|
|
19
|
+
releaseId: result.releaseId,
|
|
20
|
+
value: encodeValue(result.value),
|
|
21
|
+
snapshotSequence: result.metadata.snapshotSequence?.toString() ?? null,
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function hydrateValue(entry) {
|
|
26
|
+
return decodeValue(entry.result.value);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,GAMZ,MAAM,eAAe,CAAC;AAqBvB,MAAM,UAAU,QAAQ,CACtB,SAA2C,EAC3C,cAAiB,EACjB,OAAO,GAAgB,EAAE;IAEzB,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,OAAO,CAAC,MAAM,IAAI,IAAI;QACtB,SAAS,CAAC,IAAI;QACd,WAAW,CAAC,cAAc,CAAC;KAC5B,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,GAAW,EACX,SAA2C,EAC3C,cAAiB,EACjB,OAAoB,EACpB,MAAsB;IAEtB,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO;QAAE,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IAClG,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG;QACH,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI;QAC9B,YAAY,EAAE,SAAS,CAAC,IAAI;QAC5B,SAAS,EAAE,WAAW,CAAC,cAAc,CAAC;QACtC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;YACpB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;YAChC,gBAAgB,EAAE,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,EAAE,IAAI,IAAI;SACvE,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAsB;IACjD,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BrowserFunctionAuth, CallOptions, FunctionReference, RunkuClient, RunkuError, RunkuRealtimeSubscription, RunkuResult, RunkuValue } from "@runku/client";
|
|
2
|
+
import { type RunkuDehydratedState } from "./shared.js";
|
|
3
|
+
export type QueryStatus = "pending" | "success" | "error";
|
|
4
|
+
export interface QueryState<T extends RunkuValue> {
|
|
5
|
+
readonly status: QueryStatus;
|
|
6
|
+
readonly data: T | undefined;
|
|
7
|
+
readonly error: RunkuError | null;
|
|
8
|
+
readonly releaseId: string | null;
|
|
9
|
+
readonly snapshotSequence: bigint | null;
|
|
10
|
+
readonly isStale: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface QueryEntry<T extends RunkuValue = RunkuValue> {
|
|
13
|
+
snapshot: QueryState<T>;
|
|
14
|
+
listeners: Set<() => void>;
|
|
15
|
+
subscription: RunkuRealtimeSubscription<T> | null;
|
|
16
|
+
}
|
|
17
|
+
/** Internal query store. It is emitted for package tests but is not a public package export. */
|
|
18
|
+
export declare class RunkuStore {
|
|
19
|
+
#private;
|
|
20
|
+
readonly client: RunkuClient;
|
|
21
|
+
readonly entries: Map<string, QueryEntry<RunkuValue>>;
|
|
22
|
+
constructor(client: RunkuClient, identityKey: string, state: RunkuDehydratedState | null);
|
|
23
|
+
entry(key: string): QueryEntry;
|
|
24
|
+
listen<A extends RunkuValue, R extends RunkuValue>(key: string, reference: FunctionReference<"query", A, R, BrowserFunctionAuth>, argumentsValue: A, options: CallOptions, listener: () => void): () => void;
|
|
25
|
+
refetch<A extends RunkuValue, R extends RunkuValue>(key: string, reference: FunctionReference<"query", A, R, BrowserFunctionAuth>, argumentsValue: A, options: CallOptions): Promise<RunkuResult<R>>;
|
|
26
|
+
close(): void;
|
|
27
|
+
private realtime;
|
|
28
|
+
private emit;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,UAAU,EAEV,yBAAyB,EACzB,WAAW,EACX,UAAU,EACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE1D,MAAM,WAAW,UAAU,CA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EAAE,CAAC,EAAE,CAAC,EAAE,mBAAmB,CAAC,EAChE,cAAc,EAAE,CAAC,EACjB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAczB;IAED,KAAK,IAAI,IAAI,CAQZ;IAED,OAAO,CAAC,QAAQ;IAKhB,OAAO,CAAC,IAAI;CAGb"}
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { hydrateValue, } from "./shared.js";
|
|
2
|
+
const PENDING = Object.freeze({
|
|
3
|
+
status: "pending",
|
|
4
|
+
data: undefined,
|
|
5
|
+
error: null,
|
|
6
|
+
releaseId: null,
|
|
7
|
+
snapshotSequence: null,
|
|
8
|
+
isStale: false,
|
|
9
|
+
});
|
|
10
|
+
const MAX_CACHED_QUERIES = 500;
|
|
11
|
+
/** Internal query store. It is emitted for package tests but is not a public package export. */
|
|
12
|
+
export class RunkuStore {
|
|
13
|
+
client;
|
|
14
|
+
entries = new Map();
|
|
15
|
+
#realtime = null;
|
|
16
|
+
constructor(client, identityKey, state) {
|
|
17
|
+
this.client = client;
|
|
18
|
+
if (identityKey.length === 0)
|
|
19
|
+
throw new TypeError("identityKey must not be empty");
|
|
20
|
+
if (state !== null) {
|
|
21
|
+
if (state.version !== 1 || state.identityKey !== identityKey) {
|
|
22
|
+
throw new TypeError("Runku hydration state does not match the active identity");
|
|
23
|
+
}
|
|
24
|
+
if (state.queries.length > MAX_CACHED_QUERIES) {
|
|
25
|
+
throw new TypeError("Runku hydration state exceeds the query cache limit");
|
|
26
|
+
}
|
|
27
|
+
for (const query of state.queries) {
|
|
28
|
+
this.entries.set(query.key, {
|
|
29
|
+
snapshot: Object.freeze({
|
|
30
|
+
status: "success",
|
|
31
|
+
data: hydrateValue(query),
|
|
32
|
+
error: null,
|
|
33
|
+
releaseId: query.result.releaseId,
|
|
34
|
+
snapshotSequence: query.result.snapshotSequence === null
|
|
35
|
+
? null
|
|
36
|
+
: BigInt(query.result.snapshotSequence),
|
|
37
|
+
isStale: true,
|
|
38
|
+
}),
|
|
39
|
+
listeners: new Set(),
|
|
40
|
+
subscription: null,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
entry(key) {
|
|
46
|
+
let entry = this.entries.get(key);
|
|
47
|
+
if (entry === undefined) {
|
|
48
|
+
if (this.entries.size >= MAX_CACHED_QUERIES) {
|
|
49
|
+
const evictable = [...this.entries].find(([, candidate]) => candidate.listeners.size === 0);
|
|
50
|
+
if (evictable === undefined)
|
|
51
|
+
throw new Error("Runku query cache limit reached");
|
|
52
|
+
this.entries.delete(evictable[0]);
|
|
53
|
+
}
|
|
54
|
+
entry = { snapshot: PENDING, listeners: new Set(), subscription: null };
|
|
55
|
+
this.entries.set(key, entry);
|
|
56
|
+
}
|
|
57
|
+
return entry;
|
|
58
|
+
}
|
|
59
|
+
listen(key, reference, argumentsValue, options, listener) {
|
|
60
|
+
const entry = this.entry(key);
|
|
61
|
+
entry.listeners.add(listener);
|
|
62
|
+
if (entry.subscription === null) {
|
|
63
|
+
entry.subscription = this.realtime().subscribe(reference, argumentsValue, {
|
|
64
|
+
...options,
|
|
65
|
+
onValue: (state) => {
|
|
66
|
+
entry.snapshot = Object.freeze({
|
|
67
|
+
status: "success",
|
|
68
|
+
data: state.value,
|
|
69
|
+
error: null,
|
|
70
|
+
releaseId: state.releaseId,
|
|
71
|
+
snapshotSequence: state.snapshotSequence,
|
|
72
|
+
isStale: false,
|
|
73
|
+
});
|
|
74
|
+
this.emit(entry);
|
|
75
|
+
},
|
|
76
|
+
onError: (error) => {
|
|
77
|
+
entry.snapshot = Object.freeze({
|
|
78
|
+
...entry.snapshot,
|
|
79
|
+
status: "error",
|
|
80
|
+
error,
|
|
81
|
+
isStale: true,
|
|
82
|
+
});
|
|
83
|
+
this.emit(entry);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
void entry.subscription.ready.catch(() => undefined);
|
|
87
|
+
}
|
|
88
|
+
return () => {
|
|
89
|
+
entry.listeners.delete(listener);
|
|
90
|
+
if (entry.listeners.size === 0 && entry.subscription !== null) {
|
|
91
|
+
const subscription = entry.subscription;
|
|
92
|
+
entry.subscription = null;
|
|
93
|
+
void subscription.unsubscribe();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async refetch(key, reference, argumentsValue, options) {
|
|
98
|
+
const result = await this.client.query(reference, argumentsValue, options);
|
|
99
|
+
const entry = this.entry(key);
|
|
100
|
+
if (result.metadata.kind !== "query")
|
|
101
|
+
throw new TypeError("Runku returned non-query metadata");
|
|
102
|
+
entry.snapshot = Object.freeze({
|
|
103
|
+
status: "success",
|
|
104
|
+
data: result.value,
|
|
105
|
+
error: null,
|
|
106
|
+
releaseId: result.releaseId,
|
|
107
|
+
snapshotSequence: result.metadata.snapshotSequence,
|
|
108
|
+
isStale: false,
|
|
109
|
+
});
|
|
110
|
+
this.emit(entry);
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
close() {
|
|
114
|
+
const realtime = this.#realtime;
|
|
115
|
+
this.#realtime = null;
|
|
116
|
+
realtime?.close();
|
|
117
|
+
for (const entry of this.entries.values()) {
|
|
118
|
+
entry.subscription = null;
|
|
119
|
+
entry.listeners.clear();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
realtime() {
|
|
123
|
+
this.#realtime ??= this.client.realtime();
|
|
124
|
+
return this.#realtime;
|
|
125
|
+
}
|
|
126
|
+
emit(entry) {
|
|
127
|
+
for (const listener of entry.listeners)
|
|
128
|
+
listener();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,YAAY,GAEb,MAAM,aAAa,CAAC;AAmBrB,MAAM,OAAO,GAA2B,MAAM,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;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEO,IAAI,CAAC,KAAiB;QAC5B,KAAK,MAAM,QAAQ,IAAI,KAAK,CAAC,SAAS;YAAE,QAAQ,EAAE,CAAC;IACrD,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@runku/react",
|
|
3
|
+
"version": "0.4.8",
|
|
4
|
+
"description": "React and Next.js bindings for the Runku TypeScript client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"homepage": "https://github.com/aldemi-tech/runku/tree/main/packages/react#readme",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/aldemi-tech/runku/issues"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["runku", "react", "nextjs", "typescript", "realtime"],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/aldemi-tech/runku.git",
|
|
15
|
+
"directory": "packages/react"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./server": {
|
|
25
|
+
"types": "./dist/server.d.ts",
|
|
26
|
+
"import": "./dist/server.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"engines": { "node": ">=20" },
|
|
30
|
+
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" },
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@runku/client": "0.4.8",
|
|
33
|
+
"react": ">=18.3.0 <20"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@runku/client": "workspace:*",
|
|
37
|
+
"@types/react": "19.2.2",
|
|
38
|
+
"@types/react-dom": "19.2.2",
|
|
39
|
+
"react": "19.2.8",
|
|
40
|
+
"react-dom": "19.2.8",
|
|
41
|
+
"typescript": "7.0.2"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.check.json",
|
|
46
|
+
"lint": "tsc -p tsconfig.check.json",
|
|
47
|
+
"test": "pnpm build && node --test tests/*.test.mjs",
|
|
48
|
+
"check": "pnpm typecheck && pnpm lint && pnpm test"
|
|
49
|
+
}
|
|
50
|
+
}
|