shinkansen-transmission 2.2.29 → 2.2.32
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/README.md +177 -165
- package/package.json +2 -2
package/README.md
CHANGED
@@ -1,178 +1,20 @@
|
|
1
1
|
## `shinkansen-transmission`
|
2
2
|
|
3
|
-
|
3
|
+
Shinkansen generates JSON Schema valid documents from user submissions with `<html />` forms.
|
4
4
|
|
5
|
-
|
5
|
+
# Transmission
|
6
6
|
|
7
|
-
|
7
|
+
_Transmission_ transforms HTTP `POST` data into JSON Schema valid `JSON` documents (and back again).
|
8
8
|
|
9
|
-
|
9
|
+
It can also translate JSON Schema into Zashiki description format describing `<html />` forms.
|
10
|
+
|
11
|
+
## Installation
|
10
12
|
|
11
13
|
```bash
|
12
14
|
npm i -P shinkansen-transmission
|
13
15
|
```
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
```javascript
|
18
|
-
const zashiki = toZashiki(rootSchema, values, params)
|
19
|
-
```
|
20
|
-
|
21
|
-
The transformer walks the `rootSchema` and maps fields in `values` and `params` to another structure, which it returns.
|
22
|
-
|
23
|
-
- `rootSchema` is a JSON Schema
|
24
|
-
- `values` is a document valid according to the Schema
|
25
|
-
- `params` are any other parameters for the transformer
|
26
|
-
|
27
|
-
The return value is an object with the fields `meta` and `elements`.
|
28
|
-
|
29
|
-
As you might expect, `meta` contains fields _about_ the Schema, while `elements` contains fields to be rendered as HTML. (*Shinkansen Transmission* doesn't express any opinion on what those elements are to be, but assumes that a `field` will be rendered as an HTML `<form />` element or some component which behaves like one.)
|
30
|
-
|
31
|
-
#### Transformed structure
|
32
|
-
|
33
|
-
```javascript
|
34
|
-
{
|
35
|
-
meta: {
|
36
|
-
uri: String,
|
37
|
-
name: String,
|
38
|
-
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
39
|
-
schema: Object,
|
40
|
-
rootSchema: Object,
|
41
|
-
isRequired: Boolean,
|
42
|
-
defaultValue: /* Per `type` */,
|
43
|
-
value: /* Per `type` */,
|
44
|
-
},
|
45
|
-
elements: {
|
46
|
-
title: String,
|
47
|
-
description: String,
|
48
|
-
field: {
|
49
|
-
isRequired: Boolean,
|
50
|
-
value: /* Per `type` */,
|
51
|
-
name: String
|
52
|
-
}
|
53
|
-
}
|
54
|
-
}
|
55
|
-
```
|
56
|
-
|
57
|
-
##### `enum`
|
58
|
-
|
59
|
-
```javascript
|
60
|
-
{
|
61
|
-
meta: {
|
62
|
-
uri: String,
|
63
|
-
name: String,
|
64
|
-
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
65
|
-
schema: Object,
|
66
|
-
rootSchema: Object,
|
67
|
-
isRequired: Boolean,
|
68
|
-
selectedItems: Array
|
69
|
-
},
|
70
|
-
elements: {
|
71
|
-
title: String,
|
72
|
-
description: String,
|
73
|
-
enum: {
|
74
|
-
isRequired: Boolean,
|
75
|
-
selectedItems: Array,
|
76
|
-
items: Array,
|
77
|
-
name: String
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
```
|
82
|
-
|
83
|
-
##### `anyOf`
|
84
|
-
|
85
|
-
```javascript
|
86
|
-
{
|
87
|
-
meta: {
|
88
|
-
uri: String,
|
89
|
-
name: String,
|
90
|
-
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
91
|
-
schema: Object,
|
92
|
-
rootSchema: Object,
|
93
|
-
isRequired: Boolean,
|
94
|
-
selectedItems: Array,
|
95
|
-
},
|
96
|
-
elements: {
|
97
|
-
title: String,
|
98
|
-
description: String,
|
99
|
-
anyOf: {
|
100
|
-
isRequired: Boolean,
|
101
|
-
selectedItems: Array,
|
102
|
-
items: Array,
|
103
|
-
name: String
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
```
|
108
|
-
|
109
|
-
##### `oneOf`
|
110
|
-
|
111
|
-
```javascript
|
112
|
-
{
|
113
|
-
meta: {
|
114
|
-
uri: String,
|
115
|
-
name: String,
|
116
|
-
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
117
|
-
schema: Object,
|
118
|
-
rootSchema: Object,
|
119
|
-
isRequired: Boolean,
|
120
|
-
selectedItems: Array,
|
121
|
-
},
|
122
|
-
elements: {
|
123
|
-
title: String,
|
124
|
-
description: String,
|
125
|
-
oneOf: {
|
126
|
-
required: Boolean,
|
127
|
-
selectedItems: Array,
|
128
|
-
items: Array,
|
129
|
-
name: String
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
```
|
134
|
-
|
135
|
-
##### `allOf`
|
136
|
-
|
137
|
-
- `array` or `object`
|
138
|
-
|
139
|
-
```javascript
|
140
|
-
{
|
141
|
-
meta: {
|
142
|
-
uri: String,
|
143
|
-
name: String,
|
144
|
-
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
145
|
-
schema: Object,
|
146
|
-
rootSchema: Object,
|
147
|
-
required: Boolean,
|
148
|
-
},
|
149
|
-
elements: {
|
150
|
-
title: String,
|
151
|
-
description: String,
|
152
|
-
fields: Array
|
153
|
-
}
|
154
|
-
}
|
155
|
-
```
|
156
|
-
|
157
|
-
- Any other
|
158
|
-
|
159
|
-
```javascript
|
160
|
-
{
|
161
|
-
meta: {
|
162
|
-
uri: String,
|
163
|
-
name: String,
|
164
|
-
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
165
|
-
schema: Object,
|
166
|
-
rootSchema: Object,
|
167
|
-
required: Boolean,
|
168
|
-
},
|
169
|
-
elements: {
|
170
|
-
title: String,
|
171
|
-
description: String,
|
172
|
-
field: Object
|
173
|
-
}
|
174
|
-
}
|
175
|
-
```
|
17
|
+
Your schema should be dereferenced _before_ it is transformed with _Transmission_ (we recommend [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser)).
|
176
18
|
|
177
19
|
### `fromHashToDocument`
|
178
20
|
|
@@ -342,3 +184,173 @@ A hash.
|
|
342
184
|
active: 'true'
|
343
185
|
}
|
344
186
|
```
|
187
|
+
|
188
|
+
### `toZashiki`
|
189
|
+
|
190
|
+
```javascript
|
191
|
+
const zashiki = toZashiki(rootSchema, values, params)
|
192
|
+
```
|
193
|
+
|
194
|
+
The transformer walks the `rootSchema` and maps fields in `values` and `params` to Zashiki description format, which it returns.
|
195
|
+
|
196
|
+
- `rootSchema` is a JSON Schema
|
197
|
+
- `values` is a document valid according to the Schema
|
198
|
+
- `params` are any other parameters for the transformer
|
199
|
+
|
200
|
+
The return value is an object with the fields `meta` and `elements`.
|
201
|
+
|
202
|
+
As you might expect, `meta` contains fields _about_ the Schema, while `elements` contains fields to be rendered as HTML. (_Transmission_ doesn't express any opinion on what those elements are to be, but assumes that a `field` will be rendered as an HTML `<form />` element or some component which behaves like one.)
|
203
|
+
|
204
|
+
#### Transformed structure
|
205
|
+
|
206
|
+
```javascript
|
207
|
+
{
|
208
|
+
meta: {
|
209
|
+
uri: String,
|
210
|
+
name: String,
|
211
|
+
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
212
|
+
schema: Object,
|
213
|
+
rootSchema: Object,
|
214
|
+
isRequired: Boolean,
|
215
|
+
defaultValue: /* Per `type` */,
|
216
|
+
value: /* Per `type` */,
|
217
|
+
},
|
218
|
+
elements: {
|
219
|
+
title: String,
|
220
|
+
description: String,
|
221
|
+
field: {
|
222
|
+
isRequired: Boolean,
|
223
|
+
value: /* Per `type` */,
|
224
|
+
name: String
|
225
|
+
}
|
226
|
+
}
|
227
|
+
}
|
228
|
+
```
|
229
|
+
|
230
|
+
##### `enum`
|
231
|
+
|
232
|
+
```javascript
|
233
|
+
{
|
234
|
+
meta: {
|
235
|
+
uri: String,
|
236
|
+
name: String,
|
237
|
+
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
238
|
+
schema: Object,
|
239
|
+
rootSchema: Object,
|
240
|
+
isRequired: Boolean,
|
241
|
+
selectedItems: Array
|
242
|
+
},
|
243
|
+
elements: {
|
244
|
+
title: String,
|
245
|
+
description: String,
|
246
|
+
enum: {
|
247
|
+
isRequired: Boolean,
|
248
|
+
selectedItems: Array,
|
249
|
+
items: Array,
|
250
|
+
name: String
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
```
|
255
|
+
|
256
|
+
##### `anyOf`
|
257
|
+
|
258
|
+
```javascript
|
259
|
+
{
|
260
|
+
meta: {
|
261
|
+
uri: String,
|
262
|
+
name: String,
|
263
|
+
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
264
|
+
schema: Object,
|
265
|
+
rootSchema: Object,
|
266
|
+
isRequired: Boolean,
|
267
|
+
selectedItems: Array,
|
268
|
+
},
|
269
|
+
elements: {
|
270
|
+
title: String,
|
271
|
+
description: String,
|
272
|
+
anyOf: {
|
273
|
+
isRequired: Boolean,
|
274
|
+
selectedItems: Array,
|
275
|
+
items: Array,
|
276
|
+
name: String
|
277
|
+
}
|
278
|
+
}
|
279
|
+
}
|
280
|
+
```
|
281
|
+
|
282
|
+
##### `oneOf`
|
283
|
+
|
284
|
+
```javascript
|
285
|
+
{
|
286
|
+
meta: {
|
287
|
+
uri: String,
|
288
|
+
name: String,
|
289
|
+
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
290
|
+
schema: Object,
|
291
|
+
rootSchema: Object,
|
292
|
+
isRequired: Boolean,
|
293
|
+
selectedItems: Array,
|
294
|
+
},
|
295
|
+
elements: {
|
296
|
+
title: String,
|
297
|
+
description: String,
|
298
|
+
oneOf: {
|
299
|
+
required: Boolean,
|
300
|
+
selectedItems: Array,
|
301
|
+
items: Array,
|
302
|
+
name: String
|
303
|
+
}
|
304
|
+
}
|
305
|
+
}
|
306
|
+
```
|
307
|
+
|
308
|
+
##### `allOf`
|
309
|
+
|
310
|
+
- `array` or `object`
|
311
|
+
|
312
|
+
```javascript
|
313
|
+
{
|
314
|
+
meta: {
|
315
|
+
uri: String,
|
316
|
+
name: String,
|
317
|
+
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
318
|
+
schema: Object,
|
319
|
+
rootSchema: Object,
|
320
|
+
required: Boolean,
|
321
|
+
},
|
322
|
+
elements: {
|
323
|
+
title: String,
|
324
|
+
description: String,
|
325
|
+
fields: Array
|
326
|
+
}
|
327
|
+
}
|
328
|
+
```
|
329
|
+
|
330
|
+
- Any other
|
331
|
+
|
332
|
+
```javascript
|
333
|
+
{
|
334
|
+
meta: {
|
335
|
+
uri: String,
|
336
|
+
name: String,
|
337
|
+
type: String /* One of "object" "array" "string" "number" "boolean" "null" */,
|
338
|
+
schema: Object,
|
339
|
+
rootSchema: Object,
|
340
|
+
required: Boolean,
|
341
|
+
},
|
342
|
+
elements: {
|
343
|
+
title: String,
|
344
|
+
description: String,
|
345
|
+
field: Object
|
346
|
+
}
|
347
|
+
}
|
348
|
+
```
|
349
|
+
|
350
|
+
## See also
|
351
|
+
|
352
|
+
- [Cogs](https://github.com/modernpoacher/shinkansen-cogs)
|
353
|
+
- [Sprockets](https://github.com/modernpoacher/shinkansen-sprockets)
|
354
|
+
- [Gears](https://github.com/modernpoacher/shinkansen-gears)
|
355
|
+
- [Pinion](https://github.com/modernpoacher/shinkansen-pinion)
|
356
|
+
- [Engine](https://github.com/modernpoacher/shinkansen-engine)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shinkansen-transmission",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.32",
|
4
4
|
"description": "Shinkansen Transmission",
|
5
5
|
"keywords": [
|
6
6
|
"Shinkansen",
|
@@ -41,7 +41,7 @@
|
|
41
41
|
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
42
42
|
"@babel/preset-env": "^7.21.5",
|
43
43
|
"@babel/register": "^7.21.0",
|
44
|
-
"@modernpoacher/hooks": "^1.0.
|
44
|
+
"@modernpoacher/hooks": "^1.0.398",
|
45
45
|
"@typescript-eslint/eslint-plugin": "^5.59.5",
|
46
46
|
"@typescript-eslint/parser": "^5.59.5",
|
47
47
|
"babel-loader": "^9.1.2",
|