@ellipticltd/aml-utils 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/aml-utils.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +283 -0
- package/dist/errors/errors.d.ts +9 -0
- package/dist/errors/errors.js +42 -0
- package/dist/errors/errors.spec.d.ts +1 -0
- package/dist/errors/errors.spec.js +23 -0
- package/dist/file-parser/__tests/file-parser.spec.d.ts +1 -0
- package/dist/file-parser/__tests/file-parser.spec.js +118 -0
- package/dist/file-parser/__tests/parse-row.spec.d.ts +1 -0
- package/dist/file-parser/__tests/parse-row.spec.js +29 -0
- package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +1 -0
- package/dist/file-parser/__tests/sanitize-rows.spec.js +78 -0
- package/dist/file-parser/errors.d.ts +3 -0
- package/dist/file-parser/errors.js +11 -0
- package/dist/file-parser/file-parser.d.ts +8 -0
- package/dist/file-parser/file-parser.js +68 -0
- package/dist/file-parser/parse-row.d.ts +2 -0
- package/dist/file-parser/parse-row.js +39 -0
- package/dist/file-parser/sanitzeRows.d.ts +3 -0
- package/dist/file-parser/sanitzeRows.js +18 -0
- package/dist/formatting/formatting.d.ts +2 -0
- package/dist/formatting/formatting.js +17 -0
- package/dist/formatting/formatting.spec.d.ts +1 -0
- package/dist/formatting/formatting.spec.js +37 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -0
- package/dist/middleware/middleware.d.ts +4 -0
- package/dist/middleware/middleware.js +22 -0
- package/dist/orm-helpers/ormHelpers.d.ts +1 -0
- package/dist/orm-helpers/ormHelpers.js +17 -0
- package/dist/orm-helpers/ormHelpers.spec.d.ts +1 -0
- package/dist/orm-helpers/ormHelpers.spec.js +38 -0
- package/dist/types/types.d.ts +17 -0
- package/dist/types/types.js +203 -0
- package/dist/validations/old.validations.d.ts +5 -0
- package/dist/validations/old.validations.js +303 -0
- package/dist/validations/validations.d.ts +118 -0
- package/dist/validations/validations.js +300 -0
- package/dist/validations/validations.spec.d.ts +1 -0
- package/dist/validations/validations.spec.js +287 -0
- package/index.js +12 -0
- package/lib/errors.js +51 -0
- package/lib/formatting.js +28 -0
- package/lib/middleware.js +33 -0
- package/lib/ormHelpers.js +28 -0
- package/lib/types.js +179 -0
- package/lib/validations.js +199 -0
- package/package.json +25 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/aml-utils.iml" filepath="$PROJECT_DIR$/.idea/aml-utils.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ChangeListManager">
|
|
4
|
+
<list default="true" id="1837176f-2753-4542-a965-63ae2baf847d" name="Default Changelist" comment="">
|
|
5
|
+
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
6
|
+
</list>
|
|
7
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
8
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
9
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
10
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
11
|
+
</component>
|
|
12
|
+
<component name="FileTemplateManagerImpl">
|
|
13
|
+
<option name="RECENT_TEMPLATES">
|
|
14
|
+
<list>
|
|
15
|
+
<option value="JavaScript File" />
|
|
16
|
+
<option value="TypeScript File" />
|
|
17
|
+
</list>
|
|
18
|
+
</option>
|
|
19
|
+
</component>
|
|
20
|
+
<component name="Git.Settings">
|
|
21
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
22
|
+
</component>
|
|
23
|
+
<component name="ProjectId" id="1hrMHWefXP5BVgUzWJTYxTtV0UE" />
|
|
24
|
+
<component name="ProjectViewState">
|
|
25
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
26
|
+
<option name="showExcludedFiles" value="false" />
|
|
27
|
+
<option name="showLibraryContents" value="true" />
|
|
28
|
+
</component>
|
|
29
|
+
<component name="PropertiesComponent">
|
|
30
|
+
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
|
31
|
+
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
32
|
+
<property name="TF_FMT" value="false" />
|
|
33
|
+
<property name="WebServerToolWindowFactoryState" value="false" />
|
|
34
|
+
<property name="last_opened_file_path" value="$PROJECT_DIR$/lib/file-parser" />
|
|
35
|
+
<property name="node.js.detected.package.eslint" value="true" />
|
|
36
|
+
<property name="node.js.detected.package.tslint" value="true" />
|
|
37
|
+
<property name="node.js.path.for.package.eslint" value="project" />
|
|
38
|
+
<property name="node.js.path.for.package.tslint" value="project" />
|
|
39
|
+
<property name="node.js.selected.package.eslint" value="(autodetect)" />
|
|
40
|
+
<property name="node.js.selected.package.tslint" value="(autodetect)" />
|
|
41
|
+
<property name="nodejs_package_manager_path" value="npm" />
|
|
42
|
+
<property name="ts.external.directory.path" value="$PROJECT_DIR$/node_modules/typescript/lib" />
|
|
43
|
+
</component>
|
|
44
|
+
<component name="RecentsManager">
|
|
45
|
+
<key name="MoveFile.RECENT_KEYS">
|
|
46
|
+
<recent name="$PROJECT_DIR$/test" />
|
|
47
|
+
<recent name="$PROJECT_DIR$" />
|
|
48
|
+
<recent name="$PROJECT_DIR$/lib/validations" />
|
|
49
|
+
<recent name="$PROJECT_DIR$/lib/types" />
|
|
50
|
+
<recent name="$PROJECT_DIR$/lib/middleware" />
|
|
51
|
+
</key>
|
|
52
|
+
<key name="CopyFile.RECENT_KEYS">
|
|
53
|
+
<recent name="$PROJECT_DIR$/lib/file-parser" />
|
|
54
|
+
<recent name="$PROJECT_DIR$" />
|
|
55
|
+
</key>
|
|
56
|
+
</component>
|
|
57
|
+
<component name="RunManager" selected="npm.test:unit">
|
|
58
|
+
<configuration default="true" type="js.build_tools.npm">
|
|
59
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
60
|
+
<command value="run" />
|
|
61
|
+
<scripts>
|
|
62
|
+
<script value="test:unit" />
|
|
63
|
+
</scripts>
|
|
64
|
+
<node-interpreter value="project" />
|
|
65
|
+
<envs />
|
|
66
|
+
<method v="2" />
|
|
67
|
+
</configuration>
|
|
68
|
+
<configuration name="build" type="js.build_tools.npm">
|
|
69
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
70
|
+
<command value="run" />
|
|
71
|
+
<scripts>
|
|
72
|
+
<script value="build" />
|
|
73
|
+
</scripts>
|
|
74
|
+
<node-interpreter value="project" />
|
|
75
|
+
<envs />
|
|
76
|
+
<method v="2" />
|
|
77
|
+
</configuration>
|
|
78
|
+
<configuration name="build:watch" type="js.build_tools.npm">
|
|
79
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
80
|
+
<command value="run" />
|
|
81
|
+
<scripts>
|
|
82
|
+
<script value="build:dev" />
|
|
83
|
+
</scripts>
|
|
84
|
+
<node-interpreter value="project" />
|
|
85
|
+
<envs />
|
|
86
|
+
<method v="2" />
|
|
87
|
+
</configuration>
|
|
88
|
+
<configuration name="test:unit" type="js.build_tools.npm" nameIsGenerated="true">
|
|
89
|
+
<package-json value="$PROJECT_DIR$/package.json" />
|
|
90
|
+
<command value="run" />
|
|
91
|
+
<scripts>
|
|
92
|
+
<script value="test:unit" />
|
|
93
|
+
</scripts>
|
|
94
|
+
<node-interpreter value="project" />
|
|
95
|
+
<envs />
|
|
96
|
+
<method v="2" />
|
|
97
|
+
</configuration>
|
|
98
|
+
<list>
|
|
99
|
+
<item itemvalue="npm.test:unit" />
|
|
100
|
+
<item itemvalue="npm.build" />
|
|
101
|
+
<item itemvalue="npm.build:watch" />
|
|
102
|
+
</list>
|
|
103
|
+
</component>
|
|
104
|
+
<component name="SvnConfiguration">
|
|
105
|
+
<configuration />
|
|
106
|
+
</component>
|
|
107
|
+
<component name="TaskManager">
|
|
108
|
+
<task active="true" id="Default" summary="Default task">
|
|
109
|
+
<changelist id="1837176f-2753-4542-a965-63ae2baf847d" name="Default Changelist" comment="" />
|
|
110
|
+
<created>1600764670024</created>
|
|
111
|
+
<option name="number" value="Default" />
|
|
112
|
+
<option name="presentableId" value="Default" />
|
|
113
|
+
<updated>1600764670024</updated>
|
|
114
|
+
<workItem from="1600764673198" duration="1110000" />
|
|
115
|
+
<workItem from="1600790902200" duration="191000" />
|
|
116
|
+
<workItem from="1603740426879" duration="815000" />
|
|
117
|
+
<workItem from="1603814034908" duration="420000" />
|
|
118
|
+
<workItem from="1604490631639" duration="26088000" />
|
|
119
|
+
<workItem from="1604668327464" duration="4737000" />
|
|
120
|
+
<workItem from="1604998987498" duration="184000" />
|
|
121
|
+
<workItem from="1615990383007" duration="1644000" />
|
|
122
|
+
<workItem from="1616177379467" duration="17000" />
|
|
123
|
+
<workItem from="1617703307593" duration="1940000" />
|
|
124
|
+
<workItem from="1635945075936" duration="328000" />
|
|
125
|
+
</task>
|
|
126
|
+
<task id="LOCAL-00001" summary="perf: typescriptify AML-utils, add code needed for sem-ver">
|
|
127
|
+
<created>1604566799538</created>
|
|
128
|
+
<option name="number" value="00001" />
|
|
129
|
+
<option name="presentableId" value="LOCAL-00001" />
|
|
130
|
+
<option name="project" value="LOCAL" />
|
|
131
|
+
<updated>1604566799538</updated>
|
|
132
|
+
</task>
|
|
133
|
+
<task id="LOCAL-00002" summary="fix: add sem-rel to circle">
|
|
134
|
+
<created>1604571794163</created>
|
|
135
|
+
<option name="number" value="00002" />
|
|
136
|
+
<option name="presentableId" value="LOCAL-00002" />
|
|
137
|
+
<option name="project" value="LOCAL" />
|
|
138
|
+
<updated>1604571794163</updated>
|
|
139
|
+
</task>
|
|
140
|
+
<task id="LOCAL-00003" summary="fix: remove slack failure">
|
|
141
|
+
<created>1604571843808</created>
|
|
142
|
+
<option name="number" value="00003" />
|
|
143
|
+
<option name="presentableId" value="LOCAL-00003" />
|
|
144
|
+
<option name="project" value="LOCAL" />
|
|
145
|
+
<updated>1604571843808</updated>
|
|
146
|
+
</task>
|
|
147
|
+
<task id="LOCAL-00004" summary="fix: fixed yml">
|
|
148
|
+
<created>1604571931194</created>
|
|
149
|
+
<option name="number" value="00004" />
|
|
150
|
+
<option name="presentableId" value="LOCAL-00004" />
|
|
151
|
+
<option name="project" value="LOCAL" />
|
|
152
|
+
<updated>1604571931194</updated>
|
|
153
|
+
</task>
|
|
154
|
+
<task id="LOCAL-00005" summary="fix: install missing package">
|
|
155
|
+
<created>1604572225290</created>
|
|
156
|
+
<option name="number" value="00005" />
|
|
157
|
+
<option name="presentableId" value="LOCAL-00005" />
|
|
158
|
+
<option name="project" value="LOCAL" />
|
|
159
|
+
<updated>1604572225290</updated>
|
|
160
|
+
</task>
|
|
161
|
+
<task id="LOCAL-00006" summary="fix: changed fingerprint">
|
|
162
|
+
<created>1604574091631</created>
|
|
163
|
+
<option name="number" value="00006" />
|
|
164
|
+
<option name="presentableId" value="LOCAL-00006" />
|
|
165
|
+
<option name="project" value="LOCAL" />
|
|
166
|
+
<updated>1604574091631</updated>
|
|
167
|
+
</task>
|
|
168
|
+
<task id="LOCAL-00007" summary="fix: changed fingerprint">
|
|
169
|
+
<created>1604577629348</created>
|
|
170
|
+
<option name="number" value="00007" />
|
|
171
|
+
<option name="presentableId" value="LOCAL-00007" />
|
|
172
|
+
<option name="project" value="LOCAL" />
|
|
173
|
+
<updated>1604577629348</updated>
|
|
174
|
+
</task>
|
|
175
|
+
<task id="LOCAL-00008" summary="docs: added sem-ver readme BREAKING CHANGE">
|
|
176
|
+
<created>1604579846788</created>
|
|
177
|
+
<option name="number" value="00008" />
|
|
178
|
+
<option name="presentableId" value="LOCAL-00008" />
|
|
179
|
+
<option name="project" value="LOCAL" />
|
|
180
|
+
<updated>1604579846788</updated>
|
|
181
|
+
</task>
|
|
182
|
+
<task id="LOCAL-00009" summary="feat: pointless change to trigger BREAKING CHANGE">
|
|
183
|
+
<created>1604580920744</created>
|
|
184
|
+
<option name="number" value="00009" />
|
|
185
|
+
<option name="presentableId" value="LOCAL-00009" />
|
|
186
|
+
<option name="project" value="LOCAL" />
|
|
187
|
+
<updated>1604580920744</updated>
|
|
188
|
+
</task>
|
|
189
|
+
<task id="LOCAL-00010" summary="fix: changed validations to ts to fix type error">
|
|
190
|
+
<created>1604584764468</created>
|
|
191
|
+
<option name="number" value="00010" />
|
|
192
|
+
<option name="presentableId" value="LOCAL-00010" />
|
|
193
|
+
<option name="project" value="LOCAL" />
|
|
194
|
+
<updated>1604584764468</updated>
|
|
195
|
+
</task>
|
|
196
|
+
<task id="LOCAL-00011" summary="fix: changed validations to ts to fix type error">
|
|
197
|
+
<created>1604585867783</created>
|
|
198
|
+
<option name="number" value="00011" />
|
|
199
|
+
<option name="presentableId" value="LOCAL-00011" />
|
|
200
|
+
<option name="project" value="LOCAL" />
|
|
201
|
+
<updated>1604585867783</updated>
|
|
202
|
+
</task>
|
|
203
|
+
<task id="LOCAL-00012" summary="fix: changed validations to ts to fix type error">
|
|
204
|
+
<created>1604586095227</created>
|
|
205
|
+
<option name="number" value="00012" />
|
|
206
|
+
<option name="presentableId" value="LOCAL-00012" />
|
|
207
|
+
<option name="project" value="LOCAL" />
|
|
208
|
+
<updated>1604586095227</updated>
|
|
209
|
+
</task>
|
|
210
|
+
<task id="LOCAL-00013" summary="fix: fixed tests import">
|
|
211
|
+
<created>1604586309840</created>
|
|
212
|
+
<option name="number" value="00013" />
|
|
213
|
+
<option name="presentableId" value="LOCAL-00013" />
|
|
214
|
+
<option name="project" value="LOCAL" />
|
|
215
|
+
<updated>1604586309840</updated>
|
|
216
|
+
</task>
|
|
217
|
+
<task id="LOCAL-00014" summary="fix: reverted ts">
|
|
218
|
+
<created>1604592769095</created>
|
|
219
|
+
<option name="number" value="00014" />
|
|
220
|
+
<option name="presentableId" value="LOCAL-00014" />
|
|
221
|
+
<option name="project" value="LOCAL" />
|
|
222
|
+
<updated>1604592769095</updated>
|
|
223
|
+
</task>
|
|
224
|
+
<task id="LOCAL-00015" summary="docs: fixed file path">
|
|
225
|
+
<created>1604655865516</created>
|
|
226
|
+
<option name="number" value="00015" />
|
|
227
|
+
<option name="presentableId" value="LOCAL-00015" />
|
|
228
|
+
<option name="project" value="LOCAL" />
|
|
229
|
+
<updated>1604655865516</updated>
|
|
230
|
+
</task>
|
|
231
|
+
<task id="LOCAL-00016" summary="test: moved stubs to a before block">
|
|
232
|
+
<created>1604656533443</created>
|
|
233
|
+
<option name="number" value="00016" />
|
|
234
|
+
<option name="presentableId" value="LOCAL-00016" />
|
|
235
|
+
<option name="project" value="LOCAL" />
|
|
236
|
+
<updated>1604656533443</updated>
|
|
237
|
+
</task>
|
|
238
|
+
<task id="LOCAL-00017" summary="feat: exposed isSafeString">
|
|
239
|
+
<created>1604670252385</created>
|
|
240
|
+
<option name="number" value="00017" />
|
|
241
|
+
<option name="presentableId" value="LOCAL-00017" />
|
|
242
|
+
<option name="project" value="LOCAL" />
|
|
243
|
+
<updated>1604670252385</updated>
|
|
244
|
+
</task>
|
|
245
|
+
<option name="localTasksCounter" value="18" />
|
|
246
|
+
<servers />
|
|
247
|
+
</component>
|
|
248
|
+
<component name="TypeScriptGeneratedFilesManager">
|
|
249
|
+
<option name="version" value="2" />
|
|
250
|
+
</component>
|
|
251
|
+
<component name="VcsManagerConfiguration">
|
|
252
|
+
<MESSAGE value="typescriptify AML-utils, add code needed for sem-ver" />
|
|
253
|
+
<MESSAGE value="BREAKING CHANGE: typescriptify AML-utils, add code needed for sem-ver" />
|
|
254
|
+
<MESSAGE value="perf: typescriptify AML-utils, add code needed for sem-ver" />
|
|
255
|
+
<MESSAGE value="fix: add sem-rel to circle" />
|
|
256
|
+
<MESSAGE value="fix: remove slack failure" />
|
|
257
|
+
<MESSAGE value="fix: fixed yml" />
|
|
258
|
+
<MESSAGE value="fix: install missing package" />
|
|
259
|
+
<MESSAGE value="fix: changed fingerprint" />
|
|
260
|
+
<MESSAGE value="MAJOR: changed fingerprint" />
|
|
261
|
+
<MESSAGE value="major: changed fingerprint" />
|
|
262
|
+
<MESSAGE value="BREAKING CHANGE changed fingerprint" />
|
|
263
|
+
<MESSAGE value="BREAKING CHANGE: changed fingerprint" />
|
|
264
|
+
<MESSAGE value="BREAKING CHANGE: added sem-ver readme" />
|
|
265
|
+
<MESSAGE value="docs!: added sem-ver readme" />
|
|
266
|
+
<MESSAGE value="docs: added sem-ver readme BREAKING CHANGE" />
|
|
267
|
+
<MESSAGE value="feat: pointless change to trigger BREAKING CHANGE" />
|
|
268
|
+
<MESSAGE value="fix: changed validations to ts to fix type error" />
|
|
269
|
+
<MESSAGE value="fix: fixed tests import" />
|
|
270
|
+
<MESSAGE value="fix: reverted ts" />
|
|
271
|
+
<MESSAGE value="docs: fixed file path" />
|
|
272
|
+
<MESSAGE value="tests: moved stubs to a before block" />
|
|
273
|
+
<MESSAGE value="test: moved stubs to a before block" />
|
|
274
|
+
<MESSAGE value="feat: exposed isSafeString" />
|
|
275
|
+
<option name="LAST_COMMIT_MESSAGE" value="feat: exposed isSafeString" />
|
|
276
|
+
</component>
|
|
277
|
+
<component name="WindowStateProjectService">
|
|
278
|
+
<state x="385" y="196" width="670" height="676" key="search.everywhere.popup" timestamp="1635945233042">
|
|
279
|
+
<screen x="0" y="0" width="1440" height="900" />
|
|
280
|
+
</state>
|
|
281
|
+
<state x="385" y="196" width="670" height="676" key="search.everywhere.popup/0.0.1440.900@0.0.1440.900" timestamp="1635945233042" />
|
|
282
|
+
</component>
|
|
283
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const RequestError: any;
|
|
2
|
+
export const ServerError: any;
|
|
3
|
+
export const Forbidden: any;
|
|
4
|
+
export const Unauthorized: any;
|
|
5
|
+
export const BadRequest: any;
|
|
6
|
+
export const NotFound: any;
|
|
7
|
+
export const ConflictError: any;
|
|
8
|
+
export const InvalidArguments: any;
|
|
9
|
+
export const ServerTimeout: any;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const create = require('create-error');
|
|
3
|
+
const AppError = create('AppError');
|
|
4
|
+
const RequestError = create(AppError, 'RequestError');
|
|
5
|
+
RequestError.toJSON = () => ({
|
|
6
|
+
message: this.message,
|
|
7
|
+
});
|
|
8
|
+
const Forbidden = create(RequestError, 'ForbiddenError', {
|
|
9
|
+
status: 403,
|
|
10
|
+
});
|
|
11
|
+
const Unauthorized = create(RequestError, 'UnauthorizedError', {
|
|
12
|
+
status: 401,
|
|
13
|
+
});
|
|
14
|
+
const BadRequest = create(RequestError, 'BadRequestError', {
|
|
15
|
+
status: 400,
|
|
16
|
+
});
|
|
17
|
+
const NotFound = create(RequestError, 'NotFoundError', {
|
|
18
|
+
status: 404,
|
|
19
|
+
});
|
|
20
|
+
const ConflictError = create(RequestError, 'ConflictError', {
|
|
21
|
+
status: 409,
|
|
22
|
+
});
|
|
23
|
+
const ServerError = create(RequestError, 'ServerError', {
|
|
24
|
+
status: 500,
|
|
25
|
+
});
|
|
26
|
+
const InvalidArguments = create(RequestError, 'InvalidArgumentsError', {
|
|
27
|
+
status: 500,
|
|
28
|
+
});
|
|
29
|
+
const ServerTimeout = create(RequestError, 'ServerTimeoutError', {
|
|
30
|
+
status: 503,
|
|
31
|
+
});
|
|
32
|
+
module.exports = {
|
|
33
|
+
RequestError,
|
|
34
|
+
ServerError,
|
|
35
|
+
Forbidden,
|
|
36
|
+
Unauthorized,
|
|
37
|
+
BadRequest,
|
|
38
|
+
NotFound,
|
|
39
|
+
ConflictError,
|
|
40
|
+
InvalidArguments,
|
|
41
|
+
ServerTimeout,
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { RequestError, Forbidden, Unauthorized, BadRequest, NotFound, } = require('./errors');
|
|
3
|
+
describe('lib/error', () => {
|
|
4
|
+
describe('RequestError', () => {
|
|
5
|
+
it('should inherit from Error', () => (new RequestError instanceof Error).should.be.true);
|
|
6
|
+
describe('Forbidden Error', () => {
|
|
7
|
+
it('should inherit from Error', () => new Forbidden instanceof Error);
|
|
8
|
+
return it('should inherit from RequestError', () => new Forbidden instanceof RequestError);
|
|
9
|
+
});
|
|
10
|
+
describe('Unauthorized Error', () => {
|
|
11
|
+
it('should inherit from Error', () => new Unauthorized instanceof Error);
|
|
12
|
+
return it('should inherit from RequestError', () => new Unauthorized instanceof RequestError);
|
|
13
|
+
});
|
|
14
|
+
describe('BadRequest Error', () => {
|
|
15
|
+
it('should inherit from Error', () => new BadRequest instanceof Error);
|
|
16
|
+
return it('should inherit from RequestError', () => new BadRequest instanceof RequestError);
|
|
17
|
+
});
|
|
18
|
+
return describe('NotFound Error', () => {
|
|
19
|
+
it('should inherit from Error', () => new NotFound instanceof Error);
|
|
20
|
+
return it('should inherit from RequestError', () => new NotFound instanceof RequestError);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
35
|
+
const chai_1 = require("chai");
|
|
36
|
+
const file_parser_1 = __importDefault(require("../file-parser"));
|
|
37
|
+
const sanitizeRows = __importStar(require("../sanitzeRows"));
|
|
38
|
+
const parseRow = __importStar(require("../parse-row"));
|
|
39
|
+
describe('file-parser', () => {
|
|
40
|
+
const dependencies = {
|
|
41
|
+
processRow: sinon_1.default.spy(),
|
|
42
|
+
};
|
|
43
|
+
const parsedRows = [];
|
|
44
|
+
let mockParseRow;
|
|
45
|
+
let mockSanitizeRows;
|
|
46
|
+
let mockSetTimeout;
|
|
47
|
+
before(() => {
|
|
48
|
+
mockParseRow = sinon_1.default.stub(parseRow, 'default').returns(parsedRows);
|
|
49
|
+
mockSanitizeRows = sinon_1.default.stub(sanitizeRows, 'default').returns([{}]);
|
|
50
|
+
mockSetTimeout = sinon_1.default.stub(global, 'setTimeout').callsFake((callback) => callback());
|
|
51
|
+
});
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
sinon_1.default.resetHistory();
|
|
54
|
+
});
|
|
55
|
+
after(() => {
|
|
56
|
+
sinon_1.default.restore();
|
|
57
|
+
});
|
|
58
|
+
it('should call parseRow once per input new line', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const input = '\n';
|
|
60
|
+
yield file_parser_1.default(input, 50, dependencies);
|
|
61
|
+
chai_1.expect(mockParseRow).to.be.calledTwice;
|
|
62
|
+
}));
|
|
63
|
+
it('should call pass parseRow result into sanitizeRows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const input = '\n';
|
|
65
|
+
yield file_parser_1.default(input, 50, dependencies);
|
|
66
|
+
chai_1.expect(mockSanitizeRows).to.be.calledOnce;
|
|
67
|
+
chai_1.expect(mockSanitizeRows).to.be.deep.calledWith([[], []], dependencies.processRow);
|
|
68
|
+
}));
|
|
69
|
+
it('should throw error when number of rows is more than max rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
const input = '\n';
|
|
71
|
+
mockSanitizeRows.returns(new Array(20));
|
|
72
|
+
try {
|
|
73
|
+
yield file_parser_1.default(input, 10, dependencies);
|
|
74
|
+
chai_1.expect(1).to.equal(2);
|
|
75
|
+
}
|
|
76
|
+
catch (ex) {
|
|
77
|
+
chai_1.expect(ex.name).to.equal('TooManyRowsError');
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
it('should throw error when no rows returned from sanitizeRows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const input = '\n';
|
|
82
|
+
mockSanitizeRows.returns([]);
|
|
83
|
+
try {
|
|
84
|
+
yield file_parser_1.default(input, 10, dependencies);
|
|
85
|
+
chai_1.expect(1).to.equal(2);
|
|
86
|
+
}
|
|
87
|
+
catch (ex) {
|
|
88
|
+
chai_1.expect(ex.name).to.equal('Error');
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
it('should throw error an error when content is "invalidFileType"', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
const input = 'invalidFileType';
|
|
93
|
+
mockSanitizeRows.returns([]);
|
|
94
|
+
try {
|
|
95
|
+
yield file_parser_1.default(input, 10, dependencies);
|
|
96
|
+
chai_1.expect(1).to.equal(2);
|
|
97
|
+
}
|
|
98
|
+
catch (ex) {
|
|
99
|
+
chai_1.expect(ex.message).to.equal('Invalid file type');
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
it('should call process row once per row in single timeout', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
const input = '\n';
|
|
104
|
+
const fakeRows = (new Array(30)).fill({});
|
|
105
|
+
mockSanitizeRows.returns(fakeRows);
|
|
106
|
+
yield file_parser_1.default(input, 70, dependencies);
|
|
107
|
+
chai_1.expect(dependencies.processRow).to.be.callCount(30);
|
|
108
|
+
chai_1.expect(mockSetTimeout).to.be.calledOnce;
|
|
109
|
+
}));
|
|
110
|
+
it('should call process row once per row in two timeouts when more than 30 rows', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const input = '\n';
|
|
112
|
+
const fakeRows = (new Array(50)).fill({});
|
|
113
|
+
mockSanitizeRows.returns(fakeRows);
|
|
114
|
+
yield file_parser_1.default(input, 70, dependencies);
|
|
115
|
+
chai_1.expect(dependencies.processRow).to.be.callCount(50);
|
|
116
|
+
chai_1.expect(mockSetTimeout).to.be.calledTwice;
|
|
117
|
+
}));
|
|
118
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const parse_row_1 = __importDefault(require("../parse-row"));
|
|
8
|
+
describe('parse-row', () => {
|
|
9
|
+
it('should handle tabs', () => {
|
|
10
|
+
const input = 'asdas \t asdar \t aaaaa \t bbb bb';
|
|
11
|
+
const result = parse_row_1.default(input);
|
|
12
|
+
chai_1.expect(result).to.have.length(4);
|
|
13
|
+
});
|
|
14
|
+
it('should handle comas', () => {
|
|
15
|
+
const input = 'asdas, asdar, aaaaa, bbb bb';
|
|
16
|
+
const result = parse_row_1.default(input);
|
|
17
|
+
chai_1.expect(result).to.have.length(4);
|
|
18
|
+
});
|
|
19
|
+
it('should handle spaces', () => {
|
|
20
|
+
const input = 'asdas asdar aaaaa bbb bb';
|
|
21
|
+
const result = parse_row_1.default(input);
|
|
22
|
+
chai_1.expect(result).to.have.length(4);
|
|
23
|
+
});
|
|
24
|
+
it('should handle spaces', () => {
|
|
25
|
+
const input = 'asdas asdar aaaaa bbb bb';
|
|
26
|
+
const result = parse_row_1.default(input);
|
|
27
|
+
chai_1.expect(result).to.have.length(5);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
8
|
+
const sanitzeRows_1 = __importDefault(require("../sanitzeRows"));
|
|
9
|
+
describe('sanitize-rows', () => {
|
|
10
|
+
it('should remove empty rows at the start of the array', () => {
|
|
11
|
+
const input = [
|
|
12
|
+
['', '', ''],
|
|
13
|
+
['this', 'is', 'valid'],
|
|
14
|
+
['this', 'is', 'valid'],
|
|
15
|
+
];
|
|
16
|
+
const result = sanitzeRows_1.default(input, () => ({
|
|
17
|
+
isValid: true,
|
|
18
|
+
}));
|
|
19
|
+
chai_1.expect(result).to.have.length(2);
|
|
20
|
+
});
|
|
21
|
+
it('should remove empty rows at the end of the array', () => {
|
|
22
|
+
const input = [
|
|
23
|
+
['this', 'is', 'valid'],
|
|
24
|
+
['this', 'is', 'valid'],
|
|
25
|
+
['', '', ''],
|
|
26
|
+
];
|
|
27
|
+
const result = sanitzeRows_1.default(input, () => ({
|
|
28
|
+
isValid: true,
|
|
29
|
+
}));
|
|
30
|
+
chai_1.expect(result).to.have.length(2);
|
|
31
|
+
});
|
|
32
|
+
it('should remove empty rows at the start and end of the array', () => {
|
|
33
|
+
const input = [
|
|
34
|
+
['', '', ''],
|
|
35
|
+
['', '', ''],
|
|
36
|
+
['', '', ''],
|
|
37
|
+
['this', 'is', 'valid'],
|
|
38
|
+
['this', 'is', 'valid'],
|
|
39
|
+
['', '', ''],
|
|
40
|
+
['', '', ''],
|
|
41
|
+
['', '', ''],
|
|
42
|
+
];
|
|
43
|
+
const result = sanitzeRows_1.default(input, () => ({
|
|
44
|
+
isValid: true,
|
|
45
|
+
}));
|
|
46
|
+
chai_1.expect(result).to.have.length(2);
|
|
47
|
+
});
|
|
48
|
+
it('should remove the first row if it is not empty and not valid', () => {
|
|
49
|
+
const input = [
|
|
50
|
+
['', '', ''],
|
|
51
|
+
['this', 'is', 'invalid'],
|
|
52
|
+
['this', 'is', 'valid'],
|
|
53
|
+
['this', 'is', 'valid'],
|
|
54
|
+
['', '', ''],
|
|
55
|
+
['', '', ''],
|
|
56
|
+
['', '', ''],
|
|
57
|
+
];
|
|
58
|
+
const returnsFalseOnce = sinon_1.default.stub();
|
|
59
|
+
returnsFalseOnce.returns(true);
|
|
60
|
+
returnsFalseOnce.onFirstCall().returns(false);
|
|
61
|
+
const result = sanitzeRows_1.default(input, returnsFalseOnce);
|
|
62
|
+
chai_1.expect(result).to.have.length(2);
|
|
63
|
+
});
|
|
64
|
+
it('should allow rows with some empty values', () => {
|
|
65
|
+
const input = [
|
|
66
|
+
['this', 'is', 'invalid'],
|
|
67
|
+
['this', 'is', 'valid'],
|
|
68
|
+
['this', 'is', 'valid'],
|
|
69
|
+
['valid', '', ''],
|
|
70
|
+
['', '', ''],
|
|
71
|
+
['', '', ''],
|
|
72
|
+
];
|
|
73
|
+
const result = sanitzeRows_1.default(input, () => ({
|
|
74
|
+
isValid: true,
|
|
75
|
+
}));
|
|
76
|
+
chai_1.expect(result).to.have.length(4);
|
|
77
|
+
});
|
|
78
|
+
});
|