ngx-zero 0.1.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.
- package/LICENSE +21 -0
- package/README.md +194 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -0
- package/dist/features.d.ts +9 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +14 -0
- package/dist/features.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/inject-connection-state.d.ts +6 -0
- package/dist/inject-connection-state.d.ts.map +1 -0
- package/dist/inject-connection-state.js +41 -0
- package/dist/inject-connection-state.js.map +1 -0
- package/dist/inject-mutator.d.ts +4 -0
- package/dist/inject-mutator.d.ts.map +1 -0
- package/dist/inject-mutator.js +63 -0
- package/dist/inject-mutator.js.map +1 -0
- package/dist/inject-query.d.ts +7 -0
- package/dist/inject-query.d.ts.map +1 -0
- package/dist/inject-query.js +47 -0
- package/dist/inject-query.js.map +1 -0
- package/dist/inject-zero.d.ts +6 -0
- package/dist/inject-zero.d.ts.map +1 -0
- package/dist/inject-zero.js +16 -0
- package/dist/inject-zero.js.map +1 -0
- package/dist/instance-manager.d.ts +13 -0
- package/dist/instance-manager.d.ts.map +1 -0
- package/dist/instance-manager.js +140 -0
- package/dist/instance-manager.js.map +1 -0
- package/dist/mutator-call-tracker.d.ts +16 -0
- package/dist/mutator-call-tracker.d.ts.map +1 -0
- package/dist/mutator-call-tracker.js +53 -0
- package/dist/mutator-call-tracker.js.map +1 -0
- package/dist/mutator-ref.d.ts +35 -0
- package/dist/mutator-ref.d.ts.map +1 -0
- package/dist/mutator-ref.js +2 -0
- package/dist/mutator-ref.js.map +1 -0
- package/dist/options-diff.d.ts +6 -0
- package/dist/options-diff.d.ts.map +1 -0
- package/dist/options-diff.js +31 -0
- package/dist/options-diff.js.map +1 -0
- package/dist/provide-zero-testing.d.ts +7 -0
- package/dist/provide-zero-testing.d.ts.map +1 -0
- package/dist/provide-zero-testing.js +17 -0
- package/dist/provide-zero-testing.js.map +1 -0
- package/dist/provide-zero.d.ts +5 -0
- package/dist/provide-zero.d.ts.map +1 -0
- package/dist/provide-zero.js +12 -0
- package/dist/provide-zero.js.map +1 -0
- package/dist/query-identity.d.ts +15 -0
- package/dist/query-identity.d.ts.map +1 -0
- package/dist/query-identity.js +20 -0
- package/dist/query-identity.js.map +1 -0
- package/dist/query-ref.d.ts +27 -0
- package/dist/query-ref.d.ts.map +1 -0
- package/dist/query-ref.js +2 -0
- package/dist/query-ref.js.map +1 -0
- package/dist/query-view-controller.d.ts +48 -0
- package/dist/query-view-controller.d.ts.map +1 -0
- package/dist/query-view-controller.js +150 -0
- package/dist/query-view-controller.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +21 -0
- package/dist/utils.js.map +1 -0
- package/dist/with-bootstrap.d.ts +4 -0
- package/dist/with-bootstrap.d.ts.map +1 -0
- package/dist/with-bootstrap.js +8 -0
- package/dist/with-bootstrap.js.map +1 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ivan Anchev
|
|
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,194 @@
|
|
|
1
|
+
# ngx-zero
|
|
2
|
+
|
|
3
|
+
Signals-first, zoneless-ready Angular bindings for [Rocicorp Zero](https://zero.rocicorp.dev).
|
|
4
|
+
|
|
5
|
+
## Quick look
|
|
6
|
+
|
|
7
|
+
### Provide
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// app.config.ts
|
|
11
|
+
provideZero(() => ({
|
|
12
|
+
schema,
|
|
13
|
+
cacheURL: environment.zeroCache,
|
|
14
|
+
userID: auth.userId(),
|
|
15
|
+
auth: auth.jwt(),
|
|
16
|
+
}))
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Query
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// component — one inject per use-site, fully inferred
|
|
23
|
+
export class IssuesList {
|
|
24
|
+
readonly issues = injectQuery(() => queries.issues.open({ assignee: this.userId() }));
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
@for (issue of issues.data(); track issue.id) {
|
|
30
|
+
<app-issue [issue]="issue" />
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Mutate
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export class IssuesList {
|
|
38
|
+
readonly create = injectMutator(mutators.issue.create);
|
|
39
|
+
readonly close = injectMutator(mutators.issue.close);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Fire-and-forget from the template, driving UI state off the signals:
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<button (click)="close.mutate({ id: issue.id })" [disabled]="close.pending()">
|
|
47
|
+
Close
|
|
48
|
+
</button>
|
|
49
|
+
|
|
50
|
+
@if (close.error(); as err) {
|
|
51
|
+
<p class="error">{{ err.message }}</p>
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or await the outcome - the returned promises never reject:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
async addIssue(title: string) {
|
|
59
|
+
const { client, server } = this.create.mutate({ id: crypto.randomUUID(), title });
|
|
60
|
+
|
|
61
|
+
await client; // optimistic apply settled
|
|
62
|
+
const result = await server; // authoritative server outcome
|
|
63
|
+
if (result.type === 'error') {
|
|
64
|
+
// mutation was rejected and rolled back
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Why
|
|
70
|
+
|
|
71
|
+
- **Signals end-to-end.** Zoneless-first, zone.js fully supported (no `NgZone.run`
|
|
72
|
+
anywhere).
|
|
73
|
+
- **Tight inference.** Zero generics at call sites via Zero's own `DefaultTypes`
|
|
74
|
+
registration.
|
|
75
|
+
- **Modern Zero only.** Built on the ≥1.x API: query/mutator registries,
|
|
76
|
+
`zero.materialize`, `zero.connection`.
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
### `provideZero(source, ...features)`
|
|
81
|
+
|
|
82
|
+
Registers Zero at the environment level. `source` is `ZeroOptions`, an external
|
|
83
|
+
`{ zero }` instance, or a thunk of either. When the thunk reads signals
|
|
84
|
+
(`userID`, `auth`), ngx-zero reconciles on change — rotating auth reconnects in
|
|
85
|
+
place, switching users recreates the instance.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
provideZero(
|
|
89
|
+
() => ({ schema, cacheURL: env.zeroCache, userID: auth.userId(), auth: auth.jwt() }),
|
|
90
|
+
withBootstrap(zero => zero.preload(queries.issues.open())),
|
|
91
|
+
)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `injectQuery(queryThunk, options?)`
|
|
95
|
+
|
|
96
|
+
Materializes a query and exposes it as signals. The thunk is reactive: reading a
|
|
97
|
+
signal inside it re-runs the query when that signal changes. Returning a falsy
|
|
98
|
+
value disables the query.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
readonly issue = injectQuery(
|
|
102
|
+
() => this.issueId() && queries.issue.byId({ id: this.issueId()! }),
|
|
103
|
+
{ ttl: '1m', keepPreviousData: true },
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Returns a `QueryRef`:
|
|
108
|
+
|
|
109
|
+
| Member | Type | Meaning |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `data` | `Signal<TData>` | Rows (or row for `.one()` queries) |
|
|
112
|
+
| `status` | `Signal<QueryStatus>` | `'unknown' \| 'complete' \| 'error' \| 'disabled'` |
|
|
113
|
+
| `error` | `Signal<ErroredQuery \| undefined>` | Cleared on next successful emission |
|
|
114
|
+
| `isComplete` | `Signal<boolean>` | Shorthand for `status() === 'complete'` |
|
|
115
|
+
| `retry()` | method | Destroy and re-materialize |
|
|
116
|
+
| `updateTTL(ttl)` | method | Forward a TTL to the current view |
|
|
117
|
+
|
|
118
|
+
### `injectMutator(mutator, options?)`
|
|
119
|
+
|
|
120
|
+
Binds a registry mutator to a `mutate()` function plus lifecycle signals.
|
|
121
|
+
Returned promises never reject; errors land in the `error` signal.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
readonly close = injectMutator(mutators.issue.close);
|
|
125
|
+
|
|
126
|
+
close.clientPending() // optimistic apply in flight
|
|
127
|
+
close.pending() // server confirmation in flight
|
|
128
|
+
close.clientResult() / close.serverResult() // outcome details
|
|
129
|
+
close.error() // client error, else server error (rollback)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `injectConnectionState()`
|
|
133
|
+
|
|
134
|
+
The current instance's connection state as a signal — seeded synchronously and
|
|
135
|
+
following instance replacement. `'needs-auth'` is the cue to refresh auth: when
|
|
136
|
+
the refreshed token lands in `provideZero`'s thunk, Zero reconnects in place.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
readonly connection = injectConnectionState();
|
|
140
|
+
|
|
141
|
+
constructor() {
|
|
142
|
+
effect(() => {
|
|
143
|
+
if (this.connection().name === 'needs-auth') {
|
|
144
|
+
void this.auth.refreshSession();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```html
|
|
151
|
+
@if (connection().name !== 'connected') {
|
|
152
|
+
<span class="badge">offline</span>
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `injectZero()`
|
|
157
|
+
|
|
158
|
+
Escape hatch: the raw `Zero` instance as a signal, for anything not covered
|
|
159
|
+
above.
|
|
160
|
+
|
|
161
|
+
### `provideZeroTesting(source, ...features)`
|
|
162
|
+
|
|
163
|
+
Test-friendly `provideZero`: forces a local-only instance (`cacheURL: null`,
|
|
164
|
+
`server: null`) with an in-memory store, for `TestBed` setups.
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
pnpm install
|
|
170
|
+
pnpm typecheck
|
|
171
|
+
pnpm test
|
|
172
|
+
pnpm build
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Local playground
|
|
176
|
+
|
|
177
|
+
[`examples/playground`](examples/playground) runs the library against a real
|
|
178
|
+
backend: Postgres in Docker, `zero-cache`, and a Hono API embedded in the Vite
|
|
179
|
+
dev server.
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
pnpm playground:db # once: start Postgres, push the schema, seed
|
|
183
|
+
pnpm playground # build ngx-zero, then run zero-cache + vite
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Open http://localhost:5173 — create/complete/delete issues, switch users to
|
|
187
|
+
exercise instance rotation, rotate auth to exercise in-place reconnection, or
|
|
188
|
+
add a title containing "rollback" to watch a server rejection roll back an
|
|
189
|
+
optimistic mutation. Details in the
|
|
190
|
+
[playground README](examples/playground/README.md).
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
[MIT](LICENSE)
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAEnD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,KAAK,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Provider } from '@angular/core';
|
|
2
|
+
export type ZeroFeatureKind = 'bootstrap';
|
|
3
|
+
export interface ZeroFeature<K extends ZeroFeatureKind = ZeroFeatureKind> {
|
|
4
|
+
readonly ɵkind: K;
|
|
5
|
+
readonly ɵproviders: readonly Provider[];
|
|
6
|
+
}
|
|
7
|
+
export declare function zeroFeature<K extends ZeroFeatureKind>(kind: K, providers: readonly Provider[]): ZeroFeature<K>;
|
|
8
|
+
export declare function assertUniqueFeatureKinds(features: readonly ZeroFeature[]): void;
|
|
9
|
+
//# sourceMappingURL=features.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC;AAE1C,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe;IACtE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,QAAQ,CAAC,UAAU,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC1C;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACnD,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,SAAS,QAAQ,EAAE,GAC7B,WAAW,CAAC,CAAC,CAAC,CAEhB;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAQ/E"}
|
package/dist/features.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ngxZeroError } from './errors.js';
|
|
2
|
+
export function zeroFeature(kind, providers) {
|
|
3
|
+
return { ɵkind: kind, ɵproviders: providers };
|
|
4
|
+
}
|
|
5
|
+
export function assertUniqueFeatureKinds(features) {
|
|
6
|
+
const kinds = new Set();
|
|
7
|
+
for (const f of features) {
|
|
8
|
+
if (kinds.has(f.ɵkind)) {
|
|
9
|
+
throw ngxZeroError(`provideZero(): duplicate feature "${f.ɵkind}".`);
|
|
10
|
+
}
|
|
11
|
+
kinds.add(f.ɵkind);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=features.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features.js","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,MAAM,UAAU,WAAW,CACzB,IAAO,EACP,SAA8B;IAE9B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,QAAgC;IACvE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,YAAY,CAAC,qCAAqC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;QACvE,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { provideZero } from './provide-zero.js';
|
|
2
|
+
export { injectZero } from './inject-zero.js';
|
|
3
|
+
export { injectQuery } from './inject-query.js';
|
|
4
|
+
export { injectMutator } from './inject-mutator.js';
|
|
5
|
+
export { injectConnectionState } from './inject-connection-state.js';
|
|
6
|
+
export { provideZeroTesting, type ZeroTestingOptions } from './provide-zero-testing.js';
|
|
7
|
+
export { withBootstrap } from './with-bootstrap.js';
|
|
8
|
+
export type { ZeroFeature, ZeroFeatureKind } from './features.js';
|
|
9
|
+
export type { InjectQueryOptions, QueryRef, QueryStatus } from './query-ref.js';
|
|
10
|
+
export type { InjectMutatorOptions, MutatorError, MutatorRef } from './mutator-ref.js';
|
|
11
|
+
export type { ConnectionState, Falsy } from '@rocicorp/zero';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAChF,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvF,YAAY,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { provideZero } from './provide-zero.js';
|
|
2
|
+
export { injectZero } from './inject-zero.js';
|
|
3
|
+
export { injectQuery } from './inject-query.js';
|
|
4
|
+
export { injectMutator } from './inject-mutator.js';
|
|
5
|
+
export { injectConnectionState } from './inject-connection-state.js';
|
|
6
|
+
export { provideZeroTesting } from './provide-zero-testing.js';
|
|
7
|
+
export { withBootstrap } from './with-bootstrap.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAA2B,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Injector, type Signal } from '@angular/core';
|
|
2
|
+
import type { ConnectionState } from '@rocicorp/zero';
|
|
3
|
+
export declare function injectConnectionState(options?: {
|
|
4
|
+
injector?: Injector;
|
|
5
|
+
}): Signal<ConnectionState>;
|
|
6
|
+
//# sourceMappingURL=inject-connection-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-connection-state.d.ts","sourceRoot":"","sources":["../src/inject-connection-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,EAGR,KAAK,MAAM,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,eAAe,EAAQ,MAAM,gBAAgB,CAAC;AAI5D,wBAAgB,qBAAqB,CACnC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAO,GACpC,MAAM,CAAC,eAAe,CAAC,CAiDzB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { assertInInjectionContext, DestroyRef, effect, inject, Injector, signal, untracked, } from '@angular/core';
|
|
2
|
+
import { ngxZeroError } from './errors.js';
|
|
3
|
+
import { ZERO_INSTANCE } from './instance-manager.js';
|
|
4
|
+
export function injectConnectionState(options = {}) {
|
|
5
|
+
if (options.injector === undefined) {
|
|
6
|
+
assertInInjectionContext(injectConnectionState);
|
|
7
|
+
}
|
|
8
|
+
const injector = options.injector ?? inject(Injector);
|
|
9
|
+
const manager = injector.get(ZERO_INSTANCE, null, { optional: true });
|
|
10
|
+
if (!manager) {
|
|
11
|
+
throw ngxZeroError('injectConnectionState() could not find a Zero instance manager. ' +
|
|
12
|
+
'Add provideZero(...) to your ApplicationConfig providers.');
|
|
13
|
+
}
|
|
14
|
+
const initial = untracked(() => manager.zeroOrThrow());
|
|
15
|
+
const state = signal(initial.connection.state.current);
|
|
16
|
+
let subscribed;
|
|
17
|
+
let unsubscribe;
|
|
18
|
+
// Zero's subscribe() does not replay the current value, so every (re)attach
|
|
19
|
+
// seeds from `current` before listening.
|
|
20
|
+
const attach = (zero) => {
|
|
21
|
+
if (zero === subscribed) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
unsubscribe?.();
|
|
25
|
+
subscribed = zero;
|
|
26
|
+
state.set(zero.connection.state.current);
|
|
27
|
+
unsubscribe = zero.connection.state.subscribe(next => state.set(next));
|
|
28
|
+
};
|
|
29
|
+
attach(initial);
|
|
30
|
+
effect(() => {
|
|
31
|
+
const zero = manager.zeroOrThrow();
|
|
32
|
+
untracked(() => attach(zero));
|
|
33
|
+
}, { injector });
|
|
34
|
+
injector.get(DestroyRef).onDestroy(() => {
|
|
35
|
+
unsubscribe?.();
|
|
36
|
+
unsubscribe = undefined;
|
|
37
|
+
subscribed = undefined;
|
|
38
|
+
});
|
|
39
|
+
return state.asReadonly();
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=inject-connection-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-connection-state.js","sourceRoot":"","sources":["../src/inject-connection-state.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,UAAU,EACV,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,UAAU,qBAAqB,CACnC,UAAmC,EAAE;IAErC,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACnC,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;IAClD,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC,Q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QACtC,WAAW,EAAE,EAAE,CAAC;QAChB,WAAW,GAAG,SAAS,CAAC;QACxB,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,UAAU,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DefaultContext, DefaultSchema, DefaultWrappedTransaction, Mutator, ReadonlyJSONValue, Schema } from '@rocicorp/zero';
|
|
2
|
+
import type { InjectMutatorOptions, MutatorRef } from './mutator-ref.js';
|
|
3
|
+
export declare function injectMutator<TInput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TContext = DefaultContext, TWrappedTransaction = DefaultWrappedTransaction>(mutator: Mutator<TInput, TSchema, TContext, TWrappedTransaction>, options?: InjectMutatorOptions): MutatorRef<TInput>;
|
|
4
|
+
//# sourceMappingURL=inject-mutator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-mutator.d.ts","sourceRoot":"","sources":["../src/inject-mutator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,yBAAyB,EACzB,OAAO,EAGP,iBAAiB,EACjB,MAAM,EACP,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzE,wBAAgB,aAAa,CAC3B,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,MAAM,GAAG,aAAa,EACtC,QAAQ,GAAG,cAAc,EACzB,mBAAmB,GAAG,yBAAyB,EAE/C,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,EAChE,OAAO,CAAC,EAAE,oBAAoB,GAC7B,UAAU,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { assertInInjectionContext, DestroyRef, inject, Injector, untracked, } from '@angular/core';
|
|
2
|
+
import { ngxZeroError } from './errors.js';
|
|
3
|
+
import { ZERO_INSTANCE } from './instance-manager.js';
|
|
4
|
+
import { MutatorCallTracker } from './mutator-call-tracker.js';
|
|
5
|
+
// Upstream's AnyMutator alias is private — take the leaf as `unknown`,
|
|
6
|
+
// cast once at the zero.mutate boundary.
|
|
7
|
+
export function injectMutator(mutator, options = {}) {
|
|
8
|
+
if (options.injector === undefined) {
|
|
9
|
+
assertInInjectionContext(injectMutator);
|
|
10
|
+
}
|
|
11
|
+
const injector = options.injector ?? inject(Injector);
|
|
12
|
+
const manager = injector.get(ZERO_INSTANCE, null, { optional: true });
|
|
13
|
+
if (!manager) {
|
|
14
|
+
throw ngxZeroError('injectMutator() could not find a Zero instance manager. ' +
|
|
15
|
+
'Add provideZero(...) to your ApplicationConfig providers.');
|
|
16
|
+
}
|
|
17
|
+
const tracker = new MutatorCallTracker();
|
|
18
|
+
injector.get(DestroyRef).onDestroy(() => tracker.destroy());
|
|
19
|
+
const mutate = (args) => {
|
|
20
|
+
// untracked: a mutate() inside an effect must not subscribe it to
|
|
21
|
+
// instance changes.
|
|
22
|
+
const zero = untracked(() => manager.zeroOrThrow());
|
|
23
|
+
const buildRequest = mutator;
|
|
24
|
+
// begin() after zero.mutate: its sync throw (unregistered mutator) must
|
|
25
|
+
// not leave a fake pending call.
|
|
26
|
+
const raw = zero.mutate(buildRequest(args));
|
|
27
|
+
const callId = tracker.begin();
|
|
28
|
+
const client = settleSafe(raw.client);
|
|
29
|
+
const server = settleSafe(raw.server);
|
|
30
|
+
// Two-arg then: the rejection handler is defensive-only (settleSafe is
|
|
31
|
+
// total); a throwing settle must stay observable, not swallowed.
|
|
32
|
+
void client.then(details => tracker.settleClient(callId, details), noop);
|
|
33
|
+
void server.then(details => tracker.settleServer(callId, details), noop);
|
|
34
|
+
return { client, server };
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
mutate,
|
|
38
|
+
clientPending: tracker.clientPending,
|
|
39
|
+
pending: tracker.pending,
|
|
40
|
+
clientResult: tracker.clientResult,
|
|
41
|
+
serverResult: tracker.serverResult,
|
|
42
|
+
error: tracker.error,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Never-reject boundary: rejections become Zero's own error details shape. */
|
|
46
|
+
function settleSafe(promise) {
|
|
47
|
+
return promise.catch((reason) => ({
|
|
48
|
+
type: 'error',
|
|
49
|
+
error: { type: 'zero', message: describeReason(reason) },
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
// Total for any unknown reason: a hostile coercion (throwing
|
|
53
|
+
// Symbol.toPrimitive or message getter) must not re-reject the boundary.
|
|
54
|
+
function describeReason(reason) {
|
|
55
|
+
try {
|
|
56
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return 'Unknown mutation failure';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function noop() { }
|
|
63
|
+
//# sourceMappingURL=inject-mutator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-mutator.js","sourceRoot":"","sources":["../src/inject-mutator.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,UAAU,EACV,MAAM,EACN,QAAQ,EACR,SAAS,GACV,MAAM,eAAe,CAAC;AAWvB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAa/D,uEAAuE;AACvE,yCAAyC;AACzC,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,UAAgC,EAAE;IAElC,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACnC,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CA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CAAC,CAAC;QAEzE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,SAAS,UAAU,CACjB,OAAsC;IAEtC,OAAO,OAAO,CAAC,KAAK,CAClB,CAAC,MAAe,EAAwB,EAAE,CAAC,CAAC;QAC1C,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE;KACzD,CAAC,CACH,CAAC;AACJ,CAAC;AAED,6DAA6D;AAC7D,yEAAyE;AACzE,SAAS,cAAc,CAAC,MAAe;IACrC,IAAI,CAAC;QACH,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,0BAA0B,CAAC;IACpC,CAAC;AACH,CAAC;AAED,SAAS,IAAI,KAAU,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseDefaultContext, BaseDefaultSchema, DefaultContext, DefaultSchema, Falsy, HumanReadable, PullRow, QueryOrQueryRequest, ReadonlyJSONValue } from '@rocicorp/zero';
|
|
2
|
+
import type { InjectQueryOptions, QueryRef, QueryStatus } from './query-ref.js';
|
|
3
|
+
/** Always-enabled: tight data type, status can never be 'disabled'. */
|
|
4
|
+
export declare function injectQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends BaseDefaultSchema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext extends BaseDefaultContext = DefaultContext>(queryThunk: () => QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext>, options?: InjectQueryOptions): QueryRef<HumanReadable<TReturn>>;
|
|
5
|
+
/** Disableable: data widens with `| undefined`, status with 'disabled'. */
|
|
6
|
+
export declare function injectQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends BaseDefaultSchema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext extends BaseDefaultContext = DefaultContext>(queryThunk: () => QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext> | Falsy, options?: InjectQueryOptions): QueryRef<HumanReadable<TReturn> | undefined, QueryStatus>;
|
|
7
|
+
//# sourceMappingURL=inject-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-query.d.ts","sourceRoot":"","sources":["../src/inject-query.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,KAAK,EACL,aAAa,EACb,OAAO,EACP,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EACV,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAUxB,uEAAuE;AACvE,wBAAgB,WAAW,CACzB,MAAM,SAAS,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC/C,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,iBAAiB,GAAG,SAAS,EAC7C,OAAO,SAAS,iBAAiB,GAAG,aAAa,EACjD,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,QAAQ,SAAS,kBAAkB,GAAG,cAAc,EAEpD,UAAU,EAAE,MAAM,mBAAmB,CACnC,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,CACT,EACD,OAAO,CAAC,EAAE,kBAAkB,GAC3B,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAEpC,2EAA2E;AAC3E,wBAAgB,WAAW,CACzB,MAAM,SAAS,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,EAC/C,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,iBAAiB,GAAG,SAAS,EAC7C,OAAO,SAAS,iBAAiB,GAAG,aAAa,EACjD,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,QAAQ,SAAS,kBAAkB,GAAG,cAAc,EAEpD,UAAU,EAAE,MACR,mBAAmB,CACjB,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,CACT,GACD,KAAK,EACT,OAAO,CAAC,EAAE,kBAAkB,GAC3B,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, untracked, } from '@angular/core';
|
|
2
|
+
import { ngxZeroError } from './errors.js';
|
|
3
|
+
import { ZERO_INSTANCE } from './instance-manager.js';
|
|
4
|
+
import { resolveQuery, } from './query-identity.js';
|
|
5
|
+
import { DISABLED, QueryViewController, } from './query-view-controller.js';
|
|
6
|
+
export function injectQuery(queryThunk, options = {}) {
|
|
7
|
+
if (options.injector === undefined) {
|
|
8
|
+
assertInInjectionContext(injectQuery);
|
|
9
|
+
}
|
|
10
|
+
const injector = options.injector ?? inject(Injector);
|
|
11
|
+
const manager = injector.get(ZERO_INSTANCE, null, { optional: true });
|
|
12
|
+
if (!manager) {
|
|
13
|
+
throw ngxZeroError('injectQuery() could not find a Zero instance manager. ' +
|
|
14
|
+
'Add provideZero(...) to your ApplicationConfig providers.');
|
|
15
|
+
}
|
|
16
|
+
// One computed for both change sources (instance + thunk signals);
|
|
17
|
+
// key-equal reruns keep the old reference via `equal`.
|
|
18
|
+
const spec = computed(() => {
|
|
19
|
+
const zero = manager.zeroOrThrow();
|
|
20
|
+
const result = queryThunk();
|
|
21
|
+
if (!result) {
|
|
22
|
+
return { zero, key: DISABLED, query: undefined };
|
|
23
|
+
}
|
|
24
|
+
return { zero, ...resolveQuery(zero, result) };
|
|
25
|
+
}, { equal: (a, b) => a.zero === b.zero && a.key === b.key });
|
|
26
|
+
const controller = new QueryViewController({
|
|
27
|
+
keepPreviousData: options.keepPreviousData ?? false,
|
|
28
|
+
ttl: options.ttl,
|
|
29
|
+
});
|
|
30
|
+
injector.get(DestroyRef).onDestroy(() => controller.destroy());
|
|
31
|
+
// Eager: the first change-detection pass renders real rows; the effect's
|
|
32
|
+
// first flush re-reads the same cached spec and is a no-op.
|
|
33
|
+
untracked(() => controller.reconcile(spec()));
|
|
34
|
+
effect(() => {
|
|
35
|
+
const current = spec();
|
|
36
|
+
untracked(() => controller.reconcile(current));
|
|
37
|
+
}, { injector });
|
|
38
|
+
return {
|
|
39
|
+
data: controller.data,
|
|
40
|
+
status: controller.status,
|
|
41
|
+
error: controller.error,
|
|
42
|
+
isComplete: computed(() => controller.status() === 'complete'),
|
|
43
|
+
retry: () => controller.retry(spec),
|
|
44
|
+
updateTTL: ttl => controller.updateTTL(ttl),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=inject-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-query.js","sourceRoot":"","sources":["../src/inject-query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,QAAQ,EACR,UAAU,EACV,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAS,GACV,MAAM,eAAe,CAAC;AAYvB,OAAO,EAAE,YAAY,EA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B,UAAU,CAAC,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAe1E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assertInInjectionContext, inject, Injector } from '@angular/core';
|
|
2
|
+
import { ngxZeroError } from './errors.js';
|
|
3
|
+
import { ZERO_INSTANCE } from './instance-manager.js';
|
|
4
|
+
export function injectZero(options) {
|
|
5
|
+
if (options?.injector === undefined) {
|
|
6
|
+
assertInInjectionContext(injectZero);
|
|
7
|
+
}
|
|
8
|
+
const injector = options?.injector ?? inject(Injector);
|
|
9
|
+
const manager = injector.get(ZERO_INSTANCE, null, { optional: true });
|
|
10
|
+
if (!manager) {
|
|
11
|
+
throw ngxZeroError('injectZero() could not find a Zero instance manager. ' +
|
|
12
|
+
'Add provideZero(...) to your ApplicationConfig providers.');
|
|
13
|
+
}
|
|
14
|
+
return manager.zeroOrThrow;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=inject-zero.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-zero.js","sourceRoot":"","sources":["../src/inject-zero.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,UAAU,UAAU,CAAC,OAAiC;IAC1D,IAAI,OAAO,EAAE,QAAQ,KAAK,SAAS,EAAE,CAAC;QACpC,wBAAwB,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEvD,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAEtE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,YAAY,CAChB,uDAAuD;YACvD,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,WAAW,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Zero, type ZeroOptions } from '@rocicorp/zero';
|
|
3
|
+
import type { ZeroInstanceHooks, ZeroInstanceOptions } from './types.js';
|
|
4
|
+
export declare const ZERO_INSTANCE: InjectionToken<ZeroInstanceManager>;
|
|
5
|
+
export declare const ZERO_CONSTRUCTOR: InjectionToken<(options: ZeroOptions) => Zero>;
|
|
6
|
+
export declare const ZERO_INSTANCE_HOOKS: InjectionToken<readonly ZeroInstanceHooks[]>;
|
|
7
|
+
export declare class ZeroInstanceManager {
|
|
8
|
+
#private;
|
|
9
|
+
readonly zeroOrThrow: import("@angular/core").Signal<Zero<import("@rocicorp/zero").Schema, undefined, unknown>>;
|
|
10
|
+
constructor(source: ZeroInstanceOptions);
|
|
11
|
+
start(): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=instance-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance-manager.d.ts","sourceRoot":"","sources":["../src/instance-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,cAAc,EAIf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGxD,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,aAAa,qCAEzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,2BAAgC,WAAW,KAAK,IAAI,CAGhF,CAAC;AAEF,eAAO,MAAM,mBAAmB,8CAE/B,CAAC;AAMF,qBAAa,mBAAmB;;IAc9B,QAAQ,CAAC,WAAW,4FAQjB;gBAUS,MAAM,EAAE,mBAAmB;IAMvC,KAAK,IAAI,IAAI;CAiJd"}
|