@convex-dev/sharded-counter 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 +201 -0
- package/README.md +246 -0
- package/dist/commonjs/client/index.d.ts +37 -0
- package/dist/commonjs/client/index.d.ts.map +1 -0
- package/dist/commonjs/client/index.js +30 -0
- package/dist/commonjs/client/index.js.map +1 -0
- package/dist/commonjs/component/_generated/api.d.ts +14 -0
- package/dist/commonjs/component/_generated/api.d.ts.map +1 -0
- package/dist/commonjs/component/_generated/api.js +24 -0
- package/dist/commonjs/component/_generated/api.js.map +1 -0
- package/dist/commonjs/component/_generated/server.d.ts +64 -0
- package/dist/commonjs/component/_generated/server.d.ts.map +1 -0
- package/dist/commonjs/component/_generated/server.js +76 -0
- package/dist/commonjs/component/_generated/server.js.map +1 -0
- package/dist/commonjs/component/convex.config.d.ts +3 -0
- package/dist/commonjs/component/convex.config.d.ts.map +1 -0
- package/dist/commonjs/component/convex.config.js +3 -0
- package/dist/commonjs/component/convex.config.js.map +1 -0
- package/dist/commonjs/component/public.d.ts +10 -0
- package/dist/commonjs/component/public.d.ts.map +1 -0
- package/dist/commonjs/component/public.js +42 -0
- package/dist/commonjs/component/public.js.map +1 -0
- package/dist/commonjs/component/schema.d.ts +15 -0
- package/dist/commonjs/component/schema.d.ts.map +1 -0
- package/dist/commonjs/component/schema.js +10 -0
- package/dist/commonjs/component/schema.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/client/index.d.ts +37 -0
- package/dist/esm/client/index.d.ts.map +1 -0
- package/dist/esm/client/index.js +30 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/component/_generated/api.d.ts +14 -0
- package/dist/esm/component/_generated/api.d.ts.map +1 -0
- package/dist/esm/component/_generated/api.js +24 -0
- package/dist/esm/component/_generated/api.js.map +1 -0
- package/dist/esm/component/_generated/server.d.ts +64 -0
- package/dist/esm/component/_generated/server.d.ts.map +1 -0
- package/dist/esm/component/_generated/server.js +76 -0
- package/dist/esm/component/_generated/server.js.map +1 -0
- package/dist/esm/component/convex.config.d.ts +3 -0
- package/dist/esm/component/convex.config.d.ts.map +1 -0
- package/dist/esm/component/convex.config.js +3 -0
- package/dist/esm/component/convex.config.js.map +1 -0
- package/dist/esm/component/public.d.ts +10 -0
- package/dist/esm/component/public.d.ts.map +1 -0
- package/dist/esm/component/public.js +42 -0
- package/dist/esm/component/public.js.map +1 -0
- package/dist/esm/component/schema.d.ts +15 -0
- package/dist/esm/component/schema.d.ts.map +1 -0
- package/dist/esm/component/schema.js +10 -0
- package/dist/esm/component/schema.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/package.json +76 -0
- package/src/client/index.ts +82 -0
- package/src/component/_generated/api.d.ts +58 -0
- package/src/component/_generated/api.js +27 -0
- package/src/component/_generated/dataModel.d.ts +64 -0
- package/src/component/_generated/server.d.ts +153 -0
- package/src/component/_generated/server.js +94 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/counter.test.ts +45 -0
- package/src/component/public.ts +43 -0
- package/src/component/schema.ts +10 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* prettier-ignore-start */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
5
|
+
*
|
|
6
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
7
|
+
*
|
|
8
|
+
* To regenerate, run `npx convex dev`.
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { actionGeneric, httpActionGeneric, queryGeneric, mutationGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, componentsGeneric, } from "convex/server";
|
|
12
|
+
/**
|
|
13
|
+
* Define a query in this Convex app's public API.
|
|
14
|
+
*
|
|
15
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
16
|
+
*
|
|
17
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
18
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
19
|
+
*/
|
|
20
|
+
export const query = queryGeneric;
|
|
21
|
+
/**
|
|
22
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
23
|
+
*
|
|
24
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
25
|
+
*
|
|
26
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
27
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
28
|
+
*/
|
|
29
|
+
export const internalQuery = internalQueryGeneric;
|
|
30
|
+
/**
|
|
31
|
+
* Define a mutation in this Convex app's public API.
|
|
32
|
+
*
|
|
33
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
34
|
+
*
|
|
35
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
36
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
37
|
+
*/
|
|
38
|
+
export const mutation = mutationGeneric;
|
|
39
|
+
/**
|
|
40
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
41
|
+
*
|
|
42
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
43
|
+
*
|
|
44
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
45
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
46
|
+
*/
|
|
47
|
+
export const internalMutation = internalMutationGeneric;
|
|
48
|
+
/**
|
|
49
|
+
* Define an action in this Convex app's public API.
|
|
50
|
+
*
|
|
51
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
52
|
+
* code and code with side-effects, like calling third-party services.
|
|
53
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
54
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
55
|
+
*
|
|
56
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
57
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
58
|
+
*/
|
|
59
|
+
export const action = actionGeneric;
|
|
60
|
+
/**
|
|
61
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
62
|
+
*
|
|
63
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
64
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
65
|
+
*/
|
|
66
|
+
export const internalAction = internalActionGeneric;
|
|
67
|
+
/**
|
|
68
|
+
* Define a Convex HTTP action.
|
|
69
|
+
*
|
|
70
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
|
|
71
|
+
* as its second.
|
|
72
|
+
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
|
|
73
|
+
*/
|
|
74
|
+
export const httpAction = httpActionGeneric;
|
|
75
|
+
/* prettier-ignore-end */
|
|
76
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,oBAAoB;AACpB;;;;;;;GAOG;AAEH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE5C,yBAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../../src/component/convex.config.ts"],"names":[],"mappings":";AAEA,wBAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex.config.js","sourceRoot":"","sources":["../../../src/component/convex.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAe,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DEFAULT_SHARD_COUNT = 16;
|
|
2
|
+
export declare const add: import("convex/server").RegisteredMutation<"public", {
|
|
3
|
+
shards?: number | undefined;
|
|
4
|
+
name: string;
|
|
5
|
+
count: number;
|
|
6
|
+
}, Promise<void>>;
|
|
7
|
+
export declare const count: import("convex/server").RegisteredQuery<"public", {
|
|
8
|
+
name: string;
|
|
9
|
+
}, Promise<number>>;
|
|
10
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/component/public.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,eAAO,MAAM,GAAG;;;;iBAyBd,CAAC;AAEH,eAAO,MAAM,KAAK;;mBAUhB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server";
|
|
3
|
+
export const DEFAULT_SHARD_COUNT = 16;
|
|
4
|
+
export const add = mutation({
|
|
5
|
+
args: {
|
|
6
|
+
name: v.string(),
|
|
7
|
+
count: v.number(),
|
|
8
|
+
shards: v.optional(v.number()),
|
|
9
|
+
},
|
|
10
|
+
returns: v.null(),
|
|
11
|
+
handler: async (ctx, args) => {
|
|
12
|
+
const shard = Math.floor(Math.random() * (args.shards ?? DEFAULT_SHARD_COUNT));
|
|
13
|
+
const counter = await ctx.db
|
|
14
|
+
.query("counters")
|
|
15
|
+
.withIndex("name", (q) => q.eq("name", args.name).eq("shard", shard))
|
|
16
|
+
.unique();
|
|
17
|
+
if (counter) {
|
|
18
|
+
await ctx.db.patch(counter._id, {
|
|
19
|
+
value: counter.value + args.count,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await ctx.db.insert("counters", {
|
|
24
|
+
name: args.name,
|
|
25
|
+
value: args.count,
|
|
26
|
+
shard,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
export const count = query({
|
|
32
|
+
args: { name: v.string() },
|
|
33
|
+
returns: v.number(),
|
|
34
|
+
handler: async (ctx, args) => {
|
|
35
|
+
const counters = await ctx.db
|
|
36
|
+
.query("counters")
|
|
37
|
+
.withIndex("name", (q) => q.eq("name", args.name))
|
|
38
|
+
.collect();
|
|
39
|
+
return counters.reduce((sum, counter) => sum + counter.value, 0);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=public.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/component/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC,MA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EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE;aAC1B,KAAK,CAAC,UAAU,CAAC;aACjB,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aACjD,OAAO,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const _default: import("convex/server").SchemaDefinition<{
|
|
2
|
+
counters: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
3
|
+
name: string;
|
|
4
|
+
value: number;
|
|
5
|
+
shard: number;
|
|
6
|
+
}, {
|
|
7
|
+
name: import("convex/values").VString<string, "required">;
|
|
8
|
+
value: import("convex/values").VFloat64<number, "required">;
|
|
9
|
+
shard: import("convex/values").VFloat64<number, "required">;
|
|
10
|
+
}, "required", "name" | "value" | "shard">, {
|
|
11
|
+
name: ["name", "shard", "_creationTime"];
|
|
12
|
+
}, {}, {}>;
|
|
13
|
+
}, true>;
|
|
14
|
+
export default _default;
|
|
15
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,wBAMG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export default defineSchema({
|
|
4
|
+
counters: defineTable({
|
|
5
|
+
name: v.string(),
|
|
6
|
+
value: v.number(),
|
|
7
|
+
shard: v.number(),
|
|
8
|
+
}).index("name", ["name", "shard"]),
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,eAAe,YAAY,CAAC;IAC1B,QAAQ,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
|
|
2
|
+
import { GenericId } from "convex/values";
|
|
3
|
+
import { api } from "../component/_generated/api";
|
|
4
|
+
export declare class ShardedCounter<Shards extends Record<string, number>> {
|
|
5
|
+
component: UseApi<typeof api>;
|
|
6
|
+
options?: {
|
|
7
|
+
shards?: Shards | undefined;
|
|
8
|
+
defaultShards?: number | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
constructor(component: UseApi<typeof api>, options?: {
|
|
11
|
+
shards?: Shards | undefined;
|
|
12
|
+
defaultShards?: number | undefined;
|
|
13
|
+
} | undefined);
|
|
14
|
+
add<Name extends string = keyof Shards & string>(ctx: RunMutationCtx, name: Name, count?: number): Promise<null>;
|
|
15
|
+
count<Name extends string = keyof Shards & string>(ctx: RunQueryCtx, name: Name): Promise<number>;
|
|
16
|
+
for<Name extends string = keyof Shards & string>(name: Name): {
|
|
17
|
+
add: (ctx: RunMutationCtx, count?: number) => Promise<null>;
|
|
18
|
+
subtract: (ctx: RunMutationCtx, count?: number) => Promise<null>;
|
|
19
|
+
inc: (ctx: RunMutationCtx) => Promise<null>;
|
|
20
|
+
dec: (ctx: RunMutationCtx) => Promise<null>;
|
|
21
|
+
count: (ctx: RunQueryCtx) => Promise<number>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
type RunQueryCtx = {
|
|
25
|
+
runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
|
|
26
|
+
};
|
|
27
|
+
type RunMutationCtx = {
|
|
28
|
+
runMutation: GenericMutationCtx<GenericDataModel>["runMutation"];
|
|
29
|
+
};
|
|
30
|
+
export type OpaqueIds<T> = T extends GenericId<infer _T> ? string : T extends (infer U)[] ? OpaqueIds<U>[] : T extends object ? {
|
|
31
|
+
[K in keyof T]: OpaqueIds<T[K]>;
|
|
32
|
+
} : T;
|
|
33
|
+
export type UseApi<API> = Expand<{
|
|
34
|
+
[mod in keyof API]: API[mod] extends FunctionReference<infer FType, "public", infer FArgs, infer FReturnType, infer FComponentPath> ? FunctionReference<FType, "internal", OpaqueIds<FArgs>, OpaqueIds<FReturnType>, FComponentPath> : UseApi<API[mod]>;
|
|
35
|
+
}>;
|
|
36
|
+
export {};
|
|
37
|
+
//# 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,EACL,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAElD,qBAAa,cAAc,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAEtD,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,CAAC;IAC7B,OAAO,CAAC;;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AW,EACjB,MAAM,cAAc,CACrB,GACG,iBAAiB,CACf,KAAK,EACL,UAAU,EACV,SAAS,CAAC,KAAK,CAAC,EAChB,SAAS,CAAC,WAAW,CAAC,EACtB,cAAc,CACf,GACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class ShardedCounter {
|
|
2
|
+
component;
|
|
3
|
+
options;
|
|
4
|
+
constructor(component, options) {
|
|
5
|
+
this.component = component;
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
async add(ctx, name, count = 1) {
|
|
9
|
+
const shards = this.options?.shards?.[name] ?? this.options?.defaultShards;
|
|
10
|
+
return ctx.runMutation(this.component.public.add, {
|
|
11
|
+
name,
|
|
12
|
+
count,
|
|
13
|
+
shards,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
async count(ctx, name) {
|
|
17
|
+
return ctx.runQuery(this.component.public.count, { name });
|
|
18
|
+
}
|
|
19
|
+
// Another way of exporting functionality
|
|
20
|
+
for(name) {
|
|
21
|
+
return {
|
|
22
|
+
add: async (ctx, count = 1) => this.add(ctx, name, count),
|
|
23
|
+
subtract: async (ctx, count = 1) => this.add(ctx, name, -count),
|
|
24
|
+
inc: async (ctx) => this.add(ctx, name, 1),
|
|
25
|
+
dec: async (ctx) => this.add(ctx, name, -1),
|
|
26
|
+
count: async (ctx) => this.count(ctx, name),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,cAAc;IAEhB;IACA;IAFT,YACS,SAA6B,EAC7B,OAAqD;QADrD,cAAS,GAAT,SAAS,CAAoB;QAC7B,YAAO,GAAP,OAAO,CAA8C;IAC3D,CAAC;I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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility for referencing Convex functions in your app's API.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* ```js
|
|
6
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export const api: import("convex/server").AnyApi;
|
|
10
|
+
export const internal: import("convex/server").AnyApi;
|
|
11
|
+
export const components: {
|
|
12
|
+
[x: string]: import("../../../node_modules/convex/dist/esm-types/server/components").AnyComponentReference;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAcA;;;;;;;GAOG;AACH,iDAA0B;AAC1B,sDAA+B;AAC/B;;EAA8C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* prettier-ignore-start */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Generated `api` utility.
|
|
5
|
+
*
|
|
6
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
7
|
+
*
|
|
8
|
+
* To regenerate, run `npx convex dev`.
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
12
|
+
/**
|
|
13
|
+
* A utility for referencing Convex functions in your app's API.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```js
|
|
17
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const api = anyApi;
|
|
21
|
+
export const internal = anyApi;
|
|
22
|
+
export const components = componentsGeneric();
|
|
23
|
+
/* prettier-ignore-end */
|
|
24
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,oBAAoB;AACpB;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC;AAC1B,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAE,CAAC;AAE9C,yBAAyB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define a query in this Convex app's public API.
|
|
3
|
+
*
|
|
4
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
5
|
+
*
|
|
6
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
7
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
8
|
+
*/
|
|
9
|
+
export const query: import("convex/server").QueryBuilder<any, "public">;
|
|
10
|
+
/**
|
|
11
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
12
|
+
*
|
|
13
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
14
|
+
*
|
|
15
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
16
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
17
|
+
*/
|
|
18
|
+
export const internalQuery: import("convex/server").QueryBuilder<any, "internal">;
|
|
19
|
+
/**
|
|
20
|
+
* Define a mutation in this Convex app's public API.
|
|
21
|
+
*
|
|
22
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
23
|
+
*
|
|
24
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
25
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
26
|
+
*/
|
|
27
|
+
export const mutation: import("convex/server").MutationBuilder<any, "public">;
|
|
28
|
+
/**
|
|
29
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
30
|
+
*
|
|
31
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
32
|
+
*
|
|
33
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
34
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
35
|
+
*/
|
|
36
|
+
export const internalMutation: import("convex/server").MutationBuilder<any, "internal">;
|
|
37
|
+
/**
|
|
38
|
+
* Define an action in this Convex app's public API.
|
|
39
|
+
*
|
|
40
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
41
|
+
* code and code with side-effects, like calling third-party services.
|
|
42
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
43
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
44
|
+
*
|
|
45
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
46
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
47
|
+
*/
|
|
48
|
+
export const action: import("convex/server").ActionBuilder<any, "public">;
|
|
49
|
+
/**
|
|
50
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
51
|
+
*
|
|
52
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
53
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
54
|
+
*/
|
|
55
|
+
export const internalAction: import("convex/server").ActionBuilder<any, "internal">;
|
|
56
|
+
/**
|
|
57
|
+
* Define a Convex HTTP action.
|
|
58
|
+
*
|
|
59
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
|
|
60
|
+
* as its second.
|
|
61
|
+
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
|
|
62
|
+
*/
|
|
63
|
+
export const httpAction: (func: (ctx: import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, request: Request) => Promise<Response>) => import("convex/server").PublicHttpAction;
|
|
64
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAuBA;;;;;;;GAOG;AACH,wEAAkC;AAElC;;;;;;;GAOG;AACH,kFAAkD;AAElD;;;;;;;GAOG;AACH,8EAAwC;AAExC;;;;;;;GAOG;AACH,wFAAwD;AAExD;;;;;;;;;;GAUG;AACH,0EAAoC;AAEpC;;;;;GAKG;AACH,oFAAoD;AAEpD;;;;;;GAMG;AACH,8MAA4C"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* prettier-ignore-start */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
5
|
+
*
|
|
6
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
7
|
+
*
|
|
8
|
+
* To regenerate, run `npx convex dev`.
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { actionGeneric, httpActionGeneric, queryGeneric, mutationGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, componentsGeneric, } from "convex/server";
|
|
12
|
+
/**
|
|
13
|
+
* Define a query in this Convex app's public API.
|
|
14
|
+
*
|
|
15
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
16
|
+
*
|
|
17
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
18
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
19
|
+
*/
|
|
20
|
+
export const query = queryGeneric;
|
|
21
|
+
/**
|
|
22
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
23
|
+
*
|
|
24
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
25
|
+
*
|
|
26
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
27
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
28
|
+
*/
|
|
29
|
+
export const internalQuery = internalQueryGeneric;
|
|
30
|
+
/**
|
|
31
|
+
* Define a mutation in this Convex app's public API.
|
|
32
|
+
*
|
|
33
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
34
|
+
*
|
|
35
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
36
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
37
|
+
*/
|
|
38
|
+
export const mutation = mutationGeneric;
|
|
39
|
+
/**
|
|
40
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
41
|
+
*
|
|
42
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
43
|
+
*
|
|
44
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
45
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
46
|
+
*/
|
|
47
|
+
export const internalMutation = internalMutationGeneric;
|
|
48
|
+
/**
|
|
49
|
+
* Define an action in this Convex app's public API.
|
|
50
|
+
*
|
|
51
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
52
|
+
* code and code with side-effects, like calling third-party services.
|
|
53
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
54
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
55
|
+
*
|
|
56
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
57
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
58
|
+
*/
|
|
59
|
+
export const action = actionGeneric;
|
|
60
|
+
/**
|
|
61
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
62
|
+
*
|
|
63
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
64
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
65
|
+
*/
|
|
66
|
+
export const internalAction = internalActionGeneric;
|
|
67
|
+
/**
|
|
68
|
+
* Define a Convex HTTP action.
|
|
69
|
+
*
|
|
70
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
|
|
71
|
+
* as its second.
|
|
72
|
+
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
|
|
73
|
+
*/
|
|
74
|
+
export const httpAction = httpActionGeneric;
|
|
75
|
+
/* prettier-ignore-end */
|
|
76
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,oBAAoB;AACpB;;;;;;;GAOG;AAEH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE5C,yBAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../../src/component/convex.config.ts"],"names":[],"mappings":";AAEA,wBAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convex.config.js","sourceRoot":"","sources":["../../../src/component/convex.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAe,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DEFAULT_SHARD_COUNT = 16;
|
|
2
|
+
export declare const add: import("convex/server").RegisteredMutation<"public", {
|
|
3
|
+
shards?: number | undefined;
|
|
4
|
+
name: string;
|
|
5
|
+
count: number;
|
|
6
|
+
}, Promise<void>>;
|
|
7
|
+
export declare const count: import("convex/server").RegisteredQuery<"public", {
|
|
8
|
+
name: string;
|
|
9
|
+
}, Promise<number>>;
|
|
10
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/component/public.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,eAAO,MAAM,GAAG;;;;iBAyBd,CAAC;AAEH,eAAO,MAAM,KAAK;;mBAUhB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { mutation, query } from "./_generated/server";
|
|
3
|
+
export const DEFAULT_SHARD_COUNT = 16;
|
|
4
|
+
export const add = mutation({
|
|
5
|
+
args: {
|
|
6
|
+
name: v.string(),
|
|
7
|
+
count: v.number(),
|
|
8
|
+
shards: v.optional(v.number()),
|
|
9
|
+
},
|
|
10
|
+
returns: v.null(),
|
|
11
|
+
handler: async (ctx, args) => {
|
|
12
|
+
const shard = Math.floor(Math.random() * (args.shards ?? DEFAULT_SHARD_COUNT));
|
|
13
|
+
const counter = await ctx.db
|
|
14
|
+
.query("counters")
|
|
15
|
+
.withIndex("name", (q) => q.eq("name", args.name).eq("shard", shard))
|
|
16
|
+
.unique();
|
|
17
|
+
if (counter) {
|
|
18
|
+
await ctx.db.patch(counter._id, {
|
|
19
|
+
value: counter.value + args.count,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await ctx.db.insert("counters", {
|
|
24
|
+
name: args.name,
|
|
25
|
+
value: args.count,
|
|
26
|
+
shard,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
export const count = query({
|
|
32
|
+
args: { name: v.string() },
|
|
33
|
+
returns: v.number(),
|
|
34
|
+
handler: async (ctx, args) => {
|
|
35
|
+
const counters = await ctx.db
|
|
36
|
+
.query("counters")
|
|
37
|
+
.withIndex("name", (q) => q.eq("name", args.name))
|
|
38
|
+
.collect();
|
|
39
|
+
return counters.reduce((sum, counter) => sum + counter.value, 0);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=public.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.js","sourceRoot":"","sources":["../../../src/component/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KAC/B;IACD,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE;IACjB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CA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,EAAE,OAAO,EAAE,EAAE,CAAC,GAAG,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const _default: import("convex/server").SchemaDefinition<{
|
|
2
|
+
counters: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
3
|
+
name: string;
|
|
4
|
+
value: number;
|
|
5
|
+
shard: number;
|
|
6
|
+
}, {
|
|
7
|
+
name: import("convex/values").VString<string, "required">;
|
|
8
|
+
value: import("convex/values").VFloat64<number, "required">;
|
|
9
|
+
shard: import("convex/values").VFloat64<number, "required">;
|
|
10
|
+
}, "required", "name" | "value" | "shard">, {
|
|
11
|
+
name: ["name", "shard", "_creationTime"];
|
|
12
|
+
}, {}, {}>;
|
|
13
|
+
}, true>;
|
|
14
|
+
export default _default;
|
|
15
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,wBAMG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
export default defineSchema({
|
|
4
|
+
counters: defineTable({
|
|
5
|
+
name: v.string(),
|
|
6
|
+
value: v.number(),
|
|
7
|
+
shard: v.number(),
|
|
8
|
+
}).index("name", ["name", "shard"]),
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,eAAe,YAAY,CAAC;IAC1B,QAAQ,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC,CAAC"}
|