김재형

Setup mirage js

...@@ -2072,6 +2072,11 @@ ...@@ -2072,6 +2072,11 @@
2072 "chalk": "^3.0.0" 2072 "chalk": "^3.0.0"
2073 } 2073 }
2074 }, 2074 },
2075 + "@miragejs/pretender-node-polyfill": {
2076 + "version": "0.1.2",
2077 + "resolved": "https://registry.npmjs.org/@miragejs/pretender-node-polyfill/-/pretender-node-polyfill-0.1.2.tgz",
2078 + "integrity": "sha512-M/BexG/p05C5lFfMunxo/QcgIJnMT2vDVCd00wNqK2ImZONIlEETZwWJu1QtLxtmYlSHlCFl3JNzp0tLe7OJ5g=="
2079 + },
2075 "@mrmlnc/readdir-enhanced": { 2080 "@mrmlnc/readdir-enhanced": {
2076 "version": "2.2.1", 2081 "version": "2.2.1",
2077 "resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz", 2082 "resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
...@@ -7606,6 +7611,11 @@ ...@@ -7606,6 +7611,11 @@
7606 "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", 7611 "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=",
7607 "dev": true 7612 "dev": true
7608 }, 7613 },
7614 + "fake-xml-http-request": {
7615 + "version": "2.1.1",
7616 + "resolved": "https://registry.npmjs.org/fake-xml-http-request/-/fake-xml-http-request-2.1.1.tgz",
7617 + "integrity": "sha512-Kn2WYYS6cDBS5jq/voOfSGCA0TafOYAUPbEp8mUVpD/DVV5bQIDjlq+MLLvNUokkbTpjBVlLDaM5PnX+PwZMlw=="
7618 + },
7609 "fast-deep-equal": { 7619 "fast-deep-equal": {
7610 "version": "3.1.1", 7620 "version": "3.1.1",
7611 "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", 7621 "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz",
...@@ -9408,6 +9418,11 @@ ...@@ -9408,6 +9418,11 @@
9408 "integrity": "sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==", 9418 "integrity": "sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==",
9409 "dev": true 9419 "dev": true
9410 }, 9420 },
9421 + "inflected": {
9422 + "version": "2.0.4",
9423 + "resolved": "https://registry.npmjs.org/inflected/-/inflected-2.0.4.tgz",
9424 + "integrity": "sha512-HQPzFLTTUvwfeUH6RAGjD8cHS069mBqXG5n4qaxX7sJXBhVQrsGgF+0ZJGkSuN6a8pcUWB/GXStta11kKi/WvA=="
9425 + },
9411 "inflight": { 9426 "inflight": {
9412 "version": "1.0.6", 9427 "version": "1.0.6",
9413 "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 9428 "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
...@@ -12647,18 +12662,118 @@ ...@@ -12647,18 +12662,118 @@
12647 "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=", 12662 "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=",
12648 "dev": true 12663 "dev": true
12649 }, 12664 },
12665 + "lodash.assign": {
12666 + "version": "4.2.0",
12667 + "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz",
12668 + "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc="
12669 + },
12670 + "lodash.camelcase": {
12671 + "version": "4.3.0",
12672 + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
12673 + "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY="
12674 + },
12675 + "lodash.clonedeep": {
12676 + "version": "4.5.0",
12677 + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
12678 + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
12679 + },
12680 + "lodash.compact": {
12681 + "version": "3.0.1",
12682 + "resolved": "https://registry.npmjs.org/lodash.compact/-/lodash.compact-3.0.1.tgz",
12683 + "integrity": "sha1-VAzjg3dFl1gHRx4WtKK6IeclbKU="
12684 + },
12685 + "lodash.find": {
12686 + "version": "4.6.0",
12687 + "resolved": "https://registry.npmjs.org/lodash.find/-/lodash.find-4.6.0.tgz",
12688 + "integrity": "sha1-ywcE1Hq3F4n/oN6Ll92Sb7iLE7E="
12689 + },
12690 + "lodash.flatten": {
12691 + "version": "4.4.0",
12692 + "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz",
12693 + "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8="
12694 + },
12650 "lodash.flow": { 12695 "lodash.flow": {
12651 "version": "3.5.0", 12696 "version": "3.5.0",
12652 "resolved": "https://registry.npmjs.org/lodash.flow/-/lodash.flow-3.5.0.tgz", 12697 "resolved": "https://registry.npmjs.org/lodash.flow/-/lodash.flow-3.5.0.tgz",
12653 "integrity": "sha1-h79AKSuM+D5OjOGjrkIJ4gBxZ1o=", 12698 "integrity": "sha1-h79AKSuM+D5OjOGjrkIJ4gBxZ1o=",
12654 "dev": true 12699 "dev": true
12655 }, 12700 },
12701 + "lodash.forin": {
12702 + "version": "4.4.0",
12703 + "resolved": "https://registry.npmjs.org/lodash.forin/-/lodash.forin-4.4.0.tgz",
12704 + "integrity": "sha1-XT8grlZAEfvog4H32YlJyclRlzE="
12705 + },
12706 + "lodash.get": {
12707 + "version": "4.4.2",
12708 + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
12709 + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
12710 + },
12711 + "lodash.has": {
12712 + "version": "4.5.2",
12713 + "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz",
12714 + "integrity": "sha1-0Z9NwQlQWMzL4rDN9O4P5Ko3yGI="
12715 + },
12716 + "lodash.invokemap": {
12717 + "version": "4.6.0",
12718 + "resolved": "https://registry.npmjs.org/lodash.invokemap/-/lodash.invokemap-4.6.0.tgz",
12719 + "integrity": "sha1-F0jNpdiw74NpxOs+xUwh/rofLWI="
12720 + },
12721 + "lodash.isempty": {
12722 + "version": "4.4.0",
12723 + "resolved": "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz",
12724 + "integrity": "sha1-b4bL7di+TsmHvpqvM8loTbGzHn4="
12725 + },
12726 + "lodash.isequal": {
12727 + "version": "4.5.0",
12728 + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
12729 + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
12730 + },
12731 + "lodash.isfunction": {
12732 + "version": "3.0.9",
12733 + "resolved": "https://registry.npmjs.org/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz",
12734 + "integrity": "sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw=="
12735 + },
12736 + "lodash.isinteger": {
12737 + "version": "4.0.4",
12738 + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
12739 + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M="
12740 + },
12741 + "lodash.isplainobject": {
12742 + "version": "4.0.6",
12743 + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
12744 + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
12745 + },
12746 + "lodash.lowerfirst": {
12747 + "version": "4.3.1",
12748 + "resolved": "https://registry.npmjs.org/lodash.lowerfirst/-/lodash.lowerfirst-4.3.1.tgz",
12749 + "integrity": "sha1-3jx7EuAsZSSgBZwvbLfFxSZVoT0="
12750 + },
12751 + "lodash.map": {
12752 + "version": "4.6.0",
12753 + "resolved": "https://registry.npmjs.org/lodash.map/-/lodash.map-4.6.0.tgz",
12754 + "integrity": "sha1-dx7Hg540c9nEzeKLGTlMNWL09tM="
12755 + },
12756 + "lodash.mapvalues": {
12757 + "version": "4.6.0",
12758 + "resolved": "https://registry.npmjs.org/lodash.mapvalues/-/lodash.mapvalues-4.6.0.tgz",
12759 + "integrity": "sha1-G6+lAF3p3W9PJmaMMMo3IwzJaJw="
12760 + },
12656 "lodash.memoize": { 12761 "lodash.memoize": {
12657 "version": "4.1.2", 12762 "version": "4.1.2",
12658 "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", 12763 "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
12659 "integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=", 12764 "integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=",
12660 "dev": true 12765 "dev": true
12661 }, 12766 },
12767 + "lodash.pick": {
12768 + "version": "4.4.0",
12769 + "resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz",
12770 + "integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM="
12771 + },
12772 + "lodash.snakecase": {
12773 + "version": "4.1.1",
12774 + "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz",
12775 + "integrity": "sha1-OdcUo1NXFHg3rv1ktdy7Fr7Nj40="
12776 + },
12662 "lodash.sortby": { 12777 "lodash.sortby": {
12663 "version": "4.7.0", 12778 "version": "4.7.0",
12664 "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", 12779 "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
...@@ -12687,8 +12802,17 @@ ...@@ -12687,8 +12802,17 @@
12687 "lodash.uniq": { 12802 "lodash.uniq": {
12688 "version": "4.5.0", 12803 "version": "4.5.0",
12689 "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", 12804 "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
12690 - "integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=", 12805 + "integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M="
12691 - "dev": true 12806 + },
12807 + "lodash.uniqby": {
12808 + "version": "4.7.0",
12809 + "resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz",
12810 + "integrity": "sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI="
12811 + },
12812 + "lodash.values": {
12813 + "version": "4.3.0",
12814 + "resolved": "https://registry.npmjs.org/lodash.values/-/lodash.values-4.3.0.tgz",
12815 + "integrity": "sha1-o6bCsOvsxcLLocF+bmIP6BtT00c="
12692 }, 12816 },
12693 "log-symbols": { 12817 "log-symbols": {
12694 "version": "4.0.0", 12818 "version": "4.0.0",
...@@ -13275,6 +13399,39 @@ ...@@ -13275,6 +13399,39 @@
13275 "minipass": "^3.0.0" 13399 "minipass": "^3.0.0"
13276 } 13400 }
13277 }, 13401 },
13402 + "miragejs": {
13403 + "version": "0.1.40",
13404 + "resolved": "https://registry.npmjs.org/miragejs/-/miragejs-0.1.40.tgz",
13405 + "integrity": "sha512-7zxIcynzdS6425KZ2+TWD6F6DqESorulSDW2QBXf4iKyVn/J5vSielcubAK8sTKUefTPCrSRi7PwgNOb0JlmIg==",
13406 + "requires": {
13407 + "@miragejs/pretender-node-polyfill": "^0.1.0",
13408 + "inflected": "^2.0.4",
13409 + "lodash.assign": "^4.2.0",
13410 + "lodash.camelcase": "^4.3.0",
13411 + "lodash.clonedeep": "^4.5.0",
13412 + "lodash.compact": "^3.0.1",
13413 + "lodash.find": "^4.6.0",
13414 + "lodash.flatten": "^4.4.0",
13415 + "lodash.forin": "^4.4.0",
13416 + "lodash.get": "^4.4.2",
13417 + "lodash.has": "^4.5.2",
13418 + "lodash.invokemap": "^4.6.0",
13419 + "lodash.isempty": "^4.4.0",
13420 + "lodash.isequal": "^4.5.0",
13421 + "lodash.isfunction": "^3.0.9",
13422 + "lodash.isinteger": "^4.0.4",
13423 + "lodash.isplainobject": "^4.0.6",
13424 + "lodash.lowerfirst": "^4.3.1",
13425 + "lodash.map": "^4.6.0",
13426 + "lodash.mapvalues": "^4.6.0",
13427 + "lodash.pick": "^4.4.0",
13428 + "lodash.snakecase": "^4.1.1",
13429 + "lodash.uniq": "^4.5.0",
13430 + "lodash.uniqby": "^4.7.0",
13431 + "lodash.values": "^4.3.0",
13432 + "pretender": "^3.4.3"
13433 + }
13434 + },
13278 "mississippi": { 13435 "mississippi": {
13279 "version": "3.0.0", 13436 "version": "3.0.0",
13280 "resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz", 13437 "resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz",
...@@ -15768,6 +15925,15 @@ ...@@ -15768,6 +15925,15 @@
15768 "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=", 15925 "integrity": "sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=",
15769 "dev": true 15926 "dev": true
15770 }, 15927 },
15928 + "pretender": {
15929 + "version": "3.4.3",
15930 + "resolved": "https://registry.npmjs.org/pretender/-/pretender-3.4.3.tgz",
15931 + "integrity": "sha512-AlbkBly9R8KR+R0sTCJ/ToOeEoUMtt52QVCetui5zoSmeLOU3S8oobFsyPLm1O2txR6t58qDNysqPnA1vVi8Hg==",
15932 + "requires": {
15933 + "fake-xml-http-request": "^2.1.1",
15934 + "route-recognizer": "^0.3.3"
15935 + }
15936 + },
15771 "prettier": { 15937 "prettier": {
15772 "version": "2.0.5", 15938 "version": "2.0.5",
15773 "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", 15939 "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
...@@ -17092,6 +17258,11 @@ ...@@ -17092,6 +17258,11 @@
17092 "inherits": "^2.0.1" 17258 "inherits": "^2.0.1"
17093 } 17259 }
17094 }, 17260 },
17261 + "route-recognizer": {
17262 + "version": "0.3.4",
17263 + "resolved": "https://registry.npmjs.org/route-recognizer/-/route-recognizer-0.3.4.tgz",
17264 + "integrity": "sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g=="
17265 + },
17095 "rsvp": { 17266 "rsvp": {
17096 "version": "4.8.5", 17267 "version": "4.8.5",
17097 "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz", 17268 "resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
6 "dependencies": { 6 "dependencies": {
7 "classnames": "^2.2.6", 7 "classnames": "^2.2.6",
8 "ky": "^0.20.0", 8 "ky": "^0.20.0",
9 + "miragejs": "^0.1.40",
9 "react": "^16.13.1", 10 "react": "^16.13.1",
10 "react-dom": "^16.13.1", 11 "react-dom": "^16.13.1",
11 "react-router-dom": "^5.2.0" 12 "react-router-dom": "^5.2.0"
......
...@@ -7,6 +7,8 @@ import { App } from "./App"; ...@@ -7,6 +7,8 @@ import { App } from "./App";
7 7
8 import * as serviceWorker from "./serviceWorker"; 8 import * as serviceWorker from "./serviceWorker";
9 9
10 +import "./server";
11 +
10 ReactDOM.render( 12 ReactDOM.render(
11 <React.StrictMode> 13 <React.StrictMode>
12 <App /> 14 <App />
......
1 +import { createServer, Model } from "miragejs";
2 +import { ModelDefinition } from "miragejs/-types";
3 +
4 +interface Item {
5 + id: string;
6 + is_folder: boolean;
7 + name: string;
8 + mime_type: string | null;
9 + path: string | null;
10 + parent: string | null;
11 + user_id: string;
12 + size: number;
13 + is_deleted: boolean;
14 + created_timestamp: string;
15 + updated_timestamp: string;
16 + status: boolean;
17 +}
18 +
19 +interface SharedItem {
20 + id: string;
21 + file_id: string;
22 + until: string;
23 + password: string;
24 +}
25 +
26 +interface User {
27 + id: string;
28 + user_id: string;
29 + name: string;
30 + password: string;
31 + total_size: number;
32 + current_size: number;
33 +}
34 +
35 +const ItemModel: ModelDefinition<Item> = Model;
36 +const SharedItemModel: ModelDefinition<SharedItem> = Model;
37 +const UserModel: ModelDefinition<User> = Model;
38 +
39 +createServer({
40 + models: {
41 + item: ItemModel,
42 + shared_item: SharedItemModel,
43 + user: UserModel,
44 + },
45 +
46 + factories: {},
47 +
48 + routes() {
49 + this.namespace = "api";
50 +
51 + this.get("/items/:item_id/children", (schema, request) => {
52 + const directory = schema.find("item", request.params.item_id);
53 + if (!directory || !directory.is_folder) {
54 + return {
55 + status: 404,
56 + message: "Not Found",
57 + };
58 + }
59 +
60 + const list = schema.where("item", { parent: directory.id }).models;
61 + return {
62 + status: 200,
63 + data: {
64 + ...directory.attrs,
65 + count: list.length,
66 + list,
67 + },
68 + };
69 + });
70 + },
71 +
72 + seeds(server) {
73 + const user = server.create("user", {
74 + id: "1",
75 + user_id: "test",
76 + name: "테스트",
77 + password: "password",
78 + total_size: 1024 * 1024 * 1024 * 5, // 5GB
79 + current_size: 1024 * 1024 * 1024 * 1, // 1GB
80 + });
81 +
82 + const rootDir = server.create("item", {
83 + id: "1",
84 + is_folder: true,
85 + name: "root",
86 + mime_type: null,
87 + path: null,
88 + parent: null,
89 + user_id: user.id,
90 + size: 0,
91 + is_deleted: false,
92 + created_timestamp: "2020-05-14T06:20:44Z",
93 + updated_timestamp: "2020-05-14T06:20:44Z",
94 + status: true,
95 + });
96 +
97 + server.create("item", {
98 + id: "2",
99 + is_folder: false,
100 + name: "image.jpg",
101 + mime_type: "image/jpeg",
102 + path: "",
103 + parent: rootDir.id,
104 + user_id: user.id,
105 + size: 1024 * 1024 * 5,
106 + is_deleted: false,
107 + created_timestamp: "2020-05-14T06:20:44Z",
108 + updated_timestamp: "2020-05-14T06:20:44Z",
109 + status: true,
110 + });
111 + },
112 +});