@warp-drive/ember 0.0.0-alpha.6 → 0.0.0-alpha.61

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/addon/index.js DELETED
@@ -1,624 +0,0 @@
1
- import { tracked, cached } from '@glimmer/tracking';
2
- import { getPromiseResult, setPromiseResult } from '@ember-data/request';
3
- import { assert } from '@ember/debug';
4
- import { service } from '@ember/service';
5
- import Component from '@glimmer/component';
6
- import { macroCondition, moduleExists, importSync } from '@embroider/macros';
7
- import { precompileTemplate } from '@ember/template-compilation';
8
- import { setComponentTemplate } from '@ember/component';
9
-
10
- var __defProp = Object.defineProperty;
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
-
16
- // src/runtime.ts
17
- var runtime_exports = {};
18
- __export(runtime_exports, {
19
- c: () => decorateClass,
20
- f: () => decorateFieldV1,
21
- g: () => decorateFieldV2,
22
- i: () => initializeDeferredDecorator,
23
- m: () => decorateMethodV1,
24
- n: () => decorateMethodV2,
25
- p: () => decoratePOJO
26
- });
27
- var deferred = /* @__PURE__ */ new WeakMap();
28
- function deferDecorator(proto, prop, desc) {
29
- let map = deferred.get(proto);
30
- if (!map) {
31
- map = /* @__PURE__ */ new Map();
32
- deferred.set(proto, map);
33
- }
34
- map.set(prop, desc);
35
- }
36
- function findDeferredDecorator(target, prop) {
37
- let cursor = target.prototype;
38
- while (cursor) {
39
- let desc = deferred.get(cursor)?.get(prop);
40
- if (desc) {
41
- return desc;
42
- }
43
- cursor = cursor.prototype;
44
- }
45
- }
46
- function decorateFieldV1(target, prop, decorators, initializer) {
47
- return decorateFieldV2(target.prototype, prop, decorators, initializer);
48
- }
49
- function decorateFieldV2(prototype, prop, decorators, initializer) {
50
- let desc = {
51
- configurable: true,
52
- enumerable: true,
53
- writable: true,
54
- initializer: null
55
- };
56
- if (initializer) {
57
- desc.initializer = initializer;
58
- }
59
- for (let decorator of decorators) {
60
- desc = decorator(prototype, prop, desc) || desc;
61
- }
62
- if (desc.initializer === void 0) {
63
- Object.defineProperty(prototype, prop, desc);
64
- } else {
65
- deferDecorator(prototype, prop, desc);
66
- }
67
- }
68
- function decorateMethodV1({ prototype }, prop, decorators) {
69
- return decorateMethodV2(prototype, prop, decorators);
70
- }
71
- function decorateMethodV2(prototype, prop, decorators) {
72
- const origDesc = Object.getOwnPropertyDescriptor(prototype, prop);
73
- let desc = { ...origDesc };
74
- for (let decorator of decorators) {
75
- desc = decorator(prototype, prop, desc) || desc;
76
- }
77
- if (desc.initializer !== void 0) {
78
- desc.value = desc.initializer ? desc.initializer.call(prototype) : void 0;
79
- desc.initializer = void 0;
80
- }
81
- Object.defineProperty(prototype, prop, desc);
82
- }
83
- function initializeDeferredDecorator(target, prop) {
84
- let desc = findDeferredDecorator(target.constructor, prop);
85
- if (desc) {
86
- Object.defineProperty(target, prop, {
87
- enumerable: desc.enumerable,
88
- configurable: desc.configurable,
89
- writable: desc.writable,
90
- value: desc.initializer ? desc.initializer.call(target) : void 0
91
- });
92
- }
93
- }
94
- function decorateClass(target, decorators) {
95
- return decorators.reduce(
96
- (accum, decorator) => decorator(accum) || accum,
97
- target
98
- );
99
- }
100
- function decoratePOJO(pojo, decorated) {
101
- for (let [type, prop, decorators] of decorated) {
102
- if (type === "field") {
103
- decoratePojoField(pojo, prop, decorators);
104
- } else {
105
- decorateMethodV2(pojo, prop, decorators);
106
- }
107
- }
108
- return pojo;
109
- }
110
- function decoratePojoField(pojo, prop, decorators) {
111
- let desc = {
112
- configurable: true,
113
- enumerable: true,
114
- writable: true,
115
- initializer: () => Object.getOwnPropertyDescriptor(pojo, prop)?.value
116
- };
117
- for (let decorator of decorators) {
118
- desc = decorator(pojo, prop, desc) || desc;
119
- }
120
- if (desc.initializer) {
121
- desc.value = desc.initializer.call(pojo);
122
- delete desc.initializer;
123
- }
124
- Object.defineProperty(pojo, prop, desc);
125
- }
126
-
127
- const RequestCache = new WeakMap();
128
- function isAbortError(error) {
129
- return error instanceof DOMException && error.name === 'AbortError';
130
- }
131
- async function watchStream(stream, state) {
132
- const reader = stream.getReader();
133
- let bytesLoaded = 0;
134
- let shouldForward = state._stream !== null && state._stream.readable.locked;
135
- let isForwarding = shouldForward;
136
- let writer = state._stream?.writable.getWriter();
137
- const buffer = [];
138
- state._isPending = false;
139
- state._isStarted = true;
140
- state._startTime = performance.now();
141
-
142
- // eslint-disable-next-line no-constant-condition
143
- while (true) {
144
- const {
145
- value,
146
- done
147
- } = await reader.read();
148
- if (done) {
149
- break;
150
- }
151
- bytesLoaded += value.byteLength;
152
- state._bytesLoaded = bytesLoaded;
153
- state._lastPacketTime = performance.now();
154
- shouldForward = shouldForward || state._stream !== null && state._stream.readable.locked;
155
- if (shouldForward) {
156
- if (!isForwarding) {
157
- isForwarding = true;
158
- writer = state._stream.writable.getWriter();
159
- for (const item of buffer) {
160
- await writer.ready;
161
- await writer.write(item);
162
- }
163
- buffer.length = 0;
164
- }
165
- await writer.ready;
166
- await writer.write(value);
167
- } else {
168
- buffer.push(value);
169
- }
170
- }
171
-
172
- // if we are still forwarding, we need to close the writer
173
- if (isForwarding) {
174
- await writer.ready;
175
- await writer.close();
176
- } else if (state._stream) {
177
- // if we are not forwarding, we need to cancel the stream
178
- await state._stream.readable.cancel('The Stream Has Already Ended');
179
- state._stream = null;
180
- }
181
- const endTime = performance.now();
182
- state._endTime = endTime;
183
- state._isComplete = true;
184
- state._isStarted = false;
185
- }
186
- class RequestLoadingState {
187
- _stream = null;
188
- _future;
189
- _triggered = false;
190
- _trigger() {
191
- if (this._triggered) {
192
- return;
193
- }
194
- this._triggered = true;
195
- const future = this._future;
196
- const promise = future.getStream();
197
- if (promise.sizeHint) {
198
- this._sizeHint = promise.sizeHint;
199
- }
200
- this.promise = promise.then(stream => {
201
- if (!stream) {
202
- this._isPending = false;
203
- this._isComplete = true;
204
- return;
205
- }
206
- return watchStream(stream, this);
207
- }, error => {
208
- this._isPending = false;
209
- this._isStarted = false;
210
- if (isAbortError(error)) {
211
- this._isCancelled = true;
212
- this._isComplete = true;
213
- }
214
- this._isErrored = true;
215
- this._error = error;
216
- });
217
- }
218
- promise = null;
219
- static {
220
- decorateFieldV2(this.prototype, "_sizeHint", [tracked], function () {
221
- return 0;
222
- });
223
- }
224
- #_sizeHint = (initializeDeferredDecorator(this, "_sizeHint"), void 0);
225
- static {
226
- decorateFieldV2(this.prototype, "_bytesLoaded", [tracked], function () {
227
- return 0;
228
- });
229
- }
230
- #_bytesLoaded = (initializeDeferredDecorator(this, "_bytesLoaded"), void 0);
231
- static {
232
- decorateFieldV2(this.prototype, "_startTime", [tracked], function () {
233
- return 0;
234
- });
235
- }
236
- #_startTime = (initializeDeferredDecorator(this, "_startTime"), void 0);
237
- static {
238
- decorateFieldV2(this.prototype, "_endTime", [tracked], function () {
239
- return 0;
240
- });
241
- }
242
- #_endTime = (initializeDeferredDecorator(this, "_endTime"), void 0);
243
- static {
244
- decorateFieldV2(this.prototype, "_lastPacketTime", [tracked], function () {
245
- return 0;
246
- });
247
- }
248
- #_lastPacketTime = (initializeDeferredDecorator(this, "_lastPacketTime"), void 0);
249
- static {
250
- decorateFieldV2(this.prototype, "_isPending", [tracked], function () {
251
- return true;
252
- });
253
- }
254
- #_isPending = (initializeDeferredDecorator(this, "_isPending"), void 0);
255
- static {
256
- decorateFieldV2(this.prototype, "_isStarted", [tracked], function () {
257
- return false;
258
- });
259
- }
260
- #_isStarted = (initializeDeferredDecorator(this, "_isStarted"), void 0);
261
- static {
262
- decorateFieldV2(this.prototype, "_isComplete", [tracked], function () {
263
- return false;
264
- });
265
- }
266
- #_isComplete = (initializeDeferredDecorator(this, "_isComplete"), void 0);
267
- static {
268
- decorateFieldV2(this.prototype, "_isCancelled", [tracked], function () {
269
- return false;
270
- });
271
- }
272
- #_isCancelled = (initializeDeferredDecorator(this, "_isCancelled"), void 0);
273
- static {
274
- decorateFieldV2(this.prototype, "_isErrored", [tracked], function () {
275
- return false;
276
- });
277
- }
278
- #_isErrored = (initializeDeferredDecorator(this, "_isErrored"), void 0);
279
- static {
280
- decorateFieldV2(this.prototype, "_error", [tracked], function () {
281
- return null;
282
- });
283
- }
284
- #_error = (initializeDeferredDecorator(this, "_error"), void 0);
285
- get isPending() {
286
- this._trigger();
287
- return this._isPending;
288
- }
289
- get sizeHint() {
290
- this._trigger();
291
- return this._sizeHint;
292
- }
293
- get stream() {
294
- this._trigger();
295
- if (!this._stream) {
296
- if (this._isComplete || this._isCancelled || this._isErrored) {
297
- return null;
298
- }
299
- this._stream = new TransformStream();
300
- }
301
- return this._stream.readable;
302
- }
303
- get isStarted() {
304
- this._trigger();
305
- return this._isStarted;
306
- }
307
- get bytesLoaded() {
308
- this._trigger();
309
- return this._bytesLoaded;
310
- }
311
- get startTime() {
312
- this._trigger();
313
- return this._startTime;
314
- }
315
- get endTime() {
316
- this._trigger();
317
- return this._endTime;
318
- }
319
- get lastPacketTime() {
320
- this._trigger();
321
- return this._lastPacketTime;
322
- }
323
- get isComplete() {
324
- this._trigger();
325
- return this._isComplete;
326
- }
327
- get isCancelled() {
328
- this._trigger();
329
- return this._isCancelled;
330
- }
331
- get isErrored() {
332
- this._trigger();
333
- return this._isErrored;
334
- }
335
- get error() {
336
- this._trigger();
337
- return this._error;
338
- }
339
- get elapsedTime() {
340
- return (this.endTime || this.lastPacketTime) - this.startTime;
341
- }
342
- get completeRatio() {
343
- return this.sizeHint ? this.bytesLoaded / this.sizeHint : 0;
344
- }
345
- get remainingRatio() {
346
- return 1 - this.completeRatio;
347
- }
348
- get duration() {
349
- return this.endTime - this.startTime;
350
- }
351
- get speed() {
352
- // bytes per second
353
- return this.bytesLoaded / (this.elapsedTime / 1000);
354
- }
355
- constructor(future) {
356
- this._future = future;
357
- }
358
- abort() {
359
- this._future.abort();
360
- }
361
- }
362
- class RequestState {
363
- #request;
364
- #loadingState = null;
365
- static {
366
- decorateFieldV2(this.prototype, "result", [tracked], function () {
367
- return null;
368
- });
369
- }
370
- #result = (initializeDeferredDecorator(this, "result"), void 0);
371
- static {
372
- decorateFieldV2(this.prototype, "error", [tracked], function () {
373
- return null;
374
- });
375
- }
376
- #error = (initializeDeferredDecorator(this, "error"), void 0);
377
- static {
378
- decorateFieldV2(this.prototype, "isLoading", [tracked], function () {
379
- return true;
380
- });
381
- }
382
- #isLoading = (initializeDeferredDecorator(this, "isLoading"), void 0);
383
- static {
384
- decorateFieldV2(this.prototype, "isSuccess", [tracked], function () {
385
- return false;
386
- });
387
- }
388
- #isSuccess = (initializeDeferredDecorator(this, "isSuccess"), void 0);
389
- static {
390
- decorateFieldV2(this.prototype, "isError", [tracked], function () {
391
- return false;
392
- });
393
- }
394
- #isError = (initializeDeferredDecorator(this, "isError"), void 0);
395
- static {
396
- decorateFieldV2(this.prototype, "request", [tracked], function () {
397
- return null;
398
- });
399
- }
400
- #request_ = (initializeDeferredDecorator(this, "request"), void 0);
401
- static {
402
- decorateFieldV2(this.prototype, "response", [tracked], function () {
403
- return null;
404
- });
405
- }
406
- #response = (initializeDeferredDecorator(this, "response"), void 0);
407
- get isCancelled() {
408
- return this.isError && isAbortError(this.error);
409
- }
410
- get loadingState() {
411
- if (!this.#loadingState) {
412
- this.#loadingState = new RequestLoadingState(this.#request);
413
- }
414
- return this.#loadingState;
415
- }
416
- constructor(future) {
417
- this.#request = future;
418
- const state = getPromiseResult(future);
419
- if (state) {
420
- this.request = state.result.request;
421
- this.response = state.result.response;
422
- this.isLoading = false;
423
- if (state.isError) {
424
- this.error = state.result;
425
- this.isError = true;
426
- } else {
427
- this.result = state.result.content;
428
- this.isSuccess = true;
429
- }
430
- } else {
431
- void future.then(result => {
432
- setPromiseResult(future, {
433
- isError: false,
434
- result
435
- });
436
- this.result = result.content;
437
- this.isSuccess = true;
438
- this.isLoading = false;
439
- this.request = result.request;
440
- this.response = result.response;
441
- }, error => {
442
- setPromiseResult(future, {
443
- isError: true,
444
- result: error
445
- });
446
- this.error = error;
447
- this.isError = true;
448
- this.isLoading = false;
449
- this.request = error.request;
450
- this.response = error.response;
451
- });
452
- }
453
- }
454
- }
455
- function getRequestState(future) {
456
- let state = RequestCache.get(future);
457
- if (!state) {
458
- state = new RequestState(future);
459
- RequestCache.set(future, state);
460
- }
461
- return state;
462
- }
463
-
464
- const PromiseCache = new WeakMap();
465
- class PromiseState {
466
- static {
467
- decorateFieldV2(this.prototype, "result", [tracked], function () {
468
- return null;
469
- });
470
- }
471
- #result = (initializeDeferredDecorator(this, "result"), void 0);
472
- static {
473
- decorateFieldV2(this.prototype, "error", [tracked], function () {
474
- return null;
475
- });
476
- }
477
- #error = (initializeDeferredDecorator(this, "error"), void 0);
478
- static {
479
- decorateFieldV2(this.prototype, "isPending", [tracked], function () {
480
- return true;
481
- });
482
- }
483
- #isPending = (initializeDeferredDecorator(this, "isPending"), void 0);
484
- static {
485
- decorateFieldV2(this.prototype, "isSuccess", [tracked], function () {
486
- return false;
487
- });
488
- }
489
- #isSuccess = (initializeDeferredDecorator(this, "isSuccess"), void 0);
490
- static {
491
- decorateFieldV2(this.prototype, "isError", [tracked], function () {
492
- return false;
493
- });
494
- }
495
- #isError = (initializeDeferredDecorator(this, "isError"), void 0);
496
- constructor(promise) {
497
- const state = getPromiseResult(promise);
498
- if (state) {
499
- if (state.isError) {
500
- this.error = state.result;
501
- this.isError = true;
502
- this.isPending = false;
503
- } else {
504
- this.result = state.result;
505
- this.isSuccess = true;
506
- this.isPending = false;
507
- }
508
- } else {
509
- void promise.then(result => {
510
- setPromiseResult(promise, {
511
- isError: false,
512
- result
513
- });
514
- this.result = result;
515
- this.isSuccess = true;
516
- this.isPending = false;
517
- }, error => {
518
- setPromiseResult(promise, {
519
- isError: true,
520
- result: error
521
- });
522
- this.error = error;
523
- this.isError = true;
524
- this.isPending = false;
525
- });
526
- }
527
- }
528
- }
529
- function getPromiseState(promise) {
530
- let state = PromiseCache.get(promise);
531
- if (!state) {
532
- state = new PromiseState(promise);
533
- PromiseCache.set(promise, state);
534
- }
535
- return state;
536
- }
537
-
538
- function notNull(x1) {
539
- assert('Expected a non-null value, but got null', x1 !== null);
540
- return x1;
541
- }
542
- const and = (x1, y1) => Boolean(x1 && y1);
543
- class Throw extends Component {
544
- constructor(owner1, args1) {
545
- super(owner1, args1);
546
- throw this.args.error;
547
- }
548
- static {
549
- setComponentTemplate(precompileTemplate("", {
550
- strictMode: true
551
- }), this);
552
- }
553
- }
554
- class Await extends Component {
555
- get state() {
556
- return getPromiseState(this.args.promise);
557
- }
558
- static {
559
- setComponentTemplate(precompileTemplate("\n {{#if this.state.isPending}}\n {{yield to=\"pending\"}}\n {{else if (and this.state.isError (has-block \"error\"))}}\n {{yield (notNull this.state.error) to=\"error\"}}\n {{else if this.state.isSuccess}}\n {{yield (notNull this.state.result) to=\"success\"}}\n {{else}}\n <Throw @error={{(notNull this.state.error)}} />\n {{/if}}\n ", {
560
- scope: () => ({
561
- and,
562
- notNull,
563
- Throw
564
- }),
565
- strictMode: true
566
- }), this);
567
- }
568
- }
569
-
570
- let provide = service;
571
- if (macroCondition(moduleExists('ember-provide-consume-context'))) {
572
- const {
573
- consume
574
- } = importSync('ember-provide-consume-context');
575
- provide = consume;
576
- }
577
- class Request extends Component {
578
- static {
579
- decorateFieldV2(this.prototype, "_store", [provide('store')]);
580
- }
581
- #_store = (initializeDeferredDecorator(this, "_store"), void 0);
582
- /**
583
- * @internal
584
- */
585
- retry = () => {};
586
- reload = () => {};
587
- refresh = () => {};
588
- get request() {
589
- const {
590
- request: request1,
591
- query: query1
592
- } = this.args;
593
- assert(`Cannot use both @request and @query args with the <Request> component`, !request1 || !query1);
594
- if (request1) {
595
- return request1;
596
- }
597
- assert(`You must provide either @request or an @query arg with the <Request> component`, query1);
598
- return this.store.request(query1);
599
- }
600
- static {
601
- decorateMethodV2(this.prototype, "request", [cached]);
602
- }
603
- get store() {
604
- const store1 = this.args.store || this._store;
605
- assert(moduleExists('ember-provide-consume-context') ? `No store was provided to the <Request> component. Either provide a store via the @store arg or via the context API provided by ember-provide-consume-context.` : `No store was provided to the <Request> component. Either provide a store via the @store arg or by registering a store service.`, store1);
606
- return store1;
607
- }
608
- get reqState() {
609
- return getRequestState(this.request);
610
- }
611
- static {
612
- setComponentTemplate(precompileTemplate("\n {{#if this.reqState.isLoading}}\n {{yield this.reqState.loadingState to=\"loading\"}}\n {{else if (and this.reqState.isCancelled (has-block \"cancelled\"))}}\n {{yield (notNull this.reqState.error) to=\"cancelled\"}}\n {{else if (and this.reqState.isError (has-block \"error\"))}}\n {{yield (notNull this.reqState.error) to=\"error\"}}\n {{else if this.reqState.isSuccess}}\n {{yield (notNull this.reqState.result) to=\"content\"}}\n {{else}}\n <Throw @error={{(notNull this.reqState.error)}} />\n {{/if}}\n ", {
613
- scope: () => ({
614
- and,
615
- notNull,
616
- Throw
617
- }),
618
- strictMode: true
619
- }), this);
620
- }
621
- }
622
-
623
- export { Await, Request, Throw, getPromiseState, getRequestState };
624
- //# sourceMappingURL=index.js.map