Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
fix: update deps, make server side compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
noramass committed Jan 20, 2021
1 parent 2a51971 commit ace6c37
Show file tree
Hide file tree
Showing 8 changed files with 4,738 additions and 10,297 deletions.
14,910 changes: 4,682 additions & 10,228 deletions package-lock.json

Large diffs are not rendered by default.

66 changes: 34 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,50 @@
},
"homepage": "https://github.com/rocketbase-io/skeleton-key#readme",
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@microsoft/api-documenter": "^7.8.4",
"@microsoft/api-extractor": "^7.8.4",
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@microsoft/api-documenter": "^7.12.4",
"@microsoft/api-extractor": "^7.13.0",
"@rocketbase/rollup-plugin-api-extractor": "^1.0.3",
"@rocketbase/rollup-plugin-exec": "^1.0.1",
"@rocketbase/rollup-plugin-sequential": "^1.1.0",
"@semantic-release/changelog": "^3.0.6",
"@semantic-release/commit-analyzer": "^7.0.0",
"@semantic-release/git": "^8.0.0",
"@semantic-release/github": "^6.0.1",
"@semantic-release/npm": "^6.0.0",
"@semantic-release/release-notes-generator": "^7.3.5",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.2.0",
"@semantic-release/npm": "^7.0.10",
"@semantic-release/release-notes-generator": "^9.0.1",
"@types/axios": "^0.14.0",
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^24.9.0",
"@types/lodash": "^4.14.152",
"@types/node": "^13.13.9",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@wessberg/rollup-plugin-ts": "^1.2.24",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"fetch-mock": "^8.3.2",
"husky": "^4.2.5",
"jest": "^25.5.4",
"@types/fetch-mock": "^7.3.3",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.21",
"@types/urijs": "^1.19.14",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"@wessberg/rollup-plugin-ts": "^1.3.8",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.3.1",
"fetch-mock": "^9.11.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"jest-preset-typescript": "^1.2.0",
"lint-staged": "^10.2.5",
"prettier": "^1.19.1",
"rollup": "^1.32.1",
"lint-staged": "^10.5.3",
"prettier": "^2.2.1",
"rollup": "^2.37.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-sourcemaps": "^0.5.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-ts-paths": "^1.0.5",
"semantic-release": "^16.0.4",
"ts-jest": "^24.3.0",
"typescript": "^3.9.3",
"webpack": "^4.43.0",
"semantic-release": "^17.3.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3",
"webpack": "^5.15.0",
"xhr-mock": "^2.5.1"
},
"dependencies": {
"axios": "^0.19.2"
"axios": "^0.21.1",
"urijs": "^1.19.5"
},
"publishConfig": {
"@rocketbase:registry": "https://registry.npmjs.org/",
Expand Down
34 changes: 12 additions & 22 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Constructor } from "./types";

export interface IEventing<K> {
const EVENTS = Symbol("Events");

export interface IEventing<K extends string> {
[EVENTS]: Record<K, ((...args: any[]) => void)[]>
on(event: K, callback: (...args: any[]) => void): this;
once(event: K, callback: (...args: any[]) => void): this;
off(event: K, callback?: (...args: any[]) => void): this;
Expand All @@ -9,8 +12,6 @@ export interface IEventing<K> {
waitForEvent(event: K): Promise<any[]>;
}

const EVENTS = Symbol("Events");

export function Eventing<K extends string = string, T extends {} = {}>(
Base: Constructor<T> = Object as any
): Constructor<T> & Constructor<IEventing<K>> {
Expand All @@ -27,46 +28,35 @@ export function Eventing<K extends string = string, T extends {} = {}>(
return Cls as Constructor<T> & Constructor<IEventing<K>>;
}

export function on<K, R extends IEventing<K>>(this: R, event: K, callback: (ev: any) => void): R {
// @ts-ignore
if (!this[EVENTS]) this[EVENTS] = {};
// @ts-ignore
if (!this[EVENTS][event]) this[EVENTS][event] = [];
// @ts-ignore
this[EVENTS][event].push(callback);
export function on<K extends string, R extends IEventing<K>>(this: R, event: K, callback: (...args: any[]) => void): R {
((this[EVENTS] ??= {} as any)[event] ??= []).push(callback);
return this;
}

export function once<K, R extends IEventing<K>>(this: R, event: K, callback: (ev: any) => void): R {
export function once<K extends string, R extends IEventing<K>>(this: R, event: K, callback: (...args: any[]) => void): R {
const onceHandler = (...args: any[]) => {
// @ts-ignore
const result = callback.apply(this, args);
this.off(event, onceHandler);
return result;
};
return this.on(event, onceHandler);
}

export function off<K, R extends IEventing<K>>(this: R, event: K, callback?: (ev: any) => void): R {
// @ts-ignore
export function off<K extends string, R extends IEventing<K>>(this: R, event: K, callback?: (...args: any[]) => void): R {
if (!callback) delete this[EVENTS][event];
// @ts-ignore
else this[EVENTS][event] = this[EVENTS][event].filter(cb => cb !== callback);
return this;
}

export function emit<K, R extends IEventing<K>>(this: R, event: K, ...data: any[]): Promise<any[]> {
// @ts-ignore
export function emit<K extends string, R extends IEventing<K>>(this: R, event: K, ...data: any[]): Promise<any[]> {
if (this[EVENTS] && this[EVENTS][event]) return Promise.all(this[EVENTS][event].map(cb => cb(...data)));
return Promise.resolve([] as any);
}

export function emitSync<K, R extends IEventing<K>>(this: R, event: K, ...data: any[]): any[] {
// @ts-ignore
if (this[EVENTS] && this[EVENTS][event]) return this[EVENTS][event].map(cb => cb(...data));
return [];
export function emitSync<K extends string, R extends IEventing<K>>(this: R, event: K, ...data: any[]): any[] {
return this[EVENTS]?.[event]?.map(cb => cb(...data)) ?? [];
}

export function waitForEvent<K, R extends IEventing<K>>(this: R, event: K): Promise<any[]> {
export function waitForEvent<K extends string, R extends IEventing<K>>(this: R, event: K): Promise<any[]> {
return new Promise(resolve => this.once(event, resolve));
}
2 changes: 1 addition & 1 deletion src/intercept/intercept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ export function installInterceptors() {
interceptFunction(XMLHttpRequest.prototype, "open", xmlHttpRequestOpenMiddleware);
interceptFunction(XMLHttpRequest.prototype, "send", xmlHttpRequestSendMiddleware, true);
interceptFunction(XMLHttpRequest.prototype, "setRequestHeader", xmlHttpRequestSetRequestHeaderMiddleware);
interceptFunction(window, "fetch", fetchMiddleware);
interceptFunction(Function("return this")() as typeof global, "fetch", fetchMiddleware);
}
5 changes: 2 additions & 3 deletions src/jwt/atob-polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// tslint:disable
/* istanbul ignore file */
import { InvalidCharacterError } from "./invalid-character-error";
/**
* The code was extracted from:
* https://github.com/davidchambers/Base64.js
* (dual-licensed under Apache 2.0 and WTFPL)
*/
import { InvalidCharacterError } from "./invalid-character-error";

window.atob =
(typeof window !== "undefined" && window.atob && window.atob.bind(window)) ||
export const atob = (typeof global !== "undefined" && global.atob && global.atob.bind(global)) ||
(() => {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function polyfill(input: string): string {
Expand Down
1 change: 1 addition & 0 deletions src/jwt/url-decode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* istanbul ignore file */
import { InvalidCharacterError } from "./invalid-character-error";
import { atob } from "./atob-polyfill";

/**
* The code was extracted from:
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ export interface Constructor<T> {
name: string;
new (...args: any[]): T;
}

export type MethodOnly<T> = T extends (...args: any[]) => unknown ? T : never;
export type MethodsOnly<T> = { [Key in keyof T]: MethodOnly<T[Key]> };
14 changes: 3 additions & 11 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import URI from "urijs";

export function only<T, K extends keyof T>(target: T, ...members: K[]): Pick<T, K> {
const copy: Partial<T> = {};
members.forEach(member => target[member] !== undefined && (copy[member] = target[member]));
Expand All @@ -8,14 +10,4 @@ export function urlMatches(target: string, needle: string): boolean {
return urlAbsolute(target).indexOf(urlAbsolute(needle)) !== -1;
}

export const urlAbsolute = (() => {
if (window.URL) return (url: string) => new URL(url, window.location.href).href;
let a: HTMLAnchorElement;
/* istanbul ignore next */
return (url: string) => {
// IE Fallback
if (!a) a = document.createElement("a");
a.href = url;
return a.href;
};
})();
export const urlAbsolute = (url: string) => new URI(url).absoluteTo(global?.location?.href).href();

0 comments on commit ace6c37

Please sign in to comment.