@operato/scene-restful 7.0.1 → 7.3.19
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/package.json +3 -3
- package/CHANGELOG.md +0 -690
- package/demo/index.html +0 -116
- package/demo/things-scene-restful.html +0 -5
- package/demo/things-theme.html +0 -178
- package/src/index.ts +0 -5
- package/src/jsonp.ts +0 -85
- package/src/restful.ts +0 -453
- package/test/basic-test.html +0 -67
- package/test/index.html +0 -24
- package/test/unit/test-restful.js +0 -33
- package/test/unit/util.js +0 -22
- package/tsconfig.json +0 -24
- package/tsconfig.tsbuildinfo +0 -1
package/src/restful.ts
DELETED
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import { Component, ComponentNature, DataSource, RectPath, Shape, warn } from '@hatiolab/things-scene'
|
|
2
|
-
|
|
3
|
-
import jsonp from './jsonp'
|
|
4
|
-
|
|
5
|
-
const NATURE: ComponentNature = {
|
|
6
|
-
mutable: false,
|
|
7
|
-
resizable: true,
|
|
8
|
-
rotatable: true,
|
|
9
|
-
properties: [
|
|
10
|
-
{
|
|
11
|
-
type: 'select',
|
|
12
|
-
label: 'method',
|
|
13
|
-
name: 'method',
|
|
14
|
-
property: {
|
|
15
|
-
options: [
|
|
16
|
-
{
|
|
17
|
-
display: 'GET',
|
|
18
|
-
value: 'GET'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
display: 'POST',
|
|
22
|
-
value: 'POST'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
display: 'PUT',
|
|
26
|
-
value: 'PUT'
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
display: 'DELETE',
|
|
30
|
-
value: 'DELETE'
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
type: 'string',
|
|
37
|
-
label: 'url',
|
|
38
|
-
name: 'url'
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
type: 'string',
|
|
42
|
-
label: 'authorization',
|
|
43
|
-
name: 'authorization'
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: 'select',
|
|
47
|
-
label: 'data-format',
|
|
48
|
-
name: 'dataFormat',
|
|
49
|
-
property: {
|
|
50
|
-
options: [
|
|
51
|
-
{
|
|
52
|
-
display: 'json',
|
|
53
|
-
value: 'json'
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
display: 'jsonp',
|
|
57
|
-
value: 'jsonp'
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
display: 'text',
|
|
61
|
-
value: 'text'
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
type: 'select',
|
|
68
|
-
label: 'content-type',
|
|
69
|
-
name: 'contentType',
|
|
70
|
-
property: {
|
|
71
|
-
options: [
|
|
72
|
-
{
|
|
73
|
-
display: 'application/json',
|
|
74
|
-
value: 'application/json'
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
display: 'application/x-www-form-urlencoded',
|
|
78
|
-
value: 'application/x-www-form-urlencoded'
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
display: 'text/plain',
|
|
82
|
-
value: 'text/plain'
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
type: 'select',
|
|
89
|
-
label: 'mode',
|
|
90
|
-
name: 'mode',
|
|
91
|
-
property: {
|
|
92
|
-
options: [
|
|
93
|
-
{
|
|
94
|
-
display: 'cors',
|
|
95
|
-
value: 'cors'
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
display: 'no-cors',
|
|
99
|
-
value: 'no-cors'
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
display: 'same-origin',
|
|
103
|
-
value: 'same-origin'
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
type: 'select',
|
|
110
|
-
label: 'credentials',
|
|
111
|
-
name: 'credentials',
|
|
112
|
-
property: {
|
|
113
|
-
options: [
|
|
114
|
-
{
|
|
115
|
-
display: 'same-origin',
|
|
116
|
-
value: 'same-origin'
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
display: 'include',
|
|
120
|
-
value: 'include'
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
display: 'omit',
|
|
124
|
-
value: 'omit'
|
|
125
|
-
}
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
type: 'select',
|
|
131
|
-
label: 'cache',
|
|
132
|
-
name: 'cache',
|
|
133
|
-
property: {
|
|
134
|
-
options: [
|
|
135
|
-
{
|
|
136
|
-
display: 'default',
|
|
137
|
-
value: 'default'
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
display: 'no-cache',
|
|
141
|
-
value: 'no-cache'
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
display: 'reload',
|
|
145
|
-
value: 'reload'
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
display: 'force-cache',
|
|
149
|
-
value: 'force-cache'
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
display: 'only-if-cached',
|
|
153
|
-
value: 'only-if-cached'
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
type: 'select',
|
|
160
|
-
label: 'redirect',
|
|
161
|
-
name: 'redirect',
|
|
162
|
-
property: {
|
|
163
|
-
options: [
|
|
164
|
-
{
|
|
165
|
-
display: 'follow',
|
|
166
|
-
value: 'follow'
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
display: 'manual',
|
|
170
|
-
value: 'manual'
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
display: 'error',
|
|
174
|
-
value: 'error'
|
|
175
|
-
}
|
|
176
|
-
]
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
type: 'select',
|
|
181
|
-
label: 'referrer-policy',
|
|
182
|
-
name: 'referrerPolicy',
|
|
183
|
-
property: {
|
|
184
|
-
options: [
|
|
185
|
-
{
|
|
186
|
-
display: 'no-referrer-when-downgrade',
|
|
187
|
-
value: 'no-referrer-when-downgrade'
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
display: 'no-referrer',
|
|
191
|
-
value: 'no-referrer'
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
display: 'origin',
|
|
195
|
-
value: 'origin'
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
display: 'origin-when-cross-origin',
|
|
199
|
-
value: 'origin-when-cross-origin'
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
display: 'same-origin',
|
|
203
|
-
value: 'same-origin'
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
display: 'strict-origin',
|
|
207
|
-
value: 'strict-origin'
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
display: 'strict-origin-when-cross-origin',
|
|
211
|
-
value: 'strict-origin-when-cross-origin'
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
display: 'unsafe-url',
|
|
215
|
-
value: 'unsafe-url'
|
|
216
|
-
}
|
|
217
|
-
]
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
type: 'key-values',
|
|
222
|
-
label: 'headers',
|
|
223
|
-
name: 'headers'
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
type: 'number',
|
|
227
|
-
label: 'period',
|
|
228
|
-
name: 'period',
|
|
229
|
-
placeholder: 'SECONDS'
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
type: 'checkbox',
|
|
233
|
-
label: 'fetch-on-load',
|
|
234
|
-
name: 'fetchOnLoad'
|
|
235
|
-
}
|
|
236
|
-
],
|
|
237
|
-
help: 'scene/component/restful'
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const REST_IMAGE =
|
|
241
|
-
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKIAAACWCAMAAABqx6OSAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAB1WlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOkNvbXByZXNzaW9uPjE8L3RpZmY6Q29tcHJlc3Npb24+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgICAgIDx0aWZmOlBob3RvbWV0cmljSW50ZXJwcmV0YXRpb24+MjwvdGlmZjpQaG90b21ldHJpY0ludGVycHJldGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KAtiABQAAASNQTFRFAAAA/4AA1VUrzE0zyEk3zkU7zEQzz0g40kQ10UE0z0U10UM2zkQ40UU40EU20UQ3z0Q20EQ3z0U30UM30EQ4z0U30EM30UQ3z0M20EM30EQ30EQ30EQ30EQ40EQ30EQ30EQ20EQ30EQ30EQ30EQ30EQ30EQ30EQ30EQ2zDIkzTcpzjoszjstzjwvzz4wzz8xz0Az0EI10EQ30Ec60Uo+0kxA009D1FNI1FZK1F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rQ6bppJxSZ82EDoMhhB92g1mJ/ZWXw1ogB8JyhPPqv3jCiQA0jcNORTvAkxc9axAjkoGTIInvcUmp6CKISRhT0hhHDg7GnGAVRDiUL6tFFshdQuivEIyyDEvhONz28FmHsyVAwpj+kJYjyilQvGGtJ3pyofApZ6UK7cXNVJ2HvjSCOQDQW0q4YQxQBDiPulWBswHezsc7Av7VeJzGKuPLZ6RX7gC1cjnRwGP2WFj5OryTEeLU/c+lc9MMDgvhMRdQ9vdI1SQU3zWbzjHRvMVaX/i4C9rI5oIeMAOFp8br68FC7LiXY929mpLt3H9fpjE5S9U31hfe4XgTS36IS9/cl4lm0tBKAxQ3Wmajc1YdIneq7YMHEDctOLli8c8ESqAsWkl2wHD98U6N4JFixqSEcFYdtavwyujXUzsfjUbO3hqLxeL5tdGtoxAZb+7F5Zu4G21nzsW18g422TZnsb1N2zd2m7Pa3KZMGtimpm70ZZSKoDgG+utnbCzVaGUObvdQt82ip0pBUM3vLvIZLrZSixrbM3XDwwAXHN1xwCGZqPmw/4ZijRC44kOWGY23Tzj8caP8Ry8Xxr5Hv2Eu4o+MldBcc93XBoWk3HD13wQF+2jxrQtL9GoQLXiZxwys5bnixyQWvh7nhJTs3vKrohhc+p+b2Jkm496nUB85/+dgNr3BLS2UTmmyFF6c+LeenE3BDUgY3pLawPkHIgQnJqJyfZsXiZDUmJexzfsofNyROsij91K7JSfqcn8RrygWp0HBFrpm2BhC0JqEc3mvdMGlVxKq0fGSscXpywyk3pIgkNenwRJuyl3R6ulKyXOH0pK9ydOHw1LmycALisaN3yL4ExIqFOzyNc3/N9EMy7IOAs5Jh/5M79D8U6UTFcE/VFgAAAABJRU5ErkJggg=='
|
|
242
|
-
|
|
243
|
-
const WARN_NO_URL = 'Valid URL property required'
|
|
244
|
-
|
|
245
|
-
export default class Restful extends DataSource(RectPath(Shape)) {
|
|
246
|
-
static _image: HTMLImageElement
|
|
247
|
-
|
|
248
|
-
static get image() {
|
|
249
|
-
if (!Restful._image) {
|
|
250
|
-
Restful._image = new Image()
|
|
251
|
-
Restful._image.src = REST_IMAGE
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return Restful._image
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private _repeatTimer!: number
|
|
258
|
-
private _isStarted = false
|
|
259
|
-
|
|
260
|
-
get url() {
|
|
261
|
-
return this.getState('url')
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
set url(url) {
|
|
265
|
-
this.setState('url', url)
|
|
266
|
-
this._initRestful()
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
get period() {
|
|
270
|
-
return Number(this.state.period) * 1000
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
set period(period) {
|
|
274
|
-
this.setState('period', Number(period))
|
|
275
|
-
this._initRestful()
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
get value() {
|
|
279
|
-
return this.state.value
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
set value(value) {
|
|
283
|
-
this.setState('value', value)
|
|
284
|
-
this._initRestful(true)
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
get withCredentials() {
|
|
288
|
-
return !!this.getState('withCredentials')
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
set withCredentials(withCredentials) {
|
|
292
|
-
this.setState('withCredentials', withCredentials)
|
|
293
|
-
this._initRestful()
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
get repeatTimer() {
|
|
297
|
-
return this._repeatTimer
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
set repeatTimer(repeatTimer) {
|
|
301
|
-
this._stopRepeater()
|
|
302
|
-
this._repeatTimer = repeatTimer
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
ready() {
|
|
306
|
-
this._initRestful(this.state.fetchOnLoad)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
_initRestful(force: boolean = false) {
|
|
310
|
-
if (!this.app.isViewMode) return
|
|
311
|
-
|
|
312
|
-
if (!this.url) {
|
|
313
|
-
warn(WARN_NO_URL)
|
|
314
|
-
return
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
this._stopRepeater()
|
|
318
|
-
if (this.period > 0) {
|
|
319
|
-
this._startRepeater()
|
|
320
|
-
} else {
|
|
321
|
-
force && this.fetch()
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
dispose() {
|
|
326
|
-
super.dispose()
|
|
327
|
-
this._stopRepeater()
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
_startRepeater() {
|
|
331
|
-
this._isStarted = true
|
|
332
|
-
|
|
333
|
-
var self = this
|
|
334
|
-
|
|
335
|
-
function _() {
|
|
336
|
-
if (!self._isStarted) {
|
|
337
|
-
return
|
|
338
|
-
}
|
|
339
|
-
self.fetch()
|
|
340
|
-
|
|
341
|
-
if (!self.period) {
|
|
342
|
-
self._stopRepeater()
|
|
343
|
-
return
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
self._repeatTimer = setTimeout(() => {
|
|
347
|
-
requestAnimationFrame(_)
|
|
348
|
-
}, self.period)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
requestAnimationFrame(_)
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
_stopRepeater() {
|
|
355
|
-
this._isStarted = false
|
|
356
|
-
if (this.repeatTimer) {
|
|
357
|
-
clearTimeout(this._repeatTimer)
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
async fetch() {
|
|
362
|
-
var {
|
|
363
|
-
url,
|
|
364
|
-
method = 'GET',
|
|
365
|
-
mode = 'cors',
|
|
366
|
-
cache = 'default',
|
|
367
|
-
credentials = 'same-origin',
|
|
368
|
-
redirect = 'follow',
|
|
369
|
-
referrerPolicy = 'no-referrer-when-downgrade',
|
|
370
|
-
contentType = 'application/json',
|
|
371
|
-
dataFormat = 'json',
|
|
372
|
-
headers = {},
|
|
373
|
-
value
|
|
374
|
-
} = this.state
|
|
375
|
-
|
|
376
|
-
if (dataFormat == 'jsonp') {
|
|
377
|
-
if (value && typeof value == 'string') {
|
|
378
|
-
url = value
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
jsonp(url, {}, (self, data) => {
|
|
382
|
-
if (this._isStarted && data) {
|
|
383
|
-
this.data = data
|
|
384
|
-
}
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
return
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
var options: any = {
|
|
391
|
-
method,
|
|
392
|
-
mode,
|
|
393
|
-
cache,
|
|
394
|
-
credentials,
|
|
395
|
-
headers: {
|
|
396
|
-
'Content-Type': contentType,
|
|
397
|
-
...headers
|
|
398
|
-
},
|
|
399
|
-
redirect,
|
|
400
|
-
referrerPolicy
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (method != 'GET' && method != 'HEAD') {
|
|
404
|
-
if (contentType == 'application/json') {
|
|
405
|
-
options.body = JSON.stringify(value)
|
|
406
|
-
} else {
|
|
407
|
-
options.body = value
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
if (value && typeof value == 'string') {
|
|
411
|
-
url = value
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const response = await fetch(url, options)
|
|
416
|
-
|
|
417
|
-
if (!this._isStarted) {
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (dataFormat === 'json') {
|
|
422
|
-
this.data = await response.json()
|
|
423
|
-
} else if (dataFormat === 'text') {
|
|
424
|
-
this.data = await response.text()
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
render(context: CanvasRenderingContext2D) {
|
|
429
|
-
var { left, top, width, height } = this.bounds
|
|
430
|
-
|
|
431
|
-
context.beginPath()
|
|
432
|
-
this.drawImage(context, Restful.image, left, top, width, height)
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
ondblclick(e: Event) {
|
|
436
|
-
if (!this.url) {
|
|
437
|
-
warn(WARN_NO_URL)
|
|
438
|
-
return
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
this.fetch()
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
get controls() {
|
|
445
|
-
return []
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
get nature() {
|
|
449
|
-
return NATURE
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
Component.register('restful', Restful)
|
package/test/basic-test.html
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
@license
|
|
3
|
-
Copyright © HatioLab Inc. All rights reserved.
|
|
4
|
-
-->
|
|
5
|
-
<!doctype html>
|
|
6
|
-
<html>
|
|
7
|
-
<head>
|
|
8
|
-
<meta charset="utf-8">
|
|
9
|
-
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
|
10
|
-
|
|
11
|
-
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
|
|
12
|
-
<script src="../../web-component-tester/browser.js"></script>
|
|
13
|
-
|
|
14
|
-
<!-- Step 1: import the element to test -->
|
|
15
|
-
<link rel="import" href="../things-scene-restful.html">
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
|
|
19
|
-
<!-- You can use the document as a place to set up your fixtures. -->
|
|
20
|
-
<test-fixture id="things-scene-restful-fixture">
|
|
21
|
-
<template>
|
|
22
|
-
<things-scene-restful>
|
|
23
|
-
<h2>things-scene-restful</h2>
|
|
24
|
-
</things-scene-restful>
|
|
25
|
-
</template>
|
|
26
|
-
</test-fixture>
|
|
27
|
-
|
|
28
|
-
<script>
|
|
29
|
-
suite('<things-scene-restful>', function() {
|
|
30
|
-
|
|
31
|
-
var myEl;
|
|
32
|
-
|
|
33
|
-
setup(function() {
|
|
34
|
-
myEl = fixture('things-scene-restful-fixture');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('defines the "author" property', function() {
|
|
38
|
-
assert.equal(myEl.author.name, 'Dimitri Glazkov');
|
|
39
|
-
assert.equal(myEl.author.image, 'http://addyosmani.com/blog/wp-content/uploads/2013/04/unicorn.jpg');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('says hello', function() {
|
|
43
|
-
assert.equal(myEl.sayHello(), 'things-scene-restful says, Hello World!');
|
|
44
|
-
|
|
45
|
-
var greetings = myEl.sayHello('greetings Earthlings');
|
|
46
|
-
assert.equal(greetings, 'things-scene-restful says, greetings Earthlings');
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('fires lasers', function(done) {
|
|
50
|
-
myEl.addEventListener('things-scene-restful-lasers', function(event) {
|
|
51
|
-
assert.equal(event.detail.sound, 'Pew pew!');
|
|
52
|
-
done();
|
|
53
|
-
});
|
|
54
|
-
myEl.fireLasers();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('distributed children', function() {
|
|
58
|
-
var els = myEl.getContentChildren();
|
|
59
|
-
assert.equal(els.length, 1, 'one distributed node');
|
|
60
|
-
assert.equal(els[0], myEl.querySelector('h2'), 'content distributed correctly');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
</script>
|
|
65
|
-
|
|
66
|
-
</body>
|
|
67
|
-
</html>
|
package/test/index.html
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
@license
|
|
3
|
-
Copyright © HatioLab Inc. All rights reserved.
|
|
4
|
-
-->
|
|
5
|
-
<!DOCTYPE html>
|
|
6
|
-
<html>
|
|
7
|
-
<head>
|
|
8
|
-
<meta charset="utf-8">
|
|
9
|
-
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
|
10
|
-
|
|
11
|
-
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
|
|
12
|
-
<script src="../../web-component-tester/browser.js"></script>
|
|
13
|
-
</head>
|
|
14
|
-
<body>
|
|
15
|
-
<script>
|
|
16
|
-
// Load and run all tests (.html, .js):
|
|
17
|
-
WCT.loadSuites([
|
|
18
|
-
'basic-test.html',
|
|
19
|
-
'basic-test.html?dom=shadow'
|
|
20
|
-
]);
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
</body>
|
|
24
|
-
</html>
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import './util'
|
|
6
|
-
|
|
7
|
-
import { expect } from 'chai'
|
|
8
|
-
|
|
9
|
-
import '../../bower_components/things-scene-core/things-scene-min'
|
|
10
|
-
import { Restful } from '../../src/index'
|
|
11
|
-
|
|
12
|
-
describe('Restful', function () {
|
|
13
|
-
|
|
14
|
-
var board;
|
|
15
|
-
|
|
16
|
-
beforeEach(function () {
|
|
17
|
-
board = scene.create({
|
|
18
|
-
model: {
|
|
19
|
-
components: [{
|
|
20
|
-
id: 'restful',
|
|
21
|
-
type: 'restful'
|
|
22
|
-
}]
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('component should be found by its id.', function () {
|
|
28
|
-
|
|
29
|
-
var component = board.findById('restful')
|
|
30
|
-
|
|
31
|
-
expect(!!component).not.to.equal(false);
|
|
32
|
-
});
|
|
33
|
-
});
|
package/test/unit/util.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var noop = () => {}
|
|
6
|
-
|
|
7
|
-
global.Canvas = require('canvas');
|
|
8
|
-
|
|
9
|
-
Canvas.prototype.setAttribute = noop;
|
|
10
|
-
Canvas.prototype.style = {};
|
|
11
|
-
|
|
12
|
-
global.Image = Canvas.Image;
|
|
13
|
-
global.screen = {
|
|
14
|
-
width: 1280,
|
|
15
|
-
height: 800
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
global.window = global;
|
|
19
|
-
|
|
20
|
-
global.addEventListener = noop;
|
|
21
|
-
global.location = {};
|
|
22
|
-
global.getComputedStyle = noop;
|
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2018",
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"noEmitOnError": true,
|
|
7
|
-
"lib": ["es2019", "dom"],
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": false,
|
|
10
|
-
"allowJs": true,
|
|
11
|
-
"allowSyntheticDefaultImports": true,
|
|
12
|
-
"experimentalDecorators": true,
|
|
13
|
-
"importHelpers": true,
|
|
14
|
-
"outDir": "dist",
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"inlineSources": true,
|
|
17
|
-
"rootDir": "src",
|
|
18
|
-
"declaration": true,
|
|
19
|
-
"incremental": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"types": []
|
|
22
|
-
},
|
|
23
|
-
"include": ["**/*.ts", "*.d.ts"]
|
|
24
|
-
}
|
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/tslib/tslib.d.ts","../../node_modules/@hatiolab/things-scene/things-scene.d.ts","./src/jsonp.ts","./src/restful.ts","./src/index.ts"],"fileInfos":[{"version":"44e584d4f6444f58791784f1d530875970993129442a847597db702a073ca68c","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7",{"version":"4af6b0c727b7a2896463d512fafd23634229adf69ac7c00e2ae15a09cb084fad","affectsGlobalScope":true},{"version":"6920e1448680767498a0b77c6a00a8e77d14d62c3da8967b171f1ddffa3c18e4","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"4a882ffbb4ed09d9b7734f784aebb1dfe488d63725c40759165c5d9c657ca029","26d1ec00a52200684283272eaed524de74adc033bdff6522f72e03c796a46ff8",{"version":"bbe91d2ee0412fd9d5aec1d602b94b1d43c9da4aa3e814767d9bb3fb6a0a0575","signature":"3d6a4f4ed57c588cf519752d79cc6ca2cc41ffc847cc82a739e8db63a8cd9391"},{"version":"f8da817b83a7994224b9f287b2e928493f28d7990bd844948166c864491fde16","signature":"ea82ab6e05e324663db5f56a288846db6374916b655abd3ec2fd2e05d6e98d55"},{"version":"2b3a3527a046942eff5d94fd51faa2fd386681d726148a602bd3cc9d9bc1a572","signature":"54ca01afdac7a1c6a39714582e7a71dbbe971b576dad2535d5a8f6612bc940ca"}],"root":[[39,41]],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":false,"experimentalDecorators":true,"importHelpers":true,"inlineSources":true,"module":99,"noEmitOnError":true,"outDir":"./dist","rootDir":"./src","skipLibCheck":true,"sourceMap":true,"strict":true,"target":5},"fileIdsList":[[37,40],[37,38],[37,38,39]],"referencedMap":[[41,1],[39,2],[40,3]]},"version":"5.5.2"}
|