Updated 3 files and added 149 files (automated)
parent
2be5c54104
commit
8ee7b84763
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JavaScriptLibraryMappings">
|
||||
<includedPredefinedLibrary name="Node.js Core" />
|
||||
</component>
|
||||
</project>
|
@ -1 +1 @@
|
||||
12.2.1
|
||||
12.2.2
|
@ -0,0 +1,258 @@
|
||||
const axios = require('axios');
|
||||
const secrets = require('../secrets.json');
|
||||
const list = require('./list.json');
|
||||
const names = require('../projects.json');
|
||||
const fs = require('fs');
|
||||
|
||||
let found = [];
|
||||
|
||||
function generateShortName(name) {
|
||||
let parts = name.toLowerCase().replace(/[^a-z\d -]/gm, "").replaceAll(" ", "-").split("-");
|
||||
let newName = "";
|
||||
|
||||
if (name.toLowerCase().replace(/[^a-z\d]/gm, "").length <= 4) {
|
||||
return name.toLowerCase().replace(/[^a-z\d]/gm, "").toUpperCase();
|
||||
}
|
||||
|
||||
if (parts.length === 1) {
|
||||
let letters = name.toLowerCase().replace(/[aeiouy\d]/gm, "").toUpperCase();
|
||||
|
||||
if (letters.length < 4) {
|
||||
return letters.substring(0, 4);
|
||||
} else {
|
||||
return letters.substring(0, 2) + letters.substring(letters.length - 2, letters.length + 1);
|
||||
}
|
||||
} else {
|
||||
for (let index in parts) {
|
||||
index = parseInt(index);
|
||||
if (index > 2) continue;
|
||||
|
||||
newName += parts[index].substring(0, 1).toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
return newName;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await axios.post("https://auth.equestria.horse/hub/api/rest/roles/15f32332-f7a0-4e3d-83cb-e869585416b0/reset", {}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})
|
||||
|
||||
return;
|
||||
|
||||
let token = (await axios.post("https://auth.equestria.horse/hub/api/rest/oauth2/token", "grant_type=client_credentials&scope=Hub", {
|
||||
headers: {
|
||||
Authorization: "Basic " + Buffer.from(secrets.service).toString("base64")
|
||||
}
|
||||
})).data['access_token'];
|
||||
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/services/6c532510-08b5-42f5-8199-c7277ad33274", {
|
||||
key: "VCS",
|
||||
vendor: "The Gitea Authors",
|
||||
applicationName: "Gitea",
|
||||
version: (await axios.get("https://git.equestria.dev/api/v1/version")).data.version
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + token
|
||||
}
|
||||
}));
|
||||
|
||||
let projects = [];
|
||||
let page = 1;
|
||||
let results = [null];
|
||||
|
||||
while (results.length > 0) {
|
||||
results = (await axios.get("https://git.equestria.dev/api/v1/orgs/equestria.dev/repos?limit=1000&page=" + page + "&token=" + secrets.gitea)).data;
|
||||
projects.push(...results);
|
||||
page++;
|
||||
}
|
||||
|
||||
for (let project of projects) {
|
||||
console.log("[" + project.id + "] " + project.name + (project['archived'] && project['private'] ? " (archived, private)" : (project['archived'] ? " (archived)" : (project['private'] ? " (private)" : ""))));
|
||||
|
||||
found.push(project.id.toString());
|
||||
|
||||
if (!Object.keys(list).includes(project['id'].toString())) {
|
||||
list[project.id] = {
|
||||
id: (await axios.post("https://bugs.equestria.dev/api/admin/projects", {
|
||||
name: project.name,
|
||||
shortName: generateShortName(project.name),
|
||||
leader: {
|
||||
id: "1-0"
|
||||
}
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data.id,
|
||||
shortName: generateShortName(project.name),
|
||||
organization: {
|
||||
id: project['private'] ? "297eeed8-a9f2-45f6-8c17-6543f25930bb" : "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
};
|
||||
|
||||
console.log(" Created on YouTrack with ID " + list[project.id].id + " and name " + list[project.id].shortName);
|
||||
} else if (Object.keys(list).includes(project['id'])) {
|
||||
console.log(" Project is already on YouTrack");
|
||||
}
|
||||
|
||||
fs.writeFileSync("list.json", JSON.stringify(list, null, 2));
|
||||
}
|
||||
|
||||
console.log("Running tasks...");
|
||||
|
||||
for (let project in list) {
|
||||
console.log(" " + project + ": " + list[project]["id"]);
|
||||
|
||||
if (!found.includes(project)) {
|
||||
console.log(" => Preparing to delete");
|
||||
|
||||
let hub = (await axios.get("https://auth.equestria.horse/hub/api/rest/projects?archived=true", {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data['projects'];
|
||||
|
||||
for (let prj of hub) {
|
||||
if (!list[project]) continue;
|
||||
process.stdout.write(" " + prj.id + ": " + prj.name);
|
||||
|
||||
let id = prj['resources'].filter(i => i.key)[0].id;
|
||||
let yt = null;
|
||||
|
||||
try {
|
||||
yt = (await axios.get("https://bugs.equestria.dev/api/admin/projects/" + id, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data.id;
|
||||
} catch (e) {}
|
||||
|
||||
console.log(": " + yt);
|
||||
|
||||
if (yt === list[project]["id"]) {
|
||||
console.log(" Matching!");
|
||||
|
||||
(await axios.delete("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
|
||||
(await axios.delete("https://bugs.equestria.dev/api/admin/projects/" + list[project]["id"], {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
|
||||
delete list[project];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log(" => Preparing to sync");
|
||||
let gitea = projects.filter(i => i.id.toString() === project)[0];
|
||||
|
||||
let hub = (await axios.get("https://auth.equestria.horse/hub/api/rest/projects?archived=true", {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data['projects'];
|
||||
|
||||
for (let prj of hub) {
|
||||
process.stdout.write(" " + prj.id + ": " + prj.name);
|
||||
|
||||
let id = prj['resources'].filter(i => i.key)[0].id;
|
||||
let yt = null;
|
||||
|
||||
try {
|
||||
yt = (await axios.get("https://bugs.equestria.dev/api/admin/projects/" + id, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data.id;
|
||||
} catch (e) {}
|
||||
|
||||
console.log(": " + yt);
|
||||
|
||||
if (yt === list[project]["id"]) {
|
||||
console.log(" Matching!");
|
||||
|
||||
if (gitea['archived']) {
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
archived: true
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
}
|
||||
|
||||
if (gitea['private']) {
|
||||
console.log(" Marking as private");
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
organization: {
|
||||
id: "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
} else {
|
||||
console.log(" Marking as public");
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
organization: {
|
||||
id: "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
}
|
||||
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
description: gitea['description']
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
|
||||
if (Object.keys(names).includes(gitea['name'])) {
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
name: names[gitea['name']]
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
|
||||
(await axios.post("https://bugs.equestria.dev/api/admin/projects/" + yt, {
|
||||
name: names[gitea['name']]
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
}
|
||||
|
||||
if (gitea['avatar_url']) {
|
||||
(await axios.post("https://auth.equestria.horse/hub/api/rest/projects/" + prj.id, {
|
||||
icon: "data:image/png;base64," + (await axios.get(gitea['avatar_url'], { responseType: 'arraybuffer' })).data.toString("base64")
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + secrets.youtrack
|
||||
}
|
||||
})).data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync("list.json", JSON.stringify(list, null, 2));
|
||||
})();
|
@ -0,0 +1,394 @@
|
||||
{
|
||||
"7": {
|
||||
"id": "0-369",
|
||||
"shortName": "ZN",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"11": {
|
||||
"id": "0-370",
|
||||
"shortName": "DP3",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"13": {
|
||||
"id": "0-371",
|
||||
"shortName": "VPRL",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"14": {
|
||||
"id": "0-372",
|
||||
"shortName": "VS",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"15": {
|
||||
"id": "0-373",
|
||||
"shortName": "DSGN",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"17": {
|
||||
"id": "0-374",
|
||||
"shortName": "DP",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"18": {
|
||||
"id": "0-375",
|
||||
"shortName": "QSDB",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"19": {
|
||||
"id": "0-376",
|
||||
"shortName": "BS",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"20": {
|
||||
"id": "0-377",
|
||||
"shortName": "BC",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"21": {
|
||||
"id": "0-378",
|
||||
"shortName": "ELAC",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"24": {
|
||||
"id": "0-379",
|
||||
"shortName": "PIT",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"25": {
|
||||
"id": "0-380",
|
||||
"shortName": "SO",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"26": {
|
||||
"id": "0-381",
|
||||
"shortName": "SB",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"28": {
|
||||
"id": "0-382",
|
||||
"shortName": "IS",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"29": {
|
||||
"id": "0-383",
|
||||
"shortName": "CP",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"33": {
|
||||
"id": "0-384",
|
||||
"shortName": "CH",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"34": {
|
||||
"id": "0-385",
|
||||
"shortName": "HRHT",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"35": {
|
||||
"id": "0-386",
|
||||
"shortName": "TRRT",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"89": {
|
||||
"id": "0-387",
|
||||
"shortName": "HRSS",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"90": {
|
||||
"id": "0-388",
|
||||
"shortName": "STTS",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"91": {
|
||||
"id": "0-389",
|
||||
"shortName": "ET",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"92": {
|
||||
"id": "0-390",
|
||||
"shortName": "MS",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"93": {
|
||||
"id": "0-391",
|
||||
"shortName": "MT",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"94": {
|
||||
"id": "0-392",
|
||||
"shortName": "MO",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"95": {
|
||||
"id": "0-393",
|
||||
"shortName": "MI",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"96": {
|
||||
"id": "0-394",
|
||||
"shortName": "LUNA",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"97": {
|
||||
"id": "0-395",
|
||||
"shortName": "PNCN",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"98": {
|
||||
"id": "0-396",
|
||||
"shortName": "PTCH",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"99": {
|
||||
"id": "0-397",
|
||||
"shortName": "TMSK",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"100": {
|
||||
"id": "0-398",
|
||||
"shortName": "WING",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"101": {
|
||||
"id": "0-399",
|
||||
"shortName": "C",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"102": {
|
||||
"id": "0-400",
|
||||
"shortName": "WC",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"105": {
|
||||
"id": "0-401",
|
||||
"shortName": "PLTT",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"106": {
|
||||
"id": "0-402",
|
||||
"shortName": "MSCH",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"107": {
|
||||
"id": "0-403",
|
||||
"shortName": "MSWN",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"108": {
|
||||
"id": "0-404",
|
||||
"shortName": "DLT",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"109": {
|
||||
"id": "0-405",
|
||||
"shortName": "PNSH",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"110": {
|
||||
"id": "0-406",
|
||||
"shortName": "GNTL",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"111": {
|
||||
"id": "0-407",
|
||||
"shortName": "DA",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"112": {
|
||||
"id": "0-408",
|
||||
"shortName": "PLEX",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"113": {
|
||||
"id": "0-409",
|
||||
"shortName": "PNCH",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"114": {
|
||||
"id": "0-410",
|
||||
"shortName": "TPSH",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"116": {
|
||||
"id": "0-411",
|
||||
"shortName": "NOTS",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"117": {
|
||||
"id": "0-412",
|
||||
"shortName": "PPN",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"118": {
|
||||
"id": "0-413",
|
||||
"shortName": "PLWR",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"119": {
|
||||
"id": "0-414",
|
||||
"shortName": "BR",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"120": {
|
||||
"id": "0-415",
|
||||
"shortName": "BG",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"121": {
|
||||
"id": "0-416",
|
||||
"shortName": "OSAL",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"122": {
|
||||
"id": "0-417",
|
||||
"shortName": "DMN",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"123": {
|
||||
"id": "0-418",
|
||||
"shortName": "SE",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"126": {
|
||||
"id": "0-419",
|
||||
"shortName": "DK",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
},
|
||||
"127": {
|
||||
"id": "0-420",
|
||||
"shortName": "CHA",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"128": {
|
||||
"id": "0-421",
|
||||
"shortName": "DTZD",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"129": {
|
||||
"id": "0-422",
|
||||
"shortName": "MSDL",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"130": {
|
||||
"id": "0-423",
|
||||
"shortName": "PONE",
|
||||
"organization": {
|
||||
"id": "297eeed8-a9f2-45f6-8c17-6543f25930bb"
|
||||
}
|
||||
},
|
||||
"131": {
|
||||
"id": "0-424",
|
||||
"shortName": "PWLS",
|
||||
"organization": {
|
||||
"id": "957f7b0e-3aa3-4c08-9fb2-d708e8b23ff4"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
{
|
||||
"name": "youtrack",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz",
|
||||
"integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Alex Indigo
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -0,0 +1,233 @@
|
||||
# asynckit [](https://www.npmjs.com/package/asynckit)
|
||||
|
||||
Minimal async jobs utility library, with streams support.
|
||||
|
||||
[](https://travis-ci.org/alexindigo/asynckit)
|
||||
[](https://travis-ci.org/alexindigo/asynckit)
|
||||
[](https://ci.appveyor.com/project/alexindigo/asynckit)
|
||||
|
||||
[](https://coveralls.io/github/alexindigo/asynckit?branch=master)
|
||||
[](https://david-dm.org/alexindigo/asynckit)
|
||||
[](https://www.bithound.io/github/alexindigo/asynckit)
|
||||
|
||||
<!-- [](https://www.npmjs.com/package/reamde) -->
|
||||
|
||||
AsyncKit provides harness for `parallel` and `serial` iterators over list of items represented by arrays or objects.
|
||||
Optionally it accepts abort function (should be synchronously return by iterator for each item), and terminates left over jobs upon an error event. For specific iteration order built-in (`ascending` and `descending`) and custom sort helpers also supported, via `asynckit.serialOrdered` method.
|
||||
|
||||
It ensures async operations to keep behavior more stable and prevent `Maximum call stack size exceeded` errors, from sync iterators.
|
||||
|
||||
| compression | size |
|
||||
| :----------------- | -------: |
|
||||
| asynckit.js | 12.34 kB |
|
||||
| asynckit.min.js | 4.11 kB |
|
||||
| asynckit.min.js.gz | 1.47 kB |
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install --save asynckit
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Parallel Jobs
|
||||
|
||||
Runs iterator over provided array in parallel. Stores output in the `result` array,
|
||||
on the matching positions. In unlikely event of an error from one of the jobs,
|
||||
will terminate rest of the active jobs (if abort function is provided)
|
||||
and return error along with salvaged data to the main callback function.
|
||||
|
||||
#### Input Array
|
||||
|
||||
```javascript
|
||||
var parallel = require('asynckit').parallel
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
parallel(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// async job accepts one element from the array
|
||||
// and a callback function
|
||||
function asyncJob(item, cb)
|
||||
{
|
||||
// different delays (in ms) per item
|
||||
var delay = item * 25;
|
||||
|
||||
// pretend different jobs take different time to finish
|
||||
// and not in consequential order
|
||||
var timeoutId = setTimeout(function() {
|
||||
target.push(item);
|
||||
cb(null, item * 2);
|
||||
}, delay);
|
||||
|
||||
// allow to cancel "leftover" jobs upon error
|
||||
// return function, invoking of which will abort this job
|
||||
return clearTimeout.bind(null, timeoutId);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-parallel-array.js](test/test-parallel-array.js).
|
||||
|
||||
#### Input Object
|
||||
|
||||
Also it supports named jobs, listed via object.
|
||||
|
||||
```javascript
|
||||
var parallel = require('asynckit/parallel')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
|
||||
, expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
|
||||
, expectedTarget = [ 1, 1, 2, 4, 8, 16, 32, 64 ]
|
||||
, expectedKeys = [ 'first', 'one', 'two', 'four', 'eight', 'sixteen', 'thirtyTwo', 'sixtyFour' ]
|
||||
, target = []
|
||||
, keys = []
|
||||
;
|
||||
|
||||
parallel(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
assert.deepEqual(keys, expectedKeys);
|
||||
});
|
||||
|
||||
// supports full value, key, callback (shortcut) interface
|
||||
function asyncJob(item, key, cb)
|
||||
{
|
||||
// different delays (in ms) per item
|
||||
var delay = item * 25;
|
||||
|
||||
// pretend different jobs take different time to finish
|
||||
// and not in consequential order
|
||||
var timeoutId = setTimeout(function() {
|
||||
keys.push(key);
|
||||
target.push(item);
|
||||
cb(null, item * 2);
|
||||
}, delay);
|
||||
|
||||
// allow to cancel "leftover" jobs upon error
|
||||
// return function, invoking of which will abort this job
|
||||
return clearTimeout.bind(null, timeoutId);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-parallel-object.js](test/test-parallel-object.js).
|
||||
|
||||
### Serial Jobs
|
||||
|
||||
Runs iterator over provided array sequentially. Stores output in the `result` array,
|
||||
on the matching positions. In unlikely event of an error from one of the jobs,
|
||||
will not proceed to the rest of the items in the list
|
||||
and return error along with salvaged data to the main callback function.
|
||||
|
||||
#### Input Array
|
||||
|
||||
```javascript
|
||||
var serial = require('asynckit/serial')
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
serial(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// extended interface (item, key, callback)
|
||||
// also supported for arrays
|
||||
function asyncJob(item, key, cb)
|
||||
{
|
||||
target.push(key);
|
||||
|
||||
// it will be automatically made async
|
||||
// even it iterator "returns" in the same event loop
|
||||
cb(null, item * 2);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-serial-array.js](test/test-serial-array.js).
|
||||
|
||||
#### Input Object
|
||||
|
||||
Also it supports named jobs, listed via object.
|
||||
|
||||
```javascript
|
||||
var serial = require('asynckit').serial
|
||||
, assert = require('assert')
|
||||
;
|
||||
|
||||
var source = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, expectedResult = [ 2, 2, 8, 32, 128, 64, 16, 4 ]
|
||||
, expectedTarget = [ 0, 1, 2, 3, 4, 5, 6, 7 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
|
||||
, expectedResult = { first: 2, one: 2, four: 8, sixteen: 32, sixtyFour: 128, thirtyTwo: 64, eight: 16, two: 4 }
|
||||
, expectedTarget = [ 1, 1, 4, 16, 64, 32, 8, 2 ]
|
||||
, target = []
|
||||
;
|
||||
|
||||
|
||||
serial(source, asyncJob, function(err, result)
|
||||
{
|
||||
assert.deepEqual(result, expectedResult);
|
||||
assert.deepEqual(target, expectedTarget);
|
||||
});
|
||||
|
||||
// shortcut interface (item, callback)
|
||||
// works for object as well as for the arrays
|
||||
function asyncJob(item, cb)
|
||||
{
|
||||
target.push(item);
|
||||
|
||||
// it will be automatically made async
|
||||
// even it iterator "returns" in the same event loop
|
||||
cb(null, item * 2);
|
||||
}
|
||||
```
|
||||
|
||||
More examples could be found in [test/test-serial-object.js](test/test-serial-object.js).
|
||||
|
||||
_Note: Since _object_ is an _unordered_ collection of properties,
|
||||
it may produce unexpected results with sequential iterations.
|
||||
Whenever order of the jobs' execution is important please use `serialOrdered` method._
|
||||
|
||||
### Ordered Serial Iterations
|
||||
|
||||
TBD
|
||||
|
||||
For example [compare-property](compare-property) package.
|
||||
|
||||
### Streaming interface
|
||||
|
||||
TBD
|
||||
|
||||
## Want to Know More?
|
||||
|
||||
More examples can be found in [test folder](test/).
|
||||
|
||||
Or open an [issue](https://github.com/alexindigo/asynckit/issues) with questions and/or suggestions.
|
||||
|
||||
## License
|
||||
|
||||
AsyncKit is licensed under the MIT license.
|
@ -0,0 +1,76 @@
|
||||
/* eslint no-console: "off" */
|
||||
|
||||
var asynckit = require('./')
|
||||
, async = require('async')
|
||||
, assert = require('assert')
|
||||
, expected = 0
|
||||
;
|
||||
|
||||
var Benchmark = require('benchmark');
|
||||
var suite = new Benchmark.Suite;
|
||||
|
||||
var source = [];
|
||||
for (var z = 1; z < 100; z++)
|
||||
{
|
||||
source.push(z);
|
||||
expected += z;
|
||||
}
|
||||
|
||||
suite
|
||||
// add tests
|
||||
|
||||
.add('async.map', function(deferred)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
async.map(source,
|
||||
function(i, cb)
|
||||
{
|
||||
setImmediate(function()
|
||||
{
|
||||
total += i;
|
||||
cb(null, total);
|
||||
});
|
||||
},
|
||||
function(err, result)
|
||||
{
|
||||
assert.ifError(err);
|
||||
assert.equal(result[result.length - 1], expected);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {'defer': true})
|
||||
|
||||
|
||||
.add('asynckit.parallel', function(deferred)
|
||||
{
|
||||
var total = 0;
|
||||
|
||||
asynckit.parallel(source,
|
||||
function(i, cb)
|
||||
{
|
||||
setImmediate(function()
|
||||
{
|
||||
total += i;
|
||||
cb(null, total);
|
||||
});
|
||||
},
|
||||
function(err, result)
|
||||
{
|
||||
assert.ifError(err);
|
||||
assert.equal(result[result.length - 1], expected);
|
||||
deferred.resolve();
|
||||
});
|
||||
}, {'defer': true})
|
||||
|
||||
|
||||
// add listeners
|
||||
.on('cycle', function(ev)
|
||||
{
|
||||
console.log(String(ev.target));
|
||||
})
|
||||
.on('complete', function()
|
||||
{
|
||||
console.log('Fastest is ' + this.filter('fastest').map('name'));
|
||||
})
|
||||
// run async
|
||||
.run({ 'async': true });
|
@ -0,0 +1,6 @@
|
||||
module.exports =
|
||||
{
|
||||
parallel : require('./parallel.js'),
|
||||
serial : require('./serial.js'),
|
||||
serialOrdered : require('./serialOrdered.js')
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
// API
|
||||
module.exports = abort;
|
||||
|
||||
/**
|
||||
* Aborts leftover active jobs
|
||||
*
|
||||
* @param {object} state - current state object
|
||||
*/
|
||||
function abort(state)
|
||||
{
|
||||
Object.keys(state.jobs).forEach(clean.bind(state));
|
||||
|
||||
// reset leftover jobs
|
||||
state.jobs = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up leftover job by invoking abort function for the provided job id
|
||||
*
|
||||
* @this state
|
||||
* @param {string|number} key - job id to abort
|
||||
*/
|
||||
function clean(key)
|
||||
{
|
||||
if (typeof this.jobs[key] == 'function')
|
||||
{
|
||||
this.jobs[key]();
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
var defer = require('./defer.js');
|
||||
|
||||
// API
|
||||
module.exports = async;
|
||||
|
||||
/**
|
||||
* Runs provided callback asynchronously
|
||||
* even if callback itself is not
|
||||
*
|
||||
* @param {function} callback - callback to invoke
|
||||
* @returns {function} - augmented callback
|
||||
*/
|
||||
function async(callback)
|
||||
{
|
||||
var isAsync = false;
|
||||
|
||||
// check if async happened
|
||||
defer(function() { isAsync = true; });
|
||||
|
||||
return function async_callback(err, result)
|
||||
{
|
||||
if (isAsync)
|
||||
{
|
||||
callback(err, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
defer(function nextTick_callback()
|
||||
{
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
module.exports = defer;
|
||||
|
||||
/**
|
||||
* Runs provided function on next iteration of the event loop
|
||||
*
|
||||
* @param {function} fn - function to run
|
||||
*/
|
||||
function defer(fn)
|
||||
{
|
||||
var nextTick = typeof setImmediate == 'function'
|
||||
? setImmediate
|
||||
: (
|
||||
typeof process == 'object' && typeof process.nextTick == 'function'
|
||||
? process.nextTick
|
||||
: null
|
||||
);
|
||||
|
||||
if (nextTick)
|
||||
{
|
||||
nextTick(fn);
|
||||
}
|
||||
else
|
||||
{
|
||||
setTimeout(fn, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
var async = require('./async.js')
|
||||
, abort = require('./abort.js')
|
||||
;
|
||||
|
||||
// API
|
||||
module.exports = iterate;
|
||||
|
||||
/**
|
||||
* Iterates over each job object
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {object} state - current job status
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
*/
|
||||
function iterate(list, iterator, state, callback)
|
||||
{
|
||||
// store current index
|
||||
var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
|
||||
|
||||
state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
|
||||
{
|
||||
// don't repeat yourself
|
||||
// skip secondary callbacks
|
||||
if (!(key in state.jobs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// clean up jobs
|
||||
delete state.jobs[key];
|
||||
|
||||
if (error)
|
||||
{
|
||||
// don't process rest of the results
|
||||
// stop still active jobs
|
||||
// and reset the list
|
||||
abort(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.results[key] = output;
|
||||
}
|
||||
|
||||
// return salvaged results
|
||||
callback(error, state.results);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs iterator over provided job element
|
||||
*
|
||||
* @param {function} iterator - iterator to invoke
|
||||
* @param {string|number} key - key/index of the element in the list of jobs
|
||||
* @param {mixed} item - job description
|
||||
* @param {function} callback - invoked after iterator is done with the job
|
||||
* @returns {function|mixed} - job abort function or something else
|
||||
*/
|
||||
function runJob(iterator, key, item, callback)
|
||||
{
|
||||
var aborter;
|
||||
|
||||
// allow shortcut if iterator expects only two arguments
|
||||
if (iterator.length == 2)
|
||||
{
|
||||
aborter = iterator(item, async(callback));
|
||||
}
|
||||
// otherwise go with full three arguments
|
||||
else
|
||||
{
|
||||
aborter = iterator(item, key, async(callback));
|
||||
}
|
||||
|
||||
return aborter;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
var parallel = require('../parallel.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableParallel;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.parallel`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableParallel(list, iterator, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableParallel))
|
||||
{
|
||||
return new ReadableParallel(list, iterator, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableParallel.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(parallel, list, iterator, callback);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
var serial = require('../serial.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableSerial;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.serial`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableSerial(list, iterator, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableSerial))
|
||||
{
|
||||
return new ReadableSerial(list, iterator, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableSerial.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(serial, list, iterator, callback);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
var serialOrdered = require('../serialOrdered.js');
|
||||
|
||||
// API
|
||||
module.exports = ReadableSerialOrdered;
|
||||
// expose sort helpers
|
||||
module.exports.ascending = serialOrdered.ascending;
|
||||
module.exports.descending = serialOrdered.descending;
|
||||
|
||||
/**
|
||||
* Streaming wrapper to `asynckit.serialOrdered`
|
||||
*
|
||||
* @param {array|object} list - array or object (named list) to iterate over
|
||||
* @param {function} iterator - iterator to run
|
||||
* @param {function} sortMethod - custom sort function
|
||||
* @param {function} callback - invoked when all elements processed
|
||||
* @returns {stream.Readable#}
|
||||
*/
|
||||
function ReadableSerialOrdered(list, iterator, sortMethod, callback)
|
||||
{
|
||||
if (!(this instanceof ReadableSerialOrdered))
|
||||
{
|
||||
return new ReadableSerialOrdered(list, iterator, sortMethod, callback);
|
||||
}
|
||||
|
||||
// turn on object mode
|
||||
ReadableSerialOrdered.super_.call(this, {objectMode: true});
|
||||
|
||||
this._start(serialOrdered, list, iterator, sortMethod, callback);
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
// API
|
||||
module.exports = state;
|
||||
|
||||
/**
|
||||
* Creates initial state object
|
||||
* for iteration over list
|
||||
*
|
||||
* @param {array|object} list - list to iterate over
|
||||
* @param {function|null} sortMethod - function to use for keys sort,
|
||||
* or `null` to keep them as is
|
||||
* @returns {object} - initial state object
|
||||
*/
|
||||
function state(list, sortMethod)
|
||||
{
|
||||
var isNamedList = !Array.isArray(list)
|
||||
, initState =
|
||||
{
|
||||
index : 0,
|
||||
keyedList: isNamedList || sortMethod ? Object. |