@spooky-sync/client-angular 0.0.0-stage → 0.0.1-canary.384
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/AGENTS.md +120 -0
- package/QUICK_START.md +199 -0
- package/README.md +78 -2
- package/fesm2022/spooky-sync-client-angular.mjs +1507 -0
- package/fesm2022/spooky-sync-client-angular.mjs.map +1 -0
- package/package.json +48 -3
- package/skills/sp00ky-angular/SKILL.md +97 -0
- package/types/spooky-sync-client-angular.d.ts +758 -0
- package/types/spooky-sync-client-angular.d.ts.map +1 -0
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
import { SchemaStructure, TableNames, TableModel, GetTable, GenericSchema, InnerQuery, FinalQuery, QueryBuilder, ChannelTableNames, ChannelPeer, BackendNames, BackendRoutes, RoutePayload, BucketNames, BucketDefinitionSchema, ColumnSchema, QueryResult, RelationshipFieldsFromSchema, GetRelationship, RelatedFieldsMap, RelatedFieldMapEntry } from '@spooky-sync/query-builder';
|
|
2
|
+
export { GenericModel, GenericSchema, GetCardinality, GetTable, InferRelatedModelFromMetadata, QueryInfo, QueryModifier, QueryModifierBuilder, QueryResult, RelationshipDefinition, RelationshipsMetadata, TableModel, TableNames } from '@spooky-sync/query-builder';
|
|
3
|
+
import { RecordId, Surreal } from 'surrealdb';
|
|
4
|
+
export { RecordId, Uuid } from 'surrealdb';
|
|
5
|
+
import * as _angular_core from '@angular/core';
|
|
6
|
+
import { Injector, EnvironmentProviders, Signal } from '@angular/core';
|
|
7
|
+
import { Sp00kyConfig, Sp00kyClient, UpdateOptions, Sp00kyQueryResultPromise, PreloadOptions as PreloadOptions$1, ChannelQuery, Sp00kyChannel, RunOptions, AuthService, SyncHealth, StorageHealth, WebPushModule, BucketHandle, SyncHealthStatus, ConnectionState, StorageHealthStatus, ImpersonationInfo, FeatureFlagOptions, AppReleaseOptions, CrdtField, ChannelStatus, BucketPutOptions, BucketPutResult } from '@spooky-sync/core';
|
|
8
|
+
export { ChannelOp, ChannelState, ChannelStatus, ChannelsConfig, ConnectionState, PreloadRefresh, PushDeviceKind, PushNotification, PushPayload, ReconnectConfig, Sp00kyChannel, StorageHealth, StorageHealthStatus, SyncHealth, SyncHealthConfig, SyncHealthStatus, WebPushClientMessage, WebPushConfig, WebPushDevice, WebPushError, WebPushErrorCode, WebPushInfo, WebPushMessage, WebPushMessageInput, WebPushModule, WebPushSubscribeOptions, WebPushSupport, WebPushSyncOptions, WebPushSyncStatus, WebPushUnsubscribeOptions, WebPushUnsupportedReason, WebPushUpdateOptions } from '@spooky-sync/core';
|
|
9
|
+
import * as _spooky_sync_client_angular from '@spooky-sync/client-angular';
|
|
10
|
+
|
|
11
|
+
type Model<T> = T;
|
|
12
|
+
type ModelPayload<T> = T & {
|
|
13
|
+
id: RecordId;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A value, a signal, or a function that reads signals. Angular tracks the
|
|
17
|
+
* signals read inside it, so an input that should follow component state is
|
|
18
|
+
* passed as a signal (`this.postId`, an `input()`) or a function
|
|
19
|
+
* (`() => this.postId()`); a plain value is fixed.
|
|
20
|
+
*/
|
|
21
|
+
type MaybeSignal<T> = T | (() => T);
|
|
22
|
+
/**
|
|
23
|
+
* Every `inject*` function must run in an injection context (a constructor, a
|
|
24
|
+
* field initializer, a factory). Pass `injector` to call one anywhere else,
|
|
25
|
+
* like Angular's own `effect()` and `toSignal()`.
|
|
26
|
+
*/
|
|
27
|
+
interface InjectOptions {
|
|
28
|
+
injector?: Injector;
|
|
29
|
+
}
|
|
30
|
+
/** Options for database provisioning. */
|
|
31
|
+
interface ProvisionOptions {
|
|
32
|
+
/** Force re-provision even if schema already exists */
|
|
33
|
+
force?: boolean;
|
|
34
|
+
}
|
|
35
|
+
type CacheStrategy = 'memory' | 'indexeddb';
|
|
36
|
+
/** Infer Schema type (Record<TableName, Model>) from the schema const. */
|
|
37
|
+
type InferSchemaFromConst<S extends SchemaStructure> = {
|
|
38
|
+
[K in TableNames<S>]: TableModel<GetTable<S, K>>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Infer Relationships type from the schema const's relationships array,
|
|
42
|
+
* converted from array format to nested object format.
|
|
43
|
+
*/
|
|
44
|
+
type InferRelationshipsFromConst<S extends SchemaStructure, Schema extends GenericSchema> = {
|
|
45
|
+
[TableName in TableNames<S>]: {
|
|
46
|
+
[Rel in Extract<S['relationships'][number], {
|
|
47
|
+
from: TableName;
|
|
48
|
+
}> as Rel['field']]: {
|
|
49
|
+
model: Rel['to'] extends keyof Schema ? Schema[Rel['to']] : any;
|
|
50
|
+
table: Rel['to'];
|
|
51
|
+
cardinality: Rel['cardinality'];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
type Prettify<T> = {
|
|
56
|
+
[K in keyof T]: T[K];
|
|
57
|
+
} & {};
|
|
58
|
+
type SyncedDbConfig<S extends SchemaStructure> = Prettify<Sp00kyConfig<S>>;
|
|
59
|
+
/** Second argument of `provideSp00ky`. */
|
|
60
|
+
interface Sp00kyOptions<S extends SchemaStructure> {
|
|
61
|
+
/**
|
|
62
|
+
* Prewarm data into the local cache before the app renders. Runs after
|
|
63
|
+
* `init()`, inside the same app initializer. Best-effort: a rejection is
|
|
64
|
+
* logged and the app starts anyway.
|
|
65
|
+
*/
|
|
66
|
+
preload?: (db: SyncedDb<S>) => Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* SyncedDb - a thin wrapper around the sp00ky core client for Angular.
|
|
71
|
+
* Delegates all logic to the underlying `Sp00kyClient` instance.
|
|
72
|
+
*
|
|
73
|
+
* It is also the DI token: `provideSp00ky(config)` provides one instance per
|
|
74
|
+
* application, and `inject(SyncedDb)` / `injectDb()` return it.
|
|
75
|
+
*
|
|
76
|
+
* NOTE: keep in sync with packages/client-react/src/db.ts,
|
|
77
|
+
* packages/client-svelte/src/db.ts and packages/client-solid2/src/index.ts
|
|
78
|
+
* (SyncedDb). Copied rather than shared so each binding's dependency graph
|
|
79
|
+
* stays its own. Angular rows are plain objects (signals never proxy), so
|
|
80
|
+
* unlike the Svelte and Solid 2 copies nothing is unwrapped before a write.
|
|
81
|
+
*/
|
|
82
|
+
declare class SyncedDb<S extends SchemaStructure> {
|
|
83
|
+
private config;
|
|
84
|
+
private sp00ky;
|
|
85
|
+
private _initialized;
|
|
86
|
+
constructor(config: SyncedDbConfig<S>);
|
|
87
|
+
getSp00ky(): Sp00kyClient<S>;
|
|
88
|
+
/** Initialize the core client. */
|
|
89
|
+
init(): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Tear down the client: leaves the tabs broker, closes the local store and
|
|
92
|
+
* remote socket, and frees the wasm circuit.
|
|
93
|
+
*/
|
|
94
|
+
close(): Promise<void>;
|
|
95
|
+
/** Create a new record in the database. */
|
|
96
|
+
create(id: string, payload: Record<string, unknown>): Promise<void>;
|
|
97
|
+
/** Update an existing record in the database. */
|
|
98
|
+
update<TName extends TableNames<S>>(tableName: TName, recordId: string, payload: Partial<TableModel<GetTable<S, TName>>>, options?: UpdateOptions): Promise<void>;
|
|
99
|
+
/** Delete an existing record in the database. */
|
|
100
|
+
delete<TName extends TableNames<S>>(tableName: TName, selector: string | RecordId | InnerQuery<GetTable<S, TName>, boolean>): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Preload/prewarm a built query into the local cache without a component
|
|
103
|
+
* subscribing to it, so a later `injectQuery` for the same data paints
|
|
104
|
+
* instantly. Best-effort.
|
|
105
|
+
*/
|
|
106
|
+
preload(finalQuery: FinalQuery<S, any, any, any, any, Sp00kyQueryResultPromise>, options?: PreloadOptions$1): Promise<void>;
|
|
107
|
+
/** Start a query on `table`. Finish it with `.build()` and pass it to `injectQuery`. */
|
|
108
|
+
query<TName extends TableNames<S>>(table: TName): QueryBuilder<S, TName, Sp00kyQueryResultPromise, {}, false>;
|
|
109
|
+
/**
|
|
110
|
+
* Open a peer to peer channel to `peers` for the rows `query` matches (a
|
|
111
|
+
* query on a `-- @channel` table; only its `where` counts). Prefer the
|
|
112
|
+
* `injectChannel` function, which closes it with the component.
|
|
113
|
+
*/
|
|
114
|
+
channel<T extends ChannelTableNames<S>>(query: ChannelQuery<S, T> | ReadonlyArray<ChannelQuery<S, T>>, peers: Iterable<ChannelPeer>): Sp00kyChannel<S, T>;
|
|
115
|
+
/** Run a backend operation (writes an outbox job row). */
|
|
116
|
+
run<B extends BackendNames<S>, R extends BackendRoutes<S, B>>(backend: B, path: R, payload: RoutePayload<S, B, R>, options?: RunOptions): Promise<void>;
|
|
117
|
+
/** Authenticate the remote connection with a token. */
|
|
118
|
+
authenticate(token: string): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Tell the client that this app's own impersonation banner is on screen.
|
|
121
|
+
* Only needed with `impersonationBanner: { mode: 'custom' }`; the
|
|
122
|
+
* `injectImpersonation({ rendersBanner: true })` calls it for you.
|
|
123
|
+
*/
|
|
124
|
+
acknowledgeImpersonationBanner(): void;
|
|
125
|
+
/** Sign out, clear session and local storage. */
|
|
126
|
+
signOut(): Promise<void>;
|
|
127
|
+
/** Execute a function with direct access to the remote database connection. */
|
|
128
|
+
useRemote<T>(fn: (db: Surreal) => T | Promise<T>): Promise<T>;
|
|
129
|
+
/**
|
|
130
|
+
* Run one SurrealQL statement against the REMOTE database, results shaped
|
|
131
|
+
* like the SDK's own `.query()` (one entry per statement). Nothing is cached
|
|
132
|
+
* locally. Prefer this over `useRemote(s => s.query(...))` for a plain read:
|
|
133
|
+
* the bare SDK client that callback receives skips the connect gate, so a
|
|
134
|
+
* statement issued while the socket is being rebuilt fails with "Specify a
|
|
135
|
+
* namespace to use" instead of waiting for the session.
|
|
136
|
+
*/
|
|
137
|
+
remoteQuery<T extends unknown[] = unknown[]>(sql: string, vars?: Record<string, unknown>): Promise<T>;
|
|
138
|
+
/** Access the remote database service directly. */
|
|
139
|
+
get remote(): Sp00kyClient<S>['remoteClient'];
|
|
140
|
+
/** Access the local database service directly. */
|
|
141
|
+
get local(): Sp00kyClient<S>['localClient'];
|
|
142
|
+
/** Access the auth service. */
|
|
143
|
+
get auth(): AuthService<S>;
|
|
144
|
+
get pendingMutationCount(): number;
|
|
145
|
+
/** Diagnostic, see `Sp00kyClient.liveRetryCount`. */
|
|
146
|
+
get liveRetryCount(): number;
|
|
147
|
+
subscribeToPendingMutations(cb: (count: number) => void): () => void;
|
|
148
|
+
/** Queries mid-fetch right now. See {@link injectSyncActivity}. */
|
|
149
|
+
get fetchingQueryCount(): number;
|
|
150
|
+
/**
|
|
151
|
+
* Observe how many queries are fetching from the server. Fires immediately
|
|
152
|
+
* and on every change. Prefer `injectSyncActivity` in components.
|
|
153
|
+
*/
|
|
154
|
+
subscribeToFetchActivity(cb: (fetching: number) => void): () => void;
|
|
155
|
+
/** Current sync-health snapshot. See {@link injectSyncStatus}. */
|
|
156
|
+
get syncHealth(): SyncHealth;
|
|
157
|
+
/**
|
|
158
|
+
* Observe sync health. Fires immediately with the current status and again
|
|
159
|
+
* on every healthy/degraded transition. Prefer `injectSyncStatus` in
|
|
160
|
+
* components; this is the imperative escape hatch.
|
|
161
|
+
*/
|
|
162
|
+
subscribeToSyncHealth(cb: (health: SyncHealth) => void): () => void;
|
|
163
|
+
/** Current local-store durability snapshot. See {@link injectStorageStatus}. */
|
|
164
|
+
get storageHealth(): StorageHealth;
|
|
165
|
+
/**
|
|
166
|
+
* Observe local-store durability. Fires immediately with the current
|
|
167
|
+
* snapshot and again on change. Prefer `injectStorageStatus`.
|
|
168
|
+
*/
|
|
169
|
+
subscribeToStorageHealth(cb: (health: StorageHealth) => void): () => void;
|
|
170
|
+
/**
|
|
171
|
+
* Web Push for this browser: `support()`, `subscribe()` (from a click),
|
|
172
|
+
* `devices()`, `notify()` / `test()` (push to yourself), `bridge()` for the
|
|
173
|
+
* service worker. See the push-notifications docs page.
|
|
174
|
+
*/
|
|
175
|
+
get webPush(): WebPushModule;
|
|
176
|
+
bucket<B extends BucketNames<S>>(name: B): BucketHandle;
|
|
177
|
+
getBucketConfig(name: string): BucketDefinitionSchema | undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Provide the sp00ky client to the application:
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* // app.config.ts
|
|
185
|
+
* export const appConfig: ApplicationConfig = {
|
|
186
|
+
* providers: [provideSp00ky(dbConfig)],
|
|
187
|
+
* };
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* The client starts in an app initializer, so the app renders once it is
|
|
191
|
+
* ready and every `inject*` function can use it straight away. Whatever is in
|
|
192
|
+
* the root element of `index.html` stays on screen until then. If `init()`
|
|
193
|
+
* fails, bootstrap fails: handle it on `bootstrapApplication(...).catch(...)`.
|
|
194
|
+
*
|
|
195
|
+
* `config` may also be a factory, run in the injection context, to build the
|
|
196
|
+
* config from other providers. During a server render the client is created
|
|
197
|
+
* but never started (see `injectQuery`).
|
|
198
|
+
*
|
|
199
|
+
* The client is closed when the application is destroyed.
|
|
200
|
+
*/
|
|
201
|
+
declare function provideSp00ky<S extends SchemaStructure>(config: SyncedDbConfig<S> | (() => SyncedDbConfig<S>), options?: Sp00kyOptions<S>): EnvironmentProviders;
|
|
202
|
+
/**
|
|
203
|
+
* The application's `SyncedDb`, typed with your schema:
|
|
204
|
+
* `private readonly db = injectDb<typeof schema>();`. Same instance as
|
|
205
|
+
* `inject(SyncedDb)`.
|
|
206
|
+
*/
|
|
207
|
+
declare function injectDb<S extends SchemaStructure>(options?: InjectOptions): SyncedDb<S>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Value equality for the leaves `share` does not descend into. The decoder
|
|
211
|
+
* hands out a fresh RecordId / Date / Uuid / Duration for every record-link
|
|
212
|
+
* and datetime column on every emission, so by identity every such field
|
|
213
|
+
* "changed" every time. Two instances of the same class that print alike are
|
|
214
|
+
* the same value. A class whose `toString` is the default `[object X]`
|
|
215
|
+
* (ArrayBuffer, Map, ...) cannot be compared that way and counts as changed.
|
|
216
|
+
*/
|
|
217
|
+
declare function sameValue(a: unknown, b: unknown): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Structural sharing between two emissions: returns `prev` itself where
|
|
220
|
+
* `next` is deep-equal to it, and a new value that reuses every unchanged
|
|
221
|
+
* subtree otherwise. Array items with an `id` are matched by id, so a row keeps
|
|
222
|
+
* its object identity across reorders, inserts and deletes.
|
|
223
|
+
*
|
|
224
|
+
* That is what makes one signal per query fine-grained enough: a deep-equal
|
|
225
|
+
* emission is the same value, so the signal (compared with `Object.is`) does
|
|
226
|
+
* not notify at all, and an `@for (...; track row.id)` hands an unchanged row
|
|
227
|
+
* the same object, so its `computed`s and `OnPush` children stay put.
|
|
228
|
+
*
|
|
229
|
+
* Never mutates either argument: the engine may hand the same row objects to
|
|
230
|
+
* several subscribers.
|
|
231
|
+
*/
|
|
232
|
+
declare function share<T>(prev: unknown, next: T): T;
|
|
233
|
+
type AnyFinalQuery = FinalQuery<any, any, any, any, any, Sp00kyQueryResultPromise>;
|
|
234
|
+
type BuiltQuery<S extends SchemaStructure, TableName extends TableNames<S>, T extends {
|
|
235
|
+
columns: Record<string, ColumnSchema>;
|
|
236
|
+
}, RelatedFields extends Record<string, any>, IsOne extends boolean> = FinalQuery<S, TableName, T, RelatedFields, IsOne, Sp00kyQueryResultPromise>;
|
|
237
|
+
interface QueryOptions extends InjectOptions {
|
|
238
|
+
/** Only register while true (default `true`). `false` keeps the last data. */
|
|
239
|
+
enabled?: MaybeSignal<boolean>;
|
|
240
|
+
/**
|
|
241
|
+
* Tear down the query (remote `_00_query` view + local WASM view) when the
|
|
242
|
+
* injection context is destroyed and no other subscriber remains, instead of
|
|
243
|
+
* keeping it resident for cheap re-subscription. Use for viewport-windowed
|
|
244
|
+
* lists that mount and unmount a query per scroll window. Trade-off:
|
|
245
|
+
* scrolling back to a torn-down window re-registers it.
|
|
246
|
+
*/
|
|
247
|
+
deregisterOnCleanup?: boolean;
|
|
248
|
+
}
|
|
249
|
+
/** A live query. Every field is a read-only signal: `posts.data()`, `posts.isLoading()`. */
|
|
250
|
+
interface QueryState<TData> {
|
|
251
|
+
/**
|
|
252
|
+
* The result. `[]` / `null` before the first emission, then each live
|
|
253
|
+
* emission with structural sharing: unchanged rows keep their object
|
|
254
|
+
* identity, and a deep-equal emission does not notify.
|
|
255
|
+
*/
|
|
256
|
+
readonly data: Signal<TData>;
|
|
257
|
+
/** Registration or sync error (e.g. SSP 503 during bootstrap). Never thrown. */
|
|
258
|
+
readonly error: Signal<Error | undefined>;
|
|
259
|
+
/**
|
|
260
|
+
* True only on a COLD first load: nothing painted for this identity, the
|
|
261
|
+
* server has not answered, and registration has not failed. A paint from the
|
|
262
|
+
* local cache ends it, and so does the server answering with zero rows.
|
|
263
|
+
*/
|
|
264
|
+
readonly isLoading: Signal<boolean>;
|
|
265
|
+
/** A fetch cycle is in flight (registration, a sync round). */
|
|
266
|
+
readonly isFetching: Signal<boolean>;
|
|
267
|
+
/**
|
|
268
|
+
* `data` holds the rendered rows of a known membership for this identity:
|
|
269
|
+
* the server's answer, or the membership an earlier session left on this
|
|
270
|
+
* device. From here `data` is an answer, not a cache guess.
|
|
271
|
+
*/
|
|
272
|
+
readonly isAuthoritative: Signal<boolean>;
|
|
273
|
+
/** `data` holds something: rows for a list, a row for `.one()`. */
|
|
274
|
+
readonly hasData: Signal<boolean>;
|
|
275
|
+
/** Authoritative AND no data: the server said "no rows". Render empty states on this. */
|
|
276
|
+
readonly isEmpty: Signal<boolean>;
|
|
277
|
+
/**
|
|
278
|
+
* Authoritative AND idle. The gate for trusting a short window as the end of
|
|
279
|
+
* a list, and for "create it if it is missing". Not monotonic: a later sync
|
|
280
|
+
* round re-enters `isFetching`.
|
|
281
|
+
*/
|
|
282
|
+
readonly isSettled: Signal<boolean>;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* What `data` holds: a list is never null (`[]` until the first emission), a
|
|
286
|
+
* `.one()` row is `null` until it exists.
|
|
287
|
+
*/
|
|
288
|
+
type QueryData<S extends SchemaStructure, TableName extends TableNames<S>, RelatedFields extends Record<string, any>, IsOne extends boolean> = IsOne extends true ? QueryResult<S, TableName, RelatedFields, true> | null : QueryResult<S, TableName, RelatedFields, false>;
|
|
289
|
+
/**
|
|
290
|
+
* Live query. Pass a function that builds the query, so it follows the signals
|
|
291
|
+
* it reads (`() => this.db.query('post').where({ author: this.userId() }).build()`);
|
|
292
|
+
* return `null` / `undefined` to skip. The query is re-registered only when
|
|
293
|
+
* its identity hash (surql + vars) changes, not on every rebuild.
|
|
294
|
+
*
|
|
295
|
+
* Call it in an injection context (a field initializer or constructor), or pass
|
|
296
|
+
* `{ injector }`. The registration ends with that context.
|
|
297
|
+
*
|
|
298
|
+
* ```ts
|
|
299
|
+
* @Component({
|
|
300
|
+
* template: `@for (post of posts.data(); track post.id) { <p>{{ post.title }}</p> }`,
|
|
301
|
+
* })
|
|
302
|
+
* export class PostList {
|
|
303
|
+
* private readonly db = injectDb<typeof schema>();
|
|
304
|
+
* readonly posts = injectQuery(() =>
|
|
305
|
+
* this.db.query('post').orderBy('created_at', 'desc').limit(20).build()
|
|
306
|
+
* );
|
|
307
|
+
* }
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare function injectQuery<S extends SchemaStructure, TableName extends TableNames<S>, T extends {
|
|
311
|
+
columns: Record<string, ColumnSchema>;
|
|
312
|
+
}, RelatedFields extends Record<string, any>, IsOne extends boolean, TData = QueryData<S, TableName, RelatedFields, IsOne>>(query: MaybeSignal<BuiltQuery<S, TableName, T, RelatedFields, IsOne> | null | undefined>, options?: QueryOptions): QueryState<TData>;
|
|
313
|
+
interface PreloadOptions extends PreloadOptions$1, InjectOptions {
|
|
314
|
+
/** Only preload while true (default `true`). */
|
|
315
|
+
enabled?: MaybeSignal<boolean>;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Fire-and-forget prewarm: registers the query via `db.preload` (a live query
|
|
319
|
+
* nobody subscribes to, evicted a ttl after registration unless a view mounts
|
|
320
|
+
* it first) whenever its identity changes. Nothing to clean up.
|
|
321
|
+
*
|
|
322
|
+
* Typical use: in a list row, preload the detail query the user is likely to
|
|
323
|
+
* open next, so navigation paints from cache instead of the network.
|
|
324
|
+
*/
|
|
325
|
+
declare function injectPreload(query: MaybeSignal<AnyFinalQuery | null | undefined>, options?: PreloadOptions): void;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Count of locally committed mutations not acknowledged by the server yet.
|
|
329
|
+
* Drive an "unsaved changes" indicator off it.
|
|
330
|
+
*/
|
|
331
|
+
declare function injectPendingMutations(options?: InjectOptions): Signal<number>;
|
|
332
|
+
interface SyncStatus {
|
|
333
|
+
/** Full health snapshot. */
|
|
334
|
+
readonly health: Signal<SyncHealth>;
|
|
335
|
+
/** `'healthy'` | `'degraded'`. */
|
|
336
|
+
readonly status: Signal<SyncHealthStatus>;
|
|
337
|
+
readonly isHealthy: Signal<boolean>;
|
|
338
|
+
/** `true` once sync has failed for a sustained run. Drive a banner off this. */
|
|
339
|
+
readonly isDegraded: Signal<boolean>;
|
|
340
|
+
/** `true` once at least one sync round has succeeded this session. */
|
|
341
|
+
readonly everConnected: Signal<boolean>;
|
|
342
|
+
/**
|
|
343
|
+
* `true` only for a real lost connection: degraded AFTER a first successful
|
|
344
|
+
* sync. Stays `false` during the initial "connecting" phase.
|
|
345
|
+
*/
|
|
346
|
+
readonly isOffline: Signal<boolean>;
|
|
347
|
+
/**
|
|
348
|
+
* Transport state of the remote WebSocket. Flips the instant the socket
|
|
349
|
+
* drops, unlike `status`, which only degrades after a sustained run of failed
|
|
350
|
+
* sync rounds.
|
|
351
|
+
*/
|
|
352
|
+
readonly connection: Signal<ConnectionState>;
|
|
353
|
+
/** `true` while the connection is being re-established. Usually still healthy. */
|
|
354
|
+
readonly isReconnecting: Signal<boolean>;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Observe sync health for a "can't reach the server" banner / indicator.
|
|
358
|
+
* Individual sync failures are absorbed by the retry; `isDegraded` only turns
|
|
359
|
+
* on once failures persist (core `syncHealth.degradeAfterConsecutiveFailures`,
|
|
360
|
+
* default 3) and turns off on the next successful round.
|
|
361
|
+
*
|
|
362
|
+
* Needs no component: in a service (`providedIn: 'root'`) it lives as long as
|
|
363
|
+
* the app.
|
|
364
|
+
*/
|
|
365
|
+
declare function injectSyncStatus(options?: InjectOptions): SyncStatus;
|
|
366
|
+
interface StorageStatus {
|
|
367
|
+
/** Full durability snapshot. */
|
|
368
|
+
readonly health: Signal<StorageHealth>;
|
|
369
|
+
/** `'unknown'` | `'persistent'` | `'memory'`. */
|
|
370
|
+
readonly status: Signal<StorageHealthStatus>;
|
|
371
|
+
/** `true` when the local store survives a reload. */
|
|
372
|
+
readonly isPersistent: Signal<boolean>;
|
|
373
|
+
/**
|
|
374
|
+
* `true` only when durable storage was requested and could NOT be opened, so
|
|
375
|
+
* local writes die on reload. Drive a warning off this, not off `status`: a
|
|
376
|
+
* store configured as in-memory reports `'memory'` too, by choice.
|
|
377
|
+
*/
|
|
378
|
+
readonly isMemoryFallback: Signal<boolean>;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Observe how durable the LOCAL cache is, for a "no local storage" warning.
|
|
382
|
+
* Under `localEngine: 'sqlite'` + `store: 'indexeddb'` only one client per
|
|
383
|
+
* bucket can hold the OPFS store open; a second tab runs in memory.
|
|
384
|
+
*/
|
|
385
|
+
declare function injectStorageStatus(options?: InjectOptions): StorageStatus;
|
|
386
|
+
interface SyncActivityOptions extends InjectOptions {
|
|
387
|
+
/**
|
|
388
|
+
* How long queries must be fetching before `isDownloading` turns on. Filters
|
|
389
|
+
* the sub-frame fetches a warm cache produces. Default 200 ms.
|
|
390
|
+
*/
|
|
391
|
+
downloadDelayMs?: number;
|
|
392
|
+
/** `isUploading` turns on once MORE than this many writes are queued. Default 0. */
|
|
393
|
+
uploadThreshold?: number;
|
|
394
|
+
/**
|
|
395
|
+
* How long the outbox must stay above `uploadThreshold` before `isUploading`
|
|
396
|
+
* turns on: a write acknowledged within a round trip never lights it.
|
|
397
|
+
* Default 150 ms.
|
|
398
|
+
*/
|
|
399
|
+
uploadDelayMs?: number;
|
|
400
|
+
}
|
|
401
|
+
interface SyncActivity {
|
|
402
|
+
/** Queries with traffic the user waits on (core `fetchingQueryCount`). */
|
|
403
|
+
readonly fetchingQueries: Signal<number>;
|
|
404
|
+
/** Locally committed writes the server has not acknowledged yet. */
|
|
405
|
+
readonly pendingMutations: Signal<number>;
|
|
406
|
+
/** Fetching for longer than `downloadDelayMs`. Drives a "downloading" mark. */
|
|
407
|
+
readonly isDownloading: Signal<boolean>;
|
|
408
|
+
/** More than `uploadThreshold` writes queued for longer than `uploadDelayMs`. */
|
|
409
|
+
readonly isUploading: Signal<boolean>;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* The two directions of sync traffic, for an indicator in the app chrome.
|
|
413
|
+
* `isDownloading` and `isUploading` are debounced ON by their delay and off at
|
|
414
|
+
* once, so a page that answers from cache and confirms with the server in a few
|
|
415
|
+
* milliseconds never flickers. Timers end with the injection context.
|
|
416
|
+
*/
|
|
417
|
+
declare function injectSyncActivity(options?: SyncActivityOptions): SyncActivity;
|
|
418
|
+
interface ImpersonationOptions extends InjectOptions {
|
|
419
|
+
/**
|
|
420
|
+
* This component renders the app's own impersonation banner. Required with
|
|
421
|
+
* `impersonationBanner: { mode: 'custom' }`: it acknowledges the banner, so
|
|
422
|
+
* the client does not fall back to its built-in one.
|
|
423
|
+
*/
|
|
424
|
+
rendersBanner?: boolean;
|
|
425
|
+
}
|
|
426
|
+
interface Impersonation {
|
|
427
|
+
/** The active impersonation, or `null`. */
|
|
428
|
+
readonly impersonation: Signal<ImpersonationInfo | null>;
|
|
429
|
+
readonly isImpersonating: Signal<boolean>;
|
|
430
|
+
/** Return to the admin session. */
|
|
431
|
+
stop: () => Promise<void>;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Observe admin impersonation (started from the DevTools). The client already
|
|
435
|
+
* shows its own warning bar with a Stop button; use this for anything extra,
|
|
436
|
+
* such as hiding actions an admin should not take on someone's behalf.
|
|
437
|
+
*/
|
|
438
|
+
declare function injectImpersonation(options?: ImpersonationOptions): Impersonation;
|
|
439
|
+
interface FeatureFlag {
|
|
440
|
+
/** Resolved variant (`options.fallback` when unassigned). */
|
|
441
|
+
readonly variant: Signal<string | undefined>;
|
|
442
|
+
readonly payload: Signal<unknown>;
|
|
443
|
+
/** The variant is set and not `'off'`. */
|
|
444
|
+
readonly enabled: Signal<boolean>;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* A feature flag for the signed-in user. Updates whenever the
|
|
448
|
+
* server-materialized assignment in `_00_user_feature` changes, so
|
|
449
|
+
* `spky flag enable <key>` reaches the UI without a refresh. The handle closes
|
|
450
|
+
* with the injection context.
|
|
451
|
+
*/
|
|
452
|
+
declare function injectFeatureFlag(key: string, options?: FeatureFlagOptions & InjectOptions): FeatureFlag;
|
|
453
|
+
interface AppReleaseConfig extends AppReleaseOptions, InjectOptions {
|
|
454
|
+
/** App name from sp00ky.yml, e.g. `web`. */
|
|
455
|
+
app: string;
|
|
456
|
+
/**
|
|
457
|
+
* The running build's version (X.Y.Z), typically baked in at build time
|
|
458
|
+
* (e.g. from package.json through an `environment` file).
|
|
459
|
+
*/
|
|
460
|
+
currentVersion: string;
|
|
461
|
+
}
|
|
462
|
+
interface AppRelease {
|
|
463
|
+
/** Latest announced version for the app, or undefined when no row exists. */
|
|
464
|
+
readonly latestVersion: Signal<string | undefined>;
|
|
465
|
+
/** Announced version is semver-newer than the running build. */
|
|
466
|
+
readonly updateAvailable: Signal<boolean>;
|
|
467
|
+
/** The newer release asks clients to update/reload without prompting. */
|
|
468
|
+
readonly mandatory: Signal<boolean>;
|
|
469
|
+
/** The newer release asks reloads to clear service-worker caches first. */
|
|
470
|
+
readonly cacheBust: Signal<boolean>;
|
|
471
|
+
/**
|
|
472
|
+
* Reload onto the announced release. Plain `location.reload()` normally;
|
|
473
|
+
* with cache-bust, CacheStorage is cleared, the service worker is nudged to
|
|
474
|
+
* update (never unregistered) and navigation carries a `?cb=` token.
|
|
475
|
+
*/
|
|
476
|
+
reload: () => Promise<void>;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Observe the app's announced release (`_00_app_release:<app>`, written by
|
|
480
|
+
* `spky deploy` / `spky release`) and compare it with the running build, for a
|
|
481
|
+
* "new version available, Reload" notice. Guard an automatic `reload()` on
|
|
482
|
+
* `mandatory` against loops with a per-version marker.
|
|
483
|
+
*/
|
|
484
|
+
declare function injectAppRelease(config: AppReleaseConfig): AppRelease;
|
|
485
|
+
interface Submission<Args extends unknown[], R> {
|
|
486
|
+
/** Run the wrapped async fn. Never rejects; a failure lands in `error`. */
|
|
487
|
+
submit: (...args: Args) => Promise<R | undefined>;
|
|
488
|
+
/** True while at least one submit is in flight. */
|
|
489
|
+
readonly pending: Signal<boolean>;
|
|
490
|
+
/** Error from the most recent settled submit, cleared on the next submit. */
|
|
491
|
+
readonly error: Signal<Error | undefined>;
|
|
492
|
+
/** Result of the most recent successful submit. */
|
|
493
|
+
readonly result: Signal<R | undefined>;
|
|
494
|
+
clearError: () => void;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Button pending / error state around a mutation. Deliberately no optimistic
|
|
498
|
+
* layer: the engine already commits writes locally and re-renders through live
|
|
499
|
+
* queries before it syncs. An `error` here means the LOCAL commit failed; sync
|
|
500
|
+
* failures surface through `injectSyncStatus` and `injectPendingMutations`.
|
|
501
|
+
* Needs no injection context: it only holds signals.
|
|
502
|
+
*/
|
|
503
|
+
declare function injectSubmission<Args extends unknown[], R>(fn: (...args: Args) => Promise<R>): Submission<Args, R>;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Open a `@crdt` field of the record `recordId` names, for an editor to bind
|
|
507
|
+
* to (`field()?.getDoc()`). Re-opens when the id changes, closes with the
|
|
508
|
+
* injection context. Pass the id as a signal (an `input()`) or a function to
|
|
509
|
+
* follow state.
|
|
510
|
+
*
|
|
511
|
+
* The signal stays `null` until the field is loaded (`CrdtField.isLoaded`):
|
|
512
|
+
* this device had the document, or the server answered. Until then show the
|
|
513
|
+
* column's text instead of binding an editor to a document still arriving.
|
|
514
|
+
*/
|
|
515
|
+
declare function injectCrdtField(table: string, recordId: MaybeSignal<string | null | undefined>, field: string, options?: InjectOptions): Signal<CrdtField | null>;
|
|
516
|
+
/** Who a channel connects to. */
|
|
517
|
+
type ChannelPeers = Iterable<ChannelPeer>;
|
|
518
|
+
/** What a channel carries: the rows a query (or several) matches. */
|
|
519
|
+
type ChannelQueries<S extends SchemaStructure, T extends ChannelTableNames<S>> = ChannelQuery<S, T> | ReadonlyArray<ChannelQuery<S, T>>;
|
|
520
|
+
/** An open channel, for as long as the injection context lives. */
|
|
521
|
+
interface ChannelRef<S extends SchemaStructure, T extends string> {
|
|
522
|
+
/** `idle` | `connecting` | `connected` | `failed` | `unsupported`. */
|
|
523
|
+
readonly status: Signal<ChannelStatus>;
|
|
524
|
+
/** Users with a tab connected. */
|
|
525
|
+
readonly peers: Signal<ReadonlyArray<string>>;
|
|
526
|
+
/** Writes that go to THIS channel's peers only (when the row matches its query), plus the database as always. */
|
|
527
|
+
update: Sp00kyChannel<S, T>['update'];
|
|
528
|
+
create: Sp00kyChannel<S, T>['create'];
|
|
529
|
+
delete: Sp00kyChannel<S, T>['delete'];
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Open a peer to peer channel to `peers` for the rows `query` matches, for the
|
|
533
|
+
* lifetime of the injection context. The query must be on a `-- @channel`
|
|
534
|
+
* table and only its `where` counts; it is checked against each row, never
|
|
535
|
+
* registered. Writes to matching rows (`db.update` / `db.create` /
|
|
536
|
+
* `db.delete`, or the channel's own) reach the peers over WebRTC in tens of
|
|
537
|
+
* ms; `-- @ephemeral` fields travel only this way. A connection forms when both
|
|
538
|
+
* sides list each other; your own id is skipped.
|
|
539
|
+
*
|
|
540
|
+
* ```ts
|
|
541
|
+
* readonly channel = injectChannel(
|
|
542
|
+
* () => this.db.query('message').where({ conversation: this.convoId() }),
|
|
543
|
+
* () => [this.me(), this.other()]
|
|
544
|
+
* );
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* Both arguments may be signals or functions and are compared by value, so
|
|
548
|
+
* rebuilding them is free. A `null` query closes the channel until a query
|
|
549
|
+
* comes back.
|
|
550
|
+
*/
|
|
551
|
+
declare function injectChannel<S extends SchemaStructure, T extends ChannelTableNames<S>>(query: MaybeSignal<ChannelQueries<S, T> | null | undefined>, peers: MaybeSignal<ChannelPeers | null | undefined>, options?: InjectOptions): ChannelRef<S, T>;
|
|
552
|
+
|
|
553
|
+
type PathArg = MaybeSignal<string | null | undefined>;
|
|
554
|
+
interface FileUpload {
|
|
555
|
+
readonly isUploading: Signal<boolean>;
|
|
556
|
+
readonly error: Signal<Error | null>;
|
|
557
|
+
clearError: () => void;
|
|
558
|
+
/** Validates against the bucket's `maxSize` / `allowedExtensions` first. */
|
|
559
|
+
upload: (path: string, file: File | Blob, options?: BucketPutOptions) => Promise<BucketPutResult | void>;
|
|
560
|
+
/** An object URL for the file (revoked with the injection context), or `null`. */
|
|
561
|
+
download: (path: string) => Promise<string | null>;
|
|
562
|
+
remove: (path: string) => Promise<void>;
|
|
563
|
+
exists: (path: string) => Promise<boolean>;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Upload, download, remove and probe files in a bucket, with `isUploading`
|
|
567
|
+
* and `error` signals. `bucket` may be a signal; it is read on each call.
|
|
568
|
+
*/
|
|
569
|
+
declare function injectFileUpload<S extends SchemaStructure = any>(bucket: MaybeSignal<BucketNames<S>>, options?: InjectOptions): FileUpload;
|
|
570
|
+
interface DownloadFileOptions extends InjectOptions {
|
|
571
|
+
/**
|
|
572
|
+
* Master switch, default `true`. `false` gives every caller its own private
|
|
573
|
+
* object URL fetched fresh from the bucket and revoked with its context: no
|
|
574
|
+
* sharing, no persistence, no reuse.
|
|
575
|
+
*/
|
|
576
|
+
cache?: boolean;
|
|
577
|
+
/**
|
|
578
|
+
* Keep the bytes in OPFS so they survive a reload and are available offline.
|
|
579
|
+
* Default `true`. The in-tab object URL is still shared between components
|
|
580
|
+
* rendering the same path either way.
|
|
581
|
+
*/
|
|
582
|
+
persist?: boolean;
|
|
583
|
+
/** Exempt this file from pressure eviction. Pinned bytes never expire. */
|
|
584
|
+
pin?: boolean;
|
|
585
|
+
/**
|
|
586
|
+
* `'never'` (default) treats a bucket path as immutable, which is how paths
|
|
587
|
+
* are written (`crypto.randomUUID() + ext`). `'head'` spends a remote `head()`
|
|
588
|
+
* to compare sizes before trusting the cached copy, for paths the app
|
|
589
|
+
* overwrites in place.
|
|
590
|
+
*/
|
|
591
|
+
revalidate?: 'never' | 'head';
|
|
592
|
+
}
|
|
593
|
+
interface DownloadFile {
|
|
594
|
+
/** Object URL for the file, `null` while none is resolved (or no path). */
|
|
595
|
+
readonly url: Signal<string | null>;
|
|
596
|
+
readonly isLoading: Signal<boolean>;
|
|
597
|
+
readonly error: Signal<Error | null>;
|
|
598
|
+
/** Bypass every cache layer once and fetch again. */
|
|
599
|
+
refetch: () => void;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* An object URL for a bucket file that follows `path` (a signal or function).
|
|
603
|
+
* Cached URLs are refcounted and shared between every component showing the
|
|
604
|
+
* same path; the previous URL stays valid until the next one is ready, so an
|
|
605
|
+
* `<img>` never flashes broken on a path change.
|
|
606
|
+
*/
|
|
607
|
+
declare function injectDownloadFile<S extends SchemaStructure = any>(bucket: MaybeSignal<BucketNames<S>>, path: PathArg, options?: DownloadFileOptions): DownloadFile;
|
|
608
|
+
interface BlurhashResult {
|
|
609
|
+
/** The stored blurhash for the path, `null` while loading or when none exists. */
|
|
610
|
+
readonly hash: Signal<string | null>;
|
|
611
|
+
readonly isLoading: Signal<boolean>;
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* The blurhash sidecar for a bucket image (written by `bucket.put`, see
|
|
615
|
+
* `Sp00kyConfig.blurhash`). Resolves from OPFS instantly on warm clients; a
|
|
616
|
+
* miss is remembered per tab. `injectBucketImage` / `<sp00ky-bucket-image>`
|
|
617
|
+
* bundle it with the download; use this when the hash belongs to another
|
|
618
|
+
* rendition.
|
|
619
|
+
*/
|
|
620
|
+
declare function injectBlurhash<S extends SchemaStructure = any>(bucket: MaybeSignal<BucketNames<S>>, path: PathArg, options?: InjectOptions): BlurhashResult;
|
|
621
|
+
interface BucketImageOptions extends DownloadFileOptions {
|
|
622
|
+
/**
|
|
623
|
+
* Also resolve the image's blurhash sidecar (see `Sp00kyConfig.blurhash`).
|
|
624
|
+
* Default `true`; read before the bytes, so the tiny sidecar tends to land
|
|
625
|
+
* first on the serialized remote chain.
|
|
626
|
+
*/
|
|
627
|
+
blurhash?: boolean;
|
|
628
|
+
}
|
|
629
|
+
interface BucketImageRef extends DownloadFile {
|
|
630
|
+
/** Blurhash for the same path, or `null` (off, missing, still loading). */
|
|
631
|
+
readonly blurhash: Signal<string | null>;
|
|
632
|
+
/** True once the current `url` has been decoded and is safe to paint. */
|
|
633
|
+
readonly ready: Signal<boolean>;
|
|
634
|
+
/**
|
|
635
|
+
* Drive an `<img>`: set its `src` to `url` and flip `ready` once that bitmap
|
|
636
|
+
* is DECODED (failures count too, so a broken blob degrades to
|
|
637
|
+
* paint-on-load instead of hiding forever). Reads `url`, so call it inside
|
|
638
|
+
* an effect to re-arm on every new url; returns that run's cleanup. The
|
|
639
|
+
* `sp00kyImageGate` directive does exactly this: prefer it.
|
|
640
|
+
*/
|
|
641
|
+
gate: (img: HTMLImageElement) => () => void;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Everything needed to render a bucket image without a pop-in: the refcounted
|
|
645
|
+
* object URL, the blurhash placeholder, and a decode gate so the bitmap is only
|
|
646
|
+
* revealed once it can paint in full. `<sp00ky-bucket-image>` wraps it; use
|
|
647
|
+
* this with `<img [sp00kyImageGate]="image">` for custom markup.
|
|
648
|
+
*/
|
|
649
|
+
declare function injectBucketImage<S extends SchemaStructure = any>(bucket: MaybeSignal<BucketNames<S>>, path: PathArg, options?: BucketImageOptions): BucketImageRef;
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Paints a blurhash onto the host `<canvas>`:
|
|
653
|
+
* `<canvas [sp00kyBlurhash]="hash" class="absolute inset-0 h-full w-full"></canvas>`.
|
|
654
|
+
*
|
|
655
|
+
* Size the canvas with CSS; the decode resolution stays tiny (32x32 is plenty:
|
|
656
|
+
* a blurhash carries at most 9x9 DCT components). Repaints once per hash (or
|
|
657
|
+
* size) change, after render, and never during a server render.
|
|
658
|
+
*/
|
|
659
|
+
declare class Blurhash {
|
|
660
|
+
/** The blurhash string. Nullish paints nothing (a transparent canvas). */
|
|
661
|
+
readonly hash: _angular_core.InputSignal<string | null | undefined>;
|
|
662
|
+
/** Decode width in pixels. Defaults to 32. */
|
|
663
|
+
readonly blurhashWidth: _angular_core.InputSignal<number>;
|
|
664
|
+
/** Decode height in pixels. Defaults to 32. */
|
|
665
|
+
readonly blurhashHeight: _angular_core.InputSignal<number>;
|
|
666
|
+
/** Contrast punch, see the blurhash reference decoder. Defaults to 1. */
|
|
667
|
+
readonly blurhashPunch: _angular_core.InputSignal<number>;
|
|
668
|
+
constructor();
|
|
669
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<Blurhash, never>;
|
|
670
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<Blurhash, "canvas[sp00kyBlurhash]", never, { "hash": { "alias": "sp00kyBlurhash"; "required": false; "isSignal": true; }; "blurhashWidth": { "alias": "blurhashWidth"; "required": false; "isSignal": true; }; "blurhashHeight": { "alias": "blurhashHeight"; "required": false; "isSignal": true; }; "blurhashPunch": { "alias": "blurhashPunch"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Wires an `<img>` to `injectBucketImage`: sets `src` to the image's url and
|
|
675
|
+
* flips its `ready` signal once the bitmap is decoded, re-arming on every new
|
|
676
|
+
* url. Do not also bind `src`.
|
|
677
|
+
*
|
|
678
|
+
* ```html
|
|
679
|
+
* <img [sp00kyImageGate]="cover" alt="" [style.opacity]="cover.ready() ? 1 : 0" />
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
declare class ImageGate {
|
|
683
|
+
/** The result of `injectBucketImage(...)`. */
|
|
684
|
+
readonly image: _angular_core.InputSignal<BucketImageRef>;
|
|
685
|
+
constructor();
|
|
686
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ImageGate, never>;
|
|
687
|
+
static ɵdir: _angular_core.ɵɵDirectiveDeclaration<ImageGate, "img[sp00kyImageGate]", never, { "image": { "alias": "sp00kyImageGate"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* A bucket image that never pops in. Bottom to top: the projected content (your
|
|
692
|
+
* own plate or skeleton), the stored blurhash, and the real image, which stays
|
|
693
|
+
* transparent until its bitmap is DECODED and then crossfades over the
|
|
694
|
+
* placeholders. The placeholders leave the DOM once the fade is over and come
|
|
695
|
+
* back when the path changes.
|
|
696
|
+
*
|
|
697
|
+
* ```html
|
|
698
|
+
* <sp00ky-bucket-image bucket="avatars" [path]="avatar()" class="h-12 w-12 rounded-full">
|
|
699
|
+
* <div class="h-full w-full bg-neutral-200"></div>
|
|
700
|
+
* </sp00ky-bucket-image>
|
|
701
|
+
* ```
|
|
702
|
+
*
|
|
703
|
+
* The host is the container: size and position it with `class` / `style`. It
|
|
704
|
+
* becomes `display: block` and `position: relative` unless you set otherwise.
|
|
705
|
+
*/
|
|
706
|
+
declare class BucketImage {
|
|
707
|
+
/** Bucket name from the schema. */
|
|
708
|
+
readonly bucket: _angular_core.InputSignal<string>;
|
|
709
|
+
/** Path within the bucket. Nullish renders only the placeholder layers. */
|
|
710
|
+
readonly path: _angular_core.InputSignal<string | null | undefined>;
|
|
711
|
+
readonly alt: _angular_core.InputSignal<string>;
|
|
712
|
+
/** Classes for the inner `<img>` (the layout styles are inline). */
|
|
713
|
+
readonly imgClass: _angular_core.InputSignal<string | undefined>;
|
|
714
|
+
/** `object-fit` for the image. Defaults to `cover`. */
|
|
715
|
+
readonly fit: _angular_core.InputSignal<"fill" | "cover" | "contain" | "none" | "scale-down">;
|
|
716
|
+
/** Crossfade duration in ms. Defaults to 300. */
|
|
717
|
+
readonly transition: _angular_core.InputSignal<number>;
|
|
718
|
+
/** Crossfade easing. Defaults to an ease-out-expo curve. */
|
|
719
|
+
readonly easing: _angular_core.InputSignal<string>;
|
|
720
|
+
/** Resolve the blurhash sidecar. Defaults to true. */
|
|
721
|
+
readonly blurhash: _angular_core.InputSignal<boolean>;
|
|
722
|
+
/** Download tuning, as for `injectDownloadFile`. Read when a fetch starts. */
|
|
723
|
+
readonly options: _angular_core.InputSignal<BucketImageOptions | undefined>;
|
|
724
|
+
protected readonly layer = "position:absolute;inset:0;width:100%;height:100%;";
|
|
725
|
+
protected readonly image: _spooky_sync_client_angular.BucketImageRef;
|
|
726
|
+
protected readonly settled: _angular_core.WritableSignal<boolean>;
|
|
727
|
+
private readonly reducedMotion;
|
|
728
|
+
protected readonly imgStyle: _angular_core.Signal<string>;
|
|
729
|
+
constructor();
|
|
730
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<BucketImage, never>;
|
|
731
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<BucketImage, "sp00ky-bucket-image", never, { "bucket": { "alias": "bucket"; "required": true; "isSignal": true; }; "path": { "alias": "path"; "required": false; "isSignal": true; }; "alt": { "alias": "alt"; "required": false; "isSignal": true; }; "imgClass": { "alias": "imgClass"; "required": false; "isSignal": true; }; "fit": { "alias": "fit"; "required": false; "isSignal": true; }; "transition": { "alias": "transition"; "required": false; "isSignal": true; }; "easing": { "alias": "easing"; "required": false; "isSignal": true; }; "blurhash": { "alias": "blurhash"; "required": false; "isSignal": true; }; "options": { "alias": "options"; "required": false; "isSignal": true; }; }, {}, never, ["*"], true, never>;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
type RelationshipField<Schema extends SchemaStructure, TableName extends TableNames<Schema>, Field extends RelationshipFieldsFromSchema<Schema, TableName>> = GetRelationship<Schema, TableName, Field>;
|
|
735
|
+
type RelatedFieldsTableScoped<Schema extends SchemaStructure, TableName extends TableNames<Schema>, RelatedFields extends RelationshipFieldsFromSchema<Schema, TableName> = RelationshipFieldsFromSchema<Schema, TableName>> = {
|
|
736
|
+
[K in RelatedFields]: {
|
|
737
|
+
to: RelationshipField<Schema, TableName, K>['to'];
|
|
738
|
+
relatedFields: RelatedFieldsMap;
|
|
739
|
+
cardinality: RelationshipField<Schema, TableName, K>['cardinality'];
|
|
740
|
+
};
|
|
741
|
+
};
|
|
742
|
+
type InferModel<Schema extends SchemaStructure, TableName extends TableNames<Schema>, RelatedFields extends RelatedFieldsTableScoped<Schema, TableName>> = QueryResult<Schema, TableName, RelatedFields, true>;
|
|
743
|
+
type WithRelated<Field extends string, RelatedFields extends RelatedFieldsMap = {}> = {
|
|
744
|
+
[K in Field]: Omit<RelatedFieldMapEntry, 'relatedFields'> & {
|
|
745
|
+
relatedFields: RelatedFields;
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
type WithRelatedMany<Field extends string, RelatedFields extends RelatedFieldsMap = {}> = {
|
|
749
|
+
[K in Field]: {
|
|
750
|
+
to: Field;
|
|
751
|
+
relatedFields: RelatedFields;
|
|
752
|
+
cardinality: 'many';
|
|
753
|
+
};
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
export { Blurhash, BucketImage, ImageGate, SyncedDb, injectAppRelease, injectBlurhash, injectBucketImage, injectChannel, injectCrdtField, injectDb, injectDownloadFile, injectFeatureFlag, injectFileUpload, injectImpersonation, injectPendingMutations, injectPreload, injectQuery, injectStorageStatus, injectSubmission, injectSyncActivity, injectSyncStatus, provideSp00ky, sameValue, share };
|
|
757
|
+
export type { AppRelease, AppReleaseConfig, BlurhashResult, BucketImageOptions, BucketImageRef, CacheStrategy, ChannelPeers, ChannelQueries, ChannelRef, DownloadFile, DownloadFileOptions, FeatureFlag, FileUpload, Impersonation, ImpersonationOptions, InferModel, InferRelationshipsFromConst, InferSchemaFromConst, InjectOptions, MaybeSignal, Model, ModelPayload, PreloadOptions, ProvisionOptions, QueryData, QueryOptions, QueryState, RelatedFieldsTableScoped, RelationshipField, Sp00kyOptions, StorageStatus, Submission, SyncActivity, SyncActivityOptions, SyncStatus, SyncedDbConfig, WithRelated, WithRelatedMany };
|
|
758
|
+
//# sourceMappingURL=spooky-sync-client-angular.d.ts.map
|