@hulla/db-solid 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samuel Hulla
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,3 +1,58 @@
1
- # Temporary Holding Version
1
+ # @hulla/db-solid
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ```sh
4
+ npm install @hulla/db@0.1.0 @hulla/db-solid@0.1.0 solid-js
5
+ ```
6
+
7
+ Solid bindings for generated Hulla functions. Install alongside `@hulla/db` and
8
+ `solid-js`, then set `database.client` before generation.
9
+
10
+ ```tsx
11
+ import { createQuery, createMutation } from "@hulla/db-solid";
12
+ import { list, save as saveProject } from "./db/_generated/client/projects";
13
+
14
+ function Projects(props: { projectId: string }) {
15
+ const projects = createQuery(list, () => ({ projectId: props.projectId }));
16
+ const save = createMutation(saveProject);
17
+ // await save({ projectId: props.projectId, title: "New title" });
18
+ // save.state().status is idle, pending, recovering, success or error.
19
+ return <pre>{JSON.stringify(projects().data)}</pre>;
20
+ }
21
+ ```
22
+
23
+ Call bindings in a component owner. `createQuery` returns an accessor containing
24
+ the complete query snapshot. Getter inputs follow Solid signals; equivalent
25
+ encoded inputs keep the current subscription. Observation starts after mount and
26
+ stops with owner cleanup. No-input queries accept options as their second argument.
27
+ The core database runtime owns caching, authorization and subscriptions.
28
+
29
+ For SSR, await direct server `db` operations in the application loader,
30
+ then supply the request's result as `initialData` with identical input and seed
31
+ on server and client. The seed appears as stale pending data until live data
32
+ arrives. Authenticated seeds also need `initialAuthKey` matching the local key
33
+ supplied to generated `setAuth` for that account. Input or identity changes retire the
34
+ seed. Server bindings never subscribe or issue reads.
35
+
36
+ ```ts
37
+ const projects = createQuery(list, () => ({ projectId: props.projectId }), {
38
+ initialData: props.initialProjects,
39
+ initialAuthKey: props.authKey,
40
+ });
41
+ ```
42
+
43
+ `createMutation` returns a callable mutation with a `.state` accessor. Each call
44
+ returns its original awaitable mutation handle; the state tracks the most recently
45
+ started call. No provider or additional client is needed.
46
+
47
+ ## Live pagination
48
+
49
+ Use `createPaginatedQuery(query, cursor => ({ limit: 20, cursor }))` for a generated
50
+ query that directly returns `Page<Row>`. Read the flattened rows through
51
+ `tasks().data` and append pages with `tasks.next()` or `tasks.next(3)`.
52
+ Changing reactive filters resets all loaded pages; unmounting releases them.
53
+ The optional third argument accepts flattened `initialData`, `initialAuthKey`
54
+ and the ordinary error-retention option. See the
55
+ [pagination guide](https://github.com/hulladev/db/blob/main/docs/framework-bindings.md#load-more-pages-in-a-component).
56
+
57
+ For a complete server-rendered application, see the
58
+ [SolidStart recipe](https://github.com/hulladev/db/blob/main/docs/frameworks/solidstart.md).
@@ -0,0 +1,15 @@
1
+ import { type Accessor } from "solid-js";
2
+ import { type MutationArguments, type MutationBindingState, type MutationFunction, type PaginatedQueryFunction, type PageRow, type PaginationBindingOptions, type PaginationSnapshot, type QueryArguments, type QueryBindingOptions, type QueryFunction } from "@hulla/db/bindings";
3
+ import type { Input, MutationHandle, Output, QueryState } from "@hulla/db";
4
+ export type ReactiveQueryArguments<Q extends QueryFunction> = [Input<Q>] extends [undefined] ? QueryArguments<Q> : [input: Input<Q> | Accessor<Input<Q>>, options?: QueryBindingOptions<NoInfer<Output<Q>>>];
5
+ /** Call in a component owner. Live observation starts after mount. */
6
+ export declare function createQuery<Q extends QueryFunction>(query: Q, ...args: ReactiveQueryArguments<Q>): Accessor<QueryState<Output<Q>>>;
7
+ export type PaginatedQueryResult<Q extends PaginatedQueryFunction> = Accessor<PaginationSnapshot<PageRow<Q>>> & {
8
+ readonly next: PaginationSnapshot<PageRow<Q>>["next"];
9
+ };
10
+ /** Call in a component owner. The mapper reads reactive filters and supplies the page cursor. */
11
+ export declare function createPaginatedQuery<Q extends PaginatedQueryFunction>(query: Q, mapper: (cursor: string | null) => Input<Q>, options?: PaginationBindingOptions<NoInfer<PageRow<Q>>>): PaginatedQueryResult<Q>;
12
+ export type MutationResult<M extends MutationFunction> = ((...args: MutationArguments<M>) => MutationHandle<Output<M>>) & {
13
+ readonly state: Accessor<MutationBindingState<Output<M>>>;
14
+ };
15
+ export declare function createMutation<M extends MutationFunction>(mutation: M): MutationResult<M>;
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ import { createEffect, createSignal, onCleanup, onMount, untrack } from "solid-js";
2
+ import { createMutationObserver, createPaginationObserver, createQueryObserver, queryArguments, queryKey, } from "@hulla/db/bindings";
3
+ /** Call in a component owner. Live observation starts after mount. */
4
+ export function createQuery(query, ...args) {
5
+ const { input: source, options } = queryArguments(query, args);
6
+ const readInput = () => typeof source === "function" ? source() : source;
7
+ const { initialData: _initialData, initialAuthKey: _initialAuthKey, ...liveOptions } = options;
8
+ const observe = (input, seed) => {
9
+ const resolved = [...args];
10
+ if (source !== undefined) {
11
+ resolved[0] = input;
12
+ resolved[1] = seed ? options : liveOptions;
13
+ }
14
+ return createQueryObserver(query, ...resolved);
15
+ };
16
+ let key = queryKey(query, readInput());
17
+ let observer = observe(readInput(), true);
18
+ const [state, setState] = createSignal(observer.getServerSnapshot());
19
+ let stop;
20
+ onMount(() => {
21
+ createEffect(() => {
22
+ const input = readInput();
23
+ const nextKey = queryKey(query, input);
24
+ untrack(() => {
25
+ if (nextKey !== key) {
26
+ stop?.();
27
+ key = nextKey;
28
+ observer = observe(input, false);
29
+ }
30
+ else if (stop)
31
+ return;
32
+ setState(() => observer.getSnapshot());
33
+ stop = observer.subscribe(() => setState(() => observer.getSnapshot()));
34
+ setState(() => observer.getSnapshot());
35
+ });
36
+ });
37
+ });
38
+ onCleanup(() => stop?.());
39
+ return state;
40
+ }
41
+ /** Call in a component owner. The mapper reads reactive filters and supplies the page cursor. */
42
+ export function createPaginatedQuery(query, mapper, options = {}) {
43
+ const { initialData: _initialData, initialAuthKey: _initialAuthKey, ...liveOptions } = options;
44
+ let key = queryKey(query, mapper(null));
45
+ let observer = createPaginationObserver(query, mapper, options);
46
+ const [state, setState] = createSignal(observer.getServerSnapshot());
47
+ let stop;
48
+ onMount(() => {
49
+ createEffect(() => {
50
+ const nextKey = queryKey(query, mapper(null));
51
+ untrack(() => {
52
+ if (nextKey !== key) {
53
+ stop?.();
54
+ key = nextKey;
55
+ observer = createPaginationObserver(query, mapper, liveOptions);
56
+ }
57
+ else if (stop)
58
+ return;
59
+ setState(() => observer.getSnapshot());
60
+ stop = observer.subscribe(() => setState(() => observer.getSnapshot()));
61
+ setState(() => observer.getSnapshot());
62
+ });
63
+ });
64
+ });
65
+ onCleanup(() => stop?.());
66
+ return Object.assign(state, { next: (pages) => observer.getSnapshot().next(pages) });
67
+ }
68
+ export function createMutation(mutation) {
69
+ const observer = createMutationObserver(mutation);
70
+ const [state, setState] = createSignal(observer.getServerSnapshot());
71
+ let stop;
72
+ onMount(() => {
73
+ stop = observer.subscribe(() => setState(() => observer.getSnapshot()));
74
+ setState(() => observer.getSnapshot());
75
+ });
76
+ onCleanup(() => stop?.());
77
+ return Object.assign((...args) => observer.invoke(...args), { state });
78
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@hulla/db-solid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "default": "./dist/index.js"
9
+ }
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "peerDependencies": {
17
+ "@hulla/db": "^0.1.1",
18
+ "solid-js": "^1.9.0"
19
+ },
20
+ "engines": {
21
+ "node": ">=22.18.0"
22
+ },
23
+ "description": "Solid primitives for @hulla/db reactive queries and mutations",
24
+ "license": "MIT",
25
+ "author": {
26
+ "name": "Samuel Hulla",
27
+ "url": "https://hulla.dev"
28
+ },
29
+ "homepage": "https://github.com/hulladev/db#readme",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/hulladev/db.git",
33
+ "directory": "packages/solid"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/hulladev/db/issues"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org/"
41
+ }
42
+ }