xquik-convex 0.2.0 → 0.2.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/README.md +1 -1
- package/dist/client.d.ts +103 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +73 -0
- package/dist/client.js.map +1 -0
- package/dist/component/_generated/api.d.ts +4 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/access.d.ts +1 -1
- package/dist/component/access.d.ts.map +1 -1
- package/dist/component/access.js +3 -3
- package/dist/component/access.js.map +1 -1
- package/dist/component/crons.d.ts +3 -2
- package/dist/component/crons.d.ts.map +1 -1
- package/dist/component/crons.js +6 -3
- package/dist/component/crons.js.map +1 -1
- package/dist/component/delivery.d.ts +51 -16
- package/dist/component/delivery.d.ts.map +1 -1
- package/dist/component/delivery.js +71 -41
- package/dist/component/delivery.js.map +1 -1
- package/dist/component/events.d.ts +3 -19
- package/dist/component/events.d.ts.map +1 -1
- package/dist/component/events.js +21 -17
- package/dist/component/events.js.map +1 -1
- package/dist/component/http.d.ts +3 -3
- package/dist/component/http.d.ts.map +1 -1
- package/dist/component/http.js +46 -23
- package/dist/component/http.js.map +1 -1
- package/dist/component/job.d.ts +101 -0
- package/dist/component/job.d.ts.map +1 -0
- package/dist/component/job.js +102 -0
- package/dist/component/job.js.map +1 -0
- package/dist/component/jobs.d.ts +36 -107
- package/dist/component/jobs.d.ts.map +1 -1
- package/dist/component/jobs.js +109 -121
- package/dist/component/jobs.js.map +1 -1
- package/dist/component/operation.d.ts +6 -3
- package/dist/component/operation.d.ts.map +1 -1
- package/dist/component/operation.js +8 -3
- package/dist/component/operation.js.map +1 -1
- package/dist/component/operations.d.ts +1331 -190
- package/dist/component/operations.d.ts.map +1 -1
- package/dist/component/operations.js +2 -191
- package/dist/component/operations.js.map +1 -1
- package/dist/component/registry.d.ts +14 -0
- package/dist/component/registry.d.ts.map +1 -0
- package/dist/component/registry.js +154 -0
- package/dist/component/registry.js.map +1 -0
- package/dist/component/registry.json +14402 -46998
- package/dist/component/request.d.ts +12 -18
- package/dist/component/request.d.ts.map +1 -1
- package/dist/component/request.js +94 -169
- package/dist/component/request.js.map +1 -1
- package/dist/component/schema.d.ts +37 -36
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +30 -29
- package/dist/component/schema.js.map +1 -1
- package/dist/component/shape.d.ts +12 -10
- package/dist/component/shape.d.ts.map +1 -1
- package/dist/component/shape.js +30 -18
- package/dist/component/shape.js.map +1 -1
- package/dist/component/values.d.ts +10 -8
- package/dist/component/values.d.ts.map +1 -1
- package/dist/component/values.js +15 -10
- package/dist/component/values.js.map +1 -1
- package/dist/component/webhooks.d.ts +49 -39
- package/dist/component/webhooks.d.ts.map +1 -1
- package/dist/component/webhooks.js +91 -77
- package/dist/component/webhooks.js.map +1 -1
- package/dist/test.d.ts +41 -40
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +5 -3
- package/dist/test.js.map +1 -1
- package/package.json +26 -10
- package/src/client.ts +129 -0
- package/src/component/_generated/api.ts +4 -0
- package/src/component/access.ts +3 -3
- package/src/component/crons.ts +7 -4
- package/src/component/delivery.ts +93 -42
- package/src/component/events.ts +23 -18
- package/src/component/http.ts +59 -21
- package/src/component/job.ts +131 -0
- package/src/component/jobs.ts +131 -143
- package/src/component/operation.ts +16 -5
- package/src/component/operations.ts +193 -191
- package/src/component/registry.json +14402 -46998
- package/src/component/registry.ts +184 -0
- package/src/component/request.ts +121 -170
- package/src/component/schema.ts +33 -34
- package/src/component/shape.ts +49 -25
- package/src/component/values.ts +19 -10
- package/src/component/webhooks.ts +120 -78
- package/src/test.ts +8 -5
- package/dist/client/index.d.ts +0 -85
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -50
- package/dist/client/index.js.map +0 -1
- package/src/client/index.ts +0 -97
package/dist/component/events.js
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
import { paginationOptsValidator, paginationResultValidator } from "convex/server";
|
|
2
|
-
import { v } from "convex/values";
|
|
3
1
|
import { env, query } from "./_generated/server.js";
|
|
4
|
-
import {
|
|
2
|
+
import { paginationOptsValidator, paginationResultValidator } from "convex/server";
|
|
3
|
+
import requireApiKey from "./access.js";
|
|
5
4
|
import schema from "./schema.js";
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { v } from "convex/values";
|
|
6
|
+
const eventDoc = schema.tables.events.validator.extend({
|
|
8
7
|
_creationTime: v.number(),
|
|
8
|
+
_id: v.id("events"),
|
|
9
9
|
});
|
|
10
|
-
|
|
10
|
+
const eventFilter = v.union(v.object({ eventType: v.string() }), v.object({ monitorId: v.string() }));
|
|
11
|
+
const list = query({
|
|
11
12
|
args: {
|
|
13
|
+
filter: v.optional(eventFilter),
|
|
12
14
|
paginationOpts: paginationOptsValidator,
|
|
13
|
-
filter: v.optional(v.union(v.object({ eventType: v.string() }), v.object({ monitorId: v.string() }))),
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
-
handler: async (ctx, { paginationOpts, filter }) => {
|
|
16
|
+
handler: async (ctx, { filter, paginationOpts }) => {
|
|
17
17
|
requireApiKey(env.XQUIK_API_KEY);
|
|
18
18
|
const events = ctx.db.query("events");
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
let ordered = events.withIndex("by_occurred");
|
|
20
|
+
if (typeof filter === "object" && "eventType" in filter) {
|
|
21
|
+
ordered = events.withIndex("by_type", (range) => range.eq("eventType", filter.eventType));
|
|
22
|
+
}
|
|
23
|
+
if (typeof filter === "object" && "monitorId" in filter) {
|
|
24
|
+
ordered = events.withIndex("by_monitor", (range) => range.eq("monitorId", filter.monitorId));
|
|
25
|
+
}
|
|
24
26
|
return await ordered.order("desc").paginate(paginationOpts);
|
|
25
27
|
},
|
|
28
|
+
returns: paginationResultValidator(eventDoc),
|
|
26
29
|
});
|
|
27
|
-
|
|
30
|
+
const get = query({
|
|
28
31
|
args: { streamEventId: v.string() },
|
|
29
|
-
returns: v.union(v.null(), eventDoc),
|
|
30
32
|
handler: async (ctx, { streamEventId }) => {
|
|
31
33
|
requireApiKey(env.XQUIK_API_KEY);
|
|
32
34
|
return await ctx.db
|
|
33
35
|
.query("events")
|
|
34
|
-
.withIndex("by_stream_event", (
|
|
36
|
+
.withIndex("by_stream_event", (range) => range.eq("streamEventId", streamEventId))
|
|
35
37
|
.unique();
|
|
36
38
|
},
|
|
39
|
+
returns: v.union(v.null(), eventDoc),
|
|
37
40
|
});
|
|
41
|
+
export { get, list };
|
|
38
42
|
//# sourceMappingURL=events.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/component/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/component/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,aAAa,MAAM,aAAa,CAAC;AACxC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;IACrD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC;CACpB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,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AAK,EAAE,GAAG,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE;QACxC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACjC,OAAO,MAAM,GAAG,CAAC,EAAE;aAChB,KAAK,CAAC,QAAQ,CAAC;aACf,SAAS,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;aACjF,MAAM,EAAE,CAAC;IACd,CAAC;IACD,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC;CACrC,CAAC,CAAC;AAEH,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/component/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
1
|
+
import type { HttpRouter } from "convex/server";
|
|
2
|
+
declare const _default: HttpRouter;
|
|
3
|
+
export default _default;
|
|
4
4
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;;AA+DhD,wBAAwB"}
|
package/dist/component/http.js
CHANGED
|
@@ -1,30 +1,53 @@
|
|
|
1
|
+
import { check, readDelivery } from "./delivery.js";
|
|
2
|
+
import { httpAction } from "./_generated/server.js";
|
|
1
3
|
import { httpRouter } from "convex/server";
|
|
2
4
|
import { internal } from "./_generated/api.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
const OK = 200;
|
|
6
|
+
const BAD_REQUEST = 400;
|
|
7
|
+
const UNAUTHORIZED = 401;
|
|
8
|
+
const NOT_FOUND = 404;
|
|
9
|
+
const SLASH = "/";
|
|
5
10
|
function reply(status, text) {
|
|
6
|
-
return new Response(text, {
|
|
11
|
+
return new Response(text, { headers: { "content-type": "text/plain" }, status });
|
|
7
12
|
}
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
function tokenOf(url) {
|
|
14
|
+
const { pathname } = new URL(url);
|
|
15
|
+
return pathname.slice(pathname.lastIndexOf(SLASH) + SLASH.length);
|
|
16
|
+
}
|
|
17
|
+
async function admit(secret, headers, body) {
|
|
18
|
+
const verdict = await check(secret, headers, body, Date.now());
|
|
19
|
+
if (!verdict.ok) {
|
|
20
|
+
return { ok: false, reason: verdict.reason, status: UNAUTHORIZED };
|
|
21
|
+
}
|
|
17
22
|
const delivery = readDelivery(new TextDecoder().decode(body));
|
|
18
|
-
if (delivery ===
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (delivery.kind === "invalid") {
|
|
24
|
+
return { ok: false, reason: "not an Xquik delivery", status: BAD_REQUEST };
|
|
25
|
+
}
|
|
26
|
+
return { delivery, nonce: verdict.nonce, ok: true };
|
|
27
|
+
}
|
|
28
|
+
function answer(outcome) {
|
|
29
|
+
if (outcome === "replay") {
|
|
30
|
+
return reply(UNAUTHORIZED, "replayed nonce");
|
|
31
|
+
}
|
|
32
|
+
return reply(OK, outcome);
|
|
33
|
+
}
|
|
34
|
+
const receive = httpAction(async (ctx, request) => {
|
|
35
|
+
const endpoint = await ctx.runQuery(internal.webhooks.endpoint, { token: tokenOf(request.url) });
|
|
36
|
+
if (endpoint === null) {
|
|
37
|
+
return reply(NOT_FOUND, "unknown webhook URL");
|
|
38
|
+
}
|
|
39
|
+
const admission = await admit(endpoint.secret, request.headers, await request.arrayBuffer());
|
|
40
|
+
if (!admission.ok) {
|
|
41
|
+
return reply(admission.status, admission.reason);
|
|
42
|
+
}
|
|
43
|
+
const { _id: endpointId } = endpoint;
|
|
44
|
+
const { delivery, nonce } = admission;
|
|
45
|
+
return answer(await ctx.runMutation(internal.webhooks.ingest, { delivery, endpointId, nonce }));
|
|
26
46
|
});
|
|
27
|
-
|
|
28
|
-
http
|
|
29
|
-
|
|
47
|
+
function router() {
|
|
48
|
+
const http = httpRouter();
|
|
49
|
+
http.route({ handler: receive, method: "POST", pathPrefix: "/webhooks/" });
|
|
50
|
+
return http;
|
|
51
|
+
}
|
|
52
|
+
export default router();
|
|
30
53
|
//# sourceMappingURL=http.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/component/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,MAAM,EAAE,GAAG,GAAG,CAAC;AACf,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,KAAK,GAAG,GAAG,CAAC;AAQlB,SAAS,KAAK,CAAC,MAAc,EAAE,IAAY;IACzC,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,EAAE,QAAQ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AAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjG,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7F,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IACrC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IACtC,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAClG,CAAC,CAAC,CAAC;AAEH,SAAS,MAAM;IACb,MAAM,IAAI,GAAG,UAAU,EAAE,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,eAAe,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Infer, Value } from "convex/values";
|
|
2
|
+
import type { jobStatus } from "./schema.js";
|
|
3
|
+
import type { Operation } from "./shape.js";
|
|
4
|
+
declare const jobDoc: import("convex/values").VObject<{
|
|
5
|
+
key?: string;
|
|
6
|
+
error?: Value;
|
|
7
|
+
everyMs?: number;
|
|
8
|
+
result?: Value;
|
|
9
|
+
scheduledId?: import("convex/values").GenericId<"_scheduled_functions">;
|
|
10
|
+
status: "failed" | "succeeded" | "canceled" | "scheduled";
|
|
11
|
+
args: Record<string, Value>;
|
|
12
|
+
operation: string;
|
|
13
|
+
attempts: number;
|
|
14
|
+
runs: number;
|
|
15
|
+
_creationTime: number;
|
|
16
|
+
_id: import("convex/values").GenericId<"jobs">;
|
|
17
|
+
}, {
|
|
18
|
+
args: import("convex/values").VRecord<Record<string, Value>, import("convex/values").VString<string, "required">, import("convex/values").Validator<Value, "required", string>, "required", string>;
|
|
19
|
+
attempts: import("convex/values").VFloat64<number, "required">;
|
|
20
|
+
error: import("convex/values").VId<Value | undefined, "optional"> | import("convex/values").VString<Value | undefined, "optional"> | import("convex/values").VFloat64<Value | undefined, "optional"> | import("convex/values").VInt64<Value | undefined, "optional"> | import("convex/values").VCommitTs<Value | undefined, "optional"> | import("convex/values").VBoolean<Value | undefined, "optional"> | import("convex/values").VNull<Value | undefined, "optional"> | import("convex/values").VAny<Value | undefined, "optional", string> | import("convex/values").VLiteral<Value | undefined, "optional"> | import("convex/values").VBytes<Value | undefined, "optional"> | import("convex/values").VObject<Value | undefined, Record<string, import("convex/values").Validator<any, import("convex/values").OptionalProperty, any>>, "optional", string> | import("convex/values").VArray<Value | undefined, import("convex/values").Validator<any, "required", any>, "optional"> | import("convex/values").VRecord<Value | undefined, import("convex/values").Validator<string, "required", any>, import("convex/values").Validator<any, "required", any>, "optional", string> | import("convex/values").VUnion<Value | undefined, import("convex/values").Validator<any, "required", any>[], "optional", string>;
|
|
21
|
+
everyMs: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
22
|
+
key: import("convex/values").VString<string | undefined, "optional">;
|
|
23
|
+
operation: import("convex/values").VString<string, "required">;
|
|
24
|
+
result: import("convex/values").VId<Value | undefined, "optional"> | import("convex/values").VString<Value | undefined, "optional"> | import("convex/values").VFloat64<Value | undefined, "optional"> | import("convex/values").VInt64<Value | undefined, "optional"> | import("convex/values").VCommitTs<Value | undefined, "optional"> | import("convex/values").VBoolean<Value | undefined, "optional"> | import("convex/values").VNull<Value | undefined, "optional"> | import("convex/values").VAny<Value | undefined, "optional", string> | import("convex/values").VLiteral<Value | undefined, "optional"> | import("convex/values").VBytes<Value | undefined, "optional"> | import("convex/values").VObject<Value | undefined, Record<string, import("convex/values").Validator<any, import("convex/values").OptionalProperty, any>>, "optional", string> | import("convex/values").VArray<Value | undefined, import("convex/values").Validator<any, "required", any>, "optional"> | import("convex/values").VRecord<Value | undefined, import("convex/values").Validator<string, "required", any>, import("convex/values").Validator<any, "required", any>, "optional", string> | import("convex/values").VUnion<Value | undefined, import("convex/values").Validator<any, "required", any>[], "optional", string>;
|
|
25
|
+
runs: import("convex/values").VFloat64<number, "required">;
|
|
26
|
+
scheduledId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions"> | undefined, "optional">;
|
|
27
|
+
status: import("convex/values").VUnion<"failed" | "succeeded" | "canceled" | "scheduled", [import("convex/values").VLiteral<"scheduled", "required">, import("convex/values").VLiteral<"succeeded", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"canceled", "required">], "required", never>;
|
|
28
|
+
_creationTime: import("convex/values").VFloat64<number, "required">;
|
|
29
|
+
_id: import("convex/values").VId<import("convex/values").GenericId<"jobs">, "required">;
|
|
30
|
+
}, "required", "key" | "error" | "status" | "_creationTime" | "_id" | "args" | "everyMs" | "operation" | "result" | "attempts" | "runs" | "scheduledId" | `error.${string}` | `args.${string}` | `result.${string}`>;
|
|
31
|
+
declare const failure: import("convex/values").VObject<{
|
|
32
|
+
retryAfterMs?: number;
|
|
33
|
+
error: Value;
|
|
34
|
+
ok: false;
|
|
35
|
+
retryable: boolean;
|
|
36
|
+
}, {
|
|
37
|
+
error: import("convex/values").Validator<Value, "required", string>;
|
|
38
|
+
ok: import("convex/values").VLiteral<false, "required">;
|
|
39
|
+
retryAfterMs: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
40
|
+
retryable: import("convex/values").VBoolean<boolean, "required">;
|
|
41
|
+
}, "required", "error" | "ok" | `error.${string}` | "retryAfterMs" | "retryable">;
|
|
42
|
+
declare const outcome: import("convex/values").VUnion<{
|
|
43
|
+
ok: true;
|
|
44
|
+
result: Value;
|
|
45
|
+
} | {
|
|
46
|
+
retryAfterMs?: number;
|
|
47
|
+
error: Value;
|
|
48
|
+
ok: false;
|
|
49
|
+
retryable: boolean;
|
|
50
|
+
}, [import("convex/values").VObject<{
|
|
51
|
+
ok: true;
|
|
52
|
+
result: Value;
|
|
53
|
+
}, {
|
|
54
|
+
ok: import("convex/values").VLiteral<true, "required">;
|
|
55
|
+
result: import("convex/values").Validator<Value, "required", string>;
|
|
56
|
+
}, "required", "ok" | "result" | `result.${string}`>, import("convex/values").VObject<{
|
|
57
|
+
retryAfterMs?: number;
|
|
58
|
+
error: Value;
|
|
59
|
+
ok: false;
|
|
60
|
+
retryable: boolean;
|
|
61
|
+
}, {
|
|
62
|
+
error: import("convex/values").Validator<Value, "required", string>;
|
|
63
|
+
ok: import("convex/values").VLiteral<false, "required">;
|
|
64
|
+
retryAfterMs: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
65
|
+
retryable: import("convex/values").VBoolean<boolean, "required">;
|
|
66
|
+
}, "required", "error" | "ok" | `error.${string}` | "retryAfterMs" | "retryable">], "required", "error" | "ok" | "result" | `error.${string}` | `result.${string}` | "retryAfterMs" | "retryable">;
|
|
67
|
+
type Outcome = Infer<typeof outcome>;
|
|
68
|
+
type Failure = Infer<typeof failure>;
|
|
69
|
+
type Attempt = {
|
|
70
|
+
readonly ok: true;
|
|
71
|
+
} | {
|
|
72
|
+
readonly ok: false;
|
|
73
|
+
readonly retryAfterMs?: number;
|
|
74
|
+
readonly retryable: boolean;
|
|
75
|
+
};
|
|
76
|
+
interface Plan {
|
|
77
|
+
readonly status: Infer<typeof jobStatus>;
|
|
78
|
+
readonly delayMs?: number;
|
|
79
|
+
readonly attempts: number;
|
|
80
|
+
}
|
|
81
|
+
declare function plan(job: {
|
|
82
|
+
readonly attempts: number;
|
|
83
|
+
readonly everyMs?: number;
|
|
84
|
+
}, result: Attempt): Plan;
|
|
85
|
+
declare function runsAfter(runs: number, next: Plan): number;
|
|
86
|
+
declare function isScheduled(job: {
|
|
87
|
+
readonly status: string;
|
|
88
|
+
} | null): job is {
|
|
89
|
+
readonly status: "scheduled";
|
|
90
|
+
};
|
|
91
|
+
declare function isLive(scheduled: {
|
|
92
|
+
readonly state: {
|
|
93
|
+
readonly kind: string;
|
|
94
|
+
};
|
|
95
|
+
} | null): boolean;
|
|
96
|
+
declare function requireInterval(everyMs: number | undefined): void;
|
|
97
|
+
declare function unexpected(id: string): Failure;
|
|
98
|
+
declare function failed(definition: Operation, error: unknown): Failure;
|
|
99
|
+
export { failed, isLive, isScheduled, jobDoc, outcome, plan, requireInterval, runsAfter, unexpected };
|
|
100
|
+
export type { Attempt, Failure, Outcome, Plan };
|
|
101
|
+
//# sourceMappingURL=job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.d.ts","sourceRoot":"","sources":["../../src/component/job.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAe5C,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;oNAAwF,CAAC;AAGrG,QAAA,MAAM,OAAO;;;;;;;;;;iFAKX,CAAC;AACH,QAAA,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;kMAA4B,CAAC;AAE1C,KAAK,OAAO,GAAG,KAAK,CAAC,OAAO,OAAO,CAAC,CAAC;AACrC,KAAK,OAAO,GAAG,KAAK,CAAC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E,OAAO,GAAG,OAAO,CAU9D;AAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AACtG,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ConvexError, v } from "convex/values";
|
|
2
|
+
import { isRecord } from "./shape.js";
|
|
3
|
+
import { json } from "./values.js";
|
|
4
|
+
import schema from "./schema.js";
|
|
5
|
+
const MAX_ATTEMPTS = 5;
|
|
6
|
+
const MIN_EVERY_MS = 60_000;
|
|
7
|
+
const ONE_ATTEMPT = 1;
|
|
8
|
+
const ONE_RUN = 1;
|
|
9
|
+
const NO_RETRIES = 0;
|
|
10
|
+
const FIRST_DELAY_MS = 1000;
|
|
11
|
+
const BACKOFF = 2;
|
|
12
|
+
const MS_PER_SECOND = 1000;
|
|
13
|
+
const TOO_MANY_REQUESTS = 429;
|
|
14
|
+
const SERVER_ERROR = 500;
|
|
15
|
+
const LIVE = new Set(["inProgress", "pending"]);
|
|
16
|
+
const jobDoc = schema.tables.jobs.validator.extend({ _creationTime: v.number(), _id: v.id("jobs") });
|
|
17
|
+
const success = v.object({ ok: v.literal(true), result: json });
|
|
18
|
+
const failure = v.object({
|
|
19
|
+
error: json,
|
|
20
|
+
ok: v.literal(false),
|
|
21
|
+
retryAfterMs: v.optional(v.number()),
|
|
22
|
+
retryable: v.boolean(),
|
|
23
|
+
});
|
|
24
|
+
const outcome = v.union(success, failure);
|
|
25
|
+
function plan(job, result) {
|
|
26
|
+
if (!result.ok && result.retryable && job.attempts + ONE_ATTEMPT < MAX_ATTEMPTS) {
|
|
27
|
+
return {
|
|
28
|
+
attempts: job.attempts + ONE_ATTEMPT,
|
|
29
|
+
delayMs: result.retryAfterMs ?? FIRST_DELAY_MS * BACKOFF ** job.attempts,
|
|
30
|
+
status: "scheduled",
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (typeof job.everyMs === "number") {
|
|
34
|
+
return { attempts: 0, delayMs: job.everyMs, status: "scheduled" };
|
|
35
|
+
}
|
|
36
|
+
if (result.ok) {
|
|
37
|
+
return { attempts: 0, status: "succeeded" };
|
|
38
|
+
}
|
|
39
|
+
return { attempts: 0, status: "failed" };
|
|
40
|
+
}
|
|
41
|
+
function runsAfter(runs, next) {
|
|
42
|
+
if (next.attempts === NO_RETRIES) {
|
|
43
|
+
return runs + ONE_RUN;
|
|
44
|
+
}
|
|
45
|
+
return runs;
|
|
46
|
+
}
|
|
47
|
+
function isScheduled(job) {
|
|
48
|
+
if (job === null) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return job.status === "scheduled";
|
|
52
|
+
}
|
|
53
|
+
function isLive(scheduled) {
|
|
54
|
+
if (scheduled === null) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return LIVE.has(scheduled.state.kind);
|
|
58
|
+
}
|
|
59
|
+
function requireInterval(everyMs) {
|
|
60
|
+
if ((everyMs ?? MIN_EVERY_MS) < MIN_EVERY_MS) {
|
|
61
|
+
throw new ConvexError({
|
|
62
|
+
error: "interval_too_short",
|
|
63
|
+
message: `Set everyMs to ${String(MIN_EVERY_MS)} or more.`,
|
|
64
|
+
status: 400,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function keyed(definition) {
|
|
69
|
+
return definition.params.some((param) => param.name === "idempotencyKey");
|
|
70
|
+
}
|
|
71
|
+
function isConvexError(error) {
|
|
72
|
+
return error instanceof ConvexError;
|
|
73
|
+
}
|
|
74
|
+
function errorData(error) {
|
|
75
|
+
if (isConvexError(error)) {
|
|
76
|
+
return error.data;
|
|
77
|
+
}
|
|
78
|
+
return { message: String(error) };
|
|
79
|
+
}
|
|
80
|
+
function asRecord(data) {
|
|
81
|
+
if (isRecord(data)) {
|
|
82
|
+
return data;
|
|
83
|
+
}
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
function unexpected(id) {
|
|
87
|
+
const message = `Xquik answered ${id} with a result its schema does not allow.`;
|
|
88
|
+
return { error: { error: "unexpected_result", message, status: 502 }, ok: false, retryable: false };
|
|
89
|
+
}
|
|
90
|
+
function failed(definition, error) {
|
|
91
|
+
const data = errorData(error);
|
|
92
|
+
const { retryAfter, status } = asRecord(data);
|
|
93
|
+
const safe = definition.method === "GET" || keyed(definition);
|
|
94
|
+
const transient = typeof status !== "number" || status === TOO_MANY_REQUESTS || status >= SERVER_ERROR;
|
|
95
|
+
const retryable = safe && transient;
|
|
96
|
+
if (typeof retryAfter === "number") {
|
|
97
|
+
return { error: data, ok: false, retryAfterMs: retryAfter * MS_PER_SECOND, retryable };
|
|
98
|
+
}
|
|
99
|
+
return { error: data, ok: false, retryable };
|
|
100
|
+
}
|
|
101
|
+
export { failed, isLive, isScheduled, jobDoc, outcome, plan, requireInterval, runsAfter, unexpected };
|
|
102
|
+
//# sourceMappingURL=job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job.js","sourceRoot":"","sources":["../../src/component/job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,aAAa,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,SAAS,CAAC;IACpC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,GAAG,aAAa,EAAE,SAAS,EAAE,CAAC;IACzF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AAC/C,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/component/jobs.d.ts
CHANGED
|
@@ -1,133 +1,62 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { jobStatus } from "./schema.js";
|
|
4
|
-
import { type Operation } from "./shape.js";
|
|
5
|
-
export declare const MAX_ATTEMPTS = 5;
|
|
6
|
-
export declare const MIN_EVERY_MS = 60000;
|
|
7
|
-
export declare const jobDoc: import("convex/values").VObject<{
|
|
8
|
-
key?: string;
|
|
9
|
-
error?: Value;
|
|
10
|
-
everyMs?: number;
|
|
11
|
-
result?: Value;
|
|
12
|
-
scheduledId?: import("convex/values").GenericId<"_scheduled_functions">;
|
|
13
|
-
status: "failed" | "succeeded" | "canceled" | "scheduled";
|
|
14
|
-
args: Record<string, Value>;
|
|
15
|
-
operation: string;
|
|
16
|
-
attempts: number;
|
|
17
|
-
runs: number;
|
|
18
|
-
_creationTime: number;
|
|
19
|
-
_id: import("convex/values").GenericId<"jobs">;
|
|
20
|
-
}, {
|
|
21
|
-
key: import("convex/values").VString<string | undefined, "optional">;
|
|
22
|
-
operation: import("convex/values").VString<string, "required">;
|
|
23
|
-
args: import("convex/values").VRecord<Record<string, Value>, import("convex/values").VString<string, "required">, import("convex/values").Validator<Value, "required", string>, "required", string>;
|
|
24
|
-
everyMs: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
25
|
-
status: import("convex/values").VUnion<"failed" | "succeeded" | "canceled" | "scheduled", [import("convex/values").VLiteral<"scheduled", "required">, import("convex/values").VLiteral<"succeeded", "required">, import("convex/values").VLiteral<"failed", "required">, import("convex/values").VLiteral<"canceled", "required">], "required", never>;
|
|
26
|
-
attempts: import("convex/values").VFloat64<number, "required">;
|
|
27
|
-
runs: import("convex/values").VFloat64<number, "required">;
|
|
28
|
-
scheduledId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions"> | undefined, "optional">;
|
|
29
|
-
result: import("convex/values").VId<Value | undefined, "optional"> | import("convex/values").VString<Value | undefined, "optional"> | import("convex/values").VFloat64<Value | undefined, "optional"> | import("convex/values").VInt64<Value | undefined, "optional"> | import("convex/values").VCommitTs<Value | undefined, "optional"> | import("convex/values").VBoolean<Value | undefined, "optional"> | import("convex/values").VNull<Value | undefined, "optional"> | import("convex/values").VAny<Value | undefined, "optional", string> | import("convex/values").VLiteral<Value | undefined, "optional"> | import("convex/values").VBytes<Value | undefined, "optional"> | import("convex/values").VObject<Value | undefined, Record<string, import("convex/values").Validator<any, import("convex/values").OptionalProperty, any>>, "optional", string> | import("convex/values").VArray<Value | undefined, import("convex/values").Validator<any, "required", any>, "optional"> | import("convex/values").VRecord<Value | undefined, import("convex/values").Validator<string, "required", any>, import("convex/values").Validator<any, "required", any>, "optional", string> | import("convex/values").VUnion<Value | undefined, import("convex/values").Validator<any, "required", any>[], "optional", string>;
|
|
30
|
-
error: import("convex/values").VId<Value | undefined, "optional"> | import("convex/values").VString<Value | undefined, "optional"> | import("convex/values").VFloat64<Value | undefined, "optional"> | import("convex/values").VInt64<Value | undefined, "optional"> | import("convex/values").VCommitTs<Value | undefined, "optional"> | import("convex/values").VBoolean<Value | undefined, "optional"> | import("convex/values").VNull<Value | undefined, "optional"> | import("convex/values").VAny<Value | undefined, "optional", string> | import("convex/values").VLiteral<Value | undefined, "optional"> | import("convex/values").VBytes<Value | undefined, "optional"> | import("convex/values").VObject<Value | undefined, Record<string, import("convex/values").Validator<any, import("convex/values").OptionalProperty, any>>, "optional", string> | import("convex/values").VArray<Value | undefined, import("convex/values").Validator<any, "required", any>, "optional"> | import("convex/values").VRecord<Value | undefined, import("convex/values").Validator<string, "required", any>, import("convex/values").Validator<any, "required", any>, "optional", string> | import("convex/values").VUnion<Value | undefined, import("convex/values").Validator<any, "required", any>[], "optional", string>;
|
|
31
|
-
_id: import("convex/values").VId<import("convex/values").GenericId<"jobs">, "required">;
|
|
32
|
-
_creationTime: import("convex/values").VFloat64<number, "required">;
|
|
33
|
-
}, "required", "key" | "error" | "status" | "_creationTime" | "_id" | "args" | "everyMs" | "operation" | "result" | "attempts" | "runs" | "scheduledId" | `error.${string}` | `args.${string}` | `result.${string}`>;
|
|
34
|
-
declare const outcome: import("convex/values").VUnion<{
|
|
35
|
-
ok: true;
|
|
36
|
-
result: Value;
|
|
37
|
-
} | {
|
|
38
|
-
retryAfterMs?: number;
|
|
39
|
-
error: Value;
|
|
40
|
-
ok: false;
|
|
41
|
-
retryable: boolean;
|
|
42
|
-
}, [import("convex/values").VObject<{
|
|
43
|
-
ok: true;
|
|
44
|
-
result: Value;
|
|
45
|
-
}, {
|
|
46
|
-
ok: import("convex/values").VLiteral<true, "required">;
|
|
47
|
-
result: import("convex/values").Validator<Value, "required", string>;
|
|
48
|
-
}, "required", "ok" | "result" | `result.${string}`>, import("convex/values").VObject<{
|
|
49
|
-
retryAfterMs?: number;
|
|
50
|
-
error: Value;
|
|
51
|
-
ok: false;
|
|
52
|
-
retryable: boolean;
|
|
53
|
-
}, {
|
|
54
|
-
ok: import("convex/values").VLiteral<false, "required">;
|
|
55
|
-
error: import("convex/values").Validator<Value, "required", string>;
|
|
56
|
-
retryable: import("convex/values").VBoolean<boolean, "required">;
|
|
57
|
-
retryAfterMs: import("convex/values").VFloat64<number | undefined, "optional">;
|
|
58
|
-
}, "required", "error" | "ok" | `error.${string}` | "retryable" | "retryAfterMs">], "required", "error" | "ok" | "result" | `error.${string}` | `result.${string}` | "retryable" | "retryAfterMs">;
|
|
59
|
-
export type Outcome = Infer<typeof outcome>;
|
|
60
|
-
export interface Plan {
|
|
61
|
-
readonly status: Infer<typeof jobStatus>;
|
|
62
|
-
readonly delayMs: number | null;
|
|
63
|
-
readonly attempts: number;
|
|
64
|
-
}
|
|
65
|
-
export declare function plan(job: {
|
|
66
|
-
readonly attempts: number;
|
|
67
|
-
readonly everyMs?: number;
|
|
68
|
-
}, result: Outcome): Plan;
|
|
69
|
-
export declare function checked(id: string, definition: Operation, value: Value): Outcome;
|
|
70
|
-
export declare function failed(definition: Operation, error: unknown): Extract<Outcome, {
|
|
71
|
-
ok: false;
|
|
72
|
-
}>;
|
|
73
|
-
export declare const enqueue: import("convex/server").RegisteredMutation<"public", {
|
|
1
|
+
import type { GenericId } from "convex/values";
|
|
2
|
+
declare const enqueue: import("convex/server").RegisteredMutation<"public", {
|
|
74
3
|
key?: string;
|
|
75
4
|
delayMs?: number;
|
|
76
5
|
everyMs?: number;
|
|
77
|
-
args: Record<string, Value>;
|
|
6
|
+
args: Record<string, import("convex/values").Value>;
|
|
78
7
|
operation: string;
|
|
79
|
-
}, Promise<
|
|
80
|
-
|
|
81
|
-
jobId:
|
|
8
|
+
}, Promise<GenericId<"jobs">>>;
|
|
9
|
+
declare const load: import("convex/server").RegisteredQuery<"internal", {
|
|
10
|
+
jobId: GenericId<"jobs">;
|
|
82
11
|
}, Promise<{
|
|
83
|
-
_id:
|
|
12
|
+
_id: GenericId<"jobs">;
|
|
84
13
|
_creationTime: number;
|
|
85
14
|
key?: string;
|
|
86
|
-
error?: Value;
|
|
15
|
+
error?: import("convex/values").Value;
|
|
87
16
|
everyMs?: number;
|
|
88
|
-
result?: Value;
|
|
89
|
-
scheduledId?:
|
|
17
|
+
result?: import("convex/values").Value;
|
|
18
|
+
scheduledId?: GenericId<"_scheduled_functions">;
|
|
90
19
|
status: "failed" | "succeeded" | "canceled" | "scheduled";
|
|
91
|
-
args: Record<string, Value>;
|
|
20
|
+
args: Record<string, import("convex/values").Value>;
|
|
92
21
|
operation: string;
|
|
93
22
|
attempts: number;
|
|
94
23
|
runs: number;
|
|
95
24
|
} | null>>;
|
|
96
|
-
|
|
97
|
-
jobId:
|
|
98
|
-
}, Promise<
|
|
99
|
-
|
|
100
|
-
jobId:
|
|
25
|
+
declare const run: import("convex/server").RegisteredAction<"internal", {
|
|
26
|
+
jobId: GenericId<"jobs">;
|
|
27
|
+
}, Promise<void>>;
|
|
28
|
+
declare const finish: import("convex/server").RegisteredMutation<"internal", {
|
|
29
|
+
jobId: GenericId<"jobs">;
|
|
101
30
|
outcome: {
|
|
102
31
|
ok: true;
|
|
103
|
-
result: Value;
|
|
32
|
+
result: import("convex/values").Value;
|
|
104
33
|
} | {
|
|
105
34
|
retryAfterMs?: number;
|
|
106
|
-
error: Value;
|
|
35
|
+
error: import("convex/values").Value;
|
|
107
36
|
ok: false;
|
|
108
37
|
retryable: boolean;
|
|
109
38
|
};
|
|
110
|
-
}, Promise<
|
|
111
|
-
|
|
112
|
-
jobId:
|
|
113
|
-
}, Promise<
|
|
114
|
-
|
|
115
|
-
jobId:
|
|
39
|
+
}, Promise<void>>;
|
|
40
|
+
declare const cancel: import("convex/server").RegisteredMutation<"public", {
|
|
41
|
+
jobId: GenericId<"jobs">;
|
|
42
|
+
}, Promise<void>>;
|
|
43
|
+
declare const get: import("convex/server").RegisteredQuery<"public", {
|
|
44
|
+
jobId: GenericId<"jobs">;
|
|
116
45
|
}, Promise<{
|
|
117
|
-
_id:
|
|
46
|
+
_id: GenericId<"jobs">;
|
|
118
47
|
_creationTime: number;
|
|
119
48
|
key?: string;
|
|
120
|
-
error?: Value;
|
|
49
|
+
error?: import("convex/values").Value;
|
|
121
50
|
everyMs?: number;
|
|
122
|
-
result?: Value;
|
|
123
|
-
scheduledId?:
|
|
51
|
+
result?: import("convex/values").Value;
|
|
52
|
+
scheduledId?: GenericId<"_scheduled_functions">;
|
|
124
53
|
status: "failed" | "succeeded" | "canceled" | "scheduled";
|
|
125
|
-
args: Record<string, Value>;
|
|
54
|
+
args: Record<string, import("convex/values").Value>;
|
|
126
55
|
operation: string;
|
|
127
56
|
attempts: number;
|
|
128
57
|
runs: number;
|
|
129
58
|
} | null>>;
|
|
130
|
-
|
|
59
|
+
declare const list: import("convex/server").RegisteredQuery<"public", {
|
|
131
60
|
status?: "failed" | "succeeded" | "canceled" | "scheduled";
|
|
132
61
|
paginationOpts: {
|
|
133
62
|
id?: number;
|
|
@@ -138,18 +67,18 @@ export declare const list: import("convex/server").RegisteredQuery<"public", {
|
|
|
138
67
|
cursor: string | null;
|
|
139
68
|
};
|
|
140
69
|
}, Promise<import("convex/server").PaginationResult<{
|
|
141
|
-
_id:
|
|
70
|
+
_id: GenericId<"jobs">;
|
|
142
71
|
_creationTime: number;
|
|
143
72
|
key?: string;
|
|
144
|
-
error?: Value;
|
|
73
|
+
error?: import("convex/values").Value;
|
|
145
74
|
everyMs?: number;
|
|
146
|
-
result?: Value;
|
|
147
|
-
scheduledId?:
|
|
75
|
+
result?: import("convex/values").Value;
|
|
76
|
+
scheduledId?: GenericId<"_scheduled_functions">;
|
|
148
77
|
status: "failed" | "succeeded" | "canceled" | "scheduled";
|
|
149
|
-
args: Record<string, Value>;
|
|
78
|
+
args: Record<string, import("convex/values").Value>;
|
|
150
79
|
operation: string;
|
|
151
80
|
attempts: number;
|
|
152
81
|
runs: number;
|
|
153
82
|
}>>>;
|
|
154
|
-
export {};
|
|
83
|
+
export { cancel, enqueue, finish, get, list, load, run };
|
|
155
84
|
//# sourceMappingURL=jobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../../src/component/jobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../../src/component/jobs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAS/C,QAAA,MAAM,OAAO;;;;;;8BAkDX,CAAC;AAEH,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;UAIR,CAAC;AAEH,QAAA,MAAM,GAAG;;iBAqBP,CAAC;AAEH,QAAA,MAAM,MAAM;;;;;;;;;;;iBA0CV,CAAC;AAEH,QAAA,MAAM,MAAM;;iBAgBV,CAAC;AAEH,QAAA,MAAM,GAAG;;;;;;;;;;;;;;;UAOP,CAAC;AAEH,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;IAcR,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC"}
|