shinkansen-sprockets 1.0.28

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 (58) 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/components/common/text-content/index.js +1 -0
  7. package/lib/components/description/fieldset/index.js +1 -0
  8. package/lib/components/description/index.js +1 -0
  9. package/lib/components/error-message/fieldset/index.js +1 -0
  10. package/lib/components/error-message/index.js +1 -0
  11. package/lib/components/group/check-answers/answer-title.js +1 -0
  12. package/lib/components/group/check-answers/answer-value.js +1 -0
  13. package/lib/components/group/check-answers/change-answer.js +1 -0
  14. package/lib/components/group/check-answers/index.js +1 -0
  15. package/lib/components/group/check-answers/visually-hidden-text.js +1 -0
  16. package/lib/components/group/error-summary/index.js +1 -0
  17. package/lib/components/group/fieldset/index.js +1 -0
  18. package/lib/components/group/index.js +1 -0
  19. package/lib/components/title/check-answers/index.js +1 -0
  20. package/lib/components/title/error-summary/index.js +1 -0
  21. package/lib/components/title/fieldset/index.js +1 -0
  22. package/lib/components/title/index.js +1 -0
  23. package/lib/index.js +1 -0
  24. package/lib/sprockets/check-answers/index.js +1 -0
  25. package/lib/sprockets/error-summary/index.js +1 -0
  26. package/lib/sprockets/fieldset/index.js +1 -0
  27. package/lib/sprockets/index.js +1 -0
  28. package/lib/transformers/check-answers/index.js +1 -0
  29. package/lib/transformers/common/index.js +1 -0
  30. package/lib/transformers/error-message/index.js +1 -0
  31. package/lib/transformers/error-summary/index.js +1 -0
  32. package/package.json +107 -0
  33. package/src/components/common/text-content/index.js +14 -0
  34. package/src/components/description/fieldset/index.js +19 -0
  35. package/src/components/description/index.js +61 -0
  36. package/src/components/error-message/fieldset/index.js +19 -0
  37. package/src/components/error-message/index.js +103 -0
  38. package/src/components/group/check-answers/answer-title.js +21 -0
  39. package/src/components/group/check-answers/answer-value.js +45 -0
  40. package/src/components/group/check-answers/change-answer.js +35 -0
  41. package/src/components/group/check-answers/index.js +104 -0
  42. package/src/components/group/check-answers/visually-hidden-text.js +25 -0
  43. package/src/components/group/error-summary/index.js +106 -0
  44. package/src/components/group/fieldset/index.js +19 -0
  45. package/src/components/group/index.js +42 -0
  46. package/src/components/title/check-answers/index.js +33 -0
  47. package/src/components/title/error-summary/index.js +33 -0
  48. package/src/components/title/fieldset/index.js +19 -0
  49. package/src/components/title/index.js +59 -0
  50. package/src/index.js +13 -0
  51. package/src/sprockets/check-answers/index.js +74 -0
  52. package/src/sprockets/error-summary/index.js +79 -0
  53. package/src/sprockets/fieldset/index.js +108 -0
  54. package/src/sprockets/index.js +86 -0
  55. package/src/transformers/check-answers/index.js +12 -0
  56. package/src/transformers/common/index.js +14 -0
  57. package/src/transformers/error-message/index.js +234 -0
  58. package/src/transformers/error-summary/index.js +234 -0
@@ -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
+ }
@@ -0,0 +1,234 @@
1
+ import debug from 'debug'
2
+
3
+ const log = debug('shinkansen-sprockets:transformers:error-summary')
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('Error incompatible with Zashiki')
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('Error incompatible with Zashiki')
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
+ }