relay-forms-nodeps 1.0.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.
Files changed (96) hide show
  1. package/.babelrc.js +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +124 -0
  4. package/lib/RelayFormsTypes.d.ts +37 -0
  5. package/lib/RelayFormsTypes.js +5 -0
  6. package/lib/Utils.d.ts +11 -0
  7. package/lib/Utils.js +87 -0
  8. package/lib/es/RelayFormsTypes.d.ts +37 -0
  9. package/lib/es/RelayFormsTypes.js +0 -0
  10. package/lib/es/Utils.d.ts +11 -0
  11. package/lib/es/Utils.js +81 -0
  12. package/lib/es/index.d.ts +9 -0
  13. package/lib/es/index.js +7 -0
  14. package/lib/es/relay/RelayModernRecord.d.ts +107 -0
  15. package/lib/es/relay/RelayModernRecord.js +183 -0
  16. package/lib/es/relay/RelayModernSelector.d.ts +11 -0
  17. package/lib/es/relay/RelayModernSelector.js +29 -0
  18. package/lib/es/relay/RelayModernStore.d.ts +51 -0
  19. package/lib/es/relay/RelayModernStore.js +355 -0
  20. package/lib/es/relay/RelayReader.d.ts +14 -0
  21. package/lib/es/relay/RelayReader.js +86 -0
  22. package/lib/es/relay/RelayRecordProxy.d.ts +28 -0
  23. package/lib/es/relay/RelayRecordProxy.js +57 -0
  24. package/lib/es/relay/RelayRecordSource.d.ts +28 -0
  25. package/lib/es/relay/RelayRecordSource.js +70 -0
  26. package/lib/es/relay/RelayRecordSourceMutator.d.ts +36 -0
  27. package/lib/es/relay/RelayRecordSourceMutator.js +75 -0
  28. package/lib/es/relay/RelayRecordSourceProxy.d.ts +25 -0
  29. package/lib/es/relay/RelayRecordSourceProxy.js +52 -0
  30. package/lib/es/relay/RelayReferenceMarker.d.ts +10 -0
  31. package/lib/es/relay/RelayReferenceMarker.js +54 -0
  32. package/lib/es/relay/RelayStoreProvider.d.ts +7 -0
  33. package/lib/es/relay/RelayStoreProvider.js +16 -0
  34. package/lib/es/relay/RelayStoreUtils.d.ts +51 -0
  35. package/lib/es/relay/RelayStoreUtils.js +199 -0
  36. package/lib/es/relay/RelayTypes.d.ts +92 -0
  37. package/lib/es/relay/RelayTypes.js +0 -0
  38. package/lib/es/relay/queries.d.ts +86 -0
  39. package/lib/es/relay/queries.js +68 -0
  40. package/lib/es/useForceUpdate.d.ts +1 -0
  41. package/lib/es/useForceUpdate.js +8 -0
  42. package/lib/es/useFormSetValue.d.ts +2 -0
  43. package/lib/es/useFormSetValue.js +84 -0
  44. package/lib/es/useFormState.d.ts +2 -0
  45. package/lib/es/useFormState.js +49 -0
  46. package/lib/es/useFormSubmit.d.ts +2 -0
  47. package/lib/es/useFormSubmit.js +105 -0
  48. package/lib/es/useFormValue.d.ts +2 -0
  49. package/lib/es/useFormValue.js +19 -0
  50. package/lib/index.d.ts +9 -0
  51. package/lib/index.js +20 -0
  52. package/lib/relay/RelayModernRecord.d.ts +107 -0
  53. package/lib/relay/RelayModernRecord.js +188 -0
  54. package/lib/relay/RelayModernSelector.d.ts +11 -0
  55. package/lib/relay/RelayModernSelector.js +36 -0
  56. package/lib/relay/RelayModernStore.d.ts +51 -0
  57. package/lib/relay/RelayModernStore.js +359 -0
  58. package/lib/relay/RelayReader.d.ts +14 -0
  59. package/lib/relay/RelayReader.js +92 -0
  60. package/lib/relay/RelayRecordProxy.d.ts +28 -0
  61. package/lib/relay/RelayRecordProxy.js +60 -0
  62. package/lib/relay/RelayRecordSource.d.ts +28 -0
  63. package/lib/relay/RelayRecordSource.js +75 -0
  64. package/lib/relay/RelayRecordSourceMutator.d.ts +36 -0
  65. package/lib/relay/RelayRecordSourceMutator.js +80 -0
  66. package/lib/relay/RelayRecordSourceProxy.d.ts +25 -0
  67. package/lib/relay/RelayRecordSourceProxy.js +57 -0
  68. package/lib/relay/RelayReferenceMarker.d.ts +10 -0
  69. package/lib/relay/RelayReferenceMarker.js +60 -0
  70. package/lib/relay/RelayStoreProvider.d.ts +7 -0
  71. package/lib/relay/RelayStoreProvider.js +22 -0
  72. package/lib/relay/RelayStoreUtils.d.ts +51 -0
  73. package/lib/relay/RelayStoreUtils.js +208 -0
  74. package/lib/relay/RelayTypes.d.ts +92 -0
  75. package/lib/relay/RelayTypes.js +5 -0
  76. package/lib/relay/queries.d.ts +86 -0
  77. package/lib/relay/queries.js +73 -0
  78. package/lib/umd/relay-forms-nodeps.js +1478 -0
  79. package/lib/umd/relay-forms-nodeps.js.map +1 -0
  80. package/lib/umd/relay-forms-nodeps.min.js +2 -0
  81. package/lib/umd/relay-forms-nodeps.min.js.map +1 -0
  82. package/lib/useForceUpdate.d.ts +1 -0
  83. package/lib/useForceUpdate.js +14 -0
  84. package/lib/useFormSetValue.d.ts +2 -0
  85. package/lib/useFormSetValue.js +90 -0
  86. package/lib/useFormState.d.ts +2 -0
  87. package/lib/useFormState.js +54 -0
  88. package/lib/useFormSubmit.d.ts +2 -0
  89. package/lib/useFormSubmit.js +110 -0
  90. package/lib/useFormValue.d.ts +2 -0
  91. package/lib/useFormValue.js +25 -0
  92. package/package.json +89 -0
  93. package/replace.config.js +5 -0
  94. package/rollup.config.js +92 -0
  95. package/tsconfig.esm.json +7 -0
  96. package/yarn-error.log +127 -0
@@ -0,0 +1,86 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @flow strict-local
9
+ * @format
10
+ */
11
+ import { RelayModernRecord } from './RelayModernRecord';
12
+ import { LINKED_FIELD } from './RelayStoreUtils';
13
+ export function relayRead(recordSource, selector) {
14
+ var reader = new RelayReader(recordSource, selector);
15
+ return reader.read();
16
+ }
17
+ /**
18
+ * @private
19
+ */
20
+ var RelayReader = /** @class */function () {
21
+ function RelayReader(recordSource, selector) {
22
+ this._recordSource = recordSource;
23
+ this._seenRecords = new Set();
24
+ this._selector = selector;
25
+ }
26
+ RelayReader.prototype.read = function () {
27
+ var _a = this._selector,
28
+ node = _a.node,
29
+ dataID = _a.dataID;
30
+ var data = this._traverse(node, dataID, null);
31
+ return {
32
+ data: data,
33
+ seenRecords: this._seenRecords,
34
+ selector: this._selector
35
+ };
36
+ };
37
+ RelayReader.prototype._traverse = function (node, dataID, prevData) {
38
+ if (dataID == null) {
39
+ return dataID;
40
+ }
41
+ var record = this._recordSource.get(dataID);
42
+ this._seenRecords.add(dataID);
43
+ if (record == null) {
44
+ return record;
45
+ }
46
+ var data = prevData || {};
47
+ this._traverseSelections(node.selections, record, data);
48
+ return data;
49
+ };
50
+ RelayReader.prototype._traverseSelections = function (selections, record, data) {
51
+ var _this = this;
52
+ var _loop_1 = function (i) {
53
+ var selection = selections[i];
54
+ var name_1 = selection.name;
55
+ var prevData = data[name_1];
56
+ var value = null;
57
+ if (selection.kind == LINKED_FIELD) {
58
+ if (selection.plural) {
59
+ var ids = RelayModernRecord.getLinkedRecordIDs(record, name_1);
60
+ if (ids != null) {
61
+ var linkedArray_1 = prevData || [];
62
+ ids.forEach(function (linkedID, nextIndex) {
63
+ var prevItem = linkedArray_1[nextIndex];
64
+ linkedArray_1[nextIndex] = _this._traverse(selection, linkedID, prevItem);
65
+ });
66
+ value = linkedArray_1;
67
+ }
68
+ } else {
69
+ var id = RelayModernRecord.getLinkedRecordID(record, name_1);
70
+ value = this_1._traverse(selection, id, prevData);
71
+ }
72
+ } else {
73
+ // relay-forms, now default scalar
74
+ value = RelayModernRecord.getValue(record, name_1);
75
+ //this._readScalar(selection, record, data);
76
+ }
77
+
78
+ data[name_1] = value;
79
+ };
80
+ var this_1 = this;
81
+ for (var i = 0; i < selections.length; i++) {
82
+ _loop_1(i);
83
+ }
84
+ };
85
+ return RelayReader;
86
+ }();
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+ import { RelayRecordSourceMutator } from './RelayRecordSourceMutator';
11
+ import { RecordProxy } from './RelayTypes';
12
+ /**
13
+ * @internal
14
+ *
15
+ * A helper class for manipulating a given record from a record source via an
16
+ * imperative/OO-style API.
17
+ */
18
+ export declare class RelayRecordProxy implements RecordProxy {
19
+ _dataID: any;
20
+ _mutator: RelayRecordSourceMutator;
21
+ _source: any;
22
+ constructor(source: any, mutator: any, dataID: any);
23
+ getDataID(): string;
24
+ setValue(value: any, name: string): this;
25
+ setLinkedRecord(record: RecordProxy, name: string): this;
26
+ getLinkedRecords(name: string): Array<RecordProxy | null | undefined> | null | undefined;
27
+ setLinkedRecords(records: any, name: string): RecordProxy;
28
+ }
@@ -0,0 +1,57 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @flow strict-local
9
+ * @format
10
+ */
11
+ // flowlint ambiguous-object-type:error
12
+ 'use strict';
13
+
14
+ /**
15
+ * @internal
16
+ *
17
+ * A helper class for manipulating a given record from a record source via an
18
+ * imperative/OO-style API.
19
+ */
20
+ var RelayRecordProxy = /** @class */function () {
21
+ function RelayRecordProxy(source, mutator, dataID) {
22
+ this._dataID = dataID;
23
+ this._mutator = mutator;
24
+ this._source = source;
25
+ }
26
+ RelayRecordProxy.prototype.getDataID = function () {
27
+ return this._dataID;
28
+ };
29
+ RelayRecordProxy.prototype.setValue = function (value, name) {
30
+ this._mutator.setValue(this._dataID, name, value);
31
+ return this;
32
+ };
33
+ RelayRecordProxy.prototype.setLinkedRecord = function (record, name) {
34
+ var linkedID = record.getDataID();
35
+ this._mutator.setLinkedRecordID(this._dataID, name, linkedID);
36
+ return this;
37
+ };
38
+ RelayRecordProxy.prototype.getLinkedRecords = function (name) {
39
+ var _this = this;
40
+ var linkedIDs = this._mutator.getLinkedRecordIDs(this._dataID, name);
41
+ if (linkedIDs == null) {
42
+ return linkedIDs;
43
+ }
44
+ return linkedIDs.map(function (linkedID) {
45
+ return linkedID != null ? _this._source.get(linkedID) : linkedID;
46
+ });
47
+ };
48
+ RelayRecordProxy.prototype.setLinkedRecords = function (records, name) {
49
+ var linkedIDs = records.map(function (record) {
50
+ return record && record.getDataID();
51
+ });
52
+ this._mutator.setLinkedRecordIDs(this._dataID, name, linkedIDs);
53
+ return this;
54
+ };
55
+ return RelayRecordProxy;
56
+ }();
57
+ export { RelayRecordProxy };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+ import { MutableRecordSource, Record, RecordState } from './RelayTypes';
11
+ /**
12
+ * An implementation of the `MutableRecordSource` interface (defined in
13
+ * `RelayStoreTypes`) that holds all records in memory (JS Map).
14
+ */
15
+ export declare class RelayRecordSource implements MutableRecordSource {
16
+ _records: any;
17
+ constructor(records?: any);
18
+ clear(): void;
19
+ delete(dataID: any): void;
20
+ get(dataID: any): Record | null | undefined;
21
+ getRecordIDs(): Array<string>;
22
+ getStatus(dataID: any): RecordState;
23
+ has(dataID: any): boolean;
24
+ remove(dataID: any): void;
25
+ set(dataID: any, record: any): void;
26
+ size(): number;
27
+ toJSON(): any;
28
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+ import { RelayRecordState } from './RelayStoreUtils';
11
+ var EXISTENT = RelayRecordState.EXISTENT,
12
+ NONEXISTENT = RelayRecordState.NONEXISTENT,
13
+ UNKNOWN = RelayRecordState.UNKNOWN;
14
+ /**
15
+ * An implementation of the `MutableRecordSource` interface (defined in
16
+ * `RelayStoreTypes`) that holds all records in memory (JS Map).
17
+ */
18
+ var RelayRecordSource = /** @class */function () {
19
+ function RelayRecordSource(records) {
20
+ var _this = this;
21
+ this._records = new Map();
22
+ if (records != null) {
23
+ Object.keys(records).forEach(function (key) {
24
+ _this._records.set(key, records[key]);
25
+ });
26
+ }
27
+ }
28
+ RelayRecordSource.prototype.clear = function () {
29
+ this._records = new Map();
30
+ };
31
+ RelayRecordSource.prototype.delete = function (dataID) {
32
+ this._records.set(dataID, null);
33
+ };
34
+ RelayRecordSource.prototype.get = function (dataID) {
35
+ return this._records.get(dataID);
36
+ };
37
+ RelayRecordSource.prototype.getRecordIDs = function () {
38
+ return Array.from(this._records.keys());
39
+ };
40
+ RelayRecordSource.prototype.getStatus = function (dataID) {
41
+ if (!this._records.has(dataID)) {
42
+ return UNKNOWN;
43
+ }
44
+ return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
45
+ };
46
+ RelayRecordSource.prototype.has = function (dataID) {
47
+ return this._records.has(dataID);
48
+ };
49
+ RelayRecordSource.prototype.remove = function (dataID) {
50
+ this._records.delete(dataID);
51
+ };
52
+ RelayRecordSource.prototype.set = function (dataID, record) {
53
+ this._records.set(dataID, record);
54
+ };
55
+ RelayRecordSource.prototype.size = function () {
56
+ return this._records.size;
57
+ };
58
+ RelayRecordSource.prototype.toJSON = function () {
59
+ var obj = {};
60
+ for (var _i = 0, _a = this._records.entries(); _i < _a.length; _i++) {
61
+ var _b = _a[_i],
62
+ key = _b[0],
63
+ value = _b[1];
64
+ obj[key] = value;
65
+ }
66
+ return obj;
67
+ };
68
+ return RelayRecordSource;
69
+ }();
70
+ export { RelayRecordSource };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+ import { MutableRecordSource, Record, RecordSource } from './RelayTypes';
11
+ /**
12
+ * @internal
13
+ *
14
+ * Wrapper API that is an amalgam of the `RelayModernRecord` API and
15
+ * `MutableRecordSource` interface, implementing copy-on-write semantics for records
16
+ * in a record source.
17
+ *
18
+ * Modifications are applied to fresh copies of records:
19
+ * - Records in `base` are never modified.
20
+ * - Modifications cause a fresh version of a record to be created in `sink`.
21
+ * These sink records contain only modified fields.
22
+ */
23
+ export declare class RelayRecordSourceMutator {
24
+ __sources: Array<RecordSource>;
25
+ _base: RecordSource;
26
+ _sink: MutableRecordSource;
27
+ constructor(base: any, sink: any);
28
+ _getSinkRecord(dataID: any): Record;
29
+ create(dataID: any): void;
30
+ delete(dataID: any): void;
31
+ getStatus(dataID: any): "EXISTENT" | "NONEXISTENT" | "UNKNOWN";
32
+ setValue(dataID: any, storageKey: string, value: any): void;
33
+ setLinkedRecordID(dataID: any, storageKey: any, linkedID: any): void;
34
+ getLinkedRecordIDs(dataID: any, storageKey: string): any;
35
+ setLinkedRecordIDs(dataID: any, storageKey: string, linkedIDs: any): void;
36
+ }
@@ -0,0 +1,75 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @flow strict-local
9
+ * @format
10
+ */
11
+ import { RelayModernRecord } from './RelayModernRecord';
12
+ /**
13
+ * @internal
14
+ *
15
+ * Wrapper API that is an amalgam of the `RelayModernRecord` API and
16
+ * `MutableRecordSource` interface, implementing copy-on-write semantics for records
17
+ * in a record source.
18
+ *
19
+ * Modifications are applied to fresh copies of records:
20
+ * - Records in `base` are never modified.
21
+ * - Modifications cause a fresh version of a record to be created in `sink`.
22
+ * These sink records contain only modified fields.
23
+ */
24
+ var RelayRecordSourceMutator = /** @class */function () {
25
+ function RelayRecordSourceMutator(base, sink) {
26
+ this.__sources = [sink, base];
27
+ this._base = base;
28
+ this._sink = sink;
29
+ }
30
+ RelayRecordSourceMutator.prototype._getSinkRecord = function (dataID) {
31
+ var sinkRecord = this._sink.get(dataID);
32
+ if (!sinkRecord) {
33
+ sinkRecord = RelayModernRecord.create(dataID);
34
+ this._sink.set(dataID, sinkRecord);
35
+ }
36
+ return sinkRecord;
37
+ };
38
+ RelayRecordSourceMutator.prototype.create = function (dataID) {
39
+ var record = RelayModernRecord.create(dataID);
40
+ this._sink.set(dataID, record);
41
+ };
42
+ RelayRecordSourceMutator.prototype.delete = function (dataID) {
43
+ this._sink.delete(dataID);
44
+ };
45
+ RelayRecordSourceMutator.prototype.getStatus = function (dataID) {
46
+ return this._sink.has(dataID) ? this._sink.getStatus(dataID) : this._base.getStatus(dataID);
47
+ };
48
+ RelayRecordSourceMutator.prototype.setValue = function (dataID, storageKey, value) {
49
+ var sinkRecord = this._getSinkRecord(dataID);
50
+ RelayModernRecord.setValue(sinkRecord, storageKey, value);
51
+ };
52
+ RelayRecordSourceMutator.prototype.setLinkedRecordID = function (dataID, storageKey, linkedID) {
53
+ var sinkRecord = this._getSinkRecord(dataID);
54
+ RelayModernRecord.setLinkedRecordID(sinkRecord, storageKey, linkedID);
55
+ };
56
+ RelayRecordSourceMutator.prototype.getLinkedRecordIDs = function (dataID, storageKey) {
57
+ for (var ii = 0; ii < this.__sources.length; ii++) {
58
+ var record = this.__sources[ii].get(dataID);
59
+ if (record) {
60
+ var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
61
+ if (linkedIDs !== undefined) {
62
+ return linkedIDs;
63
+ }
64
+ } else if (record === null) {
65
+ return null;
66
+ }
67
+ }
68
+ };
69
+ RelayRecordSourceMutator.prototype.setLinkedRecordIDs = function (dataID, storageKey, linkedIDs) {
70
+ var sinkRecord = this._getSinkRecord(dataID);
71
+ RelayModernRecord.setLinkedRecordIDs(sinkRecord, storageKey, linkedIDs);
72
+ };
73
+ return RelayRecordSourceMutator;
74
+ }();
75
+ export { RelayRecordSourceMutator };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ */
10
+ import { RelayRecordSourceMutator } from './RelayRecordSourceMutator';
11
+ import { RecordSourceProxy } from './RelayTypes';
12
+ /**
13
+ * @internal
14
+ *
15
+ * A helper for manipulating a `RecordSource` via an imperative/OO-style API.
16
+ */
17
+ export declare class RelayRecordSourceProxy implements RecordSourceProxy {
18
+ __mutator: RelayRecordSourceMutator;
19
+ _proxies: any;
20
+ constructor(mutator: any);
21
+ create(dataID: any): any;
22
+ delete(dataID: any): void;
23
+ get(dataID: any): any;
24
+ getRoot(): any;
25
+ }
@@ -0,0 +1,52 @@
1
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @flow
9
+ * @format
10
+ */
11
+ import { RelayRecordProxy } from './RelayRecordProxy';
12
+ import { RelayStoreUtils, RelayRecordState } from './RelayStoreUtils';
13
+ /**
14
+ * @internal
15
+ *
16
+ * A helper for manipulating a `RecordSource` via an imperative/OO-style API.
17
+ */
18
+ var RelayRecordSourceProxy = /** @class */function () {
19
+ function RelayRecordSourceProxy(mutator) {
20
+ this.__mutator = mutator;
21
+ this._proxies = {};
22
+ }
23
+ RelayRecordSourceProxy.prototype.create = function (dataID) {
24
+ this.__mutator.create(dataID);
25
+ delete this._proxies[dataID];
26
+ return this.get(dataID);
27
+ };
28
+ RelayRecordSourceProxy.prototype.delete = function (dataID) {
29
+ delete this._proxies[dataID];
30
+ this.__mutator.delete(dataID);
31
+ };
32
+ RelayRecordSourceProxy.prototype.get = function (dataID) {
33
+ if (!this._proxies.hasOwnProperty(dataID)) {
34
+ var status_1 = this.__mutator.getStatus(dataID);
35
+ if (status_1 === RelayRecordState.EXISTENT) {
36
+ this._proxies[dataID] = new RelayRecordProxy(this, this.__mutator, dataID);
37
+ } else {
38
+ this._proxies[dataID] = status_1 === RelayRecordState.NONEXISTENT ? null : undefined;
39
+ }
40
+ }
41
+ return this._proxies[dataID];
42
+ };
43
+ RelayRecordSourceProxy.prototype.getRoot = function () {
44
+ var root = this.get(RelayStoreUtils.ROOT_ID);
45
+ if (!root) {
46
+ root = this.create(RelayStoreUtils.ROOT_ID);
47
+ }
48
+ return root;
49
+ };
50
+ return RelayRecordSourceProxy;
51
+ }();
52
+ export { RelayRecordSourceProxy };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+ export declare function mark(recordSource: any, selector: any, references: any): void;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+ import { RelayModernRecord } from './RelayModernRecord';
11
+ import { LINKED_FIELD } from './RelayStoreUtils';
12
+ export function mark(recordSource, selector, references) {
13
+ var dataID = selector.dataID,
14
+ node = selector.node;
15
+ var marker = new RelayReferenceMarker(recordSource, references);
16
+ marker.mark(node, dataID);
17
+ }
18
+ /**
19
+ * @private
20
+ */
21
+ var RelayReferenceMarker = /** @class */function () {
22
+ function RelayReferenceMarker(recordSource, references) {
23
+ this._recordSource = recordSource;
24
+ this._references = references;
25
+ }
26
+ RelayReferenceMarker.prototype.mark = function (node, dataID) {
27
+ this._traverse(node, dataID);
28
+ };
29
+ RelayReferenceMarker.prototype._traverse = function (node, dataID) {
30
+ if (dataID != null) {
31
+ this._references.add(dataID);
32
+ var record = this._recordSource.get(dataID);
33
+ record != null && this._traverseSelections(node.selections, record);
34
+ }
35
+ };
36
+ RelayReferenceMarker.prototype._traverseSelections = function (selections, record) {
37
+ var _this = this;
38
+ selections.forEach(function (selection) {
39
+ var name = selection.name;
40
+ if (selection.kind == LINKED_FIELD) {
41
+ if (selection.plural) {
42
+ var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, name) || [];
43
+ linkedIDs.forEach(function (linkedID) {
44
+ _this._traverse(selection, linkedID);
45
+ });
46
+ } else {
47
+ var linkedID = RelayModernRecord.getLinkedRecordID(record, name);
48
+ _this._traverse(selection, linkedID);
49
+ }
50
+ }
51
+ });
52
+ };
53
+ return RelayReferenceMarker;
54
+ }();
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { Store } from './RelayTypes';
3
+ export declare const StoreProvider: <TStore extends Store = Store>(props: {
4
+ children: React.ReactNode;
5
+ store: TStore;
6
+ }) => JSX.Element;
7
+ export declare function useStore<TStore extends Store = Store>(): TStore;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ var ReactRelayContext = React.createContext(null);
3
+ export var StoreProvider = function (props) {
4
+ var context = React.useMemo(function () {
5
+ return {
6
+ store: props.store
7
+ };
8
+ }, [props.store]);
9
+ return React.createElement(ReactRelayContext.Provider, {
10
+ value: context
11
+ }, props.children);
12
+ };
13
+ export function useStore() {
14
+ var store = React.useContext(ReactRelayContext).store;
15
+ return store;
16
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ */
10
+ export declare function isPromise(p: any): boolean;
11
+ /**
12
+ * Checks if two values are equal. Values may be primitives, arrays, or objects.
13
+ * Returns true if both arguments have the same keys and values.
14
+ *
15
+ * @see http://underscorejs.org
16
+ * @copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
17
+ * @license MIT
18
+ */
19
+ export declare function areEqual(a: any, b: any): boolean;
20
+ /**
21
+ * Constants shared by all implementations of RecordSource/MutableRecordSource/etc.
22
+ */
23
+ export declare const RelayStoreUtils: {
24
+ ID_KEY: string;
25
+ REF_KEY: string;
26
+ REFS_KEY: string;
27
+ ROOT_ID: string;
28
+ };
29
+ export declare enum RelayRecordState {
30
+ /**
31
+ * Record exists (either fetched from the server or produced by a local,
32
+ * optimistic update).
33
+ */
34
+ EXISTENT = "EXISTENT",
35
+ /**
36
+ * Record is known not to exist (either as the result of a mutation, or
37
+ * because the server returned `null` when queried for the record).
38
+ */
39
+ NONEXISTENT = "NONEXISTENT",
40
+ /**
41
+ * Record State is unknown because it has not yet been fetched from the
42
+ * server.
43
+ */
44
+ UNKNOWN = "UNKNOWN"
45
+ }
46
+ export declare const LINKED_FIELD = "LinkedField";
47
+ /**
48
+ * Recycles subtrees from `prevData` by replacing equal subtrees in `nextData`.
49
+ */
50
+ export declare function recycleNodesInto<T>(prevData: T, nextData: T): T;
51
+ export declare function hasOverlappingIDs(seenRecords: any, updatedRecordIDs: any): boolean;