@convex-dev/crons 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -28
- package/package.json +16 -3
- package/dist/commonjs/component/index.d.ts +0 -135
- package/dist/commonjs/component/index.d.ts.map +0 -1
- package/dist/commonjs/component/index.js +0 -289
- package/dist/commonjs/component/index.js.map +0 -1
- package/dist/commonjs/component/parseArgs.d.ts +0 -11
- package/dist/commonjs/component/parseArgs.d.ts.map +0 -1
- package/dist/commonjs/component/parseArgs.js +0 -28
- package/dist/commonjs/component/parseArgs.js.map +0 -1
- package/dist/commonjs/frontend/index.d.ts +0 -2
- package/dist/commonjs/frontend/index.d.ts.map +0 -1
- package/dist/commonjs/frontend/index.js +0 -8
- package/dist/commonjs/frontend/index.js.map +0 -1
- package/dist/esm/component/index.d.ts +0 -135
- package/dist/esm/component/index.d.ts.map +0 -1
- package/dist/esm/component/index.js +0 -289
- package/dist/esm/component/index.js.map +0 -1
- package/dist/esm/component/parseArgs.d.ts +0 -11
- package/dist/esm/component/parseArgs.d.ts.map +0 -1
- package/dist/esm/component/parseArgs.js +0 -28
- package/dist/esm/component/parseArgs.js.map +0 -1
- package/dist/esm/frontend/index.d.ts +0 -2
- package/dist/esm/frontend/index.d.ts.map +0 -1
- package/dist/esm/frontend/index.js +0 -8
- package/dist/esm/frontend/index.js.map +0 -1
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
// Implementation of crons in user space.
|
|
2
|
-
//
|
|
3
|
-
// Crons can be registered at runtime via the `registerCron` or
|
|
4
|
-
// `registerInterval` mutations.
|
|
5
|
-
//
|
|
6
|
-
// If you'd like to statically define cronjobs like in the built-in `crons.ts`
|
|
7
|
-
// Convex feature you can do so via an init script that idempotently registers a
|
|
8
|
-
// cron with a given name. e.g., in an `init.ts` file that gets run on every
|
|
9
|
-
// deploy via `convex dev --run init`:
|
|
10
|
-
//
|
|
11
|
-
// if ((await ctx.runQuery(components.crons.lib.getByName, { name: "daily" })) == null) {
|
|
12
|
-
// await ctx.runMutation(components.crons.lib.registerCron, {
|
|
13
|
-
// name: "daily",
|
|
14
|
-
// cronspec: "0 0 * * *",
|
|
15
|
-
// functionHandle: await createFunctionHandle(internal.whatever.myFunctionName)
|
|
16
|
-
// args: { message: "daily cron" },
|
|
17
|
-
// });
|
|
18
|
-
// }
|
|
19
|
-
import { v } from "convex/values";
|
|
20
|
-
import { parseArgs } from "./parseArgs.js";
|
|
21
|
-
import { mutation, query, internalMutation, } from "./_generated/server.js";
|
|
22
|
-
import { internal } from "./_generated/api.js";
|
|
23
|
-
import parser from "cron-parser";
|
|
24
|
-
/**
|
|
25
|
-
* Schedule a mutation or action to run on a recurring basis.
|
|
26
|
-
*
|
|
27
|
-
* Like the unix command `cron`, Sunday is 0, Monday is 1, etc.
|
|
28
|
-
*
|
|
29
|
-
* ```
|
|
30
|
-
* * * * * * *
|
|
31
|
-
* ┬ ┬ ┬ ┬ ┬ ┬
|
|
32
|
-
* │ │ │ │ │ |
|
|
33
|
-
* │ │ │ │ │ └── day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
|
|
34
|
-
* │ │ │ │ └───── month (1 - 12)
|
|
35
|
-
* │ │ │ └──────── day of month (1 - 31, L)
|
|
36
|
-
* │ │ └─────────── hour (0 - 23)
|
|
37
|
-
* │ └────────────── minute (0 - 59)
|
|
38
|
-
* └───────────────── second (0 - 59, optional)
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @param name - Optional unique name for the cron job. Will throw if a name is
|
|
42
|
-
* provided and a cron with the same name already exists.
|
|
43
|
-
* @param cronspec - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
|
|
44
|
-
* @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
|
|
45
|
-
* @param args - The arguments to the function.
|
|
46
|
-
* @returns The ID of the cron job.
|
|
47
|
-
*/
|
|
48
|
-
export const registerCron = mutation({
|
|
49
|
-
args: {
|
|
50
|
-
name: v.optional(v.string()),
|
|
51
|
-
cronspec: v.string(),
|
|
52
|
-
functionHandle: v.string(),
|
|
53
|
-
args: v.any(),
|
|
54
|
-
},
|
|
55
|
-
handler: async (ctx, { name, cronspec, functionHandle, args }) => {
|
|
56
|
-
return await scheduleCron(ctx, { cronspec: cronspec, kind: "cron" }, functionHandle, name, args);
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
/**
|
|
60
|
-
* Schedule a mutation or action to run on the given interval.
|
|
61
|
-
*
|
|
62
|
-
* @param name - Optional unique name for the cron job. Will throw if a name is
|
|
63
|
-
* provided and a cron with the same name already exists.
|
|
64
|
-
* @param ms - The time in ms between runs for this scheduled job, >= 1000.
|
|
65
|
-
* @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
|
|
66
|
-
* @param args - Any arguments to the function.
|
|
67
|
-
* @returns The ID of the cron job.
|
|
68
|
-
*/
|
|
69
|
-
export const registerInterval = mutation({
|
|
70
|
-
args: {
|
|
71
|
-
name: v.optional(v.string()),
|
|
72
|
-
ms: v.float64(),
|
|
73
|
-
functionHandle: v.string(),
|
|
74
|
-
args: v.any(),
|
|
75
|
-
},
|
|
76
|
-
handler: async (ctx, { name, ms, functionHandle, args }) => {
|
|
77
|
-
return await scheduleCron(ctx, { kind: "interval", ms }, functionHandle, name, args);
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
/**
|
|
81
|
-
* List all user space cron jobs.
|
|
82
|
-
*
|
|
83
|
-
* @returns List of `cron` table rows.
|
|
84
|
-
*/
|
|
85
|
-
export const list = query({
|
|
86
|
-
args: {},
|
|
87
|
-
handler: async (ctx) => {
|
|
88
|
-
return await ctx.db.query("crons").collect();
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
/**
|
|
92
|
-
* Get an existing cron job by id.
|
|
93
|
-
*
|
|
94
|
-
* @param id - ID of the cron job.
|
|
95
|
-
* @returns Cron job document.
|
|
96
|
-
*/
|
|
97
|
-
export const get = query({
|
|
98
|
-
args: {
|
|
99
|
-
id: v.id("crons"),
|
|
100
|
-
},
|
|
101
|
-
handler: async (ctx, { id }) => {
|
|
102
|
-
return await ctx.db.get(id);
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
/**
|
|
106
|
-
* Get an existing cron job by name.
|
|
107
|
-
*
|
|
108
|
-
* @param name - Name of the cron job.
|
|
109
|
-
* @returns Cron job document.
|
|
110
|
-
*/
|
|
111
|
-
export const getByName = query({
|
|
112
|
-
args: {
|
|
113
|
-
name: v.string(),
|
|
114
|
-
},
|
|
115
|
-
handler: async (ctx, { name }) => {
|
|
116
|
-
return await ctx.db
|
|
117
|
-
.query("crons")
|
|
118
|
-
.withIndex("name", (q) => q.eq("name", name))
|
|
119
|
-
.unique();
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
/**
|
|
123
|
-
* Delete and deschedule a cron job by id.
|
|
124
|
-
*
|
|
125
|
-
* @param id - ID of the cron job.
|
|
126
|
-
*/
|
|
127
|
-
export const del = mutation({
|
|
128
|
-
args: {
|
|
129
|
-
id: v.id("crons"),
|
|
130
|
-
},
|
|
131
|
-
handler: async (ctx, { id }) => {
|
|
132
|
-
const cron = await ctx.db.get(id);
|
|
133
|
-
if (!cron) {
|
|
134
|
-
throw new Error(`Cron ${id} not found`);
|
|
135
|
-
}
|
|
136
|
-
await delCron(ctx, cron);
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
/**
|
|
140
|
-
* Delete and deschedule a cron job by name.
|
|
141
|
-
*
|
|
142
|
-
* @param name - Name of the cron job.
|
|
143
|
-
*/
|
|
144
|
-
export const delByName = mutation({
|
|
145
|
-
args: {
|
|
146
|
-
name: v.string(),
|
|
147
|
-
},
|
|
148
|
-
handler: async (ctx, { name }) => {
|
|
149
|
-
const cron = await ctx.db
|
|
150
|
-
.query("crons")
|
|
151
|
-
.withIndex("name", (q) => q.eq("name", name))
|
|
152
|
-
.unique();
|
|
153
|
-
if (!cron) {
|
|
154
|
-
throw new Error(`Cron "${name}" not found`);
|
|
155
|
-
}
|
|
156
|
-
await delCron(ctx, cron);
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
async function delCron(ctx, cron) {
|
|
160
|
-
if (!cron.schedulerJobId) {
|
|
161
|
-
throw new Error(`Cron ${cron._id} not scheduled`);
|
|
162
|
-
}
|
|
163
|
-
console.log(`Canceling scheduler job ${cron.schedulerJobId}`);
|
|
164
|
-
await ctx.scheduler.cancel(cron.schedulerJobId);
|
|
165
|
-
if (cron.executionJobId) {
|
|
166
|
-
console.log(`Canceling execution job ${cron.executionJobId}`);
|
|
167
|
-
await ctx.scheduler.cancel(cron.executionJobId);
|
|
168
|
-
}
|
|
169
|
-
console.log(`Deleting cron ${cron._id}`);
|
|
170
|
-
await ctx.db.delete(cron._id);
|
|
171
|
-
}
|
|
172
|
-
// Initial registration and scheduling of the cron job.
|
|
173
|
-
async function scheduleCron(ctx, schedule, functionHandle, name, args) {
|
|
174
|
-
// Input validation
|
|
175
|
-
if (name &&
|
|
176
|
-
(await ctx.db
|
|
177
|
-
.query("crons")
|
|
178
|
-
.withIndex("name", (q) => q.eq("name", name))
|
|
179
|
-
.unique())) {
|
|
180
|
-
throw new Error(`Cron with name "${name}" already exists`);
|
|
181
|
-
}
|
|
182
|
-
if (schedule.kind === "interval" && schedule.ms < 1000) {
|
|
183
|
-
throw new Error("Interval must be >= 1000ms"); // Just a sanity check.
|
|
184
|
-
}
|
|
185
|
-
if (schedule.kind === "cron") {
|
|
186
|
-
try {
|
|
187
|
-
parser.parseExpression(schedule.cronspec);
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
throw new Error(`Invalid cronspec: "${schedule.cronspec}"`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
args = parseArgs(args);
|
|
194
|
-
if (schedule.kind === "interval") {
|
|
195
|
-
const id = await ctx.db.insert("crons", {
|
|
196
|
-
functionHandle,
|
|
197
|
-
args,
|
|
198
|
-
name,
|
|
199
|
-
schedule: { kind: "interval", ms: schedule.ms },
|
|
200
|
-
});
|
|
201
|
-
// TODO: add support for extracting the function name from a function handle
|
|
202
|
-
console.log(`Scheduling cron with name "${name}" and id ${id} to run ${functionHandle}(${JSON.stringify(args)}) every ${schedule.ms} ms`);
|
|
203
|
-
const schedulerJobId = await ctx.scheduler.runAfter(schedule.ms, internal.index.rescheduler, { id });
|
|
204
|
-
await ctx.db.patch(id, { schedulerJobId });
|
|
205
|
-
return id;
|
|
206
|
-
}
|
|
207
|
-
const id = await ctx.db.insert("crons", {
|
|
208
|
-
functionHandle,
|
|
209
|
-
args,
|
|
210
|
-
name,
|
|
211
|
-
schedule: { kind: "cron", cronspec: schedule.cronspec },
|
|
212
|
-
});
|
|
213
|
-
console.log(`Scheduling cron with name "${name}" and id ${id} to run ${functionHandle}(${JSON.stringify(args)}) on cronspec "${schedule.cronspec}"`);
|
|
214
|
-
const schedulerJobId = await ctx.scheduler.runAt(nextScheduledDate(new Date(), schedule.cronspec), internal.index.rescheduler, { id });
|
|
215
|
-
await ctx.db.patch(id, { schedulerJobId });
|
|
216
|
-
return id;
|
|
217
|
-
}
|
|
218
|
-
// Continue rescheduling a cron job.
|
|
219
|
-
//
|
|
220
|
-
// This is the main worker function that does the scheduling but also schedules
|
|
221
|
-
// the target function so that it runs in a different context. As a result this
|
|
222
|
-
// function probably *shouldn't* fail since it isn't doing much, but under heavy
|
|
223
|
-
// OCC contention it's possible it may eventually fail. In this case the cron
|
|
224
|
-
// will be lost and we'll need a janitor job to recover it.
|
|
225
|
-
export const rescheduler = internalMutation({
|
|
226
|
-
args: {
|
|
227
|
-
id: v.id("crons"),
|
|
228
|
-
},
|
|
229
|
-
handler: async (ctx, { id }) => {
|
|
230
|
-
// Cron job is the logical concept we're rescheduling repeatedly.
|
|
231
|
-
const cronJob = await ctx.db.get(id);
|
|
232
|
-
if (!cronJob) {
|
|
233
|
-
throw Error(`Cron ${id} not found`);
|
|
234
|
-
}
|
|
235
|
-
if (!cronJob.schedulerJobId) {
|
|
236
|
-
throw Error(`Cron ${id} not scheduled`);
|
|
237
|
-
}
|
|
238
|
-
// Scheduler job is the job that's running right now, that we use to trigger
|
|
239
|
-
// repeated executions.
|
|
240
|
-
const schedulerJob = await ctx.db.system.get(cronJob.schedulerJobId);
|
|
241
|
-
if (!schedulerJob) {
|
|
242
|
-
throw Error(`Scheduler job ${cronJob.schedulerJobId} not found`);
|
|
243
|
-
}
|
|
244
|
-
// XXX The convex-test library runs mutations through the `inProgress` state
|
|
245
|
-
// but the production state machine does not. Remove the `inProgress` allowance
|
|
246
|
-
// once the test library has been updated.
|
|
247
|
-
if (schedulerJob.state.kind !== "pending" &&
|
|
248
|
-
schedulerJob.state.kind !== "inProgress") {
|
|
249
|
-
throw Error(`We are running in job ${schedulerJob._id} but state is ${schedulerJob.state.kind}`);
|
|
250
|
-
}
|
|
251
|
-
// Execution job is the previous job used to actually do the work of the cron.
|
|
252
|
-
let stillRunning = false;
|
|
253
|
-
if (cronJob.executionJobId) {
|
|
254
|
-
const executionJob = await ctx.db.system.get(cronJob.executionJobId);
|
|
255
|
-
if (executionJob &&
|
|
256
|
-
(executionJob.state.kind === "pending" ||
|
|
257
|
-
executionJob.state.kind === "inProgress")) {
|
|
258
|
-
stillRunning = true;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (stillRunning) {
|
|
262
|
-
console.log(`Cron ${cronJob._id} still running, skipping this run.`);
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
console.log(`Running cron ${cronJob._id}.`);
|
|
266
|
-
await ctx.scheduler.runAfter(0, cronJob.functionHandle, cronJob.args);
|
|
267
|
-
}
|
|
268
|
-
// Now reschedule the next run.
|
|
269
|
-
if (cronJob.schedule.kind === "interval") {
|
|
270
|
-
const nextTime = schedulerJob.scheduledTime + cronJob.schedule.ms;
|
|
271
|
-
const nextSchedulerJobId = await ctx.scheduler.runAt(nextTime, internal.index.rescheduler, { id });
|
|
272
|
-
await ctx.db.patch(id, { schedulerJobId: nextSchedulerJobId });
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
const nextTime = nextScheduledDate(new Date(schedulerJob.scheduledTime), cronJob.schedule.cronspec);
|
|
276
|
-
const nextSchedulerJobId = await ctx.scheduler.runAt(nextTime, internal.index.rescheduler, { id });
|
|
277
|
-
await ctx.db.patch(id, { schedulerJobId: nextSchedulerJobId });
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
|
-
// Calculate the next date to run a cron given the last time it was scheduled.
|
|
282
|
-
function nextScheduledDate(prevDate, cronspec) {
|
|
283
|
-
const options = {
|
|
284
|
-
currentDate: prevDate,
|
|
285
|
-
};
|
|
286
|
-
const interval = parser.parseExpression(cronspec, options);
|
|
287
|
-
return interval.next().toDate();
|
|
288
|
-
}
|
|
289
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,+DAA+D;AAC/D,gCAAgC;AAChC,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,sCAAsC;AACtC,EAAE;AACF,yFAAyF;AACzF,+DAA+D;AAC/D,qBAAqB;AACrB,6BAA6B;AAC7B,mFAAmF;AACnF,uCAAuC;AACvC,QAAQ;AACR,IAAI;AAGJ,OAAO,EAAE,CAAC,EAAS,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAEL,QAAQ,EACR,KAAK,EACL,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAA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E,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;SAChE;IACH,CAAC;CACF,CAAC,CAAC;AAEH,8EAA8E;AAC9E,SAAS,iBAAiB,CAAC,QAAc,EAAE,QAAgB;IACzD,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;KACtB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Value } from "convex/values";
|
|
2
|
-
/**
|
|
3
|
-
* Validate that the arguments to a Convex function are an object, defaulting
|
|
4
|
-
* `undefined` to `{}`.
|
|
5
|
-
*/
|
|
6
|
-
export declare function parseArgs(args: Record<string, Value> | undefined): Record<string, Value>;
|
|
7
|
-
/**
|
|
8
|
-
* Check whether a value is a plain old JavaScript object.
|
|
9
|
-
*/
|
|
10
|
-
export declare function isSimpleObject(value: unknown): boolean;
|
|
11
|
-
//# sourceMappingURL=parseArgs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseArgs.d.ts","sourceRoot":"","sources":["../../../src/component/parseArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,SAAS,GACtC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAYvB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,WAU5C"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// TODO export these from Convex if they're not already
|
|
2
|
-
/**
|
|
3
|
-
* Validate that the arguments to a Convex function are an object, defaulting
|
|
4
|
-
* `undefined` to `{}`.
|
|
5
|
-
*/
|
|
6
|
-
export function parseArgs(args) {
|
|
7
|
-
if (args === undefined) {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
if (!isSimpleObject(args)) {
|
|
11
|
-
throw new Error(`The arguments to a Convex function must be an object. Received: ${args}`);
|
|
12
|
-
}
|
|
13
|
-
return args;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Check whether a value is a plain old JavaScript object.
|
|
17
|
-
*/
|
|
18
|
-
export function isSimpleObject(value) {
|
|
19
|
-
const isObject = typeof value === "object";
|
|
20
|
-
const prototype = Object.getPrototypeOf(value);
|
|
21
|
-
const isSimple = prototype === null ||
|
|
22
|
-
prototype === Object.prototype ||
|
|
23
|
-
// Objects generated from other contexts (e.g. across Node.js `vm` modules) will not satisfy the previous
|
|
24
|
-
// conditions but are still simple objects.
|
|
25
|
-
prototype?.constructor?.name === "Object";
|
|
26
|
-
return isObject && isSimple;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=parseArgs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseArgs.js","sourceRoot":"","sources":["../../../src/component/parseArgs.ts"],"names":[],"mappings":"AAEA,uDAAuD;AAEvD;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,IAAuC;IAEvC,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,OAAO,EAAE,CAAC;KACX;IACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,mEACE,IACF,EAAE,CACH,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,QAAQ,GACZ,SAAS,KAAK,IAAI;QAClB,SAAS,KAAK,MAAM,CAAC,SAAS;QAC9B,yGAAyG;QACzG,2CAA2C;QAC3C,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC;IAC5C,OAAO,QAAQ,IAAI,QAAQ,CAAC;AAC9B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frontend/index.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frontend/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;CAC5E;AAED,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|