@typed/async-data 0.7.1 → 0.8.0

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.
@@ -3,23 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.asyncDataFromSelf = exports.asyncDataFromJson = exports.asyncData = exports.Progress = void 0;
6
+ exports.asyncDataFromJson = exports.Progress = exports.AsyncDataFromSelf = exports.AsyncData = void 0;
7
7
  var Arbitrary = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Arbitrary"));
8
8
  var AST = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/AST"));
9
9
  var Eq = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Equivalence"));
10
- var Parser = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Parser"));
11
10
  var ParseResult = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/ParseResult"));
12
11
  var Pretty = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Pretty"));
13
12
  var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema"));
14
- var AsyncData = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@typed/async-data/AsyncData"));
15
- var _effect = /*#__PURE__*/require("effect");
16
13
  var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Cause"));
14
+ var Data = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Data"));
17
15
  var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
16
+ var Equal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Equal"));
17
+ var FiberId = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/FiberId"));
18
18
  var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option"));
19
19
  var _Predicate = /*#__PURE__*/require("effect/Predicate");
20
+ var _AsyncData = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./AsyncData.js"));
20
21
  var P = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Progress.js"));
21
22
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
22
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
24
  /**
24
25
  * @since 1.0.0
25
26
  */
@@ -38,13 +39,13 @@ const SUCCESS_PRETTY = print => success => Option.match(success.refreshing, {
38
39
  onSome: () => `AsyncData.Success(timestamp=${success.timestamp}, refreshing=true, value=${print(success.value)})`
39
40
  });
40
41
  const OPTIMISTIC_PRETTY = (printValue, printError) => optimistic => `AsyncData.Optimistic(timestamp=${optimistic.timestamp}, value=${printValue(optimistic.value)}, previous=${asyncDataPretty(printValue, printError)(optimistic.previous)})`;
41
- const ProgressSchemaJson = /*#__PURE__*/Schema.struct({
42
- loaded: Schema.bigint,
43
- total: /*#__PURE__*/Schema.optional(Schema.bigint)
42
+ const ProgressSchemaJson = /*#__PURE__*/Schema.Struct({
43
+ loaded: Schema.BigInt,
44
+ total: /*#__PURE__*/Schema.optional(Schema.BigInt)
44
45
  });
45
- const ProgressSchema = /*#__PURE__*/Schema.data( /*#__PURE__*/Schema.struct({
46
- loaded: Schema.bigintFromSelf,
47
- total: /*#__PURE__*/Schema.optionFromSelf(Schema.bigintFromSelf)
46
+ const ProgressSchema = /*#__PURE__*/Schema.Data( /*#__PURE__*/Schema.Struct({
47
+ loaded: Schema.BigIntFromSelf,
48
+ total: /*#__PURE__*/Schema.OptionFromSelf(Schema.BigIntFromSelf)
48
49
  }));
49
50
  const progressArbitrary = fc => fc.bigInt().chain(loaded => fc.option(fc.bigInt({
50
51
  min: loaded
@@ -52,20 +53,23 @@ const progressArbitrary = fc => fc.bigInt().chain(loaded => fc.option(fc.bigInt(
52
53
  /**
53
54
  * @since 1.0.0
54
55
  */
55
- const Progress = exports.Progress = /*#__PURE__*/ProgressSchemaJson.pipe( /*#__PURE__*/Schema.transform(ProgressSchema, json => P.make(json.loaded, json.total), progress => ({
56
- loaded: progress.loaded,
57
- total: Option.getOrUndefined(progress.total)
58
- })), /*#__PURE__*/Schema.annotations({
56
+ const Progress = exports.Progress = /*#__PURE__*/ProgressSchemaJson.pipe( /*#__PURE__*/Schema.transform(ProgressSchema, {
57
+ decode: json => P.make(json.loaded, json.total),
58
+ encode: progress => ({
59
+ loaded: progress.loaded,
60
+ total: Option.getOrUndefined(progress.total)
61
+ })
62
+ }), /*#__PURE__*/Schema.annotations({
59
63
  [AST.IdentifierAnnotationId]: "Progress",
60
64
  [Pretty.PrettyHookId]: () => "Progress",
61
65
  [Arbitrary.ArbitraryHookId]: () => progressArbitrary,
62
- [Eq.EquivalenceHookId]: () => _effect.Equal.equals
66
+ [Eq.EquivalenceHookId]: () => Equal.equals
63
67
  }));
64
- const loadingArbitrary = fc => fc.option(progressArbitrary(fc)).map(progress => AsyncData.loading({
68
+ const loadingArbitrary = fc => fc.option(progressArbitrary(fc)).map(progress => _AsyncData.loading({
65
69
  timestamp: Date.now(),
66
70
  progress: progress || undefined
67
71
  }));
68
- const failureArbitrary = cause => fc => fc.option(loadingArbitrary(fc)).chain(refreshing => cause(fc).chain(cause => fc.date().map(date => AsyncData.failCause(cause, {
72
+ const failureArbitrary = cause => fc => fc.option(loadingArbitrary(fc)).chain(refreshing => cause(fc).chain(cause => fc.date().map(date => _AsyncData.failCause(cause, {
69
73
  timestamp: date.getTime(),
70
74
  refreshing: refreshing || undefined
71
75
  }))));
@@ -83,7 +87,7 @@ const FailureFrom = (cause, timestamp, refreshing) => {
83
87
  }
84
88
  return base;
85
89
  };
86
- const successArbitrary = value => fc => fc.option(loadingArbitrary(fc)).chain(refreshing => value(fc).chain(a => fc.date().map(date => AsyncData.success(a, {
90
+ const successArbitrary = value => fc => fc.option(loadingArbitrary(fc)).chain(refreshing => value(fc).chain(a => fc.date().map(date => _AsyncData.success(a, {
87
91
  timestamp: date.getTime(),
88
92
  refreshing: refreshing || undefined
89
93
  }))));
@@ -107,7 +111,7 @@ const OptimisticFrom = (value, timestamp, previous) => ({
107
111
  timestamp,
108
112
  previous
109
113
  });
110
- const optimisticArbitrary = (valueArb, causeArb) => fc => asyncDataArbitrary(valueArb, causeArb)(fc).chain(previous => valueArb(fc).chain(value => fc.date().map(date => AsyncData.optimistic(previous, value, {
114
+ const optimisticArbitrary = (valueArb, causeArb) => fc => asyncDataArbitrary(valueArb, causeArb)(fc).chain(previous => valueArb(fc).chain(value => fc.date().map(date => _AsyncData.optimistic(previous, value, {
111
115
  timestamp: date.getTime()
112
116
  }))));
113
117
  const fromEq = (a, b) => {
@@ -121,25 +125,25 @@ const fromEq = (a, b) => {
121
125
  if (a.timestamp !== loadingB.timestamp) return false;
122
126
  if (a.progress === undefined && loadingB.progress === undefined) return true;
123
127
  if (a.progress === undefined || loadingB.progress === undefined) return false;
124
- return _effect.Equal.equals(_effect.Data.struct(a.progress), _effect.Data.struct(loadingB.progress));
128
+ return Equal.equals(Data.struct(a.progress), Data.struct(loadingB.progress));
125
129
  }
126
130
  case "Failure":
127
131
  {
128
132
  const failureB = b;
129
- if (!(_effect.Equal.equals(_effect.Data.struct(a.cause), _effect.Data.struct(failureB.cause)) && a.timestamp === failureB.timestamp)) return false;
133
+ if (!(Equal.equals(Data.struct(a.cause), Data.struct(failureB.cause)) && a.timestamp === failureB.timestamp)) return false;
130
134
  if (a.refreshing === undefined && failureB.refreshing === undefined) return true;
131
135
  if (a.refreshing === undefined || failureB.refreshing === undefined) return false;
132
- return _effect.Equal.equals(_effect.Data.struct(a.refreshing), _effect.Data.struct(failureB.refreshing));
136
+ return Equal.equals(Data.struct(a.refreshing), Data.struct(failureB.refreshing));
133
137
  }
134
138
  case "Success":
135
139
  {
136
140
  const successB = b;
137
- return _effect.Equal.equals(a.value, successB.value) && a.timestamp === successB.timestamp && _effect.Equal.equals(a.refreshing, successB.refreshing);
141
+ return Equal.equals(a.value, successB.value) && a.timestamp === successB.timestamp && Equal.equals(a.refreshing, successB.refreshing);
138
142
  }
139
143
  case "Optimistic":
140
144
  {
141
145
  const optimisticB = b;
142
- return _effect.Equal.equals(a.value, optimisticB.value) && a.timestamp === optimisticB.timestamp && fromEq(a.previous, optimisticB.previous);
146
+ return Equal.equals(a.value, optimisticB.value) && a.timestamp === optimisticB.timestamp && fromEq(a.previous, optimisticB.previous);
143
147
  }
144
148
  }
145
149
  };
@@ -156,12 +160,12 @@ function isProgressFrom(value) {
156
160
  function isLoadingFrom(value) {
157
161
  return (0, _Predicate.hasProperty)(value, "_tag") && value._tag === "Loading" && (0, _Predicate.hasProperty)(value, "timestamp") && typeof value.timestamp === "number" && ((0, _Predicate.hasProperty)(value, "progress") ? isProgressFrom(value.progress) : true);
158
162
  }
159
- const isCauseFrom = /*#__PURE__*/Schema.is( /*#__PURE__*/Schema.from( /*#__PURE__*/Schema.cause({
160
- defect: Schema.unknown,
161
- error: Schema.unknown
163
+ const isCauseEncoded = /*#__PURE__*/Schema.is( /*#__PURE__*/Schema.encodedSchema( /*#__PURE__*/Schema.Cause({
164
+ defect: Schema.Unknown,
165
+ error: Schema.Unknown
162
166
  })));
163
167
  function isFailureFrom(value) {
164
- return (0, _Predicate.hasProperty)(value, "_tag") && value._tag === "Failure" && (0, _Predicate.hasProperty)(value, "cause") && isCauseFrom(value.cause) && (0, _Predicate.hasProperty)(value, "timestamp") && typeof value.timestamp === "number" && ((0, _Predicate.hasProperty)(value, "refreshing") ? value.refreshing === undefined || isLoadingFrom(value.refreshing) : true);
168
+ return (0, _Predicate.hasProperty)(value, "_tag") && value._tag === "Failure" && (0, _Predicate.hasProperty)(value, "cause") && isCauseEncoded(value.cause) && (0, _Predicate.hasProperty)(value, "timestamp") && typeof value.timestamp === "number" && ((0, _Predicate.hasProperty)(value, "refreshing") ? value.refreshing === undefined || isLoadingFrom(value.refreshing) : true);
165
169
  }
166
170
  function isSuccessFrom(value) {
167
171
  return (0, _Predicate.hasProperty)(value, "_tag") && value._tag === "Success" && (0, _Predicate.hasProperty)(value, "value") && (0, _Predicate.hasProperty)(value, "timestamp") && typeof value.timestamp === "number" && ((0, _Predicate.hasProperty)(value, "refreshing") ? value.refreshing === undefined || isLoadingFrom(value.refreshing) : true);
@@ -176,73 +180,76 @@ function isAsyncDataFrom(value) {
176
180
  * @since 1.0.0
177
181
  */
178
182
  const asyncDataFromJson = (value, error) => {
179
- const schema = Schema.declare([value, Schema.cause({
183
+ const schema = Schema.declare([value, Schema.Cause({
180
184
  error,
181
- defect: Schema.unknown
182
- })], (valueSchema, causeSchema) => {
183
- const parseCause = Parser.decode(causeSchema);
184
- const parseValue = Parser.decode(valueSchema);
185
- const parseAsyncData = (input, options) => {
186
- return Effect.gen(function* (_) {
187
- if (!isAsyncDataFrom(input)) {
188
- return yield* _(Effect.fail(ParseResult.forbidden(schema.ast, input)));
189
- }
190
- switch (input._tag) {
191
- case "NoData":
192
- case "Loading":
193
- return input;
194
- case "Failure":
195
- {
196
- const cause = yield* _(parseCause(input.cause, options));
197
- return FailureFrom(cause, input.timestamp, input.refreshing);
198
- }
199
- case "Success":
200
- {
201
- const a = yield* _(parseValue(input.value, options));
202
- return SuccessFrom(a, input.timestamp, input.refreshing);
203
- }
204
- case "Optimistic":
205
- {
206
- const previous = yield* _(parseAsyncData(input.previous, options));
207
- const value = yield* _(parseValue(input.value, options));
208
- return OptimisticFrom(value, input.timestamp, previous);
209
- }
210
- }
211
- });
212
- };
213
- return parseAsyncData;
214
- }, (valueSchema, causeSchema) => {
215
- const parseCause = Parser.encode(causeSchema);
216
- const parseValue = Parser.encode(valueSchema);
217
- const parseAsyncData = (input, options) => {
218
- return Effect.gen(function* (_) {
219
- if (!isAsyncDataFrom(input)) {
220
- return yield* _(Effect.fail(ParseResult.forbidden(schema.ast, input)));
221
- }
222
- switch (input._tag) {
223
- case "NoData":
224
- case "Loading":
225
- return input;
226
- case "Failure":
227
- {
228
- const cause = yield* _(parseCause(causeFromToCause(input.cause), options));
229
- return FailureFrom(cause, input.timestamp, input.refreshing);
230
- }
231
- case "Success":
232
- {
233
- const a = yield* _(parseValue(input.value, options));
234
- return SuccessFrom(a, input.timestamp, input.refreshing);
235
- }
236
- case "Optimistic":
237
- {
238
- const previous = yield* _(parseAsyncData(input.previous, options));
239
- const value = yield* _(parseValue(input.value, options));
240
- return OptimisticFrom(value, input.timestamp, previous);
241
- }
242
- }
243
- });
244
- };
245
- return parseAsyncData;
185
+ defect: Schema.Unknown
186
+ })], {
187
+ decode: (valueSchema, causeSchema) => {
188
+ const parseCause = ParseResult.decode(causeSchema);
189
+ const parseValue = ParseResult.decode(valueSchema);
190
+ const parseAsyncData = (input, options) => {
191
+ return Effect.gen(function* () {
192
+ if (!isAsyncDataFrom(input)) {
193
+ return yield* Effect.fail(new ParseResult.Forbidden(schema.ast, input));
194
+ }
195
+ switch (input._tag) {
196
+ case "NoData":
197
+ case "Loading":
198
+ return input;
199
+ case "Failure":
200
+ {
201
+ const cause = yield* parseCause(input.cause, options);
202
+ return FailureFrom(cause, input.timestamp, input.refreshing);
203
+ }
204
+ case "Success":
205
+ {
206
+ const a = yield* parseValue(input.value, options);
207
+ return SuccessFrom(a, input.timestamp, input.refreshing);
208
+ }
209
+ case "Optimistic":
210
+ {
211
+ const previous = yield* parseAsyncData(input.previous, options);
212
+ const value = yield* parseValue(input.value, options);
213
+ return OptimisticFrom(value, input.timestamp, previous);
214
+ }
215
+ }
216
+ });
217
+ };
218
+ return parseAsyncData;
219
+ },
220
+ encode: (valueSchema, causeSchema) => {
221
+ const parseCause = ParseResult.encode(causeSchema);
222
+ const parseValue = ParseResult.encode(valueSchema);
223
+ const parseAsyncData = (input, options) => {
224
+ return Effect.gen(function* () {
225
+ if (!isAsyncDataFrom(input)) {
226
+ return yield* Effect.fail(new ParseResult.Forbidden(schema.ast, input));
227
+ }
228
+ switch (input._tag) {
229
+ case "NoData":
230
+ case "Loading":
231
+ return input;
232
+ case "Failure":
233
+ {
234
+ const cause = yield* parseCause(causeFromToCause(input.cause), options);
235
+ return FailureFrom(cause, input.timestamp, input.refreshing);
236
+ }
237
+ case "Success":
238
+ {
239
+ const a = yield* parseValue(input.value, options);
240
+ return SuccessFrom(a, input.timestamp, input.refreshing);
241
+ }
242
+ case "Optimistic":
243
+ {
244
+ const previous = yield* parseAsyncData(input.previous, options);
245
+ const value = yield* parseValue(input.value, options);
246
+ return OptimisticFrom(value, input.timestamp, previous);
247
+ }
248
+ }
249
+ });
250
+ };
251
+ return parseAsyncData;
252
+ }
246
253
  }, {
247
254
  title: "AsyncDataFrom",
248
255
  equivalence: () => fromEq,
@@ -255,109 +262,115 @@ const asyncDataFromJson = (value, error) => {
255
262
  * @since 1.0.0
256
263
  */
257
264
  exports.asyncDataFromJson = asyncDataFromJson;
258
- const asyncData = (valueSchema, errorSchema) => {
265
+ const AsyncData = (valueSchema, errorSchema) => {
259
266
  const from = asyncDataFromJson(valueSchema, errorSchema);
260
- const to = asyncDataFromSelf(Schema.to(valueSchema), Schema.to(errorSchema));
261
- return from.pipe(Schema.transform(to, asyncDataFromToAsyncData, asyncDataToAsyncDataFrom));
267
+ const to = AsyncDataFromSelf(Schema.typeSchema(valueSchema), Schema.typeSchema(errorSchema));
268
+ return from.pipe(Schema.transform(to, {
269
+ decode: asyncDataFromToAsyncData,
270
+ encode: asyncDataToAsyncDataFrom
271
+ }));
262
272
  };
263
273
  /**
264
274
  * @since 1.0.0
265
275
  */
266
- exports.asyncData = asyncData;
267
- const asyncDataFromSelf = (value, error) => {
268
- const schema = Schema.declare([value, Schema.causeFromSelf({
276
+ exports.AsyncData = AsyncData;
277
+ const AsyncDataFromSelf = (value, error) => {
278
+ const schema = Schema.declare([value, Schema.CauseFromSelf({
269
279
  error
270
- })], (valueSchema, causeSchema) => {
271
- const parseCause = Parser.decode(causeSchema);
272
- const parseValue = Parser.decode(valueSchema);
273
- const parseAsyncData = (input, options) => {
274
- return Effect.gen(function* (_) {
275
- if (!AsyncData.isAsyncData(input)) {
276
- return yield* _(Effect.fail(ParseResult.forbidden(schema.ast, input)));
277
- }
278
- switch (input._tag) {
279
- case "NoData":
280
- case "Loading":
281
- return input;
282
- case "Failure":
283
- {
284
- const cause = yield* _(parseCause(input.cause, options));
285
- return AsyncData.failCause(cause, {
286
- timestamp: input.timestamp,
287
- refreshing: Option.getOrUndefined(input.refreshing)
288
- });
289
- }
290
- case "Success":
291
- {
292
- const a = yield* _(parseValue(input.value, options));
293
- return AsyncData.success(a, {
294
- timestamp: input.timestamp,
295
- refreshing: Option.getOrUndefined(input.refreshing)
296
- });
297
- }
298
- case "Optimistic":
299
- {
300
- const previous = yield* _(parseAsyncData(input.previous, options));
301
- const value = yield* _(parseValue(input.value, options));
302
- return AsyncData.optimistic(previous, value, {
303
- timestamp: input.timestamp
304
- });
305
- }
306
- }
307
- });
308
- };
309
- return parseAsyncData;
310
- }, (valueSchema, causeSchema) => {
311
- const parseCause = Parser.encode(causeSchema);
312
- const parseValue = Parser.encode(valueSchema);
313
- const parseAsyncData = (input, options) => {
314
- return Effect.gen(function* (_) {
315
- if (!AsyncData.isAsyncData(input)) {
316
- return yield* _(Effect.fail(ParseResult.forbidden(schema.ast, input)));
317
- }
318
- switch (input._tag) {
319
- case "NoData":
320
- case "Loading":
321
- return input;
322
- case "Failure":
323
- {
324
- const cause = yield* _(parseCause(input.cause, options));
325
- return AsyncData.failCause(cause, {
326
- timestamp: input.timestamp,
327
- refreshing: Option.getOrUndefined(input.refreshing)
328
- });
329
- }
330
- case "Success":
331
- {
332
- const a = yield* _(parseValue(input.value, options));
333
- return AsyncData.success(a, {
334
- timestamp: input.timestamp,
335
- refreshing: Option.getOrUndefined(input.refreshing)
336
- });
337
- }
338
- case "Optimistic":
339
- {
340
- const previous = yield* _(parseAsyncData(input.previous, options));
341
- const value = yield* _(parseValue(input.value, options));
342
- return AsyncData.optimistic(previous, value, {
343
- timestamp: input.timestamp
344
- });
345
- }
346
- }
347
- });
348
- };
349
- return parseAsyncData;
280
+ })], {
281
+ decode: (valueSchema, causeSchema) => {
282
+ const parseCause = ParseResult.decode(causeSchema);
283
+ const parseValue = ParseResult.decode(valueSchema);
284
+ const parseAsyncData = (input, options) => {
285
+ return Effect.gen(function* () {
286
+ if (!_AsyncData.isAsyncData(input)) {
287
+ return yield* Effect.fail(new ParseResult.Forbidden(schema.ast, input));
288
+ }
289
+ switch (input._tag) {
290
+ case "NoData":
291
+ case "Loading":
292
+ return input;
293
+ case "Failure":
294
+ {
295
+ const cause = yield* parseCause(input.cause, options);
296
+ return _AsyncData.failCause(cause, {
297
+ timestamp: input.timestamp,
298
+ refreshing: Option.getOrUndefined(input.refreshing)
299
+ });
300
+ }
301
+ case "Success":
302
+ {
303
+ const a = yield* parseValue(input.value, options);
304
+ return _AsyncData.success(a, {
305
+ timestamp: input.timestamp,
306
+ refreshing: Option.getOrUndefined(input.refreshing)
307
+ });
308
+ }
309
+ case "Optimistic":
310
+ {
311
+ const previous = yield* parseAsyncData(input.previous, options);
312
+ const value = yield* parseValue(input.value, options);
313
+ return _AsyncData.optimistic(previous, value, {
314
+ timestamp: input.timestamp
315
+ });
316
+ }
317
+ }
318
+ });
319
+ };
320
+ return parseAsyncData;
321
+ },
322
+ encode: (valueSchema, causeSchema) => {
323
+ const parseCause = ParseResult.encode(causeSchema);
324
+ const parseValue = ParseResult.encode(valueSchema);
325
+ const parseAsyncData = (input, options) => {
326
+ return Effect.gen(function* () {
327
+ if (!_AsyncData.isAsyncData(input)) {
328
+ return yield* Effect.fail(new ParseResult.Forbidden(schema.ast, input));
329
+ }
330
+ switch (input._tag) {
331
+ case "NoData":
332
+ case "Loading":
333
+ return input;
334
+ case "Failure":
335
+ {
336
+ const cause = yield* parseCause(input.cause, options);
337
+ return _AsyncData.failCause(cause, {
338
+ timestamp: input.timestamp,
339
+ refreshing: Option.getOrUndefined(input.refreshing)
340
+ });
341
+ }
342
+ case "Success":
343
+ {
344
+ const a = yield* parseValue(input.value, options);
345
+ return _AsyncData.success(a, {
346
+ timestamp: input.timestamp,
347
+ refreshing: Option.getOrUndefined(input.refreshing)
348
+ });
349
+ }
350
+ case "Optimistic":
351
+ {
352
+ const previous = yield* parseAsyncData(input.previous, options);
353
+ const value = yield* parseValue(input.value, options);
354
+ return _AsyncData.optimistic(previous, value, {
355
+ timestamp: input.timestamp
356
+ });
357
+ }
358
+ }
359
+ });
360
+ };
361
+ return parseAsyncData;
362
+ }
350
363
  }, {
351
364
  title: "AsyncData",
352
365
  pretty: asyncDataPretty,
353
366
  arbitrary: asyncDataArbitrary,
354
- equivalence: () => _effect.Equal.equals
367
+ equivalence: () => Equal.equals
355
368
  });
356
369
  return schema;
357
370
  };
358
- exports.asyncDataFromSelf = asyncDataFromSelf;
371
+ exports.AsyncDataFromSelf = AsyncDataFromSelf;
359
372
  function asyncDataPretty(A, E) {
360
- return AsyncData.match({
373
+ return _AsyncData.match({
361
374
  NoData: () => NO_DATA_PRETTY,
362
375
  Loading: LOADING_PRETTY,
363
376
  Failure: (_, data) => FAILURE_PRETTY(E)(data),
@@ -369,7 +382,7 @@ function asyncDataArbitrary(A, E) {
369
382
  const failureArb = failureArbitrary(E);
370
383
  const successArb = successArbitrary(A);
371
384
  const optimisticArb = optimisticArbitrary(A, E);
372
- return fc => fc.oneof(fc.constant(AsyncData.noData()), fc.constant(AsyncData.loading()), failureArb(fc), successArb(fc), optimisticArb(fc));
385
+ return fc => fc.oneof(fc.constant(_AsyncData.noData()), fc.constant(_AsyncData.loading()), failureArb(fc), successArb(fc), optimisticArb(fc));
373
386
  }
374
387
  function progressFromJson(json) {
375
388
  if (json === undefined) return Option.none();
@@ -384,7 +397,7 @@ function progressToJson(progres) {
384
397
  }
385
398
  function loadingFromJson(json) {
386
399
  if (json === undefined) return;
387
- return AsyncData.loading({
400
+ return _AsyncData.loading({
388
401
  timestamp: json.timestamp,
389
402
  progress: Option.getOrUndefined(progressFromJson(json.progress))
390
403
  });
@@ -421,14 +434,14 @@ function causeFromToCause(from) {
421
434
  function fiberIdFromToFiberId(id) {
422
435
  switch (id._tag) {
423
436
  case "None":
424
- return _effect.FiberId.none;
437
+ return FiberId.none;
425
438
  case "Runtime":
426
- return _effect.FiberId.runtime(id.id, id.startTimeMillis);
439
+ return FiberId.runtime(id.id, id.startTimeMillis);
427
440
  case "Composite":
428
- return _effect.FiberId.composite(fiberIdFromToFiberId(id.left), fiberIdFromToFiberId(id.right));
441
+ return FiberId.composite(fiberIdFromToFiberId(id.left), fiberIdFromToFiberId(id.right));
429
442
  }
430
443
  }
431
- function causeToCauseFrom(cause) {
444
+ function causeToCauseEncoded(cause) {
432
445
  switch (cause._tag) {
433
446
  case "Die":
434
447
  return {
@@ -452,14 +465,14 @@ function causeToCauseFrom(cause) {
452
465
  case "Parallel":
453
466
  return {
454
467
  _tag: "Parallel",
455
- left: causeToCauseFrom(cause.left),
456
- right: causeToCauseFrom(cause.right)
468
+ left: causeToCauseEncoded(cause.left),
469
+ right: causeToCauseEncoded(cause.right)
457
470
  };
458
471
  case "Sequential":
459
472
  return {
460
473
  _tag: "Sequential",
461
- left: causeToCauseFrom(cause.left),
462
- right: causeToCauseFrom(cause.right)
474
+ left: causeToCauseEncoded(cause.left),
475
+ right: causeToCauseEncoded(cause.right)
463
476
  };
464
477
  }
465
478
  }
@@ -493,7 +506,7 @@ function asyncDataToAsyncDataFrom(data) {
493
506
  case "Loading":
494
507
  return loadingToJson(data);
495
508
  case "Failure":
496
- return FailureFrom(causeToCauseFrom(data.cause), data.timestamp, Option.getOrUndefined(Option.map(data.refreshing, loadingToJson)));
509
+ return FailureFrom(causeToCauseEncoded(data.cause), data.timestamp, Option.getOrUndefined(Option.map(data.refreshing, loadingToJson)));
497
510
  case "Success":
498
511
  return SuccessFrom(data.value, data.timestamp, Option.getOrUndefined(Option.map(data.refreshing, loadingToJson)));
499
512
  case "Optimistic":
@@ -503,21 +516,21 @@ function asyncDataToAsyncDataFrom(data) {
503
516
  function asyncDataFromToAsyncData(data) {
504
517
  switch (data._tag) {
505
518
  case "NoData":
506
- return AsyncData.noData();
519
+ return _AsyncData.noData();
507
520
  case "Loading":
508
521
  return loadingFromJson(data);
509
522
  case "Failure":
510
- return AsyncData.failCause(causeFromToCause(data.cause), {
523
+ return _AsyncData.failCause(causeFromToCause(data.cause), {
511
524
  timestamp: data.timestamp,
512
525
  refreshing: loadingFromJson(data.refreshing)
513
526
  });
514
527
  case "Success":
515
- return AsyncData.success(data.value, {
528
+ return _AsyncData.success(data.value, {
516
529
  timestamp: data.timestamp,
517
530
  refreshing: loadingFromJson(data.refreshing)
518
531
  });
519
532
  case "Optimistic":
520
- return AsyncData.optimistic(asyncDataFromToAsyncData(data.previous), data.value, {
533
+ return _AsyncData.optimistic(asyncDataFromToAsyncData(data.previous), data.value, {
521
534
  timestamp: data.timestamp
522
535
  });
523
536
  }