New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rr-apilib

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rr-apilib - npm Package Compare versions

Comparing version 0.5.6-alpha to 0.6.0-alpha

1

lib/class/Attachment.d.ts

@@ -21,2 +21,3 @@ import User from "./User";

constructor(client: Client, resource: Resource, user: User | null, data: APIResourceAttachmentData);
_patch(data: APIResourceAttachmentData): void;
/** Return data for api request */

@@ -23,0 +24,0 @@ toJSON(): {

@@ -20,2 +20,9 @@ import { __extends } from "tslib";

}
Attachment.prototype._patch = function (data) {
this.data = data;
this.fileUrl = data.fileUrl;
this.type = data.type;
this.fileName = data.fileName;
this.createdAt = new Date(data.createdAt);
};
/** Return data for api request */

@@ -22,0 +29,0 @@ Attachment.prototype.toJSON = function () {

@@ -24,2 +24,3 @@ import User from "./User";

private getCreator;
_patch(data: APICategoryData): void;
/** Refresh all category managers */

@@ -26,0 +27,0 @@ refresh(): void;

@@ -10,3 +10,3 @@ import { __extends } from "tslib";

var _a;
_this = _super.call(this, client, data === null || data === void 0 ? void 0 : data.id, "/categories") || this;
_this = _super.call(this, client, data.id, "/categories") || this;
_this.data = data;

@@ -25,2 +25,12 @@ _this.name = data.name;

};
Category.prototype._patch = function (data) {
var _a;
this.data = data;
this.name = data.name;
this.isVisible = data.isVisible;
this.createdAt = new Date(data.createdAt);
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null;
this.creator = this.getCreator((_a = this.data.creator) === null || _a === void 0 ? void 0 : _a.id);
this.resources = new CategoryResourceManager(this);
};
/** Refresh all category managers */

@@ -27,0 +37,0 @@ Category.prototype.refresh = function () {

@@ -19,2 +19,3 @@ import Base from "./Base";

constructor(client: Client, resource: Resource, data: APIResourceCommentData);
_patch(data: APIResourceCommentData): void;
/** Return data for api request */

@@ -21,0 +22,0 @@ toJSON(): {

@@ -17,2 +17,9 @@ import { __extends } from "tslib";

}
Comment.prototype._patch = function (data) {
var _a;
this.data = data;
this.comment = data.comment;
this.createdAt = new Date(data.createdAt);
this.user = data.user ? (_a = this.client.users.cache.get(data.user.id)) !== null && _a !== void 0 ? _a : null : null;
};
/** Return data for api request */

@@ -19,0 +26,0 @@ Comment.prototype.toJSON = function () {

@@ -43,2 +43,3 @@ import { APIResourceData } from "../@types";

unlike(): Promise<Resource> | undefined;
_patch(data: APIResourceData): void;
/** Return data for api request */

@@ -50,4 +51,5 @@ toJSON(): {

isPublic: boolean;
attachments: string[];
categories: string[];
};
}

@@ -58,2 +58,18 @@ import { __extends } from "tslib";

};
Resource.prototype._patch = function (data) {
var _a;
this.data = data;
this.title = data.title;
this.description = data.description;
this.createdAt = new Date(data.createdAt);
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null;
this.isPublic = data.isPublic;
this.user = this.getCreator((_a = data.user) === null || _a === void 0 ? void 0 : _a.id);
this.attachments = new ResourceAttachmentManager(this);
this.categories = new ResourceCategoryManager(this);
this.comments = new ResourceCommentManager(this);
this.likes = new ResourceLikeManager(this);
this.validations = new ResourceValidationStateManager(this);
this.client.refresh();
};
/** Return data for api request */

@@ -66,2 +82,3 @@ Resource.prototype.toJSON = function () {

isPublic: this.isPublic,
attachments: this.attachments.cache.map(function (a) { return a.getIri(); }),
categories: this.categories.cache.map(function (c) { return c.getIri(); }),

@@ -68,0 +85,0 @@ };

@@ -24,2 +24,3 @@ import Base from "./Base";

constructor(client: Client, data: APIUserData);
_patch(data: APIUserData): void;
/** Refresh all user managers */

@@ -26,0 +27,0 @@ refresh(): void;

@@ -19,2 +19,12 @@ import { __extends } from "tslib";

}
User.prototype._patch = function (data) {
this.data = data;
this.email = data.email;
this.roles = data.roles;
this.name = data.name;
this.firstname = data.firstname;
this.createdAt = new Date(data.createdAt);
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null;
this.resources = new UserResourceManager(this);
};
/** Refresh all user managers */

@@ -21,0 +31,0 @@ User.prototype.refresh = function () {

@@ -17,2 +17,3 @@ import Base from "./Base";

constructor(client: Client, resource: Resource, data: APIResourceUserLikeData);
_patch(data: APIResourceUserLikeData): void;
/** Refresh all resource managers */

@@ -19,0 +20,0 @@ refresh(): void;

@@ -16,2 +16,8 @@ import { __extends } from "tslib";

}
UserLike.prototype._patch = function (data) {
var _a;
this.data = data;
this.userId = this.data.user.id;
this.user = (_a = this.client.users.cache.get(this.userId)) !== null && _a !== void 0 ? _a : null;
};
/** Refresh all resource managers */

@@ -18,0 +24,0 @@ UserLike.prototype.refresh = function () {

@@ -20,2 +20,3 @@ import User from "./User";

private getModerator;
_patch(data: APIValidationStateData): void;
refresh(): void;

@@ -22,0 +23,0 @@ /** Return data for api request */

@@ -21,2 +21,10 @@ import { __extends } from "tslib";

};
ValidationState.prototype._patch = function (data) {
var _a, _b, _c;
this.data = data;
this.state = data.state;
this.updatedAt = new Date(data.updatedAt);
this.moderator = this.getModerator((_a = data.moderator) === null || _a === void 0 ? void 0 : _a.id);
this.resource = ((_b = data.resource) === null || _b === void 0 ? void 0 : _b.id) ? (_c = this.client.resources.cache.get(data.resource.id)) !== null && _c !== void 0 ? _c : null : null;
};
ValidationState.prototype.refresh = function () {

@@ -23,0 +31,0 @@ var _a, _b, _c;

5

lib/managers/CategoryManager.d.ts

@@ -5,2 +5,3 @@ import { Collection } from "@discordjs/collection";

import Category from "../class/Category";
import { APICategoryData } from "../@types";
import CategoryBuilder from "../builders/CategoryBuilder";

@@ -13,2 +14,4 @@ /** Category manager which allow to manipulate

constructor(client: Client);
_add(data: APICategoryData): Category;
_remove(id: string): void;
/** Fetch all existing categories from the api */

@@ -23,3 +26,3 @@ fetchAll(): Promise<Collection<string, Category>>;

/** Delete an existing category */
delete(category: Category): Promise<Category>;
delete(category: Category): Promise<void>;
}

@@ -14,6 +14,19 @@ import { __awaiter, __extends, __generator } from "tslib";

}
CategoryManager.prototype._add = function (data) {
var existing = this.cache.get(data.id);
if (existing) {
existing._patch(data);
return existing;
}
var category = new Category(this.client, data);
this.cache.set(category.id, category);
return category;
};
CategoryManager.prototype._remove = function (id) {
this.cache.delete(id);
};
/** Fetch all existing categories from the api */
CategoryManager.prototype.fetchAll = function () {
return __awaiter(this, void 0, void 0, function () {
var data, _i, data_1, c, categorie;
var data, _i, data_1, c;
return __generator(this, function (_a) {

@@ -26,4 +39,3 @@ switch (_a.label) {

c = data_1[_i];
categorie = new Category(this.client, c);
this.cache.set(categorie.id, categorie);
this._add(c);
}

@@ -38,3 +50,3 @@ return [2 /*return*/, this.cache];

return __awaiter(this, void 0, void 0, function () {
var data, category;
var data;
return __generator(this, function (_a) {

@@ -46,5 +58,3 @@ switch (_a.label) {

if (data) {
category = new Category(this.client, data);
this.cache.set(category.id, category);
return [2 /*return*/, category];
return [2 /*return*/, this._add(data)];
}

@@ -59,3 +69,3 @@ return [2 /*return*/, null];

return __awaiter(this, void 0, void 0, function () {
var data, categoryData, category;
var data, categoryData;
return __generator(this, function (_a) {

@@ -68,5 +78,3 @@ switch (_a.label) {

categoryData = _a.sent();
category = new Category(this.client, categoryData);
this.cache.set(category.id, category);
return [2 /*return*/, category];
return [2 /*return*/, this._add(categoryData)];
}

@@ -79,3 +87,3 @@ });

return __awaiter(this, void 0, void 0, function () {
var data, categoryData, editCategory;
var data, categoryData;
return __generator(this, function (_a) {

@@ -88,5 +96,3 @@ switch (_a.label) {

categoryData = _a.sent();
editCategory = new Category(this.client, categoryData);
this.cache.set(editCategory.id, editCategory);
return [2 /*return*/, editCategory];
return [2 /*return*/, this._add(categoryData)];
}

@@ -104,4 +110,4 @@ });

_a.sent();
this.cache.delete(category.id);
return [2 /*return*/, category];
this._remove(category.id);
return [2 /*return*/];
}

@@ -108,0 +114,0 @@ });

@@ -12,2 +12,3 @@ import { Collection } from "@discordjs/collection";

constructor(resource: Resource);
refresh(): void;
/** Upload a new attachment for this resource */

@@ -14,0 +15,0 @@ create(data: AttachmentBuilder): Promise<Resource>;

@@ -11,8 +11,11 @@ import { __awaiter, __extends, __generator } from "tslib";

_this.cache = new Collection();
for (var _i = 0, _a = _this.resource.data.attachments; _i < _a.length; _i++) {
_this.refresh();
return _this;
}
ResourceAttachmentManager.prototype.refresh = function () {
for (var _i = 0, _a = this.resource.data.attachments; _i < _a.length; _i++) {
var a = _a[_i];
_this.cache.set(a.id, new Attachment(_this.client, _this.resource, null, a));
this.cache.set(a.id, new Attachment(this.client, this.resource, this.resource.user, a));
}
return _this;
}
};
/** Upload a new attachment for this resource */

@@ -19,0 +22,0 @@ ResourceAttachmentManager.prototype.create = function (data) {

@@ -13,2 +13,5 @@ import { Collection } from "@discordjs/collection";

refresh(): void;
private putResource;
/** Set an array of categories for this resource */
set(categories: Category[]): Promise<Resource>;
/** Add a new category for this resource */

@@ -15,0 +18,0 @@ add(category: Category): Promise<Resource>;

@@ -23,14 +23,13 @@ import { __awaiter, __extends, __generator } from "tslib";

};
/** Add a new category for this resource */
ResourceCategoryManager.prototype.add = function (category) {
ResourceCategoryManager.prototype.putResource = function () {
return __awaiter(this, void 0, void 0, function () {
var json;
var json, updated;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.cache.set(category.id, category);
json = this.resource.toJSON();
return [4 /*yield*/, this.client.rest.putRequest("/resources/".concat(this.resource.id), json)];
case 1:
_a.sent();
updated = _a.sent();
this.resource._patch(updated);
return [2 /*return*/, this.resource];

@@ -41,18 +40,20 @@ }

};
/** Set an array of categories for this resource */
ResourceCategoryManager.prototype.set = function (categories) {
this.cache.clear();
for (var _i = 0, categories_1 = categories; _i < categories_1.length; _i++) {
var c = categories_1[_i];
this.cache.set(c.id, c);
}
return this.putResource();
};
/** Add a new category for this resource */
ResourceCategoryManager.prototype.add = function (category) {
this.cache.set(category.id, category);
return this.putResource();
};
/** Remove a category for this resource */
ResourceCategoryManager.prototype.remove = function (category) {
return __awaiter(this, void 0, void 0, function () {
var json;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.cache.delete(category.id);
json = this.resource.toJSON();
return [4 /*yield*/, this.client.rest.putRequest("/resources/".concat(this.resource.id), json)];
case 1:
_a.sent();
return [2 /*return*/, this.resource];
}
});
});
this.cache.delete(category.id);
return this.putResource();
};

@@ -59,0 +60,0 @@ return ResourceCategoryManager;

@@ -12,2 +12,4 @@ import { Collection } from "@discordjs/collection";

constructor(resource: Resource);
private _add;
private _remove;
/** Sort comments by created date */

@@ -14,0 +16,0 @@ sort(): Collection<string, Comment>;

@@ -13,14 +13,24 @@ import { __awaiter, __extends, __generator } from "tslib";

var c = _a[_i];
var comment = new Comment(_this.client, _this.resource, c);
_this.cache.set(comment.id, comment);
_this._add(c);
}
var sorted = _this.sort();
_this.cache = sorted;
_this.sort();
return _this;
}
ResourceCommentManager.prototype._add = function (data) {
var existing = this.cache.get(data.id);
if (existing) {
existing._patch(data);
}
var comment = new Comment(this.client, this.resource, data);
this.cache.set(comment.id, comment);
};
ResourceCommentManager.prototype._remove = function (id) {
this.cache.delete(id);
};
/** Sort comments by created date */
ResourceCommentManager.prototype.sort = function () {
return this.cache.sort(function (c1, c2) {
this.cache.sort(function (c1, c2) {
return c2.createdAt.getTime() - c1.createdAt.getTime();
});
return this.cache;
};

@@ -30,3 +40,3 @@ /** Create a new comment for this resource */

return __awaiter(this, void 0, void 0, function () {
var json, commentData, comment;
var json, commentData;
return __generator(this, function (_a) {

@@ -39,4 +49,3 @@ switch (_a.label) {

commentData = _a.sent();
comment = new Comment(this.client, this.resource, commentData);
this.cache.set(comment.id, comment);
this._add(commentData);
return [2 /*return*/, this.resource];

@@ -52,6 +61,7 @@ }

switch (_a.label) {
case 0: return [4 /*yield*/, this.client.rest.deleteRequest("/comments/".concat(comment.id))];
case 0:
this._remove(comment.id);
return [4 /*yield*/, this.client.rest.deleteRequest("/comments/".concat(comment.id))];
case 1:
_a.sent();
this.cache.delete(comment.id);
return [2 /*return*/, this.resource];

@@ -58,0 +68,0 @@ }

@@ -12,2 +12,4 @@ import { Collection } from "@discordjs/collection";

constructor(resource: Resource);
private _add;
private _remove;
/** Check if authenticated user has like this resource */

@@ -14,0 +16,0 @@ getMeLike(): UserLike | null;

@@ -18,2 +18,13 @@ import { __awaiter, __extends, __generator } from "tslib";

}
ResourceLikeManager.prototype._add = function (data) {
var existing = this.cache.get(data.id);
if (existing) {
existing._patch(data);
}
var like = new UserLike(this.client, this.resource, data);
this.cache.set(like.id, like);
};
ResourceLikeManager.prototype._remove = function (id) {
this.cache.delete(id);
};
/** Check if authenticated user has like this resource */

@@ -24,5 +35,3 @@ ResourceLikeManager.prototype.getMeLike = function () {

var me = this.cache.find(function (l) { var _a; return l.userId === ((_a = _this.client.auth.me) === null || _a === void 0 ? void 0 : _a.id); });
if (me) {
return me;
}
return me !== null && me !== void 0 ? me : null;
}

@@ -34,3 +43,3 @@ return null;

return __awaiter(this, void 0, void 0, function () {
var hasPreviousLike, json, likeData, userLike;
var hasPreviousLike, json, likeData;
return __generator(this, function (_a) {

@@ -47,4 +56,3 @@ switch (_a.label) {

likeData = _a.sent();
userLike = new UserLike(this.client, this.resource, likeData);
this.cache.set(userLike.id, userLike);
this._add(likeData);
return [2 /*return*/, this.resource];

@@ -60,6 +68,7 @@ }

switch (_a.label) {
case 0: return [4 /*yield*/, this.client.rest.deleteRequest("/user_likes/".concat(like.id))];
case 0:
this._remove(like.id);
return [4 /*yield*/, this.client.rest.deleteRequest("/user_likes/".concat(like.id))];
case 1:
_a.sent();
this.cache.delete(like.id);
return [2 /*return*/, this.resource];

@@ -66,0 +75,0 @@ }

@@ -6,2 +6,3 @@ import { Collection } from "@discordjs/collection";

import ResourceBuilder from "../builders/ResourceBuilder";
import { APIResourceData } from "../@types";
/** Resource manager which allow to manipulate

@@ -13,2 +14,4 @@ * the resources in the api */

constructor(client: Client);
_add(data: APIResourceData): Resource;
_remove(id: string): void;
getValidateResources(): Collection<string, Resource>;

@@ -24,4 +27,3 @@ /** Fetch all existing resources from the api */

/** Delete an existing resource */
delete(resource: Resource): Promise<Resource>;
private refreshCategoryManager;
delete(resource: Resource): Promise<void>;
}

@@ -15,6 +15,27 @@ import { __awaiter, __extends, __generator } from "tslib";

}
ResourceManager.prototype._add = function (data) {
var existing = this.cache.get(data.id);
if (existing) {
existing._patch(data);
existing.categories.cache.forEach(function (c) {
c.resources.cache.delete(existing.id);
});
return existing;
}
var resource = new Resource(this.client, data);
this.cache.set(resource.id, resource);
return resource;
};
ResourceManager.prototype._remove = function (id) {
this.cache.delete(id);
};
ResourceManager.prototype.getValidateResources = function () {
return this.cache.filter(function (r) {
return r.validations.getLastValidationState().state === APIValidationState.Validated;
var finalCache = new Collection();
this.cache.forEach(function (r) {
var last = r.validations.getLastValidationState();
if (last && last.state === APIValidationState.Validated) {
finalCache.set(r.id, r);
}
});
return finalCache;
};

@@ -24,3 +45,3 @@ /** Fetch all existing resources from the api */

return __awaiter(this, void 0, void 0, function () {
var data, _i, data_1, r, resource;
var data, _i, data_1, r;
return __generator(this, function (_a) {

@@ -33,4 +54,3 @@ switch (_a.label) {

r = data_1[_i];
resource = new Resource(this.client, r);
this.cache.set(resource.id, resource);
this._add(r);
}

@@ -45,3 +65,3 @@ return [2 /*return*/, this.cache];

return __awaiter(this, void 0, void 0, function () {
var data, resource;
var data;
return __generator(this, function (_a) {

@@ -53,6 +73,3 @@ switch (_a.label) {

if (data) {
resource = new Resource(this.client, data);
this.cache.set(resource.id, resource);
this.refreshCategoryManager(resource);
return [2 /*return*/, resource];
return [2 /*return*/, this._add(data)];
}

@@ -97,6 +114,3 @@ return [2 /*return*/, null];

_b.label = 8;
case 8:
this.cache.set(resource.id, resource);
this.refreshCategoryManager(resource);
return [2 /*return*/, resource];
case 8: return [2 /*return*/, this._add(resourceData)];
}

@@ -109,3 +123,3 @@ });

return __awaiter(this, void 0, void 0, function () {
var data, resourceData, editResource;
var data, resourceData;
return __generator(this, function (_a) {

@@ -118,6 +132,3 @@ switch (_a.label) {

resourceData = _a.sent();
editResource = new Resource(this.client, resourceData);
this.cache.set(editResource.id, editResource);
this.refreshCategoryManager(editResource);
return [2 /*return*/, editResource];
return [2 /*return*/, this._add(resourceData)];
}

@@ -132,7 +143,8 @@ });

switch (_a.label) {
case 0: return [4 /*yield*/, this.client.rest.deleteRequest("/resources/".concat(resource.id))];
case 0:
this._remove(resource.id);
return [4 /*yield*/, this.client.rest.deleteRequest("/resources/".concat(resource.id))];
case 1:
_a.sent();
this.cache.delete(resource.id);
return [2 /*return*/, resource];
return [2 /*return*/];
}

@@ -142,8 +154,2 @@ });

};
ResourceManager.prototype.refreshCategoryManager = function (resource) {
resource.categories.cache.forEach(function (c) {
c.client.resources.cache.set(resource.id, resource);
c.resources.cache.set(resource.id, resource);
});
};
return ResourceManager;

@@ -150,0 +156,0 @@ }(BaseManager));

@@ -15,3 +15,3 @@ import Resource from "../class/Resource";

/** Get last validation state */
getLastValidationState(): ValidationState;
getLastValidationState(): ValidationState | null;
/** Create a new validation state for this resource */

@@ -18,0 +18,0 @@ create(validation: ValidationStateBuilder): Promise<Resource>;

@@ -26,2 +26,5 @@ import { __awaiter, __extends, __generator } from "tslib";

var defaultArray = Array.from(this.cache.values());
if (defaultArray.length === 0) {
return null;
}
var sortByDate = defaultArray.sort(function (v1, v2) {

@@ -28,0 +31,0 @@ return v2.updatedAt.getTime() - v1.updatedAt.getTime();

@@ -60,3 +60,3 @@ import { __awaiter, __extends, __generator } from "tslib";

data = builder.toJSON();
return [4 /*yield*/, this.client.rest.postRequest('/users', data)];
return [4 /*yield*/, this.client.rest.postRequest('/users', data, false)];
case 1:

@@ -63,0 +63,0 @@ ressourceData = _a.sent();

{
"name": "rr-apilib",
"version": "0.5.6-alpha",
"version": "0.6.0-alpha",
"description": "Library for interact with RR-API",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc