@warp-drive-mirror/ember 5.5.0-alpha.18 → 5.5.0-alpha.20

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.
@@ -1,5 +1,3 @@
1
- /// <reference path="./-private/request-state.d.ts" />
2
- /// <reference path="./-private/promise-state.d.ts" />
3
1
  /// <reference path="./-private/await.d.ts" />
4
2
  /// <reference path="./-private/request.d.ts" />
5
3
  declare module '@warp-drive-mirror/ember' {
@@ -49,9 +47,181 @@ declare module '@warp-drive-mirror/ember' {
49
47
  * @module @warp-drive-mirror/ember
50
48
  * @main @warp-drive-mirror/ember
51
49
  */
52
- export { getRequestState } from '@warp-drive-mirror/ember/-private/request-state';
53
- export { getPromiseState } from '@warp-drive-mirror/ember/-private/promise-state';
54
50
  export { Request } from './-private/request';
55
51
  export { Await, Throw } from './-private/await';
52
+ /**
53
+ * PromiseState provides a reactive wrapper for a promise which allows you write declarative
54
+ * code around a promise's control flow. It is useful in both Template and JavaScript contexts,
55
+ * allowing you to quickly derive behaviors and data from pending, error and success states.
56
+ *
57
+ * ```ts
58
+ * interface PromiseState<T = unknown, E = unknown> {
59
+ * isPending: boolean;
60
+ * isSuccess: boolean;
61
+ * isError: boolean;
62
+ * result: T | null;
63
+ * error: E | null;
64
+ * }
65
+ * ```
66
+ *
67
+ * To get the state of a promise, use `getPromiseState`.
68
+ *
69
+ * @class PromiseState
70
+ * @public
71
+ */
72
+ /**
73
+ * Returns a reactive state-machine for the provided promise or awaitable.
74
+ *
75
+ * Repeat calls to `getPromiseState` with the same promise will return the same state object
76
+ * making is safe and easy to use in templates and JavaScript code to produce reactive
77
+ * behaviors around promises.
78
+ *
79
+ * `getPromiseState` can be used in both JavaScript and Template contexts.
80
+ *
81
+ * ```ts
82
+ * import { getPromiseState } from '@warp-drive-mirror/ember';
83
+ *
84
+ * const state = getPromiseState(promise);
85
+ * ```
86
+ *
87
+ * For instance, we could write a getter on a component that updates whenever
88
+ * the promise state advances or the promise changes, by combining the function
89
+ * with the use of `@cached`
90
+ *
91
+ * ```ts
92
+ * class Component {
93
+ * @cached
94
+ * get title() {
95
+ * const state = getPromiseState(this.args.request);
96
+ * if (state.isPending) {
97
+ * return 'loading...';
98
+ * }
99
+ * if (state.isError) { return null; }
100
+ * return state.result.title;
101
+ * }
102
+ * }
103
+ * ```
104
+ *
105
+ * Or in a template as a helper:
106
+ *
107
+ * ```gjs
108
+ * import { getPromiseState } from '@warp-drive-mirror/ember';
109
+ *
110
+ * <template>
111
+ * {{#let (getPromiseState @request) as |state|}}
112
+ * {{#if state.isPending}} <Spinner />
113
+ * {{else if state.isError}} <ErrorForm @error={{state.error}} />
114
+ * {{else}}
115
+ * <h1>{{state.result.title}}</h1>
116
+ * {{/if}}
117
+ * {{/let}}
118
+ * </template>
119
+ * ```
120
+ *
121
+ * If looking to use in a template, consider also the `<Await />` component.
122
+ *
123
+ * @method getPromiseState
124
+ * @for @warp-drive-mirror/ember
125
+ * @static
126
+ * @public
127
+ * @param {Promise<T> | Awaitable<T, E>} promise
128
+ * @return {PromiseState<T, E>}
129
+ */
130
+ export { getPromiseState } from '@ember-data-mirror/store/-private';
131
+ /**
132
+ * Lazily consumes the stream of a request, providing a number of
133
+ * reactive properties that can be used to build UIs that respond
134
+ * to the progress of a request.
135
+ *
136
+ * @class RequestLoadingState
137
+ * @public
138
+ */
139
+ /**
140
+ * RequestState extends the concept of PromiseState to provide a reactive
141
+ * wrapper for a request `Future` which allows you write declarative code
142
+ * around a Future's control flow.
143
+ *
144
+ * It is useful in both Template and JavaScript contexts, allowing you
145
+ * to quickly derive behaviors and data from pending, error and success
146
+ * states.
147
+ *
148
+ * The key difference between a Promise and a Future is that Futures provide
149
+ * access to a stream of their content, the identity of the request (if any)
150
+ * as well as the ability to attempt to abort the request.
151
+ *
152
+ * ```ts
153
+ * interface Future<T> extends Promise<T>> {
154
+ * getStream(): Promise<ReadableStream>;
155
+ * abort(): void;
156
+ * lid: StableDocumentIdentifier | null;
157
+ * }
158
+ * ```
159
+ *
160
+ * These additional APIs allow us to craft even richer state experiences.
161
+ *
162
+ * To get the state of a request, use `getRequestState`.
163
+ *
164
+ * @class RequestState
165
+ * @public
166
+ */
167
+ /**
168
+ *
169
+ *
170
+ * `getRequestState` can be used in both JavaScript and Template contexts.
171
+ *
172
+ * ```ts
173
+ * import { getRequestState } from '@warp-drive-mirror/ember';
174
+ *
175
+ * const state = getRequestState(future);
176
+ * ```
177
+ *
178
+ * For instance, we could write a getter on a component that updates whenever
179
+ * the request state advances or the future changes, by combining the function
180
+ * with the use of `@cached`
181
+ *
182
+ * ```ts
183
+ * class Component {
184
+ * @cached
185
+ * get title() {
186
+ * const state = getRequestState(this.args.request);
187
+ * if (state.isPending) {
188
+ * return 'loading...';
189
+ * }
190
+ * if (state.isError) { return null; }
191
+ * return state.result.title;
192
+ * }
193
+ * }
194
+ * ```
195
+ *
196
+ * Or in a template as a helper:
197
+ *
198
+ * ```gjs
199
+ * import { getRequestState } from '@warp-drive-mirror/ember';
200
+ *
201
+ * <template>
202
+ * {{#let (getRequestState @request) as |state|}}
203
+ * {{#if state.isPending}}
204
+ * <Spinner />
205
+ * {{else if state.isError}}
206
+ * <ErrorForm @error={{state.error}} />
207
+ * {{else}}
208
+ * <h1>{{state.result.title}}</h1>
209
+ * {{/if}}
210
+ * {{/let}}
211
+ * </template>
212
+ * ```
213
+ *
214
+ * If looking to use in a template, consider also the `<Request />` component
215
+ * which offers a numbe of additional capabilities for requests *beyond* what
216
+ * `RequestState` provides.
217
+ *
218
+ * @method getRequestState
219
+ * @for @warp-drive-mirror/ember
220
+ * @static
221
+ * @public
222
+ * @param future
223
+ * @return {RequestState}
224
+ */
225
+ export { getRequestState, type RequestLoadingState } from '@ember-data-mirror/store/-private';
56
226
  }
57
227
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,EAAE,eAAe,EAAE,KAAK,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -1,91 +0,0 @@
1
- declare module '@warp-drive-mirror/ember/-private/promise-state' {
2
- import type { Awaitable } from '@ember-data-mirror/request';
3
- /**
4
- * PromiseState provides a reactive wrapper for a promise which allows you write declarative
5
- * code around a promise's control flow. It is useful in both Template and JavaScript contexts,
6
- * allowing you to quickly derive behaviors and data from pending, error and success states.
7
- *
8
- * ```ts
9
- * interface PromiseState<T = unknown, E = unknown> {
10
- * isPending: boolean;
11
- * isSuccess: boolean;
12
- * isError: boolean;
13
- * result: T | null;
14
- * error: E | null;
15
- * }
16
- * ```
17
- *
18
- * To get the state of a promise, use `getPromiseState`.
19
- *
20
- * @class PromiseState
21
- * @public
22
- */
23
- export class PromiseState<T = unknown, E = unknown> {
24
- result: T | null;
25
- error: E | null;
26
- isPending: boolean;
27
- isSuccess: boolean;
28
- isError: boolean;
29
- constructor(promise: Promise<T> | Awaitable<T, E>);
30
- }
31
- /**
32
- * Returns a reactive state-machine for the provided promise or awaitable.
33
- *
34
- * Repeat calls to `getPromiseState` with the same promise will return the same state object
35
- * making is safe and easy to use in templates and JavaScript code to produce reactive
36
- * behaviors around promises.
37
- *
38
- * `getPromiseState` can be used in both JavaScript and Template contexts.
39
- *
40
- * ```ts
41
- * import { getPromiseState } from '@warp-drive-mirror/ember';
42
- *
43
- * const state = getPromiseState(promise);
44
- * ```
45
- *
46
- * For instance, we could write a getter on a component that updates whenever
47
- * the promise state advances or the promise changes, by combining the function
48
- * with the use of `@cached`
49
- *
50
- * ```ts
51
- * class Component {
52
- * @cached
53
- * get title() {
54
- * const state = getPromiseState(this.args.request);
55
- * if (state.isPending) {
56
- * return 'loading...';
57
- * }
58
- * if (state.isError) { return null; }
59
- * return state.result.title;
60
- * }
61
- * }
62
- * ```
63
- *
64
- * Or in a template as a helper:
65
- *
66
- * ```gjs
67
- * import { getPromiseState } from '@warp-drive-mirror/ember';
68
- *
69
- * <template>
70
- * {{#let (getPromiseState @request) as |state|}}
71
- * {{#if state.isPending}} <Spinner />
72
- * {{else if state.isError}} <ErrorForm @error={{state.error}} />
73
- * {{else}}
74
- * <h1>{{state.result.title}}</h1>
75
- * {{/if}}
76
- * {{/let}}
77
- * </template>
78
- * ```
79
- *
80
- * If looking to use in a template, consider also the `<Await />` component.
81
- *
82
- * @method getPromiseState
83
- * @for @warp-drive-mirror/ember
84
- * @static
85
- * @public
86
- * @param {Promise<T> | Awaitable<T, E>} promise
87
- * @return {PromiseState<T, E>}
88
- */
89
- export function getPromiseState<T = unknown, E = unknown>(promise: Promise<T> | Awaitable<T, E>): PromiseState<T, E>;
90
- }
91
- //# sourceMappingURL=promise-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"promise-state.d.ts","sourceRoot":"","sources":["../../src/-private/promise-state.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAKrD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO;IACvC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAQ;IACxB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAQ;IACvB,SAAS,UAAQ;IACjB,SAAS,UAAS;IAClB,OAAO,UAAS;gBAEb,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;CA8BlD;AAaD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAUnH"}
@@ -1,149 +0,0 @@
1
- declare module '@warp-drive-mirror/ember/-private/request-state' {
2
- import type { Future, ImmutableRequestInfo, ResponseInfo, StructuredErrorDocument } from '@ember-data-mirror/request';
3
- /**
4
- * Lazily consumes the stream of a request, providing a number of
5
- * reactive properties that can be used to build UIs that respond
6
- * to the progress of a request.
7
- *
8
- * @class RequestLoadingState
9
- * @public
10
- */
11
- export class RequestLoadingState {
12
- _stream: TransformStream | null;
13
- _future: Future<unknown>;
14
- _triggered: boolean;
15
- _trigger(): void;
16
- promise: Promise<void> | null;
17
- _sizeHint: number;
18
- _bytesLoaded: number;
19
- _startTime: number;
20
- _endTime: number;
21
- _lastPacketTime: number;
22
- _isPending: boolean;
23
- _isStarted: boolean;
24
- _isComplete: boolean;
25
- _isCancelled: boolean;
26
- _isErrored: boolean;
27
- _error: Error | null;
28
- get isPending(): boolean;
29
- get sizeHint(): number;
30
- get stream(): ReadableStream | null;
31
- get isStarted(): boolean;
32
- get bytesLoaded(): number;
33
- get startTime(): number;
34
- get endTime(): number;
35
- get lastPacketTime(): number;
36
- get isComplete(): boolean;
37
- get isCancelled(): boolean;
38
- get isErrored(): boolean;
39
- get error(): Error | null;
40
- get elapsedTime(): number;
41
- get completedRatio(): number;
42
- get remainingRatio(): number;
43
- get duration(): number;
44
- get speed(): number;
45
- constructor(future: Future<unknown>);
46
- abort: () => void;
47
- }
48
- /**
49
- * RequestState extends the concept of PromiseState to provide a reactive
50
- * wrapper for a request `Future` which allows you write declarative code
51
- * around a Future's control flow.
52
- *
53
- * It is useful in both Template and JavaScript contexts, allowing you
54
- * to quickly derive behaviors and data from pending, error and success
55
- * states.
56
- *
57
- * The key difference between a Promise and a Future is that Futures provide
58
- * access to a stream of their content, the identity of the request (if any)
59
- * as well as the ability to attempt to abort the request.
60
- *
61
- * ```ts
62
- * interface Future<T> extends Promise<T>> {
63
- * getStream(): Promise<ReadableStream>;
64
- * abort(): void;
65
- * lid: StableDocumentIdentifier | null;
66
- * }
67
- * ```
68
- *
69
- * These additional APIs allow us to craft even richer state experiences.
70
- *
71
- * To get the state of a request, use `getRequestState`.
72
- *
73
- * @class RequestState
74
- * @public
75
- */
76
- export class RequestState<T = unknown, RT = unknown> {
77
- #private;
78
- result: RT | null;
79
- error: StructuredErrorDocument | null;
80
- isLoading: boolean;
81
- isSuccess: boolean;
82
- isError: boolean;
83
- request: ImmutableRequestInfo<T, RT> | null;
84
- response: Response | ResponseInfo | null;
85
- get isCancelled(): boolean;
86
- get loadingState(): RequestLoadingState;
87
- constructor(future: Future<RT>);
88
- }
89
- /**
90
- *
91
- *
92
- * `getRequestState` can be used in both JavaScript and Template contexts.
93
- *
94
- * ```ts
95
- * import { getRequestState } from '@warp-drive-mirror/ember';
96
- *
97
- * const state = getRequestState(future);
98
- * ```
99
- *
100
- * For instance, we could write a getter on a component that updates whenever
101
- * the request state advances or the future changes, by combining the function
102
- * with the use of `@cached`
103
- *
104
- * ```ts
105
- * class Component {
106
- * @cached
107
- * get title() {
108
- * const state = getRequestState(this.args.request);
109
- * if (state.isPending) {
110
- * return 'loading...';
111
- * }
112
- * if (state.isError) { return null; }
113
- * return state.result.title;
114
- * }
115
- * }
116
- * ```
117
- *
118
- * Or in a template as a helper:
119
- *
120
- * ```gjs
121
- * import { getRequestState } from '@warp-drive-mirror/ember';
122
- *
123
- * <template>
124
- * {{#let (getRequestState @request) as |state|}}
125
- * {{#if state.isPending}}
126
- * <Spinner />
127
- * {{else if state.isError}}
128
- * <ErrorForm @error={{state.error}} />
129
- * {{else}}
130
- * <h1>{{state.result.title}}</h1>
131
- * {{/if}}
132
- * {{/let}}
133
- * </template>
134
- * ```
135
- *
136
- * If looking to use in a template, consider also the `<Request />` component
137
- * which offers a numbe of additional capabilities for requests *beyond* what
138
- * `RequestState` provides.
139
- *
140
- * @method getRequestState
141
- * @for @warp-drive-mirror/ember
142
- * @static
143
- * @public
144
- * @param future
145
- * @return {RequestState}
146
- */
147
- export function getRequestState<RT, T>(future: Future<RT>): RequestState<T, RT>;
148
- }
149
- //# sourceMappingURL=request-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../../src/-private/request-state.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,YAAY,EAEZ,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAiE7B;;;;;;;GAOG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,EAAE,eAAe,GAAG,IAAI,CAAQ;IACvC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,UAAU,UAAS;IACnB,QAAQ;IAgCR,OAAO,EAAE,OAAO,CAA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