-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
47 lines (45 loc) · 1.22 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import redirects from "./redirects.json";
import { basehub } from "basehub";
import chunk from "lodash/chunk";
const { redirectsTarget } = await basehub().query({
redirectsTarget: {
_id: true,
},
});
for (const redirectsChunk of chunk(redirects, 500)) {
const { transaction } = await basehub().mutation({
transaction: {
__args: {
data: redirectsChunk.map((redirect) => {
const title = `${redirect.source} -> ${redirect.destination}`;
return {
type: "create",
parentId: redirectsTarget._id,
data: {
type: "instance",
title,
idempotency: { key: "title", value: title },
value: {
source: {
type: "text",
value: redirect.source,
},
destination: {
type: "text",
value: redirect.destination,
},
permanent: {
type: "boolean",
value: redirect.permanent,
},
},
},
};
}),
},
status: true,
message: true,
},
});
console.log({ transaction });
}