@tanstack/lit-query 0.0.1 → 0.2.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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -43
  3. package/dist/QueryClientProvider.d.ts +85 -0
  4. package/dist/QueryClientProvider.d.ts.map +1 -0
  5. package/dist/QueryClientProvider.js +137 -0
  6. package/dist/QueryClientProvider.js.map +1 -0
  7. package/dist/accessor.d.ts +32 -0
  8. package/dist/accessor.d.ts.map +1 -0
  9. package/dist/accessor.js +12 -0
  10. package/dist/accessor.js.map +1 -0
  11. package/dist/context.d.ts +59 -0
  12. package/dist/context.d.ts.map +1 -0
  13. package/dist/context.js +100 -0
  14. package/dist/context.js.map +1 -0
  15. package/dist/controllers/BaseController.d.ts +38 -0
  16. package/dist/controllers/BaseController.d.ts.map +1 -0
  17. package/dist/controllers/BaseController.js +204 -0
  18. package/dist/controllers/BaseController.js.map +1 -0
  19. package/dist/createInfiniteQueryController.d.ts +76 -0
  20. package/dist/createInfiniteQueryController.d.ts.map +1 -0
  21. package/dist/createInfiniteQueryController.js +221 -0
  22. package/dist/createInfiniteQueryController.js.map +1 -0
  23. package/dist/createMutationController.d.ts +79 -0
  24. package/dist/createMutationController.d.ts.map +1 -0
  25. package/dist/createMutationController.js +193 -0
  26. package/dist/createMutationController.js.map +1 -0
  27. package/dist/createQueriesController.d.ts +145 -0
  28. package/dist/createQueriesController.d.ts.map +1 -0
  29. package/dist/createQueriesController.js +302 -0
  30. package/dist/createQueriesController.js.map +1 -0
  31. package/dist/createQueryController.d.ts +67 -0
  32. package/dist/createQueryController.d.ts.map +1 -0
  33. package/dist/createQueryController.js +211 -0
  34. package/dist/createQueryController.js.map +1 -0
  35. package/dist/index.d.ts +24 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +15 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/infiniteQueryOptions.d.ts +21 -0
  40. package/dist/infiniteQueryOptions.d.ts.map +1 -0
  41. package/dist/infiniteQueryOptions.js +22 -0
  42. package/dist/infiniteQueryOptions.js.map +1 -0
  43. package/dist/mutationOptions.d.ts +19 -0
  44. package/dist/mutationOptions.d.ts.map +1 -0
  45. package/dist/mutationOptions.js +20 -0
  46. package/dist/mutationOptions.js.map +1 -0
  47. package/dist/queryOptions.d.ts +62 -0
  48. package/dist/queryOptions.d.ts.map +1 -0
  49. package/dist/queryOptions.js +4 -0
  50. package/dist/queryOptions.js.map +1 -0
  51. package/dist/types.d.ts +31 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +2 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/useIsFetching.d.ts +45 -0
  56. package/dist/useIsFetching.d.ts.map +1 -0
  57. package/dist/useIsFetching.js +116 -0
  58. package/dist/useIsFetching.js.map +1 -0
  59. package/dist/useIsMutating.d.ts +45 -0
  60. package/dist/useIsMutating.d.ts.map +1 -0
  61. package/dist/useIsMutating.js +116 -0
  62. package/dist/useIsMutating.js.map +1 -0
  63. package/dist/useMutationState.d.ts +57 -0
  64. package/dist/useMutationState.d.ts.map +1 -0
  65. package/dist/useMutationState.js +132 -0
  66. package/dist/useMutationState.js.map +1 -0
  67. package/dist-cjs/QueryClientProvider.d.cts +84 -0
  68. package/dist-cjs/QueryClientProvider.js +141 -0
  69. package/dist-cjs/QueryClientProvider.js.map +1 -0
  70. package/dist-cjs/accessor.d.cts +31 -0
  71. package/dist-cjs/accessor.js +16 -0
  72. package/dist-cjs/accessor.js.map +1 -0
  73. package/dist-cjs/context.d.cts +58 -0
  74. package/dist-cjs/context.js +109 -0
  75. package/dist-cjs/context.js.map +1 -0
  76. package/dist-cjs/controllers/BaseController.d.cts +37 -0
  77. package/dist-cjs/controllers/BaseController.js +208 -0
  78. package/dist-cjs/controllers/BaseController.js.map +1 -0
  79. package/dist-cjs/createInfiniteQueryController.d.cts +75 -0
  80. package/dist-cjs/createInfiniteQueryController.js +224 -0
  81. package/dist-cjs/createInfiniteQueryController.js.map +1 -0
  82. package/dist-cjs/createMutationController.d.cts +78 -0
  83. package/dist-cjs/createMutationController.js +196 -0
  84. package/dist-cjs/createMutationController.js.map +1 -0
  85. package/dist-cjs/createQueriesController.d.cts +144 -0
  86. package/dist-cjs/createQueriesController.js +305 -0
  87. package/dist-cjs/createQueriesController.js.map +1 -0
  88. package/dist-cjs/createQueryController.d.cts +66 -0
  89. package/dist-cjs/createQueryController.js +214 -0
  90. package/dist-cjs/createQueryController.js.map +1 -0
  91. package/dist-cjs/index.d.cts +23 -0
  92. package/dist-cjs/index.js +49 -0
  93. package/dist-cjs/index.js.map +1 -0
  94. package/dist-cjs/infiniteQueryOptions.d.cts +20 -0
  95. package/dist-cjs/infiniteQueryOptions.js +25 -0
  96. package/dist-cjs/infiniteQueryOptions.js.map +1 -0
  97. package/dist-cjs/mutationOptions.d.cts +18 -0
  98. package/dist-cjs/mutationOptions.js +23 -0
  99. package/dist-cjs/mutationOptions.js.map +1 -0
  100. package/dist-cjs/package.json +3 -0
  101. package/dist-cjs/queryOptions.d.cts +61 -0
  102. package/dist-cjs/queryOptions.js +7 -0
  103. package/dist-cjs/queryOptions.js.map +1 -0
  104. package/dist-cjs/types.d.cts +30 -0
  105. package/dist-cjs/types.js +3 -0
  106. package/dist-cjs/types.js.map +1 -0
  107. package/dist-cjs/useIsFetching.d.cts +44 -0
  108. package/dist-cjs/useIsFetching.js +119 -0
  109. package/dist-cjs/useIsFetching.js.map +1 -0
  110. package/dist-cjs/useIsMutating.d.cts +44 -0
  111. package/dist-cjs/useIsMutating.js +119 -0
  112. package/dist-cjs/useIsMutating.js.map +1 -0
  113. package/dist-cjs/useMutationState.d.cts +56 -0
  114. package/dist-cjs/useMutationState.js +135 -0
  115. package/dist-cjs/useMutationState.js.map +1 -0
  116. package/package.json +73 -8
  117. package/src/QueryClientProvider.ts +174 -0
  118. package/src/accessor.ts +43 -0
  119. package/src/context.ts +120 -0
  120. package/src/controllers/BaseController.ts +284 -0
  121. package/src/createInfiniteQueryController.ts +394 -0
  122. package/src/createMutationController.ts +361 -0
  123. package/src/createQueriesController.ts +633 -0
  124. package/src/createQueryController.ts +342 -0
  125. package/src/index.ts +72 -0
  126. package/src/infiniteQueryOptions.ts +48 -0
  127. package/src/mutationOptions.ts +31 -0
  128. package/src/queryOptions.ts +143 -0
  129. package/src/types.ts +77 -0
  130. package/src/useIsFetching.ts +159 -0
  131. package/src/useIsMutating.ts +159 -0
  132. package/src/useMutationState.ts +201 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Tanner Linsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,127 @@
1
1
  # @tanstack/lit-query
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@tanstack/lit-query`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
3
+ Lit adapter for `@tanstack/query-core` using Lit reactive controllers.
4
+
5
+ This package is currently experimental and v0.1. Pin exact versions if you use
6
+ it in production while the API is early.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @tanstack/lit-query @tanstack/query-core lit
12
+ ```
13
+
14
+ For local development in this repository:
15
+
16
+ ```bash
17
+ pnpm install
18
+ pnpm --dir packages/lit-query run build
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```ts
24
+ import { LitElement, html } from 'lit'
25
+ import {
26
+ QueryClient,
27
+ QueryClientProvider,
28
+ createQueryController,
29
+ } from '@tanstack/lit-query'
30
+
31
+ const client = new QueryClient({
32
+ defaultOptions: { queries: { retry: false } },
33
+ })
34
+
35
+ class AppProvider extends QueryClientProvider {
36
+ constructor() {
37
+ super()
38
+ this.client = client
39
+ }
40
+ }
41
+ customElements.define('app-provider', AppProvider)
42
+
43
+ class UsersView extends LitElement {
44
+ private readonly users = createQueryController(this, {
45
+ queryKey: ['users'],
46
+ queryFn: async () => {
47
+ const response = await fetch('/api/users')
48
+ return response.json() as Promise<Array<{ id: string; name: string }>>
49
+ },
50
+ })
51
+
52
+ render() {
53
+ const query = this.users()
54
+ if (query.isPending) return html`Loading...`
55
+ if (query.isError) return html`Error`
56
+ return html`<ul>
57
+ ${query.data?.map((u) => html`<li>${u.name}</li>`)}
58
+ </ul>`
59
+ }
60
+ }
61
+ customElements.define('users-view', UsersView)
62
+ ```
63
+
64
+ ## API Surface
65
+
66
+ - `QueryClientProvider`, `useQueryClient`, `resolveQueryClient`
67
+ - `createQueryController`
68
+ - `createMutationController`
69
+ - `createInfiniteQueryController`
70
+ - `createQueriesController`
71
+ - `useIsFetching`, `useIsMutating`, `useMutationState`
72
+ - `queryOptions`, `infiniteQueryOptions`, `mutationOptions`
73
+
74
+ ## Runnable Examples
75
+
76
+ This repo includes runnable Lit examples under the top-level `examples/lit`
77
+ directory so they can be surfaced in the docs:
78
+
79
+ - `examples/lit/basic`: Vite Lit app covering query and mutation primitives.
80
+ - `examples/lit/pagination`: pagination, prefetching, optimistic updates, and error recovery.
81
+ - `examples/lit/ssr`: Lit SSR render, dehydrate, and hydrate flow.
82
+
83
+ Run an example from the repo root:
84
+
85
+ ```bash
86
+ pnpm --dir examples/lit/basic run dev
87
+ pnpm --dir examples/lit/pagination run dev
88
+ pnpm --dir examples/lit/ssr run dev
89
+ ```
90
+
91
+ Open:
92
+
93
+ - `http://127.0.0.1:4173/` (basic example)
94
+ - `http://127.0.0.1:4183/` (pagination example app)
95
+ - `http://127.0.0.1:4174/` (SSR example app)
96
+
97
+ Use a different port (optional):
98
+
99
+ ```bash
100
+ DEMO_PORT=4180 pnpm --dir examples/lit/basic run dev
101
+ PAGINATION_DEMO_PORT=4181 PAGINATION_API_PORT=4182 pnpm --dir examples/lit/pagination run dev
102
+ SSR_PORT=4180 pnpm --dir examples/lit/ssr run dev
103
+ SSR_HOST=0.0.0.0 pnpm --dir examples/lit/ssr run dev
104
+ ```
105
+
106
+ ## Integration Smoke
107
+
108
+ For the framework build smoke used in CI:
109
+
110
+ ```bash
111
+ pnpm --dir integrations/lit-vite run build
112
+ ```
113
+
114
+ ## Quality Gates
115
+
116
+ From the repository root:
117
+
118
+ ```bash
119
+ pnpm --dir packages/lit-query run test:types
120
+ pnpm --dir packages/lit-query run test:lib
121
+ pnpm --dir packages/lit-query run build
122
+ pnpm --dir packages/lit-query run test:build
123
+ ```
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,85 @@
1
+ import type { QueryClient } from '@tanstack/query-core';
2
+ import type { TemplateResult } from 'lit';
3
+ import { LitElement } from 'lit';
4
+ /**
5
+ * Lit element that provides a `QueryClient` to descendant Lit Query
6
+ * controllers through Lit context.
7
+ *
8
+ * The `client` is a property, not an attribute. When rendering this element in
9
+ * a Lit template, bind it with property binding: `.client=${queryClient}`.
10
+ * The provider throws if it connects without a client, or if an already
11
+ * connected provider has its client cleared.
12
+ *
13
+ * This class is not registered as a custom element by the package. Applications
14
+ * must register either a subclass or the class itself with
15
+ * `customElements.define`.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { html, LitElement } from 'lit'
20
+ * import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
21
+ *
22
+ * const queryClient = new QueryClient()
23
+ *
24
+ * class AppQueryProvider extends QueryClientProvider {
25
+ * constructor() {
26
+ * super()
27
+ * this.client = queryClient
28
+ * }
29
+ * }
30
+ *
31
+ * customElements.define('app-query-provider', AppQueryProvider)
32
+ *
33
+ * class AppRoot extends LitElement {
34
+ * render() {
35
+ * return html`<app-query-provider><todos-view></todos-view></app-query-provider>`
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { html } from 'lit'
43
+ * import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
44
+ *
45
+ * const queryClient = new QueryClient()
46
+ *
47
+ * customElements.define('query-client-provider', QueryClientProvider)
48
+ *
49
+ * const view = html`
50
+ * <query-client-provider .client=${queryClient}>
51
+ * <todos-view></todos-view>
52
+ * </query-client-provider>
53
+ * `
54
+ * ```
55
+ */
56
+ export declare class QueryClientProvider extends LitElement {
57
+ /** @internal */
58
+ static properties: {
59
+ client: {
60
+ attribute: boolean;
61
+ };
62
+ };
63
+ /**
64
+ * The `QueryClient` provided to descendant controllers and global fallback
65
+ * helpers while this provider is connected.
66
+ *
67
+ * Bind this as a property in Lit templates with `.client=${queryClient}`.
68
+ */
69
+ client: QueryClient;
70
+ private readonly contextProvider;
71
+ private mountedClient;
72
+ constructor();
73
+ /** @internal */
74
+ connectedCallback(): void;
75
+ /** @internal */
76
+ disconnectedCallback(): void;
77
+ /** @internal */
78
+ protected willUpdate(changedProperties: Map<PropertyKey, unknown>): void;
79
+ /** @internal */
80
+ render(): TemplateResult;
81
+ private mountClient;
82
+ private unmountClient;
83
+ private requireClient;
84
+ }
85
+ //# sourceMappingURL=QueryClientProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.d.ts","sourceRoot":"","sources":["../src/QueryClientProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,UAAU,EAAQ,MAAM,KAAK,CAAA;AAQtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;IACjD,gBAAgB;IAChB,MAAM,CAAC,UAAU;;;;MAEhB;IAED;;;;;OAKG;IACK,MAAM,EAAE,WAAW,CAAA;IAE3B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4C;IAE5E,OAAO,CAAC,aAAa,CAAyB;;IAS9C,gBAAgB;IAChB,iBAAiB,IAAI,IAAI;IAOzB,gBAAgB;IAChB,oBAAoB,IAAI,IAAI;IAK5B,gBAAgB;IAChB,SAAS,CAAC,UAAU,CAAC,iBAAiB,EAAE,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,IAAI;IA+BxE,gBAAgB;IAChB,MAAM,IAAI,cAAc;IAIxB,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,aAAa;CAOtB"}
@@ -0,0 +1,137 @@
1
+ import { ContextProvider } from '@lit/context';
2
+ import { LitElement, html } from 'lit';
3
+ import { createMissingQueryClientError, queryClientContext, registerDefaultQueryClient, unregisterDefaultQueryClient, } from './context.js';
4
+ /**
5
+ * Lit element that provides a `QueryClient` to descendant Lit Query
6
+ * controllers through Lit context.
7
+ *
8
+ * The `client` is a property, not an attribute. When rendering this element in
9
+ * a Lit template, bind it with property binding: `.client=${queryClient}`.
10
+ * The provider throws if it connects without a client, or if an already
11
+ * connected provider has its client cleared.
12
+ *
13
+ * This class is not registered as a custom element by the package. Applications
14
+ * must register either a subclass or the class itself with
15
+ * `customElements.define`.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { html, LitElement } from 'lit'
20
+ * import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
21
+ *
22
+ * const queryClient = new QueryClient()
23
+ *
24
+ * class AppQueryProvider extends QueryClientProvider {
25
+ * constructor() {
26
+ * super()
27
+ * this.client = queryClient
28
+ * }
29
+ * }
30
+ *
31
+ * customElements.define('app-query-provider', AppQueryProvider)
32
+ *
33
+ * class AppRoot extends LitElement {
34
+ * render() {
35
+ * return html`<app-query-provider><todos-view></todos-view></app-query-provider>`
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { html } from 'lit'
43
+ * import { QueryClient, QueryClientProvider } from '@tanstack/lit-query'
44
+ *
45
+ * const queryClient = new QueryClient()
46
+ *
47
+ * customElements.define('query-client-provider', QueryClientProvider)
48
+ *
49
+ * const view = html`
50
+ * <query-client-provider .client=${queryClient}>
51
+ * <todos-view></todos-view>
52
+ * </query-client-provider>
53
+ * `
54
+ * ```
55
+ */
56
+ export class QueryClientProvider extends LitElement {
57
+ /** @internal */
58
+ static properties = {
59
+ client: { attribute: false },
60
+ };
61
+ contextProvider;
62
+ mountedClient;
63
+ constructor() {
64
+ super();
65
+ this.contextProvider = new ContextProvider(this, {
66
+ context: queryClientContext,
67
+ });
68
+ }
69
+ /** @internal */
70
+ connectedCallback() {
71
+ super.connectedCallback();
72
+ const client = this.requireClient();
73
+ this.contextProvider.setValue(client);
74
+ this.mountClient(client);
75
+ }
76
+ /** @internal */
77
+ disconnectedCallback() {
78
+ this.unmountClient(this.mountedClient);
79
+ super.disconnectedCallback();
80
+ }
81
+ /** @internal */
82
+ willUpdate(changedProperties) {
83
+ if (!changedProperties.has('client')) {
84
+ return;
85
+ }
86
+ const nextClient = this.client;
87
+ if (!nextClient) {
88
+ if (this.isConnected) {
89
+ this.unmountClient(this.mountedClient);
90
+ // Sentinel: notify active consumers that the provider is now unbound.
91
+ this.contextProvider.setValue(undefined);
92
+ throw createMissingQueryClientError();
93
+ }
94
+ return;
95
+ }
96
+ const previousClient = changedProperties.get('client');
97
+ if (previousClient && previousClient !== nextClient && this.isConnected) {
98
+ this.unmountClient(previousClient);
99
+ }
100
+ this.contextProvider.setValue(nextClient);
101
+ if (this.isConnected) {
102
+ this.mountClient(nextClient);
103
+ }
104
+ }
105
+ /** @internal */
106
+ render() {
107
+ return html `<slot></slot>`;
108
+ }
109
+ mountClient(client) {
110
+ if (this.mountedClient === client) {
111
+ return;
112
+ }
113
+ if (this.mountedClient) {
114
+ this.unmountClient(this.mountedClient);
115
+ }
116
+ client.mount();
117
+ registerDefaultQueryClient(client);
118
+ this.mountedClient = client;
119
+ }
120
+ unmountClient(client) {
121
+ if (!client) {
122
+ return;
123
+ }
124
+ client.unmount();
125
+ unregisterDefaultQueryClient(client);
126
+ if (this.mountedClient === client) {
127
+ this.mountedClient = undefined;
128
+ }
129
+ }
130
+ requireClient() {
131
+ if (!this.client) {
132
+ throw createMissingQueryClientError();
133
+ }
134
+ return this.client;
135
+ }
136
+ }
137
+ //# sourceMappingURL=QueryClientProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.js","sourceRoot":"","sources":["../src/QueryClientProvider.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * A value that can be passed directly or read from a zero-argument getter.
3
+ *
4
+ * Lit Query APIs read function accessors during host updates, so the getter can
5
+ * depend on reactive host state.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const staticKey: Accessor<readonly unknown[]> = ['todos']
10
+ * const reactiveKey: Accessor<readonly unknown[]> = () => ['todos', this.userId]
11
+ * ```
12
+ */
13
+ export type Accessor<T> = T | (() => T);
14
+ export declare function readAccessor<T>(value: Accessor<T>): T;
15
+ /**
16
+ * A callable accessor with a `current` property for reading the latest
17
+ * controller result.
18
+ *
19
+ * Controller creators and cache state helpers return this shape so render code
20
+ * can use either `result()` or `result.current`.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const query = this.todos()
25
+ * const sameQuery = this.todos.current
26
+ * ```
27
+ */
28
+ export type ValueAccessor<T> = (() => T) & {
29
+ readonly current: T;
30
+ };
31
+ export declare function createValueAccessor<T>(getter: () => T): ValueAccessor<T>;
32
+ //# sourceMappingURL=accessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessor.d.ts","sourceRoot":"","sources":["../src/accessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAEvC,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAErD;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG;IACzC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;CACpB,CAAA;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAOxE"}
@@ -0,0 +1,12 @@
1
+ export function readAccessor(value) {
2
+ return typeof value === 'function' ? value() : value;
3
+ }
4
+ export function createValueAccessor(getter) {
5
+ const accessor = (() => getter());
6
+ Object.defineProperty(accessor, 'current', {
7
+ get: getter,
8
+ enumerable: true,
9
+ });
10
+ return accessor;
11
+ }
12
+ //# sourceMappingURL=accessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accessor.js","sourceRoot":"","sources":["../src/accessor.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,YAAY,CAAI,KAAkB;IAChD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAiB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAA;AACnE,CAAC;AAmBD,MAAM,UAAU,mBAAmB,CAAI,MAAe;IACpD,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAqB,CAAA;IACrD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,SAAS,EAAE;QACzC,GAAG,EAAE,MAAM;QACX,UAAU,EAAE,IAAI;KACjB,CAAC,CAAA;IACF,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,59 @@
1
+ import type { QueryClient } from '@tanstack/query-core';
2
+ /**
3
+ * Lit context key used by `QueryClientProvider` and host-bound APIs to share a
4
+ * `QueryClient` through the DOM tree.
5
+ *
6
+ * Most applications use `QueryClientProvider` instead of interacting with this
7
+ * context directly.
8
+ */
9
+ export declare const queryClientContext: {
10
+ __context__: QueryClient;
11
+ };
12
+ /**
13
+ * Registers a `QueryClient` as a process-local fallback for APIs that resolve a
14
+ * client without an explicit argument.
15
+ *
16
+ * `QueryClientProvider` calls this automatically while it is connected. Prefer
17
+ * passing an explicit client or rendering under a provider when possible.
18
+ *
19
+ * @param client - The query client to register as the current default.
20
+ */
21
+ export declare function registerDefaultQueryClient(client: QueryClient): void;
22
+ /**
23
+ * Unregisters a client previously registered with
24
+ * `registerDefaultQueryClient`.
25
+ *
26
+ * `QueryClientProvider` calls this automatically when it disconnects.
27
+ *
28
+ * @param client - The query client registration to release.
29
+ */
30
+ export declare function unregisterDefaultQueryClient(client: QueryClient): void;
31
+ /**
32
+ * Returns the registered default `QueryClient`, if exactly one default client is
33
+ * available.
34
+ *
35
+ * @returns The default query client, or `undefined` when there is no registered
36
+ * client or more than one registered client.
37
+ */
38
+ export declare function getDefaultQueryClient(): QueryClient | undefined;
39
+ export declare function createMissingQueryClientError(): Error;
40
+ /**
41
+ * Resolves the current default `QueryClient` registered by a connected
42
+ * `QueryClientProvider`.
43
+ *
44
+ * This helper is useful outside a Lit reactive controller when a single
45
+ * provider is mounted. It throws if no client is registered or if multiple
46
+ * clients are mounted and the default would be ambiguous.
47
+ *
48
+ * @returns The single registered query client.
49
+ */
50
+ export declare function useQueryClient(): QueryClient;
51
+ /**
52
+ * Resolves an explicit `QueryClient` or falls back to `useQueryClient`.
53
+ *
54
+ * @param explicit - Optional client supplied by the caller.
55
+ * @returns The explicit client when provided, otherwise the current default
56
+ * client.
57
+ */
58
+ export declare function resolveQueryClient(explicit?: QueryClient): QueryClient;
59
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB;;CAE9B,CAAA;AAUD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAGpE;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAkBtE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,WAAW,GAAG,SAAS,CAM/D;AAED,wBAAgB,6BAA6B,IAAI,KAAK,CAErD;AAMD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAW5C;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,CAEtE"}
@@ -0,0 +1,100 @@
1
+ import { createContext } from '@lit/context';
2
+ /**
3
+ * Lit context key used by `QueryClientProvider` and host-bound APIs to share a
4
+ * `QueryClient` through the DOM tree.
5
+ *
6
+ * Most applications use `QueryClientProvider` instead of interacting with this
7
+ * context directly.
8
+ */
9
+ export const queryClientContext = createContext(Symbol.for('tanstack-query-client'));
10
+ const missingQueryClientMessage = 'No QueryClient available. Pass one explicitly or render within QueryClientProvider.';
11
+ const ambiguousQueryClientMessage = 'Multiple QueryClients are mounted. Pass one explicitly instead of relying on global QueryClient helpers.';
12
+ const registeredClients = new Map();
13
+ let defaultClient;
14
+ /**
15
+ * Registers a `QueryClient` as a process-local fallback for APIs that resolve a
16
+ * client without an explicit argument.
17
+ *
18
+ * `QueryClientProvider` calls this automatically while it is connected. Prefer
19
+ * passing an explicit client or rendering under a provider when possible.
20
+ *
21
+ * @param client - The query client to register as the current default.
22
+ */
23
+ export function registerDefaultQueryClient(client) {
24
+ registeredClients.set(client, (registeredClients.get(client) ?? 0) + 1);
25
+ defaultClient = client;
26
+ }
27
+ /**
28
+ * Unregisters a client previously registered with
29
+ * `registerDefaultQueryClient`.
30
+ *
31
+ * `QueryClientProvider` calls this automatically when it disconnects.
32
+ *
33
+ * @param client - The query client registration to release.
34
+ */
35
+ export function unregisterDefaultQueryClient(client) {
36
+ const count = registeredClients.get(client);
37
+ if (count === undefined) {
38
+ return;
39
+ }
40
+ if (count > 1) {
41
+ registeredClients.set(client, count - 1);
42
+ return;
43
+ }
44
+ registeredClients.delete(client);
45
+ if (defaultClient !== client) {
46
+ return;
47
+ }
48
+ const remaining = [...registeredClients.keys()];
49
+ defaultClient = remaining.at(-1);
50
+ }
51
+ /**
52
+ * Returns the registered default `QueryClient`, if exactly one default client is
53
+ * available.
54
+ *
55
+ * @returns The default query client, or `undefined` when there is no registered
56
+ * client or more than one registered client.
57
+ */
58
+ export function getDefaultQueryClient() {
59
+ if (registeredClients.size > 1) {
60
+ return undefined;
61
+ }
62
+ return defaultClient;
63
+ }
64
+ export function createMissingQueryClientError() {
65
+ return new Error(missingQueryClientMessage);
66
+ }
67
+ function createAmbiguousQueryClientError() {
68
+ return new Error(ambiguousQueryClientMessage);
69
+ }
70
+ /**
71
+ * Resolves the current default `QueryClient` registered by a connected
72
+ * `QueryClientProvider`.
73
+ *
74
+ * This helper is useful outside a Lit reactive controller when a single
75
+ * provider is mounted. It throws if no client is registered or if multiple
76
+ * clients are mounted and the default would be ambiguous.
77
+ *
78
+ * @returns The single registered query client.
79
+ */
80
+ export function useQueryClient() {
81
+ const client = getDefaultQueryClient();
82
+ if (client) {
83
+ return client;
84
+ }
85
+ if (registeredClients.size > 1) {
86
+ throw createAmbiguousQueryClientError();
87
+ }
88
+ throw createMissingQueryClientError();
89
+ }
90
+ /**
91
+ * Resolves an explicit `QueryClient` or falls back to `useQueryClient`.
92
+ *
93
+ * @param explicit - Optional client supplied by the caller.
94
+ * @returns The explicit client when provided, otherwise the current default
95
+ * client.
96
+ */
97
+ export function resolveQueryClient(explicit) {
98
+ return explicit ?? useQueryClient();
99
+ }
100
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAG5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CACpC,CAAA;AAED,MAAM,yBAAyB,GAC7B,qFAAqF,CAAA;AACvF,MAAM,2BAA2B,GAC/B,0GAA0G,CAAA;AAE5G,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAA;AACxD,IAAI,aAAsC,CAAA;AAE1C;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAmB;IAC5D,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACvE,aAAa,GAAG,MAAM,CAAA;AACxB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAAC,MAAmB;IAC9D,MAAM,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC3C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAM;IACR,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;QACxC,OAAM;IACR,CAAC;IAED,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,aAAa,KAAK,MAAM,EAAE,CAAC;QAC7B,OAAM;IACR,CAAC;IAED,MAAM,SAAS,GAAG,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAA;IAC/C,aAAa,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,OAAO,aAAa,CAAA;AACtB,CAAC;AAED,MAAM,UAAU,6BAA6B;IAC3C,OAAO,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;AAC7C,CAAC;AAED,SAAS,+BAA+B;IACtC,OAAO,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;AAC/C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAA;IACtC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,+BAA+B,EAAE,CAAA;IACzC,CAAC;IAED,MAAM,6BAA6B,EAAE,CAAA;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAsB;IACvD,OAAO,QAAQ,IAAI,cAAc,EAAE,CAAA;AACrC,CAAC"}