@convex-dev/agent 0.1.0 → 0.1.1-alpha.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/dist/commonjs/component/files.d.ts +18 -4
- package/dist/commonjs/component/files.d.ts.map +1 -1
- package/dist/commonjs/component/files.js +49 -5
- package/dist/commonjs/component/files.js.map +1 -1
- package/dist/commonjs/deltaStreaming.d.ts +2 -0
- package/dist/commonjs/deltaStreaming.d.ts.map +1 -0
- package/dist/commonjs/deltaStreaming.js +2 -0
- package/dist/commonjs/deltaStreaming.js.map +1 -0
- package/dist/esm/component/files.d.ts +18 -4
- package/dist/esm/component/files.d.ts.map +1 -1
- package/dist/esm/component/files.js +49 -5
- package/dist/esm/component/files.js.map +1 -1
- package/dist/esm/deltaStreaming.d.ts +2 -0
- package/dist/esm/deltaStreaming.d.ts.map +1 -0
- package/dist/esm/deltaStreaming.js +2 -0
- package/dist/esm/deltaStreaming.js.map +1 -0
- package/package.json +1 -1
- package/src/component/_generated/api.d.ts +5 -4
- package/src/component/files.ts +50 -5
- package/src/deltaStreaming.ts +1 -0
|
@@ -3,15 +3,29 @@ import { Id } from "./_generated/dataModel.js";
|
|
|
3
3
|
export declare const addFile: import("convex/server").RegisteredMutation<"public", {
|
|
4
4
|
storageId: string;
|
|
5
5
|
hash: string;
|
|
6
|
-
}, Promise<
|
|
6
|
+
}, Promise<{
|
|
7
|
+
fileId: import("convex/values").GenericId<"files">;
|
|
8
|
+
storageIdUnused: boolean;
|
|
9
|
+
}>>;
|
|
7
10
|
export declare function addFileHandler(ctx: MutationCtx, args: {
|
|
8
11
|
storageId: string;
|
|
9
12
|
hash: string;
|
|
10
|
-
}): Promise<
|
|
11
|
-
|
|
13
|
+
}): Promise<{
|
|
14
|
+
fileId: import("convex/values").GenericId<"files">;
|
|
15
|
+
storageIdUnused: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* If you plan to have the same file added over and over without a reference to
|
|
19
|
+
* the fileId, you can use this query to get the fileId of the existing file.
|
|
20
|
+
* And if it's
|
|
21
|
+
*/
|
|
22
|
+
export declare const useExistingFile: import("convex/server").RegisteredMutation<"public", {
|
|
23
|
+
hash: string;
|
|
24
|
+
}, Promise<import("convex/values").GenericId<"files"> | null>>;
|
|
25
|
+
export declare const copyFile: import("convex/server").RegisteredMutation<"public", {
|
|
12
26
|
fileId: Id<"files">;
|
|
13
27
|
}, Promise<void>>;
|
|
14
|
-
export declare function
|
|
28
|
+
export declare function copyFileHandler(ctx: MutationCtx, args: {
|
|
15
29
|
fileId: Id<"files">;
|
|
16
30
|
}): Promise<void>;
|
|
17
31
|
export declare const getFilesToDelete: import("convex/server").RegisteredQuery<"public", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAS,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAE/C,eAAO,MAAM,OAAO;
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAS,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAE/C,eAAO,MAAM,OAAO;eAcC,MAAM;UAAQ,MAAM;;;;GAJvC,CAAC;AAEH,wBAAsB,cAAc,CAClC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;;;GAyB1C;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe;;8DAkB1B,CAAC;AAEH,eAAO,MAAM,QAAQ;YAUH,EAAE,CAAC,OAAO,CAAC;iBAJ3B,CAAC;AAEH,wBAAsB,eAAe,CACnC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;IAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,CAAA;CAAE,iBAS9B;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;GAwB3B,CAAC"}
|
|
@@ -7,24 +7,68 @@ export const addFile = mutation({
|
|
|
7
7
|
hash: v.string(),
|
|
8
8
|
},
|
|
9
9
|
handler: addFileHandler,
|
|
10
|
-
returns:
|
|
10
|
+
returns: {
|
|
11
|
+
fileId: v.id("files"),
|
|
12
|
+
storageIdUnused: v.boolean(),
|
|
13
|
+
},
|
|
11
14
|
});
|
|
12
15
|
export async function addFileHandler(ctx, args) {
|
|
16
|
+
const existingFile = await ctx.db
|
|
17
|
+
.query("files")
|
|
18
|
+
.withIndex("hash", (q) => q.eq("hash", args.hash))
|
|
19
|
+
.first();
|
|
20
|
+
if (existingFile) {
|
|
21
|
+
// increment the refcount
|
|
22
|
+
await ctx.db.patch(existingFile._id, {
|
|
23
|
+
refcount: existingFile.refcount + 1,
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
fileId: existingFile._id,
|
|
27
|
+
storageIdUnused: existingFile.storageId !== args.storageId,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
13
30
|
const fileId = await ctx.db.insert("files", {
|
|
14
31
|
storageId: args.storageId,
|
|
15
32
|
hash: args.hash,
|
|
16
33
|
refcount: 1,
|
|
17
34
|
});
|
|
18
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
fileId,
|
|
37
|
+
storageIdUnused: false,
|
|
38
|
+
};
|
|
19
39
|
}
|
|
20
|
-
|
|
40
|
+
/**
|
|
41
|
+
* If you plan to have the same file added over and over without a reference to
|
|
42
|
+
* the fileId, you can use this query to get the fileId of the existing file.
|
|
43
|
+
* And if it's
|
|
44
|
+
*/
|
|
45
|
+
export const useExistingFile = mutation({
|
|
46
|
+
args: {
|
|
47
|
+
hash: v.string(),
|
|
48
|
+
},
|
|
49
|
+
handler: async (ctx, args) => {
|
|
50
|
+
const file = await ctx.db
|
|
51
|
+
.query("files")
|
|
52
|
+
.withIndex("hash", (q) => q.eq("hash", args.hash))
|
|
53
|
+
.first();
|
|
54
|
+
if (!file) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
await ctx.db.patch(file._id, {
|
|
58
|
+
refcount: file.refcount + 1,
|
|
59
|
+
});
|
|
60
|
+
return file._id;
|
|
61
|
+
},
|
|
62
|
+
returns: v.union(v.id("files"), v.null()),
|
|
63
|
+
});
|
|
64
|
+
export const copyFile = mutation({
|
|
21
65
|
args: {
|
|
22
66
|
fileId: v.id("files"),
|
|
23
67
|
},
|
|
24
|
-
handler:
|
|
68
|
+
handler: copyFileHandler,
|
|
25
69
|
returns: v.null(),
|
|
26
70
|
});
|
|
27
|
-
export async function
|
|
71
|
+
export async function copyFileHandler(ctx, args) {
|
|
28
72
|
const file = await ctx.db.get(args.fileId);
|
|
29
73
|
if (!file) {
|
|
30
74
|
throw new Error("File not found");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAe,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC9B,IAAI,EAAE;QACJ,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACjB;IACD,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;A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AC1B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;KACpB,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deltaStreaming.d.ts","sourceRoot":"","sources":["../../src/deltaStreaming.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deltaStreaming.js","sourceRoot":"","sources":["../../src/deltaStreaming.ts"],"names":[],"mappings":""}
|
|
@@ -3,15 +3,29 @@ import { Id } from "./_generated/dataModel.js";
|
|
|
3
3
|
export declare const addFile: import("convex/server").RegisteredMutation<"public", {
|
|
4
4
|
storageId: string;
|
|
5
5
|
hash: string;
|
|
6
|
-
}, Promise<
|
|
6
|
+
}, Promise<{
|
|
7
|
+
fileId: import("convex/values").GenericId<"files">;
|
|
8
|
+
storageIdUnused: boolean;
|
|
9
|
+
}>>;
|
|
7
10
|
export declare function addFileHandler(ctx: MutationCtx, args: {
|
|
8
11
|
storageId: string;
|
|
9
12
|
hash: string;
|
|
10
|
-
}): Promise<
|
|
11
|
-
|
|
13
|
+
}): Promise<{
|
|
14
|
+
fileId: import("convex/values").GenericId<"files">;
|
|
15
|
+
storageIdUnused: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* If you plan to have the same file added over and over without a reference to
|
|
19
|
+
* the fileId, you can use this query to get the fileId of the existing file.
|
|
20
|
+
* And if it's
|
|
21
|
+
*/
|
|
22
|
+
export declare const useExistingFile: import("convex/server").RegisteredMutation<"public", {
|
|
23
|
+
hash: string;
|
|
24
|
+
}, Promise<import("convex/values").GenericId<"files"> | null>>;
|
|
25
|
+
export declare const copyFile: import("convex/server").RegisteredMutation<"public", {
|
|
12
26
|
fileId: Id<"files">;
|
|
13
27
|
}, Promise<void>>;
|
|
14
|
-
export declare function
|
|
28
|
+
export declare function copyFileHandler(ctx: MutationCtx, args: {
|
|
15
29
|
fileId: Id<"files">;
|
|
16
30
|
}): Promise<void>;
|
|
17
31
|
export declare const getFilesToDelete: import("convex/server").RegisteredQuery<"public", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAS,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAE/C,eAAO,MAAM,OAAO;
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,WAAW,EAAS,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAE/C,eAAO,MAAM,OAAO;eAcC,MAAM;UAAQ,MAAM;;;;GAJvC,CAAC;AAEH,wBAAsB,cAAc,CAClC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;;;GAyB1C;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe;;8DAkB1B,CAAC;AAEH,eAAO,MAAM,QAAQ;YAUH,EAAE,CAAC,OAAO,CAAC;iBAJ3B,CAAC;AAEH,wBAAsB,eAAe,CACnC,GAAG,EAAE,WAAW,EAChB,IAAI,EAAE;IAAE,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,CAAA;CAAE,iBAS9B;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;GAwB3B,CAAC"}
|
|
@@ -7,24 +7,68 @@ export const addFile = mutation({
|
|
|
7
7
|
hash: v.string(),
|
|
8
8
|
},
|
|
9
9
|
handler: addFileHandler,
|
|
10
|
-
returns:
|
|
10
|
+
returns: {
|
|
11
|
+
fileId: v.id("files"),
|
|
12
|
+
storageIdUnused: v.boolean(),
|
|
13
|
+
},
|
|
11
14
|
});
|
|
12
15
|
export async function addFileHandler(ctx, args) {
|
|
16
|
+
const existingFile = await ctx.db
|
|
17
|
+
.query("files")
|
|
18
|
+
.withIndex("hash", (q) => q.eq("hash", args.hash))
|
|
19
|
+
.first();
|
|
20
|
+
if (existingFile) {
|
|
21
|
+
// increment the refcount
|
|
22
|
+
await ctx.db.patch(existingFile._id, {
|
|
23
|
+
refcount: existingFile.refcount + 1,
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
fileId: existingFile._id,
|
|
27
|
+
storageIdUnused: existingFile.storageId !== args.storageId,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
13
30
|
const fileId = await ctx.db.insert("files", {
|
|
14
31
|
storageId: args.storageId,
|
|
15
32
|
hash: args.hash,
|
|
16
33
|
refcount: 1,
|
|
17
34
|
});
|
|
18
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
fileId,
|
|
37
|
+
storageIdUnused: false,
|
|
38
|
+
};
|
|
19
39
|
}
|
|
20
|
-
|
|
40
|
+
/**
|
|
41
|
+
* If you plan to have the same file added over and over without a reference to
|
|
42
|
+
* the fileId, you can use this query to get the fileId of the existing file.
|
|
43
|
+
* And if it's
|
|
44
|
+
*/
|
|
45
|
+
export const useExistingFile = mutation({
|
|
46
|
+
args: {
|
|
47
|
+
hash: v.string(),
|
|
48
|
+
},
|
|
49
|
+
handler: async (ctx, args) => {
|
|
50
|
+
const file = await ctx.db
|
|
51
|
+
.query("files")
|
|
52
|
+
.withIndex("hash", (q) => q.eq("hash", args.hash))
|
|
53
|
+
.first();
|
|
54
|
+
if (!file) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
await ctx.db.patch(file._id, {
|
|
58
|
+
refcount: file.refcount + 1,
|
|
59
|
+
});
|
|
60
|
+
return file._id;
|
|
61
|
+
},
|
|
62
|
+
returns: v.union(v.id("files"), v.null()),
|
|
63
|
+
});
|
|
64
|
+
export const copyFile = mutation({
|
|
21
65
|
args: {
|
|
22
66
|
fileId: v.id("files"),
|
|
23
67
|
},
|
|
24
|
-
handler:
|
|
68
|
+
handler: copyFileHandler,
|
|
25
69
|
returns: v.null(),
|
|
26
70
|
});
|
|
27
|
-
export async function
|
|
71
|
+
export async function copyFileHandler(ctx, args) {
|
|
28
72
|
const file = await ctx.db.get(args.fileId);
|
|
29
73
|
if (!file) {
|
|
30
74
|
throw new Error("File not found");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAe,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC9B,IAAI,EAAE;QACJ,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACjB;IACD,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/component/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAe,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,aAAa,CAAC;AAGxC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC9B,IAAI,EAAE;QACJ,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;KACjB;IACD,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE;QACP,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC;QACrB,eAAe,EAAE,C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AAC,MAAM,EAAE,CAAC;QAC9B,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;KAC9B;IACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC3B,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC;aAC1C,KAAK,CAAC,OAAO,CAAC;aACd,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;aACjD,QAAQ,CAAC;YACR,QAAQ,EAAE,IAAI,CAAC,KAAK,IAAI,GAAG;YAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI;SAC5B,CAAC,CAAC;QACL,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;QAChB,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;KACpB,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deltaStreaming.d.ts","sourceRoot":"","sources":["../../src/deltaStreaming.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deltaStreaming.js","sourceRoot":"","sources":["../../src/deltaStreaming.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -58,8 +58,9 @@ export type Mounts = {
|
|
|
58
58
|
"mutation",
|
|
59
59
|
"public",
|
|
60
60
|
{ hash: string; storageId: string },
|
|
61
|
-
string
|
|
61
|
+
{ fileId: string; storageIdUnused: boolean }
|
|
62
62
|
>;
|
|
63
|
+
copyFile: FunctionReference<"mutation", "public", { fileId: string }, null>;
|
|
63
64
|
getFilesToDelete: FunctionReference<
|
|
64
65
|
"query",
|
|
65
66
|
"public",
|
|
@@ -76,11 +77,11 @@ export type Mounts = {
|
|
|
76
77
|
isDone: boolean;
|
|
77
78
|
}
|
|
78
79
|
>;
|
|
79
|
-
|
|
80
|
+
useExistingFile: FunctionReference<
|
|
80
81
|
"mutation",
|
|
81
82
|
"public",
|
|
82
|
-
{
|
|
83
|
-
null
|
|
83
|
+
{ hash: string },
|
|
84
|
+
string | null
|
|
84
85
|
>;
|
|
85
86
|
};
|
|
86
87
|
messages: {
|
package/src/component/files.ts
CHANGED
|
@@ -9,30 +9,75 @@ export const addFile = mutation({
|
|
|
9
9
|
hash: v.string(),
|
|
10
10
|
},
|
|
11
11
|
handler: addFileHandler,
|
|
12
|
-
returns:
|
|
12
|
+
returns: {
|
|
13
|
+
fileId: v.id("files"),
|
|
14
|
+
storageIdUnused: v.boolean(),
|
|
15
|
+
},
|
|
13
16
|
});
|
|
14
17
|
|
|
15
18
|
export async function addFileHandler(
|
|
16
19
|
ctx: MutationCtx,
|
|
17
20
|
args: { storageId: string; hash: string }
|
|
18
21
|
) {
|
|
22
|
+
const existingFile = await ctx.db
|
|
23
|
+
.query("files")
|
|
24
|
+
.withIndex("hash", (q) => q.eq("hash", args.hash))
|
|
25
|
+
.first();
|
|
26
|
+
if (existingFile) {
|
|
27
|
+
// increment the refcount
|
|
28
|
+
await ctx.db.patch(existingFile._id, {
|
|
29
|
+
refcount: existingFile.refcount + 1,
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
fileId: existingFile._id,
|
|
33
|
+
storageIdUnused: existingFile.storageId !== args.storageId,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
19
36
|
const fileId = await ctx.db.insert("files", {
|
|
20
37
|
storageId: args.storageId,
|
|
21
38
|
hash: args.hash,
|
|
22
39
|
refcount: 1,
|
|
23
40
|
});
|
|
24
|
-
return
|
|
41
|
+
return {
|
|
42
|
+
fileId,
|
|
43
|
+
storageIdUnused: false,
|
|
44
|
+
};
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
|
|
47
|
+
/**
|
|
48
|
+
* If you plan to have the same file added over and over without a reference to
|
|
49
|
+
* the fileId, you can use this query to get the fileId of the existing file.
|
|
50
|
+
* And if it's
|
|
51
|
+
*/
|
|
52
|
+
export const useExistingFile = mutation({
|
|
53
|
+
args: {
|
|
54
|
+
hash: v.string(),
|
|
55
|
+
},
|
|
56
|
+
handler: async (ctx, args) => {
|
|
57
|
+
const file = await ctx.db
|
|
58
|
+
.query("files")
|
|
59
|
+
.withIndex("hash", (q) => q.eq("hash", args.hash))
|
|
60
|
+
.first();
|
|
61
|
+
if (!file) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
await ctx.db.patch(file._id, {
|
|
65
|
+
refcount: file.refcount + 1,
|
|
66
|
+
});
|
|
67
|
+
return file._id;
|
|
68
|
+
},
|
|
69
|
+
returns: v.union(v.id("files"), v.null()),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const copyFile = mutation({
|
|
28
73
|
args: {
|
|
29
74
|
fileId: v.id("files"),
|
|
30
75
|
},
|
|
31
|
-
handler:
|
|
76
|
+
handler: copyFileHandler,
|
|
32
77
|
returns: v.null(),
|
|
33
78
|
});
|
|
34
79
|
|
|
35
|
-
export async function
|
|
80
|
+
export async function copyFileHandler(
|
|
36
81
|
ctx: MutationCtx,
|
|
37
82
|
args: { fileId: Id<"files"> }
|
|
38
83
|
) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { v } from "convex/values";
|