Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Typescipt and make Collection Array-like #1067

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
# IDE
/.idea/
/*.iml
types/assert*
5 changes: 5 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ module.exports = {
},
},
],
["@babel/typescript"],
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/proposal-object-rest-spread",
],
};
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ let internal = {
testEnvironment: "jsdom",
testMatch: ["**/__tests__/internal/**/*-test.[jt]s?(x)"],
moduleNameMapper: {
"@lib(.*)": "<rootDir>/lib$1",
"^miragejs$": "<rootDir>/lib/index",
"@lib(.*)": "<rootDir>/dist$1",
"^miragejs$": "<rootDir>/dist/index",
},
};

Expand Down
49 changes: 0 additions & 49 deletions lib/assert.js

This file was deleted.

20 changes: 20 additions & 0 deletions lib/assert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default function assert(bool: boolean, text: string = "") {
if (typeof bool === "string" && !text) {
throw new MirageError(bool);
}

if (!bool) {
throw new MirageError(text.replace(/^ +/gm, "") || "Assertion failed");
}
}

export class MirageError extends Error {
constructor(message: string, stack?: string) {
super();
if (stack) {
this.stack = `Mirage: ${stack}`;
}
this.name = "MirageError";
this.message = `Mirage: ${message}`;
}
}
3 changes: 3 additions & 0 deletions lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import isFunction from "lodash.isfunction";
import mapValues from "lodash.mapvalues";
import referenceSort from "./utils/reference-sort";

/**
* @type {Class}
*/
let Factory = function () {
this.build = function (sequence) {
let object = {};
Expand Down