@bb-labs/convex-cache 0.0.1 → 0.0.3
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 +6 -6
- package/dist/cli/fns/dev.js +1 -0
- package/dist/cli/fns/fns/convex-runner.js +56 -55
- package/dist/cli/fns/fns/generate-z-schema/fns/load-convex.d.ts +1 -1
- package/dist/cli/fns/fns/generate-z-schema/fns/load-convex.js +4 -1
- package/dist/cli/fns/fns/generate-z-schema/generate.d.ts +1 -1
- package/dist/cli/fns/fns/generate-z-schema/utils/find-fn-ref.d.ts +1 -1
- package/dist/cli/lib/dir-watcher.js +53 -47
- package/dist/cli/lib/shell-runner.js +103 -102
- package/dist/convex-cache/adapters/next/fns/build-preloader.d.ts +4 -4
- package/dist/convex-cache/adapters/next/fns/preload-query.d.ts +4 -4
- package/dist/convex-cache/adapters/next/hooks/hooks.d.ts +5 -5
- package/dist/convex-cache/adapters/next/hooks/hooks.js +10 -4
- package/dist/convex-cache/adapters/next/lib/revalidate-query-cache.d.ts +5 -5
- package/dist/convex-cache/adapters/next/lib/revalidate-query-cache.js +2 -2
- package/dist/convex-cache/adapters/next/server-fns/preload-query.d.ts +4 -4
- package/dist/convex-cache/adapters/next/server-fns/preload-query.js +3 -3
- package/dist/convex-cache/adapters/next/types/preloaded.d.ts +4 -4
- package/dist/convex-cache/adapters/react/hooks/hooks.d.ts +3 -3
- package/dist/convex-cache/adapters/react/hooks/hooks.js +7 -1
- package/dist/convex-cache/adapters/react/provider/provider.js +1 -0
- package/dist/convex-cache/core/client-cache/helpers/hooks/use-client-cache.d.ts +1 -1
- package/dist/convex-cache/core/client-cache/helpers/hooks/use-client-cache.js +5 -3
- package/dist/convex-cache/core/client-cache/queries/paginated-query.d.ts +2 -2
- package/dist/convex-cache/core/client-cache/queries/paginated-query.js +2 -1
- package/dist/convex-cache/core/client-cache/queries/query.d.ts +2 -2
- package/dist/convex-cache/core/client-cache/queries/query.js +2 -1
- package/dist/convex-cache/core/server-cache/queries/paginated-query.d.ts +3 -3
- package/dist/convex-cache/core/server-cache/queries/paginated-query.js +11 -3
- package/dist/convex-cache/core/server-cache/queries/query.d.ts +3 -3
- package/dist/convex-cache/core/server-cache/queries/query.js +1 -1
- package/dist/convex-cache/core/types/types/paginated-query.d.ts +1 -1
- package/dist/convex-cache/core/types/types/query.d.ts +2 -2
- package/package.json +9 -16
package/README.md
CHANGED
|
@@ -33,9 +33,9 @@ The client cache stores query results in IndexedDb, enabling instant page loads.
|
|
|
33
33
|
|
|
34
34
|
<a aria-label="Client Cache Flowchart" href="https://github.com/bigbang-sdk/convex-cache">
|
|
35
35
|
<picture>
|
|
36
|
-
<source srcset="https://raw.githubusercontent.com/
|
|
37
|
-
<source srcset="https://raw.githubusercontent.com/
|
|
38
|
-
<img src="https://raw.githubusercontent.com/
|
|
36
|
+
<source srcset="https://raw.githubusercontent.com/beepbop-labs/libraries/refs/heads/main/packages/convex-cache/assets/flowchart/client-cache-dark.png" media="(prefers-color-scheme: dark)" />
|
|
37
|
+
<source srcset="https://raw.githubusercontent.com/beepbop-labs/libraries/refs/heads/main/packages/convex-cache/assets/flowchart/client-cache-light.png" media="(prefers-color-scheme: light)" />
|
|
38
|
+
<img src="https://raw.githubusercontent.com/beepbop-labs/libraries/refs/heads/main/packages/convex-cache/assets/flowchart/client-cache-light.png" alt="Client Cache Flowchart" referrerpolicy="no-referrer-when-downgrade" />
|
|
39
39
|
</picture>
|
|
40
40
|
</a>
|
|
41
41
|
|
|
@@ -60,9 +60,9 @@ The server cache (with Next.js) leverages Next.js's native caching system, integ
|
|
|
60
60
|
|
|
61
61
|
<a aria-label="Server Cache Flowchart" href="https://github.com/bigbang-sdk/convex-cache">
|
|
62
62
|
<picture>
|
|
63
|
-
<source srcset="https://raw.githubusercontent.com/
|
|
64
|
-
<source srcset="https://raw.githubusercontent.com/
|
|
65
|
-
<img src="https://raw.githubusercontent.com/
|
|
63
|
+
<source srcset="https://raw.githubusercontent.com/beepbop-labs/libraries/refs/heads/main/packages/convex-cache/assets/flowchart/server-cache-dark.png" media="(prefers-color-scheme: dark)" />
|
|
64
|
+
<source srcset="https://raw.githubusercontent.com/beepbop-labs/libraries/refs/heads/main/packages/convex-cache/assets/flowchart/server-cache-light.png" media="(prefers-color-scheme: light)" />
|
|
65
|
+
<img src="https://raw.githubusercontent.com/beepbop-labs/libraries/refs/heads/main/packages/convex-cache/assets/flowchart/server-cache-light.png" alt="Server Cache Flowchart" referrerpolicy="no-referrer-when-downgrade" />
|
|
66
66
|
</picture>
|
|
67
67
|
</a>
|
|
68
68
|
|
package/dist/cli/fns/dev.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/cli/fns/dev.ts
|
|
2
2
|
import { DirWatcher } from "../lib/dir-watcher.js";
|
|
3
3
|
import { ConvexRunner } from "./fns/convex-runner.js";
|
|
4
|
+
import { runCmd } from "../lib/package-cmds.js";
|
|
4
5
|
import { getConvexDir } from "../lib/convex-config.js";
|
|
5
6
|
/**
|
|
6
7
|
* Start a one-off Convex dev run and then watch the Convex directory
|
|
@@ -7,65 +7,66 @@ import { runCmd, runFileCmd } from "../../lib/package-cmds.js";
|
|
|
7
7
|
* Uses ShellRunner under the hood and ensures only one run happens at a time.
|
|
8
8
|
*/
|
|
9
9
|
export class ConvexRunner {
|
|
10
|
+
tasks = new ShellRunner();
|
|
11
|
+
skipConvex;
|
|
12
|
+
isRunning = false;
|
|
10
13
|
constructor({ skipConvex = false }) {
|
|
11
|
-
this.tasks = new ShellRunner();
|
|
12
|
-
this.isRunning = false;
|
|
13
|
-
/**
|
|
14
|
-
* Cancel any in-flight Convex task run.
|
|
15
|
-
* This will cause the current runOnce() to reject with a "cancelled" error.
|
|
16
|
-
*/
|
|
17
|
-
this.cancel = () => {
|
|
18
|
-
if (!this.isRunning)
|
|
19
|
-
return;
|
|
20
|
-
this.tasks.cancelAll();
|
|
21
|
-
};
|
|
22
|
-
this.resolveCurrentPath = () => {
|
|
23
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
24
|
-
const __dirname = path.dirname(__filename);
|
|
25
|
-
return __dirname;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Run the Convex command once, then regenerate the Zod schema.
|
|
29
|
-
* If a run is already in progress, this is a no-op.
|
|
30
|
-
* If skipConvex is true, skips the Convex command and only generates schemas.
|
|
31
|
-
*/
|
|
32
|
-
this.runOnce = async () => {
|
|
33
|
-
if (this.isRunning)
|
|
34
|
-
return;
|
|
35
|
-
this.isRunning = true;
|
|
36
|
-
this.tasks.resetCancelled();
|
|
37
|
-
try {
|
|
38
|
-
if (!this.skipConvex) {
|
|
39
|
-
const convexCmd = await runCmd("convex dev --once");
|
|
40
|
-
await this.tasks.run(convexCmd, {
|
|
41
|
-
kind: "convex",
|
|
42
|
-
label: "➡️ Uploading functions to Convex...",
|
|
43
|
-
successMessage: "✅ Convex functions uploaded",
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
const generateSchemaPath = path.join(this.resolveCurrentPath(), "generate-z-schema/generate.js");
|
|
47
|
-
const generateSchemaCmd = await runFileCmd(generateSchemaPath);
|
|
48
|
-
await this.tasks.run(generateSchemaCmd, {
|
|
49
|
-
kind: "schema",
|
|
50
|
-
label: "➡️ Generating Zod schemas...",
|
|
51
|
-
successMessage: "✅ Zod schemas generated",
|
|
52
|
-
});
|
|
53
|
-
console.log(`\n👀 Watching for any changes...`);
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
// Ignore cancellations from ShellRunner, log everything else.
|
|
57
|
-
if (!(err instanceof ShellRunnerError && err.message === "cancelled") && (typeof err !== "object" || err === null || err.message !== "cancelled")) {
|
|
58
|
-
console.error("⚠️ Convex run failed:", err);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
this.isRunning = false;
|
|
63
|
-
this.tasks.resetCancelled();
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
14
|
this.skipConvex = skipConvex;
|
|
67
15
|
}
|
|
68
16
|
get running() {
|
|
69
17
|
return this.isRunning;
|
|
70
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Cancel any in-flight Convex task run.
|
|
21
|
+
* This will cause the current runOnce() to reject with a "cancelled" error.
|
|
22
|
+
*/
|
|
23
|
+
cancel = () => {
|
|
24
|
+
if (!this.isRunning)
|
|
25
|
+
return;
|
|
26
|
+
this.tasks.cancelAll();
|
|
27
|
+
};
|
|
28
|
+
resolveCurrentPath = () => {
|
|
29
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
30
|
+
const __dirname = path.dirname(__filename);
|
|
31
|
+
return __dirname;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Run the Convex command once, then regenerate the Zod schema.
|
|
35
|
+
* If a run is already in progress, this is a no-op.
|
|
36
|
+
* If skipConvex is true, skips the Convex command and only generates schemas.
|
|
37
|
+
*/
|
|
38
|
+
runOnce = async () => {
|
|
39
|
+
if (this.isRunning)
|
|
40
|
+
return;
|
|
41
|
+
this.isRunning = true;
|
|
42
|
+
this.tasks.resetCancelled();
|
|
43
|
+
try {
|
|
44
|
+
if (!this.skipConvex) {
|
|
45
|
+
const convexCmd = await runCmd("convex dev --once");
|
|
46
|
+
await this.tasks.run(convexCmd, {
|
|
47
|
+
kind: "convex",
|
|
48
|
+
label: "➡️ Uploading functions to Convex...",
|
|
49
|
+
successMessage: "✅ Convex functions uploaded",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const generateSchemaPath = path.join(this.resolveCurrentPath(), "generate-z-schema/generate.js");
|
|
53
|
+
const generateSchemaCmd = await runFileCmd(generateSchemaPath);
|
|
54
|
+
await this.tasks.run(generateSchemaCmd, {
|
|
55
|
+
kind: "schema",
|
|
56
|
+
label: "➡️ Generating Zod schemas...",
|
|
57
|
+
successMessage: "✅ Zod schemas generated",
|
|
58
|
+
});
|
|
59
|
+
console.log(`\n👀 Watching for any changes...`);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
// Ignore cancellations from ShellRunner, log everything else.
|
|
63
|
+
if (!(err instanceof ShellRunnerError && err.message === "cancelled") && (typeof err !== "object" || err === null || err.message !== "cancelled")) {
|
|
64
|
+
console.error("⚠️ Convex run failed:", err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
this.isRunning = false;
|
|
69
|
+
this.tasks.resetCancelled();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
71
72
|
}
|
|
@@ -24,7 +24,10 @@ export const loadConvexApi = async (convexDir) => {
|
|
|
24
24
|
];
|
|
25
25
|
const existing = candidates.find((p) => fs.existsSync(p));
|
|
26
26
|
if (!existing) {
|
|
27
|
-
console.warn([
|
|
27
|
+
console.warn([
|
|
28
|
+
"⚠️ No convex/_generated/api.{ts,js,mjs,cjs} found in this project.",
|
|
29
|
+
'⚠️ Skipping schema extraction. Run "npx convex dev" or "npx convex codegen" first.',
|
|
30
|
+
].join("\n"));
|
|
28
31
|
return null;
|
|
29
32
|
}
|
|
30
33
|
try {
|
|
@@ -6,54 +6,17 @@ import path from "path";
|
|
|
6
6
|
* after changes settle for `debounceMs` milliseconds.
|
|
7
7
|
*/
|
|
8
8
|
export class DirWatcher {
|
|
9
|
+
rootDir;
|
|
10
|
+
rootLabel;
|
|
11
|
+
recursive;
|
|
12
|
+
debounceMs;
|
|
13
|
+
shouldIgnore;
|
|
14
|
+
onChange;
|
|
15
|
+
debounceTimer = null;
|
|
16
|
+
lastRelPath = null;
|
|
17
|
+
watcher = null;
|
|
18
|
+
started = false;
|
|
9
19
|
constructor(options) {
|
|
10
|
-
this.debounceTimer = null;
|
|
11
|
-
this.lastRelPath = null;
|
|
12
|
-
this.watcher = null;
|
|
13
|
-
this.started = false;
|
|
14
|
-
/**
|
|
15
|
-
* Start watching the directory.
|
|
16
|
-
* Exits the process if the root directory does not exist or watcher fails.
|
|
17
|
-
*/
|
|
18
|
-
this.start = () => {
|
|
19
|
-
if (this.started)
|
|
20
|
-
return;
|
|
21
|
-
if (!fs.existsSync(this.rootDir)) {
|
|
22
|
-
console.error(`watch root not found: ${this.rootDir}`);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
this.watcher = fs.watch(this.rootDir, { recursive: this.recursive }, (eventType, filename) => {
|
|
27
|
-
this.handleFsEvent(eventType, filename);
|
|
28
|
-
});
|
|
29
|
-
this.watcher.on("error", (err) => {
|
|
30
|
-
console.error(`fs.watch error for ${this.rootDir}:`, err);
|
|
31
|
-
this.stop();
|
|
32
|
-
// Keep behavior simple & explicit: fail hard on watcher errors
|
|
33
|
-
process.exit(1);
|
|
34
|
-
});
|
|
35
|
-
this.started = true;
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
console.error(`Failed to start fs.watch on ${this.rootDir} (recursive=${this.recursive}):`, err);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Stop watching the directory and clear any pending debounce timer.
|
|
44
|
-
*/
|
|
45
|
-
this.stop = () => {
|
|
46
|
-
if (this.watcher) {
|
|
47
|
-
this.watcher.close();
|
|
48
|
-
this.watcher = null;
|
|
49
|
-
}
|
|
50
|
-
if (this.debounceTimer) {
|
|
51
|
-
clearTimeout(this.debounceTimer);
|
|
52
|
-
this.debounceTimer = null;
|
|
53
|
-
}
|
|
54
|
-
this.lastRelPath = null;
|
|
55
|
-
this.started = false;
|
|
56
|
-
};
|
|
57
20
|
const { rootDir, recursive = true, debounceMs = 200, shouldIgnore, onChange } = options;
|
|
58
21
|
// Normalize to an absolute path to avoid ambiguity
|
|
59
22
|
this.rootDir = path.resolve(rootDir);
|
|
@@ -63,6 +26,49 @@ export class DirWatcher {
|
|
|
63
26
|
this.shouldIgnore = shouldIgnore;
|
|
64
27
|
this.onChange = onChange;
|
|
65
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Start watching the directory.
|
|
31
|
+
* Exits the process if the root directory does not exist or watcher fails.
|
|
32
|
+
*/
|
|
33
|
+
start = () => {
|
|
34
|
+
if (this.started)
|
|
35
|
+
return;
|
|
36
|
+
if (!fs.existsSync(this.rootDir)) {
|
|
37
|
+
console.error(`watch root not found: ${this.rootDir}`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
this.watcher = fs.watch(this.rootDir, { recursive: this.recursive }, (eventType, filename) => {
|
|
42
|
+
this.handleFsEvent(eventType, filename);
|
|
43
|
+
});
|
|
44
|
+
this.watcher.on("error", (err) => {
|
|
45
|
+
console.error(`fs.watch error for ${this.rootDir}:`, err);
|
|
46
|
+
this.stop();
|
|
47
|
+
// Keep behavior simple & explicit: fail hard on watcher errors
|
|
48
|
+
process.exit(1);
|
|
49
|
+
});
|
|
50
|
+
this.started = true;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.error(`Failed to start fs.watch on ${this.rootDir} (recursive=${this.recursive}):`, err);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Stop watching the directory and clear any pending debounce timer.
|
|
59
|
+
*/
|
|
60
|
+
stop = () => {
|
|
61
|
+
if (this.watcher) {
|
|
62
|
+
this.watcher.close();
|
|
63
|
+
this.watcher = null;
|
|
64
|
+
}
|
|
65
|
+
if (this.debounceTimer) {
|
|
66
|
+
clearTimeout(this.debounceTimer);
|
|
67
|
+
this.debounceTimer = null;
|
|
68
|
+
}
|
|
69
|
+
this.lastRelPath = null;
|
|
70
|
+
this.started = false;
|
|
71
|
+
};
|
|
66
72
|
/**
|
|
67
73
|
* Internal handler for fs.watch events.
|
|
68
74
|
* Keeps behavior identical to the original implementation:
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
2
|
export class ShellRunnerError extends Error {
|
|
3
|
+
kind;
|
|
4
|
+
code;
|
|
5
|
+
signal;
|
|
3
6
|
constructor(message, kind, code = null, signal = null) {
|
|
4
7
|
super(message);
|
|
5
8
|
this.kind = kind;
|
|
@@ -13,121 +16,119 @@ export class ShellRunnerError extends Error {
|
|
|
13
16
|
* and allows cancelling all running processes.
|
|
14
17
|
*/
|
|
15
18
|
export class ShellRunner {
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
currentProcs = new Map();
|
|
20
|
+
cancelled = false;
|
|
21
|
+
get isCancelled() {
|
|
22
|
+
return this.cancelled;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reset the internal "cancelled" flag back to false.
|
|
26
|
+
* Does not restart any cancelled processes; it only affects
|
|
27
|
+
* how subsequent runs behave.
|
|
28
|
+
*/
|
|
29
|
+
resetCancelled = () => {
|
|
18
30
|
this.cancelled = false;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Run a shell command with the given options.
|
|
34
|
+
*
|
|
35
|
+
* Resolves on successful exit code (0), rejects otherwise,
|
|
36
|
+
* or if the runner is cancelled / AbortSignal aborts / a process of this kind is already running.
|
|
37
|
+
*/
|
|
38
|
+
run = async (command, options) => {
|
|
39
|
+
const { label, kind, successMessage, shell = true, spawnOptions, abortSignal } = options;
|
|
40
|
+
// Fast-fail if globally cancelled or already aborted.
|
|
41
|
+
if (this.cancelled) {
|
|
42
|
+
throw new ShellRunnerError("ShellRunner is cancelled", kind);
|
|
43
|
+
}
|
|
44
|
+
if (abortSignal?.aborted) {
|
|
45
|
+
throw new ShellRunnerError("Run aborted before start", kind);
|
|
46
|
+
}
|
|
47
|
+
// Enforce single process per kind.
|
|
48
|
+
if (this.currentProcs.has(kind)) {
|
|
49
|
+
throw new ShellRunnerError(`A task of kind "${kind}" is already running`, kind);
|
|
50
|
+
}
|
|
51
|
+
console.log(`\n${label}`);
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const child = spawn(command, {
|
|
54
|
+
shell,
|
|
55
|
+
stdio: ["inherit", "inherit", "inherit"],
|
|
56
|
+
...spawnOptions,
|
|
57
|
+
});
|
|
58
|
+
this.currentProcs.set(kind, child);
|
|
59
|
+
// Support AbortSignal-based cancellation
|
|
60
|
+
const abortHandler = () => {
|
|
61
|
+
if (!child.killed) {
|
|
62
|
+
child.kill("SIGINT");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (abortSignal) {
|
|
66
|
+
abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
45
67
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const abortHandler = () => {
|
|
56
|
-
if (!child.killed) {
|
|
57
|
-
child.kill("SIGINT");
|
|
58
|
-
}
|
|
59
|
-
};
|
|
68
|
+
let settled = false;
|
|
69
|
+
const settle = (fn) => {
|
|
70
|
+
if (settled)
|
|
71
|
+
return;
|
|
72
|
+
settled = true;
|
|
73
|
+
// Cleanup
|
|
74
|
+
if (this.currentProcs.get(kind) === child) {
|
|
75
|
+
this.currentProcs.delete(kind);
|
|
76
|
+
}
|
|
60
77
|
if (abortSignal) {
|
|
61
|
-
abortSignal.
|
|
78
|
+
abortSignal.removeEventListener("abort", abortHandler);
|
|
62
79
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (this.currentProcs.get(kind) === child) {
|
|
70
|
-
this.currentProcs.delete(kind);
|
|
71
|
-
}
|
|
72
|
-
if (abortSignal) {
|
|
73
|
-
abortSignal.removeEventListener("abort", abortHandler);
|
|
80
|
+
fn();
|
|
81
|
+
};
|
|
82
|
+
child.on("exit", (code, signal) => {
|
|
83
|
+
settle(() => {
|
|
84
|
+
if (this.cancelled || abortSignal?.aborted) {
|
|
85
|
+
return reject(new ShellRunnerError("cancelled", kind, code, signal));
|
|
74
86
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
settle(() => {
|
|
79
|
-
if (this.cancelled || abortSignal?.aborted) {
|
|
80
|
-
return reject(new ShellRunnerError("cancelled", kind, code, signal));
|
|
87
|
+
if (code === 0) {
|
|
88
|
+
if (successMessage) {
|
|
89
|
+
console.log(successMessage);
|
|
81
90
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return resolve();
|
|
87
|
-
}
|
|
88
|
-
console.error(`❌ ${label} failed (code=${code ?? "unknown"}, signal=${signal ?? "none"})`);
|
|
89
|
-
reject(new ShellRunnerError(`${label} failed with code ${code ?? "unknown"}`, kind, code, signal));
|
|
90
|
-
});
|
|
91
|
+
return resolve();
|
|
92
|
+
}
|
|
93
|
+
console.error(`❌ ${label} failed (code=${code ?? "unknown"}, signal=${signal ?? "none"})`);
|
|
94
|
+
reject(new ShellRunnerError(`${label} failed with code ${code ?? "unknown"}`, kind, code, signal));
|
|
91
95
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
});
|
|
97
|
+
child.on("error", (err) => {
|
|
98
|
+
settle(() => {
|
|
99
|
+
console.error(`❌ Failed to start ${label}:`, err);
|
|
100
|
+
reject(err);
|
|
97
101
|
});
|
|
98
102
|
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
child.kill(signal);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// ignore
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Cancel a single running task kind, if present.
|
|
117
|
-
*/
|
|
118
|
-
this.cancelKind = (kind, signal = "SIGINT") => {
|
|
119
|
-
const child = this.currentProcs.get(kind);
|
|
120
|
-
if (!child)
|
|
121
|
-
return;
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Mark the runner as cancelled and send the given signal
|
|
107
|
+
* (default SIGINT) to all tracked child processes.
|
|
108
|
+
*/
|
|
109
|
+
cancelAll = (signal = "SIGINT") => {
|
|
110
|
+
this.cancelled = true;
|
|
111
|
+
for (const child of this.currentProcs.values()) {
|
|
122
112
|
try {
|
|
123
113
|
child.kill(signal);
|
|
124
114
|
}
|
|
125
115
|
catch {
|
|
126
116
|
// ignore
|
|
127
117
|
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Cancel a single running task kind, if present.
|
|
122
|
+
*/
|
|
123
|
+
cancelKind = (kind, signal = "SIGINT") => {
|
|
124
|
+
const child = this.currentProcs.get(kind);
|
|
125
|
+
if (!child)
|
|
126
|
+
return;
|
|
127
|
+
try {
|
|
128
|
+
child.kill(signal);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// ignore
|
|
132
|
+
}
|
|
133
|
+
};
|
|
133
134
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q_Query } from "../../../core/types/types/query";
|
|
2
|
-
import { PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
|
-
import { PreloadQueryReturn, T_PreloadQueryParams } from "./preload-query";
|
|
4
|
-
import { T_SchemaMap } from "../../../types/schema-map";
|
|
1
|
+
import type { Q_Query } from "../../../core/types/types/query";
|
|
2
|
+
import type { PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
|
+
import type { PreloadQueryReturn, T_PreloadQueryParams } from "./preload-query";
|
|
4
|
+
import type { T_SchemaMap } from "../../../types/schema-map";
|
|
5
5
|
export declare function buildPreloader(schemaMap: T_SchemaMap): <Q extends Q_Query | PQ_Query>(params: Omit<T_PreloadQueryParams<Q>, "schemaMap">) => Promise<PreloadQueryReturn<Q>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PQ_CachedResult, PQ_Query } from "../../../core/types/types/paginated-query";
|
|
2
|
-
import { Q_Query, Q_Result } from "../../../core/types/types/query";
|
|
3
|
-
import { PQ_ArgsPreloaded, PQ_OptionsPreloaded, Q_ArgsPreloaded, Q_OptionsPreloaded } from "../types/preloaded";
|
|
4
|
-
import { T_SchemaMap } from "../../../types/schema-map";
|
|
1
|
+
import type { PQ_CachedResult, PQ_Query } from "../../../core/types/types/paginated-query";
|
|
2
|
+
import type { Q_Query, Q_Result } from "../../../core/types/types/query";
|
|
3
|
+
import type { PQ_ArgsPreloaded, PQ_OptionsPreloaded, Q_ArgsPreloaded, Q_OptionsPreloaded } from "../types/preloaded";
|
|
4
|
+
import type { T_SchemaMap } from "../../../types/schema-map";
|
|
5
5
|
export type PreloadQueryReturn<Q extends Q_Query | PQ_Query> = Q extends PQ_Query ? PQ_CachedResult<Q> | undefined : Q_Result<Q> | undefined;
|
|
6
6
|
export type T_PreloadQueryParams<Q extends Q_Query | PQ_Query> = {
|
|
7
7
|
query: Q;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Q_Query, PQ_Query } from "../../../core/types";
|
|
2
|
-
import { T_UseCachedPaginatedQueryServer } from "../../../core/server-cache/queries/paginated-query";
|
|
3
|
-
import { T_UseCachedQueryServer } from "../../../core/server-cache/queries/query";
|
|
1
|
+
import type { Q_Query, PQ_Query } from "../../../core/types";
|
|
2
|
+
import { type T_UseCachedPaginatedQueryServer } from "../../../core/server-cache/queries/paginated-query";
|
|
3
|
+
import { type T_UseCachedQueryServer } from "../../../core/server-cache/queries/query";
|
|
4
4
|
type T_UseCachedQueryServerParams<Q extends Q_Query> = Omit<T_UseCachedQueryServer<Q>, "revalidateCache">;
|
|
5
|
-
export declare const useCachedQueryServer: <Q extends Q_Query>({ query, args, preloadedData }: T_UseCachedQueryServerParams<Q>) => import("../../../core/types").Q_Result<Q> | undefined;
|
|
5
|
+
export declare const useCachedQueryServer: <Q extends Q_Query>({ query, args, preloadedData, }: T_UseCachedQueryServerParams<Q>) => import("../../../core/types").Q_Result<Q> | undefined;
|
|
6
6
|
type T_UseCachedPaginatedQueryServerParams<Q extends PQ_Query> = Omit<T_UseCachedPaginatedQueryServer<Q>, "revalidateCache">;
|
|
7
|
-
export declare const useCachedPaginatedQueryServer: <Q extends PQ_Query>({ query, args, options, preloadedData }: T_UseCachedPaginatedQueryServerParams<Q>) => import("../../../core/types").PQ_Result<Q>;
|
|
7
|
+
export declare const useCachedPaginatedQueryServer: <Q extends PQ_Query>({ query, args, options, preloadedData, }: T_UseCachedPaginatedQueryServerParams<Q>) => import("../../../core/types").PQ_Result<Q>;
|
|
8
8
|
export {};
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { _useCachedPaginatedQueryServer } from "../../../core/server-cache/queries/paginated-query";
|
|
1
|
+
import { _useCachedPaginatedQueryServer, } from "../../../core/server-cache/queries/paginated-query";
|
|
2
2
|
import { _useCachedQueryServer } from "../../../core/server-cache/queries/query";
|
|
3
3
|
import { revalidatePaginatedQueryCache, revalidateQueryCache } from "../lib/revalidate-query-cache";
|
|
4
|
-
export const useCachedQueryServer = ({ query, args, preloadedData }) => {
|
|
4
|
+
export const useCachedQueryServer = ({ query, args, preloadedData, }) => {
|
|
5
5
|
return _useCachedQueryServer({ query, args, preloadedData, revalidateCache: revalidateQueryCache });
|
|
6
6
|
};
|
|
7
|
-
export const useCachedPaginatedQueryServer = ({ query, args, options, preloadedData }) => {
|
|
8
|
-
return _useCachedPaginatedQueryServer({
|
|
7
|
+
export const useCachedPaginatedQueryServer = ({ query, args, options, preloadedData, }) => {
|
|
8
|
+
return _useCachedPaginatedQueryServer({
|
|
9
|
+
query,
|
|
10
|
+
args,
|
|
11
|
+
options,
|
|
12
|
+
preloadedData,
|
|
13
|
+
revalidateCache: revalidatePaginatedQueryCache,
|
|
14
|
+
});
|
|
9
15
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Q_Query } from "../../../core/types/types/query";
|
|
2
|
-
import { PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
|
-
import { PQ_ArgsPreloaded, Q_ArgsPreloaded } from "../types/preloaded";
|
|
4
|
-
export declare const revalidateQueryCache: <Q extends Q_Query>({ query, args }: {
|
|
1
|
+
import type { Q_Query } from "../../../core/types/types/query";
|
|
2
|
+
import type { PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
|
+
import type { PQ_ArgsPreloaded, Q_ArgsPreloaded } from "../types/preloaded";
|
|
4
|
+
export declare const revalidateQueryCache: <Q extends Q_Query>({ query, args, }: {
|
|
5
5
|
query: Q;
|
|
6
6
|
args: Q_ArgsPreloaded<Q>;
|
|
7
7
|
}) => Promise<void>;
|
|
@@ -9,5 +9,5 @@ type T_RevalidatePaginatedQueryCacheParams<Q extends PQ_Query> = {
|
|
|
9
9
|
query: Q;
|
|
10
10
|
args: PQ_ArgsPreloaded<Q>;
|
|
11
11
|
};
|
|
12
|
-
export declare const revalidatePaginatedQueryCache: <Q extends PQ_Query>({ query, args }: T_RevalidatePaginatedQueryCacheParams<Q>) => Promise<void>;
|
|
12
|
+
export declare const revalidatePaginatedQueryCache: <Q extends PQ_Query>({ query, args, }: T_RevalidatePaginatedQueryCacheParams<Q>) => Promise<void>;
|
|
13
13
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { makeQueryKey } from "../../../core/helpers/utils/query-key";
|
|
2
2
|
import { getFunctionName } from "convex/server";
|
|
3
3
|
import { revalidateCache } from "../server-fns/revalidate-cache";
|
|
4
|
-
export const revalidateQueryCache = async ({ query, args }) => {
|
|
4
|
+
export const revalidateQueryCache = async ({ query, args, }) => {
|
|
5
5
|
const queryName = getFunctionName(query);
|
|
6
6
|
const { tag } = makeQueryKey({
|
|
7
7
|
queryName,
|
|
@@ -10,7 +10,7 @@ export const revalidateQueryCache = async ({ query, args }) => {
|
|
|
10
10
|
});
|
|
11
11
|
await revalidateCache({ tag });
|
|
12
12
|
};
|
|
13
|
-
export const revalidatePaginatedQueryCache = async ({ query, args }) => {
|
|
13
|
+
export const revalidatePaginatedQueryCache = async ({ query, args, }) => {
|
|
14
14
|
const queryName = getFunctionName(query);
|
|
15
15
|
const { tag } = makeQueryKey({
|
|
16
16
|
queryName,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Q_Query, Q_Result } from "../../../core/types/types/query";
|
|
2
|
-
import { PQ_CachedResult, PQ_Query } from "../../../core/types/types/paginated-query";
|
|
1
|
+
import type { Q_Query, Q_Result } from "../../../core/types/types/query";
|
|
2
|
+
import type { PQ_CachedResult, PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
3
|
import type { PQ_ArgsPreloaded, PQ_OptionsPreloaded, Q_ArgsPreloaded, Q_OptionsPreloaded } from "../types/preloaded";
|
|
4
4
|
type T_PreloadQueryParams<Q extends Q_Query> = {
|
|
5
5
|
queryName: string;
|
|
6
6
|
args: Q_ArgsPreloaded<Q>;
|
|
7
7
|
options?: Q_OptionsPreloaded<Q>;
|
|
8
8
|
};
|
|
9
|
-
export declare const _preloadQuery: ({ queryName, args, options }: T_PreloadQueryParams<Q_Query>) => Promise<Q_Result<Q_Query>>;
|
|
9
|
+
export declare const _preloadQuery: ({ queryName, args, options, }: T_PreloadQueryParams<Q_Query>) => Promise<Q_Result<Q_Query>>;
|
|
10
10
|
type T_PreloadPaginatedQueryParams<Q extends PQ_Query> = {
|
|
11
11
|
queryName: string;
|
|
12
12
|
args: PQ_ArgsPreloaded<Q>;
|
|
13
13
|
options?: PQ_OptionsPreloaded<Q>;
|
|
14
14
|
};
|
|
15
|
-
export declare const _preloadPaginatedQuery: ({ queryName, args, options }: T_PreloadPaginatedQueryParams<PQ_Query>) => Promise<PQ_CachedResult<PQ_Query>>;
|
|
15
|
+
export declare const _preloadPaginatedQuery: ({ queryName, args, options, }: T_PreloadPaginatedQueryParams<PQ_Query>) => Promise<PQ_CachedResult<PQ_Query>>;
|
|
16
16
|
export {};
|
|
@@ -3,7 +3,7 @@ import { fetchQuery } from "convex/nextjs";
|
|
|
3
3
|
import { cacheLife, cacheTag } from "next/cache";
|
|
4
4
|
import { makeQueryKey } from "../../../core/helpers/utils/query-key";
|
|
5
5
|
import { defaultCacheProfile } from "../utils/cache-profile";
|
|
6
|
-
export const _preloadQuery = async ({ queryName, args, options }) => {
|
|
6
|
+
export const _preloadQuery = async ({ queryName, args, options, }) => {
|
|
7
7
|
"use cache";
|
|
8
8
|
const { tag } = makeQueryKey({ queryName, args, kind: "query" });
|
|
9
9
|
cacheTag(tag);
|
|
@@ -13,7 +13,7 @@ export const _preloadQuery = async ({ queryName, args, options }) => {
|
|
|
13
13
|
const result = await fetchQuery(fnRef, ...argsTuple);
|
|
14
14
|
return result;
|
|
15
15
|
};
|
|
16
|
-
export const _preloadPaginatedQuery = async ({ queryName, args, options }) => {
|
|
16
|
+
export const _preloadPaginatedQuery = async ({ queryName, args, options, }) => {
|
|
17
17
|
"use cache";
|
|
18
18
|
const { tag } = makeQueryKey({ queryName, args, kind: "paginated" });
|
|
19
19
|
cacheTag(tag);
|
|
@@ -23,7 +23,7 @@ export const _preloadPaginatedQuery = async ({ queryName, args, options }) => {
|
|
|
23
23
|
const result = await fetchQuery(fnRef, ...argsTuple);
|
|
24
24
|
return convertPaginatedResultForClient({ result });
|
|
25
25
|
};
|
|
26
|
-
const convertPaginatedResultForClient = ({ result }) => {
|
|
26
|
+
const convertPaginatedResultForClient = ({ result, }) => {
|
|
27
27
|
return {
|
|
28
28
|
results: result.page,
|
|
29
29
|
status: "Exhausted",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ArgsAndOptions } from "convex/server";
|
|
2
|
-
import { PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
|
-
import { Q_Query } from "../../../core/types/types/query";
|
|
4
|
-
import { NextjsOptions } from "convex/nextjs";
|
|
1
|
+
import type { ArgsAndOptions } from "convex/server";
|
|
2
|
+
import type { PQ_Query } from "../../../core/types/types/paginated-query";
|
|
3
|
+
import type { Q_Query } from "../../../core/types/types/query";
|
|
4
|
+
import type { NextjsOptions } from "convex/nextjs";
|
|
5
5
|
export type Q_ArgsPreloaded<Q extends Q_Query> = ArgsAndOptions<Q, NextjsOptions>[0];
|
|
6
6
|
export type PQ_ArgsPreloaded<Q extends PQ_Query> = ArgsAndOptions<Q, NextjsOptions>[0];
|
|
7
7
|
export type Q_OptionsPreloaded<Q extends Q_Query> = ArgsAndOptions<Q, NextjsOptions>[1];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T_UseCachedPaginatedQueryClient } from "../../../core/client-cache/queries/paginated-query";
|
|
2
|
-
import { Q_Query, PQ_Query } from "../../../core/types";
|
|
3
|
-
import { T_UseCachedQueryClient } from "../../../core/client-cache/queries/query";
|
|
1
|
+
import type { T_UseCachedPaginatedQueryClient } from "../../../core/client-cache/queries/paginated-query";
|
|
2
|
+
import type { Q_Query, PQ_Query } from "../../../core/types";
|
|
3
|
+
import { type T_UseCachedQueryClient } from "../../../core/client-cache/queries/query";
|
|
4
4
|
type T_UseQuery<Q extends Q_Query> = Omit<T_UseCachedQueryClient<Q>, "schemaMap" | "useLocalDb">;
|
|
5
5
|
type T_UsePaginatedQuery<Q extends PQ_Query> = Omit<T_UseCachedPaginatedQueryClient<Q>, "schemaMap" | "useLocalDb">;
|
|
6
6
|
export declare const useCachedQueryClient: <Q extends Q_Query>({ query, args }: T_UseQuery<Q>) => import("../../../core/types").Q_Result<Q> | undefined;
|
|
@@ -8,5 +8,11 @@ export const useCachedQueryClient = ({ query, args }) => {
|
|
|
8
8
|
};
|
|
9
9
|
export const useCachedPaginatedQueryClient = ({ query, args, options }) => {
|
|
10
10
|
const { schemaMap, useLocalDb } = useConvexProvider();
|
|
11
|
-
return _useCachedPaginatedQueryClient({
|
|
11
|
+
return _useCachedPaginatedQueryClient({
|
|
12
|
+
query,
|
|
13
|
+
args,
|
|
14
|
+
options,
|
|
15
|
+
schemaMap,
|
|
16
|
+
useLocalDb: (useLocalDb ?? useLocalDbDefault),
|
|
17
|
+
});
|
|
12
18
|
};
|
|
@@ -6,5 +6,5 @@ type T_UseClientCache<T> = {
|
|
|
6
6
|
schema: z.ZodSchema<T>;
|
|
7
7
|
useLocalDb: typeof useLocalDbDefault<T>;
|
|
8
8
|
};
|
|
9
|
-
export declare const useClientCache: <T>({ storageKey, raw, schema, useLocalDb }: T_UseClientCache<T>) => T | null | undefined;
|
|
9
|
+
export declare const useClientCache: <T>({ storageKey, raw, schema, useLocalDb, }: T_UseClientCache<T>) => T | null | undefined;
|
|
10
10
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { useLocalDb as useLocalDbDefault } from "@bb-labs/local-db";
|
|
1
2
|
import { useEffect } from "react";
|
|
2
|
-
import
|
|
3
|
-
|
|
3
|
+
import { isDeepEqual } from "@bb-labs/deep-equal";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export const useClientCache = ({ storageKey, raw, schema, useLocalDb, }) => {
|
|
4
6
|
const { value: stored, setValue: setStored } = useLocalDb({
|
|
5
7
|
key: storageKey,
|
|
6
8
|
schema,
|
|
@@ -9,7 +11,7 @@ export const useClientCache = ({ storageKey, raw, schema, useLocalDb }) => {
|
|
|
9
11
|
storeName: "local-store",
|
|
10
12
|
});
|
|
11
13
|
useEffect(() => {
|
|
12
|
-
if (raw !== undefined && !
|
|
14
|
+
if (raw !== undefined && !isDeepEqual(raw, stored))
|
|
13
15
|
setStored(raw);
|
|
14
16
|
}, [raw, stored, setStored]);
|
|
15
17
|
return stored;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PQ_Query, PQ_Args, PQ_Result, PQ_CachedResult } from "../../types/types/paginated-query";
|
|
1
|
+
import type { PQ_Query, PQ_Args, PQ_Result, PQ_CachedResult } from "../../types/types/paginated-query";
|
|
2
2
|
import type { T_SchemaMap } from "../../../types/schema-map";
|
|
3
3
|
import { useLocalDb as useLocalDbDefault } from "@bb-labs/local-db";
|
|
4
4
|
export type T_UseCachedPaginatedQueryClient<Q extends PQ_Query> = {
|
|
@@ -10,4 +10,4 @@ export type T_UseCachedPaginatedQueryClient<Q extends PQ_Query> = {
|
|
|
10
10
|
schemaMap: T_SchemaMap;
|
|
11
11
|
useLocalDb: typeof useLocalDbDefault<PQ_CachedResult<Q>>;
|
|
12
12
|
};
|
|
13
|
-
export declare const _useCachedPaginatedQueryClient: <Q extends PQ_Query>({ query, args, options, schemaMap, useLocalDb }: T_UseCachedPaginatedQueryClient<Q>) => PQ_Result<Q>;
|
|
13
|
+
export declare const _useCachedPaginatedQueryClient: <Q extends PQ_Query>({ query, args, options, schemaMap, useLocalDb, }: T_UseCachedPaginatedQueryClient<Q>) => PQ_Result<Q>;
|
|
@@ -4,7 +4,8 @@ import { useClientCache } from "../helpers/hooks/use-client-cache";
|
|
|
4
4
|
import { getFunctionName } from "convex/server";
|
|
5
5
|
import { useMemo } from "react";
|
|
6
6
|
import { fetchSchemaFromMap } from "../../helpers/utils/fetch-schema-from-map";
|
|
7
|
-
|
|
7
|
+
import { useLocalDb as useLocalDbDefault } from "@bb-labs/local-db";
|
|
8
|
+
export const _useCachedPaginatedQueryClient = ({ query, args, options, schemaMap, useLocalDb, }) => {
|
|
8
9
|
const queryName = useMemo(() => getFunctionName(query), [query]);
|
|
9
10
|
const schema = useMemo(() => fetchSchemaFromMap({
|
|
10
11
|
queryName,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Q_Query, Q_Args, Q_Result } from "../../types/types/query";
|
|
1
|
+
import type { Q_Query, Q_Args, Q_Result } from "../../types/types/query";
|
|
2
2
|
import type { T_SchemaMap } from "../../../types/schema-map";
|
|
3
3
|
import { useLocalDb as useLocalDbDefault } from "@bb-labs/local-db";
|
|
4
4
|
export type T_UseCachedQueryClient<Q extends Q_Query> = {
|
|
@@ -7,4 +7,4 @@ export type T_UseCachedQueryClient<Q extends Q_Query> = {
|
|
|
7
7
|
schemaMap: T_SchemaMap;
|
|
8
8
|
useLocalDb: typeof useLocalDbDefault<Q_Result<Q>>;
|
|
9
9
|
};
|
|
10
|
-
export declare const _useCachedQueryClient: <Q extends Q_Query>({ query, args, schemaMap, useLocalDb }: T_UseCachedQueryClient<Q>) => Q_Result<Q> | undefined;
|
|
10
|
+
export declare const _useCachedQueryClient: <Q extends Q_Query>({ query, args, schemaMap, useLocalDb, }: T_UseCachedQueryClient<Q>) => Q_Result<Q> | undefined;
|
|
@@ -3,8 +3,9 @@ import { getFunctionName } from "convex/server";
|
|
|
3
3
|
import { useQueryKey } from "../helpers/hooks/use-query-key";
|
|
4
4
|
import { useClientCache } from "../helpers/hooks/use-client-cache";
|
|
5
5
|
import { useMemo } from "react";
|
|
6
|
+
import { useLocalDb as useLocalDbDefault } from "@bb-labs/local-db";
|
|
6
7
|
import { fetchSchemaFromMap } from "../../helpers/utils/fetch-schema-from-map";
|
|
7
|
-
export const _useCachedQueryClient = ({ query, args, schemaMap, useLocalDb }) => {
|
|
8
|
+
export const _useCachedQueryClient = ({ query, args, schemaMap, useLocalDb, }) => {
|
|
8
9
|
const queryName = useMemo(() => getFunctionName(query), [query]);
|
|
9
10
|
const schema = useMemo(() => fetchSchemaFromMap({
|
|
10
11
|
queryName,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PQ_Query, PQ_Args, PQ_Result, PQ_CachedResult } from "../../types/types/paginated-query";
|
|
2
|
-
import { PQ_ArgsPreloaded } from "../../../adapters/next/types/preloaded";
|
|
1
|
+
import type { PQ_Query, PQ_Args, PQ_Result, PQ_CachedResult } from "../../types/types/paginated-query";
|
|
2
|
+
import type { PQ_ArgsPreloaded } from "../../../adapters/next/types/preloaded";
|
|
3
3
|
export type T_UseCachedPaginatedQueryServer<Q extends PQ_Query> = {
|
|
4
4
|
query: Q;
|
|
5
5
|
args: PQ_Args<Q>;
|
|
@@ -12,4 +12,4 @@ export type T_UseCachedPaginatedQueryServer<Q extends PQ_Query> = {
|
|
|
12
12
|
args: PQ_ArgsPreloaded<Q>;
|
|
13
13
|
}) => void;
|
|
14
14
|
};
|
|
15
|
-
export declare const _useCachedPaginatedQueryServer: <Q extends PQ_Query>({ query, args, options, preloadedData, revalidateCache }: T_UseCachedPaginatedQueryServer<Q>) => PQ_Result<Q>;
|
|
15
|
+
export declare const _useCachedPaginatedQueryServer: <Q extends PQ_Query>({ query, args, options, preloadedData, revalidateCache, }: T_UseCachedPaginatedQueryServer<Q>) => PQ_Result<Q>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usePaginatedQuery } from "convex/react";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import { isDeepEqual } from "@bb-labs/deep-equal";
|
|
4
|
-
export const _useCachedPaginatedQueryServer = ({ query, args, options, preloadedData, revalidateCache }) => {
|
|
4
|
+
export const _useCachedPaginatedQueryServer = ({ query, args, options, preloadedData, revalidateCache, }) => {
|
|
5
5
|
const raw = usePaginatedQuery(query, args, options);
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
if (args === "skip")
|
|
@@ -10,7 +10,15 @@ export const _useCachedPaginatedQueryServer = ({ query, args, options, preloaded
|
|
|
10
10
|
return;
|
|
11
11
|
if (isDeepEqual(preloadedData, raw))
|
|
12
12
|
return;
|
|
13
|
-
revalidateCache({
|
|
13
|
+
revalidateCache({
|
|
14
|
+
query,
|
|
15
|
+
args: { ...args, paginationOpts: { numItems: options.initialNumItems, cursor: null } },
|
|
16
|
+
});
|
|
14
17
|
}, [raw]);
|
|
15
|
-
return raw.status == "LoadingFirstPage"
|
|
18
|
+
return raw.status == "LoadingFirstPage"
|
|
19
|
+
? {
|
|
20
|
+
...(preloadedData ?? { results: [], status: "LoadingFirstPage", isLoading: false }),
|
|
21
|
+
loadMore: () => { },
|
|
22
|
+
}
|
|
23
|
+
: raw;
|
|
16
24
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q_Query, Q_Args, Q_Result } from "../../types/types/query";
|
|
2
|
-
import { Q_ArgsPreloaded } from "../../../adapters/next/types/preloaded";
|
|
1
|
+
import type { Q_Query, Q_Args, Q_Result } from "../../types/types/query";
|
|
2
|
+
import type { Q_ArgsPreloaded } from "../../../adapters/next/types/preloaded";
|
|
3
3
|
export type T_UseCachedQueryServer<Q extends Q_Query> = {
|
|
4
4
|
query: Q;
|
|
5
5
|
args: Q_Args<Q>;
|
|
@@ -9,4 +9,4 @@ export type T_UseCachedQueryServer<Q extends Q_Query> = {
|
|
|
9
9
|
args: Q_ArgsPreloaded<Q>;
|
|
10
10
|
}) => void;
|
|
11
11
|
};
|
|
12
|
-
export declare const _useCachedQueryServer: <Q extends Q_Query>({ query, args, preloadedData, revalidateCache }: T_UseCachedQueryServer<Q>) => Q_Result<Q> | undefined;
|
|
12
|
+
export declare const _useCachedQueryServer: <Q extends Q_Query>({ query, args, preloadedData, revalidateCache, }: T_UseCachedQueryServer<Q>) => Q_Result<Q> | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useQuery } from "convex/react";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import { isDeepEqual } from "@bb-labs/deep-equal";
|
|
4
|
-
export const _useCachedQueryServer = ({ query, args, preloadedData, revalidateCache }) => {
|
|
4
|
+
export const _useCachedQueryServer = ({ query, args, preloadedData, revalidateCache, }) => {
|
|
5
5
|
const raw = useQuery(query, args);
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
if (args === "skip")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConvexHttpClient } from "convex/browser";
|
|
2
|
-
import { PaginatedQueryReference, PaginatedQueryArgs, UsePaginatedQueryResult, PaginatedQueryItem } from "convex/react";
|
|
2
|
+
import type { PaginatedQueryReference, PaginatedQueryArgs, UsePaginatedQueryResult, PaginatedQueryItem } from "convex/react";
|
|
3
3
|
export type PQ_Query = PaginatedQueryReference;
|
|
4
4
|
export type PQ_Args<Q extends PQ_Query> = PaginatedQueryArgs<Q> | "skip";
|
|
5
5
|
export type PQ_Result<Q extends PQ_Query> = UsePaginatedQueryResult<PaginatedQueryItem<Q>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OptionalRestArgsOrSkip } from "convex/react";
|
|
2
|
-
import { FunctionReference, FunctionReturnType } from "convex/server";
|
|
1
|
+
import type { OptionalRestArgsOrSkip } from "convex/react";
|
|
2
|
+
import type { FunctionReference, FunctionReturnType } from "convex/server";
|
|
3
3
|
export type Q_Query = FunctionReference<"query">;
|
|
4
4
|
export type Q_Args<Q extends Q_Query> = OptionalRestArgsOrSkip<Q>[0];
|
|
5
5
|
export type Q_Result<Q extends Q_Query> = FunctionReturnType<Q>;
|
package/package.json
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bb-labs/convex-cache",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "A library for caching Convex queries on the client and server",
|
|
5
|
-
"homepage": "https://github.com/beepbop-labs/convex-cache",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"convex-cache",
|
|
8
|
-
"convex",
|
|
9
|
-
"react",
|
|
10
|
-
"nextjs"
|
|
11
|
-
],
|
|
12
|
-
"author": "Beepbop",
|
|
13
|
-
"license": "MIT",
|
|
3
|
+
"version": "0.0.3",
|
|
14
4
|
"repository": {
|
|
15
5
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/beepbop-labs/
|
|
6
|
+
"url": "https://github.com/beepbop-labs/libraries.git"
|
|
17
7
|
},
|
|
18
8
|
"files": [
|
|
19
|
-
"dist"
|
|
20
|
-
"README.md"
|
|
9
|
+
"dist"
|
|
21
10
|
],
|
|
22
11
|
"type": "module",
|
|
23
12
|
"exports": {
|
|
@@ -32,13 +21,16 @@
|
|
|
32
21
|
"convex-cache": "dist/cli/index.js"
|
|
33
22
|
},
|
|
34
23
|
"scripts": {
|
|
35
|
-
"build": "
|
|
36
|
-
"
|
|
24
|
+
"build": "bldr",
|
|
25
|
+
"dev": "bldr -w",
|
|
26
|
+
"clean": "rm -rf node_modules bun.lock dist"
|
|
37
27
|
},
|
|
38
28
|
"dependencies": {
|
|
29
|
+
"@bb-labs/bldr": "^0.0.15",
|
|
39
30
|
"@bb-labs/deep-equal": "^0.0.1",
|
|
40
31
|
"@bb-labs/deep-sort": "^0.0.1",
|
|
41
32
|
"@bb-labs/local-db": "^0.0.1",
|
|
33
|
+
"@bb-labs/tsconfigs": "^0.0.3",
|
|
42
34
|
"commander": "^14.0.2",
|
|
43
35
|
"convex": "^1.29.3",
|
|
44
36
|
"convex-helpers": "^0.1.106",
|
|
@@ -53,6 +45,7 @@
|
|
|
53
45
|
"devDependencies": {
|
|
54
46
|
"@types/node": "^24.10.1",
|
|
55
47
|
"@types/react": "^19.2.7",
|
|
48
|
+
"tsc-alias": "^1.8.16",
|
|
56
49
|
"typescript": "^5.9.3"
|
|
57
50
|
}
|
|
58
51
|
}
|