@noy-db/in-tanstack-query 0.2.0-pre.9 → 0.3.0-pre.2

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/README.md CHANGED
@@ -26,7 +26,7 @@ See the [main repository](https://github.com/vLannaAi/noy-db#readme) for setup,
26
26
 
27
27
  - Source — [`packages/in-tanstack-query`](https://github.com/vLannaAi/noy-db/tree/main/packages/in-tanstack-query)
28
28
  - Issues — [github.com/vLannaAi/noy-db/issues](https://github.com/vLannaAi/noy-db/issues)
29
- - Spec — [`SPEC.md`](https://github.com/vLannaAi/noy-db/blob/main/SPEC.md)
29
+ - Spec — [`SPEC.md`](https://github.com/vLannaAi/noy-db-docs/blob/main/SPEC.md)
30
30
 
31
31
  ## License
32
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noy-db/in-tanstack-query",
3
- "version": "0.2.0-pre.9",
3
+ "version": "0.3.0-pre.2",
4
4
  "description": "TanStack Query adapter for noy-db — queryFn + mutationFn helpers that speak the Collection API, plus automatic invalidation from noy-db change events. Framework-agnostic (React / Vue / Solid / Svelte).",
5
5
  "license": "MIT",
6
6
  "author": "vLannaAi <vicio@lanna.ai>",
@@ -17,17 +17,10 @@
17
17
  "sideEffects": false,
18
18
  "exports": {
19
19
  ".": {
20
- "import": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
23
- },
24
- "require": {
25
- "types": "./dist/index.d.cts",
26
- "default": "./dist/index.cjs"
27
- }
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
28
22
  }
29
23
  },
30
- "main": "./dist/index.cjs",
31
24
  "module": "./dist/index.js",
32
25
  "types": "./dist/index.d.ts",
33
26
  "files": [
@@ -36,15 +29,15 @@
36
29
  "LICENSE"
37
30
  ],
38
31
  "engines": {
39
- "node": ">=18.0.0"
32
+ "node": ">=22.0.0"
40
33
  },
41
34
  "peerDependencies": {
42
35
  "@tanstack/query-core": "^5.0.0",
43
- "@noy-db/hub": "0.2.0-pre.9"
36
+ "@noy-db/hub": "0.3.0-pre.2"
44
37
  },
45
38
  "devDependencies": {
46
39
  "@tanstack/query-core": "^5.59.0",
47
- "@noy-db/hub": "0.2.0-pre.9"
40
+ "@noy-db/hub": "0.3.0-pre.2"
48
41
  },
49
42
  "keywords": [
50
43
  "noy-db",
package/dist/index.cjs DELETED
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- bindInvalidation: () => bindInvalidation,
24
- collectionDeleteOptions: () => collectionDeleteOptions,
25
- collectionGetOptions: () => collectionGetOptions,
26
- collectionListOptions: () => collectionListOptions,
27
- collectionPutOptions: () => collectionPutOptions,
28
- collectionQueryKey: () => collectionQueryKey,
29
- collectionQueryOptions: () => collectionQueryOptions
30
- });
31
- module.exports = __toCommonJS(index_exports);
32
- function collectionQueryKey(vault, collection, ...extra) {
33
- return ["noy-db", vault, collection, ...extra];
34
- }
35
- function collectionListOptions(vault, collectionName, getCollection) {
36
- return {
37
- queryKey: collectionQueryKey(vault, collectionName, "list"),
38
- queryFn: async () => {
39
- const coll = getCollection();
40
- return coll.list();
41
- }
42
- };
43
- }
44
- function collectionGetOptions(vault, collectionName, id, getCollection) {
45
- return {
46
- queryKey: collectionQueryKey(vault, collectionName, "get", id),
47
- queryFn: async () => {
48
- const coll = getCollection();
49
- return coll.get(id);
50
- }
51
- };
52
- }
53
- function collectionQueryOptions(vault, collectionName, getCollection, builder, keyTag = "query") {
54
- return {
55
- queryKey: collectionQueryKey(vault, collectionName, keyTag),
56
- queryFn: async () => {
57
- const coll = getCollection();
58
- return Promise.resolve(builder(coll.query()));
59
- }
60
- };
61
- }
62
- function collectionPutOptions(getCollection) {
63
- return {
64
- mutationFn: async ({ id, record }) => {
65
- const coll = getCollection();
66
- await coll.put(id, record);
67
- }
68
- };
69
- }
70
- function collectionDeleteOptions(getCollection) {
71
- return {
72
- mutationFn: async ({ id }) => {
73
- const coll = getCollection();
74
- await coll.delete(id);
75
- }
76
- };
77
- }
78
- function bindInvalidation(queryClient, vault, collectionName, collection) {
79
- return collection.subscribe(() => {
80
- void queryClient.invalidateQueries({
81
- queryKey: collectionQueryKey(vault, collectionName)
82
- });
83
- });
84
- }
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {
87
- bindInvalidation,
88
- collectionDeleteOptions,
89
- collectionGetOptions,
90
- collectionListOptions,
91
- collectionPutOptions,
92
- collectionQueryKey,
93
- collectionQueryOptions
94
- });
95
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * **@noy-db/in-tanstack-query** — TanStack Query adapter for noy-db.\n *\n * Three framework-agnostic pieces:\n *\n * 1. **{@link collectionQueryOptions}** — returns a\n * `{ queryKey, queryFn }` pair ready to hand to `useQuery()` in\n * any TanStack-supported framework (React, Vue, Solid, Svelte).\n *\n * 2. **{@link collectionMutationOptions}** — same shape for\n * `useMutation()`, with `put`/`delete` actions against a\n * `Collection`.\n *\n * 3. **{@link bindInvalidation}** — subscribes to a `Collection`'s\n * change stream and invalidates the matching query keys on every\n * mutation. Drop-in replacement for ad-hoc `invalidateQueries`\n * calls scattered through mutation callbacks.\n *\n * Keeping these as option-factories (not custom hooks) means the\n * same code works across every TanStack framework binding — no\n * framework-specific exports needed.\n *\n * @packageDocumentation\n */\n\nimport type { Collection, Query } from '@noy-db/hub'\nimport type { QueryClient } from '@tanstack/query-core'\n\n/** The canonical TanStack queryKey shape for a collection scope. */\nexport type CollectionQueryKey =\n | readonly ['noy-db', string, string]\n | readonly ['noy-db', string, string, string]\n | readonly ['noy-db', string, string, ...unknown[]]\n\nexport function collectionQueryKey(vault: string, collection: string, ...extra: unknown[]): CollectionQueryKey {\n return ['noy-db', vault, collection, ...extra] as CollectionQueryKey\n}\n\n/**\n * Build `{ queryKey, queryFn }` for a Collection list query. Pass the\n * returned object directly into `useQuery(options)` — works across\n * every TanStack framework binding.\n */\nexport function collectionListOptions<T>(\n vault: string,\n collectionName: string,\n getCollection: () => Collection<T>,\n): { queryKey: CollectionQueryKey; queryFn: () => Promise<T[]> } {\n return {\n queryKey: collectionQueryKey(vault, collectionName, 'list'),\n queryFn: async () => {\n const coll = getCollection()\n return coll.list()\n },\n }\n}\n\n/**\n * Build `{ queryKey, queryFn }` for a single-record query. Returns\n * `null` when the record is absent.\n */\nexport function collectionGetOptions<T>(\n vault: string,\n collectionName: string,\n id: string,\n getCollection: () => Collection<T>,\n): { queryKey: CollectionQueryKey; queryFn: () => Promise<T | null> } {\n return {\n queryKey: collectionQueryKey(vault, collectionName, 'get', id),\n queryFn: async () => {\n const coll = getCollection()\n return coll.get(id)\n },\n }\n}\n\n/**\n * Build `{ queryKey, queryFn }` for an arbitrary query builder. The\n * builder receives the collection's `query()` chain and returns a\n * terminal result (`.toArray()`, `.count()`, `.aggregate({...})`, …).\n */\nexport function collectionQueryOptions<T, R>(\n vault: string,\n collectionName: string,\n getCollection: () => Collection<T>,\n builder: (q: Query<T>) => Promise<R> | R,\n keyTag: string = 'query',\n): { queryKey: CollectionQueryKey; queryFn: () => Promise<R> } {\n return {\n queryKey: collectionQueryKey(vault, collectionName, keyTag),\n queryFn: async () => {\n const coll = getCollection()\n return Promise.resolve(builder(coll.query() as unknown as Query<T>))\n },\n }\n}\n\n/**\n * Build `{ mutationFn }` for a record put. Caller's `onSuccess` is\n * where you'd usually call `invalidateQueries(collectionQueryKey(...))`\n * — or let {@link bindInvalidation} do it automatically.\n */\nexport function collectionPutOptions<T>(\n getCollection: () => Collection<T>,\n): { mutationFn: (args: { id: string; record: T }) => Promise<void> } {\n return {\n mutationFn: async ({ id, record }) => {\n const coll = getCollection()\n await coll.put(id, record)\n },\n }\n}\n\n/** Build `{ mutationFn }` for a record delete. */\nexport function collectionDeleteOptions<T>(\n getCollection: () => Collection<T>,\n): { mutationFn: (args: { id: string }) => Promise<void> } {\n return {\n mutationFn: async ({ id }) => {\n const coll = getCollection()\n await coll.delete(id)\n },\n }\n}\n\n/**\n * Subscribe to a Collection's change stream and invalidate the\n * corresponding query scope on every mutation. Returns an unsubscribe\n * function — call on cleanup (framework-specific).\n *\n * ```ts\n * const stop = bindInvalidation(queryClient, 'acme', 'invoices', invoices)\n * // … later, e.g. in React's useEffect cleanup:\n * stop()\n * ```\n */\nexport function bindInvalidation<T>(\n queryClient: QueryClient,\n vault: string,\n collectionName: string,\n collection: Collection<T>,\n): () => void {\n return collection.subscribe(() => {\n void queryClient.invalidateQueries({\n queryKey: collectionQueryKey(vault, collectionName),\n })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCO,SAAS,mBAAmB,OAAe,eAAuB,OAAsC;AAC7G,SAAO,CAAC,UAAU,OAAO,YAAY,GAAG,KAAK;AAC/C;AAOO,SAAS,sBACd,OACA,gBACA,eAC+D;AAC/D,SAAO;AAAA,IACL,UAAU,mBAAmB,OAAO,gBAAgB,MAAM;AAAA,IAC1D,SAAS,YAAY;AACnB,YAAM,OAAO,cAAc;AAC3B,aAAO,KAAK,KAAK;AAAA,IACnB;AAAA,EACF;AACF;AAMO,SAAS,qBACd,OACA,gBACA,IACA,eACoE;AACpE,SAAO;AAAA,IACL,UAAU,mBAAmB,OAAO,gBAAgB,OAAO,EAAE;AAAA,IAC7D,SAAS,YAAY;AACnB,YAAM,OAAO,cAAc;AAC3B,aAAO,KAAK,IAAI,EAAE;AAAA,IACpB;AAAA,EACF;AACF;AAOO,SAAS,uBACd,OACA,gBACA,eACA,SACA,SAAiB,SAC4C;AAC7D,SAAO;AAAA,IACL,UAAU,mBAAmB,OAAO,gBAAgB,MAAM;AAAA,IAC1D,SAAS,YAAY;AACnB,YAAM,OAAO,cAAc;AAC3B,aAAO,QAAQ,QAAQ,QAAQ,KAAK,MAAM,CAAwB,CAAC;AAAA,IACrE;AAAA,EACF;AACF;AAOO,SAAS,qBACd,eACoE;AACpE,SAAO;AAAA,IACL,YAAY,OAAO,EAAE,IAAI,OAAO,MAAM;AACpC,YAAM,OAAO,cAAc;AAC3B,YAAM,KAAK,IAAI,IAAI,MAAM;AAAA,IAC3B;AAAA,EACF;AACF;AAGO,SAAS,wBACd,eACyD;AACzD,SAAO;AAAA,IACL,YAAY,OAAO,EAAE,GAAG,MAAM;AAC5B,YAAM,OAAO,cAAc;AAC3B,YAAM,KAAK,OAAO,EAAE;AAAA,IACtB;AAAA,EACF;AACF;AAaO,SAAS,iBACd,aACA,OACA,gBACA,YACY;AACZ,SAAO,WAAW,UAAU,MAAM;AAChC,SAAK,YAAY,kBAAkB;AAAA,MACjC,UAAU,mBAAmB,OAAO,cAAc;AAAA,IACpD,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
package/dist/index.d.cts DELETED
@@ -1,88 +0,0 @@
1
- import { Collection, Query } from '@noy-db/hub';
2
- import { QueryClient } from '@tanstack/query-core';
3
-
4
- /**
5
- * **@noy-db/in-tanstack-query** — TanStack Query adapter for noy-db.
6
- *
7
- * Three framework-agnostic pieces:
8
- *
9
- * 1. **{@link collectionQueryOptions}** — returns a
10
- * `{ queryKey, queryFn }` pair ready to hand to `useQuery()` in
11
- * any TanStack-supported framework (React, Vue, Solid, Svelte).
12
- *
13
- * 2. **{@link collectionMutationOptions}** — same shape for
14
- * `useMutation()`, with `put`/`delete` actions against a
15
- * `Collection`.
16
- *
17
- * 3. **{@link bindInvalidation}** — subscribes to a `Collection`'s
18
- * change stream and invalidates the matching query keys on every
19
- * mutation. Drop-in replacement for ad-hoc `invalidateQueries`
20
- * calls scattered through mutation callbacks.
21
- *
22
- * Keeping these as option-factories (not custom hooks) means the
23
- * same code works across every TanStack framework binding — no
24
- * framework-specific exports needed.
25
- *
26
- * @packageDocumentation
27
- */
28
-
29
- /** The canonical TanStack queryKey shape for a collection scope. */
30
- type CollectionQueryKey = readonly ['noy-db', string, string] | readonly ['noy-db', string, string, string] | readonly ['noy-db', string, string, ...unknown[]];
31
- declare function collectionQueryKey(vault: string, collection: string, ...extra: unknown[]): CollectionQueryKey;
32
- /**
33
- * Build `{ queryKey, queryFn }` for a Collection list query. Pass the
34
- * returned object directly into `useQuery(options)` — works across
35
- * every TanStack framework binding.
36
- */
37
- declare function collectionListOptions<T>(vault: string, collectionName: string, getCollection: () => Collection<T>): {
38
- queryKey: CollectionQueryKey;
39
- queryFn: () => Promise<T[]>;
40
- };
41
- /**
42
- * Build `{ queryKey, queryFn }` for a single-record query. Returns
43
- * `null` when the record is absent.
44
- */
45
- declare function collectionGetOptions<T>(vault: string, collectionName: string, id: string, getCollection: () => Collection<T>): {
46
- queryKey: CollectionQueryKey;
47
- queryFn: () => Promise<T | null>;
48
- };
49
- /**
50
- * Build `{ queryKey, queryFn }` for an arbitrary query builder. The
51
- * builder receives the collection's `query()` chain and returns a
52
- * terminal result (`.toArray()`, `.count()`, `.aggregate({...})`, …).
53
- */
54
- declare function collectionQueryOptions<T, R>(vault: string, collectionName: string, getCollection: () => Collection<T>, builder: (q: Query<T>) => Promise<R> | R, keyTag?: string): {
55
- queryKey: CollectionQueryKey;
56
- queryFn: () => Promise<R>;
57
- };
58
- /**
59
- * Build `{ mutationFn }` for a record put. Caller's `onSuccess` is
60
- * where you'd usually call `invalidateQueries(collectionQueryKey(...))`
61
- * — or let {@link bindInvalidation} do it automatically.
62
- */
63
- declare function collectionPutOptions<T>(getCollection: () => Collection<T>): {
64
- mutationFn: (args: {
65
- id: string;
66
- record: T;
67
- }) => Promise<void>;
68
- };
69
- /** Build `{ mutationFn }` for a record delete. */
70
- declare function collectionDeleteOptions<T>(getCollection: () => Collection<T>): {
71
- mutationFn: (args: {
72
- id: string;
73
- }) => Promise<void>;
74
- };
75
- /**
76
- * Subscribe to a Collection's change stream and invalidate the
77
- * corresponding query scope on every mutation. Returns an unsubscribe
78
- * function — call on cleanup (framework-specific).
79
- *
80
- * ```ts
81
- * const stop = bindInvalidation(queryClient, 'acme', 'invoices', invoices)
82
- * // … later, e.g. in React's useEffect cleanup:
83
- * stop()
84
- * ```
85
- */
86
- declare function bindInvalidation<T>(queryClient: QueryClient, vault: string, collectionName: string, collection: Collection<T>): () => void;
87
-
88
- export { type CollectionQueryKey, bindInvalidation, collectionDeleteOptions, collectionGetOptions, collectionListOptions, collectionPutOptions, collectionQueryKey, collectionQueryOptions };