shinkansen-cogs 1.5.24

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.
Files changed (108) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/README.md +11 -0
  3. package/babel.config.js +72 -0
  4. package/gulp.sh +42 -0
  5. package/index.js +7 -0
  6. package/lib/cogs/checkbox/index.js +1 -0
  7. package/lib/cogs/email/index.js +1 -0
  8. package/lib/cogs/index.js +1 -0
  9. package/lib/cogs/number/index.js +1 -0
  10. package/lib/cogs/password/index.js +1 -0
  11. package/lib/cogs/radio/index.js +1 -0
  12. package/lib/cogs/select/index.js +1 -0
  13. package/lib/cogs/text/index.js +1 -0
  14. package/lib/cogs/textarea/index.js +1 -0
  15. package/lib/components/common/disabled/index.js +1 -0
  16. package/lib/components/common/readonly/index.js +1 -0
  17. package/lib/components/common/required/index.js +1 -0
  18. package/lib/components/common/text-content/index.js +1 -0
  19. package/lib/components/description/checkbox/index.js +1 -0
  20. package/lib/components/description/email/index.js +1 -0
  21. package/lib/components/description/index.js +1 -0
  22. package/lib/components/description/number/index.js +1 -0
  23. package/lib/components/description/password/index.js +1 -0
  24. package/lib/components/description/radio/index.js +1 -0
  25. package/lib/components/description/select/index.js +1 -0
  26. package/lib/components/description/text/index.js +1 -0
  27. package/lib/components/description/textarea/index.js +1 -0
  28. package/lib/components/error-message/checkbox/index.js +1 -0
  29. package/lib/components/error-message/email/index.js +1 -0
  30. package/lib/components/error-message/index.js +1 -0
  31. package/lib/components/error-message/number/index.js +1 -0
  32. package/lib/components/error-message/password/index.js +1 -0
  33. package/lib/components/error-message/radio/index.js +1 -0
  34. package/lib/components/error-message/select/index.js +1 -0
  35. package/lib/components/error-message/text/index.js +1 -0
  36. package/lib/components/error-message/textarea/index.js +1 -0
  37. package/lib/components/field/checkbox/index.js +1 -0
  38. package/lib/components/field/email/index.js +1 -0
  39. package/lib/components/field/index.js +1 -0
  40. package/lib/components/field/number/index.js +1 -0
  41. package/lib/components/field/password/index.js +1 -0
  42. package/lib/components/field/radio/index.js +1 -0
  43. package/lib/components/field/select/index.js +1 -0
  44. package/lib/components/field/text/index.js +1 -0
  45. package/lib/components/field/textarea/index.js +1 -0
  46. package/lib/components/title/checkbox/index.js +1 -0
  47. package/lib/components/title/email/index.js +1 -0
  48. package/lib/components/title/index.js +1 -0
  49. package/lib/components/title/number/index.js +1 -0
  50. package/lib/components/title/password/index.js +1 -0
  51. package/lib/components/title/radio/index.js +1 -0
  52. package/lib/components/title/select/index.js +1 -0
  53. package/lib/components/title/text/index.js +1 -0
  54. package/lib/components/title/textarea/index.js +1 -0
  55. package/lib/index.js +1 -0
  56. package/lib/transformers/error-message/index.js +1 -0
  57. package/package.json +107 -0
  58. package/src/cogs/checkbox/index.js +138 -0
  59. package/src/cogs/email/index.js +115 -0
  60. package/src/cogs/index.js +225 -0
  61. package/src/cogs/number/index.js +124 -0
  62. package/src/cogs/password/index.js +115 -0
  63. package/src/cogs/radio/index.js +149 -0
  64. package/src/cogs/select/index.js +117 -0
  65. package/src/cogs/text/index.js +115 -0
  66. package/src/cogs/textarea/index.js +115 -0
  67. package/src/components/common/disabled/index.js +9 -0
  68. package/src/components/common/readonly/index.js +9 -0
  69. package/src/components/common/required/index.js +9 -0
  70. package/src/components/common/text-content/index.js +14 -0
  71. package/src/components/description/checkbox/index.js +19 -0
  72. package/src/components/description/email/index.js +19 -0
  73. package/src/components/description/index.js +61 -0
  74. package/src/components/description/number/index.js +19 -0
  75. package/src/components/description/password/index.js +19 -0
  76. package/src/components/description/radio/index.js +19 -0
  77. package/src/components/description/select/index.js +19 -0
  78. package/src/components/description/text/index.js +19 -0
  79. package/src/components/description/textarea/index.js +19 -0
  80. package/src/components/error-message/checkbox/index.js +19 -0
  81. package/src/components/error-message/email/index.js +19 -0
  82. package/src/components/error-message/index.js +103 -0
  83. package/src/components/error-message/number/index.js +19 -0
  84. package/src/components/error-message/password/index.js +19 -0
  85. package/src/components/error-message/radio/index.js +19 -0
  86. package/src/components/error-message/select/index.js +19 -0
  87. package/src/components/error-message/text/index.js +19 -0
  88. package/src/components/error-message/textarea/index.js +19 -0
  89. package/src/components/field/checkbox/index.js +55 -0
  90. package/src/components/field/email/index.js +56 -0
  91. package/src/components/field/index.js +165 -0
  92. package/src/components/field/number/index.js +65 -0
  93. package/src/components/field/password/index.js +56 -0
  94. package/src/components/field/radio/index.js +72 -0
  95. package/src/components/field/select/index.js +62 -0
  96. package/src/components/field/text/index.js +56 -0
  97. package/src/components/field/textarea/index.js +55 -0
  98. package/src/components/title/checkbox/index.js +19 -0
  99. package/src/components/title/email/index.js +19 -0
  100. package/src/components/title/index.js +134 -0
  101. package/src/components/title/number/index.js +19 -0
  102. package/src/components/title/password/index.js +19 -0
  103. package/src/components/title/radio/index.js +19 -0
  104. package/src/components/title/select/index.js +19 -0
  105. package/src/components/title/text/index.js +19 -0
  106. package/src/components/title/textarea/index.js +19 -0
  107. package/src/index.js +28 -0
  108. package/src/transformers/error-message/index.js +234 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * NumberTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from 'shinkansen-cogs/components/title'
6
+
7
+ export default class NumberTitle extends Title {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'number')
10
+ }
11
+ }
12
+
13
+ NumberTitle.propTypes = {
14
+ ...Title.propTypes
15
+ }
16
+
17
+ NumberTitle.defaultProps = {
18
+ ...Title.defaultProps
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * PasswordTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from 'shinkansen-cogs/components/title'
6
+
7
+ export default class PasswordTitle extends Title {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'password')
10
+ }
11
+ }
12
+
13
+ PasswordTitle.propTypes = {
14
+ ...Title.propTypes
15
+ }
16
+
17
+ PasswordTitle.defaultProps = {
18
+ ...Title.defaultProps
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * RadioTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from 'shinkansen-cogs/components/title'
6
+
7
+ export default class RadioTitle extends Title {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'radio')
10
+ }
11
+ }
12
+
13
+ RadioTitle.propTypes = {
14
+ ...Title.propTypes
15
+ }
16
+
17
+ RadioTitle.defaultProps = {
18
+ ...Title.defaultProps
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * SelectTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from 'shinkansen-cogs/components/title'
6
+
7
+ export default class SelectTitle extends Title {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'select')
10
+ }
11
+ }
12
+
13
+ SelectTitle.propTypes = {
14
+ ...Title.propTypes
15
+ }
16
+
17
+ SelectTitle.defaultProps = {
18
+ ...Title.defaultProps
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * TextTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from 'shinkansen-cogs/components/title'
6
+
7
+ export default class TextTitle extends Title {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'text')
10
+ }
11
+ }
12
+
13
+ TextTitle.propTypes = {
14
+ ...Title.propTypes
15
+ }
16
+
17
+ TextTitle.defaultProps = {
18
+ ...Title.defaultProps
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * TextareaTitle component
3
+ */
4
+ import classnames from 'classnames'
5
+ import Title from 'shinkansen-cogs/components/title'
6
+
7
+ export default class TextareaTitle extends Title {
8
+ getClassName () {
9
+ return classnames(super.getClassName(), 'textarea')
10
+ }
11
+ }
12
+
13
+ TextareaTitle.propTypes = {
14
+ ...Title.propTypes
15
+ }
16
+
17
+ TextareaTitle.defaultProps = {
18
+ ...Title.defaultProps
19
+ }
package/src/index.js ADDED
@@ -0,0 +1,28 @@
1
+ import CheckboxCog from './cogs/checkbox'
2
+ import EmailCog from './cogs/email'
3
+ import NumberCog from './cogs/number'
4
+ import PasswordCog from './cogs/password'
5
+ import RadioCog from './cogs/radio'
6
+ import SelectCog from './cogs/select'
7
+ import TextCog from './cogs/text'
8
+ import TextareaCog from './cogs/textarea'
9
+
10
+ export CheckboxCog from './cogs/checkbox'
11
+ export EmailCog from './cogs/email'
12
+ export NumberCog from './cogs/number'
13
+ export PasswordCog from './cogs/password'
14
+ export RadioCog from './cogs/radio'
15
+ export SelectCog from './cogs/select'
16
+ export TextCog from './cogs/text'
17
+ export TextareaCog from './cogs/textarea'
18
+
19
+ export default {
20
+ CheckboxCog,
21
+ EmailCog,
22
+ NumberCog,
23
+ PasswordCog,
24
+ RadioCog,
25
+ SelectCog,
26
+ TextCog,
27
+ TextareaCog
28
+ }
@@ -0,0 +1,234 @@
1
+ import debug from 'debug'
2
+
3
+ const log = debug('shinkansen-cogs:transformers:error-message')
4
+
5
+ export function getErrorTextForMaxItems (components = {}) {
6
+ log('getErrorTextForMaxItems')
7
+
8
+ return 'Max items'
9
+ }
10
+
11
+ export function getErrorTextForMinItems (components = {}) {
12
+ log('getErrorTextForMinItems')
13
+
14
+ return 'Min items'
15
+ }
16
+
17
+ export function getErrorTextForMaxLength (components = {}) {
18
+ log('getErrorTextForMaxLength')
19
+
20
+ return 'Max length'
21
+ }
22
+
23
+ export function getErrorTextForMinLength (components = {}) {
24
+ log('getErrorTextForMinLength')
25
+
26
+ return 'Min length'
27
+ }
28
+
29
+ export function getErrorTextForMaxProperties (components = {}) {
30
+ log('getErrorTextForMaxProperties')
31
+
32
+ return 'Max properties'
33
+ }
34
+
35
+ export function getErrorTextForMinProperties (components = {}) {
36
+ log('getErrorTextForMinProperties')
37
+
38
+ return 'Min properties'
39
+ }
40
+
41
+ export function getErrorTextForAdditionalItems (components = {}) {
42
+ log('getErrorTextForAdditionalItems')
43
+
44
+ return 'Additional items'
45
+ }
46
+
47
+ export function getErrorTextForMaximum (components = {}) {
48
+ log('getErrorTextForMaximum')
49
+
50
+ return 'Maximum'
51
+ }
52
+
53
+ export function getErrorTextForMinimum (components = {}) {
54
+ log('getErrorTextForMinimum')
55
+
56
+ return 'Minimum'
57
+ }
58
+
59
+ export function getErrorTextForFormat (components = {}) {
60
+ log('getErrorTextForFormat')
61
+
62
+ return 'Format'
63
+ }
64
+
65
+ export function getErrorTextForAdditionalProperties (components = {}) {
66
+ log('getErrorTextForAdditionalProperties')
67
+
68
+ return 'Additional properties'
69
+ }
70
+
71
+ export function getErrorTextForDependencies (components = {}) {
72
+ log('getErrorTextForDependencies')
73
+
74
+ return 'Dependencies'
75
+ }
76
+
77
+ export function getErrorTextForUniqeItems (components = {}) {
78
+ log('getErrorTextForUniqeItems')
79
+
80
+ return 'Unique items'
81
+ }
82
+
83
+ export function getErrorTextForPropertyRequired (components = {}) {
84
+ log('getErrorTextForPropertyRequired')
85
+
86
+ return 'Property required'
87
+ }
88
+
89
+ export function getErrorTextForPropertyNames (components = {}) {
90
+ log('getErrorTextForPropertyNames')
91
+
92
+ return 'Property names'
93
+ }
94
+
95
+ export function getErrorTextForPatternRequired (components = {}) {
96
+ log('getErrorTextForMultipleOf')
97
+
98
+ return 'Pattern required'
99
+ }
100
+
101
+ export function getErrorTextForMultipleOf (components = {}) {
102
+ log('getErrorTextForMultipleOf')
103
+
104
+ return 'Multiple of'
105
+ }
106
+
107
+ export function getErrorTextForPattern (components = {}) {
108
+ log('getErrorTextForPattern')
109
+
110
+ return 'Pattern'
111
+ }
112
+
113
+ export function getErrorTextForConst (components = {}) {
114
+ log('getErrorTextForConst')
115
+
116
+ return 'Const'
117
+ }
118
+
119
+ export function getErrorTextForEnum (components = {}) {
120
+ log('getErrorTextForEnum')
121
+
122
+ return 'Enum'
123
+ }
124
+
125
+ export function getErrorTextFor$Ref (components = {}) {
126
+ log('getErrorTextFor$Ref')
127
+
128
+ return '$Ref'
129
+ }
130
+
131
+ export function getErrorTextForOneOf (components = {}) {
132
+ log('getErrorTextForOneOf')
133
+
134
+ return 'One of'
135
+ }
136
+
137
+ export function getErrorTextForUnknown (components = {}) {
138
+ log('getErrorTextForUnknown')
139
+
140
+ return 'Unknown'
141
+ }
142
+
143
+ export function getErrorTextForTypeInvalid ({ expectedType } = {}, components = {}) {
144
+ log('getErrorTextForTypeInvalid')
145
+
146
+ switch (expectedType) {
147
+ case 'string':
148
+ return 'Type invalid (expected string)'
149
+ case 'number':
150
+ return 'Type invalid (expected number)'
151
+ case 'object':
152
+ return 'Type invalid (expected object)'
153
+ case 'array':
154
+ return 'Type invalid (expected array)'
155
+ case 'boolean':
156
+ return 'Type invalid (expected boolean)'
157
+ case 'null':
158
+ return 'Type invalid (expected null)'
159
+ default:
160
+ throw new Error('Incompatible with Shinkansen')
161
+ }
162
+ }
163
+
164
+ export function getErrorTextByType ({ type, params } = {}, components = {}) {
165
+ log('getErrorTextByType')
166
+
167
+ switch (type) {
168
+ case 'MAX_ITEMS':
169
+ return getErrorTextForMaxItems(components)
170
+ case 'MIN_ITEMS':
171
+ return getErrorTextForMinItems(components)
172
+ case 'MAX_LENGTH':
173
+ return getErrorTextForMaxLength(components)
174
+ case 'MIN_LENGTH':
175
+ return getErrorTextForMinLength(components)
176
+ case 'MAX_PROPERTIES':
177
+ return getErrorTextForMaxProperties(components)
178
+ case 'MIN_PROPERTIES':
179
+ return getErrorTextForMinProperties(components)
180
+ case 'ADDITIONAL_ITEMS':
181
+ return getErrorTextForAdditionalItems(components)
182
+ case 'MAXIMUM':
183
+ return getErrorTextForMaximum(components)
184
+ case 'MINIMUM':
185
+ return getErrorTextForMinimum(components)
186
+ case 'FORMAT':
187
+ return getErrorTextForFormat(components)
188
+ case 'ADDITIONAL_PROPERTIES':
189
+ return getErrorTextForAdditionalProperties(components)
190
+ case 'DEPENDENCIES':
191
+ return getErrorTextForDependencies(components)
192
+ case 'UNIQUE_ITEMS':
193
+ return getErrorTextForUniqeItems(components)
194
+ case 'PROPERTY_REQUIRED':
195
+ return getErrorTextForPropertyRequired(components)
196
+ case 'PROPERTY_NAMES':
197
+ return getErrorTextForPropertyNames(components)
198
+ case 'PATTERN_REQUIRED':
199
+ return getErrorTextForPatternRequired(components)
200
+ case 'TYPE_INVALID':
201
+ return getErrorTextForTypeInvalid(params, components)
202
+ case 'MULTIPLE_OF':
203
+ return getErrorTextForMultipleOf(components)
204
+ case 'PATTERN':
205
+ return getErrorTextForPattern(components)
206
+ case 'CONST':
207
+ return getErrorTextForConst(components)
208
+ case 'ENUM':
209
+ return getErrorTextForEnum(components)
210
+ case '$REF':
211
+ return getErrorTextFor$Ref(components)
212
+ case 'ONE_OF':
213
+ return getErrorTextForOneOf(components)
214
+ case 'UNKNOWN':
215
+ return getErrorTextForUnknown(components)
216
+ default:
217
+ throw new Error('Incompatible with Shinkansen')
218
+ }
219
+ }
220
+
221
+ export function getErrorHref ({ uri = '' } = {}) {
222
+ log('getErrorHref')
223
+
224
+ return '#'.concat(uri)
225
+ }
226
+
227
+ export default function transform (error, components) {
228
+ log('transform')
229
+
230
+ return {
231
+ text: getErrorTextByType(error, components),
232
+ href: getErrorHref(error)
233
+ }
234
+ }