@isograph/react 0.0.0-main-200dcbf4 → 0.0.0-main-bdb28ffc
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/.turbo/turbo-compile-libs.log +1 -1
- package/dist/core/PromiseWrapper.d.ts +4 -4
- package/dist/core/PromiseWrapper.d.ts.map +1 -1
- package/dist/core/PromiseWrapper.js +2 -9
- package/dist/core/read.d.ts.map +1 -1
- package/dist/core/read.js +1 -2
- package/package.json +4 -4
- package/src/core/PromiseWrapper.ts +13 -16
- package/src/core/read.ts +3 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type AnyError = any;
|
|
2
|
-
export declare const NOT_SET:
|
|
2
|
+
export declare const NOT_SET: unique symbol;
|
|
3
3
|
export type NotSet = typeof NOT_SET;
|
|
4
4
|
export type Result<T, E> = {
|
|
5
5
|
kind: 'Ok';
|
|
@@ -13,11 +13,11 @@ export type Result<T, E> = {
|
|
|
13
13
|
* Before the promise is resolved, value becomes non-null.
|
|
14
14
|
*/
|
|
15
15
|
export type PromiseWrapper<T, E = any> = {
|
|
16
|
-
readonly promise: Promise<T
|
|
16
|
+
readonly promise: Promise<Exclude<T, NotSet>>;
|
|
17
17
|
result: Result<Exclude<T, NotSet>, E> | NotSet;
|
|
18
18
|
};
|
|
19
|
-
export declare function wrapPromise<T>(promise: Promise<T
|
|
20
|
-
export declare function wrapResolvedValue<T>(value: T): PromiseWrapper<T, never>;
|
|
19
|
+
export declare function wrapPromise<T>(promise: Promise<Exclude<T, NotSet>>): PromiseWrapper<T, any>;
|
|
20
|
+
export declare function wrapResolvedValue<T>(value: Exclude<T, NotSet>): PromiseWrapper<T, never>;
|
|
21
21
|
export declare function readPromise<T, E>(p: PromiseWrapper<T, E>): T;
|
|
22
22
|
export type PromiseState<T, E> = {
|
|
23
23
|
kind: 'Pending';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromiseWrapper.d.ts","sourceRoot":"","sources":["../../src/core/PromiseWrapper.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC;AAE3B,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"PromiseWrapper.d.ts","sourceRoot":"","sources":["../../src/core/PromiseWrapper.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC;AAE3B,eAAO,MAAM,OAAO,eAAoB,CAAC;AACzC,MAAM,MAAM,MAAM,GAAG,OAAO,OAAO,CAAC;AAEpC,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IACnB;IACE,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,CAAC,CAAC;CACV,GACD;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEN;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;CAChD,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GACnC,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,CAWxB;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,GACxB,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,CAQ1B;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAY5D;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IACzB;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACrB,GACD,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjB,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAClC,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GACtB,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAQpB"}
|
|
@@ -11,11 +11,9 @@ function wrapPromise(promise) {
|
|
|
11
11
|
const wrapper = { promise, result: exports.NOT_SET };
|
|
12
12
|
promise
|
|
13
13
|
.then((v) => {
|
|
14
|
-
// v is assignable to Exclude<T, Symbol> | Symbol
|
|
15
14
|
wrapper.result = { kind: 'Ok', value: v };
|
|
16
15
|
})
|
|
17
16
|
.catch((e) => {
|
|
18
|
-
// e is assignable to Exclude<T, Symbol> | Symbol
|
|
19
17
|
wrapper.result = { kind: 'Err', error: e };
|
|
20
18
|
});
|
|
21
19
|
return wrapper;
|
|
@@ -25,7 +23,6 @@ function wrapResolvedValue(value) {
|
|
|
25
23
|
promise: Promise.resolve(value),
|
|
26
24
|
result: {
|
|
27
25
|
kind: 'Ok',
|
|
28
|
-
// @ts-expect-error one should not call wrapResolvedValue with NOT_SET
|
|
29
26
|
value,
|
|
30
27
|
},
|
|
31
28
|
};
|
|
@@ -33,7 +30,6 @@ function wrapResolvedValue(value) {
|
|
|
33
30
|
function readPromise(p) {
|
|
34
31
|
const { result } = p;
|
|
35
32
|
if (result !== exports.NOT_SET) {
|
|
36
|
-
// Safety: p.result is either NOT_SET or an actual value.
|
|
37
33
|
const resultKind = result;
|
|
38
34
|
if (resultKind.kind === 'Ok') {
|
|
39
35
|
return resultKind.value;
|
|
@@ -45,11 +41,8 @@ function readPromise(p) {
|
|
|
45
41
|
throw p.promise;
|
|
46
42
|
}
|
|
47
43
|
function getPromiseState(p) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Safety: p.result is either NOT_SET or an actual value.
|
|
51
|
-
const resultKind = result;
|
|
52
|
-
return resultKind;
|
|
44
|
+
if (p.result !== exports.NOT_SET) {
|
|
45
|
+
return p.result;
|
|
53
46
|
}
|
|
54
47
|
return {
|
|
55
48
|
kind: 'Pending',
|
package/dist/core/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAEL,wCAAwC,EAEzC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,IAAI,EACT,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/core/read.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAEL,wCAAwC,EAEzC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,KAAK,qBAAqB,EAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,IAAI,EACT,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAGL,cAAc,EAIf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,SAAS,EACT,KAAK,qBAAqB,EAC1B,KAAK,6BAA6B,EAClC,KAAK,iBAAiB,EACtB,KAAK,8BAA8B,EACnC,KAAK,iBAAiB,EACvB,MAAM,UA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B,EAAE,2BAA2B,EAClD,yBAAyB,EAAE,cAAc,GACxC,cAAc,CAAC,OAAO,CAAC,CAuDzB"}
|
package/dist/core/read.js
CHANGED
|
@@ -43,9 +43,8 @@ function readButDoNotEvaluate(environment, fragmentReference, networkRequestOpti
|
|
|
43
43
|
// in the browser. However, during initial SSR on NextJS, throwing a rejected
|
|
44
44
|
// promise results in an infinite loop (including re-issuing the query until the
|
|
45
45
|
// process OOM's or something.) Hence, we throw an error.
|
|
46
|
-
// TODO investigate why we cannot check against NOT_SET here and we have to cast
|
|
47
46
|
const result = fragmentReference.networkRequest.result;
|
|
48
|
-
if (result.kind === 'Err') {
|
|
47
|
+
if (result !== PromiseWrapper_1.NOT_SET && result.kind === 'Err') {
|
|
49
48
|
throw new Error('NetworkError', { cause: result.error });
|
|
50
49
|
}
|
|
51
50
|
throw new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isograph/react",
|
|
3
|
-
"version": "0.0.0-main-
|
|
3
|
+
"version": "0.0.0-main-bdb28ffc",
|
|
4
4
|
"description": "Use Isograph with React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"iso": "cross-env ISO_PRINT_ABSOLUTE_FILEPATH=1 ../../target/debug/isograph_cli --config ./isograph.config.json"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
23
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
|
24
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
|
22
|
+
"@isograph/disposable-types": "0.0.0-main-bdb28ffc",
|
|
23
|
+
"@isograph/react-disposable-state": "0.0.0-main-bdb28ffc",
|
|
24
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-bdb28ffc"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type AnyError = any;
|
|
2
2
|
|
|
3
|
-
export const NOT_SET
|
|
3
|
+
export const NOT_SET = Symbol('NOT_SET');
|
|
4
4
|
export type NotSet = typeof NOT_SET;
|
|
5
5
|
|
|
6
6
|
export type Result<T, E> =
|
|
@@ -18,31 +18,32 @@ export type Result<T, E> =
|
|
|
18
18
|
* Before the promise is resolved, value becomes non-null.
|
|
19
19
|
*/
|
|
20
20
|
export type PromiseWrapper<T, E = any> = {
|
|
21
|
-
readonly promise: Promise<T
|
|
21
|
+
readonly promise: Promise<Exclude<T, NotSet>>;
|
|
22
22
|
result: Result<Exclude<T, NotSet>, E> | NotSet;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export function wrapPromise<T>(
|
|
25
|
+
export function wrapPromise<T>(
|
|
26
|
+
promise: Promise<Exclude<T, NotSet>>,
|
|
27
|
+
): PromiseWrapper<T, any> {
|
|
26
28
|
// TODO confirm suspense works if the promise is already resolved.
|
|
27
29
|
const wrapper: PromiseWrapper<T, any> = { promise, result: NOT_SET };
|
|
28
30
|
promise
|
|
29
31
|
.then((v) => {
|
|
30
|
-
|
|
31
|
-
wrapper.result = { kind: 'Ok', value: v as any };
|
|
32
|
+
wrapper.result = { kind: 'Ok', value: v };
|
|
32
33
|
})
|
|
33
34
|
.catch((e) => {
|
|
34
|
-
|
|
35
|
-
wrapper.result = { kind: 'Err', error: e as any };
|
|
35
|
+
wrapper.result = { kind: 'Err', error: e };
|
|
36
36
|
});
|
|
37
37
|
return wrapper;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function wrapResolvedValue<T>(
|
|
40
|
+
export function wrapResolvedValue<T>(
|
|
41
|
+
value: Exclude<T, NotSet>,
|
|
42
|
+
): PromiseWrapper<T, never> {
|
|
41
43
|
return {
|
|
42
44
|
promise: Promise.resolve(value),
|
|
43
45
|
result: {
|
|
44
46
|
kind: 'Ok',
|
|
45
|
-
// @ts-expect-error one should not call wrapResolvedValue with NOT_SET
|
|
46
47
|
value,
|
|
47
48
|
},
|
|
48
49
|
};
|
|
@@ -51,8 +52,7 @@ export function wrapResolvedValue<T>(value: T): PromiseWrapper<T, never> {
|
|
|
51
52
|
export function readPromise<T, E>(p: PromiseWrapper<T, E>): T {
|
|
52
53
|
const { result } = p;
|
|
53
54
|
if (result !== NOT_SET) {
|
|
54
|
-
|
|
55
|
-
const resultKind = result as Result<T, any>;
|
|
55
|
+
const resultKind = result;
|
|
56
56
|
if (resultKind.kind === 'Ok') {
|
|
57
57
|
return resultKind.value;
|
|
58
58
|
} else {
|
|
@@ -73,11 +73,8 @@ export type PromiseState<T, E> =
|
|
|
73
73
|
export function getPromiseState<T, E>(
|
|
74
74
|
p: PromiseWrapper<T, E>,
|
|
75
75
|
): PromiseState<T, E> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// Safety: p.result is either NOT_SET or an actual value.
|
|
79
|
-
const resultKind = result as Result<T, any>;
|
|
80
|
-
return resultKind;
|
|
76
|
+
if (p.result !== NOT_SET) {
|
|
77
|
+
return p.result;
|
|
81
78
|
}
|
|
82
79
|
return {
|
|
83
80
|
kind: 'Pending',
|
package/src/core/read.ts
CHANGED
|
@@ -30,9 +30,9 @@ import { logMessage } from './logging';
|
|
|
30
30
|
import { maybeMakeNetworkRequest } from './makeNetworkRequest';
|
|
31
31
|
import {
|
|
32
32
|
getPromiseState,
|
|
33
|
+
NOT_SET,
|
|
33
34
|
PromiseWrapper,
|
|
34
35
|
readPromise,
|
|
35
|
-
Result,
|
|
36
36
|
wrapPromise,
|
|
37
37
|
wrapResolvedValue,
|
|
38
38
|
} from './PromiseWrapper';
|
|
@@ -104,12 +104,8 @@ export function readButDoNotEvaluate<
|
|
|
104
104
|
// promise results in an infinite loop (including re-issuing the query until the
|
|
105
105
|
// process OOM's or something.) Hence, we throw an error.
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
any,
|
|
110
|
-
any
|
|
111
|
-
>;
|
|
112
|
-
if (result.kind === 'Err') {
|
|
107
|
+
const result = fragmentReference.networkRequest.result;
|
|
108
|
+
if (result !== NOT_SET && result.kind === 'Err') {
|
|
113
109
|
throw new Error('NetworkError', { cause: result.error });
|
|
114
110
|
}
|
|
115
111
|
|