ngx-signal-query 1.0.0-dev.1
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 +21 -0
- package/README.md +108 -0
- package/fesm2022/ngx-signal-query.mjs +1003 -0
- package/fesm2022/ngx-signal-query.mjs.map +1 -0
- package/index.d.ts +619 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dzmitry Hutaryan
|
|
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
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# ngx-signal-query
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ngx-signal-query)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
Signal-first asynchronous state management for Angular â querying, caching, and
|
|
7
|
+
mutations built entirely on Angular Signals. Inspired by
|
|
8
|
+
[TanStack Query](https://tanstack.com/query), reimagined for the signal era: no
|
|
9
|
+
`Observable` subscriptions to manage, just signals you read in templates.
|
|
10
|
+
|
|
11
|
+
> â ïļ Pre-1.0 â the API may still change between minor versions.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- ðĶ **Signal-native** â query state is exposed as signals (`data()`, `status()`, âĶ), no manual subscriptions.
|
|
16
|
+
- ðïļ **Caching & deduplication** â identical query keys share a single in-flight request and cache entry.
|
|
17
|
+
- âïļ **Mutations** â with `onMutate` / `onSuccess` / `onError` lifecycle for optimistic updates.
|
|
18
|
+
- ð **Retries & polling** â configurable `retry` and `refetchInterval`.
|
|
19
|
+
- ð **Global indicators** â `injectIsFetching()` / `injectIsMutating()` for app-wide loading state.
|
|
20
|
+
- ðŠķ **Lean** â ESM, `sideEffects: false`, no runtime deps beyond `tslib`.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install ngx-signal-query
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Requires **Angular 20+** (`@angular/core` and `@angular/common` are peer dependencies).
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
### 1. Provide the query client
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// app.config.ts
|
|
36
|
+
import { ApplicationConfig } from '@angular/core'
|
|
37
|
+
import { provideHttpClient } from '@angular/common/http'
|
|
38
|
+
import { provideQueryClient } from 'ngx-signal-query'
|
|
39
|
+
|
|
40
|
+
export const appConfig: ApplicationConfig = {
|
|
41
|
+
providers: [provideHttpClient(), provideQueryClient()],
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Fetch data in a component
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { Component, inject } from '@angular/core'
|
|
49
|
+
import { HttpClient } from '@angular/common/http'
|
|
50
|
+
import { injectQuery } from 'ngx-signal-query'
|
|
51
|
+
|
|
52
|
+
type Todo = { id: number; title: string }
|
|
53
|
+
|
|
54
|
+
@Component({
|
|
55
|
+
selector: 'app-todos',
|
|
56
|
+
template: `
|
|
57
|
+
<p>status: {{ todos.status() }}</p>
|
|
58
|
+
|
|
59
|
+
@if (todos.data(); as data) {
|
|
60
|
+
<ul>
|
|
61
|
+
@for (todo of data; track todo.id) {
|
|
62
|
+
<li>{{ todo.title }}</li>
|
|
63
|
+
}
|
|
64
|
+
</ul>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
<button (click)="todos.refetch()">Refetch</button>
|
|
68
|
+
`,
|
|
69
|
+
})
|
|
70
|
+
export class TodosComponent {
|
|
71
|
+
private readonly http = inject(HttpClient)
|
|
72
|
+
|
|
73
|
+
protected readonly todos = injectQuery(() => ({
|
|
74
|
+
queryKey: ['todos'],
|
|
75
|
+
queryFn: () => this.http.get<Todo[]>('/api/todos'),
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Mutations
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import {
|
|
84
|
+
mutationOptions,
|
|
85
|
+
injectMutation,
|
|
86
|
+
injectQueryClient,
|
|
87
|
+
} from 'ngx-signal-query'
|
|
88
|
+
|
|
89
|
+
const client = injectQueryClient()
|
|
90
|
+
|
|
91
|
+
const addTodo = injectMutation(() =>
|
|
92
|
+
mutationOptions({
|
|
93
|
+
mutationFn: (title: string) => http.post<Todo>('/api/todos', { title }),
|
|
94
|
+
onSuccess: () => client.invalidateQueries({ queryKey: ['todos'] }),
|
|
95
|
+
}),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
// in a template
|
|
99
|
+
// <button (click)="addTodo.mutate('Buy milk')" [disabled]="addTodo.isPending()">Add</button>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
ð Full guides and API reference â **coming soon** (documentation site is in progress).
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
[MIT](./LICENSE)
|