@hops-ops/distributed 0.0.0

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.
Files changed (242) hide show
  1. package/README.md +454 -0
  2. package/dist/auth-headers.d.ts +8 -0
  3. package/dist/auth-headers.js +35 -0
  4. package/dist/diagnostics.d.ts +2 -0
  5. package/dist/diagnostics.js +1 -0
  6. package/dist/document.d.ts +8 -0
  7. package/dist/document.js +6 -0
  8. package/dist/identity.d.ts +23 -0
  9. package/dist/identity.js +73 -0
  10. package/dist/index.d.ts +7 -0
  11. package/dist/index.js +6 -0
  12. package/dist/internal/cache-engine/create.d.ts +5 -0
  13. package/dist/internal/cache-engine/create.js +7 -0
  14. package/dist/internal/cache-engine/engine.d.ts +32 -0
  15. package/dist/internal/cache-engine/engine.js +1287 -0
  16. package/dist/internal/cache-engine/errors.d.ts +5 -0
  17. package/dist/internal/cache-engine/errors.js +10 -0
  18. package/dist/internal/cache-engine/helpers.d.ts +55 -0
  19. package/dist/internal/cache-engine/helpers.js +545 -0
  20. package/dist/internal/cache-engine/index.d.ts +3 -0
  21. package/dist/internal/cache-engine/index.js +2 -0
  22. package/dist/internal/cache-engine/types.d.ts +300 -0
  23. package/dist/internal/cache-engine/types.js +1 -0
  24. package/dist/internal/cache-engine.d.ts +3 -0
  25. package/dist/internal/cache-engine.js +2 -0
  26. package/dist/lib/assert-name.d.ts +2 -0
  27. package/dist/lib/assert-name.js +6 -0
  28. package/dist/lib/compare-code-units.d.ts +2 -0
  29. package/dist/lib/compare-code-units.js +4 -0
  30. package/dist/lib/deep-equal.d.ts +2 -0
  31. package/dist/lib/deep-equal.js +24 -0
  32. package/dist/lib/freeze-record.d.ts +2 -0
  33. package/dist/lib/freeze-record.js +13 -0
  34. package/dist/lib/index.d.ts +6 -0
  35. package/dist/lib/index.js +6 -0
  36. package/dist/lib/is-plain-record.d.ts +2 -0
  37. package/dist/lib/is-plain-record.js +8 -0
  38. package/dist/lib/report.d.ts +7 -0
  39. package/dist/lib/report.js +26 -0
  40. package/dist/protocol.d.ts +179 -0
  41. package/dist/protocol.js +558 -0
  42. package/dist/react/context.d.ts +20 -0
  43. package/dist/react/context.js +24 -0
  44. package/dist/react/index.d.ts +2 -0
  45. package/dist/react/index.js +3 -0
  46. package/dist/react/query.d.ts +20 -0
  47. package/dist/react/query.js +99 -0
  48. package/dist/replica/command-id.d.ts +2 -0
  49. package/dist/replica/command-id.js +19 -0
  50. package/dist/replica/command-runtime/constants.d.ts +5 -0
  51. package/dist/replica/command-runtime/constants.js +5 -0
  52. package/dist/replica/command-runtime/create.d.ts +2 -0
  53. package/dist/replica/command-runtime/create.js +644 -0
  54. package/dist/replica/command-runtime/errors.d.ts +16 -0
  55. package/dist/replica/command-runtime/errors.js +41 -0
  56. package/dist/replica/command-runtime/index.d.ts +5 -0
  57. package/dist/replica/command-runtime/index.js +4 -0
  58. package/dist/replica/command-runtime/lib/binding.d.ts +4 -0
  59. package/dist/replica/command-runtime/lib/binding.js +64 -0
  60. package/dist/replica/command-runtime/lib/effects.d.ts +11 -0
  61. package/dist/replica/command-runtime/lib/effects.js +89 -0
  62. package/dist/replica/command-runtime/lib/index.d.ts +9 -0
  63. package/dist/replica/command-runtime/lib/index.js +9 -0
  64. package/dist/replica/command-runtime/lib/inventory.d.ts +10 -0
  65. package/dist/replica/command-runtime/lib/inventory.js +141 -0
  66. package/dist/replica/command-runtime/lib/output.d.ts +13 -0
  67. package/dist/replica/command-runtime/lib/output.js +190 -0
  68. package/dist/replica/command-runtime/lib/projection.d.ts +20 -0
  69. package/dist/replica/command-runtime/lib/projection.js +255 -0
  70. package/dist/replica/command-runtime/lib/status.d.ts +7 -0
  71. package/dist/replica/command-runtime/lib/status.js +127 -0
  72. package/dist/replica/command-runtime/lib/transport.d.ts +16 -0
  73. package/dist/replica/command-runtime/lib/transport.js +112 -0
  74. package/dist/replica/command-runtime/lib/util.d.ts +16 -0
  75. package/dist/replica/command-runtime/lib/util.js +127 -0
  76. package/dist/replica/command-runtime/lifecycle.d.ts +11 -0
  77. package/dist/replica/command-runtime/lifecycle.js +13 -0
  78. package/dist/replica/command-runtime/symbols.d.ts +30 -0
  79. package/dist/replica/command-runtime/symbols.js +30 -0
  80. package/dist/replica/command-runtime/types.d.ts +222 -0
  81. package/dist/replica/command-runtime/types.js +1 -0
  82. package/dist/replica/command-runtime.d.ts +3 -0
  83. package/dist/replica/command-runtime.js +2 -0
  84. package/dist/replica/commands/clone.d.ts +12 -0
  85. package/dist/replica/commands/clone.js +187 -0
  86. package/dist/replica/commands/constants.d.ts +6 -0
  87. package/dist/replica/commands/constants.js +6 -0
  88. package/dist/replica/commands/errors.d.ts +7 -0
  89. package/dist/replica/commands/errors.js +22 -0
  90. package/dist/replica/commands/implementation.d.ts +8 -0
  91. package/dist/replica/commands/implementation.js +8 -0
  92. package/dist/replica/commands/index.d.ts +5 -0
  93. package/dist/replica/commands/index.js +4 -0
  94. package/dist/replica/commands/prepare.d.ts +27 -0
  95. package/dist/replica/commands/prepare.js +77 -0
  96. package/dist/replica/commands/presets.d.ts +12 -0
  97. package/dist/replica/commands/presets.js +84 -0
  98. package/dist/replica/commands/receipt.d.ts +3 -0
  99. package/dist/replica/commands/receipt.js +36 -0
  100. package/dist/replica/commands/resolve.d.ts +11 -0
  101. package/dist/replica/commands/resolve.js +165 -0
  102. package/dist/replica/commands/types.d.ts +278 -0
  103. package/dist/replica/commands/types.js +2 -0
  104. package/dist/replica/commands/util.d.ts +21 -0
  105. package/dist/replica/commands/util.js +96 -0
  106. package/dist/replica/commands/validate.d.ts +18 -0
  107. package/dist/replica/commands/validate.js +477 -0
  108. package/dist/replica/commands.d.ts +3 -0
  109. package/dist/replica/commands.js +2 -0
  110. package/dist/replica/diagnostics/event-log.d.ts +4 -0
  111. package/dist/replica/diagnostics/event-log.js +463 -0
  112. package/dist/replica/diagnostics/implementation.d.ts +4 -0
  113. package/dist/replica/diagnostics/implementation.js +4 -0
  114. package/dist/replica/diagnostics/index.d.ts +2 -0
  115. package/dist/replica/diagnostics/index.js +1 -0
  116. package/dist/replica/diagnostics/inspect.d.ts +6 -0
  117. package/dist/replica/diagnostics/inspect.js +170 -0
  118. package/dist/replica/diagnostics/types.d.ts +295 -0
  119. package/dist/replica/diagnostics/types.js +2 -0
  120. package/dist/replica/diagnostics.d.ts +3 -0
  121. package/dist/replica/diagnostics.js +2 -0
  122. package/dist/replica/distributed-replica/clocks.d.ts +23 -0
  123. package/dist/replica/distributed-replica/clocks.js +156 -0
  124. package/dist/replica/distributed-replica/constants.d.ts +12 -0
  125. package/dist/replica/distributed-replica/constants.js +10 -0
  126. package/dist/replica/distributed-replica/helpers.d.ts +48 -0
  127. package/dist/replica/distributed-replica/helpers.js +445 -0
  128. package/dist/replica/distributed-replica/hydration.d.ts +19 -0
  129. package/dist/replica/distributed-replica/hydration.js +380 -0
  130. package/dist/replica/distributed-replica/impl-diagnostics.d.ts +22 -0
  131. package/dist/replica/distributed-replica/impl-diagnostics.js +189 -0
  132. package/dist/replica/distributed-replica/impl-fetch-live.d.ts +39 -0
  133. package/dist/replica/distributed-replica/impl-fetch-live.js +395 -0
  134. package/dist/replica/distributed-replica/impl-hydration-orchestrate.d.ts +56 -0
  135. package/dist/replica/distributed-replica/impl-hydration-orchestrate.js +299 -0
  136. package/dist/replica/distributed-replica/impl-optimistic.d.ts +31 -0
  137. package/dist/replica/distributed-replica/impl-optimistic.js +172 -0
  138. package/dist/replica/distributed-replica/impl-protocol.d.ts +53 -0
  139. package/dist/replica/distributed-replica/impl-protocol.js +108 -0
  140. package/dist/replica/distributed-replica/impl.d.ts +44 -0
  141. package/dist/replica/distributed-replica/impl.js +1776 -0
  142. package/dist/replica/distributed-replica/index.d.ts +2 -0
  143. package/dist/replica/distributed-replica/index.js +4 -0
  144. package/dist/replica/distributed-replica/optimistic.d.ts +30 -0
  145. package/dist/replica/distributed-replica/optimistic.js +221 -0
  146. package/dist/replica/distributed-replica/types.d.ts +147 -0
  147. package/dist/replica/distributed-replica/types.js +1 -0
  148. package/dist/replica/distributed-replica/watch.d.ts +19 -0
  149. package/dist/replica/distributed-replica/watch.js +95 -0
  150. package/dist/replica/distributed-replica.d.ts +2 -0
  151. package/dist/replica/distributed-replica.js +2 -0
  152. package/dist/replica/graphql-transport.d.ts +24 -0
  153. package/dist/replica/graphql-transport.js +122 -0
  154. package/dist/replica/identity/clone.d.ts +6 -0
  155. package/dist/replica/identity/clone.js +54 -0
  156. package/dist/replica/identity/codec.d.ts +48 -0
  157. package/dist/replica/identity/codec.js +789 -0
  158. package/dist/replica/identity/constants.d.ts +3 -0
  159. package/dist/replica/identity/constants.js +18 -0
  160. package/dist/replica/identity/implementation.d.ts +5 -0
  161. package/dist/replica/identity/implementation.js +5 -0
  162. package/dist/replica/identity/index.d.ts +3 -0
  163. package/dist/replica/identity/index.js +3 -0
  164. package/dist/replica/identity/keys.d.ts +29 -0
  165. package/dist/replica/identity/keys.js +173 -0
  166. package/dist/replica/identity.d.ts +2 -0
  167. package/dist/replica/identity.js +2 -0
  168. package/dist/replica/index-maintenance/engine.d.ts +84 -0
  169. package/dist/replica/index-maintenance/engine.js +677 -0
  170. package/dist/replica/index-maintenance/implementation.d.ts +4 -0
  171. package/dist/replica/index-maintenance/implementation.js +4 -0
  172. package/dist/replica/index-maintenance/index.d.ts +2 -0
  173. package/dist/replica/index-maintenance/index.js +1 -0
  174. package/dist/replica/index-maintenance/registry.d.ts +2 -0
  175. package/dist/replica/index-maintenance/registry.js +49 -0
  176. package/dist/replica/index-maintenance/types.d.ts +58 -0
  177. package/dist/replica/index-maintenance/types.js +1 -0
  178. package/dist/replica/index-maintenance.d.ts +3 -0
  179. package/dist/replica/index-maintenance.js +2 -0
  180. package/dist/replica/index.d.ts +17 -0
  181. package/dist/replica/index.js +9 -0
  182. package/dist/replica/materialize.d.ts +10 -0
  183. package/dist/replica/materialize.js +163 -0
  184. package/dist/replica/normalize.d.ts +27 -0
  185. package/dist/replica/normalize.js +298 -0
  186. package/dist/replica/operation-binding.d.ts +14 -0
  187. package/dist/replica/operation-binding.js +76 -0
  188. package/dist/replica/persistence/idb.d.ts +20 -0
  189. package/dist/replica/persistence/idb.js +193 -0
  190. package/dist/replica/persistence/implementation.d.ts +4 -0
  191. package/dist/replica/persistence/implementation.js +4 -0
  192. package/dist/replica/persistence/index.d.ts +2 -0
  193. package/dist/replica/persistence/index.js +1 -0
  194. package/dist/replica/persistence/state.d.ts +104 -0
  195. package/dist/replica/persistence/state.js +734 -0
  196. package/dist/replica/persistence/types.d.ts +54 -0
  197. package/dist/replica/persistence/types.js +1 -0
  198. package/dist/replica/persistence.d.ts +3 -0
  199. package/dist/replica/persistence.js +2 -0
  200. package/dist/replica/query-plan/constants.d.ts +13 -0
  201. package/dist/replica/query-plan/constants.js +7 -0
  202. package/dist/replica/query-plan/filter.d.ts +39 -0
  203. package/dist/replica/query-plan/filter.js +544 -0
  204. package/dist/replica/query-plan/index.d.ts +4 -0
  205. package/dist/replica/query-plan/index.js +3 -0
  206. package/dist/replica/query-plan/order.d.ts +11 -0
  207. package/dist/replica/query-plan/order.js +158 -0
  208. package/dist/replica/query-plan/pagination.d.ts +6 -0
  209. package/dist/replica/query-plan/pagination.js +90 -0
  210. package/dist/replica/query-plan/resolve.d.ts +14 -0
  211. package/dist/replica/query-plan/resolve.js +163 -0
  212. package/dist/replica/query-plan/types.d.ts +89 -0
  213. package/dist/replica/query-plan/types.js +1 -0
  214. package/dist/replica/query-plan/util.d.ts +13 -0
  215. package/dist/replica/query-plan/util.js +62 -0
  216. package/dist/replica/query-plan.d.ts +3 -0
  217. package/dist/replica/query-plan.js +2 -0
  218. package/dist/replica/revalidation.d.ts +9 -0
  219. package/dist/replica/revalidation.js +86 -0
  220. package/dist/replica/selection.d.ts +20 -0
  221. package/dist/replica/selection.js +109 -0
  222. package/dist/replica/types.d.ts +657 -0
  223. package/dist/replica/types.js +1 -0
  224. package/dist/request.d.ts +17 -0
  225. package/dist/request.js +123 -0
  226. package/dist/sveltekit/auth.d.ts +18 -0
  227. package/dist/sveltekit/auth.js +9 -0
  228. package/dist/sveltekit/context.d.ts +28 -0
  229. package/dist/sveltekit/context.js +58 -0
  230. package/dist/sveltekit/index.d.ts +4 -0
  231. package/dist/sveltekit/index.js +4 -0
  232. package/dist/sveltekit/replica.d.ts +145 -0
  233. package/dist/sveltekit/replica.js +491 -0
  234. package/dist/sveltekit/server-replica.d.ts +52 -0
  235. package/dist/sveltekit/server-replica.js +176 -0
  236. package/dist/sveltekit/vite.d.ts +103 -0
  237. package/dist/sveltekit/vite.js +878 -0
  238. package/dist/types.d.ts +33 -0
  239. package/dist/types.js +1 -0
  240. package/dist/websocket.d.ts +41 -0
  241. package/dist/websocket.js +187 -0
  242. package/package.json +95 -0
@@ -0,0 +1,123 @@
1
+ /** Isomorphic HTTP GraphQL request helper with injectable URL and authentication. */
2
+ import { buildAuthHeaders } from './auth-headers.js';
3
+ import { documentToString } from './document.js';
4
+ import { DistributedProtocolError, parseGraphqlResponseExtensions } from './protocol.js';
5
+ async function readResponseBody(response) {
6
+ let rawText;
7
+ if (typeof response.text === 'function') {
8
+ try {
9
+ rawText = await response.text();
10
+ }
11
+ catch {
12
+ // A fetch-compatible test double may only implement json().
13
+ }
14
+ }
15
+ if (rawText !== undefined) {
16
+ try {
17
+ return { body: asResponseBody(JSON.parse(rawText)) };
18
+ }
19
+ catch {
20
+ return { body: {}, rawText };
21
+ }
22
+ }
23
+ try {
24
+ return { body: asResponseBody(await response.json()) };
25
+ }
26
+ catch {
27
+ return { body: {} };
28
+ }
29
+ }
30
+ function asResponseBody(value) {
31
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
32
+ ? value
33
+ : {};
34
+ }
35
+ function httpFailureMessage(response, body, rawText) {
36
+ const jsonDetail = typeof body.error === 'string' ? body.error.trim() : '';
37
+ if (jsonDetail)
38
+ return jsonDetail;
39
+ const statusText = response.statusText?.trim();
40
+ const status = `HTTP ${response.status}${statusText ? ` ${statusText}` : ''}`;
41
+ const textDetail = rawText?.trim() ?? '';
42
+ if (!textDetail ||
43
+ /^<(?:!doctype\s+html|html|head|body)(?:\s|>)/i.test(textDetail)) {
44
+ return status;
45
+ }
46
+ const maxDetailLength = 500;
47
+ const boundedDetail = textDetail.length > maxDetailLength
48
+ ? `${textDetail.slice(0, maxDetailLength - 1)}…`
49
+ : textDetail;
50
+ return `${status}: ${boundedDetail}`;
51
+ }
52
+ /** POST a GraphQL document to `url`. */
53
+ export async function requestGraphql(url, document, auth = {}, variables = {}, options = {}) {
54
+ const fetchImpl = options.fetch ?? globalThis.fetch;
55
+ if (typeof fetchImpl !== 'function') {
56
+ throw new Error('requestGraphql requires a fetch implementation in this runtime; pass { fetch } as the final argument');
57
+ }
58
+ const token = auth.accessToken?.trim() ?? '';
59
+ const response = await fetchImpl(url, {
60
+ method: 'POST',
61
+ headers: buildAuthHeaders(auth),
62
+ body: JSON.stringify({
63
+ query: documentToString(document),
64
+ variables,
65
+ ...(options.extensions === undefined
66
+ ? {}
67
+ : { extensions: options.extensions })
68
+ }),
69
+ ...(options.signal === undefined ? {} : { signal: options.signal })
70
+ });
71
+ const { body, rawText } = await readResponseBody(response);
72
+ let extensions;
73
+ try {
74
+ extensions = parseGraphqlResponseExtensions(body.extensions);
75
+ }
76
+ catch (error) {
77
+ if (error instanceof DistributedProtocolError) {
78
+ return {
79
+ data: undefined,
80
+ errors: [
81
+ ...(body.errors ?? []),
82
+ {
83
+ message: error.message,
84
+ extensions: { code: error.code }
85
+ }
86
+ ],
87
+ status: response.status
88
+ };
89
+ }
90
+ throw error;
91
+ }
92
+ if (response.status === 401) {
93
+ const detail = body.errors?.[0]?.message ??
94
+ body.error ??
95
+ (token
96
+ ? 'Bearer rejected (audience/issuer/expiry) — sign out and back in'
97
+ : 'no access token — re-login; check OIDC scopes include the project audience');
98
+ return {
99
+ data: body.data,
100
+ errors: [{ message: detail }],
101
+ ...(extensions === undefined ? {} : { extensions }),
102
+ status: response.status
103
+ };
104
+ }
105
+ if (response.status >= 400 &&
106
+ response.status < 600 &&
107
+ !body.errors?.length) {
108
+ return {
109
+ data: body.data,
110
+ errors: [{ message: httpFailureMessage(response, body, rawText) }],
111
+ ...(extensions === undefined ? {} : { extensions }),
112
+ status: response.status
113
+ };
114
+ }
115
+ return {
116
+ data: body.data,
117
+ errors: body.errors,
118
+ ...(extensions === undefined ? {} : { extensions }),
119
+ status: response.status
120
+ };
121
+ }
122
+ export { documentToString } from './document.js';
123
+ export { buildAuthHeaders } from './auth-headers.js';
@@ -0,0 +1,18 @@
1
+ import type { GqlAuth } from '../types.js';
2
+ /** Minimal page-data shape needed to bind browser GraphQL authentication. */
3
+ export type PageGraphqlData = {
4
+ accessToken?: string | null;
5
+ session?: {
6
+ accessToken?: string | null;
7
+ user?: {
8
+ id?: string | null;
9
+ name?: string | null;
10
+ email?: string | null;
11
+ username?: string | null;
12
+ groups?: string[];
13
+ } | null;
14
+ } | null;
15
+ engineRole?: string | null;
16
+ };
17
+ /** Map SSR/page data into GraphQL auth (Bearer preferred; DevHeaders for local development). */
18
+ export declare function authFromPageData(data: PageGraphqlData): GqlAuth;
@@ -0,0 +1,9 @@
1
+ /** Map SSR/page data into GraphQL auth (Bearer preferred; DevHeaders for local development). */
2
+ export function authFromPageData(data) {
3
+ const accessToken = data.accessToken ?? data.session?.accessToken ?? null;
4
+ return {
5
+ accessToken,
6
+ userId: accessToken ? undefined : (data.session?.user?.id ?? undefined),
7
+ role: data.engineRole ?? undefined
8
+ };
9
+ }
@@ -0,0 +1,28 @@
1
+ import type { ReplicaOperationArtifact } from '../replica/index.js';
2
+ import type { GraphqlVariables } from '../types.js';
3
+ import type { DistributedSvelteKitClient, SveltekitBoundOperation } from './replica.js';
4
+ /**
5
+ * Install one client in the current Svelte component tree.
6
+ *
7
+ * The context key is module-global, but the client value is not: Svelte owns
8
+ * it per component tree/request. A nested elevated layout may deliberately
9
+ * replace the nearest user-safe client.
10
+ */
11
+ export declare function provideDistributedSvelteKitClient<TCommands>(client: DistributedSvelteKitClient<TCommands>): DistributedSvelteKitClient<TCommands>;
12
+ /**
13
+ * Resolve the nearest client during component initialization.
14
+ *
15
+ * This intentionally calls Svelte `getContext` each time. Generated modules
16
+ * may contain static operation wrappers, but never capture a client or command
17
+ * tree at module evaluation time.
18
+ */
19
+ export declare function useDistributedSvelteKitClient<TCommands = Readonly<Record<never, never>>>(): DistributedSvelteKitClient<TCommands>;
20
+ /** Resolve the nearest generated command surface without a global proxy. */
21
+ export declare function useDistributedSvelteKitCommands<TCommands>(): TCommands;
22
+ /**
23
+ * Define one SSR-safe generated operation wrapper.
24
+ *
25
+ * The wrapper stores only immutable compiler output. `use()` and `read()`
26
+ * resolve the nearest tree-local client when the component calls them.
27
+ */
28
+ export declare function defineDistributedSvelteKitOperation<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>): SveltekitBoundOperation<TData, TVariables>;
@@ -0,0 +1,58 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ const DISTRIBUTED_CLIENT_CONTEXT = Symbol('@hops-ops/distributed/sveltekit/client');
3
+ /**
4
+ * Install one client in the current Svelte component tree.
5
+ *
6
+ * The context key is module-global, but the client value is not: Svelte owns
7
+ * it per component tree/request. A nested elevated layout may deliberately
8
+ * replace the nearest user-safe client.
9
+ */
10
+ export function provideDistributedSvelteKitClient(client) {
11
+ if (client === null ||
12
+ typeof client !== 'object' ||
13
+ typeof client.operation !== 'function') {
14
+ throw new TypeError('provideDistributedSvelteKitClient requires a Distributed SvelteKit client');
15
+ }
16
+ setContext(DISTRIBUTED_CLIENT_CONTEXT, client);
17
+ return client;
18
+ }
19
+ /**
20
+ * Resolve the nearest client during component initialization.
21
+ *
22
+ * This intentionally calls Svelte `getContext` each time. Generated modules
23
+ * may contain static operation wrappers, but never capture a client or command
24
+ * tree at module evaluation time.
25
+ */
26
+ export function useDistributedSvelteKitClient() {
27
+ const client = getContext(DISTRIBUTED_CLIENT_CONTEXT);
28
+ if (client === undefined) {
29
+ throw new Error('Distributed client is missing from the active Svelte component tree; call generated provideDistributed(...) in a parent layout');
30
+ }
31
+ return client;
32
+ }
33
+ /** Resolve the nearest generated command surface without a global proxy. */
34
+ export function useDistributedSvelteKitCommands() {
35
+ return useDistributedSvelteKitClient().commands;
36
+ }
37
+ /**
38
+ * Define one SSR-safe generated operation wrapper.
39
+ *
40
+ * The wrapper stores only immutable compiler output. `use()` and `read()`
41
+ * resolve the nearest tree-local client when the component calls them.
42
+ */
43
+ export function defineDistributedSvelteKitOperation(artifact) {
44
+ const use = ((...args) => {
45
+ const operation = useDistributedSvelteKitClient().operation(artifact);
46
+ const invoke = operation.use;
47
+ return invoke(...args);
48
+ });
49
+ return Object.freeze({
50
+ artifact,
51
+ use,
52
+ read(variables) {
53
+ return useDistributedSvelteKitClient()
54
+ .operation(artifact)
55
+ .read(variables);
56
+ }
57
+ });
58
+ }
@@ -0,0 +1,4 @@
1
+ export { authFromPageData, type PageGraphqlData } from './auth.js';
2
+ export { defineDistributedSvelteKitOperation, provideDistributedSvelteKitClient, useDistributedSvelteKitClient, useDistributedSvelteKitCommands } from './context.js';
3
+ export { bindSveltekitOperation, createPageDataSessionSource, createDistributedSvelteKit, sessionSourceFromPageData, type CreateDistributedSvelteKitOptions, type DistributedSvelteKitClient, type SveltekitBoundOperation, type SveltekitCommandRuntimeFactory, type SveltekitCommandRuntimeFactoryOptions, type SveltekitCommandRuntimeLike, type SveltekitDistributedPageData, type SveltekitPageDataSessionSource, type SveltekitPageDataSource, type SveltekitQuerySnapshot, type SveltekitQueryStore, type SveltekitReplicaAuthority, type SveltekitReplicaHydration, type SveltekitSessionSource, type UseSveltekitOperationOptions } from './replica.js';
4
+ export { createDistributedSvelteKitServer, registerDistributedRoute, type CreateDistributedSvelteKitServerOptions, type DistributedRouteOperation, type DistributedRoutePlan, type DistributedRouteVariables, type DistributedSvelteKitServer, type SveltekitServerLoadEventLike } from './server-replica.js';
@@ -0,0 +1,4 @@
1
+ export { authFromPageData } from './auth.js';
2
+ export { defineDistributedSvelteKitOperation, provideDistributedSvelteKitClient, useDistributedSvelteKitClient, useDistributedSvelteKitCommands } from './context.js';
3
+ export { bindSveltekitOperation, createPageDataSessionSource, createDistributedSvelteKit, sessionSourceFromPageData } from './replica.js';
4
+ export { createDistributedSvelteKitServer, registerDistributedRoute } from './server-replica.js';
@@ -0,0 +1,145 @@
1
+ import { type DistributedReplica, type DistributedReplicaOptions, type ReplicaAuthoritativeScope, type ReplicaCommandReceipt, type ReplicaCommandRuntime, type ReplicaCommandRuntimeOptions, type ReplicaGraphqlTransport, type ReplicaOperationArtifact, type ReplicaSnapshot } from '../replica/index.js';
2
+ import type { GqlAuth, GqlError, GraphqlVariables } from '../types.js';
3
+ import type { WebSocketConstructor } from '../websocket.js';
4
+ import type { FetchLike } from '../request.js';
5
+ import { type PageGraphqlData } from './auth.js';
6
+ type UnknownCommandEntries = Readonly<Record<string, never>>;
7
+ export type SveltekitSessionSource = Readonly<{
8
+ /** Current credential. HTTP, WS, and commands all call this exact source. */
9
+ getAuth(): GqlAuth | Promise<GqlAuth>;
10
+ /**
11
+ * Notify on token, logout, role, tenant, or session changes.
12
+ *
13
+ * The adapter re-reads `getAuth`; callers never label a cache scope.
14
+ */
15
+ subscribe?(listener: () => void): () => void;
16
+ }>;
17
+ export type SveltekitPageDataSource<TData extends PageGraphqlData> = Readonly<{
18
+ get(): TData;
19
+ subscribe?(listener: () => void): () => void;
20
+ }>;
21
+ export type SveltekitPageDataSessionSource<TData extends PageGraphqlData> = Readonly<{
22
+ session: SveltekitSessionSource;
23
+ get(): TData;
24
+ set(next: TData): void;
25
+ }>;
26
+ export type SveltekitReplicaHydration = Readonly<{
27
+ version: 1;
28
+ state: import('../replica/index.js').ReplicaDehydratedState;
29
+ readonly operations?: readonly string[];
30
+ }>;
31
+ /**
32
+ * Independently trusted SSR/session authority for one hydration transfer.
33
+ *
34
+ * Do not persist this beside replica state. State never authorizes its own
35
+ * scope; the adapter compares its embedded scope to this server-owned value.
36
+ */
37
+ export type SveltekitReplicaAuthority = Readonly<{
38
+ version: 1;
39
+ scope: ReplicaAuthoritativeScope;
40
+ }>;
41
+ export type SveltekitDistributedPageData = PageGraphqlData & Readonly<{
42
+ distributed?: SveltekitReplicaHydration;
43
+ distributedAuthority?: SveltekitReplicaAuthority;
44
+ }>;
45
+ export type SveltekitCommandRuntimeLike<TCommands> = Pick<ReplicaCommandRuntime<UnknownCommandEntries>, 'dispose'> & Readonly<{
46
+ commands: TCommands;
47
+ }>;
48
+ export type SveltekitCommandRuntimeFactory<TCommands> = (replica: DistributedReplica, transport: ReplicaGraphqlTransport, options: SveltekitCommandRuntimeFactoryOptions) => SveltekitCommandRuntimeLike<TCommands>;
49
+ export type SveltekitCommandRuntimeFactoryOptions = Pick<ReplicaCommandRuntimeOptions, 'diagnostics'>;
50
+ export type CreateDistributedSvelteKitOptions<TCommands = Readonly<Record<never, never>>> = Readonly<{
51
+ session: SveltekitSessionSource;
52
+ /** Same-origin `/graphql` by default. */
53
+ url?: string | (() => string);
54
+ fetch?: FetchLike;
55
+ webSocket?: WebSocketConstructor;
56
+ /**
57
+ * Set to SvelteKit's `$app/environment` `browser` flag. When false,
58
+ * store subscriptions remain side-effect-free during component SSR.
59
+ */
60
+ browser?: boolean;
61
+ hydration?: SveltekitReplicaHydration;
62
+ /** Required with `hydration`; must come from current trusted SSR page data. */
63
+ authority?: SveltekitReplicaAuthority;
64
+ createCommands?: SveltekitCommandRuntimeFactory<TCommands>;
65
+ replica?: Omit<DistributedReplicaOptions, 'transport'>;
66
+ onAuthError?: (error: unknown) => void;
67
+ }>;
68
+ export type SveltekitQuerySnapshot<TData> = ReplicaSnapshot<TData> & Readonly<{
69
+ loading: boolean;
70
+ error?: GqlError;
71
+ /** Causally accepted commands still waiting for projection visibility. */
72
+ pending: readonly ReplicaCommandReceipt<unknown>[];
73
+ refetch(): Promise<void>;
74
+ }>;
75
+ export interface SveltekitQueryStore<TData> {
76
+ /** Current value for imperative code and adapter conformance. */
77
+ get(): SveltekitQuerySnapshot<TData>;
78
+ /** Svelte-readable store contract; use `$query` in a component. */
79
+ subscribe(listener: (snapshot: SveltekitQuerySnapshot<TData>) => void): () => void;
80
+ refetch(): Promise<void>;
81
+ destroy(): void;
82
+ readonly data: ReplicaSnapshot<TData>['data'];
83
+ readonly status: ReplicaSnapshot<TData>['status'];
84
+ readonly complete: boolean;
85
+ readonly loading: boolean;
86
+ readonly fetching: boolean;
87
+ readonly stale: boolean;
88
+ readonly live: ReplicaSnapshot<TData>['live'];
89
+ readonly errors: readonly GqlError[];
90
+ readonly error: GqlError | undefined;
91
+ readonly pending: readonly ReplicaCommandReceipt<unknown>[];
92
+ }
93
+ export type UseSveltekitOperationOptions = Readonly<{
94
+ /** Defaults to true when the compiler emitted a live companion. */
95
+ live?: boolean;
96
+ }>;
97
+ type UseOperationArguments<TVariables extends GraphqlVariables> = Record<string, never> extends TVariables ? [] | [variables: TVariables] | [
98
+ variables: TVariables,
99
+ options: UseSveltekitOperationOptions
100
+ ] : [
101
+ variables: TVariables,
102
+ options?: UseSveltekitOperationOptions
103
+ ];
104
+ export type SveltekitBoundOperation<TData, TVariables extends GraphqlVariables> = Readonly<{
105
+ artifact: ReplicaOperationArtifact<TData, TVariables>;
106
+ use(...args: UseOperationArguments<TVariables>): SveltekitQueryStore<TData>;
107
+ read(variables: TVariables): ReplicaSnapshot<TData>;
108
+ }>;
109
+ export type DistributedSvelteKitClient<TCommands> = Readonly<{
110
+ replica: DistributedReplica;
111
+ transport: ReplicaGraphqlTransport;
112
+ commands: TCommands;
113
+ operation<TData, TVariables extends GraphqlVariables>(artifact: ReplicaOperationArtifact<TData, TVariables>): SveltekitBoundOperation<TData, TVariables>;
114
+ /**
115
+ * Apply a server seed. A malformed or mismatched seed closes the old
116
+ * generation and returns false so the bound operation refetches.
117
+ */
118
+ hydrate(hydration: SveltekitReplicaHydration, authority: SveltekitReplicaAuthority): boolean;
119
+ invalidateAuthorization(): void;
120
+ destroy(): void;
121
+ }>;
122
+ /**
123
+ * Bind the framework-neutral replica to Svelte's readable-store lifecycle.
124
+ *
125
+ * Generated `$distributed` modules call this once, then export
126
+ * `client.operation(Operation_Todos)` and `client.commands`.
127
+ */
128
+ export declare function createDistributedSvelteKit<TCommands = Readonly<Record<never, never>>>(options: CreateDistributedSvelteKitOptions<TCommands>): DistributedSvelteKitClient<TCommands>;
129
+ /**
130
+ * Low-level composition seam for applications that already own a replica.
131
+ *
132
+ * Most SvelteKit applications use `createDistributedSvelteKit().operation()`;
133
+ * this form exists for custom composition and framework adapter conformance.
134
+ */
135
+ export declare function bindSveltekitOperation<TData, TVariables extends GraphqlVariables>(replica: DistributedReplica, artifact: ReplicaOperationArtifact<TData, TVariables>): SveltekitBoundOperation<TData, TVariables>;
136
+ /** Map SvelteKit page data into the one shared transport/session source. */
137
+ export declare function sessionSourceFromPageData<TData extends PageGraphqlData>(source: SveltekitPageDataSource<TData>): SveltekitSessionSource;
138
+ /**
139
+ * Create the single mutable page-data/session source owned by one layout.
140
+ *
141
+ * HTTP, WebSocket reconnects, commands, and authorization invalidation all
142
+ * observe `session`; navigation updates the same source through `set`.
143
+ */
144
+ export declare function createPageDataSessionSource<TData extends PageGraphqlData>(initial: TData): SveltekitPageDataSessionSource<TData>;
145
+ export {};