@hamzasaleemorg/convex-kv 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/index.d.ts +129 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +153 -0
- package/dist/client/index.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +61 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/kv.d.ts +62 -0
- package/dist/component/kv.d.ts.map +1 -0
- package/dist/component/kv.js +220 -0
- package/dist/component/kv.js.map +1 -0
- package/dist/component/schema.d.ts +22 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +15 -0
- package/dist/component/schema.js.map +1 -0
- package/package.json +91 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.test.ts +24 -0
- package/src/client/index.ts +197 -0
- package/src/client/setup.test.ts +26 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +95 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/kv.test.ts +51 -0
- package/src/component/kv.ts +249 -0
- package/src/component/schema.ts +16 -0
- package/src/component/setup.test.ts +11 -0
- package/src/test.ts +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Convex KV
|
|
2
|
+
|
|
3
|
+
A hierarchical key-value store component for Convex. Supports pseudo-tables, caching, and document storage with ordered keys and automatic expiration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Hierarchical Keys: Array-based paths like `["users", "123", "profile"]`.
|
|
8
|
+
- Ordered Scans: Lexicographical storage for efficient prefix range queries.
|
|
9
|
+
- Time-To-Live (TTL): Optional automatic expiration for keys.
|
|
10
|
+
- Atomic Operations: Operations run in standard Convex transactions.
|
|
11
|
+
- Recursive Deletion: Automatic batching for large prefix clears.
|
|
12
|
+
- Typed Clients: TypeScript generics and optional runtime validation.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Create or update `convex/convex.config.ts`:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { defineApp } from "convex/server";
|
|
20
|
+
import convexKv from "@hamzasaleemorg/convex-kv/convex.config.js";
|
|
21
|
+
|
|
22
|
+
const app = defineApp();
|
|
23
|
+
app.use(convexKv);
|
|
24
|
+
|
|
25
|
+
export default app;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Client Initialization
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { components } from "./_generated/api";
|
|
34
|
+
import { kvClientFactory } from "@hamzasaleemorg/convex-kv";
|
|
35
|
+
|
|
36
|
+
const kv = kvClientFactory(components.convexKv);
|
|
37
|
+
|
|
38
|
+
// Create a typed client for a specific prefix
|
|
39
|
+
const store = kv.use<{ name: string }>(["users"]);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Basic Operations
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// Store a value with optional TTL (1 hour)
|
|
46
|
+
await store.set(ctx, ["123"], { name: "Alice" }, { ttl: 3600000 });
|
|
47
|
+
|
|
48
|
+
// Retrieve a value
|
|
49
|
+
const user = await store.get(ctx, ["123"]);
|
|
50
|
+
|
|
51
|
+
// Check existence
|
|
52
|
+
const exists = await store.has(ctx, ["123"]);
|
|
53
|
+
|
|
54
|
+
// Delete a key
|
|
55
|
+
await store.delete(ctx, ["123"]);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Hierarchical Queries
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// Fetch all entries under a prefix
|
|
62
|
+
const allUsers = await store.getAll(ctx, []);
|
|
63
|
+
|
|
64
|
+
// Paginate entries
|
|
65
|
+
const page = await store.list(ctx, [], { limit: 10 });
|
|
66
|
+
|
|
67
|
+
// Recursively delete a sub-tree
|
|
68
|
+
await store.deleteAll(ctx, []);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Expiration (TTL)
|
|
72
|
+
|
|
73
|
+
To physically remove expired keys, expose a mutation in your `convex/` folder and schedule it via crons.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// convex/my_kv.ts
|
|
77
|
+
import { mutation } from "./_generated/server";
|
|
78
|
+
import { components } from "./_generated/api";
|
|
79
|
+
|
|
80
|
+
export const vacuum = mutation({
|
|
81
|
+
handler: async (ctx) => {
|
|
82
|
+
await ctx.runMutation(components.convexKv.kv.vacuum);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// convex/crons.ts
|
|
87
|
+
import { cronJobs } from "convex/server";
|
|
88
|
+
import { api } from "./_generated/api";
|
|
89
|
+
|
|
90
|
+
const crons = cronJobs();
|
|
91
|
+
crons.interval("vacuum", { minutes: 5 }, api.my_kv.vacuum);
|
|
92
|
+
export default crons;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## API Reference
|
|
97
|
+
|
|
98
|
+
### `KeyValueStore<V>`
|
|
99
|
+
|
|
100
|
+
- `get(ctx, key)`: Returns the value or null if missing/expired.
|
|
101
|
+
- `getWithMetadata(ctx, key)`: Returns the value, metadata, and timestamps.
|
|
102
|
+
- `set(ctx, key, value, options?)`: Stores a value. Options: `ttl`, `expiresAt`, `metadata`.
|
|
103
|
+
- `delete(ctx, key)`: Removes a single key.
|
|
104
|
+
- `has(ctx, key)`: Returns boolean existence.
|
|
105
|
+
- `list(ctx, prefix, options?)`: Paginated scan. Options: `limit`, `cursor`, `includeValues`.
|
|
106
|
+
- `getAll(ctx, prefix, options?)`: Fetch all entries under prefix.
|
|
107
|
+
- `deleteAll(ctx, prefix)`: Batched recursive deletion.
|
|
108
|
+
- `withPrefix(prefix, validator?)`: Creates a scoped sub-store.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=_ignore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ignore.d.ts","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_ignore.js","sourceRoot":"","sources":["../../../src/client/_generated/_ignore.ts"],"names":[],"mappings":";AAAA,kEAAkE"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { GenericMutationCtx, GenericQueryCtx, GenericDataModel } from "convex/server";
|
|
2
|
+
import type { Validator } from "convex/values";
|
|
3
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
4
|
+
/**
|
|
5
|
+
* Minimal context types required for the client store to execute operations.
|
|
6
|
+
*/
|
|
7
|
+
export type RunQuery = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
|
|
8
|
+
export type RunMutation = Pick<GenericMutationCtx<GenericDataModel>, "runMutation">;
|
|
9
|
+
/**
|
|
10
|
+
* A client for interacting with the hierarchical Key-Value store.
|
|
11
|
+
*
|
|
12
|
+
* Supports hierarchical keys (e.g., ["users", "123", "profile"]),
|
|
13
|
+
* atomic mutations, and prefix-based range queries.
|
|
14
|
+
*
|
|
15
|
+
* @template V The type of values stored in this specific instance/prefix.
|
|
16
|
+
*/
|
|
17
|
+
export declare class KeyValueStore<V = any> {
|
|
18
|
+
private component;
|
|
19
|
+
private prefix;
|
|
20
|
+
private options;
|
|
21
|
+
constructor(component: ComponentApi, prefix?: string[], options?: {
|
|
22
|
+
validator?: Validator<V, any, any>;
|
|
23
|
+
/**
|
|
24
|
+
* Optional internal type metadata for identification or read-time validation.
|
|
25
|
+
*/
|
|
26
|
+
metadata?: any;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves the value associated with a specific key path.
|
|
30
|
+
*
|
|
31
|
+
* @param ctx Convex Query Context.
|
|
32
|
+
* @param key The relative key path array.
|
|
33
|
+
* @returns The stored value, or null if it doesn't exist or is expired.
|
|
34
|
+
*/
|
|
35
|
+
get(ctx: RunQuery, key: string[]): Promise<V | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the value along with its internal metadata (timestamps, expiration, etc.).
|
|
38
|
+
*
|
|
39
|
+
* @param ctx Convex Query Context.
|
|
40
|
+
* @param key The relative key path array.
|
|
41
|
+
* @returns The full entry object or null.
|
|
42
|
+
*/
|
|
43
|
+
getWithMetadata(ctx: RunQuery, key: string[]): Promise<{
|
|
44
|
+
key: string[];
|
|
45
|
+
value: V;
|
|
46
|
+
metadata?: any;
|
|
47
|
+
updatedAt: number;
|
|
48
|
+
expiresAt?: number;
|
|
49
|
+
} | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Stores a value at the specified key path.
|
|
52
|
+
*
|
|
53
|
+
* This is an atomic "upsert" operation. If a value already exists at this path,
|
|
54
|
+
* it will be overwritten.
|
|
55
|
+
*
|
|
56
|
+
* @param ctx Convex Mutation Context.
|
|
57
|
+
* @param key The relative key path array.
|
|
58
|
+
* @param value The value to store.
|
|
59
|
+
* @param options.ttl Time-To-Live in milliseconds from now.
|
|
60
|
+
* @param options.expiresAt Exact Unix timestamp when the key should expire.
|
|
61
|
+
*/
|
|
62
|
+
set(ctx: RunMutation, key: string[], value: V, options?: {
|
|
63
|
+
metadata?: any;
|
|
64
|
+
ttl?: number;
|
|
65
|
+
expiresAt?: number;
|
|
66
|
+
}): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Permanently removes a single key from the store.
|
|
69
|
+
*/
|
|
70
|
+
delete(ctx: RunMutation, key: string[]): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Quickly determines if a key exists without loading its value into memory.
|
|
73
|
+
* Efficient for existence checks on large blobs.
|
|
74
|
+
*/
|
|
75
|
+
has(ctx: RunQuery, key: string[]): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Scans and returns keys under a specific prefix with pagination support.
|
|
78
|
+
*
|
|
79
|
+
* @param options.includeValues If false, only returns keys and metadata (saves bandwidth).
|
|
80
|
+
* @param options.limit Number of items per page.
|
|
81
|
+
* @param options.cursor Pagination cursor from a previous call.
|
|
82
|
+
*/
|
|
83
|
+
list(ctx: RunQuery, prefix: string[], options?: {
|
|
84
|
+
limit?: number;
|
|
85
|
+
cursor?: string;
|
|
86
|
+
includeValues?: boolean;
|
|
87
|
+
}): Promise<any>;
|
|
88
|
+
/**
|
|
89
|
+
* Fetches all entries under a prefix in a single call.
|
|
90
|
+
* Useful for small-to-medium datasets (up to ~1000 items).
|
|
91
|
+
*/
|
|
92
|
+
getAll(ctx: RunQuery, prefix: string[], options?: {
|
|
93
|
+
includeValues?: boolean;
|
|
94
|
+
}): Promise<any>;
|
|
95
|
+
/**
|
|
96
|
+
* Recursively removes all keys under a specific prefix.
|
|
97
|
+
*
|
|
98
|
+
* For large hierarchies, this operation is automatically batched
|
|
99
|
+
* using the Convex scheduler to prevent timeout errors.
|
|
100
|
+
*/
|
|
101
|
+
deleteAll(ctx: RunMutation, prefix: string[]): Promise<any>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new scoped client for a specific sub-hierarchy.
|
|
104
|
+
*
|
|
105
|
+
* This allows you to treat a prefix like a "table" or "collection".
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const users = kv.withPrefix(["users"]);
|
|
109
|
+
* await users.get(ctx, ["123"]); // Actually gets ["users", "123"]
|
|
110
|
+
*/
|
|
111
|
+
withPrefix<SubV = V>(prefix: string[], validator?: Validator<SubV, any, any>): KeyValueStore<SubV>;
|
|
112
|
+
/** Alias for withPrefix to support various developer naming conventions. */
|
|
113
|
+
subStore: <SubV = V>(prefix: string[], validator?: Validator<SubV, any, any>) => KeyValueStore<SubV>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a client factory that simplifies working with multiple typed prefixes.
|
|
117
|
+
*
|
|
118
|
+
* @param component The Convex Component API reference (usually `components.convexKv`).
|
|
119
|
+
*/
|
|
120
|
+
export declare function kvClientFactory(component: ComponentApi): {
|
|
121
|
+
/**
|
|
122
|
+
* Initializes a KeyValueStore instance for a specific prefix and type.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* const store = kv.use<{ count: number }>(["analytics"]);
|
|
126
|
+
*/
|
|
127
|
+
use<V = any>(prefix?: string[], validator?: Validator<V, any, any>): KeyValueStore<V>;
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MA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|
|
1
|
+
/**
|
|
2
|
+
* A client for interacting with the hierarchical Key-Value store.
|
|
3
|
+
*
|
|
4
|
+
* Supports hierarchical keys (e.g., ["users", "123", "profile"]),
|
|
5
|
+
* atomic mutations, and prefix-based range queries.
|
|
6
|
+
*
|
|
7
|
+
* @template V The type of values stored in this specific instance/prefix.
|
|
8
|
+
*/
|
|
9
|
+
export class KeyValueStore {
|
|
10
|
+
component;
|
|
11
|
+
prefix;
|
|
12
|
+
options;
|
|
13
|
+
constructor(component, prefix = [], options = {}) {
|
|
14
|
+
this.component = component;
|
|
15
|
+
this.prefix = prefix;
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves the value associated with a specific key path.
|
|
20
|
+
*
|
|
21
|
+
* @param ctx Convex Query Context.
|
|
22
|
+
* @param key The relative key path array.
|
|
23
|
+
* @returns The stored value, or null if it doesn't exist or is expired.
|
|
24
|
+
*/
|
|
25
|
+
async get(ctx, key) {
|
|
26
|
+
const result = await this.getWithMetadata(ctx, key);
|
|
27
|
+
return result?.value ?? null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the value along with its internal metadata (timestamps, expiration, etc.).
|
|
31
|
+
*
|
|
32
|
+
* @param ctx Convex Query Context.
|
|
33
|
+
* @param key The relative key path array.
|
|
34
|
+
* @returns The full entry object or null.
|
|
35
|
+
*/
|
|
36
|
+
async getWithMetadata(ctx, key) {
|
|
37
|
+
return (await ctx.runQuery(this.component.kv.get, {
|
|
38
|
+
key: [...this.prefix, ...key],
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Stores a value at the specified key path.
|
|
43
|
+
*
|
|
44
|
+
* This is an atomic "upsert" operation. If a value already exists at this path,
|
|
45
|
+
* it will be overwritten.
|
|
46
|
+
*
|
|
47
|
+
* @param ctx Convex Mutation Context.
|
|
48
|
+
* @param key The relative key path array.
|
|
49
|
+
* @param value The value to store.
|
|
50
|
+
* @param options.ttl Time-To-Live in milliseconds from now.
|
|
51
|
+
* @param options.expiresAt Exact Unix timestamp when the key should expire.
|
|
52
|
+
*/
|
|
53
|
+
async set(ctx, key, value, options = {}) {
|
|
54
|
+
// Note: If you provided a validator at initialization, it should be checked here.
|
|
55
|
+
if (this.options.validator) {
|
|
56
|
+
// In a production environment, you might use a runtime check here.
|
|
57
|
+
}
|
|
58
|
+
await ctx.runMutation(this.component.kv.set, {
|
|
59
|
+
key: [...this.prefix, ...key],
|
|
60
|
+
value,
|
|
61
|
+
metadata: options.metadata ?? this.options.metadata,
|
|
62
|
+
ttl: options.ttl,
|
|
63
|
+
expiresAt: options.expiresAt,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Permanently removes a single key from the store.
|
|
68
|
+
*/
|
|
69
|
+
async delete(ctx, key) {
|
|
70
|
+
await ctx.runMutation(this.component.kv.remove, {
|
|
71
|
+
key: [...this.prefix, ...key],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Quickly determines if a key exists without loading its value into memory.
|
|
76
|
+
* Efficient for existence checks on large blobs.
|
|
77
|
+
*/
|
|
78
|
+
async has(ctx, key) {
|
|
79
|
+
return await ctx.runQuery(this.component.kv.has, {
|
|
80
|
+
key: [...this.prefix, ...key],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Scans and returns keys under a specific prefix with pagination support.
|
|
85
|
+
*
|
|
86
|
+
* @param options.includeValues If false, only returns keys and metadata (saves bandwidth).
|
|
87
|
+
* @param options.limit Number of items per page.
|
|
88
|
+
* @param options.cursor Pagination cursor from a previous call.
|
|
89
|
+
*/
|
|
90
|
+
async list(ctx, prefix, options = {}) {
|
|
91
|
+
return await ctx.runQuery(this.component.kv.list, {
|
|
92
|
+
prefix: [...this.prefix, ...prefix],
|
|
93
|
+
...options,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Fetches all entries under a prefix in a single call.
|
|
98
|
+
* Useful for small-to-medium datasets (up to ~1000 items).
|
|
99
|
+
*/
|
|
100
|
+
async getAll(ctx, prefix, options = {}) {
|
|
101
|
+
return await ctx.runQuery(this.component.kv.getAll, {
|
|
102
|
+
prefix: [...this.prefix, ...prefix],
|
|
103
|
+
...options,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Recursively removes all keys under a specific prefix.
|
|
108
|
+
*
|
|
109
|
+
* For large hierarchies, this operation is automatically batched
|
|
110
|
+
* using the Convex scheduler to prevent timeout errors.
|
|
111
|
+
*/
|
|
112
|
+
async deleteAll(ctx, prefix) {
|
|
113
|
+
return await ctx.runMutation(this.component.kv.deleteAll, {
|
|
114
|
+
prefix: [...this.prefix, ...prefix],
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new scoped client for a specific sub-hierarchy.
|
|
119
|
+
*
|
|
120
|
+
* This allows you to treat a prefix like a "table" or "collection".
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* const users = kv.withPrefix(["users"]);
|
|
124
|
+
* await users.get(ctx, ["123"]); // Actually gets ["users", "123"]
|
|
125
|
+
*/
|
|
126
|
+
withPrefix(prefix, validator) {
|
|
127
|
+
return new KeyValueStore(this.component, [...this.prefix, ...prefix], {
|
|
128
|
+
validator: validator ?? this.options.validator,
|
|
129
|
+
metadata: this.options.metadata,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** Alias for withPrefix to support various developer naming conventions. */
|
|
133
|
+
subStore = this.withPrefix;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Creates a client factory that simplifies working with multiple typed prefixes.
|
|
137
|
+
*
|
|
138
|
+
* @param component The Convex Component API reference (usually `components.convexKv`).
|
|
139
|
+
*/
|
|
140
|
+
export function kvClientFactory(component) {
|
|
141
|
+
return {
|
|
142
|
+
/**
|
|
143
|
+
* Initializes a KeyValueStore instance for a specific prefix and type.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* const store = kv.use<{ count: number }>(["analytics"]);
|
|
147
|
+
*/
|
|
148
|
+
use(prefix = [], validator) {
|
|
149
|
+
return new KeyValueStore(component, prefix, { validator });
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAkBA;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IAEd;IACA;IACA;IAHV,YACU,SAAuB,EACvB,SAAmB,EAAE,EACrB,UAMJ,EAAE;QARE,cAAS,GAAT,SAAS,CAAc;QACvB,WAAM,GAAN,MAAM,CAAe;QACrB,YAAO,GAAP,OAAO,CAMT;IACJ,CAAC;IAEL;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,CAAC,GAAa,EAAE,GAAa;QACpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACpD,OAAO,MAAM,EAAE,KAAK,IAAI,IAAI,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,GAAa,EAAE,GAAa;QAChD,OAAO,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE;YAChD,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;SAC9B,CAAC,CAA8F,CAAC;IACnG,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,GAAG,CACP,GAAgB,EAChB,GAAa,EACb,KAAQ,EACR,UAAgE,EAAE;QAElE,kFAAkF;QAClF,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;Y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
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type * as kv from "../kv.js";
|
|
10
|
+
import type { ApiFromModules, FilterApi, FunctionReference } from "convex/server";
|
|
11
|
+
declare const fullApi: ApiFromModules<{
|
|
12
|
+
kv: typeof kv;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```js
|
|
19
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const api: FilterApi<typeof fullApi, FunctionReference<any, "public">>;
|
|
23
|
+
/**
|
|
24
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
* ```js
|
|
28
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const internal: FilterApi<typeof fullApi, FunctionReference<any, "internal">>;
|
|
32
|
+
export declare const components: {};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EAClB,MAAM,eAAe,CAAC;AAGvB,QAAA,MAAM,OAAO,EAAE,cAAc,CAAC;IAC5B,EAAE,EAAE,OAAO,EAAE,CAAC;CACf,CAAiB,CAAC;AAEnB;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,SAAS,CACzB,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,QAAQ,CAAC,CACjB,CAAC;AAElB;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,SAAS,CAC9B,OAAO,OAAO,EACd,iBAAiB,CAAC,GAAG,EAAE,UAAU,CAAC,CACnB,CAAC;AAElB,eAAO,MAAM,UAAU,EAAqC,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
11
|
+
const fullApi = anyApi;
|
|
12
|
+
/**
|
|
13
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```js
|
|
17
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const api = anyApi;
|
|
21
|
+
/**
|
|
22
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
23
|
+
*
|
|
24
|
+
* Usage:
|
|
25
|
+
* ```js
|
|
26
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const internal = anyApi;
|
|
30
|
+
export const components = componentsGeneric();
|
|
31
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/component/_generated/api.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AASH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,OAAO,GAER,MAAa,CAAC;AAEnB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAGZ,MAAa,CAAC;AAElB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAGjB,MAAa,CAAC;AAElB,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAmB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated `ComponentApi` utility.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { FunctionReference } from "convex/server";
|
|
10
|
+
/**
|
|
11
|
+
* A utility for referencing a Convex component's exposed API.
|
|
12
|
+
*
|
|
13
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```ts
|
|
16
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
17
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> = {
|
|
22
|
+
kv: {
|
|
23
|
+
deleteAll: FunctionReference<"mutation", "internal", {
|
|
24
|
+
prefix: Array<string>;
|
|
25
|
+
}, any, Name>;
|
|
26
|
+
get: FunctionReference<"query", "internal", {
|
|
27
|
+
key: Array<string>;
|
|
28
|
+
}, null | {
|
|
29
|
+
expiresAt?: number;
|
|
30
|
+
key: Array<string>;
|
|
31
|
+
metadata?: any;
|
|
32
|
+
updatedAt: number;
|
|
33
|
+
value: any;
|
|
34
|
+
}, Name>;
|
|
35
|
+
getAll: FunctionReference<"query", "internal", {
|
|
36
|
+
includeValues?: boolean;
|
|
37
|
+
prefix: Array<string>;
|
|
38
|
+
}, any, Name>;
|
|
39
|
+
has: FunctionReference<"query", "internal", {
|
|
40
|
+
key: Array<string>;
|
|
41
|
+
}, boolean, Name>;
|
|
42
|
+
list: FunctionReference<"query", "internal", {
|
|
43
|
+
cursor?: string;
|
|
44
|
+
includeValues?: boolean;
|
|
45
|
+
limit?: number;
|
|
46
|
+
prefix: Array<string>;
|
|
47
|
+
}, any, Name>;
|
|
48
|
+
remove: FunctionReference<"mutation", "internal", {
|
|
49
|
+
key: Array<string>;
|
|
50
|
+
}, null, Name>;
|
|
51
|
+
set: FunctionReference<"mutation", "internal", {
|
|
52
|
+
expiresAt?: number;
|
|
53
|
+
key: Array<string>;
|
|
54
|
+
metadata?: any;
|
|
55
|
+
ttl?: number;
|
|
56
|
+
value: any;
|
|
57
|
+
}, null, Name>;
|
|
58
|
+
vacuum: FunctionReference<"mutation", "internal", {}, any, Name>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,IAC3E;IACE,EAAE,EAAE;QACF,SAAS,EAAE,iBAAiB,CAC1B,UAAU,EACV,UAAU,EACV;YAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;SAAE,EACzB,GAAG,EACH,IAAI,CACL,CAAC;QACF,GAAG,EAAE,iBAAiB,CACpB,OAAO,EACP,UAAU,EACV;YAAE,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;SAAE,EACtB,IAAI,GAAG;YACL,SAAS,CAAC,EAAE,MAAM,CAAC;YACnB,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACnB,QAAQ,CAAC,EAAE,GAAG,CAAC;YACf,SAAS,EAAE,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oot":"","sources":["../../../src/component/_generated/component.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated data model types.
|
|
3
|
+
*
|
|
4
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
5
|
+
*
|
|
6
|
+
* To regenerate, run `npx convex dev`.
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { DataModelFromSchemaDefinition, DocumentByName, TableNamesInDataModel, SystemTableNames } from "convex/server";
|
|
10
|
+
import type { GenericId } from "convex/values";
|
|
11
|
+
import schema from "../schema.js";
|
|
12
|
+
/**
|
|
13
|
+
* The names of all of your Convex tables.
|
|
14
|
+
*/
|
|
15
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
16
|
+
/**
|
|
17
|
+
* The type of a document stored in Convex.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
20
|
+
*/
|
|
21
|
+
export type Doc<TableName extends TableNames> = DocumentByName<DataModel, TableName>;
|
|
22
|
+
/**
|
|
23
|
+
* An identifier for a document in Convex.
|
|
24
|
+
*
|
|
25
|
+
* Convex documents are uniquely identified by their `Id`, which is accessible
|
|
26
|
+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
|
|
27
|
+
*
|
|
28
|
+
* Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
|
|
29
|
+
*
|
|
30
|
+
* IDs are just strings at runtime, but this type can be used to distinguish them from other
|
|
31
|
+
* strings when type checking.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
34
|
+
*/
|
|
35
|
+
export type Id<TableName extends TableNames | SystemTableNames> = GenericId<TableName>;
|
|
36
|
+
/**
|
|
37
|
+
* A type describing your Convex data model.
|
|
38
|
+
*
|
|
39
|
+
* This type includes information about what tables you have, the type of
|
|
40
|
+
* documents stored in those tables, and the indexes defined on them.
|
|
41
|
+
*
|
|
42
|
+
* This type is used to parameterize methods like `queryGeneric` and
|
|
43
|
+
* `mutationGeneric` to make them type-safe.
|
|
44
|
+
*/
|
|
45
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
|
|
46
|
+
//# sourceMappingURL=dataModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataModel.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,6BAA6B,EAC7B,cAAc,EACd,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAE1D;;;;GAIG;AACH,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,UAAU,IAAI,cAAc,CAC5D,SAAS,EACT,SAAS,CACV,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,EAAE,CAAC,SAAS,SAAS,UAAU,GAAG,gBAAgB,IAC5D,SAAS,CAAC,SAAS,CAAC,CAAC;AAEvB;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,6BAA6B,CAAC,OAAO,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataModel.js","sourceRoot":"","sources":["../../../src/component/_generated/dataModel.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AASH,OAAO,MAAM,MAAM,cAAc,CAAC"}
|