@isograph/react 0.0.0-main-adb0955b → 0.0.0-main-ba9f1dc0
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/dist/core/check.d.ts +11 -0
- package/dist/core/check.js +125 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +4 -4
- package/src/core/check.ts +194 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NormalizationAst } from './entrypoint';
|
|
2
|
+
import { Variables } from './FragmentReference';
|
|
3
|
+
import { IsographEnvironment, Link } from './IsographEnvironment';
|
|
4
|
+
type CheckResult = {
|
|
5
|
+
kind: 'EnoughData';
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'MissingData';
|
|
8
|
+
record: Link;
|
|
9
|
+
};
|
|
10
|
+
export declare function check(environment: IsographEnvironment, normalizationAst: NormalizationAst, variables: Variables): CheckResult;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.check = check;
|
|
4
|
+
const cache_1 = require("./cache");
|
|
5
|
+
const IsographEnvironment_1 = require("./IsographEnvironment");
|
|
6
|
+
function check(environment, normalizationAst, variables) {
|
|
7
|
+
return checkFromRecord(environment, normalizationAst, variables, environment.store[IsographEnvironment_1.ROOT_ID], IsographEnvironment_1.ROOT_ID);
|
|
8
|
+
}
|
|
9
|
+
function checkFromRecord(environment, normalizationAst, variables, record, backupId) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
normalizationAstLoop: for (const normalizationAstNode of normalizationAst) {
|
|
12
|
+
switch (normalizationAstNode.kind) {
|
|
13
|
+
case 'Scalar': {
|
|
14
|
+
const parentRecordKey = (0, cache_1.getParentRecordKey)(normalizationAstNode, variables);
|
|
15
|
+
const scalarValue = record[parentRecordKey];
|
|
16
|
+
// null means the value is known to be missing, so it must
|
|
17
|
+
// be exactly undefined
|
|
18
|
+
if (scalarValue === undefined) {
|
|
19
|
+
return {
|
|
20
|
+
kind: 'MissingData',
|
|
21
|
+
record: {
|
|
22
|
+
__link: (_a = record.id) !== null && _a !== void 0 ? _a : backupId,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
continue normalizationAstLoop;
|
|
27
|
+
}
|
|
28
|
+
case 'Linked': {
|
|
29
|
+
const parentRecordKey = (0, cache_1.getParentRecordKey)(normalizationAstNode, variables);
|
|
30
|
+
const linkedValue = record[parentRecordKey];
|
|
31
|
+
if (linkedValue === undefined) {
|
|
32
|
+
return {
|
|
33
|
+
kind: 'MissingData',
|
|
34
|
+
record: {
|
|
35
|
+
__link: (_b = record.id) !== null && _b !== void 0 ? _b : backupId,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else if (linkedValue === null) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
else if (Array.isArray(linkedValue)) {
|
|
43
|
+
arrayItemsLoop: for (const item of linkedValue) {
|
|
44
|
+
const link = (0, IsographEnvironment_1.getLink)(item);
|
|
45
|
+
if (link === null) {
|
|
46
|
+
throw new Error('Unexpected non-link in the Isograph store. ' +
|
|
47
|
+
'This is indicative of a bug in Isograph.');
|
|
48
|
+
}
|
|
49
|
+
const linkedRecord = environment.store[link.__link];
|
|
50
|
+
if (linkedRecord === undefined) {
|
|
51
|
+
return {
|
|
52
|
+
kind: 'MissingData',
|
|
53
|
+
record: link,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
else if (linkedRecord === null) {
|
|
57
|
+
continue arrayItemsLoop;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// TODO in __DEV__ assert linkedRecord is an object
|
|
61
|
+
const result = checkFromRecord(environment, normalizationAstNode.selections, variables, linkedRecord,
|
|
62
|
+
// TODO this seems likely to be wrong
|
|
63
|
+
backupId + '.' + parentRecordKey);
|
|
64
|
+
if (result.kind === 'MissingData') {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const link = (0, IsographEnvironment_1.getLink)(linkedValue);
|
|
72
|
+
if (link === null) {
|
|
73
|
+
throw new Error('Unexpected non-link in the Isograph store. ' +
|
|
74
|
+
'This is indicative of a bug in Isograph.');
|
|
75
|
+
}
|
|
76
|
+
const linkedRecord = environment.store[link.__link];
|
|
77
|
+
if (linkedRecord === undefined) {
|
|
78
|
+
return {
|
|
79
|
+
kind: 'MissingData',
|
|
80
|
+
record: link,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
else if (linkedRecord === null) {
|
|
84
|
+
continue normalizationAstLoop;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// TODO in __DEV__ assert linkedRecord is an object
|
|
88
|
+
const result = checkFromRecord(environment, normalizationAstNode.selections, variables, linkedRecord,
|
|
89
|
+
// TODO this seems likely to be wrong
|
|
90
|
+
backupId + '.' + parentRecordKey);
|
|
91
|
+
if (result.kind === 'MissingData') {
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
continue normalizationAstLoop;
|
|
97
|
+
}
|
|
98
|
+
case 'InlineFragment': {
|
|
99
|
+
const existingRecordTypename = record['__typename'];
|
|
100
|
+
if (existingRecordTypename == null ||
|
|
101
|
+
existingRecordTypename !== normalizationAstNode.type) {
|
|
102
|
+
return {
|
|
103
|
+
kind: 'MissingData',
|
|
104
|
+
record: {
|
|
105
|
+
__link: (_c = record.id) !== null && _c !== void 0 ? _c : backupId,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const result = checkFromRecord(environment, normalizationAstNode.selections, variables, record, backupId);
|
|
110
|
+
if (result.kind === 'MissingData') {
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
continue normalizationAstLoop;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
let _ = normalizationAstNode;
|
|
117
|
+
_;
|
|
118
|
+
throw new Error('Unexpected case. This is indicative of a bug in Isograph.');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
kind: 'EnoughData',
|
|
124
|
+
};
|
|
125
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { readButDoNotEvaluate } from './core/read';
|
|
|
9
9
|
export { type ExtractSecondParam, type CombineWithIntrinsicAttributes, type Argument, type ArgumentName, type ArgumentValue, type Arguments, } from './core/util';
|
|
10
10
|
export { type FragmentReference, type Variables, type ExtractParameters, type ExtractData, stableIdForFragmentReference, } from './core/FragmentReference';
|
|
11
11
|
export { type LogMessage, type LogFunction, logMessage, registerLogger, } from './core/logging';
|
|
12
|
+
export { check } from './core/check';
|
|
12
13
|
export { IsographEnvironmentProvider, useIsographEnvironment, type IsographEnvironmentProviderProps, } from './react/IsographEnvironmentProvider';
|
|
13
14
|
export { useImperativeReference } from './react/useImperativeReference';
|
|
14
15
|
export { FragmentReader } from './react/FragmentReader';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useImperativeLoadableField = exports.useConnectionSpecPagination = exports.useSkipLimitPagination = exports.useImperativeExposedMutationField = exports.useClientSideDefer = exports.RenderAfterCommit__DO_NOT_USE = exports.useRerenderOnChange = exports.useLazyReference = exports.useSubscribeToMultiple = exports.useReadAndSubscribe = exports.useResult = exports.FragmentReader = exports.useImperativeReference = exports.useIsographEnvironment = exports.IsographEnvironmentProvider = exports.registerLogger = exports.logMessage = exports.stableIdForFragmentReference = exports.readButDoNotEvaluate = exports.assertIsEntrypoint = exports.defaultMissingFieldHandler = exports.createIsographStore = exports.createIsographEnvironment = exports.ROOT_ID = exports.makeNetworkRequest = exports.normalizeData = exports.subscribe = exports.wrapPromise = exports.wrapResolvedValue = exports.getPromiseState = exports.readPromise = exports.garbageCollectEnvironment = exports.unretainQuery = exports.retainQuery = void 0;
|
|
3
|
+
exports.useImperativeLoadableField = exports.useConnectionSpecPagination = exports.useSkipLimitPagination = exports.useImperativeExposedMutationField = exports.useClientSideDefer = exports.RenderAfterCommit__DO_NOT_USE = exports.useRerenderOnChange = exports.useLazyReference = exports.useSubscribeToMultiple = exports.useReadAndSubscribe = exports.useResult = exports.FragmentReader = exports.useImperativeReference = exports.useIsographEnvironment = exports.IsographEnvironmentProvider = exports.check = exports.registerLogger = exports.logMessage = exports.stableIdForFragmentReference = exports.readButDoNotEvaluate = exports.assertIsEntrypoint = exports.defaultMissingFieldHandler = exports.createIsographStore = exports.createIsographEnvironment = exports.ROOT_ID = exports.makeNetworkRequest = exports.normalizeData = exports.subscribe = exports.wrapPromise = exports.wrapResolvedValue = exports.getPromiseState = exports.readPromise = exports.garbageCollectEnvironment = exports.unretainQuery = exports.retainQuery = void 0;
|
|
4
4
|
var garbageCollection_1 = require("./core/garbageCollection");
|
|
5
5
|
Object.defineProperty(exports, "retainQuery", { enumerable: true, get: function () { return garbageCollection_1.retainQuery; } });
|
|
6
6
|
Object.defineProperty(exports, "unretainQuery", { enumerable: true, get: function () { return garbageCollection_1.unretainQuery; } });
|
|
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "stableIdForFragmentReference", { enumerable: tru
|
|
|
29
29
|
var logging_1 = require("./core/logging");
|
|
30
30
|
Object.defineProperty(exports, "logMessage", { enumerable: true, get: function () { return logging_1.logMessage; } });
|
|
31
31
|
Object.defineProperty(exports, "registerLogger", { enumerable: true, get: function () { return logging_1.registerLogger; } });
|
|
32
|
+
var check_1 = require("./core/check");
|
|
33
|
+
Object.defineProperty(exports, "check", { enumerable: true, get: function () { return check_1.check; } });
|
|
32
34
|
var IsographEnvironmentProvider_1 = require("./react/IsographEnvironmentProvider");
|
|
33
35
|
Object.defineProperty(exports, "IsographEnvironmentProvider", { enumerable: true, get: function () { return IsographEnvironmentProvider_1.IsographEnvironmentProvider; } });
|
|
34
36
|
Object.defineProperty(exports, "useIsographEnvironment", { enumerable: true, get: function () { return IsographEnvironmentProvider_1.useIsographEnvironment; } });
|
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-ba9f1dc0",
|
|
4
4
|
"description": "Use Isograph with React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"tsc": "tsc"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
21
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
|
22
|
-
"@isograph/reference-counted-pointer": "0.0.0-main-
|
|
20
|
+
"@isograph/disposable-types": "0.0.0-main-ba9f1dc0",
|
|
21
|
+
"@isograph/react-disposable-state": "0.0.0-main-ba9f1dc0",
|
|
22
|
+
"@isograph/reference-counted-pointer": "0.0.0-main-ba9f1dc0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "18.3.1"
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { getParentRecordKey } from './cache';
|
|
2
|
+
import { NormalizationAst } from './entrypoint';
|
|
3
|
+
import { Variables } from './FragmentReference';
|
|
4
|
+
import {
|
|
5
|
+
getLink,
|
|
6
|
+
IsographEnvironment,
|
|
7
|
+
Link,
|
|
8
|
+
ROOT_ID,
|
|
9
|
+
StoreRecord,
|
|
10
|
+
} from './IsographEnvironment';
|
|
11
|
+
|
|
12
|
+
type CheckResult =
|
|
13
|
+
| {
|
|
14
|
+
kind: 'EnoughData';
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
kind: 'MissingData';
|
|
18
|
+
record: Link;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function check(
|
|
22
|
+
environment: IsographEnvironment,
|
|
23
|
+
normalizationAst: NormalizationAst,
|
|
24
|
+
variables: Variables,
|
|
25
|
+
): CheckResult {
|
|
26
|
+
return checkFromRecord(
|
|
27
|
+
environment,
|
|
28
|
+
normalizationAst,
|
|
29
|
+
variables,
|
|
30
|
+
environment.store[ROOT_ID],
|
|
31
|
+
ROOT_ID,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function checkFromRecord(
|
|
36
|
+
environment: IsographEnvironment,
|
|
37
|
+
normalizationAst: NormalizationAst,
|
|
38
|
+
variables: Variables,
|
|
39
|
+
record: StoreRecord,
|
|
40
|
+
backupId: string,
|
|
41
|
+
): CheckResult {
|
|
42
|
+
normalizationAstLoop: for (const normalizationAstNode of normalizationAst) {
|
|
43
|
+
switch (normalizationAstNode.kind) {
|
|
44
|
+
case 'Scalar': {
|
|
45
|
+
const parentRecordKey = getParentRecordKey(
|
|
46
|
+
normalizationAstNode,
|
|
47
|
+
variables,
|
|
48
|
+
);
|
|
49
|
+
const scalarValue = record[parentRecordKey];
|
|
50
|
+
|
|
51
|
+
// null means the value is known to be missing, so it must
|
|
52
|
+
// be exactly undefined
|
|
53
|
+
if (scalarValue === undefined) {
|
|
54
|
+
return {
|
|
55
|
+
kind: 'MissingData',
|
|
56
|
+
record: {
|
|
57
|
+
__link: record.id ?? backupId,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
continue normalizationAstLoop;
|
|
62
|
+
}
|
|
63
|
+
case 'Linked': {
|
|
64
|
+
const parentRecordKey = getParentRecordKey(
|
|
65
|
+
normalizationAstNode,
|
|
66
|
+
variables,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const linkedValue = record[parentRecordKey];
|
|
70
|
+
|
|
71
|
+
if (linkedValue === undefined) {
|
|
72
|
+
return {
|
|
73
|
+
kind: 'MissingData',
|
|
74
|
+
record: {
|
|
75
|
+
__link: record.id ?? backupId,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
} else if (linkedValue === null) {
|
|
79
|
+
continue;
|
|
80
|
+
} else if (Array.isArray(linkedValue)) {
|
|
81
|
+
arrayItemsLoop: for (const item of linkedValue) {
|
|
82
|
+
const link = getLink(item);
|
|
83
|
+
if (link === null) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
'Unexpected non-link in the Isograph store. ' +
|
|
86
|
+
'This is indicative of a bug in Isograph.',
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const linkedRecord = environment.store[link.__link];
|
|
91
|
+
|
|
92
|
+
if (linkedRecord === undefined) {
|
|
93
|
+
return {
|
|
94
|
+
kind: 'MissingData',
|
|
95
|
+
record: link,
|
|
96
|
+
};
|
|
97
|
+
} else if (linkedRecord === null) {
|
|
98
|
+
continue arrayItemsLoop;
|
|
99
|
+
} else {
|
|
100
|
+
// TODO in __DEV__ assert linkedRecord is an object
|
|
101
|
+
const result = checkFromRecord(
|
|
102
|
+
environment,
|
|
103
|
+
normalizationAstNode.selections,
|
|
104
|
+
variables,
|
|
105
|
+
linkedRecord,
|
|
106
|
+
// TODO this seems likely to be wrong
|
|
107
|
+
backupId + '.' + parentRecordKey,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (result.kind === 'MissingData') {
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
const link = getLink(linkedValue);
|
|
117
|
+
if (link === null) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
'Unexpected non-link in the Isograph store. ' +
|
|
120
|
+
'This is indicative of a bug in Isograph.',
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const linkedRecord = environment.store[link.__link];
|
|
125
|
+
|
|
126
|
+
if (linkedRecord === undefined) {
|
|
127
|
+
return {
|
|
128
|
+
kind: 'MissingData',
|
|
129
|
+
record: link,
|
|
130
|
+
};
|
|
131
|
+
} else if (linkedRecord === null) {
|
|
132
|
+
continue normalizationAstLoop;
|
|
133
|
+
} else {
|
|
134
|
+
// TODO in __DEV__ assert linkedRecord is an object
|
|
135
|
+
const result = checkFromRecord(
|
|
136
|
+
environment,
|
|
137
|
+
normalizationAstNode.selections,
|
|
138
|
+
variables,
|
|
139
|
+
linkedRecord,
|
|
140
|
+
// TODO this seems likely to be wrong
|
|
141
|
+
backupId + '.' + parentRecordKey,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (result.kind === 'MissingData') {
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
continue normalizationAstLoop;
|
|
151
|
+
}
|
|
152
|
+
case 'InlineFragment': {
|
|
153
|
+
const existingRecordTypename = record['__typename'];
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
existingRecordTypename == null ||
|
|
157
|
+
existingRecordTypename !== normalizationAstNode.type
|
|
158
|
+
) {
|
|
159
|
+
return {
|
|
160
|
+
kind: 'MissingData',
|
|
161
|
+
record: {
|
|
162
|
+
__link: record.id ?? backupId,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const result = checkFromRecord(
|
|
168
|
+
environment,
|
|
169
|
+
normalizationAstNode.selections,
|
|
170
|
+
variables,
|
|
171
|
+
record,
|
|
172
|
+
backupId,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
if (result.kind === 'MissingData') {
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
continue normalizationAstLoop;
|
|
180
|
+
}
|
|
181
|
+
default: {
|
|
182
|
+
let _: never = normalizationAstNode;
|
|
183
|
+
_;
|
|
184
|
+
throw new Error(
|
|
185
|
+
'Unexpected case. This is indicative of a bug in Isograph.',
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
kind: 'EnoughData',
|
|
193
|
+
};
|
|
194
|
+
}
|