김재형

Setup mirage js

......@@ -2072,6 +2072,11 @@
"chalk": "^3.0.0"
}
},
"@miragejs/pretender-node-polyfill": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@miragejs/pretender-node-polyfill/-/pretender-node-polyfill-0.1.2.tgz",
"integrity": "sha512-M/BexG/p05C5lFfMunxo/QcgIJnMT2vDVCd00wNqK2ImZONIlEETZwWJu1QtLxtmYlSHlCFl3JNzp0tLe7OJ5g=="
},
"@mrmlnc/readdir-enhanced": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
......@@ -7606,6 +7611,11 @@
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=",
"dev": true
},
"fake-xml-http-request": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/fake-xml-http-request/-/fake-xml-http-request-2.1.1.tgz",
"integrity": "sha512-Kn2WYYS6cDBS5jq/voOfSGCA0TafOYAUPbEp8mUVpD/DVV5bQIDjlq+MLLvNUokkbTpjBVlLDaM5PnX+PwZMlw=="
},
"fast-deep-equal": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz",
......@@ -9408,6 +9418,11 @@
"integrity": "sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==",
"dev": true
},
"inflected": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inflected/-/inflected-2.0.4.tgz",
"integrity": "sha512-HQPzFLTTUvwfeUH6RAGjD8cHS069mBqXG5n4qaxX7sJXBhVQrsGgF+0ZJGkSuN6a8pcUWB/GXStta11kKi/WvA=="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
......@@ -12647,18 +12662,118 @@
"integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=",
"dev": true
},
"lodash.assign": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz",
"integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc="
},
"lodash.camelcase": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY="
},
"lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
},
"lodash.compact": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/lodash.compact/-/lodash.compact-3.0.1.tgz",
"integrity": "sha1-VAzjg3dFl1gHRx4WtKK6IeclbKU="
},
"lodash.find": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.find/-/lodash.find-4.6.0.tgz",
"integrity": "sha1-ywcE1Hq3F4n/oN6Ll92Sb7iLE7E="
},
"lodash.flatten": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
"integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8="
},
"lodash.flow": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/lodash.flow/-/lodash.flow-3.5.0.tgz",
"integrity": "sha1-h79AKSuM+D5OjOGjrkIJ4gBxZ1o=",
"dev": true
},
"lodash.forin": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.forin/-/lodash.forin-4.4.0.tgz",
"integrity": "sha1-XT8grlZAEfvog4H32YlJyclRlzE="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.has": {
"version": "4.5.2",
"resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
"integrity": "sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI="
},
"lodash.invokemap": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.invokemap/-/lodash.invokemap-4.6.0.tgz",
"integrity": "sha1-F0jNpdiw74NpxOs+xUwh/rofLWI="
},
"lodash.isempty": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz",
"integrity": "sha1-b4bL7di+TsmHvpqvM8loTbGzHn4="
},
"lodash.isequal": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
"integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
},
"lodash.isfunction": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz",
"integrity": "sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw=="
},
"lodash.isinteger": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
"integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
},
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
},
"lodash.lowerfirst": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/lodash.lowerfirst/-/lodash.lowerfirst-4.3.1.tgz",
"integrity": "sha1-3jx7EuAsZSSgBZwvbLfFxSZVoT0="
},
"lodash.map": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz",
"integrity": "sha1-dx7Hg540c9nEzeKLGTlMNWL09tM="
},
"lodash.mapvalues": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.mapvalues/-/lodash.mapvalues-4.6.0.tgz",
"integrity": "sha1-G6+lAF3p3W9PJmaMMMo3IwzJaJw="
},
"lodash.memoize": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=",
"dev": true
},
"lodash.pick": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz",
"integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM="
},
"lodash.snakecase": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz",
"integrity": "sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40="
},
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
......@@ -12687,8 +12802,17 @@
"lodash.uniq": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
"dev": true
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M="
},
"lodash.uniqby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz",
"integrity": "sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI="
},
"lodash.values": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/lodash.values/-/lodash.values-4.3.0.tgz",
"integrity": "sha1-o6bCsOvsxcLLocF+bmIP6BtT00c="
},
"log-symbols": {
"version": "4.0.0",
......@@ -13275,6 +13399,39 @@
"minipass": "^3.0.0"
}
},
"miragejs": {
"version": "0.1.40",
"resolved": "https://registry.npmjs.org/miragejs/-/miragejs-0.1.40.tgz",
"integrity": "sha512-7zxIcynzdS6425KZ2+TWD6F6DqESorulSDW2QBXf4iKyVn/J5vSielcubAK8sTKUefTPCrSRi7PwgNOb0JlmIg==",
"requires": {
"@miragejs/pretender-node-polyfill": "^0.1.0",
"inflected": "^2.0.4",
"lodash.assign": "^4.2.0",
"lodash.camelcase": "^4.3.0",
"lodash.clonedeep": "^4.5.0",
"lodash.compact": "^3.0.1",
"lodash.find": "^4.6.0",
"lodash.flatten": "^4.4.0",
"lodash.forin": "^4.4.0",
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
"lodash.invokemap": "^4.6.0",
"lodash.isempty": "^4.4.0",
"lodash.isequal": "^4.5.0",
"lodash.isfunction": "^3.0.9",
"lodash.isinteger": "^4.0.4",
"lodash.isplainobject": "^4.0.6",
"lodash.lowerfirst": "^4.3.1",
"lodash.map": "^4.6.0",
"lodash.mapvalues": "^4.6.0",
"lodash.pick": "^4.4.0",
"lodash.snakecase": "^4.1.1",
"lodash.uniq": "^4.5.0",
"lodash.uniqby": "^4.7.0",
"lodash.values": "^4.3.0",
"pretender": "^3.4.3"
}
},
"mississippi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz",
......@@ -15768,6 +15925,15 @@
"integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
"dev": true
},
"pretender": {
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/pretender/-/pretender-3.4.3.tgz",
"integrity": "sha512-AlbkBly9R8KR+R0sTCJ/ToOeEoUMtt52QVCetui5zoSmeLOU3S8oobFsyPLm1O2txR6t58qDNysqPnA1vVi8Hg==",
"requires": {
"fake-xml-http-request": "^2.1.1",
"route-recognizer": "^0.3.3"
}
},
"prettier": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
......@@ -17092,6 +17258,11 @@
"inherits": "^2.0.1"
}
},
"route-recognizer": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/route-recognizer/-/route-recognizer-0.3.4.tgz",
"integrity": "sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g=="
},
"rsvp": {
"version": "4.8.5",
"resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz",
......
......@@ -6,6 +6,7 @@
"dependencies": {
"classnames": "^2.2.6",
"ky": "^0.20.0",
"miragejs": "^0.1.40",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0"
......
......@@ -7,6 +7,8 @@ import { App } from "./App";
import * as serviceWorker from "./serviceWorker";
import "./server";
ReactDOM.render(
<React.StrictMode>
<App />
......
import { createServer, Model } from "miragejs";
import { ModelDefinition } from "miragejs/-types";
interface Item {
id: string;
is_folder: boolean;
name: string;
mime_type: string | null;
path: string | null;
parent: string | null;
user_id: string;
size: number;
is_deleted: boolean;
created_timestamp: string;
updated_timestamp: string;
status: boolean;
}
interface SharedItem {
id: string;
file_id: string;
until: string;
password: string;
}
interface User {
id: string;
user_id: string;
name: string;
password: string;
total_size: number;
current_size: number;
}
const ItemModel: ModelDefinition<Item> = Model;
const SharedItemModel: ModelDefinition<SharedItem> = Model;
const UserModel: ModelDefinition<User> = Model;
createServer({
models: {
item: ItemModel,
shared_item: SharedItemModel,
user: UserModel,
},
factories: {},
routes() {
this.namespace = "api";
this.get("/items/:item_id/children", (schema, request) => {
const directory = schema.find("item", request.params.item_id);
if (!directory || !directory.is_folder) {
return {
status: 404,
message: "Not Found",
};
}
const list = schema.where("item", { parent: directory.id }).models;
return {
status: 200,
data: {
...directory.attrs,
count: list.length,
list,
},
};
});
},
seeds(server) {
const user = server.create("user", {
id: "1",
user_id: "test",
name: "테스트",
password: "password",
total_size: 1024 * 1024 * 1024 * 5, // 5GB
current_size: 1024 * 1024 * 1024 * 1, // 1GB
});
const rootDir = server.create("item", {
id: "1",
is_folder: true,
name: "root",
mime_type: null,
path: null,
parent: null,
user_id: user.id,
size: 0,
is_deleted: false,
created_timestamp: "2020-05-14T06:20:44Z",
updated_timestamp: "2020-05-14T06:20:44Z",
status: true,
});
server.create("item", {
id: "2",
is_folder: false,
name: "image.jpg",
mime_type: "image/jpeg",
path: "",
parent: rootDir.id,
user_id: user.id,
size: 1024 * 1024 * 5,
is_deleted: false,
created_timestamp: "2020-05-14T06:20:44Z",
updated_timestamp: "2020-05-14T06:20:44Z",
status: true,
});
},
});