Skip to content

Commit

Permalink
Prepare tag release
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomayobre committed Sep 16, 2021
1 parent c86aaba commit 8c99d22
Show file tree
Hide file tree
Showing 30 changed files with 1,372 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist/helpers/deepClone.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const deepClone: <T>(obj: T) => T;
8 changes: 8 additions & 0 deletions dist/helpers/deepClone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepClone = void 0;
var v8_1 = require("v8");
var deepClone = function (obj) {
return (0, v8_1.deserialize)((0, v8_1.serialize)(obj));
};
exports.deepClone = deepClone;
1 change: 1 addition & 0 deletions dist/helpers/getFulfilledResults.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const getFulfilledResults: <T extends {} | null>(results: PromiseSettledResult<T | undefined>[]) => T[];
14 changes: 14 additions & 0 deletions dist/helpers/getFulfilledResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFulfilledResults = void 0;
var getFulfilledResults = function (results) {
return results
.map(function (result) {
if (result.status === "fulfilled") {
return result.value;
}
return undefined;
})
.filter(function (value) { return value !== undefined; });
};
exports.getFulfilledResults = getFulfilledResults;
2 changes: 2 additions & 0 deletions dist/helpers/guaranteeBuffer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="node" />
export declare const guaranteeBuffer: (buffer: string | Buffer | ArrayBuffer) => Buffer;
12 changes: 12 additions & 0 deletions dist/helpers/guaranteeBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.guaranteeBuffer = void 0;
var guaranteeBuffer = function (buffer) {
if (buffer instanceof ArrayBuffer)
return Buffer.from(buffer);
if (typeof buffer === "string") {
return Buffer.from(buffer.replace(/^data:image\/[a-z]+;base64,/, ""), "base64");
}
return buffer;
};
exports.guaranteeBuffer = guaranteeBuffer;
1 change: 1 addition & 0 deletions dist/helpers/guaranteeError.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const guaranteeError: (error: unknown) => Error;
9 changes: 9 additions & 0 deletions dist/helpers/guaranteeError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.guaranteeError = void 0;
var guaranteeError = function (error) {
return error instanceof Error
? error
: new Error(typeof error === "string" ? error : "Unknown error");
};
exports.guaranteeError = guaranteeError;
1 change: 1 addition & 0 deletions dist/helpers/importDirectory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const importDirectory: (dir: string) => Promise<void>;
59 changes: 59 additions & 0 deletions dist/helpers/importDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importDirectory = void 0;
var path = require("path");
var importFile = function (file) { return __awaiter(void 0, void 0, void 0, function () {
var _a, name, ext, exports_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = path.parse(file), name = _a.name, ext = _a.ext;
if (!(name !== "index" && ext === ".ts")) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.resolve().then(function () { return require("./" + file); })];
case 1:
exports_1 = _b.sent();
return [2 /*return*/, [name, exports_1]];
case 2: return [2 /*return*/];
}
});
}); };
var importDirectory = function (dir) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/];
}); }); };
exports.importDirectory = importDirectory;
4 changes: 4 additions & 0 deletions dist/helpers/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { deepClone } from "./deepClone";
export { getFulfilledResults } from "./getFulfilledResults";
export { guaranteeBuffer } from "./guaranteeBuffer";
export { guaranteeError } from "./guaranteeError";
11 changes: 11 additions & 0 deletions dist/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.guaranteeError = exports.guaranteeBuffer = exports.getFulfilledResults = exports.deepClone = void 0;
var deepClone_1 = require("./deepClone");
Object.defineProperty(exports, "deepClone", { enumerable: true, get: function () { return deepClone_1.deepClone; } });
var getFulfilledResults_1 = require("./getFulfilledResults");
Object.defineProperty(exports, "getFulfilledResults", { enumerable: true, get: function () { return getFulfilledResults_1.getFulfilledResults; } });
var guaranteeBuffer_1 = require("./guaranteeBuffer");
Object.defineProperty(exports, "guaranteeBuffer", { enumerable: true, get: function () { return guaranteeBuffer_1.guaranteeBuffer; } });
var guaranteeError_1 = require("./guaranteeError");
Object.defineProperty(exports, "guaranteeError", { enumerable: true, get: function () { return guaranteeError_1.guaranteeError; } });
12 changes: 12 additions & 0 deletions dist/import/fromNSAC.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="node" />
import { AddInvitesOptions, InviteItem } from "../models/invite";
export declare const parseNSAC: (file: Buffer | ArrayBuffer | string) => Promise<InviteItem[]>;
export declare const importFromNSAC: (file: Buffer | ArrayBuffer | string, event: string, role: string, options: Partial<AddInvitesOptions>) => Promise<{
found: import("@typegoose/typegoose").DocumentType<import("../models/invite").Invite, import("@typegoose/typegoose/lib/types").BeAnObject>[];
created: import("@typegoose/typegoose").DocumentType<import("../models/invite").Invite, import("@typegoose/typegoose/lib/types").BeAnObject>[];
error: {
email: string;
error: Error;
}[];
deactivated: number;
}>;
75 changes: 75 additions & 0 deletions dist/import/fromNSAC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importFromNSAC = exports.parseNSAC = void 0;
var xlsx = require("xlsx");
var guaranteeBuffer_1 = require("../helpers/guaranteeBuffer");
var invite_1 = require("../models/invite");
var parseNSAC = function (file) { return __awaiter(void 0, void 0, void 0, function () {
var buffer, workbook, data;
return __generator(this, function (_a) {
buffer = (0, guaranteeBuffer_1.guaranteeBuffer)(file);
if (!buffer) {
throw new Error("File couldn't be converted to a proper buffer");
}
workbook = xlsx.read(buffer, { type: "buffer" });
data = xlsx.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
return [2 /*return*/, data.map(function (item) { return ({
email: item.Email,
meta: JSON.stringify({
location: item.Location,
name: item.Name,
registrationDate: item["Registration Date"],
}),
}); })];
});
}); };
exports.parseNSAC = parseNSAC;
var importFromNSAC = function (file, event, role, options) { return __awaiter(void 0, void 0, void 0, function () {
var invites;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, exports.parseNSAC)(file)];
case 1:
invites = _a.sent();
return [4 /*yield*/, invite_1.InviteModel.addInviteList(event, invites, role, options)];
case 2: return [2 /*return*/, _a.sent()];
}
});
}); };
exports.importFromNSAC = importFromNSAC;
35 changes: 35 additions & 0 deletions dist/import/fromOldData.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference types="node" />
import { InviteItem } from "../models/invite";
import { UserItem } from "../models/user";
export declare const parseOldData: (file: Buffer | ArrayBuffer | string) => Promise<[UserItem[], InviteItem[]]>;
declare type Overwrites = {
role: boolean;
inviteMeta: boolean;
userMeta: boolean;
name: boolean;
};
export declare const importFromParsedOldData: (users: UserItem[], invites: InviteItem[], event?: string, overwrites?: Partial<Overwrites>) => Promise<{
users: import("@typegoose/typegoose").DocumentType<import("../models/user").User, import("@typegoose/typegoose/lib/types").BeAnObject>[];
invites: {
found: import("@typegoose/typegoose").DocumentType<import("../models/invite").Invite, import("@typegoose/typegoose/lib/types").BeAnObject>[];
created: import("@typegoose/typegoose").DocumentType<import("../models/invite").Invite, import("@typegoose/typegoose/lib/types").BeAnObject>[];
error: {
email: string;
error: Error;
}[];
deactivated: number;
};
}>;
export declare const importFromOldData: (file: Buffer | ArrayBuffer | string, event?: string, overwrites?: Partial<Overwrites>) => Promise<{
users: import("@typegoose/typegoose").DocumentType<import("../models/user").User, import("@typegoose/typegoose/lib/types").BeAnObject>[];
invites: {
found: import("@typegoose/typegoose").DocumentType<import("../models/invite").Invite, import("@typegoose/typegoose/lib/types").BeAnObject>[];
created: import("@typegoose/typegoose").DocumentType<import("../models/invite").Invite, import("@typegoose/typegoose/lib/types").BeAnObject>[];
error: {
email: string;
error: Error;
}[];
deactivated: number;
};
}>;
export {};
Loading

0 comments on commit 8c99d22

Please sign in to comment.